diff options
-rw-r--r-- | src/grep.c | 3 | ||||
-rw-r--r-- | src/kwset.c | 15 | ||||
-rw-r--r-- | src/system.h | 14 |
3 files changed, 24 insertions, 8 deletions
@@ -1700,7 +1700,8 @@ static bool grepfile (int dirdesc, char const *name, bool follow, bool command_line) { int oflag = (O_RDONLY | O_NOCTTY - | (binary ? O_BINARY : 0) + | (IGNORE_DUPLICATE_BRANCH_WARNING + (binary ? O_BINARY : 0)) | (follow ? 0 : O_NOFOLLOW) | (skip_devices (command_line) ? O_NONBLOCK : 0)); int desc = openat_safer (dirdesc, name, oflag); diff --git a/src/kwset.c b/src/kwset.c index 2599af5a..a2ce6b6b 100644 --- a/src/kwset.c +++ b/src/kwset.c @@ -756,10 +756,10 @@ bmexec (kwset_t kwset, char const *text, ptrdiff_t size, { /* Help the compiler inline in two ways, depending on whether kwset->trans is null. */ - ptrdiff_t ret = (kwset->trans - ? bmexec_trans (kwset, text, size) - : bmexec_trans (kwset, text, size)); - + ptrdiff_t ret = (IGNORE_DUPLICATE_BRANCH_WARNING + (kwset->trans + ? bmexec_trans (kwset, text, size) + : bmexec_trans (kwset, text, size))); if (0 <= ret) { kwsmatch->index = 0; @@ -905,9 +905,10 @@ acexec (kwset_t kwset, char const *text, ptrdiff_t size, assume (0 <= size); /* Help the compiler inline in two ways, depending on whether kwset->trans is null. */ - return (kwset->trans - ? acexec_trans (kwset, text, size, kwsmatch, longest) - : acexec_trans (kwset, text, size, kwsmatch, longest)); + return (IGNORE_DUPLICATE_BRANCH_WARNING + (kwset->trans + ? acexec_trans (kwset, text, size, kwsmatch, longest) + : acexec_trans (kwset, text, size, kwsmatch, longest))); } /* Find the first instance of a KWSET member in TEXT, which has SIZE bytes. diff --git a/src/system.h b/src/system.h index f9747935..bac78235 100644 --- a/src/system.h +++ b/src/system.h @@ -115,4 +115,18 @@ __asan_unpoison_memory_region (void const volatile *addr, size_t size) { } # endif #endif +/* When we deliberately use duplicate branches, use this macro to + disable gcc's -Wduplicated-branches in the containing expression. */ +#if 7 <= __GNUC__ +# define IGNORE_DUPLICATE_BRANCH_WARNING(exp) \ + ({ \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wduplicated-branches\"") \ + exp; \ + _Pragma ("GCC diagnostic pop") \ + }) +#else +# define IGNORE_DUPLICATE_BRANCH_WARNING(exp) exp +#endif + #endif |