From: Dmitry V. Levin Date: Sun, 16 Sep 2018 11:44:01 +0000 (+0000) Subject: Ignore warnings about overridden initialization of hwaddr_sizes X-Git-Tag: v4.25~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af39dee46cee733053ec7cae3ffa049be0ce3877;p=strace Ignore warnings about overridden initialization of hwaddr_sizes As hwaddr_sizes array is explicitly initialized this way, ignore potential warnings reported by gcc -Woverride-init and clang -Winitializer-overrides. * gcc_compat.h (CLANG_PREREQ): New macro. (DIAG_PUSH_IGNORE_OVERRIDE_INIT, DIAG_POP_IGNORE_OVERRIDE_INIT): New macros non-trivially defined for gcc >= 4.2 and clang >= 2.8. * sock.c (print_ifreq): Use them to ignore warnings about overridden initialization of hwaddr_sizes array. Closes: https://github.com/strace/strace/issues/77 --- diff --git a/gcc_compat.h b/gcc_compat.h index 251080bb..066b40e8 100644 --- a/gcc_compat.h +++ b/gcc_compat.h @@ -33,10 +33,20 @@ # define GNUC_PREREQ(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) #else -# define __attribute__(x) /* empty */ # define GNUC_PREREQ(maj, min) 0 #endif +#if defined __clang__ && defined __clang_major__ && defined __clang_minor__ +# define CLANG_PREREQ(maj, min) \ + ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min)) +#else +# define CLANG_PREREQ(maj, min) 0 +#endif + +#if !(GNUC_PREREQ(2, 0) || CLANG_PREREQ(1, 0)) +# define __attribute__(x) /* empty */ +#endif + #if GNUC_PREREQ(2, 5) # define ATTRIBUTE_NORETURN __attribute__((__noreturn__)) #else @@ -99,6 +109,23 @@ # define ATTRIBUTE_FALLTHROUGH ((void) 0) #endif +#if CLANG_PREREQ(2, 8) +# define DIAG_PUSH_IGNORE_OVERRIDE_INIT \ + _Pragma("clang diagnostic push"); \ + _Pragma("clang diagnostic ignored \"-Winitializer-overrides\""); +# define DIAG_POP_IGNORE_OVERRIDE_INIT \ + _Pragma("clang diagnostic pop"); +#elif GNUC_PREREQ(4, 2) +# define DIAG_PUSH_IGNORE_OVERRIDE_INIT \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Woverride-init\""); +# define DIAG_POP_IGNORE_OVERRIDE_INIT \ + _Pragma("GCC diagnostic pop"); +#else +# define DIAG_PUSH_IGNORE_OVERRIDE_INIT /* empty */ +# define DIAG_POP_IGNORE_OVERRIDE_INIT /* empty */ +#endif + #if GNUC_PREREQ(6, 0) # define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE \ _Pragma("GCC diagnostic push"); \ diff --git a/sock.c b/sock.c index a477bcea..f17045e0 100644 --- a/sock.c +++ b/sock.c @@ -57,6 +57,8 @@ print_ifname(const char *ifname) print_quoted_string(ifname, IFNAMSIZ + 1, QUOTE_0_TERMINATED); } +DIAG_PUSH_IGNORE_OVERRIDE_INIT + static void print_ifreq(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t arg, const struct_ifreq *const ifr) @@ -202,6 +204,8 @@ print_ifreq(struct tcb *const tcp, const unsigned int code, } } +DIAG_POP_IGNORE_OVERRIDE_INIT + static unsigned int print_ifc_len(int len) {