[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / flexible-array-init.c
blob17b520fe83094298b0075e555b61d96b2efe6b19
1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
3 struct { int x; int y[]; } a = { 1, 7, 11 };
4 // CHECK: @a ={{.*}} global { i32, [2 x i32] } { i32 1, [2 x i32] [i32 7, i32 11] }
6 struct { int y[]; } a1 = { 8, 12 };
7 // CHECK: @a1 ={{.*}} global { [2 x i32] } { [2 x i32] [i32 8, i32 12] }
9 struct { int x; int y[]; } b = { 1, { 13, 15 } };
10 // CHECK: @b ={{.*}} global { i32, [2 x i32] } { i32 1, [2 x i32] [i32 13, i32 15] }
12 struct { int y[]; } b1 = { { 14, 16 } };
13 // CHECK: @b1 ={{.*}} global { [2 x i32] } { [2 x i32] [i32 14, i32 16] }
15 // sizeof(c) == 8, so this global should be at least 8 bytes.
16 struct { int x; char c; char y[]; } c = { 1, 2, { 13, 15 } };
17 // CHECK: @c ={{.*}} global { i32, i8, [2 x i8], i8 } { i32 1, i8 2, [2 x i8] c"\0D\0F", i8 0 }
19 // sizeof(d) == 8, so this global should be at least 8 bytes.
20 struct __attribute((packed, aligned(4))) { char a; int x; char z[]; } d = { 1, 2, { 13, 15 } };
21 // CHECK: @d ={{.*}} <{ i8, i32, [2 x i8], i8 }> <{ i8 1, i32 2, [2 x i8] c"\0D\0F", i8 0 }>,
23 // This global needs 9 bytes to hold all the flexible array members.
24 struct __attribute((packed, aligned(4))) { char a; int x; char z[]; } e = { 1, 2, { 13, 15, 17, 19 } };
25 // CHECK: @e ={{.*}} <{ i8, i32, [4 x i8] }> <{ i8 1, i32 2, [4 x i8] c"\0D\0F\11\13" }>
27 struct { int x; char y[]; } f = { 1, { 13, 15 } };
28 // CHECK: @f ={{.*}} global <{ i32, [2 x i8] }> <{ i32 1, [2 x i8] c"\0D\0F" }>
30 struct __attribute((packed)) { short a; char z[]; } g = { 2, { 11, 13, 15 } };
31 // CHECK: @g ={{.*}} <{ i16, [3 x i8] }> <{ i16 2, [3 x i8] c"\0B\0D\0F" }>,
33 // Last member is the potential flexible array, unnamed initializer skips it.
34 struct { int a; union { int b; short x; }; int c; int d; } h = {1, 2, {}, 3};
35 // CHECK: @h = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, i32 3 }
36 struct { int a; union { int b; short x[0]; }; int c; int d; } h0 = {1, 2, {}, 3};
37 // CHECK: @h0 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, i32 3 }
38 struct { int a; union { int b; short x[1]; }; int c; int d; } h1 = {1, 2, {}, 3};
39 // CHECK: @h1 = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, i32 3 }
40 struct {
41 int a;
42 union {
43 int b;
44 struct {
45 struct { } __ununsed;
46 short x[];
49 int c;
50 int d;
51 } hiding = {1, 2, {}, 3};
52 // CHECK: @hiding = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, i32 3 }
53 struct { int a; union { int b; short x[]; }; int c; int d; } hf = {1, 2, {}, 3};
54 // CHECK: @hf = global %struct.anon{{.*}} { i32 1, %union.anon{{.*}} { i32 2 }, i32 0, i32 3 }
56 // First member is the potential flexible array, initialization requires braces.
57 struct { int a; union { short x; int b; }; int c; int d; } i = {1, 2, {}, 3};
58 // CHECK: @i = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 x i8] } { i16 2, [2 x i8] zeroinitializer }, i32 0, i32 3 }
59 struct { int a; union { short x[0]; int b; }; int c; int d; } i0 = {1, {}, 2, 3};
60 // CHECK: @i0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { [0 x i16], [4 x i8] } zeroinitializer, i32 2, i32 3 }
61 struct { int a; union { short x[1]; int b; }; int c; int d; } i1 = {1, {2}, {}, 3};
62 // CHECK: @i1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { [1 x i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] zeroinitializer }, i32 0, i32 3 }
63 struct { int a; union { short x[]; int b; }; int c; int d; } i_f = {4, {}, {}, 6};
64 // CHECK: @i_f = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 4, { [0 x i16], [4 x i8] } zeroinitializer, i32 0, i32 6 }
66 // Named initializers; order doesn't matter.
67 struct { int a; union { int b; short x; }; int c; int d; } hn = {.a = 1, .x = 2, .c = 3};
68 // CHECK: @hn = global { i32, { i16, [2 x i8] }, i32, i32 } { i32 1, { i16, [2 x i8] } { i16 2, [2 x i8] zeroinitializer }, i32 3, i32 0 }
69 struct { int a; union { int b; short x[0]; }; int c; int d; } hn0 = {.a = 1, .x = {2}, .c = 3};
70 // CHECK: @hn0 = global { i32, { [0 x i16], [4 x i8] }, i32, i32 } { i32 1, { [0 x i16], [4 x i8] } zeroinitializer, i32 3, i32 0 }
71 struct { int a; union { int b; short x[1]; }; int c; int d; } hn1 = {.a = 1, .x = {2}, .c = 3};
72 // CHECK: @hn1 = global { i32, { [1 x i16], [2 x i8] }, i32, i32 } { i32 1, { [1 x i16], [2 x i8] } { [1 x i16] [i16 2], [2 x i8] zeroinitializer }, i32 3, i32 0 }
74 struct { char a[]; } empty_struct = {};
75 // CHECK: @empty_struct ={{.*}} global %struct.anon{{.*}} zeroinitializer, align 1
77 struct { char a[]; } empty_struct0 = {0};
78 // CHECK: @empty_struct0 = global { [1 x i8] } zeroinitializer, align 1
80 union { struct { int a; char b[]; }; } struct_in_union = {};
81 // CHECK: @struct_in_union = global %union.anon{{.*}} zeroinitializer, align 4
83 union { struct { int a; char b[]; }; } struct_in_union0 = {0};
84 // CHECK: @struct_in_union0 = global %union.anon{{.*}} zeroinitializer, align 4
86 union { int a; char b[]; } trailing_in_union = {};
87 // CHECK: @trailing_in_union = global %union.anon{{.*}} zeroinitializer, align 4
89 union { int a; char b[]; } trailing_in_union0 = {0};
90 // CHECK: @trailing_in_union0 = global %union.anon{{.*}} zeroinitializer, align 4
92 union { char a[]; } only_in_union = {};
93 // CHECK: @only_in_union = global %union.anon{{.*}} zeroinitializer, align 1
95 union { char a[]; } only_in_union0 = {0};
96 // CHECK: @only_in_union0 = global { [1 x i8] } zeroinitializer, align 1
98 union { char a[]; int b; } first_in_union = {};
99 // CHECK: @first_in_union = global { [0 x i8], [4 x i8] } zeroinitializer, align 4
101 union { char a[]; int b; } first_in_union0 = {0};
102 // CHECK: @first_in_union0 = global { [1 x i8], [3 x i8] } zeroinitializer, align 4
104 union { char a[]; int b; } first_in_union123 = { {1, 2, 3} };
105 // CHECK: @first_in_union123 = global { [3 x i8], i8 } { [3 x i8] c"\01\02\03", i8 0 }, align 4