brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 1dc16ef Raw
102 lines · cpp
1// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++1y -fexperimental-new-constant-interpreter | FileCheck %s2//3// expected-no-diagnostics4 5struct A {6  constexpr A() : n(1) {}7  ~A();8  int n;9};10struct B : A {11  A a[3];12  constexpr B() {13    ++a[0].n;14    a[1].n += 2;15    a[2].n = n + a[1].n;16  }17};18B b;19 20// CHECK: @b ={{.*}} global {{.*}} i32 1, {{.*}} { i32 2 }, {{.*}} { i32 3 }, {{.*}} { i32 4 }21// CHECK-NOT: _ZN1BC22 23namespace ModifyStaticTemporary {24  struct A { int &&temporary; int x; };25  constexpr int f(int &r) { r *= 9; return r - 12; }26  A a = { 6, f(a.temporary) };27  // CHECK: @_ZGRN21ModifyStaticTemporary1aE_ = internal global i32 5428  // CHECK: @_ZN21ModifyStaticTemporary1aE ={{.*}} global {{.*}} ptr @_ZGRN21ModifyStaticTemporary1aE_, i32 4229 30  A b = { 7, ++b.temporary };31  // CHECK: @_ZGRN21ModifyStaticTemporary1bE_ = internal global i32 832  // CHECK: @_ZN21ModifyStaticTemporary1bE ={{.*}} global {{.*}} ptr @_ZGRN21ModifyStaticTemporary1bE_, i32 833 34  // Can't emit all of 'c' as a constant here, so emit the initial value of35  // 'c.temporary', not the value as modified by the partial evaluation within36  // the initialization of 'c.x'.37  A c = { 10, (++c.temporary, b.x) };38  // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer39  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 1040}41 42// CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 443// CHECK: @_ZN28VariableTemplateWithConstRef3useE ={{.*}} constant ptr @_ZGRN28VariableTemplateWithConstRef1iIvEE_44namespace VariableTemplateWithConstRef {45  template <typename T>46  const int &i = 5;47  const int &use = i<void>;48}49 50// CHECK: @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_ = linkonce_odr hidden constant i32 5, align 451// CHECK: @_ZN34HiddenVariableTemplateWithConstRef3useE ={{.*}} constant ptr @_ZGRN34HiddenVariableTemplateWithConstRef1iIvEE_52namespace HiddenVariableTemplateWithConstRef {53  template <typename T>54  __attribute__((visibility("hidden"))) const int &i = 5;55  const int &use = i<void>;56}57 58// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ = linkonce_odr constant i32 159// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE1_ }60// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ = linkonce_odr constant i32 261// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE3_ }62// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ = linkonce_odr constant i32 363// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE5_ }64// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ = linkonce_odr constant i32 465// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ = linkonce_odr global {{.*}} { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE7_ }66// CHECK: @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_ = linkonce_odr global %"struct.VariableTemplateWithPack::S" { ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE0_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE2_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE4_, ptr @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE6_ }67// CHECK: @_ZN24VariableTemplateWithPack1pE ={{.*}} global {{.*}} @_ZGRN24VariableTemplateWithPack1sIJLi1ELi2ELi3ELi4EEEE_68namespace VariableTemplateWithPack {69  struct A {70    const int &r;71  };72  struct S {73    A &&a, &&b, &&c, &&d;74  };75  template <int... N>76  S &&s = {A{N}...};77  S *p = &s<1, 2, 3, 4>;78}79 80 81// CHECK: @_ZGR1z_ ={{.*}} global [2 x i32] [i32 10, i32 2]82// CHECK: @z = global { ptr, i32 } { ptr @_ZGR1z_, i32 10 }83typedef int v[2];84struct Z { int &&x, y; };85Z z = { v{1,2}[0], z.x = 10 };86 87// CHECK: @_ZGR2z2_ ={{.*}} global %struct.R { i64 10 }88// @z = {{.}} global %struct.Z { ptr @_ZGR1z_, %struct.R { i64 10 } }89struct R { mutable long x; };90struct Z2 { const R &x, y; };91Z2 z2 = { R{1}, z2.x.x = 10 };92 93// CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev, {{.*}} @b94 95// CHECK: define96// CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE_97// CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE_, {{.*}} @_ZN21ModifyStaticTemporary1cE98// CHECK: add99// CHECK: store100// CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE101// CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE102