llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Kartik Ohlan (Ko496-glitch)

<details>
<summary>Changes</summary>

#<!-- -->189260 

Fix assertion failure in boolean vector indexing by truncating to i1.

---
Full diff: https://github.com/llvm/llvm-project/pull/189305.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+3) 
- (added) clang/test/CodeGen/ext-vector-bool-read.cpp (+21) 


``````````diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 23802cdeb4811..20a38b6367df5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2781,6 +2781,9 @@ 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
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;
+}

``````````

</details>


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

Reply via email to