[clang] [analyzer][NFC] Simplify BugType handling in core.BitwiseShift (PR #74609)

via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 6 07:39:16 PST 2023


https://github.com/DonatNagyE created https://github.com/llvm/llvm-project/pull/74609

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.)

>From ed7f7e6983d93dffac225ea7594e9efa0b8d52ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <donat.nagy at ericsson.com>
Date: Wed, 6 Dec 2023 16:33:48 +0100
Subject: [PATCH] [analyzer][NFC] Simplify BugType handling in
 core.BitwiseShift

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.)
---
 clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

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;



More information about the cfe-commits mailing list