Author: Andre Sun Date: 2026-10-07T10:40:08Z New Revision: 448badfab126bdee384360a9355fa707068203c2
URL: https://github.com/llvm/llvm-project/commit/448badfab126bdee384360a9355fa707068203c2 DIFF: https://github.com/llvm/llvm-project/commit/448badfab126bdee384360a9355fa707068203c2.diff LOG: [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (#228666) Skip synthetic parentheses with identical source locations in `readability-redundant-parentheses`. This also stops `__builtin_dump_struct(&s, printf)` from being rewritten to `(&s, printf)` and stops variables being deleted from OpenMP `linear` clauses. Fixes #224705. --------- Co-authored-by: Baranov Victor <[email protected]> Added: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp Modified: clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp clang-tools-extra/docs/ReleaseNotes.md clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp index bc1d10586da8a..09dd53e83b547 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()), diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md index 20b612509d7f7..b973c3f1f4a0e 100644 --- a/clang-tools-extra/docs/ReleaseNotes.md +++ b/clang-tools-extra/docs/ReleaseNotes.md @@ -328,8 +328,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 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 0000000000000..98e9c36fb0a86 --- /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 c6275be9f2498..12286cd513f85 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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
