From 53c1c10bebf401c2a1e5492725b56ba91cc62477 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 llvm-svn: 326233 --- .../Checkers/NonnullGlobalConstantsChecker.cpp | 2 +- clang/test/Analysis/novoidtypecrash.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/Analysis/novoidtypecrash.c diff --git a/clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp index 0b4ecb41d20f..f65e1d022eda 100644 --- a/clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp +++ b/clang/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/clang/test/Analysis/novoidtypecrash.c b/clang/test/Analysis/novoidtypecrash.c new file mode 100644 index 000000000000..c04cfca29b4f --- /dev/null +++ b/clang/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; +}