Skip to content

Commit 83d1f88

Browse files
committed
std.debug: add assertAligned
1 parent bad836a commit 83d1f88

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/std/debug.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@ pub fn assertReadable(slice: []const volatile u8) void {
566566
for (slice) |*byte| _ = byte.*;
567567
}
568568

569+
/// Invokes detectable illegal behavior when the provided array is not aligned
570+
/// to the provided amount.
571+
pub fn assertAligned(ptr: anytype, comptime alignment: std.mem.Alignment) void {
572+
const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @alignCast(@ptrCast(ptr));
573+
_ = aligned_ptr;
574+
}
575+
569576
/// Equivalent to `@panic` but with a formatted message.
570577
pub fn panic(comptime format: []const u8, args: anytype) noreturn {
571578
@branchHint(.cold);

0 commit comments

Comments
 (0)