]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix assertion failure invalidating on const member function calls (PR25392).
authorDevin Coughlin <dcoughlin@apple.com>
Mon, 9 Nov 2015 19:50:29 +0000 (19:50 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Mon, 9 Nov 2015 19:50:29 +0000 (19:50 +0000)
We now return early when the 'this' value cannot be converted to a MemRegion.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252506 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/const-method-call.cpp

index 32c168819bf74d86347414f12df563836081e220..a07427a57e0eed4a09f52a1c39cb135ec686bf73 100644 (file)
@@ -438,7 +438,9 @@ void CXXInstanceCall::getExtraInvalidatedValues(ValueList &Values,
       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);
   }
index 25909f82758044fb2e477e53baa21d29a7e9e391..b8aaeea6c3eba43f626d5e1de30d7f36ab121e71 100644 (file)
@@ -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