[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr
Deep Majumder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 28 02:37:38 PDT 2021
RedDocMD updated this revision to Diff 362310.
RedDocMD added a comment.
Invalidating via the CallEvent
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105821/new/
https://reviews.llvm.org/D105821
Files:
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
*Call, *this);
ExplodedNodeSet DstInvalidated;
- StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
- for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
- I != E; ++I)
- defaultEvalCall(Bldr, *I, *Call, CallOpts);
+ // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+ // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+ // DstPreCall.end();
+ // I != E; ++I)
+ // defaultEvalCall(Bldr, *I, *Call, CallOpts);
+ getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
*Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
for (const auto &EvalCallChecker : EvalCallCheckers) {
// TODO: Support the situation when the call doesn't correspond
// to any Expr.
- ProgramPoint L = ProgramPoint::getProgramPoint(
- Call.getOriginExpr(), ProgramPoint::PostStmtKind,
- Pred->getLocationContext(), EvalCallChecker.Checker);
bool evaluated = false;
{ // CheckerContext generates transitions(populates checkDest) on
// destruction, so introduce the scope to make sure it gets properly
// populated.
- CheckerContext C(B, Eng, Pred, L);
+ CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
evaluated = EvalCallChecker(Call, C);
}
assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -139,7 +139,8 @@
if (RD->getDeclName().isIdentifier()) {
StringRef Name = RD->getName();
- return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
+ llvm::ArrayRef<llvm::StringLiteral> ValidNames(STD_PTR_NAMES);
+ return llvm::is_contained(ValidNames, Name);
}
return false;
}
@@ -279,6 +280,7 @@
CheckerContext &C) const {
ProgramStateRef State = C.getState();
+ Call.dump();
// If any one of the arg is a unique_ptr, then
// we can try this function
@@ -372,6 +374,20 @@
}
}
+ if (const auto *DC = dyn_cast<CXXDestructorCall>(&Call)) {
+ llvm::errs() << "Found destructor call\n";
+ State = DC->invalidateRegions(C.blockCount(), State);
+ const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+ assert(ThisRegion && "We do not support explicit calls to destructor");
+ const auto *InnerPtrVal = State->get<TrackedRegionMap>(ThisRegion);
+ State = State->remove<TrackedRegionMap>(ThisRegion);
+ if (InnerPtrVal)
+ State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+ C.getLocationContext(), true);
+ C.addTransition(State);
+ return true;
+ }
+
if (!ModelSmartPtrDereference)
return false;
@@ -402,8 +418,8 @@
}));
} else {
const auto *TrackingExpr = Call.getArgExpr(0);
- assert(TrackingExpr->getType()->isPointerType() &&
- "Adding a non pointer value to TrackedRegionMap");
+ if (TrackingExpr->getType()->isPointerType())
+ return false;
auto ArgVal = Call.getArgSVal(0);
State = State->set<TrackedRegionMap>(ThisRegion, ArgVal);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105821.362310.patch
Type: text/x-patch
Size: 4042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210728/c6bfe195/attachment-0001.bin>
More information about the cfe-commits
mailing list