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
// 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)) {
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)) {}
+ }
+}
+
+