-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C23] Use thread_local semantics (#70107)
When implementing thread_local as a keyword in C23, we accidentally started using C++11 thread_local semantics when using that keyword instead of using C11 _Thread_local semantics. This oversight is fixed by pretending the user wrote _Thread_local instead. This doesn't have the best behavior in terms of diagnostics, but it does correct the semantic behavior. Fixes #70068 Fixes #69167
- Loading branch information
1 parent
afbe354
commit 2a41d97
Showing
4 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -std=c23 -emit-llvm -o - %s | FileCheck %s | ||
|
||
// Ensure that thread_local and _Thread_local emit the same codegen. See | ||
// https://github.com/llvm/llvm-project/issues/70068 for details. | ||
|
||
void func(void) { | ||
static thread_local int i = 12; | ||
static _Thread_local int j = 13; | ||
|
||
extern thread_local int k; | ||
extern thread_local int l; | ||
|
||
(void)k; | ||
(void)l; | ||
} | ||
|
||
// CHECK: @func.i = internal thread_local global i32 12, align 4 | ||
// CHECK-NEXT: @func.j = internal thread_local global i32 13, align 4 | ||
// CHECK-NEXT: @k = external thread_local global i32, align 4 | ||
// CHECK-NEXT: @l = external thread_local global i32, align 4 | ||
|
||
// CHECK: define dso_local void @func() | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: %[[K:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @k) | ||
// CHECK-NEXT: load i32, ptr %[[K]], align 4 | ||
// CHECK-NEXT: %[[L:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @l) | ||
// CHECK-NEXT: load i32, ptr %[[L]], align 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -std=c23 %s -verify | ||
|
||
// Ensure that thread_local and _Thread_local are synonyms in C23 and both | ||
// restrict local variables to be explicitly static or extern. | ||
void func(void) { | ||
// FIXME: it would be nice if the diagnostic said 'thread_local' in this case. | ||
thread_local int i = 12; // expected-error {{'_Thread_local' variables must have global storage}} | ||
_Thread_local int j = 13; // expected-error {{'_Thread_local' variables must have global storage}} | ||
|
||
static thread_local int k = 14; | ||
static _Thread_local int l = 15; | ||
|
||
extern thread_local int m; | ||
extern thread_local int n; | ||
} | ||
|
||
// This would previously fail because the tls models were different. | ||
extern thread_local unsigned a; | ||
_Thread_local unsigned a = 0; |