add behavior test for @memset on slices

and avoid new language feature in std.ArrayList for now, until x86_64
self-hosted backend can implement it.
This commit is contained in:
Andrew Kelley
2023-04-23 15:26:57 -07:00
parent 482a0f648c
commit 7c56145a76
2 changed files with 64 additions and 2 deletions

View File

@@ -121,7 +121,13 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
mem.copy(T, new_memory, self.items);
@memset(self.items, undefined);
// TODO: write like this instead:
//@memset(self.items, undefined);
// first we need to implement memset with element ABI size > 1 in
// the x86_64 selfhosted backend.
@memset(@ptrCast([*]u8, self.items.ptr)[0..self.items.len * @sizeOf(T)], undefined);
self.clearAndFree();
return new_memory;
}
@@ -597,7 +603,13 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
mem.copy(T, new_memory, self.items);
@memset(self.items, undefined);
// TODO: write like this instead:
//@memset(self.items, undefined);
// first we need to implement memset with element ABI size > 1 in
// the x86_64 selfhosted backend.
@memset(@ptrCast([*]u8, self.items.ptr)[0..self.items.len * @sizeOf(T)], undefined);
self.clearAndFree(allocator);
return new_memory;
}