feature. See also
. The project being documented here (as the example) is the Zig library itself.
ubsan_rt.overflowHandler
fn overflowHandler(
comptime sym_name: []const u8,
comptime operator: []const u8,
) void
File
Code
fn overflowHandler(
comptime sym_name: []const u8,
comptime operator: []const u8,
) void {
const S = struct {
fn abort(
data: *const OverflowData,
lhs_handle: ValueHandle,
rhs_handle: ValueHandle,
) callconv(.c) noreturn {
handler(data, lhs_handle, rhs_handle);
}
fn handler(
data: *const OverflowData,
lhs_handle: ValueHandle,
rhs_handle: ValueHandle,
) callconv(.c) noreturn {
const lhs: Value = .{ .handle = lhs_handle, .td = data.td };
const rhs: Value = .{ .handle = rhs_handle, .td = data.td };
const signed_str = if (data.td.isSigned()) "signed" else "unsigned";
panic(
@returnAddress(),
"{s} integer overflow: {f} " ++ operator ++ " {f} cannot be represented in type {s}",
.{ signed_str, lhs, rhs, data.td.getName() },
);
}
};
exportHandlerWithAbort(&S.handler, &S.abort, sym_name);
}