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

[analyzer][NFC] Simplify BugType handling in core.BitwiseShift #74609

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

NagyDonat
Copy link
Contributor

Eliminate the mutable unique_ptr hack because it's no longer needed. (This cleanup could be done anywhere, I'm doing it here now because it was me who published this checker with the old hack when it was already superfluous.)

Eliminate the `mutable unique_ptr` hack because it's no longer needed.
(This cleanup could be done anywhere, I'm doing it here now because it
was me who published this checker with the old hack when it was already
superfluous.)
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Dec 6, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 6, 2023

@llvm/pr-subscribers-clang

Author: None (DonatNagyE)

Changes

Eliminate the mutable unique_ptr hack because it's no longer needed. (This cleanup could be done anywhere, I'm doing it here now because it was me who published this checker with the old hack when it was already superfluous.)


Full diff: https://github.com/llvm/llvm-project/pull/74609.diff

1 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp (+2-6)
diff --git a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
index d4aa9fa1339f4..339927c165fe0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
@@ -344,7 +344,7 @@ BitwiseShiftValidator::createBugReport(StringRef ShortMsg, StringRef Msg) const
 } // anonymous namespace
 
 class BitwiseShiftChecker : public Checker<check::PreStmt<BinaryOperator>> {
-  mutable std::unique_ptr<BugType> BTPtr;
+  BugType BT{this, "Bitwise shift", "Suspicious operation"};
 
 public:
   void checkPreStmt(const BinaryOperator *B, CheckerContext &Ctx) const {
@@ -353,11 +353,7 @@ class BitwiseShiftChecker : public Checker<check::PreStmt<BinaryOperator>> {
     if (Op != BO_Shl && Op != BO_Shr)
       return;
 
-    if (!BTPtr)
-      BTPtr = std::make_unique<BugType>(this, "Bitwise shift",
-                                        "Suspicious operation");
-
-    BitwiseShiftValidator(B, Ctx, *BTPtr, Pedantic).run();
+    BitwiseShiftValidator(B, Ctx, BT, Pedantic).run();
   }
 
   bool Pedantic = false;

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 6, 2023

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

Author: None (DonatNagyE)

Changes

Eliminate the mutable unique_ptr hack because it's no longer needed. (This cleanup could be done anywhere, I'm doing it here now because it was me who published this checker with the old hack when it was already superfluous.)


Full diff: https://github.com/llvm/llvm-project/pull/74609.diff

1 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp (+2-6)
diff --git a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
index d4aa9fa1339f4..339927c165fe0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
@@ -344,7 +344,7 @@ BitwiseShiftValidator::createBugReport(StringRef ShortMsg, StringRef Msg) const
 } // anonymous namespace
 
 class BitwiseShiftChecker : public Checker<check::PreStmt<BinaryOperator>> {
-  mutable std::unique_ptr<BugType> BTPtr;
+  BugType BT{this, "Bitwise shift", "Suspicious operation"};
 
 public:
   void checkPreStmt(const BinaryOperator *B, CheckerContext &Ctx) const {
@@ -353,11 +353,7 @@ class BitwiseShiftChecker : public Checker<check::PreStmt<BinaryOperator>> {
     if (Op != BO_Shl && Op != BO_Shr)
       return;
 
-    if (!BTPtr)
-      BTPtr = std::make_unique<BugType>(this, "Bitwise shift",
-                                        "Suspicious operation");
-
-    BitwiseShiftValidator(B, Ctx, *BTPtr, Pedantic).run();
+    BitwiseShiftValidator(B, Ctx, BT, Pedantic).run();
   }
 
   bool Pedantic = false;

Copy link
Collaborator

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

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

Thanks!

@NagyDonat NagyDonat merged commit e4c7ee3 into llvm:main Dec 7, 2023
6 checks passed
@NagyDonat NagyDonat deleted the bitwiseshift_cleanup_bt branch December 7, 2023 09:23
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