21 #include "llvm/IR/CallSite.h"
22 #include "llvm/IR/Intrinsics.h"
24 using namespace clang;
25 using namespace CodeGen;
31 assert(CE ==
nullptr || isa<CXXMemberCallExpr>(CE) ||
32 isa<CXXOperatorCallExpr>(CE));
34 "Trying to emit a member or operator call expr on a static method!");
61 unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0;
67 "No CallExpr specified for function with non-zero number of arguments");
79 *
this, MD, Callee, ReturnValue, This, ImplicitParam, ImplicitParamTy, CE,
91 ImplicitParam, ImplicitParamTy, CE, Args);
101 return cast<CXXRecordDecl>(Ty->
getDecl());
110 if (isa<BinaryOperator>(callee))
113 const MemberExpr *ME = cast<MemberExpr>(callee);
116 if (MD->isStatic()) {
129 CE, MD, ReturnValue, HasQualifier, Qualifier, IsArrow, Base);
136 assert(isa<CXXMemberCallExpr>(CE) || isa<CXXOperatorCallExpr>(CE));
139 bool CanUseVirtualCall = MD->
isVirtual() && !HasQualifier;
145 assert(DevirtualizedMethod);
155 DevirtualizedMethod =
nullptr;
165 DevirtualizedMethod =
nullptr;
177 if (isa<CXXDestructorDecl>(MD))
return RValue::get(
nullptr);
178 if (isa<CXXConstructorDecl>(MD) &&
179 cast<CXXConstructorDecl>(MD)->isDefaultConstructor())
187 unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0;
194 if (isa<CXXConstructorDecl>(MD) &&
195 cast<CXXConstructorDecl>(MD)->isCopyOrMoveConstructor()) {
197 assert(CE->
getNumArgs() == 1 &&
"unexpected argcount for trivial ctor");
202 llvm_unreachable(
"unknown trivial member function");
208 DevirtualizedMethod ? DevirtualizedMethod : MD;
210 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl))
213 else if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(CalleeDecl))
227 bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod;
232 "Destructor shouldn't have explicit parameters");
233 assert(ReturnValue.
isNull() &&
"Destructor shouldn't have return value");
234 if (UseVirtualCall) {
236 *
this, Dtor,
Dtor_Complete, This, cast<CXXMemberCallExpr>(CE));
240 else if (!DevirtualizedMethod)
245 cast<CXXDestructorDecl>(DevirtualizedMethod);
256 }
else if (UseVirtualCall) {
268 else if (!DevirtualizedMethod)
277 *
this, MD, This, UseVirtualCall);
339 "Trying to emit a member call expr on a static method!");
341 E, MD, ReturnValue,
false,
nullptr,
373 llvm::GlobalVariable *NullVariable =
374 new llvm::GlobalVariable(CGF.
CGM.
getModule(), NullConstant->getType(),
376 llvm::GlobalVariable::PrivateLinkage,
377 NullConstant, Twine());
389 CGF.
Builder.CreateMemSet(DestPtr, CGF.
Builder.getInt8(0), SizeVal,
396 assert(!Dest.
isIgnored() &&
"Must have a destination!");
417 if (CD->isTrivial() && CD->isDefaultConstructor())
437 bool ForVirtualBase =
false;
438 bool Delegating =
false;
452 ForVirtualBase =
true;
470 Exp = E->getSubExpr();
471 assert(isa<CXXConstructExpr>(Exp) &&
472 "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr");
485 &&
"EmitSynthesizedCXXCopyCtor - Copied-in Array");
504 unsigned minElements,
513 return sizeWithoutCookie;
517 unsigned sizeWidth = CGF.
SizeTy->getBitWidth();
520 llvm::APInt cookieSize(sizeWidth,
527 assert(isa<llvm::IntegerType>(numElements->getType()));
537 llvm::IntegerType *numElementsType
538 = cast<llvm::IntegerType>(numElements->getType());
539 unsigned numElementsWidth = numElementsType->getBitWidth();
542 llvm::APInt arraySizeMultiplier(sizeWidth, 1);
545 type = CAT->getElementType();
546 arraySizeMultiplier *= CAT->getSize();
550 llvm::APInt typeSizeMultiplier(sizeWidth, typeSize.
getQuantity());
551 typeSizeMultiplier *= arraySizeMultiplier;
558 if (llvm::ConstantInt *numElementsC =
559 dyn_cast<llvm::ConstantInt>(numElements)) {
560 const llvm::APInt &count = numElementsC->getValue();
562 bool hasAnyOverflow =
false;
565 if (isSigned && count.isNegative())
566 hasAnyOverflow =
true;
571 else if (numElementsWidth > sizeWidth &&
572 numElementsWidth - sizeWidth > count.countLeadingZeros())
573 hasAnyOverflow =
true;
576 llvm::APInt adjustedCount = count.zextOrTrunc(sizeWidth);
580 if (adjustedCount.ult(minElements))
581 hasAnyOverflow =
true;
586 numElements = llvm::ConstantInt::get(CGF.
SizeTy,
587 adjustedCount * arraySizeMultiplier);
591 llvm::APInt allocationSize
592 = adjustedCount.umul_ov(typeSizeMultiplier, overflow);
593 hasAnyOverflow |= overflow;
596 if (cookieSize != 0) {
599 sizeWithoutCookie = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
601 allocationSize = allocationSize.uadd_ov(cookieSize, overflow);
602 hasAnyOverflow |= overflow;
606 if (hasAnyOverflow) {
607 size = llvm::Constant::getAllOnesValue(CGF.
SizeTy);
609 size = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
632 if (numElementsWidth > sizeWidth) {
633 llvm::APInt threshold(numElementsWidth, 1);
634 threshold <<= sizeWidth;
637 = llvm::ConstantInt::get(numElementsType, threshold);
639 hasOverflow = CGF.
Builder.CreateICmpUGE(numElements, thresholdV);
640 numElements = CGF.
Builder.CreateTrunc(numElements, CGF.
SizeTy);
643 }
else if (isSigned) {
644 if (numElementsWidth < sizeWidth)
645 numElements = CGF.
Builder.CreateSExt(numElements, CGF.
SizeTy);
652 if (typeSizeMultiplier == 1)
653 hasOverflow = CGF.
Builder.CreateICmpSLT(numElements,
654 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
657 }
else if (numElementsWidth < sizeWidth) {
658 numElements = CGF.
Builder.CreateZExt(numElements, CGF.
SizeTy);
661 assert(numElements->getType() == CGF.
SizeTy);
666 hasOverflow = CGF.
Builder.CreateICmpULT(numElements,
667 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
668 }
else if (numElementsWidth > sizeWidth) {
672 hasOverflow = CGF.
Builder.CreateOr(hasOverflow,
673 CGF.
Builder.CreateICmpULT(numElements,
674 llvm::ConstantInt::get(CGF.
SizeTy, minElements)));
687 if (typeSizeMultiplier != 1) {
692 llvm::ConstantInt::get(CGF.
SizeTy, typeSizeMultiplier);
694 CGF.
Builder.CreateCall(umul_with_overflow, {size, tsmV});
698 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
700 hasOverflow = overflowed;
702 size = CGF.
Builder.CreateExtractValue(result, 0);
705 if (arraySizeMultiplier != 1) {
708 if (typeSize.
isOne()) {
709 assert(arraySizeMultiplier == typeSizeMultiplier);
715 llvm::ConstantInt::get(CGF.
SizeTy, arraySizeMultiplier);
716 numElements = CGF.
Builder.CreateMul(numElements, asmV);
721 assert(arraySizeMultiplier == 1);
725 if (cookieSize != 0) {
726 sizeWithoutCookie = size;
733 CGF.
Builder.CreateCall(uadd_with_overflow, {size, cookieSizeV});
737 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
739 hasOverflow = overflowed;
741 size = CGF.
Builder.CreateExtractValue(result, 0);
748 size = CGF.
Builder.CreateSelect(hasOverflow,
749 llvm::Constant::getAllOnesValue(CGF.
SizeTy),
754 sizeWithoutCookie = size;
756 assert(sizeWithoutCookie &&
"didn't set sizeWithoutCookie?");
785 llvm_unreachable(
"bad evaluation kind");
799 unsigned InitListElements = 0;
802 llvm::AllocaInst *EndOfInit =
nullptr;
805 llvm::Instruction *CleanupDominator =
nullptr;
808 if (
const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
809 InitListElements = ILE->getNumInits();
816 unsigned AS = CurPtr->getType()->getPointerAddressSpace();
818 llvm::Type *AllocPtrTy = ElementTy->getPointerTo(AS);
819 CurPtr =
Builder.CreateBitCast(CurPtr, AllocPtrTy);
830 CleanupDominator =
Builder.CreateStore(BeginPtr, EndOfInit);
836 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
841 Builder.CreateStore(
Builder.CreateBitCast(CurPtr, BeginPtr->getType()),
847 ILE->getInit(i)->getType(), CurPtr);
848 CurPtr =
Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr, 1,
853 Init = ILE->getArrayFiller();
862 assert(SubILE->getNumInits() == 0 &&
"explicit inits in array filler?");
863 Init = SubILE->getArrayFiller();
867 CurPtr =
Builder.CreateBitCast(CurPtr, BeginPtr->getType());
871 auto TryMemsetInitialization = [&]() ->
bool {
881 auto *RemainingSize = AllocSizeWithoutCookie;
882 if (InitListElements) {
884 auto *InitializedSize = llvm::ConstantInt::get(
885 RemainingSize->getType(),
888 RemainingSize =
Builder.CreateSub(RemainingSize, InitializedSize);
900 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
901 if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
903 if (CleanupDominator)
908 assert(Init &&
"have trailing elements to initialize but no initializer");
920 if (TryMemsetInitialization())
928 if (EndOfInit)
Builder.CreateStore(CurPtr, EndOfInit);
931 if (InitListElements)
932 NumElements =
Builder.CreateSub(
934 llvm::ConstantInt::get(NumElements->getType(), InitListElements));
936 CCE->requiresZeroInitialization());
942 if (isa<ImplicitValueInitExpr>(Init)) {
943 if (TryMemsetInitialization())
955 "got wrong type of element to initialize");
958 if (
auto *ILE = dyn_cast<InitListExpr>(Init))
959 if (ILE->getNumInits() == 0 && TryMemsetInitialization())
964 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
966 if (RType->getDecl()->isStruct()) {
967 unsigned NumFields = 0;
968 for (
auto *Field : RType->getDecl()->fields())
969 if (!Field->isUnnamedBitfield())
971 if (ILE->getNumInits() == NumFields)
972 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i)
973 if (!isa<ImplicitValueInitExpr>(ILE->getInit(i)))
975 if (ILE->getNumInits() == NumFields && TryMemsetInitialization())
982 llvm::BasicBlock *EntryBB =
Builder.GetInsertBlock();
988 Builder.CreateInBoundsGEP(BeginPtr, NumElements,
"array.end");
995 Builder.CreateCondBr(IsEmpty, ContBB, LoopBB);
1002 llvm::PHINode *CurPtrPhi =
1003 Builder.CreatePHI(CurPtr->getType(), 2,
"array.cur");
1004 CurPtrPhi->addIncoming(CurPtr, EntryBB);
1008 if (EndOfInit)
Builder.CreateStore(CurPtr, EndOfInit);
1015 CleanupDominator =
Builder.CreateUnreachable();
1022 if (CleanupDominator) {
1024 CleanupDominator->eraseFromParent();
1029 Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr, 1,
"array.next");
1034 Builder.CreateCondBr(IsEnd, ContBB, LoopBB);
1035 CurPtrPhi->addIncoming(NextPtr,
Builder.GetInsertBlock());
1041 QualType ElementType, llvm::Type *ElementTy,
1047 AllocSizeWithoutCookie);
1058 llvm::Instruction *CallOrInvoke;
1062 Args, CalleeType,
false),
1070 llvm::Function *Fn = dyn_cast<llvm::Function>(CalleeAddr);
1071 if (Callee->isReplaceableGlobalAllocationFunction() &&
1072 Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) {
1074 if (llvm::CallInst *CI = dyn_cast<llvm::CallInst>(CallOrInvoke))
1075 CI->addAttribute(llvm::AttributeSet::FunctionIndex,
1076 llvm::Attribute::Builtin);
1077 else if (llvm::InvokeInst *II = dyn_cast<llvm::InvokeInst>(CallOrInvoke))
1078 II->addAttribute(llvm::AttributeSet::FunctionIndex,
1079 llvm::Attribute::Builtin);
1081 llvm_unreachable(
"unexpected kind of call instruction");
1091 const Stmt *ArgS = Arg;
1097 .getCXXOperatorName(IsDelete ? OO_Delete : OO_New);
1099 if (
auto *FD = dyn_cast<FunctionDecl>(
Decl))
1100 if (Ctx.hasSameType(FD->getType(),
QualType(Type, 0)))
1102 llvm_unreachable(
"predeclared global operator new/delete is missing");
1109 size_t NumPlacementArgs;
1114 RValue *getPlacementArgs() {
return reinterpret_cast<RValue*
>(
this+1); }
1117 static size_t getExtraSize(
size_t NumPlacementArgs) {
1118 return NumPlacementArgs *
sizeof(
RValue);
1121 CallDeleteDuringNew(
size_t NumPlacementArgs,
1125 : NumPlacementArgs(NumPlacementArgs), OperatorDelete(OperatorDelete),
1126 Ptr(Ptr), AllocSize(AllocSize) {}
1128 void setPlacementArg(
unsigned I,
RValue Arg) {
1129 assert(I < NumPlacementArgs &&
"index out of range");
1130 getPlacementArgs()[I] = Arg;
1150 for (
unsigned I = 0; I != NumPlacementArgs; ++I)
1151 DeleteArgs.
add(getPlacementArgs()[I], *AI++);
1162 size_t NumPlacementArgs;
1172 static size_t getExtraSize(
size_t NumPlacementArgs) {
1176 CallDeleteDuringConditionalNew(
size_t NumPlacementArgs,
1180 : NumPlacementArgs(NumPlacementArgs), OperatorDelete(OperatorDelete),
1181 Ptr(Ptr), AllocSize(AllocSize) {}
1184 assert(I < NumPlacementArgs &&
"index out of range");
1185 getPlacementArgs()[I] = Arg;
1198 DeleteArgs.
add(Ptr.restore(CGF), *AI++);
1202 RValue RV = AllocSize.restore(CGF);
1203 DeleteArgs.
add(RV, *AI++);
1207 for (
unsigned I = 0; I != NumPlacementArgs; ++I) {
1208 RValue RV = getPlacementArgs()[I].restore(CGF);
1209 DeleteArgs.
add(RV, *AI++);
1228 CallDeleteDuringNew *Cleanup = CGF.
EHStack
1234 Cleanup->setPlacementArg(I, NewArgs[I+1].RV);
1245 CallDeleteDuringConditionalNew *Cleanup = CGF.
EHStack
1252 Cleanup->setPlacementArg(I,
1273 unsigned minElements = 0;
1276 minElements = ILE->getNumInits();
1283 allocSizeWithoutCookie);
1285 allocatorArgs.add(
RValue::get(allocSize), sizeType);
1297 assert(allocatorArgs.size() == 2);
1298 RV = allocatorArgs[1].RV;
1312 llvm::BasicBlock *nullCheckBB =
nullptr;
1313 llvm::BasicBlock *contBB =
nullptr;
1316 unsigned AS = allocation->getType()->getPointerAddressSpace();
1323 conditional.
begin(*
this);
1325 nullCheckBB =
Builder.GetInsertBlock();
1330 Builder.CreateCondBr(isNull, contBB, notNullBB);
1337 llvm::Instruction *cleanupDominator =
nullptr;
1342 cleanupDominator =
Builder.CreateUnreachable();
1345 assert((allocSize == allocSizeWithoutCookie) ==
1347 if (allocSize != allocSizeWithoutCookie) {
1355 llvm::Type *elementPtrTy = elementTy->getPointerTo(AS);
1359 allocSizeWithoutCookie);
1365 if (result->getType() != resultType)
1366 result =
Builder.CreateBitCast(result, resultType);
1371 if (operatorDeleteCleanup.
isValid()) {
1373 cleanupDominator->eraseFromParent();
1377 conditional.
end(*
this);
1379 llvm::BasicBlock *notNullBB =
Builder.GetInsertBlock();
1382 llvm::PHINode *PHI =
Builder.CreatePHI(result->getType(), 2);
1383 PHI->addIncoming(result, notNullBB);
1384 PHI->addIncoming(llvm::Constant::getNullValue(result->getType()),
1406 if (DeleteFTy->getNumParams() == 2) {
1407 SizeTy = DeleteFTy->getParamType(1);
1409 Size = llvm::ConstantInt::get(
ConvertType(SizeTy),
1413 QualType ArgTy = DeleteFTy->getParamType(0);
1434 : Ptr(Ptr), OperatorDelete(OperatorDelete), ElementType(ElementType) {}
1447 OperatorDelete, ElementType);
1476 Ptr, OperatorDelete, ElementType);
1523 : Ptr(Ptr), OperatorDelete(OperatorDelete), NumElements(NumElements),
1524 ElementType(ElementType), CookieSize(CookieSize) {}
1542 llvm::IntegerType *SizeTy
1543 = cast<llvm::IntegerType>(CGF.
ConvertType(
size_t));
1550 = llvm::ConstantInt::get(SizeTy, ElementTypeSize.getQuantity());
1552 Size = CGF.
Builder.CreateMul(Size, NumElements);
1555 if (!CookieSize.isZero()) {
1557 = llvm::ConstantInt::get(SizeTy, CookieSize.getQuantity());
1558 Size = CGF.
Builder.CreateAdd(Size, CookieSizeV);
1579 numElements, allocatedPtr, cookieSize);
1581 assert(allocatedPtr &&
"ReadArrayCookie didn't set allocated pointer");
1586 allocatedPtr, operatorDelete,
1587 numElements, elementType,
1592 assert(numElements &&
"no element count for a type with a destructor!");
1595 CGF.
Builder.CreateInBoundsGEP(deletedPtr, numElements,
"delete.end");
1620 Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull);
1631 GEP.push_back(Zero);
1635 =
getContext().getAsConstantArrayType(DeleteTy)) {
1637 DeleteTy = Arr->getElementType();
1640 GEP.push_back(Zero);
1643 Ptr =
Builder.CreateInBoundsGEP(Ptr, GEP,
"del.first");
1661 if (
const auto *CE = dyn_cast<CastExpr>(E)) {
1662 if (!CE->getSubExpr()->isGLValue())
1667 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
1670 if (
const auto *BO = dyn_cast<BinaryOperator>(E))
1674 if (
const auto *ACO = dyn_cast<AbstractConditionalOperator>(E))
1680 if (isa<ArraySubscriptExpr>(E))
1683 if (
const auto *UO = dyn_cast<UnaryOperator>(E))
1691 llvm::Type *StdTypeInfoPtrTy) {
1706 llvm::BasicBlock *BadTypeidBlock =
1711 CGF.
Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock);
1723 llvm::Type *StdTypeInfoPtrTy =
1729 return Builder.CreateBitCast(TypeInfo, StdTypeInfoPtrTy);
1750 return llvm::Constant::getNullValue(DestLTy);
1758 return llvm::UndefValue::get(DestLTy);
1776 bool isDynamicCastToVoid;
1784 isDynamicCastToVoid =
false;
1785 SrcRecordTy = SrcTy;
1789 assert(SrcRecordTy->
isRecordType() &&
"source type must be a record type!");
1794 bool ShouldNullCheckSrcValue =
1798 llvm::BasicBlock *CastNull =
nullptr;
1799 llvm::BasicBlock *CastNotNull =
nullptr;
1802 if (ShouldNullCheckSrcValue) {
1807 Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
1811 if (isDynamicCastToVoid) {
1816 "destination type must be a record type!");
1818 DestTy, DestRecordTy, CastEnd);
1821 if (ShouldNullCheckSrcValue) {
1830 if (ShouldNullCheckSrcValue) {
1831 llvm::PHINode *PHI =
Builder.CreatePHI(Value->getType(), 2);
1832 PHI->addIncoming(Value, CastNotNull);
1833 PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull);
1849 i != e; ++i, ++CurField) {
1852 if (CurField->hasCapturedVLAType()) {
1853 auto VAT = CurField->getCapturedVLAType();
1857 if (CurField->getType()->isArrayType())
A call to an overloaded operator written using operator syntax.
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init, ArrayRef< VarDecl * > ArrayIndexes)
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
virtual void EmitBadTypeidCall(CodeGenFunction &CGF)=0
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, llvm::Value *ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
void end(CodeGenFunction &CGF)
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
bool isConstantArrayType() const
void EmitVTablePtrCheckForCall(const CXXMethodDecl *MD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
DestructionKind isDestructedType() const
CXXCtorType getCtorType() const
bool isElidable() const
Whether this construction is elidable.
llvm::Module & getModule() const
bool isOne() const
isOne - Test whether the quantity equals one.
bool isInConditionalBranch() const
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
Checking the 'this' pointer for a constructor call.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name...
bool isRecordType() const
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, QualType SrcRecordTy)=0
bool hasDefinition() const
QualType getPointeeType() const
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
QualType getRecordType(const RecordDecl *Decl) const
Represents a call to a C++ constructor.
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
const LangOptions & getLangOpts() const
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
static RValue EmitNewDeleteCall(CodeGenFunction &CGF, const FunctionDecl *Callee, const FunctionProtoType *CalleeType, const CallArgList &Args)
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, llvm::Value *This)
Represents a C++ constructor within a class.
Expr * ignoreParenBaseCasts() LLVM_READONLY
Ignore parentheses and derived-to-base casts.
llvm::Value * getAddress() const
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
static llvm::Value * EmitCXXNewAllocSize(CodeGenFunction &CGF, const CXXNewExpr *e, unsigned minElements, llvm::Value *&numElements, llvm::Value *&sizeWithoutCookie)
CharUnits getAlignment() const
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEndPointer, QualType elementType, Destroyer *destroyer)
static saved_type save(CodeGenFunction &CGF, type value)
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, llvm::Value *Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
const Expr * getCallee() const
T * pushCleanupWithExtra(CleanupKind Kind, size_t N, As...A)
field_iterator field_begin() const
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
const CGFunctionInfo & arrangeCXXStructorDeclaration(const CXXMethodDecl *MD, StructorType Type)
llvm::Value * ReturnValue
IsZeroed_t isZeroed() const
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
unsigned getNumParams() const
An object to manage conditionally-evaluated expressions.
llvm::Value * EmitCXXNewExpr(const CXXNewExpr *E)
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, CallExpr::const_arg_iterator ArgBeg, CallExpr::const_arg_iterator ArgEnd, const FunctionDecl *CalleeDecl=nullptr, unsigned ParamsToSkip=0)
EmitCallArgs - Emit call arguments for a function.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getReturnType() const
static llvm::Value * EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E, llvm::Type *StdTypeInfoPtrTy)
llvm::IntegerType * SizeTy
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, llvm::Type *ElementTy, llvm::Value *NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
bool isPotentiallyEvaluated() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
void EmitAggregateAssign(llvm::Value *DestPtr, llvm::Value *SrcPtr, QualType EltTy)
static void EmitArrayDelete(CodeGenFunction &CGF, const CXXDeleteExpr *E, llvm::Value *deletedPtr, QualType elementType)
Emit the code for deleting an array of objects.
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment=CharUnits())
void EmitSynthesizedCXXCopyCtor(llvm::Value *Dest, llvm::Value *Src, const Expr *Exp)
Describes an C or C++ initializer list.
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
bool isAlwaysNull() const
RValue EmitCall(const CGFunctionInfo &FnInfo, llvm::Value *Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, const Decl *TargetDecl=nullptr, llvm::Instruction **callOrInvoke=nullptr)
llvm::Value * GetVTablePtr(llvm::Value *This, llvm::Type *Ty)
virtual llvm::Value * getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This, llvm::Type *Ty, SourceLocation Loc)=0
Build a virtual function pointer in the ABI-specific way.
ArrayRef< VarDecl * > getCaptureInitIndexVars(capture_init_iterator Iter) const
Retrieve the set of index variables used in the capture initializer of an array captured by copy...
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, Destroyer *destroyer)
const CXXRecordDecl * getParent() const
capture_init_iterator capture_init_end() const
Retrieve the iterator pointing one past the last initialization argument for this lambda expression...
Expr * getInitializer()
The initializer of this new-expression.
Expr * getExprOperand() const
bool isObjCLifetimeType() const
A builtin binary operation expression such as "x + y" or "x <= y".
bool needsEHCleanup(QualType::DestructionKind kind)
RecordDecl * getDecl() const
llvm::Value * EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE)
QualType getTypeAsWritten() const
void initFullExprCleanup()
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
static RequiredArgs commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD, llvm::Value *Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE, CallArgList &Args)
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy)
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
arg_iterator placement_arg_end()
void begin(CodeGenFunction &CGF)
const ArrayType * getAsArrayTypeUnsafe() const
llvm::GlobalValue * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false)
Return the address of the constructor/destructor of the given type.
FunctionDecl * getOperatorDelete() const
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
QualType getParamType(unsigned i) const
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)
Qualifiers::ObjCLifetime getObjCLifetime() const
getObjCLifetime - Returns lifetime attribute of this type.
capture_init_iterator capture_init_begin() const
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
param_type_iterator param_type_begin() const
FunctionDecl * getOperatorDelete() const
QualType getPointeeType() const
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
bool isSignedIntegerOrEnumerationType() const
static TypeEvaluationKind getEvaluationKind(QualType T)
virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr, const CXXDeleteExpr *expr, QualType ElementType, llvm::Value *&NumElements, llvm::Value *&AllocPtr, CharUnits &CookieSize)
virtual llvm::Value * EmitDynamicCastCall(CodeGenFunction &CGF, llvm::Value *Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd)=0
bool CanDevirtualizeMemberFunctionCall(const Expr *Base, const CXXMethodDecl *MD)
CGCXXABI & getCXXABI() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
RValue EmitCXXMemberOrOperatorCall(const CXXMethodDecl *MD, llvm::Value *Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E)
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
Represents a C++ destructor within a class.
static void EnterNewDeleteCleanup(CodeGenFunction &CGF, const CXXNewExpr *E, llvm::Value *NewPtr, llvm::Value *AllocSize, const CallArgList &NewArgs)
CharUnits getNonVirtualAlignment() const
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
ASTContext & getContext() const
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
void add(RValue rvalue, QualType type, bool needscopy=false)
stable_iterator stable_begin() const
virtual llvm::Value * EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, llvm::Value *This, const CXXMemberCallExpr *CE)=0
Emit the ABI-specific virtual destructor call.
bool shouldNullCheckAllocation(const ASTContext &Ctx) const
True if the allocation result needs to be null-checked.
QualType getAllocatedType() const
void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest)
RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow, const Expr *Base)
static void EmitObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, llvm::Value *Ptr, QualType ElementType)
Emit the code for deleting a single object.
llvm::Value * EmitCastToVoidPtr(llvm::Value *value)
Emit a cast to void* in the appropriate address space.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
There is no lifetime qualification on this type.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, llvm::Value *This, const CXXConstructExpr *E)
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields. These padding are added to help Addres...
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
ASTContext & getContext() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, QualType EltTy, bool isVolatile=false, CharUnits Alignment=CharUnits::Zero(), bool isAssignment=false)
static CXXRecordDecl * getCXXRecord(const Expr *E)
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
Deactive a cleanup that was created in an active state.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getBestDynamicClassType() const
For an expression of class type or pointer to class type, return the most derived class decl the expr...
virtual llvm::Value * EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, const Expr *E, llvm::Value *&This, llvm::Value *MemPtr, const MemberPointerType *MPT)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty)
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
SanitizerSet SanOpts
Sanitizers enabled for this function.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
bool hasInitializer() const
Whether this new-expression has any initializer at all.
lookup_result lookup(DeclarationName Name) const
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
Assigning into this object requires a lifetime extension.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const Expr *Arg, bool IsDelete)
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required)
Arrange a call to a C++ method, passing the given arguments.
bool isDynamicClass() const
CXXCtorType
C++ constructor types.
SourceLocation getExprLoc() const LLVM_READONLY
static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init, QualType AllocType, llvm::Value *NewPtr)
QualType getPointeeType() const
void EmitARCDestroyWeak(llvm::Value *addr)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
static CharUnits CalculateCookiePadding(CodeGenFunction &CGF, const CXXNewExpr *E)
static const Type * getElementType(const Expr *BaseExpr)
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=0, bool ForVTable=false, bool DontDefer=false)
Represents a delete expression for memory deallocation and destructor calls, e.g. "delete[] pArray"...
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType type, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
unsigned getNumPlacementArgs() const
unsigned getNumArgs() const
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), bool SkipNullCheck=false)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
void EmitAggExpr(const Expr *E, AggValueSlot AS)
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, llvm::Value *This, llvm::Value *Src, const CXXConstructExpr *E)
static llvm::Value * EmitDynamicCastToNull(CodeGenFunction &CGF, QualType DestTy)
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
FunctionDecl * getOperatorNew() const
QualType getCanonicalType() const
static void EmitNullBaseClassInitialization(CodeGenFunction &CGF, llvm::Value *DestPtr, const CXXRecordDecl *Base)
Represents a call to a CUDA kernel function.
llvm::PointerType * Int8PtrTy
SourceLocation getLocStart() const LLVM_READONLY
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
CharUnits getNonVirtualSize() const
static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, QualType ElementType, llvm::Type *ElementTy, llvm::Value *NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
arg_iterator placement_arg_begin()
RValue EmitCXXStructorCall(const CXXMethodDecl *MD, llvm::Value *Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E, StructorType Type)
static bool isGLValueFromPointerDeref(const Expr *E)
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
const Type * getClass() const
llvm::Value * getAddr() const
Reading or writing from this object requires a barrier call.
bool isPODType(ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, const ConstantArrayType *ArrayTy, llvm::Value *ArrayPtr, const CXXConstructExpr *E, bool ZeroInitialization=false)
llvm::Value * BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
Represents a C++ struct/union/class.
void EmitBranch(llvm::BasicBlock *Block)
llvm::Type * ConvertType(QualType T)
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
void EmitCXXDeleteExpr(const CXXDeleteExpr *E)
LValue EmitLValue(const Expr *E)
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
virtual llvm::Value * adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This, bool VirtualCall)
static RValue get(llvm::Value *V)
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
static AggValueSlot forAddr(llvm::Value *addr, CharUnits align, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
virtual llvm::Value * EmitDynamicCastToVoid(CodeGenFunction &CGF, llvm::Value *Value, QualType SrcRecordTy, QualType DestTy)=0
virtual llvm::Value * InitializeArrayCookie(CodeGenFunction &CGF, llvm::Value *NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
bool isTypeOperand() const
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
TranslationUnitDecl * getTranslationUnitDecl()
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool isZeroInitializable(QualType T)
Represents an implicitly-generated value initialization of an object of a given type.
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Expr * IgnoreParens() LLVM_READONLY
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPointerType() const
OverloadedOperatorKind getOverloadedOperator() const
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.