forked from OSchip/llvm-project
[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 llvm-svn: 359530
This commit is contained in:
parent
baa5507438
commit
eb71c0c961
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue