https://github.com/Ko496-glitch updated 
https://github.com/llvm/llvm-project/pull/189305

>From f14a2f1a3fda870a55e9f268d664068c297bd084 Mon Sep 17 00:00:00 2001
From: kartikohlan <[email protected]>
Date: Sun, 29 Mar 2026 23:49:47 -0400
Subject: [PATCH 1/2] [Clang] Fix assertion failure (#189260)

---
 clang/lib/CodeGen/CGExpr.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 23802cdeb4811..737d4fd145a4d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2781,6 +2781,10 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
             Builder.getInt1Ty(), IRStoreTy->getPrimitiveSizeInBits());
         Vec = Builder.CreateBitCast(Vec, IRVecTy);
         // iN --> <N x i1>.
+
+        if(SrcVal->getType() != Builder.getInt1Ty())
+            SrcVal = Builder.CreateTrunc(SrcVal,Builder.getInt1Ty());
+        }
       }
 
       // Allow inserting `<1 x T>` into an `<N x T>`. It can happen with scalar

>From d42b8d685123ba62d18c8ad44b0dffc686a792ef Mon Sep 17 00:00:00 2001
From: kartikohlan <[email protected]>
Date: Mon, 30 Mar 2026 18:46:21 -0400
Subject: [PATCH 2/2] [Clang] Fix assertion failure when storing to
 ext_vector_type bool elements

Fixed a crash when assigning to an element of an ext_vector_type with
bool element type by guarding the ZExt with VecTy->isVectorTy().

Fixes #GH189260
---
 clang/docs/LanguageExtensions.rst           |  2 -
 clang/docs/ReleaseNotes.rst                 |  1 +
 clang/lib/CodeGen/CGExpr.cpp                |  8 +--
 clang/test/CodeGen/ext-vector-bool-read.cpp | 56 +++++++++++++++++++++
 4 files changed, 59 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/ext-vector-bool-read.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 549e1a6a58617..8f6826c3891ac 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -653,8 +653,6 @@ differences:
   boolean vectors.
 * Casting a scalar bool value to a boolean vector type means broadcasting the
   scalar value onto all lanes (same as general ext_vector_type).
-* It is not possible to access or swizzle elements of a boolean vector
-  (different than general ext_vector_type).
 
 The size and alignment are both the number of bits rounded up to the next power
 of two, but the alignment is at most the maximum vector alignment of the
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db4bd9e821086..b2e62106506f0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -407,6 +407,7 @@ Bug Fixes in This Version
 - Fixed the behavior in C23 of ``auto``, by emitting an error when an array 
type is specified for a ``char *``. (#GH162694)
 - Fixed incorrect rejection of ``auto`` with reordered declaration specifiers 
in C23. (#GH164121)
 - Fixed a crash where constexpr evaluation encountered invalid overrides. 
(#GH183290)
+- Fixed a crash when assigning to an element of an ``ext_vector_type`` with 
``bool`` element type. (#GH189260)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 737d4fd145a4d..2ef399a7e7309 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2771,8 +2771,8 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
       llvm::Type *VecTy = Vec->getType();
       llvm::Value *SrcVal = Src.getScalarVal();
 
-      if (SrcVal->getType()->getPrimitiveSizeInBits() <
-          VecTy->getScalarSizeInBits())
+      if (VecTy->isVectorTy() && SrcVal->getType()->getPrimitiveSizeInBits() <
+                                     VecTy->getScalarSizeInBits())
         SrcVal = Builder.CreateZExt(SrcVal, VecTy->getScalarType());
 
       auto *IRStoreTy = dyn_cast<llvm::IntegerType>(Vec->getType());
@@ -2781,10 +2781,6 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
             Builder.getInt1Ty(), IRStoreTy->getPrimitiveSizeInBits());
         Vec = Builder.CreateBitCast(Vec, IRVecTy);
         // iN --> <N x i1>.
-
-        if(SrcVal->getType() != Builder.getInt1Ty())
-            SrcVal = Builder.CreateTrunc(SrcVal,Builder.getInt1Ty());
-        }
       }
 
       // Allow inserting `<1 x T>` into an `<N x T>`. It can happen with scalar
diff --git a/clang/test/CodeGen/ext-vector-bool-read.cpp 
b/clang/test/CodeGen/ext-vector-bool-read.cpp
new file mode 100644
index 0000000000000..527cf160c1614
--- /dev/null
+++ b/clang/test/CodeGen/ext-vector-bool-read.cpp
@@ -0,0 +1,56 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O2 -o - %s | 
FileCheck %s --check-prefix=OPT
+
+// Regression test for GH#189260: Clang crashed with an assertion failure
+// in InsertElementInst when storing to an element of an ext_vector_type
+// with bool element type.
+
+typedef __attribute__((ext_vector_type(32))) bool v32bool;
+v32bool v32b = {};
+
+// CHECK-LABEL: define dso_local void @_Z5test1v(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr @v32b, align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32 [[TMP0]] to <32 x i1>
+// CHECK-NEXT:    [[VECINS:%.*]] = insertelement <32 x i1> [[TMP1]], i1 true, 
i32 0
+// CHECK-NEXT:    [[TMP2:%.*]] = bitcast <32 x i1> [[VECINS]] to i32
+// CHECK-NEXT:    store i32 [[TMP2]], ptr @v32b, align 4
+// CHECK-NEXT:    ret void
+//
+// OPT-LABEL: define dso_local void @_Z5test1v(
+// OPT-SAME: ) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// OPT-NEXT:  [[ENTRY:.*:]]
+// OPT-NEXT:    [[TMP0:%.*]] = load <32 x i1>, ptr @v32b, align 4
+// OPT-NEXT:    [[VECINS:%.*]] = insertelement <32 x i1> [[TMP0]], i1 true, 
i64 0
+// OPT-NEXT:    store <32 x i1> [[VECINS]], ptr @v32b, align 4
+// OPT-NEXT:    ret void
+//
+void test1() {
+
+    v32b[0] = true;
+}
+
+// CHECK-LABEL: define dso_local void @_Z5test2v(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr @v32b, align 4
+// CHECK-NEXT:    [[TMP1:%.*]] = bitcast i32 [[TMP0]] to <32 x i1>
+// CHECK-NEXT:    [[VECINS:%.*]] = insertelement <32 x i1> [[TMP1]], i1 true, 
i32 31
+// CHECK-NEXT:    [[TMP2:%.*]] = bitcast <32 x i1> [[VECINS]] to i32
+// CHECK-NEXT:    store i32 [[TMP2]], ptr @v32b, align 4
+// CHECK-NEXT:    ret void
+//
+// OPT-LABEL: define dso_local void @_Z5test2v(
+// OPT-SAME: ) local_unnamed_addr #[[ATTR0]] {
+// OPT-NEXT:  [[ENTRY:.*:]]
+// OPT-NEXT:    [[TMP0:%.*]] = load <32 x i1>, ptr @v32b, align 4
+// OPT-NEXT:    [[VECINS:%.*]] = insertelement <32 x i1> [[TMP0]], i1 true, 
i64 31
+// OPT-NEXT:    store <32 x i1> [[VECINS]], ptr @v32b, align 4
+// OPT-NEXT:    ret void
+//
+void test2() {
+
+    v32b[31] = true;
+}

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

Reply via email to