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