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);
}
Grüße
Thomas
>From cc312ee7bbd3fa44b007eecec876995f293b5094 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <[email protected]>
Date: Thu, 18 Jun 2026 20:09:58 +0200
Subject: [PATCH] c++: parser - Support for target address spaces in C++:
simplify 'comp_ptr_ttypes_real'
..., and fix source code indentation.
The 'POINTER_TYPE'/'TREE_TYPE's will be handled in a second outer loop iteration:
for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
---
gcc/cp/typeck.cc | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index ed80427b0f15..f6fffc35f100 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -12067,29 +12067,14 @@ 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));
+ /* 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;
- }
- 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);
--
2.34.1