r207561 - [analyzer] Don't assert when combining using .* on a temporary.

Jordan Rose jordan_rose at apple.com
Tue Apr 29 10:08:12 PDT 2014


Author: jrose
Date: Tue Apr 29 12:08:12 2014
New Revision: 207561

URL: http://llvm.org/viewvc/llvm-project?rev=207561&view=rev
Log:
[analyzer] Don't assert when combining using .* on a temporary.

While we don't model pointer-to-member operators yet (neither .* nor ->*),
CallAndMessageChecker still checks to make sure the 'this' object is not
null or undefined first. However, it also expects that the object should
always have a valid MemRegion, something that's generally important elsewhere
in the analyzer as well. Ensure this is true ahead of time, just like we do
for member access.

PR19531

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
    cfe/trunk/test/Analysis/member-expr.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=207561&r1=207560&r2=207561&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Tue Apr 29 12:08:12 2014
@@ -81,6 +81,12 @@ void ExprEngine::VisitBinaryOperator(con
         }
       }
 
+      // Although we don't yet model pointers-to-members, we do need to make
+      // sure that the members of temporaries have a valid 'this' pointer for
+      // other checks.
+      if (B->getOpcode() == BO_PtrMemD)
+        state = createTemporaryRegionIfNeeded(state, LCtx, LHS);
+
       // Process non-assignments except commas or short-circuited
       // logical expressions (LAnd and LOr).
       SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());      

Modified: cfe/trunk/test/Analysis/member-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/member-expr.cpp?rev=207561&r1=207560&r2=207561&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/member-expr.cpp (original)
+++ cfe/trunk/test/Analysis/member-expr.cpp Tue Apr 29 12:08:12 2014
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection %s -verify
 
+void clang_analyzer_checkInlined(bool);
 void clang_analyzer_eval(int);
 
 namespace EnumsViaMemberExpr {
@@ -20,4 +21,21 @@ namespace EnumsViaMemberExpr {
   void testEnumPtr(Foo *Baz) {
     clang_analyzer_eval(Baz->Bar == Foo::Bar); // expected-warning{{TRUE}}
   }
-}
\ No newline at end of file
+}
+
+namespace PR19531 {
+  struct A {
+    A() : x(0) {}
+    bool h() const;
+    int x;
+  };
+
+  struct B {
+    void g(bool (A::*mp_f)() const) {
+      // This used to trigger an assertion because the 'this' pointer is a
+      // temporary.
+      (A().*mp_f)();
+    }
+    void f() { g(&A::h); }
+  };
+}





More information about the cfe-commits mailing list