blob: 8c0b8c22096dfc9e8cc7d53a4e0b0317af46b9c3 [file] [log] [blame]
Stephen Hines176edba2014-12-01 14:53:08 -08001// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++1y -O1 -disable-llvm-optzns %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-optzns -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
8template <typename T> int x = 42;
9
10// CHECK-DAG: @_Z1xIZL3foovE3FooE = internal global
11
12// CHECK-DAG: define internal dereferenceable(4) i32* @_ZL3foov(
13static int &foo() {
14 struct Foo { };
15
16 // CHECK-DAG: ret i32* @_Z1xIZL3foovE3FooE
17 return x<Foo>;
18}
19
20
21#if !__has_feature(cxx_exceptions) // File A
22// CHECKA-DAG: define dereferenceable(4) i32* @_Z3barv(
23int &bar() {
24 // CHECKA-DAG: call dereferenceable(4) i32* @_ZL3foov()
25 return foo();
26}
27
28#else // File B
29
30// CHECKB-DAG: declare dereferenceable(4) i32* @_Z3barv(
31int &bar();
32
33int main() {
34 // CHECKB-DAG: call dereferenceable(4) i32* @_Z3barv()
35 // CHECKB-DAG: call dereferenceable(4) i32* @_ZL3foov()
36 &bar() == &foo() ? throw 0 : (void)0; // Should not throw exception at runtime.
37}
38
39#endif // end of Files A and B
40