aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core/RegionStore.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-02-13 03:11:06 +0000
committerJordan Rose <jordan_rose@apple.com>2013-02-13 03:11:06 +0000
commit38f68ef19cb51d5876e9025b5fceb44b33ec9ed7 (patch)
tree068ddb9e8bdda120632d421a06ddc96d7bdc13cc /lib/StaticAnalyzer/Core/RegionStore.cpp
parent04870edbea6cf88412c8c9c1eba65f7fc1fa12d9 (diff)
[analyzer] Use Clang's evaluation for global constants and default arguments.
Previously, we were handling only simple integer constants for globals and the smattering of implicitly-valued expressions handled by Environment for default arguments. Now, we can use any integer constant expression that Clang can evaluate, in addition to everything we handled before. PR15094 / <rdar://problem/12830437> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175026 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/RegionStore.cpp')
-rw-r--r--lib/StaticAnalyzer/Core/RegionStore.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/StaticAnalyzer/Core/RegionStore.cpp b/lib/StaticAnalyzer/Core/RegionStore.cpp
index 399f9ebae8..9572f64865 100644
--- a/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1524,11 +1524,14 @@ SVal RegionStoreManager::getBindingForVar(RegionBindingsConstRef B,
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());
- }
+ llvm::APSInt Result;
+ if (Init->EvaluateAsInt(Result, Ctx))
+ return svalBuilder.makeIntVal(Result);
+
+ if (Init->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
+ return svalBuilder.makeNull();
+
+ // FIXME: Handle other possible constant expressions.
}
}