]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m4/sim_ac_option_warnings.m4
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / sim / m4 / sim_ac_option_warnings.m4
1 dnl Copyright (C) 1997-2024 Free Software Foundation, Inc.
2 dnl
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.
7 dnl
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.
12 dnl
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/>.
15 dnl
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
19 AC_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
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
29 ERROR_ON_WARNING=yes
30 fi
31
32 WERROR_CFLAGS=""
33 if test "${ERROR_ON_WARNING}" = yes ; then
34 WERROR_CFLAGS="-Werror"
35 fi
36
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
48 -Wduplicated-cond
49 -Wshadow=local
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
55 "
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
61 -Wimplicit-int
62 -Wincompatible-function-pointer-types
63 -Wincompatible-pointer-types
64 -Wint-conversion
65 -Wmisleading-indentation
66 -Wmissing-parameter-type
67 -Wmissing-prototypes
68 -Wold-style-declaration
69 -Wold-style-definition
70 -Wpointer-sign
71 -Wreturn-mismatch
72 -Wreturn-type
73 -Wshift-negative-value
74 -Wstrict-prototypes
75 dnl The cgen virtual insn logic involves enum conversions.
76 dnl Disable until we can figure out how to make this work.
77 -Wno-enum-conversion
78 "
79 build_build_warnings="
80 dnl TODO Fix the sh/gencode.c which triggers a ton of these warnings.
81 -Wno-missing-braces
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.
88 -Wno-shadow=local
89 "
90
91 case "${host}" in
92 *-*-mingw32*)
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" ;;
96 *-*-solaris*)
97 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
98 # doesn't understand.
99 build_warnings="$build_warnings -Wno-unknown-pragmas"
100 # Solaris 11 <unistd.h> marks vfork deprecated.
101 build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
102 *)
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" ;;
106 esac
107
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
111 yes) ;;
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"`;;
118 esac
119 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
120 echo "Setting compiler warning flags = $build_warnings" 6>&1
121 fi])dnl
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
125 yes) ;;
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"`;;
132 esac
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
135 fi])dnl
136 WARN_CFLAGS=""
137 BUILD_WARN_CFLAGS=""
138 if test "x${build_warnings}" != x -a "x$GCC" = xyes
139 then
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
145 case $w in
146 -Werr*) WERROR_CFLAGS=-Werror ;;
147 *) _SIM_TEST_WARNING_FLAG($w, [WARN_CFLAGS="${WARN_CFLAGS} $w"]) ;;
148 esac
149 done
150 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
151 ])
152
153 dnl Test the host flags.
154 _SIM_TEST_ALL_WARNING_FLAGS
155
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
164 ])
165
166 dnl Test individual flags to export to dedicated variables.
167 m4_map([_SIM_EXPORT_WARNING_FLAG], m4_split(m4_normalize([
168 -Wno-shadow=local
169 -Wno-unused-but-set-variable
170 ])))dnl
171 fi
172 ])
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.
177 w="$1"
178 case $w in
179 -Wno-*)
180 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
181 -Wformat-nonliteral)
182 dnl gcc requires -Wformat before -Wformat-nonliteral
183 dnl will work, so stick them together.
184 w="-Wformat $w"
185 wtest="$w"
186 ;;
187 *)
188 wtest=$w ;;
189 esac
190
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"
196 ])
197 dnl Export variable $1 to $2 for use in makefiles.
198 AC_DEFUN([_SIM_EXPORT_WARNING], [dnl
199 AS_VAR_SET($1, $2)
200 AC_SUBST($1)
201 ])
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)
208 AC_MSG_RESULT(yes)
209 ], [AC_MSG_RESULT(no)])
210 ])
211 AC_SUBST(WARN_CFLAGS)
212 AC_SUBST(WERROR_CFLAGS)
213 AC_SUBST(BUILD_WARN_CFLAGS)
214 AC_SUBST(BUILD_WERROR_CFLAGS)