summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2019-08-13 22:03:08 +0000
committerKristof Umann <dkszelethus@gmail.com>2019-08-13 22:03:08 +0000
commite1117addd664c3b52b4a8b7be8bdd678d42f264c (patch)
tree1f25bac12fc96e6af1f643f172f03ee3afb274c2 /clang/lib/StaticAnalyzer/Core/BugReporter.cpp
parent6c97f8898685d5d07f14e859b21fad1ffe5c39c2 (diff)
downloadbcm5719-llvm-e1117addd664c3b52b4a8b7be8bdd678d42f264c.tar.gz
bcm5719-llvm-e1117addd664c3b52b4a8b7be8bdd678d42f264c.zip
[analyzer][NFC] Make sure that the BugReport is not modified during the construction of non-visitor pieces
I feel this is kinda important, because in a followup patch I'm adding different kinds of interestingness, and propagating the correct kind in BugReporter.cpp is just one less thing to worry about. Differential Revision: https://reviews.llvm.org/D65578 llvm-svn: 368755
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/BugReporter.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/BugReporter.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 92d35b96692..f2983b7f4b6 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -192,13 +192,17 @@ public:
};
/// Contains every contextual information needed for constructing a
-/// PathDiagnostic object for a given bug report. This class (and aside from
-/// some caching BugReport does in the background) and its fields are immutable,
-/// and passes a BugReportConstruct object around during the construction.
+/// PathDiagnostic object for a given bug report. This class and its fields are
+/// immutable, and passes a BugReportConstruct object around during the
+/// construction.
class PathDiagnosticBuilder : public BugReporterContext {
/// A linear path from the error node to the root.
std::unique_ptr<const ExplodedGraph> BugPath;
- BugReport *R;
+ /// The bug report we're describing. Visitors create their diagnostics with
+ /// them being the last entities being able to modify it (for example,
+ /// changing interestingness here would cause inconsistencies as to how this
+ /// file and visitors construct diagnostics), hence its const.
+ const BugReport *R;
/// The leaf of the bug path. This isn't the same as the bug reports error
/// node, which refers to the *original* graph, not the bug path.
const ExplodedNode *const ErrorNode;
@@ -257,7 +261,7 @@ private:
ExecutionContinues(llvm::raw_string_ostream &os,
const PathDiagnosticConstruct &C) const;
- BugReport *getBugReport() const { return R; }
+ const BugReport *getBugReport() const { return R; }
};
} // namespace
@@ -2172,14 +2176,13 @@ const Stmt *BugReport::getStmt() const {
return S;
}
-llvm::iterator_range<BugReport::ranges_iterator> BugReport::getRanges() {
+llvm::iterator_range<BugReport::ranges_iterator> BugReport::getRanges() const {
// If no custom ranges, add the range of the statement corresponding to
// the error node.
if (Ranges.empty()) {
if (const auto *E = dyn_cast_or_null<Expr>(getStmt()))
- addRange(E->getSourceRange());
- else
- return llvm::make_range(ranges_iterator(), ranges_iterator());
+ return llvm::make_range(&ErrorNodeRange, &ErrorNodeRange + 1);
+ return llvm::make_range(ranges_iterator(), ranges_iterator());
}
// User-specified absence of range info.
OpenPOWER on IntegriCloud