21 using namespace clang;
25 class BoolAssignmentChecker :
public Checker< check::Bind > {
26 mutable std::unique_ptr<BuiltinBug> BT;
29 void checkBind(SVal loc, SVal val,
const Stmt *S, CheckerContext &C)
const;
34 CheckerContext &C)
const {
35 if (ExplodedNode *N = C.generateNonFatalErrorNode(state)) {
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,
55 CheckerContext &C)
const {
58 const TypedValueRegion *TR =
59 dyn_cast_or_null<TypedValueRegion>(loc.getAsRegion());
80 SValBuilder &svalBuilder = C.getSValBuilder();
81 ConstraintManager &CM = C.getConstraintManager();
84 DefinedSVal zeroVal = svalBuilder.makeIntVal(0, valTy);
85 SVal greaterThanOrEqualToZeroVal =
86 svalBuilder.evalBinOp(state, BO_GE, *DV, zeroVal,
87 svalBuilder.getConditionType());
90 greaterThanOrEqualToZeroVal.getAs<DefinedSVal>();
92 if (!greaterThanEqualToZero) {
99 std::tie(stateGE, stateLT) = CM.assumeDual(state, *greaterThanEqualToZero);
108 emitReport(stateLT, C);
116 assert(stateGE == state);
120 DefinedSVal OneVal = svalBuilder.makeIntVal(1, valTy);
121 SVal lessThanEqToOneVal =
122 svalBuilder.evalBinOp(state, BO_LE, *DV, OneVal,
123 svalBuilder.getConditionType());
126 lessThanEqToOneVal.getAs<DefinedSVal>();
128 if (!lessThanEqToOne) {
135 std::tie(stateLE, stateGT) = CM.assumeDual(state, *lessThanEqToOne);
144 emitReport(stateGT, C);
152 assert(stateLE == state);
155 void ento::registerBoolAssignmentChecker(CheckerManager &mgr) {
156 mgr.registerChecker<BoolAssignmentChecker>();
A (possibly-)qualified type.
Stmt - This represents one statement.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const T * getAs() const
Member-template getAs<specific type>'.
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)
Dataflow Directional Tag Classes.
bool isBooleanType() const