['__builtin_uadd_overflow', '0U, 0U, (void*)0', false],
['__builtin_uaddl_overflow', '0UL, 0UL, (void*)0', false],
['__builtin_uaddll_overflow', '0ULL, 0ULL, (void*)0', false],
+ ['__builtin_umul_overflow', '0U, 0U, (void*)0', false],
+ ['__builtin_umull_overflow', '0UL, 0UL, (void*)0', false],
+ ['__builtin_umulll_overflow', '0ULL, 0ULL, (void*)0', false],
]
foreach tuple : _builtins
builtin = tuple[0]
return UINT64_MAX - a < b;
#endif
}
+
+static inline bool umul32_overflow(uint32_t a, uint32_t b, uint32_t *res)
+{
+#if (HAVE___BUILTIN_UMUL_OVERFLOW && __SIZEOF_INT__ == 4)
+ return __builtin_umul_overflow(a, b, res);
+#else
+ *res = a * b;
+ return UINT32_MAX / a < b;
+#endif
+}
+
+static inline bool umul64_overflow(uint64_t a, uint64_t b, uint64_t *res)
+{
+#if (HAVE___BUILTIN_UMULL_OVERFLOW && __SIZEOF_LONG__ == 8)
+ return __builtin_umull_overflow(a, b, res);
+#elif (HAVE___BUILTIN_UMULLL_OVERFLOW && __SIZEOF_LONG_LONG__ == 8)
+ return __builtin_umulll_overflow(a, b, res);
+#else
+ *res = a * b;
+ return UINT64_MAX / a < b;
+#endif
+}
DEFINE_TEST(test_uadd64_overflow,
.description = "check implementation of uadd64_overflow()")
+static int test_umul32_overflow(const struct test *t)
+{
+ uint32_t res;
+ bool overflow;
+
+ overflow = umul32_overflow(UINT32_MAX / 0x10, 0x10, &res);
+ assert_return(!overflow, EXIT_FAILURE);
+ assert_return(res == (UINT32_MAX & ~0xf), EXIT_FAILURE);
+
+ overflow = umul32_overflow(UINT32_MAX, 0x10, &res);
+ assert_return(overflow, EXIT_FAILURE);
+
+ return EXIT_SUCCESS;
+}
+DEFINE_TEST(test_umul32_overflow,
+ .description = "check implementation of umul32_overflow()")
+
+static int test_umul64_overflow(const struct test *t)
+{
+ uint64_t res;
+ bool overflow;
+
+ overflow = umul64_overflow(UINT64_MAX / 0x10, 0x10, &res);
+ assert_return(!overflow, EXIT_FAILURE);
+ assert_return(res == (UINT64_MAX & ~0xf), EXIT_FAILURE);
+
+ overflow = umul64_overflow(UINT64_MAX, 0x10, &res);
+ assert_return(overflow, EXIT_FAILURE);
+
+ return EXIT_SUCCESS;
+}
+DEFINE_TEST(test_umul64_overflow,
+ .description = "check implementation of umul64_overflow()")
+
static int test_backoff_time(const struct test *t)
{
unsigned long long delta = 0;