218 lines · cpp
1// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o %t2// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -std=c++03 -o %t.033// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -std=c++11 -o %t.114// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -disable-llvm-passes -O3 -emit-llvm -o %t.opt5// RUN: FileCheck %s < %t6// RUN: FileCheck %s < %t.037// RUN: FileCheck %s < %t.118// RUN: FileCheck --check-prefix=CHECK-OPT %s < %t.opt9 10namespace {11 struct A {12 virtual void f() { }13 };14}15 16void f() { A b; }17 18struct B {19 B();20 virtual void f();21};22 23B::B() { }24 25struct C : virtual B {26 C();27 virtual void f() { }28};29 30C::C() { }31 32struct D {33 virtual void f();34};35 36void D::f() { }37 38static struct : D { } e;39 40// Force 'e' to be constructed and therefore have a vtable defined.41void use_e() {42 e.f();43}44 45// The destructor is the key function.46template<typename T>47struct E {48 virtual ~E();49};50 51template<typename T> E<T>::~E() { }52 53// Anchor is the key function54template<>55struct E<char> {56 virtual void anchor();57};58 59void E<char>::anchor() { }60 61template struct E<short>;62extern template struct E<int>;63 64void use_E() {65 E<int> ei;66 (void)ei;67 E<long> el;68 (void)el;69}70 71// No key function72template<typename T>73struct F {74 virtual void foo() { }75};76 77// No key function78template<>79struct F<char> {80 virtual void foo() { }81};82 83template struct F<short>;84extern template struct F<int>;85 86void use_F() {87 F<char> fc;88 fc.foo();89 F<int> fi;90 fi.foo();91 F<long> fl;92 (void)fl;93}94 95// B has a key function that is not defined in this translation unit so its vtable96// has external linkage.97// CHECK-DAG: @_ZTV1B = external unnamed_addr addrspace(1) constant98 99// C has no key function, so its vtable should have weak_odr linkage100// and hidden visibility101// CHECK-DAG: @_ZTV1C = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat, align 8{{$}}102// CHECK-DAG: @_ZTS1C = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 1{{$}}103// CHECK-DAG: @_ZTI1C = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 8{{$}}104// CHECK-DAG: @_ZTT1C = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat, align 8{{$}}105 106// D has a key function that is defined in this translation unit so its vtable is107// defined in the translation unit.108// CHECK-DAG: @_ZTV1D ={{.*}} unnamed_addr addrspace(1) constant109// CHECK-DAG: @_ZTS1D ={{.*}} addrspace(1) constant110// CHECK-DAG: @_ZTI1D ={{.*}} addrspace(1) constant111 112// E<char> is an explicit specialization with a key function defined113// in this translation unit, so its vtable should have external114// linkage.115// CHECK-DAG: @_ZTV1EIcE ={{.*}} unnamed_addr addrspace(1) constant116// CHECK-DAG: @_ZTS1EIcE ={{.*}} addrspace(1) constant117// CHECK-DAG: @_ZTI1EIcE ={{.*}} addrspace(1) constant118 119// E<short> is an explicit template instantiation with a key function120// defined in this translation unit, so its vtable should have121// weak_odr linkage.122// CHECK-DAG: @_ZTV1EIsE = weak_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,123// CHECK-DAG: @_ZTS1EIsE = weak_odr addrspace(1) constant {{.*}}, comdat, align 1{{$}}124// CHECK-DAG: @_ZTI1EIsE = weak_odr addrspace(1) constant {{.*}}, comdat, align 8{{$}}125 126// F<short> is an explicit template instantiation without a key127// function, so its vtable should have weak_odr linkage128// CHECK-DAG: @_ZTV1FIsE = weak_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,129// CHECK-DAG: @_ZTS1FIsE = weak_odr addrspace(1) constant {{.*}}, comdat, align 1{{$}}130// CHECK-DAG: @_ZTI1FIsE = weak_odr addrspace(1) constant {{.*}}, comdat, align 8{{$}}131 132// E<long> is an implicit template instantiation with a key function133// defined in this translation unit, so its vtable should have134// linkonce_odr linkage.135// CHECK-DAG: @_ZTV1EIlE = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,136// CHECK-DAG: @_ZTS1EIlE = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 1{{$}}137// CHECK-DAG: @_ZTI1EIlE = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 8{{$}}138 139// F<long> is an implicit template instantiation with no key function,140// so its vtable should have linkonce_odr linkage.141// CHECK-DAG: @_ZTV1FIlE = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,142// CHECK-DAG: @_ZTS1FIlE = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 1{{$}}143// CHECK-DAG: @_ZTI1FIlE = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 8{{$}}144 145// F<int> is an explicit template instantiation declaration without a146// key function, so its vtable should have external linkage.147// CHECK-DAG: @_ZTV1FIiE = external unnamed_addr addrspace(1) constant148// CHECK-OPT-DAG: @_ZTV1FIiE = available_externally unnamed_addr addrspace(1) constant149 150// E<int> is an explicit template instantiation declaration. It has a151// key function is not instantiated, so we know that vtable definition152// will be generated in TU where key function will be defined153// so we can mark it as external (without optimizations) and154// available_externally (with optimizations) because all of the inline155// virtual functions have been emitted.156// CHECK-DAG: @_ZTV1EIiE = external unnamed_addr addrspace(1) constant157// CHECK-OPT-DAG: @_ZTV1EIiE = available_externally unnamed_addr addrspace(1) constant158 159// The anonymous struct for e has no linkage, so the vtable should have160// internal linkage.161// CHECK-DAG: @"_ZTV3$_0" = internal unnamed_addr addrspace(1) constant162// CHECK-DAG: @"_ZTS3$_0" = internal addrspace(1) constant163// CHECK-DAG: @"_ZTI3$_0" = internal addrspace(1) constant164 165// The A vtable should have internal linkage since it is inside an anonymous166// namespace.167// CHECK-DAG: @_ZTVN12_GLOBAL__N_11AE = internal unnamed_addr addrspace(1) constant168// CHECK-DAG: @_ZTSN12_GLOBAL__N_11AE = internal addrspace(1) constant169// CHECK-DAG: @_ZTIN12_GLOBAL__N_11AE = internal addrspace(1) constant170 171// F<char> is an explicit specialization without a key function, so172// its vtable should have linkonce_odr linkage.173// CHECK-DAG: @_ZTV1FIcE = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,174// CHECK-DAG: @_ZTS1FIcE = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 1{{$}}175// CHECK-DAG: @_ZTI1FIcE = linkonce_odr addrspace(1) constant {{.*}}, comdat, align 8{{$}}176 177// CHECK-DAG: @_ZTV1GIiE = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,178template <typename T>179class G {180public:181 G() {}182 virtual void f0();183 virtual void f1();184};185template <>186void G<int>::f1() {}187template <typename T>188void G<T>::f0() {}189void G_f0() { new G<int>(); }190 191// H<int> has a key function without a body but it's a template instantiation192// so its VTable must be emitted.193// CHECK-DAG: @_ZTV1HIiE = linkonce_odr unnamed_addr addrspace(1) constant {{.*}}, comdat,194template <typename T>195class H {196public:197 virtual ~H();198};199 200void use_H() {201 H<int> h;202}203 204// I<int> has an explicit instantiation declaration and needs a VTT and205// construction vtables.206 207// CHECK-DAG: @_ZTV1IIiE = external unnamed_addr addrspace(1) constant208// CHECK-DAG: @_ZTT1IIiE = external unnamed_addr addrspace(1) constant209// CHECK-NOT: @_ZTC1IIiE210//211// CHECK-OPT-DAG: @_ZTV1IIiE = available_externally unnamed_addr addrspace(1) constant212// CHECK-OPT-DAG: @_ZTT1IIiE = available_externally unnamed_addr addrspace(1) constant213struct VBase1 { virtual void f(); }; struct VBase2 : virtual VBase1 {};214template<typename T>215struct I : VBase2 {};216extern template struct I<int>;217I<int> i;218