22 #include "llvm/IR/CallSite.h" 23 #include "llvm/IR/Intrinsics.h" 25 using namespace clang;
26 using namespace CodeGen;
29 struct MemberCallInfo {
41 assert(CE ==
nullptr || isa<CXXMemberCallExpr>(CE) ||
42 isa<CXXOperatorCallExpr>(CE));
44 "Trying to emit a member or operator call expr on a static method!");
51 RD ? C.getPointerType(C.getTypeDeclType(RD)) : C.VoidPtrTy);
60 unsigned PrefixSize = Args.size() - 1;
70 unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0;
76 "No CallExpr specified for function with non-zero number of arguments");
78 return {required, PrefixSize};
89 *
this, MD, This, ImplicitParam, ImplicitParamTy, CE, Args, RtlArgs);
90 auto &FnInfo = CGM.getTypes().arrangeCXXMethodCall(
91 Args, FPT, CallInfo.ReqArgs, CallInfo.PrefixSize);
92 return EmitCall(FnInfo, Callee, ReturnValue, Args,
nullptr,
102 ImplicitParamTy, CE, Args,
nullptr);
103 return EmitCall(CGM.getTypes().arrangeCXXStructorDeclaration(DD, Type),
120 BaseValue = EmitPointerWithAlignment(BaseExpr);
124 LValue BaseLV = EmitLValue(BaseExpr);
137 EmitARCRelease(Builder.CreateLoad(BaseValue,
143 EmitARCDestroyWeak(BaseValue);
163 return cast<CXXRecordDecl>(Ty->
getDecl());
172 if (isa<BinaryOperator>(callee))
173 return EmitCXXMemberPointerCallExpr(CE, ReturnValue);
175 const MemberExpr *ME = cast<MemberExpr>(callee);
178 if (MD->isStatic()) {
181 return EmitCall(getContext().getPointerType(MD->getType()), callee, CE,
190 return EmitCXXMemberOrOperatorMemberCallExpr(
191 CE, MD, ReturnValue, HasQualifier, Qualifier, IsArrow, Base);
198 assert(isa<CXXMemberCallExpr>(CE) || isa<CXXOperatorCallExpr>(CE));
201 bool CanUseVirtualCall = MD->
isVirtual() && !HasQualifier;
204 if (CanUseVirtualCall &&
208 assert(DevirtualizedMethod);
218 DevirtualizedMethod =
nullptr;
228 DevirtualizedMethod =
nullptr;
236 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(CE)) {
237 if (OCE->isAssignmentOp()) {
238 RtlArgs = &RtlArgStorage;
241 0, EvaluationOrder::ForceRightToLeft);
249 Address ThisValue = EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
250 This = MakeAddrLValue(ThisValue, Base->
getType(), BaseInfo, TBAAInfo);
252 This = EmitLValue(Base);
257 if (isa<CXXDestructorDecl>(MD))
return RValue::get(
nullptr);
258 if (isa<CXXConstructorDecl>(MD) &&
259 cast<CXXConstructorDecl>(MD)->isDefaultConstructor())
266 LValue RHS = isa<CXXOperatorCallExpr>(CE)
267 ? MakeNaturalAlignAddrLValue(
268 (*RtlArgs)[0].getRValue(*this).getScalarVal(),
271 EmitAggregateAssign(This, RHS, CE->
getType());
275 if (isa<CXXConstructorDecl>(MD) &&
276 cast<CXXConstructorDecl>(MD)->isCopyOrMoveConstructor()) {
278 assert(CE->
getNumArgs() == 1 &&
"unexpected argcount for trivial ctor");
280 LValue RHS = EmitLValue(Arg);
281 LValue Dest = MakeAddrLValue(This.getAddress(), Arg->getType());
284 EmitAggregateCopy(Dest, RHS, Arg->
getType(),
288 llvm_unreachable(
"unknown trivial member function");
294 DevirtualizedMethod ? DevirtualizedMethod : MD;
296 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl))
297 FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration(
299 else if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(CalleeDecl))
300 FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration(
303 FInfo = &CGM.getTypes().arrangeCXXMethodDeclaration(CalleeDecl);
305 llvm::FunctionType *Ty = CGM.getTypes().GetFunctionType(*FInfo);
316 if (
const auto *CMCE = dyn_cast<CXXMemberCallExpr>(CE)) {
317 auto *IOA = CMCE->getImplicitObjectArgument();
318 bool IsImplicitObjectCXXThis = IsWrappedCXXThis(IOA);
319 if (IsImplicitObjectCXXThis)
320 SkippedChecks.
set(SanitizerKind::Alignment,
true);
321 if (IsImplicitObjectCXXThis || isa<DeclRefExpr>(IOA))
322 SkippedChecks.
set(SanitizerKind::Null,
true);
339 bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod;
343 "Destructor shouldn't have explicit parameters");
344 assert(ReturnValue.
isNull() &&
"Destructor shouldn't have return value");
345 if (UseVirtualCall) {
346 CGM.getCXXABI().EmitVirtualDestructorCall(
348 cast<CXXMemberCallExpr>(CE));
351 if (getLangOpts().AppleKext && MD->
isVirtual() && HasQualifier)
353 else if (!DevirtualizedMethod)
359 cast<CXXDestructorDecl>(DevirtualizedMethod);
364 EmitCXXMemberOrOperatorCall(
365 CalleeDecl, Callee, ReturnValue, This.getPointer(),
376 }
else if (UseVirtualCall) {
379 if (SanOpts.has(SanitizerKind::CFINVCall) &&
383 std::tie(VTable, RD) =
384 CGM.getCXXABI().LoadVTablePtr(*
this, This.getAddress(),
386 EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->
getLocStart());
389 if (getLangOpts().AppleKext && MD->
isVirtual() && HasQualifier)
391 else if (!DevirtualizedMethod)
395 CGM.GetAddrOfFunction(DevirtualizedMethod, Ty),
396 DevirtualizedMethod);
402 CGM.getCXXABI().adjustThisArgumentForVirtualFunctionCall(
403 *
this, CalleeDecl, This.getAddress(), UseVirtualCall);
404 This.setAddress(NewThisAddr);
407 return EmitCXXMemberOrOperatorCall(
408 CalleeDecl, Callee, ReturnValue, This.getPointer(),
431 This = EmitPointerWithAlignment(BaseExpr);
433 This = EmitLValue(BaseExpr).getAddress();
435 EmitTypeCheck(TCK_MemberCall, E->
getExprLoc(), This.getPointer(),
444 CGM.getCXXABI().EmitLoadOfMemberFunctionPointer(*
this, BO, This,
445 ThisPtrForCall, MemFnPtr, MPT);
450 getContext().getPointerType(getContext().getTagDeclType(RD));
460 return EmitCall(CGM.getTypes().arrangeCXXMethodCall(Args, FPT, required,
462 Callee, ReturnValue, Args,
nullptr, E->
getExprLoc());
470 "Trying to emit a member call expr on a static method!");
471 return EmitCXXMemberOrOperatorMemberCallExpr(
472 E, MD, ReturnValue,
false,
nullptr,
478 return CGM.getCUDARuntime().EmitCUDAKernelCallExpr(*
this, E, ReturnValue);
500 std::vector<CharUnits> VBPtrOffsets =
502 for (
CharUnits VBPtrOffset : VBPtrOffsets) {
504 if (VBPtrOffset >= NVSize)
506 std::pair<CharUnits, CharUnits> LastStore = Stores.pop_back_val();
507 CharUnits LastStoreOffset = LastStore.first;
508 CharUnits LastStoreSize = LastStore.second;
510 CharUnits SplitBeforeOffset = LastStoreOffset;
511 CharUnits SplitBeforeSize = VBPtrOffset - SplitBeforeOffset;
512 assert(!SplitBeforeSize.
isNegative() &&
"negative store size!");
513 if (!SplitBeforeSize.
isZero())
514 Stores.emplace_back(SplitBeforeOffset, SplitBeforeSize);
516 CharUnits SplitAfterOffset = VBPtrOffset + VBPtrWidth;
517 CharUnits SplitAfterSize = LastStoreSize - SplitAfterOffset;
518 assert(!SplitAfterSize.
isNegative() &&
"negative store size!");
519 if (!SplitAfterSize.
isZero())
520 Stores.emplace_back(SplitAfterOffset, SplitAfterSize);
530 if (!NullConstantForBase->isNullValue()) {
531 llvm::GlobalVariable *NullVariable =
new llvm::GlobalVariable(
533 true, llvm::GlobalVariable::PrivateLinkage,
534 NullConstantForBase, Twine());
538 NullVariable->setAlignment(Align.getQuantity());
543 for (std::pair<CharUnits, CharUnits>
Store : Stores) {
557 for (std::pair<CharUnits, CharUnits>
Store : Stores) {
563 CGF.
Builder.getInt8(0), StoreSizeVal);
571 assert(!Dest.
isIgnored() &&
"Must have a destination!");
593 if (CD->isTrivial() && CD->isDefaultConstructor())
599 if (getLangOpts().ElideConstructors && E->
isElidable()) {
600 assert(getContext().hasSameUnqualifiedType(E->
getType(),
603 EmitAggExpr(E->
getArg(0), Dest);
609 = getContext().getAsArrayType(E->
getType())) {
614 bool ForVirtualBase =
false;
615 bool Delegating =
false;
620 Type = CurGD.getCtorType();
629 ForVirtualBase =
true;
637 EmitCXXConstructorCall(CD, Type, ForVirtualBase, Delegating,
646 Exp = E->getSubExpr();
647 assert(isa<CXXConstructExpr>(Exp) &&
648 "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr");
658 EmitNullInitialization(Dest, E->
getType());
660 assert(!getContext().getAsConstantArrayType(E->
getType())
661 &&
"EmitSynthesizedCXXCopyCtor - Copied-in Array");
662 EmitSynthesizedCXXCopyCtorCall(CD, Dest, Src, E);
680 unsigned minElements,
689 return sizeWithoutCookie;
693 unsigned sizeWidth = CGF.
SizeTy->getBitWidth();
696 llvm::APInt cookieSize(sizeWidth,
706 assert(isa<llvm::IntegerType>(numElements->getType()));
716 llvm::IntegerType *numElementsType
717 = cast<llvm::IntegerType>(numElements->getType());
718 unsigned numElementsWidth = numElementsType->getBitWidth();
721 llvm::APInt arraySizeMultiplier(sizeWidth, 1);
724 type = CAT->getElementType();
725 arraySizeMultiplier *= CAT->getSize();
729 llvm::APInt typeSizeMultiplier(sizeWidth, typeSize.
getQuantity());
730 typeSizeMultiplier *= arraySizeMultiplier;
737 if (llvm::ConstantInt *numElementsC =
738 dyn_cast<llvm::ConstantInt>(numElements)) {
739 const llvm::APInt &count = numElementsC->getValue();
741 bool hasAnyOverflow =
false;
744 if (isSigned && count.isNegative())
745 hasAnyOverflow =
true;
750 else if (numElementsWidth > sizeWidth &&
751 numElementsWidth - sizeWidth > count.countLeadingZeros())
752 hasAnyOverflow =
true;
755 llvm::APInt adjustedCount = count.zextOrTrunc(sizeWidth);
759 if (adjustedCount.ult(minElements))
760 hasAnyOverflow =
true;
765 numElements = llvm::ConstantInt::get(CGF.
SizeTy,
766 adjustedCount * arraySizeMultiplier);
770 llvm::APInt allocationSize
771 = adjustedCount.umul_ov(typeSizeMultiplier, overflow);
772 hasAnyOverflow |= overflow;
775 if (cookieSize != 0) {
778 sizeWithoutCookie = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
780 allocationSize = allocationSize.uadd_ov(cookieSize, overflow);
781 hasAnyOverflow |= overflow;
785 if (hasAnyOverflow) {
786 size = llvm::Constant::getAllOnesValue(CGF.
SizeTy);
788 size = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
811 if (numElementsWidth > sizeWidth) {
812 llvm::APInt threshold(numElementsWidth, 1);
813 threshold <<= sizeWidth;
816 = llvm::ConstantInt::get(numElementsType, threshold);
818 hasOverflow = CGF.
Builder.CreateICmpUGE(numElements, thresholdV);
819 numElements = CGF.
Builder.CreateTrunc(numElements, CGF.
SizeTy);
822 }
else if (isSigned) {
823 if (numElementsWidth < sizeWidth)
824 numElements = CGF.
Builder.CreateSExt(numElements, CGF.
SizeTy);
831 if (typeSizeMultiplier == 1)
832 hasOverflow = CGF.
Builder.CreateICmpSLT(numElements,
833 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
836 }
else if (numElementsWidth < sizeWidth) {
837 numElements = CGF.
Builder.CreateZExt(numElements, CGF.
SizeTy);
840 assert(numElements->getType() == CGF.
SizeTy);
845 hasOverflow = CGF.
Builder.CreateICmpULT(numElements,
846 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
847 }
else if (numElementsWidth > sizeWidth) {
851 hasOverflow = CGF.
Builder.CreateOr(hasOverflow,
852 CGF.
Builder.CreateICmpULT(numElements,
853 llvm::ConstantInt::get(CGF.
SizeTy, minElements)));
866 if (typeSizeMultiplier != 1) {
871 llvm::ConstantInt::get(CGF.
SizeTy, typeSizeMultiplier);
873 CGF.
Builder.CreateCall(umul_with_overflow, {size, tsmV});
877 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
879 hasOverflow = overflowed;
881 size = CGF.
Builder.CreateExtractValue(result, 0);
884 if (arraySizeMultiplier != 1) {
887 if (typeSize.
isOne()) {
888 assert(arraySizeMultiplier == typeSizeMultiplier);
894 llvm::ConstantInt::get(CGF.
SizeTy, arraySizeMultiplier);
895 numElements = CGF.
Builder.CreateMul(numElements, asmV);
900 assert(arraySizeMultiplier == 1);
904 if (cookieSize != 0) {
905 sizeWithoutCookie = size;
912 CGF.
Builder.CreateCall(uadd_with_overflow, {size, cookieSizeV});
916 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
918 hasOverflow = overflowed;
920 size = CGF.
Builder.CreateExtractValue(result, 0);
927 size = CGF.
Builder.CreateSelect(hasOverflow,
928 llvm::Constant::getAllOnesValue(CGF.
SizeTy),
933 sizeWithoutCookie = size;
935 assert(sizeWithoutCookie &&
"didn't set sizeWithoutCookie?");
965 llvm_unreachable(
"bad evaluation kind");
979 unsigned InitListElements = 0;
985 llvm::Instruction *CleanupDominator =
nullptr;
987 CharUnits ElementSize = getContext().getTypeSizeInChars(ElementType);
992 auto TryMemsetInitialization = [&]() ->
bool {
995 if (!CGM.getTypes().isZeroInitializable(ElementType))
1002 auto *RemainingSize = AllocSizeWithoutCookie;
1003 if (InitListElements) {
1005 auto *InitializedSize = llvm::ConstantInt::get(
1006 RemainingSize->getType(),
1007 getContext().getTypeSizeInChars(ElementType).getQuantity() *
1009 RemainingSize = Builder.CreateSub(RemainingSize, InitializedSize);
1013 Builder.CreateMemSet(CurPtr, Builder.getInt8(0), RemainingSize,
false);
1018 if (
const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
1021 if (ILE->isStringLiteralInit()) {
1033 EmitAggExpr(ILE->getInit(0), Slot);
1037 cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe())
1038 ->getSize().getZExtValue();
1041 Builder.getSize(InitListElements),
1047 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1048 if (!ConstNum || !ConstNum->equalsInt(InitListElements)) {
1049 bool OK = TryMemsetInitialization();
1051 assert(OK &&
"couldn't memset character type?");
1056 InitListElements = ILE->getNumInits();
1063 ElementTy = ConvertTypeForMem(AllocType);
1064 CurPtr = Builder.CreateElementBitCast(CurPtr, ElementTy);
1065 InitListElements *= getContext().getConstantArrayElementCount(CAT);
1069 if (needsEHCleanup(DtorKind)) {
1074 EndOfInit = CreateTempAlloca(BeginPtr.
getType(), getPointerAlign(),
1076 CleanupDominator = Builder.CreateStore(BeginPtr.
getPointer(), EndOfInit);
1077 pushIrregularPartialArrayCleanup(BeginPtr.
getPointer(), EndOfInit,
1078 ElementType, ElementAlign,
1079 getDestroyer(DtorKind));
1080 Cleanup = EHStack.stable_begin();
1084 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
1091 Builder.CreateStore(FinishedPtr, EndOfInit);
1097 ILE->getInit(i)->getType(), CurPtr,
1099 CurPtr =
Address(Builder.CreateInBoundsGEP(CurPtr.getPointer(),
1106 Init = ILE->getArrayFiller();
1111 while (Init && Init->
getType()->isConstantArrayType()) {
1115 assert(SubILE->getNumInits() == 0 &&
"explicit inits in array filler?");
1116 Init = SubILE->getArrayFiller();
1120 CurPtr = Builder.CreateBitCast(CurPtr, BeginPtr.
getType());
1125 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1126 if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
1128 if (CleanupDominator)
1129 DeactivateCleanupBlock(Cleanup, CleanupDominator);
1133 assert(Init &&
"have trailing elements to initialize but no initializer");
1145 if (TryMemsetInitialization())
1154 Builder.CreateStore(CurPtr.
getPointer(), EndOfInit);
1157 if (InitListElements)
1158 NumElements = Builder.CreateSub(
1160 llvm::ConstantInt::get(NumElements->getType(), InitListElements));
1161 EmitCXXAggrConstructorCall(Ctor, NumElements, CurPtr, CCE,
1163 CCE->requiresZeroInitialization());
1169 if (isa<ImplicitValueInitExpr>(Init)) {
1170 if (TryMemsetInitialization())
1181 assert(getContext().hasSameUnqualifiedType(ElementType, Init->
getType()) &&
1182 "got wrong type of element to initialize");
1185 if (
auto *ILE = dyn_cast<InitListExpr>(Init))
1186 if (ILE->getNumInits() == 0 && TryMemsetInitialization())
1191 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
1193 if (RType->getDecl()->isStruct()) {
1194 unsigned NumElements = 0;
1195 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RType->getDecl()))
1196 NumElements = CXXRD->getNumBases();
1197 for (
auto *Field : RType->getDecl()->fields())
1198 if (!Field->isUnnamedBitfield())
1201 if (ILE->getNumInits() == NumElements)
1202 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i)
1203 if (!isa<ImplicitValueInitExpr>(ILE->getInit(i)))
1205 if (ILE->getNumInits() == NumElements && TryMemsetInitialization())
1212 llvm::BasicBlock *EntryBB = Builder.GetInsertBlock();
1213 llvm::BasicBlock *LoopBB = createBasicBlock(
"new.loop");
1214 llvm::BasicBlock *ContBB = createBasicBlock(
"new.loop.end");
1218 Builder.CreateInBoundsGEP(BeginPtr.
getPointer(), NumElements,
"array.end");
1224 Builder.CreateICmpEQ(CurPtr.
getPointer(), EndPtr,
"array.isempty");
1225 Builder.CreateCondBr(IsEmpty, ContBB, LoopBB);
1232 llvm::PHINode *CurPtrPhi =
1233 Builder.CreatePHI(CurPtr.
getType(), 2,
"array.cur");
1234 CurPtrPhi->addIncoming(CurPtr.
getPointer(), EntryBB);
1236 CurPtr =
Address(CurPtrPhi, ElementAlign);
1240 Builder.CreateStore(CurPtr.
getPointer(), EndOfInit);
1243 if (!CleanupDominator && needsEHCleanup(DtorKind)) {
1245 ElementType, ElementAlign,
1246 getDestroyer(DtorKind));
1247 Cleanup = EHStack.stable_begin();
1248 CleanupDominator = Builder.CreateUnreachable();
1256 if (CleanupDominator) {
1257 DeactivateCleanupBlock(Cleanup, CleanupDominator);
1258 CleanupDominator->eraseFromParent();
1263 Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr.
getPointer(), 1,
1268 llvm::Value *IsEnd = Builder.CreateICmpEQ(NextPtr, EndPtr,
"array.atend");
1269 Builder.CreateCondBr(IsEnd, ContBB, LoopBB);
1270 CurPtrPhi->addIncoming(NextPtr, Builder.GetInsertBlock());
1282 AllocSizeWithoutCookie);
1294 llvm::Instruction *CallOrInvoke;
1299 Args, CalleeType,
false),
1307 llvm::Function *Fn = dyn_cast<llvm::Function>(CalleePtr);
1309 Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) {
1311 if (llvm::CallInst *CI = dyn_cast<llvm::CallInst>(CallOrInvoke))
1312 CI->addAttribute(llvm::AttributeList::FunctionIndex,
1313 llvm::Attribute::Builtin);
1314 else if (llvm::InvokeInst *II = dyn_cast<llvm::InvokeInst>(CallOrInvoke))
1315 II->addAttribute(llvm::AttributeList::FunctionIndex,
1316 llvm::Attribute::Builtin);
1318 llvm_unreachable(
"unexpected kind of call instruction");
1332 .getCXXOperatorName(IsDelete ? OO_Delete : OO_New);
1335 if (
auto *FD = dyn_cast<FunctionDecl>(
Decl))
1336 if (Ctx.hasSameType(FD->getType(),
QualType(Type, 0)))
1338 llvm_unreachable(
"predeclared global operator new/delete is missing");
1343 struct UsualDeleteParams {
1344 bool DestroyingDelete =
false;
1346 bool Alignment =
false;
1351 UsualDeleteParams Params;
1361 Params.DestroyingDelete =
true;
1373 Params.Alignment =
true;
1377 assert(AI == AE &&
"unexpected usual deallocation function parameter");
1385 template<
typename Traits>
1388 typedef typename Traits::ValueTy ValueTy;
1390 typedef typename Traits::RValueTy RValueTy;
1391 struct PlacementArg {
1396 unsigned NumPlacementArgs : 31;
1397 unsigned PassAlignmentToPlacementDelete : 1;
1403 PlacementArg *getPlacementArgs() {
1404 return reinterpret_cast<PlacementArg *
>(
this + 1);
1408 static size_t getExtraSize(
size_t NumPlacementArgs) {
1409 return NumPlacementArgs *
sizeof(PlacementArg);
1412 CallDeleteDuringNew(
size_t NumPlacementArgs,
1414 ValueTy AllocSize,
bool PassAlignmentToPlacementDelete,
1416 : NumPlacementArgs(NumPlacementArgs),
1417 PassAlignmentToPlacementDelete(PassAlignmentToPlacementDelete),
1418 OperatorDelete(OperatorDelete), Ptr(Ptr), AllocSize(AllocSize),
1419 AllocAlign(AllocAlign) {}
1421 void setPlacementArg(
unsigned I, RValueTy Arg,
QualType Type) {
1422 assert(I < NumPlacementArgs &&
"index out of range");
1423 getPlacementArgs()[I] = {Arg, Type};
1436 UsualDeleteParams Params;
1437 if (NumPlacementArgs) {
1440 Params.Alignment = PassAlignmentToPlacementDelete;
1447 assert(!Params.DestroyingDelete &&
1448 "should not call destroying delete in a new-expression");
1452 DeleteArgs.add(Traits::get(CGF, AllocSize),
1459 if (Params.Alignment)
1460 DeleteArgs.add(
RValue::get(llvm::ConstantInt::get(
1465 for (
unsigned I = 0; I != NumPlacementArgs; ++I) {
1466 auto Arg = getPlacementArgs()[I];
1467 DeleteArgs.add(Traits::get(CGF, Arg.ArgValue), Arg.ArgType);
1489 struct DirectCleanupTraits {
1493 static RValue get(CodeGenFunction &, RValueTy V) {
return V; }
1496 typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup;
1498 DirectCleanup *Cleanup = CGF.
EHStack 1507 auto &Arg = NewArgs[I + NumNonPlacementArgs];
1508 Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty);
1520 struct ConditionalCleanupTraits {
1524 return V.restore(CGF);
1527 typedef CallDeleteDuringNew<ConditionalCleanupTraits> ConditionalCleanup;
1529 ConditionalCleanup *Cleanup = CGF.
EHStack 1538 auto &Arg = NewArgs[I + NumNonPlacementArgs];
1539 Cleanup->setPlacementArg(
1554 unsigned minElements = 0;
1560 ->getSize().getZExtValue();
1569 allocSizeWithoutCookie);
1570 CharUnits allocAlign = getContext().getTypeAlignInChars(allocType);
1581 allocation = EmitPointerWithAlignment(arg, &BaseInfo);
1593 allocatorArgs.
add(
RValue::get(allocSize), getContext().getSizeType());
1600 unsigned ParamsToSkip = 0;
1603 QualType sizeType = getContext().getSizeType();
1607 if (allocSize != allocSizeWithoutCookie) {
1609 allocAlign =
std::max(allocAlign, cookieAlign);
1617 assert(getContext().hasSameUnqualifiedType(
1620 "wrong type for alignment parameter");
1624 assert(allocator->
isVariadic() &&
"can't pass alignment to allocator");
1645 unsigned AllocatorAlign = llvm::PowerOf2Floor(std::min<uint64_t>(
1646 Target.getNewAlign(), getContext().getTypeSize(allocType)));
1648 allocationAlign, getContext().toCharUnitsFromBits(AllocatorAlign));
1651 allocation =
Address(RV.getScalarVal(), allocationAlign);
1661 llvm::BasicBlock *nullCheckBB =
nullptr;
1662 llvm::BasicBlock *contBB =
nullptr;
1669 conditional.
begin(*
this);
1671 nullCheckBB = Builder.GetInsertBlock();
1672 llvm::BasicBlock *notNullBB = createBasicBlock(
"new.notnull");
1673 contBB = createBasicBlock(
"new.cont");
1676 Builder.CreateIsNull(allocation.
getPointer(),
"new.isnull");
1677 Builder.CreateCondBr(isNull, contBB, notNullBB);
1678 EmitBlock(notNullBB);
1684 llvm::Instruction *cleanupDominator =
nullptr;
1689 operatorDeleteCleanup = EHStack.stable_begin();
1690 cleanupDominator = Builder.CreateUnreachable();
1693 assert((allocSize == allocSizeWithoutCookie) ==
1695 if (allocSize != allocSizeWithoutCookie) {
1697 allocation = CGM.getCXXABI().InitializeArrayCookie(*
this, allocation,
1702 llvm::Type *elementTy = ConvertTypeForMem(allocType);
1703 Address result = Builder.CreateElementBitCast(allocation, elementTy);
1709 if (CGM.getCodeGenOpts().StrictVTablePointers &&
1721 allocSizeWithoutCookie);
1727 if (result.
getType() != resultType)
1728 result = Builder.CreateBitCast(result, resultType);
1733 if (operatorDeleteCleanup.
isValid()) {
1734 DeactivateCleanupBlock(operatorDeleteCleanup, cleanupDominator);
1735 cleanupDominator->eraseFromParent();
1740 conditional.
end(*
this);
1742 llvm::BasicBlock *notNullBB = Builder.GetInsertBlock();
1745 llvm::PHINode *PHI = Builder.CreatePHI(resultPtr->getType(), 2);
1746 PHI->addIncoming(resultPtr, notNullBB);
1747 PHI->addIncoming(llvm::Constant::getNullValue(resultPtr->getType()),
1760 assert((!NumElements && CookieSize.
isZero()) ||
1769 auto ParamTypeIt = DeleteFTy->param_type_begin();
1773 llvm::Value *DeletePtr = Builder.CreateBitCast(Ptr, ConvertType(ArgTy));
1777 if (Params.DestroyingDelete) {
1780 auto *V = llvm::UndefValue::get(getTypes().ConvertType(DDTag));
1786 QualType SizeType = *ParamTypeIt++;
1787 CharUnits DeleteTypeSize = getContext().getTypeSizeInChars(DeleteTy);
1788 llvm::Value *Size = llvm::ConstantInt::get(ConvertType(SizeType),
1793 Size = Builder.CreateMul(Size, NumElements);
1796 if (!CookieSize.
isZero())
1797 Size = Builder.CreateAdd(
1798 Size, llvm::ConstantInt::get(SizeTy, CookieSize.
getQuantity()));
1804 if (Params.Alignment) {
1805 QualType AlignValType = *ParamTypeIt++;
1806 CharUnits DeleteTypeAlign = getContext().toCharUnitsFromBits(
1807 getContext().getTypeAlignIfKnown(DeleteTy));
1808 llvm::Value *Align = llvm::ConstantInt::get(ConvertType(AlignValType),
1813 assert(ParamTypeIt == DeleteFTy->param_type_end() &&
1814 "unknown parameter to usual delete function");
1830 : Ptr(Ptr), OperatorDelete(OperatorDelete), ElementType(ElementType) {}
1843 OperatorDelete, ElementType);
1854 if (Dtor && Dtor->isVirtual())
1886 if (Dtor->isVirtual()) {
1899 OperatorDelete, ElementType);
1940 : Ptr(Ptr), OperatorDelete(OperatorDelete), NumElements(NumElements),
1941 ElementType(ElementType), CookieSize(CookieSize) {}
1944 CGF.
EmitDeleteCall(OperatorDelete, Ptr, ElementType, NumElements,
1959 numElements, allocatedPtr, cookieSize);
1961 assert(allocatedPtr &&
"ReadArrayCookie didn't set allocated pointer");
1966 allocatedPtr, operatorDelete,
1967 numElements, elementType,
1972 assert(numElements &&
"no element count for a type with a destructor!");
1980 CGF.
Builder.CreateInBoundsGEP(arrayBegin, numElements,
"delete.end");
1997 Address Ptr = EmitPointerWithAlignment(Arg);
2000 llvm::BasicBlock *DeleteNotNull = createBasicBlock(
"delete.notnull");
2001 llvm::BasicBlock *DeleteEnd = createBasicBlock(
"delete.end");
2005 Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull);
2006 EmitBlock(DeleteNotNull);
2014 EmitBlock(DeleteEnd);
2025 GEP.push_back(Zero);
2029 = getContext().getAsConstantArrayType(DeleteTy)) {
2031 DeleteTy = Arr->getElementType();
2034 GEP.push_back(Zero);
2049 EmitBlock(DeleteEnd);
2055 if (
const auto *CE = dyn_cast<CastExpr>(E)) {
2056 if (!CE->getSubExpr()->isGLValue())
2061 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
2064 if (
const auto *BO = dyn_cast<BinaryOperator>(E))
2065 if (BO->getOpcode() == BO_Comma)
2068 if (
const auto *ACO = dyn_cast<AbstractConditionalOperator>(E))
2074 if (isa<ArraySubscriptExpr>(E))
2077 if (
const auto *UO = dyn_cast<UnaryOperator>(E))
2078 if (UO->getOpcode() == UO_Deref)
2108 llvm::BasicBlock *BadTypeidBlock =
2113 CGF.
Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock);
2126 ConvertType(E->
getType())->getPointerTo();
2131 return Builder.CreateBitCast(TypeInfo, StdTypeInfoPtrTy);
2144 return Builder.CreateBitCast(CGM.GetAddrOfRTTIDescriptor(OperandTy),
2152 return llvm::Constant::getNullValue(DestLTy);
2160 return llvm::UndefValue::get(DestLTy);
2165 CGM.EmitExplicitCastExprType(DCE,
this);
2175 bool isDynamicCastToVoid;
2183 isDynamicCastToVoid =
false;
2184 SrcRecordTy = SrcTy;
2200 assert(SrcRecordTy->
isRecordType() &&
"source type must be a record type!");
2205 bool ShouldNullCheckSrcValue =
2206 CGM.getCXXABI().shouldDynamicCastCallBeNullChecked(SrcTy->
isPointerType(),
2209 llvm::BasicBlock *CastNull =
nullptr;
2210 llvm::BasicBlock *CastNotNull =
nullptr;
2211 llvm::BasicBlock *CastEnd = createBasicBlock(
"dynamic_cast.end");
2213 if (ShouldNullCheckSrcValue) {
2214 CastNull = createBasicBlock(
"dynamic_cast.null");
2215 CastNotNull = createBasicBlock(
"dynamic_cast.notnull");
2218 Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
2219 EmitBlock(CastNotNull);
2223 if (isDynamicCastToVoid) {
2224 Value = CGM.getCXXABI().EmitDynamicCastToVoid(*
this, ThisAddr, SrcRecordTy,
2228 "destination type must be a record type!");
2229 Value = CGM.getCXXABI().EmitDynamicCastCall(*
this, ThisAddr, SrcRecordTy,
2230 DestTy, DestRecordTy, CastEnd);
2231 CastNotNull = Builder.GetInsertBlock();
2234 if (ShouldNullCheckSrcValue) {
2235 EmitBranch(CastEnd);
2237 EmitBlock(CastNull);
2238 EmitBranch(CastEnd);
2243 if (ShouldNullCheckSrcValue) {
2244 llvm::PHINode *PHI = Builder.CreatePHI(Value->getType(), 2);
2245 PHI->addIncoming(Value, CastNotNull);
2246 PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull);
2261 i != e; ++i, ++CurField) {
2263 LValue LV = EmitLValueForFieldInitialization(SlotLV, *CurField);
2264 if (CurField->hasCapturedVLAType()) {
2265 auto VAT = CurField->getCapturedVLAType();
2266 EmitStoreThroughLValue(
RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV);
2268 EmitInitializerForField(*CurField, LV, *i);
A call to an overloaded operator written using operator syntax.
ReturnValueSlot - Contains the address where the return value of a function can be stored...
virtual void EmitBadTypeidCall(CodeGenFunction &CGF)=0
Represents a function declaration or definition.
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Address getAddress() const
void end(CodeGenFunction &CGF)
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
llvm::iterator_range< arg_iterator > placement_arguments()
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
A (possibly-)qualified type.
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 ...
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
CodeGenTypes & getTypes()
static CGCallee BuildAppleKextVirtualCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Type *Ty, const CXXRecordDecl *RD)
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
void EmitARCDestroyWeak(Address addr)
void @objc_destroyWeak(i8** addr) Essentially objc_storeWeak(addr, nil).
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
virtual bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy)=0
Checking the 'this' pointer for a constructor call.
bool isRecordType() const
Decl - This represents one declaration (or definition), e.g.
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet())
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
CharUnits getPointerSize() const
FunctionDecl * getOperatorNew() const
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
The base class of the type hierarchy.
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a call to a C++ constructor.
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
bool isZero() const
isZero - Test whether the quantity equals zero.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool isZero(ProgramStateRef State, const NonLoc &Val)
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
Expr * ignoreParenBaseCasts() LLVM_READONLY
Ignore parentheses and derived-to-base casts.
static llvm::Value * EmitCXXNewAllocSize(CodeGenFunction &CGF, const CXXNewExpr *e, unsigned minElements, llvm::Value *&numElements, llvm::Value *&sizeWithoutCookie)
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::Instruction **callOrInvoke, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type, and using the given argument list which specifies both the LLVM arguments and the types they were derived from.
static saved_type save(CodeGenFunction &CGF, type value)
QualType getReturnType() const
unsigned getNumParams() const
const T * getAs() const
Member-template getAs<specific type>'.
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
IsZeroed_t isZeroed() const
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
llvm::Value * getPointer() const
unsigned getNumPlacementArgs() const
static MemberCallInfo commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE, CallArgList &Args, CallArgList *RtlArgs)
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
bool hasDefinition() const
Expr * getExprOperand() const
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
RValue EmitCXXMemberOrOperatorCall(const CXXMethodDecl *Method, const CGCallee &Callee, ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *E, CallArgList *RtlArgs)
The collection of all-type qualifiers we support.
void add(RValue rvalue, QualType type)
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
An object to manage conditionally-evaluated expressions.
llvm::Value * EmitCXXNewExpr(const CXXNewExpr *E)
Address getAddress() const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ArrayRef< QualType > getParamTypes() const
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
static llvm::Value * EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E, llvm::Type *StdTypeInfoPtrTy)
llvm::IntegerType * SizeTy
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
QualType getDestroyedType() const
Retrieve the type being destroyed.
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.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function...
bool isReplaceableGlobalAllocationFunction(bool *IsAligned=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
FunctionDecl * getOperatorDelete() const
bool isElidable() const
Whether this construction is elidable.
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...
CharUnits - This is an opaque type for sizes expressed in character units.
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
Destroy a __strong variable.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
bool isOne() const
isOne - Test whether the quantity equals one.
Expr * getInitializer()
The initializer of this new-expression.
CharUnits getAlignment() const
Return the alignment of this pointer.
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Checking the operand of a dynamic_cast or a typeid expression.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind...
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
const Type * getClass() const
Scope - A scope is a transient data structure that is used while parsing the program.
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, QualType DeleteTy, llvm::Value *NumElements=nullptr, CharUnits CookieSize=CharUnits())
field_iterator field_begin() const
param_type_iterator param_type_begin() const
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
static void EmitNullBaseClassInitialization(CodeGenFunction &CGF, Address DestPtr, const CXXRecordDecl *Base)
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
void begin(CodeGenFunction &CGF)
bool isNegative() const
isNegative - Test whether the quantity is less than zero.
This object can be modified without requiring retains or releases.
Checking the 'this' pointer for a call to a non-static member function.
TypeSourceInfo * getAllocatedTypeSourceInfo() const
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
void addFrom(const CallArgList &other)
Add all the arguments from another CallArgList to this one.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
ASTContext & getContext() const
Represents a prototype with parameter type info, e.g.
bool isDynamicClass() const
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr)
Returns the extra size required in order to store the array cookie for the given new-expression.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name...
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
SourceLocation getBeginLoc() const
Get the begin source location.
Expr - This represents one expression.
bool isVariadic() const
Whether this function is variadic.
bool isDefaulted() const
Whether this function is defaulted per C++0x.
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.
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.
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, llvm::Value *CompletePtr, QualType ElementType)
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, 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.
const T * castAs() const
Member-template castAs<specific type>.
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
SourceLocation getExprLoc() const LLVM_READONLY
Represents a C++ destructor within a class.
bool isSanitizerChecked() const
unsigned getNumInits() const
const Expr * getCallee() const
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise, it used a '.
llvm::PointerType * getType() const
Return the type of the pointer value.
virtual bool EmitBadCastCall(CodeGenFunction &CGF)=0
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
A class for recording the number of arguments that a function signature requires. ...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type...
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)
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 hasInitializer() const
Whether this new-expression has any initializer at all.
QualType getRecordType(const RecordDecl *Decl) const
static void EmitObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType)
Emit the code for deleting a single object.
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
llvm::Value * EmitCastToVoidPtr(llvm::Value *value)
Emit a cast to void* in the appropriate address space.
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
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...
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
QualType getDestroyedType() const
Retrieve the type being destroyed.
GlobalDecl - represents a global declaration.
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
There is no lifetime qualification on this type.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Assigning into this object requires the old value to be released and the new value to be retained...
QualType getCanonicalType() const
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup. ...
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
virtual llvm::Value * EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, Address ThisPtr, llvm::Type *StdTypeInfoPtrTy)=0
A saved depth on the scope stack.
static CXXRecordDecl * getCXXRecord(const Expr *E)
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Represents a call to a member function that may be written either with member call syntax (e...
A scoped helper to set the current debug location to the specified location or preferred location of ...
static void EmitArrayDelete(CodeGenFunction &CGF, const CXXDeleteExpr *E, Address deletedPtr, QualType elementType)
Emit the code for deleting an array of objects.
Represents a static or instance method of a struct/union/class.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type...
QualType getAllocatedType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE, Address Ptr, QualType ElementType, const CXXDestructorDecl *Dtor)=0
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
All available information about a concrete callee.
const CXXRecordDecl * getBestDynamicClassType() const
For an expression of class type or pointer to class type, return the most derived class decl the expr...
EnumDecl * getDecl() const
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
Assigning into this object requires a lifetime extension.
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.
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function...
FunctionDecl * getOperatorDelete() const
CXXCtorType
C++ constructor types.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
static CharUnits CalculateCookiePadding(CodeGenFunction &CGF, const CXXNewExpr *E)
CharUnits getNonVirtualAlignment() const
getNonVirtualSize - Get the non-virtual alignment (in chars) of an object, which is the alignment of ...
CGFunctionInfo - Class to encapsulate the information about a function definition.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset...
bool isTypeOperand() const
Dataflow Directional Tag Classes.
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This)
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
DeclarationName - The name of a declaration.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
SourceLocation getLocStart() const LLVM_READONLY
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
A pointer to member type per C++ 8.3.3 - Pointers to members.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
llvm::Module & getModule() const
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
bool isStringLiteralInit() const
static llvm::Value * EmitDynamicCastToNull(CodeGenFunction &CGF, QualType DestTy)
AlignmentSource getAlignmentSource() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
CXXMethodDecl * getDevirtualizedMethod(const Expr *Base, bool IsAppleKext)
If it's possible to devirtualize a call to this method, return the called function.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Represents a call to a CUDA kernel function.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Expr * getArg(unsigned Arg)
Return the specified argument.
Base for LValueReferenceType and RValueReferenceType.
void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp)
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.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
bool isConstantArrayType() const
static bool isGLValueFromPointerDeref(const Expr *E)
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Reading or writing from this object requires a barrier call.
Overlap_t mayOverlap() const
QualType getParamType(unsigned i) const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Represents a C++ struct/union/class.
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Get the type of the implicit "this" parameter used by a method.
bool hasStrongOrWeakObjCLifetime() const
static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, QualType ElementType, llvm::Type *ElementTy, Address NewPtr, llvm::Value *NumElements, llvm::Value *AllocSizeWithoutCookie)
llvm::Type * ConvertType(QualType T)
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const CallExpr *TheCallExpr, bool IsDelete)
void EmitCXXDeleteExpr(const CXXDeleteExpr *E)
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
T * pushCleanupWithExtra(CleanupKind Kind, size_t N, As... A)
Push a cleanup with non-constant storage requirements on the stack.
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, llvm::FunctionType *FTy)
static UsualDeleteParams getUsualDeleteParams(const FunctionDecl *FD)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
llvm::Constant * tryEmitAbstract(const Expr *E, QualType T)
Try to emit the result of the given expression as an abstract constant.
CGCXXABI & getCXXABI() const
__DEVICE__ int max(int __a, int __b)
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument for this lambda expression...
bool isAlwaysNull() const
isAlwaysNull - Return whether the result of the dynamic_cast is proven to always be null...
static RValue get(llvm::Value *V)
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional, const FunctionDecl *FD)
Compute the arguments required by the given formal prototype, given that there may be some additional...
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
bool isPointerType() const
static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init, QualType AllocType, Address NewPtr, AggValueSlot::Overlap_t MayOverlap)
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...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
virtual std::vector< CharUnits > getVBPtrOffsets(const CXXRecordDecl *RD)
Gets the offsets of all the virtual base pointers in a given class.
bool shouldNullCheckAllocation(const ASTContext &Ctx) const
True if the allocation result needs to be null-checked.
LValue - This represents an lvalue references.
An abstract representation of regular/ObjC call/message targets.
Information for lazily generating a cleanup.
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr...
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
TranslationUnitDecl * getTranslationUnitDecl()
CallArgList - Type for representing both the value and type of arguments in a call.
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
Represents the canonical version of C arrays with a specified constant size.
Represents an implicitly-generated value initialization of an object of a given type.
QualType getPointeeType() const
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
ConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
param_type_iterator param_type_end() const