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

>From 2d47db0ff28f869363ed3808a82d6996dd07c2c5 Mon Sep 17 00:00:00 2001
From: kartikohlan <[email protected]>
Date: Sun, 29 Mar 2026 23:49:47 -0400
Subject: [PATCH 1/3] [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 45a41f0bc15e448ab22921d14c7f39acae8d83b4 Mon Sep 17 00:00:00 2001
From: kartikohlan <[email protected]>
Date: Mon, 30 Mar 2026 18:46:21 -0400
Subject: [PATCH 2/3] Added the exisiting practise and fixed the format

---
 clang/lib/CodeGen/CGExpr.cpp                |  5 ++---
 clang/test/CodeGen/ext-vector-bool-read.cpp | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/ext-vector-bool-read.cpp

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 737d4fd145a4d..20a38b6367df5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2782,9 +2782,8 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
         Vec = Builder.CreateBitCast(Vec, IRVecTy);
         // iN --> <N x i1>.
 
-        if(SrcVal->getType() != Builder.getInt1Ty())
-            SrcVal = Builder.CreateTrunc(SrcVal,Builder.getInt1Ty());
-        }
+        SrcVal = Builder.CreateIntCast(SrcVal, Builder.getInt1Ty(),
+                                          /*isSigned=*/false);
       }
 
       // 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..358dc5919b245
--- /dev/null
+++ b/clang/test/CodeGen/ext-vector-bool-read.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O2 -o - %s | 
FileCheck %s
+
+// 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: @_Z5test1v
+void test1() {
+    // CHECK: insertelement <32 x i1>
+    v32b[0] = true;
+}
+
+// CHECK-LABEL: @_Z5test2v
+void test2() {
+    // CHECK: insertelement <32 x i1>
+    v32b[31] = true;
+}

>From 37a355c8576b16d22a8dd125b864df4608e41009 Mon Sep 17 00:00:00 2001
From: kartikohlan <[email protected]>
Date: Wed, 8 Apr 2026 19:50:45 -0400
Subject: [PATCH 3/3] Fix for the relase notes

---
 clang/docs/ReleaseNotes.rst                 |  1 +
 clang/lib/CodeGen/CGExpr.cpp                |  7 +--
 clang/test/CodeGen/ext-vector-bool-read.cpp | 47 ++++++++++++++++++---
 3 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc17eead02589..313a0fcac0f69 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,7 @@ Bug Fixes in This Version
 - Correctly diagnosing and no longer crashing when ``export module foo``
   (without a semicolon) are the final tokens in a module file. (#GH187771)
 - Fixed a crash in duplicate attribute checking caused by comparing constant 
arguments with different integer signedness. (#GH188259)
+- 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 20a38b6367df5..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,9 +2781,6 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
             Builder.getInt1Ty(), IRStoreTy->getPrimitiveSizeInBits());
         Vec = Builder.CreateBitCast(Vec, IRVecTy);
         // iN --> <N x i1>.
-
-        SrcVal = Builder.CreateIntCast(SrcVal, Builder.getInt1Ty(),
-                                          /*isSigned=*/false);
       }
 
       // 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
index 358dc5919b245..527cf160c1614 100644
--- a/clang/test/CodeGen/ext-vector-bool-read.cpp
+++ b/clang/test/CodeGen/ext-vector-bool-read.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O2 -o - %s | 
FileCheck %s
+// 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
@@ -8,14 +9,48 @@
 typedef __attribute__((ext_vector_type(32))) bool v32bool;
 v32bool v32b = {};
 
-// CHECK-LABEL: @_Z5test1v
+// 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() {
-    // CHECK: insertelement <32 x i1>
+
     v32b[0] = true;
 }
 
-// CHECK-LABEL: @_Z5test2v
+// 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() {
-    // CHECK: insertelement <32 x i1>
+
     v32b[31] = true;
 }

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

Reply via email to