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

1

2

3

4

5

6

7

8

9

10

11

12

13

17

18using namespace clang;

19using namespace CodeGen;

20

22

26 CGF.CXXABIThisAlignment);

27}

28

32 "cannot yet compile %0 in this ABI");

34 DiagID)

35 << S;

36}

37

40}

41

42llvm::Type *

45}

46

49 llvm::Value *&ThisPtrForCall,

52

53 const auto *RD =

55 ThisPtrForCall =

59 llvm::Constant *FnPtr = llvm::Constant::getNullValue(

62}

63

64llvm::Value *

69 llvm::Type *Ty =

71 return llvm::Constant::getNullValue(Ty);

72}

73

76 llvm::Value *Src) {

79}

80

82 llvm::Constant *Src) {

84}

85

86llvm::Value *

88 llvm::Value *L,

89 llvm::Value *R,

91 bool Inequality) {

93 return CGF.Builder.getFalse();

94}

95

96llvm::Value *

98 llvm::Value *MemPtr,

101 return CGF.Builder.getFalse();

102}

103

104llvm::Constant *

107}

108

112}

113

117}

118

121}

122

124

125 return true;

126}

127

130

131

132

133 auto *ThisDecl =

137 params.push_back(ThisDecl);

138 CGF.CXXABIThisDecl = ThisDecl;

139

140

141

146 CGF.CXXABIThisAlignment = Layout.getAlignment();

147 } else {

148 CGF.CXXABIThisAlignment = Layout.getNonVirtualAlignment();

149 }

150}

151

154 "this");

155}

156

158

159 assert(getThisDecl(CGF) && "no 'this' variable for function");

160 CGF.CXXABIThisValue = ThisPtr;

161}

162

165 return true;

166

167

168

171 return true;

172

173 return false;

174}

175

177 const VarDecl *VD, bool InspectInitForWeakDef) const {

179 if (VD->hasAttr())

180 return true;

181

182

183

184 if (!InspectInitForWeakDef && (VD->isWeak() || VD->hasAttr()))

185 return false;

186

188 if (!InitDecl)

189 return false;

190

191

192 if (!InitDecl->hasInit())

193 return true;

194

195

196

199

200

201

202

203

204

206}

207

211 "cannot handle aggregates");

212 CGF.EmitReturnOfRValue(RV, ResultType);

213}

214

219}

220

222

224}

225

228 llvm::Value *NumElements,

231

234}

235

238

239

240 if (expr->doesUsualArrayDeleteWantSize())

241 return true;

242

244}

245

247

248

249 if (expr->doesUsualArrayDeleteWantSize())

250 return true;

251

252 return expr->getAllocatedType().isDestructedType();

253}

254

257 llvm::Value *&numElements,

258 llvm::Value *&allocPtr, CharUnits &cookieSize) {

259

261

262

265 numElements = nullptr;

267 return;

268 }

269

274}

275

280 return llvm::ConstantInt::get(CGF.SizeTy, 0);

281}

282

283

284

285

287 assert(E->getCastKind() == CK_DerivedToBaseMemberPointer ||

288 E->getCastKind() == CK_BaseToDerivedMemberPointer);

289

291 if (E->getCastKind() == CK_DerivedToBaseMemberPointer)

292 derivedType = E->getSubExpr()->getType();

293 else

295

298

300 E->path_begin(),

301 E->path_end());

302}

303

304llvm::BasicBlock *

308 llvm_unreachable("shouldn't be called in this ABI");

309

311 return nullptr;

312}

313

317

319}

320

323

325}

326

328 return false;

329}

330

331llvm::CallInst *

333 llvm::Value *Exn) {

334

336}

337

340}

341

343 return std::vector();

344}

345

351 for (size_t i = 0; i < AddedArgs.Prefix.size(); ++i) {

352 Args.insert(Args.begin() + 1 + i,

354 AddedArgs.Prefix[i].Type));

355 }

356 for (const auto &arg : AddedArgs.Suffix) {

358 }

360 AddedArgs.Suffix.size());

361}

APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...

QualType getMemberPointerType(QualType T, const Type *Cls) const

Return the uniqued reference to the type for a member pointer to the specified type in the specified ...

QualType getRecordType(const RecordDecl *Decl) const

const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const

Get or compute information about the layout of the specified record (struct/union/class) D,...

FullSourceLoc getFullLoc(SourceLocation Loc) const

QualType getPointerDiffType() const

Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.

Represents a C++ constructor within a class.

Represents a delete expression for memory deallocation and destructor calls, e.g.

Represents a C++ destructor within a class.

Represents a static or instance method of a struct/union/class.

const CXXRecordDecl * getParent() const

Return the parent of this method declaration, which is the class in which this method is defined.

QualType getThisType() const

Return the type of the this pointer.

Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".

