1*67e74705SXin Li // RUN: %clang_cc1 -std=c++1z %s -triple x86_64-linux-gnu -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck %s 2*67e74705SXin Li 3*67e74705SXin Li namespace Constant { 4*67e74705SXin Li struct A { 5*67e74705SXin Li int n; 6*67e74705SXin Li char k; 7*67e74705SXin Li ~A(); 8*67e74705SXin Li }; 9*67e74705SXin Li 10*67e74705SXin Li struct B { 11*67e74705SXin Li char k2; 12*67e74705SXin Li }; 13*67e74705SXin Li 14*67e74705SXin Li struct C : B {}; 15*67e74705SXin Li 16*67e74705SXin Li struct D : A, C {}; 17*67e74705SXin Li 18*67e74705SXin Li C c1 = {}; 19*67e74705SXin Li C c2 = {1}; 20*67e74705SXin Li // CHECK: @_ZN8Constant2c1E = global { i8 } zeroinitializer, align 1 21*67e74705SXin Li // CHECK: @_ZN8Constant2c2E = global { i8 } { i8 1 }, align 1 22*67e74705SXin Li 23*67e74705SXin Li // Test packing bases into tail padding. 24*67e74705SXin Li D d1 = {}; 25*67e74705SXin Li D d2 = {1, 2, 3}; 26*67e74705SXin Li D d3 = {1}; 27*67e74705SXin Li // CHECK: @_ZN8Constant2d1E = global { i32, i8, i8 } zeroinitializer, align 4 28*67e74705SXin Li // CHECK: @_ZN8Constant2d2E = global { i32, i8, i8 } { i32 1, i8 2, i8 3 }, align 4 29*67e74705SXin Li // CHECK: @_ZN8Constant2d3E = global { i32, i8, i8 } { i32 1, i8 0, i8 0 }, align 4 30*67e74705SXin Li 31*67e74705SXin Li // CHECK-LABEL: define {{.*}}global_var_init 32*67e74705SXin Li // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN8Constant1DD1Ev {{.*}} @_ZN8Constant2d1E 33*67e74705SXin Li 34*67e74705SXin Li // CHECK-LABEL: define {{.*}}global_var_init 35*67e74705SXin Li // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN8Constant1DD1Ev {{.*}} @_ZN8Constant2d2E 36*67e74705SXin Li 37*67e74705SXin Li // CHECK-LABEL: define {{.*}}global_var_init 38*67e74705SXin Li // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN8Constant1DD1Ev {{.*}} @_ZN8Constant2d3E 39*67e74705SXin Li } 40*67e74705SXin Li 41*67e74705SXin Li namespace Dynamic { 42*67e74705SXin Li struct A { 43*67e74705SXin Li A(); 44*67e74705SXin Li A(int); 45*67e74705SXin Li A(const char*, unsigned); 46*67e74705SXin Li ~A(); 47*67e74705SXin Li void *p; 48*67e74705SXin Li }; 49*67e74705SXin Li 50*67e74705SXin Li struct B { 51*67e74705SXin Li ~B(); 52*67e74705SXin Li int n = 5; 53*67e74705SXin Li }; 54*67e74705SXin Li 55*67e74705SXin Li struct C { 56*67e74705SXin Li C(bool = true); 57*67e74705SXin Li }; 58*67e74705SXin Li 59*67e74705SXin Li int f(), g(), h(), i(); 60*67e74705SXin Li struct D : A, B, C { 61*67e74705SXin Li int n = f(); 62*67e74705SXin Li }; 63*67e74705SXin Li 64*67e74705SXin Li D d1 = {}; 65*67e74705SXin Li // CHECK-LABEL: define {{.*}}global_var_init 66*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1AC2Ev({{.*}} @_ZN7Dynamic2d1E 67*67e74705SXin Li // CHECK: store i32 5, {{.*}}i8* getelementptr inbounds {{.*}} @_ZN7Dynamic2d1E{{.*}}, i64 8 68*67e74705SXin Li // CHECK: invoke void @_ZN7Dynamic1CC2Eb({{.*}} @_ZN7Dynamic2d1E{{.*}}, i1 zeroext true) 69*67e74705SXin Li // CHECK: unwind label %[[UNWIND:.*]] 70*67e74705SXin Li // CHECK: invoke i32 @_ZN7Dynamic1fEv() 71*67e74705SXin Li // CHECK: unwind label %[[UNWIND:.*]] 72*67e74705SXin Li // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @_ZN7Dynamic2d1E, i32 0, i32 2 73*67e74705SXin Li // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN7Dynamic1DD1Ev {{.*}} @_ZN7Dynamic2d1E 74*67e74705SXin Li // CHECK: ret 75*67e74705SXin Li // 76*67e74705SXin Li // UNWIND: 77*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1BD1Ev({{.*}}i8* getelementptr inbounds {{.*}} @_ZN7Dynamic2d1E{{.*}}, i64 8 78*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1AD1Ev({{.*}} @_ZN7Dynamic2d1E 79*67e74705SXin Li 80*67e74705SXin Li D d2 = {1, 2, false}; 81*67e74705SXin Li // CHECK-LABEL: define {{.*}}global_var_init 82*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1AC1Ei({{.*}} @_ZN7Dynamic2d2E{{.*}}, i32 1) 83*67e74705SXin Li // CHECK: store i32 2, {{.*}}i8* getelementptr inbounds {{.*}}@_ZN7Dynamic2d2E{{.*}}, i64 8 84*67e74705SXin Li // CHECK: invoke void @_ZN7Dynamic1CC1Eb({{.*}} @_ZN7Dynamic2d2E{{.*}}, i1 zeroext false) 85*67e74705SXin Li // CHECK: invoke i32 @_ZN7Dynamic1fEv() 86*67e74705SXin Li // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @_ZN7Dynamic2d2E, i32 0, i32 2 87*67e74705SXin Li // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN7Dynamic1DD1Ev {{.*}} @_ZN7Dynamic2d2E 88*67e74705SXin Li // CHECK: ret void 89*67e74705SXin Li 90*67e74705SXin Li D d3 = {g(), h(), {}, i()}; 91*67e74705SXin Li // CHECK-LABEL: define {{.*}}global_var_init 92*67e74705SXin Li // CHECK: %[[G_CALL:.*]] = call i32 @_ZN7Dynamic1gEv() 93*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1AC1Ei({{.*}} @_ZN7Dynamic2d3E{{.*}}, i32 %[[G_CALL]]) 94*67e74705SXin Li // CHECK: %[[H_CALL:.*]] = invoke i32 @_ZN7Dynamic1hEv() 95*67e74705SXin Li // CHECK: unwind label %[[DESTROY_A_LPAD:.*]] 96*67e74705SXin Li // CHECK: store i32 %[[H_CALL]], {{.*}}i8* getelementptr inbounds {{.*}} @_ZN7Dynamic2d3E{{.*}}, i64 8 97*67e74705SXin Li // CHECK: invoke void @_ZN7Dynamic1CC2Eb({{.*}} @_ZN7Dynamic2d3E{{.*}}, i1 zeroext true) 98*67e74705SXin Li // CHECK: unwind label %[[DESTROY_AB_LPAD:.*]] 99*67e74705SXin Li // CHECK: %[[I_CALL:.*]] = invoke i32 @_ZN7Dynamic1iEv() 100*67e74705SXin Li // CHECK: unwind label %[[DESTROY_AB_LPAD:.*]] 101*67e74705SXin Li // CHECK: store i32 %[[I_CALL]], i32* getelementptr {{.*}} @_ZN7Dynamic2d3E, i32 0, i32 2 102*67e74705SXin Li // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN7Dynamic1DD1Ev {{.*}} @_ZN7Dynamic2d3E to i8* 103*67e74705SXin Li // CHECK: ret 104*67e74705SXin Li // 105*67e74705SXin Li // DESTROY_A_LPAD: 106*67e74705SXin Li // CHECK: br label %[[A_CLEANUP:.*]] 107*67e74705SXin Li // 108*67e74705SXin Li // DESTROY_B_LPAD: 109*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1BD1Ev({{.*}}i8* getelementptr inbounds {{.*}} @_ZN7Dynamic2d3E{{.*}}, i64 8 110*67e74705SXin Li // CHECK: br label %[[A_CLEANUP:.*]] 111*67e74705SXin Li // 112*67e74705SXin Li // A_CLEANUP: 113*67e74705SXin Li // CHECK: call void @_ZN7Dynamic1AD1Ev({{.*}} @_ZN7Dynamic2d3E 114*67e74705SXin Li } 115