#include <os/overflow.h>
os/overflow.h
Facilities for performing type- and overflow-checked arithmetic. These
functions return non-zero if overflow occured, zero otherwise. In either case,
the potentially overflowing operation is fully performed, mod the size of the
output type. See:
http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins
for full details.
The compiler enforces that users of os_*_overflow() check the return value to
determine whether overflow occured.
function__os_warn_unused
bool __header_always_inline OS_WARN_RESULT __os_warn_unused(__const bool x)
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu libkern/os/overflow.h
Identity function returning its boolean argument, marked OS_WARN_RESULT. The os_add_overflow, os_sub_overflow, os_mul_overflow, and related macros wrap their overflow-flag result in it so the compiler warns if a caller discards the overflow indication.
macroos_add_overflow
#define os_add_overflow(a, b, res) __os_warn_unused(__builtin_add_overflow((a), (b), (res)))
macroos_sub_overflow
#define os_sub_overflow(a, b, res) __os_warn_unused(__builtin_sub_overflow((a), (b), (res)))
macroos_mul_overflow
#define os_mul_overflow(a, b, res) __os_warn_unused(__builtin_mul_overflow((a), (b), (res)))
macroos_add3_overflow
os_add3_overflow(a, b, c) -> (a + b + c)
#define os_add3_overflow(a, b, c, res) __os_warn_unused(__extension__({ __typeof(*(res)) _tmp; bool _s, _t; _s = os_add_overflow((a), (b), &_tmp); _t = os_add_overflow((c), _tmp, (res)); _s | _t; }))
macroos_sub3_overflow
os_sub3_overflow(a, b, c) -> ((a - b) - c)
#define os_sub3_overflow(a, b, c, res) __os_warn_unused(__extension__({ __typeof(*(res)) _tmp; bool _s, _t; _s = os_sub_overflow((a), (b), &_tmp); _t = os_sub_overflow(_tmp, (c), (res)); _s | _t; }))
macroos_mul3_overflow
os_mul3_overflow(a, b, c) -> (a * b * c)
#define os_mul3_overflow(a, b, c, res) __os_warn_unused(__extension__({ __typeof(*(res)) _tmp; bool _s, _t; _s = os_mul_overflow((a), (b), &_tmp); _t = os_mul_overflow((c), _tmp, (res)); _s | _t; }))
macroos_add_and_mul_overflow
os_add_and_mul_overflow(a, b, x) -> (a + b)*x
#define os_add_and_mul_overflow(a, b, x, res) __os_warn_unused(__extension__({ __typeof(*(res)) _tmp; bool _s, _t; _s = os_add_overflow((a), (b), &_tmp); _t = os_mul_overflow((x), _tmp, (res)); _s | _t; }))
macroos_mul_and_add_overflow
os_mul_and_add_overflow(a, x, b) -> a*x + b
#define os_mul_and_add_overflow(a, x, b, res) __os_warn_unused(__extension__({ __typeof(*(res)) _tmp; bool _s, _t; _s = os_mul_overflow((a), (x), &_tmp); _t = os_add_overflow((b), _tmp, (res)); _s | _t; }))
macroos_convert_overflow
os_convert_overflow(a) -> a [converted to the result type]
#define os_convert_overflow(a, res) os_add_overflow((a), 0, (res))
macroos_inc_overflow
os_inc_overflow(res) -> *res += 1
#define os_inc_overflow(res) __os_warn_unused(__extension__({ __typeof((res)) _tmp = (res); os_add_overflow(*_tmp, 1, _tmp); }))
macroos_dec_overflow
os_dec_overflow(res) -> *res -= 1
#define os_dec_overflow(res) __os_warn_unused(__extension__({ __typeof((res)) _tmp = (res); os_sub_overflow(*_tmp, 1, _tmp); }))