mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
llvm: correctly bitcast for memset intrinsic path
This commit is contained in:
committed by
Andrew Kelley
parent
2322d45d80
commit
06ab4f702e
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user