| 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) ptr @_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 |
static int x; |
| 60 |
return x; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
#if !__has_feature(cxx_exceptions) // File A |
| 65 |
// CHECKA-DAG: define{{.*}} nonnull align 4 dereferenceable(4) ptr @_Z3barv( |
| 66 |
const int &bar() { |
| 67 |
// CHECKA-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov() |
| 68 |
return foo(); |
| 69 |
} |
| 70 |
|
| 71 |
#else // File B |
| 72 |
|
| 73 |
// CHECKB-DAG: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z3barv( |
| 74 |
const int &bar(); |
| 75 |
|
| 76 |
int 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 B |
| 83 |
|