blob: 5ed582d232b6f64bf92ffa1fd0d3282c15ffd48a [file] [log] [blame]
Richard Smith04e51762013-04-14 23:01:42 +00001// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
2
3int g();
4
5// CHECK: @_ZZ1fvE1n = internal thread_local global i32 0
6// CHECK: @_ZGVZ1fvE1n = internal thread_local global i8 0
7
8// CHECK: @_ZZ8tls_dtorvE1s = internal thread_local global
9// CHECK: @_ZGVZ8tls_dtorvE1s = internal thread_local global i8 0
10
11// CHECK: @_ZZ8tls_dtorvE1t = internal thread_local global
12// CHECK: @_ZGVZ8tls_dtorvE1t = internal thread_local global i8 0
13
14// CHECK: @_ZZ8tls_dtorvE1u = internal thread_local global
15// CHECK: @_ZGVZ8tls_dtorvE1u = internal thread_local global i8 0
16// CHECK: @_ZGRZ8tls_dtorvE1u = internal thread_local global
17
18// CHECK: define i32 @_Z1fv()
19int f() {
20 // CHECK: %[[GUARD:.*]] = load i8* @_ZGVZ1fvE1n, align 1
21 // CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
22 // CHECK: br i1 %[[NEED_INIT]]
23
24 // CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
25 // CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
26 // CHECK: store i8 1, i8* @_ZGVZ1fvE1n
27 // CHECK: br label
28 static thread_local int n = g();
29
30 // CHECK: load i32* @_ZZ1fvE1n, align 4
31 return n;
32}
33
34struct S { S(); ~S(); };
35struct T { ~T(); };
36
37// CHECK: define void @_Z8tls_dtorv()
38void tls_dtor() {
39 // CHECK: load i8* @_ZGVZ8tls_dtorvE1s
40 // CHECK: call void @_ZN1SC1Ev(%struct.S* @_ZZ8tls_dtorvE1s)
41 // CHECK: call i32 @__cxa_thread_atexit({{.*}}@_ZN1SD1Ev {{.*}} @_ZZ8tls_dtorvE1s{{.*}} @__dso_handle
42 // CHECK: store i8 1, i8* @_ZGVZ8tls_dtorvE1s
43 static thread_local S s;
44
45 // CHECK: load i8* @_ZGVZ8tls_dtorvE1t
46 // CHECK-NOT: _ZN1T
47 // CHECK: call i32 @__cxa_thread_atexit({{.*}}@_ZN1TD1Ev {{.*}}@_ZZ8tls_dtorvE1t{{.*}} @__dso_handle
48 // CHECK: store i8 1, i8* @_ZGVZ8tls_dtorvE1t
49 static thread_local T t;
50
51 // CHECK: load i8* @_ZGVZ8tls_dtorvE1u
52 // CHECK: call void @_ZN1SC1Ev(%struct.S* @_ZGRZ8tls_dtorvE1u)
53 // CHECK: call i32 @__cxa_thread_atexit({{.*}}@_ZN1SD1Ev {{.*}} @_ZGRZ8tls_dtorvE1u{{.*}} @__dso_handle
54 // CHECK: store i8 1, i8* @_ZGVZ8tls_dtorvE1u
55 static thread_local const S &u = S();
56}