blob: 50629b590562b7909974c54ed52ea2acebe04cf6 [file] [log] [blame]
Richard Smithc3bf52c2013-04-20 22:23:05 +00001// RUN: %clang_cc1 -std=c++1y %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
2
3struct A {
4 int n = 0;
5 const char *p;
6 char k = p[n];
7 int f();
8 int x = f();
9 union {
10 char c;
11 double d = 1.0;
12 };
13};
14
15int f();
16
17union B {
18 int a;
19 int f();
20 int b = f();
21};
22
23A a { .p = "foobar" };
24A b { 4, "bazquux", .x = 42, .c = 9 };
25A c { 1, 0, 'A', f(), { 3 } };
26
27// CHECK: @[[STR_A:.*]] = {{.*}} [7 x i8] c"foobar\00"
Richard Smith6391ea22013-05-09 07:14:00 +000028// CHECK: @a = global {{.*}} zeroinitializer
29
30// @b has a constant initializer
Richard Smithc3bf52c2013-04-20 22:23:05 +000031// CHECK: @[[STR_B:.*]] = {{.*}} [8 x i8] c"bazquux\00"
Richard Smith6391ea22013-05-09 07:14:00 +000032// CHECK: @b = global {{.*}} i32 4, {{.*}} @[[STR_B]], {{.*}} i8 117, i32 42, {{.*}} i8 9
Richard Smithc3bf52c2013-04-20 22:23:05 +000033
34B x;
35B y {};
36B z { 1 };
37// CHECK: @z = global {{.*}} { i32 1 }
38
Stephen Hines176edba2014-12-01 14:53:08 -080039// Brace initialization should initialize the first field even though it is
40// unnamed.
41union C {
42 struct {
43 int C::*memptr;
44 };
45};
46
47C n{};
48// CHECK: @n = global %union.C { %struct.anon { i64 -1 } }, align 8
49
Richard Smithc3bf52c2013-04-20 22:23:05 +000050// Initialization of 'a':
51
52// CHECK: store i32 0, i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
53// CHECK: store i8* {{.*}} @[[STR_A]]{{.*}}, i8** getelementptr inbounds ({{.*}} @a, i32 0, i32 1)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070054// CHECK: load i32, i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
55// CHECK: load i8*, i8** getelementptr inbounds ({{.*}} @a, i32 0, i32 1)
56// CHECK: getelementptr inbounds i8, i8* %{{.*}}, {{.*}} %{{.*}}
Richard Smithc3bf52c2013-04-20 22:23:05 +000057// CHECK: store i8 %{{.*}}, i8* getelementptr inbounds ({{.*}} @a, i32 0, i32 2)
58// CHECK: call i32 @_ZN1A1fEv({{.*}} @a)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070059// CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}}, {{.*}}* @a, i32 0, i32 3)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070060// CHECK: store double 1.000000e+00, double* getelementptr inbounds ({{.*}} @a, i32 0, i32 4, i32 0)
Richard Smithc3bf52c2013-04-20 22:23:05 +000061
Richard Smith6391ea22013-05-09 07:14:00 +000062// No dynamic initialization of 'b':
Richard Smithc3bf52c2013-04-20 22:23:05 +000063
Richard Smith6391ea22013-05-09 07:14:00 +000064// CHECK-NOT: @b
Richard Smithc3bf52c2013-04-20 22:23:05 +000065
66// Initialization of 'c':
67
68// CHECK: store i32 1, i32* getelementptr inbounds ({{.*}} @c, i32 0, i32 0)
69// CHECK: store i8* null, i8** getelementptr inbounds ({{.*}} @c, i32 0, i32 1)
70// CHECK-NOT: load
71// CHECK: store i8 65, i8* getelementptr inbounds ({{.*}} @c, i32 0, i32 2)
72// CHECK: call i32 @_Z1fv()
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070073// CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}}, {{.*}}* @c, i32 0, i32 3)
Richard Smithc3bf52c2013-04-20 22:23:05 +000074// CHECK-NOT: C1Ev
75// CHECK: store i8 3, i8* {{.*}} @c, i32 0, i32 4)
76
77// CHECK: call void @_ZN1BC1Ev({{.*}} @x)
78
79// CHECK: call i32 @_ZN1B1fEv({{.*}} @y)
80// CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}} @y, i32 0, i32 0)