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