https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/182627

>From 9a862f048bcb456aed54118d0b6a80753c1a3f92 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <[email protected]>
Date: Fri, 20 Feb 2026 18:31:40 -0500
Subject: [PATCH 1/5] Change ``TryGetExprRange`` such that unsigned vectors get
 non negative ranges

---
 clang/lib/Sema/SemaChecking.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ba4b25961d70d..052828107a867 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11500,6 +11500,15 @@ static std::optional<IntRange> 
TryGetExprRange(ASTContext &C, const Expr *E,
                                Approximate);
       }
 
+      QualType T = E->getType();
+      if (const auto *VT = T->getAs<VectorType>()) {
+        QualType ElemTy = VT->getElementType();
+        if (ElemTy->isUnsignedIntegerType()) {
+          return TryGetExprRange(C, UO->getSubExpr(), MaxWidth,
+                                 InConstantContext, Approximate);
+        }
+      }
+
       std::optional<IntRange> SubRange = TryGetExprRange(
           C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
 
@@ -11518,6 +11527,15 @@ static std::optional<IntRange> 
TryGetExprRange(ASTContext &C, const Expr *E,
                                Approximate);
       }
 
+      QualType T = E->getType();
+
+      if (const auto *VT = T->getAs<VectorType>()) {
+        QualType ElemTy = VT->getElementType();
+        if (ElemTy->isUnsignedIntegerType()) {
+          return TryGetExprRange(C, UO->getSubExpr(), MaxWidth,
+                                 InConstantContext, Approximate);
+        }
+      }
       std::optional<IntRange> SubRange = TryGetExprRange(
           C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
 

>From 667aa51d47895a223972b672971400b2a8d550a0 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <[email protected]>
Date: Fri, 20 Feb 2026 19:02:27 -0500
Subject: [PATCH 2/5] Add tests and edit release notes

---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/test/Sema/compare.cpp | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 clang/test/Sema/compare.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 77e2078a5ffbf..18c3667894172 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -498,6 +498,8 @@ Improvements to Clang's diagnostics
 - Clang now generates a fix-it for C++20 designated initializers when the 
   initializers do not match the declaration order in the structure. 
 
+- Clang now doesn't throw assertion errors when comparing unsigned 
vectors(#173614)
+
 Improvements to Clang's time-trace
 ----------------------------------
 
diff --git a/clang/test/Sema/compare.cpp b/clang/test/Sema/compare.cpp
new file mode 100644
index 0000000000000..fb5d82847e2a0
--- /dev/null
+++ b/clang/test/Sema/compare.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only
+// Expect no assertion failures in this file (#173614).
+typedef unsigned long __attribute__((__vector_size__(8))) W;
+
+int i;
+W g;
+
+void negation(void) {
+  W w = i == (-g);
+}
+
+void bitwiseNot(void) {
+  W w = i == (~g);
+}

>From c1ef4e51f751885035449ac399ad33ed838697be Mon Sep 17 00:00:00 2001
From: Yutong Zhu <[email protected]>
Date: Mon, 23 Feb 2026 15:57:47 -0500
Subject: [PATCH 3/5] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Mariya Podchishchaeva <[email protected]>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 18c3667894172..74a75c1cd2fdf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -498,7 +498,7 @@ Improvements to Clang's diagnostics
 - Clang now generates a fix-it for C++20 designated initializers when the 
   initializers do not match the declaration order in the structure. 
 
-- Clang now doesn't throw assertion errors when comparing unsigned 
vectors(#173614)
+- Clang now doesn't throw assertion errors when comparing unsigned vectors 
(#GH173614).
 
 Improvements to Clang's time-trace
 ----------------------------------

>From 02f299633be2c056b28c53a59a33ecac5d22d4e6 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <[email protected]>
Date: Mon, 23 Feb 2026 17:11:55 -0500
Subject: [PATCH 4/5] Merge compare.cpp into compare.c

---
 clang/test/Sema/compare.c   | 15 +++++++++++++++
 clang/test/Sema/compare.cpp | 14 --------------
 2 files changed, 15 insertions(+), 14 deletions(-)
 delete mode 100644 clang/test/Sema/compare.cpp

diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index fdae3bc19841e..1dc9d0d878929 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -481,3 +481,18 @@ int test26(short n) {
   return ~n == 32768; // expected-warning {{result of comparison of 16-bit 
signed value == 32768 is always false}}
 }
 #endif
+
+typedef unsigned long __attribute__((__vector_size__(8))) W;
+void test27(void) {
+  int i;
+  W g;
+  // We expect no assertion failures here.
+  W w = i == (-g); // expected-warning {{}}
+}
+
+void test28(void) {
+  int i;
+  W g;
+  // We expect no assertion failures here.
+  W w = i == (~g); // expected-warning {{}}
+}
diff --git a/clang/test/Sema/compare.cpp b/clang/test/Sema/compare.cpp
deleted file mode 100644
index fb5d82847e2a0..0000000000000
--- a/clang/test/Sema/compare.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only
-// Expect no assertion failures in this file (#173614).
-typedef unsigned long __attribute__((__vector_size__(8))) W;
-
-int i;
-W g;
-
-void negation(void) {
-  W w = i == (-g);
-}
-
-void bitwiseNot(void) {
-  W w = i == (~g);
-}

>From 2644c2cd00cee6d5b9bb0e233abc397c49bf6cb1 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <[email protected]>
Date: Mon, 2 Mar 2026 13:47:47 -0500
Subject: [PATCH 5/5] "Deduplicate the type checking logic and tests"

---
 clang/lib/Sema/SemaChecking.cpp | 28 ++++++++--------------------
 clang/test/Sema/compare.c       | 10 ++--------
 2 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 052828107a867..d8c8884547f21 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11223,6 +11223,12 @@ static QualType GetExprType(const Expr *E) {
   return Ty;
 }
 
+static bool isUnsignedScalarType(QualType T) {
+  if (const auto *VT = T->getAs<VectorType>())
+    T = VT->getElementType();
+  return T->isUnsignedIntegerType();
+}
+
 /// Attempts to estimate an approximate range for the given integer expression.
 /// Returns a range if successful, otherwise it returns \c std::nullopt if a
 /// reliable estimation cannot be determined.
@@ -11495,20 +11501,11 @@ static std::optional<IntRange> 
TryGetExprRange(ASTContext &C, const Expr *E,
       return IntRange::forValueOfType(C, GetExprType(E));
 
     case UO_Minus: {
-      if (E->getType()->isUnsignedIntegerType()) {
+      if (isUnsignedScalarType(E->getType())) {
         return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,
                                Approximate);
       }
 
-      QualType T = E->getType();
-      if (const auto *VT = T->getAs<VectorType>()) {
-        QualType ElemTy = VT->getElementType();
-        if (ElemTy->isUnsignedIntegerType()) {
-          return TryGetExprRange(C, UO->getSubExpr(), MaxWidth,
-                                 InConstantContext, Approximate);
-        }
-      }
-
       std::optional<IntRange> SubRange = TryGetExprRange(
           C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
 
@@ -11522,20 +11519,11 @@ static std::optional<IntRange> 
TryGetExprRange(ASTContext &C, const Expr *E,
     }
 
     case UO_Not: {
-      if (E->getType()->isUnsignedIntegerType()) {
+      if (isUnsignedScalarType(E->getType())) {
         return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,
                                Approximate);
       }
 
-      QualType T = E->getType();
-
-      if (const auto *VT = T->getAs<VectorType>()) {
-        QualType ElemTy = VT->getElementType();
-        if (ElemTy->isUnsignedIntegerType()) {
-          return TryGetExprRange(C, UO->getSubExpr(), MaxWidth,
-                                 InConstantContext, Approximate);
-        }
-      }
       std::optional<IntRange> SubRange = TryGetExprRange(
           C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
 
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index 1dc9d0d878929..e9e4f17f825ef 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -487,12 +487,6 @@ void test27(void) {
   int i;
   W g;
   // We expect no assertion failures here.
-  W w = i == (-g); // expected-warning {{}}
-}
-
-void test28(void) {
-  int i;
-  W g;
-  // We expect no assertion failures here.
-  W w = i == (~g); // expected-warning {{}}
+  W w1 = i == (-g); // expected-warning {{}}
+  W w2 = i == (~g); // expected-warning {{}}
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to