Skip to content

Commit 2379e91

Browse files
authored
[Clang] Fix assertion failure when storing to ext_vector_type bool elements (llvm#189305)
llvm#189260 Fix assertion failure in boolean vector indexing by truncating to i1.
1 parent cfda886 commit 2379e91

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,6 @@ differences:
653653
boolean vectors.
654654
* Casting a scalar bool value to a boolean vector type means broadcasting the
655655
scalar value onto all lanes (same as general ext_vector_type).
656-
* It is not possible to access or swizzle elements of a boolean vector
657-
(different than general ext_vector_type).
658656

659657
The size and alignment are both the number of bits rounded up to the next power
660658
of two, but the alignment is at most the maximum vector alignment of the

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ Bug Fixes in This Version
407407
- Fixed the behavior in C23 of ``auto``, by emitting an error when an array type is specified for a ``char *``. (#GH162694)
408408
- Fixed incorrect rejection of ``auto`` with reordered declaration specifiers in C23. (#GH164121)
409409
- Fixed a crash where constexpr evaluation encountered invalid overrides. (#GH183290)
410+
- Fixed a crash when assigning to an element of an ``ext_vector_type`` with ``bool`` element type. (#GH189260)
410411

411412
Bug Fixes to Compiler Builtins
412413
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,8 +2771,8 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
27712771
llvm::Type *VecTy = Vec->getType();
27722772
llvm::Value *SrcVal = Src.getScalarVal();
27732773

2774-
if (SrcVal->getType()->getPrimitiveSizeInBits() <
2775-
VecTy->getScalarSizeInBits())
2774+
if (VecTy->isVectorTy() && SrcVal->getType()->getPrimitiveSizeInBits() <
2775+
VecTy->getScalarSizeInBits())
27762776
SrcVal = Builder.CreateZExt(SrcVal, VecTy->getScalarType());
27772777

27782778
auto *IRStoreTy = dyn_cast<llvm::IntegerType>(Vec->getType());
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 6
2+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK
3+
4+
// Regression test for GH#189260: Clang crashed with an assertion failure
5+
// in InsertElementInst when storing to an element of an ext_vector_type
6+
// with bool element type.
7+
8+
typedef __attribute__((ext_vector_type(32))) bool v32bool;
9+
v32bool v32b = {};
10+
11+
12+
// CHECK-LABEL: define dso_local void @_Z5test1v(
13+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
14+
// CHECK-NEXT: [[ENTRY:.*:]]
15+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @v32b, align 4
16+
// CHECK-NEXT: [[TMP1:%.*]] = bitcast i32 [[TMP0]] to <32 x i1>
17+
// CHECK-NEXT: [[VECINS:%.*]] = insertelement <32 x i1> [[TMP1]], i1 true, i32 0
18+
// CHECK-NEXT: [[TMP2:%.*]] = bitcast <32 x i1> [[VECINS]] to i32
19+
// CHECK-NEXT: store i32 [[TMP2]], ptr @v32b, align 4
20+
// CHECK-NEXT: ret void
21+
//
22+
void test1() {
23+
v32b[0] = true;
24+
}
25+
26+
// CHECK-LABEL: define dso_local void @_Z5test2v(
27+
// CHECK-SAME: ) #[[ATTR0]] {
28+
// CHECK-NEXT: [[ENTRY:.*:]]
29+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @v32b, align 4
30+
// CHECK-NEXT: [[TMP1:%.*]] = bitcast i32 [[TMP0]] to <32 x i1>
31+
// CHECK-NEXT: [[VECINS:%.*]] = insertelement <32 x i1> [[TMP1]], i1 true, i32 31
32+
// CHECK-NEXT: [[TMP2:%.*]] = bitcast <32 x i1> [[VECINS]] to i32
33+
// CHECK-NEXT: store i32 [[TMP2]], ptr @v32b, align 4
34+
// CHECK-NEXT: ret void
35+
//
36+
void test2() {
37+
v32b[31] = true;
38+
}

0 commit comments

Comments
 (0)