vtable-linkage.cpp revision 6c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52e
1// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s 2 3namespace { 4 struct A { 5 virtual void f() { } 6 }; 7} 8 9void f() { A b; } 10 11struct B { 12 B(); 13 virtual void f(); 14}; 15 16B::B() { } 17 18struct C { 19 C(); 20 virtual void f() { } 21}; 22 23C::C() { } 24 25struct D { 26 virtual void f(); 27}; 28 29void D::f() { } 30 31static struct : D { } e; 32 33// The destructor is the key function. 34template<typename T> 35struct E { 36 virtual ~E(); 37}; 38 39template<typename T> E<T>::~E() { } 40 41// Anchor is the key function 42template<> 43struct E<char> { 44 virtual void anchor(); 45}; 46 47void E<char>::anchor() { } 48 49template struct E<short>; 50extern template struct E<int>; 51 52void use_E() { 53 E<int> ei; 54 (void)ei; 55 E<long> el; 56 (void)el; 57} 58 59// No key function 60template<typename T> 61struct F { 62 virtual void foo() { } 63}; 64 65// No key function 66template<> 67struct F<char> { 68 virtual void foo() { } 69}; 70 71template struct F<short>; 72extern template struct F<int>; 73 74void use_F(F<char> &fc) { 75 F<int> fi; 76 (void)fi; 77 F<long> fl; 78 (void)fl; 79 fc.foo(); 80} 81 82// B has a key function that is not defined in this translation unit so its vtable 83// has external linkage. 84// CHECK: @_ZTV1B = external constant 85 86// C has no key function, so its vtable should have weak_odr linkage. 87// CHECK: @_ZTS1C = weak_odr constant 88// CHECK: @_ZTI1C = weak_odr constant 89// CHECK: @_ZTV1C = weak_odr constant 90 91// D has a key function that is defined in this translation unit so its vtable is 92// defined in the translation unit. 93// CHECK: @_ZTS1D = constant 94// CHECK: @_ZTI1D = constant 95// CHECK: @_ZTV1D = constant 96 97// E<char> is an explicit specialization with a key function defined 98// in this translation unit, so its vtable should have external 99// linkage. 100// CHECK: @_ZTS1EIcE = constant 101// CHECK: @_ZTI1EIcE = constant 102// CHECK: @_ZTV1EIcE = constant 103 104// E<short> is an explicit template instantiation with a key function 105// defined in this translation unit, so its vtable should have 106// weak_odr linkage. 107// CHECK: @_ZTS1EIsE = weak_odr constant 108// CHECK: @_ZTI1EIsE = weak_odr constant 109// CHECK: @_ZTV1EIsE = weak_odr constant 110 111// F<short> is an explicit template instantiation without a key 112// function, so its vtable should have weak_odr linkage 113// CHECK: @_ZTS1FIsE = weak_odr constant 114// CHECK: @_ZTI1FIsE = weak_odr constant 115// CHECK: @_ZTV1FIsE = weak_odr constant 116 117// E<long> is an implicit template instantiation with a key function 118// defined in this translation unit, so its vtable should have 119// weak_odr linkage. 120// CHECK: @_ZTS1EIlE = weak_odr constant 121// CHECK: @_ZTI1EIlE = weak_odr constant 122// CHECK: @_ZTV1EIlE = weak_odr constant 123 124// F<long> is an implicit template instantiation with no key function, 125// so its vtable should have weak_odr linkage. 126// CHECK: @_ZTS1FIlE = weak_odr constant 127// CHECK: @_ZTI1FIlE = weak_odr constant 128// CHECK: @_ZTV1FIlE = weak_odr constant 129 130// F<int> is an explicit template instantiation declaration without a 131// key function, so its vtable should have weak_odr linkage. 132// CHECK: @_ZTS1FIiE = weak_odr constant 133// CHECK: @_ZTI1FIiE = weak_odr constant 134// CHECK: @_ZTV1FIiE = weak_odr constant 135 136// E<int> is an explicit template instantiation declaration. It has a 137// key function that is not instantiated, so we should only reference 138// its vtable, not define it. 139// CHECK: @_ZTV1EIiE = external constant 140 141// The anonymous struct for e has no linkage, so the vtable should have 142// internal linkage. 143// CHECK: @"_ZTS3$_0" = internal constant 144// CHECK: @"_ZTI3$_0" = internal constant 145// CHECK: @"_ZTV3$_0" = internal constant 146 147// The A vtable should have internal linkage since it is inside an anonymous 148// namespace. 149// CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant 150// CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant 151// CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant 152 153 154