Skip to content

Commit

Permalink
Do not use __builtin_unreachable() in PCRE2_ASSERT()
Browse files Browse the repository at this point in the history
__builting_unreachable() implementation is not defined and has
been known to not trigger failures under some compilers.

Default instead to using assert(), which has the added benefit
of printing a descriptive message and it is also likely more
portable as it is part of ANSI C.
  • Loading branch information
carenas committed Sep 20, 2024
1 parent 86d9ac3 commit d9a058a
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 25 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ CHECK_C_SOURCE_COMPILES(
HAVE_BUILTIN_ASSUME
)

CHECK_C_SOURCE_COMPILES(
"int main(void) { if (__builtin_expect(1+1, 2)) return 1; return 0; }"
HAVE_BUILTIN_EXPECT
)

CHECK_C_SOURCE_COMPILES(
"#include <stddef.h>
int main(void) { int a,b; size_t m; __builtin_mul_overflow(a,b,&m); return 0; }"
Expand Down
14 changes: 0 additions & 14 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@ if test "$pcre2_cc_cv_builtin_assume" = yes; then
fi
AC_LANG_POP([C])

# Check for the expect() builtin

AC_MSG_CHECKING([for __builtin_expect()])
AC_LANG_PUSH([C])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[if (__builtin_expect(1+1, 2)) return 1]])],
[pcre2_cc_cv_builtin_expect=yes],
[pcre2_cc_cv_builtin_expect=no])
AC_MSG_RESULT([$pcre2_cc_cv_builtin_expect])
if test "$pcre2_cc_cv_builtin_expect" = yes; then
AC_DEFINE([HAVE_BUILTIN_EXPECT], 1,
[Define this if your compiler provides __builtin_expect()])
fi
AC_LANG_POP([C])

# Check for the mul_overflow() builtin

AC_MSG_CHECKING([for __builtin_mul_overflow()])
Expand Down
4 changes: 1 addition & 3 deletions src/pcre2_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#endif

#ifdef PCRE2_DEBUG
#if defined(HAVE_BUILTIN_EXPECT) && defined(HAVE_BUILTIN_UNREACHABLE)
#define PCRE2_ASSERT(x) do { if (__builtin_expect(!(x), 0)) __builtin_unreachable(); } while (0)
#elif defined(HAVE_ASSERT_H)
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
#include <assert.h>
#define PCRE2_ASSERT(x) assert(x)
#elif defined(HAVE_STDLIB_H) && defined(HAVE_STDIO_H)
Expand Down
3 changes: 0 additions & 3 deletions vms/configure.com
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,6 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to 1 if you have the 'bcopy' function. */
#define HAVE_BCOPY 1

/* Define this if your compiler provides __builtin_expect() */
#undef HAVE_BUILTIN_EXPECT

/* Define this if your compiler provides __builtin_mul_overflow() */
#undef HAVE_BUILTIN_MUL_OVERFLOW

Expand Down

0 comments on commit d9a058a

Please sign in to comment.