Skip to content

Commit 3f02d8a

Browse files
committedJul 25, 2014
Add test case for fix of linkage bug that miscompiled variable templates instantiated from similarly named local types (cf. r212233)
llvm-svn: 213987
1 parent 185cc18 commit 3f02d8a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// 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+
8+
template <typename T> int x = 42;
9+
10+
// CHECK-DAG: @_Z1xIZL3foovE3FooE = internal global
11+
12+
// CHECK-DAG: define internal dereferenceable(4) i32* @_ZL3foov(
13+
static 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(
23+
int &bar() {
24+
// CHECKA-DAG: %call = call dereferenceable(4) i32* @_ZL3foov()
25+
return foo();
26+
}
27+
28+
#else // File B
29+
30+
// CHECKB-DAG: declare dereferenceable(4) i32* @_Z3barv(
31+
int &bar();
32+
33+
int main() {
34+
// CHECKB-DAG: %call = call dereferenceable(4) i32* @_Z3barv()
35+
// CHECKB-DAG: %call1 = 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+

0 commit comments

Comments
 (0)
Please sign in to comment.