authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-04-28 15:06:18-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-28 15:06:18-04:00
log8facd99d41b1290f9b29ec22c9dcce680d972810
tree0ab61812da58df4127b8b56ec43eb88c0e6d5eb2
parentd038676a1f46ecab2bd095d3503ab05bcd8de58c
parent8be4511061f18e1bf2b6f7bf108482c6d1e30aa6
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23708 from ziglang/memmove-followups

`@memmove` followups

13 files changed, 60 insertions(+), 96 deletions(-)

lib/std/debug.zig+4-6
...@@ -126,18 +126,16 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {...@@ -126,18 +126,16 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
126 @branchHint(.cold);126 @branchHint(.cold);
127 call("for loop over objects with non-equal lengths", @returnAddress());127 call("for loop over objects with non-equal lengths", @returnAddress());
128 }128 }
129 pub fn memcpyLenMismatch() noreturn {129 /// Delete after next zig1.wasm update
130 pub const memcpyLenMismatch = copyLenMismatch;
131 pub fn copyLenMismatch() noreturn {
130 @branchHint(.cold);132 @branchHint(.cold);
131 call("@memcpy arguments have non-equal lengths", @returnAddress());133 call("source and destination arguments have non-equal lengths", @returnAddress());
132 }134 }
133 pub fn memcpyAlias() noreturn {135 pub fn memcpyAlias() noreturn {
134 @branchHint(.cold);136 @branchHint(.cold);
135 call("@memcpy arguments alias", @returnAddress());137 call("@memcpy arguments alias", @returnAddress());
136 }138 }
137 pub fn memmoveLenMismatch() noreturn {
138 @branchHint(.cold);
139 call("@memmove arguments have non-equal lengths", @returnAddress());
140 }
141 pub fn noreturnReturned() noreturn {139 pub fn noreturnReturned() noreturn {
142 @branchHint(.cold);140 @branchHint(.cold);
143 call("'noreturn' function returned", @returnAddress());141 call("'noreturn' function returned", @returnAddress());
lib/std/debug/no_panic.zig+4-6
...@@ -125,17 +125,15 @@ pub fn forLenMismatch() noreturn {...@@ -125,17 +125,15 @@ pub fn forLenMismatch() noreturn {
125 @trap();125 @trap();
126}126}
127127
128pub fn memcpyLenMismatch() noreturn {128/// Delete after next zig1.wasm update
129 @branchHint(.cold);129pub const memcpyLenMismatch = copyLenMismatch;
130 @trap();
131}
132130
133pub fn memcpyAlias() noreturn {131pub fn copyLenMismatch() noreturn {
134 @branchHint(.cold);132 @branchHint(.cold);
135 @trap();133 @trap();
136}134}
137135
138pub fn memmoveLenMismatch() noreturn {136pub fn memcpyAlias() noreturn {
139 @branchHint(.cold);137 @branchHint(.cold);
140 @trap();138 @trap();
141}139}
lib/std/debug/simple_panic.zig+5-6
...@@ -120,18 +120,17 @@ pub fn forLenMismatch() noreturn {...@@ -120,18 +120,17 @@ pub fn forLenMismatch() noreturn {
120 call("for loop over objects with non-equal lengths", null);120 call("for loop over objects with non-equal lengths", null);
121}121}
122122
123pub fn memcpyLenMismatch() noreturn {123/// Delete after next zig1.wasm update
124 call("@memcpy arguments have non-equal lengths", null);124pub const memcpyLenMismatch = copyLenMismatch;
125
126pub fn copyLenMismatch() noreturn {
127 call("source and destination have non-equal lengths", null);
125}128}
126129
127pub fn memcpyAlias() noreturn {130pub fn memcpyAlias() noreturn {
128 call("@memcpy arguments alias", null);131 call("@memcpy arguments alias", null);
129}132}
130133
131pub fn memmoveLenMismatch() noreturn {
132 call("@memmove arguments have non-equal lengths", null);
133}
134
135pub fn noreturnReturned() noreturn {134pub fn noreturnReturned() noreturn {
136 call("'noreturn' function returned", null);135 call("'noreturn' function returned", null);
137}136}
lib/std/zig/Zir.zig+3-3
...@@ -983,12 +983,12 @@ pub const Inst = struct {...@@ -983,12 +983,12 @@ pub const Inst = struct {
983 /// Implements the `@memcpy` builtin.983 /// Implements the `@memcpy` builtin.
984 /// Uses the `pl_node` union field with payload `Bin`.984 /// Uses the `pl_node` union field with payload `Bin`.
985 memcpy,985 memcpy,
986 /// Implements the `@memset` builtin.
987 /// Uses the `pl_node` union field with payload `Bin`.
988 memset,
989 /// Implements the `@memmove` builtin.986 /// Implements the `@memmove` builtin.
990 /// Uses the `pl_node` union field with payload `Bin`.987 /// Uses the `pl_node` union field with payload `Bin`.
991 memmove,988 memmove,
989 /// Implements the `@memset` builtin.
990 /// Uses the `pl_node` union field with payload `Bin`.
991 memset,
992 /// Implements the `@min` builtin for 2 args.992 /// Implements the `@min` builtin for 2 args.
993 /// Uses the `pl_node` union field with payload `Bin`993 /// Uses the `pl_node` union field with payload `Bin`
994 min,994 min,
src/Sema.zig+14-34
...@@ -1574,17 +1574,17 @@ fn analyzeBodyInner(...@@ -1574,17 +1574,17 @@ fn analyzeBodyInner(
1574 continue;1574 continue;
1575 },1575 },
1576 .memcpy => {1576 .memcpy => {
1577 try sema.zirMemcpy(block, inst);1577 try sema.zirMemcpy(block, inst, .memcpy, true);
1578 i += 1;1578 i += 1;
1579 continue;1579 continue;
1580 },1580 },
1581 .memset => {1581 .memmove => {
1582 try sema.zirMemset(block, inst);1582 try sema.zirMemcpy(block, inst, .memmove, false);
1583 i += 1;1583 i += 1;
1584 continue;1584 continue;
1585 },1585 },
1586 .memmove => {1586 .memset => {
1587 try sema.zirMemmove(block, inst);1587 try sema.zirMemset(block, inst);
1588 i += 1;1588 i += 1;
1589 continue;1589 continue;
1590 },1590 },
...@@ -25630,19 +25630,12 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A...@@ -25630,19 +25630,12 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
25630 return block.addBitCast(new_ty, non_slice_ptr);25630 return block.addBitCast(new_ty, non_slice_ptr);
25631}25631}
2563225632
25633fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {25633fn zirMemcpy(
25634 return sema.analyzeCopy(block, inst, .memcpy);
25635}
25636
25637fn zirMemmove(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
25638 return sema.analyzeCopy(block, inst, .memmove);
25639}
25640
25641fn analyzeCopy(
25642 sema: *Sema,25634 sema: *Sema,
25643 block: *Block,25635 block: *Block,
25644 inst: Zir.Inst.Index,25636 inst: Zir.Inst.Index,
25645 op: enum { memcpy, memmove },25637 air_tag: Air.Inst.Tag,
25638 check_aliasing: bool,
25646) CompileError!void {25639) CompileError!void {
25647 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25640 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25648 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25641 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -25659,12 +25652,12 @@ fn analyzeCopy(...@@ -25659,12 +25652,12 @@ fn analyzeCopy(
25659 const zcu = pt.zcu;25652 const zcu = pt.zcu;
2566025653
25661 if (dest_ty.isConstPtr(zcu)) {25654 if (dest_ty.isConstPtr(zcu)) {
25662 return sema.fail(block, dest_src, "cannot {s} to constant pointer", .{@tagName(op)});25655 return sema.fail(block, dest_src, "cannot copy to constant pointer", .{});
25663 }25656 }
2566425657
25665 if (dest_len == .none and src_len == .none) {25658 if (dest_len == .none and src_len == .none) {
25666 const msg = msg: {25659 const msg = msg: {
25667 const msg = try sema.errMsg(src, "unknown @{s} length", .{@tagName(op)});25660 const msg = try sema.errMsg(src, "unknown copy length", .{});
25668 errdefer msg.destroy(sema.gpa);25661 errdefer msg.destroy(sema.gpa);
25669 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{25662 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
25670 dest_ty.fmt(pt),25663 dest_ty.fmt(pt),
...@@ -25710,7 +25703,7 @@ fn analyzeCopy(...@@ -25710,7 +25703,7 @@ fn analyzeCopy(
25710 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {25703 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {
25711 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {25704 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {
25712 const msg = msg: {25705 const msg = msg: {
25713 const msg = try sema.errMsg(src, "non-matching @{s} lengths", .{@tagName(op)});25706 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});
25714 errdefer msg.destroy(sema.gpa);25707 errdefer msg.destroy(sema.gpa);
25715 try sema.errNote(dest_src, msg, "length {} here", .{25708 try sema.errNote(dest_src, msg, "length {} here", .{
25716 dest_len_val.fmtValueSema(pt, sema),25709 dest_len_val.fmtValueSema(pt, sema),
...@@ -25730,11 +25723,7 @@ fn analyzeCopy(...@@ -25730,11 +25723,7 @@ fn analyzeCopy(
2573025723
25731 if (block.wantSafety()) {25724 if (block.wantSafety()) {
25732 const ok = try block.addBinOp(.cmp_eq, dest_len, src_len);25725 const ok = try block.addBinOp(.cmp_eq, dest_len, src_len);
25733 const panic_id: Zcu.SimplePanicId = switch (op) {25726 try sema.addSafetyCheck(block, src, ok, .copy_len_mismatch);
25734 .memcpy => .memcpy_len_mismatch,
25735 .memmove => .memmove_len_mismatch,
25736 };
25737 try sema.addSafetyCheck(block, src, ok, panic_id);
25738 }25727 }
25739 } else if (dest_len != .none) {25728 } else if (dest_len != .none) {
25740 if (try sema.resolveDefinedValue(block, dest_src, dest_len)) |dest_len_val| {25729 if (try sema.resolveDefinedValue(block, dest_src, dest_len)) |dest_len_val| {
...@@ -25762,11 +25751,6 @@ fn analyzeCopy(...@@ -25762,11 +25751,6 @@ fn analyzeCopy(
25762 return;25751 return;
25763 }25752 }
2576425753
25765 const check_aliasing = switch (op) {
25766 .memcpy => true,
25767 .memmove => false,
25768 };
25769
25770 const runtime_src = rs: {25754 const runtime_src = rs: {
25771 const dest_ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;25755 const dest_ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;
25772 const src_ptr_val = try sema.resolveDefinedValue(block, src_src, src_ptr) orelse break :rs src_src;25756 const src_ptr_val = try sema.resolveDefinedValue(block, src_src, src_ptr) orelse break :rs src_src;
...@@ -25898,10 +25882,7 @@ fn analyzeCopy(...@@ -25898,10 +25882,7 @@ fn analyzeCopy(
25898 }25882 }
2589925883
25900 _ = try block.addInst(.{25884 _ = try block.addInst(.{
25901 .tag = switch (op) {25885 .tag = air_tag,
25902 .memcpy => .memcpy,
25903 .memmove => .memmove,
25904 },
25905 .data = .{ .bin_op = .{25886 .data = .{ .bin_op = .{
25906 .lhs = new_dest_ptr,25887 .lhs = new_dest_ptr,
25907 .rhs = new_src_ptr,25888 .rhs = new_src_ptr,
...@@ -38153,9 +38134,8 @@ fn getExpectedBuiltinFnType(sema: *Sema, decl: Zcu.BuiltinDecl) CompileError!Typ...@@ -38153,9 +38134,8 @@ fn getExpectedBuiltinFnType(sema: *Sema, decl: Zcu.BuiltinDecl) CompileError!Typ
38153 .@"panic.shiftRhsTooBig",38134 .@"panic.shiftRhsTooBig",
38154 .@"panic.invalidEnumValue",38135 .@"panic.invalidEnumValue",
38155 .@"panic.forLenMismatch",38136 .@"panic.forLenMismatch",
38156 .@"panic.memcpyLenMismatch",38137 .@"panic.copyLenMismatch",
38157 .@"panic.memcpyAlias",38138 .@"panic.memcpyAlias",
38158 .@"panic.memmoveLenMismatch",
38159 .@"panic.noreturnReturned",38139 .@"panic.noreturnReturned",
38160 => try pt.funcType(.{38140 => try pt.funcType(.{
38161 .param_types = &.{},38141 .param_types = &.{},
src/Zcu.zig+4-8
...@@ -300,9 +300,8 @@ pub const BuiltinDecl = enum {...@@ -300,9 +300,8 @@ pub const BuiltinDecl = enum {
300 @"panic.shiftRhsTooBig",300 @"panic.shiftRhsTooBig",
301 @"panic.invalidEnumValue",301 @"panic.invalidEnumValue",
302 @"panic.forLenMismatch",302 @"panic.forLenMismatch",
303 @"panic.memcpyLenMismatch",303 @"panic.copyLenMismatch",
304 @"panic.memcpyAlias",304 @"panic.memcpyAlias",
305 @"panic.memmoveLenMismatch",
306 @"panic.noreturnReturned",305 @"panic.noreturnReturned",
307306
308 VaList,307 VaList,
...@@ -378,9 +377,8 @@ pub const BuiltinDecl = enum {...@@ -378,9 +377,8 @@ pub const BuiltinDecl = enum {
378 .@"panic.shiftRhsTooBig",377 .@"panic.shiftRhsTooBig",
379 .@"panic.invalidEnumValue",378 .@"panic.invalidEnumValue",
380 .@"panic.forLenMismatch",379 .@"panic.forLenMismatch",
381 .@"panic.memcpyLenMismatch",380 .@"panic.copyLenMismatch",
382 .@"panic.memcpyAlias",381 .@"panic.memcpyAlias",
383 .@"panic.memmoveLenMismatch",
384 .@"panic.noreturnReturned",382 .@"panic.noreturnReturned",
385 => .func,383 => .func,
386 };384 };
...@@ -446,9 +444,8 @@ pub const SimplePanicId = enum {...@@ -446,9 +444,8 @@ pub const SimplePanicId = enum {
446 shift_rhs_too_big,444 shift_rhs_too_big,
447 invalid_enum_value,445 invalid_enum_value,
448 for_len_mismatch,446 for_len_mismatch,
449 memcpy_len_mismatch,447 copy_len_mismatch,
450 memcpy_alias,448 memcpy_alias,
451 memmove_len_mismatch,
452 noreturn_returned,449 noreturn_returned,
453450
454 pub fn toBuiltin(id: SimplePanicId) BuiltinDecl {451 pub fn toBuiltin(id: SimplePanicId) BuiltinDecl {
...@@ -471,9 +468,8 @@ pub const SimplePanicId = enum {...@@ -471,9 +468,8 @@ pub const SimplePanicId = enum {
471 .shift_rhs_too_big => .@"panic.shiftRhsTooBig",468 .shift_rhs_too_big => .@"panic.shiftRhsTooBig",
472 .invalid_enum_value => .@"panic.invalidEnumValue",469 .invalid_enum_value => .@"panic.invalidEnumValue",
473 .for_len_mismatch => .@"panic.forLenMismatch",470 .for_len_mismatch => .@"panic.forLenMismatch",
474 .memcpy_len_mismatch => .@"panic.memcpyLenMismatch",471 .copy_len_mismatch => .@"panic.copyLenMismatch",
475 .memcpy_alias => .@"panic.memcpyAlias",472 .memcpy_alias => .@"panic.memcpyAlias",
476 .memmove_len_mismatch => .@"panic.memmoveLenMismatch",
477 .noreturn_returned => .@"panic.noreturnReturned",473 .noreturn_returned => .@"panic.noreturnReturned",
478 // zig fmt: on474 // zig fmt: on
479 };475 };
src/codegen/c.zig+3-15
...@@ -3348,8 +3348,8 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -3348,8 +3348,8 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
3348 .atomic_load => try airAtomicLoad(f, inst),3348 .atomic_load => try airAtomicLoad(f, inst),
3349 .memset => try airMemset(f, inst, false),3349 .memset => try airMemset(f, inst, false),
3350 .memset_safe => try airMemset(f, inst, true),3350 .memset_safe => try airMemset(f, inst, true),
3351 .memcpy => try airMemcpy(f, inst),3351 .memcpy => try airMemcpy(f, inst, "memcpy("),
3352 .memmove => try airMemmove(f, inst),3352 .memmove => try airMemcpy(f, inst, "memmove("),
3353 .set_union_tag => try airSetUnionTag(f, inst),3353 .set_union_tag => try airSetUnionTag(f, inst),
3354 .get_union_tag => try airGetUnionTag(f, inst),3354 .get_union_tag => try airGetUnionTag(f, inst),
3355 .clz => try airUnBuiltinCall(f, inst, air_datas[@intFromEnum(inst)].ty_op.operand, "clz", .bits),3355 .clz => try airUnBuiltinCall(f, inst, air_datas[@intFromEnum(inst)].ty_op.operand, "clz", .bits),
...@@ -6976,15 +6976,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6976,15 +6976,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6976 return .none;6976 return .none;
6977}6977}
69786978
6979fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {6979fn airMemcpy(f: *Function, inst: Air.Inst.Index, function_paren: []const u8) !CValue {
6980 return copyOp(f, inst, .memcpy);
6981}
6982
6983fn airMemmove(f: *Function, inst: Air.Inst.Index) !CValue {
6984 return copyOp(f, inst, .memmove);
6985}
6986
6987fn copyOp(f: *Function, inst: Air.Inst.Index, op: enum { memcpy, memmove }) !CValue {
6988 const pt = f.object.dg.pt;6980 const pt = f.object.dg.pt;
6989 const zcu = pt.zcu;6981 const zcu = pt.zcu;
6990 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6982 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
...@@ -6999,10 +6991,6 @@ fn copyOp(f: *Function, inst: Air.Inst.Index, op: enum { memcpy, memmove }) !CVa...@@ -6999,10 +6991,6 @@ fn copyOp(f: *Function, inst: Air.Inst.Index, op: enum { memcpy, memmove }) !CVa
6999 try writeArrayLen(f, writer, dest_ptr, dest_ty);6991 try writeArrayLen(f, writer, dest_ptr, dest_ty);
7000 try writer.writeAll(" != 0) ");6992 try writer.writeAll(" != 0) ");
7001 }6993 }
7002 const function_paren = switch (op) {
7003 .memcpy => "memcpy(",
7004 .memmove => "memmove(",
7005 };
7006 try writer.writeAll(function_paren);6994 try writer.writeAll(function_paren);
7007 try writeSliceOrPtr(f, writer, dest_ptr, dest_ty);6995 try writeSliceOrPtr(f, writer, dest_ptr, dest_ty);
7008 try writer.writeAll(", ");6996 try writer.writeAll(", ");
test/cases/compile_errors/bad_panic_call_signature.zig+3-2
...@@ -27,9 +27,10 @@ pub const panic = struct {...@@ -27,9 +27,10 @@ pub const panic = struct {
27 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;27 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;
28 pub const invalidEnumValue = simple_panic.invalidEnumValue;28 pub const invalidEnumValue = simple_panic.invalidEnumValue;
29 pub const forLenMismatch = simple_panic.forLenMismatch;29 pub const forLenMismatch = simple_panic.forLenMismatch;
30 pub const memcpyLenMismatch = simple_panic.memcpyLenMismatch;30 /// Delete after next zig1.wasm update
31 pub const memcpyLenMismatch = copyLenMismatch;
32 pub const copyLenMismatch = simple_panic.copyLenMismatch;
31 pub const memcpyAlias = simple_panic.memcpyAlias;33 pub const memcpyAlias = simple_panic.memcpyAlias;
32 pub const memmoveLenMismatch = simple_panic.memmoveLenMismatch;
33 pub const noreturnReturned = simple_panic.noreturnReturned;34 pub const noreturnReturned = simple_panic.noreturnReturned;
34};35};
3536
test/cases/compile_errors/bad_panic_generic_signature.zig+3-2
...@@ -23,9 +23,10 @@ pub const panic = struct {...@@ -23,9 +23,10 @@ pub const panic = struct {
23 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;23 pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;
24 pub const invalidEnumValue = simple_panic.invalidEnumValue;24 pub const invalidEnumValue = simple_panic.invalidEnumValue;
25 pub const forLenMismatch = simple_panic.forLenMismatch;25 pub const forLenMismatch = simple_panic.forLenMismatch;
26 pub const memcpyLenMismatch = simple_panic.memcpyLenMismatch;26 /// Delete after next zig1.wasm update
27 pub const memcpyLenMismatch = copyLenMismatch;
28 pub const copyLenMismatch = simple_panic.copyLenMismatch;
27 pub const memcpyAlias = simple_panic.memcpyAlias;29 pub const memcpyAlias = simple_panic.memcpyAlias;
28 pub const memmoveLenMismatch = simple_panic.memmoveLenMismatch;
29 pub const noreturnReturned = simple_panic.noreturnReturned;30 pub const noreturnReturned = simple_panic.noreturnReturned;
30};31};
3132
test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig+6-6
...@@ -66,29 +66,29 @@ pub export fn memset_array() void {...@@ -66,29 +66,29 @@ pub export fn memset_array() void {
66// backend=stage266// backend=stage2
67// target=native67// target=native
68//68//
69// :5:5: error: unknown @memcpy length69// :5:5: error: unknown copy length
70// :5:18: note: destination type '[*]u8' provides no length70// :5:18: note: destination type '[*]u8' provides no length
71// :5:24: note: source type '[*]const u8' provides no length71// :5:24: note: source type '[*]const u8' provides no length
72// :10:13: error: type '*u8' is not an indexable pointer72// :10:13: error: type '*u8' is not an indexable pointer
73// :10:13: note: operand must be a slice, a many pointer or a pointer to an array73// :10:13: note: operand must be a slice, a many pointer or a pointer to an array
74// :15:13: error: type '*u8' is not an indexable pointer74// :15:13: error: type '*u8' is not an indexable pointer
75// :15:13: note: operand must be a slice, a many pointer or a pointer to an array75// :15:13: note: operand must be a slice, a many pointer or a pointer to an array
76// :20:5: error: non-matching @memcpy lengths76// :20:5: error: non-matching copy lengths
77// :20:13: note: length 6 here77// :20:13: note: length 6 here
78// :20:20: note: length 5 here78// :20:20: note: length 5 here
79// :24:13: error: cannot memset constant pointer79// :24:13: error: cannot memset constant pointer
80// :29:13: error: cannot memcpy to constant pointer80// :29:13: error: cannot copy to constant pointer
81// :33:13: error: type '[5]u8' is not an indexable pointer81// :33:13: error: type '[5]u8' is not an indexable pointer
82// :33:13: note: operand must be a slice, a many pointer or a pointer to an array82// :33:13: note: operand must be a slice, a many pointer or a pointer to an array
83// :39:5: error: unknown @memmove length83// :39:5: error: unknown copy length
84// :39:19: note: destination type '[*]u8' provides no length84// :39:19: note: destination type '[*]u8' provides no length
85// :39:25: note: source type '[*]const u8' provides no length85// :39:25: note: source type '[*]const u8' provides no length
86// :44:14: error: type '*u8' is not an indexable pointer86// :44:14: error: type '*u8' is not an indexable pointer
87// :44:14: note: operand must be a slice, a many pointer or a pointer to an array87// :44:14: note: operand must be a slice, a many pointer or a pointer to an array
88// :49:5: error: non-matching @memmove lengths88// :49:5: error: non-matching copy lengths
89// :49:14: note: length 6 here89// :49:14: note: length 6 here
90// :49:21: note: length 5 here90// :49:21: note: length 5 here
91// :54:14: error: cannot memmove to constant pointer91// :54:14: error: cannot copy to constant pointer
92// :58:14: error: type '[5]u8' is not an indexable pointer92// :58:14: error: type '[5]u8' is not an indexable pointer
93// :58:14: note: operand must be a slice, a many pointer or a pointer to an array93// :58:14: note: operand must be a slice, a many pointer or a pointer to an array
94// :62:13: error: type '[5]u8' is not an indexable pointer94// :62:13: error: type '[5]u8' is not an indexable pointer
test/cases/safety/memcpy_len_mismatch.zig+1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "@memcpy arguments have non-equal lengths")) {5 if (std.mem.eql(u8, message, "source and destination arguments have non-equal lengths")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/memmove_len_mismatch.zig+1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "@memmove arguments have non-equal lengths")) {5 if (std.mem.eql(u8, message, "source and destination arguments have non-equal lengths")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/incremental/change_panic_handler_explicit+9-6
...@@ -37,9 +37,10 @@ pub const panic = struct {...@@ -37,9 +37,10 @@ pub const panic = struct {
37 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;37 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
38 pub const invalidEnumValue = no_panic.invalidEnumValue;38 pub const invalidEnumValue = no_panic.invalidEnumValue;
39 pub const forLenMismatch = no_panic.forLenMismatch;39 pub const forLenMismatch = no_panic.forLenMismatch;
40 pub const memcpyLenMismatch = no_panic.memcpyLenMismatch;40 /// Delete after next zig1.wasm update
41 pub const memcpyLenMismatch = copyLenMismatch;
42 pub const copyLenMismatch = no_panic.copyLenMismatch;
41 pub const memcpyAlias = no_panic.memcpyAlias;43 pub const memcpyAlias = no_panic.memcpyAlias;
42 pub const memmoveLenMismatch = no_panic.memmoveLenMismatch;
43 pub const noreturnReturned = no_panic.noreturnReturned;44 pub const noreturnReturned = no_panic.noreturnReturned;
44};45};
45fn myPanic(msg: []const u8, _: ?usize) noreturn {46fn myPanic(msg: []const u8, _: ?usize) noreturn {
...@@ -85,9 +86,10 @@ pub const panic = struct {...@@ -85,9 +86,10 @@ pub const panic = struct {
85 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;86 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
86 pub const invalidEnumValue = no_panic.invalidEnumValue;87 pub const invalidEnumValue = no_panic.invalidEnumValue;
87 pub const forLenMismatch = no_panic.forLenMismatch;88 pub const forLenMismatch = no_panic.forLenMismatch;
88 pub const memcpyLenMismatch = no_panic.memcpyLenMismatch;89 /// Delete after next zig1.wasm update
90 pub const memcpyLenMismatch = copyLenMismatch;
91 pub const copyLenMismatch = no_panic.copyLenMismatch;
89 pub const memcpyAlias = no_panic.memcpyAlias;92 pub const memcpyAlias = no_panic.memcpyAlias;
90 pub const memmoveLenMismatch = no_panic.memmoveLenMismatch;
91 pub const noreturnReturned = no_panic.noreturnReturned;93 pub const noreturnReturned = no_panic.noreturnReturned;
92};94};
93fn myPanic(msg: []const u8, _: ?usize) noreturn {95fn myPanic(msg: []const u8, _: ?usize) noreturn {
...@@ -133,9 +135,10 @@ pub const panic = struct {...@@ -133,9 +135,10 @@ pub const panic = struct {
133 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;135 pub const shiftRhsTooBig = no_panic.shiftRhsTooBig;
134 pub const invalidEnumValue = no_panic.invalidEnumValue;136 pub const invalidEnumValue = no_panic.invalidEnumValue;
135 pub const forLenMismatch = no_panic.forLenMismatch;137 pub const forLenMismatch = no_panic.forLenMismatch;
136 pub const memcpyLenMismatch = no_panic.memcpyLenMismatch;138 /// Delete after next zig1.wasm update
139 pub const memcpyLenMismatch = copyLenMismatch;
140 pub const copyLenMismatch = no_panic.copyLenMismatch;
137 pub const memcpyAlias = no_panic.memcpyAlias;141 pub const memcpyAlias = no_panic.memcpyAlias;
138 pub const memmoveLenMismatch = no_panic.memmoveLenMismatch;
139 pub const noreturnReturned = no_panic.noreturnReturned;142 pub const noreturnReturned = no_panic.noreturnReturned;
140};143};
141fn myPanicNew(msg: []const u8, _: ?usize) noreturn {144fn myPanicNew(msg: []const u8, _: ?usize) noreturn {