brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · 9b1a6e4 Raw
152 lines · cpp
1// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s2 3template <typename T> struct InlineAuto {4  template <typename G> inline static auto var = 5;5};6int inlineauto = InlineAuto<int>::var<int>;7// CHECK: @_ZN10InlineAutoIiE3varIiEE = {{.*}}i32 5{{.*}}comdat8 9template <typename> struct PartialInlineAuto {10  template <typename, typename> inline static auto var = 6;11  template <typename T> inline static auto var<int, T> = 7;12};13 14int partialinlineauto = PartialInlineAuto<int>::var<int, int>;15// CHECK: @_ZN17PartialInlineAutoIiE3varIiiEE = {{.*}}i32 7{{.*}}comdat16 17struct Q {18  // CHECK: @_ZN1Q1kE = linkonce_odr constant i32 5, comdat19  static constexpr int k = 5;20};21const int &r = Q::k;22 23int f();24 25// const does not imply internal linkage.26// CHECK: @external_inline = linkonce_odr constant i32 5, comdat27inline const int external_inline = 5;28const int &use1 = external_inline;29 30// static still does, though.31// CHECK: @_ZL15internal_inline = internal constant i32 532static inline const int internal_inline = 5;33const int &use2 = internal_inline;34 35int a = f();36// CHECK: @b = linkonce_odr global i32 0, comdat37// CHECK: @_ZGV1b = linkonce_odr global i64 0, comdat($b)38inline int b = f();39int c = f();40 41// For compatibility with C++11 and C++14, an out-of-line declaration of a42// static constexpr local variable promotes the variable to weak_odr.43struct compat {44  static constexpr int a = 1;45  static constexpr int b = 2;46  static constexpr int c = 3;47  static inline constexpr int d = 4;48  static const int e = 5;49  static const int f = 6;50  static const int g = 7;51};52const int &compat_use_before_redecl = compat::b;53const int compat::a;54const int compat::b;55const int compat::c;56const int compat::d;57const int compat::e;58constexpr int compat::f;59constexpr inline int compat::g;60const int &compat_use_after_redecl1 = compat::c;61const int &compat_use_after_redecl2 = compat::d;62const int &compat_use_after_redecl3 = compat::g;63// CHECK-DAG: @_ZN6compat1bE = weak_odr constant i32 264// CHECK-DAG: @_ZN6compat1aE = weak_odr constant i32 165// CHECK-DAG: @_ZN6compat1cE = weak_odr constant i32 366// CHECK-DAG: @_ZN6compat1dE = linkonce_odr constant i32 467// CHECK-DAG: @_ZN6compat1eE ={{.*}} constant i32 568// CHECK-DAG: @_ZN6compat1fE = weak_odr constant i32 669// CHECK-DAG: @_ZN6compat1gE = linkonce_odr constant i32 770 71template<typename T> struct X {72  static int a;73  static inline int b;74  static int c;75  static const int d;76  static int e;77};78// CHECK: @_ZN1XIiE1aE = linkonce_odr global i32 1079// CHECK: @_ZN1XIiE1bE ={{.*}} global i32 2080// CHECK-NOT: @_ZN1XIiE1cE81// CHECK: @_ZN1XIiE1dE = linkonce_odr constant i32 4082// CHECK: @_ZN1XIiE1eE = linkonce_odr global i32 5083template<> inline int X<int>::a = 10;84int &use3 = X<int>::a;85template<> int X<int>::b = 20;86template<> inline int X<int>::c = 30;87template<typename T> constexpr int X<T>::d = 40;88template<typename T> inline int X<T>::e = 50;89const int *use_x_int_d = &X<int>::d;90const int *use_x_int_e = &X<int>::e;91 92template<typename T> struct Y;93template<> struct Y<int> {94  static constexpr int a = 123;95  static constexpr int b = 456;96  static constexpr int c = 789;97};98// CHECK: @_ZN1YIiE1aE = weak_odr constant i32 12399constexpr int Y<int>::a;100// CHECK: @_ZN1YIiE1bE = linkonce_odr constant i32 456101const int &yib = Y<int>::b;102// CHECK-NOT: @_ZN1YIiE1cE103 104// CHECK-LABEL: define {{.*}}global_var_init105// CHECK: call noundef i32 @_Z1fv106 107// CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($b)108// CHECK: load atomic {{.*}} acquire, align109// CHECK: br110// CHECK: __cxa_guard_acquire(ptr @_ZGV1b)111// CHECK: br112// CHECK: call noundef i32 @_Z1fv113// CHECK: __cxa_guard_release(ptr @_ZGV1b)114 115// CHECK-LABEL: define {{.*}}global_var_init116// CHECK: call noundef i32 @_Z1fv117 118template<typename T> inline int d = f();119int e = d<int>;120 121// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat122// CHECK: _ZGV1dIiE123// CHECK-NOT: __cxa_guard_acquire(ptr @_ZGV1b)124// CHECK: call noundef i32 @_Z1fv125// CHECK-NOT: __cxa_guard_release(ptr @_ZGV1b)126 127namespace PR35599 {128struct Marker1 {};129struct Marker2 {};130 131template <typename>132struct Foo {133  struct Bar { Bar(); };134  inline static Bar bar;135};136 137void run() {138  // All we want here are ODR uses. Anything that requires that the type is139  // complete is uninteresting.140#pragma clang diagnostic push141#pragma clang diagnostic ignored "-Wunused-value"142  Foo<Marker1>::bar;143#pragma clang diagnostic pop144  static_cast<void>(Foo<Marker2>::bar);145}146 147// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat148// CHECK: call void @_ZN7PR355993FooINS_7Marker1EE3BarC1Ev149// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat150// CHECK: call void @_ZN7PR355993FooINS_7Marker2EE3BarC1Ev151}152