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