feature. See also
. The project being documented here (as the example) is the Zig library itself.
ubsan_rt.alignmentAssumptionHandler
fn alignmentAssumptionHandler(
data: *const AlignmentAssumptionData,
pointer: ValueHandle,
alignment_handle: ValueHandle,
maybe_offset: ?ValueHandle,
) callconv(.c) noreturn
File
Code
fn alignmentAssumptionHandler(
data: *const AlignmentAssumptionData,
pointer: ValueHandle,
alignment_handle: ValueHandle,
maybe_offset: ?ValueHandle,
) callconv(.c) noreturn {
const real_pointer = @intFromPtr(pointer) - @intFromPtr(maybe_offset);
const lsb = @ctz(real_pointer);
const actual_alignment = @as(u64, 1) << @intCast(lsb);
const mask = @intFromPtr(alignment_handle) - 1;
const misalignment_offset = real_pointer & mask;
const alignment: Value = .{ .handle = alignment_handle, .td = data.td };
if (maybe_offset) |offset| {
panic(
@returnAddress(),
"assumption of {f} byte alignment (with offset of {d} byte) for pointer of type {s} failed\n" ++
"offset address is {d} aligned, misalignment offset is {d} bytes",
.{
alignment,
@intFromPtr(offset),
data.td.getName(),
actual_alignment,
misalignment_offset,
},
);
} else {
panic(
@returnAddress(),
"assumption of {f} byte alignment for pointer of type {s} failed\n" ++
"address is {d} aligned, misalignment offset is {d} bytes",
.{
alignment,
data.td.getName(),
actual_alignment,
misalignment_offset,
},
);
}
}