xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/const-init-cxx1y.cpp (revision eda6f5931d42c77e1480347b1fc3eef2f8d33806)
1 // RUN: not %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++1y | FileCheck %s
2 
3 struct A {
4   constexpr A() : n(1) {}
5   ~A();
6   int n;
7 };
8 struct B : A {
9   A a[3];
10   constexpr B() {
11     ++a[0].n;
12     a[1].n += 2;
13     a[2].n = n + a[1].n;
14   }
15 };
16 B b;
17 
18 // CHECK: @b = global {{.*}} i32 1, {{.*}} { i32 2 }, {{.*}} { i32 3 }, {{.*}} { i32 4 }
19 // CHECK-NOT: _ZN1BC
20 
21 namespace ModifyStaticTemporary {
22   struct A { int &&temporary; int x; };
23   constexpr int f(int &r) { r *= 9; return r - 12; }
24   A a = { 6, f(a.temporary) };
25   // CHECK: @_ZGRN21ModifyStaticTemporary1aE = private global i32 54
26   // CHECK: @_ZN21ModifyStaticTemporary1aE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1aE, i32 42
27 
28   A b = { 7, ++b.temporary };
29   // CHECK: @_ZGRN21ModifyStaticTemporary1bE = private global i32 8
30   // CHECK: @_ZN21ModifyStaticTemporary1bE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1bE, i32 8
31 
32   // Can't emit all of 'c' as a constant here, so emit the initial value of
33   // 'c.temporary', not the value as modified by the partial evaluation within
34   // the initialization of 'c.x'.
35   A c = { 10, (++c.temporary, b.x) };
36   // CHECK: @_ZGRN21ModifyStaticTemporary1cE = private global i32 10
37   // CHECK: @_ZN21ModifyStaticTemporary1cE = global {{.*}} zeroinitializer
38 }
39 
40 // CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev {{.*}} @b
41 
42 // CHECK: define
43 // CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE
44 // CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE, {{.*}} @_ZN21ModifyStaticTemporary1cE
45 // CHECK: add
46 // CHECK: store
47 // CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
48 // CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE
49