[clang] [Clang] Fix assertion "unsigned range includes negative?" in AnalyzeComparison during Sema of vector comparison with mismatched signed/unsigned types and __builtin_convertvector (PR #182627)
Yutong Zhu via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 22:00:42 PDT 2026
https://github.com/YutongZhuu updated https://github.com/llvm/llvm-project/pull/182627
>From 4f5a57f96fb1e48b400b7da31181f3e1e9ffd347 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Fri, 20 Feb 2026 18:31:40 -0500
Subject: [PATCH 01/10] 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 f0a1a529841b2..920841fb4004e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12229,6 +12229,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);
@@ -12247,6 +12256,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 6f334c6e245d4564671447d315bc4cf900e7190c Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Fri, 20 Feb 2026 19:02:27 -0500
Subject: [PATCH 02/10] Add tests and edit release notes
---
clang/docs/ReleaseNotes.md | 3 +++
clang/test/Sema/compare.cpp | 14 ++++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 clang/test/Sema/compare.cpp
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index cd59d6e942a35..7438954928a38 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -281,6 +281,9 @@ features cannot lower the translation-unit ABI level;
### Improvements to Clang's diagnostics
+- Clang now doesn't throw assertion errors when comparing unsigned vectors
+ (#GH173614).
+
- `-Wfortify-source` now diagnoses when `strlcat` or `__builtin_strlcat` is called with a size
argument larger than the destination buffer.
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 7443407d39b24413819e3712d502f2eacab356d9 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Mon, 23 Feb 2026 17:11:55 -0500
Subject: [PATCH 03/10] 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 5cc09e54b77efe17dfe6087799c0533785ddf9fc Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Mon, 2 Mar 2026 13:50:06 -0500
Subject: [PATCH 04/10] 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 920841fb4004e..fcc045905ce82 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11952,6 +11952,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.
@@ -12224,20 +12230,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);
@@ -12251,20 +12248,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 {{}}
}
>From 10ad2580fa52f9872064d69b1ab6818d96586a18 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Mon, 2 Mar 2026 14:49:56 -0500
Subject: [PATCH 05/10] Change function name to be clearer
---
clang/lib/Sema/SemaChecking.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index fcc045905ce82..c6af80dbb9999 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11952,7 +11952,7 @@ static QualType GetExprType(const Expr *E) {
return Ty;
}
-static bool isUnsignedScalarType(QualType T) {
+static bool isUnsignedIntegerOrVectorElementType(QualType T) {
if (const auto *VT = T->getAs<VectorType>())
T = VT->getElementType();
return T->isUnsignedIntegerType();
@@ -12230,7 +12230,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
return IntRange::forValueOfType(C, GetExprType(E));
case UO_Minus: {
- if (isUnsignedScalarType(E->getType())) {
+ if (isUnsignedIntegerOrVectorElementType(E->getType())) {
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
Approximate);
}
@@ -12248,7 +12248,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
}
case UO_Not: {
- if (isUnsignedScalarType(E->getType())) {
+ if (isUnsignedIntegerOrVectorElementType(E->getType())) {
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
Approximate);
}
>From 3dd6c0f7ad14642d2ab8f33a74f41daf091f8819 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Tue, 28 Apr 2026 20:03:42 -0400
Subject: [PATCH 06/10] Address comments 1. Refactor the type check helper
function into Type.cpp 2. Edit release notes
---
clang/docs/ReleaseNotes.md | 2 +-
clang/include/clang/AST/TypeBase.h | 6 +++++-
clang/lib/AST/Type.cpp | 6 ++++++
clang/lib/Sema/SemaChecking.cpp | 10 ++--------
clang/test/Sema/compare.c | 31 +++++++++++++++++++++++++++---
5 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 7438954928a38..5e0491e5b2f3d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -281,7 +281,7 @@ features cannot lower the translation-unit ABI level;
### Improvements to Clang's diagnostics
-- Clang now doesn't throw assertion errors when comparing unsigned vectors
+- 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
diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h
index 9edf8a0ce9c68..e96d311de4ce3 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -3096,10 +3096,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// enumeration types whose underlying type is a signed integer type.
bool isSignedIntegerOrEnumerationType() const;
- /// Determines whether this is an integer type that is unsigned or an
+ /// Return true if this is an integer type that is unsigned or an
/// enumeration types whose underlying type is a unsigned integer type.
bool isUnsignedIntegerOrEnumerationType() const;
+ // Determine whether this is an unsigned integer type or an unsigned integer
+ // vector type.
+ bool isUnsignedIntegerOrVectorType() const;
+
/// Return true if this is a fixed point type according to
/// ISO/IEC JTC1 SC22 WG14 N1169.
bool isFixedPointType() const;
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4b539b7c2b1f6..387cb335fadf4 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2405,6 +2405,12 @@ bool Type::isUnsignedIntegerOrEnumerationType() const {
return false;
}
+bool Type::isUnsignedIntegerOrVectorType() const {
+ if (const auto *VT = getAs<VectorType>())
+ return VT->getElementType()->isUnsignedIntegerType();
+ return isUnsignedIntegerType();
+}
+
bool Type::hasUnsignedIntegerRepresentation() const {
if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c6af80dbb9999..89d01eebc7333 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11952,12 +11952,6 @@ static QualType GetExprType(const Expr *E) {
return Ty;
}
-static bool isUnsignedIntegerOrVectorElementType(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.
@@ -12230,7 +12224,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
return IntRange::forValueOfType(C, GetExprType(E));
case UO_Minus: {
- if (isUnsignedIntegerOrVectorElementType(E->getType())) {
+ if (E->getType()->isUnsignedIntegerOrVectorType()) {
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
Approximate);
}
@@ -12248,7 +12242,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
}
case UO_Not: {
- if (isUnsignedIntegerOrVectorElementType(E->getType())) {
+ if (E->getType()->isUnsignedIntegerOrVectorType()) {
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
Approximate);
}
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index e9e4f17f825ef..953237d3c7419 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -483,10 +483,35 @@ int test26(short n) {
#endif
typedef unsigned long __attribute__((__vector_size__(8))) W;
+
void test27(void) {
int i;
W g;
- // We expect no assertion failures here.
- W w1 = i == (-g); // expected-warning {{}}
- W w2 = i == (~g); // expected-warning {{}}
+
+ W w1 = i == (-g);
+ // expected-warning at -1 {{}}
+
+ W w3 = i == (+g);
+ // expected-warning at -1 {{}}
+
+ W w2 = i == (~g);
+ // expected-warning at -1 {{}}
+
+ W w4 = i == (!g);
+ // expected-error at -1 {{}}
+
+ W w5 = i == (++g);
+ // expected-error at -1 {{}}
+
+ W w6 = i == (g++);
+ // expected-error at -1 {{}}
+
+ W w7 = i == (--g);
+ // expected-error at -1 {{}}
+
+ W w8 = i == (g--);
+ // expected-error at -1 {{}}
+
+ W w9 = i == (*g);
+ // expected-error at -1 {{}}
}
>From a1dbe99e89a76f05b94044b6e901238df6c878b5 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Tue, 28 Apr 2026 23:41:49 -0400
Subject: [PATCH 07/10] Spell out warning and error messages
---
clang/test/Sema/compare.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index 953237d3c7419..0b9517a62a7b7 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -489,29 +489,29 @@ void test27(void) {
W g;
W w1 = i == (-g);
- // expected-warning at -1 {{}}
-
+ // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'W'}}
+
W w3 = i == (+g);
- // expected-warning at -1 {{}}
-
+ // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'W'}}
+
W w2 = i == (~g);
- // expected-warning at -1 {{}}
+ // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'W'}}
W w4 = i == (!g);
- // expected-error at -1 {{}}
+ // expected-error at -1 {{invalid argument type 'W' (vector of 1 'unsigned long' value) to unary expression}}
W w5 = i == (++g);
- // expected-error at -1 {{}}
+ // expected-error at -1 {{cannot increment value of type 'W'}}
W w6 = i == (g++);
- // expected-error at -1 {{}}
+ // expected-error at -1 {{cannot increment value of type 'W'}}
W w7 = i == (--g);
- // expected-error at -1 {{}}
+ // expected-error at -1 {{cannot decrement value of type 'W'}}
W w8 = i == (g--);
- // expected-error at -1 {{}}
+ // expected-error at -1 {{cannot decrement value of type 'W'}}
W w9 = i == (*g);
- // expected-error at -1 {{}}
+ // expected-error at -1 {{indirection requires pointer operand ('W' (vector of 1 'unsigned long' value) invalid)}}
}
>From b2b323792a54ad681e19f13fd103192f088f76e3 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Fri, 15 May 2026 13:12:30 -0400
Subject: [PATCH 08/10] Reuse hasUnsignedRepresentation()
---
clang/include/clang/AST/TypeBase.h | 4 ----
clang/lib/AST/Type.cpp | 6 ------
clang/lib/Sema/SemaChecking.cpp | 4 ++--
3 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h
index e96d311de4ce3..0a95084f52b0c 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -3100,10 +3100,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// enumeration types whose underlying type is a unsigned integer type.
bool isUnsignedIntegerOrEnumerationType() const;
- // Determine whether this is an unsigned integer type or an unsigned integer
- // vector type.
- bool isUnsignedIntegerOrVectorType() const;
-
/// Return true if this is a fixed point type according to
/// ISO/IEC JTC1 SC22 WG14 N1169.
bool isFixedPointType() const;
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 387cb335fadf4..4b539b7c2b1f6 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2405,12 +2405,6 @@ bool Type::isUnsignedIntegerOrEnumerationType() const {
return false;
}
-bool Type::isUnsignedIntegerOrVectorType() const {
- if (const auto *VT = getAs<VectorType>())
- return VT->getElementType()->isUnsignedIntegerType();
- return isUnsignedIntegerType();
-}
-
bool Type::hasUnsignedIntegerRepresentation() const {
if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 89d01eebc7333..5ad1a5e4c9bb1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12224,7 +12224,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
return IntRange::forValueOfType(C, GetExprType(E));
case UO_Minus: {
- if (E->getType()->isUnsignedIntegerOrVectorType()) {
+ if (GetExprType(E)->hasUnsignedIntegerRepresentation()) {
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
Approximate);
}
@@ -12242,7 +12242,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
}
case UO_Not: {
- if (E->getType()->isUnsignedIntegerOrVectorType()) {
+ if (GetExprType(E)->hasUnsignedIntegerRepresentation()) {
return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
Approximate);
}
>From e3e62302900d9a20f21e9aed7c9c247011b9a16c Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Fri, 15 May 2026 13:16:13 -0400
Subject: [PATCH 09/10] Revert an unintended change
---
clang/include/clang/AST/TypeBase.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h
index 0a95084f52b0c..9edf8a0ce9c68 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -3096,7 +3096,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// enumeration types whose underlying type is a signed integer type.
bool isSignedIntegerOrEnumerationType() const;
- /// Return true if this is an integer type that is unsigned or an
+ /// Determines whether this is an integer type that is unsigned or an
/// enumeration types whose underlying type is a unsigned integer type.
bool isUnsignedIntegerOrEnumerationType() const;
>From fe1213fb29f80a897e0b696179f71532278800af Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Sat, 16 May 2026 21:49:24 -0400
Subject: [PATCH 10/10] Add additional tests for matrix types and built-in sve
types
---
clang/test/Sema/compare.c | 79 ++++++++++++++++++++++++++-------------
1 file changed, 52 insertions(+), 27 deletions(-)
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index 0b9517a62a7b7..ed205cc7b9f9a 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,36 +483,60 @@ int test26(short n) {
}
#endif
-typedef unsigned long __attribute__((__vector_size__(8))) W;
+typedef unsigned long __attribute__((__vector_size__(8))) V;
void test27(void) {
int i;
- W g;
-
- W w1 = i == (-g);
- // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'W'}}
-
- W w3 = i == (+g);
- // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'W'}}
-
- W w2 = i == (~g);
- // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'W'}}
-
- W w4 = i == (!g);
- // expected-error at -1 {{invalid argument type 'W' (vector of 1 'unsigned long' value) to unary expression}}
-
- W w5 = i == (++g);
- // expected-error at -1 {{cannot increment value of type 'W'}}
+ V v;
+
+ V v1 = i == (-v);
+ // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'V'}}
+
+ V v2 = i == (+v);
+ // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'V'}}
+
+ V v3 = i == (~v);
+ // expected-warning at -1 {{comparison of integers of different signs: 'int' and 'V'}}
+
+ V v4 = i == (!v);
+ // expected-error at -1 {{invalid argument type 'V' (vector of 1 'unsigned long' value) to unary expression}}
+
+ V v5 = i == (++v);
+ // expected-error at -1 {{cannot increment value of type 'V'}}
+
+ V v6 = i == (v++);
+ // expected-error at -1 {{cannot increment value of type 'V'}}
+
+ V v7 = i == (--v);
+ // expected-error at -1 {{cannot decrement value of type 'V'}}
+
+ V v8 = i == (v--);
+ // expected-error at -1 {{cannot decrement value of type 'V'}}
+
+ V v9 = i == (*v);
+ // expected-error at -1 {{indirection requires pointer operand ('V' (vector of 1 'unsigned long' value) invalid)}}
+}
- W w6 = i == (g++);
- // expected-error at -1 {{cannot increment value of type 'W'}}
+typedef unsigned long __attribute__((matrix_type(8, 8))) M;
- W w7 = i == (--g);
- // expected-error at -1 {{cannot decrement value of type 'W'}}
+void test28(void) {
+ int i;
+ M m;
- W w8 = i == (g--);
- // expected-error at -1 {{cannot decrement value of type 'W'}}
+ M m1 = i == (-m);
+ // expected-error at -1 {{invalid argument type 'M' (aka 'unsigned long __attribute__((matrix_type(8, 8)))') to unary expression}}
+ M m2 = i == (~m);
+ // expected-error at -1 {{invalid argument type 'M' (aka 'unsigned long __attribute__((matrix_type(8, 8)))') to unary expression}}
+}
- W w9 = i == (*g);
- // expected-error at -1 {{indirection requires pointer operand ('W' (vector of 1 'unsigned long' value) invalid)}}
+#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 at -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 at -1 {{cannot convert between scalar type 'int' and vector type 'svuint8_t' (aka '__SVUint8_t') as implicit conversion would cause truncation}}
}
+#endif
More information about the cfe-commits
mailing list