diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-03-30 20:31:04 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-03-30 20:31:04 +0000 |
| commit | 2d107f9d1d0bfb4b54cd5c056d2ee45c052e585e (patch) | |
| tree | 3ca3459fa3d60d196a97e98629d5244ca88c34b7 /clang/lib/Checker | |
| parent | f7c226da000ae5ebbf503380422ec9ce1f70108e (diff) | |
| download | bcm5719-llvm-2d107f9d1d0bfb4b54cd5c056d2ee45c052e585e.tar.gz bcm5719-llvm-2d107f9d1d0bfb4b54cd5c056d2ee45c052e585e.zip | |
RegionStore: specially handle loads from integer global variables declared 'const'.
Fixes a false positive reported in PR 6288.
llvm-svn: 99922
Diffstat (limited to 'clang/lib/Checker')
| -rw-r--r-- | clang/lib/Checker/RegionStore.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Checker/RegionStore.cpp b/clang/lib/Checker/RegionStore.cpp index 26d33f6588b..d590a86a81c 100644 --- a/clang/lib/Checker/RegionStore.cpp +++ b/clang/lib/Checker/RegionStore.cpp @@ -1313,8 +1313,23 @@ SVal RegionStoreManager::RetrieveVar(Store store, const VarRegion *R) { return ValMgr.getRegionValueSymbolVal(R); if (isa<GlobalsSpaceRegion>(MS)) { - if (VD->isFileVarDecl()) + if (VD->isFileVarDecl()) { + // 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 = ValMgr.makeIntVal(IL); + return ValMgr.getSValuator().EvalCast(V, Init->getType(), + IL->getType()); + } + } + return ValMgr.getRegionValueSymbolVal(R); + } if (T->isIntegerType()) return ValMgr.makeIntVal(0, T); |

