[analyzer] Only attempt to get the value of locations of known type

Fixes https://bugs.llvm.org/show_bug.cgi?id=36474

In general, getSVal API should be changed so that it does not crash on
some non-obvious conditions.
It should either be updated to require a type, or to return Optional<SVal>.

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

llvm-svn: 326233
This commit is contained in:
George Karpenkov 2018-02-27 19:28:52 +00:00
parent fc0d02cbbf
commit 53c1c10beb
2 changed files with 9 additions and 1 deletions

View File

@ -73,9 +73,9 @@ void NonnullGlobalConstantsChecker::checkLocation(SVal location, bool isLoad,
return;
ProgramStateRef State = C.getState();
SVal V = State->getSVal(location.castAs<Loc>());
if (isGlobalConstString(location)) {
SVal V = State->getSVal(location.castAs<Loc>());
Optional<DefinedOrUnknownSVal> Constr = V.getAs<DefinedOrUnknownSVal>();
if (Constr) {

View File

@ -0,0 +1,8 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core %s
a;
b(void **c) { // no-crash
*c = a;
int *d;
b(&d);
*d;
}