xref: /llvm-project/clang/test/CodeGen/flexible-array-init.c (revision 6cf0b1b3da3e8662baf030a2d741e3becaaab2b0)
1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
2 
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] }
5 
6 struct { int x; int y[]; } b = { 1, { 13, 15 } };
7 // CHECK: @b ={{.*}} global { i32, [2 x i32] } { i32 1, [2 x i32] [i32 13, i32 15] }
8 
9 // sizeof(c) == 8, so this global should be at least 8 bytes.
10 struct { int x; char c; char y[]; } c = { 1, 2, { 13, 15 } };
11 // CHECK: @c ={{.*}} global { i32, i8, [2 x i8] } { i32 1, i8 2, [2 x i8] c"\0D\0F" }
12 
13 // sizeof(d) == 8, so this global should be at least 8 bytes.
14 struct __attribute((packed, aligned(4))) { char a; int x; char z[]; } d = { 1, 2, { 13, 15 } };
15 // CHECK: @d ={{.*}} <{ i8, i32, [2 x i8], i8 }> <{ i8 1, i32 2, [2 x i8] c"\0D\0F", i8 undef }>,
16 
17 // This global needs 9 bytes to hold all the flexible array members.
18 struct __attribute((packed, aligned(4))) { char a; int x; char z[]; } e = { 1, 2, { 13, 15, 17, 19 } };
19 // CHECK: @e ={{.*}} <{ i8, i32, [4 x i8] }> <{ i8 1, i32 2, [4 x i8] c"\0D\0F\11\13" }>
20 
21 // FIXME: This global should be 6 bytes, not 8.  Not likely to matter in most
22 // cases, but still a bug.
23 struct { int x; char y[]; } f = { 1, { 13, 15 } };
24 // CHECK: @f ={{.*}} global { i32, [2 x i8] } { i32 1, [2 x i8] c"\0D\0F" }
25