84 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++1y -O1 -disable-llvm-passes %s -o - | FileCheck %s -check-prefix=CHECKA -check-prefix=CHECK2// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++1y -O1 -disable-llvm-passes -fcxx-exceptions %s -o - | FileCheck %s -check-prefix=CHECKB -check-prefix=CHECK3// expected-no-diagnostics4 5// The variable template specialization x<Foo> generated in each file6// should be 'internal global' and not 'linkonce_odr global'.7 8template <typename T> int x = 42;9// CHECK-DAG: @_Z1xIiE = linkonce_odr global10// CHECK-DAG: @_Z1xIZL3foovE3FooE = internal global11 12// 'static' affects the linkage of the global13template <typename T> static int y = 42;14// CHECK-DAG: @_ZL1yIiE = internal global15// CHECK-DAG: @_ZL1yIZL3foovE3FooE = internal global16 17// 'const' does not18template <typename T> const int z = 42;19// CHECK-DAG: @_Z1zIiE = linkonce_odr constant20// CHECK-DAG: @_Z1zIZL3foovE3FooE = internal constant21 22template <typename T> T t = 42;23// CHECK-DAG: @_Z1tIiE = linkonce_odr global24// CHECK-DAG: @_Z1tIKiE = linkonce_odr constant25 26int mode;27 28// CHECK-DAG: define internal noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov(29static const int &foo() {30 struct Foo { };31 32 switch (mode) {33 case 0:34 // CHECK-DAG: @_Z1xIiE35 return x<int>;36 case 1:37 // CHECK-DAG: @_Z1xIZL3foovE3FooE38 return x<Foo>;39 case 2:40 // CHECK-DAG: @_ZL1yIiE41 return y<int>;42 case 3:43 // CHECK-DAG: @_ZL1yIZL3foovE3FooE44 return y<Foo>;45 case 4:46 // CHECK-DAG: @_Z1zIiE47 return z<int>;48 case 5:49 // CHECK-DAG: @_Z1zIZL3foovE3FooE50 return z<Foo>;51 case 6:52 // CHECK-DAG: @_Z1tIiE53 return t<int>;54 case 7:55 // CHECK-DAG: @_Z1tIKiE56 return t<const int>;57 }58 59 static int x;60 return x;61}62 63 64#if !__has_feature(cxx_exceptions) // File A65// CHECKA-DAG: define{{.*}} nonnull align 4 dereferenceable(4) ptr @_Z3barv(66const int &bar() {67 // CHECKA-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov()68 return foo();69}70 71#else // File B72 73// CHECKB-DAG: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z3barv(74const int &bar();75 76int main() {77 // CHECKB-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_Z3barv()78 // CHECKB-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov()79 &bar() == &foo() ? throw 0 : (void)0; // Should not throw exception at runtime.80}81 82#endif // end of Files A and B83 84