sim: ppc: unify (most) compiler warnings with common code
authorMike Frysinger <vapier@gentoo.org>
Wed, 30 Jun 2021 02:06:30 +0000 (22:06 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 30 Jun 2021 18:41:25 +0000 (14:41 -0400)
Copy most of the common build warning logic over from the common
code to help keep code behavior a bit consistent, and turn them
on by default.  We disable a few flags for now until we can clean
the code up.

sim/ppc/ChangeLog
sim/ppc/configure
sim/ppc/configure.ac

index 7a23d68842bd30c6c7f41132d22c485a62a35f90..1166d9223cfcb8cd1e502535be79c83d57147549 100644 (file)
@@ -1,3 +1,9 @@
+2021-06-30  Mike Frysinger  <vapier@gentoo.org>
+
+       * configure.ac: Add -W flags from ../m4/sim_ac_option_warnings.m4.
+       Run compile tests against each flag.
+       * configure: Regenerate.
+
 2021-06-29  Mike Frysinger  <vapier@gentoo.org>
 
        * main.c (sim_io_error): Add comment
index a3b7b30bf22eae3fd0ee36a5721b060392a74f0e..54b9ba2d094b1a2e53ed0cb1e3d6c46f7ac011ad 100755 (executable)
@@ -3496,18 +3496,55 @@ else
 fi
 
 
+sim_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith
+-Wno-unused -Wunused-value -Wunused-function
+-Wno-switch -Wno-char-subscripts
+-Wempty-body -Wunused-but-set-parameter
+-Wno-error=maybe-uninitialized
+-Wno-missing-declarations
+-Wno-missing-prototypes
+-Wdeclaration-after-statement -Wmissing-parameter-type
+-Wno-pointer-sign
+-Wold-style-declaration -Wold-style-definition
+"
 # Check whether --enable-sim-warnings was given.
 if test "${enable_sim_warnings+set}" = set; then :
   enableval=$enable_sim_warnings; case "${enableval}" in
-  yes) sim_warnings="-Werror -Wall -Wpointer-arith -Wmissing-prototypes -Wmissing-declarations ";;
+  yes) ;;
   no)  sim_warnings="-w";;
   *)   sim_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
 esac
 if test x"$silent" != x"yes" && test x"$sim_warnings" != x""; then
   echo "Setting warning flags = $sim_warnings" 6>&1
 fi
-else
-  sim_warnings=""
+fi
+if test "x${sim_warnings}" != x -a "x$GCC" = xyes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking compiler warning flags" >&5
+$as_echo_n "checking compiler warning flags... " >&6; }
+  build_warnings="${sim_warnings}"
+  sim_warnings=
+  for w in ${build_warnings}; do
+        saved_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS -Werror $w"
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  sim_warnings="${sim_warnings} $w"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    CFLAGS="$saved_CFLAGS"
+  done
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${sim_warnings}" >&5
+$as_echo "${sim_warnings}" >&6; }
 fi
 
 
index 30952f30a4afc1e27c4624e520de2acc2ae41a84..a7d226df5cf62d546e36c9b41eb9c00d272c0ad8 100644 (file)
@@ -430,16 +430,41 @@ if test x"$silent" != x"yes" && test x"$sim_timebase" != x""; then
 fi],[sim_timebase=""])dnl
 
 
+dnl TODO: Switch to common $(WARN_CFLAGS).
+sim_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith
+-Wno-unused -Wunused-value -Wunused-function
+-Wno-switch -Wno-char-subscripts
+-Wempty-body -Wunused-but-set-parameter
+-Wno-error=maybe-uninitialized
+-Wno-missing-declarations
+-Wno-missing-prototypes
+-Wdeclaration-after-statement -Wmissing-parameter-type
+-Wno-pointer-sign
+-Wold-style-declaration -Wold-style-definition
+"
 AC_ARG_ENABLE(sim-warnings,
 [  --enable-sim-warnings=opts          Extra CFLAGS for turning on compiler warnings except for idecode.o, semantics.o and psim.o],
 [case "${enableval}" in
-  yes) sim_warnings="-Werror -Wall -Wpointer-arith -Wmissing-prototypes -Wmissing-declarations ";;
+  yes) ;;
   no)  sim_warnings="-w";;
   *)   sim_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
 esac
 if test x"$silent" != x"yes" && test x"$sim_warnings" != x""; then
   echo "Setting warning flags = $sim_warnings" 6>&1
-fi],[sim_warnings=""])dnl
+fi])dnl
+if test "x${sim_warnings}" != x -a "x$GCC" = xyes; then
+  AC_MSG_CHECKING(compiler warning flags)
+  build_warnings="${sim_warnings}"
+  sim_warnings=
+  for w in ${build_warnings}; do
+    dnl Check that GCC accepts it
+    saved_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS -Werror $w"
+    AC_TRY_COMPILE([],[],sim_warnings="${sim_warnings} $w",)
+    CFLAGS="$saved_CFLAGS"
+  done
+  AC_MSG_RESULT(${sim_warnings})
+fi
 
 
 AC_ARG_ENABLE(sim-xor-endian,