forked from OSchip/llvm-project
[analyzer] [NFC] Minor ExprEngineC refactoring
Move a repeated block of code into a function. Differential Revision: https://reviews.llvm.org/D39584 llvm-svn: 317849
This commit is contained in:
parent
e8c4bf54ba
commit
8ee82ed81b
|
@ -20,6 +20,24 @@ using namespace clang;
|
||||||
using namespace ento;
|
using namespace ento;
|
||||||
using llvm::APSInt;
|
using llvm::APSInt;
|
||||||
|
|
||||||
|
/// \brief Optionally conjure and return a symbol for offset when processing
|
||||||
|
/// an expression \p Expression.
|
||||||
|
/// If \p Other is a location, conjure a symbol for \p Symbol
|
||||||
|
/// (offset) if it is unknown so that memory arithmetic always
|
||||||
|
/// results in an ElementRegion.
|
||||||
|
/// \p Count The number of times the current basic block was visited.
|
||||||
|
static SVal conjureOffsetSymbolOnLocation(
|
||||||
|
SVal Symbol, SVal Other, Expr* Expression, SValBuilder &svalBuilder,
|
||||||
|
unsigned Count, const LocationContext *LCtx) {
|
||||||
|
QualType Ty = Expression->getType();
|
||||||
|
if (Other.getAs<Loc>() &&
|
||||||
|
Ty->isIntegralOrEnumerationType() &&
|
||||||
|
Symbol.isUnknown()) {
|
||||||
|
return svalBuilder.conjureSymbolVal(Expression, LCtx, Ty, Count);
|
||||||
|
}
|
||||||
|
return Symbol;
|
||||||
|
}
|
||||||
|
|
||||||
void ExprEngine::VisitBinaryOperator(const BinaryOperator* B,
|
void ExprEngine::VisitBinaryOperator(const BinaryOperator* B,
|
||||||
ExplodedNode *Pred,
|
ExplodedNode *Pred,
|
||||||
ExplodedNodeSet &Dst) {
|
ExplodedNodeSet &Dst) {
|
||||||
|
@ -63,24 +81,13 @@ void ExprEngine::VisitBinaryOperator(const BinaryOperator* B,
|
||||||
StmtNodeBuilder Bldr(*it, Tmp2, *currBldrCtx);
|
StmtNodeBuilder Bldr(*it, Tmp2, *currBldrCtx);
|
||||||
|
|
||||||
if (B->isAdditiveOp()) {
|
if (B->isAdditiveOp()) {
|
||||||
// If one of the operands is a location, conjure a symbol for the other
|
|
||||||
// one (offset) if it's unknown so that memory arithmetic always
|
|
||||||
// results in an ElementRegion.
|
|
||||||
// TODO: This can be removed after we enable history tracking with
|
// TODO: This can be removed after we enable history tracking with
|
||||||
// SymSymExpr.
|
// SymSymExpr.
|
||||||
unsigned Count = currBldrCtx->blockCount();
|
unsigned Count = currBldrCtx->blockCount();
|
||||||
if (LeftV.getAs<Loc>() &&
|
RightV = conjureOffsetSymbolOnLocation(
|
||||||
RHS->getType()->isIntegralOrEnumerationType() &&
|
RightV, LeftV, RHS, svalBuilder, Count, LCtx);
|
||||||
RightV.isUnknown()) {
|
LeftV = conjureOffsetSymbolOnLocation(
|
||||||
RightV = svalBuilder.conjureSymbolVal(RHS, LCtx, RHS->getType(),
|
LeftV, RightV, LHS, svalBuilder, Count, LCtx);
|
||||||
Count);
|
|
||||||
}
|
|
||||||
if (RightV.getAs<Loc>() &&
|
|
||||||
LHS->getType()->isIntegralOrEnumerationType() &&
|
|
||||||
LeftV.isUnknown()) {
|
|
||||||
LeftV = svalBuilder.conjureSymbolVal(LHS, LCtx, LHS->getType(),
|
|
||||||
Count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Although we don't yet model pointers-to-members, we do need to make
|
// Although we don't yet model pointers-to-members, we do need to make
|
||||||
|
|
Loading…
Reference in New Issue