[clang] [clang][analyzer] Reformat code of BoolAssignmentChecker (NFC). (PR #81461)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 02:24:53 PST 2024
https://github.com/balazske created https://github.com/llvm/llvm-project/pull/81461
This is only a code reformatting and rename of variables to the newer format.
>From d1078be3394fc240de014f72116e18d6740b5773 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <balazs.keri at ericsson.com>
Date: Mon, 12 Feb 2024 09:59:32 +0100
Subject: [PATCH] [clang][analyzer] Reformat code of BoolAssignmentChecker
(NFC).
This is only a code reformatting and rename of variables to the
newer format.
---
.../Checkers/BoolAssignmentChecker.cpp | 55 +++++++++----------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
index a09db6d2d0ec5b..837cbbce8f45f3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp
@@ -23,19 +23,19 @@ using namespace clang;
using namespace ento;
namespace {
- class BoolAssignmentChecker : public Checker< check::Bind > {
- const BugType BT{this, "Assignment of a non-Boolean value"};
- void emitReport(ProgramStateRef state, CheckerContext &C,
- bool IsTainted = false) const;
-
- public:
- void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const;
- };
+class BoolAssignmentChecker : public Checker<check::Bind> {
+ const BugType BT{this, "Assignment of a non-Boolean value"};
+ void emitReport(ProgramStateRef State, CheckerContext &C,
+ bool IsTainted = false) const;
+
+public:
+ void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const;
+};
} // end anonymous namespace
-void BoolAssignmentChecker::emitReport(ProgramStateRef state, CheckerContext &C,
+void BoolAssignmentChecker::emitReport(ProgramStateRef State, CheckerContext &C,
bool IsTainted) const {
- if (ExplodedNode *N = C.generateNonFatalErrorNode(state)) {
+ if (ExplodedNode *N = C.generateNonFatalErrorNode(State)) {
StringRef Msg = IsTainted ? "Might assign a tainted non-Boolean value"
: "Assignment of a non-Boolean value";
C.emitReport(std::make_unique<PathSensitiveBugReport>(BT, Msg, N));
@@ -47,59 +47,58 @@ static bool isBooleanType(QualType Ty) {
return true;
if (const TypedefType *TT = Ty->getAs<TypedefType>())
- return TT->getDecl()->getName() == "BOOL" || // Objective-C
- TT->getDecl()->getName() == "_Bool" || // stdbool.h < C99
- TT->getDecl()->getName() == "Boolean"; // MacTypes.h
+ return TT->getDecl()->getName() == "BOOL" || // Objective-C
+ TT->getDecl()->getName() == "_Bool" || // stdbool.h < C99
+ TT->getDecl()->getName() == "Boolean"; // MacTypes.h
return false;
}
-void BoolAssignmentChecker::checkBind(SVal loc, SVal val, const Stmt *S,
+void BoolAssignmentChecker::checkBind(SVal Loc, SVal Val, const Stmt *S,
CheckerContext &C) const {
// We are only interested in stores into Booleans.
const TypedValueRegion *TR =
- dyn_cast_or_null<TypedValueRegion>(loc.getAsRegion());
+ dyn_cast_or_null<TypedValueRegion>(Loc.getAsRegion());
if (!TR)
return;
- QualType valTy = TR->getValueType();
+ QualType RegTy = TR->getValueType();
- if (!isBooleanType(valTy))
+ if (!isBooleanType(RegTy))
return;
// Get the value of the right-hand side. We only care about values
// that are defined (UnknownVals and UndefinedVals are handled by other
// checkers).
- std::optional<NonLoc> NV = val.getAs<NonLoc>();
+ std::optional<NonLoc> NV = Val.getAs<NonLoc>();
if (!NV)
return;
// Check if the assigned value meets our criteria for correctness. It must
// be a value that is either 0 or 1. One way to check this is to see if
// the value is possibly < 0 (for a negative value) or greater than 1.
- ProgramStateRef state = C.getState();
- SValBuilder &svalBuilder = C.getSValBuilder();
- BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
+ ProgramStateRef State = C.getState();
+ BasicValueFactory &BVF = C.getSValBuilder().getBasicValueFactory();
ConstraintManager &CM = C.getConstraintManager();
- llvm::APSInt Zero = BVF.getValue(0, valTy);
- llvm::APSInt One = BVF.getValue(1, valTy);
+ llvm::APSInt Zero = BVF.getValue(0, RegTy);
+ llvm::APSInt One = BVF.getValue(1, RegTy);
ProgramStateRef StIn, StOut;
- std::tie(StIn, StOut) = CM.assumeInclusiveRangeDual(state, *NV, Zero, One);
+ std::tie(StIn, StOut) = CM.assumeInclusiveRangeDual(State, *NV, Zero, One);
if (!StIn)
emitReport(StOut, C);
- if (StIn && StOut && taint::isTainted(state, *NV))
+ if (StIn && StOut && taint::isTainted(State, *NV))
emitReport(StOut, C, /*IsTainted=*/true);
}
-void ento::registerBoolAssignmentChecker(CheckerManager &mgr) {
- mgr.registerChecker<BoolAssignmentChecker>();
+void ento::registerBoolAssignmentChecker(CheckerManager &Mgr) {
+ Mgr.registerChecker<BoolAssignmentChecker>();
}
-bool ento::shouldRegisterBoolAssignmentChecker(const CheckerManager &mgr) {
+bool ento::shouldRegisterBoolAssignmentChecker(const CheckerManager &Mgr) {
return true;
}
More information about the cfe-commits
mailing list