commit 4c9d06416c1f0e4e7bf5139a705c50ad18f9c39a (tree)
parent 175589fc713d0c706812508fb6bb566b77423b83
Author: Justus Klausecker <justusk@noreply.codeberg.org>
Date: Mon, 29 Jun 2026 11:31:49 +0200
Merge pull request 'Test coverage for overlapping assignments' (#35918) from Fri3dNstuff/zig:overlapping-copy into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35918
Reviewed-by: Justus Klausecker <justusk@noreply.codeberg.org>
Diffstat:
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/test/behavior.zig b/test/behavior.zig
@@ -60,6 +60,7 @@ test {
_ = @import("behavior/nan.zig");
_ = @import("behavior/null.zig");
_ = @import("behavior/optional.zig");
+ _ = @import("behavior/overlapping_assign.zig");
_ = @import("behavior/packed-struct.zig");
_ = @import("behavior/packed_struct_explicit_backing_int.zig");
_ = @import("behavior/packed-union.zig");
diff --git a/test/behavior/overlapping_assign.zig b/test/behavior/overlapping_assign.zig
@@ -0,0 +1,49 @@
+const std = @import("std");
+const expect = std.testing.expect;
+
+test "assignment to overlapping memory" {
+ try theTest();
+ try comptime theTest();
+}
+
+fn theTest() !void {
+ var a1: [3]usize = .{ 0, 1, 2 };
+ const b1: [3]usize = .{ 0, 0, 1 };
+ a1[1..3].* = a1[0..2].*;
+ for (a1, b1) |a, b| {
+ try expect(a == b);
+ }
+
+ var a2: [3]usize = .{ 0, 1, 2 };
+ const b2: [3]usize = .{ 1, 2, 2 };
+ a2[0..2].* = a2[1..3].*;
+ for (a2, b2) |a, b| {
+ try expect(a == b);
+ }
+
+ var a3: [16]u8 = .{
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ };
+ const b3: [16]u8 = .{
+ 0, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ };
+ a3[1..16].* = a3[0..15].*;
+ for (a3, b3) |a, b| {
+ try expect(a == b);
+ }
+
+ var a4: [16]u8 = .{
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ };
+ const b4: [16]u8 = .{
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 15,
+ };
+ a4[0..15].* = a4[1..16].*;
+ for (a4, b4) |a, b| {
+ try expect(a == b);
+ }
+}