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()) {
182 return EmitCall(getContext().getPointerType(MD->getType()), callee, CE,
191 return EmitCXXMemberOrOperatorMemberCallExpr(
192 CE, MD, ReturnValue, HasQualifier, Qualifier, IsArrow, Base);
199 assert(isa<CXXMemberCallExpr>(CE) || isa<CXXOperatorCallExpr>(CE));
202 bool CanUseVirtualCall = MD->
isVirtual() && !HasQualifier;
205 if (CanUseVirtualCall &&
209 assert(DevirtualizedMethod);
219 DevirtualizedMethod =
nullptr;
229 DevirtualizedMethod =
nullptr;
237 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(CE)) {
238 if (OCE->isAssignmentOp()) {
239 RtlArgs = &RtlArgStorage;
242 0, EvaluationOrder::ForceRightToLeft);
250 Address ThisValue = EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
251 This = MakeAddrLValue(ThisValue, Base->
getType(), BaseInfo, TBAAInfo);
253 This = EmitLValue(Base);
258 if (isa<CXXDestructorDecl>(MD))
return RValue::get(
nullptr);
259 if (isa<CXXConstructorDecl>(MD) &&
260 cast<CXXConstructorDecl>(MD)->isDefaultConstructor())
267 LValue RHS = isa<CXXOperatorCallExpr>(CE)
268 ? MakeNaturalAlignAddrLValue(
269 (*RtlArgs)[0].getRValue(*this).getScalarVal(),
272 EmitAggregateAssign(This, RHS, CE->
getType());
276 if (isa<CXXConstructorDecl>(MD) &&
277 cast<CXXConstructorDecl>(MD)->isCopyOrMoveConstructor()) {
279 assert(CE->
getNumArgs() == 1 &&
"unexpected argcount for trivial ctor");
281 LValue RHS = EmitLValue(Arg);
282 LValue Dest = MakeAddrLValue(This.getAddress(), Arg->getType());
285 EmitAggregateCopy(Dest, RHS, Arg->
getType(),
289 llvm_unreachable(
"unknown trivial member function");
295 DevirtualizedMethod ? DevirtualizedMethod : MD;
297 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl))
298 FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration(
300 else if (
const auto *Ctor = dyn_cast<CXXConstructorDecl>(CalleeDecl))
301 FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration(
304 FInfo = &CGM.getTypes().arrangeCXXMethodDeclaration(CalleeDecl);
306 llvm::FunctionType *Ty = CGM.getTypes().GetFunctionType(*FInfo);
317 if (
const auto *CMCE = dyn_cast<CXXMemberCallExpr>(CE)) {
318 auto *IOA = CMCE->getImplicitObjectArgument();
319 bool IsImplicitObjectCXXThis = IsWrappedCXXThis(IOA);
320 if (IsImplicitObjectCXXThis)
321 SkippedChecks.
set(SanitizerKind::Alignment,
true);
322 if (IsImplicitObjectCXXThis || isa<DeclRefExpr>(IOA))
323 SkippedChecks.
set(SanitizerKind::Null,
true);
340 bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod;
344 "Destructor shouldn't have explicit parameters");
345 assert(ReturnValue.
isNull() &&
"Destructor shouldn't have return value");
346 if (UseVirtualCall) {
347 CGM.getCXXABI().EmitVirtualDestructorCall(
349 cast<CXXMemberCallExpr>(CE));
352 if (getLangOpts().AppleKext && MD->
isVirtual() && HasQualifier)
354 else if (!DevirtualizedMethod)
360 cast<CXXDestructorDecl>(DevirtualizedMethod);
365 EmitCXXMemberOrOperatorCall(
366 CalleeDecl, Callee, ReturnValue, This.getPointer(),
377 }
else if (UseVirtualCall) {
380 if (SanOpts.has(SanitizerKind::CFINVCall) &&
384 std::tie(VTable, RD) =
385 CGM.getCXXABI().LoadVTablePtr(*
this, This.getAddress(),
387 EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->
getBeginLoc());
390 if (getLangOpts().AppleKext && MD->
isVirtual() && HasQualifier)
392 else if (!DevirtualizedMethod)
404 CGM.getCXXABI().adjustThisArgumentForVirtualFunctionCall(
405 *
this, CalleeDecl, This.getAddress(), UseVirtualCall);
406 This.setAddress(NewThisAddr);
409 return EmitCXXMemberOrOperatorCall(
410 CalleeDecl, Callee, ReturnValue, This.getPointer(),
433 This = EmitPointerWithAlignment(BaseExpr);
435 This = EmitLValue(BaseExpr).getAddress();
437 EmitTypeCheck(TCK_MemberCall, E->
getExprLoc(), This.getPointer(),
446 CGM.getCXXABI().EmitLoadOfMemberFunctionPointer(*
this, BO, This,
447 ThisPtrForCall, MemFnPtr, MPT);
452 getContext().getPointerType(getContext().getTagDeclType(RD));
462 return EmitCall(CGM.getTypes().arrangeCXXMethodCall(Args, FPT, required,
464 Callee, ReturnValue, Args,
nullptr, E->
getExprLoc());
472 "Trying to emit a member call expr on a static method!");
473 return EmitCXXMemberOrOperatorMemberCallExpr(
474 E, MD, ReturnValue,
false,
nullptr,
480 return CGM.getCUDARuntime().EmitCUDAKernelCallExpr(*
this, E, ReturnValue);
502 std::vector<CharUnits> VBPtrOffsets =
504 for (
CharUnits VBPtrOffset : VBPtrOffsets) {
506 if (VBPtrOffset >= NVSize)
508 std::pair<CharUnits, CharUnits> LastStore = Stores.pop_back_val();
509 CharUnits LastStoreOffset = LastStore.first;
510 CharUnits LastStoreSize = LastStore.second;
512 CharUnits SplitBeforeOffset = LastStoreOffset;
513 CharUnits SplitBeforeSize = VBPtrOffset - SplitBeforeOffset;
514 assert(!SplitBeforeSize.
isNegative() &&
"negative store size!");
515 if (!SplitBeforeSize.
isZero())
516 Stores.emplace_back(SplitBeforeOffset, SplitBeforeSize);
518 CharUnits SplitAfterOffset = VBPtrOffset + VBPtrWidth;
519 CharUnits SplitAfterSize = LastStoreSize - SplitAfterOffset;
520 assert(!SplitAfterSize.
isNegative() &&
"negative store size!");
521 if (!SplitAfterSize.
isZero())
522 Stores.emplace_back(SplitAfterOffset, SplitAfterSize);
532 if (!NullConstantForBase->isNullValue()) {
533 llvm::GlobalVariable *NullVariable =
new llvm::GlobalVariable(
535 true, llvm::GlobalVariable::PrivateLinkage,
536 NullConstantForBase, Twine());
540 NullVariable->setAlignment(Align.getQuantity());
545 for (std::pair<CharUnits, CharUnits>
Store : Stores) {
559 for (std::pair<CharUnits, CharUnits>
Store : Stores) {
565 CGF.
Builder.getInt8(0), StoreSizeVal);
573 assert(!Dest.
isIgnored() &&
"Must have a destination!");
595 if (CD->isTrivial() && CD->isDefaultConstructor())
601 if (getLangOpts().ElideConstructors && E->
isElidable()) {
602 assert(getContext().hasSameUnqualifiedType(E->
getType(),
605 EmitAggExpr(E->
getArg(0), Dest);
611 = getContext().getAsArrayType(E->
getType())) {
616 bool ForVirtualBase =
false;
617 bool Delegating =
false;
622 Type = CurGD.getCtorType();
631 ForVirtualBase =
true;
639 EmitCXXConstructorCall(CD, Type, ForVirtualBase, Delegating,
648 Exp = E->getSubExpr();
649 assert(isa<CXXConstructExpr>(Exp) &&
650 "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr");
660 EmitNullInitialization(Dest, E->
getType());
662 assert(!getContext().getAsConstantArrayType(E->
getType())
663 &&
"EmitSynthesizedCXXCopyCtor - Copied-in Array");
664 EmitSynthesizedCXXCopyCtorCall(CD, Dest, Src, E);
682 unsigned minElements,
691 return sizeWithoutCookie;
695 unsigned sizeWidth = CGF.
SizeTy->getBitWidth();
698 llvm::APInt cookieSize(sizeWidth,
708 assert(isa<llvm::IntegerType>(numElements->getType()));
718 llvm::IntegerType *numElementsType
719 = cast<llvm::IntegerType>(numElements->getType());
720 unsigned numElementsWidth = numElementsType->getBitWidth();
723 llvm::APInt arraySizeMultiplier(sizeWidth, 1);
726 type = CAT->getElementType();
727 arraySizeMultiplier *= CAT->getSize();
731 llvm::APInt typeSizeMultiplier(sizeWidth, typeSize.
getQuantity());
732 typeSizeMultiplier *= arraySizeMultiplier;
739 if (llvm::ConstantInt *numElementsC =
740 dyn_cast<llvm::ConstantInt>(numElements)) {
741 const llvm::APInt &count = numElementsC->getValue();
743 bool hasAnyOverflow =
false;
746 if (isSigned && count.isNegative())
747 hasAnyOverflow =
true;
752 else if (numElementsWidth > sizeWidth &&
753 numElementsWidth - sizeWidth > count.countLeadingZeros())
754 hasAnyOverflow =
true;
757 llvm::APInt adjustedCount = count.zextOrTrunc(sizeWidth);
761 if (adjustedCount.ult(minElements))
762 hasAnyOverflow =
true;
767 numElements = llvm::ConstantInt::get(CGF.
SizeTy,
768 adjustedCount * arraySizeMultiplier);
772 llvm::APInt allocationSize
773 = adjustedCount.umul_ov(typeSizeMultiplier, overflow);
774 hasAnyOverflow |= overflow;
777 if (cookieSize != 0) {
780 sizeWithoutCookie = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
782 allocationSize = allocationSize.uadd_ov(cookieSize, overflow);
783 hasAnyOverflow |= overflow;
787 if (hasAnyOverflow) {
788 size = llvm::Constant::getAllOnesValue(CGF.
SizeTy);
790 size = llvm::ConstantInt::get(CGF.
SizeTy, allocationSize);
813 if (numElementsWidth > sizeWidth) {
814 llvm::APInt threshold(numElementsWidth, 1);
815 threshold <<= sizeWidth;
818 = llvm::ConstantInt::get(numElementsType, threshold);
820 hasOverflow = CGF.
Builder.CreateICmpUGE(numElements, thresholdV);
821 numElements = CGF.
Builder.CreateTrunc(numElements, CGF.
SizeTy);
824 }
else if (isSigned) {
825 if (numElementsWidth < sizeWidth)
826 numElements = CGF.
Builder.CreateSExt(numElements, CGF.
SizeTy);
833 if (typeSizeMultiplier == 1)
834 hasOverflow = CGF.
Builder.CreateICmpSLT(numElements,
835 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
838 }
else if (numElementsWidth < sizeWidth) {
839 numElements = CGF.
Builder.CreateZExt(numElements, CGF.
SizeTy);
842 assert(numElements->getType() == CGF.
SizeTy);
847 hasOverflow = CGF.
Builder.CreateICmpULT(numElements,
848 llvm::ConstantInt::get(CGF.
SizeTy, minElements));
849 }
else if (numElementsWidth > sizeWidth) {
853 hasOverflow = CGF.
Builder.CreateOr(hasOverflow,
854 CGF.
Builder.CreateICmpULT(numElements,
855 llvm::ConstantInt::get(CGF.
SizeTy, minElements)));
868 if (typeSizeMultiplier != 1) {
873 llvm::ConstantInt::get(CGF.
SizeTy, typeSizeMultiplier);
875 CGF.
Builder.CreateCall(umul_with_overflow, {size, tsmV});
879 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
881 hasOverflow = overflowed;
883 size = CGF.
Builder.CreateExtractValue(result, 0);
886 if (arraySizeMultiplier != 1) {
889 if (typeSize.
isOne()) {
890 assert(arraySizeMultiplier == typeSizeMultiplier);
896 llvm::ConstantInt::get(CGF.
SizeTy, arraySizeMultiplier);
897 numElements = CGF.
Builder.CreateMul(numElements, asmV);
902 assert(arraySizeMultiplier == 1);
906 if (cookieSize != 0) {
907 sizeWithoutCookie = size;
914 CGF.
Builder.CreateCall(uadd_with_overflow, {size, cookieSizeV});
918 hasOverflow = CGF.
Builder.CreateOr(hasOverflow, overflowed);
920 hasOverflow = overflowed;
922 size = CGF.
Builder.CreateExtractValue(result, 0);
929 size = CGF.
Builder.CreateSelect(hasOverflow,
930 llvm::Constant::getAllOnesValue(CGF.
SizeTy),
935 sizeWithoutCookie = size;
937 assert(sizeWithoutCookie &&
"didn't set sizeWithoutCookie?");
967 llvm_unreachable(
"bad evaluation kind");
981 unsigned InitListElements = 0;
987 llvm::Instruction *CleanupDominator =
nullptr;
989 CharUnits ElementSize = getContext().getTypeSizeInChars(ElementType);
994 auto TryMemsetInitialization = [&]() ->
bool {
997 if (!CGM.getTypes().isZeroInitializable(ElementType))
1004 auto *RemainingSize = AllocSizeWithoutCookie;
1005 if (InitListElements) {
1007 auto *InitializedSize = llvm::ConstantInt::get(
1008 RemainingSize->getType(),
1009 getContext().getTypeSizeInChars(ElementType).getQuantity() *
1011 RemainingSize = Builder.CreateSub(RemainingSize, InitializedSize);
1015 Builder.CreateMemSet(CurPtr, Builder.getInt8(0), RemainingSize,
false);
1020 if (
const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
1023 if (ILE->isStringLiteralInit()) {
1035 EmitAggExpr(ILE->getInit(0), Slot);
1039 cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe())
1040 ->getSize().getZExtValue();
1043 Builder.getSize(InitListElements),
1049 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1050 if (!ConstNum || !ConstNum->equalsInt(InitListElements)) {
1051 bool OK = TryMemsetInitialization();
1053 assert(OK &&
"couldn't memset character type?");
1058 InitListElements = ILE->getNumInits();
1065 ElementTy = ConvertTypeForMem(AllocType);
1066 CurPtr = Builder.CreateElementBitCast(CurPtr, ElementTy);
1067 InitListElements *= getContext().getConstantArrayElementCount(CAT);
1071 if (needsEHCleanup(DtorKind)) {
1076 EndOfInit = CreateTempAlloca(BeginPtr.
getType(), getPointerAlign(),
1078 CleanupDominator = Builder.CreateStore(BeginPtr.
getPointer(), EndOfInit);
1079 pushIrregularPartialArrayCleanup(BeginPtr.
getPointer(), EndOfInit,
1080 ElementType, ElementAlign,
1081 getDestroyer(DtorKind));
1082 Cleanup = EHStack.stable_begin();
1086 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
1093 Builder.CreateStore(FinishedPtr, EndOfInit);
1099 ILE->getInit(i)->getType(), CurPtr,
1101 CurPtr =
Address(Builder.CreateInBoundsGEP(CurPtr.getPointer(),
1108 Init = ILE->getArrayFiller();
1113 while (Init && Init->
getType()->isConstantArrayType()) {
1117 assert(SubILE->getNumInits() == 0 &&
"explicit inits in array filler?");
1118 Init = SubILE->getArrayFiller();
1122 CurPtr = Builder.CreateBitCast(CurPtr, BeginPtr.
getType());
1127 llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements);
1128 if (ConstNum && ConstNum->getZExtValue() <= InitListElements) {
1130 if (CleanupDominator)
1131 DeactivateCleanupBlock(Cleanup, CleanupDominator);
1135 assert(Init &&
"have trailing elements to initialize but no initializer");
1147 if (TryMemsetInitialization())
1156 Builder.CreateStore(CurPtr.
getPointer(), EndOfInit);
1159 if (InitListElements)
1160 NumElements = Builder.CreateSub(
1162 llvm::ConstantInt::get(NumElements->getType(), InitListElements));
1163 EmitCXXAggrConstructorCall(Ctor, NumElements, CurPtr, CCE,
1165 CCE->requiresZeroInitialization());
1171 if (isa<ImplicitValueInitExpr>(Init)) {
1172 if (TryMemsetInitialization())
1183 assert(getContext().hasSameUnqualifiedType(ElementType, Init->
getType()) &&
1184 "got wrong type of element to initialize");
1187 if (
auto *ILE = dyn_cast<InitListExpr>(Init))
1188 if (ILE->getNumInits() == 0 && TryMemsetInitialization())
1193 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
1195 if (RType->getDecl()->isStruct()) {
1196 unsigned NumElements = 0;
1197 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RType->getDecl()))
1198 NumElements = CXXRD->getNumBases();
1199 for (
auto *Field : RType->getDecl()->fields())
1200 if (!Field->isUnnamedBitfield())
1203 if (ILE->getNumInits() == NumElements)
1204 for (
unsigned i = 0, e = ILE->getNumInits(); i != e; ++i)
1205 if (!isa<ImplicitValueInitExpr>(ILE->getInit(i)))
1207 if (ILE->getNumInits() == NumElements && TryMemsetInitialization())
1214 llvm::BasicBlock *EntryBB = Builder.GetInsertBlock();
1215 llvm::BasicBlock *LoopBB = createBasicBlock(
"new.loop");
1216 llvm::BasicBlock *ContBB = createBasicBlock(
"new.loop.end");
1220 Builder.CreateInBoundsGEP(BeginPtr.
getPointer(), NumElements,
"array.end");
1226 Builder.CreateICmpEQ(CurPtr.
getPointer(), EndPtr,
"array.isempty");
1227 Builder.CreateCondBr(IsEmpty, ContBB, LoopBB);
1234 llvm::PHINode *CurPtrPhi =
1235 Builder.CreatePHI(CurPtr.
getType(), 2,
"array.cur");
1236 CurPtrPhi->addIncoming(CurPtr.
getPointer(), EntryBB);
1238 CurPtr =
Address(CurPtrPhi, ElementAlign);
1242 Builder.CreateStore(CurPtr.
getPointer(), EndOfInit);
1245 if (!CleanupDominator && needsEHCleanup(DtorKind)) {
1247 ElementType, ElementAlign,
1248 getDestroyer(DtorKind));
1249 Cleanup = EHStack.stable_begin();
1250 CleanupDominator = Builder.CreateUnreachable();
1258 if (CleanupDominator) {
1259 DeactivateCleanupBlock(Cleanup, CleanupDominator);
1260 CleanupDominator->eraseFromParent();
1265 Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr.
getPointer(), 1,
1270 llvm::Value *IsEnd = Builder.CreateICmpEQ(NextPtr, EndPtr,
"array.atend");
1271 Builder.CreateCondBr(IsEnd, ContBB, LoopBB);
1272 CurPtrPhi->addIncoming(NextPtr, Builder.GetInsertBlock());
1284 AllocSizeWithoutCookie);
1296 llvm::Instruction *CallOrInvoke;
1301 Args, CalleeType,
false),
1309 llvm::Function *Fn = dyn_cast<llvm::Function>(CalleePtr);
1311 Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) {
1313 if (llvm::CallInst *CI = dyn_cast<llvm::CallInst>(CallOrInvoke))
1314 CI->addAttribute(llvm::AttributeList::FunctionIndex,
1315 llvm::Attribute::Builtin);
1316 else if (llvm::InvokeInst *II = dyn_cast<llvm::InvokeInst>(CallOrInvoke))
1317 II->addAttribute(llvm::AttributeList::FunctionIndex,
1318 llvm::Attribute::Builtin);
1320 llvm_unreachable(
"unexpected kind of call instruction");
1334 .getCXXOperatorName(IsDelete ? OO_Delete : OO_New);
1337 if (
auto *FD = dyn_cast<FunctionDecl>(
Decl))
1338 if (Ctx.hasSameType(FD->getType(),
QualType(Type, 0)))
1340 llvm_unreachable(
"predeclared global operator new/delete is missing");
1345 struct UsualDeleteParams {
1346 bool DestroyingDelete =
false;
1348 bool Alignment =
false;
1353 UsualDeleteParams Params;
1363 Params.DestroyingDelete =
true;
1375 Params.Alignment =
true;
1379 assert(AI == AE &&
"unexpected usual deallocation function parameter");
1387 template<
typename Traits>
1390 typedef typename Traits::ValueTy ValueTy;
1392 typedef typename Traits::RValueTy RValueTy;
1393 struct PlacementArg {
1398 unsigned NumPlacementArgs : 31;
1399 unsigned PassAlignmentToPlacementDelete : 1;
1405 PlacementArg *getPlacementArgs() {
1406 return reinterpret_cast<PlacementArg *
>(
this + 1);
1410 static size_t getExtraSize(
size_t NumPlacementArgs) {
1411 return NumPlacementArgs *
sizeof(PlacementArg);
1414 CallDeleteDuringNew(
size_t NumPlacementArgs,
1416 ValueTy AllocSize,
bool PassAlignmentToPlacementDelete,
1418 : NumPlacementArgs(NumPlacementArgs),
1419 PassAlignmentToPlacementDelete(PassAlignmentToPlacementDelete),
1420 OperatorDelete(OperatorDelete), Ptr(Ptr), AllocSize(AllocSize),
1421 AllocAlign(AllocAlign) {}
1423 void setPlacementArg(
unsigned I, RValueTy Arg,
QualType Type) {
1424 assert(I < NumPlacementArgs &&
"index out of range");
1425 getPlacementArgs()[I] = {Arg, Type};
1438 UsualDeleteParams Params;
1439 if (NumPlacementArgs) {
1442 Params.Alignment = PassAlignmentToPlacementDelete;
1449 assert(!Params.DestroyingDelete &&
1450 "should not call destroying delete in a new-expression");
1454 DeleteArgs.add(Traits::get(CGF, AllocSize),
1461 if (Params.Alignment)
1462 DeleteArgs.add(
RValue::get(llvm::ConstantInt::get(
1467 for (
unsigned I = 0; I != NumPlacementArgs; ++I) {
1468 auto Arg = getPlacementArgs()[I];
1469 DeleteArgs.add(Traits::get(CGF, Arg.ArgValue), Arg.ArgType);
1491 struct DirectCleanupTraits {
1495 static RValue get(CodeGenFunction &, RValueTy V) {
return V; }
1498 typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup;
1500 DirectCleanup *Cleanup = CGF.
EHStack 1509 auto &Arg = NewArgs[I + NumNonPlacementArgs];
1510 Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty);
1522 struct ConditionalCleanupTraits {
1526 return V.restore(CGF);
1529 typedef CallDeleteDuringNew<ConditionalCleanupTraits> ConditionalCleanup;
1531 ConditionalCleanup *Cleanup = CGF.
EHStack 1540 auto &Arg = NewArgs[I + NumNonPlacementArgs];
1541 Cleanup->setPlacementArg(
1556 unsigned minElements = 0;
1562 ->getSize().getZExtValue();
1571 allocSizeWithoutCookie);
1572 CharUnits allocAlign = getContext().getTypeAlignInChars(allocType);
1583 allocation = EmitPointerWithAlignment(arg, &BaseInfo);
1595 allocatorArgs.
add(
RValue::get(allocSize), getContext().getSizeType());
1602 unsigned ParamsToSkip = 0;
1605 QualType sizeType = getContext().getSizeType();
1609 if (allocSize != allocSizeWithoutCookie) {
1611 allocAlign =
std::max(allocAlign, cookieAlign);
1619 assert(getContext().hasSameUnqualifiedType(
1622 "wrong type for alignment parameter");
1626 assert(allocator->
isVariadic() &&
"can't pass alignment to allocator");
1647 unsigned AllocatorAlign = llvm::PowerOf2Floor(std::min<uint64_t>(
1648 Target.getNewAlign(), getContext().getTypeSize(allocType)));
1650 allocationAlign, getContext().toCharUnitsFromBits(AllocatorAlign));
1653 allocation =
Address(RV.getScalarVal(), allocationAlign);
1662 sanitizePerformTypeCheck());
1664 llvm::BasicBlock *nullCheckBB =
nullptr;
1665 llvm::BasicBlock *contBB =
nullptr;
1672 conditional.
begin(*
this);
1674 nullCheckBB = Builder.GetInsertBlock();
1675 llvm::BasicBlock *notNullBB = createBasicBlock(
"new.notnull");
1676 contBB = createBasicBlock(
"new.cont");
1679 Builder.CreateIsNull(allocation.
getPointer(),
"new.isnull");
1680 Builder.CreateCondBr(isNull, contBB, notNullBB);
1681 EmitBlock(notNullBB);
1687 llvm::Instruction *cleanupDominator =
nullptr;
1692 operatorDeleteCleanup = EHStack.stable_begin();
1693 cleanupDominator = Builder.CreateUnreachable();
1696 assert((allocSize == allocSizeWithoutCookie) ==
1698 if (allocSize != allocSizeWithoutCookie) {
1700 allocation = CGM.getCXXABI().InitializeArrayCookie(*
this, allocation,
1705 llvm::Type *elementTy = ConvertTypeForMem(allocType);
1706 Address result = Builder.CreateElementBitCast(allocation, elementTy);
1712 if (CGM.getCodeGenOpts().StrictVTablePointers &&
1724 allocSizeWithoutCookie);
1730 if (result.
getType() != resultType)
1731 result = Builder.CreateBitCast(result, resultType);
1736 if (operatorDeleteCleanup.
isValid()) {
1737 DeactivateCleanupBlock(operatorDeleteCleanup, cleanupDominator);
1738 cleanupDominator->eraseFromParent();
1743 conditional.
end(*
this);
1745 llvm::BasicBlock *notNullBB = Builder.GetInsertBlock();
1748 llvm::PHINode *PHI = Builder.CreatePHI(resultPtr->getType(), 2);
1749 PHI->addIncoming(resultPtr, notNullBB);
1750 PHI->addIncoming(llvm::Constant::getNullValue(resultPtr->getType()),
1763 assert((!NumElements && CookieSize.
isZero()) ||
1772 auto ParamTypeIt = DeleteFTy->param_type_begin();
1776 llvm::Value *DeletePtr = Builder.CreateBitCast(Ptr, ConvertType(ArgTy));
1780 if (Params.DestroyingDelete) {
1783 auto *V = llvm::UndefValue::get(getTypes().ConvertType(DDTag));
1789 QualType SizeType = *ParamTypeIt++;
1790 CharUnits DeleteTypeSize = getContext().getTypeSizeInChars(DeleteTy);
1791 llvm::Value *Size = llvm::ConstantInt::get(ConvertType(SizeType),
1796 Size = Builder.CreateMul(Size, NumElements);
1799 if (!CookieSize.
isZero())
1800 Size = Builder.CreateAdd(
1801 Size, llvm::ConstantInt::get(SizeTy, CookieSize.
getQuantity()));
1807 if (Params.Alignment) {
1808 QualType AlignValType = *ParamTypeIt++;
1809 CharUnits DeleteTypeAlign = getContext().toCharUnitsFromBits(
1810 getContext().getTypeAlignIfKnown(DeleteTy));
1811 llvm::Value *Align = llvm::ConstantInt::get(ConvertType(AlignValType),
1816 assert(ParamTypeIt == DeleteFTy->param_type_end() &&
1817 "unknown parameter to usual delete function");
1833 : Ptr(Ptr), OperatorDelete(OperatorDelete), ElementType(ElementType) {}
1846 OperatorDelete, ElementType);
1857 if (Dtor && Dtor->isVirtual())
1889 if (Dtor->isVirtual()) {
1902 OperatorDelete, ElementType);
1943 : Ptr(Ptr), OperatorDelete(OperatorDelete), NumElements(NumElements),
1944 ElementType(ElementType), CookieSize(CookieSize) {}
1947 CGF.
EmitDeleteCall(OperatorDelete, Ptr, ElementType, NumElements,
1962 numElements, allocatedPtr, cookieSize);
1964 assert(allocatedPtr &&
"ReadArrayCookie didn't set allocated pointer");
1969 allocatedPtr, operatorDelete,
1970 numElements, elementType,
1975 assert(numElements &&
"no element count for a type with a destructor!");
1983 CGF.
Builder.CreateInBoundsGEP(arrayBegin, numElements,
"delete.end");
2000 Address Ptr = EmitPointerWithAlignment(Arg);
2003 llvm::BasicBlock *DeleteNotNull = createBasicBlock(
"delete.notnull");
2004 llvm::BasicBlock *DeleteEnd = createBasicBlock(
"delete.end");
2008 Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull);
2009 EmitBlock(DeleteNotNull);
2017 EmitBlock(DeleteEnd);
2028 GEP.push_back(Zero);
2032 = getContext().getAsConstantArrayType(DeleteTy)) {
2034 DeleteTy = Arr->getElementType();
2037 GEP.push_back(Zero);
2052 EmitBlock(DeleteEnd);
2058 if (
const auto *CE = dyn_cast<CastExpr>(E)) {
2059 if (!CE->getSubExpr()->isGLValue())
2064 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
2067 if (
const auto *BO = dyn_cast<BinaryOperator>(E))
2068 if (BO->getOpcode() == BO_Comma)
2071 if (
const auto *ACO = dyn_cast<AbstractConditionalOperator>(E))
2077 if (isa<ArraySubscriptExpr>(E))
2080 if (
const auto *UO = dyn_cast<UnaryOperator>(E))
2081 if (UO->getOpcode() == UO_Deref)
2111 llvm::BasicBlock *BadTypeidBlock =
2116 CGF.
Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock);
2129 ConvertType(E->
getType())->getPointerTo();
2134 return Builder.CreateBitCast(TypeInfo, StdTypeInfoPtrTy);
2147 return Builder.CreateBitCast(CGM.GetAddrOfRTTIDescriptor(OperandTy),
2155 return llvm::Constant::getNullValue(DestLTy);
2163 return llvm::UndefValue::get(DestLTy);
2168 CGM.EmitExplicitCastExprType(DCE,
this);
2178 bool isDynamicCastToVoid;
2186 isDynamicCastToVoid =
false;
2187 SrcRecordTy = SrcTy;
2203 assert(SrcRecordTy->
isRecordType() &&
"source type must be a record type!");
2208 bool ShouldNullCheckSrcValue =
2209 CGM.getCXXABI().shouldDynamicCastCallBeNullChecked(SrcTy->
isPointerType(),
2212 llvm::BasicBlock *CastNull =
nullptr;
2213 llvm::BasicBlock *CastNotNull =
nullptr;
2214 llvm::BasicBlock *CastEnd = createBasicBlock(
"dynamic_cast.end");
2216 if (ShouldNullCheckSrcValue) {
2217 CastNull = createBasicBlock(
"dynamic_cast.null");
2218 CastNotNull = createBasicBlock(
"dynamic_cast.notnull");
2221 Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
2222 EmitBlock(CastNotNull);
2226 if (isDynamicCastToVoid) {
2227 Value = CGM.getCXXABI().EmitDynamicCastToVoid(*
this, ThisAddr, SrcRecordTy,
2231 "destination type must be a record type!");
2232 Value = CGM.getCXXABI().EmitDynamicCastCall(*
this, ThisAddr, SrcRecordTy,
2233 DestTy, DestRecordTy, CastEnd);
2234 CastNotNull = Builder.GetInsertBlock();
2237 if (ShouldNullCheckSrcValue) {
2238 EmitBranch(CastEnd);
2240 EmitBlock(CastNull);
2241 EmitBranch(CastEnd);
2246 if (ShouldNullCheckSrcValue) {
2247 llvm::PHINode *PHI = Builder.CreatePHI(Value->getType(), 2);
2248 PHI->addIncoming(Value, CastNotNull);
2249 PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull);
2263 i != e; ++i, ++CurField) {
2265 LValue LV = EmitLValueForFieldInitialization(SlotLV, *CurField);
2266 if (CurField->hasCapturedVLAType()) {
2267 auto VAT = CurField->getCapturedVLAType();
2268 EmitStoreThroughLValue(
RValue::get(VLASizeMap[VAT->getSizeExpr()]), LV);
2270 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.
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
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
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
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.
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
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. ...
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
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...
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.
LValue - This represents an lvalue references.
An abstract representation of regular/ObjC call/message targets.
Information for lazily generating a cleanup.
SourceLocation getBeginLoc() const LLVM_READONLY
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