1// RUN: %clang_cc1 %s -triple=armv7-unknown-unknown -emit-llvm -o - | FileCheck %s 2// RUN: %clang_cc1 %s -triple=armv7-unknown-unknown -emit-llvm -o - | FileCheck -check-prefix=CHECK-LATE %s 3 4// The 'a' variants ask for the v-table first. 5// The 'b' variants ask for the v-table second. 6// The 'c' variants ask for the v-table third. 7// We do a separate CHECK-LATE pass because the RTTI definition gets 8// changed after the fact, which causes reordering of the globals. 9 10// These are not separated into namespaces because the way that Sema 11// currently reports namespaces to IR-generation (i.e., en masse for 12// the entire namespace at once) subverts the ordering that we're 13// trying to test. 14 15namespace std { class type_info; } 16extern void use(const std::type_info &rtti); 17 18/*** Test0a ******************************************************************/ 19 20struct Test0a { 21 Test0a(); 22 virtual inline void foo(); 23 virtual void bar(); 24}; 25 26// V-table should be defined externally. 27Test0a::Test0a() { use(typeid(Test0a)); } 28// CHECK: @_ZTV6Test0a = external unnamed_addr constant 29// CHECK: @_ZTI6Test0a = external constant 30 31// This is still not a key function. 32void Test0a::foo() {} 33 34/*** Test0b ******************************************************************/ 35 36struct Test0b { 37 Test0b(); 38 virtual inline void foo(); 39 virtual void bar(); 40}; 41 42// This is still not a key function. 43void Test0b::foo() {} 44 45// V-table should be defined externally. 46Test0b::Test0b() { use(typeid(Test0b)); } 47// CHECK: @_ZTV6Test0b = external unnamed_addr constant 48// CHECK: @_ZTI6Test0b = external constant 49 50/*** Test1a ******************************************************************/ 51 52struct Test1a { 53 Test1a(); 54 virtual void foo(); 55 virtual void bar(); 56}; 57 58// V-table should be defined externally. 59Test1a::Test1a() { use(typeid(Test1a)); } 60// CHECK: @_ZTV6Test1a = external unnamed_addr constant 61// CHECK: @_ZTI6Test1a = external constant 62 63// 'bar' becomes the key function when 'foo' is defined inline. 64inline void Test1a::foo() {} 65 66/*** Test1b ******************************************************************/ 67 68struct Test1b { 69 Test1b(); 70 virtual void foo(); 71 virtual void bar(); 72}; 73 74// 'bar' becomes the key function when 'foo' is defined inline. 75inline void Test1b::foo() {} 76 77// V-table should be defined externally. 78Test1b::Test1b() { use(typeid(Test1b)); } 79// CHECK: @_ZTV6Test1b = external unnamed_addr constant 80// CHECK: @_ZTI6Test1b = external constant 81 82/*** Test2a ******************************************************************/ 83 84struct Test2a { 85 Test2a(); 86 virtual void foo(); 87 virtual void bar(); 88}; 89 90// V-table should be defined with strong linkage. 91Test2a::Test2a() { use(typeid(Test2a)); } 92// CHECK: @_ZTV6Test2a = unnamed_addr constant 93// CHECK-LATE: @_ZTS6Test2a = constant 94// CHECK-LATE: @_ZTI6Test2a = constant 95 96// 'bar' becomes the key function when 'foo' is defined inline. 97void Test2a::bar() {} 98inline void Test2a::foo() {} 99 100/*** Test2b ******************************************************************/ 101 102struct Test2b { 103 Test2b(); 104 virtual void foo(); 105 virtual void bar(); 106}; 107 108// 'bar' becomes the key function when 'foo' is defined inline. 109void Test2b::bar() {} 110 111// V-table should be defined with strong linkage. 112Test2b::Test2b() { use(typeid(Test2b)); } 113// CHECK: @_ZTV6Test2b = unnamed_addr constant 114// CHECK-LATE: @_ZTS6Test2b = constant 115// CHECK-LATE: @_ZTI6Test2b = constant 116 117inline void Test2b::foo() {} 118 119/*** Test2c ******************************************************************/ 120 121struct Test2c { 122 Test2c(); 123 virtual void foo(); 124 virtual void bar(); 125}; 126 127// 'bar' becomes the key function when 'foo' is defined inline. 128void Test2c::bar() {} 129inline void Test2c::foo() {} 130 131// V-table should be defined with strong linkage. 132Test2c::Test2c() { use(typeid(Test2c)); } 133// CHECK: @_ZTV6Test2c = unnamed_addr constant 134// CHECK: @_ZTS6Test2c = constant 135// CHECK: @_ZTI6Test2c = constant 136 137/*** Test3a ******************************************************************/ 138 139struct Test3a { 140 Test3a(); 141 virtual void foo(); 142 virtual void bar(); 143}; 144 145// V-table should be defined with weak linkage. 146Test3a::Test3a() { use(typeid(Test3a)); } 147// CHECK: @_ZTV6Test3a = linkonce_odr unnamed_addr constant 148// CHECK-LATE: @_ZTS6Test3a = linkonce_odr constant 149// CHECK-LATE: @_ZTI6Test3a = linkonce_odr constant 150 151// There ceases to be a key function after these declarations. 152inline void Test3a::bar() {} 153inline void Test3a::foo() {} 154 155/*** Test3b ******************************************************************/ 156 157struct Test3b { 158 Test3b(); 159 virtual void foo(); 160 virtual void bar(); 161}; 162 163// There ceases to be a key function after these declarations. 164inline void Test3b::bar() {} 165 166// V-table should be defined with weak linkage. 167Test3b::Test3b() { use(typeid(Test3b)); } 168// CHECK: @_ZTV6Test3b = linkonce_odr unnamed_addr constant 169// CHECK-LATE: @_ZTS6Test3b = linkonce_odr constant 170// CHECK-LATE: @_ZTI6Test3b = linkonce_odr constant 171 172inline void Test3b::foo() {} 173 174/*** Test3c ******************************************************************/ 175 176struct Test3c { 177 Test3c(); 178 virtual void foo(); 179 virtual void bar(); 180}; 181 182// There ceases to be a key function after these declarations. 183inline void Test3c::bar() {} 184inline void Test3c::foo() {} 185 186// V-table should be defined with weak linkage. 187Test3c::Test3c() { use(typeid(Test3c)); } 188// CHECK: @_ZTV6Test3c = linkonce_odr unnamed_addr constant 189// CHECK: @_ZTS6Test3c = linkonce_odr constant 190// CHECK: @_ZTI6Test3c = linkonce_odr constant 191 192/*** Test4a ******************************************************************/ 193 194template <class T> struct Test4a { 195 Test4a(); 196 virtual void foo(); 197 virtual void bar(); 198}; 199 200// V-table should be defined with weak linkage. 201template <> Test4a<int>::Test4a() { use(typeid(Test4a)); } 202// CHECK: @_ZTV6Test4aIiE = linkonce_odr unnamed_addr constant 203// CHECK: @_ZTS6Test4aIiE = linkonce_odr constant 204// CHECK: @_ZTI6Test4aIiE = linkonce_odr constant 205 206// There ceases to be a key function after these declarations. 207template <> inline void Test4a<int>::bar() {} 208template <> inline void Test4a<int>::foo() {} 209 210/*** Test4b ******************************************************************/ 211 212template <class T> struct Test4b { 213 Test4b(); 214 virtual void foo(); 215 virtual void bar(); 216}; 217 218// There ceases to be a key function after these declarations. 219template <> inline void Test4b<int>::bar() {} 220 221// V-table should be defined with weak linkage. 222template <> Test4b<int>::Test4b() { use(typeid(Test4b)); } 223// CHECK: @_ZTV6Test4bIiE = linkonce_odr unnamed_addr constant 224// CHECK: @_ZTS6Test4bIiE = linkonce_odr constant 225// CHECK: @_ZTI6Test4bIiE = linkonce_odr constant 226 227template <> inline void Test4b<int>::foo() {} 228 229/*** Test4c ******************************************************************/ 230 231template <class T> struct Test4c { 232 Test4c(); 233 virtual void foo(); 234 virtual void bar(); 235}; 236 237// There ceases to be a key function after these declarations. 238template <> inline void Test4c<int>::bar() {} 239template <> inline void Test4c<int>::foo() {} 240 241// V-table should be defined with weak linkage. 242template <> Test4c<int>::Test4c() { use(typeid(Test4c)); } 243// CHECK: @_ZTV6Test4cIiE = linkonce_odr unnamed_addr constant 244// CHECK: @_ZTS6Test4cIiE = linkonce_odr constant 245// CHECK: @_ZTI6Test4cIiE = linkonce_odr constant 246 247/*** Test5a ******************************************************************/ 248 249template <class T> struct Test5a { 250 Test5a(); 251 virtual void foo(); 252 virtual void bar(); 253}; 254 255template <> inline void Test5a<int>::bar(); 256template <> inline void Test5a<int>::foo(); 257 258// V-table should be defined with weak linkage. 259template <> Test5a<int>::Test5a() { use(typeid(Test5a)); } 260// CHECK: @_ZTV6Test5aIiE = linkonce_odr unnamed_addr constant 261// CHECK: @_ZTS6Test5aIiE = linkonce_odr constant 262// CHECK: @_ZTI6Test5aIiE = linkonce_odr constant 263 264// There ceases to be a key function after these declarations. 265template <> inline void Test5a<int>::bar() {} 266template <> inline void Test5a<int>::foo() {} 267 268/*** Test5b ******************************************************************/ 269 270template <class T> struct Test5b { 271 Test5b(); 272 virtual void foo(); 273 virtual void bar(); 274}; 275 276// There ceases to be a key function after these declarations. 277template <> inline void Test5a<int>::bar(); 278template <> inline void Test5b<int>::bar() {} 279 280// V-table should be defined with weak linkage. 281template <> Test5b<int>::Test5b() { use(typeid(Test5b)); } 282// CHECK: @_ZTV6Test5bIiE = linkonce_odr unnamed_addr constant 283// CHECK: @_ZTS6Test5bIiE = linkonce_odr constant 284// CHECK: @_ZTI6Test5bIiE = linkonce_odr constant 285 286template <> inline void Test5a<int>::foo(); 287template <> inline void Test5b<int>::foo() {} 288 289/*** Test5c ******************************************************************/ 290 291template <class T> struct Test5c { 292 Test5c(); 293 virtual void foo(); 294 virtual void bar(); 295}; 296 297// There ceases to be a key function after these declarations. 298template <> inline void Test5a<int>::bar(); 299template <> inline void Test5a<int>::foo(); 300template <> inline void Test5c<int>::bar() {} 301template <> inline void Test5c<int>::foo() {} 302 303// V-table should be defined with weak linkage. 304template <> Test5c<int>::Test5c() { use(typeid(Test5c)); } 305// CHECK: @_ZTV6Test5cIiE = linkonce_odr unnamed_addr constant 306// CHECK: @_ZTS6Test5cIiE = linkonce_odr constant 307// CHECK: @_ZTI6Test5cIiE = linkonce_odr constant 308