|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --input-file=%t.cir %s |
| 3 | + |
| 4 | +// Pure virtual functions are allowed to be defined, but the vtable should still |
| 5 | +// point to __cxa_pure_virtual instead of the definition. For destructors, the |
| 6 | +// base object destructor (which is not included in the vtable) should be |
| 7 | +// defined as usual. The complete object destructors and deleting destructors |
| 8 | +// should contain a trap, and the vtable entries for them should point to |
| 9 | +// __cxa_pure_virtual. |
| 10 | +class C { |
| 11 | + C(); |
| 12 | + virtual ~C() = 0; |
| 13 | + virtual void pure() = 0; |
| 14 | +}; |
| 15 | + |
| 16 | +C::C() = default; |
| 17 | +C::~C() = default; |
| 18 | +void C::pure() {} |
| 19 | + |
| 20 | +// CHECK: @_ZTV1C = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI1C> : !cir.ptr<!u8i> |
| 21 | +// complete object destructor (D1) |
| 22 | +// CHECK-SAME: #cir.global_view<@__cxa_pure_virtual> : !cir.ptr<!u8i>, |
| 23 | +// deleting destructor (D0) |
| 24 | +// CHECK-SAME: #cir.global_view<@__cxa_pure_virtual> : !cir.ptr<!u8i>, |
| 25 | +// C::pure |
| 26 | +// CHECK-SAME: #cir.global_view<@__cxa_pure_virtual> : !cir.ptr<!u8i>]> |
| 27 | + |
| 28 | +// The base object destructor should be emitted as normal. |
| 29 | +// CHECK-LABEL: cir.func @_ZN1CD2Ev(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { |
| 30 | +// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} |
| 31 | +// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> |
| 32 | +// CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> |
| 33 | +// CHECK-NEXT: cir.return |
| 34 | +// CHECK-NEXT: } |
| 35 | + |
| 36 | +// The complete object destructor should trap. |
| 37 | +// CHECK-LABEL: cir.func @_ZN1CD1Ev(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { |
| 38 | +// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} |
| 39 | +// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> |
| 40 | +// CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> |
| 41 | +// CHECK-NEXT: cir.trap |
| 42 | +// CHECK-NEXT: } |
| 43 | + |
| 44 | +// The deleting destructor should trap. |
| 45 | +// CHECK-LABEL: cir.func @_ZN1CD0Ev(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { |
| 46 | +// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} |
| 47 | +// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> |
| 48 | +// CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> |
| 49 | +// CHECK-NEXT: cir.trap |
| 50 | +// CHECK-NEXT: } |
| 51 | + |
| 52 | +// C::pure should be emitted as normal. |
| 53 | +// CHECK-LABEL: cir.func @_ZN1C4pureEv(%arg0: !cir.ptr<!ty_C> loc({{[^)]+}})) {{.*}} { |
| 54 | +// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>>, ["this", init] {alignment = 8 : i64} |
| 55 | +// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> |
| 56 | +// CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_C>>, !cir.ptr<!ty_C> |
| 57 | +// CHECK-NEXT: cir.return |
| 58 | +// CHECK-NEXT: } |
0 commit comments