https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/228666
>From d90c4699880f29568c86b7c84b80b105a6677791 Mon Sep 17 00:00:00 2001 From: Andre Sun <[email protected]> Date: Sat, 3 Oct 2026 02:13:12 -0400 Subject: [PATCH 1/3] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses Fixes #224705. --- .../readability/RedundantParenthesesCheck.cpp | 2 ++ .../readability/redundant-parentheses-openmp.cpp | 8 ++++++++ .../checkers/readability/redundant-parentheses.cpp | 14 ++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp diff --git a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp index bc1d10586da8ab..75a11ffc02503b 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp @@ -93,6 +93,8 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder *Finder) { void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) { const auto *PE = Result.Nodes.getNodeAs<ParenExpr>("dup"); + if (PE->getLParen() == PE->getRParen()) + return; diag(PE->getBeginLoc(), "redundant parentheses around expression") << createSpacedRemoval(PE->getLParen(), *Result.SourceManager, getLangOpts()) diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp new file mode 100644 index 00000000000000..98e9c36fb0a863 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp @@ -0,0 +1,8 @@ +// RUN: %check_clang_tidy %s readability-redundant-parentheses %t -- -- -fopenmp=libomp + +void linearClause(int *a, int n) { + int i = 0; +#pragma omp simd linear(i) + for (int k = 0; k < n; ++k) + a[k] = i; +} diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp index c6275be9f24988..12286cd513f853 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp @@ -74,6 +74,20 @@ void ignoreStdMaxMin() { (std::min)(1,2); } +int global = 0; +template <int &R> int &referenceTemplateArgument() { + return R; +} +int &useReferenceTemplateArgument() { + return referenceTemplateArgument<global>(); +} + +extern "C" int printf(const char *, ...); +struct Dumped { int x; }; +void dumpStruct(Dumped *d) { + __builtin_dump_struct(d, printf); +} + struct Foo { bool x; >From 02341fa5bb4f9d4738cfaa6f946e975c8d17a8eb Mon Sep 17 00:00:00 2001 From: Andre Sun <[email protected]> Date: Sat, 3 Oct 2026 11:50:31 -0400 Subject: [PATCH 2/3] Document fix in release notes --- clang-tools-extra/docs/ReleaseNotes.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md index 41aa783cabd248..ec39e65827132d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.md +++ b/clang-tools-extra/docs/ReleaseNotes.md @@ -319,8 +319,14 @@ infrastructure are described first, followed by tool-specific sections. `atomic_compare_exchange_strong()`. - Improved {doc}`readability-redundant-parentheses - <clang-tidy/checks/readability/redundant-parentheses>` check by fixing a false - positive on the required parentheses of `typeof` and `typeof_unqual` operands. + <clang-tidy/checks/readability/redundant-parentheses>` check: + + - Fixed a false positive on the required parentheses of `typeof` and + `typeof_unqual` operands. + + - Fixed false positives and incorrect fixes caused by synthetic parentheses + in reference non-type template parameter uses, `__builtin_dump_struct` calls, + and OpenMP `linear` clauses. - Fixed {doc}`readability-simplify-boolean-expr <clang-tidy/checks/readability/simplify-boolean-expr>` producing invalid >From 71063bdb1bbc3e918fdabc3d3e53e20c61c7725a Mon Sep 17 00:00:00 2001 From: Andre Sun <[email protected]> Date: Sat, 3 Oct 2026 12:25:39 -0400 Subject: [PATCH 3/3] Use AST matcher --- .../clang-tidy/readability/RedundantParenthesesCheck.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp index 75a11ffc02503b..09dd53e83b5477 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp @@ -34,6 +34,10 @@ AST_MATCHER(ParenExpr, isInMacro) { E->getBeginLoc().isMacroID() || E->getEndLoc().isMacroID(); } +AST_MATCHER(ParenExpr, isWritten) { + return Node.getLParen() != Node.getRParen(); +} + AST_MATCHER(TypeLoc, isTypeOfExprTypeLoc) { return !Node.getUnqualifiedLoc().getAs<TypeOfExprTypeLoc>().isNull(); } @@ -82,6 +86,7 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder *Finder) { callExpr(unless(cxxOperatorCallExpr( unless(hasAnyOperatorName("()", "[]"))))), arraySubscriptExpr())), + isWritten(), unless(anyOf(isInMacro(), // sizeof(...) is common used. hasParent(unaryExprOrTypeTraitExpr()), @@ -93,8 +98,6 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder *Finder) { void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) { const auto *PE = Result.Nodes.getNodeAs<ParenExpr>("dup"); - if (PE->getLParen() == PE->getRParen()) - return; diag(PE->getBeginLoc(), "redundant parentheses around expression") << createSpacedRemoval(PE->getLParen(), *Result.SourceManager, getLangOpts()) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
