]> granicus.if.org Git - clang/commitdiff
[analyzer] Only attempt to get the value of locations of known type
authorGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 27 Feb 2018 19:28:52 +0000 (19:28 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 27 Feb 2018 19:28:52 +0000 (19:28 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326233 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
test/Analysis/novoidtypecrash.c [new file with mode: 0644]

index 0b4ecb41d20f3816e0051a08e2713da7360d9aa0..f65e1d022edabb890aa079b33911177c6fa70909 100644 (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) {
diff --git a/test/Analysis/novoidtypecrash.c b/test/Analysis/novoidtypecrash.c
new file mode 100644 (file)
index 0000000..c04cfca
--- /dev/null
@@ -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;
+}