24#include "llvm/ADT/ArrayRef.h"
25#include "llvm/ADT/STLExtras.h"
26#include "llvm/Support/Casting.h"
27#include "llvm/Support/Signals.h"
28#include "llvm/Support/TimeProfiler.h"
31using llvm::isa_and_present;
33OriginList *FactsGenerator::getOriginsList(
const ValueDecl &D) {
34 return FactMgr.getOriginMgr().getOrCreateList(&D);
36OriginList *FactsGenerator::getOriginsList(
const Expr &E) {
37 return FactMgr.getOriginMgr().getOrCreateList(&E);
40bool FactsGenerator::hasOrigins(QualType QT)
const {
41 return FactMgr.getOriginMgr().hasOrigins(QT);
44bool FactsGenerator::hasOrigins(
const Expr *E)
const {
45 return FactMgr.getOriginMgr().hasOrigins(E);
65 "Dst is non-null but Src is null. List must have the same length");
66 assert(Dst->getLength() == Src->getLength() &&
67 "Lists must have the same length");
70 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
71 Dst->getOuterOriginID(), Src->getOuterOriginID(), Kill));
72 Dst = Dst->peelOuterOrigin();
73 Src = Src->peelOuterOrigin();
106 llvm::TimeTraceScope TimeProfile(
"FactGenerator");
107 const CFG &Cfg = *AC.getCFG();
112 CurrentBlockFacts.clear();
113 EscapesInCurrentBlock.clear();
114 CurrentBlock =
Block;
116 CurrentBlockFacts.append(PlaceholderLoanFacts.begin(),
117 PlaceholderLoanFacts.end());
118 for (
unsigned I = 0; I <
Block->size(); ++I) {
120 if (std::optional<CFGStmt> CS = Element.
getAs<
CFGStmt>())
121 Visit(CS->getStmt());
122 else if (std::optional<CFGInitializer>
Initializer =
124 handleCXXCtorInitializer(
Initializer->getInitializer());
125 else if (std::optional<CFGLifetimeEnds> LifetimeEnds =
127 handleLifetimeEnds(*LifetimeEnds);
128 else if (std::optional<CFGFullExprCleanup> FullExprCleanup =
130 handleFullExprCleanup(*FullExprCleanup);
136 CurrentBlockFacts.append(EscapesInCurrentBlock.begin(),
137 EscapesInCurrentBlock.end());
138 FactMgr.addBlockFacts(
Block, CurrentBlockFacts);
157 if (
const auto *VD = dyn_cast<VarDecl>(D))
158 if (
const Expr *InitExpr = VD->getInit()) {
162 OriginList *InitList = getOriginsList(*InitExpr);
163 assert(InitList &&
"VarDecl had origins but InitExpr did not");
164 flow(VDList, InitList,
true);
187 "gl-value DRE of non-pointer type should have an origin list");
190 CurrentBlockFacts.push_back(
197 handleGSLPointerConstruction(CCE);
208 flow(getOriginsList(*CCE), ArgList,
true);
218 flow(getOriginsList(*CCE), ArgList,
true);
223 {CCE->getArgs(), CCE->getNumArgs()},
229 killAndFlowOrigin(*DIE, *
Init);
236 killAndFlowOrigin(*FD, *CII->
getInit());
247 {MCE->getImplicitObjectArgument()},
258 handleFunctionCall(MCE,
Method, Args,
false);
265 assert(ME->
isGLValue() &&
"Field member should be GL value");
267 assert(Dst &&
"Field member should have an origin list as it is GL value");
269 assert(Src &&
"Base expression should be a pointer/reference type");
280 {CE->getArgs(), CE->getNumArgs()});
298 case CK_LValueToRValue:
302 assert(Src &&
"LValue being cast to RValue has no origin list");
310 case CK_NullToPointer:
315 case CK_ConstructorConversion:
316 case CK_UserDefinedConversion:
317 flow(Dest, Src,
true);
319 case CK_UncheckedDerivedToBase:
320 case CK_DerivedToBase:
324 flow(Dest, Src,
true);
326 case CK_ArrayToPointerDecay:
331 assert(Src &&
"Array expression should have origins as it is GL value");
335 case CK_FunctionToPointerDecay:
336 case CK_BuiltinFnToFnPtr:
343 flow(Dest, Src,
true);
362 "Taking address of void is not valid in C++");
367 killAndFlowOrigin(*UO, *SubExpr);
372 killAndFlowOrigin(*UO, *SubExpr);
382 if (
OriginList *List = getOriginsList(*RetExpr))
385 L->getOuterOriginID(), RetExpr));
389void FactsGenerator::handleAssignment(
const Expr *TargetExpr,
391 const Expr *RHSExpr) {
395 if (
const auto *DRE_LHS = dyn_cast<DeclRefExpr>(LHSExpr)) {
396 LHSList = getOriginsList(*DRE_LHS);
397 assert(LHSList &&
"LHS is a DRE and should have an origin list");
402 if (
const auto *ME_LHS = dyn_cast<MemberExpr>(LHSExpr)) {
403 LHSList = getOriginsList(*ME_LHS);
404 assert(LHSList &&
"LHS is a MemberExpr and should have an origin list");
408 OriginList *RHSList = getOriginsList(*RHSExpr);
416 if (
const auto *DRE_LHS = dyn_cast<DeclRefExpr>(LHSExpr)) {
417 QualType QT = DRE_LHS->getDecl()->getType();
424 if (UseFact *UF = UseFacts.lookup(DRE_LHS)) {
425 const OriginList *FullList = UF->getUsedOrigins();
428 FullList->getOuterOriginID()));
429 if (
const OriginList *InnerList = FullList->peelOuterOrigin()) {
430 UseFact *WriteUF = FactMgr.
createFact<UseFact>(DRE_LHS, InnerList);
431 WriteUF->markAsWritten();
432 CurrentBlockFacts.push_back(WriteUF);
437 markUseAsWrite(DRE_LHS);
444 CurrentBlockFacts.push_back(
445 FactMgr.createFact<KillOriginFact>(LHSInner->getOuterOriginID()));
456 flow(getOriginsList(*TargetExpr), LHSList,
true);
459void FactsGenerator::handlePointerArithmetic(
const BinaryOperator *BO) {
460 if (Expr *RHS = BO->getRHS(); RHS->getType()->isPointerType()) {
461 killAndFlowOrigin(*BO, *RHS);
464 Expr *LHS = BO->getLHS();
465 assert(LHS->getType()->isPointerType() &&
466 "Pointer arithmetic must have a pointer operand");
467 killAndFlowOrigin(*BO, *LHS);
472 killAndFlowOrigin(*BO, *BO->
getRHS());
478 handlePointerArithmetic(BO);
492 const auto Preds = CurrentBlock->preds();
496 bool TBHasEdge =
true;
497 bool FBHasEdge =
true;
499 switch (CurrentBlock->pred_size()) {
503 TBHasEdge = llvm::any_of(**Preds.begin(),
506 if (auto CS = Elt.getAs<CFGStmt>())
507 return CS->getStmt() == ExpectedStmt;
510 FBHasEdge = !TBHasEdge;
514 const auto *It = Preds.begin();
515 TBHasEdge = It->isReachable();
516 FBHasEdge = (++It)->isReachable();
520 llvm_unreachable(
"expected at most 2 predecessors");
524 bool FirstFlow =
true;
525 auto HandleFlow = [&](
const Expr *E) {
527 killAndFlowOrigin(*CO, *E);
535 HandleFlow(TrueExpr);
537 HandleFlow(FalseExpr);
563 MD && MD->isDefaulted()) {
573 Args = Args.slice(1);
581 if (handleTestPoint(FCE))
587 if (!hasOrigins(ILE))
594 if (!hasOrigins(ILE->
getInit(0)))
596 killAndFlowOrigin(*ILE, *ILE->
getInit(0));
612 assert((!SubExprList ||
614 "MTE top level origin should contain a loan to the MTE itself");
617 flow(RValMTEList, SubExprList,
true);
622 CurrentBlockFacts.push_back(
635 for (
const Expr *
Init : LE->capture_inits()) {
656 assert(ASE->
isGLValue() &&
"Array subscript should be a GL value");
658 assert(Dst &&
"Array subscript should have origins as it is a GL value");
660 assert(Src &&
"Base of array subscript should have origins");
665bool FactsGenerator::handlePlacementNew(
const CXXNewExpr *NE,
671 if (NE->getNumPlacementArgs() != 1)
675 if (OperatorNew->getNumParams() <= 1)
679 OperatorNew->getParamDecl(1)->getType()->getAs<
PointerType>();
680 if (!Arg || !Arg->isVoidPointerType())
685 const Expr *PlacementArg = NE->getPlacementArg(0);
686 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(PlacementArg);
687 ICE && ICE->getCastKind() == CK_BitCast &&
688 PlacementArg->getType()->isVoidPointerType())
689 PlacementArg = ICE->getSubExpr();
690 OriginList *PlacementList = getOriginsList(*PlacementArg);
704 const Expr *
Init = NE->getInitializer();
706 bool HandledAsPlacementNew =
false;
707 if (NE->getNumPlacementArgs() == 1)
708 HandledAsPlacementNew = handlePlacementNew(NE, NewList);
713 if (!HandledAsPlacementNew &&
714 (NE->getNumPlacementArgs() == 0 ||
715 (OperatorNew && OperatorNew->isReplaceableGlobalAllocationFunction()))) {
717 CurrentBlockFacts.push_back(
723 if (!NewList || !
Init)
729 flow(NewList, InitList,
true);
734 CurrentBlockFacts.push_back(
738bool FactsGenerator::escapesViaReturn(
OriginID OID)
const {
739 return llvm::any_of(EscapesInCurrentBlock, [OID](
const Fact *F) {
741 return EF->getEscapedOriginID() == OID;
746void FactsGenerator::handleLifetimeEnds(
const CFGLifetimeEnds &LifetimeEnds) {
752 std::optional<OriginID> ExpiredOID;
753 if (OriginList *List = getOriginsList(*LifetimeEndsVD)) {
754 OriginID OID = List->getOuterOriginID();
757 if (!escapesViaReturn(OID))
760 CurrentBlockFacts.push_back(FactMgr.
createFact<ExpireFact>(
765void FactsGenerator::handleFullExprCleanup(
766 const CFGFullExprCleanup &FullExprCleanup) {
767 for (
const auto *MTE : FullExprCleanup.getExpiringMTEs())
768 CurrentBlockFacts.push_back(FactMgr.createFact<ExpireFact>(
769 AccessPath(MTE), FullExprCleanup.getCleanupLoc()));
772void FactsGenerator::handleExitBlock() {
773 for (
const Origin &O : FactMgr.getOriginMgr().getOrigins())
774 if (
auto *FD = dyn_cast_if_present<FieldDecl>(O.getDecl()))
776 EscapesInCurrentBlock.push_back(
777 FactMgr.createFact<FieldEscapeFact>(O.ID, FD));
778 else if (
auto *VD = dyn_cast_if_present<VarDecl>(O.getDecl())) {
781 if (VD->hasGlobalStorage()) {
782 EscapesInCurrentBlock.push_back(
783 FactMgr.createFact<GlobalEscapeFact>(O.ID, VD));
788void FactsGenerator::handleGSLPointerConstruction(
const CXXConstructExpr *CCE) {
790 if (CCE->getNumArgs() != 1)
793 const Expr *Arg = CCE->getArg(0);
795 OriginList *ArgList = getOriginsList(*Arg);
796 assert(ArgList &&
"GSL pointer argument should have an origin list");
802 flow(getOriginsList(*CCE), ArgList,
true);
803 }
else if (Arg->getType()->isPointerType()) {
808 OriginList *ArgList = getOriginsList(*Arg);
809 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
810 getOriginsList(*CCE)->getOuterOriginID(), ArgList->getOuterOriginID(),
815 handleFunctionCall(CCE, CCE->getConstructor(),
816 {CCE->getArgs(), CCE->getNumArgs()},
821void FactsGenerator::handleMovedArgsInCall(
const FunctionDecl *FD,
822 ArrayRef<const Expr *> Args) {
823 unsigned IsInstance = 0;
824 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
831 const Expr *UniquePtrExpr = Args[0];
832 OriginList *MovedOrigins = getOriginsList(*UniquePtrExpr);
834 CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>(
835 UniquePtrExpr, MovedOrigins->getOuterOriginID()));
840 for (
unsigned I = IsInstance;
841 I < Args.size() && I < FD->getNumParams() + IsInstance; ++I) {
842 const ParmVarDecl *PVD = FD->getParamDecl(I - IsInstance);
843 if (!PVD->getType()->isRValueReferenceType())
845 const Expr *Arg = Args[I];
846 OriginList *MovedOrigins = getOriginsList(*Arg);
847 assert(MovedOrigins->getLength() >= 1 &&
848 "unexpected length for r-value reference param");
850 CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>(
851 Arg, MovedOrigins->getOuterOriginID()));
855void FactsGenerator::handleInvalidatingCall(
const Expr *
Call,
856 const FunctionDecl *FD,
857 ArrayRef<const Expr *> Args) {
858 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
859 if (!MD || !MD->isInstance())
871 OriginList *ThisList = getOriginsList(*Args[0]);
873 CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
874 ThisList->getOuterOriginID(),
Call));
877void FactsGenerator::handleDestructiveCall(
const Expr *
Call,
878 const FunctionDecl *FD,
879 ArrayRef<const Expr *> Args) {
882 OriginList *ArgList = getOriginsList(*Args[0]);
884 CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
885 ArgList->getOuterOriginID(),
Call));
888void FactsGenerator::handleImplicitObjectFieldUses(
const Expr *
Call,
889 const FunctionDecl *FD) {
890 const auto *MemberCall = dyn_cast_or_null<CXXMemberCallExpr>(
Call);
894 if (!isa_and_present<CXXThisExpr>(
895 MemberCall->getImplicitObjectArgument()->IgnoreImpCasts()))
898 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
899 assert(MD &&
"Function must be a CXXMethodDecl for member calls");
901 const auto *ClassDecl = MD->getParent()->getDefinition();
905 const auto UseFields = [&](
const CXXRecordDecl *RD) {
906 for (
const auto *Field : RD->fields())
907 if (
auto *FieldList = getOriginsList(*Field))
908 CurrentBlockFacts.push_back(
909 FactMgr.createFact<UseFact>(
Call, FieldList));
912 UseFields(ClassDecl);
914 ClassDecl->forallBases([&](
const CXXRecordDecl *Base) {
920void FactsGenerator::handleLifetimeCaptureBy(
const FunctionDecl *FD,
921 ArrayRef<const Expr *> Args) {
927 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
930 auto getArgCaptureBy = [FD,
931 IsInstance](
unsigned I) -> LifetimeCaptureByAttr * {
932 const ParmVarDecl *PVD =
nullptr;
935 if (I > 0 && I - 1 < FD->getNumParams())
936 PVD = FD->getParamDecl(I - 1);
938 if (I < FD->getNumParams())
939 PVD = FD->getParamDecl(I);
941 return PVD ? PVD->getAttr<LifetimeCaptureByAttr>() :
nullptr;
943 for (
unsigned I = 0; I < Args.size(); ++I) {
944 const LifetimeCaptureByAttr *Attr = getArgCaptureBy(I);
947 OriginList *CapturedOriginList = getOriginsList(*Args[I]);
948 if (!CapturedOriginList)
950 if (!CapturedOriginList)
952 for (
int CapturingArgIdx : Attr->params()) {
954 if (CapturingArgIdx == LifetimeCaptureByAttr::Global ||
955 CapturingArgIdx == LifetimeCaptureByAttr::Unknown ||
956 CapturingArgIdx == LifetimeCaptureByAttr::Invalid)
958 ArrayRef<const Expr *> CallArgs = IsInstance ? Args.drop_front() : Args;
959 const Expr *CapturedByArg =
960 (CapturingArgIdx == LifetimeCaptureByAttr::This)
962 : CallArgs[CapturingArgIdx];
963 assert(CapturedByArg &&
"Capturer expression must be valid");
965 OriginList *CapturingOriginList = getOriginsList(*CapturedByArg);
973 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
974 Dest->getOuterOriginID(), CapturedOriginList->getOuterOriginID(),
980void FactsGenerator::handleFunctionCall(
const Expr *
Call,
981 const FunctionDecl *FD,
982 ArrayRef<const Expr *> Args,
983 bool IsGslConstruction) {
984 OriginList *CallList = getOriginsList(*
Call);
990 for (
const Expr *Arg : Args)
992 handleInvalidatingCall(
Call, FD, Args);
993 handleDestructiveCall(
Call, FD, Args);
994 handleMovedArgsInCall(FD, Args);
995 handleImplicitObjectFieldUses(
Call, FD);
996 handleLifetimeCaptureBy(FD, Args);
1000 assert(Args.size() == 1 &&
1001 "std reference cast builtins take exactly one argument");
1004 flow(CallList, getOriginsList(*Args[0]),
true);
1007 auto IsArgLifetimeBound = [FD, &Args](
unsigned I) ->
bool {
1008 const ParmVarDecl *PVD =
nullptr;
1009 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
1016 if ((I - 1) <
Method->getNumParams())
1019 PVD =
Method->getParamDecl(I - 1);
1024 }
else if (I < FD->getNumParams()) {
1026 PVD = FD->getParamDecl(I);
1028 return PVD ? PVD->hasAttr<clang::LifetimeBoundAttr>() :
false;
1030 auto shouldTrackPointerImplicitObjectArg = [FD, &Args](
unsigned I) ->
bool {
1031 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
1041 bool KillSrc =
true;
1042 for (
unsigned I = 0; I < Args.size(); ++I) {
1043 OriginList *ArgList = getOriginsList(*Args[I]);
1046 if (IsGslConstruction) {
1050 assert(!Args[I]->isGLValue() || ArgList->getLength() >= 2);
1057 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1058 CallList->getOuterOriginID(), ArgList->getOuterOriginID(),
1061 }
else if (IsArgLifetimeBound(I)) {
1068 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1069 CallList->getOuterOriginID(), ArgList->getOuterOriginID(),
1073 }
else if (shouldTrackPointerImplicitObjectArg(I)) {
1074 assert(ArgList->getLength() >= 2 &&
1075 "Object arg of pointer type should have at least two origins");
1077 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1078 CallList->getOuterOriginID(),
1079 ArgList->peelOuterOrigin()->getOuterOriginID(), KillSrc));
1081 }
else if (IsArgLifetimeBound(I)) {
1085 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1086 CallList->getOuterOriginID(), ArgList->getOuterOriginID(), KillSrc));
1094bool FactsGenerator::handleTestPoint(
const CXXFunctionalCastExpr *FCE) {
1095 if (!FCE->getType()->isVoidType())
1098 const auto *SubExpr = FCE->getSubExpr()->IgnoreParenImpCasts();
1099 if (
const auto *SL = dyn_cast<StringLiteral>(SubExpr)) {
1100 llvm::StringRef LiteralValue = SL->getString();
1101 const std::string Prefix =
"__lifetime_test_point_";
1103 if (LiteralValue.starts_with(Prefix)) {
1104 StringRef Annotation = LiteralValue.drop_front(Prefix.length());
1105 CurrentBlockFacts.push_back(
1106 FactMgr.createFact<TestPointFact>(Annotation));
1113void FactsGenerator::handleUse(
const Expr *E) {
1114 OriginList *List = getOriginsList(*E);
1120 if (
auto *DRE = dyn_cast<DeclRefExpr>(E);
1121 DRE && !DRE->getDecl()->
getType()->isReferenceType())
1126 if (!UseFacts.contains(E)) {
1127 UseFact *UF = FactMgr.createFact<UseFact>(E, List);
1128 CurrentBlockFacts.push_back(UF);
1133void FactsGenerator::markUseAsWrite(
const DeclRefExpr *DRE) {
1134 if (UseFacts.contains(DRE))
1135 UseFacts[DRE]->markAsWritten();
1140llvm::SmallVector<Fact *> FactsGenerator::issuePlaceholderLoans() {
1141 const auto *FD = dyn_cast<FunctionDecl>(AC.getDecl());
1145 llvm::SmallVector<Fact *> PlaceholderLoanFacts;
1146 if (
auto ThisOrigins = FactMgr.getOriginMgr().getThisOrigins()) {
1147 OriginList *List = *ThisOrigins;
1148 const Loan *L = FactMgr.getLoanMgr().createLoan(
1151 PlaceholderLoanFacts.push_back(
1152 FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
1154 for (
const ParmVarDecl *PVD : FD->parameters()) {
1155 OriginList *List = getOriginsList(*PVD);
1158 const Loan *L = FactMgr.getLoanMgr().createLoan(
1160 PlaceholderLoanFacts.push_back(
1161 FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
1163 return PlaceholderLoanFacts;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines an enumeration for C++ overloaded operators.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isAdditiveOp(Opcode Opc)
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
Represents a single basic block in a source-level CFG.
Represents a top-level expression in a basic block.
std::optional< T > getAs() const
Convert to the specified CFGElement type, returning std::nullopt if this CFGElement is not of the des...
Represents C++ base or member initializer from constructor's initialization list.
Represents the point where the lifetime of an automatic object ends.
const VarDecl * getVarDecl() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const Stmt * getTriggerStmt() const
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Represents binding an expression to a temporary.
const Expr * getSubExpr() const
Represents a call to a C++ constructor.
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ base or member initializer.
Expr * getInit() const
Get the initializer.
FieldDecl * getAnyMember() const
A use of a default initializer in a constructor or in aggregate initialization.
Expr * getExpr()
Get the initialization expression that will be used.
Represents a delete expression for memory deallocation and destructor calls, e.g.
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Represents a call to a member function that may be written either with member call syntax (e....
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Represents a static or instance method of a struct/union/class.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
The null pointer literal (C++11 [lex.nullptr])
A call to an overloaded operator written using operator syntax.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Expr ** getArgs()
Retrieve the call arguments.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
ConditionalOperator - The ?
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
A reference to a declared variable, function, enum, etc.
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
This represents one expression.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
bool isDefaulted() const
Whether this function is defaulted.
Describes an C or C++ initializer list.
unsigned getNumInits() const
const Expr * getInit(unsigned Init) const
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
RetTy Visit(PTR(Stmt) S, ParamTys... P)
SourceLocation getEndLoc() const LLVM_READONLY
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isPointerType() const
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isPointerOrReferenceType() const
bool isFunctionType() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
Represents the storage location being borrowed, e.g., a specific stack variable or a field within it:...
static AccessPath Placeholder(const ParmVarDecl *PVD)
FactType * createFact(Args &&...args)
OriginManager & getOriginMgr()
LoanManager & getLoanMgr()
An abstract base class for a single, atomic lifetime-relevant event.
void VisitDeclRefExpr(const DeclRefExpr *DRE)
void VisitBinaryOperator(const BinaryOperator *BO)
void VisitCallExpr(const CallExpr *CE)
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE)
void VisitCastExpr(const CastExpr *CE)
void VisitReturnStmt(const ReturnStmt *RS)
void VisitCXXConstructExpr(const CXXConstructExpr *CCE)
void VisitMemberExpr(const MemberExpr *ME)
void VisitCXXDeleteExpr(const CXXDeleteExpr *DE)
void VisitCXXNewExpr(const CXXNewExpr *NE)
void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *FCE)
void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *DIE)
void VisitInitListExpr(const InitListExpr *ILE)
void VisitLambdaExpr(const LambdaExpr *LE)
void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *N)
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE)
void VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE)
void VisitUnaryOperator(const UnaryOperator *UO)
void VisitDeclStmt(const DeclStmt *DS)
void VisitConditionalOperator(const ConditionalOperator *CO)
void VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE)
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE)
Represents that an origin's storage has been invalidated by a container operation (e....
Loan * createLoan(AccessPath Path, const Expr *IssueExpr)
Represents lending a storage location.
A list of origins representing levels of indirection for pointer-like types.
OriginID getOuterOriginID() const
OriginList * peelOuterOrigin() const
OriginList * createSingleOriginList(OriginID OID)
Wraps an existing OriginID in a new single-element OriginList, so a fact can refer to a single level ...
Represents that an origin escapes via a return statement.
utils::ID< struct OriginTag > OriginID
static OriginList * getRValueOrigins(const Expr *E, OriginList *List)
Simulates LValueToRValue conversion by peeling the outer lvalue origin if the expression is a GLValue...
bool doesDeclHaveStorage(const ValueDecl *D)
Returns true if the declaration has its own storage that can be borrowed.
static const Loan * createLoan(FactManager &FactMgr, const DeclRefExpr *DRE)
Creates a loan for the storage path of a given declaration reference.
bool isGslPointerType(QualType QT)
bool isStdCallableWrapperType(const CXXRecordDecl *RD)
bool shouldTrackFirstArgument(const FunctionDecl *FD)
bool shouldTrackImplicitObjectArg(const Expr &ImplicitObjectArgument, const CXXMethodDecl *Callee, bool RunningUnderLifetimeSafety)
bool isUniquePtrRelease(const CXXMethodDecl &MD)
bool isStdReferenceCast(const FunctionDecl *FD)
bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD)
const FunctionDecl * getDeclWithMergedLifetimeBoundAttrs(const FunctionDecl *FD)
bool isInvalidationMethod(const CXXMethodDecl &MD)
bool destructsFirstArg(const FunctionDecl &FD)
bool isGslOwnerType(QualType QT)
bool shouldTrackSecondArgument(const FunctionDecl *FD)
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ SD_FullExpression
Full-expression storage duration (for temporaries).
U cast(CodeGen::Address addr)
llvm::Expected< Stmt * > ExpectedStmt