summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2019-04-30 03:00:57 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2019-04-30 03:00:57 +0000
commit4ecb1e1c614b63724545e32904ca321e148e629c (patch)
tree0b051378a11e2451b75c9dfeb3bba652cc9effda
parent753d85a17fa0430aa27e38fa6ac5d5dd0240c351 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359530 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp2
-rw-r--r--test/Analysis/smart-ptr.cpp10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp b/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
index 451a6c8a90..4b321f0f6a 100644
--- a/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ b/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -39,7 +39,7 @@ bool SmartPtrModeling::isNullAfterMoveMethod(
// 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();
}
diff --git a/test/Analysis/smart-ptr.cpp b/test/Analysis/smart-ptr.cpp
index 3f1782480b..ae6966b4e6 100644
--- a/test/Analysis/smart-ptr.cpp
+++ b/test/Analysis/smart-ptr.cpp
@@ -16,3 +16,13 @@ void derefAfterMove(std::unique_ptr<int> P) {
// 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