Skip to content

Commit dd18b11

Browse files
author
George Karpenkov
committedJun 27, 2018
[analyzer] [NFC] A convenient getter for getting a current stack frame
Differential Revision: https://reviews.llvm.org/D44756 llvm-svn: 335701
1 parent fb5e8d9 commit dd18b11

24 files changed

+70
-71
lines changed
 

‎clang/include/clang/Analysis/AnalysisDeclContext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class LocationContext : public llvm::FoldingSetNode {
264264
return Ctx->getSelfDecl();
265265
}
266266

267-
const StackFrameContext *getCurrentStackFrame() const;
267+
const StackFrameContext *getStackFrame() const;
268268

269269
/// Return true if the current LocationContext has no caller context.
270270
virtual bool inTopFrame() const;

‎clang/include/clang/Analysis/ProgramPoint.h

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class ProgramPoint {
181181
return L.getPointer();
182182
}
183183

184+
const StackFrameContext *getStackFrame() const {
185+
return getLocationContext()->getStackFrame();
186+
}
187+
184188
// For use with DenseMap. This hash is probably slow.
185189
unsigned getHashValue() const {
186190
llvm::FoldingSetNodeID ID;

‎clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ struct NodeBuilderContext {
211211
/// visited on the exploded graph path.
212212
unsigned blockCount() const {
213213
return Eng.WList->getBlockCounter().getNumVisited(
214-
LC->getCurrentStackFrame(),
214+
LC->getStackFrame(),
215215
Block->getBlockID());
216216
}
217217
};

‎clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ExplodedNode : public llvm::FoldingSetNode {
147147
}
148148

149149
const StackFrameContext *getStackFrame() const {
150-
return getLocationContext()->getCurrentStackFrame();
150+
return getLocation().getStackFrame();
151151
}
152152

153153
const Decl &getCodeDecl() const { return *getLocationContext()->getDecl(); }

‎clang/lib/Analysis/AnalysisDeclContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ LocationContextManager::getBlockInvocationContext(AnalysisDeclContext *ctx,
442442
// LocationContext methods.
443443
//===----------------------------------------------------------------------===//
444444

445-
const StackFrameContext *LocationContext::getCurrentStackFrame() const {
445+
const StackFrameContext *LocationContext::getStackFrame() const {
446446
const LocationContext *LC = this;
447447
while (LC) {
448448
if (const auto *SFC = dyn_cast<StackFrameContext>(LC))
@@ -453,7 +453,7 @@ const StackFrameContext *LocationContext::getCurrentStackFrame() const {
453453
}
454454

455455
bool LocationContext::inTopFrame() const {
456-
return getCurrentStackFrame()->inTopFrame();
456+
return getStackFrame()->inTopFrame();
457457
}
458458

459459
bool LocationContext::isParentOf(const LocationContext *LC) const {

‎clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void CXXSelfAssignmentChecker::checkBeginFunction(CheckerContext &C) const {
4848
auto &State = C.getState();
4949
auto &SVB = C.getSValBuilder();
5050
auto ThisVal =
51-
State->getSVal(SVB.getCXXThis(MD, LCtx->getCurrentStackFrame()));
51+
State->getSVal(SVB.getCXXThis(MD, LCtx->getStackFrame()));
5252
auto Param = SVB.makeLoc(State->getRegion(MD->getParamDecl(0), LCtx));
5353
auto ParamVal = State->getSVal(Param);
5454
ProgramStateRef SelfAssignState = State->bindLoc(Param, ThisVal, LCtx);

‎clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void ExprInspectionChecker::analyzerEval(const CallExpr *CE,
149149

150150
// A specific instantiation of an inlined function may have more constrained
151151
// values than can generally be assumed. Skip the check.
152-
if (LC->getCurrentStackFrame()->getParent() != nullptr)
152+
if (LC->getStackFrame()->getParent() != nullptr)
153153
return;
154154

155155
reportBug(getArgumentValueString(CE, C), C);
@@ -178,7 +178,7 @@ void ExprInspectionChecker::analyzerCheckInlined(const CallExpr *CE,
178178
// when we are analyzing it as an inlined function. This means that
179179
// clang_analyzer_checkInlined(true) should always print TRUE, but
180180
// clang_analyzer_checkInlined(false) should never actually print anything.
181-
if (LC->getCurrentStackFrame()->getParent() == nullptr)
181+
if (LC->getStackFrame()->getParent() == nullptr)
182182
return;
183183

184184
reportBug(getArgumentValueString(CE, C), C);

‎clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ MallocChecker::getAllocationSite(const ExplodedNode *N, SymbolRef Sym,
22582258
// Do not show local variables belonging to a function other than
22592259
// where the error is reported.
22602260
if (!VR ||
2261-
(VR->getStackFrame() == LeakContext->getCurrentStackFrame()))
2261+
(VR->getStackFrame() == LeakContext->getStackFrame()))
22622262
ReferenceRegion = MR;
22632263
}
22642264
}
@@ -2919,7 +2919,7 @@ std::shared_ptr<PathDiagnosticPiece> MallocChecker::MallocBugVisitor::VisitNode(
29192919
// reference counting operations within it (see the code above),
29202920
// and if so, we'd conclude that it likely is a reference counting
29212921
// pointer destructor.
2922-
ReleaseDestructorLC = LC->getCurrentStackFrame();
2922+
ReleaseDestructorLC = LC->getStackFrame();
29232923
// It is unlikely that releasing memory is delegated to a destructor
29242924
// inside a destructor of a shared pointer, because it's fairly hard
29252925
// to pass the information that the pointer indeed needs to be

‎clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ static void setFlag(ProgramStateRef state, SVal val, CheckerContext &C) {
186186
}
187187

188188
static QualType parameterTypeFromSVal(SVal val, CheckerContext &C) {
189-
const StackFrameContext *
190-
SFC = C.getLocationContext()->getCurrentStackFrame();
189+
const StackFrameContext * SFC = C.getStackFrame();
191190
if (Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>()) {
192191
const MemRegion* R = X->getRegion();
193192
if (const VarRegion *VR = R->getAs<VarRegion>())

‎clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1968,8 +1968,8 @@ CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
19681968
const Stmt *S = N->getLocation().castAs<StmtPoint>().getStmt();
19691969

19701970
if (isa<ObjCIvarRefExpr>(S) &&
1971-
isSynthesizedAccessor(LCtx->getCurrentStackFrame())) {
1972-
S = LCtx->getCurrentStackFrame()->getCallSite();
1971+
isSynthesizedAccessor(LCtx->getStackFrame())) {
1972+
S = LCtx->getStackFrame()->getCallSite();
19731973
}
19741974

19751975
if (isa<ObjCArrayLiteral>(S)) {
@@ -2297,7 +2297,7 @@ GetAllocationSite(ProgramStateManager& StateMgr, const ExplodedNode *N,
22972297
const VarRegion *VR = R->getBaseRegion()->getAs<VarRegion>();
22982298
// Do not show local variables belonging to a function other than
22992299
// where the error is reported.
2300-
if (!VR || VR->getStackFrame() == LeakContext->getCurrentStackFrame())
2300+
if (!VR || VR->getStackFrame() == LeakContext->getStackFrame())
23012301
FirstBinding = R;
23022302
}
23032303

‎clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool StackAddrEscapeChecker::isArcManagedBlock(const MemRegion *R,
120120
bool StackAddrEscapeChecker::isNotInCurrentFrame(const MemRegion *R,
121121
CheckerContext &C) {
122122
const StackSpaceRegion *S = cast<StackSpaceRegion>(R->getMemorySpace());
123-
return S->getStackFrame() != C.getLocationContext()->getCurrentStackFrame();
123+
return S->getStackFrame() != C.getStackFrame();
124124
}
125125

126126
bool StackAddrEscapeChecker::isSemaphoreCaptured(const BlockDecl &B) const {
@@ -303,8 +303,7 @@ void StackAddrEscapeChecker::checkEndFunction(CheckerContext &Ctx) const {
303303
public:
304304
SmallVector<std::pair<const MemRegion *, const MemRegion *>, 10> V;
305305

306-
CallBack(CheckerContext &CC)
307-
: Ctx(CC), CurSFC(CC.getLocationContext()->getCurrentStackFrame()) {}
306+
CallBack(CheckerContext &CC) : Ctx(CC), CurSFC(CC.getStackFrame()) {}
308307

309308
bool HandleBinding(StoreManager &SMgr, Store S, const MemRegion *Region,
310309
SVal Val) override {

‎clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ VirtualCallChecker::VirtualBugVisitor::VisitNode(const ExplodedNode *N,
108108
if (!MD)
109109
return nullptr;
110110
auto ThiSVal =
111-
State->getSVal(SVB.getCXXThis(MD, LCtx->getCurrentStackFrame()));
111+
State->getSVal(SVB.getCXXThis(MD, LCtx->getStackFrame()));
112112
const MemRegion *Reg = ThiSVal.castAs<loc::MemRegionVal>().getRegion();
113113
if (!Reg)
114114
return nullptr;
@@ -230,7 +230,7 @@ void VirtualCallChecker::registerCtorDtorCallInState(bool IsBeginFunction,
230230
// Enter a constructor, set the corresponding memregion be true.
231231
if (isa<CXXConstructorDecl>(MD)) {
232232
auto ThiSVal =
233-
State->getSVal(SVB.getCXXThis(MD, LCtx->getCurrentStackFrame()));
233+
State->getSVal(SVB.getCXXThis(MD, LCtx->getStackFrame()));
234234
const MemRegion *Reg = ThiSVal.getAsRegion();
235235
if (IsBeginFunction)
236236
State = State->set<CtorDtorMap>(Reg, ObjectState::CtorCalled);
@@ -244,7 +244,7 @@ void VirtualCallChecker::registerCtorDtorCallInState(bool IsBeginFunction,
244244
// Enter a Destructor, set the corresponding memregion be true.
245245
if (isa<CXXDestructorDecl>(MD)) {
246246
auto ThiSVal =
247-
State->getSVal(SVB.getCXXThis(MD, LCtx->getCurrentStackFrame()));
247+
State->getSVal(SVB.getCXXThis(MD, LCtx->getStackFrame()));
248248
const MemRegion *Reg = ThiSVal.getAsRegion();
249249
if (IsBeginFunction)
250250
State = State->set<CtorDtorMap>(Reg, ObjectState::DtorCalled);

‎clang/lib/StaticAnalyzer/Core/BugReporter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ static void reversePropagateInterestingSymbols(BugReport &R,
865865
const LocationContext *CallerCtx)
866866
{
867867
// FIXME: Handle non-CallExpr-based CallEvents.
868-
const StackFrameContext *Callee = CalleeCtx->getCurrentStackFrame();
868+
const StackFrameContext *Callee = CalleeCtx->getStackFrame();
869869
const Stmt *CallSite = Callee->getCallSite();
870870
if (const auto *CE = dyn_cast_or_null<CallExpr>(CallSite)) {
871871
if (const auto *FD = dyn_cast<FunctionDecl>(CalleeCtx->getDecl())) {
@@ -1956,7 +1956,7 @@ static std::unique_ptr<PathDiagnostic> generatePathDiagnosticForConsumer(
19561956
if (AddPathEdges) {
19571957
// Add an edge to the start of the function.
19581958
// We'll prune it out later, but it helps make diagnostics more uniform.
1959-
const StackFrameContext *CalleeLC = PDB.LC->getCurrentStackFrame();
1959+
const StackFrameContext *CalleeLC = PDB.LC->getStackFrame();
19601960
const Decl *D = CalleeLC->getDecl();
19611961
addEdgeToPath(PD->getActivePath(), PrevLoc,
19621962
PathDiagnosticLocation::createBegin(D, SM), CalleeLC);
@@ -2051,7 +2051,7 @@ const Decl *BugReport::getDeclWithIssue() const {
20512051
return nullptr;
20522052

20532053
const LocationContext *LC = N->getLocationContext();
2054-
return LC->getCurrentStackFrame()->getDecl();
2054+
return LC->getStackFrame()->getDecl();
20552055
}
20562056

20572057
void BugReport::Profile(llvm::FoldingSetNodeID& hash) const {

‎clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class NoStoreFuncVisitor final : public BugReporterVisitor {
264264
BugReport &BR) override {
265265

266266
const LocationContext *Ctx = N->getLocationContext();
267-
const StackFrameContext *SCtx = Ctx->getCurrentStackFrame();
267+
const StackFrameContext *SCtx = Ctx->getStackFrame();
268268
ProgramStateRef State = N->getState();
269269
auto CallExitLoc = N->getLocationAs<CallExitBegin>();
270270

@@ -319,7 +319,7 @@ class NoStoreFuncVisitor final : public BugReporterVisitor {
319319
/// The calculation is cached in FramesModifyingRegion.
320320
bool isRegionOfInterestModifiedInFrame(const ExplodedNode *N) {
321321
const LocationContext *Ctx = N->getLocationContext();
322-
const StackFrameContext *SCtx = Ctx->getCurrentStackFrame();
322+
const StackFrameContext *SCtx = Ctx->getStackFrame();
323323
if (!FramesModifyingCalculated.count(SCtx))
324324
findModifyingFrames(N);
325325
return FramesModifyingRegion.count(SCtx);
@@ -333,7 +333,7 @@ class NoStoreFuncVisitor final : public BugReporterVisitor {
333333
ProgramStateRef LastReturnState = N->getState();
334334
SVal ValueAtReturn = LastReturnState->getSVal(RegionOfInterest);
335335
const LocationContext *Ctx = N->getLocationContext();
336-
const StackFrameContext *OriginalSCtx = Ctx->getCurrentStackFrame();
336+
const StackFrameContext *OriginalSCtx = Ctx->getStackFrame();
337337

338338
do {
339339
ProgramStateRef State = N->getState();
@@ -344,16 +344,15 @@ class NoStoreFuncVisitor final : public BugReporterVisitor {
344344
}
345345

346346
FramesModifyingCalculated.insert(
347-
N->getLocationContext()->getCurrentStackFrame());
347+
N->getLocationContext()->getStackFrame());
348348

349349
if (wasRegionOfInterestModifiedAt(N, LastReturnState, ValueAtReturn)) {
350-
const StackFrameContext *SCtx =
351-
N->getLocationContext()->getCurrentStackFrame();
350+
const StackFrameContext *SCtx = N->getStackFrame();
352351
while (!SCtx->inTopFrame()) {
353352
auto p = FramesModifyingRegion.insert(SCtx);
354353
if (!p.second)
355354
break; // Frame and all its parents already inserted.
356-
SCtx = SCtx->getParent()->getCurrentStackFrame();
355+
SCtx = SCtx->getParent()->getStackFrame();
357356
}
358357
}
359358

@@ -913,7 +912,7 @@ static bool isInitializationOfVar(const ExplodedNode *N, const VarRegion *VR) {
913912

914913
assert(VR->getDecl()->hasLocalStorage());
915914
const LocationContext *LCtx = N->getLocationContext();
916-
return FrameSpace->getStackFrame() == LCtx->getCurrentStackFrame();
915+
return FrameSpace->getStackFrame() == LCtx->getStackFrame();
917916
}
918917

919918
/// Show diagnostics for initializing or declaring a region \p R with a bad value.
@@ -2310,7 +2309,7 @@ CXXSelfAssignmentBRVisitor::VisitNode(const ExplodedNode *Succ,
23102309
const auto Param =
23112310
State->getSVal(State->getRegion(Met->getParamDecl(0), LCtx));
23122311
const auto This =
2313-
State->getSVal(SVB.getCXXThis(Met, LCtx->getCurrentStackFrame()));
2312+
State->getSVal(SVB.getCXXThis(Met, LCtx->getStackFrame()));
23142313

23152314
auto L = PathDiagnosticLocation::create(Met, BRC.getSourceManager());
23162315

‎clang/lib/StaticAnalyzer/Core/CallEvent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ CallEventRef<>
12211221
CallEventManager::getCaller(const StackFrameContext *CalleeCtx,
12221222
ProgramStateRef State) {
12231223
const LocationContext *ParentCtx = CalleeCtx->getParent();
1224-
const LocationContext *CallerCtx = ParentCtx->getCurrentStackFrame();
1224+
const LocationContext *CallerCtx = ParentCtx->getStackFrame();
12251225
assert(CallerCtx && "This should not be used for top-level stack frames");
12261226

12271227
const Stmt *CallSite = CalleeCtx->getCallSite();

‎clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void CoreEngine::HandleBlockEntrance(const BlockEntrance &L,
256256
const LocationContext *LC = Pred->getLocationContext();
257257
unsigned BlockId = L.getBlock()->getBlockID();
258258
BlockCounter Counter = WList->getBlockCounter();
259-
Counter = BCounterFactory.IncrementCount(Counter, LC->getCurrentStackFrame(),
259+
Counter = BCounterFactory.IncrementCount(Counter, LC->getStackFrame(),
260260
BlockId);
261261
WList->setBlockCounter(Counter);
262262

‎clang/lib/StaticAnalyzer/Core/Environment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static const Stmt *ignoreTransparentExprs(const Stmt *S) {
6767
EnvironmentEntry::EnvironmentEntry(const Stmt *S, const LocationContext *L)
6868
: std::pair<const Stmt *,
6969
const StackFrameContext *>(ignoreTransparentExprs(S),
70-
L ? L->getCurrentStackFrame()
70+
L ? L->getStackFrame()
7171
: nullptr) {}
7272

7373
SVal Environment::lookupExpr(const EnvironmentEntry &E) const {

0 commit comments

Comments
 (0)
Please sign in to comment.