File tree Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Original file line number Diff line number Diff line change @@ -719,6 +719,10 @@ Bug Fixes in This Version
719
719
points (i.e., uses function descriptor objects instead).
720
720
- Fixes a ``clang-17 `` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF ``
721
721
cannot be used with ``Release `` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237 >`_).
722
+ - No longer use C++ ``thread_local `` semantics in C23 when using
723
+ ``thread_local `` instead of ``_Thread_local ``.
724
+ Fixes (`#70068 <https://github.com/llvm/llvm-project/issues/70068 >`_) and
725
+ (`#69167 <https://github.com/llvm/llvm-project/issues/69167 >`_)
722
726
723
727
Bug Fixes to Compiler Builtins
724
728
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -3997,9 +3997,16 @@ void Parser::ParseDeclarationSpecifiers(
3997
3997
break ;
3998
3998
case tok::kw_thread_local:
3999
3999
if (getLangOpts ().C2x )
4000
- Diag (Tok, diag::warn_c2x_compat_keyword) << Tok.getName ();
4001
- isInvalid = DS.SetStorageClassSpecThread (DeclSpec::TSCS_thread_local, Loc,
4002
- PrevSpec, DiagID);
4000
+ Diag (Tok, diag::warn_c23_compat_keyword) << Tok.getName ();
4001
+ // We map thread_local to _Thread_local in C23 mode so it retains the C
4002
+ // semantics rather than getting the C++ semantics.
4003
+ // FIXME: diagnostics will show _Thread_local when the user wrote
4004
+ // thread_local in source in C23 mode; we need some general way to
4005
+ // identify which way the user spelled the keyword in source.
4006
+ isInvalid = DS.SetStorageClassSpecThread (
4007
+ getLangOpts ().C2x ? DeclSpec::TSCS__Thread_local
4008
+ : DeclSpec::TSCS_thread_local,
4009
+ Loc, PrevSpec, DiagID);
4003
4010
isStorageClass = true ;
4004
4011
break ;
4005
4012
case tok::kw__Thread_local:
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -triple i686-pc-linux-gnu -std=c23 -emit-llvm -o - %s | FileCheck %s
2
+
3
+ // Ensure that thread_local and _Thread_local emit the same codegen. See
4
+ // https://github.com/llvm/llvm-project/issues/70068 for details.
5
+
6
+ void func (void ) {
7
+ static thread_local int i = 12 ;
8
+ static _Thread_local int j = 13 ;
9
+
10
+ extern thread_local int k ;
11
+ extern thread_local int l ;
12
+
13
+ (void )k ;
14
+ (void )l ;
15
+ }
16
+
17
+ // CHECK: @func.i = internal thread_local global i32 12, align 4
18
+ // CHECK-NEXT: @func.j = internal thread_local global i32 13, align 4
19
+ // CHECK-NEXT: @k = external thread_local global i32, align 4
20
+ // CHECK-NEXT: @l = external thread_local global i32, align 4
21
+
22
+ // CHECK: define dso_local void @func()
23
+ // CHECK-NEXT: entry:
24
+ // CHECK-NEXT: %[[K:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @k)
25
+ // CHECK-NEXT: load i32, ptr %[[K]], align 4
26
+ // CHECK-NEXT: %[[L:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @l)
27
+ // CHECK-NEXT: load i32, ptr %[[L]], align 4
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -fsyntax-only -std=c23 %s -verify
2
+
3
+ // Ensure that thread_local and _Thread_local are synonyms in C23 and both
4
+ // restrict local variables to be explicitly static or extern.
5
+ void func (void ) {
6
+ // FIXME: it would be nice if the diagnostic said 'thread_local' in this case.
7
+ thread_local int i = 12 ; // expected-error {{'_Thread_local' variables must have global storage}}
8
+ _Thread_local int j = 13 ; // expected-error {{'_Thread_local' variables must have global storage}}
9
+
10
+ static thread_local int k = 14 ;
11
+ static _Thread_local int l = 15 ;
12
+
13
+ extern thread_local int m ;
14
+ extern thread_local int n ;
15
+ }
16
+
17
+ // This would previously fail because the tls models were different.
18
+ extern thread_local unsigned a ;
19
+ _Thread_local unsigned a = 0 ;
You can’t perform that action at this time.
0 commit comments