Go to the documentation of this file.
25 #include "llvm/Support/SaveAndRestore.h"
27 using namespace clang;
28 using namespace CodeGen;
55 llvm::Value *BaseValue,
57 unsigned CVRQualifiers,
70 V = CGF.
Builder.CreateBitCast(
V, llvm::PointerType::getUnqual(LTy));
89 uint64_t FieldBitOffset =
95 llvm::alignTo(BitOffset + BitFieldSize, AlignmentBits));
119 struct CatchHandler {
122 llvm::BasicBlock *
Block;
129 CallObjCEndCatch(
bool MightThrow, llvm::FunctionCallee Fn)
130 : MightThrow(MightThrow), Fn(Fn) {}
132 llvm::FunctionCallee Fn;
145 llvm::FunctionCallee beginCatchFn,
146 llvm::FunctionCallee endCatchFn,
147 llvm::FunctionCallee exceptionRethrowFn) {
150 if (S.getNumCatchStmts())
158 FinallyInfo.
enter(CGF, Finally->getFinallyBody(),
159 beginCatchFn, endCatchFn, exceptionRethrowFn);
165 if (S.getNumCatchStmts()) {
167 const VarDecl *CatchDecl = CatchStmt->getCatchParamDecl();
169 Handlers.push_back(CatchHandler());
170 CatchHandler &Handler = Handlers.back();
171 Handler.Variable = CatchDecl;
172 Handler.Body = CatchStmt->getCatchBody();
179 Handler.TypeInfo = catchAll.RTTI;
180 Handler.Flags = catchAll.Flags;
189 for (
unsigned I = 0, E = Handlers.size(); I != E; ++I)
190 Catch->
setHandler(I, { Handlers[I].TypeInfo, Handlers[I].Flags }, Handlers[I].Block);
199 const Stmt *FinallyBlock = Finally->getFinallyBody();
207 llvm::Function *FinallyFunc = HelperCGF.
CurFn;
219 if (S.getNumCatchStmts())
223 CGBuilderTy::InsertPoint SavedIP = CGF.
Builder.saveAndClearIP();
226 for (
unsigned I = 0, E = Handlers.size(); I != E; ++I) {
227 CatchHandler &Handler = Handlers[I];
230 llvm::CatchPadInst *CPI =
nullptr;
233 if ((CPI = dyn_cast_or_null<llvm::CatchPadInst>(Handler.Block->getFirstNonPHI()))) {
240 llvm::Value *Exn = RawExn;
248 bool EndCatchMightThrow = (Handler.Variable ==
nullptr);
256 if (
const VarDecl *CatchParam = Handler.Variable) {
257 llvm::Type *CatchType = CGF.
ConvertType(CatchParam->getType());
258 llvm::Value *CastExn = CGF.
Builder.CreateBitCast(Exn, CatchType);
277 CGF.
Builder.restoreIP(SavedIP);
280 if (!useFunclets && S.getFinallyStmt())
281 FinallyInfo.
exit(CGF);
308 llvm_unreachable(
"invalid ownership qualifier");
313 llvm::FunctionCallee SyncExitFn;
314 llvm::Value *SyncArg;
315 CallSyncExit(llvm::FunctionCallee SyncExitFn, llvm::Value *SyncArg)
316 : SyncExitFn(SyncExitFn), SyncArg(SyncArg) {}
326 llvm::FunctionCallee syncEnterFn,
327 llvm::FunctionCallee syncExitFn) {
332 const Expr *lockExpr = S.getSynchExpr();
343 CGF.
Builder.CreateCall(syncEnterFn, lock)->setDoesNotThrow();
368 llvm::PointerType *signatureType =
382 llvm::PointerType *signatureType =
391 llvm::Value *receiver) {
405 dyn_cast_or_null<ObjCMethodDecl>(CGF.
CurCodeDecl)) {
406 auto self = curMethod->getSelfDecl();
407 if (self->getType().isConstQualified()) {
408 if (
auto LI = dyn_cast<llvm::LoadInst>(receiver->stripPointerCasts())) {
410 if (selfAddr == LI->getPointerOperand()) {
423 if (
ID->isWeakImported())
425 }
while ((
ID =
ID->getSuperClass()));
433 CallArgList::const_iterator I =
callArgs.begin();
437 if (param->
hasAttr<NSConsumedAttr>()) {
438 RValue RV = I->getRValue(CGF);
440 "NullReturnState::complete - arg not on object");
445 if (RT && RT->getDecl()->isParamDestroyedInCallee()) {
446 RValue RV = I->getRValue(CGF);
456 llvm_unreachable(
"unexpected dtor kind");
471 bool includeCategoryName) {
473 llvm::raw_string_ostream out(buffer);
476 includeCategoryName);
Represents an ObjC class declaration.
static Destroyer destroyCXXObject
void mangleObjCMethodName(const ObjCMethodDecl *MD, raw_ostream &OS, bool includePrefixByte=true, bool includeCategoryNamespace=true)
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
unsigned getBitWidthValue(const ASTContext &Ctx) const
llvm::PointerType * Int8PtrTy
A class controlling the emission of a finally block.
CodeGen::CodeGenModule & CGM
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
Produce the code for a CK_ARCConsumeObject.
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
const CGFunctionInfo & arrangeUnprototypedObjCMessageSend(QualType returnType, const CallArgList &args)
void EmitAtSynchronizedStmt(CodeGenFunction &CGF, const ObjCAtSynchronizedStmt &S, llvm::FunctionCallee syncEnterFn, llvm::FunctionCallee syncExitFn)
Emits an @synchronize() statement, using the syncEnterFn and syncExitFn arguments as the functions ca...
@ OCL_Weak
Reading or writing from this object requires a barrier call.
static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Create a new object to represent a bit-field access.
LValue EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, const ObjCInterfaceDecl *OID, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers, llvm::Value *Offset)
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
MangleContext & getMangleContext()
Gets the mangle context.
class EHCatchScope * pushCatch(unsigned NumHandlers)
Push a set of catch handlers on the stack.
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
void enter(CodeGenFunction &CGF, const Stmt *Finally, llvm::FunctionCallee beginCatchFn, llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn)
Enters a finally block for an implementation using zero-cost exceptions.
A (possibly-)qualified type.
ASTContext & getContext() const
Represents a parameter to a function.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Represents Objective-C's @try ... @catch ... @finally statement.
MessageSendInfo getMessageSendInfo(const ObjCMethodDecl *method, QualType resultType, CallArgList &callArgs)
Compute the pointer-to-function type to which a message send should be casted in order to correctly c...
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
void popCatchScope()
popCatchScope - Pops the catch scope at the top of the EHScope stack, emitting any required code (oth...
param_const_iterator param_end() const
static void destroyCalleeDestroyedArguments(CodeGenFunction &CGF, const ObjCMethodDecl *method, const CallArgList &callArgs)
Destroy the callee-destroyed arguments of the given method, if it has any.
const CGFunctionInfo & arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD, QualType receiverType)
Arrange the argument and result information for the function type through which to perform a send to ...
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=None)
EmitStmt - Emit the code for the statement.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
llvm::BasicBlock * getBlock() const
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
const ObjCInterfaceDecl * getClassInterface() const
llvm::PointerType * VoidPtrTy
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
bool usesFuncletPads() const
Does this personality use landingpads or the family of pad instructions designed to form funclets?
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
Represents Objective-C's @catch statement.
A scope which attempts to handle some, possibly all, types of exceptions.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
llvm::Constant * emitObjCProtocolObject(CodeGenModule &CGM, const ObjCProtocolDecl *p)
Get a pointer to a protocol object for the given declaration, emitting it if it hasn't already been e...
Information for lazily generating a cleanup.
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc)
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
const NamedDecl * CurSEHParent
std::string getSymbolNameForMethod(const ObjCMethodDecl *method, bool includeCategoryName=true)
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
const T * getAs() const
Member-template getAs<specific type>'.
Address getExceptionSlot()
Returns a pointer to the function's exception object and selector slot, which is assigned in every la...
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
Represents Objective-C's @synchronized statement.
SourceLocation getEndLoc() const LLVM_READONLY
Represents a variable declaration or definition.
static CGBitFieldInfo MakeInfo(class CodeGenTypes &Types, const FieldDecl *FD, uint64_t Offset, uint64_t Size, uint64_t StorageSize, CharUnits StorageOffset)
Given a bit-field decl, build an appropriate helper object for accessing that field (which is expecte...
CodeGenTypes & getTypes()
Represents Objective-C's @finally statement.
llvm::LLVMContext & getLLVMContext()
ASTContext & getContext() const
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
void EmitInitOfCatchParam(CodeGenFunction &CGF, llvm::Value *exn, const VarDecl *paramDecl)
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
EmitARCRetainScalarExpr - Semantically equivalent to EmitARCRetainObject(e->getType(),...
const TargetInfo & getTarget() const
QualType withCVRQualifiers(unsigned CVR) const
Structure with information about how a bitfield should be accessed.
void setHandler(unsigned I, llvm::Constant *Type, llvm::BasicBlock *Block)
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
LValue - This represents an lvalue references.
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
bool isBitField() const
Determines whether this field is a bitfield.
llvm::Value * getPointer() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CGCXXABI & getCXXABI() const
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Value * getExceptionFromSlot()
Returns the contents of the function's exception object and selector slots.
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
unsigned ComputeBitfieldBitOffset(CodeGen::CodeGenModule &CGM, const ObjCInterfaceDecl *ID, const ObjCIvarDecl *Ivar)
llvm::Type * ConvertType(QualType T)
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
bool canMessageReceiverBeNull(CodeGenFunction &CGF, const ObjCMethodDecl *method, bool isSuper, const ObjCInterfaceDecl *classReceiver, llvm::Value *receiver)
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
static Destroyer destroyNonTrivialCStruct
CGFunctionInfo - Class to encapsulate the information about a function definition.
SmallVector< llvm::Value *, 8 > ObjCEHValueStack
ObjCEHValueStack - Stack of Objective-C exception values, used for rethrows.
ObjCMethodDecl - Represents an instance or class method declaration.
@ OCL_None
There is no lifetime qualification on this type.
param_const_iterator param_begin() const
virtual CatchTypeInfo getCatchAllTypeInfo()
A jump destination is an abstract label, branching to which may require a jump out through normal cle...
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
ObjCLifetime getObjCLifetime() const
Stmt - This represents one statement.
ObjCIvarDecl - Represents an ObjC instance variable.
virtual llvm::Constant * GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0
GetOrEmitProtocol - Get the protocol object for the given declaration, emitting it if necessary.
static bool isWeakLinkedClass(const ObjCInterfaceDecl *cls)
Represents an Objective-C protocol declaration.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, const Stmt *OutlinedStmt)
Arrange a function prototype that can be called by Windows exception handling personalities.
unsigned getCharAlign() const
llvm::Instruction * CurrentFuncletPad
const CGFunctionInfo & arrangeCall(const CGFunctionInfo &declFI, const CallArgList &args)
Given a function info for a declaration, return the function info for a call with the given arguments...
uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID, const ObjCImplementationDecl *ID, const ObjCIvarDecl *Ivar) const
Get the offset of an ObjCIvarDecl in bits.
void EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
CharUnits - This is an opaque type for sizes expressed in character units.
uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM, const ObjCInterfaceDecl *OID, const ObjCIvarDecl *Ivar)
Compute an offset to the given ivar, suitable for passing to EmitValueForIvarAtOffset.
void EmitTryCatchStmt(CodeGenFunction &CGF, const ObjCAtTryStmt &S, llvm::FunctionCallee beginCatchFn, llvm::FunctionCallee endCatchFn, llvm::FunctionCallee exceptionRethrowFn)
Emits a try / catch statement.
QualType getUsageType(QualType objectType) const
Retrieve the type of this instance variable when viewed as a member of a specific object type.
This represents one expression.
void exit(CodeGenFunction &CGF)
const Type * getTypeForDecl() const
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
bool isClassMethod() const
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
CallArgList - Type for representing both the value and type of arguments in a call.
virtual llvm::Constant * GetEHType(QualType T)=0
Get the type constant to catch for the given ObjC pointer type.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
const LangOptions & getLangOpts() const
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.