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