]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Address some issues with XL C on Linux/POWER9.
authorDenis Ovsienko <[email protected]>
Tue, 27 Jul 2021 13:06:28 +0000 (14:06 +0100)
committerDenis Ovsienko <[email protected]>
Tue, 27 Jul 2021 13:24:01 +0000 (14:24 +0100)
XL C 16.1.1 Community Edition for Linux generated three warnings for
every file:

In file included from ./tcpdump.c:155:
./netdissect.h:254:8: warning: 1540-2990 The attribute
"__attribute__((format(printf, 2, 3)))" is not supported. The
      attribute is ignored.
                     PRINTFLIKE_FUNCPTR(2, 3);
                     ^
./netdissect.h:259:10: warning: 1540-2990 The attribute
" __attribute__((format(printf, 3, 4)))" is not supported.
      The attribute is ignored.
                                     PRINTFLIKE_FUNCPTR(3, 4);
                                     ^
./netdissect.h:263:9: warning: 1540-2990 The attribute
" __attribute__((format(printf, 2, 3)))" is not supported. The
      attribute is ignored.
                      PRINTFLIKE_FUNCPTR(2, 3);
                      ^

As it turns out, this is a bug in the compiler. In compiler-tests.h
update ND_IS_AT_LEAST_XL_C_VERSION() to tell newer XL C versions. In
funcattrs.h exempt XL C 16.1 from PRINTFLIKE_FUNCPTR().

In the course of preparing these changes notice that XL C uses the Clang
block in diag-control.h (XL C mimics both Clang and GCC to some extent),
although the behaviour is different between the two compilers. Add a new
block for XL C there.

In build_common.sh add more comments to explain XL C quirks and detect
XL C for Linux too so it receives the right CFLAGS. Update CHANGES to
mention this and earlier improvements.

CHANGES
build_common.sh
compiler-tests.h
diag-control.h
funcattrs.h

diff --git a/CHANGES b/CHANGES
index 3a005bc1f83283e5ab42630171b9866fb83938b7..435b9e7b93df3eb60083dfeb6ee16d2e8194b640 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,7 @@ Monthday, Month DD, YYYY by gharris and denis
       Handle some Autoconf/make errors better.
       Fix "make releasetar" on AIX and Solaris.
       Mend "make check" on Solaris 9 with Autoconf.
+      Address assorted compiler warnings.
 
 Wednesday, June 9, 2021 by gharris
   Summary for 4.99.1 tcpdump release
index 794ec2c6850a095c09ae4bdb1645931b447708f9..8ace59e4dddabf766cc5c0cd297080671f234a44 100644 (file)
@@ -74,9 +74,12 @@ print_cc_version() {
         "$CC" --version
         ;;
     xl*)
-        # XL C for AIX recognizes -qversion, prints to stdout and exits with 0,
-        # but on an unknown command-line flag displays its man page and waits.
-        "$CC" -qversion
+        # XL C 12.1 and 13.1 recognize "-qversion", print to stdout and exit
+        # with 0. XL C 12.1 on an unknown command-line flag displays its man
+        # page and waits.
+        # XL C 16.1 recognizes "-qversion" and "--version", prints to stdout
+        # and exits with 0. Community Edition also prints a banner to stderr.
+        "$CC" -qversion 2>/dev/null
         ;;
     sun*)
         # Sun compilers recognize -V, print to stderr and exit with an error.
@@ -116,7 +119,7 @@ cc_id() {
         return
     fi
 
-    cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^IBM XL C.* for AIX, V\([0-9\.]*\).*$/xlc-\1/'`
+    cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^IBM XL C.*, V\([0-9\.]*\).*$/xlc-\1/'`
     if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
         echo "$cc_id_guessed"
         return
@@ -144,6 +147,8 @@ cc_werr_cflags() {
         echo '-Werror'
         ;;
     xlc-*)
+        # XL C 12.1 and 13.1 recognize "-qhalt=w". XL C 16.1 recognizes that
+        # and "-Werror".
         echo '-qhalt=w'
         ;;
     suncc-*)
index 8b1a2331ed7a88ac0dfc272ce20c63ff3baff690..d9cf81f0751104072f92ba7298b03d6d1814095b 100644 (file)
  *
  * The version number in __xlC__ has the major version in the
  * upper 8 bits and the minor version in the lower 8 bits.
+ * On AIX __xlC__ is always defined, __ibmxl__ becomes defined in XL C 16.1.
+ * On Linux since XL C 13.1.6 __xlC__ is not defined by default anymore, but
+ * __ibmxl__ is defined since at least XL C 13.1.1.
  */
 
 #if ! defined(__xlC__)
+#if ! defined(__ibmxl__)
 #define ND_IS_AT_LEAST_XL_C_VERSION(major,minor) 0
 #else
+#define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \
+       (__ibmxl_version__ > (major) || \
+        (__ibmxl_version__ == (major) && __ibmxl_release__ >= (minor)))
+#endif /* ! __ibmxl__ */
+#else /* ! __xlC__ */
 #define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \
        (__xlC__ >= (((major) << 8) | (minor)))
 #endif
index 8c9ca7214e04ab9b045362ebfb86220c71f9d365..efebec455a8081d095cd8901d73b6ab9d8872933 100644 (file)
   #define DIAG_DO_PRAGMA(x) _Pragma (#x)
 #endif
 
+/*
+ * XL C 12.1 and 13.1 for AIX require no attention in this department.
+ * XL C 16.1 defines both __GNUC__ and __clang__, so has to be tested first.
+ */
+#if ND_IS_AT_LEAST_XL_C_VERSION(16,1)
+  /*
+   * See respective Clang note below.
+   */
+  #define DIAG_OFF_ASSIGN_ENUM \
+    DIAG_DO_PRAGMA(clang diagnostic push) \
+    DIAG_DO_PRAGMA(clang diagnostic ignored "-Wassign-enum")
+  #define DIAG_ON_ASSIGN_ENUM \
+    DIAG_DO_PRAGMA(clang diagnostic pop)
+
+  #define DIAG_OFF_CAST_QUAL
+  #define DIAG_ON_CAST_QUAL
+  #define DIAG_OFF_DEPRECATION
+  #define DIAG_ON_DEPRECATION
 /*
  * The current clang compilers also define __GNUC__ and __GNUC_MINOR__
  * thus we need to test the clang case before the GCC one
  */
-#if ND_IS_AT_LEAST_CLANG_VERSION(2,8)
+#elif ND_IS_AT_LEAST_CLANG_VERSION(2,8)
   /*
    * Clang complains if you OR together multiple enum values of a
    * given enum type and them pass it as an argument of that enum
index f37e07e213bb4f1dbc1d08fdb8ac6cb266ae127a..00efad73b099fa5f3dc2291577330f407012d9c8 100644 (file)
   /*
    * However, GCC didn't support that for function *pointers* until GCC
    * 4.1.0; see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3481.
+   * XL C 16.1 (and possibly some earlier versions, but not 12.1 or 13.1) has
+   * a similar bug, a bugfix for which should be available later:
+   * https://www.ibm.com/support/pages/apar/LI81402
    */
-  #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 401))
+  #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 401)) || \
+      (ND_IS_AT_LEAST_XL_C_VERSION(16,1) && !ND_IS_AT_LEAST_XL_C_VERSION(16,2))
     #define PRINTFLIKE_FUNCPTR(x,y)
   #else
     #define PRINTFLIKE_FUNCPTR(x,y) __attribute__((__format__(__printf__,x,y)))