https://github.com/flovent updated 
https://github.com/llvm/llvm-project/pull/141345

>From e6c5673a6b7b7f73ddf4b1f14391757313a65485 Mon Sep 17 00:00:00 2001
From: flovent <flb...@protonmail.com>
Date: Sat, 24 May 2025 21:29:53 +0800
Subject: [PATCH 1/2] [clang-tidy] Add check for assignment or comparision
 operators' operand in `readability-math-missing-parentheses`

---
 .../readability/MathMissingParenthesesCheck.cpp  | 16 +++++++++-------
 clang-tools-extra/docs/ReleaseNotes.rst          |  5 +++++
 .../readability/math-missing-parentheses.cpp     | 14 ++++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index 64ce94e3fc1db..d867c94242f9b 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -16,13 +16,15 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::readability {
 
 void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
-                                    unless(isAssignmentOperator()),
-                                    unless(isComparisonOperator()),
-                                    unless(hasAnyOperatorName("&&", "||")),
-                                    hasDescendant(binaryOperator()))
-                         .bind("binOp"),
-                     this);
+  Finder->addMatcher(
+      binaryOperator(
+          unless(hasParent(binaryOperator(unless(isAssignmentOperator()),
+                                          unless(isComparisonOperator())))),
+          unless(isAssignmentOperator()), unless(isComparisonOperator()),
+          unless(hasAnyOperatorName("&&", "||")),
+          hasDescendant(binaryOperator()))
+          .bind("binOp"),
+      this);
 }
 
 static int getPrecedence(const BinaryOperator *BinOp) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8032f0d23f494..a7530a236e9ec 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,11 @@ Changes in existing checks
   <clang-tidy/checks/concurrency/mt-unsafe>` check by fixing a false positive
   where ``strerror`` was flagged as MT-unsafe.
 
+- Improved :doc:`readability-math-missing-parentheses
+  <clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
+  false negatives where math expressions are the operand of assignment 
operators
+  or comparison operators.
+
 - Improved :doc:`misc-const-correctness
   <clang-tidy/checks/misc/const-correctness>` check by adding the option
   `AllowedTypes`, that excludes specified types from const-correctness
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
index 80d2bc304bb5b..5c10ed59178d8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
@@ -157,3 +157,17 @@ namespace PR92516 {
     for (j = i + 1, 2; j < 1; ++j) {}
   }
 }
+
+namespace PR141249 {
+  void AssignAsParentBinOp(int* netChange, int* nums, int k, int i) {
+    //CHECK-MESSAGES: :[[@LINE+1]]:30: warning: '-' has higher precedence than 
'^'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+    netChange[i] = nums[i] ^ k - nums[i];
+  }
+}
+
+void CompareAsParentBinOp(int b) {
+  //CHECK-MESSAGES: :[[@LINE+1]]:12: warning: '*' has higher precedence than 
'-'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
+  if (b == 1 * 2 - 3)   {
+
+  }
+}

>From 7d4d9e12c68f359ad338f6a9bb7e7e874305f04c Mon Sep 17 00:00:00 2001
From: flovent <flb...@protonmail.com>
Date: Sat, 24 May 2025 22:41:31 +0800
Subject: [PATCH 2/2] keep alpha order of note

---
 clang-tools-extra/docs/ReleaseNotes.rst | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a7530a236e9ec..2f859e47d0b70 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,11 +176,6 @@ Changes in existing checks
   <clang-tidy/checks/concurrency/mt-unsafe>` check by fixing a false positive
   where ``strerror`` was flagged as MT-unsafe.
 
-- Improved :doc:`readability-math-missing-parentheses
-  <clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
-  false negatives where math expressions are the operand of assignment 
operators
-  or comparison operators.
-
 - Improved :doc:`misc-const-correctness
   <clang-tidy/checks/misc/const-correctness>` check by adding the option
   `AllowedTypes`, that excludes specified types from const-correctness
@@ -239,6 +234,11 @@ Changes in existing checks
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
 
+- Improved :doc:`readability-math-missing-parentheses
+  <clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
+  false negatives where math expressions are the operand of assignment 
operators
+  or comparison operators.
+
 Removed checks
 ^^^^^^^^^^^^^^
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to