diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-01-28 02:49:58 +0000 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-01-29 06:35:22 +0000 |
| commit | 71d16106ad76bb31bc4e17dc37f8d8b5498a12dd (patch) | |
| tree | f8db4c1ed772e3188447afad05156dd6d1c664fc /test/cases/compile_errors/memcpy_alias.zig | |
| parent | 97ccf3504f0b4787b86fa882312aba01ab980121 (diff) | |
| download | zig-71d16106ad76bb31bc4e17dc37f8d8b5498a12dd.tar.gz zig-71d16106ad76bb31bc4e17dc37f8d8b5498a12dd.zip | |
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.
Diffstat (limited to 'test/cases/compile_errors/memcpy_alias.zig')
| -rw-r--r-- | test/cases/compile_errors/memcpy_alias.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/cases/compile_errors/memcpy_alias.zig b/test/cases/compile_errors/memcpy_alias.zig new file mode 100644 index 0000000000..3f6a5653e8 --- /dev/null +++ b/test/cases/compile_errors/memcpy_alias.zig @@ -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 |
