@@ -8514,8 +8514,7 @@ pub const FuncGen = struct {
8514
8514
// Any WebAssembly runtime will trap when the destination pointer is out-of-bounds, regardless
8515
8515
// of the length. This means we need to emit a check where we skip the memset when the length
8516
8516
// is 0 as we allow for undefined pointers in 0-sized slices.
8517
- const needs_wasm_safety_check = safety and
8518
- o.target.isWasm() and
8517
+ const intrinsic_len0_traps = o.target.isWasm() and
8519
8518
ptr_ty.isSlice(mod) and
8520
8519
std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory);
8521
8520
@@ -8529,7 +8528,7 @@ pub const FuncGen = struct {
8529
8528
else
8530
8529
u8_llvm_ty.getUndef();
8531
8530
const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8532
- if (needs_wasm_safety_check ) {
8531
+ if (intrinsic_len0_traps ) {
8533
8532
try self.safeWasmMemset(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
8534
8533
} else {
8535
8534
_ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
@@ -8552,7 +8551,7 @@ pub const FuncGen = struct {
8552
8551
});
8553
8552
const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8554
8553
8555
- if (needs_wasm_safety_check ) {
8554
+ if (intrinsic_len0_traps ) {
8556
8555
try self.safeWasmMemset(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
8557
8556
} else {
8558
8557
_ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
@@ -8569,7 +8568,7 @@ pub const FuncGen = struct {
8569
8568
const fill_byte = try self.bitCast(value, elem_ty, Type.u8);
8570
8569
const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
8571
8570
8572
- if (needs_wasm_safety_check ) {
8571
+ if (intrinsic_len0_traps ) {
8573
8572
try self.safeWasmMemset(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
8574
8573
} else {
8575
8574
_ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
@@ -8654,13 +8653,10 @@ pub const FuncGen = struct {
8654
8653
) !void {
8655
8654
const parent_block = self.context.createBasicBlock("Block");
8656
8655
const llvm_usize_ty = self.context.intType(self.dg.object.target.ptrBitWidth());
8657
- const cond = try self.cmp(len, llvm_usize_ty.constInt(0, .False), Type.usize, .eq );
8656
+ const cond = try self.cmp(len, llvm_usize_ty.constInt(0, .False), Type.usize, .neq );
8658
8657
const then_block = self.context.appendBasicBlock(self.llvm_func, "Then");
8659
- const else_block = self.context.appendBasicBlock(self.llvm_func, "Else");
8660
- _ = self.builder.buildCondBr(cond, then_block, else_block);
8658
+ _ = self.builder.buildCondBr(cond, then_block, parent_block);
8661
8659
self.builder.positionBuilderAtEnd(then_block);
8662
- _ = self.builder.buildBr(parent_block);
8663
- self.builder.positionBuilderAtEnd(else_block);
8664
8660
_ = self.builder.buildMemSet(dest_ptr, fill_byte, len, dest_ptr_align, is_volatile);
8665
8661
_ = self.builder.buildBr(parent_block);
8666
8662
self.llvm_func.appendExistingBasicBlock(parent_block);
@@ -8682,24 +8678,18 @@ pub const FuncGen = struct {
8682
8678
8683
8679
// When bulk-memory is enabled, this will be lowered to WebAssembly's memory.copy instruction.
8684
8680
// This instruction will trap on an invalid address, regardless of the length.
8685
- // For this reason we must add a safety- check for 0-sized slices as its pointer field can be undefined.
8681
+ // For this reason we must add a check for 0-sized slices as its pointer field can be undefined.
8686
8682
// We only have to do this for slices as arrays will have a valid pointer.
8687
8683
if (o.target.isWasm() and
8688
8684
std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and
8689
- (src_ptr_ty.isSlice(mod) or dest_ptr_ty.isSlice(mod) ))
8685
+ dest_ptr_ty.isSlice(mod))
8690
8686
{
8691
8687
const parent_block = self.context.createBasicBlock("Block");
8692
-
8693
8688
const llvm_usize_ty = self.context.intType(o.target.ptrBitWidth());
8694
- const cond = try self.cmp(len, llvm_usize_ty.constInt(0, .False), Type.usize, .eq );
8689
+ const cond = try self.cmp(len, llvm_usize_ty.constInt(0, .False), Type.usize, .neq );
8695
8690
const then_block = self.context.appendBasicBlock(self.llvm_func, "Then");
8696
- const else_block = self.context.appendBasicBlock(self.llvm_func, "Else");
8697
- _ = self.builder.buildCondBr(cond, then_block, else_block);
8698
-
8691
+ _ = self.builder.buildCondBr(cond, then_block, parent_block);
8699
8692
self.builder.positionBuilderAtEnd(then_block);
8700
- _ = self.builder.buildBr(parent_block);
8701
-
8702
- self.builder.positionBuilderAtEnd(else_block);
8703
8693
_ = self.builder.buildMemCpy(
8704
8694
dest_ptr,
8705
8695
dest_ptr_ty.ptrAlignment(mod),
0 commit comments