clang: lib/CodeGen/CGVTT.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

17using namespace clang;

18using namespace CodeGen;

19

20static llvm::GlobalVariable *

24 llvm::GlobalVariable::LinkageTypes Linkage,

26 if (VTable.getBase() == MostDerivedClass) {

28 "Most derived class vtable must have a zero offset!");

29

31 }

32

37 AddressPoints);

38}

39

40void

42 llvm::GlobalVariable::LinkageTypes Linkage,

45 llvm::ArrayType *ArrayType = llvm::ArrayType::get(

47

50 for (const VTTVTable *i = Builder.getVTTVTables().begin(),

51 *e = Builder.getVTTVTables().end(); i != e; ++i) {

52 VTableAddressPoints.push_back(VTableAddressPointsMapTy());

54 VTableAddressPoints.back()));

55 }

56

58 for (const VTTComponent *i = Builder.getVTTComponents().begin(),

59 *e = Builder.getVTTComponents().end(); i != e; ++i) {

60 const VTTVTable &VTTVT = Builder.getVTTVTables()[i->VTableIndex];

61 llvm::GlobalVariable *VTable = VTables[i->VTableIndex];

63 if (VTTVT.getBase() == RD) {

64

65 AddressPoint =

67 i->VTableBase);

68 } else {

69 AddressPoint = VTableAddressPoints[i->VTableIndex].lookup(i->VTableBase);

71 "Did not find ctor vtable address point!");

72 }

73

74 llvm::Value *Idxs[] = {

75 llvm::ConstantInt::get(CGM.Int32Ty, 0),

78 };

79

80

81

82 unsigned ComponentSize =

83 CGM.getDataLayout().getTypeAllocSize(getVTableComponentType());

84 unsigned VTableSize = CGM.getDataLayout().getTypeAllocSize(

85 castllvm::StructType(VTable->getValueType())

86 ->getElementType(AddressPoint.VTableIndex));

88 llvm::ConstantRange InRange(

89 llvm::APInt(32, (int)-Offset, true),

90 llvm::APInt(32, (int)(VTableSize - Offset), true));

91 llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(

92 VTable->getValueType(), VTable, Idxs, true, InRange);

93

94 if (const auto &Schema =

98

99 VTTComponents.push_back(Init);

100 }

101

102 llvm::Constant *Init = llvm::ConstantArray::get(ArrayType, VTTComponents);

103

104 VTT->setInitializer(Init);

105

106

107 VTT->setLinkage(Linkage);

108

110 VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));

111

112

113

114

116}

117

119 assert(RD->getNumVBases() && "Only classes with virtual bases need a VTT");

120

122 llvm::raw_svector_ostream Out(OutName);

124 .mangleCXXVTT(RD, Out);

125 StringRef Name = OutName.str();

126

127

129

131

132 llvm::ArrayType *ArrayType = llvm::ArrayType::get(

135

137 Name, ArrayType, llvm::GlobalValue::ExternalLinkage, Align);

138 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);

140 return GV;

141}

142

145 BaseSubobjectPairTy ClassSubobjectPair(RD, Base);

146

147 SubVTTIndicesMapTy::iterator I = SubVTTIndices.find(ClassSubobjectPair);

148 if (I != SubVTTIndices.end())

149 return I->second;

150

152

153 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator

154 I = Builder.getSubVTTIndices().begin(),

155 E = Builder.getSubVTTIndices().end();

156 I != E; ++I) {

157

158 BaseSubobjectPairTy ClassSubobjectPair(RD, I->first);

159

160 SubVTTIndices.insert(std::make_pair(ClassSubobjectPair, I->second));

161 }

162

163 I = SubVTTIndices.find(ClassSubobjectPair);

164 assert(I != SubVTTIndices.end() && "Did not find index!");

165

166 return I->second;

167}

168

169uint64_t

172 SecondaryVirtualPointerIndicesMapTy::iterator I =

173 SecondaryVirtualPointerIndices.find(std::make_pair(RD, Base));

174

175 if (I != SecondaryVirtualPointerIndices.end())

176 return I->second;

177

179

180

181 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =

182 Builder.getSecondaryVirtualPointerIndices().begin(),

183 E = Builder.getSecondaryVirtualPointerIndices().end(); I != E; ++I) {

184 std::pair<const CXXRecordDecl *, BaseSubobject> Pair =

185 std::make_pair(RD, I->first);

186

187 SecondaryVirtualPointerIndices.insert(std::make_pair(Pair, I->second));

188 }

189

190 I = SecondaryVirtualPointerIndices.find(std::make_pair(RD, Base));

191 assert(I != SecondaryVirtualPointerIndices.end() && "Did not find index!");

192

193 return I->second;

194}

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.

PointerAuthOptions PointerAuth

Configuration for pointer-signing.

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...

MangleContext & getMangleContext()

Gets the mangle context.

This class organizes the cross-function state that is used while generating LLVM code.

void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const

Set visibility, dllimport/dllexport and dso_local.

llvm::Module & getModule() const

const llvm::DataLayout & getDataLayout() const

CGCXXABI & getCXXABI() const

ASTContext & getContext() const

bool supportsCOMDAT() const

const CodeGenOptions & getCodeGenOpts() const

llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, llvm::Align Alignment)

Will return a global variable of the given type.

llvm::Constant * getConstantSignedPointer(llvm::Constant *Pointer, const PointerAuthSchema &Schema, llvm::Constant *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)

Sign a constant pointer using the given scheme, producing a constant with the same IR type.

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...

void EmitVTTDefinition(llvm::GlobalVariable *VTT, llvm::GlobalVariable::LinkageTypes Linkage, const CXXRecordDecl *RD)

EmitVTTDefinition - Emit the definition of the given vtable.

GlobalDecl - represents a global declaration.

const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)

A (possibly-)qualified type.

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

The JSON file list parser is used to communicate input to InstallAPI.

Linkage

Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.

llvm::PointerType * GlobalsInt8PtrTy

llvm::IntegerType * Int32Ty

PointerAuthSchema CXXVTTVTablePointers

The ABI for C++ virtual table pointers as installed in a VTT.

unsigned AddressPointIndex