forked from OSchip/llvm-project
Improves the coding style in SValBuilder. This patch:
- renames evalCastNL and evalCastL to evalCastFromNonLoc and evalCastFromLoc (avoid abbreviations that aren't well known). - makes all function parameter names start with a lower case letter for consistency and distinction from member variables. - avoids abbreviations in function parameter names. Reviewed by kremenek@apple.com. llvm-svn: 126722
This commit is contained in:
parent
ff42ec5895
commit
5ad574c096
|
@ -49,10 +49,10 @@ protected:
|
|||
const unsigned ArrayIndexWidth;
|
||||
|
||||
public:
|
||||
// FIXME: Make these protected again one RegionStoreManager correctly
|
||||
// handles loads from differening bound value types.
|
||||
virtual SVal evalCastNL(NonLoc val, QualType castTy) = 0;
|
||||
virtual SVal evalCastL(Loc val, QualType castTy) = 0;
|
||||
// FIXME: Make these protected again once RegionStoreManager correctly
|
||||
// handles loads from different bound value types.
|
||||
virtual SVal evalCastFromNonLoc(NonLoc val, QualType castTy) = 0;
|
||||
virtual SVal evalCastFromLoc(Loc val, QualType castTy) = 0;
|
||||
|
||||
public:
|
||||
SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
|
||||
|
@ -66,30 +66,30 @@ public:
|
|||
|
||||
virtual ~SValBuilder() {}
|
||||
|
||||
SVal evalCast(SVal V, QualType castTy, QualType originalType);
|
||||
SVal evalCast(SVal val, QualType castTy, QualType originalType);
|
||||
|
||||
virtual SVal evalMinus(NonLoc val) = 0;
|
||||
|
||||
virtual SVal evalComplement(NonLoc val) = 0;
|
||||
|
||||
virtual SVal evalBinOpNN(const GRState *state, BinaryOperator::Opcode Op,
|
||||
virtual SVal evalBinOpNN(const GRState *state, BinaryOperator::Opcode op,
|
||||
NonLoc lhs, NonLoc rhs, QualType resultTy) = 0;
|
||||
|
||||
virtual SVal evalBinOpLL(const GRState *state, BinaryOperator::Opcode Op,
|
||||
virtual SVal evalBinOpLL(const GRState *state, BinaryOperator::Opcode op,
|
||||
Loc lhs, Loc rhs, QualType resultTy) = 0;
|
||||
|
||||
virtual SVal evalBinOpLN(const GRState *state, BinaryOperator::Opcode Op,
|
||||
virtual SVal evalBinOpLN(const GRState *state, BinaryOperator::Opcode op,
|
||||
Loc lhs, NonLoc rhs, QualType resultTy) = 0;
|
||||
|
||||
/// getKnownValue - evaluates a given SVal. If the SVal has only one possible
|
||||
/// (integer) value, that value is returned. Otherwise, returns NULL.
|
||||
virtual const llvm::APSInt *getKnownValue(const GRState *state, SVal V) = 0;
|
||||
virtual const llvm::APSInt *getKnownValue(const GRState *state, SVal val) = 0;
|
||||
|
||||
SVal evalBinOp(const GRState *ST, BinaryOperator::Opcode Op,
|
||||
SVal L, SVal R, QualType T);
|
||||
SVal evalBinOp(const GRState *state, BinaryOperator::Opcode op,
|
||||
SVal lhs, SVal rhs, QualType type);
|
||||
|
||||
DefinedOrUnknownSVal evalEQ(const GRState *ST, DefinedOrUnknownSVal L,
|
||||
DefinedOrUnknownSVal R);
|
||||
DefinedOrUnknownSVal evalEQ(const GRState *state, DefinedOrUnknownSVal lhs,
|
||||
DefinedOrUnknownSVal rhs);
|
||||
|
||||
ASTContext &getContext() { return Context; }
|
||||
const ASTContext &getContext() const { return Context; }
|
||||
|
@ -115,46 +115,48 @@ public:
|
|||
|
||||
// Forwarding methods to SymbolManager.
|
||||
|
||||
const SymbolConjured* getConjuredSymbol(const Stmt* E, QualType T,
|
||||
unsigned VisitCount,
|
||||
const void* SymbolTag = 0) {
|
||||
return SymMgr.getConjuredSymbol(E, T, VisitCount, SymbolTag);
|
||||
const SymbolConjured* getConjuredSymbol(const Stmt* stmt, QualType type,
|
||||
unsigned visitCount,
|
||||
const void* symbolTag = 0) {
|
||||
return SymMgr.getConjuredSymbol(stmt, type, visitCount, symbolTag);
|
||||
}
|
||||
|
||||
const SymbolConjured* getConjuredSymbol(const Expr* E, unsigned VisitCount,
|
||||
const void* SymbolTag = 0) {
|
||||
return SymMgr.getConjuredSymbol(E, VisitCount, SymbolTag);
|
||||
const SymbolConjured* getConjuredSymbol(const Expr* expr, unsigned visitCount,
|
||||
const void* symbolTag = 0) {
|
||||
return SymMgr.getConjuredSymbol(expr, visitCount, symbolTag);
|
||||
}
|
||||
|
||||
/// makeZeroVal - Construct an SVal representing '0' for the specified type.
|
||||
DefinedOrUnknownSVal makeZeroVal(QualType T);
|
||||
DefinedOrUnknownSVal makeZeroVal(QualType type);
|
||||
|
||||
/// getRegionValueSymbolVal - make a unique symbol for value of R.
|
||||
DefinedOrUnknownSVal getRegionValueSymbolVal(const TypedRegion *R);
|
||||
/// getRegionValueSymbolVal - make a unique symbol for value of region.
|
||||
DefinedOrUnknownSVal getRegionValueSymbolVal(const TypedRegion *region);
|
||||
|
||||
DefinedOrUnknownSVal getConjuredSymbolVal(const void *SymbolTag,
|
||||
const Expr *E, unsigned Count);
|
||||
DefinedOrUnknownSVal getConjuredSymbolVal(const void *SymbolTag,
|
||||
const Expr *E, QualType T,
|
||||
unsigned Count);
|
||||
DefinedOrUnknownSVal getConjuredSymbolVal(const void *symbolTag,
|
||||
const Expr *expr, unsigned count);
|
||||
DefinedOrUnknownSVal getConjuredSymbolVal(const void *symbolTag,
|
||||
const Expr *expr, QualType type,
|
||||
unsigned count);
|
||||
|
||||
DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
|
||||
const TypedRegion *R);
|
||||
DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(
|
||||
SymbolRef parentSymbol, const TypedRegion *region);
|
||||
|
||||
DefinedSVal getMetadataSymbolVal(const void *SymbolTag, const MemRegion *MR,
|
||||
const Expr *E, QualType T, unsigned Count);
|
||||
DefinedSVal getMetadataSymbolVal(
|
||||
const void *symbolTag, const MemRegion *region,
|
||||
const Expr *expr, QualType type, unsigned count);
|
||||
|
||||
DefinedSVal getFunctionPointer(const FunctionDecl *FD);
|
||||
DefinedSVal getFunctionPointer(const FunctionDecl *func);
|
||||
|
||||
DefinedSVal getBlockPointer(const BlockDecl *BD, CanQualType locTy,
|
||||
const LocationContext *LC);
|
||||
DefinedSVal getBlockPointer(const BlockDecl *block, CanQualType locTy,
|
||||
const LocationContext *locContext);
|
||||
|
||||
NonLoc makeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals) {
|
||||
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
|
||||
NonLoc makeCompoundVal(QualType type, llvm::ImmutableList<SVal> vals) {
|
||||
return nonloc::CompoundVal(BasicVals.getCompoundValData(type, vals));
|
||||
}
|
||||
|
||||
NonLoc makeLazyCompoundVal(const void *store, const TypedRegion *R) {
|
||||
return nonloc::LazyCompoundVal(BasicVals.getLazyCompoundValData(store, R));
|
||||
NonLoc makeLazyCompoundVal(const void *store, const TypedRegion *region) {
|
||||
return nonloc::LazyCompoundVal(
|
||||
BasicVals.getLazyCompoundValData(store, region));
|
||||
}
|
||||
|
||||
NonLoc makeZeroArrayIndex() {
|
||||
|
@ -165,60 +167,63 @@ public:
|
|||
return nonloc::ConcreteInt(BasicVals.getValue(idx, ArrayIndexTy));
|
||||
}
|
||||
|
||||
SVal convertToArrayIndex(SVal V);
|
||||
SVal convertToArrayIndex(SVal val);
|
||||
|
||||
nonloc::ConcreteInt makeIntVal(const IntegerLiteral* I) {
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(I->getValue(),
|
||||
I->getType()->isUnsignedIntegerType()));
|
||||
nonloc::ConcreteInt makeIntVal(const IntegerLiteral* integer) {
|
||||
return nonloc::ConcreteInt(
|
||||
BasicVals.getValue(integer->getValue(),
|
||||
integer->getType()->isUnsignedIntegerType()));
|
||||
}
|
||||
|
||||
nonloc::ConcreteInt makeBoolVal(const CXXBoolLiteralExpr *E) {
|
||||
return makeTruthVal(E->getValue());
|
||||
nonloc::ConcreteInt makeBoolVal(const CXXBoolLiteralExpr *boolean) {
|
||||
return makeTruthVal(boolean->getValue());
|
||||
}
|
||||
|
||||
nonloc::ConcreteInt makeIntVal(const llvm::APSInt& V) {
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(V));
|
||||
nonloc::ConcreteInt makeIntVal(const llvm::APSInt& integer) {
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(integer));
|
||||
}
|
||||
|
||||
loc::ConcreteInt makeIntLocVal(const llvm::APSInt &v) {
|
||||
return loc::ConcreteInt(BasicVals.getValue(v));
|
||||
loc::ConcreteInt makeIntLocVal(const llvm::APSInt &integer) {
|
||||
return loc::ConcreteInt(BasicVals.getValue(integer));
|
||||
}
|
||||
|
||||
NonLoc makeIntVal(const llvm::APInt& V, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(V, isUnsigned));
|
||||
NonLoc makeIntVal(const llvm::APInt& integer, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(integer, isUnsigned));
|
||||
}
|
||||
|
||||
DefinedSVal makeIntVal(uint64_t X, QualType T) {
|
||||
if (Loc::isLocType(T))
|
||||
return loc::ConcreteInt(BasicVals.getValue(X, T));
|
||||
DefinedSVal makeIntVal(uint64_t integer, QualType type) {
|
||||
if (Loc::isLocType(type))
|
||||
return loc::ConcreteInt(BasicVals.getValue(integer, type));
|
||||
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(X, T));
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(integer, type));
|
||||
}
|
||||
|
||||
NonLoc makeIntVal(uint64_t X, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
|
||||
NonLoc makeIntVal(uint64_t integer, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(BasicVals.getIntValue(integer, isUnsigned));
|
||||
}
|
||||
|
||||
NonLoc makeIntValWithPtrWidth(uint64_t X, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(BasicVals.getIntWithPtrWidth(X, isUnsigned));
|
||||
NonLoc makeIntValWithPtrWidth(uint64_t integer, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(
|
||||
BasicVals.getIntWithPtrWidth(integer, isUnsigned));
|
||||
}
|
||||
|
||||
NonLoc makeIntVal(uint64_t X, unsigned BitWidth, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
|
||||
NonLoc makeIntVal(uint64_t integer, unsigned bitWidth, bool isUnsigned) {
|
||||
return nonloc::ConcreteInt(
|
||||
BasicVals.getValue(integer, bitWidth, isUnsigned));
|
||||
}
|
||||
|
||||
NonLoc makeLocAsInteger(Loc V, unsigned Bits) {
|
||||
return nonloc::LocAsInteger(BasicVals.getPersistentSValWithData(V, Bits));
|
||||
NonLoc makeLocAsInteger(Loc loc, unsigned bits) {
|
||||
return nonloc::LocAsInteger(BasicVals.getPersistentSValWithData(loc, bits));
|
||||
}
|
||||
|
||||
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
|
||||
const llvm::APSInt& rhs, QualType T);
|
||||
const llvm::APSInt& rhs, QualType type);
|
||||
|
||||
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
|
||||
const SymExpr *rhs, QualType T);
|
||||
const SymExpr *rhs, QualType type);
|
||||
|
||||
nonloc::ConcreteInt makeTruthVal(bool b, QualType T) {
|
||||
return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T));
|
||||
nonloc::ConcreteInt makeTruthVal(bool b, QualType type) {
|
||||
return nonloc::ConcreteInt(BasicVals.getTruthValue(b, type));
|
||||
}
|
||||
|
||||
nonloc::ConcreteInt makeTruthVal(bool b) {
|
||||
|
@ -229,20 +234,20 @@ public:
|
|||
return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
|
||||
}
|
||||
|
||||
Loc makeLoc(SymbolRef Sym) {
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(Sym));
|
||||
Loc makeLoc(SymbolRef sym) {
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
|
||||
}
|
||||
|
||||
Loc makeLoc(const MemRegion* R) {
|
||||
return loc::MemRegionVal(R);
|
||||
Loc makeLoc(const MemRegion* region) {
|
||||
return loc::MemRegionVal(region);
|
||||
}
|
||||
|
||||
Loc makeLoc(const AddrLabelExpr *E) {
|
||||
return loc::GotoLabel(E->getLabel());
|
||||
Loc makeLoc(const AddrLabelExpr *expr) {
|
||||
return loc::GotoLabel(expr->getLabel());
|
||||
}
|
||||
|
||||
Loc makeLoc(const llvm::APSInt& V) {
|
||||
return loc::ConcreteInt(BasicVals.getValue(V));
|
||||
Loc makeLoc(const llvm::APSInt& integer) {
|
||||
return loc::ConcreteInt(BasicVals.getValue(integer));
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -25,12 +25,12 @@ using namespace ento;
|
|||
// Basic SVal creation.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType T) {
|
||||
if (Loc::isLocType(T))
|
||||
DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) {
|
||||
if (Loc::isLocType(type))
|
||||
return makeNull();
|
||||
|
||||
if (T->isIntegerType())
|
||||
return makeIntVal(0, T);
|
||||
if (type->isIntegerType())
|
||||
return makeIntVal(0, type);
|
||||
|
||||
// FIXME: Handle floats.
|
||||
// FIXME: Handle structs.
|
||||
|
@ -39,44 +39,44 @@ DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType T) {
|
|||
|
||||
|
||||
NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
|
||||
const llvm::APSInt& v, QualType T) {
|
||||
const llvm::APSInt& rhs, QualType type) {
|
||||
// The Environment ensures we always get a persistent APSInt in
|
||||
// BasicValueFactory, so we don't need to get the APSInt from
|
||||
// BasicValueFactory again.
|
||||
assert(!Loc::isLocType(T));
|
||||
return nonloc::SymExprVal(SymMgr.getSymIntExpr(lhs, op, v, T));
|
||||
assert(!Loc::isLocType(type));
|
||||
return nonloc::SymExprVal(SymMgr.getSymIntExpr(lhs, op, rhs, type));
|
||||
}
|
||||
|
||||
NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
|
||||
const SymExpr *rhs, QualType T) {
|
||||
const SymExpr *rhs, QualType type) {
|
||||
assert(SymMgr.getType(lhs) == SymMgr.getType(rhs));
|
||||
assert(!Loc::isLocType(T));
|
||||
return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, T));
|
||||
assert(!Loc::isLocType(type));
|
||||
return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, type));
|
||||
}
|
||||
|
||||
|
||||
SVal SValBuilder::convertToArrayIndex(SVal V) {
|
||||
if (V.isUnknownOrUndef())
|
||||
return V;
|
||||
SVal SValBuilder::convertToArrayIndex(SVal val) {
|
||||
if (val.isUnknownOrUndef())
|
||||
return val;
|
||||
|
||||
// Common case: we have an appropriately sized integer.
|
||||
if (nonloc::ConcreteInt* CI = dyn_cast<nonloc::ConcreteInt>(&V)) {
|
||||
if (nonloc::ConcreteInt* CI = dyn_cast<nonloc::ConcreteInt>(&val)) {
|
||||
const llvm::APSInt& I = CI->getValue();
|
||||
if (I.getBitWidth() == ArrayIndexWidth && I.isSigned())
|
||||
return V;
|
||||
return val;
|
||||
}
|
||||
|
||||
return evalCastNL(cast<NonLoc>(V), ArrayIndexTy);
|
||||
return evalCastFromNonLoc(cast<NonLoc>(val), ArrayIndexTy);
|
||||
}
|
||||
|
||||
DefinedOrUnknownSVal
|
||||
SValBuilder::getRegionValueSymbolVal(const TypedRegion* R) {
|
||||
QualType T = R->getValueType();
|
||||
SValBuilder::getRegionValueSymbolVal(const TypedRegion* region) {
|
||||
QualType T = region->getValueType();
|
||||
|
||||
if (!SymbolManager::canSymbolicate(T))
|
||||
return UnknownVal();
|
||||
|
||||
SymbolRef sym = SymMgr.getRegionValueSymbol(R);
|
||||
SymbolRef sym = SymMgr.getRegionValueSymbol(region);
|
||||
|
||||
if (Loc::isLocType(T))
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
|
||||
|
@ -84,15 +84,15 @@ SValBuilder::getRegionValueSymbolVal(const TypedRegion* R) {
|
|||
return nonloc::SymbolVal(sym);
|
||||
}
|
||||
|
||||
DefinedOrUnknownSVal SValBuilder::getConjuredSymbolVal(const void *SymbolTag,
|
||||
const Expr *E,
|
||||
unsigned Count) {
|
||||
QualType T = E->getType();
|
||||
DefinedOrUnknownSVal SValBuilder::getConjuredSymbolVal(const void *symbolTag,
|
||||
const Expr *expr,
|
||||
unsigned count) {
|
||||
QualType T = expr->getType();
|
||||
|
||||
if (!SymbolManager::canSymbolicate(T))
|
||||
return UnknownVal();
|
||||
|
||||
SymbolRef sym = SymMgr.getConjuredSymbol(E, Count, SymbolTag);
|
||||
SymbolRef sym = SymMgr.getConjuredSymbol(expr, count, symbolTag);
|
||||
|
||||
if (Loc::isLocType(T))
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
|
||||
|
@ -100,31 +100,32 @@ DefinedOrUnknownSVal SValBuilder::getConjuredSymbolVal(const void *SymbolTag,
|
|||
return nonloc::SymbolVal(sym);
|
||||
}
|
||||
|
||||
DefinedOrUnknownSVal SValBuilder::getConjuredSymbolVal(const void *SymbolTag,
|
||||
const Expr *E,
|
||||
QualType T,
|
||||
unsigned Count) {
|
||||
DefinedOrUnknownSVal SValBuilder::getConjuredSymbolVal(const void *symbolTag,
|
||||
const Expr *expr,
|
||||
QualType type,
|
||||
unsigned count) {
|
||||
|
||||
if (!SymbolManager::canSymbolicate(T))
|
||||
if (!SymbolManager::canSymbolicate(type))
|
||||
return UnknownVal();
|
||||
|
||||
SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count, SymbolTag);
|
||||
SymbolRef sym = SymMgr.getConjuredSymbol(expr, type, count, symbolTag);
|
||||
|
||||
if (Loc::isLocType(T))
|
||||
if (Loc::isLocType(type))
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
|
||||
|
||||
return nonloc::SymbolVal(sym);
|
||||
}
|
||||
|
||||
DefinedSVal SValBuilder::getMetadataSymbolVal(const void *SymbolTag,
|
||||
const MemRegion *MR,
|
||||
const Expr *E, QualType T,
|
||||
unsigned Count) {
|
||||
assert(SymbolManager::canSymbolicate(T) && "Invalid metadata symbol type");
|
||||
DefinedSVal SValBuilder::getMetadataSymbolVal(const void *symbolTag,
|
||||
const MemRegion *region,
|
||||
const Expr *expr, QualType type,
|
||||
unsigned count) {
|
||||
assert(SymbolManager::canSymbolicate(type) && "Invalid metadata symbol type");
|
||||
|
||||
SymbolRef sym = SymMgr.getMetadataSymbol(MR, E, T, Count, SymbolTag);
|
||||
SymbolRef sym =
|
||||
SymMgr.getMetadataSymbol(region, expr, type, count, symbolTag);
|
||||
|
||||
if (Loc::isLocType(T))
|
||||
if (Loc::isLocType(type))
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
|
||||
|
||||
return nonloc::SymbolVal(sym);
|
||||
|
@ -132,13 +133,13 @@ DefinedSVal SValBuilder::getMetadataSymbolVal(const void *SymbolTag,
|
|||
|
||||
DefinedOrUnknownSVal
|
||||
SValBuilder::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
|
||||
const TypedRegion *R) {
|
||||
QualType T = R->getValueType();
|
||||
const TypedRegion *region) {
|
||||
QualType T = region->getValueType();
|
||||
|
||||
if (!SymbolManager::canSymbolicate(T))
|
||||
return UnknownVal();
|
||||
|
||||
SymbolRef sym = SymMgr.getDerivedSymbol(parentSymbol, R);
|
||||
SymbolRef sym = SymMgr.getDerivedSymbol(parentSymbol, region);
|
||||
|
||||
if (Loc::isLocType(T))
|
||||
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
|
||||
|
@ -146,53 +147,53 @@ SValBuilder::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
|
|||
return nonloc::SymbolVal(sym);
|
||||
}
|
||||
|
||||
DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl* FD) {
|
||||
return loc::MemRegionVal(MemMgr.getFunctionTextRegion(FD));
|
||||
DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl* func) {
|
||||
return loc::MemRegionVal(MemMgr.getFunctionTextRegion(func));
|
||||
}
|
||||
|
||||
DefinedSVal SValBuilder::getBlockPointer(const BlockDecl *D,
|
||||
CanQualType locTy,
|
||||
const LocationContext *LC) {
|
||||
DefinedSVal SValBuilder::getBlockPointer(const BlockDecl *block,
|
||||
CanQualType locTy,
|
||||
const LocationContext *locContext) {
|
||||
const BlockTextRegion *BC =
|
||||
MemMgr.getBlockTextRegion(D, locTy, LC->getAnalysisContext());
|
||||
const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, LC);
|
||||
MemMgr.getBlockTextRegion(block, locTy, locContext->getAnalysisContext());
|
||||
const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, locContext);
|
||||
return loc::MemRegionVal(BD);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
SVal SValBuilder::evalBinOp(const GRState *ST, BinaryOperator::Opcode Op,
|
||||
SVal L, SVal R, QualType T) {
|
||||
SVal SValBuilder::evalBinOp(const GRState *state, BinaryOperator::Opcode op,
|
||||
SVal lhs, SVal rhs, QualType type) {
|
||||
|
||||
if (L.isUndef() || R.isUndef())
|
||||
if (lhs.isUndef() || rhs.isUndef())
|
||||
return UndefinedVal();
|
||||
|
||||
if (L.isUnknown() || R.isUnknown())
|
||||
if (lhs.isUnknown() || rhs.isUnknown())
|
||||
return UnknownVal();
|
||||
|
||||
if (isa<Loc>(L)) {
|
||||
if (isa<Loc>(R))
|
||||
return evalBinOpLL(ST, Op, cast<Loc>(L), cast<Loc>(R), T);
|
||||
if (isa<Loc>(lhs)) {
|
||||
if (isa<Loc>(rhs))
|
||||
return evalBinOpLL(state, op, cast<Loc>(lhs), cast<Loc>(rhs), type);
|
||||
|
||||
return evalBinOpLN(ST, Op, cast<Loc>(L), cast<NonLoc>(R), T);
|
||||
return evalBinOpLN(state, op, cast<Loc>(lhs), cast<NonLoc>(rhs), type);
|
||||
}
|
||||
|
||||
if (isa<Loc>(R)) {
|
||||
if (isa<Loc>(rhs)) {
|
||||
// Support pointer arithmetic where the addend is on the left
|
||||
// and the pointer on the right.
|
||||
assert(Op == BO_Add);
|
||||
assert(op == BO_Add);
|
||||
|
||||
// Commute the operands.
|
||||
return evalBinOpLN(ST, Op, cast<Loc>(R), cast<NonLoc>(L), T);
|
||||
return evalBinOpLN(state, op, cast<Loc>(rhs), cast<NonLoc>(lhs), type);
|
||||
}
|
||||
|
||||
return evalBinOpNN(ST, Op, cast<NonLoc>(L), cast<NonLoc>(R), T);
|
||||
return evalBinOpNN(state, op, cast<NonLoc>(lhs), cast<NonLoc>(rhs), type);
|
||||
}
|
||||
|
||||
DefinedOrUnknownSVal SValBuilder::evalEQ(const GRState *ST,
|
||||
DefinedOrUnknownSVal L,
|
||||
DefinedOrUnknownSVal R) {
|
||||
return cast<DefinedOrUnknownSVal>(evalBinOp(ST, BO_EQ, L, R,
|
||||
DefinedOrUnknownSVal SValBuilder::evalEQ(const GRState *state,
|
||||
DefinedOrUnknownSVal lhs,
|
||||
DefinedOrUnknownSVal rhs) {
|
||||
return cast<DefinedOrUnknownSVal>(evalBinOp(state, BO_EQ, lhs, rhs,
|
||||
Context.IntTy));
|
||||
}
|
||||
|
||||
|
@ -213,11 +214,11 @@ SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
|
|||
|
||||
// Check for casts from integers to integers.
|
||||
if (castTy->isIntegerType() && originalTy->isIntegerType())
|
||||
return evalCastNL(cast<NonLoc>(val), castTy);
|
||||
return evalCastFromNonLoc(cast<NonLoc>(val), castTy);
|
||||
|
||||
// Check for casts from pointers to integers.
|
||||
if (castTy->isIntegerType() && Loc::isLocType(originalTy))
|
||||
return evalCastL(cast<Loc>(val), castTy);
|
||||
return evalCastFromLoc(cast<Loc>(val), castTy);
|
||||
|
||||
// Check for casts from integers to pointers.
|
||||
if (Loc::isLocType(castTy) && originalTy->isIntegerType()) {
|
||||
|
@ -256,7 +257,7 @@ SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
|
|||
// need the original decayed type.
|
||||
// QualType elemTy = cast<ArrayType>(originalTy)->getElementType();
|
||||
// QualType pointerTy = C.getPointerType(elemTy);
|
||||
return evalCastL(cast<Loc>(val), castTy);
|
||||
return evalCastFromLoc(cast<Loc>(val), castTy);
|
||||
}
|
||||
|
||||
// Check for casts from a region to a specific type.
|
||||
|
@ -305,6 +306,6 @@ SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
|
|||
|
||||
DispatchCast:
|
||||
// All other cases.
|
||||
return isa<Loc>(val) ? evalCastL(cast<Loc>(val), castTy)
|
||||
: evalCastNL(cast<NonLoc>(val), castTy);
|
||||
return isa<Loc>(val) ? evalCastFromLoc(cast<Loc>(val), castTy)
|
||||
: evalCastFromNonLoc(cast<NonLoc>(val), castTy);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ using namespace ento;
|
|||
namespace {
|
||||
class SimpleSValBuilder : public SValBuilder {
|
||||
protected:
|
||||
virtual SVal evalCastNL(NonLoc val, QualType castTy);
|
||||
virtual SVal evalCastL(Loc val, QualType castTy);
|
||||
virtual SVal evalCastFromNonLoc(NonLoc val, QualType castTy);
|
||||
virtual SVal evalCastFromLoc(Loc val, QualType castTy);
|
||||
|
||||
public:
|
||||
SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
|
||||
|
@ -57,7 +57,7 @@ SValBuilder *ento::createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc,
|
|||
// Transfer function for Casts.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
SVal SimpleSValBuilder::evalCastNL(NonLoc val, QualType castTy) {
|
||||
SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
|
||||
|
||||
bool isLocType = Loc::isLocType(castTy);
|
||||
|
||||
|
@ -106,7 +106,7 @@ SVal SimpleSValBuilder::evalCastNL(NonLoc val, QualType castTy) {
|
|||
return makeIntVal(i);
|
||||
}
|
||||
|
||||
SVal SimpleSValBuilder::evalCastL(Loc val, QualType castTy) {
|
||||
SVal SimpleSValBuilder::evalCastFromLoc(Loc val, QualType castTy) {
|
||||
|
||||
// Casts from pointers -> pointers, just return the lval.
|
||||
//
|
||||
|
@ -255,11 +255,12 @@ SVal SimpleSValBuilder::MakeSymIntVal(const SymExpr *LHS,
|
|||
}
|
||||
|
||||
// Idempotent ops (like a*1) can still change the type of an expression.
|
||||
// Wrap the LHS up in a NonLoc again and let evalCastNL do the dirty work.
|
||||
// Wrap the LHS up in a NonLoc again and let evalCastFromNonLoc do the
|
||||
// dirty work.
|
||||
if (isIdempotent) {
|
||||
if (SymbolRef LHSSym = dyn_cast<SymbolData>(LHS))
|
||||
return evalCastNL(nonloc::SymbolVal(LHSSym), resultTy);
|
||||
return evalCastNL(nonloc::SymExprVal(LHS), resultTy);
|
||||
return evalCastFromNonLoc(nonloc::SymbolVal(LHSSym), resultTy);
|
||||
return evalCastFromNonLoc(nonloc::SymExprVal(LHS), resultTy);
|
||||
}
|
||||
|
||||
// If we reach this point, the expression cannot be simplified.
|
||||
|
@ -289,7 +290,7 @@ SVal SimpleSValBuilder::evalBinOpNN(const GRState *state,
|
|||
return makeIntVal(0, resultTy);
|
||||
case BO_Or:
|
||||
case BO_And:
|
||||
return evalCastNL(lhs, resultTy);
|
||||
return evalCastFromNonLoc(lhs, resultTy);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
@ -552,7 +553,7 @@ SVal SimpleSValBuilder::evalBinOpLL(const GRState *state,
|
|||
default:
|
||||
break;
|
||||
case BO_Sub:
|
||||
return evalCastL(lhs, resultTy);
|
||||
return evalCastFromLoc(lhs, resultTy);
|
||||
case BO_EQ:
|
||||
case BO_LE:
|
||||
case BO_LT:
|
||||
|
@ -588,7 +589,7 @@ SVal SimpleSValBuilder::evalBinOpLL(const GRState *state,
|
|||
SVal ResultVal = cast<loc::ConcreteInt>(lhs).evalBinOp(BasicVals, op,
|
||||
*rInt);
|
||||
if (Loc *Result = dyn_cast<Loc>(&ResultVal))
|
||||
return evalCastL(*Result, resultTy);
|
||||
return evalCastFromLoc(*Result, resultTy);
|
||||
else
|
||||
return UnknownVal();
|
||||
}
|
||||
|
@ -633,7 +634,7 @@ SVal SimpleSValBuilder::evalBinOpLL(const GRState *state,
|
|||
default:
|
||||
break;
|
||||
case BO_Sub:
|
||||
return evalCastL(lhs, resultTy);
|
||||
return evalCastFromLoc(lhs, resultTy);
|
||||
case BO_EQ:
|
||||
case BO_LT:
|
||||
case BO_LE:
|
||||
|
@ -698,7 +699,7 @@ SVal SimpleSValBuilder::evalBinOpLL(const GRState *state,
|
|||
NonLoc *LeftIndex = dyn_cast<NonLoc>(&LeftIndexVal);
|
||||
if (!LeftIndex)
|
||||
return UnknownVal();
|
||||
LeftIndexVal = evalCastNL(*LeftIndex, resultTy);
|
||||
LeftIndexVal = evalCastFromNonLoc(*LeftIndex, resultTy);
|
||||
LeftIndex = dyn_cast<NonLoc>(&LeftIndexVal);
|
||||
if (!LeftIndex)
|
||||
return UnknownVal();
|
||||
|
@ -708,7 +709,7 @@ SVal SimpleSValBuilder::evalBinOpLL(const GRState *state,
|
|||
NonLoc *RightIndex = dyn_cast<NonLoc>(&RightIndexVal);
|
||||
if (!RightIndex)
|
||||
return UnknownVal();
|
||||
RightIndexVal = evalCastNL(*RightIndex, resultTy);
|
||||
RightIndexVal = evalCastFromNonLoc(*RightIndex, resultTy);
|
||||
RightIndex = dyn_cast<NonLoc>(&RightIndexVal);
|
||||
if (!RightIndex)
|
||||
return UnknownVal();
|
||||
|
|
|
@ -230,9 +230,9 @@ SVal StoreManager::CastRetrievedVal(SVal V, const TypedRegion *R,
|
|||
}
|
||||
|
||||
if (const Loc *L = dyn_cast<Loc>(&V))
|
||||
return svalBuilder.evalCastL(*L, castTy);
|
||||
return svalBuilder.evalCastFromLoc(*L, castTy);
|
||||
else if (const NonLoc *NL = dyn_cast<NonLoc>(&V))
|
||||
return svalBuilder.evalCastNL(*NL, castTy);
|
||||
return svalBuilder.evalCastFromNonLoc(*NL, castTy);
|
||||
|
||||
return V;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue