[clang] [Clang] Fix assertion failure (#189260) (PR #189305)
Kartik Ohlan via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 22:30:48 PDT 2026
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 <kartik7ohlan at gmail.com>
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 45a41f0bc15e448ab22921d14c7f39acae8d83b4 Mon Sep 17 00:00:00 2001
From: kartikohlan <kartik7ohlan at gmail.com>
Date: Mon, 30 Mar 2026 18:46:21 -0400
Subject: [PATCH 2/2] 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;
+}
More information about the cfe-commits
mailing list