Summary: * Don't bother using a thread wrapper when the variable is known to have constant initialization. * Emit the thread wrapper as discardable-if-unused in TUs that don't contain a definition of the thread_local variable. * Don't emit the thread wrapper at all if the thread_local variable is unused and discardable; it will be emitted by all TUs that need it. Reviewers: rjmccall, jdoerfert Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67429 llvm-svn: 371767
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2a %s -emit-llvm -o - | FileCheck %s
|
|
|
|
// CHECK-DAG: @a = external thread_local global i32
|
|
extern thread_local int a;
|
|
|
|
// CHECK-DAG: @b = external thread_local global i32
|
|
extern thread_local constinit int b;
|
|
|
|
// CHECK-LABEL: define i32 @_Z1fv()
|
|
// CHECK: call i32* @_ZTW1a()
|
|
// CHECK: }
|
|
int f() { return a; }
|
|
|
|
// CHECK-LABEL: define linkonce_odr {{.*}} @_ZTW1a()
|
|
// CHECK: br i1
|
|
// CHECK: call void @_ZTH1a()
|
|
// CHECK: }
|
|
|
|
// CHECK-LABEL: define i32 @_Z1gv()
|
|
// CHECK-NOT: call
|
|
// CHECK: load i32, i32* @b
|
|
// CHECK-NOT: call
|
|
// CHECK: }
|
|
int g() { return b; }
|
|
|
|
// CHECK-NOT: define {{.*}} @_ZTW1b()
|
|
|
|
extern thread_local int c;
|
|
|
|
// CHECK-LABEL: define i32 @_Z1hv()
|
|
// CHECK: call i32* @_ZTW1c()
|
|
// CHECK: load i32, i32* %
|
|
// CHECK: }
|
|
int h() { return c; }
|
|
|
|
thread_local int c = 0;
|
|
|
|
int d_init();
|
|
thread_local int d = d_init();
|
|
|
|
// Note: use of 'c' does not trigger initialization of 'd', because 'c' has a
|
|
// constant initializer.
|
|
// CHECK-LABEL: define weak_odr {{.*}} @_ZTW1c()
|
|
// CHECK-NOT: br i1
|
|
// CHECK-NOT: call
|
|
// CHECK: ret i32* @c
|
|
// CHECK: }
|