sim: warnings: rework individual flag disable into dedicated vars

The -Wshadow=local is too new for some compilers, so move it to a var
that we test at configure time.
This commit is contained in:
Mike Frysinger 2023-12-23 01:00:08 -05:00
parent 576d2c97d8
commit 4da6be3f1a
4 changed files with 157 additions and 51 deletions

View File

@ -1677,6 +1677,8 @@ SDL_LIBS = @SDL_LIBS@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SIM_CFLAG_WNO_SHADOW_LOCAL = @SIM_CFLAG_WNO_SHADOW_LOCAL@
SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE = @SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE@
SIM_ENABLED_ARCHES = @SIM_ENABLED_ARCHES@
SIM_FRV_TRAPDUMP_FLAGS = @SIM_FRV_TRAPDUMP_FLAGS@
SIM_HW_CFLAGS = @SIM_HW_CFLAGS@
@ -2160,10 +2162,9 @@ testsuite_common_CPPFLAGS = \
@SIM_ENABLE_ARCH_cr16_TRUE@cr16_gencode_SOURCES = cr16/gencode.c
@SIM_ENABLE_ARCH_cr16_TRUE@cr16_gencode_LDADD = cr16/cr16-opc.o
@SIM_ENABLE_ARCH_cris_TRUE@AM_CFLAGS_cris_mloopv10f.o = \
@SIM_ENABLE_ARCH_cris_TRUE@ -Wno-unused-but-set-variable \
@SIM_ENABLE_ARCH_cris_TRUE@ -Wno-shadow=local
@SIM_ENABLE_ARCH_cris_TRUE@AM_CFLAGS_cris_mloopv32f.o = -Wno-unused-but-set-variable
@SIM_ENABLE_ARCH_cris_TRUE@AM_CFLAGS_cris_mloopv10f.o = $(SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE) \
@SIM_ENABLE_ARCH_cris_TRUE@ $(SIM_CFLAG_WNO_SHADOW_LOCAL)
@SIM_ENABLE_ARCH_cris_TRUE@AM_CFLAGS_cris_mloopv32f.o = $(SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE)
@SIM_ENABLE_ARCH_cris_TRUE@nodist_cris_libsim_a_SOURCES = \
@SIM_ENABLE_ARCH_cris_TRUE@ cris/modules.c

127
sim/configure vendored
View File

@ -657,6 +657,8 @@ SIM_MIPS_FPU_BITSIZE
SIM_MIPS_BITSIZE
SIM_MIPS_SUBTARGET
SIM_FRV_TRAPDUMP_FLAGS
SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE
SIM_CFLAG_WNO_SHADOW_LOCAL
IGEN_FLAGS_SMP
SIM_INLINE
SIM_HW_SOCKSER
@ -12290,7 +12292,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 12293 "configure"
#line 12295 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -12396,7 +12398,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 12399 "configure"
#line 12401 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -15906,28 +15908,23 @@ $as_echo_n "checking compiler warning flags... " >&6; }
# 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"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
*) w="$w"
case $w in
-Wno-*)
wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
-Wformat-nonliteral)
w="-Wformat $w"
wtest="$w"
;;
*)
wtest=$w ;;
esac
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror $wtest"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
@ -15942,11 +15939,95 @@ if ac_fn_c_try_compile "$LINENO"; then :
WARN_CFLAGS="${WARN_CFLAGS} $w"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$saved_CFLAGS"
CFLAGS="$saved_CFLAGS"
;;
esac
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${WARN_CFLAGS} ${WERROR_CFLAGS}" >&5
$as_echo "${WARN_CFLAGS} ${WERROR_CFLAGS}" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wno-shadow=local is supported" >&5
$as_echo_n "checking whether -Wno-shadow=local is supported... " >&6; }
w="-Wno-shadow=local"
case $w in
-Wno-*)
wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
-Wformat-nonliteral)
w="-Wformat $w"
wtest="$w"
;;
*)
wtest=$w ;;
esac
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror $wtest"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
SIM_CFLAG_WNO_SHADOW_LOCAL=-Wno-shadow=local
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$saved_CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wno-unused-but-set-variable is supported" >&5
$as_echo_n "checking whether -Wno-unused-but-set-variable is supported... " >&6; }
w="-Wno-unused-but-set-variable"
case $w in
-Wno-*)
wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
-Wformat-nonliteral)
w="-Wformat $w"
wtest="$w"
;;
*)
wtest=$w ;;
esac
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror $wtest"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
SIM_CFLAG_WNO_UNUSED_BUT_SET_VARIABLE=-Wno-unused-but-set-variable
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$saved_CFLAGS"
fi

View File

@ -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

View File

@ -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)