r368755 - [analyzer][NFC] Make sure that the BugReport is not modified during the construction of non-visitor pieces
Kristof Umann via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 13 15:03:08 PDT 2019
Author: szelethus
Date: Tue Aug 13 15:03:08 2019
New Revision: 368755
URL: http://llvm.org/viewvc/llvm-project?rev=368755&view=rev
Log:
[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
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h?rev=368755&r1=368754&r2=368755&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Tue Aug 13 15:03:08 2019
@@ -105,6 +105,7 @@ protected:
const ExplodedNode *ErrorNode = nullptr;
SmallVector<SourceRange, 4> Ranges;
+ const SourceRange ErrorNodeRange;
ExtraTextList ExtraText;
NoteList Notes;
@@ -155,16 +156,22 @@ protected:
llvm::SmallSet<const ExplodedNode *, 4> TrackedConditions;
public:
- BugReport(const BugType& bt, StringRef desc, const ExplodedNode *errornode)
- : BT(bt), Description(desc), ErrorNode(errornode) {}
+ BugReport(const BugType &bt, StringRef desc, const ExplodedNode *errornode)
+ : BT(bt), Description(desc), ErrorNode(errornode),
+ ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+ : SourceRange()) {}
- BugReport(const BugType& bt, StringRef shortDesc, StringRef desc,
+ BugReport(const BugType &bt, StringRef shortDesc, StringRef desc,
const ExplodedNode *errornode)
: BT(bt), ShortDescription(shortDesc), Description(desc),
- ErrorNode(errornode) {}
+ ErrorNode(errornode),
+ ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+ : SourceRange()) {}
BugReport(const BugType &bt, StringRef desc, PathDiagnosticLocation l)
- : BT(bt), Description(desc), Location(l) {}
+ : BT(bt), Description(desc), Location(l),
+ ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+ : SourceRange()) {}
/// Create a BugReport with a custom uniqueing location.
///
@@ -323,7 +330,7 @@ public:
}
/// Get the SourceRanges associated with the report.
- virtual llvm::iterator_range<ranges_iterator> getRanges();
+ virtual llvm::iterator_range<ranges_iterator> getRanges() const;
/// Add custom or predefined bug report visitors to this report.
///
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h?rev=368755&r1=368754&r2=368755&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h Tue Aug 13 15:03:08 2019
@@ -82,7 +82,7 @@ public:
/// Generates the default final diagnostic piece.
static PathDiagnosticPieceRef getDefaultEndPath(const BugReporterContext &BRC,
const ExplodedNode *N,
- BugReport &BR);
+ const BugReport &BR);
};
/// Finds last store into the given region,
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h?rev=368755&r1=368754&r2=368755&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h Tue Aug 13 15:03:08 2019
@@ -67,7 +67,7 @@ public:
ExplodedNode *n, SymbolRef sym,
StringRef endText);
- llvm::iterator_range<ranges_iterator> getRanges() override {
+ llvm::iterator_range<ranges_iterator> getRanges() const override {
if (!isLeak)
return BugReport::getRanges();
return llvm::make_range(ranges_iterator(), ranges_iterator());
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=368755&r1=368754&r2=368755&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Tue Aug 13 15:03:08 2019
@@ -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.
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=368755&r1=368754&r2=368755&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Aug 13 15:03:08 2019
@@ -267,7 +267,7 @@ void BugReporterVisitor::finalizeVisitor
PathDiagnosticPieceRef
BugReporterVisitor::getDefaultEndPath(const BugReporterContext &BRC,
const ExplodedNode *EndPathNode,
- BugReport &BR) {
+ const BugReport &BR) {
PathDiagnosticLocation L = PathDiagnosticLocation::createEndOfPath(
EndPathNode, BRC.getSourceManager());
More information about the cfe-commits
mailing list