r252506 - [analyzer] Fix assertion failure invalidating on const member function calls (PR25392).

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 11:50:29 PST 2015


Author: dcoughlin
Date: Mon Nov  9 13:50:29 2015
New Revision: 252506

URL: http://llvm.org/viewvc/llvm-project?rev=252506&view=rev
Log:
[analyzer] Fix assertion failure invalidating on const member function calls (PR25392).

We now return early when the 'this' value cannot be converted to a MemRegion.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
    cfe/trunk/test/Analysis/const-method-call.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=252506&r1=252505&r2=252506&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Mon Nov  9 13:50:29 2015
@@ -438,7 +438,9 @@ void CXXInstanceCall::getExtraInvalidate
       return;
     // Preserve CXXThis.
     const MemRegion *ThisRegion = ThisVal.getAsRegion();
-    assert(ThisRegion && "ThisValue was not a memory region");
+    if (!ThisRegion)
+      return;
+
     ETraits->setTrait(ThisRegion->getBaseRegion(),
       RegionAndSymbolInvalidationTraits::TK_PreserveContents);
   }

Modified: cfe/trunk/test/Analysis/const-method-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/const-method-call.cpp?rev=252506&r1=252505&r2=252506&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/const-method-call.cpp (original)
+++ cfe/trunk/test/Analysis/const-method-call.cpp Mon Nov  9 13:50:29 2015
@@ -204,6 +204,25 @@ void PR21606()
     s2().f(0);
 }
 
+// --- PR25392 --- //
+
+struct HasConstMemberFunction {
+public:
+  void constMemberFunction() const;
+};
+
+HasConstMemberFunction hasNoReturn() { } // expected-warning {{control reaches end of non-void function}}
+
+void testUnknownWithConstMemberFunction() {
+  hasNoReturn().constMemberFunction();
+}
+
+void testNonRegionLocWithConstMemberFunction() {
+  (*((HasConstMemberFunction *)(&&label))).constMemberFunction();
+
+  label: return;
+}
+
 // FIXME
 // When there is a circular reference to an object and a const method is called
 // the object is not invalidated because TK_PreserveContents has already been




More information about the cfe-commits mailing list