xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++1y %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc struct A {
4f4a2713aSLionel Sambuc   int n = 0;
5f4a2713aSLionel Sambuc   const char *p;
6f4a2713aSLionel Sambuc   char k = p[n];
7f4a2713aSLionel Sambuc   int f();
8f4a2713aSLionel Sambuc   int x = f();
9f4a2713aSLionel Sambuc   union {
10f4a2713aSLionel Sambuc     char c;
11f4a2713aSLionel Sambuc     double d = 1.0;
12f4a2713aSLionel Sambuc   };
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc int f();
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc union B {
18f4a2713aSLionel Sambuc   int a;
19f4a2713aSLionel Sambuc   int f();
20f4a2713aSLionel Sambuc   int b = f();
21f4a2713aSLionel Sambuc };
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc A a { .p = "foobar" };
24f4a2713aSLionel Sambuc A b { 4, "bazquux", .x = 42, .c = 9 };
25f4a2713aSLionel Sambuc A c { 1, 0, 'A', f(), { 3 } };
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc // CHECK: @[[STR_A:.*]] = {{.*}} [7 x i8] c"foobar\00"
28f4a2713aSLionel Sambuc // CHECK: @a = global {{.*}} zeroinitializer
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc // @b has a constant initializer
31f4a2713aSLionel Sambuc // CHECK: @[[STR_B:.*]] = {{.*}} [8 x i8] c"bazquux\00"
32f4a2713aSLionel Sambuc // CHECK: @b = global {{.*}} i32 4, {{.*}} @[[STR_B]], {{.*}} i8 117, i32 42, {{.*}} i8 9
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc B x;
35f4a2713aSLionel Sambuc B y {};
36f4a2713aSLionel Sambuc B z { 1 };
37f4a2713aSLionel Sambuc // CHECK: @z = global {{.*}} { i32 1 }
38f4a2713aSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc // Brace initialization should initialize the first field even though it is
40*0a6a1f1dSLionel Sambuc // unnamed.
41*0a6a1f1dSLionel Sambuc union C {
42*0a6a1f1dSLionel Sambuc   struct {
43*0a6a1f1dSLionel Sambuc     int C::*memptr;
44*0a6a1f1dSLionel Sambuc   };
45*0a6a1f1dSLionel Sambuc };
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc C n{};
48*0a6a1f1dSLionel Sambuc // CHECK: @n = global %union.C { %struct.anon { i64 -1 } }, align 8
49*0a6a1f1dSLionel Sambuc 
50f4a2713aSLionel Sambuc // Initialization of 'a':
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc // CHECK: store i32 0, i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
53f4a2713aSLionel Sambuc // CHECK: store i8* {{.*}} @[[STR_A]]{{.*}}, i8** getelementptr inbounds ({{.*}} @a, i32 0, i32 1)
54f4a2713aSLionel Sambuc // CHECK: load i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
55f4a2713aSLionel Sambuc // CHECK: load i8** getelementptr inbounds ({{.*}} @a, i32 0, i32 1)
56f4a2713aSLionel Sambuc // CHECK: getelementptr inbounds i8* %{{.*}}, {{.*}} %{{.*}}
57f4a2713aSLionel Sambuc // CHECK: store i8 %{{.*}}, i8* getelementptr inbounds ({{.*}} @a, i32 0, i32 2)
58f4a2713aSLionel Sambuc // CHECK: call i32 @_ZN1A1fEv({{.*}} @a)
59f4a2713aSLionel Sambuc // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}}* @a, i32 0, i32 3)
60*0a6a1f1dSLionel Sambuc // CHECK: store double 1.000000e+00, double* getelementptr inbounds ({{.*}} @a, i32 0, i32 4, i32 0)
61f4a2713aSLionel Sambuc 
62f4a2713aSLionel Sambuc // No dynamic initialization of 'b':
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc // CHECK-NOT: @b
65f4a2713aSLionel Sambuc 
66f4a2713aSLionel Sambuc // Initialization of 'c':
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc // CHECK: store i32 1, i32* getelementptr inbounds ({{.*}} @c, i32 0, i32 0)
69f4a2713aSLionel Sambuc // CHECK: store i8* null, i8** getelementptr inbounds ({{.*}} @c, i32 0, i32 1)
70f4a2713aSLionel Sambuc // CHECK-NOT: load
71f4a2713aSLionel Sambuc // CHECK: store i8 65, i8* getelementptr inbounds ({{.*}} @c, i32 0, i32 2)
72f4a2713aSLionel Sambuc // CHECK: call i32 @_Z1fv()
73f4a2713aSLionel Sambuc // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}}* @c, i32 0, i32 3)
74f4a2713aSLionel Sambuc // CHECK-NOT: C1Ev
75f4a2713aSLionel Sambuc // CHECK: store i8 3, i8* {{.*}} @c, i32 0, i32 4)
76f4a2713aSLionel Sambuc 
77f4a2713aSLionel Sambuc // CHECK: call void @_ZN1BC1Ev({{.*}} @x)
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc // CHECK: call i32 @_ZN1B1fEv({{.*}} @y)
80f4a2713aSLionel Sambuc // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}} @y, i32 0, i32 0)
81