aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-10-06 03:44:49 +0000
committerTed Kremenek <kremenek@apple.com>2009-10-06 03:44:49 +0000
commitb1d042212fbb3f6a08864b703b7bdf0dca58fd9c (patch)
tree9ea279fe355d0d054dbd7f89ed26ed4fa25a6adf
parentcd8f6ac9b613e1fe962ebf9c87d822ce765275e6 (diff)
Fix crash introduced by r83358 where a symbol could be eagerly
evaluated to an APSInt with a different bitwidth than the other operand in a binary expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83368 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/SimpleSValuator.cpp9
-rw-r--r--test/Analysis/misc-ps.m11
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/Analysis/SimpleSValuator.cpp b/lib/Analysis/SimpleSValuator.cpp
index 2869fabea3..636ce15c33 100644
--- a/lib/Analysis/SimpleSValuator.cpp
+++ b/lib/Analysis/SimpleSValuator.cpp
@@ -349,8 +349,13 @@ SVal SimpleSValuator::EvalBinOpNN(const GRState *state,
// Does the symbol simplify to a constant?
if (Sym->getType(ValMgr.getContext())->isIntegerType())
if (const llvm::APSInt *Constant = state->getSymVal(Sym)) {
- lhs = nonloc::ConcreteInt(*Constant);
- continue;
+ // What should we convert it to?
+ if (nonloc::ConcreteInt *rhs_I = dyn_cast<nonloc::ConcreteInt>(&rhs)){
+ BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
+ lhs = nonloc::ConcreteInt(BVF.Convert(rhs_I->getValue(),
+ *Constant));
+ continue;
+ }
}
if (isa<nonloc::ConcreteInt>(rhs)) {
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index 565dc61f3b..10e5823c20 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -681,3 +681,14 @@ void *rdar7152418_bar();
return 1;
}
+// Test constant-folding of symbolic values, automatically handling type
+// conversions of the symbol as necessary. Previously this would crash
+// once we started eagerly evaluating symbols whose values were constrained
+// to a single value.
+void test_constant_symbol(signed char x) {
+ while (1) {
+ if (x == ((signed char) 0)) {}
+ }
+}
+
+