| 1 |
# manywarnings.m4 serial 23 |
| 2 |
dnl Copyright (C) 2008-2023 Free Software Foundation, Inc. |
| 3 |
dnl This file is free software; the Free Software Foundation |
| 4 |
dnl gives unlimited permission to copy and/or distribute it, |
| 5 |
dnl with or without modifications, as long as this notice is preserved. |
| 6 |
|
| 7 |
dnl From Simon Josefsson |
| 8 |
|
| 9 |
# gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) |
| 10 |
# -------------------------------------------------- |
| 11 |
# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. |
| 12 |
# Elements separated by whitespace. In set logic terms, the function |
| 13 |
# does OUTVAR = LISTVAR \ REMOVEVAR. |
| 14 |
AC_DEFUN([gl_MANYWARN_COMPLEMENT], |
| 15 |
[ |
| 16 |
gl_warn_set= |
| 17 |
set x $2; shift |
| 18 |
for gl_warn_item |
| 19 |
do |
| 20 |
case " $3 " in |
| 21 |
*" $gl_warn_item "*) |
| 22 |
;; |
| 23 |
*) |
| 24 |
gl_AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"]) |
| 25 |
;; |
| 26 |
esac |
| 27 |
done |
| 28 |
$1=$gl_warn_set |
| 29 |
]) |
| 30 |
|
| 31 |
# gl_MANYWARN_ALL_GCC(VARIABLE) |
| 32 |
# ----------------------------- |
| 33 |
# Add all documented GCC warning parameters to variable VARIABLE. |
| 34 |
# Note that you need to test them using gl_WARN_ADD if you want to |
| 35 |
# make sure your gcc understands it. |
| 36 |
# |
| 37 |
# The effects of this macro depend on the current language (_AC_LANG). |
| 38 |
AC_DEFUN([gl_MANYWARN_ALL_GCC], |
| 39 |
[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) |
| 40 |
|
| 41 |
# Specialization for _AC_LANG = C. |
| 42 |
AC_DEFUN([gl_MANYWARN_ALL_GCC(C)], |
| 43 |
[ |
| 44 |
AC_LANG_PUSH([C]) |
| 45 |
|
| 46 |
dnl First, check for some issues that only occur when combining multiple |
| 47 |
dnl gcc warning categories. |
| 48 |
AC_REQUIRE([AC_PROG_CC]) |
| 49 |
if test -n "$GCC"; then |
| 50 |
|
| 51 |
dnl Check if -Wextra -Werror -Wno-missing-field-initializers is supported |
| 52 |
dnl with the current $CC $CFLAGS $CPPFLAGS. |
| 53 |
AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported], |
| 54 |
[gl_cv_cc_nomfi_supported], |
| 55 |
[gl_save_CFLAGS="$CFLAGS" |
| 56 |
CFLAGS="$CFLAGS -Wextra -Werror -Wno-missing-field-initializers" |
| 57 |
AC_COMPILE_IFELSE( |
| 58 |
[AC_LANG_PROGRAM([[]], [[]])], |
| 59 |
[gl_cv_cc_nomfi_supported=yes], |
| 60 |
[gl_cv_cc_nomfi_supported=no]) |
| 61 |
CFLAGS="$gl_save_CFLAGS" |
| 62 |
]) |
| 63 |
|
| 64 |
if test "$gl_cv_cc_nomfi_supported" = yes; then |
| 65 |
dnl Now check whether -Wno-missing-field-initializers is needed |
| 66 |
dnl for the { 0, } construct. |
| 67 |
AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed], |
| 68 |
[gl_cv_cc_nomfi_needed], |
| 69 |
[gl_save_CFLAGS="$CFLAGS" |
| 70 |
CFLAGS="$CFLAGS -Wextra -Werror" |
| 71 |
AC_COMPILE_IFELSE( |
| 72 |
[AC_LANG_PROGRAM( |
| 73 |
[[int f (void) |
| 74 |
{ |
| 75 |
typedef struct { int a; int b; } s_t; |
| 76 |
s_t s1 = { 0, }; |
| 77 |
return s1.b; |
| 78 |
} |
| 79 |
]], |
| 80 |
[[]])], |
| 81 |
[gl_cv_cc_nomfi_needed=no], |
| 82 |
[gl_cv_cc_nomfi_needed=yes]) |
| 83 |
CFLAGS="$gl_save_CFLAGS" |
| 84 |
]) |
| 85 |
fi |
| 86 |
|
| 87 |
dnl Next, check if -Werror -Wuninitialized is useful with the |
| 88 |
dnl user's choice of $CFLAGS; some versions of gcc warn that it |
| 89 |
dnl has no effect if -O is not also used |
| 90 |
AC_CACHE_CHECK([whether -Wuninitialized is supported], |
| 91 |
[gl_cv_cc_uninitialized_supported], |
| 92 |
[gl_save_CFLAGS="$CFLAGS" |
| 93 |
CFLAGS="$CFLAGS -Werror -Wuninitialized" |
| 94 |
AC_COMPILE_IFELSE( |
| 95 |
[AC_LANG_PROGRAM([[]], [[]])], |
| 96 |
[gl_cv_cc_uninitialized_supported=yes], |
| 97 |
[gl_cv_cc_uninitialized_supported=no]) |
| 98 |
CFLAGS="$gl_save_CFLAGS" |
| 99 |
]) |
| 100 |
|
| 101 |
fi |
| 102 |
|
| 103 |
# List all gcc warning categories. |
| 104 |
# To compare this list to your installed GCC's, run this Bash command: |
| 105 |
# |
| 106 |
# comm -3 \ |
| 107 |
# <((sed -n 's/^ *\(-[^ 0-9][^ ]*\).*/\1/p' manywarnings.m4; \ |
| 108 |
# awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \ |
| 109 |
# <(LC_ALL=C gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort) |
| 110 |
|
| 111 |
$1= |
| 112 |
for gl_manywarn_item in -fanalyzer -fno-common \ |
| 113 |
-Wall \ |
| 114 |
-Warith-conversion \ |
| 115 |
-Wbad-function-cast \ |
| 116 |
-Wcast-align=strict \ |
| 117 |
-Wdate-time \ |
| 118 |
-Wdisabled-optimization \ |
| 119 |
-Wdouble-promotion \ |
| 120 |
-Wduplicated-branches \ |
| 121 |
-Wduplicated-cond \ |
| 122 |
-Wextra \ |
| 123 |
-Wformat-signedness \ |
| 124 |
-Winit-self \ |
| 125 |
-Winline \ |
| 126 |
-Winvalid-pch \ |
| 127 |
-Wlogical-op \ |
| 128 |
-Wmissing-declarations \ |
| 129 |
-Wmissing-include-dirs \ |
| 130 |
-Wmissing-prototypes \ |
| 131 |
-Wnested-externs \ |
| 132 |
-Wnull-dereference \ |
| 133 |
-Wold-style-definition \ |
| 134 |
-Wopenmp-simd \ |
| 135 |
-Woverlength-strings \ |
| 136 |
-Wpacked \ |
| 137 |
-Wpointer-arith \ |
| 138 |
-Wshadow \ |
| 139 |
-Wstack-protector \ |
| 140 |
-Wstrict-overflow \ |
| 141 |
-Wstrict-prototypes \ |
| 142 |
-Wsuggest-attribute=cold \ |
| 143 |
-Wsuggest-attribute=const \ |
| 144 |
-Wsuggest-attribute=format \ |
| 145 |
-Wsuggest-attribute=malloc \ |
| 146 |
-Wsuggest-attribute=noreturn \ |
| 147 |
-Wsuggest-attribute=pure \ |
| 148 |
-Wsuggest-final-methods \ |
| 149 |
-Wsuggest-final-types \ |
| 150 |
-Wsync-nand \ |
| 151 |
-Wsystem-headers \ |
| 152 |
-Wtrampolines \ |
| 153 |
-Wuninitialized \ |
| 154 |
-Wunknown-pragmas \ |
| 155 |
-Wunsafe-loop-optimizations \ |
| 156 |
-Wunused-macros \ |
| 157 |
-Wvariadic-macros \ |
| 158 |
-Wvector-operation-performance \ |
| 159 |
-Wvla \ |
| 160 |
-Wwrite-strings \ |
| 161 |
\ |
| 162 |
; do |
| 163 |
gl_AS_VAR_APPEND([$1], [" $gl_manywarn_item"]) |
| 164 |
done |
| 165 |
|
| 166 |
# gcc --help=warnings outputs an unusual form for these options; list |
| 167 |
# them here so that the above 'comm' command doesn't report a false match. |
| 168 |
gl_AS_VAR_APPEND([$1], [' -Warray-bounds=2']) |
| 169 |
gl_AS_VAR_APPEND([$1], [' -Wattribute-alias=2']) |
| 170 |
gl_AS_VAR_APPEND([$1], [' -Wbidi-chars=any,ucn']) |
| 171 |
gl_AS_VAR_APPEND([$1], [' -Wformat-overflow=2']) |
| 172 |
gl_AS_VAR_APPEND([$1], [' -Wformat=2']) |
| 173 |
gl_AS_VAR_APPEND([$1], [' -Wformat-truncation=2']) |
| 174 |
gl_AS_VAR_APPEND([$1], [' -Wimplicit-fallthrough=5']) |
| 175 |
gl_AS_VAR_APPEND([$1], [' -Wshift-overflow=2']) |
| 176 |
gl_AS_VAR_APPEND([$1], [' -Wuse-after-free=3']) |
| 177 |
gl_AS_VAR_APPEND([$1], [' -Wunused-const-variable=2']) |
| 178 |
gl_AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031']) |
| 179 |
|
| 180 |
# These are needed for older GCC versions. |
| 181 |
if test -n "$GCC"; then |
| 182 |
case `($CC --version) 2>/dev/null` in |
| 183 |
'gcc (GCC) '[[0-3]].* | \ |
| 184 |
'gcc (GCC) '4.[[0-7]].*) |
| 185 |
gl_AS_VAR_APPEND([$1], [' -fdiagnostics-show-option']) |
| 186 |
gl_AS_VAR_APPEND([$1], [' -funit-at-a-time']) |
| 187 |
;; |
| 188 |
esac |
| 189 |
fi |
| 190 |
|
| 191 |
# Disable specific options as needed. |
| 192 |
if test "$gl_cv_cc_nomfi_needed" = yes; then |
| 193 |
gl_AS_VAR_APPEND([$1], [' -Wno-missing-field-initializers']) |
| 194 |
fi |
| 195 |
|
| 196 |
if test "$gl_cv_cc_uninitialized_supported" = no; then |
| 197 |
gl_AS_VAR_APPEND([$1], [' -Wno-uninitialized']) |
| 198 |
fi |
| 199 |
|
| 200 |
# This warning have too many false alarms in GCC 11.2.1. |
| 201 |
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101713 |
| 202 |
gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-malloc-leak']) |
| 203 |
|
| 204 |
AC_LANG_POP([C]) |
| 205 |
]) |
| 206 |
|
| 207 |
# Specialization for _AC_LANG = C++. |
| 208 |
AC_DEFUN([gl_MANYWARN_ALL_GCC(C++)], |
| 209 |
[ |
| 210 |
gl_MANYWARN_ALL_GCC_CXX_IMPL([$1]) |
| 211 |
]) |