xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/const-init-cxx1y.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++1y | FileCheck %s
2*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc struct A {
AA5f4a2713aSLionel Sambuc   constexpr A() : n(1) {}
6f4a2713aSLionel Sambuc   ~A();
7f4a2713aSLionel Sambuc   int n;
8f4a2713aSLionel Sambuc };
9f4a2713aSLionel Sambuc struct B : A {
10f4a2713aSLionel Sambuc   A a[3];
BB11f4a2713aSLionel Sambuc   constexpr B() {
12f4a2713aSLionel Sambuc     ++a[0].n;
13f4a2713aSLionel Sambuc     a[1].n += 2;
14f4a2713aSLionel Sambuc     a[2].n = n + a[1].n;
15f4a2713aSLionel Sambuc   }
16f4a2713aSLionel Sambuc };
17f4a2713aSLionel Sambuc B b;
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc // CHECK: @b = global {{.*}} i32 1, {{.*}} { i32 2 }, {{.*}} { i32 3 }, {{.*}} { i32 4 }
20f4a2713aSLionel Sambuc // CHECK-NOT: _ZN1BC
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc namespace ModifyStaticTemporary {
23f4a2713aSLionel Sambuc   struct A { int &&temporary; int x; };
f(int & r)24f4a2713aSLionel Sambuc   constexpr int f(int &r) { r *= 9; return r - 12; }
25f4a2713aSLionel Sambuc   A a = { 6, f(a.temporary) };
26*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN21ModifyStaticTemporary1aE_ = private global i32 54
27*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN21ModifyStaticTemporary1aE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1aE_, i32 42
28f4a2713aSLionel Sambuc 
29f4a2713aSLionel Sambuc   A b = { 7, ++b.temporary };
30*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN21ModifyStaticTemporary1bE_ = private global i32 8
31*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN21ModifyStaticTemporary1bE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1bE_, i32 8
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc   // Can't emit all of 'c' as a constant here, so emit the initial value of
34f4a2713aSLionel Sambuc   // 'c.temporary', not the value as modified by the partial evaluation within
35f4a2713aSLionel Sambuc   // the initialization of 'c.x'.
36f4a2713aSLionel Sambuc   A c = { 10, (++c.temporary, b.x) };
37*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = private global i32 10
38f4a2713aSLionel Sambuc   // CHECK: @_ZN21ModifyStaticTemporary1cE = global {{.*}} zeroinitializer
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
42*0a6a1f1dSLionel Sambuc // CHECK: @_ZN28VariableTemplateWithConstRef3useE = constant i32* @_ZGRN28VariableTemplateWithConstRef1iIvEE_
43*0a6a1f1dSLionel Sambuc namespace VariableTemplateWithConstRef {
44*0a6a1f1dSLionel Sambuc   template <typename T>
45*0a6a1f1dSLionel Sambuc   const int &i = 5;
46*0a6a1f1dSLionel Sambuc   const int &use = i<void>;
47*0a6a1f1dSLionel Sambuc }
48*0a6a1f1dSLionel Sambuc 
49*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_ = linkonce_odr hidden constant i32 5, align 4
50*0a6a1f1dSLionel Sambuc // CHECK: @_ZN34HiddenVariableTemplateWithConstRef3useE = constant i32* @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_
51*0a6a1f1dSLionel Sambuc namespace HiddenVariableTemplateWithConstRef {
52*0a6a1f1dSLionel Sambuc   template <typename T>
53*0a6a1f1dSLionel Sambuc   __attribute__((visibility("hidden"))) const int &i = 5;
54*0a6a1f1dSLionel Sambuc   const int &use = i<void>;
55*0a6a1f1dSLionel Sambuc }
56*0a6a1f1dSLionel Sambuc 
57*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ = linkonce_odr constant i32 1
58*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ }
59*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ = linkonce_odr constant i32 2
60*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ }
61*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ = linkonce_odr constant i32 3
62*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ }
63*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ = linkonce_odr constant i32 4
64*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ }
65*0a6a1f1dSLionel Sambuc // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_ = linkonce_odr global %"struct.VariableTemplateWithPack::S" { {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_, {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_, {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_, {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ }
66*0a6a1f1dSLionel Sambuc // CHECK: @_ZN24VariableTemplateWithPack1pE = global {{.*}} @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_
67*0a6a1f1dSLionel Sambuc namespace VariableTemplateWithPack {
68*0a6a1f1dSLionel Sambuc   struct A {
69*0a6a1f1dSLionel Sambuc     const int &r;
70*0a6a1f1dSLionel Sambuc   };
71*0a6a1f1dSLionel Sambuc   struct S {
72*0a6a1f1dSLionel Sambuc     A &&a, &&b, &&c, &&d;
73*0a6a1f1dSLionel Sambuc   };
74*0a6a1f1dSLionel Sambuc   template <int... N>
75*0a6a1f1dSLionel Sambuc   S &&s = {A{N}...};
76*0a6a1f1dSLionel Sambuc   S *p = &s<1, 2, 3, 4>;
77*0a6a1f1dSLionel Sambuc }
78*0a6a1f1dSLionel Sambuc 
79f4a2713aSLionel Sambuc // CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev {{.*}} @b
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc // CHECK: define
82*0a6a1f1dSLionel Sambuc // CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE_
83*0a6a1f1dSLionel Sambuc // CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE_, {{.*}} @_ZN21ModifyStaticTemporary1cE
84f4a2713aSLionel Sambuc // CHECK: add
85f4a2713aSLionel Sambuc // CHECK: store
86f4a2713aSLionel Sambuc // CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
87f4a2713aSLionel Sambuc // CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE
88