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 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. 86 -Wno-shadow=local 87 " 88 89 case "${host}" in 90 *-*-mingw32*) 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" ;; 94 *-*-solaris*) 95 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC 96 # doesn't understand. 97 build_warnings="$build_warnings -Wno-unknown-pragmas" 98 # Solaris 11 <unistd.h> marks vfork deprecated. 99 build_warnings="$build_warnings -Wno-deprecated-declarations" ;; 100 *) 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" ;; 104 esac 105 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 109 yes) ;; 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"`;; 116 esac 117 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then 118 echo "Setting compiler warning flags = $build_warnings" 6>&1 119 fi])dnl 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 123 yes) ;; 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"`;; 130 esac 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 133 fi])dnl 134 WARN_CFLAGS="" 135 BUILD_WARN_CFLAGS="" 136 if test "x${build_warnings}" != x -a "x$GCC" = xyes 137 then 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 143 case $w in 144 -Werr*) WERROR_CFLAGS=-Werror ;; 145 *) _SIM_TEST_WARNING_FLAG($w, [WARN_CFLAGS="${WARN_CFLAGS} $w"]) ;; 146 esac 147 done 148 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS}) 149 ]) 150 151 dnl Test the host flags. 152 _SIM_TEST_ALL_WARNING_FLAGS 153 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 162 ]) 163 164 dnl Test individual flags to export to dedicated variables. 165 m4_map([_SIM_EXPORT_WARNING_FLAG], m4_split(m4_normalize([ 166 -Wno-shadow=local 167 -Wno-unused-but-set-variable 168 ])))dnl 169 fi 170 ]) 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. 175 w="$1" 176 case $w in 177 -Wno-*) 178 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;; 179 -Wformat-nonliteral) 180 dnl gcc requires -Wformat before -Wformat-nonliteral 181 dnl will work, so stick them together. 182 w="-Wformat $w" 183 wtest="$w" 184 ;; 185 *) 186 wtest=$w ;; 187 esac 188 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" 194 ]) 195 dnl Export variable $1 to $2 for use in makefiles. 196 AC_DEFUN([_SIM_EXPORT_WARNING], [dnl 197 AS_VAR_SET($1, $2) 198 AC_SUBST($1) 199 ]) 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) 206 AC_MSG_RESULT(yes) 207 ], [AC_MSG_RESULT(no)]) 208 ]) 209 AC_SUBST(WARN_CFLAGS) 210 AC_SUBST(WERROR_CFLAGS) 211 AC_SUBST(BUILD_WARN_CFLAGS) 212 AC_SUBST(BUILD_WERROR_CFLAGS) 213