[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGen / designated-initializers.c
blobe630a6b4181516902731ff9e69c562b2c26dd34f
1 // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
3 struct foo {
4 void *a;
5 int b;
6 };
8 // CHECK: @u ={{.*}} global %union.anon zeroinitializer
9 union { int i; float f; } u = { };
11 // CHECK: @u2 ={{.*}} global { i32, [4 x i8] } { i32 0, [4 x i8] undef }
12 union { int i; double f; } u2 = { };
14 // CHECK: @u3 ={{.*}} global %union.anon.1 zeroinitializer
15 union { double f; int i; } u3 = { };
17 // CHECK: @b ={{.*}} global [2 x i32] [i32 0, i32 22]
18 int b[2] = {
19 [1] = 22
22 // PR6955
24 struct ds {
25 struct {
26 struct {
27 short a;
29 short b;
30 struct {
31 short c;
36 // Traditional C anonymous member init
37 struct ds ds0 = { { { .a = 0 } } };
38 // C1X lookup-based anonymous member init cases
39 struct ds ds1 = { { .a = 1 } };
40 struct ds ds2 = { { .b = 1 } };
41 struct ds ds3 = { .a = 0 };
42 // CHECK: @ds4 ={{.*}} global %struct.ds { %struct.anon.3 { %struct.anon zeroinitializer, i16 0, %struct.anon.2 { i16 1 } } }
43 struct ds ds4 = { .c = 1 };
44 struct ds ds5 = { { { .a = 0 } }, .b = 1 };
45 struct ds ds6 = { { .a = 0, .b = 1 } };
46 // CHECK: @ds7 ={{.*}} global %struct.ds { %struct.anon.3 { %struct.anon { i16 2 }, i16 3, %struct.anon.2 zeroinitializer } }
47 struct ds ds7 = {
48 { {
49 .a = 1
50 } },
51 .a = 2,
52 .b = 3
56 // <rdar://problem/10465114>
57 struct overwrite_string_struct1 {
58 __typeof(L"foo"[0]) L[6];
59 int M;
60 } overwrite_string1[] = { { { L"foo" }, 1 }, [0].L[2] = L'x'};
61 // CHECK: [6 x i32] [i32 102, i32 111, i32 120, i32 0, i32 0, i32 0], i32 1
62 struct overwrite_string_struct2 {
63 char L[6];
64 int M;
65 } overwrite_string2[] = { { { "foo" }, 1 }, [0].L[2] = 'x'};
66 // CHECK: [6 x i8] c"fox\00\00\00", i32 1
67 struct overwrite_string_struct3 {
68 char L[3];
69 int M;
70 } overwrite_string3[] = { { { "foo" }, 1 }, [0].L[2] = 'x'};
71 // CHECK: [3 x i8] c"fox", i32 1
72 struct overwrite_string_struct4 {
73 char L[3];
74 int M;
75 } overwrite_string4[] = { { { "foobar" }, 1 }, [0].L[2] = 'x'};
76 // CHECK: [3 x i8] c"fox", i32 1
77 struct overwrite_string_struct5 {
78 char L[6];
79 int M;
80 } overwrite_string5[] = { { { "foo" }, 1 }, [0].L[4] = 'y'};
81 // CHECK: [6 x i8] c"foo\00y\00", i32 1
84 // CHECK: @u1 = {{.*}} { i32 65535 }
85 union u_FFFF { char c; long l; } u1 = { .l = 0xFFFF };
88 /// PR16644
89 typedef union u_16644 {
90 struct s_16644 {
91 int zero;
92 int one;
93 int two;
94 int three;
95 } a;
96 int b[4];
97 } union_16644_t;
99 // CHECK: @union_16644_instance_0 = {{.*}} { i32 0, i32 0, i32 0, i32 3 } }
100 union_16644_t union_16644_instance_0 =
102 .b[0] = 0,
103 .a.one = 1,
104 .b[2] = 2,
105 .a.three = 3,
108 // CHECK: @union_16644_instance_1 = {{.*}} [i32 10, i32 0, i32 0, i32 0]
109 union_16644_t union_16644_instance_1 =
111 .a.three = 13,
112 .b[2] = 12,
113 .a.one = 11,
114 .b[0] = 10,
117 // CHECK: @union_16644_instance_2 = {{.*}} [i32 0, i32 20, i32 0, i32 0]
118 union_16644_t union_16644_instance_2 =
120 .a.one = 21,
121 .b[1] = 20,
124 // CHECK: @union_16644_instance_3 = {{.*}} { i32 0, i32 31, i32 0, i32 0 }
125 union_16644_t union_16644_instance_3 =
127 .b[1] = 30,
128 .a = {
129 .one = 31
133 // CHECK: @union_16644_instance_4 = {{.*}} { i32 5, i32 2, i32 0, i32 0 } {{.*}} [i32 0, i32 4, i32 0, i32 0]
134 union_16644_t union_16644_instance_4[2] =
136 [0].a.one = 2,
137 [1].a.zero = 3,
138 [0].a.zero = 5,
139 [1].b[1] = 4
142 // CHECK: @lab ={{.*}} global { [4 x i8], i32 } { [4 x i8] undef, i32 123 }
143 struct leading_anon_bitfield { int : 32; int n; } lab = { .n = 123 };
145 // rdar://45691981
146 struct Base {
147 struct {
148 int A;
151 struct Derived {
152 struct Base B;
154 struct Derived D = {{}, .B.A = 42};
155 // CHECK: @D ={{.*}} global %struct.Derived { %struct.Base { %struct.anon.4 { i32 42 } } }, align 4
157 void test1(int argc, char **argv)
159 // CHECK: internal global %struct.foo { ptr null, i32 1024 }
160 static struct foo foo = {
161 .b = 1024,
164 // CHECK: call void @llvm.memset
165 union { int i; float f; } u2 = { };
167 // CHECK-NOT: call void @llvm.memset
168 union { int i; float f; } u3;
170 // CHECK: ret void
174 // PR7151
175 struct S {
176 int nkeys;
177 int *keys;
178 union {
179 void *data;
183 void test2(void) {
184 struct S *btkr;
186 *btkr = (struct S) {
187 .keys = 0,
188 { .data = 0 },