GRExprEngine:
- Conjure symbols at '--' and '++' unary operations
- Add utility method SVal::GetConjuredSymbolVal() and constify some arguments
along the way.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67395 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 1f47bc7..80467eb 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -2449,7 +2449,13 @@
BinaryOperator::Opcode Op = U->isIncrementOp() ? BinaryOperator::Add
: BinaryOperator::Sub;
- SVal Result = EvalBinOp(Op, V2, MakeConstantVal(1U, U));
+ SVal Result = EvalBinOp(Op, V2, MakeConstantVal(1U, U));
+
+ // Conjure a new symbol if necessary to recover precision.
+ if (Result.isUnknown() || !getConstraintManager().canReasonAbout(Result))
+ Result = SVal::GetConjuredSymbolVal(SymMgr, Ex,
+ Builder->getCurrentBlockCount());
+
state = BindExpr(state, U, U->isPostfix() ? V2 : Result);
// Perform the store.
diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp
index 3762ae5..12bf795 100644
--- a/lib/Analysis/SVals.cpp
+++ b/lib/Analysis/SVals.cpp
@@ -338,6 +338,23 @@
return UnknownVal();
}
+SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, const Expr* E,
+ unsigned Count) {
+
+ QualType T = E->getType();
+
+ if (Loc::IsLocType(T)) {
+ SymbolRef Sym = SymMgr.getConjuredSymbol(E, Count);
+ return loc::SymbolVal(Sym);
+ }
+ else if (T->isIntegerType() && T->isScalarType()) {
+ SymbolRef Sym = SymMgr.getConjuredSymbol(E, Count);
+ return nonloc::SymbolVal(Sym);
+ }
+
+ return UnknownVal();
+}
+
nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
unsigned Bits) {
return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
diff --git a/lib/Analysis/SymbolManager.cpp b/lib/Analysis/SymbolManager.cpp
index 589178f..4d101f1 100644
--- a/lib/Analysis/SymbolManager.cpp
+++ b/lib/Analysis/SymbolManager.cpp
@@ -52,7 +52,8 @@
return SymbolCounter++;
}
-SymbolRef SymbolManager::getConjuredSymbol(Stmt* E, QualType T, unsigned Count,
+SymbolRef SymbolManager::getConjuredSymbol(const Stmt* E, QualType T,
+ unsigned Count,
const void* SymbolTag) {
llvm::FoldingSetNodeID profile;