diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h @@ -375,50 +375,6 @@ } // namespace bugreporter -/// Finds last store into the given region, -/// which is different from a given symbolic value. -class FindLastStoreBRVisitor final - : public bugreporter::TrackingBugReporterVisitor { - const MemRegion *R; - SVal V; - bool Satisfied = false; - - /// If the visitor is tracking the value directly responsible for the - /// bug, we are going to employ false positive suppression. - bool EnableNullFPSuppression; - - using TrackingKind = bugreporter::TrackingKind; - TrackingKind TKind; - const StackFrameContext *OriginSFC; - -public: - /// \param V We're searching for the store where \c R received this value. - /// \param R The region we're tracking. - /// \param TKind May limit the amount of notes added to the bug report. - /// \param OriginSFC Only adds notes when the last store happened in a - /// different stackframe to this one. Disregarded if the tracking kind - /// is thorough. - /// This is useful, because for non-tracked regions, notes about - /// changes to its value in a nested stackframe could be pruned, and - /// this visitor can prevent that without polluting the bugpath too - /// much. - FindLastStoreBRVisitor(bugreporter::TrackerRef ParentTracker, KnownSVal V, - const MemRegion *R, bool InEnableNullFPSuppression, - TrackingKind TKind, - const StackFrameContext *OriginSFC = nullptr) - : TrackingBugReporterVisitor(ParentTracker), R(R), V(V), - EnableNullFPSuppression(InEnableNullFPSuppression), TKind(TKind), - OriginSFC(OriginSFC) { - assert(R); - } - - void Profile(llvm::FoldingSetNodeID &ID) const override; - - PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, - BugReporterContext &BRC, - PathSensitiveBugReport &BR) override; -}; - class TrackConstraintBRVisitor final : public BugReporterVisitor { DefinedSVal Constraint; bool Assumption; diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -1219,10 +1219,53 @@ } // end of anonymous namespace //===----------------------------------------------------------------------===// -// Implementation of FindLastStoreBRVisitor. +// StoreSiteFinder //===----------------------------------------------------------------------===// -void FindLastStoreBRVisitor::Profile(llvm::FoldingSetNodeID &ID) const { +/// Finds last store into the given region, +/// which is different from a given symbolic value. +class StoreSiteFinder final : public TrackingBugReporterVisitor { + const MemRegion *R; + SVal V; + bool Satisfied = false; + + /// If the visitor is tracking the value directly responsible for the + /// bug, we are going to employ false positive suppression. + bool EnableNullFPSuppression; + + using TrackingKind = bugreporter::TrackingKind; + TrackingKind TKind; + const StackFrameContext *OriginSFC; + +public: + /// \param V We're searching for the store where \c R received this value. + /// \param R The region we're tracking. + /// \param TKind May limit the amount of notes added to the bug report. + /// \param OriginSFC Only adds notes when the last store happened in a + /// different stackframe to this one. Disregarded if the tracking kind + /// is thorough. + /// This is useful, because for non-tracked regions, notes about + /// changes to its value in a nested stackframe could be pruned, and + /// this visitor can prevent that without polluting the bugpath too + /// much. + StoreSiteFinder(bugreporter::TrackerRef ParentTracker, KnownSVal V, + const MemRegion *R, bool InEnableNullFPSuppression, + TrackingKind TKind, + const StackFrameContext *OriginSFC = nullptr) + : TrackingBugReporterVisitor(ParentTracker), R(R), V(V), + EnableNullFPSuppression(InEnableNullFPSuppression), TKind(TKind), + OriginSFC(OriginSFC) { + assert(R); + } + + void Profile(llvm::FoldingSetNodeID &ID) const override; + + PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, + BugReporterContext &BRC, + PathSensitiveBugReport &BR) override; +}; + +void StoreSiteFinder::Profile(llvm::FoldingSetNodeID &ID) const { static int tag = 0; ID.AddPointer(&tag); ID.AddPointer(R); @@ -1393,10 +1436,9 @@ } } -PathDiagnosticPieceRef -FindLastStoreBRVisitor::VisitNode(const ExplodedNode *Succ, - BugReporterContext &BRC, - PathSensitiveBugReport &BR) { +PathDiagnosticPieceRef StoreSiteFinder::VisitNode(const ExplodedNode *Succ, + BugReporterContext &BRC, + PathSensitiveBugReport &BR) { if (Satisfied) return nullptr; @@ -2240,8 +2282,8 @@ Tracker::Result Tracker::track(KnownSVal V, const MemRegion *R, TrackingOptions Opts, const StackFrameContext *Origin) { - Report.addVisitor( - this, V, R, Opts.EnableNullFPSuppression, Opts.Kind, Origin); + Report.addVisitor(this, V, R, Opts.EnableNullFPSuppression, + Opts.Kind, Origin); return {true, false}; }