From 30fe9ecac23bc5f9b6ec0af088c0cea94f167687 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 6 Feb 2010 03:57:59 +0000 Subject: [PATCH] Fix regression in RegionStore (from BasicStore) where static variables were not treated as being implicitly initialized to 0 (and instead were getting symbolicated). llvm-svn: 95478 --- clang/lib/Checker/RegionStore.cpp | 18 +++++++++++++++--- clang/test/Analysis/misc-ps.m | 7 +++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/clang/lib/Checker/RegionStore.cpp b/clang/lib/Checker/RegionStore.cpp index 341bfe7a7212..2e212db3e628 100644 --- a/clang/lib/Checker/RegionStore.cpp +++ b/clang/lib/Checker/RegionStore.cpp @@ -1394,11 +1394,23 @@ SVal RegionStoreManager::RetrieveVar(Store store, const VarRegion *R) { // Lazily derive a value for the VarRegion. const VarDecl *VD = R->getDecl(); + QualType T = VD->getType(); + const MemSpaceRegion *MS = R->getMemorySpace(); + + if (isa(MS) || + isa(MS)) + return ValMgr.getRegionValueSymbolVal(R, T); - if (R->hasGlobalsOrParametersStorage() || - isa(R->getMemorySpace())) - return ValMgr.getRegionValueSymbolVal(R, VD->getType()); + if (isa(MS)) { + if (VD->isFileVarDecl()) + return ValMgr.getRegionValueSymbolVal(R, T); + if (T->isIntegerType()) + return ValMgr.makeIntVal(0, T); + + return UnknownVal(); + } + return UndefinedVal(); } diff --git a/clang/test/Analysis/misc-ps.m b/clang/test/Analysis/misc-ps.m index 88cc12892989..c1b3d9788b22 100644 --- a/clang/test/Analysis/misc-ps.m +++ b/clang/test/Analysis/misc-ps.m @@ -901,3 +901,10 @@ int bar_rev95274() { return 0; } +void rdar7582031_test_static_init_zero() { + static unsigned x; + if (x == 0) + return; + int *p = 0; + *p = 0xDEADBEEF; +}