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

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 11:28:52 PST 2018


Author: george.karpenkov
Date: Tue Feb 27 11:28:52 2018
New Revision: 326233

URL: http://llvm.org/viewvc/llvm-project?rev=326233&view=rev
Log:
[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

Added:
    cfe/trunk/test/Analysis/novoidtypecrash.c
Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp?rev=326233&r1=326232&r2=326233&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp Tue Feb 27 11:28:52 2018
@@ -73,9 +73,9 @@ void NonnullGlobalConstantsChecker::chec
     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) {

Added: cfe/trunk/test/Analysis/novoidtypecrash.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/novoidtypecrash.c?rev=326233&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/novoidtypecrash.c (added)
+++ cfe/trunk/test/Analysis/novoidtypecrash.c Tue Feb 27 11:28:52 2018
@@ -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;
+}




More information about the cfe-commits mailing list