Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / const-init-cxx1y.cpp
blob4ca0a277993e7a42ab6aab78ece4b53a94e047a1
1 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++1y | FileCheck %s
2 // expected-no-diagnostics
4 struct A {
5 constexpr A() : n(1) {}
6 ~A();
7 int n;
8 };
9 struct B : A {
10 A a[3];
11 constexpr B() {
12 ++a[0].n;
13 a[1].n += 2;
14 a[2].n = n + a[1].n;
17 B b;
19 // CHECK: @b ={{.*}} global {{.*}} i32 1, {{.*}} { i32 2 }, {{.*}} { i32 3 }, {{.*}} { i32 4 }
20 // CHECK-NOT: _ZN1BC
22 namespace ModifyStaticTemporary {
23 struct A { int &&temporary; int x; };
24 constexpr int f(int &r) { r *= 9; return r - 12; }
25 A a = { 6, f(a.temporary) };
26 // CHECK: @_ZGRN21ModifyStaticTemporary1aE_ = internal global i32 54
27 // CHECK: @_ZN21ModifyStaticTemporary1aE ={{.*}} global {{.*}} ptr @_ZGRN21ModifyStaticTemporary1aE_, i32 42
29 A b = { 7, ++b.temporary };
30 // CHECK: @_ZGRN21ModifyStaticTemporary1bE_ = internal global i32 8
31 // CHECK: @_ZN21ModifyStaticTemporary1bE ={{.*}} global {{.*}} ptr @_ZGRN21ModifyStaticTemporary1bE_, i32 8
33 // Can't emit all of 'c' as a constant here, so emit the initial value of
34 // 'c.temporary', not the value as modified by the partial evaluation within
35 // the initialization of 'c.x'.
36 A c = { 10, (++c.temporary, b.x) };
37 // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
38 // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
41 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
42 // CHECK: @_ZN28VariableTemplateWithConstRef3useE ={{.*}} constant ptr @_ZGRN28VariableTemplateWithConstRef1iIvEE_
43 namespace VariableTemplateWithConstRef {
44 template <typename T>
45 const int &i = 5;
46 const int &use = i<void>;
49 // CHECK: @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_ = linkonce_odr hidden constant i32 5, align 4
50 // CHECK: @_ZN34HiddenVariableTemplateWithConstRef3useE ={{.*}} constant ptr @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_
51 namespace HiddenVariableTemplateWithConstRef {
52 template <typename T>
53 __attribute__((visibility("hidden"))) const int &i = 5;
54 const int &use = i<void>;
57 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ = linkonce_odr constant i32 1
58 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ }
59 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ = linkonce_odr constant i32 2
60 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ }
61 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ = linkonce_odr constant i32 3
62 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ }
63 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ = linkonce_odr constant i32 4
64 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ }
65 // CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_ = linkonce_odr global %"struct.VariableTemplateWithPack::S" { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ }
66 // CHECK: @_ZN24VariableTemplateWithPack1pE ={{.*}} global {{.*}} @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_
67 namespace VariableTemplateWithPack {
68 struct A {
69 const int &r;
71 struct S {
72 A &&a, &&b, &&c, &&d;
74 template <int... N>
75 S &&s = {A{N}...};
76 S *p = &s<1, 2, 3, 4>;
80 // CHECK: @_ZGR1z_ ={{.*}} global [2 x i32] [i32 10, i32 2]
81 // CHECK: @z = global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }
82 typedef int v[2];
83 struct Z { int &&x, y; };
84 Z z = { v{1,2}[0], z.x = 10 };
86 // CHECK: @_ZGR2z2_ ={{.*}} global %struct.R { i64 10 }
87 // @z = {{.}} global %struct.Z { ptr @_ZGR1z_, %struct.R { i64 10 } }
88 struct R { mutable long x; };
89 struct Z2 { const R &x, y; };
90 Z2 z2 = { R{1}, z2.x.x = 10 };
92 // CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev, {{.*}} @b
94 // CHECK: define
95 // CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE_
96 // CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE_, {{.*}} @_ZN21ModifyStaticTemporary1cE
97 // CHECK: add
98 // CHECK: store
99 // CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
100 // CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE