[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / cxx1y-variable-template-linkage.cpp
blobac542870f1f4b8b322b7f383ee233499f00ce883
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
5 // The variable template specialization x<Foo> generated in each file
6 // should be 'internal global' and not 'linkonce_odr global'.
8 template <typename T> int x = 42;
9 // CHECK-DAG: @_Z1xIiE = linkonce_odr global
10 // CHECK-DAG: @_Z1xIZL3foovE3FooE = internal global
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
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
22 template <typename T> T t = 42;
23 // CHECK-DAG: @_Z1tIiE = linkonce_odr global
24 // CHECK-DAG: @_Z1tIKiE = linkonce_odr constant
26 int mode;
28 // CHECK-DAG: define internal noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov(
29 static const int &foo() {
30 struct Foo { };
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>;
61 #if !__has_feature(cxx_exceptions) // File A
62 // CHECKA-DAG: define{{.*}} nonnull align 4 dereferenceable(4) ptr @_Z3barv(
63 const int &bar() {
64 // CHECKA-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov()
65 return foo();
68 #else // File B
70 // CHECKB-DAG: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z3barv(
71 const int &bar();
73 int main() {
74 // CHECKB-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_Z3barv()
75 // CHECKB-DAG: call noundef nonnull align 4 dereferenceable(4) ptr @_ZL3foov()
76 &bar() == &foo() ? throw 0 : (void)0; // Should not throw exception at runtime.
79 #endif // end of Files A and B