Represents a C++ struct/union/class.

bool isEffectivelyFinal() const

Determine whether it's impossible for a class to be derived from this class.

unsigned getNumVBases() const

Retrieves the number of virtual base classes of this class.

CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...

CharUnits - This is an opaque type for sizes expressed in character units.

static CharUnits Zero()

Zero - Construct a CharUnits quantity of zero.

Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...

llvm::Value * emitRawPointer(CodeGenFunction &CGF) const

Return the pointer contained in this class after authenticating it and adding offset to it if necessa...

Address withElementType(llvm::Type *ElemTy) const

Return address with different element type, but same pointer and alignment.

Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")

Given a pointer to i8, adjust it by a given constant offset.

llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")

llvm::Constant * getMemberPointerAdjustment(const CastExpr *E)

A utility method for computing the offset required for the given base-to-derived or derived-to-base m...

virtual std::vector< CharUnits > getVBPtrOffsets(const CXXRecordDecl *RD)

Gets the offsets of all the virtual base pointers in a given class.

virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, const CXXDeleteExpr *expr, QualType ElementType, llvm::Value *&NumElements, llvm::Value *&AllocPtr, CharUnits &CookieSize)

Reads the array cookie associated with the given pointer, if it has one.

virtual void setCXXDestructorDLLStorage(llvm::GlobalValue *GV, const CXXDestructorDecl *Dtor, CXXDtorType DT) const

virtual bool NeedsVTTParameter(GlobalDecl GD)

Return whether the given global decl needs a VTT parameter.

virtual llvm::CallInst * emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn)

ImplicitParamDecl * getThisDecl(CodeGenFunction &CGF)

virtual llvm::Type * ConvertMemberPointerType(const MemberPointerType *MPT)

Find the LLVM type used to represent the given member pointer type.

virtual llvm::Constant * EmitNullMemberPointer(const MemberPointerType *MPT)

Create a null member pointer of the given type.

virtual CharUnits getArrayCookieSizeImpl(QualType elementType)

Returns the extra size required in order to store the array cookie for the given type.

virtual void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResultType)

void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)

Build a parameter variable suitable for 'this'.

virtual llvm::Value * EmitMemberPointerIsNotNull(CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)

Determine if a member pointer is non-null. Returns an i1.

bool isEmittedWithConstantInitializer(const VarDecl *VD, bool InspectInitForWeakDef=false) const

Determine whether we will definitely emit this variable with a constant initializer,...

virtual llvm::Value * EmitMemberPointerComparison(CodeGenFunction &CGF, llvm::Value *L, llvm::Value *R, const MemberPointerType *MPT, bool Inequality)

Emit a comparison between two member pointers. Returns an i1.

virtual llvm::Constant * EmitMemberPointer(const APValue &MP, QualType MPT)

Create a member pointer for the given member pointer constant.

Address getThisAddress(CodeGenFunction &CGF)

virtual llvm::Value * readArrayCookieImpl(CodeGenFunction &IGF, Address ptr, CharUnits cookieSize)

Reads the array cookie for an allocation which is known to have one.

virtual llvm::Value * EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, Address Base, llvm::Value *MemPtr, const MemberPointerType *MPT)

Calculate an l-value from an object and a data member pointer.

virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType)

virtual CatchTypeInfo getCatchAllTypeInfo()

bool mayNeedDestruction(const VarDecl *VD) const

virtual llvm::BasicBlock * EmitCtorCompleteObjectHandler(CodeGenFunction &CGF, const CXXRecordDecl *RD)

virtual bool isThisCompleteObject(GlobalDecl GD) const =0

Determine whether there's something special about the rules of the ABI tell us that 'this' is a compl...

void setCXXABIThisValue(CodeGenFunction &CGF, llvm::Value *ThisPtr)

llvm::Value * loadIncomingCXXThis(CodeGenFunction &CGF)

Loads the incoming C++ this pointer as it was passed by the caller.

void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S)

Issue a diagnostic about unsupported features in the ABI.

virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)

Create a member pointer for the given field.

llvm::Constant * GetBogusMemberPointer(QualType T)

Get a null value for unsupported member pointers.

virtual CGCallee EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, const Expr *E, Address This, llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, const MemberPointerType *MPT)

Load a member function from an object and a member function pointer.

virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)

Returns the extra size required in order to store the array cookie for the given new-expression.

virtual bool isZeroInitializable(const MemberPointerType *MPT)

Return true if the given member pointer can be zero-initialized (in the C++ sense) with an LLVM zeroi...

AddedStructorArgCounts addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, CallArgList &Args)

Add any ABI-specific implicit arguments needed to call a constructor.

virtual llvm::Value * EmitMemberPointerConversion(CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)

Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion.

virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)

