blob: 426233d8dfd3226b5d394c0c36092a292414d2b4 [file] [log] [blame]
Nuno Lopesa75b71f2010-04-18 19:06:43 +00001// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
Daniel Dunbare4c92382009-02-13 22:58:39 +00002
Lauro Ramos Venancio305762c2008-02-18 22:44:02 +00003void f1() {
4 // Scalars in braces.
5 int a = { 1 };
Lauro Ramos Venancio305762c2008-02-18 22:44:02 +00006}
7
8void f2() {
9 int a[2][2] = { { 1, 2 }, { 3, 4 } };
10 int b[3][3] = { { 1, 2 }, { 3, 4 } };
11 int *c[2] = { &a[1][1], &b[2][2] };
12 int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
13 int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
Lauro Ramos Venancio145cd892008-02-19 19:27:31 +000014 char ext[3][3] = {".Y",".U",".V"};
Anders Carlssona3881fc2008-01-29 01:28:48 +000015}
Chris Lattnerd3c38562008-05-04 00:56:25 +000016
17typedef void (* F)(void);
18extern void foo(void);
19struct S { F f; };
20void f3() {
21 struct S a[1] = { { foo } };
22}
23
Daniel Dunbare4c92382009-02-13 22:58:39 +000024// Constants
Nuno Lopesa75b71f2010-04-18 19:06:43 +000025// CHECK: @g3 = constant i32 10
26// CHECK: @f4.g4 = internal constant i32 12
Daniel Dunbare4c92382009-02-13 22:58:39 +000027const int g3 = 10;
28int f4() {
29 static const int g4 = 12;
30 return g4;
31}
Chris Lattnerb35baae2010-03-08 21:08:07 +000032
33// PR6537
34typedef union vec3 {
35 struct { double x, y, z; };
36 double component[3];
37} vec3;
38vec3 f5(vec3 value) {
39 return (vec3) {{
40 .x = value.x
41 }};
42}
John McCall0f2b6922010-07-07 05:08:32 +000043
44// rdar://problem/8154689
45void f6() {
46 int x;
47 long ids[] = { (long) &x };
48}
Chris Lattner9046c222010-10-10 17:49:49 +000049
50
51
52
53// CHECK: @test7 = global{{.*}}{ i32 0, [4 x i8] c"bar\00" }
54// PR8217
55struct a7 {
56 int b;
57 char v[];
58};
59
60struct a7 test7 = { .b = 0, .v = "bar" };
Chris Lattner70b02942010-12-02 01:58:41 +000061
62
63// PR279 comment #3
64char test8(int X) {
65 char str[100000] = "abc"; // tail should be memset.
66 return str[X];
67// CHECK: @test8(
68// CHECK: call void @llvm.memset
69// CHECK: store i8 97
70// CHECK: store i8 98
71// CHECK: store i8 99
72}
Chris Lattner1b726772010-12-02 07:07:26 +000073
74void bar(void*);
75
76// PR279
77int test9(int X) {
78 int Arr[100] = { X }; // Should use memset
79 bar(Arr);
80// CHECK: @test9
81// CHECK: call void @llvm.memset
82// CHECK-NOT: store i32 0
83// CHECK: call void @bar
84}
85
86struct a {
87 int a, b, c, d, e, f, g, h, i, j, k, *p;
88};
89
90struct b {
91 struct a a,b,c,d,e,f,g;
92};
93
94int test10(int X) {
95 struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
96 bar(&S);
97
98 // CHECK: @test10
99 // CHECK: call void @llvm.memset
100 // CHECK-NOT: store i32 0
101 // CHECK: call void @bar
102}
Chris Lattnere0fd8322011-02-19 22:28:58 +0000103
104
105// PR9257
106struct test11S {
107 int A[10];
108};
109void test11(struct test11S *P) {
110 *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
111 // CHECK: @test11
112 // CHECK: store i32 4
113 // CHECK: store i32 4
114 // CHECK: store i32 4
115 // CHECK: store i32 4
116 // CHECK: ret void
117}
Chris Lattnerf742eb02011-07-10 00:18:59 +0000118
119
120// Verify that we can convert a recursive struct with a memory that returns
121// an instance of the struct we're converting.
122struct test12 {
123 struct test12 (*p)(void);
124} test12g;
125
Eli Friedman5a13d4d2012-02-24 23:53:49 +0000126
127void test13(int x) {
128 struct X { int a; int b : 10; int c; };
129 struct X y = {.c = x};
130 // CHECK: @test13
131 // CHECK: and i32 {{.*}}, -1024
132}