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 =
92 if (!greaterThanEqualToZero) {
99 std::tie(stateGE, stateLT) = CM.
assumeDual(state, *greaterThanEqualToZero);
108 emitReport(stateLT, C);
116 assert(stateGE == state);
121 SVal lessThanEqToOneVal =
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)
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph). Uses the default CheckerContex...
virtual QualType getValueType() const =0
bool isBooleanType() const
static bool isBooleanType(QualType Ty)
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
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)
QualType getConditionType() const
ConstraintManager & getConstraintManager()
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
const MemRegion * getAsRegion() const
SValBuilder & getSValBuilder()