From f1f1c08af656c118cbcf99a40d868b757044ead5 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Sun, 15 Oct 2017 00:43:26 +0000 Subject: Address CLang "undefined defined" warnings. Building tcpdump with CLang recently started to produce 9 warnings per each .c file along the following lines: In file included from ./print-pflog.c:39: In file included from ./netdissect.h:75: In file included from ../libpcap/pcap.h:43: In file included from ../libpcap/pcap/pcap.h:72: ../libpcap/pcap/funcattrs.h:115:8: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined] || PCAP_IS_AT_LEAST_SUNC_VERSION(5, 9) \ ^ ../libpcap/pcap/compiler-tests.h:89:3: note: expanded from macro 'PCAP_IS_AT_LEAST_SUNC_VERSION' (defined(__SUNPRO_C) && \ ^ Replace each involved 2-ary macro with one or more 0-ary macro(s) and use those. This will require to add a new 0-ary macro for each new required combination of major/minor version numbers of a particular compiler, but this change makes tcpdump compile almost cleanly again. --- optimize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'optimize.c') diff --git a/optimize.c b/optimize.c index 4ea910e3..30ecec38 100644 --- a/optimize.c +++ b/optimize.c @@ -60,7 +60,7 @@ int pcap_optimizer_debug; * * This is the same as the count of trailing zeroes in the word. */ -#if PCAP_IS_AT_LEAST_GNUC_VERSION(3, 4) +#if PCAP_IS_AT_LEAST_GNUC_VERSION_3_4 /* * GCC 3.4 and later; we have __builtin_ctz(). */ -- cgit v1.2.3 From 26576666d6318258363ba27d5abdbbb88b1e56ac Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Sun, 15 Oct 2017 11:42:22 +0000 Subject: Improve the "undefined defined" problem solution. Rearrange the preprocessor directives to keep the improvement made in commit f1f1c08 on one hand and to re-enable the 2-ary macros, which allow to avoid code duplication, on the other. This change has very little effect on the tcpdump build time. --- optimize.c | 2 +- pcap/compiler-tests.h | 75 +++++++++++++-------------------------------------- pcap/funcattrs.h | 26 +++++++++--------- 3 files changed, 33 insertions(+), 70 deletions(-) (limited to 'optimize.c') diff --git a/optimize.c b/optimize.c index 30ecec38..8aeec3cf 100644 --- a/optimize.c +++ b/optimize.c @@ -60,7 +60,7 @@ int pcap_optimizer_debug; * * This is the same as the count of trailing zeroes in the word. */ -#if PCAP_IS_AT_LEAST_GNUC_VERSION_3_4 +#if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) /* * GCC 3.4 and later; we have __builtin_ctz(). */ diff --git a/pcap/compiler-tests.h b/pcap/compiler-tests.h index a7ae2521..552941ca 100644 --- a/pcap/compiler-tests.h +++ b/pcap/compiler-tests.h @@ -60,34 +60,12 @@ * later release. */ -#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 3)) -#define PCAP_IS_AT_LEAST_GNUC_VERSION_2_3 1 +#if ! defined(__GNUC__) +#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 #else -#define PCAP_IS_AT_LEAST_GNUC_VERSION_2_3 0 -#endif - -#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define PCAP_IS_AT_LEAST_GNUC_VERSION_2_5 1 -#else -#define PCAP_IS_AT_LEAST_GNUC_VERSION_2_5 0 -#endif - -#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) -#define PCAP_IS_AT_LEAST_GNUC_VERSION_3_1 1 -#else -#define PCAP_IS_AT_LEAST_GNUC_VERSION_3_1 0 -#endif - -#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -#define PCAP_IS_AT_LEAST_GNUC_VERSION_3_4 1 -#else -#define PCAP_IS_AT_LEAST_GNUC_VERSION_3_4 0 -#endif - -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) -#define PCAP_IS_AT_LEAST_GNUC_VERSION_4_5 1 -#else -#define PCAP_IS_AT_LEAST_GNUC_VERSION_4_5 0 +#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \ + (__GNUC__ > (major) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) #endif /* @@ -107,27 +85,16 @@ * for a partial mapping, which we assume continues for later * 12.x product releases. */ + +#if ! defined(__SUNPRO_C) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 +#else #define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \ (((minor) >= 10) ? \ (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ (((major) << 8) | ((minor) << 4))) - -#if defined(__SUNPRO_C) && __SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD(5, 5) -#define PCAP_IS_AT_LEAST_SUNC_VERSION_5_5 1 -#else -#define PCAP_IS_AT_LEAST_SUNC_VERSION_5_5 0 -#endif - -#if defined(__SUNPRO_C) && __SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD(5, 9) -#define PCAP_IS_AT_LEAST_SUNC_VERSION_5_9 1 -#else -#define PCAP_IS_AT_LEAST_SUNC_VERSION_5_9 0 -#endif - -#if defined(__SUNPRO_C) && __SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD(5, 13) -#define PCAP_IS_AT_LEAST_SUNC_VERSION_5_13 1 -#else -#define PCAP_IS_AT_LEAST_SUNC_VERSION_5_13 0 +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \ + (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))) #endif /* @@ -137,16 +104,11 @@ * upper 8 bits and the minor version in the lower 8 bits. */ -#if defined(__xlC__) && __xlC__ >= ((10 << 8) | 1) -#define PCAP_IS_AT_LEAST_XL_C_VERSION_10_1 1 -#else -#define PCAP_IS_AT_LEAST_XL_C_VERSION_10_1 0 -#endif - -#if defined(__xlC__) && __xlC__ >= ((12 << 8) | 0) -#define PCAP_IS_AT_LEAST_XL_C_VERSION_12_0 1 +#if ! defined(__xlC__) +#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 #else -#define PCAP_IS_AT_LEAST_XL_C_VERSION_12_0 0 +#define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ + (__xlC__ >= (((major) << 8) | (minor))) #endif /* @@ -160,10 +122,11 @@ * number, and add two digits of patch.) */ -#if defined(__HP_aCC) && (__HP_aCC >= (6*10000 + 10*100)) -#define PCAP_IS_AT_LEAST_HP_C_VERSION_6_10 1 +#if ! defined(__HP_aCC) +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 #else -#define PCAP_IS_AT_LEAST_HP_C_VERSION_6_10 0 +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \ + (__HP_aCC >= ((major)*10000 + (minor)*100)) #endif #endif /* lib_pcap_funcattrs_h */ diff --git a/pcap/funcattrs.h b/pcap/funcattrs.h index cd105016..cf923064 100644 --- a/pcap/funcattrs.h +++ b/pcap/funcattrs.h @@ -73,15 +73,15 @@ * shared library by default, so we might have to explicitly mark * functions as exported. */ - #if PCAP_IS_AT_LEAST_GNUC_VERSION_3_4 \ - || PCAP_IS_AT_LEAST_XL_C_VERSION_12_0 + #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0) /* * GCC 3.4 or later, or some compiler asserting compatibility with * GCC 3.4 or later, or XL C 13.0 or later, so we have * __attribute__((visibility()). */ #define PCAP_API_DEF __attribute__((visibility("default"))) - #elif PCAP_IS_AT_LEAST_SUNC_VERSION_5_5 + #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5) /* * Sun C 5.5 or later, so we have __global. * (Sun C 5.9 and later also have __attribute__((visibility()), @@ -111,10 +111,10 @@ * declaration, as the MSVC version has to go before the declaration.) */ #if __has_attribute(noreturn) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION_2_5 \ - || PCAP_IS_AT_LEAST_SUNC_VERSION_5_9 \ - || PCAP_IS_AT_LEAST_XL_C_VERSION_10_1 \ - || PCAP_IS_AT_LEAST_HP_C_VERSION_6_10 + || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \ + || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ + || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) /* * Compiler with support for __attribute((noreturn)), or GCC 2.5 and * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1 @@ -138,9 +138,9 @@ * string". */ #if __has_attribute(__format__) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION_2_3 \ - || PCAP_IS_AT_LEAST_XL_C_VERSION_10_1 \ - || PCAP_IS_AT_LEAST_HP_C_VERSION_6_10 + || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ + || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) /* * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1 * and later (do any earlier versions of XL C support this?), @@ -161,8 +161,8 @@ * (Thank you, Microsoft, for requiring the function name.) */ #if __has_attribute(deprecated) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION_4_5 \ - || PCAP_IS_AT_LEAST_SUNC_VERSION_5_13 + || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \ + || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13) /* * Compiler that supports __has_attribute and __attribute__((deprecated)), * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later. @@ -172,7 +172,7 @@ * recent enough to support __attribute__((deprecated(msg)))). */ #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg))) -#elif PCAP_IS_AT_LEAST_GNUC_VERSION_3_1 +#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1) /* * GCC 3.1 through 4.4. * -- cgit v1.2.3