[clang] [clang][analyzer] Reformat code of BoolAssignmentChecker (NFC). (PR #81461)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 02:25:21 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Balázs Kéri (balazske)
<details>
<summary>Changes</summary>
This is only a code reformatting and rename of variables to the newer format.
---
Full diff: https://github.com/llvm/llvm-project/pull/81461.diff
1 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/BoolAssignmentChecker.cpp (+27-28)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/81461
More information about the cfe-commits
mailing list