summaryrefslogtreecommitdiffstats
path: root/clang/lib/Checker
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-30 20:31:04 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-30 20:31:04 +0000
commit2d107f9d1d0bfb4b54cd5c056d2ee45c052e585e (patch)
tree3ca3459fa3d60d196a97e98629d5244ca88c34b7 /clang/lib/Checker
parentf7c226da000ae5ebbf503380422ec9ce1f70108e (diff)
downloadbcm5719-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.cpp17
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);
OpenPOWER on IntegriCloud