r177186 - [analyzer] Look through ExprWhenCleanups when trying to track a NULL.

Jordan Rose jordan_rose at apple.com
Fri Mar 15 14:41:46 PDT 2013


Author: jrose
Date: Fri Mar 15 16:41:46 2013
New Revision: 177186

URL: http://llvm.org/viewvc/llvm-project?rev=177186&view=rev
Log:
[analyzer] Look through ExprWhenCleanups when trying to track a NULL.

Silences a few false positives in LLVM.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
    cfe/trunk/test/Analysis/inlining/false-positive-suppression.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=177186&r1=177185&r2=177186&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Mar 15 16:41:46 2013
@@ -778,7 +778,8 @@ bool bugreporter::trackNullOrUndefValue(
   if (!S || !N)
     return false;
 
-  // Peel off OpaqueValueExpr.
+  if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(S))
+    S = EWC->getSubExpr();
   if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(S))
     S = OVE->getSourceExpr();
 

Modified: cfe/trunk/test/Analysis/inlining/false-positive-suppression.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/false-positive-suppression.cpp?rev=177186&r1=177185&r2=177186&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/false-positive-suppression.cpp (original)
+++ cfe/trunk/test/Analysis/inlining/false-positive-suppression.cpp Fri Mar 15 16:41:46 2013
@@ -40,6 +40,11 @@ inline void* operator new(__typeof__(siz
 
 extern bool coin();
 
+class SomeClass {
+public:
+  void doSomething();
+};
+
 namespace References {
   class Map {
     int *&getNewBox();
@@ -83,11 +88,6 @@ namespace References {
     *box = 1; // expected-warning {{Dereference of null pointer}}
   }
 
-  class SomeClass {
-  public:
-    void doSomething();
-  };
-
   SomeClass *&getSomeClass() {
     if (coin()) {
       extern SomeClass *&opaqueClass();
@@ -174,3 +174,39 @@ void test3() {
 }
 
 
+namespace Cleanups {
+  class NonTrivial {
+  public:
+    ~NonTrivial();
+
+    SomeClass *getNull() {
+      return 0;
+    }
+  };
+
+  void testImmediate() {
+    NonTrivial().getNull()->doSomething();
+#ifndef SUPPRESSED
+    // expected-warning at -2 {{Called C++ object pointer is null}}
+#endif
+  }
+
+  void testAssignment() {
+    SomeClass *ptr = NonTrivial().getNull();
+    ptr->doSomething();
+#ifndef SUPPRESSED
+    // expected-warning at -2 {{Called C++ object pointer is null}}
+#endif
+  }
+
+  void testArgumentHelper(SomeClass *arg) {
+    arg->doSomething();
+#ifndef SUPPRESSED
+    // expected-warning at -2 {{Called C++ object pointer is null}}
+#endif
+  }
+
+  void testArgument() {
+    testArgumentHelper(NonTrivial().getNull());
+  }
+}





More information about the cfe-commits mailing list