[clang-tools-extra] [clang-tidy][NFC] Clean up and slightly optimize `modernize-use-integer-sign-comparison` (PR #163492)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 20 01:09:20 PDT 2025


================
@@ -119,23 +118,16 @@ void UseIntegerSignComparisonCheck::check(
   Expr::EvalResult EVResult;
   if (!SignedCastExpression->isValueDependent() &&
       SignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
-                                                        *Result.Context)) {
-    const llvm::APSInt SValue = EVResult.Val.getInt();
-    if (SValue.isNonNegative())
-      return;
-  }
+                                                        *Result.Context) &&
+      EVResult.Val.getInt().isNonNegative())
+    return;
 
   const auto *BinaryOp =
       Result.Nodes.getNodeAs<BinaryOperator>("intComparison");
-  if (BinaryOp == nullptr)
-    return;
-
-  const BinaryOperator::Opcode OpCode = BinaryOp->getOpcode();
+  assert(BinaryOp);
 
   const Expr *LHS = BinaryOp->getLHS()->IgnoreImpCasts();
   const Expr *RHS = BinaryOp->getRHS()->IgnoreImpCasts();
-  if (LHS == nullptr || RHS == nullptr)
-    return;
----------------
localspook wrote:

`IgnoreImpCasts` repeatedly applies this function to the `Expr` it's called on:
https://github.com/llvm/llvm-project/blob/4d6f43d64f07f5adc9f37212756794e20b4ae8c5/clang/include/clang/AST/IgnoreExpr.h#L48-L56
until it reaches a fixed point. I don't think `ImplicitCastExpr` or `FullExpr` can have a null subexpression, so I think this change is safe

https://github.com/llvm/llvm-project/pull/163492


More information about the cfe-commits mailing list