92 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir --check-prefix=CIR %s3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll --check-prefix=LLVM %s5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll --check-prefix=OGCG %s7 8struct A {9 A() = default;10 A(int); // This constructor triggers the null base class initialization.11};12 13struct B : A {14};15 16void test_empty_base_null_init() {17 B{};18}19 20// CIR: cir.func {{.*}} @_Z25test_empty_base_null_initv()21// CIR-NEXT: %[[B_ADDR:.*]] = cir.alloca !rec_B, !cir.ptr<!rec_B>, ["agg.tmp.ensured"]22// CIR-NEXT: %[[A_ADDR:.*]] = cir.base_class_addr %[[B_ADDR]] : !cir.ptr<!rec_B> nonnull [0] -> !cir.ptr<!rec_A>23 24// LLVM: define{{.*}} @_Z25test_empty_base_null_initv()25// LLVM-NEXT: %[[B:.*]] = alloca %struct.B26// LLVM-NEXT: ret void27 28// OGCG: define{{.*}} @_Z25test_empty_base_null_initv()29// OGCG-NEXT: entry:30// OGCG-NEXT: %[[B:.*]] = alloca %struct.B31// OGCG-NEXT: ret void32 33 34struct C {35 int c;36 C() = default;37 C(int); // This constructor triggers the null base class initialization.38};39 40struct D : C {41};42 43void test_non_empty_base_null_init() {44 D{};45}46 47// CIR: cir.func {{.*}} @_Z29test_non_empty_base_null_initv()48// CIR: %[[TMP:.*]] = cir.alloca !rec_D, !cir.ptr<!rec_D>, ["agg.tmp.ensured"]49// CIR: %[[BASE:.*]] = cir.base_class_addr %[[TMP]] : !cir.ptr<!rec_D> nonnull [0] -> !cir.ptr<!rec_C>50// CIR: %[[ZERO:.*]] = cir.const #cir.const_record<{#cir.int<0> : !s32i}> : !rec_C51// CIR: cir.store{{.*}} %[[ZERO]], %[[BASE]]52 53// LLVM: define{{.*}} void @_Z29test_non_empty_base_null_initv()54// LLVM: %[[TMP:.*]] = alloca %struct.D55// LLVM: store %struct.C zeroinitializer, ptr %[[TMP]]56 57// OGCG: define {{.*}} void @_Z29test_non_empty_base_null_initv()58// OGCG: %[[TMP:.*]] = alloca %struct.D59// OGCG: %[[BASE:.*]] = getelementptr inbounds i8, ptr %[[TMP]], i64 060// OGCG: call void @llvm.memset.p0.i64(ptr{{.*}} %[[BASE]], i8 0, i64 4, i1 false)61 62struct E {63 int e;64};65 66struct F : E {67 F() = default;68 F(int);69};70 71struct G : F {72};73 74void test_base_chain_null_init() {75 G{};76}77 78// CIR: cir.func {{.*}} @_Z25test_base_chain_null_initv()79// CIR: %[[TMP:.*]] = cir.alloca !rec_G, !cir.ptr<!rec_G>, ["agg.tmp.ensured"]80// CIR: %[[BASE:.*]] = cir.base_class_addr %[[TMP]] : !cir.ptr<!rec_G> nonnull [0] -> !cir.ptr<!rec_F>81// CIR: %[[ZERO:.*]] = cir.const #cir.const_record<{#cir.zero : !rec_E}> : !rec_F82// CIR: cir.store{{.*}} %[[ZERO]], %[[BASE]]83 84// LLVM: define{{.*}} void @_Z25test_base_chain_null_initv()85// LLVM: %[[TMP:.*]] = alloca %struct.G86// LLVM: store %struct.F zeroinitializer, ptr %[[TMP]]87 88// OGCG: define {{.*}} void @_Z25test_base_chain_null_initv()89// OGCG: %[[TMP:.*]] = alloca %struct.G90// OGCG: %[[BASE:.*]] = getelementptr inbounds i8, ptr %[[TMP]], i64 091// OGCG: call void @llvm.memset.p0.i64(ptr{{.*}} %[[BASE]], i8 0, i64 4, i1 false)92