Okay, here's the updated patch series.  I've broken the commits down
somewhat.

Of course, this version depends on typed qualifiers, see
https://inbox.sourceware.org/gcc-patches/[email protected]/

I've also set up self-testing for the various routines affected by
address-space checks, so that we have target-independent tests.

This revision does not do away with copying the address-space qualifier
to array types.  I can go back and do that if desired.

Though, it seems to me valid also to adjust TYPE_ADDR_SPACE to strip
arrays, and use THIS_TYPES_ADDR_SPACE or such to access the actual
TYPE_ADDR_SPACE field; the latter for an array (and OFFSET_TYPEs, and
maybe others that I am not recalling immediately) must always be the
element (or struct) type.

Johann mentioned:

> The old way of reading from flash is qua inline asm (macros provided
> bv libc's avr/pgmspace.h for convenience.  So an old code may read:
>
> const int vals[] = { 1, 2 } __attribute((progmem));
>
> ... p = &vals[idx];
>
> int flash_read_int (const int *p /*points to flash*/)
> {
>     return pgm_read_int (p); // #include <avr/pgmspace.h>
> }
>
> Using a plain *p would use the wrong instructions and read from RAM.
> Without changing the interface of flash_read_int(), a code using AS
> is:
>
> int flash_read_int (const int *p /*points to flash*/)
> {
>     return * (const __flash int*) p;
> }
>
> That's why casting between address-spaces is allowed.  Though in your
> example, wrong code would be generated (except SS *p uses pgm_read_xxx
> for access), and -Waddr-space-convert should complain as the cast is
> implicit.
>
> Zo find questionable uses, users can -Waddr-space-convert, so that
> avr's TARGET_CONVERT_TO_TYPE diagnoses them.  The idea is that
> explicit casts are okay (wanted by the user) while implicit casts
> should be diagnosed.
>
> Unfortunately, the c++ front doesn't call TARGET_CONVERT_TO_TYPE
> whereas the c front does. (TARGET_ADDR_SPACE_CONVERT is for emitting
> actual RTL for such conversions, be they explicit or implicit.  It
> runs late after LTO streaming, and therefore it is not well suited for
> diagnostics).

I see that the C++ FE does call that hook in ocp_convert.  Maybe the
issue was in the way a previous version of the patch handled the actual
conversion, and goes away with this revision.

Johann, please re-test.  If it fails again, please let me know and I
will look into it in more detail.

This patch still doesn't address the issue that exists with
constructors, or generally member functions, but it is a start.

Tested on x86_64-linux-gnu.

On the review comments:

Jason Merrill <[email protected]> writes:

>>              /* We're permitted to remove the addr-space difference.  Doing
>>                 this will allow deducing to T without the address-space, and
>>                 then applying a qualifying conversion to it.  */
>>              arg_pointee = (cp_build_qualified_type
>>                             (arg_pointee,
>>                              CLEAR_QUAL_ADDR_SPACE (arg_pointee_quals)));
>
> This seems wrong for the case where parm is generic and we want to deduce a
> specific address space?

Yes, it was.  I worked out the logic incorrectly.  This revision never
replaces the PARM address space if generic (i.e. it will always have it
be deduced).

> True, though then it seems the above subset_p call is redundant.  And
> the check for different AS at !is_toplevel could join the constp == 0
> check.

No, because that check is not necessarily reached for two differing
address spaces that are overlapping, for instance.  But, it is
sufficient to check for the address space difference alone and reject,
so the check does become simpler.

>>> (which is gratuitously obscure, the parameter should really be a bool
>>> called something like "proper" and constp be a local variable)
>> I wouldn't mind making this change also, if you want.  I left a comment,
>> but this is still quite confusing.
>
> Sounds good, but let's make that a separate patch.

Done; that's patch 7.


Arsen Arsenović (6):
  gcc/cp-tree: require that temp_override deduces on first constructor
    arg
  gcc/target.def: fix HOOK_PREFIX redefinition warning
  gcc/{c,cp,c-family}: move some address space handling into c-family
  gcc/c-family: implement addr_space_test, a helper for self-testing
    ASes
  gcc/c++: implement basic support for Named Address Spaces in C++
    [PR69549]
  c++: make comp_ptr_ttypes_real slightly easier to understand

Thomas Schwinge (1):
  gcc/system.h: Allow for '#define INCLUDE_ITERATOR' to '#include
    <iterator>'

 gcc/c-family/c-common.cc                      | 142 +++++
 gcc/c-family/c-common.h                       |  62 +-
 gcc/c/c-decl.cc                               |  26 +-
 gcc/c/c-typeck.cc                             |  26 -
 gcc/cp/call.cc                                |  60 +-
 gcc/cp/class.cc                               |   8 +-
 gcc/cp/cp-gimplify.cc                         |  37 ++
 gcc/cp/cp-lang.cc                             |   1 +
 gcc/cp/cp-objcp-common.h                      |   5 +-
 gcc/cp/cp-tree.h                              | 111 +++-
 gcc/cp/decl.cc                                | 141 ++++-
 gcc/cp/error.cc                               |   1 +
 gcc/cp/init.cc                                |  32 +-
 gcc/cp/lex.cc                                 |  23 +
 gcc/cp/mangle.cc                              |  11 +-
 gcc/cp/method.cc                              |  23 +-
 gcc/cp/module.cc                              |  45 +-
 gcc/cp/parser.cc                              | 195 ++++--
 gcc/cp/pt.cc                                  | 432 +++++++++++--
 gcc/cp/reflect.cc                             |   7 +-
 gcc/cp/rtti.cc                                |   4 +-
 gcc/cp/search.cc                              |  21 +-
 gcc/cp/semantics.cc                           |  32 +-
 gcc/cp/tree.cc                                | 171 +++++-
 gcc/cp/typeck.cc                              | 573 +++++++++++++++---
 gcc/cp/typeck2.cc                             |  13 +-
 gcc/doc/extend.texi                           |   2 +-
 gcc/doc/tm.texi                               |   8 +-
 gcc/doc/tm.texi.in                            |   8 +-
 gcc/system.h                                  |   3 +
 gcc/target.def                                |   1 +
 gcc/testsuite/g++.dg/abi/mangle-addr-space1.C |   9 +
 gcc/testsuite/g++.dg/abi/mangle-addr-space2.C |   9 +
 gcc/testsuite/g++.dg/ext/addr-space-conv.C    | 209 +++++++
 gcc/testsuite/g++.dg/ext/addr-space-decl.C    |   5 +
 gcc/testsuite/g++.dg/ext/addr-space-ops.C     |  24 +
 gcc/testsuite/g++.dg/ext/addr-space-ref.C     |  29 +
 gcc/testsuite/g++.dg/parse/addr-space.C       |   9 +
 gcc/testsuite/g++.dg/parse/addr-space1.C      |  10 +
 gcc/testsuite/g++.dg/parse/addr-space2.C      |   9 +
 .../g++.dg/template/addr-space-overload.C     |  17 +
 .../g++.dg/template/addr-space-strip1.C       |  18 +
 .../g++.dg/template/addr-space-strip2.C       |  17 +
 .../g++.dg/template/spec-addr-space.C         |  10 +
 44 files changed, 2236 insertions(+), 363 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/abi/mangle-addr-space1.C
 create mode 100644 gcc/testsuite/g++.dg/abi/mangle-addr-space2.C
 create mode 100644 gcc/testsuite/g++.dg/ext/addr-space-conv.C
 create mode 100644 gcc/testsuite/g++.dg/ext/addr-space-decl.C
 create mode 100644 gcc/testsuite/g++.dg/ext/addr-space-ops.C
 create mode 100644 gcc/testsuite/g++.dg/ext/addr-space-ref.C
 create mode 100644 gcc/testsuite/g++.dg/parse/addr-space.C
 create mode 100644 gcc/testsuite/g++.dg/parse/addr-space1.C
 create mode 100644 gcc/testsuite/g++.dg/parse/addr-space2.C
 create mode 100644 gcc/testsuite/g++.dg/template/addr-space-overload.C
 create mode 100644 gcc/testsuite/g++.dg/template/addr-space-strip1.C
 create mode 100644 gcc/testsuite/g++.dg/template/addr-space-strip2.C
 create mode 100644 gcc/testsuite/g++.dg/template/spec-addr-space.C

-- 
2.55.0

Reply via email to