diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-09-27 15:31:12 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-09-27 15:32:25 -0700 |
commit | 3e09538374d9f03c735e86c98bbf41191f73906a (patch) | |
tree | 262f3a6221066d95868bd1654ef69115407e27f8 | |
parent | 40e0d268606ff41814ba3e0f987239e2fad1b8e6 (diff) | |
download | grep-3e09538374d9f03c735e86c98bbf41191f73906a.tar.gz |
maint: generalize the -Wcast-align fix
* src/grep.c (CAST_ALIGNED): New macro.
(skip_easy_bytes): Use it.
-rw-r--r-- | src/grep.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -469,6 +469,21 @@ init_easy_encoding (void) easy_encoding &= mbclen_cache[i] == 1; } +/* A cast to TYPE of VAL. Use this when TYPE is a pointer type, VAL + is properly aligned for TYPE, and 'gcc -Wcast-align' cannot infer + the alignment and would otherwise complain about the cast. */ +#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) +# define CAST_ALIGNED(type, val) \ + ({ __typeof__ (val) val_ = val; \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wcast-align\"") \ + (type) val_; \ + _Pragma ("GCC diagnostic pop") \ + }) +#else +# define CAST_ALIGNED(type, val) ((type) (val)) +#endif + /* An unsigned type suitable for fast matching. */ typedef uintmax_t uword; @@ -496,15 +511,8 @@ skip_easy_bytes (char const *buf) for (p = buf; (uintptr_t) p % sizeof (uword) != 0; p++) if (*p & HIBYTE) return p; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - /* We have aligned P to a uword boundary, so we can safely - tell gcc to suppress its cast-alignment warning. */ - for (s = (uword const *) p; ! (*s & hibyte_mask); s++) + for (s = CAST_ALIGNED (uword const *, p); ! (*s & hibyte_mask); s++) continue; -#pragma GCC diagnostic pop - for (p = (char const *) s; ! (*p & HIBYTE); p++) continue; return p; |