2015-05-07 14:15:46 +08:00
|
|
|
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -fms-extensions -fms-compatibility -fms-compatibility-version=19 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
|
2015-05-08 05:19:06 +08:00
|
|
|
// REQUIRES: asserts
|
|
|
|
|
2015-05-07 14:15:46 +08:00
|
|
|
struct S {
|
|
|
|
S();
|
|
|
|
~S();
|
|
|
|
};
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-DAG: @"?s@?1??f@@YAAAUS@@XZ@4U2@A" = linkonce_odr dso_local thread_local global %struct.S zeroinitializer
|
|
|
|
// CHECK-DAG: @"??__J?1??f@@YAAAUS@@XZ@51" = linkonce_odr thread_local global i32 0
|
|
|
|
// CHECK-DAG: @"?s@?1??g@@YAAAUS@@XZ@4U2@A" = linkonce_odr dso_local global %struct.S zeroinitializer
|
|
|
|
// CHECK-DAG: @"?$TSS0@?1??g@@YAAAUS@@XZ@4HA" = linkonce_odr global i32 0
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-DAG: @_Init_thread_epoch = external thread_local global i32, align 4
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-DAG: @"?j@?1??h@@YAAAUS@@_N@Z@4U2@A" = linkonce_odr dso_local thread_local global %struct.S zeroinitializer
|
|
|
|
// CHECK-DAG: @"??__J?1??h@@YAAAUS@@_N@Z@51" = linkonce_odr thread_local global i32 0
|
|
|
|
// CHECK-DAG: @"?i@?1??h@@YAAAUS@@_N@Z@4U2@A" = linkonce_odr dso_local global %struct.S zeroinitializer
|
|
|
|
// CHECK-DAG: @"?$TSS0@?1??h@@YAAAUS@@_N@Z@4HA" = linkonce_odr global i32 0
|
|
|
|
// CHECK-DAG: @"?i@?1??g1@@YAHXZ@4HA" = internal global i32 0, align 4
|
|
|
|
// CHECK-DAG: @"?$TSS0@?1??g1@@YAHXZ@4HA" = internal global i32 0, align 4
|
2015-05-07 14:15:46 +08:00
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-LABEL: define {{.*}} @"?f@@YAAAUS@@XZ"()
|
2015-06-18 04:53:19 +08:00
|
|
|
// CHECK-SAME: personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
|
2015-05-07 14:15:46 +08:00
|
|
|
extern inline S &f() {
|
|
|
|
static thread_local S s;
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: %[[guard:.*]] = load i32, i32* @"??__J?1??f@@YAAAUS@@XZ@51"
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: %[[mask:.*]] = and i32 %[[guard]], 1
|
2017-07-27 06:01:09 +08:00
|
|
|
// CHECK-NEXT: %[[cmp:.*]] = icmp eq i32 %[[mask]], 0
|
|
|
|
// CHECK-NEXT: br i1 %[[cmp]], label %[[init:.*]], label %[[init_end:.*]], !prof ![[unlikely_threadlocal:.*]]
|
2015-05-07 14:15:46 +08:00
|
|
|
//
|
|
|
|
// CHECK: [[init]]:
|
|
|
|
// CHECK-NEXT: %[[or:.*]] = or i32 %[[guard]], 1
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: store i32 %[[or]], i32* @"??__J?1??f@@YAAAUS@@XZ@51"
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke {{.*}} @"??0S@@QAE@XZ"(%struct.S* @"?s@?1??f@@YAAAUS@@XZ@4U2@A")
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: to label %[[invoke_cont:.*]] unwind label %[[lpad:.*]]
|
|
|
|
//
|
|
|
|
// CHECK: [[invoke_cont]]:
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: call i32 @__tlregdtor(void ()* @"??__Fs@?1??f@@YAAAUS@@XZ@YAXXZ")
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: br label %[[init_end:.*]]
|
|
|
|
|
|
|
|
// CHECK: [[init_end]]:
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: ret %struct.S* @"?s@?1??f@@YAAAUS@@XZ@4U2@A"
|
2015-05-07 14:15:46 +08:00
|
|
|
|
|
|
|
// CHECK: [[lpad:.*]]:
|
2015-12-12 13:39:21 +08:00
|
|
|
// CHECK-NEXT: cleanuppad within none []
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: %[[guard:.*]] = load i32, i32* @"??__J?1??f@@YAAAUS@@XZ@51"
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: %[[mask:.*]] = and i32 %[[guard]], -2
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: store i32 %[[mask]], i32* @"??__J?1??f@@YAAAUS@@XZ@51"
|
2015-10-08 09:13:52 +08:00
|
|
|
// CHECK-NEXT: cleanupret {{.*}} unwind to caller
|
2015-05-07 14:15:46 +08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-LABEL: define {{.*}} @"?g@@YAAAUS@@XZ"()
|
2015-05-07 14:15:46 +08:00
|
|
|
extern inline S &g() {
|
|
|
|
static S s;
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: %[[guard:.*]] = load atomic i32, i32* @"?$TSS0@?1??g@@YAAAUS@@XZ@4HA" unordered, align 4
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: %[[epoch:.*]] = load i32, i32* @_Init_thread_epoch
|
|
|
|
// CHECK-NEXT: %[[cmp:.*]] = icmp sgt i32 %[[guard]], %[[epoch]]
|
2017-07-27 06:01:09 +08:00
|
|
|
// CHECK-NEXT: br i1 %[[cmp]], label %[[init_attempt:.*]], label %[[init_end:.*]], !prof ![[unlikely_staticlocal:.*]]
|
2015-05-07 14:15:46 +08:00
|
|
|
//
|
|
|
|
// CHECK: [[init_attempt]]:
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: call void @_Init_thread_header(i32* @"?$TSS0@?1??g@@YAAAUS@@XZ@4HA")
|
|
|
|
// CHECK-NEXT: %[[guard2:.*]] = load atomic i32, i32* @"?$TSS0@?1??g@@YAAAUS@@XZ@4HA" unordered, align 4
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: %[[cmp2:.*]] = icmp eq i32 %[[guard2]], -1
|
|
|
|
// CHECK-NEXT: br i1 %[[cmp2]], label %[[init:.*]], label %[[init_end:.*]]
|
|
|
|
//
|
|
|
|
// CHECK: [[init]]:
|
2018-10-15 23:43:00 +08:00
|
|
|
// CHECK-NEXT: invoke {{.*}} @"??0S@@QAE@XZ"(%struct.S* @"?s@?1??g@@YAAAUS@@XZ@4U2@A")
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: to label %[[invoke_cont:.*]] unwind label %[[lpad:.*]]
|
|
|
|
//
|
|
|
|
// CHECK: [[invoke_cont]]:
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: call i32 @atexit(void ()* @"??__Fs@?1??g@@YAAAUS@@XZ@YAXXZ")
|
|
|
|
// CHECK-NEXT: call void @_Init_thread_footer(i32* @"?$TSS0@?1??g@@YAAAUS@@XZ@4HA")
|
2015-05-07 14:15:46 +08:00
|
|
|
// CHECK-NEXT: br label %init.end
|
|
|
|
//
|
|
|
|
// CHECK: [[init_end]]:
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-NEXT: ret %struct.S* @"?s@?1??g@@YAAAUS@@XZ@4U2@A"
|
2015-05-07 14:15:46 +08:00
|
|
|
//
|
|
|
|
// CHECK: [[lpad]]:
|
2015-12-12 13:39:21 +08:00
|
|
|
// CHECK-NEXT: cleanuppad within none []
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK: call void @_Init_thread_abort(i32* @"?$TSS0@?1??g@@YAAAUS@@XZ@4HA")
|
2015-10-08 09:13:52 +08:00
|
|
|
// CHECK-NEXT: cleanupret {{.*}} unwind to caller
|
2015-05-07 14:15:46 +08:00
|
|
|
return s;
|
|
|
|
}
|
2015-05-07 18:11:27 +08:00
|
|
|
|
2015-05-08 05:19:06 +08:00
|
|
|
extern inline S&h(bool b) {
|
|
|
|
static thread_local S j;
|
|
|
|
static S i;
|
|
|
|
return b ? j : i;
|
|
|
|
}
|
2016-05-27 16:52:34 +08:00
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-LABEL: define dso_local i32 @"?g1@@YAHXZ"()
|
2016-05-27 16:52:34 +08:00
|
|
|
int f1();
|
|
|
|
int g1() {
|
|
|
|
static int i = f1();
|
|
|
|
return i;
|
|
|
|
}
|
2017-07-27 06:01:09 +08:00
|
|
|
|
|
|
|
// CHECK-DAG: ![[unlikely_threadlocal]] = !{!"branch_weights", i32 1, i32 1023}
|
|
|
|
// CHECK-DAG: ![[unlikely_staticlocal]] = !{!"branch_weights", i32 1, i32 1048575}
|