BugReporter (extensive diagnostics): Fix getEnclosingStmtLocation to reason
about Exprs that are not consumed and fix where the loop iteration diagnostic goes. llvm-svn: 71027
This commit is contained in:
parent
90a6145ad1
commit
98017051ae
|
@ -215,9 +215,9 @@ PathDiagnosticBuilder::ExecutionContinues(llvm::raw_string_ostream& os,
|
||||||
PathDiagnosticLocation
|
PathDiagnosticLocation
|
||||||
PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
|
PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) {
|
||||||
assert(S && "Null Stmt* passed to getEnclosingStmtLocation");
|
assert(S && "Null Stmt* passed to getEnclosingStmtLocation");
|
||||||
ParentMap &P = getParentMap();
|
ParentMap &P = getParentMap();
|
||||||
|
|
||||||
while (isa<DeclStmt>(S) || isa<Expr>(S)) {
|
while (isa<Expr>(S) && P.isConsumedExpr(cast<Expr>(S))) {
|
||||||
const Stmt *Parent = P.getParent(S);
|
const Stmt *Parent = P.getParent(S);
|
||||||
|
|
||||||
if (!Parent)
|
if (!Parent)
|
||||||
|
@ -797,8 +797,6 @@ class VISIBILITY_HIDDEN EdgeBuilder {
|
||||||
S = CE->getCond();
|
S = CE->getCond();
|
||||||
else if (const BinaryOperator *BE = dyn_cast<BinaryOperator>(S))
|
else if (const BinaryOperator *BE = dyn_cast<BinaryOperator>(S))
|
||||||
S = BE->getLHS();
|
S = BE->getLHS();
|
||||||
else if (const DoStmt *DS = dyn_cast<DoStmt>(S))
|
|
||||||
S = DS->getCond();
|
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1038,11 +1036,11 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD,
|
||||||
const CFGBlock &Blk = *BE->getSrc();
|
const CFGBlock &Blk = *BE->getSrc();
|
||||||
const Stmt *Term = Blk.getTerminator();
|
const Stmt *Term = Blk.getTerminator();
|
||||||
|
|
||||||
if (Term && !isa<DoStmt>(Term))
|
if (Term)
|
||||||
EB.addContext(Term);
|
EB.addContext(Term);
|
||||||
|
|
||||||
// Are we jumping to the head of a loop? Add a special diagnostic.
|
// Are we jumping to the head of a loop? Add a special diagnostic.
|
||||||
if (const Stmt *Loop = BE->getDst()->getLoopTarget()) {
|
if (const Stmt *Loop = BE->getSrc()->getLoopTarget()) {
|
||||||
|
|
||||||
PathDiagnosticLocation L(Loop, PDB.getSourceManager());
|
PathDiagnosticLocation L(Loop, PDB.getSourceManager());
|
||||||
PathDiagnosticEventPiece *p =
|
PathDiagnosticEventPiece *p =
|
||||||
|
@ -1086,8 +1084,11 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD,
|
||||||
PDB.getBugReporter(), PDB.getNodeMapClosure());
|
PDB.getBugReporter(), PDB.getNodeMapClosure());
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
EB.addEdge(p->getLocation(), true);
|
const PathDiagnosticLocation &Loc = p->getLocation();
|
||||||
|
EB.addEdge(Loc, true);
|
||||||
PD.push_front(p);
|
PD.push_front(p);
|
||||||
|
if (const Stmt *S = Loc.asStmt())
|
||||||
|
EB.addContext(PDB.getEnclosingStmtLocation(S).asStmt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue