[gcc r16-6472] c: Fix construction of composite type for atomic pointers [PR121081]
Martin Uecker
uecker@gcc.gnu.org
Sat Jan 3 10:37:04 GMT 2026
https://gcc.gnu.org/g:41177976c5e4448365f1966f6594458232db05fc
commit r16-6472-g41177976c5e4448365f1966f6594458232db05fc
Author: Martin Uecker <uecker@tugraz.at>
Date: Thu Dec 25 18:27:33 2025 +0100
c: Fix construction of composite type for atomic pointers [PR121081]
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.
Diff:
---
gcc/c/c-typeck.cc | 12 +++++-------
gcc/testsuite/gcc.dg/pr121081.c | 9 +++++++++
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index dd2a948872b2..26805e5cfd6b 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -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
index 000000000000..244d0e2e6e38
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr121081.c
@@ -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;
+
More information about the Gcc-cvs
mailing list