From 04870edbea6cf88412c8c9c1eba65f7fc1fa12d9 Mon Sep 17 00:00:00 2001
From: Jordan Rose <jordan_rose@apple.com>
Date: Wed, 13 Feb 2013 03:11:01 +0000
Subject: [PATCH] [analyzer] Use makeZeroVal in RegionStore's lazy evaluation
 of statics.

No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175025 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/StaticAnalyzer/Core/RegionStore.cpp | 42 +++++++++++--------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/lib/StaticAnalyzer/Core/RegionStore.cpp b/lib/StaticAnalyzer/Core/RegionStore.cpp
index 61518e61162..399f9ebae89 100644
--- a/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1514,33 +1514,29 @@ SVal RegionStoreManager::getBindingForVar(RegionBindingsConstRef B,
     return svalBuilder.getRegionValueSymbolVal(R);
 
   if (isa<GlobalsSpaceRegion>(MS)) {
-    if (isa<NonStaticGlobalSpaceRegion>(MS)) {
-      // Is 'VD' declared constant?  If so, retrieve the constant value.
-      QualType CT = Ctx.getCanonicalType(T);
-      if (CT.isConstQualified()) {
-        const Expr *Init = VD->getInit();
-        // Do the null check first, as we want to call 'IgnoreParenCasts'.
-        if (Init)
-          if (const IntegerLiteral *IL =
-              dyn_cast<IntegerLiteral>(Init->IgnoreParenCasts())) {
-            const nonloc::ConcreteInt &V = svalBuilder.makeIntVal(IL);
-            return svalBuilder.evalCast(V, Init->getType(), IL->getType());
-          }
+    // Function-scoped static variables are default-initialized to 0; if they
+    // have an initializer, it would have been processed by now.
+    if (isa<StaticGlobalSpaceRegion>(MS))
+      return svalBuilder.makeZeroVal(T);
+
+    // Other globals 
+    // Is 'VD' declared constant?  If so, retrieve the constant value.
+    QualType CT = Ctx.getCanonicalType(T);
+    if (CT.isConstQualified()) {
+      if (const Expr *Init = VD->getInit()) {
+        if (const IntegerLiteral *IL =
+            dyn_cast<IntegerLiteral>(Init->IgnoreParenCasts())) {
+          const nonloc::ConcreteInt &V = svalBuilder.makeIntVal(IL);
+          return svalBuilder.evalCast(V, Init->getType(), IL->getType());
+        }
       }
-
-      if (const Optional<SVal> &V
-            = getBindingForDerivedDefaultValue(B, MS, R, CT))
-        return V.getValue();
-
-      return svalBuilder.getRegionValueSymbolVal(R);
     }
 
-    if (T->isIntegerType())
-      return svalBuilder.makeIntVal(0, T);
-    if (T->isPointerType())
-      return svalBuilder.makeNull();
+    if (const Optional<SVal> &V
+          = getBindingForDerivedDefaultValue(B, MS, R, CT))
+      return V.getValue();
 
-    return UnknownVal();
+    return svalBuilder.getRegionValueSymbolVal(R);
   }
 
   return UndefinedVal();
-- 
GitLab