]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Do not allow thread-local tentative definitions for C2x
authorJoseph Myers <joseph@codesourcery.com>
Fri, 19 May 2023 00:42:07 +0000 (00:42 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Fri, 19 May 2023 00:42:07 +0000 (00:42 +0000)
commitc3db10967411be9c17f0ef01f13e82a947b7e12f
tree2e1f280b550a5d579ab71933545b01450f527050
parentb27760769ca03ff523caf0ec0b17296d3a2d8dba
c: Do not allow thread-local tentative definitions for C2x

C2x makes it clear that thread-local declarations can never be
tentative definitions (the legacy feature of C where you can e.g. do
"int i;" more than once at file scope, possibly with one of the
declarations initialized, and it counts as exactly one definition),
but are always definitions in the absence of "extern".  The wording
about external definitions was unclear in the thread-local case in C11
/ C17 (both about what counts as a tentative definition, and what is a
"definition" at all), not having been updated to cover the addition of
thread-local storage.

Implement this C2x requirement.  Arguably this is a defect fix that
would be appropriate to apply for all standard versions, but for now
the change is conditional on flag_isoc2x (however, it doesn't handle
_Thread_local / thread_local any different from GNU __thread).  Making
the change unconditional results in various TLS tests failing to
compile (gcc.dg/c11-thread-local-1.c gcc.dg/tls/thr-init-1.c
gcc.dg/tls/thr-init-2.c gcc.dg/torture/tls/thr-init-2.c
objc.dg/torture/tls/thr-init.m), though it's not clear if those tests
reflect any real code similarly trying to make use of thread-local
tentative definitions.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
* c-decl.cc (diagnose_mismatched_decls): Do not handle
thread-local declarations as tentative definitions for C2x.
(finish_decl): Do not allow thread-local definition with
incomplete type for C2x.

gcc/testsuite/
* gcc.dg/c2x-thread-local-2.c: New test.
gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/c2x-thread-local-2.c [new file with mode: 0644]