err.c revision 1.221 1 1.221 rillig /* $NetBSD: err.c,v 1.221 2023/12/10 15:29:38 rillig Exp $ */
2 1.2 cgd
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1994, 1995 Jochen Pohl
5 1.1 cgd * All Rights Reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.212 rillig * This product includes software developed by Jochen Pohl for
18 1.1 cgd * The NetBSD Project.
19 1.1 cgd * 4. The name of the author may not be used to endorse or promote products
20 1.1 cgd * derived from this software without specific prior written permission.
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 cgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 cgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 cgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 cgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 cgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 cgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 cgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 cgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 cgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.27 jmc #if HAVE_NBTOOL_CONFIG_H
35 1.27 jmc #include "nbtool_config.h"
36 1.27 jmc #endif
37 1.27 jmc
38 1.10 christos #include <sys/cdefs.h>
39 1.166 rillig #if defined(__RCSID)
40 1.221 rillig __RCSID("$NetBSD: err.c,v 1.221 2023/12/10 15:29:38 rillig Exp $");
41 1.1 cgd #endif
42 1.1 cgd
43 1.178 rillig #include <limits.h>
44 1.55 rillig #include <stdarg.h>
45 1.1 cgd #include <stdlib.h>
46 1.178 rillig #include <string.h>
47 1.1 cgd
48 1.1 cgd #include "lint1.h"
49 1.1 cgd
50 1.220 rillig bool seen_error;
51 1.220 rillig bool seen_warning;
52 1.12 christos
53 1.12 christos /* number of syntax errors */
54 1.220 rillig int sytxerr;
55 1.12 christos
56 1.12 christos
57 1.170 rillig static const char *const msgs[] = {
58 1.46 christos "empty declaration", /* 0 */
59 1.184 rillig "old-style declaration; add 'int'", /* 1 */
60 1.1 cgd "empty declaration", /* 2 */
61 1.215 rillig "'%s' declared in parameter declaration list", /* 3 */
62 1.1 cgd "illegal type combination", /* 4 */
63 1.1 cgd "modifying typedef with '%s'; only qualifiers allowed", /* 5 */
64 1.1 cgd "use 'double' instead of 'long float'", /* 6 */
65 1.1 cgd "only one storage class allowed", /* 7 */
66 1.1 cgd "illegal storage class", /* 8 */
67 1.207 rillig "only 'register' is valid as storage class in parameter", /* 9 */
68 1.1 cgd "duplicate '%s'", /* 10 */
69 1.1 cgd "bit-field initializer out of range", /* 11 */
70 1.1 cgd "compiler takes size of function", /* 12 */
71 1.169 rillig "incomplete enum type '%s'", /* 13 */
72 1.157 rillig "", /* 14 */
73 1.154 rillig "function returns illegal type '%s'", /* 15 */
74 1.1 cgd "array of function is illegal", /* 16 */
75 1.1 cgd "null dimension", /* 17 */
76 1.1 cgd "illegal use of 'void'", /* 18 */
77 1.74 rillig "void type for '%s'", /* 19 */
78 1.30 christos "negative array dimension (%d)", /* 20 */
79 1.169 rillig "redeclaration of formal parameter '%s'", /* 21 */
80 1.1 cgd "incomplete or misplaced function definition", /* 22 */
81 1.128 rillig "undefined label '%s'", /* 23 */
82 1.171 rillig "cannot initialize function '%s'", /* 24 */
83 1.171 rillig "cannot initialize typedef '%s'", /* 25 */
84 1.171 rillig "cannot initialize extern declaration '%s'", /* 26 */
85 1.169 rillig "redeclaration of '%s'", /* 27 */
86 1.171 rillig "redefinition of '%s'", /* 28 */
87 1.171 rillig "'%s' was previously declared extern, becomes static", /* 29 */
88 1.217 rillig "redeclaration of '%s'; C90 or later require static", /* 30 */
89 1.129 rillig "'%s' has incomplete type '%s'", /* 31 */
90 1.215 rillig "type of parameter '%s' defaults to 'int'", /* 32 */
91 1.172 rillig "duplicate member name '%s'", /* 33 */
92 1.118 rillig "nonportable bit-field type '%s'", /* 34 */
93 1.86 rillig "illegal bit-field type '%s'", /* 35 */
94 1.54 christos "illegal bit-field size: %d", /* 36 */
95 1.1 cgd "zero size bit-field", /* 37 */
96 1.1 cgd "function illegal in structure or union", /* 38 */
97 1.218 rillig "zero-sized array '%s' in struct requires C99 or later", /* 39 */
98 1.158 rillig "", /* never used */ /* 40 */
99 1.152 rillig "bit-field in union is very unusual", /* 41 */
100 1.1 cgd "forward reference to enum type", /* 42 */
101 1.173 rillig "redefinition of '%s' hides earlier one", /* 43 */
102 1.217 rillig "declaration of '%s %s' introduces new type in C90 or later", /* 44 */
103 1.1 cgd "base type is really '%s %s'", /* 45 */
104 1.137 rillig "%s tag '%s' redeclared as %s", /* 46 */
105 1.153 rillig "zero sized %s is a C99 feature", /* 47 */
106 1.173 rillig "enumeration value '%s' overflows", /* 48 */
107 1.153 rillig "anonymous struct/union members is a C11 feature", /* 49 */
108 1.208 rillig "parameter '%s' has function type, should be pointer", /* 50 */
109 1.1 cgd "parameter mismatch: %d declared, %d defined", /* 51 */
110 1.173 rillig "cannot initialize parameter '%s'", /* 52 */
111 1.215 rillig "declared parameter '%s' is missing", /* 53 */
112 1.211 rillig "trailing ',' in enum declaration requires C99 or later", /* 54 */
113 1.1 cgd "integral constant expression expected", /* 55 */
114 1.1 cgd "integral constant too large", /* 56 */
115 1.173 rillig "enumeration constant '%s' hides parameter", /* 57 */
116 1.175 rillig "type of '%s' does not match prototype", /* 58 */
117 1.173 rillig "formal parameter #%d lacks name", /* 59 */
118 1.1 cgd "void must be sole parameter", /* 60 */
119 1.173 rillig "void parameter '%s' cannot have name", /* 61 */
120 1.1 cgd "function prototype parameters must have types", /* 62 */
121 1.1 cgd "prototype does not match old-style definition", /* 63 */
122 1.1 cgd "()-less function definition", /* 64 */
123 1.176 rillig "'%s' has no named members", /* 65 */
124 1.130 rillig "", /* 66 */
125 1.1 cgd "cannot return incomplete type", /* 67 */
126 1.1 cgd "typedef already qualified with '%s'", /* 68 */
127 1.1 cgd "inappropriate qualifiers with 'void'", /* 69 */
128 1.159 rillig "", /* unused */ /* 70 */
129 1.1 cgd "too many characters in character constant", /* 71 */
130 1.1 cgd "typedef declares no type name", /* 72 */
131 1.1 cgd "empty character constant", /* 73 */
132 1.1 cgd "no hex digits follow \\x", /* 74 */
133 1.1 cgd "overflow in hex escape", /* 75 */
134 1.1 cgd "character escape does not fit in character", /* 76 */
135 1.207 rillig "bad octal digit '%c'", /* 77 */
136 1.141 rillig "", /* unused */ /* 78 */
137 1.1 cgd "dubious escape \\%c", /* 79 */
138 1.1 cgd "dubious escape \\%o", /* 80 */
139 1.1 cgd "\\a undefined in traditional C", /* 81 */
140 1.1 cgd "\\x undefined in traditional C", /* 82 */
141 1.1 cgd "storage class after type is obsolescent", /* 83 */
142 1.217 rillig "C90 to C17 require formal parameter before '...'", /* 84 */
143 1.175 rillig "dubious tag declaration '%s %s'", /* 85 */
144 1.173 rillig "automatic '%s' hides external declaration", /* 86 */
145 1.173 rillig "static '%s' hides external declaration", /* 87 */
146 1.173 rillig "typedef '%s' hides external declaration", /* 88 */
147 1.172 rillig "typedef '%s' redeclared", /* 89 */
148 1.175 rillig "inconsistent redeclaration of extern '%s'", /* 90 */
149 1.173 rillig "declaration of '%s' hides parameter", /* 91 */
150 1.175 rillig "inconsistent redeclaration of static '%s'", /* 92 */
151 1.175 rillig "dubious static function '%s' at block level", /* 93 */
152 1.175 rillig "function '%s' has illegal storage class", /* 94 */
153 1.175 rillig "declaration of '%s' hides earlier one", /* 95 */
154 1.175 rillig "cannot dereference non-pointer type '%s'", /* 96 */
155 1.208 rillig "suffix 'U' is illegal in traditional C", /* 97 */
156 1.208 rillig "suffixes 'F' and 'L' are illegal in traditional C", /* 98 */
157 1.95 rillig "'%s' undefined", /* 99 */
158 1.173 rillig "unary '+' is illegal in traditional C", /* 100 */
159 1.99 rillig "type '%s' does not have member '%s'", /* 101 */
160 1.172 rillig "illegal use of member '%s'", /* 102 */
161 1.125 rillig "left operand of '.' must be struct or union, not '%s'", /* 103 */
162 1.125 rillig "left operand of '->' must be pointer to struct or union, not '%s'", /* 104 */
163 1.1 cgd "non-unique member requires struct/union %s", /* 105 */
164 1.1 cgd "left operand of '->' must be pointer", /* 106 */
165 1.172 rillig "operands of '%s' have incompatible types '%s' and '%s'", /* 107 */
166 1.175 rillig "operand of '%s' has invalid type '%s'", /* 108 */
167 1.1 cgd "void type illegal in expression", /* 109 */
168 1.1 cgd "pointer to function is not allowed here", /* 110 */
169 1.1 cgd "unacceptable operand of '%s'", /* 111 */
170 1.1 cgd "cannot take address of bit-field", /* 112 */
171 1.176 rillig "cannot take address of register '%s'", /* 113 */
172 1.1 cgd "%soperand of '%s' must be lvalue", /* 114 */
173 1.1 cgd "%soperand of '%s' must be modifiable lvalue", /* 115 */
174 1.1 cgd "illegal pointer subtraction", /* 116 */
175 1.75 rillig "bitwise '%s' on signed value possibly nonportable", /* 117 */
176 1.217 rillig "semantics of '%s' change in C90; use explicit cast", /* 118 */
177 1.1 cgd "conversion of '%s' to '%s' is out of range", /* 119 */
178 1.75 rillig "bitwise '%s' on signed value nonportable", /* 120 */
179 1.1 cgd "negative shift", /* 121 */
180 1.103 rillig "shift amount %llu is greater than bit-size %llu of '%s'", /* 122 */
181 1.148 rillig "illegal combination of %s '%s' and %s '%s', op '%s'", /* 123 */
182 1.136 rillig "illegal combination of '%s' and '%s', op '%s'", /* 124 */
183 1.217 rillig "pointers to functions can only be compared for equality", /* 125 */
184 1.69 rillig "incompatible types '%s' and '%s' in conditional", /* 126 */
185 1.1 cgd "'&' before array or function: ignored", /* 127 */
186 1.176 rillig "operands of '%s' have incompatible pointer types to '%s' and '%s'", /* 128 */
187 1.1 cgd "expression has null effect", /* 129 */
188 1.84 rillig "enum type mismatch: '%s' '%s' '%s'", /* 130 */
189 1.1 cgd "conversion to '%s' may sign-extend incorrectly", /* 131 */
190 1.29 christos "conversion from '%s' to '%s' may lose accuracy", /* 132 */
191 1.1 cgd "conversion of pointer to '%s' loses bits", /* 133 */
192 1.1 cgd "conversion of pointer to '%s' may lose bits", /* 134 */
193 1.182 rillig "converting '%s' to '%s' increases alignment from %u to %u", /* 135 */
194 1.1 cgd "cannot do pointer arithmetic on operand of unknown size", /* 136 */
195 1.176 rillig "", /* unused */ /* 137 */
196 1.177 rillig "unknown operand size, op '%s'", /* 138 */
197 1.1 cgd "division by 0", /* 139 */
198 1.1 cgd "modulus by 0", /* 140 */
199 1.207 rillig "operator '%s' produces integer overflow", /* 141 */
200 1.207 rillig "operator '%s' produces floating point overflow", /* 142 */
201 1.42 christos "cannot take size/alignment of incomplete type", /* 143 */
202 1.155 rillig "cannot take size/alignment of function type '%s'", /* 144 */
203 1.42 christos "cannot take size/alignment of bit-field", /* 145 */
204 1.42 christos "cannot take size/alignment of void", /* 146 */
205 1.131 rillig "invalid cast from '%s' to '%s'", /* 147 */
206 1.1 cgd "improper cast of void expression", /* 148 */
207 1.176 rillig "cannot call '%s', must be a function", /* 149 */
208 1.176 rillig "argument mismatch: %d %s passed, %d expected", /* 150 */
209 1.1 cgd "void expressions may not be arguments, arg #%d", /* 151 */
210 1.1 cgd "argument cannot have unknown size, arg #%d", /* 152 */
211 1.83 rillig "converting '%s' to incompatible '%s' for argument %d", /* 153 */
212 1.176 rillig "illegal combination of %s '%s' and %s '%s', arg #%d", /* 154 */
213 1.121 rillig "passing '%s' to incompatible '%s', arg #%d", /* 155 */
214 1.176 rillig "function expects '%s', passing '%s' for arg #%d", /* 156 */
215 1.217 rillig "C90 treats constant as unsigned", /* 157 */
216 1.176 rillig "'%s' may be used before set", /* 158 */
217 1.1 cgd "assignment in conditional context", /* 159 */
218 1.1 cgd "operator '==' found where '=' was expected", /* 160 */
219 1.1 cgd "constant in conditional context", /* 161 */
220 1.176 rillig "operator '%s' compares '%s' with '%s'", /* 162 */
221 1.1 cgd "a cast does not yield an lvalue", /* 163 */
222 1.1 cgd "assignment of negative constant to unsigned type", /* 164 */
223 1.1 cgd "constant truncated by assignment", /* 165 */
224 1.1 cgd "precision lost in bit-field assignment", /* 166 */
225 1.1 cgd "array subscript cannot be negative: %ld", /* 167 */
226 1.1 cgd "array subscript cannot be > %d: %ld", /* 168 */
227 1.1 cgd "precedence confusion possible: parenthesize!", /* 169 */
228 1.208 rillig "first operand of '?' must have scalar type", /* 170 */
229 1.92 rillig "cannot assign to '%s' from '%s'", /* 171 */
230 1.1 cgd "too many struct/union initializers", /* 172 */
231 1.34 christos "too many array initializers, expected %d", /* 173 */
232 1.1 cgd "too many initializers", /* 174 */
233 1.98 rillig "initialization of incomplete type '%s'", /* 175 */
234 1.97 rillig "", /* no longer used */ /* 176 */
235 1.1 cgd "non-constant initializer", /* 177 */
236 1.1 cgd "initializer does not fit", /* 178 */
237 1.150 rillig "cannot initialize struct/union with no named member", /* 179 */
238 1.1 cgd "bit-field initializer does not fit", /* 180 */
239 1.213 rillig "{}-enclosed or constant initializer of type '%s' required", /* 181 */
240 1.176 rillig "incompatible pointer types to '%s' and '%s'", /* 182 */
241 1.176 rillig "illegal combination of %s '%s' and %s '%s'", /* 183 */
242 1.136 rillig "illegal combination of '%s' and '%s'", /* 184 */
243 1.88 rillig "cannot initialize '%s' from '%s'", /* 185 */
244 1.81 rillig "bit-field initialization is illegal in traditional C", /* 186 */
245 1.149 rillig "string literal too long (%lu) for target array (%lu)", /* 187 */
246 1.1 cgd "no automatic aggregate initialization in traditional C", /* 188 */
247 1.70 rillig "", /* no longer used */ /* 189 */
248 1.176 rillig "empty array declaration for '%s'", /* 190 */
249 1.106 rillig "'%s' set but not used in function '%s'", /* 191 */
250 1.106 rillig "'%s' unused in function '%s'", /* 192 */
251 1.1 cgd "statement not reached", /* 193 */
252 1.176 rillig "label '%s' redefined", /* 194 */
253 1.1 cgd "case not in switch", /* 195 */
254 1.1 cgd "case label affected by conversion", /* 196 */
255 1.1 cgd "non-constant case expression", /* 197 */
256 1.1 cgd "non-integral case expression", /* 198 */
257 1.207 rillig "duplicate case '%ld' in switch", /* 199 */
258 1.207 rillig "duplicate case '%lu' in switch", /* 200 */
259 1.1 cgd "default outside switch", /* 201 */
260 1.1 cgd "duplicate default in switch", /* 202 */
261 1.138 rillig "case label must be of type 'int' in traditional C", /* 203 */
262 1.1 cgd "controlling expressions must have scalar type", /* 204 */
263 1.1 cgd "switch expression must have integral type", /* 205 */
264 1.1 cgd "enumeration value(s) not handled in switch", /* 206 */
265 1.1 cgd "loop not entered at top", /* 207 */
266 1.1 cgd "break outside loop or switch", /* 208 */
267 1.1 cgd "continue outside loop", /* 209 */
268 1.81 rillig "enum type mismatch between '%s' and '%s' in initialization", /* 210 */
269 1.178 rillig "function has return type '%s' but returns '%s'", /* 211 */
270 1.1 cgd "cannot return incomplete type", /* 212 */
271 1.176 rillig "void function '%s' cannot return value", /* 213 */
272 1.133 rillig "function '%s' expects to return value", /* 214 */
273 1.122 rillig "function '%s' implicitly declared to return int", /* 215 */
274 1.176 rillig "function '%s' has 'return expr' and 'return'", /* 216 */
275 1.176 rillig "function '%s' falls off bottom without returning value", /* 217 */
276 1.217 rillig "C90 treats constant as unsigned, op '%s'", /* 218 */
277 1.1 cgd "concatenated strings are illegal in traditional C", /* 219 */
278 1.1 cgd "fallthrough on case statement", /* 220 */
279 1.81 rillig "initialization of unsigned with negative constant", /* 221 */
280 1.1 cgd "conversion of negative constant to unsigned type", /* 222 */
281 1.1 cgd "end-of-loop code not reached", /* 223 */
282 1.1 cgd "cannot recover from previous errors", /* 224 */
283 1.176 rillig "static function '%s' called but not defined", /* 225 */
284 1.168 rillig "static variable '%s' unused", /* 226 */
285 1.176 rillig "const object '%s' should have initializer", /* 227 */
286 1.1 cgd "function cannot return const or volatile object", /* 228 */
287 1.83 rillig "converting '%s' to '%s' is questionable", /* 229 */
288 1.189 rillig "nonportable character comparison '%s'", /* 230 */
289 1.208 rillig "parameter '%s' unused in function '%s'", /* 231 */
290 1.128 rillig "label '%s' unused in function '%s'", /* 232 */
291 1.168 rillig "struct '%s' never defined", /* 233 */
292 1.168 rillig "union '%s' never defined", /* 234 */
293 1.168 rillig "enum '%s' never defined", /* 235 */
294 1.168 rillig "static function '%s' unused", /* 236 */
295 1.169 rillig "redeclaration of formal parameter '%s'", /* 237 */
296 1.81 rillig "initialization of union is illegal in traditional C", /* 238 */
297 1.215 rillig "constant operand to '!'", /* 239 */
298 1.177 rillig "", /* unused */ /* 240 */
299 1.207 rillig "dubious operation '%s' on enum", /* 241 */
300 1.176 rillig "combination of '%s' and '%s', op '%s'", /* 242 */
301 1.209 rillig "operator '%s' assumes that '%s' is ordered", /* 243 */
302 1.1 cgd "illegal structure pointer combination", /* 244 */
303 1.85 rillig "incompatible structure pointers: '%s' '%s' '%s'", /* 245 */
304 1.1 cgd "dubious conversion of enum to '%s'", /* 246 */
305 1.71 rillig "pointer cast from '%s' to '%s' may be troublesome", /* 247 */
306 1.1 cgd "floating-point constant out of range", /* 248 */
307 1.33 christos "syntax error '%s'", /* 249 */
308 1.1 cgd "unknown character \\%o", /* 250 */
309 1.1 cgd "malformed integer constant", /* 251 */
310 1.1 cgd "integer constant out of range", /* 252 */
311 1.1 cgd "unterminated character constant", /* 253 */
312 1.1 cgd "newline in string or char constant", /* 254 */
313 1.207 rillig "undefined or invalid '#' directive", /* 255 */
314 1.1 cgd "unterminated comment", /* 256 */
315 1.1 cgd "extra characters in lint comment", /* 257 */
316 1.1 cgd "unterminated string constant", /* 258 */
317 1.206 rillig "argument %d is converted from '%s' to '%s' due to prototype", /* 259 */
318 1.168 rillig "previous declaration of '%s'", /* 260 */
319 1.168 rillig "previous definition of '%s'", /* 261 */
320 1.1 cgd "\\\" inside character constants undefined in traditional C", /* 262 */
321 1.1 cgd "\\? undefined in traditional C", /* 263 */
322 1.1 cgd "\\v undefined in traditional C", /* 264 */
323 1.151 rillig "%s does not support 'long long'", /* 265 */
324 1.1 cgd "'long double' is illegal in traditional C", /* 266 */
325 1.183 rillig "shift amount %u equals bit-size of '%s'", /* 267 */
326 1.168 rillig "variable '%s' declared inline", /* 268 */
327 1.208 rillig "parameter '%s' declared inline", /* 269 */
328 1.1 cgd "function prototypes are illegal in traditional C", /* 270 */
329 1.138 rillig "switch expression must be of type 'int' in traditional C", /* 271 */
330 1.1 cgd "empty translation unit", /* 272 */
331 1.217 rillig "bit-field type '%s' invalid in C90 or later", /* 273 */
332 1.217 rillig "C90 or later forbid comparison of %s with %s", /* 274 */
333 1.72 rillig "cast discards 'const' from type '%s'", /* 275 */
334 1.176 rillig "'__%s__' is illegal for type '%s'", /* 276 */
335 1.81 rillig "initialization of '%s' with '%s'", /* 277 */
336 1.1 cgd "combination of '%s' and '%s', arg #%d", /* 278 */
337 1.1 cgd "combination of '%s' and '%s' in return", /* 279 */
338 1.176 rillig "comment /* %s */ must be outside function", /* 280 */
339 1.176 rillig "duplicate comment /* %s */", /* 281 */
340 1.176 rillig "comment /* %s */ must precede function definition", /* 282 */
341 1.215 rillig "parameter number mismatch in comment /* %s */", /* 283 */
342 1.1 cgd "fallthrough on default statement", /* 284 */
343 1.1 cgd "prototype declaration", /* 285 */
344 1.1 cgd "function definition is not a prototype", /* 286 */
345 1.1 cgd "function declaration is not a prototype", /* 287 */
346 1.1 cgd "dubious use of /* VARARGS */ with /* %s */", /* 288 */
347 1.207 rillig "/* PRINTFLIKE */ and /* SCANFLIKE */ cannot be combined", /* 289 */
348 1.176 rillig "static function '%s' declared but not defined", /* 290 */
349 1.1 cgd "invalid multibyte character", /* 291 */
350 1.1 cgd "cannot concatenate wide and regular string literals", /* 292 */
351 1.215 rillig "parameter %d must be 'char *' for PRINTFLIKE/SCANFLIKE", /* 293 */
352 1.1 cgd "multi-character character constant", /* 294 */
353 1.1 cgd "conversion of '%s' to '%s' is out of range, arg #%d", /* 295 */
354 1.1 cgd "conversion of negative constant to unsigned type, arg #%d", /* 296 */
355 1.1 cgd "conversion to '%s' may sign-extend incorrectly, arg #%d", /* 297 */
356 1.29 christos "conversion from '%s' to '%s' may lose accuracy, arg #%d", /* 298 */
357 1.184 rillig "prototype does not match old-style definition, arg #%d", /* 299 */
358 1.184 rillig "old-style definition", /* 300 */
359 1.1 cgd "array of incomplete type", /* 301 */
360 1.176 rillig "'%s' returns pointer to automatic object", /* 302 */
361 1.217 rillig "conversion of %s to %s requires a cast", /* 303 */
362 1.217 rillig "conversion of %s to %s requires a cast, arg #%d", /* 304 */
363 1.217 rillig "conversion of %s to %s requires a cast, op %s", /* 305 */
364 1.176 rillig "constant truncated by conversion, op '%s'", /* 306 */
365 1.168 rillig "static variable '%s' set but not used", /* 307 */
366 1.62 rillig "invalid type for _Complex", /* 308 */
367 1.117 rillig "extra bits set to 0 in conversion of '%s' to '%s', op '%s'", /* 309 */
368 1.215 rillig "symbol renaming can't be used on function parameters", /* 310 */
369 1.9 cgd "symbol renaming can't be used on automatic variables", /* 311 */
370 1.207 rillig "%s does not support '//' comments", /* 312 */
371 1.153 rillig "struct or union member name in initializer is a C99 feature",/* 313 */
372 1.168 rillig "", /* never used */ /* 314 */
373 1.20 christos "GCC style struct or union member name in initializer", /* 315 */
374 1.45 christos "__FUNCTION__/__PRETTY_FUNCTION__ is a GCC extension", /* 316 */
375 1.153 rillig "__func__ is a C99 feature", /* 317 */
376 1.32 christos "variable array dimension is a C99/GCC extension", /* 318 */
377 1.153 rillig "compound literals are a C99/GCC extension", /* 319 */
378 1.207 rillig "'({ ... })' is a GCC extension", /* 320 */
379 1.153 rillig "array initializer with designators is a C99 feature", /* 321 */
380 1.218 rillig "zero sized array requires C99 or later", /* 322 */
381 1.37 dsl "continue in 'do ... while (0)' loop", /* 323 */
382 1.176 rillig "suggest cast from '%s' to '%s' on op '%s' to avoid overflow", /* 324 */
383 1.58 rillig "variable declaration in for loop", /* 325 */
384 1.176 rillig "attribute '%s' ignored for '%s'", /* 326 */
385 1.89 rillig "declarations after statements is a C99 feature", /* 327 */
386 1.134 rillig "union cast is a GCC extension", /* 328 */
387 1.51 christos "type '%s' is not a member of '%s'", /* 329 */
388 1.66 rillig "operand of '%s' must be bool, not '%s'", /* 330 */
389 1.66 rillig "left operand of '%s' must be bool, not '%s'", /* 331 */
390 1.66 rillig "right operand of '%s' must be bool, not '%s'", /* 332 */
391 1.66 rillig "controlling expression must be bool, not '%s'", /* 333 */
392 1.215 rillig "parameter %d expects '%s', gets passed '%s'", /* 334 */
393 1.66 rillig "operand of '%s' must not be bool", /* 335 */
394 1.66 rillig "left operand of '%s' must not be bool", /* 336 */
395 1.66 rillig "right operand of '%s' must not be bool", /* 337 */
396 1.79 rillig "option '%c' should be handled in the switch", /* 338 */
397 1.79 rillig "option '%c' should be listed in the options string", /* 339 */
398 1.126 rillig "initialization with '[a...b]' is a GCC extension", /* 340 */
399 1.102 rillig "argument to '%s' must be 'unsigned char' or EOF, not '%s'", /* 341 */
400 1.102 rillig "argument to '%s' must be cast to 'unsigned char', not to '%s'", /* 342 */
401 1.218 rillig "static array size requires C11 or later", /* 343 */
402 1.119 rillig "bit-field of type plain 'int' has implementation-defined signedness", /* 344 */
403 1.120 rillig "generic selection requires C11 or later", /* 345 */
404 1.135 rillig "call to '%s' effectively discards 'const' from argument", /* 346 */
405 1.145 rillig "redeclaration of '%s' with type '%s', expected '%s'", /* 347 */
406 1.147 rillig "maximum value %d of '%s' does not match maximum array index %d", /* 348 */
407 1.165 christos "non type argument to alignof is a GCC extension", /* 349 */
408 1.186 rillig "'_Atomic' requires C11 or later", /* 350 */
409 1.195 rillig "missing%s header declaration for '%s'", /* 351 */
410 1.191 rillig "nested 'extern' declaration of '%s'", /* 352 */
411 1.204 rillig "empty initializer braces require C23 or later", /* 353 */
412 1.216 rillig "'_Static_assert' requires C11 or later", /* 354 */
413 1.216 rillig "'_Static_assert' without message requires C23 or later", /* 355 */
414 1.1 cgd };
415 1.1 cgd
416 1.220 rillig static bool is_suppressed[sizeof(msgs) / sizeof(msgs[0])];
417 1.178 rillig
418 1.104 rillig static struct include_level {
419 1.104 rillig const char *filename;
420 1.104 rillig int lineno;
421 1.104 rillig struct include_level *by;
422 1.104 rillig } *includes;
423 1.104 rillig
424 1.178 rillig void
425 1.194 rillig suppress_messages(const char *p)
426 1.178 rillig {
427 1.194 rillig char *end;
428 1.194 rillig
429 1.194 rillig for (; ch_isdigit(*p); p = end + 1) {
430 1.194 rillig unsigned long id = strtoul(p, &end, 10);
431 1.194 rillig if ((*end != '\0' && *end != ',') ||
432 1.194 rillig id >= sizeof(msgs) / sizeof(msgs[0]) ||
433 1.194 rillig msgs[id][0] == '\0')
434 1.194 rillig break;
435 1.178 rillig
436 1.179 rillig is_suppressed[id] = true;
437 1.194 rillig
438 1.194 rillig if (*end == '\0')
439 1.194 rillig return;
440 1.178 rillig }
441 1.199 rillig errx(1, "invalid message ID '%.*s'", (int)strcspn(p, ","), p);
442 1.178 rillig }
443 1.104 rillig
444 1.104 rillig void
445 1.105 rillig update_location(const char *filename, int lineno, bool is_begin, bool is_end)
446 1.104 rillig {
447 1.104 rillig struct include_level *top;
448 1.104 rillig
449 1.104 rillig top = includes;
450 1.104 rillig if (is_begin && top != NULL)
451 1.104 rillig top->lineno = curr_pos.p_line;
452 1.104 rillig
453 1.104 rillig if (top == NULL || is_begin) {
454 1.104 rillig top = xmalloc(sizeof(*top));
455 1.104 rillig top->filename = filename;
456 1.104 rillig top->lineno = lineno;
457 1.104 rillig top->by = includes;
458 1.104 rillig includes = top;
459 1.104 rillig } else {
460 1.109 rillig if (is_end) {
461 1.104 rillig includes = top->by;
462 1.104 rillig free(top);
463 1.104 rillig top = includes;
464 1.104 rillig }
465 1.123 rillig if (top != NULL) {
466 1.123 rillig top->filename = filename;
467 1.123 rillig top->lineno = lineno;
468 1.123 rillig }
469 1.104 rillig }
470 1.104 rillig }
471 1.104 rillig
472 1.104 rillig static void
473 1.104 rillig print_stack_trace(void)
474 1.104 rillig {
475 1.105 rillig const struct include_level *top;
476 1.104 rillig
477 1.104 rillig if ((top = includes) == NULL)
478 1.104 rillig return;
479 1.105 rillig /*
480 1.105 rillig * Skip the innermost include level since it is already listed in the
481 1.105 rillig * diagnostic itself. Furthermore, its lineno is the line number of
482 1.105 rillig * the last '#' line, not the current line.
483 1.105 rillig */
484 1.104 rillig for (top = top->by; top != NULL; top = top->by)
485 1.104 rillig printf("\tincluded from %s(%d)\n", top->filename, top->lineno);
486 1.104 rillig }
487 1.104 rillig
488 1.1 cgd /*
489 1.56 rillig * If Fflag is not set, lbasename() returns a pointer to the last
490 1.1 cgd * component of the path, otherwise it returns the argument.
491 1.1 cgd */
492 1.1 cgd static const char *
493 1.18 tv lbasename(const char *path)
494 1.1 cgd {
495 1.1 cgd
496 1.1 cgd if (Fflag)
497 1.57 rillig return path;
498 1.1 cgd
499 1.188 rillig const char *base = path;
500 1.188 rillig for (const char *p = path; *p != '\0'; p++)
501 1.188 rillig if (*p == '/')
502 1.188 rillig base = p + 1;
503 1.188 rillig return base;
504 1.1 cgd }
505 1.1 cgd
506 1.210 rillig static FILE *
507 1.210 rillig output_channel(void)
508 1.210 rillig {
509 1.210 rillig return yflag ? stderr : stdout;
510 1.210 rillig }
511 1.210 rillig
512 1.3 jpo static void
513 1.116 rillig verror_at(int msgid, const pos_t *pos, va_list ap)
514 1.3 jpo {
515 1.3 jpo
516 1.179 rillig if (is_suppressed[msgid])
517 1.12 christos return;
518 1.12 christos
519 1.210 rillig FILE *out = output_channel();
520 1.210 rillig (void)fprintf(out, "%s(%d): error: ",
521 1.210 rillig lbasename(pos->p_file), pos->p_line);
522 1.210 rillig (void)vfprintf(out, msgs[msgid], ap);
523 1.210 rillig (void)fprintf(out, " [%d]\n", msgid);
524 1.205 rillig seen_error = true;
525 1.104 rillig print_stack_trace();
526 1.3 jpo }
527 1.3 jpo
528 1.3 jpo static void
529 1.116 rillig vwarning_at(int msgid, const pos_t *pos, va_list ap)
530 1.3 jpo {
531 1.3 jpo
532 1.179 rillig if (is_suppressed[msgid])
533 1.12 christos return;
534 1.12 christos
535 1.132 rillig debug_step("%s: lwarn=%d msgid=%d", __func__, lwarn, msgid);
536 1.115 rillig if (lwarn == LWARN_NONE || lwarn == msgid)
537 1.3 jpo /* this warning is suppressed by a LINTED comment */
538 1.3 jpo return;
539 1.3 jpo
540 1.210 rillig FILE *out = output_channel();
541 1.210 rillig (void)fprintf(out, "%s(%d): warning: ",
542 1.210 rillig lbasename(pos->p_file), pos->p_line);
543 1.210 rillig (void)vfprintf(out, msgs[msgid], ap);
544 1.210 rillig (void)fprintf(out, " [%d]\n", msgid);
545 1.205 rillig seen_warning = true;
546 1.104 rillig print_stack_trace();
547 1.3 jpo }
548 1.3 jpo
549 1.113 rillig static void
550 1.116 rillig vmessage_at(int msgid, const pos_t *pos, va_list ap)
551 1.113 rillig {
552 1.113 rillig
553 1.179 rillig if (is_suppressed[msgid])
554 1.113 rillig return;
555 1.113 rillig
556 1.210 rillig FILE *out = output_channel();
557 1.210 rillig (void)fprintf(out, "%s(%d): ",
558 1.210 rillig lbasename(pos->p_file), pos->p_line);
559 1.210 rillig (void)vfprintf(out, msgs[msgid], ap);
560 1.210 rillig (void)fprintf(out, " [%d]\n", msgid);
561 1.113 rillig print_stack_trace();
562 1.113 rillig }
563 1.113 rillig
564 1.113 rillig void
565 1.116 rillig (error_at)(int msgid, const pos_t *pos, ...)
566 1.113 rillig {
567 1.198 rillig va_list ap;
568 1.113 rillig
569 1.113 rillig va_start(ap, pos);
570 1.115 rillig verror_at(msgid, pos, ap);
571 1.113 rillig va_end(ap);
572 1.113 rillig }
573 1.113 rillig
574 1.3 jpo void
575 1.115 rillig (error)(int msgid, ...)
576 1.1 cgd {
577 1.198 rillig va_list ap;
578 1.1 cgd
579 1.115 rillig va_start(ap, msgid);
580 1.116 rillig verror_at(msgid, &curr_pos, ap);
581 1.1 cgd va_end(ap);
582 1.1 cgd }
583 1.1 cgd
584 1.3 jpo void
585 1.59 rillig assert_failed(const char *file, int line, const char *func, const char *cond)
586 1.59 rillig {
587 1.59 rillig
588 1.167 rillig /*
589 1.219 rillig * After encountering a parse error in the grammar, lint often does not
590 1.219 rillig * properly clean up its data structures, especially in 'dcs', the
591 1.219 rillig * stack of declaration levels. This often leads to assertion
592 1.219 rillig * failures. These cases are not interesting though, as the purpose of
593 1.219 rillig * lint is to check syntactically valid code. In such a case, exit
594 1.219 rillig * gracefully. This allows a fuzzer like afl to focus on more
595 1.167 rillig * interesting cases instead of reporting nonsense translation units
596 1.167 rillig * like 'f=({e:;}' or 'v(const(char););e(v){'.
597 1.167 rillig */
598 1.167 rillig if (sytxerr > 0)
599 1.167 rillig norecover();
600 1.167 rillig
601 1.144 rillig (void)fflush(stdout);
602 1.59 rillig (void)fprintf(stderr,
603 1.59 rillig "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
604 1.210 rillig cond, func, file, line,
605 1.210 rillig lbasename(curr_pos.p_file), curr_pos.p_line);
606 1.104 rillig print_stack_trace();
607 1.156 rillig (void)fflush(stdout);
608 1.59 rillig abort();
609 1.59 rillig }
610 1.59 rillig
611 1.59 rillig void
612 1.116 rillig (warning_at)(int msgid, const pos_t *pos, ...)
613 1.113 rillig {
614 1.198 rillig va_list ap;
615 1.113 rillig
616 1.113 rillig va_start(ap, pos);
617 1.115 rillig vwarning_at(msgid, pos, ap);
618 1.113 rillig va_end(ap);
619 1.113 rillig }
620 1.113 rillig
621 1.113 rillig void
622 1.115 rillig (warning)(int msgid, ...)
623 1.1 cgd {
624 1.198 rillig va_list ap;
625 1.3 jpo
626 1.115 rillig va_start(ap, msgid);
627 1.116 rillig vwarning_at(msgid, &curr_pos, ap);
628 1.113 rillig va_end(ap);
629 1.113 rillig }
630 1.113 rillig
631 1.113 rillig void
632 1.116 rillig (message_at)(int msgid, const pos_t *pos, ...)
633 1.113 rillig {
634 1.113 rillig va_list ap;
635 1.113 rillig
636 1.113 rillig va_start(ap, pos);
637 1.115 rillig vmessage_at(msgid, pos, ap);
638 1.3 jpo va_end(ap);
639 1.3 jpo }
640 1.3 jpo
641 1.63 rillig void
642 1.115 rillig (c99ism)(int msgid, ...)
643 1.25 perry {
644 1.198 rillig va_list ap;
645 1.164 rillig
646 1.164 rillig if (allow_c99)
647 1.164 rillig return;
648 1.25 perry
649 1.115 rillig va_start(ap, msgid);
650 1.164 rillig int severity = (!allow_gcc ? 1 : 0) + (!allow_trad ? 1 : 0);
651 1.161 rillig if (severity == 2)
652 1.116 rillig verror_at(msgid, &curr_pos, ap);
653 1.161 rillig if (severity == 1)
654 1.116 rillig vwarning_at(msgid, &curr_pos, ap);
655 1.25 perry va_end(ap);
656 1.1 cgd }
657 1.1 cgd
658 1.108 rillig void
659 1.115 rillig (c11ism)(int msgid, ...)
660 1.108 rillig {
661 1.198 rillig va_list ap;
662 1.108 rillig
663 1.162 rillig /* FIXME: C11 mode has nothing to do with GCC mode. */
664 1.163 rillig if (allow_c11 || allow_gcc)
665 1.110 rillig return;
666 1.115 rillig va_start(ap, msgid);
667 1.116 rillig verror_at(msgid, &curr_pos, ap);
668 1.108 rillig va_end(ap);
669 1.108 rillig }
670 1.108 rillig
671 1.204 rillig void
672 1.204 rillig (c23ism)(int msgid, ...)
673 1.204 rillig {
674 1.204 rillig va_list ap;
675 1.204 rillig
676 1.204 rillig if (allow_c23)
677 1.204 rillig return;
678 1.204 rillig va_start(ap, msgid);
679 1.204 rillig verror_at(msgid, &curr_pos, ap);
680 1.204 rillig va_end(ap);
681 1.204 rillig }
682 1.204 rillig
683 1.162 rillig bool
684 1.115 rillig (gnuism)(int msgid, ...)
685 1.1 cgd {
686 1.198 rillig va_list ap;
687 1.164 rillig int severity = (!allow_gcc ? 1 : 0) +
688 1.164 rillig (!allow_trad && !allow_c99 ? 1 : 0);
689 1.1 cgd
690 1.115 rillig va_start(ap, msgid);
691 1.161 rillig if (severity == 2)
692 1.116 rillig verror_at(msgid, &curr_pos, ap);
693 1.161 rillig if (severity == 1)
694 1.116 rillig vwarning_at(msgid, &curr_pos, ap);
695 1.1 cgd va_end(ap);
696 1.162 rillig return severity > 0;
697 1.1 cgd }
698 1.181 rillig
699 1.181 rillig
700 1.181 rillig static const char *queries[] = {
701 1.181 rillig "", /* unused, to make queries 1-based */
702 1.181 rillig "implicit conversion from floating point '%s' to integer '%s'", /* Q1 */
703 1.181 rillig "cast from floating point '%s' to integer '%s'", /* Q2 */
704 1.181 rillig "implicit conversion changes sign from '%s' to '%s'", /* Q3 */
705 1.181 rillig "usual arithmetic conversion for '%s' from '%s' to '%s'", /* Q4 */
706 1.181 rillig "pointer addition has integer on the left-hand side", /* Q5 */
707 1.181 rillig "no-op cast from '%s' to '%s'", /* Q6 */
708 1.181 rillig "redundant cast from '%s' to '%s' before assignment", /* Q7 */
709 1.192 rillig "octal number '%.*s'", /* Q8 */
710 1.193 rillig "parenthesized return value", /* Q9 */
711 1.196 rillig "chained assignment with '%s' and '%s'", /* Q10 */
712 1.197 rillig "static variable '%s' in function", /* Q11 */
713 1.200 rillig "comma operator with types '%s' and '%s'", /* Q12 */
714 1.201 rillig "redundant 'extern' in function declaration of '%s'", /* Q13 */
715 1.202 rillig "comparison '%s' of 'char' with plain integer %d", /* Q14 */
716 1.203 rillig "implicit conversion from integer 0 to pointer '%s'", /* Q15 */
717 1.221 rillig "'%s' was declared 'static', now non-'static'", /* Q16 */
718 1.181 rillig };
719 1.181 rillig
720 1.181 rillig bool any_query_enabled; /* for optimizing non-query scenarios */
721 1.221 rillig bool is_query_enabled[sizeof(queries) / sizeof(queries[0])];
722 1.181 rillig
723 1.181 rillig void
724 1.181 rillig (query_message)(int query_id, ...)
725 1.181 rillig {
726 1.181 rillig
727 1.181 rillig if (!is_query_enabled[query_id])
728 1.181 rillig return;
729 1.181 rillig
730 1.210 rillig va_list ap;
731 1.210 rillig FILE *out = output_channel();
732 1.210 rillig (void)fprintf(out, "%s(%d): ",
733 1.210 rillig lbasename(curr_pos.p_file), curr_pos.p_line);
734 1.181 rillig va_start(ap, query_id);
735 1.210 rillig (void)vfprintf(out, queries[query_id], ap);
736 1.181 rillig va_end(ap);
737 1.210 rillig (void)fprintf(out, " [Q%d]\n", query_id);
738 1.181 rillig print_stack_trace();
739 1.181 rillig }
740 1.181 rillig
741 1.181 rillig void
742 1.194 rillig enable_queries(const char *p)
743 1.181 rillig {
744 1.194 rillig char *end;
745 1.181 rillig
746 1.194 rillig for (; ch_isdigit(*p); p = end + 1) {
747 1.194 rillig unsigned long id = strtoul(p, &end, 10);
748 1.194 rillig if ((*end != '\0' && *end != ',') ||
749 1.194 rillig id >= sizeof(queries) / sizeof(queries[0]) ||
750 1.194 rillig queries[id][0] == '\0')
751 1.194 rillig break;
752 1.181 rillig
753 1.181 rillig any_query_enabled = true;
754 1.181 rillig is_query_enabled[id] = true;
755 1.181 rillig
756 1.194 rillig if (*end == '\0')
757 1.194 rillig return;
758 1.181 rillig }
759 1.199 rillig errx(1, "invalid query ID '%.*s'", (int)strcspn(p, ","), p);
760 1.181 rillig }
761