[PATCH] D61285: [analyzer] SmartPtrModeling: Fix a null dereference.
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 20:02:44 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rC359530: [analyzer] SmartPtrModeling: Fix a null dereference. (authored by dergachev, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D61285?vs=197222&id=197251#toc
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61285/new/
https://reviews.llvm.org/D61285
Files:
lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
test/Analysis/smart-ptr.cpp
Index: test/Analysis/smart-ptr.cpp
===================================================================
--- test/Analysis/smart-ptr.cpp
+++ test/Analysis/smart-ptr.cpp
@@ -16,3 +16,13 @@
// 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
Index: lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -39,7 +39,7 @@
// 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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61285.197251.patch
Type: text/x-patch
Size: 1184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190430/11eaf551/attachment.bin>
More information about the cfe-commits
mailing list