[cfe-commits] r163372 - in /cfe/trunk: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp test/Analysis/diagnostics/deref-track-symbolic-region.cpp test/Analysis/method-call-path-notes.cpp

Ted Kremenek kremenek at apple.com
Thu Sep 6 23:51:38 PDT 2012


Author: kremenek
Date: Fri Sep  7 01:51:37 2012
New Revision: 163372

URL: http://llvm.org/viewvc/llvm-project?rev=163372&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
    cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.cpp
    cfe/trunk/test/Analysis/method-call-path-notes.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=163372&r1=163371&r2=163372&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Sep  7 01:51:37 2012
@@ -696,8 +696,7 @@
   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 @@
   const Expr *Ex = Cond;
   
   while (true) {
-    Ex = Ex->IgnoreParens();
+    Ex = Ex->IgnoreParenCasts();
     switch (Ex->getStmtClass()) {
       default:
         return 0;
@@ -724,7 +723,7 @@
         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;

Modified: cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.cpp?rev=163372&r1=163371&r2=163372&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.cpp Fri Sep  7 01:51:37 2012
@@ -11,6 +11,7 @@
   if (p) return;
                //expected-note at -1{{Taking false branch}}
                //expected-note at -2{{Assuming pointer value is null}}
+               //expected-note at -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 at -1{{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}}
 }

Modified: cfe/trunk/test/Analysis/method-call-path-notes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/method-call-path-notes.cpp?rev=163372&r1=163371&r2=163372&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/method-call-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/method-call-path-notes.cpp Fri Sep  7 01:51:37 2012
@@ -25,7 +25,7 @@
 }
 
 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_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}}
 }
 





More information about the cfe-commits mailing list