Go to the documentation of this file.
22 #include "llvm/IR/Intrinsics.h"
24 using namespace clang;
25 using namespace CodeGen;
28 struct MemberCallInfo {
37 llvm::Value *
This, llvm::Value *ImplicitParam,
40 assert(CE ==
nullptr || isa<CXXMemberCallExpr>(CE) ||
41 isa<CXXOperatorCallExpr>(CE));
43 "Trying to emit a member or operator call expr on a static method!");
57 unsigned PrefixSize = Args.size() - 1;
67 unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0;
73 "No CallExpr specified for function with non-zero number of arguments");
75 return {required, PrefixSize};
81 llvm::Value *
This, llvm::Value *ImplicitParam,
QualType ImplicitParamTy,
86 *
this, MD,
This, ImplicitParam, ImplicitParamTy, CE, Args, RtlArgs);
88 Args, FPT, CallInfo.ReqArgs, CallInfo.PrefixSize);
101 "Pointer/Object mixup");
105 if (SrcAS != DstAS) {
114 ImplicitParamTy, CE, Args,
nullptr);
135 BaseQuals = PTy->getPointeeType().getQualifiers();
176 return cast<CXXRecordDecl>(Ty->
getDecl());
185 if (isa<BinaryOperator>(callee))
188 const MemberExpr *ME = cast<MemberExpr>(callee);
212 assert(isa<CXXMemberCallExpr>(CE) || isa<CXXOperatorCallExpr>(CE));
215 bool CanUseVirtualCall = MD->
isVirtual() && !HasQualifier;
218 if (CanUseVirtualCall &&
222 assert(DevirtualizedMethod);
224 const Expr *Inner =
Base->IgnoreParenBaseCasts();
232 DevirtualizedMethod =
nullptr;
242 DevirtualizedMethod =
nullptr;
246 bool TrivialForCodegen =
248 bool TrivialAssignment =
257 LValue TrivialAssignmentRHS;
258 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(CE)) {
259 if (OCE->isAssignmentOp()) {
260 if (TrivialAssignment) {
263 RtlArgs = &RtlArgStorage;
285 assert(
ReturnValue.isNull() &&
"Constructor shouldn't have return value");
288 *
this, Ctor,
This.getPointer(*
this),
nullptr,
292 false,
This.getAddress(*
this), Args,
298 if (TrivialForCodegen) {
299 if (isa<CXXDestructorDecl>(MD))
302 if (TrivialAssignment) {
308 LValue RHS = isa<CXXOperatorCallExpr>(CE)
309 ? TrivialAssignmentRHS
316 "unknown trivial member function");
321 DevirtualizedMethod ? DevirtualizedMethod : MD;
323 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl))
340 if (
const auto *CMCE = dyn_cast<CXXMemberCallExpr>(CE)) {
341 auto *IOA = CMCE->getImplicitObjectArgument();
343 if (IsImplicitObjectCXXThis)
344 SkippedChecks.
set(SanitizerKind::Alignment,
true);
345 if (IsImplicitObjectCXXThis || isa<DeclRefExpr>(IOA))
349 This.getPointer(*
this),
350 C.getRecordType(CalleeDecl->
getParent()),
359 bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod;
363 "Destructor shouldn't have explicit parameters");
364 assert(
ReturnValue.isNull() &&
"Destructor shouldn't have return value");
365 if (UseVirtualCall) {
367 This.getAddress(*
this),
368 cast<CXXMemberCallExpr>(CE));
372 if (
getLangOpts().AppleKext && Dtor->isVirtual() && HasQualifier)
374 else if (!DevirtualizedMethod)
382 IsArrow ?
Base->getType()->getPointeeType() :
Base->getType();
394 if (UseVirtualCall) {
408 else if (!DevirtualizedMethod)
421 *
this, CalleeDecl,
This.getAddress(*
this), UseVirtualCall);
422 This.setAddress(NewThisAddr);
457 llvm::Value *ThisPtrForCall =
nullptr;
460 ThisPtrForCall, MemFnPtr, MPT);
485 "Trying to emit a member call expr on a static method!");
515 std::vector<CharUnits> VBPtrOffsets =
517 for (
CharUnits VBPtrOffset : VBPtrOffsets) {
519 if (VBPtrOffset >= NVSize)
521 std::pair<CharUnits, CharUnits> LastStore = Stores.pop_back_val();
522 CharUnits LastStoreOffset = LastStore.first;
523 CharUnits LastStoreSize = LastStore.second;
525 CharUnits SplitBeforeOffset = LastStoreOffset;
526 CharUnits SplitBeforeSize = VBPtrOffset - SplitBeforeOffset;
527 assert(!SplitBeforeSize.
isNegative() &&
"negative store size!");
528 if (!SplitBeforeSize.
isZero())
529 Stores.emplace_back(SplitBeforeOffset, SplitBeforeSize);
531 CharUnits SplitAfterOffset = VBPtrOffset + VBPtrWidth;
532 CharUnits SplitAfterSize = LastStoreSize - SplitAfterOffset;
533 assert(!SplitAfterSize.
isNegative() &&
"negative store size!");
534 if (!SplitAfterSize.
isZero())
535 Stores.emplace_back(SplitAfterOffset, SplitAfterSize);
545 if (!NullConstantForBase->isNullValue()) {
546 llvm::GlobalVariable *NullVariable =
new llvm::GlobalVariable(
548 true, llvm::GlobalVariable::PrivateLinkage,
549 NullConstantForBase, Twine());
553 NullVariable->setAlignment(Align.
getAsAlign());
559 for (std::pair<CharUnits, CharUnits>
Store : Stores) {
562 llvm::Value *StoreSizeVal = CGF.
CGM.
getSize(StoreSize);
573 for (std::pair<CharUnits, CharUnits>
Store : Stores) {
576 llvm::Value *StoreSizeVal = CGF.
CGM.
getSize(StoreSize);
579 CGF.
Builder.getInt8(0), StoreSizeVal);
587 assert(!Dest.
isIgnored() &&
"Must have a destination!");
633 bool ForVirtualBase =
false;
634 bool Delegating =
false;
648 ForVirtualBase =
true;
663 Exp = E->getSubExpr();
664 assert(isa<CXXConstructExpr>(Exp) &&
665 "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr");
678 &&
"EmitSynthesizedCXXCopyCtor - Copied-in Array");
697 unsigned minElements,
698 llvm::Value *&numElements,
699 llvm::Value *&sizeWithoutCookie) {
706 return sizeWithoutCookie;
710 unsigned sizeWidth = CGF.
SizeTy->getBitWidth();
723 assert(isa<llvm::IntegerType>(numElements->getType()));
732 = (*e->
getArraySize())->getType()->isSignedIntegerOrEnumerationType();
733 llvm::IntegerType *numElementsType
734 = cast<llvm::IntegerType>(numElements->getType());
735 unsigned numElementsWidth = numElementsType->getBitWidth();
741 type = CAT->getElementType();
742 arraySizeMultiplier *= CAT->getSize();
747 typeSizeMultiplier *= arraySizeMultiplier;
754 if (llvm::ConstantInt *numElementsC =
755 dyn_cast<llvm::ConstantInt>(numElements)) {
756 const llvm::APInt &count = numElementsC->getValue();
758 bool hasAnyOverflow =
false;
761 if (isSigned && count.isNegative())
762 hasAnyOverflow =
true;
767 else if (numElementsWidth > sizeWidth &&
768 numElementsWidth - sizeWidth > count.countLeadingZeros())
769 hasAnyOverflow =
true;
772 llvm::APInt adjustedCount = count.zextOrTrunc(sizeWidth);
776 if (adjustedCount.ult(minElements))
777 hasAnyOverflow =
true;
782 numElements = llvm::ConstantInt::get(CGF.
SizeTy,
783 adjustedCount * arraySizeMultiplier);
788 = adjustedCount.umul_ov(typeSizeMultiplier, overflow);
789 hasAnyOverflow |= overflow;
792 if (cookieSize != 0) {
795 sizeWithoutCookie = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
797 allocationSize = allocationSize.uadd_ov(cookieSize, overflow);
798 hasAnyOverflow |= overflow;
802 if (hasAnyOverflow) {
803 size = llvm::Constant::getAllOnesValue(CGF.
SizeTy);
805 size = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
823 llvm::Value *hasOverflow =
nullptr;
828 if (numElementsWidth > sizeWidth) {
830 threshold <<= sizeWidth;
832 llvm::Value *thresholdV
833 = llvm::ConstantInt::get(numElementsType, threshold);
835 hasOverflow = CGF.
Builder.CreateICmpUGE(numElements, thresholdV);
836 numElements = CGF.
Builder.CreateTrunc(numElements, CGF.
SizeTy);
839 }
else if (isSigned) {
840 if (numElementsWidth < sizeWidth)
841 numElements = CGF.
Builder.CreateSExt(numElements, CGF.
SizeTy);
848 if (typeSizeMultiplier == 1)
849 hasOverflow = CGF.
Builder.CreateICmpSLT(numElements,
850 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
853 }
else if (numElementsWidth < sizeWidth) {
854 numElements = CGF.
Builder.CreateZExt(numElements, CGF.
SizeTy);
857 assert(numElements->getType() == CGF.
SizeTy);
862 hasOverflow = CGF.
Builder.CreateICmpULT(numElements,
863 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
864 }
else if (numElementsWidth > sizeWidth) {
868 hasOverflow = CGF.
Builder.CreateOr(hasOverflow,
869 CGF.
Builder.CreateICmpULT(numElements,
870 llvm::ConstantInt::get(CGF.
SizeTy, minElements)));
883 if (typeSizeMultiplier != 1) {
884 llvm::Function *umul_with_overflow
888 llvm::ConstantInt::get(CGF.
SizeTy, typeSizeMultiplier);
889 llvm::Value *result =
890 CGF.
Builder.CreateCall(umul_with_overflow, {size, tsmV});
892 llvm::Value *overflowed = CGF.
Builder.CreateExtractValue(result, 1);
894 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
896 hasOverflow = overflowed;
898 size = CGF.
Builder.CreateExtractValue(result, 0);
901 if (arraySizeMultiplier != 1) {
904 if (typeSize.
isOne()) {
905 assert(arraySizeMultiplier == typeSizeMultiplier);
911 llvm::ConstantInt::get(CGF.
SizeTy, arraySizeMultiplier);
912 numElements = CGF.
Builder.CreateMul(numElements, asmV);
917 assert(arraySizeMultiplier == 1);
921 if (cookieSize != 0) {
922 sizeWithoutCookie = size;
924 llvm::Function *uadd_with_overflow
927 llvm::Value *cookieSizeV = llvm::ConstantInt::get(CGF.
SizeTy, cookieSize);
928 llvm::Value *result =
929 CGF.
Builder.CreateCall(uadd_with_overflow, {size, cookieSizeV});
931 llvm::Value *overflowed = CGF.
Builder.CreateExtractValue(result, 1);
933 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
935 hasOverflow = overflowed;
937 size = CGF.
Builder.CreateExtractValue(result, 0);
944 size = CGF.
Builder.CreateSelect(hasOverflow,
945 llvm::Constant::getAllOnesValue(CGF.
SizeTy),
950 sizeWithoutCookie = size;
952 assert(sizeWithoutCookie &&
"didn't set sizeWithoutCookie?");
982 llvm_unreachable(
"bad evaluation kind");
987 Address BeginPtr, llvm::Value *NumElements,
988 llvm::Value *AllocSizeWithoutCookie) {
996 unsigned InitListElements = 0;
1002 llvm::Instruction *CleanupDominator =
nullptr;
1009 auto TryMemsetInitialization = [&]() ->
bool {
1019 auto *RemainingSize = AllocSizeWithoutCookie;
1020 if (InitListElements) {
1022 auto *InitializedSize = llvm::ConstantInt::get(
1023 RemainingSize->getType(),
1024 getContext().getTypeSizeInChars(ElementType).getQuantity() *
1026 RemainingSize =
Builder.CreateSub(RemainingSize, InitializedSize);
1035 if (
const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
1038 if (ILE->isStringLiteralInit()) {
1054 cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe())
1055 ->getSize().getZExtValue();
1057 CurPtr, InitListElements,
"string.init.end");
1060 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1061 if (!ConstNum || !ConstNum->equalsInt(InitListElements)) {
1062 bool OK = TryMemsetInitialization();
1064 assert(OK &&
"couldn't memset character type?");
1069 InitListElements = ILE->getNumInits();
1091 ElementType, ElementAlign,
1097 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
1110 ILE->getInit(i)->getType(), CurPtr,
1120 Init = ILE->getArrayFiller();
1125 while (Init && Init->getType()->isConstantArrayType()) {
1126 auto *SubILE = dyn_cast<InitListExpr>(Init);
1129 assert(SubILE->getNumInits() == 0 &&
"explicit inits in array filler?");
1130 Init = SubILE->getArrayFiller();
1139 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1140 if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
1142 if (CleanupDominator)
1147 assert(Init &&
"have trailing elements to initialize but no initializer");
1159 if (TryMemsetInitialization())
1171 if (InitListElements)
1172 NumElements =
Builder.CreateSub(
1174 llvm::ConstantInt::get(NumElements->getType(), InitListElements));
1177 CCE->requiresZeroInitialization());
1183 if (isa<ImplicitValueInitExpr>(Init)) {
1184 if (TryMemsetInitialization())
1195 assert(
getContext().hasSameUnqualifiedType(ElementType, Init->getType()) &&
1196 "got wrong type of element to initialize");
1199 if (
auto *ILE = dyn_cast<InitListExpr>(Init))
1200 if (ILE->getNumInits() == 0 && TryMemsetInitialization())
1205 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
1207 if (RType->getDecl()->isStruct()) {
1208 unsigned NumElements = 0;
1209 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RType->getDecl()))
1210 NumElements = CXXRD->getNumBases();
1211 for (
auto *Field : RType->getDecl()->fields())
1212 if (!Field->isUnnamedBitfield())
1215 if (ILE->getNumInits() == NumElements)
1216 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i)
1217 if (!isa<ImplicitValueInitExpr>(ILE->getInit(i)))
1219 if (ILE->getNumInits() == NumElements && TryMemsetInitialization())
1226 llvm::BasicBlock *EntryBB =
Builder.GetInsertBlock();
1231 llvm::Value *EndPtr =
1233 NumElements,
"array.end");
1238 llvm::Value *IsEmpty =
1240 Builder.CreateCondBr(IsEmpty, ContBB, LoopBB);
1247 llvm::PHINode *CurPtrPhi =
1249 CurPtrPhi->addIncoming(CurPtr.
getPointer(), EntryBB);
1260 ElementType, ElementAlign,
1263 CleanupDominator =
Builder.CreateUnreachable();
1271 if (CleanupDominator) {
1273 CleanupDominator->eraseFromParent();
1277 llvm::Value *NextPtr =
1283 llvm::Value *IsEnd =
Builder.CreateICmpEQ(NextPtr, EndPtr,
"array.atend");
1284 Builder.CreateCondBr(IsEnd, ContBB, LoopBB);
1285 CurPtrPhi->addIncoming(NextPtr,
Builder.GetInsertBlock());
1291 QualType ElementType, llvm::Type *ElementTy,
1292 Address NewPtr, llvm::Value *NumElements,
1293 llvm::Value *AllocSizeWithoutCookie) {
1297 AllocSizeWithoutCookie);
1309 llvm::CallBase *CallOrInvoke;
1314 Args, CalleeType,
false),
1322 llvm::Function *Fn = dyn_cast<llvm::Function>(CalleePtr);
1324 Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) {
1325 CallOrInvoke->addFnAttr(llvm::Attribute::Builtin);
1342 if (
auto *FD = dyn_cast<FunctionDecl>(
Decl))
1345 llvm_unreachable(
"predeclared global operator new/delete is missing");
1350 struct UsualDeleteParams {
1351 bool DestroyingDelete =
false;
1353 bool Alignment =
false;
1358 UsualDeleteParams Params;
1368 Params.DestroyingDelete =
true;
1380 Params.Alignment =
true;
1384 assert(AI == AE &&
"unexpected usual deallocation function parameter");
1392 template<
typename Traits>
1395 typedef typename Traits::ValueTy ValueTy;
1397 typedef typename Traits::RValueTy RValueTy;
1398 struct PlacementArg {
1403 unsigned NumPlacementArgs : 31;
1404 unsigned PassAlignmentToPlacementDelete : 1;
1410 PlacementArg *getPlacementArgs() {
1411 return reinterpret_cast<PlacementArg *
>(
this + 1);
1415 static size_t getExtraSize(
size_t NumPlacementArgs) {
1416 return NumPlacementArgs *
sizeof(PlacementArg);
1419 CallDeleteDuringNew(
size_t NumPlacementArgs,
1421 ValueTy AllocSize,
bool PassAlignmentToPlacementDelete,
1423 : NumPlacementArgs(NumPlacementArgs),
1424 PassAlignmentToPlacementDelete(PassAlignmentToPlacementDelete),
1425 OperatorDelete(OperatorDelete), Ptr(Ptr), AllocSize(AllocSize),
1426 AllocAlign(AllocAlign) {}
1428 void setPlacementArg(
unsigned I, RValueTy Arg,
QualType Type) {
1429 assert(I < NumPlacementArgs &&
"index out of range");
1430 getPlacementArgs()[I] = {Arg,
Type};
1439 DeleteArgs.
add(Traits::get(CGF, Ptr), FPT->getParamType(0));
1442 UsualDeleteParams Params;
1443 if (NumPlacementArgs) {
1446 Params.Alignment = PassAlignmentToPlacementDelete;
1453 assert(!Params.DestroyingDelete &&
1454 "should not call destroying delete in a new-expression");
1458 DeleteArgs.add(Traits::get(CGF, AllocSize),
1465 if (Params.Alignment)
1466 DeleteArgs.add(
RValue::get(llvm::ConstantInt::get(
1471 for (
unsigned I = 0; I != NumPlacementArgs; ++I) {
1472 auto Arg = getPlacementArgs()[I];
1473 DeleteArgs.add(Traits::get(CGF, Arg.ArgValue), Arg.ArgType);
1487 llvm::Value *AllocSize,
1495 struct DirectCleanupTraits {
1496 typedef llvm::Value *ValueTy;
1502 typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup;
1504 DirectCleanup *Cleanup = CGF.
EHStack
1513 auto &Arg = NewArgs[I + NumNonPlacementArgs];
1514 Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty);
1526 struct ConditionalCleanupTraits {
1530 return V.restore(CGF);
1533 typedef CallDeleteDuringNew<ConditionalCleanupTraits> ConditionalCleanup;
1535 ConditionalCleanup *Cleanup = CGF.
EHStack
1544 auto &Arg = NewArgs[I + NumNonPlacementArgs];
1545 Cleanup->setPlacementArg(
1560 unsigned minElements = 0;
1566 ->getSize().getZExtValue();
1571 llvm::Value *numElements =
nullptr;
1572 llvm::Value *allocSizeWithoutCookie =
nullptr;
1573 llvm::Value *allocSize =
1575 allocSizeWithoutCookie);
1606 unsigned ParamsToSkip = 0;
1613 if (allocSize != allocSizeWithoutCookie) {
1615 allocAlign =
std::max(allocAlign, cookieAlign);
1626 "wrong type for alignment parameter");
1630 assert(allocator->
isVariadic() &&
"can't pass alignment to allocator");
1646 if (
auto *newCall = dyn_cast<llvm::CallBase>(RV.
getScalarVal()))
1657 unsigned AllocatorAlign = llvm::PowerOf2Floor(std::min<uint64_t>(
1660 allocationAlign,
getContext().toCharUnitsFromBits(AllocatorAlign));
1674 llvm::BasicBlock *nullCheckBB =
nullptr;
1675 llvm::BasicBlock *contBB =
nullptr;
1682 conditional.
begin(*
this);
1684 nullCheckBB =
Builder.GetInsertBlock();
1688 llvm::Value *isNull =
1690 Builder.CreateCondBr(isNull, contBB, notNullBB);
1697 llvm::Instruction *cleanupDominator =
nullptr;
1703 cleanupDominator =
Builder.CreateUnreachable();
1706 assert((allocSize == allocSizeWithoutCookie) ==
1708 if (allocSize != allocSizeWithoutCookie) {
1736 SkippedChecks, numElements);
1739 allocSizeWithoutCookie);
1740 llvm::Value *resultPtr = result.
getPointer();
1746 if (resultPtr->getType() != resultType)
1747 resultPtr =
Builder.CreateBitCast(resultPtr, resultType);
1752 if (operatorDeleteCleanup.
isValid()) {
1754 cleanupDominator->eraseFromParent();
1758 conditional.
end(*
this);
1760 llvm::BasicBlock *notNullBB =
Builder.GetInsertBlock();
1763 llvm::PHINode *PHI =
Builder.CreatePHI(resultPtr->getType(), 2);
1764 PHI->addIncoming(resultPtr, notNullBB);
1765 PHI->addIncoming(llvm::Constant::getNullValue(resultPtr->getType()),
1775 llvm::Value *Ptr,
QualType DeleteTy,
1776 llvm::Value *NumElements,
1778 assert((!NumElements && CookieSize.
isZero()) ||
1785 auto ParamTypeIt = DeleteFTy->param_type_begin();
1793 llvm::AllocaInst *DestroyingDeleteTag =
nullptr;
1794 if (Params.DestroyingDelete) {
1799 DestroyingDeleteTag->setAlignment(Align.
getAsAlign());
1806 QualType SizeType = *ParamTypeIt++;
1808 llvm::Value *Size = llvm::ConstantInt::get(
ConvertType(SizeType),
1813 Size =
Builder.CreateMul(Size, NumElements);
1816 if (!CookieSize.
isZero())
1824 if (Params.Alignment) {
1825 QualType AlignValType = *ParamTypeIt++;
1829 llvm::Value *Align = llvm::ConstantInt::get(
ConvertType(AlignValType),
1834 assert(ParamTypeIt == DeleteFTy->param_type_end() &&
1835 "unknown parameter to usual delete function");
1842 if (DestroyingDeleteTag && DestroyingDeleteTag->use_empty())
1843 DestroyingDeleteTag->eraseFromParent();
1853 CallObjectDelete(llvm::Value *Ptr,
1856 : Ptr(Ptr), OperatorDelete(OperatorDelete), ElementType(ElementType) {}
1866 llvm::Value *CompletePtr,
1869 OperatorDelete, ElementType);
1880 if (Dtor && Dtor->isVirtual())
1894 llvm::BasicBlock *UnconditionalDeleteBlock) {
1916 bool UseVirtualCall =
true;
1918 if (
auto *DevirtualizedDtor =
1919 dyn_cast_or_null<const CXXDestructorDecl>(
1922 UseVirtualCall =
false;
1928 Dtor = DevirtualizedDtor;
1935 UseVirtualCall =
true;
1938 if (UseVirtualCall) {
1952 OperatorDelete, ElementType);
1978 CGF.
EmitBlock(UnconditionalDeleteBlock);
1992 llvm::Value *NumElements;
1996 CallArrayDelete(llvm::Value *Ptr,
1998 llvm::Value *NumElements,
2001 : Ptr(Ptr), OperatorDelete(OperatorDelete), NumElements(NumElements),
2002 ElementType(ElementType), CookieSize(CookieSize) {}
2005 CGF.
EmitDeleteCall(OperatorDelete, Ptr, ElementType, NumElements,
2016 llvm::Value *numElements =
nullptr;
2017 llvm::Value *allocatedPtr =
nullptr;
2020 numElements, allocatedPtr, cookieSize);
2022 assert(allocatedPtr &&
"ReadArrayCookie didn't set allocated pointer");
2027 allocatedPtr, operatorDelete,
2028 numElements, elementType,
2033 assert(numElements &&
"no element count for a type with a destructor!");
2039 llvm::Value *arrayBegin = deletedPtr.
getPointer();
2040 llvm::Value *arrayEnd = CGF.
Builder.CreateInBoundsGEP(
2041 deletedPtr.
getElementType(), arrayBegin, numElements,
"delete.end");
2072 Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull);
2092 GEP.push_back(
Zero);
2096 =
getContext().getAsConstantArrayType(DeleteTy)) {
2098 DeleteTy = Arr->getElementType();
2101 GEP.push_back(
Zero);
2123 if (
const auto *CE = dyn_cast<CastExpr>(E)) {
2124 if (!CE->getSubExpr()->isGLValue())
2129 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
2132 if (
const auto *BO = dyn_cast<BinaryOperator>(E))
2133 if (BO->getOpcode() == BO_Comma)
2136 if (
const auto *ACO = dyn_cast<AbstractConditionalOperator>(E))
2142 if (isa<ArraySubscriptExpr>(E))
2145 if (
const auto *UO = dyn_cast<UnaryOperator>(E))
2146 if (UO->getOpcode() == UO_Deref)
2153 llvm::Type *StdTypeInfoPtrTy) {
2176 llvm::BasicBlock *BadTypeidBlock =
2181 CGF.
Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock);
2193 llvm::Type *StdTypeInfoPtrTy =
2221 return llvm::Constant::getNullValue(DestLTy);
2229 return llvm::UndefValue::get(DestLTy);
2244 bool isDynamicCastToVoid;
2252 isDynamicCastToVoid =
false;
2253 SrcRecordTy = SrcTy;
2269 assert(SrcRecordTy->
isRecordType() &&
"source type must be a record type!");
2274 bool ShouldNullCheckSrcValue =
2278 llvm::BasicBlock *CastNull =
nullptr;
2279 llvm::BasicBlock *CastNotNull =
nullptr;
2282 if (ShouldNullCheckSrcValue) {
2287 Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
2292 if (isDynamicCastToVoid) {
2297 "destination type must be a record type!");
2299 DestTy, DestRecordTy, CastEnd);
2300 CastNotNull =
Builder.GetInsertBlock();
2303 if (ShouldNullCheckSrcValue) {
2312 if (ShouldNullCheckSrcValue) {
2313 llvm::PHINode *PHI =
Builder.CreatePHI(
Value->getType(), 2);
2314 PHI->addIncoming(
Value, CastNotNull);
2315 PHI->addIncoming(llvm::Constant::getNullValue(
Value->getType()), CastNull);
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.
QualType getDestroyedType() const
Retrieve the type being destroyed.
QualType getThisType() const
Return the type of the this pointer.
llvm::Type * ConvertTypeForMem(QualType T)
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, CFITypeCheckKind TCK, SourceLocation Loc)
EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
param_type_iterator param_type_begin() const
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
bool isOne() const
isOne - Test whether the quantity equals one.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
bool isRecordType() const
SourceLocation getExprLoc() const LLVM_READONLY
llvm::IntegerType * SizeTy
__DEVICE__ int max(int __a, int __b)
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy, SourceLocation Loc)
Add heapallocsite metadata for MSAllocator calls.
bool isDefaulted() const
Whether this function is defaulted.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
param_type_iterator param_type_end() const
Represents a C++ constructor within a class.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
static void EmitArrayDelete(CodeGenFunction &CGF, const CXXDeleteExpr *E, Address deletedPtr, QualType elementType)
Emit the code for deleting an array of objects.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init, QualType AllocType, Address NewPtr, AggValueSlot::Overlap_t MayOverlap)
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
bool hasStrongOrWeakObjCLifetime() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue getAggregate(Address addr, bool isVolatile=false)
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
void EmitARCDestroyWeak(Address addr)
void @objc_destroyWeak(i8** addr) Essentially objc_storeWeak(addr, nil).
QualType getReturnType() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
RValue EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, const CGCallee &Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E, CallArgList *RtlArgs)
virtual std::pair< llvm::Value *, const CXXRecordDecl * > LoadVTablePtr(CodeGenFunction &CGF, Address This, const CXXRecordDecl *RD)=0
Load a vtable from This, an object of polymorphic type RD, or from one of its virtual bases if it doe...
@ TCK_DynamicOperation
Checking the operand of a dynamic_cast or a typeid expression.
Represents the canonical version of C arrays with a specified constant size.
CharUnits getAlignment() const
Return the alignment of this pointer.
CharUnits getSizeAlign() const
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, Address Src, const CXXConstructExpr *E)
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' is g...
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
Encodes a location in the source.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Address getAddress(CodeGenFunction &CGF) const
unsigned getNumPlacementArgs() const
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
FunctionDecl * getOperatorNew() const
DeclarationNameTable DeclarationNames
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
virtual Address InitializeArrayCookie(CodeGenFunction &CGF, Address NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
Initialize the array cookie for the given allocation.
CharUnits getPointerAlign() const
A (possibly-)qualified type.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
QualType getCanonicalType() const
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
Destroy a __strong variable.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
The collection of all-type qualifiers we support.
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
CharUnits getNonVirtualAlignment() const
getNonVirtualAlignment - Get the non-virtual alignment (in chars) of an object, which is the alignmen...
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the ...
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, QualType ElementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
Describes an C or C++ initializer list.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ Ctor_Base
Base object ctor.
const LangOptions & getLangOpts() const
@ Ctor_Complete
Complete object ctor.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
const CallExpr * MustTailCall
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
QualType getAllocatedType() const
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, Address ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
bool isMostDerived(ASTContext &Context) const
Best-effort check if the expression operand refers to a most derived object.
Expr * getExprOperand() const
The name of a declaration.
TranslationUnitDecl * getTranslationUnitDecl() const
void add(RValue rvalue, QualType type)
static bool isGLValueFromPointerDeref(const Expr *E)
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
@ Dtor_Complete
Complete object dtor.
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
The base class of the type hierarchy.
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization=false)
EmitCXXAggrConstructorCall - Emit a loop to call a particular constructor for each of several members...
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
GlobalDecl - represents a global declaration.
SourceLocation getBeginLoc() const
Get the begin source location.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
LangAS getAddressSpace() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
static saved_type save(CodeGenFunction &CGF, type value)
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
static CharUnits CalculateCookiePadding(CodeGenFunction &CGF, const CXXNewExpr *E)
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ...
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
CXXCtorType
C++ constructor types.
Information for lazily generating a cleanup.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
LangAS getAddressSpace() const
Return the address space of this type.
A builtin binary operation expression such as "x + y" or "x <= y".
static llvm::Value * EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E, llvm::Type *StdTypeInfoPtrTy)
Expr * getInitializer()
The initializer of this new-expression.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Scope - A scope is a transient data structure that is used while parsing the program.
llvm::Value * EmitCXXNewExpr(const CXXNewExpr *E)
llvm::Value * EmitCastToVoidPtr(llvm::Value *value)
Emit a cast to void* in the appropriate address space.
const CodeGenOptions & getCodeGenOpts() const
llvm::PointerType * getType() const
Return the type of the pointer value.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getPointeeType() const
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
const T * getAs() const
Member-template getAs<specific type>'.
CGDebugInfo * getDebugInfo()
static bool EmitObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, llvm::BasicBlock *UnconditionalDeleteBlock)
Emit the code for deleting a single object.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Get the type of the implicit "this" parameter used by a method.
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
QualType getParamType(unsigned i) const
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
virtual Address adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, Address This, bool VirtualCall)
Perform ABI-specific "this" argument adjustment required prior to a call of a virtual function.
llvm::Module & getModule() const
Represents a C++ destructor within a class.
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.
Represents an implicitly-generated value initialization of an object of a given type.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
void begin(CodeGenFunction &CGF)
virtual void EmitBadTypeidCall(CodeGenFunction &CGF)=0
bool Zero(InterpState &S, CodePtr OpPC)
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.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
bool isStringLiteralInit() const
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
FunctionDecl * getOperatorDelete() const
CodeGenTypes & getTypes()
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
virtual std::vector< CharUnits > getVBPtrOffsets(const CXXRecordDecl *RD)
Gets the offsets of all the virtual base pointers in a given class.
static llvm::Value * EmitDynamicCastToNull(CodeGenFunction &CGF, QualType DestTy)
llvm::ConstantInt * getSize(CharUnits N)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
ASTContext & getContext() const
CharUnits getPointerSize() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
SanitizerSet SanOpts
Sanitizers enabled for this function.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
@ TCK_ConstructorCall
Checking the 'this' pointer for a constructor call.
TypeSourceInfo * getAllocatedTypeSourceInfo() const
An object to manage conditionally-evaluated expressions.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
bool isNegative() const
isNegative - Test whether the quantity is less than zero.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
bool Null(InterpState &S, CodePtr OpPC)
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits())
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Address withAlignment(CharUnits NewAlignment) const
Return address with different alignment, but same pointer and element type.
LangAS
Defines the address space values used by the address space qualifier of QualType.
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const T * castAs() const
Member-template castAs<specific type>.
Address CreateLaunderInvariantGroup(Address Addr)
A scoped helper to set the current debug location to the specified location or preferred location of ...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
bool isSanitizerChecked() const
static void EnterNewDeleteCleanup(CodeGenFunction &CGF, const CXXNewExpr *E, Address NewPtr, llvm::Value *AllocSize, CharUnits AllocAlign, const CallArgList &NewArgs)
Enter a cleanup to call 'operator delete' if the initializer in a new-expression throws.
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
Represents a C++ struct/union/class.
Qualifiers getMethodQualifiers() const
RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow, const Expr *Base)
CanQualType DeriveThisType(const CXXRecordDecl *RD, const CXXMethodDecl *MD)
Derives the 'this' type for codegen purposes, i.e.
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup.
LValue - This represents an lvalue references.
static UsualDeleteParams getUsualDeleteParams(const FunctionDecl *FD)
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
const TargetCodeGenInfo & getTargetHooks() const
bool isPointerType() const
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
llvm::Value * getPointer() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy)
Emit an aggregate assignment.
A class for recording the number of arguments that a function signature requires.
bool isZero() const
isZero - Test whether the quantity equals zero.
CGCXXABI & getCXXABI() const
Represents a prototype with parameter type info, e.g.
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
DeclContext * getParent()
getParent - Returns the containing DeclContext.
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
emitArrayDestroy - Destroys all the elements of the given array, beginning from last to first.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static RValue EmitNewDeleteCall(CodeGenFunction &CGF, const FunctionDecl *CalleeDecl, const FunctionProtoType *CalleeType, const CallArgList &Args)
Emit a call to an operator new or operator delete function, as implicitly created by new-expressions ...
Represents a delete expression for memory deallocation and destructor calls, e.g.
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Decl - This represents one declaration (or definition), e.g.
bool isTypeOperand() const
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
bool isReplaceableGlobalAllocationFunction(Optional< unsigned > *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
All available information about a concrete callee.
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
CodeGenTypes & getTypes() const
unsigned getNumParams() const
llvm::Type * ConvertType(QualType T)
T * pushCleanupWithExtra(CleanupKind Kind, size_t N, As... A)
Push a cleanup with non-constant storage requirements on the stack.
QualType getDestroyedType() const
Retrieve the type being destroyed.
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, AggValueSlot ThisAVS, const CXXConstructExpr *E)
IsZeroed_t isZeroed() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp)
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
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...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
AlignmentSource getAlignmentSource() const
A pointer to member type per C++ 8.3.3 - Pointers to members.
static CXXRecordDecl * getCXXRecord(const Expr *E)
CGFunctionInfo - Class to encapsulate the information about a function definition.
static llvm::Value * EmitCXXNewAllocSize(CodeGenFunction &CGF, const CXXNewExpr *e, unsigned minElements, llvm::Value *&numElements, llvm::Value *&sizeWithoutCookie)
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
static void EmitNullBaseClassInitialization(CodeGenFunction &CGF, Address DestPtr, const CXXRecordDecl *Base)
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, QualType SrcRecordTy)=0
PointerType - C99 6.7.5.1 - Pointer Declarators.
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
Represents a call to a CUDA kernel function.
@ OCL_None
There is no lifetime qualification on this type.
EnumDecl * getDecl() const
bool This(InterpState &S, CodePtr OpPC)
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
virtual llvm::Value * EmitDynamicCastToVoid(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy)=0
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isAlwaysNull() const
isAlwaysNull - Return whether the result of the dynamic_cast is proven to always be null.
static RValue get(llvm::Value *V)
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
Figure out the rules for calling a function with the given formal type using the given arguments.
void addFrom(const CallArgList &other)
Add all the arguments from another CallArgList to this one.
Address getAddress() const
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
llvm::iterator_range< arg_iterator > placement_arguments()
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
void EmitCXXDeleteExpr(const CXXDeleteExpr *E)
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
bool hasDefinition() const
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
FunctionDecl * getOperatorDelete() const
CXXCtorType getCtorType() const
bool hasInitializer() const
Whether this new-expression has any initializer at all.
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
BuildAppleKextVirtualCall - This routine is to support gcc's kext ABI making indirect call to virtual...
CXXMethodDecl * getDevirtualizedMethod(const Expr *Base, bool IsAppleKext)
If it's possible to devirtualize a call to this method, return the called function.
bool isVariadic() const
Whether this function is variadic.
bool isConstantArrayType() const
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
const Decl * getDecl() const
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
bool isDynamicClass() const
RecordDecl * getDecl() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
virtual llvm::Value * EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, CXXDtorType DtorType, Address This, DeleteOrMemberCallExpr E)=0
Emit the ABI-specific virtual destructor call.
virtual llvm::Value * performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, llvm::Value *V, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
Perform address space cast of an expression of pointer type.
Base for LValueReferenceType and RValueReferenceType.
llvm::Constant * tryEmitAbstract(const Expr *E, QualType T)
Try to emit the result of the given expression as an abstract constant.
CharUnits - This is an opaque type for sizes expressed in character units.
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const CallExpr *TheCallExpr, bool IsDelete)
QualType getPointeeType() const
@ TCK_MemberCall
Checking the 'this' pointer for a call to a non-static member function.
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Expr * getArg(unsigned Arg)
Return the specified argument.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Optional< Expr * > getArraySize()
This might return None even if isArray() returns true, since there might not be an array size express...
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
An abstract representation of regular/ObjC call/message targets.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
This represents one expression.
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
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
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
static MemberCallInfo commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE, CallArgList &Args, CallArgList *RtlArgs)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
CallArgList - Type for representing both the value and type of arguments in a call.
static void EmitDestroyingObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType)
Emit the code for deleting a single object with a destroying operator delete.
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Represents a function declaration or definition.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
unsigned getNumInits() const
A call to an overloaded operator written using operator syntax.
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)
Returns the extra size required in order to store the array cookie for the given new-expression.
Represents a call to a C++ constructor.
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Represents a call to a member function that may be written either with member call syntax (e....
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
A saved depth on the scope stack.
const LangOptions & getLangOpts() const
bool isElidable() const
Whether this construction is elidable.
virtual llvm::Value * EmitDynamicCastCall(CodeGenFunction &CGF, Address Value, QualType SrcRecordTy, QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd)=0
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a static or instance method of a struct/union/class.
void end(CodeGenFunction &CGF)
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
const TargetInfo & Target