[PATCH/committed] sim: warnings: rework individual flag disable into dedicated vars

Message ID 20231223062248.20111-1-vapier@gentoo.org
State New
Headers
Series [PATCH/committed] sim: warnings: rework individual flag disable into dedicated vars |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Patch is already merged

Commit Message

Mike Frysinger Dec. 23, 2023, 6:22 a.m. UTC
  The -Wshadow=local is too new for some compilers, so move it to a var
that we test at configure time.
---
 sim/Makefile.in                  |   9 ++-
 sim/configure                    | 127 +++++++++++++++++++++++++------
 sim/cris/local.mk                |   6 +-
 sim/m4/sim_ac_option_warnings.m4 |  66 +++++++++++-----
 4 files changed, 157 insertions(+), 51 deletions(-)
  

Patch

diff --git a/sim/cris/local.mk b/sim/cris/local.mk
index a8eea65572ad..fe3f3c8d043c 100644
--- a/sim/cris/local.mk
+++ b/sim/cris/local.mk
@@ -17,10 +17,10 @@ 
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ## Some CGEN kludges are causing build-time warnings.  See cris.cpu for details.
-AM_CFLAGS_%C%_mloopv10f.o = -Wno-unused-but-set-variable
-AM_CFLAGS_%C%_mloopv32f.o = -Wno-unused-but-set-variable
+AM_CFLAGS_%C%_mloopv10f.o = $(SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE)
+AM_CFLAGS_%C%_mloopv32f.o = $(SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE)
 ## Some CGEN assignments use variable names that are nested & repeated.
-AM_CFLAGS_%C%_mloopv10f.o += -Wno-shadow=local
+AM_CFLAGS_%C%_mloopv10f.o += $(SIM_CFLAG_WNO_SHADOW_LOCAL)
 
 nodist_%C%_libsim_a_SOURCES = \
 	%D%/modules.c
diff --git a/sim/m4/sim_ac_option_warnings.m4 b/sim/m4/sim_ac_option_warnings.m4
index 1c2d09152306..02b5ffaa5c76 100644
--- a/sim/m4/sim_ac_option_warnings.m4
+++ b/sim/m4/sim_ac_option_warnings.m4
@@ -128,33 +128,57 @@  then
     # Separate out the -Werror flag as some files just cannot be
     # compiled with it enabled.
     for w in ${build_warnings}; do
-	# GCC does not complain about -Wno-unknown-warning.  Invert
-	# and test -Wunknown-warning instead.
-	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
-
 	case $w in
 	-Werr*) WERROR_CFLAGS=-Werror ;;
-	*)
-	    # Check whether GCC accepts it.
-	    saved_CFLAGS="$CFLAGS"
-	    CFLAGS="$CFLAGS -Werror $wtest"
-	    AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
-	    CFLAGS="$saved_CFLAGS"
+	*) _SIM_TEST_WARNING_FLAG($w, [WARN_CFLAGS="${WARN_CFLAGS} $w"]) ;;
 	esac
     done
     AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
+
+    dnl Test individual flags to export to dedicated variables.
+    m4_map([_SIM_EXPORT_WARNING_FLAG], m4_split(m4_normalize([
+	-Wno-shadow=local
+	-Wno-unused-but-set-variable
+    ])))dnl
 fi
 ])
+dnl Test a warning flag $1 and execute $2 if it passes, else $3.
+AC_DEFUN([_SIM_TEST_WARNING_FLAG], [dnl
+  dnl GCC does not complain about -Wno-unknown-warning.  Invert
+  dnl and test -Wunknown-warning instead.
+  w="$1"
+  case $w in
+  -Wno-*)
+    wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
+  -Wformat-nonliteral)
+    dnl gcc requires -Wformat before -Wformat-nonliteral
+    dnl will work, so stick them together.
+    w="-Wformat $w"
+    wtest="$w"
+    ;;
+  *)
+    wtest=$w ;;
+  esac
+
+  dnl Check whether GCC accepts it.
+  saved_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -Werror $wtest"
+  AC_TRY_COMPILE([],[],$2,$3)
+  CFLAGS="$saved_CFLAGS"
+])
+dnl Export variable $1 to $2 for use in makefiles.
+AC_DEFUN([_SIM_EXPORT_WARNING], [dnl
+  AS_VAR_SET($1, $2)
+  AC_SUBST($1)
+])
+dnl Test if $1 is a known warning flag, and export a variable for makefiles.
+dnl If $1=-Wfoo, then SIM_CFLAG_WFOO will be set to -Wfoo if it's supported.
+AC_DEFUN([_SIM_EXPORT_WARNING_FLAG], [dnl
+  AC_MSG_CHECKING([whether $1 is supported])
+  _SIM_TEST_WARNING_FLAG($1, [dnl
+    _SIM_EXPORT_WARNING([SIM_CFLAG]m4_toupper(m4_translit($1, [-= ], [__])), $1)
+    AC_MSG_RESULT(yes)
+  ], [AC_MSG_RESULT(no)])
+])
 AC_SUBST(WARN_CFLAGS)
 AC_SUBST(WERROR_CFLAGS)