Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -o - %s \
      2 // RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
      3 // RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -o - %s \
      4 // RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
      5 
      6 // Test that we don't create common blocks.
      7 int tentative;
      8 // WEBASSEMBLY32: @tentative = global i32 0, align 4
      9 // WEBASSEMBLY64: @tentative = global i32 0, align 4
     10 
     11 // Test that WebAssembly uses the ARM-style ABI in which the static
     12 // variable's guard variable is tested via "load i8 and test the
     13 // bottom bit" rather than the Itanium/x86 ABI which uses "load i8
     14 // and compare with zero".
     15 int f();
     16 void g() {
     17   static int a = f();
     18 }
     19 // WEBASSEMBLY32-LABEL: @_Z1gv()
     20 // WEBASSEMBLY32:       %[[R0:.+]] = load atomic i8, i8* bitcast (i32* @_ZGVZ1gvE1a to i8*) acquire, align 4
     21 // WEBASSEMBLY32-NEXT:  %[[R1:.+]] = and i8 %[[R0]], 1
     22 // WEBASSEMBLY32-NEXT:  %[[R2:.+]] = icmp eq i8 %[[R1]], 0
     23 // WEBASSEMBLY32-NEXT:  br i1 %[[R2]], label %[[CHECK:.+]], label %[[END:.+]]
     24 // WEBASSEMBLY32:       [[CHECK]]
     25 // WEBASSEMBLY32:       call i32 @__cxa_guard_acquire
     26 // WEBASSEMBLY32:       [[END]]
     27 // WEBASSEMBLY32:       call void @__cxa_guard_release
     28 //
     29 // WEBASSEMBLY64-LABEL: @_Z1gv()
     30 // WEBASSEMBLY64:       %[[R0:.+]] = load atomic i8, i8* bitcast (i64* @_ZGVZ1gvE1a to i8*) acquire, align 8
     31 // WEBASSEMBLY64-NEXT:  %[[R1:.+]] = and i8 %[[R0]], 1
     32 // WEBASSEMBLY64-NEXT:  %[[R2:.+]] = icmp eq i8 %[[R1]], 0
     33 // WEBASSEMBLY64-NEXT:  br i1 %[[R2]], label %[[CHECK:.+]], label %[[END:.+]]
     34 // WEBASSEMBLY64:       [[CHECK]]
     35 // WEBASSEMBLY64:       call i32 @__cxa_guard_acquire
     36 // WEBASSEMBLY64:       [[END]]
     37 // WEBASSEMBLY64:       call void @__cxa_guard_release
     38 
     39 // Test various aspects of static constructor calls.
     40 struct A {
     41     A();
     42 };
     43 
     44 A theA;
     45 
     46 // WEBASSEMBLY32: define internal void @__cxx_global_var_init() #0 section ".text.__startup" {
     47 // WEBASSEMBLY32: call %struct.A* @_ZN1AC1Ev(%struct.A* @theA)
     48 // WEBASSEMBLY32: define internal void @_GLOBAL__sub_I_static_init_wasm.cpp() #0 section ".text.__startup" {
     49 // WEBASSEMBLY32: call void @__cxx_global_var_init()
     50 //
     51 // WEBASSEMBLY64: define internal void @__cxx_global_var_init() #0 section ".text.__startup" {
     52 // WEBASSEMBLY64: call %struct.A* @_ZN1AC1Ev(%struct.A* @theA)
     53 // WEBASSEMBLY64: define internal void @_GLOBAL__sub_I_static_init_wasm.cpp() #0 section ".text.__startup" {
     54 // WEBASSEMBLY64: call void @__cxx_global_var_init()
     55