[[]],
[[return (__builtin_clz(0xff) == 24 ? 1 : 0);]]
)],
- [have_builtin_clz=yes
- AC_MSG_RESULT(yes)],
- [have_builtin_clz=no
- AC_MSG_RESULT(no)]
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
+ ],
+ [AC_MSG_RESULT([no])]
)
-if test "yes" = "$have_builtin_clz"; then
- AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
-fi
+
+#
+# Check for __builtin_uadd_overflow
+#
+AC_MSG_CHECKING([compiler support for __builtin_*_overflow()])
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <limits.h>]],
+ [[return (__builtin_uadd_overflow(UINT_MAX, UINT_MAX, &(unsigned int){ 0 }));]]
+ )],
+ [AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_BUILTIN_OVERFLOW], [1], [define if the compiler supports __builtin_*_overflow().])
+ ],
+ [AC_MSG_RESULT([no])
+ ])
#
# Activate "rrset-order fixed" or not?
REQUIRE(t->nanoseconds < NS_PER_S && i->nanoseconds < NS_PER_S);
/* Seconds */
+#if HAVE_BUILTIN_OVERFLOW
+ if (__builtin_uadd_overflow(t->seconds, i->seconds, &result->seconds)) {
+ return (ISC_R_RANGE);
+ }
+#else
if (t->seconds > UINT_MAX - i->seconds) {
return (ISC_R_RANGE);
}
result->seconds = t->seconds + i->seconds;
+#endif
/* Nanoseconds */
result->nanoseconds = t->nanoseconds + i->nanoseconds;
REQUIRE(t->nanoseconds < NS_PER_S && i->nanoseconds < NS_PER_S);
/* Seconds */
+#if HAVE_BUILTIN_OVERFLOW
+ if (__builtin_usub_overflow(t->seconds, i->seconds, &result->seconds)) {
+ return (ISC_R_RANGE);
+ }
+#else
if (t->seconds < i->seconds) {
return (ISC_R_RANGE);
}
result->seconds = t->seconds - i->seconds;
+#endif
/* Nanoseconds */
if (t->nanoseconds >= i->nanoseconds) {