microsoft-abi-structors.cpp revision 59660c21178b6af518bd4b564e032d5c9cc218cb
1// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 -fno-rtti > %t 2>&1 2// RUN: FileCheck %s < %t 3// Using a different check prefix as the inline destructors might be placed 4// anywhere in the output. 5// RUN: FileCheck --check-prefix=DTORS %s < %t 6 7class A { 8 public: 9 A() { } 10 ~A() { } 11}; 12 13void no_constructor_destructor_infinite_recursion() { 14 A a; 15 16// CHECK: define linkonce_odr x86_thiscallcc %class.A* @"\01??0A@@QAE@XZ"(%class.A* %this) 17// CHECK: [[THIS_ADDR:%[.0-9A-Z_a-z]+]] = alloca %class.A*, align 4 18// CHECK-NEXT: store %class.A* %this, %class.A** [[THIS_ADDR]], align 4 19// CHECK-NEXT: [[T1:%[.0-9A-Z_a-z]+]] = load %class.A** [[THIS_ADDR]] 20// CHECK-NEXT: ret %class.A* [[T1]] 21// CHECK-NEXT: } 22 23// Make sure that the destructor doesn't call itself: 24// CHECK: define {{.*}} @"\01??1A@@QAE@XZ" 25// CHECK-NOT: call void @"\01??1A@@QAE@XZ" 26// CHECK: ret 27} 28 29struct B { 30 virtual ~B() { 31// Complete destructor first: 32// DTORS: define {{.*}} x86_thiscallcc void @"\01??1B@@UAE@XZ"(%struct.B* %this) 33// 34// Then, the scalar deleting destructor (used in the vtable): 35// DTORS: define {{.*}} x86_thiscallcc void @"\01??_GB@@UAEPAXI@Z"(%struct.B* %this, i1 zeroext %should_call_delete) 36// DTORS: %0 = icmp eq i8 %should_call_delete{{.*}}, 0 37// DTORS-NEXT: br i1 %0, label %dtor.continue, label %dtor.call_delete 38// DTORS: dtor.call_delete: 39// DTORS-NEXT: %1 = bitcast %struct.B* %this1 to i8* 40// DTORS-NEXT: call void @"\01??3@YAXPAX@Z"(i8* %1) nounwind 41// DTORS-NEXT: br label %dtor.continue 42// DTORS: dtor.continue: 43// DTORS-NEXT: ret void 44 } 45 virtual void foo(); 46}; 47 48// Emits the vftable in the output. 49void B::foo() {} 50 51void check_vftable_offset() { 52 B b; 53// The vftable pointer should point at the beginning of the vftable. 54// CHECK: [[THIS_PTR:%[0-9]+]] = bitcast %struct.B* {{.*}} to i8*** 55// CHECK: store i8** getelementptr inbounds ([2 x i8*]* @"\01??_7B@@6B@", i64 0, i64 0), i8*** [[THIS_PTR]] 56} 57 58// FIXME: Enable the following block and add expectations when calls 59// to virtual complete dtor are supported. 60#if 0 61void call_complete_dtor(B *obj_ptr) { 62 obj_ptr->~B(); 63} 64#endif 65 66void call_deleting_dtor(B *obj_ptr) { 67// FIXME: Add CHECKs when calls to virtual deleting dtor are generated properly. 68 delete obj_ptr; 69} 70 71struct C { 72 static int foo(); 73 74 C() { 75 static int ctor_static = foo(); 76 // CHECK that the static in the ctor gets mangled correctly: 77 // CHECK: @"\01?ctor_static@?1???0C@@QAE@XZ@4HA" 78 } 79 ~C() { 80 static int dtor_static = foo(); 81 // CHECK that the static in the dtor gets mangled correctly: 82 // CHECK: @"\01?dtor_static@?1???1C@@QAE@XZ@4HA" 83 } 84}; 85 86void use_C() { C c; } 87