]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/m4/sim_ac_option_warnings.m4
sim: warnings: enable -Wreturn-type
[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
fa113bd9 71-Wreturn-mismatch
3744b73e 72-Wreturn-type
2757c1c6 73-Wstrict-prototypes
a7292455
MF
74dnl The cgen virtual insn logic involves enum conversions.
75dnl Disable until we can figure out how to make this work.
76-Wno-enum-conversion
7f6fa743 77"
760b3e8b 78
760b3e8b 79case "${host}" in
3c7666dc
MF
80 *-*-mingw32*)
81 # Enable -Wno-format by default when using gcc on mingw since many
82 # GCC versions complain about %I64.
83 build_warnings="$build_warnings -Wno-format" ;;
84 *-*-solaris*)
85 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
86 # doesn't understand.
87 build_warnings="$build_warnings -Wno-unknown-pragmas"
88 # Solaris 11 <unistd.h> marks vfork deprecated.
89 build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
90 *)
91 # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
92 # but there's a special case for this below.
93 build_warnings="$build_warnings -Wformat-nonliteral" ;;
760b3e8b
MF
94esac
95
96AC_ARG_ENABLE(build-warnings,
97AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
98[case "${enableval}" in
99 yes) ;;
100 no) build_warnings="-w";;
101 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
102 build_warnings="${build_warnings} ${t}";;
103 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
104 build_warnings="${t} ${build_warnings}";;
105 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
106esac
107if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
108 echo "Setting compiler warning flags = $build_warnings" 6>&1
109fi])dnl
110AC_ARG_ENABLE(sim-build-warnings,
111AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
112[case "${enableval}" in
113 yes) ;;
114 no) build_warnings="-w";;
115 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
116 build_warnings="${build_warnings} ${t}";;
117 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
118 build_warnings="${t} ${build_warnings}";;
119 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
120esac
121if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
122 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
123fi])dnl
124WARN_CFLAGS=""
125if test "x${build_warnings}" != x -a "x$GCC" = xyes
126then
127 AC_MSG_CHECKING(compiler warning flags)
128 # Separate out the -Werror flag as some files just cannot be
129 # compiled with it enabled.
130 for w in ${build_warnings}; do
3c7666dc
MF
131 # GCC does not complain about -Wno-unknown-warning. Invert
132 # and test -Wunknown-warning instead.
133 case $w in
134 -Wno-*)
135 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
136 -Wformat-nonliteral)
137 # gcc requires -Wformat before -Wformat-nonliteral
138 # will work, so stick them together.
139 w="-Wformat $w"
140 wtest="$w"
141 ;;
142 *)
143 wtest=$w ;;
144 esac
145
760b3e8b
MF
146 case $w in
147 -Werr*) WERROR_CFLAGS=-Werror ;;
3c7666dc
MF
148 *)
149 # Check whether GCC accepts it.
760b3e8b 150 saved_CFLAGS="$CFLAGS"
3c7666dc 151 CFLAGS="$CFLAGS -Werror $wtest"
760b3e8b
MF
152 AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
153 CFLAGS="$saved_CFLAGS"
154 esac
155 done
156 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
157fi
158])
159AC_SUBST(WARN_CFLAGS)
160AC_SUBST(WERROR_CFLAGS)