]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/m4/sim_ac_option_warnings.m4
sim: warnings: enable -Wimplicit-fallthrough=5
[thirdparty/binutils-gdb.git] / sim / m4 / sim_ac_option_warnings.m4
CommitLineData
213516ef 1dnl Copyright (C) 1997-2023 Free Software Foundation, Inc.
760b3e8b
MF
2dnl
3dnl This program is free software; you can redistribute it and/or modify
4dnl it under the terms of the GNU General Public License as published by
5dnl the Free Software Foundation; either version 3 of the License, or
6dnl (at your option) any later version.
7dnl
8dnl This program is distributed in the hope that it will be useful,
9dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11dnl GNU General Public License for more details.
12dnl
13dnl You should have received a copy of the GNU General Public License
14dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
15dnl
16dnl --enable-build-warnings is for developers of the simulator.
17dnl it enables extra GCC specific warnings.
3c7666dc 18AC_DEFUN([SIM_AC_OPTION_WARNINGS], [dnl
760b3e8b
MF
19AC_ARG_ENABLE(werror,
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) ;;
25 esac])
26
ab18008e
MF
27dnl Enable -Werror by default when using gcc. Turn it off for releases.
28if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then
982c3a65 29 ERROR_ON_WARNING=yes
760b3e8b
MF
30fi
31
32WERROR_CFLAGS=""
982c3a65
MF
33if test "${ERROR_ON_WARNING}" = yes ; then
34 WERROR_CFLAGS="-Werror"
35fi
760b3e8b 36
3167423f
MF
37dnl The options we'll try to enable.
38dnl NB: Kept somewhat in sync with gdbsupport/warnings.m4.
b0c06375 39build_warnings="-Wall -Wpointer-arith
7f6fa743
MF
40-Wno-unused -Wunused-value -Wunused-function
41-Wno-switch -Wno-char-subscripts
00383ba6 42-Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable
b0c06375
MF
43-Wno-sign-compare -Wno-error=maybe-uninitialized
44dnl C++ -Wno-mismatched-tags
45-Wno-error=deprecated-register
46dnl C++ -Wsuggest-override
3a4ee628 47-Wimplicit-fallthrough=5
95cd009f 48-Wduplicated-cond
d137b254 49dnl -Wshadow=local
b0c06375
MF
50dnl C++ -Wdeprecated-copy
51dnl C++ -Wdeprecated-copy-dtor
52dnl C++ -Wredundant-move
7f6fa743 53-Wmissing-declarations
b0c06375
MF
54dnl C++ -Wstrict-null-sentinel
55"
56dnl Some extra warnings we use in the sim.
57build_warnings="$build_warnings
58-Wdeclaration-after-statement
59-Wdeprecated-non-prototype
60-Wimplicit-function-declaration
61-Wimplicit-int
62-Wincompatible-function-pointer-types
63-Wincompatible-pointer-types
2757c1c6 64-Wint-conversion
b0c06375
MF
65-Wmisleading-indentation
66-Wmissing-parameter-type
7f6fa743 67-Wmissing-prototypes
b0c06375
MF
68-Wold-style-declaration
69-Wold-style-definition
7f6fa743 70-Wpointer-sign
2757c1c6
MF
71-WWreturn-mismatch
72-Wstrict-prototypes
a7292455
MF
73dnl The cgen virtual insn logic involves enum conversions.
74dnl Disable until we can figure out how to make this work.
75-Wno-enum-conversion
7f6fa743 76"
760b3e8b 77
760b3e8b 78case "${host}" in
3c7666dc
MF
79 *-*-mingw32*)
80 # Enable -Wno-format by default when using gcc on mingw since many
81 # GCC versions complain about %I64.
82 build_warnings="$build_warnings -Wno-format" ;;
83 *-*-solaris*)
84 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
85 # doesn't understand.
86 build_warnings="$build_warnings -Wno-unknown-pragmas"
87 # Solaris 11 <unistd.h> marks vfork deprecated.
88 build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
89 *)
90 # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
91 # but there's a special case for this below.
92 build_warnings="$build_warnings -Wformat-nonliteral" ;;
760b3e8b
MF
93esac
94
95AC_ARG_ENABLE(build-warnings,
96AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
97[case "${enableval}" in
98 yes) ;;
99 no) build_warnings="-w";;
100 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
101 build_warnings="${build_warnings} ${t}";;
102 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
103 build_warnings="${t} ${build_warnings}";;
104 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
105esac
106if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
107 echo "Setting compiler warning flags = $build_warnings" 6>&1
108fi])dnl
109AC_ARG_ENABLE(sim-build-warnings,
110AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
111[case "${enableval}" in
112 yes) ;;
113 no) build_warnings="-w";;
114 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
115 build_warnings="${build_warnings} ${t}";;
116 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
117 build_warnings="${t} ${build_warnings}";;
118 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
119esac
120if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
121 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
122fi])dnl
123WARN_CFLAGS=""
124if test "x${build_warnings}" != x -a "x$GCC" = xyes
125then
126 AC_MSG_CHECKING(compiler warning flags)
127 # Separate out the -Werror flag as some files just cannot be
128 # compiled with it enabled.
129 for w in ${build_warnings}; do
3c7666dc
MF
130 # GCC does not complain about -Wno-unknown-warning. Invert
131 # and test -Wunknown-warning instead.
132 case $w in
133 -Wno-*)
134 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
135 -Wformat-nonliteral)
136 # gcc requires -Wformat before -Wformat-nonliteral
137 # will work, so stick them together.
138 w="-Wformat $w"
139 wtest="$w"
140 ;;
141 *)
142 wtest=$w ;;
143 esac
144
760b3e8b
MF
145 case $w in
146 -Werr*) WERROR_CFLAGS=-Werror ;;
3c7666dc
MF
147 *)
148 # Check whether GCC accepts it.
760b3e8b 149 saved_CFLAGS="$CFLAGS"
3c7666dc 150 CFLAGS="$CFLAGS -Werror $wtest"
760b3e8b
MF
151 AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
152 CFLAGS="$saved_CFLAGS"
153 esac
154 done
155 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
156fi
157])
158AC_SUBST(WARN_CFLAGS)
159AC_SUBST(WERROR_CFLAGS)