From cc206d72c2e0bd8f40287ca51e7c99ec4b4bb81e Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Tue, 27 Feb 2018 19:28:52 +0000 Subject: [PATCH] [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. Differential Revision: https://reviews.llvm.org/D43801 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326233 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Checkers/NonnullGlobalConstantsChecker.cpp | 2 +- test/Analysis/novoidtypecrash.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/Analysis/novoidtypecrash.c diff --git a/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp b/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp index 0b4ecb41d2..f65e1d022e 100644 --- a/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp @@ -73,9 +73,9 @@ void NonnullGlobalConstantsChecker::checkLocation(SVal location, bool isLoad, return; ProgramStateRef State = C.getState(); - SVal V = State->getSVal(location.castAs()); if (isGlobalConstString(location)) { + SVal V = State->getSVal(location.castAs()); Optional Constr = V.getAs(); if (Constr) { diff --git a/test/Analysis/novoidtypecrash.c b/test/Analysis/novoidtypecrash.c new file mode 100644 index 0000000000..c04cfca29b --- /dev/null +++ b/test/Analysis/novoidtypecrash.c @@ -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; +} -- 2.40.0