diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-07-18 10:42:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-19 19:57:37 -0700 |
| commit | 83d1f88ac5f053f11b91d9c3d51f5c63355b8ca3 (patch) | |
| tree | 784f498b7be97cc466a2ee2234baa5bb92b79e00 /lib/std/debug.zig | |
| parent | bad836a69bf3c1da29f39ed1a6c8bf6c66febfb6 (diff) | |
| download | zig-83d1f88ac5f053f11b91d9c3d51f5c63355b8ca3.tar.gz zig-83d1f88ac5f053f11b91d9c3d51f5c63355b8ca3.zip | |
std.debug: add assertAligned
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index a7b88e4257..655852c65e 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -566,6 +566,13 @@ pub fn assertReadable(slice: []const volatile u8) void { for (slice) |*byte| _ = byte.*; } +/// Invokes detectable illegal behavior when the provided array is not aligned +/// to the provided amount. +pub fn assertAligned(ptr: anytype, comptime alignment: std.mem.Alignment) void { + const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @alignCast(@ptrCast(ptr)); + _ = aligned_ptr; +} + /// Equivalent to `@panic` but with a formatted message. pub fn panic(comptime format: []const u8, args: anytype) noreturn { @branchHint(.cold); |
