Do not highlight bogus ranges for leaks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50549 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicObjCFoundationChecks.cpp b/lib/Analysis/BasicObjCFoundationChecks.cpp
index bb16df9..8e8feec 100644
--- a/lib/Analysis/BasicObjCFoundationChecks.cpp
+++ b/lib/Analysis/BasicObjCFoundationChecks.cpp
@@ -89,7 +89,8 @@
virtual const char* getDescription() const { return s; }
- virtual void getRanges(const SourceRange*& B, const SourceRange*& E) const {
+ virtual void getRanges(BugReporter& BR,
+ const SourceRange*& B, const SourceRange*& E) {
B = &R;
E = B+1;
}
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index 465acf0..785e4cf 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -56,27 +56,11 @@
return (*B)[0];
}
-Stmt* BugReport::getStmt() const {
- return N ? GetStmt(N->getLocation()) : NULL;
-}
-
static inline ExplodedNode<ValueState>*
GetNextNode(ExplodedNode<ValueState>* N) {
return N->pred_empty() ? NULL : *(N->pred_begin());
}
-static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
- ExplodedNode<ValueState>* N) {
-
- Stmt* S = GetStmt(N->getLocation());
-
- if (!S)
- return;
-
- os << "Execution continue on line "
- << SMgr.getLogicalLineNumber(S->getLocStart()) << '.';
-}
-
static Stmt* GetLastStmt(ExplodedNode<ValueState>* N) {
assert (isa<BlockEntrance>(N->getLocation()));
@@ -91,18 +75,39 @@
return NULL;
}
-PathDiagnosticPiece*
-BugReport::getEndPath(BugReporter& BR,
- ExplodedNode<ValueState>* EndPathNode) const {
+
+static void ExecutionContinues(std::ostream& os, SourceManager& SMgr,
+ ExplodedNode<ValueState>* N) {
- ProgramPoint ProgP = EndPathNode->getLocation();
+ Stmt* S = GetStmt(N->getLocation());
+
+ if (!S)
+ return;
+
+ os << "Execution continue on line "
+ << SMgr.getLogicalLineNumber(S->getLocStart()) << '.';
+}
+
+
+Stmt* BugReport::getStmt(BugReporter& BR) const {
+
+ ProgramPoint ProgP = N->getLocation();
Stmt *S = NULL;
if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP))
if (BE->getBlock() == &BR.getCFG().getExit())
- S = GetLastStmt(EndPathNode);
+ S = GetLastStmt(N);
if (!S)
- S = GetStmt(ProgP);
+ S = GetStmt(ProgP);
+
+ return S;
+}
+
+PathDiagnosticPiece*
+BugReport::getEndPath(BugReporter& BR,
+ ExplodedNode<ValueState>* EndPathNode) {
+
+ Stmt* S = getStmt(BR);
if (!S)
return NULL;
@@ -113,25 +118,24 @@
new PathDiagnosticPiece(L, getDescription());
const SourceRange *Beg, *End;
- getRanges(Beg, End);
-
- if (Beg == End) {
- if (Expr* E = dyn_cast<Expr>(S))
- P->addRange(E->getSourceRange());
- }
- else {
- assert (Beg < End);
- for (; Beg != End; ++Beg)
- P->addRange(*Beg);
- }
+ getRanges(BR, Beg, End);
+
+ for (; Beg != End; ++Beg)
+ P->addRange(*Beg);
return P;
}
-void BugReport::getRanges(const SourceRange*& beg,
- const SourceRange*& end) const {
- beg = NULL;
- end = NULL;
+void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
+ const SourceRange*& end) {
+
+ if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
+ R = E->getSourceRange();
+ beg = &R;
+ end = beg+1;
+ }
+ else
+ beg = end = 0;
}
FullSourceLoc BugReport::getLocation(SourceManager& Mgr) {
@@ -479,7 +483,7 @@
End = D->back()->ranges_end();
}
else
- R.getRanges(Beg, End);
+ R.getRanges(*this, Beg, End);
if (PD) {
PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription());
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp
index 9828792..ea036f0 100644
--- a/lib/Analysis/CFRefCount.cpp
+++ b/lib/Analysis/CFRefCount.cpp
@@ -1444,7 +1444,9 @@
public:
CFRefBug(CFRefCount& tf) : TF(tf) {}
- CFRefCount& getTF() { return TF; }
+ CFRefCount& getTF() { return TF; }
+
+ virtual bool ReportRanges() const { return true; }
};
class VISIBILITY_HIDDEN UseAfterRelease : public CFRefBug {
@@ -1491,7 +1493,8 @@
}
virtual void EmitWarnings(BugReporter& BR);
- virtual void GetErrorNodes(std::vector<ExplodedNode<ValueState>*>& Nodes);
+ virtual void GetErrorNodes(std::vector<ExplodedNode<ValueState>*>& Nodes);
+ virtual bool ReportRanges() const { return false; }
};
//===---------===//
@@ -1506,6 +1509,24 @@
virtual ~CFRefReport() {}
+ CFRefBug& getBugType() {
+ return (CFRefBug&) RangedBugReport::getBugType();
+ }
+ const CFRefBug& getBugType() const {
+ return (const CFRefBug&) RangedBugReport::getBugType();
+ }
+
+ virtual void getRanges(BugReporter& BR, const SourceRange*& beg,
+ const SourceRange*& end) {
+
+ if (getBugType().ReportRanges())
+ RangedBugReport::getRanges(BR, beg, end);
+ else {
+ beg = 0;
+ end = 0;
+ }
+ }
+
virtual std::pair<const char**,const char**> getExtraDescriptiveText();
virtual PathDiagnosticPiece* VisitNode(ExplodedNode<ValueState>* N,