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);
171 if (
const auto *VD = dyn_cast<VarDecl>(D))
172 if (
const Expr *InitExpr = VD->getInit()) {
176 OriginList *InitList = getOriginsList(*InitExpr);
177 assert(InitList &&
"VarDecl had origins but InitExpr did not");
178 flow(VDList, InitList,
true);
201 "gl-value DRE of non-pointer type should have an origin list");
204 CurrentBlockFacts.push_back(
211 handleGSLPointerConstruction(CCE);
222 flow(getOriginsList(*CCE), ArgList,
true);
232 flow(getOriginsList(*CCE), ArgList,
true);
237 handleFunctionCall(CCE, FD, Args,
243 killAndFlowOrigin(*DIE, *
Init);
250 killAndFlowOrigin(*FD, *CII->
getInit());
260 handleFunctionCall(MCE, FD, Args,
265 handleFunctionCall(MCE, FD, Args,
false);
271 assert(ME->
isGLValue() &&
"Field member should be GL value");
273 assert(Dst &&
"Field member should have an origin list as it is GL value");
275 assert(Src &&
"Base expression should be a pointer/reference type");
286 handleFunctionCall(CE, FD, Args);
304 case CK_LValueToRValue:
308 assert(Src &&
"LValue being cast to RValue has no origin list");
316 case CK_NullToPointer:
321 case CK_ConstructorConversion:
322 case CK_UserDefinedConversion:
323 flow(Dest, Src,
true);
325 case CK_UncheckedDerivedToBase:
326 case CK_DerivedToBase:
330 flow(Dest, Src,
true);
332 case CK_ArrayToPointerDecay:
337 assert(Src &&
"Array expression should have origins as it is GL value");
341 case CK_FunctionToPointerDecay:
342 case CK_BuiltinFnToFnPtr:
349 flow(Dest, Src,
true);
351 case CK_LValueToRValueBitCast:
352 case CK_NonAtomicToAtomic:
353 case CK_AtomicToNonAtomic: {
362 flow(Dest, RVSrc,
true);
382 "Taking address of void is not valid in C++");
387 killAndFlowOrigin(*UO, *SubExpr);
392 killAndFlowOrigin(*UO, *SubExpr);
402 flow(getOriginsList(*UO),
417 flow(getOriginsList(*UO),
428 if (
OriginList *List = getOriginsList(*RetExpr))
431 L->getOuterOriginID(), RetExpr));
435void FactsGenerator::handleAssignment(
const Expr *TargetExpr,
437 const Expr *RHSExpr) {
441 if (
const auto *DRE_LHS = dyn_cast<DeclRefExpr>(LHSExpr)) {
442 LHSList = getOriginsList(*DRE_LHS);
443 assert(LHSList &&
"LHS is a DRE and should have an origin list");
448 if (
const auto *ME_LHS = dyn_cast<MemberExpr>(LHSExpr)) {
449 LHSList = getOriginsList(*ME_LHS);
450 assert(LHSList &&
"LHS is a MemberExpr and should have an origin list");
454 OriginList *RHSList = getOriginsList(*RHSExpr);
462 if (
const auto *DRE_LHS = dyn_cast<DeclRefExpr>(LHSExpr)) {
463 QualType QT = DRE_LHS->getDecl()->getType();
470 if (UseFact *UF = UseFacts.lookup(DRE_LHS)) {
471 const OriginList *FullList = UF->getUsedOrigins();
474 FullList->getOuterOriginID()));
475 if (
const OriginList *InnerList = FullList->peelOuterOrigin()) {
476 UseFact *WriteUF = FactMgr.
createFact<UseFact>(DRE_LHS, InnerList);
477 WriteUF->markAsWritten();
478 CurrentBlockFacts.push_back(WriteUF);
483 markUseAsWrite(DRE_LHS);
490 CurrentBlockFacts.push_back(
491 FactMgr.createFact<KillOriginFact>(LHSInner->getOuterOriginID()));
502 flow(getOriginsList(*TargetExpr), LHSList,
true);
505void FactsGenerator::handlePointerArithmetic(
const BinaryOperator *BO) {
506 if (Expr *RHS = BO->getRHS(); RHS->getType()->isPointerType()) {
507 killAndFlowOrigin(*BO, *RHS);
510 Expr *LHS = BO->getLHS();
511 assert(LHS->getType()->isPointerType() &&
512 "Pointer arithmetic must have a pointer operand");
513 killAndFlowOrigin(*BO, *LHS);
530 ? getOriginsList(*BO->
getLHS())
539 killAndFlowOrigin(*BO, *BO->
getRHS());
548 flow(getOriginsList(*BO), IsCMode ? LHSList->
peelOuterOrigin() : LHSList,
554 handlePointerArithmetic(BO);
562 const Expr *ArmExpr) {
566 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(
Target))
567 if (
const Expr *Src = OVE->getSourceExpr())
568 Target = Src->IgnoreParenImpCasts();
574 if (
auto CS = Elt.getAs<
CFGStmt>())
575 if (
const auto *E = dyn_cast<Expr>(CS->getStmt()))
576 if (E->IgnoreParenImpCasts() ==
Target)
598 flow(getOriginsList(*CO), getOriginsList(*TrueExpr),
true, TBPred);
600 flow(getOriginsList(*CO), getOriginsList(*FalseExpr),
true,
627 MD && MD->isDefaulted()) {
634 handleFunctionCall(OCE, FD, Args);
641 if (handleTestPoint(FCE))
647 if (!hasOrigins(ILE))
654 if (!hasOrigins(ILE->
getInit(0)))
656 killAndFlowOrigin(*ILE, *ILE->
getInit(0));
672 assert((!SubExprList ||
674 "MTE top level origin should contain a loan to the MTE itself");
677 flow(RValMTEList, SubExprList,
true);
682 CurrentBlockFacts.push_back(
689 if (
C.capturesThis())
690 FactMgr.setThisCapturedByLambda();
691 else if (
C.capturesVariable() &&
C.getCapturedVar()->isInitCapture()) {
695 if (
const auto *ME = dyn_cast<MemberExpr>(
Init->IgnoreParenImpCasts())) {
696 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl()))
697 FactMgr.addCapturedField(FD);
709 for (
const Expr *
Init : LE->capture_inits()) {
730 assert(ASE->
isGLValue() &&
"Array subscript should be a GL value");
732 assert(Dst &&
"Array subscript should have origins as it is a GL value");
734 assert(Src &&
"Base of array subscript should have origins");
739bool FactsGenerator::handlePlacementNew(
const CXXNewExpr *NE,
745 if (NE->getNumPlacementArgs() != 1)
749 if (OperatorNew->getNumParams() <= 1)
753 OperatorNew->getParamDecl(1)->getType()->getAs<
PointerType>();
754 if (!Arg || !Arg->isVoidPointerType())
759 const Expr *PlacementArg = NE->getPlacementArg(0);
760 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(PlacementArg);
761 ICE && ICE->getCastKind() == CK_BitCast &&
762 PlacementArg->getType()->isVoidPointerType())
763 PlacementArg = ICE->getSubExpr();
764 OriginList *PlacementList = getOriginsList(*PlacementArg);
778 const Expr *
Init = NE->getInitializer();
780 bool HandledAsPlacementNew =
false;
781 if (NE->getNumPlacementArgs() == 1)
782 HandledAsPlacementNew = handlePlacementNew(NE, NewList);
787 if (!HandledAsPlacementNew &&
788 (NE->getNumPlacementArgs() == 0 ||
789 (OperatorNew && OperatorNew->isReplaceableGlobalAllocationFunction()))) {
791 CurrentBlockFacts.push_back(
797 if (!NewList || !
Init)
803 flow(NewList, InitList,
true);
808 CurrentBlockFacts.push_back(
817 if (!CS || CS->body_empty())
819 const auto *
Last = dyn_cast<Expr>(CS->body_back());
824 flow(Dst, Src,
true);
827bool FactsGenerator::escapesViaReturn(
OriginID OID)
const {
828 return llvm::any_of(EscapesInCurrentBlock, [OID](
const Fact *F) {
830 return EF->getEscapedOriginID() == OID;
835void FactsGenerator::handleLifetimeEnds(
const CFGLifetimeEnds &LifetimeEnds) {
841 std::optional<OriginID> ExpiredOID;
842 if (OriginList *List = getOriginsList(*LifetimeEndsVD)) {
843 OriginID OID = List->getOuterOriginID();
846 if (!escapesViaReturn(OID))
849 CurrentBlockFacts.push_back(FactMgr.
createFact<ExpireFact>(
854void FactsGenerator::handleFullExprCleanup(
855 const CFGFullExprCleanup &FullExprCleanup) {
856 for (
const auto *MTE : FullExprCleanup.getExpiringMTEs())
857 CurrentBlockFacts.push_back(FactMgr.createFact<ExpireFact>(
858 AccessPath(MTE), FullExprCleanup.getCleanupLoc()));
861void FactsGenerator::handleExitBlock() {
862 bool IsDestructor = isa_and_nonnull<CXXDestructorDecl>(AC.getDecl());
863 for (
const Origin &O : FactMgr.getOriginMgr().getOrigins())
866 if (
auto *FD = dyn_cast_if_present<FieldDecl>(O.getDecl());
868 EscapesInCurrentBlock.push_back(
869 FactMgr.createFact<FieldEscapeFact>(O.ID, FD));
870 else if (
auto *VD = dyn_cast_if_present<VarDecl>(O.getDecl())) {
873 if (VD->hasGlobalStorage()) {
874 EscapesInCurrentBlock.push_back(
875 FactMgr.createFact<GlobalEscapeFact>(O.ID, VD));
880void FactsGenerator::handleGSLPointerConstruction(
const CXXConstructExpr *CCE) {
882 if (CCE->getNumArgs() != 1)
885 const Expr *Arg = CCE->getArg(0);
887 OriginList *ArgList = getOriginsList(*Arg);
888 assert(ArgList &&
"GSL pointer argument should have an origin list");
894 flow(getOriginsList(*CCE), ArgList,
true);
895 }
else if (Arg->getType()->isPointerType()) {
900 OriginList *ArgList = getOriginsList(*Arg);
901 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
902 getOriginsList(*CCE)->getOuterOriginID(), ArgList->getOuterOriginID(),
908 handleFunctionCall(CCE, FD, Args,
913void FactsGenerator::handleMovedArgsInCall(
const FunctionDecl *FD,
914 ArrayRef<const Expr *> Args) {
915 unsigned ImplicitObjectArgOffset = 0;
918 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD);
920 MD->isImplicitObjectMemberFunction()) {
921 ImplicitObjectArgOffset = 1;
926 const Expr *UniquePtrExpr = Args[0];
927 OriginList *MovedOrigins = getOriginsList(*UniquePtrExpr);
929 CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>(
930 UniquePtrExpr, MovedOrigins->getOuterOriginID()));
935 for (
unsigned I = ImplicitObjectArgOffset;
936 I < Args.size() && I < FD->getNumParams() + ImplicitObjectArgOffset;
938 const ParmVarDecl *PVD = FD->getParamDecl(I - ImplicitObjectArgOffset);
941 if (PVD->isExplicitObjectParameter())
943 if (!PVD->getType()->isRValueReferenceType())
948 if (PVD->hasAttr<LifetimeBoundAttr>() ||
949 PVD->hasAttr<LifetimeCaptureByAttr>())
951 const Expr *Arg = Args[I];
952 OriginList *MovedOrigins = getOriginsList(*Arg);
953 assert(MovedOrigins->getLength() >= 1 &&
954 "unexpected length for r-value reference param");
956 CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>(
957 Arg, MovedOrigins->getOuterOriginID()));
961void FactsGenerator::handleInvalidatingCall(
const Expr *
Call,
962 const FunctionDecl *FD,
963 ArrayRef<const Expr *> Args) {
964 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
965 if (!MD || !MD->isInstance())
977 OriginList *ThisList = getOriginsList(*Args[0]);
979 CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
980 ThisList->getOuterOriginID(),
Call));
983void FactsGenerator::handleDestructiveCall(
const Expr *
Call,
984 const FunctionDecl *FD,
985 ArrayRef<const Expr *> Args) {
988 OriginList *ArgList = getOriginsList(*Args[0]);
990 CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
991 ArgList->getOuterOriginID(),
Call));
994void FactsGenerator::handleImplicitObjectFieldUses(
const Expr *
Call,
995 const FunctionDecl *FD) {
996 const auto *MemberCall = dyn_cast_or_null<CXXMemberCallExpr>(
Call);
1000 if (!isa_and_present<CXXThisExpr>(
1001 MemberCall->getImplicitObjectArgument()->IgnoreImpCasts()))
1004 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
1005 assert(MD &&
"Function must be a CXXMethodDecl for member calls");
1007 const auto *ClassDecl = MD->getParent()->getDefinition();
1011 const auto UseFields = [&](
const CXXRecordDecl *RD) {
1012 for (
const auto *Field : RD->fields())
1013 if (
auto *FieldList = getOriginsList(*Field))
1014 CurrentBlockFacts.push_back(
1015 FactMgr.createFact<UseFact>(
Call, FieldList));
1018 UseFields(ClassDecl);
1020 ClassDecl->forallBases([&](
const CXXRecordDecl *Base) {
1026void FactsGenerator::handleLifetimeCaptureBy(
const FunctionDecl *FD,
1027 ArrayRef<const Expr *> Args) {
1033 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
1036 auto getParamDeclAt = [FD, IsInstance](
unsigned I) ->
const ParmVarDecl * {
1039 if (I > 0 && I - 1 < FD->getNumParams())
1040 return FD->getParamDecl(I - 1);
1042 if (I < FD->getNumParams())
1043 return FD->getParamDecl(I);
1047 for (
unsigned I = 0; I < Args.size(); ++I) {
1048 const ParmVarDecl *PVD = getParamDeclAt(I);
1051 const auto *Attr = PVD->getAttr<LifetimeCaptureByAttr>();
1054 OriginList *CapturedOriginList = getOriginsList(*Args[I]);
1055 if (!CapturedOriginList)
1059 if (QualType ParamType = PVD->getType();
1060 (ParamType->isReferenceType() &&
1062 CapturedOriginList->getLength() > 1)
1063 CapturedOriginList = CapturedOriginList->peelOuterOrigin();
1064 for (
int CapturingArgIdx : Attr->params()) {
1066 if (CapturingArgIdx == LifetimeCaptureByAttr::Global ||
1067 CapturingArgIdx == LifetimeCaptureByAttr::Unknown ||
1068 CapturingArgIdx == LifetimeCaptureByAttr::Invalid)
1070 ArrayRef<const Expr *> CallArgs = IsInstance ? Args.drop_front() : Args;
1071 const Expr *CapturedByArg =
1072 (CapturingArgIdx == LifetimeCaptureByAttr::This)
1074 : CallArgs[CapturingArgIdx];
1075 assert(CapturedByArg &&
"Capturer expression must be valid");
1077 OriginList *CapturingOriginList = getOriginsList(*CapturedByArg);
1085 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1086 Dest->getOuterOriginID(), CapturedOriginList->getOuterOriginID(),
1092void FactsGenerator::handleFunctionCall(
const Expr *
Call,
1093 const FunctionDecl *FD,
1094 ArrayRef<const Expr *> Args,
1095 bool IsGslConstruction) {
1096 OriginList *CallList = getOriginsList(*
Call);
1102 for (
const Expr *Arg : Args)
1104 handleInvalidatingCall(
Call, FD, Args);
1105 handleDestructiveCall(
Call, FD, Args);
1106 handleMovedArgsInCall(FD, Args);
1107 handleImplicitObjectFieldUses(
Call, FD);
1108 handleLifetimeCaptureBy(FD, Args);
1112 assert(Args.size() == 1 &&
1113 "std reference cast builtins take exactly one argument");
1116 flow(CallList, getOriginsList(*Args[0]),
true);
1119 auto shouldTrackPointerImplicitObjectArg = [FD, &Args](
unsigned I) ->
bool {
1120 const auto *
Method = dyn_cast<CXXMethodDecl>(FD);
1130 bool KillSrc =
true;
1131 for (
unsigned I = 0; I < Args.size(); ++I) {
1132 OriginList *ArgList = getOriginsList(*Args[I]);
1136 if (IsGslConstruction) {
1140 assert(!Args[I]->isGLValue() || ArgList->getLength() >= 2);
1147 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1148 CallList->getOuterOriginID(), ArgList->getOuterOriginID(),
1151 }
else if (ShouldTrackArg) {
1158 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1159 CallList->getOuterOriginID(), ArgList->getOuterOriginID(),
1163 }
else if (shouldTrackPointerImplicitObjectArg(I)) {
1164 assert(ArgList->getLength() >= 2 &&
1165 "Object arg of pointer type should have at least two origins");
1167 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1168 CallList->getOuterOriginID(),
1169 ArgList->peelOuterOrigin()->getOuterOriginID(), KillSrc));
1171 }
else if (ShouldTrackArg) {
1175 CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
1176 CallList->getOuterOriginID(), ArgList->getOuterOriginID(), KillSrc));
1184bool FactsGenerator::handleTestPoint(
const CXXFunctionalCastExpr *FCE) {
1185 if (!FCE->getType()->isVoidType())
1188 const auto *SubExpr = FCE->getSubExpr()->IgnoreParenImpCasts();
1189 if (
const auto *SL = dyn_cast<StringLiteral>(SubExpr)) {
1190 llvm::StringRef LiteralValue = SL->getString();
1191 const std::string Prefix =
"__lifetime_test_point_";
1193 if (LiteralValue.starts_with(Prefix)) {
1194 StringRef Annotation = LiteralValue.drop_front(Prefix.length());
1195 CurrentBlockFacts.push_back(
1196 FactMgr.createFact<TestPointFact>(Annotation));
1203void FactsGenerator::handleUse(
const Expr *E) {
1204 OriginList *List = getOriginsList(*E);
1210 if (
auto *DRE = dyn_cast<DeclRefExpr>(E);
1211 DRE && !DRE->getDecl()->
getType()->isReferenceType())
1216 if (!UseFacts.contains(E)) {
1217 UseFact *UF = FactMgr.createFact<UseFact>(E, List);
1218 CurrentBlockFacts.push_back(UF);
1223void FactsGenerator::markUseAsWrite(
const DeclRefExpr *DRE) {
1224 if (UseFacts.contains(DRE))
1225 UseFacts[DRE]->markAsWritten();
1230llvm::SmallVector<Fact *> FactsGenerator::issuePlaceholderLoans() {
1231 const auto *FD = dyn_cast<FunctionDecl>(AC.getDecl());
1235 llvm::SmallVector<Fact *> PlaceholderLoanFacts;
1236 if (
auto ThisOrigins = FactMgr.getOriginMgr().getThisOrigins()) {
1237 OriginList *List = *ThisOrigins;
1240 PlaceholderLoanFacts.push_back(
1241 FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
1243 for (
const ParmVarDecl *PVD : FD->parameters()) {
1244 OriginList *List = getOriginsList(*PVD);
1247 const Loan *L = FactMgr.getLoanMgr().createPlaceholderLoan(PVD);
1248 PlaceholderLoanFacts.push_back(
1249 FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
1251 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.
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.
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.
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 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:...
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 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 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 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
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...
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.
FunctionCallInfo getFunctionCallInfo(const Expr *Call)
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)