diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-09-07 06:51:37 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-09-07 06:51:37 +0000 |
commit | 7c15040e9880e31514780efd6460e3e86ffca6ac (patch) | |
tree | 5a4281f2aff5a1e477eb853c79676f68a53ef648 /clang | |
parent | 1cb637cc37c60a4f18a33f80f56489a5a7602330 (diff) | |
download | bcm5719-llvm-7c15040e9880e31514780efd6460e3e86ffca6ac.tar.gz bcm5719-llvm-7c15040e9880e31514780efd6460e3e86ffca6ac.zip |
Fix bug in ConditionBRVisitor where for C++ (and not C) we were not ignoring
implicit pointer-to-boolean conversions in condition expressions. This would
result in inconsistent diagnostic emission between C and C++.
A consequence of this is now ConditionBRVisitor and TrackConstraintBRVisitor may
emit redundant diagnostics, for example:
"Assuming pointer value is null" (TrackConstraintBRVisitor)
"Assuming 'p' is null" (ConditionBRVisitor)
We need to reconcile the two, and perhaps prefer one over the other in some
cases.
llvm-svn: 163372
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 7 | ||||
-rw-r--r-- | clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp | 1 | ||||
-rw-r--r-- | clang/test/Analysis/method-call-path-notes.cpp | 4 |
3 files changed, 6 insertions, 6 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index d5fe1e0a453..6b7fc4add8b 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -696,8 +696,7 @@ ConditionBRVisitor::VisitTerminator(const Stmt *Term, assert(Cond); assert(srcBlk->succ_size() == 2); const bool tookTrue = *(srcBlk->succ_begin()) == dstBlk; - return VisitTrueTest(Cond->IgnoreParenNoopCasts(BRC.getASTContext()), - tookTrue, BRC, R, N); + return VisitTrueTest(Cond, tookTrue, BRC, R, N); } PathDiagnosticPiece * @@ -710,7 +709,7 @@ ConditionBRVisitor::VisitTrueTest(const Expr *Cond, const Expr *Ex = Cond; while (true) { - Ex = Ex->IgnoreParens(); + Ex = Ex->IgnoreParenCasts(); switch (Ex->getStmtClass()) { default: return 0; @@ -724,7 +723,7 @@ ConditionBRVisitor::VisitTrueTest(const Expr *Cond, const UnaryOperator *UO = cast<UnaryOperator>(Ex); if (UO->getOpcode() == UO_LNot) { tookTrue = !tookTrue; - Ex = UO->getSubExpr()->IgnoreParenNoopCasts(BRC.getASTContext()); + Ex = UO->getSubExpr(); continue; } return 0; diff --git a/clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp b/clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp index 87313de13a8..4a5f0cfa3f7 100644 --- a/clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp +++ b/clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp @@ -11,6 +11,7 @@ void test(S *p) { if (p) return; //expected-note@-1{{Taking false branch}} //expected-note@-2{{Assuming pointer value is null}} + //expected-note@-3{{Assuming 'p' is null}} r.y = 5; // expected-warning {{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}} // expected-note@-1{{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}} } diff --git a/clang/test/Analysis/method-call-path-notes.cpp b/clang/test/Analysis/method-call-path-notes.cpp index 17034b9b000..b95ec98ec84 100644 --- a/clang/test/Analysis/method-call-path-notes.cpp +++ b/clang/test/Analysis/method-call-path-notes.cpp @@ -25,7 +25,7 @@ void test_ic_set_to_null() { } void test_ic_null(TestInstanceCall *p) { - if (!p) // expected-note {{Assuming pointer value is null}} expected-note {{Taking true branch}} + if (!p) // expected-note {{Assuming pointer value is null}} expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}} p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}} } @@ -37,7 +37,7 @@ void test_ic_member_ptr() { } void test_cast(const TestInstanceCall *p) { - if (!p) // expected-note {{Assuming pointer value is null}} expected-note {{Taking true branch}} + if (!p) // expected-note {{Assuming pointer value is null}} expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}} const_cast<TestInstanceCall *>(p)->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}} } |