Debian Codegraph @

m4/manywarnings.m4

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