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 Figure out the igen code that triggers warnings w/FORTIFY_SOURCE.
81 -Wno-stringop-truncation
82 dnl Fixing this requires ATTRIBUTE_FALLTHROUGH support at build time, but we
83 dnl don't have gnulib there (yet).
84 -Wno-implicit-fallthrough
85 dnl TODO Enable this after cleaning up code.
91 # Enable -Wno-format by default when using gcc on mingw since many
92 # GCC versions complain about %I64.
93 build_warnings="$build_warnings -Wno-format" ;;
95 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
97 build_warnings="$build_warnings -Wno-unknown-pragmas"
98 # Solaris 11 <unistd.h> marks vfork deprecated.
99 build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
101 # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
102 # but there's a special case for this below.
103 build_warnings="$build_warnings -Wformat-nonliteral" ;;
106 AC_ARG_ENABLE(build-warnings,
107 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
108 [case "${enableval}" in
110 no) build_warnings="-w";;
111 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
112 build_warnings="${build_warnings} ${t}";;
113 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
114 build_warnings="${t} ${build_warnings}";;
115 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
117 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
118 echo "Setting compiler warning flags = $build_warnings" 6>&1
120 AC_ARG_ENABLE(sim-build-warnings,
121 AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
122 [case "${enableval}" in
124 no) build_warnings="-w";;
125 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
126 build_warnings="${build_warnings} ${t}";;
127 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
128 build_warnings="${t} ${build_warnings}";;
129 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
131 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
132 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
136 if test "x${build_warnings}" != x -a "x$GCC" = xyes
138 AC_DEFUN([_SIM_TEST_ALL_WARNING_FLAGS], [dnl
139 AC_MSG_CHECKING(compiler warning flags)
140 # Separate out the -Werror flag as some files just cannot be
141 # compiled with it enabled.
142 for w in ${build_warnings}; do
144 -Werr*) WERROR_CFLAGS=-Werror ;;
145 *) _SIM_TEST_WARNING_FLAG($w, [WARN_CFLAGS="${WARN_CFLAGS} $w"]) ;;
148 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
151 dnl Test the host flags.
152 _SIM_TEST_ALL_WARNING_FLAGS
154 dnl Test the build flags.
155 AS_IF([test "x$cross_compiling" = "xno"], [dnl
156 SAVE_WARN_CFLAGS=$WARN_CFLAGS
157 build_warnings=$build_build_warnings
158 _SIM_TEST_ALL_WARNING_FLAGS
159 BUILD_WARN_CFLAGS=$WARN_CFLAGS
160 WARN_CFLAGS=$SAVE_WARN_CFLAGS
161 BUILD_WERROR_CFLAGS=$WERROR_CFLAGS
164 dnl Test individual flags to export to dedicated variables.
165 m4_map([_SIM_EXPORT_WARNING_FLAG], m4_split(m4_normalize([
167 -Wno-unused-but-set-variable
171 dnl Test a warning flag $1 and execute $2 if it passes, else $3.
172 AC_DEFUN([_SIM_TEST_WARNING_FLAG], [dnl
173 dnl GCC does not complain about -Wno-unknown-warning. Invert
174 dnl and test -Wunknown-warning instead.
178 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
180 dnl gcc requires -Wformat before -Wformat-nonliteral
181 dnl will work, so stick them together.
189 dnl Check whether GCC accepts it.
190 saved_CFLAGS="$CFLAGS"
191 CFLAGS="$CFLAGS -Werror $wtest"
192 AC_TRY_COMPILE([],[],$2,$3)
193 CFLAGS="$saved_CFLAGS"
195 dnl Export variable $1 to $2 for use in makefiles.
196 AC_DEFUN([_SIM_EXPORT_WARNING], [dnl
200 dnl Test if $1 is a known warning flag, and export a variable for makefiles.
201 dnl If $1=-Wfoo, then SIM_CFLAG_WFOO will be set to -Wfoo if it's supported.
202 AC_DEFUN([_SIM_EXPORT_WARNING_FLAG], [dnl
203 AC_MSG_CHECKING([whether $1 is supported])
204 _SIM_TEST_WARNING_FLAG($1, [dnl
205 _SIM_EXPORT_WARNING([SIM_CFLAG]m4_toupper(m4_translit($1, [-= ], [__])), $1)
207 ], [AC_MSG_RESULT(no)])
209 AC_SUBST(WARN_CFLAGS)
210 AC_SUBST(WERROR_CFLAGS)
211 AC_SUBST(BUILD_WARN_CFLAGS)
212 AC_SUBST(BUILD_WERROR_CFLAGS)