xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/const-init-cxx11.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: not %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++11 | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // FIXME: The padding in all these objects should be zero-initialized.
4f4a2713aSLionel Sambuc namespace StructUnion {
5f4a2713aSLionel Sambuc   struct A {
6f4a2713aSLionel Sambuc     int n;
7f4a2713aSLionel Sambuc     double d;
8f4a2713aSLionel Sambuc     union U {
U(int x)9f4a2713aSLionel Sambuc       constexpr U(int x) : x(x) {}
U(const char * y)10f4a2713aSLionel Sambuc       constexpr U(const char *y) : y(y) {}
11f4a2713aSLionel Sambuc       int x;
12f4a2713aSLionel Sambuc       const char *y;
13f4a2713aSLionel Sambuc     } u;
14f4a2713aSLionel Sambuc 
AStructUnion::A15f4a2713aSLionel Sambuc     constexpr A(int n, double d, int x) : n(n), d(d), u(x) {}
AStructUnion::A16f4a2713aSLionel Sambuc     constexpr A(int n, double d, const char *y) : n(n), d(d), u(y) {}
17f4a2713aSLionel Sambuc   };
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1aE = constant {{.*}} { i32 1, double 2.000000e+00, {{.*}} { i32 3, [4 x i8] undef } }
20f4a2713aSLionel Sambuc   extern constexpr A a(1, 2.0, 3);
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1bE = constant {{.*}} { i32 4, double 5.000000e+00, {{.*}} { i8* getelementptr inbounds ([6 x i8]* @{{.*}}, i32 0, i32 0) } }
23f4a2713aSLionel Sambuc   extern constexpr A b(4, 5, "hello");
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc   struct B {
26f4a2713aSLionel Sambuc     int n;
27f4a2713aSLionel Sambuc   };
28f4a2713aSLionel Sambuc 
29f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1cE = global {{.*}} zeroinitializer
30f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion2c2E = global {{.*}} zeroinitializer
31f4a2713aSLionel Sambuc   B c;
32f4a2713aSLionel Sambuc   B c2 = B();
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1dE = global {{.*}} zeroinitializer
35f4a2713aSLionel Sambuc   B d[10];
36f4a2713aSLionel Sambuc 
37f4a2713aSLionel Sambuc   struct C {
CStructUnion::C38f4a2713aSLionel Sambuc     constexpr C() : c(0) {}
39f4a2713aSLionel Sambuc     int c;
40f4a2713aSLionel Sambuc   };
41f4a2713aSLionel Sambuc 
42f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1eE = global {{.*}} zeroinitializer
43f4a2713aSLionel Sambuc   C e[10];
44f4a2713aSLionel Sambuc 
45f4a2713aSLionel Sambuc   struct D {
DStructUnion::D46f4a2713aSLionel Sambuc     constexpr D() : d(5) {}
47f4a2713aSLionel Sambuc     int d;
48f4a2713aSLionel Sambuc   };
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1fE = global {{.*}} { i32 5 }
51f4a2713aSLionel Sambuc   D f;
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc   union E {
54f4a2713aSLionel Sambuc     int a;
55f4a2713aSLionel Sambuc     void *b = &f;
56f4a2713aSLionel Sambuc   };
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1gE = global {{.*}} @_ZN11StructUnion1fE
59f4a2713aSLionel Sambuc   E g;
60f4a2713aSLionel Sambuc 
61f4a2713aSLionel Sambuc   // CHECK: @_ZN11StructUnion1hE = global {{.*}} @_ZN11StructUnion1fE
62f4a2713aSLionel Sambuc   E h = E();
63f4a2713aSLionel Sambuc }
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc namespace BaseClass {
66f4a2713aSLionel Sambuc   template<typename T, unsigned> struct X : T {};
67f4a2713aSLionel Sambuc   struct C { char c = 1; };
68f4a2713aSLionel Sambuc   template<unsigned... Ns> struct Cs : X<C,Ns>... {};
69f4a2713aSLionel Sambuc   struct N { int n = 3; };
70f4a2713aSLionel Sambuc   struct D { double d = 4.0; };
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc   template<typename ...Ts>
TestBaseClass::Test73f4a2713aSLionel Sambuc   struct Test : Ts... { constexpr Test() : Ts()..., n(5) {} int n; };
74f4a2713aSLionel Sambuc 
75f4a2713aSLionel Sambuc   using Test1 = Test<N, C, Cs<1,2>, D, X<C,1>>;
76f4a2713aSLionel Sambuc   // CHECK: @_ZN9BaseClass2t1E = constant {{.*}} { i32 3, i8 1, i8 1, i8 1, double 4.000000e+00, i8 1, i32 5 }, align 8
77f4a2713aSLionel Sambuc   extern constexpr Test1 t1 = Test1();
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc   struct DN : D, N {};
80f4a2713aSLionel Sambuc   struct DND : DN, X<D,0> {};
81f4a2713aSLionel Sambuc   struct DNN : DN, X<N,0> {};
82f4a2713aSLionel Sambuc   // CHECK: @_ZN9BaseClass3dndE = constant {{.*}} { double 4.000000e+00, i32 3, double 4.000000e+00 }
83f4a2713aSLionel Sambuc   extern constexpr DND dnd = DND();
84f4a2713aSLionel Sambuc   // Note, N subobject is laid out in DN subobject's tail padding.
85f4a2713aSLionel Sambuc   // CHECK: @_ZN9BaseClass3dnnE = constant {{.*}} { double 4.000000e+00, i32 3, i32 3 }
86f4a2713aSLionel Sambuc   extern constexpr DNN dnn = DNN();
87f4a2713aSLionel Sambuc 
88f4a2713aSLionel Sambuc   struct E {};
89f4a2713aSLionel Sambuc   struct Test2 : X<E,0>, X<E,1>, X<E,2>, X<E,3> {};
90f4a2713aSLionel Sambuc   // CHECK: @_ZN9BaseClass2t2E = constant {{.*}} undef
91f4a2713aSLionel Sambuc   extern constexpr Test2 t2 = Test2();
92f4a2713aSLionel Sambuc 
93f4a2713aSLionel Sambuc   struct __attribute((packed)) PackedD { double y = 2; };
Test3BaseClass::Test394f4a2713aSLionel Sambuc   struct Test3 : C, PackedD { constexpr Test3() {} };
95f4a2713aSLionel Sambuc   // CHECK: @_ZN9BaseClass2t3E = constant <{ i8, double }> <{ i8 1, double 2.000000e+00 }>
96f4a2713aSLionel Sambuc   extern constexpr Test3 t3 = Test3();
97f4a2713aSLionel Sambuc }
98f4a2713aSLionel Sambuc 
99f4a2713aSLionel Sambuc namespace Array {
100f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array3arrE = constant [2 x i32] [i32 4, i32 0]
101f4a2713aSLionel Sambuc   extern constexpr int arr[2] = { 4 };
102f4a2713aSLionel Sambuc 
103f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array1cE = constant [6 x [4 x i8]] [{{.*}} c"foo\00", [4 x i8] c"a\00\00\00", [4 x i8] c"bar\00", [4 x i8] c"xyz\00", [4 x i8] c"b\00\00\00", [4 x i8] c"123\00"]
104f4a2713aSLionel Sambuc   extern constexpr char c[6][4] = { "foo", "a", { "bar" }, { 'x', 'y', 'z' }, { "b" }, '1', '2', '3' };
105f4a2713aSLionel Sambuc 
106f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array2ucE = constant [4 x i8] c"foo\00"
107f4a2713aSLionel Sambuc   extern constexpr unsigned char uc[] = { "foo" };
108f4a2713aSLionel Sambuc 
CArray::C109f4a2713aSLionel Sambuc   struct C { constexpr C() : n(5) {} int n, m = 3 * n + 1; };
110f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array5ctorsE = constant [3 x {{.*}}] [{{.*}} { i32 5, i32 16 }, {{.*}} { i32 5, i32 16 }, {{.*}} { i32 5, i32 16 }]
111f4a2713aSLionel Sambuc   extern const C ctors[3];
112f4a2713aSLionel Sambuc   constexpr C ctors[3];
113f4a2713aSLionel Sambuc 
114f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array1dE = constant {{.*}} { [2 x i32] [i32 1, i32 2], [3 x i32] [i32 3, i32 4, i32 5] }
115f4a2713aSLionel Sambuc   struct D { int n[2]; int m[3]; } extern constexpr d = { 1, 2, 3, 4, 5 };
116f4a2713aSLionel Sambuc 
117f4a2713aSLionel Sambuc   struct E {
118f4a2713aSLionel Sambuc     char c[4];
119f4a2713aSLionel Sambuc     char d[4];
EArray::E120f4a2713aSLionel Sambuc     constexpr E() : c("foo"), d("x") {}
121f4a2713aSLionel Sambuc   };
122f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array1eE = constant {{.*}} { [4 x i8] c"foo\00", [4 x i8] c"x\00\00\00" }
123f4a2713aSLionel Sambuc   extern constexpr E e = E();
124f4a2713aSLionel Sambuc 
125f4a2713aSLionel Sambuc   // PR13290
FArray::F126f4a2713aSLionel Sambuc   struct F { constexpr F() : n(4) {} int n; };
127f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array2f1E = global {{.*}} zeroinitializer
128f4a2713aSLionel Sambuc   F f1[1][1][0] = { };
129f4a2713aSLionel Sambuc   // CHECK: @_ZN5Array2f2E = global {{.* i32 4 .* i32 4 .* i32 4 .* i32 4 .* i32 4 .* i32 4 .* i32 4 .* i32 4}}
130f4a2713aSLionel Sambuc   F f2[2][2][2] = { };
131f4a2713aSLionel Sambuc }
132f4a2713aSLionel Sambuc 
133f4a2713aSLionel Sambuc namespace MemberPtr {
134f4a2713aSLionel Sambuc   struct B1 {
135f4a2713aSLionel Sambuc     int a, b;
136f4a2713aSLionel Sambuc     virtual void f();
137f4a2713aSLionel Sambuc     void g();
138f4a2713aSLionel Sambuc   };
139f4a2713aSLionel Sambuc   struct B2 {
140f4a2713aSLionel Sambuc     int c, d;
141f4a2713aSLionel Sambuc     virtual void h();
142f4a2713aSLionel Sambuc     void i();
143f4a2713aSLionel Sambuc   };
144f4a2713aSLionel Sambuc   struct C : B1 {
145f4a2713aSLionel Sambuc     int e;
146f4a2713aSLionel Sambuc     virtual void j();
147f4a2713aSLionel Sambuc     void k();
148f4a2713aSLionel Sambuc   };
149f4a2713aSLionel Sambuc   struct D : C, B2 {
150f4a2713aSLionel Sambuc     int z;
151f4a2713aSLionel Sambuc     virtual void l();
152f4a2713aSLionel Sambuc     void m();
153f4a2713aSLionel Sambuc   };
154f4a2713aSLionel Sambuc 
155f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2daE = constant i64 8
156f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dbE = constant i64 12
157f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dcE = constant i64 32
158f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2ddE = constant i64 36
159f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2deE = constant i64 16
160f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dzE = constant i64 40
161f4a2713aSLionel Sambuc   extern constexpr int (D::*da) = &B1::a;
162f4a2713aSLionel Sambuc   extern constexpr int (D::*db) = &C::b;
163f4a2713aSLionel Sambuc   extern constexpr int (D::*dc) = &B2::c;
164f4a2713aSLionel Sambuc   extern constexpr int (D::*dd) = &D::d;
165f4a2713aSLionel Sambuc   extern constexpr int (D::*de) = &C::e;
166f4a2713aSLionel Sambuc   extern constexpr int (D::*dz) = &D::z;
167f4a2713aSLionel Sambuc 
168f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2baE = constant i64 8
169f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bbE = constant i64 12
170f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bcE = constant i64 8
171f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bdE = constant i64 12
172f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2beE = constant i64 16
173f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr3b1zE = constant i64 40
174f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr3b2zE = constant i64 16
175f4a2713aSLionel Sambuc   extern constexpr int (B1::*ba) = (int(B1::*))&B1::a;
176f4a2713aSLionel Sambuc   extern constexpr int (B1::*bb) = (int(B1::*))&C::b;
177f4a2713aSLionel Sambuc   extern constexpr int (B2::*bc) = (int(B2::*))&B2::c;
178f4a2713aSLionel Sambuc   extern constexpr int (B2::*bd) = (int(B2::*))&D::d;
179f4a2713aSLionel Sambuc   extern constexpr int (B1::*be) = (int(B1::*))&C::e;
180f4a2713aSLionel Sambuc   extern constexpr int (B1::*b1z) = (int(B1::*))&D::z;
181f4a2713aSLionel Sambuc   extern constexpr int (B2::*b2z) = (int(B2::*))&D::z;
182f4a2713aSLionel Sambuc 
183f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dfE = constant {{.*}} { i64 1, i64 0 }
184f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dgE = constant {{.*}} { i64 {{.*}}2B11gEv{{.*}}, i64 0 }
185f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dhE = constant {{.*}} { i64 1, i64 24 }
186f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2diE = constant {{.*}} { i64 {{.*}}2B21iEv{{.*}}, i64 24 }
187f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2djE = constant {{.*}} { i64 9, i64 0 }
188f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dkE = constant {{.*}} { i64 {{.*}}1C1kEv{{.*}}, i64 0 }
189f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dlE = constant {{.*}} { i64 17, i64 0 }
190f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2dmE = constant {{.*}} { i64 {{.*}}1D1mEv{{.*}}, i64 0 }
191f4a2713aSLionel Sambuc   extern constexpr void (D::*df)() = &C::f;
192f4a2713aSLionel Sambuc   extern constexpr void (D::*dg)() = &B1::g;
193f4a2713aSLionel Sambuc   extern constexpr void (D::*dh)() = &B2::h;
194f4a2713aSLionel Sambuc   extern constexpr void (D::*di)() = &D::i;
195f4a2713aSLionel Sambuc   extern constexpr void (D::*dj)() = &C::j;
196f4a2713aSLionel Sambuc   extern constexpr void (D::*dk)() = &C::k;
197f4a2713aSLionel Sambuc   extern constexpr void (D::*dl)() = &D::l;
198f4a2713aSLionel Sambuc   extern constexpr void (D::*dm)() = &D::m;
199f4a2713aSLionel Sambuc 
200f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bfE = constant {{.*}} { i64 1, i64 0 }
201f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bgE = constant {{.*}} { i64 {{.*}}2B11gEv{{.*}}, i64 0 }
202f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bhE = constant {{.*}} { i64 1, i64 0 }
203f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2biE = constant {{.*}} { i64 {{.*}}2B21iEv{{.*}}, i64 0 }
204f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bjE = constant {{.*}} { i64 9, i64 0 }
205f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr2bkE = constant {{.*}} { i64 {{.*}}1C1kEv{{.*}}, i64 0 }
206f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr3b1lE = constant {{.*}} { i64 17, i64 0 }
207f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr3b1mE = constant {{.*}} { i64 {{.*}}1D1mEv{{.*}}, i64 0 }
208f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr3b2lE = constant {{.*}} { i64 17, i64 -24 }
209f4a2713aSLionel Sambuc   // CHECK: @_ZN9MemberPtr3b2mE = constant {{.*}} { i64 {{.*}}1D1mEv{{.*}}, i64 -24 }
210f4a2713aSLionel Sambuc   extern constexpr void (B1::*bf)()  = (void(B1::*)())&C::f;
211f4a2713aSLionel Sambuc   extern constexpr void (B1::*bg)()  = (void(B1::*)())&B1::g;
212f4a2713aSLionel Sambuc   extern constexpr void (B2::*bh)()  = (void(B2::*)())&B2::h;
213f4a2713aSLionel Sambuc   extern constexpr void (B2::*bi)()  = (void(B2::*)())&D::i;
214f4a2713aSLionel Sambuc   extern constexpr void (B1::*bj)()  = (void(B1::*)())&C::j;
215f4a2713aSLionel Sambuc   extern constexpr void (B1::*bk)()  = (void(B1::*)())&C::k;
216f4a2713aSLionel Sambuc   extern constexpr void (B1::*b1l)() = (void(B1::*)())&D::l;
217f4a2713aSLionel Sambuc   extern constexpr void (B1::*b1m)() = (void(B1::*)())&D::m;
218f4a2713aSLionel Sambuc   extern constexpr void (B2::*b2l)() = (void(B2::*)())&D::l;
219f4a2713aSLionel Sambuc   extern constexpr void (B2::*b2m)() = (void(B2::*)())&D::m;
220f4a2713aSLionel Sambuc }
221f4a2713aSLionel Sambuc 
222f4a2713aSLionel Sambuc namespace LiteralReference {
223f4a2713aSLionel Sambuc   struct Lit {
LitLiteralReference::Lit224f4a2713aSLionel Sambuc     constexpr Lit() : n(5) {}
225f4a2713aSLionel Sambuc     int n;
226f4a2713aSLionel Sambuc   };
227f4a2713aSLionel Sambuc 
228f4a2713aSLionel Sambuc   // This creates a non-const temporary and binds a reference to it.
229f4a2713aSLionel Sambuc   // CHECK: @[[TEMP:.*]] = private global {{.*}} { i32 5 }, align 4
230f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference3litE = constant {{.*}} @[[TEMP]], align 8
231f4a2713aSLionel Sambuc   const Lit &lit = Lit();
232f4a2713aSLionel Sambuc 
233f4a2713aSLionel Sambuc   // This creates a const temporary as part of the reference initialization.
234f4a2713aSLionel Sambuc   // CHECK: @[[TEMP:.*]] = private constant {{.*}} { i32 5 }, align 4
235f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference4lit2E = constant {{.*}} @[[TEMP]], align 8
236f4a2713aSLionel Sambuc   const Lit &lit2 = {};
237f4a2713aSLionel Sambuc 
238f4a2713aSLionel Sambuc   struct A { int &&r1; const int &&r2; };
239f4a2713aSLionel Sambuc   struct B { A &&a1; const A &&a2; };
240f4a2713aSLionel Sambuc   B b = { { 0, 1 }, { 2, 3 } };
241f4a2713aSLionel Sambuc   // CHECK: @[[TEMP0:.*]] = private global i32 0, align 4
242f4a2713aSLionel Sambuc   // CHECK: @[[TEMP1:.*]] = private constant i32 1, align 4
243f4a2713aSLionel Sambuc   // CHECK: @[[TEMPA1:.*]] = private global {{.*}} { i32* @[[TEMP0]], i32* @[[TEMP1]] }, align 8
244f4a2713aSLionel Sambuc   // CHECK: @[[TEMP2:.*]] = private global i32 2, align 4
245f4a2713aSLionel Sambuc   // CHECK: @[[TEMP3:.*]] = private constant i32 3, align 4
246f4a2713aSLionel Sambuc   // CHECK: @[[TEMPA2:.*]] = private constant {{.*}} { i32* @[[TEMP2]], i32* @[[TEMP3]] }, align 8
247f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference1bE = global {{.*}} { {{.*}}* @[[TEMPA1]], {{.*}}* @[[TEMPA2]] }, align 8
248f4a2713aSLionel Sambuc 
249f4a2713aSLionel Sambuc   struct Subobj {
250f4a2713aSLionel Sambuc     int a, b, c;
251f4a2713aSLionel Sambuc   };
252f4a2713aSLionel Sambuc   // CHECK: @[[TEMP:.*]] = private global {{.*}} { i32 1, i32 2, i32 3 }, align 4
253f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference2soE = constant {{.*}} (i8* getelementptr {{.*}} @[[TEMP]]{{.*}}, i64 4)
254f4a2713aSLionel Sambuc   constexpr int &&so = Subobj{ 1, 2, 3 }.b;
255f4a2713aSLionel Sambuc 
256f4a2713aSLionel Sambuc   struct Dummy { int padding; };
257f4a2713aSLionel Sambuc   struct Derived : Dummy, Subobj {
DerivedLiteralReference::Derived258f4a2713aSLionel Sambuc     constexpr Derived() : Dummy{200}, Subobj{4, 5, 6} {}
259f4a2713aSLionel Sambuc   };
260f4a2713aSLionel Sambuc   using ConstDerived = const Derived;
261f4a2713aSLionel Sambuc   // CHECK: @[[TEMPCOMMA:.*]] = private constant {{.*}} { i32 200, i32 4, i32 5, i32 6 }
262f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference5commaE = constant {{.*}} getelementptr {{.*}} @[[TEMPCOMMA]]{{.*}}, i64 8)
263f4a2713aSLionel Sambuc   constexpr const int &comma = (1, (2, ConstDerived{}).b);
264f4a2713aSLionel Sambuc 
265f4a2713aSLionel Sambuc   // CHECK: @[[TEMPDERIVED:.*]] = private global {{.*}} { i32 200, i32 4, i32 5, i32 6 }
266f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference4baseE = constant {{.*}} getelementptr {{.*}} @[[TEMPDERIVED]]{{.*}}, i64 4)
267f4a2713aSLionel Sambuc   constexpr Subobj &&base = Derived{};
268f4a2713aSLionel Sambuc 
269f4a2713aSLionel Sambuc   // CHECK: @_ZN16LiteralReference7derivedE = constant {{.*}} @[[TEMPDERIVED]]
270f4a2713aSLionel Sambuc   constexpr Derived &derived = static_cast<Derived&>(base);
271f4a2713aSLionel Sambuc }
272f4a2713aSLionel Sambuc 
273f4a2713aSLionel Sambuc namespace NonLiteralConstexpr {
factorial(int n)274f4a2713aSLionel Sambuc   constexpr int factorial(int n) {
275f4a2713aSLionel Sambuc     return n ? factorial(n-1) * n : 1;
276f4a2713aSLionel Sambuc   }
277f4a2713aSLionel Sambuc   extern void f(int *p);
278f4a2713aSLionel Sambuc 
279f4a2713aSLionel Sambuc   struct NonTrivialDtor {
NonTrivialDtorNonLiteralConstexpr::NonTrivialDtor280f4a2713aSLionel Sambuc     constexpr NonTrivialDtor() : n(factorial(5)), p(&n) {}
~NonTrivialDtorNonLiteralConstexpr::NonTrivialDtor281f4a2713aSLionel Sambuc     ~NonTrivialDtor() {
282f4a2713aSLionel Sambuc       f(p);
283f4a2713aSLionel Sambuc     }
284f4a2713aSLionel Sambuc 
285f4a2713aSLionel Sambuc     int n;
286f4a2713aSLionel Sambuc     int *p;
287f4a2713aSLionel Sambuc   };
288f4a2713aSLionel Sambuc   static_assert(!__is_literal(NonTrivialDtor), "");
289f4a2713aSLionel Sambuc   // CHECK: @_ZN19NonLiteralConstexpr3ntdE = global {{.*}} { i32 120, i32* getelementptr
290f4a2713aSLionel Sambuc   NonTrivialDtor ntd;
291f4a2713aSLionel Sambuc 
292f4a2713aSLionel Sambuc   struct VolatileMember {
VolatileMemberNonLiteralConstexpr::VolatileMember293f4a2713aSLionel Sambuc     constexpr VolatileMember() : n(5) {}
294f4a2713aSLionel Sambuc     volatile int n;
295f4a2713aSLionel Sambuc   };
296f4a2713aSLionel Sambuc   static_assert(!__is_literal(VolatileMember), "");
297f4a2713aSLionel Sambuc   // CHECK: @_ZN19NonLiteralConstexpr2vmE = global {{.*}} { i32 5 }
298f4a2713aSLionel Sambuc   VolatileMember vm;
299f4a2713aSLionel Sambuc 
300f4a2713aSLionel Sambuc   struct Both {
BothNonLiteralConstexpr::Both301f4a2713aSLionel Sambuc     constexpr Both() : n(10) {}
302f4a2713aSLionel Sambuc     ~Both();
303f4a2713aSLionel Sambuc     volatile int n;
304f4a2713aSLionel Sambuc   };
305f4a2713aSLionel Sambuc   // CHECK: @_ZN19NonLiteralConstexpr1bE = global {{.*}} { i32 10 }
306f4a2713aSLionel Sambuc   Both b;
307f4a2713aSLionel Sambuc 
StaticVars()308f4a2713aSLionel Sambuc   void StaticVars() {
309f4a2713aSLionel Sambuc     // CHECK: @_ZZN19NonLiteralConstexpr10StaticVarsEvE3ntd = {{.*}} { i32 120, i32* getelementptr {{.*}}
310f4a2713aSLionel Sambuc     // CHECK: @_ZGVZN19NonLiteralConstexpr10StaticVarsEvE3ntd =
311f4a2713aSLionel Sambuc     static NonTrivialDtor ntd;
312f4a2713aSLionel Sambuc     // CHECK: @_ZZN19NonLiteralConstexpr10StaticVarsEvE2vm = {{.*}} { i32 5 }
313f4a2713aSLionel Sambuc     // CHECK-NOT: @_ZGVZN19NonLiteralConstexpr10StaticVarsEvE2vm =
314f4a2713aSLionel Sambuc     static VolatileMember vm;
315f4a2713aSLionel Sambuc     // CHECK: @_ZZN19NonLiteralConstexpr10StaticVarsEvE1b = {{.*}} { i32 10 }
316f4a2713aSLionel Sambuc     // CHECK: @_ZGVZN19NonLiteralConstexpr10StaticVarsEvE1b =
317f4a2713aSLionel Sambuc     static Both b;
318f4a2713aSLionel Sambuc   }
319f4a2713aSLionel Sambuc }
320f4a2713aSLionel Sambuc 
321f4a2713aSLionel Sambuc // PR12067
322f4a2713aSLionel Sambuc namespace VirtualMembers {
323f4a2713aSLionel Sambuc   struct A {
AVirtualMembers::A324f4a2713aSLionel Sambuc     constexpr A(double d) : d(d) {}
325f4a2713aSLionel Sambuc     virtual void f();
326f4a2713aSLionel Sambuc     double d;
327f4a2713aSLionel Sambuc   };
328f4a2713aSLionel Sambuc   struct B : A {
BVirtualMembers::B329f4a2713aSLionel Sambuc     constexpr B() : A(2.0), c{'h', 'e', 'l', 'l', 'o'} {}
BVirtualMembers::B330f4a2713aSLionel Sambuc     constexpr B(int n) : A(n), c{'w', 'o', 'r', 'l', 'd'} {}
331f4a2713aSLionel Sambuc     virtual void g();
332f4a2713aSLionel Sambuc     char c[5];
333f4a2713aSLionel Sambuc   };
334f4a2713aSLionel Sambuc   struct C {
CVirtualMembers::C335f4a2713aSLionel Sambuc     constexpr C() : n(64) {}
336f4a2713aSLionel Sambuc     int n;
337f4a2713aSLionel Sambuc   };
338f4a2713aSLionel Sambuc   struct D : C, A, B {
DVirtualMembers::D339f4a2713aSLionel Sambuc     constexpr D() : A(1.0), B(), s(5) {}
340f4a2713aSLionel Sambuc     short s;
341f4a2713aSLionel Sambuc   };
342f4a2713aSLionel Sambuc   struct E : D, B {
EVirtualMembers::E343f4a2713aSLionel Sambuc     constexpr E() : B(3), c{'b','y','e'} {}
344f4a2713aSLionel Sambuc     char c[3];
345f4a2713aSLionel Sambuc   };
346f4a2713aSLionel Sambuc 
347f4a2713aSLionel Sambuc   // CHECK: @_ZN14VirtualMembers1eE = global { i8**, double, i32, i8**, double, [5 x i8], i16, i8**, double, [5 x i8], [3 x i8] } { i8** getelementptr inbounds ([11 x i8*]* @_ZTVN14VirtualMembers1EE, i64 0, i64 2), double 1.000000e+00, i32 64, i8** getelementptr inbounds ([11 x i8*]* @_ZTVN14VirtualMembers1EE, i64 0, i64 5), double 2.000000e+00, [5 x i8] c"hello", i16 5, i8** getelementptr inbounds ([11 x i8*]* @_ZTVN14VirtualMembers1EE, i64 0, i64 9), double 3.000000e+00, [5 x i8] c"world", [3 x i8] c"bye" }
348f4a2713aSLionel Sambuc   E e;
349f4a2713aSLionel Sambuc 
350f4a2713aSLionel Sambuc   struct nsMemoryImpl {
351f4a2713aSLionel Sambuc     virtual void f();
352f4a2713aSLionel Sambuc   };
353f4a2713aSLionel Sambuc   // CHECK: @_ZN14VirtualMembersL13sGlobalMemoryE = internal global { i8** } { i8** getelementptr inbounds ([3 x i8*]* @_ZTVN14VirtualMembers12nsMemoryImplE, i64 0, i64 2) }
354f4a2713aSLionel Sambuc   static nsMemoryImpl sGlobalMemory;
355f4a2713aSLionel Sambuc }
356f4a2713aSLionel Sambuc 
357f4a2713aSLionel Sambuc namespace PR13273 {
358f4a2713aSLionel Sambuc   struct U {
359f4a2713aSLionel Sambuc     int t;
360f4a2713aSLionel Sambuc     U() = default;
361f4a2713aSLionel Sambuc   };
362f4a2713aSLionel Sambuc 
363f4a2713aSLionel Sambuc   struct S : U {
364f4a2713aSLionel Sambuc     S() = default;
365f4a2713aSLionel Sambuc   };
366f4a2713aSLionel Sambuc 
367f4a2713aSLionel Sambuc   // CHECK: @_ZN7PR132731sE = {{.*}} zeroinitializer
368f4a2713aSLionel Sambuc   extern const S s {};
369f4a2713aSLionel Sambuc }
370f4a2713aSLionel Sambuc 
371f4a2713aSLionel Sambuc namespace ArrayTemporary {
372f4a2713aSLionel Sambuc   struct A { const int (&x)[3]; };
373f4a2713aSLionel Sambuc   struct B { const A (&x)[2]; };
374f4a2713aSLionel Sambuc   // CHECK: @[[A1:_ZGRN14ArrayTemporary1bE.*]] = private constant [3 x i32] [i32 1, i32 2, i32 3]
375f4a2713aSLionel Sambuc   // CHECK: @[[A2:_ZGRN14ArrayTemporary1bE.*]] = private constant [3 x i32] [i32 4, i32 5, i32 6]
376f4a2713aSLionel Sambuc   // CHECK: @[[ARR:_ZGRN14ArrayTemporary1bE.*]] = private constant [2 x {{.*}}] [{{.*}} { [3 x i32]* @[[A1]] }, {{.*}} { [3 x i32]* @[[A2]] }]
377f4a2713aSLionel Sambuc   // CHECK: @[[B:_ZGRN14ArrayTemporary1bE.*]] = private global {{.*}} { [2 x {{.*}}]* @[[ARR]] }
378f4a2713aSLionel Sambuc   // CHECK: @_ZN14ArrayTemporary1bE = constant {{.*}}* @[[B]]
379f4a2713aSLionel Sambuc   B &&b = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } };
380f4a2713aSLionel Sambuc }
381f4a2713aSLionel Sambuc 
382f4a2713aSLionel Sambuc namespace UnemittedTemporaryDecl {
383f4a2713aSLionel Sambuc   constexpr int &&ref = 0;
384f4a2713aSLionel Sambuc   extern constexpr int &ref2 = ref;
385*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN22UnemittedTemporaryDecl3refE_ = private global i32 0
386f4a2713aSLionel Sambuc 
387f4a2713aSLionel Sambuc   // FIXME: This declaration should not be emitted -- it isn't odr-used.
388f4a2713aSLionel Sambuc   // CHECK: @_ZN22UnemittedTemporaryDecl3refE
389f4a2713aSLionel Sambuc 
390*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN22UnemittedTemporaryDecl4ref2E = constant i32* @_ZGRN22UnemittedTemporaryDecl3refE_
391f4a2713aSLionel Sambuc }
392f4a2713aSLionel Sambuc 
393f4a2713aSLionel Sambuc // CHECK: @_ZZN12LocalVarInit3aggEvE1a = internal constant {{.*}} i32 101
394f4a2713aSLionel Sambuc // CHECK: @_ZZN12LocalVarInit4ctorEvE1a = internal constant {{.*}} i32 102
395f4a2713aSLionel Sambuc // CHECK: @_ZZN12LocalVarInit8mutable_EvE1a = private unnamed_addr constant {{.*}} i32 103
396*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE_ = linkonce_odr constant i32 5
397*0a6a1f1dSLionel Sambuc // CHECK: @_ZN33ClassTemplateWithStaticDataMember3useE = constant i32* @_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE_
398*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_ = linkonce_odr hidden constant i32 5
399*0a6a1f1dSLionel Sambuc // CHECK: @_ZN39ClassTemplateWithHiddenStaticDataMember3useE = constant i32* @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_
400*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRZN20InlineStaticConstRef3funEvE1i_ = linkonce_odr constant i32 10
401f4a2713aSLionel Sambuc 
402f4a2713aSLionel Sambuc // Constant initialization tests go before this point,
403f4a2713aSLionel Sambuc // dynamic initialization tests go after.
404f4a2713aSLionel Sambuc 
405f4a2713aSLionel Sambuc // We must emit a constant initializer for NonLiteralConstexpr::ntd, but also
406f4a2713aSLionel Sambuc // emit an initializer to register its destructor.
407f4a2713aSLionel Sambuc // CHECK: define {{.*}}cxx_global_var_init{{.*}}
408f4a2713aSLionel Sambuc // CHECK-NOT: NonLiteralConstexpr
409f4a2713aSLionel Sambuc // CHECK: call {{.*}}cxa_atexit{{.*}} @_ZN19NonLiteralConstexpr14NonTrivialDtorD1Ev {{.*}} @_ZN19NonLiteralConstexpr3ntdE
410f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
411f4a2713aSLionel Sambuc 
412f4a2713aSLionel Sambuc // We don't need to emit any dynamic initialization for NonLiteralConstexpr::vm.
413f4a2713aSLionel Sambuc // CHECK-NOT: NonLiteralConstexpr2vm
414f4a2713aSLionel Sambuc 
415f4a2713aSLionel Sambuc // We must emit a constant initializer for NonLiteralConstexpr::b, but also
416f4a2713aSLionel Sambuc // emit an initializer to register its destructor.
417f4a2713aSLionel Sambuc // CHECK: define {{.*}}cxx_global_var_init{{.*}}
418f4a2713aSLionel Sambuc // CHECK-NOT: NonLiteralConstexpr
419f4a2713aSLionel Sambuc // CHECK: call {{.*}}cxa_atexit{{.*}} @_ZN19NonLiteralConstexpr4BothD1Ev {{.*}} @_ZN19NonLiteralConstexpr1bE
420f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
421f4a2713aSLionel Sambuc 
422f4a2713aSLionel Sambuc // CHECK: define {{.*}}NonLiteralConstexpr10StaticVars
423f4a2713aSLionel Sambuc // CHECK-NOT: }
424f4a2713aSLionel Sambuc // CHECK: call {{.*}}cxa_atexit{{.*}}@_ZN19NonLiteralConstexpr14NonTrivialDtorD1Ev
425f4a2713aSLionel Sambuc // CHECK-NOT: }
426f4a2713aSLionel Sambuc // CHECK: call {{.*}}cxa_atexit{{.*}}@_ZN19NonLiteralConstexpr4BothD1Ev
427f4a2713aSLionel Sambuc 
428f4a2713aSLionel Sambuc // PR12848: Don't emit dynamic initializers for local constexpr variables.
429f4a2713aSLionel Sambuc namespace LocalVarInit {
f(int n)430f4a2713aSLionel Sambuc   constexpr int f(int n) { return n; }
431f4a2713aSLionel Sambuc   struct Agg { int k; };
CtorLocalVarInit::Ctor432f4a2713aSLionel Sambuc   struct Ctor { constexpr Ctor(int n) : k(n) {} int k; };
MutableLocalVarInit::Mutable433f4a2713aSLionel Sambuc   struct Mutable { constexpr Mutable(int n) : k(n) {} mutable int k; };
434f4a2713aSLionel Sambuc 
435f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @_ZN12LocalVarInit6scalarEv
436f4a2713aSLionel Sambuc   // CHECK-NOT: call
437f4a2713aSLionel Sambuc   // CHECK: store i32 100,
438f4a2713aSLionel Sambuc   // CHECK-NOT: call
439f4a2713aSLionel Sambuc   // CHECK: ret i32 100
scalar()440f4a2713aSLionel Sambuc   int scalar() { constexpr int a = { f(100) }; return a; }
441f4a2713aSLionel Sambuc 
442f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @_ZN12LocalVarInit3aggEv
443f4a2713aSLionel Sambuc   // CHECK-NOT: call
444f4a2713aSLionel Sambuc   // CHECK: ret i32 101
agg()445f4a2713aSLionel Sambuc   int agg() { constexpr Agg a = { f(101) }; return a.k; }
446f4a2713aSLionel Sambuc 
447f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @_ZN12LocalVarInit4ctorEv
448f4a2713aSLionel Sambuc   // CHECK-NOT: call
449f4a2713aSLionel Sambuc   // CHECK: ret i32 102
ctor()450f4a2713aSLionel Sambuc   int ctor() { constexpr Ctor a = { f(102) }; return a.k; }
451f4a2713aSLionel Sambuc 
452f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @_ZN12LocalVarInit8mutable_Ev
453f4a2713aSLionel Sambuc   // CHECK-NOT: call
454f4a2713aSLionel Sambuc   // CHECK: call {{.*}}memcpy{{.*}} @_ZZN12LocalVarInit8mutable_EvE1a
455f4a2713aSLionel Sambuc   // CHECK-NOT: call
456f4a2713aSLionel Sambuc   // Can't fold return value due to 'mutable'.
457f4a2713aSLionel Sambuc   // CHECK-NOT: ret i32 103
458f4a2713aSLionel Sambuc   // CHECK: }
mutable_()459f4a2713aSLionel Sambuc   int mutable_() { constexpr Mutable a = { f(103) }; return a.k; }
460f4a2713aSLionel Sambuc }
461f4a2713aSLionel Sambuc 
462f4a2713aSLionel Sambuc namespace CrossFuncLabelDiff {
463f4a2713aSLionel Sambuc   // Make sure we refuse to constant-fold the variable b.
a(bool x)464f4a2713aSLionel Sambuc   constexpr long a(bool x) { return x ? 0 : (long)&&lbl + (0 && ({lbl: 0;})); }
test()465f4a2713aSLionel Sambuc   void test() { static long b = (long)&&lbl - a(false); lbl: return; }
466f4a2713aSLionel Sambuc   // CHECK: sub nsw i64 ptrtoint (i8* blockaddress(@_ZN18CrossFuncLabelDiff4testEv, {{.*}}) to i64),
467f4a2713aSLionel Sambuc   // CHECK: store i64 {{.*}}, i64* @_ZZN18CrossFuncLabelDiff4testEvE1b, align 8
468f4a2713aSLionel Sambuc }
469f4a2713aSLionel Sambuc 
470f4a2713aSLionel Sambuc // PR12012
471f4a2713aSLionel Sambuc namespace VirtualBase {
472f4a2713aSLionel Sambuc   struct B {};
473f4a2713aSLionel Sambuc   struct D : virtual B {};
474f4a2713aSLionel Sambuc   D d;
475f4a2713aSLionel Sambuc   // CHECK: call {{.*}}@_ZN11VirtualBase1DC1Ev
476f4a2713aSLionel Sambuc 
477f4a2713aSLionel Sambuc   template<typename T> struct X : T {
XVirtualBase::X478f4a2713aSLionel Sambuc     constexpr X() : T() {}
479f4a2713aSLionel Sambuc   };
480f4a2713aSLionel Sambuc   X<D> x;
481f4a2713aSLionel Sambuc   // CHECK: call {{.*}}@_ZN11VirtualBase1XINS_1DEEC1Ev
482f4a2713aSLionel Sambuc }
483f4a2713aSLionel Sambuc 
484f4a2713aSLionel Sambuc // PR12145
485f4a2713aSLionel Sambuc namespace Unreferenced {
486f4a2713aSLionel Sambuc   int n;
487f4a2713aSLionel Sambuc   constexpr int *p = &n;
488f4a2713aSLionel Sambuc   // We must not emit a load of 'p' here, since it's not odr-used.
489f4a2713aSLionel Sambuc   int q = *p;
490f4a2713aSLionel Sambuc   // CHECK-NOT: _ZN12Unreferenced1pE
491f4a2713aSLionel Sambuc   // CHECK: = load i32* @_ZN12Unreferenced1nE
492f4a2713aSLionel Sambuc   // CHECK-NEXT: store i32 {{.*}}, i32* @_ZN12Unreferenced1qE
493f4a2713aSLionel Sambuc   // CHECK-NOT: _ZN12Unreferenced1pE
494f4a2713aSLionel Sambuc 
495f4a2713aSLionel Sambuc   // Technically, we are not required to substitute variables of reference types
496f4a2713aSLionel Sambuc   // initialized by constant expressions, because the special case for odr-use
497f4a2713aSLionel Sambuc   // of variables in [basic.def.odr]p2 only applies to objects. But we do so
498f4a2713aSLionel Sambuc   // anyway.
499f4a2713aSLionel Sambuc 
500f4a2713aSLionel Sambuc   constexpr int &r = n;
501f4a2713aSLionel Sambuc   // CHECK-NOT: _ZN12Unreferenced1rE
502f4a2713aSLionel Sambuc   int s = r;
503f4a2713aSLionel Sambuc 
504f4a2713aSLionel Sambuc   const int t = 1;
505f4a2713aSLionel Sambuc   const int &rt = t;
506f4a2713aSLionel Sambuc   int f(int);
507f4a2713aSLionel Sambuc   int u = f(rt);
508f4a2713aSLionel Sambuc   // CHECK: call i32 @_ZN12Unreferenced1fEi(i32 1)
509f4a2713aSLionel Sambuc }
510f4a2713aSLionel Sambuc 
511f4a2713aSLionel Sambuc namespace InitFromConst {
512f4a2713aSLionel Sambuc   template<typename T> void consume(T);
513f4a2713aSLionel Sambuc 
514f4a2713aSLionel Sambuc   const bool b = true;
515f4a2713aSLionel Sambuc   const int n = 5;
516f4a2713aSLionel Sambuc   constexpr double d = 4.3;
517f4a2713aSLionel Sambuc 
518f4a2713aSLionel Sambuc   struct S { int n = 7; S *p = 0; };
519f4a2713aSLionel Sambuc   constexpr S s = S();
520f4a2713aSLionel Sambuc   const S &r = s;
521f4a2713aSLionel Sambuc   constexpr const S *p = &r;
522f4a2713aSLionel Sambuc   constexpr int S::*mp = &S::n;
523f4a2713aSLionel Sambuc   constexpr int a[3] = { 1, 4, 9 };
524f4a2713aSLionel Sambuc 
test()525f4a2713aSLionel Sambuc   void test() {
526f4a2713aSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIbEEvT_(i1 zeroext true)
527f4a2713aSLionel Sambuc     consume(b);
528f4a2713aSLionel Sambuc 
529f4a2713aSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIiEEvT_(i32 5)
530f4a2713aSLionel Sambuc     consume(n);
531f4a2713aSLionel Sambuc 
532f4a2713aSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIdEEvT_(double 4.300000e+00)
533f4a2713aSLionel Sambuc     consume(d);
534f4a2713aSLionel Sambuc 
535*0a6a1f1dSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIRKNS_1SEEEvT_(%"struct.InitFromConst::S"* dereferenceable({{[0-9]+}}) @_ZN13InitFromConstL1sE)
536f4a2713aSLionel Sambuc     consume<const S&>(s);
537f4a2713aSLionel Sambuc 
538*0a6a1f1dSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIRKNS_1SEEEvT_(%"struct.InitFromConst::S"* dereferenceable({{[0-9]+}}) @_ZN13InitFromConstL1sE)
539f4a2713aSLionel Sambuc     consume<const S&>(r);
540f4a2713aSLionel Sambuc 
541f4a2713aSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIPKNS_1SEEEvT_(%"struct.InitFromConst::S"* @_ZN13InitFromConstL1sE)
542f4a2713aSLionel Sambuc     consume(p);
543f4a2713aSLionel Sambuc 
544f4a2713aSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIMNS_1SEiEEvT_(i64 0)
545f4a2713aSLionel Sambuc     consume(mp);
546f4a2713aSLionel Sambuc 
547f4a2713aSLionel Sambuc     // CHECK: call void @_ZN13InitFromConst7consumeIPKiEEvT_(i32* getelementptr inbounds ([3 x i32]* @_ZN13InitFromConstL1aE, i32 0, i32 0))
548f4a2713aSLionel Sambuc     consume(a);
549f4a2713aSLionel Sambuc   }
550f4a2713aSLionel Sambuc }
551f4a2713aSLionel Sambuc 
552f4a2713aSLionel Sambuc namespace Null {
553f4a2713aSLionel Sambuc   decltype(nullptr) null();
554f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN4Null4nullEv(
555f4a2713aSLionel Sambuc   int *p = null();
556f4a2713aSLionel Sambuc   struct S {};
557f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN4Null4nullEv(
558f4a2713aSLionel Sambuc   int S::*q = null();
559f4a2713aSLionel Sambuc }
560*0a6a1f1dSLionel Sambuc 
561*0a6a1f1dSLionel Sambuc namespace InlineStaticConstRef {
fun()562*0a6a1f1dSLionel Sambuc   inline const int &fun() {
563*0a6a1f1dSLionel Sambuc     static const int &i = 10;
564*0a6a1f1dSLionel Sambuc     return i;
565*0a6a1f1dSLionel Sambuc     // CHECK: ret i32* @_ZGRZN20InlineStaticConstRef3funEvE1i_
566*0a6a1f1dSLionel Sambuc   }
567*0a6a1f1dSLionel Sambuc   const int &use = fun();
568*0a6a1f1dSLionel Sambuc }
569*0a6a1f1dSLionel Sambuc 
570*0a6a1f1dSLionel Sambuc namespace ClassTemplateWithStaticDataMember {
571*0a6a1f1dSLionel Sambuc   template <typename T>
572*0a6a1f1dSLionel Sambuc   struct S {
573*0a6a1f1dSLionel Sambuc     static const int &a;
574*0a6a1f1dSLionel Sambuc   };
575*0a6a1f1dSLionel Sambuc   template <typename T>
576*0a6a1f1dSLionel Sambuc   const int &S<T>::a = 5;
577*0a6a1f1dSLionel Sambuc   const int &use = S<void>::a;
578*0a6a1f1dSLionel Sambuc }
579*0a6a1f1dSLionel Sambuc 
580*0a6a1f1dSLionel Sambuc namespace ClassTemplateWithHiddenStaticDataMember {
581*0a6a1f1dSLionel Sambuc   template <typename T>
582*0a6a1f1dSLionel Sambuc   struct S {
583*0a6a1f1dSLionel Sambuc     __attribute__((visibility("hidden"))) static const int &a;
584*0a6a1f1dSLionel Sambuc   };
585*0a6a1f1dSLionel Sambuc   template <typename T>
586*0a6a1f1dSLionel Sambuc   const int &S<T>::a = 5;
587*0a6a1f1dSLionel Sambuc   const int &use = S<void>::a;
588*0a6a1f1dSLionel Sambuc }
589