llvm: correctly bitcast for memset intrinsic path

This commit is contained in:
David Rubin
2026-04-09 17:57:02 -07:00
committed by Andrew Kelley
parent 2322d45d80
commit 06ab4f702e
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -5127,7 +5127,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error
const value = try self.resolveInst(bin_op.rhs);
const elem_abi_size = elem_ty.abiSize(zcu);
if (elem_abi_size == 1) {
if (elem_abi_size == 1 and elem_ty.bitSize(zcu) == 8) {
// In this case we can take advantage of LLVM's intrinsic.
const fill_byte = try self.bitCast(value, elem_ty, Type.u8);
const len = try self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
+8
View File
@@ -190,3 +190,11 @@ test "@memset a global array" {
@memset(&S.buf, S.buf[0] + 333);
try expect(S.buf[0] == 789);
}
test "@memset array of booleans" {
const S = struct {
var x: bool = false;
var y: [1]bool = undefined;
};
@memset(&S.y, S.x);
}