20static llvm::GlobalVariable *
24 llvm::GlobalVariable::LinkageTypes
Linkage,
26 if (VTable.
getBase() == MostDerivedClass) {
28 "Most derived class vtable must have a zero offset!");
42 llvm::GlobalVariable::LinkageTypes
Linkage,
44 VTTBuilder Builder(CGM.getContext(), RD,
true);
45 llvm::ArrayType *
ArrayType = llvm::ArrayType::get(
46 CGM.GlobalsInt8PtrTy, Builder.getVTTComponents().size());
50 for (
const VTTVTable *i = Builder.getVTTVTables().begin(),
51 *e = Builder.getVTTVTables().end(); i != e; ++i) {
52 VTableAddressPoints.push_back(VTableAddressPointsMapTy());
54 VTableAddressPoints.back()));
58 for (
const auto &[Idx,
C] : llvm::enumerate(Builder.getVTTComponents())) {
59 const VTTVTable &VTTVT = Builder.getVTTVTables()[
C.VTableIndex];
60 llvm::GlobalVariable *VTable = VTables[
C.VTableIndex];
68 AddressPoint = VTableAddressPoints[
C.VTableIndex].lookup(
C.VTableBase);
70 "Did not find ctor vtable address point!");
73 llvm::Value *Idxs[] = {
74 llvm::ConstantInt::get(CGM.Int32Ty, 0),
75 llvm::ConstantInt::get(CGM.Int32Ty, AddressPoint.
VTableIndex),
81 unsigned ComponentSize =
83 unsigned VTableSize = CGM.getDataLayout().getTypeAllocSize(
87 llvm::ConstantRange InRange(
88 llvm::APInt(32, (
int)-Offset,
true),
89 llvm::APInt(32, (
int)(VTableSize - Offset),
true));
90 llvm::Constant *
Init = llvm::ConstantExpr::getGetElementPtr(
91 VTable->getValueType(), VTable, Idxs,
true, InRange);
94 CGM.getVTablePointerAuthentication(VTTVT.
getBase(),
96 llvm::Constant *
Address =
nullptr;
97 if (PAuthQual->isAddressDiscriminated())
98 Address = llvm::ConstantExpr::getGetElementPtr(
99 VTT->getType(), VTT, llvm::ConstantInt::get(CGM.Int32Ty, Idx));
100 auto *Discriminator = llvm::ConstantInt::get(
101 CGM.IntPtrTy, PAuthQual->getExtraDiscriminator());
102 Init = CGM.getConstantSignedPointer(
Init, PAuthQual->getKey(),
Address,
105 VTTComponents.push_back(
Init);
108 llvm::Constant *
Init = llvm::ConstantArray::get(
ArrayType, VTTComponents);
110 VTT->setInitializer(
Init);
115 if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
116 VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
121 CGM.setGVProperties(VTT, RD);
125 assert(RD->
getNumVBases() &&
"Only classes with virtual bases need a VTT");
128 llvm::raw_svector_ostream Out(OutName);
130 .mangleCXXVTT(RD, Out);
131 StringRef Name = OutName.str();
134 (void) CGM.getCXXABI().getAddrOfVTable(RD,
CharUnits());
136 VTTBuilder Builder(CGM.getContext(), RD,
false);
138 llvm::ArrayType *
ArrayType = llvm::ArrayType::get(
139 CGM.GlobalsInt8PtrTy, Builder.getVTTComponents().size());
140 llvm::Align Align = CGM.getDataLayout().getABITypeAlign(CGM.GlobalsInt8PtrTy);
142 llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable(
143 Name,
ArrayType, llvm::GlobalValue::ExternalLinkage, Align);
144 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
145 CGM.setGVProperties(GV, RD);
151 BaseSubobjectPairTy ClassSubobjectPair(RD,
Base);
153 SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);
154 if (I != SubVTTIndices.end())
157 VTTBuilder Builder(CGM.getContext(), RD,
false);
159 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator
160 I = Builder.getSubVTTIndices().begin(),
161 E = Builder.getSubVTTIndices().end();
164 BaseSubobjectPairTy ClassSubobjectPair(RD, I->first);
166 SubVTTIndices.insert(std::make_pair(ClassSubobjectPair, I->second));
169 I = SubVTTIndices.find(ClassSubobjectPair);
170 assert(I != SubVTTIndices.end() &&
"Did not find index!");
178 SecondaryVirtualPointerIndicesMapTy::iterator I =
179 SecondaryVirtualPointerIndices.find(std::make_pair(RD,
Base));
181 if (I != SecondaryVirtualPointerIndices.end())
184 VTTBuilder Builder(CGM.getContext(), RD,
false);
187 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =
188 Builder.getSecondaryVirtualPointerIndices().begin(),
189 E = Builder.getSecondaryVirtualPointerIndices().end(); I != E; ++I) {
190 std::pair<const CXXRecordDecl *, BaseSubobject> Pair =
191 std::make_pair(RD, I->first);
193 SecondaryVirtualPointerIndices.insert(std::make_pair(Pair, I->second));
196 I = SecondaryVirtualPointerIndices.find(std::make_pair(RD,
Base));
197 assert(I != SecondaryVirtualPointerIndices.end() &&
"Did not find index!");
static llvm::GlobalVariable * GetAddrOfVTTVTable(CodeGenVTables &CGVT, CodeGenModule &CGM, const CXXRecordDecl *MostDerivedClass, const VTTVTable &VTable, llvm::GlobalVariable::LinkageTypes Linkage, VTableLayout::AddressPointsMapTy &AddressPoints)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a C++ struct/union/class.
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
This class organizes the cross-function state that is used while generating LLVM code.
CGCXXABI & getCXXABI() const
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSubVTTIndex - Return the index of the sub-VTT for the base class of the given record decl.
ItaniumVTableContext & getItaniumVTableContext()
llvm::GlobalVariable * GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, bool BaseIsVirtual, llvm::GlobalVariable::LinkageTypes Linkage, VTableAddressPointsMapTy &AddressPoints)
GenerateConstructionVTable - Generate a construction vtable for the given base subobject.
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSecondaryVirtualPointerIndex - Return the index in the VTT where the virtual pointer for the given...
llvm::Type * getVTableComponentType() const
Return the type used as components for a vtable.
void EmitVTTDefinition(llvm::GlobalVariable *VTT, llvm::GlobalVariable::LinkageTypes Linkage, const CXXRecordDecl *RD)
EmitVTTDefinition - Emit the definition of the given vtable.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
Class for building VTT layout information.
CharUnits getBaseOffset() const
const CXXRecordDecl * getBase() const
BaseSubobject getBaseSubobject() const
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
AddressPointLocation getAddressPoint(BaseSubobject Base) const
Top level wrappers for InstallAPI frontend operations.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
U cast(CodeGen::Address addr)
unsigned AddressPointIndex