Sema: @memcpy changes
* The langspec definition of `@memcpy` has been changed so that the source and destination element types must be in-memory coercible, allowing all such calls to be raw copying operations, not actually applying any coercions. * Implement aliasing check for comptime `@memcpy`; a compile error will now be emitted if the arguments alias. * Implement more efficient comptime `@memcpy` by loading and storing a whole array at once, similar to how `@memset` is implemented.
This commit is contained in:
14
test/cases/compile_errors/memcpy_alias.zig
Normal file
14
test/cases/compile_errors/memcpy_alias.zig
Normal file
@@ -0,0 +1,14 @@
|
||||
var arr: [10]u64 = undefined;
|
||||
export fn foo() void {
|
||||
@memcpy(arr[0..6], arr[4..10]);
|
||||
}
|
||||
|
||||
comptime {
|
||||
var types: [4]type = .{ u8, u16, u32, u64 };
|
||||
@memcpy(types[2..4], types[1..3]);
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :3:5: error: '@memcpy' arguments alias
|
||||
// :8:5: error: '@memcpy' arguments alias
|
||||
10
test/cases/compile_errors/memcpy_bad_type.zig
Normal file
10
test/cases/compile_errors/memcpy_bad_type.zig
Normal file
@@ -0,0 +1,10 @@
|
||||
const src: [10]u8 = @splat(0);
|
||||
var dest: [10]u16 = undefined;
|
||||
|
||||
export fn foo() void {
|
||||
@memcpy(&dest, &src);
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :5:5: error: pointer element type 'u8' cannot coerce into element type 'u16'
|
||||
Reference in New Issue
Block a user