21 using namespace clang;
25 class BoolAssignmentChecker :
public Checker< check::Bind > {
26 mutable std::unique_ptr<BuiltinBug> BT;
37 BT.reset(
new BuiltinBug(
this,
"Assignment of a non-Boolean value"));
38 C.
emitReport(llvm::make_unique<BugReport>(*BT, BT->getDescription(), N));
47 return TT->getDecl()->getName() ==
"BOOL" ||
48 TT->getDecl()->getName() ==
"_Bool" ||
49 TT->getDecl()->getName() ==
"Boolean";
54 void BoolAssignmentChecker::checkBind(
SVal loc,
SVal val,
const Stmt *
S,
59 dyn_cast_or_null<TypedValueRegion>(loc.
getAsRegion());
85 SVal greaterThanOrEqualToZeroVal =
86 svalBuilder.
evalBinOp(state, BO_GE, *DV, zeroVal,
92 if (!greaterThanEqualToZero) {
99 std::tie(stateGE, stateLT) = CM.
assumeDual(state, *greaterThanEqualToZero);
108 emitReport(stateLT, C);
116 assert(stateGE == state);
121 SVal lessThanEqToOneVal =
122 svalBuilder.
evalBinOp(state, BO_LE, *DV, OneVal,
128 if (!lessThanEqToOne) {
135 std::tie(stateLE, stateGT) = CM.
assumeDual(state, *lessThanEqToOne);
144 emitReport(stateGT, C);
152 assert(stateLE == state);
TypedValueRegion - An abstract class representing regions having a typed value.
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
A (possibly-)qualified type.
virtual QualType getValueType() const =0
bool isBooleanType() const
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
static bool isBooleanType(QualType Ty)
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
Returns a pair of states (StTrue, StFalse) where the given condition is assumed to be true or false...
const ProgramStateRef & getState() const
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
ExplodedNode * generateNonFatalErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
QualType getConditionType() const
ConstraintManager & getConstraintManager()
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
const MemRegion * getAsRegion() const
const T * getAs() const
Member-template getAs<specific type>'.
SValBuilder & getSValBuilder()