Create a member pointer for the given method.

virtual llvm::GlobalValue::LinkageTypes getCXXDestructorLinkage(GVALinkage Linkage, const CXXDestructorDecl *Dtor, CXXDtorType DT) const

virtual Address InitializeArrayCookie(CodeGenFunction &CGF, Address NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)

Initialize the array cookie for the given allocation.

ASTContext & getContext() const

virtual AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating)=0

All available information about a concrete callee.

static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())

CallArgList - Type for representing both the value and type of arguments in a call.

void add(RValue rvalue, QualType type)

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

GlobalDecl CurGD

CurGD - The GlobalDecl for the current function being compiled.

llvm::Value * getAsNaturalPointerTo(Address Addr, QualType PointeeType)

Address makeNaturalAddressForPointer(llvm::Value *Ptr, QualType T, CharUnits Alignment=CharUnits::Zero(), bool ForPointeeType=false, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)

Construct an address with the natural alignment of T.

const Decl * CurCodeDecl

CurCodeDecl - This is the inner-most code context, which includes blocks.

llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")

ASTContext & getContext() const

static bool hasAggregateEvaluationKind(QualType T)

Address GetAddrOfLocalVar(const VarDecl *VD)

GetAddrOfLocalVar - Return the address of a local variable.

llvm::LLVMContext & getLLVMContext()

DiagnosticsEngine & getDiags() const

llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage)

Returns LLVM linkage for a declarator.

CodeGenTypes & getTypes()

const TargetInfo & getTarget() const

llvm::Constant * GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd)

Returns the offset from a derived class to a class.

ASTContext & getContext() const

llvm::FunctionCallee getTerminateFn()

Get the declaration of std::terminate for the platform.

llvm::LLVMContext & getLLVMContext()

void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const

llvm::Type * ConvertType(QualType T)

ConvertType - Convert type T into a llvm::Type.

FunctionArgList - Type for representing both the decl and type of parameters to a function.

RValue - This trivial value class is used to represent the result of an expression that is evaluated.

static RValue get(llvm::Value *V)

SourceLocation getLocation() const

Concrete class used by the front-end to report problems and issues.

DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)

Issue the message to the client.

unsigned getCustomDiagID(Level L, const char(&FormatString)[N])

Return an ID for a diagnostic with the specified format string and level.

This represents one expression.

Represents a prototype with parameter type info, e.g.

GlobalDecl - represents a global declaration.

const Decl * getDecl() const

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)

Create implicit parameter.

A pointer to member type per C++ 8.3.3 - Pointers to members.

QualType getPointeeType() const

const Type * getClass() const

A (possibly-)qualified type.

DestructionKind isDestructedType() const

Returns a nonzero value if objects of this type require non-trivial work to clean up after.

A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...

RecordDecl * getDecl() const

decl_type * getMostRecentDecl()

Returns the most recent (re)declaration of this declaration.

bool hasConstructorVariants() const

Does this ABI have different entrypoints for complete-object and base-subobject constructors?

TargetCXXABI getCXXABI() const

Get the C++ ABI currently in use.

const Type * getTypeForDecl() const

The base class of the type hierarchy.

CXXRecordDecl * getAsCXXRecordDecl() const

Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...

const T * castAs() const

Member-template castAs.

QualType getPointeeType() const

If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.

const Type * getBaseElementTypeUnsafe() const

Get the base element type of this type, potentially discarding type qualifiers.

bool isIncompleteType(NamedDecl **Def=nullptr) const

Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...

const T * getAs() const

Member-template getAs'.

bool isWeak() const

Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.

Represents a variable declaration or definition.

APValue * evaluateValue() const

Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...

bool hasConstantInitialization() const

Determine whether this variable has constant initialization.

QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const

Would the destruction of this variable have any effect, and if so, what kind?

VarDecl * getInitializingDeclaration()

Get the initializing declaration of this variable, if any.

const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr

Matches expressions.

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

CXXCtorType

C++ constructor types.

GVALinkage

A more specific kind of linkage than enum Linkage.

bool isUniqueGVALinkage(GVALinkage L)

Do we know that this will be the only definition of this symbol (excluding inlining-only definitions)...

Linkage

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

CXXDtorType

C++ destructor types.

const FunctionProtoType * T

@ CXXThis

Parameter for C++ 'this' argument.

Similar to AddedStructorArgs, but only notes the number of additional arguments.

Additional implicit arguments to add to the beginning (Prefix) and end (Suffix) of a constructor / de...

SmallVector< Arg, 1 > Prefix

SmallVector< Arg, 1 > Suffix

The MS C++ ABI needs a pointer to RTTI data plus some flags to describe the type of a catch handler,...

llvm::IntegerType * Int8Ty

i8, i16, i32, and i64

llvm::IntegerType * SizeTy