From: Devin Coughlin Date: Mon, 9 Nov 2015 19:50:29 +0000 (+0000) Subject: [analyzer] Fix assertion failure invalidating on const member function calls (PR25392). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=272f51152df17b16d549f37fca32fe68cb38f401;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252506 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/CallEvent.cpp b/lib/StaticAnalyzer/Core/CallEvent.cpp index 32c168819b..a07427a57e 100644 --- a/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -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); } diff --git a/test/Analysis/const-method-call.cpp b/test/Analysis/const-method-call.cpp index 25909f8275..b8aaeea6c3 100644 --- a/test/Analysis/const-method-call.cpp +++ b/test/Analysis/const-method-call.cpp @@ -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