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"));
37 C.emitReport(llvm::make_unique<BugReport>(*BT, BT->getDescription(), N));
46 return TT->getDecl()->getName() ==
"BOOL" ||
47 TT->getDecl()->getName() ==
"_Bool" ||
48 TT->getDecl()->getName() ==
"Boolean";
53 void BoolAssignmentChecker::checkBind(SVal loc, SVal val,
const Stmt *S,
54 CheckerContext &C)
const {
57 const TypedValueRegion *TR =
58 dyn_cast_or_null<TypedValueRegion>(loc.getAsRegion());
79 SValBuilder &svalBuilder = C.getSValBuilder();
80 ConstraintManager &CM = C.getConstraintManager();
83 DefinedSVal zeroVal = svalBuilder.makeIntVal(0, valTy);
84 SVal greaterThanOrEqualToZeroVal =
85 svalBuilder.evalBinOp(state, BO_GE, *DV, zeroVal,
86 svalBuilder.getConditionType());
89 greaterThanOrEqualToZeroVal.getAs<DefinedSVal>();
91 if (!greaterThanEqualToZero) {
98 std::tie(stateGE, stateLT) = CM.assumeDual(state, *greaterThanEqualToZero);
107 emitReport(stateLT, C);
115 assert(stateGE == state);
119 DefinedSVal OneVal = svalBuilder.makeIntVal(1, valTy);
120 SVal lessThanEqToOneVal =
121 svalBuilder.evalBinOp(state, BO_LE, *DV, OneVal,
122 svalBuilder.getConditionType());
125 lessThanEqToOneVal.getAs<DefinedSVal>();
127 if (!lessThanEqToOne) {
134 std::tie(stateLE, stateGT) = CM.assumeDual(state, *lessThanEqToOne);
143 emitReport(stateGT, C);
151 assert(stateLE == state);
154 void ento::registerBoolAssignmentChecker(CheckerManager &mgr) {
155 mgr.registerChecker<BoolAssignmentChecker>();
158 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