1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc void f1() { 4*f4a2713aSLionel Sambuc // Scalars in braces. 5*f4a2713aSLionel Sambuc int a = { 1 }; 6*f4a2713aSLionel Sambuc } 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc void f2() { 9*f4a2713aSLionel Sambuc int a[2][2] = { { 1, 2 }, { 3, 4 } }; 10*f4a2713aSLionel Sambuc int b[3][3] = { { 1, 2 }, { 3, 4 } }; 11*f4a2713aSLionel Sambuc int *c[2] = { &a[1][1], &b[2][2] }; 12*f4a2713aSLionel Sambuc int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} }; 13*f4a2713aSLionel Sambuc int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} }; 14*f4a2713aSLionel Sambuc char ext[3][3] = {".Y",".U",".V"}; 15*f4a2713aSLionel Sambuc } 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc typedef void (* F)(void); 18*f4a2713aSLionel Sambuc extern void foo(void); 19*f4a2713aSLionel Sambuc struct S { F f; }; 20*f4a2713aSLionel Sambuc void f3() { 21*f4a2713aSLionel Sambuc struct S a[1] = { { foo } }; 22*f4a2713aSLionel Sambuc } 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc // Constants 25*f4a2713aSLionel Sambuc // CHECK: @g3 = constant i32 10 26*f4a2713aSLionel Sambuc // CHECK: @f4.g4 = internal constant i32 12 27*f4a2713aSLionel Sambuc const int g3 = 10; 28*f4a2713aSLionel Sambuc int f4() { 29*f4a2713aSLionel Sambuc static const int g4 = 12; 30*f4a2713aSLionel Sambuc return g4; 31*f4a2713aSLionel Sambuc } 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc // PR6537 34*f4a2713aSLionel Sambuc typedef union vec3 { 35*f4a2713aSLionel Sambuc struct { double x, y, z; }; 36*f4a2713aSLionel Sambuc double component[3]; 37*f4a2713aSLionel Sambuc } vec3; 38*f4a2713aSLionel Sambuc vec3 f5(vec3 value) { 39*f4a2713aSLionel Sambuc return (vec3) {{ 40*f4a2713aSLionel Sambuc .x = value.x 41*f4a2713aSLionel Sambuc }}; 42*f4a2713aSLionel Sambuc } 43*f4a2713aSLionel Sambuc 44*f4a2713aSLionel Sambuc // rdar://problem/8154689 45*f4a2713aSLionel Sambuc void f6() { 46*f4a2713aSLionel Sambuc int x; 47*f4a2713aSLionel Sambuc long ids[] = { (long) &x }; 48*f4a2713aSLionel Sambuc } 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc // CHECK: @test7 = global{{.*}}{ i32 0, [4 x i8] c"bar\00" } 54*f4a2713aSLionel Sambuc // PR8217 55*f4a2713aSLionel Sambuc struct a7 { 56*f4a2713aSLionel Sambuc int b; 57*f4a2713aSLionel Sambuc char v[]; 58*f4a2713aSLionel Sambuc }; 59*f4a2713aSLionel Sambuc 60*f4a2713aSLionel Sambuc struct a7 test7 = { .b = 0, .v = "bar" }; 61*f4a2713aSLionel Sambuc 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc // PR279 comment #3 64*f4a2713aSLionel Sambuc char test8(int X) { 65*f4a2713aSLionel Sambuc char str[100000] = "abc"; // tail should be memset. 66*f4a2713aSLionel Sambuc return str[X]; 67*f4a2713aSLionel Sambuc // CHECK: @test8( 68*f4a2713aSLionel Sambuc // CHECK: call void @llvm.memset 69*f4a2713aSLionel Sambuc // CHECK: store i8 97 70*f4a2713aSLionel Sambuc // CHECK: store i8 98 71*f4a2713aSLionel Sambuc // CHECK: store i8 99 72*f4a2713aSLionel Sambuc // CHECK-NOT: getelementptr 73*f4a2713aSLionel Sambuc // CHECK: load 74*f4a2713aSLionel Sambuc } 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc void bar(void*); 77*f4a2713aSLionel Sambuc 78*f4a2713aSLionel Sambuc // PR279 79*f4a2713aSLionel Sambuc int test9(int X) { 80*f4a2713aSLionel Sambuc int Arr[100] = { X }; // Should use memset 81*f4a2713aSLionel Sambuc bar(Arr); 82*f4a2713aSLionel Sambuc // CHECK: @test9 83*f4a2713aSLionel Sambuc // CHECK: call void @llvm.memset 84*f4a2713aSLionel Sambuc // CHECK-NOT: store i32 0 85*f4a2713aSLionel Sambuc // CHECK: call void @bar 86*f4a2713aSLionel Sambuc } 87*f4a2713aSLionel Sambuc 88*f4a2713aSLionel Sambuc struct a { 89*f4a2713aSLionel Sambuc int a, b, c, d, e, f, g, h, i, j, k, *p; 90*f4a2713aSLionel Sambuc }; 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc struct b { 93*f4a2713aSLionel Sambuc struct a a,b,c,d,e,f,g; 94*f4a2713aSLionel Sambuc }; 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc int test10(int X) { 97*f4a2713aSLionel Sambuc struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 }; 98*f4a2713aSLionel Sambuc bar(&S); 99*f4a2713aSLionel Sambuc 100*f4a2713aSLionel Sambuc // CHECK: @test10 101*f4a2713aSLionel Sambuc // CHECK: call void @llvm.memset 102*f4a2713aSLionel Sambuc // CHECK-NOT: store i32 0 103*f4a2713aSLionel Sambuc // CHECK: call void @bar 104*f4a2713aSLionel Sambuc } 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc 107*f4a2713aSLionel Sambuc // PR9257 108*f4a2713aSLionel Sambuc struct test11S { 109*f4a2713aSLionel Sambuc int A[10]; 110*f4a2713aSLionel Sambuc }; 111*f4a2713aSLionel Sambuc void test11(struct test11S *P) { 112*f4a2713aSLionel Sambuc *P = (struct test11S) { .A = { [0 ... 3] = 4 } }; 113*f4a2713aSLionel Sambuc // CHECK: @test11 114*f4a2713aSLionel Sambuc // CHECK: store i32 4 115*f4a2713aSLionel Sambuc // CHECK: store i32 4 116*f4a2713aSLionel Sambuc // CHECK: store i32 4 117*f4a2713aSLionel Sambuc // CHECK: store i32 4 118*f4a2713aSLionel Sambuc // CHECK: ret void 119*f4a2713aSLionel Sambuc } 120*f4a2713aSLionel Sambuc 121*f4a2713aSLionel Sambuc 122*f4a2713aSLionel Sambuc // Verify that we can convert a recursive struct with a memory that returns 123*f4a2713aSLionel Sambuc // an instance of the struct we're converting. 124*f4a2713aSLionel Sambuc struct test12 { 125*f4a2713aSLionel Sambuc struct test12 (*p)(void); 126*f4a2713aSLionel Sambuc } test12g; 127*f4a2713aSLionel Sambuc 128*f4a2713aSLionel Sambuc 129*f4a2713aSLionel Sambuc void test13(int x) { 130*f4a2713aSLionel Sambuc struct X { int a; int b : 10; int c; }; 131*f4a2713aSLionel Sambuc struct X y = {.c = x}; 132*f4a2713aSLionel Sambuc // CHECK: @test13 133*f4a2713aSLionel Sambuc // CHECK: and i16 {{.*}}, -1024 134*f4a2713aSLionel Sambuc } 135