20 using namespace clang;
24 class BoolAssignmentChecker :
public Checker< check::Bind > {
25 mutable std::unique_ptr<BuiltinBug> BT;
28 void checkBind(SVal loc, SVal val,
const Stmt *S, CheckerContext &C)
const;
33 CheckerContext &C)
const {
34 if (ExplodedNode *N = C.generateNonFatalErrorNode(state)) {
36 BT.reset(
new BuiltinBug(
this,
"Assignment of a non-Boolean value"));
39 std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N));
48 return TT->getDecl()->getName() ==
"BOOL" ||
49 TT->getDecl()->getName() ==
"_Bool" ||
50 TT->getDecl()->getName() ==
"Boolean";
55 void BoolAssignmentChecker::checkBind(SVal loc, SVal val,
const Stmt *S,
56 CheckerContext &C)
const {
59 const TypedValueRegion *TR =
60 dyn_cast_or_null<TypedValueRegion>(loc.getAsRegion());
81 SValBuilder &svalBuilder = C.getSValBuilder();
82 ConstraintManager &CM = C.getConstraintManager();
85 DefinedSVal zeroVal = svalBuilder.makeIntVal(0, valTy);
86 SVal greaterThanOrEqualToZeroVal =
87 svalBuilder.evalBinOp(state, BO_GE, *DV, zeroVal,
88 svalBuilder.getConditionType());
91 greaterThanOrEqualToZeroVal.getAs<DefinedSVal>();
93 if (!greaterThanEqualToZero) {
100 std::tie(stateGE, stateLT) = CM.assumeDual(state, *greaterThanEqualToZero);
109 emitReport(stateLT, C);
117 assert(stateGE == state);
121 DefinedSVal OneVal = svalBuilder.makeIntVal(1, valTy);
122 SVal lessThanEqToOneVal =
123 svalBuilder.evalBinOp(state, BO_LE, *DV, OneVal,
124 svalBuilder.getConditionType());
127 lessThanEqToOneVal.getAs<DefinedSVal>();
129 if (!lessThanEqToOne) {
136 std::tie(stateLE, stateGT) = CM.assumeDual(state, *lessThanEqToOne);
145 emitReport(stateGT, C);
153 assert(stateLE == state);
156 void ento::registerBoolAssignmentChecker(CheckerManager &mgr) {
157 mgr.registerChecker<BoolAssignmentChecker>();
160 bool ento::shouldRegisterBoolAssignmentChecker(
const LangOptions &LO) {
A (possibly-)qualified type.
Stmt - This represents one statement.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const T * getAs() const
Member-template getAs<specific type>'.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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