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);
70 const CFGBlock *
Block) {
74 "Dst is non-null but Src is null. List must have the same length");
75 assert(Dst->getLength() == Src->getLength() &&
76 "Lists must have the same length");
79 Fact *F = FactMgr.createFact<OriginFlowFact>(Dst->getOuterOriginID(),
80 Src->getOuterOriginID(), Kill);
82 FactMgr.appendBlockFact(
Block, F);
84 CurrentBlockFacts.push_back(F);
85 Dst = Dst->peelOuterOrigin();
86 Src = Src->peelOuterOrigin();
119 llvm::TimeTraceScope TimeProfile(
"FactGenerator");
120 const CFG &Cfg = *AC.getCFG();
125 CurrentBlockFacts.clear();
126 EscapesInCurrentBlock.clear();
127 CurrentBlock =
Block;
129 CurrentBlockFacts.append(PlaceholderLoanFacts.begin(),
130 PlaceholderLoanFacts.end());
131 for (
unsigned I = 0; I <
Block->size(); ++I) {
133 if (std::optional<CFGStmt> CS = Element.
getAs<
CFGStmt>())
134 Visit(CS->getStmt());
135 else if (std::optional<CFGInitializer>
Initializer =
137 handleCXXCtorInitializer(
Initializer->getInitializer());
138 else if (std::optional<CFGLifetimeEnds> LifetimeEnds =
140 handleLifetimeEnds(*LifetimeEnds);
141 else if (std::optional<CFGFullExprCleanup> FullExprCleanup =
143 handleFullExprCleanup(*FullExprCleanup);
149 CurrentBlockFacts.append(EscapesInCurrentBlock.begin(),
150 EscapesInCurrentBlock.end());
151 FactMgr.addBlockFacts(
Block, CurrentBlockFacts);
153 FactMgr.computePersistentOrigins(Cfg);
168 if (
const auto *VD = dyn_cast<VarDecl>(D))
169 if (
const Expr *InitExpr = VD->getInit()) {
173 OriginList *InitList = getOriginsList(*InitExpr);
174 assert(InitList &&
"VarDecl had origins but InitExpr did not");
175 flow(VDList, InitList,
true);
197 "gl-value DRE of non-pointer type should have an origin list");
200 CurrentBlockFacts.push_back(
207 handleGSLPointerConstruction(CCE);
218 flow(getOriginsList(*CCE), ArgList,
true);
228 flow(getOriginsList(*CCE), ArgList,
true);
232 handleFunctionCall(CCE,
false);
237 killAndFlowOrigin(*DIE, *
Init);
244 killAndFlowOrigin(*FD, *CII->
getInit());
253 handleFunctionCall(MCE,
true);
256 handleFunctionCall(MCE,
false);
262 assert(ME->
isGLValue() &&
"Field member should be GL value");
264 assert(Dst &&
"Field member should have an origin list as it is GL value");
266 assert(Src &&
"Base expression should be a pointer/reference type");
276 handleFunctionCall(CE);
290 OriginList *Src = Dest ? getOriginsList(*SubExpr) :
nullptr;
293 case CK_LValueToRValue:
297 flow(Dest, readValue(SubExpr),
true);
300 handleAccess(SubExpr);
302 case CK_NullToPointer:
306 case CK_ConstructorConversion:
307 case CK_UserDefinedConversion:
308 flow(Dest, Src,
true);
310 case CK_UncheckedDerivedToBase:
311 case CK_DerivedToBase:
312 case CK_BaseToDerived:
318 flow(Dest, Src,
true);
320 case CK_ArrayToPointerDecay:
325 assert(Src &&
"Array expression should have origins as it is GL value");
329 case CK_FunctionToPointerDecay:
330 case CK_BuiltinFnToFnPtr:
337 flow(Dest, Src,
true);
339 case CK_LValueToRValueBitCast:
340 case CK_NonAtomicToAtomic:
341 case CK_AtomicToNonAtomic: {
350 flow(Dest, RVSrc,
true);
370 "Taking address of void is not valid in C++");
375 killAndFlowOrigin(*UO, *SubExpr);
380 killAndFlowOrigin(*UO, *SubExpr);
390 flow(getOriginsList(*UO), readValue(SubExpr),
true);
404 flow(getOriginsList(*UO),
415 if (
OriginList *List = getOriginsList(*RetExpr))
418 L->getOuterOriginID(), RetExpr));
422void FactsGenerator::handleAssignment(
const Expr *TargetExpr,
424 const Expr *RHSExpr) {
426 handleAccess(LHSExpr);
430 if (
const auto *DRE_LHS = dyn_cast<DeclRefExpr>(LHSExpr)) {
431 LHSList = getOriginsList(*DRE_LHS);
432 assert(LHSList &&
"LHS is a DRE and should have an origin list");
437 if (
const auto *ME_LHS = dyn_cast<MemberExpr>(LHSExpr)) {
438 LHSList = getOriginsList(*ME_LHS);
439 assert(LHSList &&
"LHS is a MemberExpr and should have an origin list");
449 CurrentBlockFacts.push_back(
450 FactMgr.
createFact<KillOriginFact>(LHSInner->getOuterOriginID()));
461 flow(getOriginsList(*TargetExpr), LHSList,
true);
464void FactsGenerator::handlePointerArithmetic(
const BinaryOperator *BO) {
465 if (Expr *RHS = BO->getRHS(); RHS->getType()->isPointerType()) {
466 killAndFlowOrigin(*BO, *RHS);
469 Expr *LHS = BO->getLHS();
470 assert(LHS->getType()->isPointerType() &&
471 "Pointer arithmetic must have a pointer operand");
472 killAndFlowOrigin(*BO, *LHS);
488 ? getOriginsList(*BO->
getLHS())
489 : readValue(BO->
getLHS());
496 killAndFlowOrigin(*BO, *BO->
getRHS());
500 handleAccess(BO->
getLHS());
506 flow(getOriginsList(*BO), IsCMode ? LHSList->
peelOuterOrigin() : LHSList,
512 handlePointerArithmetic(BO);
519 const Expr *ArmExpr) {
523 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(
Target))
524 if (
const Expr *Src = OVE->getSourceExpr())
525 Target = Src->IgnoreParenImpCasts();
531 if (
auto CS = Elt.getAs<
CFGStmt>())
532 if (
const auto *E = dyn_cast<Expr>(CS->getStmt()))
555 flow(getOriginsList(*CO), getOriginsList(*TrueExpr),
true, TBPred);
557 flow(getOriginsList(*CO), getOriginsList(*FalseExpr),
true,
584 MD && MD->isDefaulted()) {
590 handleFunctionCall(OCE);
597 if (handleTestPoint(FCE))
603 if (!hasOrigins(ILE))
610 if (!hasOrigins(ILE->
getInit(0)))
612 killAndFlowOrigin(*ILE, *ILE->
getInit(0));
628 assert((!SubExprList ||
630 "MTE top level origin should contain a loan to the MTE itself");
633 flow(RValMTEList, SubExprList,
true);
638 CurrentBlockFacts.push_back(
645 if (
C.capturesThis())
646 FactMgr.setThisCapturedByLambda();
647 else if (
C.capturesVariable() &&
C.getCapturedVar()->isInitCapture()) {
651 if (
const auto *ME = dyn_cast<MemberExpr>(
Init->IgnoreParenImpCasts())) {
652 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl()))
653 FactMgr.addCapturedField(FD);
665 for (
const Expr *
Init : LE->capture_inits()) {
688 assert(ASE->
isGLValue() &&
"Array subscript should be a GL value");
690 assert(Dst &&
"Array subscript should have origins as it is a GL value");
692 assert(Src &&
"Base of array subscript should have origins");
697bool FactsGenerator::handlePlacementNew(
const CXXNewExpr *NE,
703 if (NE->getNumPlacementArgs() != 1)
707 if (OperatorNew->getNumParams() <= 1)
711 OperatorNew->getParamDecl(1)->getType()->getAs<
PointerType>();
712 if (!Arg || !Arg->isVoidPointerType())
717 const Expr *PlacementArg = NE->getPlacementArg(0);
718 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(PlacementArg);
719 ICE && ICE->getCastKind() == CK_BitCast &&
720 PlacementArg->getType()->isVoidPointerType())
721 PlacementArg = ICE->getSubExpr();
722 OriginList *PlacementList = getOriginsList(*PlacementArg);
726 handleAccess(PlacementArg);
738 const Expr *
Init = NE->getInitializer();
740 bool HandledAsPlacementNew =
false;
741 if (NE->getNumPlacementArgs() == 1)
742 HandledAsPlacementNew = handlePlacementNew(NE, NewList);
747 if (!HandledAsPlacementNew &&
748 (NE->getNumPlacementArgs() == 0 ||
749 (OperatorNew && OperatorNew->isReplaceableGlobalAllocationFunction()))) {
751 CurrentBlockFacts.push_back(
757 if (!NewList || !
Init)
763 flow(NewList, InitList,
true);
791 CurrentBlockFacts.push_back(
800 if (!CS || CS->body_empty())
802 const auto *
Last = dyn_cast<Expr>(CS->body_back());
807 flow(Dst, Src,
true);
810bool FactsGenerator::escapesViaReturn(
OriginID OID)
const {
811 return llvm::any_of(EscapesInCurrentBlock, [OID](
const Fact *F) {
813 return EF->getEscapedOriginID() == OID;
818void FactsGenerator::handleLifetimeEnds(
const CFGLifetimeEnds &LifetimeEnds) {
824 std::optional<OriginID> ExpiredOID;
825 if (OriginList *List = getOriginsList(*LifetimeEndsVD)) {
829 if (!escapesViaReturn(OID))
832 CurrentBlockFacts.push_back(FactMgr.
createFact<ExpireFact>(
837void FactsGenerator::handleFullExprCleanup(
838 const CFGFullExprCleanup &FullExprCleanup) {
839 for (
const auto *MTE : FullExprCleanup.getExpiringMTEs())
840 CurrentBlockFacts.push_back(FactMgr.createFact<ExpireFact>(
841 AccessPath(MTE), FullExprCleanup.getCleanupLoc()));
844void FactsGenerator::handleExitBlock() {
845 bool IsDestructor = isa_and_nonnull<CXXDestructorDecl>(AC.getDecl());
846 for (
const Origin &O : FactMgr.getOriginMgr().getOrigins())
849 if (
auto *FD = dyn_cast_if_present<FieldDecl>(O.getDecl());
851 EscapesInCurrentBlock.push_back(
852 FactMgr.createFact<FieldEscapeFact>(O.ID, FD));
853 else if (
auto *VD = dyn_cast_if_present<VarDecl>(O.getDecl())) {
856 if (VD->hasGlobalStorage()) {
857 EscapesInCurrentBlock.push_back(
858 FactMgr.createFact<GlobalEscapeFact>(O.ID, VD));
863void FactsGenerator::handleGSLPointerConstruction(
const CXXConstructExpr *CCE) {
865 if (CCE->getNumArgs() != 1)
868 const Expr *Arg = CCE->getArg(0);
874 OriginList *ArgList = readValue(Arg);
875 assert(ArgList &&
"GSL pointer argument should have an origin list");
876 flow(getOriginsList(*CCE), ArgList,
true);
877 }
else if (Arg->getType()->isPointerType()) {
882 OriginList *ArgList = getOriginsList(*Arg);
883 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
884 getOriginsList(*CCE)->getOuterOriginID(), ArgList->getOuterOriginID(),
889 handleFunctionCall(CCE,
true);
893void FactsGenerator::handleMovedArgsInCall(
const FunctionDecl *FD,
894 ArrayRef<const Expr *> Args) {
895 unsigned ImplicitObjectArgOffset = 0;
898 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
900 MD->isImplicitObjectMemberFunction()) {
901 ImplicitObjectArgOffset = 1;
906 const Expr *UniquePtrExpr = Args[0];
907 OriginList *MovedOrigins = getOriginsList(*UniquePtrExpr);
909 CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>(
910 UniquePtrExpr, MovedOrigins->getOuterOriginID()));
915 for (
unsigned I = ImplicitObjectArgOffset;
916 I < Args.size() && I < FD->getNumParams() + ImplicitObjectArgOffset;
918 const ParmVarDecl *PVD = FD->getParamDecl(I - ImplicitObjectArgOffset);
921 if (PVD->isExplicitObjectParameter())
923 if (!PVD->getType()->isRValueReferenceType())
928 if (PVD->hasAttr<LifetimeBoundAttr>() ||
929 PVD->hasAttr<LifetimeCaptureByAttr>())
931 const Expr *Arg = Args[I];
932 OriginList *MovedOrigins = getOriginsList(*Arg);
933 assert(MovedOrigins->getLength() >= 1 &&
934 "unexpected length for r-value reference param");
936 CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>(
937 Arg, MovedOrigins->getOuterOriginID()));
941void FactsGenerator::handleInvalidatingCall(
const Expr *
Call,
942 const FunctionDecl *FD,
943 ArrayRef<const Expr *> Args) {
944 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
945 if (!MD || !MD->isInstance())
957 OriginList *ThisList = getOriginsList(*Args[0]);
959 CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
960 ThisList->getOuterOriginID(),
Call));
963void FactsGenerator::handleDestructiveCall(
const Expr *
Call,
964 const FunctionDecl *FD,
965 ArrayRef<const Expr *> Args) {
968 OriginList *ArgList = getOriginsList(*Args[0]);
970 CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
971 ArgList->getOuterOriginID(),
Call));
974void FactsGenerator::handleImplicitObjectFieldUses(
const Expr *
Call,
975 const FunctionDecl *FD) {
976 const auto *MemberCall = dyn_cast_or_null<CXXMemberCallExpr>(
Call);
980 if (!isa_and_present<CXXThisExpr>(
981 MemberCall->getImplicitObjectArgument()->IgnoreImpCasts()))
984 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
985 assert(MD &&
"Function must be a CXXMethodDecl for member calls");
987 const auto *ClassDecl = MD->getParent()->getDefinition();
991 const auto UseFields = [&](
const CXXRecordDecl *RD) {
992 for (
const auto *Field : RD->fields())
993 if (
auto *FieldList = getOriginsList(*Field))
994 CurrentBlockFacts.push_back(
995 FactMgr.createFact<UseFact>(
Call, FieldList));
998 UseFields(ClassDecl);
1000 ClassDecl->forallBases([&](
const CXXRecordDecl *Base) {
1006void FactsGenerator::handleLifetimeCaptureBy(
const FunctionDecl *FD,
1007 ArrayRef<const Expr *> Args) {
1013 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
1014 bool HasImplicitObjectArg =
Method &&
1015 Method->isImplicitObjectMemberFunction() &&
1017 auto getParamDeclAt =
1018 [FD, HasImplicitObjectArg](
unsigned I) ->
const ParmVarDecl * {
1019 if (HasImplicitObjectArg) {
1021 if (I > 0 && I - 1 < FD->getNumParams())
1022 return FD->getParamDecl(I - 1);
1024 if (I < FD->getNumParams())
1025 return FD->getParamDecl(I);
1029 for (
unsigned I = 0; I < Args.size(); ++I) {
1030 const ParmVarDecl *PVD = getParamDeclAt(I);
1033 const auto *Attr = PVD->getAttr<LifetimeCaptureByAttr>();
1036 OriginList *CapturedOriginList = getOriginsList(*Args[I]);
1037 if (!CapturedOriginList)
1041 if (QualType ParamType = PVD->getType();
1042 (ParamType->isReferenceType() &&
1044 CapturedOriginList->getLength() > 1)
1045 CapturedOriginList = CapturedOriginList->peelOuterOrigin();
1046 for (
int CapturingArgIdx : Attr->params()) {
1048 if (CapturingArgIdx == LifetimeCaptureByAttr::Global ||
1049 CapturingArgIdx == LifetimeCaptureByAttr::Unknown ||
1050 CapturingArgIdx == LifetimeCaptureByAttr::Invalid)
1053 if (CapturingArgIdx != LifetimeCaptureByAttr::This &&
1054 (CapturingArgIdx < 0 ||
1055 static_cast<size_t>(CapturingArgIdx) >= Args.size()))
1057 const Expr *CapturedByArg = Args[CapturingArgIdx];
1058 assert(CapturedByArg &&
"Capturer expression must be valid");
1060 OriginList *Dest = readValue(CapturedByArg);
1067 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1068 Dest->getOuterOriginID(), CapturedOriginList->getOuterOriginID(),
1074void FactsGenerator::handleFunctionCall(
const Expr *
Call,
1075 bool IsGslConstruction) {
1076 FunctionCallInfo CallInfo(
Call);
1077 llvm::ArrayRef<const Expr *> Args = CallInfo.Args;
1079 for (
const Expr *Arg : Args)
1083 OriginList *CallList = getOriginsList(*
Call);
1088 handleInvalidatingCall(
Call, FD, Args);
1089 handleDestructiveCall(
Call, FD, Args);
1090 handleMovedArgsInCall(FD, Args);
1091 handleImplicitObjectFieldUses(
Call, FD);
1092 handleLifetimeCaptureBy(FD, Args);
1096 assert(Args.size() == 1 &&
1097 "std reference cast builtins take exactly one argument");
1100 flow(CallList, getOriginsList(*Args[0]),
true);
1103 auto shouldTrackPointerImplicitObjectArg = [FD, &Args](
unsigned I) ->
bool {
1104 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
1114 bool KillSrc =
true;
1115 for (
unsigned I = 0; I < Args.size(); ++I) {
1116 OriginList *ArgList = getOriginsList(*Args[I]);
1120 if (IsGslConstruction) {
1124 assert(!Args[I]->isGLValue() || ArgList->getLength() >= 2);
1125 ArgList = readValue(Args[I]);
1131 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1132 CallList->getOuterOriginID(), ArgList->getOuterOriginID(),
1135 }
else if (ShouldTrackArg) {
1142 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1143 CallList->getOuterOriginID(), ArgList->getOuterOriginID(),
1147 }
else if (shouldTrackPointerImplicitObjectArg(I)) {
1148 assert(ArgList->getLength() >= 2 &&
1149 "Object arg of pointer type should have at least two origins");
1151 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1152 CallList->getOuterOriginID(),
1153 ArgList->peelOuterOrigin()->getOuterOriginID(), KillSrc));
1155 }
else if (ShouldTrackArg) {
1159 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1160 CallList->getOuterOriginID(), ArgList->getOuterOriginID(), KillSrc));
1168bool FactsGenerator::handleTestPoint(
const CXXFunctionalCastExpr *FCE) {
1169 if (!FCE->getType()->isVoidType())
1172 const auto *SubExpr = FCE->getSubExpr()->IgnoreParenImpCasts();
1173 if (
const auto *SL = dyn_cast<StringLiteral>(SubExpr)) {
1174 llvm::StringRef LiteralValue = SL->getString();
1175 const std::string Prefix =
"__lifetime_test_point_";
1177 if (LiteralValue.starts_with(Prefix)) {
1178 StringRef Annotation = LiteralValue.drop_front(Prefix.length());
1179 CurrentBlockFacts.push_back(
1180 FactMgr.createFact<TestPointFact>(Annotation));
1187bool FactsGenerator::namesDeclStorage(
const OriginList *List)
const {
1188 return FactMgr.getOriginMgr()
1189 .getOrigin(List->getOuterOriginID())
1193void FactsGenerator::handleAccess(
const Expr *E) {
1194 OriginList *List = getOriginsList(*E);
1195 if (!List || namesDeclStorage(List))
1197 CurrentBlockFacts.push_back(FactMgr.createFact<UseFact>(
1199 FactMgr.getOriginMgr().createSingleOriginList(List->getOuterOriginID())));
1202void FactsGenerator::handleUse(
const Expr *E) {
1203 OriginList *List = getOriginsList(*E);
1204 if (List && namesDeclStorage(List))
1205 List = List->peelOuterOrigin();
1207 CurrentBlockFacts.push_back(FactMgr.createFact<UseFact>(E, List));
1213void FactsGenerator::issueFieldPlaceholderLoans(
1214 const CXXMethodDecl *MD, llvm::SmallVectorImpl<Fact *> &Facts) {
1215 const CXXRecordDecl *ClassDecl = MD->getParent()->getDefinition();
1218 auto IssueForRecord = [&](
const CXXRecordDecl *RD) {
1219 for (
const FieldDecl *Field : RD->fields()) {
1223 OriginList *FieldList = getOriginsList(*Field);
1226 const Loan *L = FactMgr.getLoanMgr().createPlaceholderLoan(Field);
1227 Facts.push_back(FactMgr.createFact<IssueFact>(
1228 L->getID(), FieldList->getOuterOriginID()));
1232 IssueForRecord(ClassDecl);
1233 ClassDecl->forallBases(IssueForRecord);
1239llvm::SmallVector<Fact *> FactsGenerator::issuePlaceholderLoans() {
1240 const auto *FD = dyn_cast<FunctionDecl>(AC.getDecl());
1244 llvm::SmallVector<Fact *> PlaceholderLoanFacts;
1245 if (
auto ThisOrigins = FactMgr.getOriginMgr().getThisOrigins()) {
1246 OriginList *List = *ThisOrigins;
1248 const Loan *L = FactMgr.getLoanMgr().createPlaceholderLoan(MD);
1249 PlaceholderLoanFacts.push_back(
1250 FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
1252 issueFieldPlaceholderLoans(MD, PlaceholderLoanFacts);
1254 for (
const ParmVarDecl *PVD : FD->parameters()) {
1255 OriginList *List = getOriginsList(*PVD);
1258 const Loan *L = FactMgr.getLoanMgr().createPlaceholderLoan(PVD);
1259 PlaceholderLoanFacts.push_back(
1260 FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
1262 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.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
unsigned getNumOutputs() const
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....
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
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.
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Expr * getExprOperand() const
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
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.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
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.
This represents a GCC inline-assembly statement extension.
Expr * getOutputExpr(unsigned i)
Describes an C or C++ initializer list.
unsigned getNumInits() const
const Expr * getInit(unsigned Init) const
Describes the capture of a variable or of this, or of a C++1y init-capture.
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;.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
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 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:...
FactType * createFact(Args &&...args)
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 VisitCXXTypeidExpr(const CXXTypeidExpr *TE)
void VisitMemberExpr(const MemberExpr *ME)
void VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO)
Visits conditional operators (e.g., cond ?
void VisitCXXDeleteExpr(const CXXDeleteExpr *DE)
void VisitCXXNewExpr(const CXXNewExpr *NE)
void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *FCE)
void VisitGCCAsmStmt(const GCCAsmStmt *AS)
void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *DIE)
void VisitInitListExpr(const InitListExpr *ILE)
void VisitLambdaExpr(const LambdaExpr *LE)
void VisitStmtExpr(const StmtExpr *SE)
void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *N)
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE)
void VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE)
void VisitUnaryOperator(const UnaryOperator *UO)
void VisitCXXThrowExpr(const CXXThrowExpr *TE)
void VisitDeclStmt(const DeclStmt *DS)
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=nullptr)
Represents a component of an access path: either a named field access or an abstract unnamed interior...
A list of origins representing levels of indirection for pointer-like types.
OriginID getOuterOriginID() const
OriginList * peelOuterOrigin() const
Represents that an origin escapes via a return statement.
utils::ID< struct OriginTag > OriginID
static const CFGBlock * findPredBlockForExpr(const CFGBlock *MergeBlock, const Expr *ArmExpr)
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 shouldTrackImplicitObjectArg(const Expr &ImplicitObjectArgument, const CXXMethodDecl *Callee, bool RunningUnderLifetimeSafety)
bool isPointerLikeType(QualType QT)
bool isUniquePtrRelease(const CXXMethodDecl &MD)
bool isStdReferenceCast(const FunctionDecl *FD)
const FunctionDecl * getDeclWithMergedLifetimeBoundAttrs(const FunctionDecl *FD)
bool isInvalidationMethod(const CXXMethodDecl &MD)
bool destructsFirstArg(const FunctionDecl &FD)
bool isGslOwnerType(QualType QT)
std::optional< LifetimeBoundParamInfo > getTrackedArgInfo(const FunctionDecl *FD, llvm::ArrayRef< const Expr * > Args, unsigned I)
bool isa(CodeGen::Address addr)
@ SD_FullExpression
Full-expression storage duration (for temporaries).
U cast(CodeGen::Address addr)