These three small patches fix some inconsistencies related to composite type which became apparent when moving the checking assertion. The first two are small fixes, while the third proposes to add a helper function for removing qualifers except atomic to make the code more robust.
Bootstrapped and regression tested for x86_64. Martin Checking assertion 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/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 | 14 ++++++++------ gcc/testsuite/gcc.dg/pr120510.c | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr120510.c diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index b59b5c8a8bb..0ffb9f65bf1 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -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 index 00000000000..d99c329c1d7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr120510.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c23" } */ + +void f (int [_Atomic]); +void f (int [_Atomic]); +void f (int [_Atomic]); + -- 2.39.5