[clang] [Clang] Fix crash on comparisons of `_BitInt` vectors wider than 128 bits (PR #232797)

Akash Manna via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 11:53:17 PDT 2026


https://github.com/akash-manna-sky updated https://github.com/llvm/llvm-project/pull/232797

>From a9f913ff55cf49cc2952c4fef3d1f9e5cd3ff23f Mon Sep 17 00:00:00 2001
From: Akash Manna <akash.manna.mymail at gmail.com>
Date: Fri, 16 Oct 2026 20:37:58 +0530
Subject: [PATCH 1/2] [Clang] Fix crash on comparisons of _BitInt vectors wider
 than 128 bits

Sema::GetSignedVectorType picks the element type for the result of a
vector comparison by matching the element's size against char, short,
int, __int128, long and long long, and asserts when nothing matches.
Since _BitInt became a legal vector element in Clang 16, any _BitInt
wider than 128 bits falls off the end of that chain: `a > 0` on a
_BitInt(512) vector trips the assertion, and a release build hands back
a long long vector instead. Sub-byte widths had the opposite problem:
_BitInt(4) reports a padded size of 8, so its comparisons quietly came
back as char vectors. The malformed input in the report is incidental;
a plain `v3i512 f(v3i512 a) { return a > 0; }` crashes the same way.

A _BitInt element is now handled before the size chain: the result is
the signed _BitInt of the same width, in the same vector kind and with
the same element count, which is what the comparison semantics call for
anyway. The builtin chain is unchanged, so no other element type is
affected, and _BitInt(128) keeps its _BitInt type rather than turning
into __int128, so the result always mirrors the operand.

Fixes #200665
---
 clang/docs/ReleaseNotes.md            |  1 +
 clang/lib/Sema/SemaExpr.cpp           |  8 +++
 clang/test/CodeGenCXX/ext-int.cpp     | 44 +++++++++++++
 clang/test/Sema/ext-int.c             | 49 ++++++++++++++
 clang/test/SemaCXX/ext-int-vector.cpp | 93 +++++++++++++++++++++++++++
 5 files changed, 195 insertions(+)
 create mode 100644 clang/test/SemaCXX/ext-int-vector.cpp

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 3f0c48cf36644d..a69c3f13b41d7f 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -725,6 +725,7 @@ features cannot lower the translation-unit ABI level;
 - Fixed an ICE hat occurred when using `__imag int/float` as lvalue in assignment. (#GH119498)
 - Fixed a C23 rejects-valid where `auto T x;` (with `T` a typedef-name) was rejected as a missing initializer. (#GH164930)
 - Fixed an assertion failure in `-Wsign-compare` when a negated or complemented vector of unsigned integers was compared against a signed constant. (#GH203575)
+- Fixed a crash when comparing vectors of `_BitInt` wider than 128 bits. (#GH200665)
 - Fixed an assertion failure when a constant statement expression that declares a variable is used as a bound of an OpenMP loop. A statement expression in a bound of a non-rectangular loop is now diagnosed. (#GH153987)
 - Fixed a bug where a bit-field accessed as the result of a statement expression
   (e.g. `({ s.b; })`) was not subject to integer promotion, unlike an ordinary
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e29caaab8e3f30..3bdcc5b9df100b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13633,6 +13633,14 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
 
 QualType Sema::GetSignedVectorType(QualType V) {
   const VectorType *VTy = V->castAs<VectorType>();
+  if (const auto *BIT = VTy->getElementType()->getAs<BitIntType>()) {
+    QualType EltTy =
+        Context.getBitIntType(/*IsUnsigned=*/false, BIT->getNumBits());
+    if (isa<ExtVectorType>(VTy))
+      return Context.getExtVectorType(EltTy, VTy->getNumElements());
+    return Context.getVectorType(EltTy, VTy->getNumElements(),
+                                 VectorKind::Generic);
+  }
   unsigned TypeSize = Context.getTypeSize(VTy->getElementType());
 
   if (isa<ExtVectorType>(VTy)) {
diff --git a/clang/test/CodeGenCXX/ext-int.cpp b/clang/test/CodeGenCXX/ext-int.cpp
index a45720c53e8772..6f78adc34e4be9 100644
--- a/clang/test/CodeGenCXX/ext-int.cpp
+++ b/clang/test/CodeGenCXX/ext-int.cpp
@@ -618,6 +618,50 @@ uint2_t2 TestBitIntVector2x2Alloca(uint2_t2 v1, uint2_t2 v2) {
   return v1 + v2;
 }
 
+typedef _BitInt(512) vint512_t3 __attribute__((ext_vector_type(3)));
+typedef _BitInt(256) vint256_t2 __attribute__((vector_size(64)));
+typedef unsigned _BitInt(256) uvint256_t2 __attribute__((vector_size(64)));
+
+vint512_t3 VectorCompareGTZero(vint512_t3 a) {
+  // CHECK: %[[CMP:.+]] = icmp sgt <3 x i512> %{{.+}}, zeroinitializer
+  // CHECK: %[[SEXT:.+]] = sext <3 x i1> %[[CMP]] to <3 x i512>
+  return a > 0;
+}
+
+vint256_t2 VectorCompareEQ(vint256_t2 a, vint256_t2 b) {
+  // CHECK: %[[CMP:.+]] = icmp eq <2 x i256> %{{.+}}, %{{.+}}
+  // CHECK: %[[SEXT:.+]] = sext <2 x i1> %[[CMP]] to <2 x i256>
+  return a == b;
+}
+
+vint256_t2 VectorCompareULT(uvint256_t2 a, uvint256_t2 b) {
+  // CHECK: %[[CMP:.+]] = icmp ult <2 x i256> %{{.+}}, %{{.+}}
+  // CHECK: %[[SEXT:.+]] = sext <2 x i1> %[[CMP]] to <2 x i256>
+  return a < b;
+}
+
+vint512_t3 VectorLogicalNot(vint512_t3 a) {
+  // CHECK: %[[CMP:.+]] = icmp eq <3 x i512> %{{.+}}, zeroinitializer
+  // CHECK: %[[SEXT:.+]] = sext <3 x i1> %[[CMP]] to <3 x i512>
+  return !a;
+}
+
+vint256_t2 VectorLogicalAnd(vint256_t2 a, vint256_t2 b) {
+  // CHECK: %[[LHS:.+]] = icmp ne <2 x i256> %{{.+}}, zeroinitializer
+  // CHECK: %[[RHS:.+]] = icmp ne <2 x i256> %{{.+}}, zeroinitializer
+  // CHECK: %[[AND:.+]] = and <2 x i1> %[[LHS]], %[[RHS]]
+  // CHECK: %[[SEXT:.+]] = sext <2 x i1> %[[AND]] to <2 x i256>
+  return a && b;
+}
+
+vint512_t3 VectorSelect(vint512_t3 a, vint512_t3 b, vint512_t3 c) {
+  // CHECK: %[[CMP:.+]] = icmp slt <3 x i512> %{{.+}}, zeroinitializer
+  // CHECK: %[[SEXT:.+]] = sext <3 x i1> %[[CMP]] to <3 x i512>
+  // CHECK: %[[COND:.+]] = icmp slt <3 x i512> %[[SEXT]], zeroinitializer
+  // CHECK: select <3 x i1> %[[COND]], <3 x i512> %{{.+}}, <3 x i512> %{{.+}}
+  return a < 0 ? b : c;
+}
+
 // Ensure that these types don't alias the normal int types.
 void TBAATest(_BitInt(sizeof(int) * 8) ExtInt,
               unsigned _BitInt(sizeof(int) * 8) ExtUInt,
diff --git a/clang/test/Sema/ext-int.c b/clang/test/Sema/ext-int.c
index ebc5bc61260b45..0b72ee5660ec42 100644
--- a/clang/test/Sema/ext-int.c
+++ b/clang/test/Sema/ext-int.c
@@ -73,3 +73,52 @@ void FromPaper1(void) {
 void FromPaper2(_BitInt(8) a1, _BitInt(24) a2) {
   _Static_assert(EXPR_HAS_TYPE(a1 * (_BitInt(32))a2, _BitInt(32)), "");
 }
+
+typedef _BitInt(4) ExtVec4x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(8) ExtVec8x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(32) ExtVec32x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(128) ExtVec128x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(256) ExtVec256x2 __attribute__((ext_vector_type(2)));
+typedef _BitInt(512) ExtVec512x3 __attribute__((ext_vector_type(3)));
+typedef _BitInt(1024) ExtVec1024x2 __attribute__((ext_vector_type(2)));
+typedef unsigned _BitInt(512) ExtUVec512x3 __attribute__((ext_vector_type(3)));
+typedef _BitInt(8) GnuVec8x4 __attribute__((vector_size(4)));
+typedef _BitInt(64) GnuVec64x4 __attribute__((vector_size(32)));
+typedef _BitInt(256) GnuVec256x2 __attribute__((vector_size(64)));
+typedef _BitInt(1024) GnuVec1024x2 __attribute__((vector_size(256)));
+typedef unsigned _BitInt(256) GnuUVec256x2 __attribute__((vector_size(64)));
+
+void GH200665(ExtVec4x4 e4a, ExtVec4x4 e4b, ExtVec8x4 e8a, ExtVec8x4 e8b,
+              ExtVec32x4 e32a, ExtVec32x4 e32b, ExtVec128x4 e128a,
+              ExtVec128x4 e128b, ExtVec256x2 e256a, ExtVec256x2 e256b,
+              ExtVec512x3 e512a, ExtVec512x3 e512b, ExtVec1024x2 e1024a,
+              ExtVec1024x2 e1024b, ExtUVec512x3 eu512a, ExtUVec512x3 eu512b,
+              GnuVec8x4 g8a, GnuVec8x4 g8b, GnuVec64x4 g64a, GnuVec64x4 g64b,
+              GnuVec256x2 g256a, GnuVec256x2 g256b, GnuVec1024x2 g1024a,
+              GnuVec1024x2 g1024b, GnuUVec256x2 gu256a, GnuUVec256x2 gu256b) {
+  _Static_assert(EXPR_HAS_TYPE(e4a == e4b, ExtVec4x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e8a != e8b, ExtVec8x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e32a < e32b, ExtVec32x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e128a <= e128b, ExtVec128x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e256a > e256b, ExtVec256x2), "");
+  _Static_assert(EXPR_HAS_TYPE(e512a >= e512b, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE(e512a > 0, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE(0 == e1024a, ExtVec1024x2), "");
+  _Static_assert(EXPR_HAS_TYPE(e1024a != e1024b, ExtVec1024x2), "");
+  _Static_assert(EXPR_HAS_TYPE(eu512a == eu512b, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE(!e4a, ExtVec4x4), "");
+  _Static_assert(EXPR_HAS_TYPE(!e512a, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE(!eu512a, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE(e512a && e512b, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE(e4a || e4b, ExtVec4x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e512a ? e512a : e512b, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE((e512a > 0) ? e512a : e512b, ExtVec512x3), "");
+  _Static_assert(EXPR_HAS_TYPE((eu512a == eu512b) ? eu512a : eu512b, ExtUVec512x3), "");
+
+  _Static_assert(EXPR_HAS_TYPE(g8a == g8b, GnuVec8x4), "");
+  _Static_assert(EXPR_HAS_TYPE(g64a < g64b, GnuVec64x4), "");
+  _Static_assert(EXPR_HAS_TYPE(g256a > g256b, GnuVec256x2), "");
+  _Static_assert(EXPR_HAS_TYPE(g256a >= 0, GnuVec256x2), "");
+  _Static_assert(EXPR_HAS_TYPE(g1024a != g1024b, GnuVec1024x2), "");
+  _Static_assert(EXPR_HAS_TYPE(gu256a <= gu256b, GnuVec256x2), "");
+}
diff --git a/clang/test/SemaCXX/ext-int-vector.cpp b/clang/test/SemaCXX/ext-int-vector.cpp
new file mode 100644
index 00000000000000..0c683a2916243d
--- /dev/null
+++ b/clang/test/SemaCXX/ext-int-vector.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-gnu %s
+
+namespace GH200665 {
+typedef _BitInt(2) ExtVec2x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(4) ExtVec4x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(8) ExtVec8x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(16) ExtVec16x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(32) ExtVec32x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(64) ExtVec64x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(128) ExtVec128x4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(256) ExtVec256x2 __attribute__((ext_vector_type(2)));
+typedef _BitInt(512) ExtVec512x3 __attribute__((ext_vector_type(3)));
+typedef _BitInt(1024) ExtVec1024x2 __attribute__((ext_vector_type(2)));
+typedef unsigned _BitInt(4) ExtUVec4x4 __attribute__((ext_vector_type(4)));
+typedef unsigned _BitInt(128) ExtUVec128x4 __attribute__((ext_vector_type(4)));
+typedef unsigned _BitInt(512) ExtUVec512x3 __attribute__((ext_vector_type(3)));
+
+typedef _BitInt(4) GnuVec4x2 __attribute__((vector_size(2)));
+typedef _BitInt(8) GnuVec8x4 __attribute__((vector_size(4)));
+typedef _BitInt(16) GnuVec16x4 __attribute__((vector_size(8)));
+typedef _BitInt(32) GnuVec32x4 __attribute__((vector_size(16)));
+typedef _BitInt(64) GnuVec64x4 __attribute__((vector_size(32)));
+typedef _BitInt(128) GnuVec128x2 __attribute__((vector_size(32)));
+typedef _BitInt(256) GnuVec256x2 __attribute__((vector_size(64)));
+typedef _BitInt(512) GnuVec512x2 __attribute__((vector_size(128)));
+typedef _BitInt(1024) GnuVec1024x2 __attribute__((vector_size(256)));
+typedef unsigned _BitInt(256) GnuUVec256x2 __attribute__((vector_size(64)));
+
+template <typename V, typename R = V> void check(V a, V b) {
+  static_assert(__is_same(decltype(a == b), R), "");
+  static_assert(__is_same(decltype(a != b), R), "");
+  static_assert(__is_same(decltype(a < b), R), "");
+  static_assert(__is_same(decltype(a <= b), R), "");
+  static_assert(__is_same(decltype(a > b), R), "");
+  static_assert(__is_same(decltype(a >= b), R), "");
+  static_assert(__is_same(decltype(a > 0), R), "");
+  static_assert(__is_same(decltype(0 < a), R), "");
+  static_assert(__is_same(decltype(!a), R), "");
+  static_assert(__is_same(decltype(a && b), R), "");
+  static_assert(__is_same(decltype(a || b), R), "");
+  static_assert(__is_same(decltype(a ? a : b), V), "");
+  static_assert(__is_same(decltype((a < b) ? a : b), V), "");
+  static_assert(__is_same(decltype(!a ? b : a), V), "");
+}
+
+template void check<ExtVec2x4>(ExtVec2x4, ExtVec2x4);
+template void check<ExtVec4x4>(ExtVec4x4, ExtVec4x4);
+template void check<ExtVec8x4>(ExtVec8x4, ExtVec8x4);
+template void check<ExtVec16x4>(ExtVec16x4, ExtVec16x4);
+template void check<ExtVec32x4>(ExtVec32x4, ExtVec32x4);
+template void check<ExtVec64x4>(ExtVec64x4, ExtVec64x4);
+template void check<ExtVec128x4>(ExtVec128x4, ExtVec128x4);
+template void check<ExtVec256x2>(ExtVec256x2, ExtVec256x2);
+template void check<ExtVec512x3>(ExtVec512x3, ExtVec512x3);
+template void check<ExtVec1024x2>(ExtVec1024x2, ExtVec1024x2);
+template void check<ExtUVec4x4, ExtVec4x4>(ExtUVec4x4, ExtUVec4x4);
+template void check<ExtUVec128x4, ExtVec128x4>(ExtUVec128x4, ExtUVec128x4);
+template void check<ExtUVec512x3, ExtVec512x3>(ExtUVec512x3, ExtUVec512x3);
+
+template void check<GnuVec4x2>(GnuVec4x2, GnuVec4x2);
+template void check<GnuVec8x4>(GnuVec8x4, GnuVec8x4);
+template void check<GnuVec16x4>(GnuVec16x4, GnuVec16x4);
+template void check<GnuVec32x4>(GnuVec32x4, GnuVec32x4);
+template void check<GnuVec64x4>(GnuVec64x4, GnuVec64x4);
+template void check<GnuVec128x2>(GnuVec128x2, GnuVec128x2);
+template void check<GnuVec256x2>(GnuVec256x2, GnuVec256x2);
+template void check<GnuVec512x2>(GnuVec512x2, GnuVec512x2);
+template void check<GnuVec1024x2>(GnuVec1024x2, GnuVec1024x2);
+template void check<GnuUVec256x2, GnuVec256x2>(GnuUVec256x2, GnuUVec256x2);
+
+typedef __int128 Int128x4 __attribute__((ext_vector_type(4)));
+typedef __int128 GnuInt128x2 __attribute__((vector_size(32)));
+void keeps_bitint(ExtVec128x4 a, ExtVec128x4 b, GnuVec128x2 c, GnuVec128x2 d) {
+  static_assert(!__is_same(decltype(a == b), Int128x4), "");
+  static_assert(!__is_same(decltype(c == d), GnuInt128x2), "");
+}
+
+// expected-error at +1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(7) __attribute__((ext_vector_type(4))) ExtVec7x4;
+// expected-error at +1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(255) __attribute__((ext_vector_type(2))) ExtVec255x2;
+// expected-error at +1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(255) __attribute__((vector_size(64))) GnuVec255x2;
+} // namespace GH200665
+
+// Original reproducer of GH200665.
+// expected-error at +1{{expected ')'}}
+using i512x3 = _BitInt(512) __attribute__((ext_vector_type(3));
+// expected-note at -1{{'i512x3' declared here}}
+// expected-error at +3{{unknown type name 'v3i512x3'; did you mean 'i512x3'?}}
+// expected-warning at +2{{variable 'a' is uninitialized when used within its own initialization}}
+// expected-error at +1{{expected ';' after top level declarator}}
+v3i512x3 a {a>0}

>From e7a3fe0475866f71c7ca5453d6063a682e75c017 Mon Sep 17 00:00:00 2001
From: Akash Manna <akash.manna.mymail at gmail.com>
Date: Sat, 17 Oct 2026 00:22:39 +0530
Subject: [PATCH 2/2] [Clang] Keep builtin result types for narrow _BitInt
 vector comparisons

Only fall back to a signed _BitInt element when no builtin integer of
the same size exists, so _BitInt up to 128 bits keeps producing the
char/short/int/long/long long/__int128 vectors it did before.
---
 clang/lib/Sema/SemaExpr.cpp           | 31 +++++++-------
 clang/test/Sema/ext-int.c             | 21 +++++----
 clang/test/SemaCXX/ext-int-vector.cpp | 62 ++++++++++++++-------------
 3 files changed, 62 insertions(+), 52 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3bdcc5b9df100b..0fe206df9ea9d1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13633,14 +13633,6 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
 
 QualType Sema::GetSignedVectorType(QualType V) {
   const VectorType *VTy = V->castAs<VectorType>();
-  if (const auto *BIT = VTy->getElementType()->getAs<BitIntType>()) {
-    QualType EltTy =
-        Context.getBitIntType(/*IsUnsigned=*/false, BIT->getNumBits());
-    if (isa<ExtVectorType>(VTy))
-      return Context.getExtVectorType(EltTy, VTy->getNumElements());
-    return Context.getVectorType(EltTy, VTy->getNumElements(),
-                                 VectorKind::Generic);
-  }
   unsigned TypeSize = Context.getTypeSize(VTy->getElementType());
 
   if (isa<ExtVectorType>(VTy)) {
@@ -13656,9 +13648,14 @@ QualType Sema::GetSignedVectorType(QualType V) {
       return Context.getExtVectorType(Context.Int128Ty, VTy->getNumElements());
     if (TypeSize == Context.getTypeSize(Context.LongTy))
       return Context.getExtVectorType(Context.LongTy, VTy->getNumElements());
-    assert(TypeSize == Context.getTypeSize(Context.LongLongTy) &&
-           "Unhandled vector element size in vector compare");
-    return Context.getExtVectorType(Context.LongLongTy, VTy->getNumElements());
+    if (TypeSize == Context.getTypeSize(Context.LongLongTy))
+      return Context.getExtVectorType(Context.LongLongTy,
+                                      VTy->getNumElements());
+    if (const auto *BIT = VTy->getElementType()->getAs<BitIntType>())
+      return Context.getExtVectorType(
+          Context.getBitIntType(/*IsUnsigned=*/false, BIT->getNumBits()),
+          VTy->getNumElements());
+    llvm_unreachable("Unhandled vector element size in vector compare");
   }
 
   if (TypeSize == Context.getTypeSize(Context.Int128Ty))
@@ -13676,10 +13673,14 @@ QualType Sema::GetSignedVectorType(QualType V) {
   if (TypeSize == Context.getTypeSize(Context.ShortTy))
     return Context.getVectorType(Context.ShortTy, VTy->getNumElements(),
                                  VectorKind::Generic);
-  assert(TypeSize == Context.getTypeSize(Context.CharTy) &&
-         "Unhandled vector element size in vector compare");
-  return Context.getVectorType(Context.CharTy, VTy->getNumElements(),
-                               VectorKind::Generic);
+  if (TypeSize == Context.getTypeSize(Context.CharTy))
+    return Context.getVectorType(Context.CharTy, VTy->getNumElements(),
+                                 VectorKind::Generic);
+  if (const auto *BIT = VTy->getElementType()->getAs<BitIntType>())
+    return Context.getVectorType(
+        Context.getBitIntType(/*IsUnsigned=*/false, BIT->getNumBits()),
+        VTy->getNumElements(), VectorKind::Generic);
+  llvm_unreachable("Unhandled vector element size in vector compare");
 }
 
 QualType Sema::GetSignedSizelessVectorType(QualType V) {
diff --git a/clang/test/Sema/ext-int.c b/clang/test/Sema/ext-int.c
index 0b72ee5660ec42..01d785f6c58eeb 100644
--- a/clang/test/Sema/ext-int.c
+++ b/clang/test/Sema/ext-int.c
@@ -87,6 +87,11 @@ typedef _BitInt(64) GnuVec64x4 __attribute__((vector_size(32)));
 typedef _BitInt(256) GnuVec256x2 __attribute__((vector_size(64)));
 typedef _BitInt(1024) GnuVec1024x2 __attribute__((vector_size(256)));
 typedef unsigned _BitInt(256) GnuUVec256x2 __attribute__((vector_size(64)));
+typedef char CharExt4 __attribute__((ext_vector_type(4)));
+typedef int IntExt4 __attribute__((ext_vector_type(4)));
+typedef __int128 Int128Ext4 __attribute__((ext_vector_type(4)));
+typedef char CharGnu4 __attribute__((vector_size(4)));
+typedef long long LongLongGnu4 __attribute__((vector_size(32)));
 
 void GH200665(ExtVec4x4 e4a, ExtVec4x4 e4b, ExtVec8x4 e8a, ExtVec8x4 e8b,
               ExtVec32x4 e32a, ExtVec32x4 e32b, ExtVec128x4 e128a,
@@ -96,27 +101,27 @@ void GH200665(ExtVec4x4 e4a, ExtVec4x4 e4b, ExtVec8x4 e8a, ExtVec8x4 e8b,
               GnuVec8x4 g8a, GnuVec8x4 g8b, GnuVec64x4 g64a, GnuVec64x4 g64b,
               GnuVec256x2 g256a, GnuVec256x2 g256b, GnuVec1024x2 g1024a,
               GnuVec1024x2 g1024b, GnuUVec256x2 gu256a, GnuUVec256x2 gu256b) {
-  _Static_assert(EXPR_HAS_TYPE(e4a == e4b, ExtVec4x4), "");
-  _Static_assert(EXPR_HAS_TYPE(e8a != e8b, ExtVec8x4), "");
-  _Static_assert(EXPR_HAS_TYPE(e32a < e32b, ExtVec32x4), "");
-  _Static_assert(EXPR_HAS_TYPE(e128a <= e128b, ExtVec128x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e4a == e4b, CharExt4), "");
+  _Static_assert(EXPR_HAS_TYPE(e8a != e8b, CharExt4), "");
+  _Static_assert(EXPR_HAS_TYPE(e32a < e32b, IntExt4), "");
+  _Static_assert(EXPR_HAS_TYPE(e128a <= e128b, Int128Ext4), "");
   _Static_assert(EXPR_HAS_TYPE(e256a > e256b, ExtVec256x2), "");
   _Static_assert(EXPR_HAS_TYPE(e512a >= e512b, ExtVec512x3), "");
   _Static_assert(EXPR_HAS_TYPE(e512a > 0, ExtVec512x3), "");
   _Static_assert(EXPR_HAS_TYPE(0 == e1024a, ExtVec1024x2), "");
   _Static_assert(EXPR_HAS_TYPE(e1024a != e1024b, ExtVec1024x2), "");
   _Static_assert(EXPR_HAS_TYPE(eu512a == eu512b, ExtVec512x3), "");
-  _Static_assert(EXPR_HAS_TYPE(!e4a, ExtVec4x4), "");
+  _Static_assert(EXPR_HAS_TYPE(!e4a, CharExt4), "");
   _Static_assert(EXPR_HAS_TYPE(!e512a, ExtVec512x3), "");
   _Static_assert(EXPR_HAS_TYPE(!eu512a, ExtVec512x3), "");
   _Static_assert(EXPR_HAS_TYPE(e512a && e512b, ExtVec512x3), "");
-  _Static_assert(EXPR_HAS_TYPE(e4a || e4b, ExtVec4x4), "");
+  _Static_assert(EXPR_HAS_TYPE(e4a || e4b, CharExt4), "");
   _Static_assert(EXPR_HAS_TYPE(e512a ? e512a : e512b, ExtVec512x3), "");
   _Static_assert(EXPR_HAS_TYPE((e512a > 0) ? e512a : e512b, ExtVec512x3), "");
   _Static_assert(EXPR_HAS_TYPE((eu512a == eu512b) ? eu512a : eu512b, ExtUVec512x3), "");
 
-  _Static_assert(EXPR_HAS_TYPE(g8a == g8b, GnuVec8x4), "");
-  _Static_assert(EXPR_HAS_TYPE(g64a < g64b, GnuVec64x4), "");
+  _Static_assert(EXPR_HAS_TYPE(g8a == g8b, CharGnu4), "");
+  _Static_assert(EXPR_HAS_TYPE(g64a < g64b, LongLongGnu4), "");
   _Static_assert(EXPR_HAS_TYPE(g256a > g256b, GnuVec256x2), "");
   _Static_assert(EXPR_HAS_TYPE(g256a >= 0, GnuVec256x2), "");
   _Static_assert(EXPR_HAS_TYPE(g1024a != g1024b, GnuVec1024x2), "");
diff --git a/clang/test/SemaCXX/ext-int-vector.cpp b/clang/test/SemaCXX/ext-int-vector.cpp
index 0c683a2916243d..d4d624f90cb5c8 100644
--- a/clang/test/SemaCXX/ext-int-vector.cpp
+++ b/clang/test/SemaCXX/ext-int-vector.cpp
@@ -14,6 +14,11 @@ typedef _BitInt(1024) ExtVec1024x2 __attribute__((ext_vector_type(2)));
 typedef unsigned _BitInt(4) ExtUVec4x4 __attribute__((ext_vector_type(4)));
 typedef unsigned _BitInt(128) ExtUVec128x4 __attribute__((ext_vector_type(4)));
 typedef unsigned _BitInt(512) ExtUVec512x3 __attribute__((ext_vector_type(3)));
+typedef char CharExt4 __attribute__((ext_vector_type(4)));
+typedef short ShortExt4 __attribute__((ext_vector_type(4)));
+typedef int IntExt4 __attribute__((ext_vector_type(4)));
+typedef long LongExt4 __attribute__((ext_vector_type(4)));
+typedef __int128 Int128Ext4 __attribute__((ext_vector_type(4)));
 
 typedef _BitInt(4) GnuVec4x2 __attribute__((vector_size(2)));
 typedef _BitInt(8) GnuVec8x4 __attribute__((vector_size(4)));
@@ -25,8 +30,14 @@ typedef _BitInt(256) GnuVec256x2 __attribute__((vector_size(64)));
 typedef _BitInt(512) GnuVec512x2 __attribute__((vector_size(128)));
 typedef _BitInt(1024) GnuVec1024x2 __attribute__((vector_size(256)));
 typedef unsigned _BitInt(256) GnuUVec256x2 __attribute__((vector_size(64)));
+typedef char CharGnu2 __attribute__((vector_size(2)));
+typedef char CharGnu4 __attribute__((vector_size(4)));
+typedef short ShortGnu4 __attribute__((vector_size(8)));
+typedef int IntGnu4 __attribute__((vector_size(16)));
+typedef long long LongLongGnu4 __attribute__((vector_size(32)));
+typedef __int128 Int128Gnu2 __attribute__((vector_size(32)));
 
-template <typename V, typename R = V> void check(V a, V b) {
+template <typename V, typename R> void check(V a, V b) {
   static_assert(__is_same(decltype(a == b), R), "");
   static_assert(__is_same(decltype(a != b), R), "");
   static_assert(__is_same(decltype(a < b), R), "");
@@ -43,38 +54,31 @@ template <typename V, typename R = V> void check(V a, V b) {
   static_assert(__is_same(decltype(!a ? b : a), V), "");
 }
 
-template void check<ExtVec2x4>(ExtVec2x4, ExtVec2x4);
-template void check<ExtVec4x4>(ExtVec4x4, ExtVec4x4);
-template void check<ExtVec8x4>(ExtVec8x4, ExtVec8x4);
-template void check<ExtVec16x4>(ExtVec16x4, ExtVec16x4);
-template void check<ExtVec32x4>(ExtVec32x4, ExtVec32x4);
-template void check<ExtVec64x4>(ExtVec64x4, ExtVec64x4);
-template void check<ExtVec128x4>(ExtVec128x4, ExtVec128x4);
-template void check<ExtVec256x2>(ExtVec256x2, ExtVec256x2);
-template void check<ExtVec512x3>(ExtVec512x3, ExtVec512x3);
-template void check<ExtVec1024x2>(ExtVec1024x2, ExtVec1024x2);
-template void check<ExtUVec4x4, ExtVec4x4>(ExtUVec4x4, ExtUVec4x4);
-template void check<ExtUVec128x4, ExtVec128x4>(ExtUVec128x4, ExtUVec128x4);
+template void check<ExtVec2x4, CharExt4>(ExtVec2x4, ExtVec2x4);
+template void check<ExtVec4x4, CharExt4>(ExtVec4x4, ExtVec4x4);
+template void check<ExtVec8x4, CharExt4>(ExtVec8x4, ExtVec8x4);
+template void check<ExtVec16x4, ShortExt4>(ExtVec16x4, ExtVec16x4);
+template void check<ExtVec32x4, IntExt4>(ExtVec32x4, ExtVec32x4);
+template void check<ExtVec64x4, LongExt4>(ExtVec64x4, ExtVec64x4);
+template void check<ExtVec128x4, Int128Ext4>(ExtVec128x4, ExtVec128x4);
+template void check<ExtVec256x2, ExtVec256x2>(ExtVec256x2, ExtVec256x2);
+template void check<ExtVec512x3, ExtVec512x3>(ExtVec512x3, ExtVec512x3);
+template void check<ExtVec1024x2, ExtVec1024x2>(ExtVec1024x2, ExtVec1024x2);
+template void check<ExtUVec4x4, CharExt4>(ExtUVec4x4, ExtUVec4x4);
+template void check<ExtUVec128x4, Int128Ext4>(ExtUVec128x4, ExtUVec128x4);
 template void check<ExtUVec512x3, ExtVec512x3>(ExtUVec512x3, ExtUVec512x3);
 
-template void check<GnuVec4x2>(GnuVec4x2, GnuVec4x2);
-template void check<GnuVec8x4>(GnuVec8x4, GnuVec8x4);
-template void check<GnuVec16x4>(GnuVec16x4, GnuVec16x4);
-template void check<GnuVec32x4>(GnuVec32x4, GnuVec32x4);
-template void check<GnuVec64x4>(GnuVec64x4, GnuVec64x4);
-template void check<GnuVec128x2>(GnuVec128x2, GnuVec128x2);
-template void check<GnuVec256x2>(GnuVec256x2, GnuVec256x2);
-template void check<GnuVec512x2>(GnuVec512x2, GnuVec512x2);
-template void check<GnuVec1024x2>(GnuVec1024x2, GnuVec1024x2);
+template void check<GnuVec4x2, CharGnu2>(GnuVec4x2, GnuVec4x2);
+template void check<GnuVec8x4, CharGnu4>(GnuVec8x4, GnuVec8x4);
+template void check<GnuVec16x4, ShortGnu4>(GnuVec16x4, GnuVec16x4);
+template void check<GnuVec32x4, IntGnu4>(GnuVec32x4, GnuVec32x4);
+template void check<GnuVec64x4, LongLongGnu4>(GnuVec64x4, GnuVec64x4);
+template void check<GnuVec128x2, Int128Gnu2>(GnuVec128x2, GnuVec128x2);
+template void check<GnuVec256x2, GnuVec256x2>(GnuVec256x2, GnuVec256x2);
+template void check<GnuVec512x2, GnuVec512x2>(GnuVec512x2, GnuVec512x2);
+template void check<GnuVec1024x2, GnuVec1024x2>(GnuVec1024x2, GnuVec1024x2);
 template void check<GnuUVec256x2, GnuVec256x2>(GnuUVec256x2, GnuUVec256x2);
 
-typedef __int128 Int128x4 __attribute__((ext_vector_type(4)));
-typedef __int128 GnuInt128x2 __attribute__((vector_size(32)));
-void keeps_bitint(ExtVec128x4 a, ExtVec128x4 b, GnuVec128x2 c, GnuVec128x2 d) {
-  static_assert(!__is_same(decltype(a == b), Int128x4), "");
-  static_assert(!__is_same(decltype(c == d), GnuInt128x2), "");
-}
-
 // expected-error at +1{{'_BitInt' vector element width must be a power of 2}}
 typedef _BitInt(7) __attribute__((ext_vector_type(4))) ExtVec7x4;
 // expected-error at +1{{'_BitInt' vector element width must be a power of 2}}



More information about the cfe-commits mailing list