[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 7 03:49:41 PST 2025


================
@@ -1060,19 +1210,24 @@ class IncrementGadget : public WarningGadget {
   const UnaryOperator *Op;
 
 public:
-  IncrementGadget(const MatchFinder::MatchResult &Result)
+  IncrementGadget(const MatchResult &Result)
       : WarningGadget(Kind::Increment),
-        Op(Result.Nodes.getNodeAs<UnaryOperator>(OpTag)) {}
+        Op(Result.getNodeAs<UnaryOperator>(OpTag)) {}
 
   static bool classof(const Gadget *G) {
     return G->getKind() == Kind::Increment;
   }
 
-  static Matcher matcher() {
-    return stmt(
-        unaryOperator(hasOperatorName("++"),
-                      hasUnaryOperand(ignoringParenImpCasts(hasPointerType())))
-            .bind(OpTag));
+  static bool matches(const Stmt *S, const ASTContext &Ctx,
+                      MatchResult &Result) {
+    const auto *UO = dyn_cast<UnaryOperator>(S);
+    if (!UO || !UO->isIncrementOp())
+      return false;
+    const auto *Operand = UO->getSubExpr()->IgnoreParenImpCasts();
+    if (!hasPointerType(*Operand))
----------------
ilya-biryukov wrote:

NIT: Maybe inline `Operand` to avoid having an extra variable?

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


More information about the cfe-commits mailing list