Author: Yutong Zhu
Date: 2026-09-22T08:41:40-04:00
New Revision: cec2eeb8ff2f1075b036d9bfd06c365d006bc972

URL: 
https://github.com/llvm/llvm-project/commit/cec2eeb8ff2f1075b036d9bfd06c365d006bc972
DIFF: 
https://github.com/llvm/llvm-project/commit/cec2eeb8ff2f1075b036d9bfd06c365d006bc972.diff

LOG: [Clang] Fix assertion "unsigned range includes negative?" in 
AnalyzeComparison during Sema of vector comparison with mismatched 
signed/unsigned types and __builtin_convertvector  (#182627)

The ``TryGetExprRange`` function now checks if the operand is an unsigned
vector when computing the ranges.

Fixes #173614

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.md
    clang/test/Sema/compare.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index ba944a62a1fff..da561d8b57204 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -284,6 +284,11 @@ features cannot lower the translation-unit ABI level;
 
 ### Improvements to Clang's diagnostics
 
+- Clang now doesn't throw assertion errors when comparing unsigned vector types
+  (#GH173614).
+
+- `-Wfortify-source` now diagnoses when `strlcat` or `__builtin_strlcat` is 
called with a size
+  argument larger than the destination buffer.
 - `-Wfortify-source` now diagnoses when `strlcat`, `__builtin_strlcat`, 
`strlcpy`, or
   `__builtin_strlcpy` is called with a size argument larger than the 
destination buffer.
 

diff  --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index d01c33d61dc8c..54cc3ffcaf5dc 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtautological-constant-in-range-compare %s 
-Wno-unreachable-code -DTEST=1
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtype-limits %s -Wno-unreachable-code -DTEST=2
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtautological-constant-in-range-compare %s 
-Wno-unreachable-code -fenable-matrix -DTEST=1
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -Wtype-limits %s -Wno-unreachable-code -fenable-matrix -DTEST=2
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-pedantic -verify -Wsign-compare -Wtype-limits -fsyntax-only %s -fenable-matrix 
-DTEST=3
 
 int test(char *C) { // nothing here should warn.
   return C != ((void*)0);
@@ -482,6 +483,63 @@ int test26(short n) {
 }
 #endif
 
+typedef unsigned long __attribute__((__vector_size__(8))) V;
+
+void test27(void) {
+  int i;
+  V v;
+  
+  V v1 = i == (-v);
+  // expected-warning@-1 {{comparison of integers of 
diff erent signs: 'int' and 'V'}}
+  
+  V v2 = i == (+v);
+  // expected-warning@-1 {{comparison of integers of 
diff erent signs: 'int' and 'V'}}
+  
+  V v3 = i == (~v);
+  // expected-warning@-1 {{comparison of integers of 
diff erent signs: 'int' and 'V'}}
+  
+  V v4 = i == (!v);
+  // expected-error@-1 {{invalid argument type 'V' (vector of 1 'unsigned 
long' value) to unary expression}}
+  
+  V v5 = i == (++v);
+  // expected-error@-1 {{cannot increment value of type 'V'}}
+  
+  V v6 = i == (v++);
+  // expected-error@-1 {{cannot increment value of type 'V'}}
+  
+  V v7 = i == (--v);
+  // expected-error@-1 {{cannot decrement value of type 'V'}}
+  
+  V v8 = i == (v--);
+  // expected-error@-1 {{cannot decrement value of type 'V'}}
+  
+  V v9 = i == (*v);
+  // expected-error@-1 {{indirection requires pointer operand ('V' (vector of 
1 'unsigned long' value) invalid)}}
+}
+
+typedef unsigned long __attribute__((matrix_type(8, 8))) M;
+
+void test28(void) {
+  int i;
+  M m;
+
+  M m1 = i == (-m);
+  // expected-error@-1 {{invalid argument type 'M' (aka 'unsigned long 
__attribute__((matrix_type(8, 8)))') to unary expression}}
+  M m2 = i == (~m);
+  // expected-error@-1 {{invalid argument type 'M' (aka 'unsigned long 
__attribute__((matrix_type(8, 8)))') to unary expression}}
+}
+
+#if TEST == 3
+#include <arm_sve.h>
+void test29(void) {
+  int i;
+  svuint8_t v = svdup_u8(5);
+  svuint8_t v1 = i == (-v); 
+  // expected-error@-1 {{cannot convert between scalar type 'int' and vector 
type 'svuint8_t' (aka '__SVUint8_t') as implicit conversion would cause 
truncation}}
+  svuint8_t v2 = i == (~v);
+  // expected-error@-1 {{cannot convert between scalar type 'int' and vector 
type 'svuint8_t' (aka '__SVUint8_t') as implicit conversion would cause 
truncation}}
+}
+#endif
 // GH203575
 typedef unsigned gh203575_uvec __attribute__((__vector_size__(sizeof(int))));
 


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

Reply via email to