23 assert(is_addition_overflow_custom == !maybe_add.has_value());
29 const bool is_addition_overflow_builtin = __builtin_add_overflow(i, j, &result_builtin);
30 assert(is_addition_overflow_custom == is_addition_overflow_builtin);
31 if (!is_addition_overflow_custom) {
32 assert(i + j == result_builtin);
35 if (is_addition_overflow_custom) {
36 assert(sat_add == std::numeric_limits<T>::min() || sat_add == std::numeric_limits<T>::max());
38 const auto add{i + j};
39 assert(add == maybe_add.value());
48 TestAdditionOverflow<int64_t>(fuzzed_data_provider);
49 TestAdditionOverflow<uint64_t>(fuzzed_data_provider);
50 TestAdditionOverflow<int32_t>(fuzzed_data_provider);
51 TestAdditionOverflow<uint32_t>(fuzzed_data_provider);
52 TestAdditionOverflow<int16_t>(fuzzed_data_provider);
53 TestAdditionOverflow<uint16_t>(fuzzed_data_provider);
54 TestAdditionOverflow<char>(fuzzed_data_provider);
55 TestAdditionOverflow<unsigned char>(fuzzed_data_provider);
56 TestAdditionOverflow<signed char>(fuzzed_data_provider);
FUZZ_TARGET(addition_overflow)
#define T(expected, seed, data)
std::optional< T > CheckedAdd(const T i, const T j) noexcept
bool AdditionOverflow(const T i, const T j) noexcept
T SaturatingAdd(const T i, const T j) noexcept