r359530 - [analyzer] SmartPtrModeling: Fix a null dereference.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 29 20:00:58 PDT 2019


Author: dergachev
Date: Mon Apr 29 20:00:57 2019
New Revision: 359530

URL: http://llvm.org/viewvc/llvm-project?rev=359530&view=rev
Log:
[analyzer] SmartPtrModeling: Fix a null dereference.

Don't crash when trying to model a call in which the callee is unknown
in compile time, eg. a pointer-to-member call.

Differential Revision: https://reviews.llvm.org/D61285

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
    cfe/trunk/test/Analysis/smart-ptr.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp?rev=359530&r1=359529&r2=359530&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp Mon Apr 29 20:00:57 2019
@@ -39,7 +39,7 @@ bool SmartPtrModeling::isNullAfterMoveMe
   // TODO: Handle other methods, such as .get() or .release().
   // But once we do, we'd need a visitor to explain null dereferences
   // that are found via such modeling.
-  const auto *CD = dyn_cast<CXXConversionDecl>(Call->getDecl());
+  const auto *CD = dyn_cast_or_null<CXXConversionDecl>(Call->getDecl());
   return CD && CD->getConversionType()->isBooleanType();
 }
 

Modified: cfe/trunk/test/Analysis/smart-ptr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/smart-ptr.cpp?rev=359530&r1=359529&r2=359530&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/smart-ptr.cpp (original)
+++ cfe/trunk/test/Analysis/smart-ptr.cpp Mon Apr 29 20:00:57 2019
@@ -16,3 +16,13 @@ void derefAfterMove(std::unique_ptr<int>
   // TODO: Report a null dereference (instead).
   *P.get() = 1; // expected-warning {{Method called on moved-from object 'P'}}
 }
+
+// Don't crash when attempting to model a call with unknown callee.
+namespace testUnknownCallee {
+struct S {
+  void foo();
+};
+void bar(S *s, void (S::*func)(void)) {
+  (s->*func)(); // no-crash
+}
+} // namespace testUnknownCallee




More information about the cfe-commits mailing list