blob: c10cde84cd24f5b0acab9b604b1d7f89dc46bbea [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++1y | FileCheck %s
2// expected-no-diagnostics
Richard Smith6391ea22013-05-09 07:14:00 +00003
4struct A {
5 constexpr A() : n(1) {}
6 ~A();
7 int n;
8};
9struct 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;
15 }
16};
17B b;
18
19// CHECK: @b = global {{.*}} i32 1, {{.*}} { i32 2 }, {{.*}} { i32 3 }, {{.*}} { i32 4 }
20// CHECK-NOT: _ZN1BC
Richard Smith211c8dd2013-06-05 00:46:14 +000021
22namespace 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) };
Stephen Hines0e2c34f2015-03-23 12:09:02 -070026 // CHECK: @_ZGRN21ModifyStaticTemporary1aE_ = internal global i32 54
Stephen Hines6bcf27b2014-05-29 04:14:42 -070027 // CHECK: @_ZN21ModifyStaticTemporary1aE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1aE_, i32 42
Richard Smith3282b842013-06-14 03:07:01 +000028
29 A b = { 7, ++b.temporary };
Stephen Hines0e2c34f2015-03-23 12:09:02 -070030 // CHECK: @_ZGRN21ModifyStaticTemporary1bE_ = internal global i32 8
Stephen Hines6bcf27b2014-05-29 04:14:42 -070031 // CHECK: @_ZN21ModifyStaticTemporary1bE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1bE_, i32 8
Richard Smith3282b842013-06-14 03:07:01 +000032
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) };
Stephen Hines0e2c34f2015-03-23 12:09:02 -070037 // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
Richard Smith3282b842013-06-14 03:07:01 +000038 // CHECK: @_ZN21ModifyStaticTemporary1cE = global {{.*}} zeroinitializer
Richard Smith211c8dd2013-06-05 00:46:14 +000039}
40
Stephen Hines6bcf27b2014-05-29 04:14:42 -070041// CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
42// CHECK: @_ZN28VariableTemplateWithConstRef3useE = constant i32* @_ZGRN28VariableTemplateWithConstRef1iIvEE_
43namespace VariableTemplateWithConstRef {
44 template <typename T>
45 const int &i = 5;
46 const int &use = i<void>;
47}
48
49// CHECK: @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_ = linkonce_odr hidden constant i32 5, align 4
50// CHECK: @_ZN34HiddenVariableTemplateWithConstRef3useE = constant i32* @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_
51namespace HiddenVariableTemplateWithConstRef {
52 template <typename T>
53 __attribute__((visibility("hidden"))) const int &i = 5;
54 const int &use = i<void>;
55}
56
57// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ = linkonce_odr constant i32 1
58// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ }
59// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ = linkonce_odr constant i32 2
60// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ }
61// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ = linkonce_odr constant i32 3
62// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ }
63// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ = linkonce_odr constant i32 4
64// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ = linkonce_odr global {{.*}} { i32* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ }
65// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_ = linkonce_odr global %"struct.VariableTemplateWithPack::S" { {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_, {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_, {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_, {{.*}}* @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ }
66// CHECK: @_ZN24VariableTemplateWithPack1pE = global {{.*}} @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_
67namespace VariableTemplateWithPack {
68 struct A {
69 const int &r;
70 };
71 struct S {
72 A &&a, &&b, &&c, &&d;
73 };
74 template <int... N>
75 S &&s = {A{N}...};
76 S *p = &s<1, 2, 3, 4>;
77}
78
Richard Smith211c8dd2013-06-05 00:46:14 +000079// CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev {{.*}} @b
Richard Smith3282b842013-06-14 03:07:01 +000080
81// CHECK: define
Stephen Hines6bcf27b2014-05-29 04:14:42 -070082// CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE_
83// CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE_, {{.*}} @_ZN21ModifyStaticTemporary1cE
Richard Smith3282b842013-06-14 03:07:01 +000084// CHECK: add
85// CHECK: store
86// CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
87// CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE