From 4f6c43d2c317f2cce9160aa4c2fcafb6ab0810ec Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Wed, 28 Aug 2024 15:43:58 +0200 Subject: [PATCH] Add assertion macros, use new PCRE2_UNREACHABLE assertion at unreachable points in code (#446) * Correct typo ('mimimum' -> 'minimum') * Add assertion macros * Use PCRE2_UNREACHABLE assertion for unreachable points in code --- CMakeLists.txt | 11 ++++++ HACKING | 2 +- config-cmake.h.in | 3 ++ configure.ac | 30 ++++++++++++++- src/config.h.generic | 9 +++++ src/config.h.in | 9 +++++ src/pcre2.h.generic | 23 ++++++++++++ src/pcre2.h.in | 23 ++++++++++++ src/pcre2_auto_possess.c | 9 +++-- src/pcre2_compile.c | 14 ++++--- src/pcre2_convert.c | 4 +- src/pcre2_match.c | 80 +++++++++++++++++++++++++--------------- src/pcre2_study.c | 3 +- src/pcre2grep.c | 5 ++- src/pcre2test.c | 5 ++- vms/configure.com | 8 ++++ 16 files changed, 188 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cec5009de..1877ff8f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,7 @@ INCLUDE(CheckIncludeFile) INCLUDE(CheckTypeSize) INCLUDE(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR +CHECK_INCLUDE_FILE(assert.h HAVE_ASSERT_H) CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H) CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) @@ -169,12 +170,22 @@ if(NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "XL") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror") endif() +CHECK_C_SOURCE_COMPILES( + "int main(void) { __builtin_expect(1+1, 2); return 0; }" + HAVE_BUILTIN_EXPECT +) + CHECK_C_SOURCE_COMPILES( "#include int main(void) { int a,b; size_t m; __builtin_mul_overflow(a,b,&m); return 0; }" HAVE_BUILTIN_MUL_OVERFLOW ) +CHECK_C_SOURCE_COMPILES( + "int main(void) { if (0) __builtin_unreachable(); return 0; }" + HAVE_BUILTIN_UNREACHABLE +) + CHECK_C_SOURCE_COMPILES( "int main(void) { char buf[128] __attribute__((uninitialized)); (void)buf; return 0; }" HAVE_ATTRIBUTE_UNINITIALIZED diff --git a/HACKING b/HACKING index 7f0aec440..2ed86381f 100644 --- a/HACKING +++ b/HACKING @@ -276,7 +276,7 @@ The following are at first also followed just by an offset for use in error messages. After the lengths of the branches of a lookbehind group have been checked the error offset is no longer needed. The lower 16 bits of the main word are now set to the maximum length of the first branch of the lookbehind -group, and the second word is set to the mimimum matching length for a +group, and the second word is set to the minimum matching length for a variable-length lookbehind group, or to LOOKBEHIND_MAX for a group whose branches are all of fixed length. These values are used when generating OP_REVERSE or OP_VREVERSE for the first branch. The miminum value is also used diff --git a/config-cmake.h.in b/config-cmake.h.in index 6539d7735..f0091b225 100644 --- a/config-cmake.h.in +++ b/config-cmake.h.in @@ -1,6 +1,9 @@ /* config.h for CMake builds */ +#cmakedefine HAVE_ASSERT_H 1 +#cmakedefine HAVE_BUILTIN_EXPECT 1 #cmakedefine HAVE_BUILTIN_MUL_OVERFLOW 1 +#cmakedefine HAVE_BUILTIN_UNREACHABLE 1 #cmakedefine HAVE_ATTRIBUTE_UNINITIALIZED 1 #cmakedefine HAVE_DIRENT_H 1 #cmakedefine HAVE_SYS_STAT_H 1 diff --git a/configure.ac b/configure.ac index 5646c5a2b..74aa7de44 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,20 @@ AC_SYS_LARGEFILE PCRE2_VISIBILITY +# Check for the expect() builtin + +AC_MSG_CHECKING([for __builtin_expect()]) +AC_LANG_PUSH([C]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[__builtin_expect(1+1, 2)]])], + [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()]) @@ -95,6 +109,20 @@ if test "$pcre2_cc_cv_builtin_mul_overflow" = yes; then fi AC_LANG_POP([C]) +# Check for the unreachable() builtin + +AC_MSG_CHECKING([for __builtin_unreachable()]) +AC_LANG_PUSH([C]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[if (0) __builtin_unreachable()]])], + [pcre2_cc_cv_builtin_unreachable=yes], + [pcre2_cc_cv_builtin_unreachable=no]) +AC_MSG_RESULT([$pcre2_cc_cv_builtin_unreachable]) +if test "$pcre2_cc_cv_builtin_unreachable" = yes; then + AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], 1, + [Define this if your compiler provides __builtin_unreachable()]) +fi +AC_LANG_POP([C]) + # Check for Clang __attribute__((uninitialized)) feature AC_MSG_CHECKING([for __attribute__((uninitialized))]) @@ -521,7 +549,7 @@ HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make sure both macros are undefined; an emulation function will then be used. */]) # Checks for header files. -AC_CHECK_HEADERS(limits.h sys/types.h sys/stat.h dirent.h) +AC_CHECK_HEADERS(assert.h limits.h sys/types.h sys/stat.h dirent.h) AC_CHECK_HEADERS([windows.h], [HAVE_WINDOWS_H=1]) AC_CHECK_HEADERS([sys/wait.h], [HAVE_SYS_WAIT_H=1]) diff --git a/src/config.h.generic b/src/config.h.generic index 009294813..089e1f5ff 100644 --- a/src/config.h.generic +++ b/src/config.h.generic @@ -52,15 +52,24 @@ sure both macros are undefined; an emulation function will then be used. */ LF does in an ASCII/Unicode environment. */ /* #undef EBCDIC_NL25 */ +/* Define to 1 if you have the header file. */ +/* #undef HAVE_ASSERT_H */ + /* Define this if your compiler supports __attribute__((uninitialized)) */ /* #undef HAVE_ATTRIBUTE_UNINITIALIZED */ /* Define to 1 if you have the 'bcopy' function. */ /* #undef HAVE_BCOPY */ +/* 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 */ +/* Define this if your compiler provides __builtin_unreachable() */ +/* #undef HAVE_BUILTIN_UNREACHABLE */ + /* Define to 1 if you have the header file. */ /* #undef HAVE_BZLIB_H */ diff --git a/src/config.h.in b/src/config.h.in index 3bb01c83d..7642d65c7 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -52,15 +52,24 @@ sure both macros are undefined; an emulation function will then be used. */ LF does in an ASCII/Unicode environment. */ #undef EBCDIC_NL25 +/* Define to 1 if you have the header file. */ +#undef HAVE_ASSERT_H + /* Define this if your compiler supports __attribute__((uninitialized)) */ #undef HAVE_ATTRIBUTE_UNINITIALIZED /* Define to 1 if you have the 'bcopy' function. */ #undef HAVE_BCOPY +/* 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 +/* Define this if your compiler provides __builtin_unreachable() */ +#undef HAVE_BUILTIN_UNREACHABLE + /* Define to 1 if you have the header file. */ #undef HAVE_BZLIB_H diff --git a/src/pcre2.h.generic b/src/pcre2.h.generic index 4ef0793a8..baa709512 100644 --- a/src/pcre2.h.generic +++ b/src/pcre2.h.generic @@ -1002,6 +1002,29 @@ PCRE2_SUFFIX a no-op. Otherwise, generate an error. */ #endif #endif /* PCRE2_CODE_UNIT_WIDTH is defined */ +/* Assertion macros */ + +#ifdef HAVE_BUILTIN_UNREACHABLE +#define PCRE2_UNREACHABLE() __builtin_unreachable() +#else +#define PCRE2_UNREACHABLE() do {} while(0) +#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) +#include +#define PCRE2_ASSERT(x) assert(x) +#elif defined(HAVE_STDLIB_H) && defined(HAVE_STDIO_H) +#define PCRE2_ASSERT(x) do { if (!(x)) { fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); abort(); }} while(0) +#else +#define PCRE2_ASSERT(x) do {} while(0) +#endif +#else +#define PCRE2_ASSERT(x) do {} while(0) +#endif + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/pcre2.h.in b/src/pcre2.h.in index a13362daf..2f6b4e866 100644 --- a/src/pcre2.h.in +++ b/src/pcre2.h.in @@ -1003,6 +1003,29 @@ PCRE2_SUFFIX a no-op. Otherwise, generate an error. */ #endif #endif /* PCRE2_CODE_UNIT_WIDTH is defined */ +/* Assertion macros */ + +#ifdef HAVE_BUILTIN_UNREACHABLE +#define PCRE2_UNREACHABLE() __builtin_unreachable() +#else +#define PCRE2_UNREACHABLE() do {} while(0) +#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) +#include +#define PCRE2_ASSERT(x) assert(x) +#elif defined(HAVE_STDLIB_H) && defined(HAVE_STDIO_H) +#define PCRE2_ASSERT(x) do { if (!(x)) { fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); abort(); }} while(0) +#else +#define PCRE2_ASSERT(x) do {} while(0) +#endif +#else +#define PCRE2_ASSERT(x) do {} while(0) +#endif + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/pcre2_auto_possess.c b/src/pcre2_auto_possess.c index e801a924a..66788cb70 100644 --- a/src/pcre2_auto_possess.c +++ b/src/pcre2_auto_possess.c @@ -245,7 +245,8 @@ switch(ptype) default: return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == negated; } - break; /* Control never reaches here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ + break; case PT_WORD: return (PRIV(ucp_gentype)[prop->chartype] == ucp_L || @@ -259,7 +260,8 @@ switch(ptype) if (c < *p) return !negated; if (c == *p++) return negated; } - break; /* Control never reaches here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ + break; /* Haven't yet thought these through. */ @@ -1119,8 +1121,7 @@ for(;;) if (list[1] == 0) return TRUE; } -/* Control never reaches here. There used to be a fail-save return FALSE; here, -but some compilers complain about an unreachable statement. */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index a49d38cf9..e1492887c 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -5233,7 +5233,8 @@ for (;;) return code; } } -/* Control never reaches here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } @@ -8482,7 +8483,7 @@ for (;; pptr++) } /* End of big switch */ } /* End of big loop */ -/* Control never reaches here. */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } @@ -8610,7 +8611,7 @@ for (;;) int branch_return; /* Insert OP_REVERSE or OP_VREVERSE if this is a lookbehind assertion. There - is only a single mimimum length for the whole assertion. When the mimimum + is only a single minimum length for the whole assertion. When the minimum length is LOOKBEHIND_MAX it means that all branches are of fixed length, though not necessarily the same length. In this case, the original OP_REVERSE can be used. It can also be used if a branch in a variable length lookbehind @@ -8787,7 +8788,8 @@ for (;;) lookbehindlength = META_DATA(*pptr); pptr++; } -/* Control never reaches here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } @@ -9472,8 +9474,8 @@ for (;; pptr++) if (meta >= sizeof(meta_extra_lengths)) return NULL; pptr += meta_extra_lengths[meta]; } -/* Control never reaches here */ -return pptr; + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c index ea4e6f844..051ca2d3d 100644 --- a/src/pcre2_convert.c +++ b/src/pcre2_convert.c @@ -1158,9 +1158,7 @@ for (i = 0; i < 2; i++) use_length = *bufflenptr + 1; } -/* Control should never get here. */ - -return PCRE2_ERROR_INTERNAL; + PCRE2_UNREACHABLE(); /* Control never reaches here */ } diff --git a/src/pcre2_match.c b/src/pcre2_match.c index cdb401184..a7e584998 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -1329,7 +1329,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, RRETURN(MATCH_NOMATCH); } } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } else /* Maximize */ @@ -1430,7 +1430,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH); Feptr++; } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } else /* Maximize */ @@ -1488,7 +1488,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } if (Lc != UCHAR21INCTEST(Feptr)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } else /* Maximize */ { @@ -1706,7 +1706,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, Feptr++; } } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* Maximize case */ @@ -1844,7 +1844,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if (Lc == *Feptr++) RRETURN(MATCH_NOMATCH); } } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* Maximize case */ @@ -2071,7 +2071,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH); } } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* If maximizing, find the longest possible run, then work backwards. */ @@ -2151,7 +2151,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, RRETURN(MATCH_NOMATCH); } } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ #undef Lbyte_map_address #undef Lbyte_map @@ -2244,7 +2245,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, GETCHARINCTEST(fc, Feptr); if (!PRIV(xclass)(fc, Lxclass_data, utf)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* If maximizing, find the longest possible run, then work backwards. */ @@ -2287,7 +2288,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } #endif /* SUPPORT_WIDE_CHARS: end of XCLASS */ @@ -3530,7 +3531,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, GETCHARINCTEST(fc, Feptr); if (Lctype == OP_NOTPROP) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_LAMP: for (;;) @@ -3551,7 +3553,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, chartype == ucp_Lt) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_GC: for (;;) @@ -3568,7 +3571,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((UCD_CATEGORY(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_PC: for (;;) @@ -3585,7 +3589,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((UCD_CHARTYPE(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_SC: for (;;) @@ -3602,7 +3607,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((UCD_SCRIPT(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_SCX: for (;;) @@ -3624,7 +3630,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if (ok == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_ALNUM: for (;;) @@ -3643,7 +3650,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((category == ucp_L || category == ucp_N) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ /* Perl space used to exclude VT, but from Perl 5.18 it is included, which means that Perl space and POSIX space are now identical. PCRE @@ -3675,7 +3683,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, break; } } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_WORD: for (;;) @@ -3698,7 +3707,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, chartype == ucp_Pc) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_CLIST: for (;;) @@ -3735,7 +3745,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } } } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_UCNC: for (;;) @@ -3754,7 +3765,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, fc >= 0xe000) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_BIDICL: for (;;) @@ -3771,7 +3783,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((UCD_BIDICLASS(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PT_BOOL: for (;;) @@ -3793,7 +3806,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if (ok == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ /* This should never occur */ default: @@ -4099,7 +4113,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } } } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* If maximizing, it is worth using inline code for speed, doing the type @@ -5111,7 +5126,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } Feptr += slength; } - /* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* If maximizing, find the longest string and work backwards, as long as @@ -5185,7 +5200,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, RRETURN(MATCH_NOMATCH); } - /* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ #undef Lcaseless #undef Lmin @@ -5409,7 +5425,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, Fecode += GET(Fecode, 1); if (*Fecode != OP_ALT) RRETURN(MATCH_NOMATCH); } - /* Control never reaches here. */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ #undef Lframe_type @@ -5494,7 +5511,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, Lstart_branch = next_ecode; if (*Lstart_branch != OP_ALT) RRETURN(MATCH_NOMATCH); } - /* Control never reaches here. */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ #undef Lframe_type #undef Lstart_branch @@ -5947,7 +5965,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } /* Now try matching, moving forward one character on failure, until we - reach the mimimum back length. */ + reach the minimum back length. */ for (;;) { @@ -5959,7 +5977,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if (utf) { FORWARDCHARTEST(Feptr, mb->end_subject); } #endif } - /* Control never reaches here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ #undef Lmin #undef Lmax @@ -6544,7 +6563,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, loop. */ } /* End of main loop */ -/* Control never reaches here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ /* ========================================================================= */ diff --git a/src/pcre2_study.c b/src/pcre2_study.c index 58c534f04..c998bfa63 100644 --- a/src/pcre2_study.c +++ b/src/pcre2_study.c @@ -758,7 +758,8 @@ for (;;) return -3; } } -/* Control never gets here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } diff --git a/src/pcre2grep.c b/src/pcre2grep.c index 5d86475a0..858a6ed0e 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -900,7 +900,8 @@ for (;;) if (strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0) return dent->d_name; } -/* Control never reaches here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } static void @@ -1695,7 +1696,7 @@ switch(endlinetype) while (p > startptr && p[-1] != '\n') p--; if (p <= startptr + 1 || p[-2] == '\r') return p; } - /* Control can never get here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ case PCRE2_NEWLINE_ANY: case PCRE2_NEWLINE_ANYCRLF: diff --git a/src/pcre2test.c b/src/pcre2test.c index df8becc06..eaacf09e1 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -3589,7 +3589,7 @@ for (;;) } } -/* Control never gets here */ + PCRE2_UNREACHABLE(); /* Control never reaches here */ } @@ -9451,7 +9451,8 @@ least 128 code units, because it is used for retrieving error messages. */ if (*endptr == 0) goto EXIT; arg_error = endptr + 1; } - /* Control never reaches here */ + + PCRE2_UNREACHABLE(); /* Control never reaches here */ } /* End of -error handling */ /* Initialize things that cannot be done until we know which test mode we are diff --git a/vms/configure.com b/vms/configure.com index b50365d4f..c6024e87c 100644 --- a/vms/configure.com +++ b/vms/configure.com @@ -496,12 +496,20 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define this if your compiler supports __attribute__((uninitialized)) */ #undef HAVE_ATTRIBUTE_UNINITIALIZED +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + /* 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 +/* Define this if your compiler provides __builtin_unreachable() */ +#undef HAVE_BUILTIN_UNREACHABLE /* Define to 1 if you have the header file. */ #define HAVE_DIRENT_H 1