Skip to content

Commit a2eb234

Browse files
authored
[clang][analyzer] Reformat code of BoolAssignmentChecker (NFC). (#81461)
This is only a code reformatting and rename of variables to the newer format.
1 parent dc866ae commit a2eb234

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ using namespace clang;
2323
using namespace ento;
2424

2525
namespace {
26-
class BoolAssignmentChecker : public Checker< check::Bind > {
27-
const BugType BT{this, "Assignment of a non-Boolean value"};
28-
void emitReport(ProgramStateRef state, CheckerContext &C,
29-
bool IsTainted = false) const;
30-
31-
public:
32-
void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const;
33-
};
26+
class BoolAssignmentChecker : public Checker<check::Bind> {
27+
const BugType BT{this, "Assignment of a non-Boolean value"};
28+
void emitReport(ProgramStateRef State, CheckerContext &C,
29+
bool IsTainted = false) const;
30+
31+
public:
32+
void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const;
33+
};
3434
} // end anonymous namespace
3535

36-
void BoolAssignmentChecker::emitReport(ProgramStateRef state, CheckerContext &C,
36+
void BoolAssignmentChecker::emitReport(ProgramStateRef State, CheckerContext &C,
3737
bool IsTainted) const {
38-
if (ExplodedNode *N = C.generateNonFatalErrorNode(state)) {
38+
if (ExplodedNode *N = C.generateNonFatalErrorNode(State)) {
3939
StringRef Msg = IsTainted ? "Might assign a tainted non-Boolean value"
4040
: "Assignment of a non-Boolean value";
4141
C.emitReport(std::make_unique<PathSensitiveBugReport>(BT, Msg, N));
@@ -47,59 +47,58 @@ static bool isBooleanType(QualType Ty) {
4747
return true;
4848

4949
if (const TypedefType *TT = Ty->getAs<TypedefType>())
50-
return TT->getDecl()->getName() == "BOOL" || // Objective-C
51-
TT->getDecl()->getName() == "_Bool" || // stdbool.h < C99
52-
TT->getDecl()->getName() == "Boolean"; // MacTypes.h
50+
return TT->getDecl()->getName() == "BOOL" || // Objective-C
51+
TT->getDecl()->getName() == "_Bool" || // stdbool.h < C99
52+
TT->getDecl()->getName() == "Boolean"; // MacTypes.h
5353

5454
return false;
5555
}
5656

57-
void BoolAssignmentChecker::checkBind(SVal loc, SVal val, const Stmt *S,
57+
void BoolAssignmentChecker::checkBind(SVal Loc, SVal Val, const Stmt *S,
5858
CheckerContext &C) const {
5959

6060
// We are only interested in stores into Booleans.
6161
const TypedValueRegion *TR =
62-
dyn_cast_or_null<TypedValueRegion>(loc.getAsRegion());
62+
dyn_cast_or_null<TypedValueRegion>(Loc.getAsRegion());
6363

6464
if (!TR)
6565
return;
6666

67-
QualType valTy = TR->getValueType();
67+
QualType RegTy = TR->getValueType();
6868

69-
if (!isBooleanType(valTy))
69+
if (!isBooleanType(RegTy))
7070
return;
7171

7272
// Get the value of the right-hand side. We only care about values
7373
// that are defined (UnknownVals and UndefinedVals are handled by other
7474
// checkers).
75-
std::optional<NonLoc> NV = val.getAs<NonLoc>();
75+
std::optional<NonLoc> NV = Val.getAs<NonLoc>();
7676
if (!NV)
7777
return;
7878

7979
// Check if the assigned value meets our criteria for correctness. It must
8080
// be a value that is either 0 or 1. One way to check this is to see if
8181
// the value is possibly < 0 (for a negative value) or greater than 1.
82-
ProgramStateRef state = C.getState();
83-
SValBuilder &svalBuilder = C.getSValBuilder();
84-
BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
82+
ProgramStateRef State = C.getState();
83+
BasicValueFactory &BVF = C.getSValBuilder().getBasicValueFactory();
8584
ConstraintManager &CM = C.getConstraintManager();
8685

87-
llvm::APSInt Zero = BVF.getValue(0, valTy);
88-
llvm::APSInt One = BVF.getValue(1, valTy);
86+
llvm::APSInt Zero = BVF.getValue(0, RegTy);
87+
llvm::APSInt One = BVF.getValue(1, RegTy);
8988

9089
ProgramStateRef StIn, StOut;
91-
std::tie(StIn, StOut) = CM.assumeInclusiveRangeDual(state, *NV, Zero, One);
90+
std::tie(StIn, StOut) = CM.assumeInclusiveRangeDual(State, *NV, Zero, One);
9291

9392
if (!StIn)
9493
emitReport(StOut, C);
95-
if (StIn && StOut && taint::isTainted(state, *NV))
94+
if (StIn && StOut && taint::isTainted(State, *NV))
9695
emitReport(StOut, C, /*IsTainted=*/true);
9796
}
9897

99-
void ento::registerBoolAssignmentChecker(CheckerManager &mgr) {
100-
mgr.registerChecker<BoolAssignmentChecker>();
98+
void ento::registerBoolAssignmentChecker(CheckerManager &Mgr) {
99+
Mgr.registerChecker<BoolAssignmentChecker>();
101100
}
102101

103-
bool ento::shouldRegisterBoolAssignmentChecker(const CheckerManager &mgr) {
102+
bool ento::shouldRegisterBoolAssignmentChecker(const CheckerManager &Mgr) {
104103
return true;
105104
}

0 commit comments

Comments
 (0)