1 // RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck %s 2 3 struct P1 { char x[6]; } g1 = { "foo" }; 4 struct LP1 { struct P1 p1; }; 5 6 struct P2 { int a, b, c; } g2 = { 1, 2, 3 }; 7 struct LP2 { struct P2 p2; }; 8 struct LP2P2 { struct P2 p1, p2; }; 9 union UP2 { struct P2 p2; }; 10 11 struct LP3 { struct P1 p1[2]; } g3 = { { "dog" }, { "cat" } }; 12 struct LLP3 { struct LP3 l3; }; 13 union ULP3 { struct LP3 l3; }; 14 15 // CHECK-LABEL: test1 16 void test1(void) 17 { 18 // CHECK: call void @llvm.memcpy{{.*}}%struct.P1, %struct.P1* @g1{{.*}}i64 6, i32 {{[0-9]}}, i1 false) 19 // CHECK: store i8 120, i8* % 20 21 struct LP1 l = { .p1 = g1, .p1.x[2] = 'x' }; 22 } 23 24 // CHECK-LABEL: test2 25 void test2(void) 26 { 27 // CHECK: call void @llvm.memcpy{{.*}}%struct.P1, %struct.P1* @g1{{.*}}i64 6, i32 {{[0-9]}}, i1 false) 28 // CHECK: store i8 114, i8* % 29 30 struct LP1 l = { .p1 = g1, .p1.x[1] = 'r' }; 31 } 32 33 // CHECK-LABEL: test3 34 void test3(void) 35 { 36 // CHECK: call void @llvm.memcpy{{.*}}%struct.P2* @g2{{.*}}i64 12, i32 {{[0-9]}}, i1 false) 37 // CHECK: store i32 10, i32* % 38 39 struct LP2 l = { .p2 = g2, .p2.b = 10 }; 40 } 41 42 // CHECK-LABEL: get235 43 struct P2 get235() 44 { 45 struct P2 p = { 2, 3, 5 }; 46 return p; 47 } 48 49 // CHECK-LABEL: get456789 50 struct LP2P2 get456789() 51 { 52 struct LP2P2 l = { { 4, 5, 6 }, { 7, 8, 9 } }; 53 return l; 54 } 55 56 // CHECK-LABEL: get123 57 union UP2 get123() 58 { 59 union UP2 u = { { 1, 2, 3 } }; 60 return u; 61 } 62 63 // CHECK-LABEL: test4 64 void test4(void) 65 { 66 // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get123() 67 // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9]+]] 68 // CHECK: [[TMP1:%[a-z0-9]+]] = bitcast {{.*}}[[TMP0]] 69 // CHECK: call void @llvm.memcpy{{.*}}[[TMP1]], i64 12, i32 {{[0-9]}}, i1 false) 70 // CHECK: store i32 100, i32* % 71 72 struct LUP2 { union UP2 up; } var = { get123(), .up.p2.a = 100 }; 73 } 74 75 // CHECK-LABEL: test5 76 void test5(void) 77 { 78 // .l3 = g3 79 // CHECK: call void @llvm.memcpy{{.*}}%struct.LP3, %struct.LP3* @g3{{.*}}i64 12, i32 {{[0-9]}}, i1 false) 80 81 // .l3.p1 = { [0] = g1 } implicitly sets [1] to zero 82 // CHECK: call void @llvm.memcpy{{.*}}%struct.P1, %struct.P1* @g1{{.*}}i64 6, i32 {{[0-9]}}, i1 false) 83 // CHECK: getelementptr{{.*}}%struct.P1, %struct.P1*{{.*}}i64 1 84 // CHECK: call void @llvm.memset{{.*}}i8 0, i64 6, i32 {{[0-9]}}, i1 false) 85 86 // .l3.p1[1].x[1] = 'x' 87 // CHECK: store i8 120, i8* % 88 89 struct LLP3 var = { .l3 = g3, .l3.p1 = { [0] = g1 }, .l3.p1[1].x[1] = 'x' }; 90 } 91 92 // CHECK-LABEL: test6 93 void test6(void) 94 { 95 // CHECK: [[LP:%[a-z0-9]+]] = getelementptr{{.*}}%struct.LLP2P2, %struct.LLP2P2*{{.*}}, i32 0, i32 0 96 // CHECK: call {{.*}}get456789(%struct.LP2P2* {{.*}}[[LP]]) 97 98 // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get235() 99 // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9]+]] 100 // CHECK: [[TMP1:%[a-z0-9]+]] = bitcast {{.*}}[[TMP0]] 101 // CHECK: call void @llvm.memcpy{{.*}}[[TMP1]], i64 12, i32 {{[0-9]}}, i1 false) 102 103 // CHECK: store i32 10, i32* % 104 105 struct LLP2P2 { struct LP2P2 lp; } var = { get456789(), 106 .lp.p1 = get235(), 107 .lp.p1.b = 10 }; 108 } 109