1 // RUN: %clang_cc1 %s -triple=armv7-apple-darwin -emit-llvm -o - | FileCheck %s 2 // RUN: %clang_cc1 %s -triple=armv7-apple-darwin -emit-llvm -o - | FileCheck -check-prefix=CHECK-LATE %s 3 4 // RUN: %clang_cc1 %s -triple=x86_64-pc-windows-gnu -emit-llvm -o - | FileCheck %s 5 // RUN: %clang_cc1 %s -triple=x86_64-pc-windows-gnu -emit-llvm -o - | FileCheck -check-prefix=CHECK-LATE %s 6 7 // The 'a' variants ask for the v-table first. 8 // The 'b' variants ask for the v-table second. 9 // The 'c' variants ask for the v-table third. 10 // We do a separate CHECK-LATE pass because the RTTI definition gets 11 // changed after the fact, which causes reordering of the globals. 12 13 // These are not separated into namespaces because the way that Sema 14 // currently reports namespaces to IR-generation (i.e., en masse for 15 // the entire namespace at once) subverts the ordering that we're 16 // trying to test. 17 18 namespace std { class type_info; } 19 extern void use(const std::type_info &rtti); 20 21 /*** Test0a ******************************************************************/ 22 23 struct Test0a { 24 Test0a(); 25 virtual inline void foo(); 26 virtual void bar(); 27 }; 28 29 // V-table should be defined externally. 30 Test0a::Test0a() { use(typeid(Test0a)); } 31 // CHECK: @_ZTV6Test0a = external unnamed_addr constant 32 // CHECK: @_ZTI6Test0a = external constant 33 34 // This is not a key function. 35 void Test0a::foo() {} 36 37 /*** Test0b ******************************************************************/ 38 39 struct Test0b { 40 Test0b(); 41 virtual inline void foo(); 42 virtual void bar(); 43 }; 44 45 // This is not a key function. 46 void Test0b::foo() {} 47 48 // V-table should be defined externally. 49 Test0b::Test0b() { use(typeid(Test0b)); } 50 // CHECK: @_ZTV6Test0b = external unnamed_addr constant 51 // CHECK: @_ZTI6Test0b = external constant 52 53 /*** Test1a ******************************************************************/ 54 55 struct Test1a { 56 Test1a(); 57 virtual void foo(); 58 virtual void bar(); 59 }; 60 61 // V-table needs to be defined weakly. 62 Test1a::Test1a() { use(typeid(Test1a)); } 63 // CHECK: @_ZTV6Test1a = linkonce_odr unnamed_addr constant 64 // CHECK-LATE: @_ZTS6Test1a = linkonce_odr constant 65 // CHECK-LATE: @_ZTI6Test1a = linkonce_odr constant 66 67 // This defines the key function. 68 inline void Test1a::foo() {} 69 70 /*** Test1b ******************************************************************/ 71 72 struct Test1b { 73 Test1b(); 74 virtual void foo(); 75 virtual void bar(); 76 }; 77 78 // This defines the key function. 79 inline void Test1b::foo() {} 80 81 // V-table should be defined weakly.. 82 Test1b::Test1b() { use(typeid(Test1b)); } 83 // CHECK: @_ZTV6Test1b = linkonce_odr unnamed_addr constant 84 // CHECK: @_ZTS6Test1b = linkonce_odr constant 85 // CHECK: @_ZTI6Test1b = linkonce_odr constant 86 87 /*** Test2a ******************************************************************/ 88 89 struct Test2a { 90 Test2a(); 91 virtual void foo(); 92 virtual void bar(); 93 }; 94 95 // V-table should be defined with weak linkage. 96 Test2a::Test2a() { use(typeid(Test2a)); } 97 // CHECK: @_ZTV6Test2a = linkonce_odr unnamed_addr constant 98 // CHECK-LATE: @_ZTS6Test2a = linkonce_odr constant 99 // CHECK-LATE: @_ZTI6Test2a = linkonce_odr constant 100 101 void Test2a::bar() {} 102 inline void Test2a::foo() {} 103 104 /*** Test2b ******************************************************************/ 105 106 struct Test2b { 107 Test2b(); 108 virtual void foo(); 109 virtual void bar(); 110 }; 111 112 void Test2b::bar() {} 113 114 // V-table should be defined with weak linkage. 115 Test2b::Test2b() { use(typeid(Test2b)); } 116 // CHECK: @_ZTV6Test2b = linkonce_odr unnamed_addr constant 117 // CHECK-LATE: @_ZTS6Test2b = linkonce_odr constant 118 // CHECK-LATE: @_ZTI6Test2b = linkonce_odr constant 119 120 inline void Test2b::foo() {} 121 122 /*** Test2c ******************************************************************/ 123 124 struct Test2c { 125 Test2c(); 126 virtual void foo(); 127 virtual void bar(); 128 }; 129 130 void Test2c::bar() {} 131 inline void Test2c::foo() {} 132 133 // V-table should be defined with weak linkage. 134 Test2c::Test2c() { use(typeid(Test2c)); } 135 // CHECK: @_ZTV6Test2c = linkonce_odr unnamed_addr constant 136 // CHECK: @_ZTS6Test2c = linkonce_odr constant 137 // CHECK: @_ZTI6Test2c = linkonce_odr constant 138 139 /*** Test3a ******************************************************************/ 140 141 struct Test3a { 142 Test3a(); 143 virtual void foo(); 144 virtual void bar(); 145 }; 146 147 // V-table should be defined with weak linkage. 148 Test3a::Test3a() { use(typeid(Test3a)); } 149 // CHECK: @_ZTV6Test3a = linkonce_odr unnamed_addr constant 150 // CHECK-LATE: @_ZTS6Test3a = linkonce_odr constant 151 // CHECK-LATE: @_ZTI6Test3a = linkonce_odr constant 152 153 // This defines the key function. 154 inline void Test3a::bar() {} 155 inline void Test3a::foo() {} 156 157 /*** Test3b ******************************************************************/ 158 159 struct Test3b { 160 Test3b(); 161 virtual void foo(); 162 virtual void bar(); 163 }; 164 165 inline void Test3b::bar() {} 166 167 // V-table should be defined with weak linkage. 168 Test3b::Test3b() { use(typeid(Test3b)); } 169 // CHECK: @_ZTV6Test3b = linkonce_odr unnamed_addr constant 170 // CHECK-LATE: @_ZTS6Test3b = linkonce_odr constant 171 // CHECK-LATE: @_ZTI6Test3b = linkonce_odr constant 172 173 // This defines the key function. 174 inline void Test3b::foo() {} 175 176 /*** Test3c ******************************************************************/ 177 178 struct Test3c { 179 Test3c(); 180 virtual void foo(); 181 virtual void bar(); 182 }; 183 184 // This defines the key function. 185 inline void Test3c::bar() {} 186 inline void Test3c::foo() {} 187 188 // V-table should be defined with weak linkage. 189 Test3c::Test3c() { use(typeid(Test3c)); } 190 // CHECK: @_ZTV6Test3c = linkonce_odr unnamed_addr constant 191 // CHECK: @_ZTS6Test3c = linkonce_odr constant 192 // CHECK: @_ZTI6Test3c = linkonce_odr constant 193