Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux -emit-llvm -o - | FileCheck --check-prefix=X86 %s
      2 // RUN: %clang_cc1 %s -triple=wasm32 -emit-llvm -o - | FileCheck --check-prefix=WASM %s
      3 // RUN: %clang_cc1 %s -triple=armv7-apple-darwin9 -emit-llvm -o - | FileCheck --check-prefix=ARM %s
      4 
      5 // Test that destructors are not passed directly to __cxa_atexit when their
      6 // signatures do not match the type of its first argument.
      7 // e.g. ARM and WebAssembly have destructors that return this instead of void.
      8 
      9 
     10 class Foo {
     11  public:
     12   ~Foo() {
     13   }
     14 };
     15 
     16 Foo global;
     17 
     18 // X86 destructors have void return, and are registered directly with __cxa_atexit.
     19 // X86: define internal void @__cxx_global_var_init()
     20 // X86:   call i32 @__cxa_atexit(void (i8*)* bitcast (void (%class.Foo*)* @_ZN3FooD1Ev to void (i8*)*), i8* getelementptr inbounds (%class.Foo, %class.Foo* @global, i32 0, i32 0), i8* @__dso_handle)
     21 
     22 // ARM destructors return this, but can be registered directly with __cxa_atexit
     23 // because the calling conventions tolerate the mismatch.
     24 // ARM: define internal void @__cxx_global_var_init()
     25 // ARM:   call i32 @__cxa_atexit(void (i8*)* bitcast (%class.Foo* (%class.Foo*)* @_ZN3FooD1Ev to void (i8*)*), i8* getelementptr inbounds (%class.Foo, %class.Foo* @global, i32 0, i32 0), i8* @__dso_handle)
     26 
     27 // Wasm destructors return this, and use a wrapper function, which is registered
     28 // with __cxa_atexit.
     29 // WASM: define internal void @__cxx_global_var_init()
     30 // WASM: call i32 @__cxa_atexit(void (i8*)* @__cxx_global_array_dtor, i8* null, i8* @__dso_handle)
     31 
     32 // WASM: define internal void @__cxx_global_array_dtor(i8*)
     33 // WASM: %call = call %class.Foo* @_ZN3FooD1Ev(%class.Foo* @global)
     34