26class BoolAssignmentChecker :
public Checker<check::Bind> {
27 const BugType BT{
this,
"Assignment of a non-Boolean value"};
29 bool IsTainted =
false)
const;
32 void checkBind(SVal Loc, SVal Val,
const Stmt *S,
bool AtDeclInit,
33 CheckerContext &
C)
const;
38 bool IsTainted)
const {
39 if (ExplodedNode *N =
C.generateNonFatalErrorNode(State)) {
40 StringRef Msg = IsTainted ?
"Might assign a tainted non-Boolean value"
41 :
"Assignment of a non-Boolean value";
42 C.emitReport(std::make_unique<PathSensitiveBugReport>(BT, Msg, N));
51 return TT->getDecl()->getName() ==
"BOOL" ||
52 TT->getDecl()->getName() ==
"_Bool" ||
53 TT->getDecl()->getName() ==
"Boolean";
58void BoolAssignmentChecker::checkBind(SVal Loc, SVal Val,
const Stmt *S,
60 CheckerContext &
C)
const {
63 const TypedValueRegion *TR =
64 dyn_cast_or_null<TypedValueRegion>(Loc.
getAsRegion());
77 std::optional<NonLoc> NV = Val.
getAs<NonLoc>();
85 BasicValueFactory &BVF =
C.getSValBuilder().getBasicValueFactory();
86 ConstraintManager &CM =
C.getConstraintManager();
88 llvm::APSInt
Zero = BVF.getValue(0, RegTy);
89 llvm::APSInt One = BVF.getValue(1, RegTy);
97 emitReport(StOut,
C,
true);
100void ento::registerBoolAssignmentChecker(CheckerManager &Mgr) {
104bool ento::shouldRegisterBoolAssignmentChecker(
const CheckerManager &Mgr) {
static bool isBooleanType(QualType Ty)
A (possibly-)qualified type.
bool isBooleanType() const
const T * getAs() const
Member-template getAs<specific type>'.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
ProgramStatePair assumeInclusiveRangeDual(ProgramStateRef State, NonLoc Value, const llvm::APSInt &From, const llvm::APSInt &To)
Returns a pair of states (StInRange, StOutOfRange) where the given value is assumed to be in the rang...
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
const MemRegion * getAsRegion() const
virtual QualType getValueType() const =0
bool isTainted(ProgramStateRef State, const Stmt *S, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric)
Check if the statement has a tainted value in the given state.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.