Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
Anders Carlsson | 1b3171d | 2009-12-04 23:50:01 +0000 | [diff] [blame] | 2 | // CHECK: ; ModuleID |
Reid Kleckner | b969e84 | 2013-08-22 20:07:45 +0000 | [diff] [blame^] | 3 | |
Anders Carlsson | 1b3171d | 2009-12-04 23:50:01 +0000 | [diff] [blame] | 4 | template<typename> struct A { static int a; }; |
| 5 | |
| 6 | // CHECK-NOT: @_ZN1AIcE1aE |
| 7 | template<> int A<char>::a; |
| 8 | |
| 9 | // CHECK: @_ZN1AIbE1aE = global i32 10 |
| 10 | template<> int A<bool>::a = 10; |
| 11 | |
Reid Kleckner | b969e84 | 2013-08-22 20:07:45 +0000 | [diff] [blame^] | 12 | // CHECK: @llvm.global_ctors = appending global [2 x { i32, void ()* }] |
| 13 | // CHECK: [{ i32, void ()* } { i32 65535, void ()* @__cxx_global_var_init }, |
| 14 | // CHECK: { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }] |
Anders Carlsson | 1b3171d | 2009-12-04 23:50:01 +0000 | [diff] [blame] | 15 | |
Reid Kleckner | b969e84 | 2013-08-22 20:07:45 +0000 | [diff] [blame^] | 16 | extern "C" int foo(); |
| 17 | template<> int A<short>::a = foo(); // Separate global_ctor entry |
| 18 | int b = foo(); // Goes in _GLOBAL__I_a |
| 19 | int c = foo(); // Goes in _GLOBAL__I_a |
| 20 | |
| 21 | // An explicit specialization is ordered, and goes in __GLOBAL_I_a. |
| 22 | template<> struct A<int> { static int a; }; |
| 23 | int A<int>::a = foo(); |
| 24 | |
| 25 | // CHECK: define internal void @__cxx_global_var_init() |
| 26 | // CHECK: call i32 @foo() |
| 27 | // CHECK: store {{.*}} @_ZN1AIsE1aE |
| 28 | // CHECK: ret |
| 29 | |
| 30 | // CHECK: define internal void @_GLOBAL__I_a() |
| 31 | // We call unique stubs for every ordered dynamic initializer in the TU. |
| 32 | // CHECK: call |
| 33 | // CHECK: call |
| 34 | // CHECK: call |
| 35 | // CHECK-NOT: call |
| 36 | // CHECK: ret |