]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: partial fix for qualifier inconsistency II [PR120510]
authorMartin Uecker <uecker@tugraz.at>
Sat, 7 Jun 2025 12:24:28 +0000 (14:24 +0200)
committerMartin Uecker <uecker@gcc.gnu.org>
Mon, 9 Jun 2025 23:14:24 +0000 (01:14 +0200)
This fixes a case where we invoke composite_type with types
that do not have matching qualifiers.  With this change, we can
activate the checking assertion that makes sure the composite
type is compatible with the two original types also for arrays.

PR c/120510

gcc/c/ChangeLog:
* c-typeck.cc (composite_type_internal): Activate checking
assertion for arrays.
(common_pointer_type): Remove qualifiers also from arrays.

gcc/c/c-typeck.cc

index 0ffb9f65bf13249044cf93687d7ef42f8a2a5647..b8a8279e50bd6a0e5b27ea98d4f51ee7414c9f2a 100644 (file)
@@ -1002,9 +1002,9 @@ composite_type (tree t1, tree t2)
 {
   struct composite_cache cache = { };
   tree n = composite_type_internal (t1, t2, &cache);
-  /* For function and arrays there are some cases where qualifiers do
+  /* For function types there are some cases where qualifiers do
      not match.  See PR120510.  */
-  if (FUNCTION_TYPE != TREE_CODE (n) && ARRAY_TYPE != TREE_CODE (n))
+  if (FUNCTION_TYPE != TREE_CODE (n))
     {
       gcc_checking_assert (comptypes (n, t1));
       gcc_checking_assert (comptypes (n, t2));
@@ -1022,9 +1022,6 @@ static tree
 common_pointer_type (tree t1, tree t2)
 {
   tree attributes;
-  tree pointed_to_1, mv1;
-  tree pointed_to_2, mv2;
-  tree target;
   unsigned target_quals;
   addr_space_t as1, as2, as_common;
   int quals1, quals2;
@@ -1046,15 +1043,11 @@ common_pointer_type (tree t1, tree t2)
   attributes = targetm.merge_type_attributes (t1, t2);
 
   /* Find the composite type of the target types, and combine the
-     qualifiers of the two types' targets.  Do not lose qualifiers on
-     array element types by taking the TYPE_MAIN_VARIANT.  */
-  mv1 = pointed_to_1 = TREE_TYPE (t1);
-  mv2 = pointed_to_2 = TREE_TYPE (t2);
-  if (TREE_CODE (mv1) != ARRAY_TYPE)
-    mv1 = TYPE_MAIN_VARIANT (pointed_to_1);
-  if (TREE_CODE (mv2) != ARRAY_TYPE)
-    mv2 = TYPE_MAIN_VARIANT (pointed_to_2);
-  target = composite_type (mv1, mv2);
+     qualifiers of the two types' targets.  */
+  tree pointed_to_1 = TREE_TYPE (t1);
+  tree pointed_to_2 = TREE_TYPE (t2);
+  tree target = composite_type (TYPE_MAIN_VARIANT (pointed_to_1),
+                               TYPE_MAIN_VARIANT (pointed_to_2));
 
   /* Strip array types to get correct qualifier for pointers to arrays */
   quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));