1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s 2 3 struct I { int k[3]; }; 4 struct M { struct I o[2]; }; 5 struct M v1[1] = { [0].o[0 ... 1].k[0 ... 1] = 4, 5 }; 6 unsigned v2[2][3] = {[0 ... 1][0 ... 1] = 2222, 3333}; 7 8 // CHECK-DAG: %struct.M = type { [2 x %struct.I] } 9 // CHECK-DAG: %struct.I = type { [3 x i32] } 10 11 // CHECK-DAG: [1 x %struct.M] [%struct.M { [2 x %struct.I] [%struct.I { [3 x i32] [i32 4, i32 4, i32 0] }, %struct.I { [3 x i32] [i32 4, i32 4, i32 5] }] }], 12 // CHECK-DAG: [2 x [3 x i32]] {{[[][[]}}3 x i32] [i32 2222, i32 2222, i32 0], [3 x i32] [i32 2222, i32 2222, i32 3333]], 13 // CHECK-DAG: [[INIT14:.*]] = private global [16 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 17, i32 17, i32 17, i32 17, i32 17, i32 17, i32 17, i32 0, i32 0, i32 0, i32 0], align 4 14 15 void f1() { 16 // Scalars in braces. 17 int a = { 1 }; 18 } 19 20 void f2() { 21 int a[2][2] = { { 1, 2 }, { 3, 4 } }; 22 int b[3][3] = { { 1, 2 }, { 3, 4 } }; 23 int *c[2] = { &a[1][1], &b[2][2] }; 24 int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} }; 25 int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} }; 26 char ext[3][3] = {".Y",".U",".V"}; 27 } 28 29 typedef void (* F)(void); 30 extern void foo(void); 31 struct S { F f; }; 32 void f3() { 33 struct S a[1] = { { foo } }; 34 } 35 36 // Constants 37 // CHECK-DAG: @g3 = constant i32 10 38 // CHECK-DAG: @f4.g4 = internal constant i32 12 39 const int g3 = 10; 40 int f4() { 41 static const int g4 = 12; 42 return g4; 43 } 44 45 // PR6537 46 typedef union vec3 { 47 struct { double x, y, z; }; 48 double component[3]; 49 } vec3; 50 vec3 f5(vec3 value) { 51 return (vec3) {{ 52 .x = value.x 53 }}; 54 } 55 56 // rdar://problem/8154689 57 void f6() { 58 int x; 59 long ids[] = { (long) &x }; 60 } 61 62 63 64 65 // CHECK-DAG: @test7 = global{{.*}}{ i32 0, [4 x i8] c"bar\00" } 66 // PR8217 67 struct a7 { 68 int b; 69 char v[]; 70 }; 71 72 struct a7 test7 = { .b = 0, .v = "bar" }; 73 74 75 // CHECK-DAG: @huge_array = global {{.*}} <{ i32 1, i32 0, i32 2, i32 0, i32 3, [999999995 x i32] zeroinitializer }> 76 int huge_array[1000000000] = {1, 0, 2, 0, 3, 0, 0, 0}; 77 78 // CHECK-DAG: @huge_struct = global {{.*}} { i32 1, <{ i32, [999999999 x i32] }> <{ i32 2, [999999999 x i32] zeroinitializer }> } 79 struct Huge { 80 int a; 81 int arr[1000 * 1000 * 1000]; 82 } huge_struct = {1, {2, 0, 0, 0}}; 83 84 85 // PR279 comment #3 86 char test8(int X) { 87 char str[100000] = "abc"; // tail should be memset. 88 return str[X]; 89 // CHECK: @test8( 90 // CHECK: call void @llvm.memset 91 // CHECK: store i8 97 92 // CHECK: store i8 98 93 // CHECK: store i8 99 94 // CHECK-NOT: getelementptr 95 // CHECK: load 96 } 97 98 void bar(void*); 99 100 // PR279 101 int test9(int X) { 102 int Arr[100] = { X }; // Should use memset 103 bar(Arr); 104 // CHECK: @test9 105 // CHECK: call void @llvm.memset 106 // CHECK-NOT: store i32 0 107 // CHECK: call void @bar 108 } 109 110 struct a { 111 int a, b, c, d, e, f, g, h, i, j, k, *p; 112 }; 113 114 struct b { 115 struct a a,b,c,d,e,f,g; 116 }; 117 118 int test10(int X) { 119 struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 }; 120 bar(&S); 121 122 // CHECK: @test10 123 // CHECK: call void @llvm.memset 124 // CHECK-NOT: store i32 0 125 // CHECK: call void @bar 126 } 127 128 129 // PR9257 130 struct test11S { 131 int A[10]; 132 }; 133 void test11(struct test11S *P) { 134 *P = (struct test11S) { .A = { [0 ... 3] = 4 } }; 135 // CHECK: @test11 136 // CHECK: store i32 4 137 // CHECK: store i32 4 138 // CHECK: store i32 4 139 // CHECK: store i32 4 140 // CHECK: ret void 141 } 142 143 144 // Verify that we can convert a recursive struct with a memory that returns 145 // an instance of the struct we're converting. 146 struct test12 { 147 struct test12 (*p)(void); 148 } test12g; 149 150 151 void test13(int x) { 152 struct X { int a; int b : 10; int c; }; 153 struct X y = {.c = x}; 154 // CHECK: @test13 155 // CHECK: and i16 {{.*}}, -1024 156 } 157 158 // CHECK-LABEL: @PR20473 159 void PR20473() { 160 // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @ 161 bar((char[2]) {""}); 162 // CHECK: memcpy{{.*}}getelementptr inbounds ([3 x i8], [3 x i8]* @ 163 bar((char[3]) {""}); 164 } 165 166 // Test that we initialize large member arrays by copying from a global and not 167 // with a series of stores. 168 struct S14 { int a[16]; }; 169 170 void test14(struct S14 *s14) { 171 // CHECK-LABEL: @test14 172 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false) 173 // CHECK-NOT: store 174 // CHECK: ret void 175 *s14 = (struct S14) { { [5 ... 11] = 17 } }; 176 } 177