[analyzer][NFC] Relocate unary transfer functions

This is an initial step of removing the SimpleSValBuilder abstraction. The SValBuilder alone should be enough.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126127
This commit is contained in:
Balazs Benics 2022-06-14 18:56:43 +02:00
parent 4d27c154a5
commit cfc915149c
3 changed files with 26 additions and 33 deletions

View File

@ -120,9 +120,8 @@ public:
SVal evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy,
QualType originalType);
virtual SVal evalMinus(NonLoc val) = 0;
virtual SVal evalComplement(NonLoc val) = 0;
SVal evalMinus(NonLoc val);
SVal evalComplement(NonLoc val);
/// Create a new value which represents a binary expression with two non-
/// location operands.

View File

@ -441,6 +441,30 @@ SVal SValBuilder::makeSymExprValNN(BinaryOperator::Opcode Op,
return UnknownVal();
}
SVal SValBuilder::evalMinus(NonLoc val) {
switch (val.getSubKind()) {
case nonloc::ConcreteIntKind:
return val.castAs<nonloc::ConcreteInt>().evalMinus(*this);
case nonloc::SymbolValKind:
return makeNonLoc(val.castAs<nonloc::SymbolVal>().getSymbol(), UO_Minus,
val.getType(Context));
default:
return UnknownVal();
}
}
SVal SValBuilder::evalComplement(NonLoc X) {
switch (X.getSubKind()) {
case nonloc::ConcreteIntKind:
return X.castAs<nonloc::ConcreteInt>().evalComplement(*this);
case nonloc::SymbolValKind:
return makeNonLoc(X.castAs<nonloc::SymbolVal>().getSymbol(), UO_Not,
X.getType(Context));
default:
return UnknownVal();
}
}
SVal SValBuilder::evalUnaryOp(ProgramStateRef state, UnaryOperator::Opcode opc,
SVal operand, QualType type) {
auto OpN = operand.getAs<NonLoc>();

View File

@ -63,8 +63,6 @@ public:
: SValBuilder(alloc, context, stateMgr) {}
~SimpleSValBuilder() override {}
SVal evalMinus(NonLoc val) override;
SVal evalComplement(NonLoc val) override;
SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op,
NonLoc lhs, NonLoc rhs, QualType resultTy) override;
SVal evalBinOpLL(ProgramStateRef state, BinaryOperator::Opcode op,
@ -90,34 +88,6 @@ SValBuilder *ento::createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc,
return new SimpleSValBuilder(alloc, context, stateMgr);
}
//===----------------------------------------------------------------------===//
// Transfer function for unary operators.
//===----------------------------------------------------------------------===//
SVal SimpleSValBuilder::evalMinus(NonLoc val) {
switch (val.getSubKind()) {
case nonloc::ConcreteIntKind:
return val.castAs<nonloc::ConcreteInt>().evalMinus(*this);
case nonloc::SymbolValKind:
return makeNonLoc(val.castAs<nonloc::SymbolVal>().getSymbol(), UO_Minus,
val.getType(Context));
default:
return UnknownVal();
}
}
SVal SimpleSValBuilder::evalComplement(NonLoc X) {
switch (X.getSubKind()) {
case nonloc::ConcreteIntKind:
return X.castAs<nonloc::ConcreteInt>().evalComplement(*this);
case nonloc::SymbolValKind:
return makeNonLoc(X.castAs<nonloc::SymbolVal>().getSymbol(), UO_Not,
X.getType(Context));
default:
return UnknownVal();
}
}
// Checks if the negation the value and flipping sign preserve
// the semantics on the operation in the resultType
static bool isNegationValuePreserving(const llvm::APSInt &Value,