Author: Kartik Ohlan Date: 2026-04-09T14:57:04-05:00 New Revision: 2379e91c2d6af1fd892c0aece9bb8b1279ada8ff
URL: https://github.com/llvm/llvm-project/commit/2379e91c2d6af1fd892c0aece9bb8b1279ada8ff DIFF: https://github.com/llvm/llvm-project/commit/2379e91c2d6af1fd892c0aece9bb8b1279ada8ff.diff LOG: [Clang] Fix assertion failure when storing to ext_vector_type bool elements (#189305) #189260 Fix assertion failure in boolean vector indexing by truncating to i1. Added: clang/test/CodeGen/ext-vector-bool-read.cpp Modified: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/lib/CodeGen/CGExpr.cpp Removed: ################################################################################ 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 @@ diff erences: 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 - ( diff erent 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 23802cdeb4811..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()); 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..9ca0eb76d7c09 --- /dev/null +++ b/clang/test/CodeGen/ext-vector-bool-read.cpp @@ -0,0 +1,38 @@ +// 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 + +// 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 +// +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 +// +void test2() { + v32b[31] = true; +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
