]> The Tcpdump Group git mirrors - libpcap/commitdiff
Address CLang "undefined defined" warnings. 653/head
authorDenis Ovsienko <[email protected]>
Sun, 15 Oct 2017 00:43:26 +0000 (00:43 +0000)
committerDenis Ovsienko <[email protected]>
Sun, 15 Oct 2017 00:43:26 +0000 (00:43 +0000)
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
pcap/compiler-tests.h
pcap/funcattrs.h

index 4ea910e3f66a44b65b66e63bda7c23f437f19d25..30ecec385522fdd92a1a87693835f3916b85afa8 100644 (file)
@@ -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().
    */
index 205cd7a610bd4a6ef137138ad917102c6cc79e0b..03ef7b4a897eff9b3b7d55d1b98de24a0f20498a 100644 (file)
  * compiler that claims to be "just like GCC" of that version or a
  * later release.
  */
-#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \
-       (defined(__GNUC__) && \
-           (__GNUC__ > (major) || \
-            (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
+
+#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 3))
+#define PCAP_IS_AT_LEAST_GNUC_VERSION_2_3 1
+#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
+#endif
 
 /*
  * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor
        (((minor) >= 10) ? \
            (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
            (((major) << 8) | ((minor) << 4)))
-#define PCAP_IS_AT_LEAST_SUNC_VERSION(major, minor) \
-       (defined(__SUNPRO_C) && \
-           (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))))
+
+#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
+#endif
 
 /*
  * Check wehether this is IBM XL C major.minor or a later release.
  * The version number in __xlC__ has the major version in the
  * upper 8 bits and the minor version in the lower 8 bits.
  */
-#define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \
-       (defined(__xlC__) && __xlC__ >= (((major) << 8) | (minor)))
+
+#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
+#else
+#define PCAP_IS_AT_LEAST_XL_C_VERSION_12_0 0
+#endif
 
 /*
  * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor
  * (Strip off the A., remove the . between the major and minor version
  * number, and add two digits of patch.)
  */
-#define PCAP_IS_AT_LEAST_HP_C_VERSION(major, minor) \
-       (defined(__HP_aCC) && \
-           (__HP_aCC >= ((major)*10000 + (minor)*100)))
+
+#if defined(__HP_aCC) && (__HP_aCC >= (6*10000 + 10*100))
+#define PCAP_IS_AT_LEAST_HP_C_VERSION_6_10 1
+#else
+#define PCAP_IS_AT_LEAST_HP_C_VERSION_6_10 0
+#endif
 
 #endif /* lib_pcap_funcattrs_h */
index a89f788dfbb0dde915380bfd0dd5ac98060f4ee9..cd10501609a16153fc7505be9093d0e5633abb1f 100644 (file)
      * 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()),
  * 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
  * 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?),
  * (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.
    * 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.
    *