|
| 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 --check-prefix=CIR |
| 3 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 | +// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM |
| 5 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 | +// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG |
| 7 | + |
| 8 | +struct Delegating { |
| 9 | + Delegating(); |
| 10 | + Delegating(int); |
| 11 | +}; |
| 12 | + |
| 13 | +// Check that the constructor being delegated to is called with the correct |
| 14 | +// arguments. |
| 15 | +Delegating::Delegating() : Delegating(0) {} |
| 16 | + |
| 17 | +// CIR: cir.func {{.*}} @_ZN10DelegatingC2Ev(%[[THIS_ARG:.*]]: !cir.ptr<!rec_Delegating> {{.*}}) |
| 18 | +// CIR: %[[THIS_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Delegating>, !cir.ptr<!cir.ptr<!rec_Delegating>>, ["this", init] |
| 19 | +// CIR: cir.store{{.*}} %[[THIS_ARG]], %[[THIS_ADDR]] |
| 20 | +// CIR: %[[THIS:.*]] = cir.load %[[THIS_ADDR]] |
| 21 | +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i |
| 22 | +// CIR: cir.call @_ZN10DelegatingC2Ei(%[[THIS]], %[[ZERO]]) : (!cir.ptr<!rec_Delegating>, !s32i) -> () |
| 23 | + |
| 24 | +// LLVM: define {{.*}} @_ZN10DelegatingC2Ev(ptr %[[THIS_ARG:.*]]) |
| 25 | +// LLVM: %[[THIS_ADDR:.*]] = alloca ptr |
| 26 | +// LLVM: store ptr %[[THIS_ARG]], ptr %[[THIS_ADDR]] |
| 27 | +// LLVM: %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]] |
| 28 | +// LLVM: call void @_ZN10DelegatingC2Ei(ptr %[[THIS]], i32 0) |
| 29 | + |
| 30 | +// OGCG: define {{.*}} @_ZN10DelegatingC2Ev(ptr {{.*}} %[[THIS_ARG:.*]]) |
| 31 | +// OGCG: %[[THIS_ADDR:.*]] = alloca ptr |
| 32 | +// OGCG: store ptr %[[THIS_ARG]], ptr %[[THIS_ADDR]] |
| 33 | +// OGCG: %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]] |
| 34 | +// OGCG: call void @_ZN10DelegatingC2Ei(ptr {{.*}} %[[THIS]], i32 {{.*}} 0) |
| 35 | + |
| 36 | +struct DelegatingWithZeroing { |
| 37 | + int i; |
| 38 | + DelegatingWithZeroing() = default; |
| 39 | + DelegatingWithZeroing(int); |
| 40 | +}; |
| 41 | + |
| 42 | +// Check that the delegating constructor performs zero-initialization here. |
| 43 | +// FIXME: we should either emit the trivial default constructor or remove the |
| 44 | +// call to it in a lowering pass. |
| 45 | +DelegatingWithZeroing::DelegatingWithZeroing(int) : DelegatingWithZeroing() {} |
| 46 | + |
| 47 | +// CIR: cir.func {{.*}} @_ZN21DelegatingWithZeroingC2Ei(%[[THIS_ARG:.*]]: !cir.ptr<!rec_DelegatingWithZeroing> {{.*}}, %[[I_ARG:.*]]: !s32i {{.*}}) |
| 48 | +// CIR: %[[THIS_ADDR:.*]] = cir.alloca !cir.ptr<!rec_DelegatingWithZeroing>, !cir.ptr<!cir.ptr<!rec_DelegatingWithZeroing>>, ["this", init] |
| 49 | +// CIR: %[[I_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["", init] |
| 50 | +// CIR: cir.store{{.*}} %[[THIS_ARG]], %[[THIS_ADDR]] |
| 51 | +// CIR: cir.store{{.*}} %[[I_ARG]], %[[I_ADDR]] |
| 52 | +// CIR: %[[THIS:.*]] = cir.load %[[THIS_ADDR]] |
| 53 | +// CIR: %[[ZERO:.*]] = cir.const #cir.zero : !rec_DelegatingWithZeroing |
| 54 | +// CIR: cir.store{{.*}} %[[ZERO]], %[[THIS]] : !rec_DelegatingWithZeroing, !cir.ptr<!rec_DelegatingWithZeroing> |
| 55 | + |
| 56 | +// LLVM: define {{.*}} void @_ZN21DelegatingWithZeroingC2Ei(ptr %[[THIS_ARG:.*]], i32 %[[I_ARG:.*]]) |
| 57 | +// LLVM: %[[THIS_ADDR:.*]] = alloca ptr |
| 58 | +// LLVM: %[[I_ADDR:.*]] = alloca i32 |
| 59 | +// LLVM: store ptr %[[THIS_ARG]], ptr %[[THIS_ADDR]] |
| 60 | +// LLVM: store i32 %[[I_ARG]], ptr %[[I_ADDR]] |
| 61 | +// LLVM: %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]] |
| 62 | +// LLVM: store %struct.DelegatingWithZeroing zeroinitializer, ptr %[[THIS]] |
| 63 | + |
| 64 | +// Note: OGCG elides the call to the default constructor. |
| 65 | + |
| 66 | +// OGCG: define {{.*}} void @_ZN21DelegatingWithZeroingC2Ei(ptr {{.*}} %[[THIS_ARG:.*]], i32 {{.*}} %[[I_ARG:.*]]) |
| 67 | +// OGCG: %[[THIS_ADDR:.*]] = alloca ptr |
| 68 | +// OGCG: %[[I_ADDR:.*]] = alloca i32 |
| 69 | +// OGCG: store ptr %[[THIS_ARG]], ptr %[[THIS_ADDR]] |
| 70 | +// OGCG: store i32 %[[I_ARG]], ptr %[[I_ADDR]] |
| 71 | +// OGCG: %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]] |
| 72 | +// OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[THIS]], i8 0, i64 4, i1 false) |
0 commit comments