blob: 34c09b85b1a33e1b2aef3a97ba8b4e00084d09d1 [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)
Timur Iskhodzhanov47453452013-02-13 12:14:25 +000033
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000034// 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)
Timur Iskhodzhanov47453452013-02-13 12:14:25 +000036// DTORS: %[[FROMBOOL:[0-9a-z]+]] = zext i1 %should_call_delete to i8
Timur Iskhodzhanovba8fa0c2013-02-13 12:24:19 +000037// DTORS-NEXT: store i8 %[[FROMBOOL]], i8* %[[SHOULD_DELETE_VAR:[0-9a-z._]+]], align 1
38// DTORS: %[[SHOULD_DELETE_VALUE:[0-9a-z._]+]] = load i8* %[[SHOULD_DELETE_VAR]]
Timur Iskhodzhanov47453452013-02-13 12:14:25 +000039// DTORS: call x86_thiscallcc void @"\01??1B@@UAE@XZ"(%struct.B* %[[THIS:[0-9a-z]+]])
40// DTORS-NEXT: %[[CONDITION:[0-9]+]] = icmp eq i8 %[[SHOULD_DELETE_VALUE]], 0
41// DTORS-NEXT: br i1 %[[CONDITION]], label %[[CONTINUE_LABEL:[0-9a-z._]+]], label %[[CALL_DELETE_LABEL:[0-9a-z._]+]]
42//
43// DTORS: [[CALL_DELETE_LABEL]]
44// DTORS-NEXT: %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %struct.B* %[[THIS]] to i8*
45// DTORS-NEXT: call void @"\01??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]]) nounwind
46// DTORS-NEXT: br label %[[CONTINUE_LABEL]]
47//
48// DTORS: [[CONTINUE_LABEL]]
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000049// DTORS-NEXT: ret void
50 }
Timur Iskhodzhanov649c7312013-01-21 13:02:41 +000051 virtual void foo();
52};
53
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000054// Emits the vftable in the output.
55void B::foo() {}
56
Timur Iskhodzhanov649c7312013-01-21 13:02:41 +000057void check_vftable_offset() {
58 B b;
59// The vftable pointer should point at the beginning of the vftable.
60// CHECK: [[THIS_PTR:%[0-9]+]] = bitcast %struct.B* {{.*}} to i8***
61// CHECK: store i8** getelementptr inbounds ([2 x i8*]* @"\01??_7B@@6B@", i64 0, i64 0), i8*** [[THIS_PTR]]
62}
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000063
64// FIXME: Enable the following block and add expectations when calls
65// to virtual complete dtor are supported.
66#if 0
67void call_complete_dtor(B *obj_ptr) {
68 obj_ptr->~B();
69}
70#endif
71
72void call_deleting_dtor(B *obj_ptr) {
73// FIXME: Add CHECKs when calls to virtual deleting dtor are generated properly.
74 delete obj_ptr;
75}
76
77struct C {
78 static int foo();
79
80 C() {
81 static int ctor_static = foo();
82 // CHECK that the static in the ctor gets mangled correctly:
83 // CHECK: @"\01?ctor_static@?1???0C@@QAE@XZ@4HA"
84 }
85 ~C() {
86 static int dtor_static = foo();
87 // CHECK that the static in the dtor gets mangled correctly:
88 // CHECK: @"\01?dtor_static@?1???1C@@QAE@XZ@4HA"
89 }
90};
91
92void use_C() { C c; }