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=CHECK 2 // 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=CHECK 3 // expected-no-diagnostics 4 5 // The variable template specialization x<Foo> generated in each file 6 // should be 'internal global' and not 'linkonce_odr global'. 7 8 template <typename T> int x = 42; 9 // CHECK-DAG: @_Z1xIiE = linkonce_odr global 10 // CHECK-DAG: @_Z1xIZL3foovE3FooE = internal global 11 12 // 'static' affects the linkage of the global 13 template <typename T> static int y = 42; 14 // CHECK-DAG: @_ZL1yIiE = internal global 15 // CHECK-DAG: @_ZL1yIZL3foovE3FooE = internal global 16 17 // 'const' does not 18 template <typename T> const int z = 42; 19 // CHECK-DAG: @_Z1zIiE = linkonce_odr constant 20 // CHECK-DAG: @_Z1zIZL3foovE3FooE = internal constant 21 22 template <typename T> T t = 42; 23 // CHECK-DAG: @_Z1tIiE = linkonce_odr global 24 // CHECK-DAG: @_Z1tIKiE = linkonce_odr constant 25 26 int mode; 27 28 // CHECK-DAG: define internal noundef nonnull align 4 dereferenceable(4) i32* @_ZL3foov( 29 static const int &foo() { 30 struct Foo { }; 31 32 switch (mode) { 33 case 0: 34 // CHECK-DAG: @_Z1xIiE 35 return x<int>; 36 case 1: 37 // CHECK-DAG: @_Z1xIZL3foovE3FooE 38 return x<Foo>; 39 case 2: 40 // CHECK-DAG: @_ZL1yIiE 41 return y<int>; 42 case 3: 43 // CHECK-DAG: @_ZL1yIZL3foovE3FooE 44 return y<Foo>; 45 case 4: 46 // CHECK-DAG: @_Z1zIiE 47 return z<int>; 48 case 5: 49 // CHECK-DAG: @_Z1zIZL3foovE3FooE 50 return z<Foo>; 51 case 6: 52 // CHECK-DAG: @_Z1tIiE 53 return t<int>; 54 case 7: 55 // CHECK-DAG: @_Z1tIKiE 56 return t<const int>; 57 } 58 } 59 60 61 #if !__has_feature(cxx_exceptions) // File A 62 // CHECKA-DAG: define{{.*}} nonnull align 4 dereferenceable(4) i32* @_Z3barv( 63 const int &bar() { 64 // CHECKA-DAG: call noundef nonnull align 4 dereferenceable(4) i32* @_ZL3foov() 65 return foo(); 66 } 67 68 #else // File B 69 70 // CHECKB-DAG: declare noundef nonnull align 4 dereferenceable(4) i32* @_Z3barv( 71 const int &bar(); 72 73 int main() { 74 // CHECKB-DAG: call noundef nonnull align 4 dereferenceable(4) i32* @_Z3barv() 75 // CHECKB-DAG: call noundef nonnull align 4 dereferenceable(4) i32* @_ZL3foov() 76 &bar() == &foo() ? throw 0 : (void)0; // Should not throw exception at runtime. 77 } 78 79 #endif // end of Files A and B 80 81