[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
https://github.com/vbvictor approved this pull request. https://github.com/llvm/llvm-project/pull/228666 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
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
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("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 00..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 &referenceTemplateArgument() {
+ return R;
+}
+int &useReferenceTemplateArgument() {
+ return referenceTemplateArgument();
+}
+
+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
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
- ` check by fixing a
false
- positive on the required parentheses of `typeof` and `typeof_unqual`
operands.
+ ` 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
` producing invalid
>From 71063bdb1bbc3e918fdabc3d3e53e20c61c7725a Mon Sep 17 00:00:00 2001
From: Andre Sun
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,
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
https://github.com/vbvictor auto_merge_enabled https://github.com/llvm/llvm-project/pull/228666 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
https://github.com/vbvictor closed https://github.com/llvm/llvm-project/pull/228666 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
@@ -93,6 +93,8 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder
*Finder) {
void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) {
const auto *PE = Result.Nodes.getNodeAs("dup");
+ if (PE->getLParen() == PE->getRParen())
+return;
and2049 wrote:
Moved it to an `isWritten` matcher on the outer `parenExpr`
https://github.com/llvm/llvm-project/pull/228666
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
https://github.com/and2049 updated
https://github.com/llvm/llvm-project/pull/228666
>From d90c4699880f29568c86b7c84b80b105a6677791 Mon Sep 17 00:00:00 2001
From: Andre Sun
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 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("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 000..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 &referenceTemplateArgument() {
+ return R;
+}
+int &useReferenceTemplateArgument() {
+ return referenceTemplateArgument();
+}
+
+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
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 41aa783cabd2487..ec39e65827132d7 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
- ` check by fixing a
false
- positive on the required parentheses of `typeof` and `typeof_unqual`
operands.
+ ` 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
` producing invalid
>From 71063bdb1bbc3e918fdabc3d3e53e20c61c7725a Mon Sep 17 00:00:00 2001
From: Andre Sun
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 75a11ffc02503b6..09dd53e83b54776 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,
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
@@ -93,6 +93,8 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder
*Finder) {
void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) {
const auto *PE = Result.Nodes.getNodeAs("dup");
+ if (PE->getLParen() == PE->getRParen())
+return;
vbvictor wrote:
This should be a custom ast matcher, something like `isWritten`.
Place it inside Finder->addMatcher(
parenExpr(
https://github.com/llvm/llvm-project/pull/228666
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
and2049 wrote: Added the release notes entry. https://github.com/llvm/llvm-project/pull/228666 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
https://github.com/and2049 updated
https://github.com/llvm/llvm-project/pull/228666
>From d90c4699880f29568c86b7c84b80b105a6677791 Mon Sep 17 00:00:00 2001
From: Andre Sun
Date: Sat, 3 Oct 2026 02:13:12 -0400
Subject: [PATCH 1/2] [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("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 00..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 &referenceTemplateArgument() {
+ return R;
+}
+int &useReferenceTemplateArgument() {
+ return referenceTemplateArgument();
+}
+
+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
Date: Sat, 3 Oct 2026 11:50:31 -0400
Subject: [PATCH 2/2] 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
- ` check by fixing a
false
- positive on the required parentheses of `typeof` and `typeof_unqual`
operands.
+ ` 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
` producing invalid
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
EugeneZelenko wrote: Please mention changes in Release Notes. https://github.com/llvm/llvm-project/pull/228666 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
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
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("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 000..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 &referenceTemplateArgument() {
+ return R;
+}
+int &useReferenceTemplateArgument() {
+ return referenceTemplateArgument();
+}
+
+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
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
https://github.com/zeyi2 commented: Please add a Release Note entry. https://github.com/llvm/llvm-project/pull/228666 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clang-tools-extra
Author: Andre Sun (and2049)
Changes
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/228666.diff
3 Files Affected:
- (modified)
clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp (+2)
- (added)
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp
(+8)
- (modified)
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
(+14)
``diff
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("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 00..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 &referenceTemplateArgument() {
+ return R;
+}
+int &useReferenceTemplateArgument() {
+ return referenceTemplateArgument();
+}
+
+extern "C" int printf(const char *, ...);
+struct Dumped { int x; };
+void dumpStruct(Dumped *d) {
+ __builtin_dump_struct(d, printf);
+}
+
struct Foo
{
bool x;
``
https://github.com/llvm/llvm-project/pull/228666
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Fix redundant-parentheses diagnosing synthetic parentheses (PR #228666)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clang-tidy
Author: Andre Sun (and2049)
Changes
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/228666.diff
3 Files Affected:
- (modified)
clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp (+2)
- (added)
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses-openmp.cpp
(+8)
- (modified)
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
(+14)
``diff
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("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 00..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 &referenceTemplateArgument() {
+ return R;
+}
+int &useReferenceTemplateArgument() {
+ return referenceTemplateArgument();
+}
+
+extern "C" int printf(const char *, ...);
+struct Dumped { int x; };
+void dumpStruct(Dumped *d) {
+ __builtin_dump_struct(d, printf);
+}
+
struct Foo
{
bool x;
``
https://github.com/llvm/llvm-project/pull/228666
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
