Make -Wformat-nonliteral work with gcc
authorTom Tromey <tom@tromey.com>
Wed, 5 Sep 2018 19:46:47 +0000 (13:46 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 6 Sep 2018 03:47:33 +0000 (21:47 -0600)
After looking into why the build failed for Simon but not for me, we
found that the underlying cause was due to how gcc treats
-Wformat-nonliteral.  gcc requires -Wformat to be given first; but
warning.m4 was not doing this, so -Wformat-nonliteral was not being
used.

This patch changes warning.m4 to account gcc's requirement.

This then showed that the target-float.c build change in the earlier
Makefile patch was also incorrect.  Simon didn't see this in his
build, but gcc now points it out.  So, this patch fixes this problem
as well.

2018-09-05  Tom Tromey  <tom@tromey.com>

* warning.m4 (AM_GDB_WARNINGS): Add -Wformat when testing
-Wformat-nonliteral.
* target-float.c (host_float_ops<T>::to_string)
(host_float_ops<T>::from_string): Use
DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL.
* configure: Rebuild.

gdb/gdbserver/ChangeLog
2018-09-05  Tom Tromey  <tom@tromey.com>

* configure: Rebuild.

gdb/ChangeLog
gdb/configure
gdb/gdbserver/ChangeLog
gdb/gdbserver/configure
gdb/target-float.c
gdb/warning.m4

index d8ca6d3dabde403de8eaf09c8e54ae490a30a5b5..69e3182ec32ab8f177c02aa05ca4f804154b19e1 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-05  Tom Tromey  <tom@tromey.com>
+
+       * warning.m4 (AM_GDB_WARNINGS): Add -Wformat when testing
+       -Wformat-nonliteral.
+       * target-float.c (host_float_ops<T>::to_string)
+       (host_float_ops<T>::from_string): Use
+       DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL.
+       * configure: Rebuild.
+
 2018-09-05  Simon Marchi  <simon.marchi@ericsson.com>
 
        * printcmd.c (printf_c_string): Use
index 270657103b69f01432b2f79a16b9b538bb5a7ce2..d92a256f1ff510ca26c11fba98dacca89f36202a 100755 (executable)
@@ -15427,7 +15427,10 @@ case "${host}" in
     build_warnings="$build_warnings -Wno-unknown-pragmas"
     # Solaris 11 <unistd.h> marks vfork deprecated.
     build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
-  *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
+  *)
+    # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
+    # but there's a special case for this below.
+    build_warnings="$build_warnings -Wformat-nonliteral" ;;
 esac
 
 # Check whether --enable-build-warnings was given.
@@ -15483,6 +15486,12 @@ $as_echo_n "checking compiler warning flags... " >&6; }
        case $w in
        -Wno-*)
                wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
+        -Wformat-nonliteral)
+               # gcc requires -Wformat before -Wformat-nonliteral
+               # will work, so stick them together.
+               w="-Wformat $w"
+               wtest="$w"
+               ;;
        *)
                wtest=$w ;;
        esac
index cd0318c79aa8fbff359bbe058b3dd810d4aa65ec..0c5c32b22effbf90cef07ce81591804242f39a2d 100644 (file)
@@ -1,3 +1,7 @@
+2018-09-05  Tom Tromey  <tom@tromey.com>
+
+       * configure: Rebuild.
+
 2018-08-28  Simon Marchi  <simon.marchi@polymtl.ca>
 
        PR build/23399
index 7454cd8ad37a97a12e870af9525dcfe86edd92b2..f5cbbaea78a15f2e32d5f782fbc1c6c3127c3de5 100755 (executable)
@@ -7258,7 +7258,10 @@ case "${host}" in
     build_warnings="$build_warnings -Wno-unknown-pragmas"
     # Solaris 11 <unistd.h> marks vfork deprecated.
     build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
-  *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
+  *)
+    # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
+    # but there's a special case for this below.
+    build_warnings="$build_warnings -Wformat-nonliteral" ;;
 esac
 
 # Check whether --enable-build-warnings was given.
@@ -7314,6 +7317,12 @@ $as_echo_n "checking compiler warning flags... " >&6; }
        case $w in
        -Wno-*)
                wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
+        -Wformat-nonliteral)
+               # gcc requires -Wformat before -Wformat-nonliteral
+               # will work, so stick them together.
+               w="-Wformat $w"
+               wtest="$w"
+               ;;
        *)
                wtest=$w ;;
        esac
index c2878cb0a08f11ff74192873c257f71d8fa6dc0a..a12f216b53dcbd63619958450b09a8c2f24dc50d 100644 (file)
@@ -948,7 +948,11 @@ host_float_ops<T>::to_string (const gdb_byte *addr, const struct type *type,
 
   T host_float;
   from_target (type, addr, &host_float);
+
+  DIAGNOSTIC_PUSH
+  DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
   return string_printf (host_format.c_str (), host_float);
+  DIAGNOSTIC_POP
 }
 
 /* Parse string IN into a target floating-number of type TYPE and
@@ -977,7 +981,10 @@ host_float_ops<T>::from_string (gdb_byte *addr, const struct type *type,
     scan_format += scanf_length_modifier<T>::value;
   scan_format += "g%n";
 
+  DIAGNOSTIC_PUSH
+  DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
   num = sscanf (in.c_str (), scan_format.c_str(), &host_float, &n);
+  DIAGNOSTIC_POP
 
   /* The sscanf man page suggests not making any assumptions on the effect
      of %n on the result, so we don't.
index dd338493f9eee8ffb50d88143968c0e5b96f2ab1..82170acc802a442c87f9e0d051c2405fc212410c 100644 (file)
@@ -58,7 +58,10 @@ case "${host}" in
     build_warnings="$build_warnings -Wno-unknown-pragmas"
     # Solaris 11 <unistd.h> marks vfork deprecated.
     build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
-  *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
+  *)
+    # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
+    # but there's a special case for this below.
+    build_warnings="$build_warnings -Wformat-nonliteral" ;;
 esac
 
 AC_ARG_ENABLE(build-warnings,
@@ -106,6 +109,12 @@ then
        case $w in
        -Wno-*)
                wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
+        -Wformat-nonliteral)
+               # gcc requires -Wformat before -Wformat-nonliteral
+               # will work, so stick them together.
+               w="-Wformat $w"
+               wtest="$w"
+               ;;
        *)
                wtest=$w ;;
        esac