Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

overflowHandler

ubsan_rt.overflowHandler
fn overflowHandler(
    comptime sym_name: []const u8,
    comptime operator: []const u8,
) void

File

lib/ubsan_rt.zig:146

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);
}