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 // PR279 comment #3 76 char test8(int X) { 77 char str[100000] = "abc"; // tail should be memset. 78 return str[X]; 79 // CHECK: @test8( 80 // CHECK: call void @llvm.memset 81 // CHECK: store i8 97 82 // CHECK: store i8 98 83 // CHECK: store i8 99 84 // CHECK-NOT: getelementptr 85 // CHECK: load 86 } 87 88 void bar(void*); 89 90 // PR279 91 int test9(int X) { 92 int Arr[100] = { X }; // Should use memset 93 bar(Arr); 94 // CHECK: @test9 95 // CHECK: call void @llvm.memset 96 // CHECK-NOT: store i32 0 97 // CHECK: call void @bar 98 } 99 100 struct a { 101 int a, b, c, d, e, f, g, h, i, j, k, *p; 102 }; 103 104 struct b { 105 struct a a,b,c,d,e,f,g; 106 }; 107 108 int test10(int X) { 109 struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 }; 110 bar(&S); 111 112 // CHECK: @test10 113 // CHECK: call void @llvm.memset 114 // CHECK-NOT: store i32 0 115 // CHECK: call void @bar 116 } 117 118 119 // PR9257 120 struct test11S { 121 int A[10]; 122 }; 123 void test11(struct test11S *P) { 124 *P = (struct test11S) { .A = { [0 ... 3] = 4 } }; 125 // CHECK: @test11 126 // CHECK: store i32 4 127 // CHECK: store i32 4 128 // CHECK: store i32 4 129 // CHECK: store i32 4 130 // CHECK: ret void 131 } 132 133 134 // Verify that we can convert a recursive struct with a memory that returns 135 // an instance of the struct we're converting. 136 struct test12 { 137 struct test12 (*p)(void); 138 } test12g; 139 140 141 void test13(int x) { 142 struct X { int a; int b : 10; int c; }; 143 struct X y = {.c = x}; 144 // CHECK: @test13 145 // CHECK: and i16 {{.*}}, -1024 146 } 147 148 // CHECK-LABEL: @PR20473 149 void PR20473() { 150 // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @ 151 bar((char[2]) {""}); 152 // CHECK: memcpy{{.*}}getelementptr inbounds ([3 x i8], [3 x i8]* @ 153 bar((char[3]) {""}); 154 } 155 156 // Test that we initialize large member arrays by copying from a global and not 157 // with a series of stores. 158 struct S14 { int a[16]; }; 159 160 void test14(struct S14 *s14) { 161 // CHECK-LABEL: @test14 162 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT14]] {{.*}}, i32 64, i1 false) 163 // CHECK-NOT: store 164 // CHECK: ret void 165 *s14 = (struct S14) { { [5 ... 11] = 17 } }; 166 } 167