1 dnl Copyright (C) 1997-2024 Free Software Foundation, Inc.
3 dnl This program is free software; you can redistribute it and/or modify
4 dnl it under the terms of the GNU General Public License as published by
5 dnl the Free Software Foundation; either version 3 of the License, or
6 dnl (at your option) any later version.
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 dnl GNU General Public License for more details.
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
16 dnl --enable-build-warnings is for developers of the simulator.
17 dnl it enables extra GCC specific warnings.
18 AC_DEFUN([SIM_AC_OPTION_WARNINGS], [dnl
20 AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
21 [case "${enableval}" in
22 yes | y) ERROR_ON_WARNING="yes" ;;
23 no | n) ERROR_ON_WARNING="no" ;;
24 *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
27 dnl Enable -Werror by default when using gcc. Turn it off for releases.
28 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then
33 if test "${ERROR_ON_WARNING}" = yes ; then
34 WERROR_CFLAGS="-Werror"
37 dnl The options we'll try to enable.
38 dnl NB: Kept somewhat in sync with gdbsupport/warnings.m4.
39 build_warnings="-Wall -Wpointer-arith
40 -Wno-unused -Wunused-value -Wunused-variable -Wunused-function
41 -Wno-switch -Wno-char-subscripts
42 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable
43 -Wno-sign-compare -Wno-error=maybe-uninitialized
44 dnl C++ -Wno-mismatched-tags
45 -Wno-error=deprecated-register
46 dnl C++ -Wsuggest-override
47 -Wimplicit-fallthrough=5
50 dnl C++ -Wdeprecated-copy
51 dnl C++ -Wdeprecated-copy-dtor
52 dnl C++ -Wredundant-move
53 -Wmissing-declarations
54 dnl C++ -Wstrict-null-sentinel
56 dnl Some extra warnings we use in the sim.
57 build_warnings="$build_warnings
58 -Wdeclaration-after-statement
59 -Wdeprecated-non-prototype
60 -Wimplicit-function-declaration
62 -Wincompatible-function-pointer-types
63 -Wincompatible-pointer-types
65 -Wmisleading-indentation
66 -Wmissing-parameter-type
68 -Wold-style-declaration
69 -Wold-style-definition
73 -Wshift-negative-value
75 dnl The cgen virtual insn logic involves enum conversions.
76 dnl Disable until we can figure out how to make this work.
79 build_build_warnings="
80 dnl TODO Fix the sh/gencode.c which triggers a ton of these warnings.
82 dnl TODO Figure out the igen code that triggers warnings w/FORTIFY_SOURCE.
83 -Wno-stringop-truncation
84 dnl Fixing this requires ATTRIBUTE_FALLTHROUGH support at build time, but we
85 dnl don't have gnulib there (yet).
86 -Wno-implicit-fallthrough
87 dnl TODO Enable this after cleaning up code.
93 # Enable -Wno-format by default when using gcc on mingw since many
94 # GCC versions complain about %I64.
95 build_warnings="$build_warnings -Wno-format" ;;
97 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
99 build_warnings="$build_warnings -Wno-unknown-pragmas"
100 # Solaris 11 <unistd.h> marks vfork deprecated.
101 build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
103 # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
104 # but there's a special case for this below.
105 build_warnings="$build_warnings -Wformat-nonliteral" ;;
108 AC_ARG_ENABLE(build-warnings,
109 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
110 [case "${enableval}" in
112 no) build_warnings="-w";;
113 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
114 build_warnings="${build_warnings} ${t}";;
115 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
116 build_warnings="${t} ${build_warnings}";;
117 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
119 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
120 echo "Setting compiler warning flags = $build_warnings" 6>&1
122 AC_ARG_ENABLE(sim-build-warnings,
123 AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
124 [case "${enableval}" in
126 no) build_warnings="-w";;
127 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
128 build_warnings="${build_warnings} ${t}";;
129 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
130 build_warnings="${t} ${build_warnings}";;
131 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
133 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
134 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
138 if test "x${build_warnings}" != x -a "x$GCC" = xyes
140 AC_DEFUN([_SIM_TEST_ALL_WARNING_FLAGS], [dnl
141 AC_MSG_CHECKING(compiler warning flags)
142 # Separate out the -Werror flag as some files just cannot be
143 # compiled with it enabled.
144 for w in ${build_warnings}; do
146 -Werr*) WERROR_CFLAGS=-Werror ;;
147 *) _SIM_TEST_WARNING_FLAG($w, [WARN_CFLAGS="${WARN_CFLAGS} $w"]) ;;
150 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
153 dnl Test the host flags.
154 _SIM_TEST_ALL_WARNING_FLAGS
156 dnl Test the build flags.
157 AS_IF([test "x$cross_compiling" = "xno"], [dnl
158 SAVE_WARN_CFLAGS=$WARN_CFLAGS
159 build_warnings=$build_build_warnings
160 _SIM_TEST_ALL_WARNING_FLAGS
161 BUILD_WARN_CFLAGS=$WARN_CFLAGS
162 WARN_CFLAGS=$SAVE_WARN_CFLAGS
163 BUILD_WERROR_CFLAGS=$WERROR_CFLAGS
166 dnl Test individual flags to export to dedicated variables.
167 m4_map([_SIM_EXPORT_WARNING_FLAG], m4_split(m4_normalize([
169 -Wno-unused-but-set-variable
173 dnl Test a warning flag $1 and execute $2 if it passes, else $3.
174 AC_DEFUN([_SIM_TEST_WARNING_FLAG], [dnl
175 dnl GCC does not complain about -Wno-unknown-warning. Invert
176 dnl and test -Wunknown-warning instead.
180 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
182 dnl gcc requires -Wformat before -Wformat-nonliteral
183 dnl will work, so stick them together.
191 dnl Check whether GCC accepts it.
192 saved_CFLAGS="$CFLAGS"
193 CFLAGS="$CFLAGS -Werror $wtest"
194 AC_TRY_COMPILE([],[],$2,$3)
195 CFLAGS="$saved_CFLAGS"
197 dnl Export variable $1 to $2 for use in makefiles.
198 AC_DEFUN([_SIM_EXPORT_WARNING], [dnl
202 dnl Test if $1 is a known warning flag, and export a variable for makefiles.
203 dnl If $1=-Wfoo, then SIM_CFLAG_WFOO will be set to -Wfoo if it's supported.
204 AC_DEFUN([_SIM_EXPORT_WARNING_FLAG], [dnl
205 AC_MSG_CHECKING([whether $1 is supported])
206 _SIM_TEST_WARNING_FLAG($1, [dnl
207 _SIM_EXPORT_WARNING([SIM_CFLAG]m4_toupper(m4_translit($1, [-= ], [__])), $1)
209 ], [AC_MSG_RESULT(no)])
211 AC_SUBST(WARN_CFLAGS)
212 AC_SUBST(WERROR_CFLAGS)
213 AC_SUBST(BUILD_WARN_CFLAGS)
214 AC_SUBST(BUILD_WERROR_CFLAGS)