26 return (
V != 0) ? !Assumption : Assumption;
52 if (
const SymIntExpr *SIE = dyn_cast<SymIntExpr>(Sym)) {
60 return assumeSymRel(State, SIE->getLHS(), op, SIE->getRHS());
68 if (
const auto *SSE = dyn_cast<SymSymExpr>(Sym)) {
85 SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
99 SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
101 bool WasEqual = SSE->getOpcode() == BO_EQ;
102 bool IsExpectedEqual = WasEqual == Assumption;
106 if (IsExpectedEqual) {
122 const llvm::APSInt &To,
bool InRange) {
131 bool IsInRange = llvm::APSInt::compareValues(*CI, From) >= 0 &&
132 llvm::APSInt::compareValues(*CI, To) <= 0;
133 if (IsInRange != InRange)
143 llvm::APSInt Adjustment = WraparoundType.
getZeroValue();
145 computeAdjustment(AdjustedSym, Adjustment);
149 llvm::APSInt ConvertedFrom = ComparisonType.
convert(From);
150 llvm::APSInt ConvertedTo = ComparisonType.
convert(To);
155 Adjustment.setIsSigned(
false);
159 ConvertedTo, Adjustment);
161 ConvertedTo, Adjustment);
183 if (!
T->isIntegralOrEnumerationType())
187 const llvm::APSInt &
Zero = BVF.getValue(0,
T);
197 const llvm::APSInt &Int) {
199 "Non-comparison ops should be rewritten as comparisons to zero.");
206 if (Int == 0 && (Op == BO_EQ || Op == BO_NE)) {
209 return assumeSym(State, Sym, (Op == BO_NE ?
true :
false));
223 llvm::APSInt Adjustment = WraparoundType.
getZeroValue();
224 computeAdjustment(Sym, Adjustment);
228 llvm::APSInt ConvertedInt = ComparisonType.
convert(Int);
233 Adjustment.setIsSigned(
false);
237 llvm_unreachable(
"invalid operation not caught by assertion above");
240 return assumeSymEQ(State, Sym, ConvertedInt, Adjustment);
243 return assumeSymNE(State, Sym, ConvertedInt, Adjustment);
246 return assumeSymGT(State, Sym, ConvertedInt, Adjustment);
249 return assumeSymGE(State, Sym, ConvertedInt, Adjustment);
252 return assumeSymLT(State, Sym, ConvertedInt, Adjustment);
255 return assumeSymLE(State, Sym, ConvertedInt, Adjustment);
259void RangedConstraintManager::computeAdjustment(
SymbolRef &Sym,
260 llvm::APSInt &Adjustment) {
262 if (
const SymIntExpr *SE = dyn_cast<SymIntExpr>(Sym)) {
264 if (Op == BO_Add || Op == BO_Sub) {
272 Adjustment = -Adjustment;
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
static bool isComparisonOp(Opcode Opc)
static Opcode negateComparisonOp(Opcode Opc)
static Opcode reverseComparisonOp(Opcode Opc)
static bool isEqualityOp(Opcode Opc)
BinaryOperatorKind Opcode
A (possibly-)qualified 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.
Represents a symbolic expression involving a binary operator.
static bool isLocType(QualType T)
SValBuilder & getSValBuilder()
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
ProgramStateManager & getStateManager()
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.
const llvm::APSInt * getAsInteger() const
If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in ...
SymbolManager & getSymbolManager() const
BasicValueFactory & getBasicVals() const
virtual QualType getType() const =0
const SymExprT * acquire(Args &&...args)
Create or retrieve a SymExpr of type SymExprT for the given arguments.
ASTContext & getContext()
SVal simplifyToSVal(ProgramStateRef State, SymbolRef Sym)
Try to simplify a given symbolic expression's associated SVal based on the constraints in State.
static bool isConcreteInfeasible(const llvm::APSInt &V, bool Assumption)
Is Assumption (i.e.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
BinarySymExprImpl< const SymExpr *, const SymExpr *, SymExpr::Kind::SymSymExprKind > SymSymExpr
Represents a symbolic expression like 'x' + 'y'.
BinarySymExprImpl< const SymExpr *, APSIntPtr, SymExpr::Kind::SymIntExprKind > SymIntExpr
Represents a symbolic expression like 'x' + 3.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
const FunctionProtoType * T