1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
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};
8 // CHECK-DAG: %struct.M = type { [2 x %struct.I] }
9 // CHECK-DAG: %struct.I = type { [3 x i32] }
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 constant [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
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"};
29 typedef void (* F
)(void);
30 extern void foo(void);
33 struct S a
[1] = { { foo
} };
37 // CHECK-DAG: @g3 ={{.*}} constant i32 10
38 // CHECK-DAG: @f4.g4 = internal constant i32 12
41 static const int g4
= 12;
47 struct { double x
, y
, z
; };
58 long ids
[] = { (long) &x
};
64 // CHECK-DAG: @test7 ={{.*}} global{{.*}}{ i32 0, [4 x i8] c"bar\00" }
71 struct a7 test7
= { .b
= 0, .v
= "bar" };
74 // CHECK-DAG: @huge_array ={{.*}} global {{.*}} <{ i32 1, i32 0, i32 2, i32 0, i32 3, [999999995 x i32] zeroinitializer }>
75 int huge_array
[1000000000] = {1, 0, 2, 0, 3, 0, 0, 0};
77 // CHECK-DAG: @huge_struct ={{.*}} global {{.*}} { i32 1, <{ i32, [999999999 x i32] }> <{ i32 2, [999999999 x i32] zeroinitializer }> }
80 int arr
[1000 * 1000 * 1000];
81 } huge_struct
= {1, {2, 0, 0, 0}};
83 // CHECK-DAG: @large_array_with_zeroes ={{.*}} constant <{ [21 x i8], [979 x i8] }> <{ [21 x i8] c"abc\01\02\03xyzzy\00\00\00\00\00\00\00\00\00q", [979 x i8] zeroinitializer }>
84 const char large_array_with_zeroes
[1000] = {
85 'a', 'b', 'c', 1, 2, 3, 'x', 'y', 'z', 'z', 'y', [20] = 'q'
90 // CHECK-DAG: @large_array_with_zeroes_2 ={{.*}} global <{ [10 x ptr], [90 x ptr] }> <{ [10 x ptr] [ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr @global], [90 x ptr] zeroinitializer }>
91 const void *large_array_with_zeroes_2
[100] = {
94 // CHECK-DAG: @large_array_with_zeroes_3 ={{.*}} global <{ [10 x ptr], [990 x ptr] }> <{ [10 x ptr] [ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null, ptr @global], [990 x ptr] zeroinitializer }>
95 const void *large_array_with_zeroes_3
[1000] = {
101 char str
[100000] = "abc"; // tail should be memset.
103 // CHECK-LABEL: @test8(
104 // CHECK: call void @llvm.memset
105 // CHECK: store i8 97, ptr %{{[0-9]*}}, align 1
106 // CHECK: store i8 98, ptr %{{[0-9]*}}, align 1
107 // CHECK: store i8 99, ptr %{{[0-9]*}}, align 1
108 // CHECK-NOT: getelementptr
116 int Arr
[100] = { X
}; // Should use memset
118 // CHECK-LABEL: @test9(
119 // CHECK: call void @llvm.memset
120 // CHECK-NOT: store i32 0
121 // CHECK: call void @bar
125 int a
, b
, c
, d
, e
, f
, g
, h
, i
, j
, k
, *p
;
129 struct a a
,b
,c
,d
,e
,f
,g
;
133 struct b S
= { .a
.a
= X
, .d
.e
= X
, .f
.e
= 0, .f
.f
= 0, .f
.p
= 0 };
136 // CHECK-LABEL: @test10(
137 // CHECK: call void @llvm.memset
138 // CHECK-NOT: store i32 0
139 // CHECK: call void @bar
142 void nonzeroMemseti8(void) {
143 char arr
[33] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, };
144 // CHECK-LABEL: @nonzeroMemseti8(
147 // CHECK: call void @llvm.memset.p0.i32(ptr {{.*}}, i8 42, i32 33, i1 false)
150 void nonzeroMemseti16(void) {
151 unsigned short arr
[17] = { 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, 0x4242, };
152 // CHECK-LABEL: @nonzeroMemseti16(
155 // CHECK: call void @llvm.memset.p0.i32(ptr {{.*}}, i8 66, i32 34, i1 false)
158 void nonzeroMemseti32(void) {
159 unsigned arr
[9] = { 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, };
160 // CHECK-LABEL: @nonzeroMemseti32(
163 // CHECK: call void @llvm.memset.p0.i32(ptr {{.*}}, i8 -16, i32 36, i1 false)
166 void nonzeroMemseti64(void) {
167 unsigned long long arr
[7] = { 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, };
168 // CHECK-LABEL: @nonzeroMemseti64(
171 // CHECK: call void @llvm.memset.p0.i32(ptr {{.*}}, i8 -86, i32 56, i1 false)
174 void nonzeroMemsetf32(void) {
175 float arr
[9] = { 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, 0x1.cacacap
+75, };
176 // CHECK-LABEL: @nonzeroMemsetf32(
179 // CHECK: call void @llvm.memset.p0.i32(ptr {{.*}}, i8 101, i32 36, i1 false)
182 void nonzeroMemsetf64(void) {
183 double arr
[7] = { 0x1.4444444444444p
+69, 0x1.4444444444444p
+69, 0x1.4444444444444p
+69, 0x1.4444444444444p
+69, 0x1.4444444444444p
+69, 0x1.4444444444444p
+69, 0x1.4444444444444p
+69, };
184 // CHECK-LABEL: @nonzeroMemsetf64(
187 // CHECK: call void @llvm.memset.p0.i32(ptr {{.*}}, i8 68, i32 56, i1 false)
194 void test11(struct test11S
*P
) {
195 *P
= (struct test11S
) { .A
= { [0 ... 3] = 4 } };
196 // CHECK-LABEL: @test11(
197 // CHECK: store i32 4, ptr %{{.*}}, align 4
198 // CHECK: store i32 4, ptr %{{.*}}, align 4
199 // CHECK: store i32 4, ptr %{{.*}}, align 4
200 // CHECK: store i32 4, ptr %{{.*}}, align 4
205 // Verify that we can convert a recursive struct with a memory that returns
206 // an instance of the struct we're converting.
208 struct test12 (*p
)(void);
213 struct X
{ int a
; int b
: 10; int c
; };
214 struct X y
= {.c
= x
};
215 // CHECK-LABEL: @test13(
216 // CHECK: and i16 {{.*}}, -1024
219 // CHECK-LABEL: @PR20473(
221 // CHECK: memcpy{{.*}}
223 // CHECK: memcpy{{.*}}
227 // Test that we initialize large member arrays by copying from a global and not
228 // with a series of stores.
229 struct S14
{ int a
[16]; };
231 void test14(struct S14
*s14
) {
232 // CHECK-LABEL: @test14(
233 // CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 {{.*}}, ptr align 4 [[INIT14]], i32 64, i1 false)
236 *s14
= (struct S14
) { { [5 ... 11] = 17 } };