[clang-tools-extra] [clang-tidy] Detect std::rot[lr] pattern within modernize.use-std-bit (PR #186324)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 13 02:30:44 PDT 2026
================
@@ -141,6 +154,48 @@ void UseStdBitCheck::check(const MatchFinder::MatchResult &Result) {
<< IncludeInserter.createIncludeInsertion(
Source.getFileID(MatchedExpr->getBeginLoc()), "<bit>");
}
+ } else if (const auto *MatchedExpr =
+ Result.Nodes.getNodeAs<BinaryOperator>("rotate_expr")) {
+ const auto *MatchedVarDecl = Result.Nodes.getNodeAs<VarDecl>("v");
+ const auto ShiftLeftAmount =
+ Result.Nodes.getNodeAs<IntegerLiteral>("shift_left_amount")->getValue();
+ const auto ShiftRightAmount =
+ Result.Nodes.getNodeAs<IntegerLiteral>("shift_right_amount")
+ ->getValue();
----------------
localspook wrote:
Prefer spelling out the type here, since it's not immediately clear from the initializer
```suggestion
const llvm::APInt ShiftLeftAmount =
Result.Nodes.getNodeAs<IntegerLiteral>("shift_left_amount")->getValue();
const llvm::APInt ShiftRightAmount =
Result.Nodes.getNodeAs<IntegerLiteral>("shift_right_amount")
->getValue();
```
https://github.com/llvm/llvm-project/pull/186324
More information about the cfe-commits
mailing list