[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
Andre Sun via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 23:20:43 PDT 2026
https://github.com/and2049 created https://github.com/llvm/llvm-project/pull/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.
>From d90c4699880f29568c86b7c84b80b105a6677791 Mon Sep 17 00:00:00 2001
From: Andre Sun <andsun9999 at gmail.com>
Date: Sat, 3 Oct 2026 02:13:12 -0400
Subject: [PATCH] [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 bc1d10586da8abb..75a11ffc02503b6 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 000000000000000..98e9c36fb0a8634
--- /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 c6275be9f249880..12286cd513f8533 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;
More information about the cfe-commits
mailing list