Home | History | Annotate | Download | only in CodeGenCXX
      1 // 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
      2 // REQUIRES: asserts
      3 
      4 struct S {
      5   S();
      6   ~S();
      7 };
      8 
      9 // CHECK-DAG: @"\01?s@?1??f@@YAAAUS@@XZ@4U2@A" = linkonce_odr thread_local global %struct.S zeroinitializer
     10 // CHECK-DAG: @"\01??__J?1??f@@YAAAUS@@XZ@51" = linkonce_odr thread_local global i32 0
     11 // CHECK-DAG: @"\01?s@?1??g@@YAAAUS@@XZ@4U2@A" = linkonce_odr global %struct.S zeroinitializer
     12 // CHECK-DAG: @"\01?$TSS0@?1??g@@YAAAUS@@XZ" = linkonce_odr global i32 0
     13 // CHECK-DAG: @_Init_thread_epoch = external thread_local global i32, align 4
     14 // CHECK-DAG: @"\01?j@?1??h@@YAAAUS@@_N@Z@4U2@A" = linkonce_odr thread_local global %struct.S zeroinitializer
     15 // CHECK-DAG: @"\01??__J?1??h@@YAAAUS@@_N@Z@51" = linkonce_odr thread_local global i32 0
     16 // CHECK-DAG: @"\01?i@?1??h@@YAAAUS@@_N@Z@4U2@A" = linkonce_odr global %struct.S zeroinitializer
     17 // CHECK-DAG: @"\01?$TSS0@?1??h@@YAAAUS@@_N@Z" = linkonce_odr global i32 0
     18 
     19 // CHECK-LABEL: define {{.*}} @"\01?f@@YAAAUS@@XZ"()
     20 // CHECK-SAME:  personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
     21 extern inline S &f() {
     22   static thread_local S s;
     23 // CHECK:       %[[guard:.*]] = load i32, i32* @"\01??__J?1??f@@YAAAUS@@XZ@51"
     24 // CHECK-NEXT:  %[[mask:.*]] = and i32 %[[guard]], 1
     25 // CHECK-NEXT:  %[[cmp:.*]] = icmp ne i32 %[[mask]], 0
     26 // CHECK-NEXT:  br i1 %[[cmp]], label %[[init_end:.*]], label %[[init:.*]]
     27 //
     28 // CHECK:     [[init]]:
     29 // CHECK-NEXT:  %[[or:.*]] = or i32 %[[guard]], 1
     30 // CHECK-NEXT:  store i32 %[[or]], i32* @"\01??__J?1??f@@YAAAUS@@XZ@51"
     31 // CHECK-NEXT:  invoke {{.*}} @"\01??0S@@QAE@XZ"(%struct.S* @"\01?s@?1??f@@YAAAUS@@XZ@4U2@A")
     32 // CHECK-NEXT:    to label %[[invoke_cont:.*]] unwind label %[[lpad:.*]]
     33 //
     34 // CHECK:     [[invoke_cont]]:
     35 // CHECK-NEXT:  call i32 @__tlregdtor(void ()* @"\01??__Fs@?1??f@@YAAAUS@@XZ@YAXXZ")
     36 // CHECK-NEXT:  br label %[[init_end:.*]]
     37 
     38 // CHECK:     [[init_end]]:
     39 // CHECK-NEXT:  ret %struct.S* @"\01?s@?1??f@@YAAAUS@@XZ@4U2@A"
     40 
     41 // CHECK:     [[lpad:.*]]:
     42 // CHECK-NEXT: cleanuppad within none []
     43 // CHECK:       %[[guard:.*]] = load i32, i32* @"\01??__J?1??f@@YAAAUS@@XZ@51"
     44 // CHECK-NEXT:  %[[mask:.*]] = and i32 %[[guard]], -2
     45 // CHECK-NEXT:  store i32 %[[mask]], i32* @"\01??__J?1??f@@YAAAUS@@XZ@51"
     46 // CHECK-NEXT:  cleanupret {{.*}} unwind to caller
     47   return s;
     48 }
     49 
     50 
     51 // CHECK-LABEL: define {{.*}} @"\01?g@@YAAAUS@@XZ"()
     52 extern inline S &g() {
     53   static S s;
     54 // CHECK:  %[[guard:.*]] = load atomic i32, i32* @"\01?$TSS0@?1??g@@YAAAUS@@XZ" unordered, align 4
     55 // CHECK-NEXT:  %[[epoch:.*]] = load i32, i32* @_Init_thread_epoch
     56 // CHECK-NEXT:  %[[cmp:.*]] = icmp sgt i32 %[[guard]], %[[epoch]]
     57 // CHECK-NEXT:  br i1 %[[cmp]], label %[[init_attempt:.*]], label %[[init_end:.*]]
     58 //
     59 // CHECK:     [[init_attempt]]:
     60 // CHECK-NEXT:  call void @_Init_thread_header(i32* @"\01?$TSS0@?1??g@@YAAAUS@@XZ")
     61 // CHECK-NEXT:  %[[guard2:.*]] = load atomic i32, i32* @"\01?$TSS0@?1??g@@YAAAUS@@XZ" unordered, align 4
     62 // CHECK-NEXT:  %[[cmp2:.*]] = icmp eq i32 %[[guard2]], -1
     63 // CHECK-NEXT:  br i1 %[[cmp2]], label %[[init:.*]], label %[[init_end:.*]]
     64 //
     65 // CHECK:     [[init]]:
     66 // CHECK-NEXT:  invoke {{.*}} @"\01??0S@@QAE@XZ"(%struct.S* @"\01?s@?1??g@@YAAAUS@@XZ@4U2@A")
     67 // CHECK-NEXT:    to label %[[invoke_cont:.*]] unwind label %[[lpad:.*]]
     68 //
     69 // CHECK:     [[invoke_cont]]:
     70 // CHECK-NEXT:  call i32 @atexit(void ()* @"\01??__Fs@?1??g@@YAAAUS@@XZ@YAXXZ")
     71 // CHECK-NEXT:  call void @_Init_thread_footer(i32* @"\01?$TSS0@?1??g@@YAAAUS@@XZ")
     72 // CHECK-NEXT:  br label %init.end
     73 //
     74 // CHECK:     [[init_end]]:
     75 // CHECK-NEXT:  ret %struct.S* @"\01?s@?1??g@@YAAAUS@@XZ@4U2@A"
     76 //
     77 // CHECK:     [[lpad]]:
     78 // CHECK-NEXT: cleanuppad within none []
     79 // CHECK:       call void @_Init_thread_abort(i32* @"\01?$TSS0@?1??g@@YAAAUS@@XZ")
     80 // CHECK-NEXT:  cleanupret {{.*}} unwind to caller
     81   return s;
     82 }
     83 
     84 extern inline S&h(bool b) {
     85   static thread_local S j;
     86   static S i;
     87   return b ? j : i;
     88 }
     89