29 if (isa<SymbolData>(Sym))
33 if (
const SymIntExpr *SIE = dyn_cast<SymIntExpr>(Sym)) {
41 return assumeSymRel(State, SIE->getLHS(), op, SIE->getRHS());
45 const llvm::APSInt &Zero =
getBasicVals().getValue(0, SIE->getType());
46 return assumeSymRel(State, SIE, (Assumption ? BO_NE : BO_EQ), Zero);
49 if (
const auto *SSE = dyn_cast<SymSymExpr>(Sym)) {
66 SymMgr.
getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
68 const llvm::APSInt &Zero =
getBasicVals().getValue(0, DiffTy);
80 SymMgr.
getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
82 bool WasEqual = SSE->
getOpcode() == BO_EQ;
83 bool IsExpectedEqual = WasEqual == Assumption;
85 const llvm::APSInt &Zero =
getBasicVals().getValue(0, ExprType);
87 if (IsExpectedEqual) {
88 return assumeSymNE(State, CanonicalEquality, Zero, Zero);
91 return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
103 const llvm::APSInt &To,
bool InRange) {
111 llvm::APSInt Adjustment = WraparoundType.
getZeroValue();
113 computeAdjustment(AdjustedSym, Adjustment);
117 llvm::APSInt ConvertedFrom = ComparisonType.
convert(From);
118 llvm::APSInt ConvertedTo = ComparisonType.
convert(To);
123 Adjustment.setIsSigned(
false);
127 ConvertedTo, Adjustment);
129 ConvertedTo, Adjustment);
145 const llvm::APSInt &Zero = BVF.getValue(0,
T);
155 const llvm::APSInt &Int) {
157 "Non-comparison ops should be rewritten as comparisons to zero.");
164 if (Int == 0 && (Op == BO_EQ || Op == BO_NE)) {
167 return assumeSym(State, Sym, (Op == BO_NE ?
true :
false));
181 llvm::APSInt Adjustment = WraparoundType.
getZeroValue();
182 computeAdjustment(Sym, Adjustment);
186 llvm::APSInt ConvertedInt = ComparisonType.
convert(Int);
191 Adjustment.setIsSigned(
false);
195 llvm_unreachable(
"invalid operation not caught by assertion above");
198 return assumeSymEQ(State, Sym, ConvertedInt, Adjustment);
201 return assumeSymNE(State, Sym, ConvertedInt, Adjustment);
204 return assumeSymGT(State, Sym, ConvertedInt, Adjustment);
207 return assumeSymGE(State, Sym, ConvertedInt, Adjustment);
210 return assumeSymLT(State, Sym, ConvertedInt, Adjustment);
213 return assumeSymLE(State, Sym, ConvertedInt, Adjustment);
217void RangedConstraintManager::computeAdjustment(
SymbolRef &Sym,
218 llvm::APSInt &Adjustment) {
220 if (
const SymIntExpr *SE = dyn_cast<SymIntExpr>(Sym)) {
222 if (Op == BO_Add || Op == BO_Sub) {
230 Adjustment = -Adjustment;
236 SValBuilder &SVB = State->getStateManager().getSValBuilder();
243 return SimplifiedSym;
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
bool isComparisonOp() const
static Opcode negateComparisonOp(Opcode Opc)
static Opcode reverseComparisonOp(Opcode Opc)
bool isEqualityOp() const
A (possibly-)qualified type.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
A record of the "type" of an APSInt, used for conversions.
llvm::APSInt getZeroValue() const LLVM_READONLY
Returns an all-zero value for this type.
uint32_t getBitWidth() const
llvm::APSInt convert(const llvm::APSInt &Value) const LLVM_READONLY
Convert and return a new APSInt with the given value, but this type's bit width and signedness.
APSIntType getAPSIntType(QualType T) const
Returns the type of the APSInt used to store values of the given QualType.
Template implementation for all binary symbolic expressions.
Represents a symbolic expression involving a binary operator.
BinaryOperator::Opcode getOpcode() const
static bool isLocType(QualType T)
virtual ProgramStateRef assumeSymNE(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &V, const llvm::APSInt &Adjustment)=0
~RangedConstraintManager() override
virtual ProgramStateRef assumeSymLE(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &V, const llvm::APSInt &Adjustment)=0
virtual ProgramStateRef assumeSymWithinInclusiveRange(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &From, const llvm::APSInt &To, const llvm::APSInt &Adjustment)=0
ProgramStateRef assumeSym(ProgramStateRef State, SymbolRef Sym, bool Assumption) override
Given a symbolic expression that can be reasoned about, assume that it is true/false and generate the...
virtual ProgramStateRef assumeSymRel(ProgramStateRef State, SymbolRef Sym, BinaryOperator::Opcode op, const llvm::APSInt &Int)
Assume a constraint between a symbolic expression and a concrete integer.
ProgramStateRef assumeSymUnsupported(ProgramStateRef State, SymbolRef Sym, bool Assumption) override
Given a symbolic expression that cannot be reasoned about, assume that it is zero/nonzero and add it ...
virtual ProgramStateRef assumeSymOutsideInclusiveRange(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &From, const llvm::APSInt &To, const llvm::APSInt &Adjustment)=0
virtual ProgramStateRef assumeSymGE(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &V, const llvm::APSInt &Adjustment)=0
virtual ProgramStateRef assumeSymGT(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &V, const llvm::APSInt &Adjustment)=0
ProgramStateRef assumeSymInclusiveRange(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &From, const llvm::APSInt &To, bool InRange) override
Given a symbolic expression within the range [From, To], assume that it is true/false and generate th...
virtual ProgramStateRef assumeSymEQ(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &V, const llvm::APSInt &Adjustment)=0
virtual ProgramStateRef assumeSymLT(ProgramStateRef State, SymbolRef Sym, const llvm::APSInt &V, const llvm::APSInt &Adjustment)=0
DefinedSVal makeSymbolVal(SymbolRef Sym)
Make an SVal that represents the given symbol.
virtual SVal simplifySVal(ProgramStateRef State, SVal Val)=0
Simplify symbolic expressions within a given SVal.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
SymbolManager & getSymbolManager() const
BasicValueFactory & getBasicVals() const
virtual QualType getType() const =0
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
ASTContext & getContext()
SVal simplifyToSVal(ProgramStateRef State, SymbolRef Sym)
Try to simplify a given symbolic expression's associated SVal based on the constraints in State.
SymbolRef simplify(ProgramStateRef State, SymbolRef Sym)
Try to simplify a given symbolic expression based on the constraints in State.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T