]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: partial fix for qualifier inconsistency [PR120510]
authorMartin Uecker <uecker@tugraz.at>
Thu, 5 Jun 2025 21:55:39 +0000 (23:55 +0200)
committerMartin Uecker <uecker@gcc.gnu.org>
Mon, 9 Jun 2025 23:14:17 +0000 (01:14 +0200)
Checking assertions revealed that we sometimes produce
composite types with incorrect qualifiers, e.g. the example

int f(int [_Atomic]);
int f(int [_Atomic]);
int f(int [_Atomic]);

was rejected because atomic was lost in the second declaration.

PR c/120510

gcc/c/ChangeLog:
* c-typeck.cc (composite_types_internal): Handle arrays
declared with atomic for function arguments.

gcc/testsuite/ChangeLog:
* gcc.dg/pr120510.c

gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/pr120510.c [new file with mode: 0644]

index b59b5c8a8bb198cca7a2ea4336a481ebdf1af839..0ffb9f65bf13249044cf93687d7ef42f8a2a5647 100644 (file)
@@ -911,14 +911,16 @@ composite_type_internal (tree t1, tree t2, struct composite_cache* cache)
             p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
          {
             tree mv1 = TREE_VALUE (p1);
-            if (mv1 && mv1 != error_mark_node
-                && TREE_CODE (mv1) != ARRAY_TYPE)
-              mv1 = TYPE_MAIN_VARIANT (mv1);
+            if (mv1 && mv1 != error_mark_node)
+              mv1 = TYPE_ATOMIC (mv1)
+                    ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv1), TYPE_QUAL_ATOMIC)
+                    : TYPE_MAIN_VARIANT (mv1);
 
             tree mv2 = TREE_VALUE (p2);
-            if (mv2 && mv2 != error_mark_node
-                && TREE_CODE (mv2) != ARRAY_TYPE)
-              mv2 = TYPE_MAIN_VARIANT (mv2);
+            if (mv2 && mv2 != error_mark_node)
+              mv2 = TYPE_ATOMIC (mv2)
+                    ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv2), TYPE_QUAL_ATOMIC)
+                    : TYPE_MAIN_VARIANT (mv2);
 
            /* A null type means arg type is not specified.
               Take whatever the other function type has.  */
diff --git a/gcc/testsuite/gcc.dg/pr120510.c b/gcc/testsuite/gcc.dg/pr120510.c
new file mode 100644 (file)
index 0000000..d99c329
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+void f (int [_Atomic]);
+void f (int [_Atomic]);
+void f (int [_Atomic]);
+