llvm-project/clang/test/CodeGenCXX/vtable-key-function-address-space.cpp
Alex Voicu 8acdcf4016 [Clang][CodeGen]vtable, typeinfo et al. are globals
All data structures and values associated with handling virtual functions / inheritance, as well as RTTI, are globals and thus can only reside in the global address space. This was not taken fully taken into account because for most targets, global & generic appear to coincide. However, on targets where global & generic ASes differ (e.g. AMDGPU), this was problematic, since it led to the generation of invalid bitcasts (which would trigger asserts in Debug) and less than optimal code. This patch does two things:

ensures that vtables, vptrs, vtts, typeinfo are generated in the right AS, and populated accordingly;
removes a bunch of bitcasts which look like left-overs from the typed ptr era.

Reviewed By: yxsamliu

Differential Revision: https://reviews.llvm.org/D153092
2023-07-19 18:04:31 +01:00

34 lines
780 B
C++

// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
// PR5697
namespace PR5697 {
struct A {
virtual void f() { }
A();
A(int);
};
// A does not have a key function, so the first constructor we emit should
// cause the vtable to be defined (without assertions.)
// CHECK: @_ZTVN6PR56971AE = linkonce_odr unnamed_addr addrspace(1) constant
A::A() { }
A::A(int) { }
}
// Make sure that we don't assert when building the vtable for a class
// template specialization or explicit instantiation with a key
// function.
template<typename T>
struct Base {
virtual ~Base();
};
template<typename T>
struct Derived : public Base<T> { };
template<>
struct Derived<char> : public Base<char> {
virtual void anchor();
};
void Derived<char>::anchor() { }