[clang-tools-extra] [clang-tidy][NFCI] Simplify bugprone-sizeof-expression (PR #93024)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Wed May 22 04:58:17 PDT 2024


https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/93024

This commit eliminates a redundant matcher subexpression from the implementation of the "sizeof-pointer-to-aggregate" part of the clang-tidy check `bugprone-sizeof-expression`.

I'm fairly certain that anything that was previously matched by the deleted matcher `StructAddrOfExpr` is also covered by the more general `PointerToStructExpr` (which remains in the same `anyOf`).

This commit is made to "prepare the ground" for a followup change that would merge the functionality of the Clang Static Analyzer checker `alpha.core.SizeofPtr` into this clang-tidy check.

>From b7fb1707601c73bd53b6ac810cd39a94f5b3cd53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <donat.nagy at ericsson.com>
Date: Wed, 22 May 2024 13:45:13 +0200
Subject: [PATCH] [clang-tidy][NFCI] Simplify bugprone-sizeof-expression

This commit eliminates a redundant matcher subexpression from the
implementation of the "sizeof-pointer-to-aggregate" part of the
clang-tidy check `bugprone-sizeof-expression`.

I'm fairly certain that anything that was previously matched by the
deleted matcher `StructAddrOfExpr` is also covered by the more general
`PointerToStructExpr` (which remains in the same `anyOf`).

This commit is made to "prepare the ground" for a followup change that
would merge the functionality of the Clang Static Analyzer checker
`alpha.core.SizeofPtr` into this clang-tidy check.
---
 .../clang-tidy/bugprone/SizeofExpressionCheck.cpp        | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index a1cffbc666199..f119711638111 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -147,9 +147,6 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
     const auto PointerToArrayExpr = ignoringParenImpCasts(
         hasType(hasCanonicalType(pointerType(pointee(arrayType())))));
 
-    const auto StructAddrOfExpr = unaryOperator(
-        hasOperatorName("&"), hasUnaryOperand(ignoringParenImpCasts(
-                                  hasType(hasCanonicalType(recordType())))));
     const auto PointerToStructType =
         hasUnqualifiedDesugaredType(pointerType(pointee(recordType())));
     const auto PointerToStructExpr = ignoringParenImpCasts(expr(
@@ -171,9 +168,9 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
                                            has(ArrayOfPointersExpr)))))))),
              sizeOfExpr(has(ArrayOfSamePointersZeroSubscriptExpr)));
 
-    Finder->addMatcher(expr(anyOf(sizeOfExpr(has(ignoringParenImpCasts(anyOf(
-                                      ArrayCastExpr, PointerToArrayExpr,
-                                      StructAddrOfExpr, PointerToStructExpr)))),
+    Finder->addMatcher(expr(anyOf(sizeOfExpr(has(ignoringParenImpCasts(
+                                      anyOf(ArrayCastExpr, PointerToArrayExpr,
+                                            PointerToStructExpr)))),
                                   sizeOfExpr(has(PointerToStructType))),
                             unless(ArrayLengthExprDenom))
                            .bind("sizeof-pointer-to-aggregate"),



More information about the cfe-commits mailing list