Skip to content
This repository was archived by the owner on Oct 24, 2019. It is now read-only.

Commit a44ea13

Browse files
committed
[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 (cherry picked from commit 4ecb1e1)
1 parent 61879a5 commit a44ea13

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool SmartPtrModeling::isNullAfterMoveMethod(
3939
// TODO: Handle other methods, such as .get() or .release().
4040
// But once we do, we'd need a visitor to explain null dereferences
4141
// that are found via such modeling.
42-
const auto *CD = dyn_cast<CXXConversionDecl>(Call->getDecl());
42+
const auto *CD = dyn_cast_or_null<CXXConversionDecl>(Call->getDecl());
4343
return CD && CD->getConversionType()->isBooleanType();
4444
}
4545

test/Analysis/smart-ptr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ void derefAfterMove(std::unique_ptr<int> P) {
1616
// TODO: Report a null dereference (instead).
1717
*P.get() = 1; // expected-warning {{Method called on moved-from object 'P'}}
1818
}
19+
20+
// Don't crash when attempting to model a call with unknown callee.
21+
namespace testUnknownCallee {
22+
struct S {
23+
void foo();
24+
};
25+
void bar(S *s, void (S::*func)(void)) {
26+
(s->*func)(); // no-crash
27+
}
28+
} // namespace testUnknownCallee

0 commit comments

Comments
 (0)