Debian Codegraph @

m4/manywarnings.m4

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