blob: 16763d53172c3cfac23b27eb7e91c8eb1bb41751 [file] [log] [blame]
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +00001// 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
Timur Iskhodzhanov85607912012-04-20 08:05:00 +00006
7class A {
8 public:
9 A() { }
10 ~A() { }
11};
12
Timur Iskhodzhanov6c9dccd2013-02-12 13:22:47 +000013void no_constructor_destructor_infinite_recursion() {
Timur Iskhodzhanov85607912012-04-20 08:05:00 +000014 A a;
15
John McCallbd315742012-09-25 08:00:39 +000016// CHECK: define linkonce_odr x86_thiscallcc %class.A* @"\01??0A@@QAE@XZ"(%class.A* %this)
NAKAMURA Takumi0e33dcd2012-09-25 09:53:18 +000017// 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]]
John McCallbd315742012-09-25 08:00:39 +000021// CHECK-NEXT: }
Timur Iskhodzhanov85607912012-04-20 08:05:00 +000022
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}
John McCallbd315742012-09-25 08:00:39 +000028
Timur Iskhodzhanov649c7312013-01-21 13:02:41 +000029struct B {
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000030 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 }
Timur Iskhodzhanov649c7312013-01-21 13:02:41 +000045 virtual void foo();
46};
47
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000048// Emits the vftable in the output.
49void B::foo() {}
50
Timur Iskhodzhanov649c7312013-01-21 13:02:41 +000051void 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}
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000057
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; }