On 6/18/26 3:57 PM, Thomas Schwinge wrote:
Hi!

On 2026-05-15T14:17:10+0200, Thomas Schwinge <[email protected]> wrote:
I've now rebased [Paul's v4] onto recent GCC trunk, [...]

Arsen is currently working on addressing the items identified in the
other sub-thread, related to implicit/explicit conversions between named
address spaces (thanks, Jason, for your review and comments!), so I'm not
sure if the following then is still valid, but anyway, in the current v4,
regarding 'comp_ptr_ttypes_real':

--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc

|  static bool
|  comp_ptr_ttypes_real (tree to, tree from, int constp)
|  {
|    bool to_more_cv_qualified = false;
|    bool is_opaque_pointer = false;
|
|    for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
|      {

@@ -11861,6 +11964,30 @@ comp_ptr_ttypes_real (tree to, tree from, int constp)
              to_more_cv_qualified = true;
            }
+ /* Warn about conversions between pointers to disjoint
+        address spaces.  */
+      if (TREE_CODE (from) == POINTER_TYPE
+         && TREE_CODE (to) == POINTER_TYPE)
+       {
+         addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (from));
+         addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (to));
+         addr_space_t as_common;
+
+         if (!addr_space_superset (as_to, as_from, &as_common)
+             || as_common != as_to)
+           return false;
+       }
+      else
+       {
+         addr_space_t as_from = TYPE_ADDR_SPACE ((from));
+         addr_space_t as_to = TYPE_ADDR_SPACE ((to));
+         addr_space_t as_common;
+
+         if (!addr_space_superset (as_to, as_from, &as_common)
+             || as_common != as_to)
+           return false;
+       }
+
          if (constp > 0)
            constp &= TYPE_READONLY (to);
        }

The 'POINTER_TYPE'/'TREE_TYPE's will be handled in a second outer loop
iteration:
for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))

..., so we may simplify this code (..., and fix source code indentation)
as per the attached (incremental to Paul's v4)
"c++: parser - Support for target address spaces in C++: simplify 
'comp_ptr_ttypes_real'",
which I intend to merge into the v5 of this patch, unless there's any
objection, of course.  It's certainly possible that I'm misunderstanding
the fine print here?  If not, with this, the changes related to
'comp_ptr_ttypes_real' of trunk vs. upcoming v5 are just:

     --- gcc/cp/typeck.cc
     +++ gcc/cp/typeck.cc
@@ -11965,6 +12067,15 @@ comp_ptr_ttypes_real (tree to, tree from, int constp)
              to_more_cv_qualified = true;
            }
+ /* Warn about conversions between pointers to disjoint
     +       address spaces.  */
     +    addr_space_t as_from = TYPE_ADDR_SPACE (from);
     +    addr_space_t as_to = TYPE_ADDR_SPACE (to);
     +    addr_space_t as_common;
     +    if (!addr_space_superset (as_to, as_from, &as_common)
     +        || as_common != as_to)
     +      return false;
     +
          if (constp > 0)
            constp &= TYPE_READONLY (to);
        }

I suspect that at_least_as_qualified_p is going to need adjustment, perhaps just to use TYPE_QUALS_NO_ADDR_SPACE.

Jason

Reply via email to