|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -fexceptions -fcxx-exceptions %s -o %t.cir |
| 2 | +// RUN: FileCheck --input-file=%t.cir %s |
| 3 | + |
| 4 | +struct Delegating { |
| 5 | + Delegating(); |
| 6 | + Delegating(int); |
| 7 | +}; |
| 8 | + |
| 9 | +// Check that the constructor being delegated to is called with the correct |
| 10 | +// arguments. |
| 11 | +Delegating::Delegating() : Delegating(0) {} |
| 12 | + |
| 13 | +// CHECK-LABEL: cir.func @_ZN10DelegatingC2Ev(%arg0: !cir.ptr<!ty_22Delegating22> {{.*}}) {{.*}} { |
| 14 | +// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22Delegating22>, !cir.ptr<!cir.ptr<!ty_22Delegating22>>, ["this", init] {alignment = 8 : i64} |
| 15 | +// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_22Delegating22>, !cir.ptr<!cir.ptr<!ty_22Delegating22>> |
| 16 | +// CHECK-NEXT: %1 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_22Delegating22>>, !cir.ptr<!ty_22Delegating22> |
| 17 | +// CHECK-NEXT: %2 = cir.const #cir.int<0> : !s32i |
| 18 | +// CHECK-NEXT: cir.call @_ZN10DelegatingC2Ei(%1, %2) : (!cir.ptr<!ty_22Delegating22>, !s32i) -> () |
| 19 | +// CHECK-NEXT: cir.return |
| 20 | +// CHECK-NEXT: } |
| 21 | + |
| 22 | +struct DelegatingWithZeroing { |
| 23 | + int i; |
| 24 | + DelegatingWithZeroing() = default; |
| 25 | + DelegatingWithZeroing(int); |
| 26 | +}; |
| 27 | + |
| 28 | +// Check that the delegating constructor performs zero-initialization here. |
| 29 | +// FIXME: we should either emit the trivial default constructor or remove the |
| 30 | +// call to it in a lowering pass. |
| 31 | +DelegatingWithZeroing::DelegatingWithZeroing(int) : DelegatingWithZeroing() {} |
| 32 | + |
| 33 | +// CHECK-LABEL: cir.func @_ZN21DelegatingWithZeroingC2Ei(%arg0: !cir.ptr<!ty_22DelegatingWithZeroing22> {{.*}}, %arg1: !s32i {{.*}}) {{.*}} { |
| 34 | +// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!ty_22DelegatingWithZeroing22>, !cir.ptr<!cir.ptr<!ty_22DelegatingWithZeroing22>>, ["this", init] {alignment = 8 : i64} |
| 35 | +// CHECK-NEXT: %1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["", init] {alignment = 4 : i64} |
| 36 | +// CHECK-NEXT: cir.store %arg0, %0 : !cir.ptr<!ty_22DelegatingWithZeroing22>, !cir.ptr<!cir.ptr<!ty_22DelegatingWithZeroing22>> |
| 37 | +// CHECK-NEXT: cir.store %arg1, %1 : !s32i, !cir.ptr<!s32i> |
| 38 | +// CHECK-NEXT: %2 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_22DelegatingWithZeroing22>>, !cir.ptr<!ty_22DelegatingWithZeroing22> |
| 39 | +// CHECK-NEXT: %3 = cir.const #cir.zero : !ty_22DelegatingWithZeroing22 |
| 40 | +// CHECK-NEXT: cir.store %3, %2 : !ty_22DelegatingWithZeroing22, !cir.ptr<!ty_22DelegatingWithZeroing22> |
| 41 | +// CHECK-NEXT: cir.call @_ZN21DelegatingWithZeroingC2Ev(%2) : (!cir.ptr<!ty_22DelegatingWithZeroing22>) -> () extra(#fn_attr1) |
| 42 | +// CHECK-NEXT: cir.return |
| 43 | +// CHECK-NEXT: } |
| 44 | + |
| 45 | +void canThrow(); |
| 46 | +struct HasNonTrivialDestructor { |
| 47 | + HasNonTrivialDestructor(); |
| 48 | + HasNonTrivialDestructor(int); |
| 49 | + ~HasNonTrivialDestructor(); |
| 50 | +}; |
| 51 | + |
| 52 | +// Check that we call the destructor whenever a cleanup is needed. |
| 53 | +// FIXME: enable and check this when exceptions are fully supported. |
| 54 | +#if 0 |
| 55 | +HasNonTrivialDestructor::HasNonTrivialDestructor(int) |
| 56 | + : HasNonTrivialDestructor() { |
| 57 | + canThrow(); |
| 58 | +} |
| 59 | +#endif |
| 60 | + |
| 61 | +// From clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp, check that virtual |
| 62 | +// inheritance and delegating constructors interact correctly. |
| 63 | +// FIXME: enable and check this when virtual inheritance is fully supported. |
| 64 | +#if 0 |
| 65 | +namespace PR14588 { |
| 66 | +void other(); |
| 67 | + |
| 68 | +class Base { |
| 69 | +public: |
| 70 | + Base() { squawk(); } |
| 71 | + virtual ~Base() {} |
| 72 | + |
| 73 | + virtual void squawk() { other(); } |
| 74 | +}; |
| 75 | + |
| 76 | +class Foo : public virtual Base { |
| 77 | +public: |
| 78 | + Foo(); |
| 79 | + Foo(const void *inVoid); |
| 80 | + virtual ~Foo() {} |
| 81 | + |
| 82 | + virtual void squawk() { other(); } |
| 83 | +}; |
| 84 | + |
| 85 | +Foo::Foo() : Foo(nullptr) { other(); } |
| 86 | +Foo::Foo(const void *inVoid) { squawk(); } |
| 87 | +} // namespace PR14588 |
| 88 | +#endif |
0 commit comments