Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 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 |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 6 | |
| 7 | class A { |
| 8 | public: |
| 9 | A() { } |
| 10 | ~A() { } |
| 11 | }; |
| 12 | |
Timur Iskhodzhanov | 6c9dccd | 2013-02-12 13:22:47 +0000 | [diff] [blame] | 13 | void no_constructor_destructor_infinite_recursion() { |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 14 | A a; |
| 15 | |
John McCall | bd31574 | 2012-09-25 08:00:39 +0000 | [diff] [blame] | 16 | // CHECK: define linkonce_odr x86_thiscallcc %class.A* @"\01??0A@@QAE@XZ"(%class.A* %this) |
NAKAMURA Takumi | 0e33dcd | 2012-09-25 09:53:18 +0000 | [diff] [blame] | 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]] |
John McCall | bd31574 | 2012-09-25 08:00:39 +0000 | [diff] [blame] | 21 | // CHECK-NEXT: } |
Timur Iskhodzhanov | 8560791 | 2012-04-20 08:05:00 +0000 | [diff] [blame] | 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 | } |
John McCall | bd31574 | 2012-09-25 08:00:39 +0000 | [diff] [blame] | 28 | |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 29 | struct B { |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 30 | virtual ~B() { |
| 31 | // Complete destructor first: |
| 32 | // DTORS: define {{.*}} x86_thiscallcc void @"\01??1B@@UAE@XZ"(%struct.B* %this) |
Timur Iskhodzhanov | 4745345 | 2013-02-13 12:14:25 +0000 | [diff] [blame^] | 33 | |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 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) |
Timur Iskhodzhanov | 4745345 | 2013-02-13 12:14:25 +0000 | [diff] [blame^] | 36 | // DTORS: %[[FROMBOOL:[0-9a-z]+]] = zext i1 %should_call_delete to i8 |
| 37 | // 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]] |
| 39 | // 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 Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 49 | // DTORS-NEXT: ret void |
| 50 | } |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 51 | virtual void foo(); |
| 52 | }; |
| 53 | |
Timur Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 54 | // Emits the vftable in the output. |
| 55 | void B::foo() {} |
| 56 | |
Timur Iskhodzhanov | 649c731 | 2013-01-21 13:02:41 +0000 | [diff] [blame] | 57 | void 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 Iskhodzhanov | 59660c2 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 63 | |
| 64 | // FIXME: Enable the following block and add expectations when calls |
| 65 | // to virtual complete dtor are supported. |
| 66 | #if 0 |
| 67 | void call_complete_dtor(B *obj_ptr) { |
| 68 | obj_ptr->~B(); |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | void 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 | |
| 77 | struct 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 | |
| 92 | void use_C() { C c; } |