/// handle the given binary expression. Depending on the state, decides to
/// either keep the expression or forget the history and generate an
/// UnknownVal.
- SVal generateUnknownVal(const ProgramState *state, BinaryOperator::Opcode op,
+ SVal makeGenericVal(const ProgramState *state, BinaryOperator::Opcode op,
NonLoc lhs, NonLoc rhs, QualType resultTy);
SVal evalBinOp(const ProgramState *state, BinaryOperator::Opcode op,
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const llvm::APSInt& rhs, QualType type);
+ NonLoc makeNonLoc(const llvm::APSInt& rhs, BinaryOperator::Opcode op,
+ const SymExpr *lhs, QualType type);
+
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const SymExpr *rhs, QualType type);
MetadataKind,
BEGIN_SYMBOLS = RegionValueKind,
END_SYMBOLS = MetadataKind,
- SymIntKind, SymSymKind, CastSymbolKind };
+ SymIntKind, IntSymKind, SymSymKind, CastSymbolKind };
private:
Kind K;
}
};
+/// IntSymExpr - Represents symbolic expression like 3 - 'x'.
+class IntSymExpr : public SymExpr {
+ const llvm::APSInt& LHS;
+ BinaryOperator::Opcode Op;
+ const SymExpr *RHS;
+ QualType T;
+
+public:
+ IntSymExpr(const llvm::APSInt& lhs, BinaryOperator::Opcode op,
+ const SymExpr *rhs, QualType t)
+ : SymExpr(IntSymKind), LHS(lhs), Op(op), RHS(rhs), T(t) {}
+
+ QualType getType(ASTContext &C) const { return T; }
+
+ BinaryOperator::Opcode getOpcode() const { return Op; }
+
+ void dumpToStream(raw_ostream &os) const;
+
+ const SymExpr *getRHS() const { return RHS; }
+ const llvm::APSInt &getLHS() const { return LHS; }
+
+ static void Profile(llvm::FoldingSetNodeID& ID, const llvm::APSInt& lhs,
+ BinaryOperator::Opcode op, const SymExpr *rhs,
+ QualType t) {
+ ID.AddInteger((unsigned) IntSymKind);
+ ID.AddPointer(&lhs);
+ ID.AddInteger(op);
+ ID.AddPointer(rhs);
+ ID.Add(t);
+ }
+
+ void Profile(llvm::FoldingSetNodeID& ID) {
+ Profile(ID, LHS, Op, RHS, T);
+ }
+
+ // Implement isa<T> support.
+ static inline bool classof(const SymExpr *SE) {
+ return SE->getKind() == IntSymKind;
+ }
+};
+
/// SymSymExpr - Represents symbolic expression like 'x' + 'y'.
class SymSymExpr : public SymExpr {
const SymExpr *LHS;
return getSymIntExpr(&lhs, op, rhs, t);
}
+ const IntSymExpr *getIntSymExpr(const llvm::APSInt& lhs,
+ BinaryOperator::Opcode op,
+ const SymExpr *rhs, QualType t);
+
const SymSymExpr *getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op,
const SymExpr *rhs, QualType t);
//===----------------------------------------------------------------------===//
-SVal SValBuilder::generateUnknownVal(const ProgramState *State,
+SVal SValBuilder::makeGenericVal(const ProgramState *State,
BinaryOperator::Opcode Op,
NonLoc LHS, NonLoc RHS,
QualType ResultTy) {
while (1) {
switch (lhs.getSubKind()) {
default:
- return generateUnknownVal(state, op, lhs, rhs, resultTy);
+ return makeGenericVal(state, op, lhs, rhs, resultTy);
case nonloc::LocAsIntegerKind: {
Loc lhsL = cast<nonloc::LocAsInteger>(lhs).getLoc();
switch (rhs.getSubKind()) {
return makeTruthVal(true, resultTy);
default:
// This case also handles pointer arithmetic.
- return generateUnknownVal(state, op, lhs, rhs, resultTy);
+ return makeGenericVal(state, op, lhs, rhs, resultTy);
}
}
}
if (lhsValue == 0)
// At this point lhs and rhs have been swapped.
return rhs;
- return generateUnknownVal(state, op, rhs, lhs, resultTy);
+ return makeGenericVal(state, op, rhs, lhs, resultTy);
default:
- return generateUnknownVal(state, op, rhs, lhs, resultTy);
+ return makeGenericVal(state, op, rhs, lhs, resultTy);
}
}
}
dyn_cast<SymIntExpr>(selhs->getSymbol());
if (!symIntExpr)
- return generateUnknownVal(state, op, lhs, rhs, resultTy);
+ return makeGenericVal(state, op, lhs, rhs, resultTy);
// Is this a logical not? (!x is represented as x == 0.)
if (op == BO_EQ && rhs.isZeroConstant()) {
// For now, only handle expressions whose RHS is a constant.
const nonloc::ConcreteInt *rhsInt = dyn_cast<nonloc::ConcreteInt>(&rhs);
if (!rhsInt)
- return generateUnknownVal(state, op, lhs, rhs, resultTy);
+ return makeGenericVal(state, op, lhs, rhs, resultTy);
// If both the LHS and the current expression are additive,
// fold their constants.
resultTy);
}
- return generateUnknownVal(state, op, lhs, rhs, resultTy);
+ return makeGenericVal(state, op, lhs, rhs, resultTy);
}
}
}