]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix construction of composite type for atomic pointers [PR121081]
authorMartin Uecker <uecker@tugraz.at>
Thu, 25 Dec 2025 17:27:33 +0000 (18:27 +0100)
committerMartin Uecker <uecker@gcc.gnu.org>
Sat, 3 Jan 2026 10:36:30 +0000 (11:36 +0100)
When constructing the composite type of two atomic pointer types,
we used "qualify_type" which did not copy the "atomic" qualifier.
Use c_build_type_attribute_qual_variant instead.

PR c/121081

gcc/c/ChangeLog:
* c-typeck.cc (composite_type_internal): Properly copy
atomic qualifier.

gcc/testsuite/ChangeLog:
* gcc.dg/pr121081.c: New test.

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

index dd2a948872b20fab6e21a7203ffc8733045e6fc6..26805e5cfd6bb039dc40b302163c7b4e8681c582 100644 (file)
@@ -689,13 +689,11 @@ composite_type_internal (tree t1, tree t2, tree cond,
     case POINTER_TYPE:
       /* For two pointers, do this recursively on the target type.  */
       {
-       tree pointed_to_1 = TREE_TYPE (t1);
-       tree pointed_to_2 = TREE_TYPE (t2);
-       tree target = composite_type_internal (pointed_to_1, pointed_to_2,
+       tree target = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
                                               cond, cache);
-       t1 = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
-       t1 = c_build_type_attribute_variant (t1, attributes);
-       return qualify_type (t1, t2);
+       tree n = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
+       return c_build_type_attribute_qual_variant (n, attributes,
+                                                   TYPE_QUALS (t2));
       }
 
     case ARRAY_TYPE:
@@ -1720,7 +1718,7 @@ comptypes_internal (const_tree type1, const_tree type2,
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
   if (!(attrval = comp_type_attributes (t1, t2)))
-     return false;
+    return false;
 
   if (2 == attrval)
     data->warning_needed = true;
diff --git a/gcc/testsuite/gcc.dg/pr121081.c b/gcc/testsuite/gcc.dg/pr121081.c
new file mode 100644 (file)
index 0000000..244d0e2
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */ 
+/* { dg-options "-std=c11" } */
+
+int * _Atomic __attribute__((visibility(""))) a;       /* { dg-warning "attribute ignored" } */
+int * _Atomic a;
+
+int * _Atomic __attribute__((visibility("hidden"))) b; /* { dg-warning "attribute ignored" } */
+int * _Atomic b;
+