xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/cxx1y-variable-template-linkage.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
4*0a6a1f1dSLionel Sambuc 
5*0a6a1f1dSLionel Sambuc // The variable template specialization x<Foo> generated in each file
6*0a6a1f1dSLionel Sambuc // should be 'internal global' and not 'linkonce_odr global'.
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc template <typename T> int x = 42;
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc // CHECK-DAG: @_Z1xIZL3foovE3FooE = internal global
11*0a6a1f1dSLionel Sambuc 
12*0a6a1f1dSLionel Sambuc // CHECK-DAG: define internal dereferenceable(4) i32* @_ZL3foov(
foo()13*0a6a1f1dSLionel Sambuc static int &foo() {
14*0a6a1f1dSLionel Sambuc    struct Foo { };
15*0a6a1f1dSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc    // CHECK-DAG: ret i32* @_Z1xIZL3foovE3FooE
17*0a6a1f1dSLionel Sambuc    return x<Foo>;
18*0a6a1f1dSLionel Sambuc }
19*0a6a1f1dSLionel Sambuc 
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc #if !__has_feature(cxx_exceptions) // File A
22*0a6a1f1dSLionel Sambuc // CHECKA-DAG: define dereferenceable(4) i32* @_Z3barv(
bar()23*0a6a1f1dSLionel Sambuc int &bar() {
24*0a6a1f1dSLionel Sambuc 	// CHECKA-DAG: call dereferenceable(4) i32* @_ZL3foov()
25*0a6a1f1dSLionel Sambuc 	return foo();
26*0a6a1f1dSLionel Sambuc }
27*0a6a1f1dSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc #else // File B
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc // CHECKB-DAG: declare dereferenceable(4) i32* @_Z3barv(
31*0a6a1f1dSLionel Sambuc int &bar();
32*0a6a1f1dSLionel Sambuc 
main()33*0a6a1f1dSLionel Sambuc int main() {
34*0a6a1f1dSLionel Sambuc 	// CHECKB-DAG: call dereferenceable(4) i32* @_Z3barv()
35*0a6a1f1dSLionel Sambuc 	// CHECKB-DAG: call dereferenceable(4) i32* @_ZL3foov()
36*0a6a1f1dSLionel Sambuc 	&bar() == &foo() ? throw 0 : (void)0; // Should not throw exception at runtime.
37*0a6a1f1dSLionel Sambuc }
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc #endif // end of Files A and B
40*0a6a1f1dSLionel Sambuc 
41