Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang][analyzer] Reformat code of BoolAssignmentChecker (NFC). #81461

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

balazske
Copy link
Collaborator

This is only a code reformatting and rename of variables to the newer format.

This is only a code reformatting and rename of variables to the
newer format.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Feb 12, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 12, 2024

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)

Changes

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 --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;
 }

Copy link
Contributor

@NagyDonat NagyDonat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just trivial cleanup, I think you can merge this PR whenever you want.

@balazske balazske merged commit a2eb234 into llvm:main Feb 14, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants