aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BugReporter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-07 23:35:17 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-07 23:35:17 +0000
commit706e3cf2fa7523b5497c52c11a2b6dad2a1ce2ac (patch)
tree513b882d73f1f43ac5b290c0bb725cb7738a7e11 /lib/Analysis/BugReporter.cpp
parent6e9d38e2b84653d1e61b19df2a7b4430d5898ca7 (diff)
Improve BugReport diagnostics for loops and ? operator.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49356 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BugReporter.cpp')
-rw-r--r--lib/Analysis/BugReporter.cpp61
1 files changed, 57 insertions, 4 deletions
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index 8eb200017f..14f98fa1f4 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -41,6 +41,11 @@ static inline Stmt* GetStmt(const ProgramPoint& P) {
return NULL;
}
+static inline Stmt* GetStmt(const CFGBlock* B) {
+ assert (!B->empty());
+ return (*B)[0];
+}
+
PathDiagnosticPiece*
BugDescription::getEndPath(ASTContext& Ctx, ExplodedNode<ValueState> *N) const {
@@ -142,7 +147,7 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
std::ostringstream os;
os << "Control jumps to line "
- << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
+ << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
PD.push_front(new PathDiagnosticPiece(L, os.str()));
break;
@@ -206,7 +211,7 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
}
os << ":' at line "
- << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
+ << SMgr.getLogicalLineNumber(S->getLocStart()) << ".\n";
break;
@@ -216,11 +221,59 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
PD.push_front(new PathDiagnosticPiece(L, os.str()));
break;
}
+
+ case Stmt::ConditionalOperatorClass: {
+
+ std::ostringstream os;
+ os << "'?' condition evaluates to ";
+
+ if (*(Src->succ_begin()+1) == Dst)
+ os << "false.";
+ else
+ os << "true.";
+
+ PD.push_front(new PathDiagnosticPiece(L, os.str()));
+
+ break;
+ }
+ case Stmt::DoStmtClass: {
+
+ if (*(Src->succ_begin()) == Dst) {
+
+ std::ostringstream os;
+
+ os << "Loop condition is true. Execution continues on line "
+ << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
+
+ PD.push_front(new PathDiagnosticPiece(L, os.str()));
+ }
+ else
+ PD.push_front(new PathDiagnosticPiece(L,
+ "Loop condition is false. Exiting loop."));
+
+ break;
+ }
- case Stmt::DoStmtClass:
case Stmt::WhileStmtClass:
- case Stmt::ForStmtClass:
+ case Stmt::ForStmtClass: {
+
+ if (*(Src->succ_begin()+1) == Dst) {
+
+ std::ostringstream os;
+
+ os << "Loop condition is false. Execution continues on line "
+ << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
+
+ PD.push_front(new PathDiagnosticPiece(L, os.str()));
+ }
+ else
+ PD.push_front(new PathDiagnosticPiece(L,
+ "Loop condition is true. Entering loop body."));
+
+ break;
+ }
+
case Stmt::IfStmtClass: {
if (*(Src->succ_begin()+1) == Dst)