blob: 0b483296b4cb68db0e5a51923e6a92fea6a8c15a [file] [log] [blame]
Richard Smith5745feb2019-06-17 21:08:30 +00001// RUN: %clang_cc1 -std=c++98 -emit-llvm -o - %s -triple x86_64-linux-gnu | FileCheck %s
2// RUN: %clang_cc1 -std=c++11 -emit-llvm -o - %s -triple x86_64-linux-gnu | FileCheck %s
3
4struct A { int x, y[3]; };
5struct B { A a; };
6
Fangrui Songdbc96b52020-02-03 10:09:39 -08007// CHECK: @b = global %{{[^ ]*}} { %{{[^ ]*}} { i32 1, [3 x i32] [i32 2, i32 5, i32 4] } }
Richard Smith5745feb2019-06-17 21:08:30 +00008B b = {(A){1, 2, 3, 4}, .a.y[1] = 5};
9
10union U {
11 int n;
12 float f;
13};
14struct C {
15 int x;
16 U u[3];
17};
18struct D {
19 C c;
20};
21
22// CHECK: @d1 = {{.*}} { i32 1, [3 x %[[U:.*]]] [%[[U]] { i32 2 }, %[[U]] { i32 5 }, %[[U]] { i32 4 }] }
23D d1 = {(C){1, {{.n=2}, {.f=3}, {.n=4}}}, .c.u[1].n = 5};
24
25// CHECK: @d2 = {{.*}} { i32 1, { %[[U]], float, %[[U]] } { %[[U]] { i32 2 }, float 5.{{0*}}e+00, %[[U]] { i32 4 } } }
26D d2 = {(C){1, 2, 3, 4}, .c.u[1].f = 5};
27
28struct Bitfield {
29 int a : 3;
30 int b : 4;
31 int c : 5;
32};
33struct WithBitfield {
34 int n;
35 Bitfield b;
36};
37// CHECK: @bitfield = {{.*}} { i32 1, { i8, i8, [2 x i8] } { i8 42, i8 2, [2 x i8] undef } }
38WithBitfield bitfield = {1, (Bitfield){2, 3, 4}, .b.b = 5};
39
40struct String {
41 const char buffer[12];
42};
43struct WithString {
44 String str;
45};
46// CHECK: @string = {{.*}} [12 x i8] c"Hello World\00" } }
47WithString string = {(String){"hello world"}, .str.buffer[0] = 'H', .str.buffer[6] = 'W'};
48
49struct LargeArray {
50 int arr[4096];
51};
52struct WithLargeArray {
53 LargeArray arr;
54};
Fangrui Songdbc96b52020-02-03 10:09:39 -080055// CHECK: @large = global { { <{ [11 x i32], [4085 x i32] }> } } { { <{ [11 x i32], [4085 x i32] }> } { <{ [11 x i32], [4085 x i32] }> <{ [11 x i32] [i32 1, i32 2, i32 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10], [4085 x i32] zeroinitializer }> } }
Richard Smith5745feb2019-06-17 21:08:30 +000056WithLargeArray large = {(LargeArray){1, 2, 3}, .arr.arr[10] = 10};
57
58union OverwritePaddingWithBitfield {
59 struct Padding { unsigned : 8; char c; } padding;
60 char bitfield : 3;
61};
62struct WithOverwritePaddingWithBitfield {
63 OverwritePaddingWithBitfield a;
64};
Fangrui Songdbc96b52020-02-03 10:09:39 -080065// CHECK: @overwrite_padding = global { { i8, i8 } } { { i8, i8 } { i8 3, i8 1 } }
Richard Smith5745feb2019-06-17 21:08:30 +000066WithOverwritePaddingWithBitfield overwrite_padding = {(OverwritePaddingWithBitfield){1}, .a.bitfield = 3};