The logic for loads and stores of _Atomic objects in the C front end involves taking the address of such objects, with really_atomic_lvalue detecting cases where this cannot be done (and also no special handling is needed for atomicity), in particular register _Atomic objects. This logic failed to deal with the case of register _Atomic compound literals, so resulting in spurious errors "error: address of register compound literal requested" followed by "error: argument 1 of '__atomic_load' must be a non-void pointer type". (This is a C23 bug that I found while changing really_atomic_lvalue as part of previous C2y changes.) Add a use of COMPOUND_LITERAL_EXPR_DECL in that case.
Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ * c-typeck.cc (really_atomic_lvalue): For a COMPOUND_LITERAL_EXPR, check C_DECL_REGISTER on the COMPOUND_LITERAL_EXPR_DECL. gcc/testsuite/ * gcc.dg/c23-complit-9.c: New test. diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 624e7a3fa359..6c807a2a7927 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2531,6 +2531,8 @@ really_atomic_lvalue (tree expr) return false; expr = TREE_OPERAND (expr, 0); } + if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR) + expr = COMPOUND_LITERAL_EXPR_DECL (expr); if (DECL_P (expr) && C_DECL_REGISTER (expr)) return false; return true; diff --git a/gcc/testsuite/gcc.dg/c23-complit-9.c b/gcc/testsuite/gcc.dg/c23-complit-9.c new file mode 100644 index 000000000000..738f1a6213fd --- /dev/null +++ b/gcc/testsuite/gcc.dg/c23-complit-9.c @@ -0,0 +1,9 @@ +/* Test register _Atomic compound literals. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23 -pedantic-errors" } */ + +void +f () +{ + (register _Atomic int) { 1 }; +} -- Joseph S. Myers josmy...@redhat.com