err.c revision 1.144 1 /* $NetBSD: err.c,v 1.144 2021/09/05 16:15:05 rillig Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for
18 * The NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #if HAVE_NBTOOL_CONFIG_H
35 #include "nbtool_config.h"
36 #endif
37
38 #include <sys/cdefs.h>
39 #if defined(__RCSID) && !defined(lint)
40 __RCSID("$NetBSD: err.c,v 1.144 2021/09/05 16:15:05 rillig Exp $");
41 #endif
42
43 #include <sys/types.h>
44 #include <stdarg.h>
45 #include <stdlib.h>
46
47 #include "lint1.h"
48
49 /* number of errors found */
50 int nerr;
51
52 /* number of syntax errors */
53 int sytxerr;
54
55
56 const char *const msgs[] = {
57 "empty declaration", /* 0 */
58 "old style declaration; add 'int'", /* 1 */
59 "empty declaration", /* 2 */
60 "'%s' declared in argument declaration list", /* 3 */
61 "illegal type combination", /* 4 */
62 "modifying typedef with '%s'; only qualifiers allowed", /* 5 */
63 "use 'double' instead of 'long float'", /* 6 */
64 "only one storage class allowed", /* 7 */
65 "illegal storage class", /* 8 */
66 "only register valid as formal parameter storage class", /* 9 */
67 "duplicate '%s'", /* 10 */
68 "bit-field initializer out of range", /* 11 */
69 "compiler takes size of function", /* 12 */
70 "incomplete enum type: %s", /* 13 */
71 "compiler takes alignment of function", /* 14 */
72 "function returns illegal type", /* 15 */
73 "array of function is illegal", /* 16 */
74 "null dimension", /* 17 */
75 "illegal use of 'void'", /* 18 */
76 "void type for '%s'", /* 19 */
77 "negative array dimension (%d)", /* 20 */
78 "redeclaration of formal parameter %s", /* 21 */
79 "incomplete or misplaced function definition", /* 22 */
80 "undefined label '%s'", /* 23 */
81 "cannot initialize function: %s", /* 24 */
82 "cannot initialize typedef: %s", /* 25 */
83 "cannot initialize extern declaration: %s", /* 26 */
84 "redeclaration of %s", /* 27 */
85 "redefinition of %s", /* 28 */
86 "previously declared extern, becomes static: %s", /* 29 */
87 "redeclaration of %s; ANSI C requires static", /* 30 */
88 "'%s' has incomplete type '%s'", /* 31 */
89 "argument type defaults to 'int': %s", /* 32 */
90 "duplicate member name: %s", /* 33 */
91 "nonportable bit-field type '%s'", /* 34 */
92 "illegal bit-field type '%s'", /* 35 */
93 "illegal bit-field size: %d", /* 36 */
94 "zero size bit-field", /* 37 */
95 "function illegal in structure or union", /* 38 */
96 "zero sized array in struct is a C99 extension: %s", /* 39 */
97 "unknown size: %s", /* 40 */
98 "illegal use of bit-field", /* 41 */
99 "forward reference to enum type", /* 42 */
100 "redefinition hides earlier one: %s", /* 43 */
101 "declaration introduces new type in ANSI C: %s %s", /* 44 */
102 "base type is really '%s %s'", /* 45 */
103 "%s tag '%s' redeclared as %s", /* 46 */
104 "zero sized %s is a C9X feature", /* 47 */
105 "overflow in enumeration values: %s", /* 48 */
106 "anonymous struct/union members is a C9X feature", /* 49 */
107 "a function is declared as an argument: %s", /* 50 */
108 "parameter mismatch: %d declared, %d defined", /* 51 */
109 "cannot initialize parameter: %s", /* 52 */
110 "declared argument %s is missing", /* 53 */
111 "trailing ',' prohibited in enum declaration", /* 54 */
112 "integral constant expression expected", /* 55 */
113 "integral constant too large", /* 56 */
114 "enumeration constant hides parameter: %s", /* 57 */
115 "type does not match prototype: %s", /* 58 */
116 "formal parameter lacks name: param #%d", /* 59 */
117 "void must be sole parameter", /* 60 */
118 "void parameter cannot have name: %s", /* 61 */
119 "function prototype parameters must have types", /* 62 */
120 "prototype does not match old-style definition", /* 63 */
121 "()-less function definition", /* 64 */
122 "%s has no named members", /* 65 */
123 "", /* 66 */
124 "cannot return incomplete type", /* 67 */
125 "typedef already qualified with '%s'", /* 68 */
126 "inappropriate qualifiers with 'void'", /* 69 */
127 "%soperand of '%s' is unsigned in ANSI C", /* 70 */
128 "too many characters in character constant", /* 71 */
129 "typedef declares no type name", /* 72 */
130 "empty character constant", /* 73 */
131 "no hex digits follow \\x", /* 74 */
132 "overflow in hex escape", /* 75 */
133 "character escape does not fit in character", /* 76 */
134 "bad octal digit %c", /* 77 */
135 "", /* unused */ /* 78 */
136 "dubious escape \\%c", /* 79 */
137 "dubious escape \\%o", /* 80 */
138 "\\a undefined in traditional C", /* 81 */
139 "\\x undefined in traditional C", /* 82 */
140 "storage class after type is obsolescent", /* 83 */
141 "ANSI C requires formal parameter before '...'", /* 84 */
142 "dubious tag declaration: %s %s", /* 85 */
143 "automatic hides external declaration: %s", /* 86 */
144 "static hides external declaration: %s", /* 87 */
145 "typedef hides external declaration: %s", /* 88 */
146 "typedef redeclared: %s", /* 89 */
147 "inconsistent redeclaration of extern: %s", /* 90 */
148 "declaration hides parameter: %s", /* 91 */
149 "inconsistent redeclaration of static: %s", /* 92 */
150 "dubious static function at block level: %s", /* 93 */
151 "function has illegal storage class: %s", /* 94 */
152 "declaration hides earlier one: %s", /* 95 */
153 "cannot dereference non-pointer type", /* 96 */
154 "suffix U is illegal in traditional C", /* 97 */
155 "suffixes F and L are illegal in traditional C", /* 98 */
156 "'%s' undefined", /* 99 */
157 "unary + is illegal in traditional C", /* 100 */
158 "type '%s' does not have member '%s'", /* 101 */
159 "illegal member use: %s", /* 102 */
160 "left operand of '.' must be struct or union, not '%s'", /* 103 */
161 "left operand of '->' must be pointer to struct or union, not '%s'", /* 104 */
162 "non-unique member requires struct/union %s", /* 105 */
163 "left operand of '->' must be pointer", /* 106 */
164 "operands of '%s' have incompatible types (%s != %s)", /* 107 */
165 "operand of '%s' has invalid type (%s)", /* 108 */
166 "void type illegal in expression", /* 109 */
167 "pointer to function is not allowed here", /* 110 */
168 "unacceptable operand of '%s'", /* 111 */
169 "cannot take address of bit-field", /* 112 */
170 "cannot take address of register %s", /* 113 */
171 "%soperand of '%s' must be lvalue", /* 114 */
172 "%soperand of '%s' must be modifiable lvalue", /* 115 */
173 "illegal pointer subtraction", /* 116 */
174 "bitwise '%s' on signed value possibly nonportable", /* 117 */
175 "semantics of '%s' change in ANSI C; use explicit cast", /* 118 */
176 "conversion of '%s' to '%s' is out of range", /* 119 */
177 "bitwise '%s' on signed value nonportable", /* 120 */
178 "negative shift", /* 121 */
179 "shift amount %llu is greater than bit-size %llu of '%s'", /* 122 */
180 "illegal combination of %s (%s) and %s (%s), op %s", /* 123 */
181 "illegal combination of '%s' and '%s', op '%s'", /* 124 */
182 "ANSI C forbids ordered comparisons of pointers to functions",/* 125 */
183 "incompatible types '%s' and '%s' in conditional", /* 126 */
184 "'&' before array or function: ignored", /* 127 */
185 "operands have incompatible pointer types, op %s (%s != %s)", /* 128 */
186 "expression has null effect", /* 129 */
187 "enum type mismatch: '%s' '%s' '%s'", /* 130 */
188 "conversion to '%s' may sign-extend incorrectly", /* 131 */
189 "conversion from '%s' to '%s' may lose accuracy", /* 132 */
190 "conversion of pointer to '%s' loses bits", /* 133 */
191 "conversion of pointer to '%s' may lose bits", /* 134 */
192 "converting '%s' to '%s' may cause alignment problem", /* 135 */
193 "cannot do pointer arithmetic on operand of unknown size", /* 136 */
194 "use of incomplete enum type, op %s", /* 137 */
195 "unknown operand size, op %s", /* 138 */
196 "division by 0", /* 139 */
197 "modulus by 0", /* 140 */
198 "integer overflow detected, op '%s'", /* 141 */
199 "floating point overflow detected, op %s", /* 142 */
200 "cannot take size/alignment of incomplete type", /* 143 */
201 "cannot take size/alignment of function", /* 144 */
202 "cannot take size/alignment of bit-field", /* 145 */
203 "cannot take size/alignment of void", /* 146 */
204 "invalid cast from '%s' to '%s'", /* 147 */
205 "improper cast of void expression", /* 148 */
206 "illegal function (type %s)", /* 149 */
207 "argument mismatch: %d arg%s passed, %d expected", /* 150 */
208 "void expressions may not be arguments, arg #%d", /* 151 */
209 "argument cannot have unknown size, arg #%d", /* 152 */
210 "converting '%s' to incompatible '%s' for argument %d", /* 153 */
211 "illegal combination of %s (%s) and %s (%s), arg #%d", /* 154 */
212 "passing '%s' to incompatible '%s', arg #%d", /* 155 */
213 "enum type mismatch, arg #%d (%s != %s)", /* 156 */
214 "ANSI C treats constant as unsigned", /* 157 */
215 "%s may be used before set", /* 158 */
216 "assignment in conditional context", /* 159 */
217 "operator '==' found where '=' was expected", /* 160 */
218 "constant in conditional context", /* 161 */
219 "comparison of %s with %s, op %s", /* 162 */
220 "a cast does not yield an lvalue", /* 163 */
221 "assignment of negative constant to unsigned type", /* 164 */
222 "constant truncated by assignment", /* 165 */
223 "precision lost in bit-field assignment", /* 166 */
224 "array subscript cannot be negative: %ld", /* 167 */
225 "array subscript cannot be > %d: %ld", /* 168 */
226 "precedence confusion possible: parenthesize!", /* 169 */
227 "first operand must have scalar type, op ? :", /* 170 */
228 "cannot assign to '%s' from '%s'", /* 171 */
229 "too many struct/union initializers", /* 172 */
230 "too many array initializers, expected %d", /* 173 */
231 "too many initializers", /* 174 */
232 "initialization of incomplete type '%s'", /* 175 */
233 "", /* no longer used */ /* 176 */
234 "non-constant initializer", /* 177 */
235 "initializer does not fit", /* 178 */
236 "", /* unused since 2021-03-29 */ /* 179 */
237 "bit-field initializer does not fit", /* 180 */
238 "{}-enclosed initializer required", /* 181 */
239 "incompatible pointer types (%s != %s)", /* 182 */
240 "illegal combination of %s (%s) and %s (%s)", /* 183 */
241 "illegal combination of '%s' and '%s'", /* 184 */
242 "cannot initialize '%s' from '%s'", /* 185 */
243 "bit-field initialization is illegal in traditional C", /* 186 */
244 "non-null byte ignored in string initializer", /* 187 */
245 "no automatic aggregate initialization in traditional C", /* 188 */
246 "", /* no longer used */ /* 189 */
247 "empty array declaration: %s", /* 190 */
248 "'%s' set but not used in function '%s'", /* 191 */
249 "'%s' unused in function '%s'", /* 192 */
250 "statement not reached", /* 193 */
251 "label %s redefined", /* 194 */
252 "case not in switch", /* 195 */
253 "case label affected by conversion", /* 196 */
254 "non-constant case expression", /* 197 */
255 "non-integral case expression", /* 198 */
256 "duplicate case in switch: %ld", /* 199 */
257 "duplicate case in switch: %lu", /* 200 */
258 "default outside switch", /* 201 */
259 "duplicate default in switch", /* 202 */
260 "case label must be of type 'int' in traditional C", /* 203 */
261 "controlling expressions must have scalar type", /* 204 */
262 "switch expression must have integral type", /* 205 */
263 "enumeration value(s) not handled in switch", /* 206 */
264 "loop not entered at top", /* 207 */
265 "break outside loop or switch", /* 208 */
266 "continue outside loop", /* 209 */
267 "enum type mismatch between '%s' and '%s' in initialization", /* 210 */
268 "return value type mismatch (%s) and (%s)", /* 211 */
269 "cannot return incomplete type", /* 212 */
270 "void function %s cannot return value", /* 213 */
271 "function '%s' expects to return value", /* 214 */
272 "function '%s' implicitly declared to return int", /* 215 */
273 "function %s has return (e); and return;", /* 216 */
274 "function %s falls off bottom without returning value", /* 217 */
275 "ANSI C treats constant as unsigned, op %s", /* 218 */
276 "concatenated strings are illegal in traditional C", /* 219 */
277 "fallthrough on case statement", /* 220 */
278 "initialization of unsigned with negative constant", /* 221 */
279 "conversion of negative constant to unsigned type", /* 222 */
280 "end-of-loop code not reached", /* 223 */
281 "cannot recover from previous errors", /* 224 */
282 "static function called but not defined: %s()", /* 225 */
283 "static variable %s unused", /* 226 */
284 "const object %s should have initializer", /* 227 */
285 "function cannot return const or volatile object", /* 228 */
286 "converting '%s' to '%s' is questionable", /* 229 */
287 "nonportable character comparison, op %s", /* 230 */
288 "argument '%s' unused in function '%s'", /* 231 */
289 "label '%s' unused in function '%s'", /* 232 */
290 "struct %s never defined", /* 233 */
291 "union %s never defined", /* 234 */
292 "enum %s never defined", /* 235 */
293 "static function %s unused", /* 236 */
294 "redeclaration of formal parameter %s", /* 237 */
295 "initialization of union is illegal in traditional C", /* 238 */
296 "constant argument to '!'", /* 239 */
297 "assignment of different structures (%s != %s)", /* 240 */
298 "dubious operation on enum, op %s", /* 241 */
299 "combination of '%s' and '%s', op %s", /* 242 */
300 "dubious comparison of enums, op %s", /* 243 */
301 "illegal structure pointer combination", /* 244 */
302 "incompatible structure pointers: '%s' '%s' '%s'", /* 245 */
303 "dubious conversion of enum to '%s'", /* 246 */
304 "pointer cast from '%s' to '%s' may be troublesome", /* 247 */
305 "floating-point constant out of range", /* 248 */
306 "syntax error '%s'", /* 249 */
307 "unknown character \\%o", /* 250 */
308 "malformed integer constant", /* 251 */
309 "integer constant out of range", /* 252 */
310 "unterminated character constant", /* 253 */
311 "newline in string or char constant", /* 254 */
312 "undefined or invalid # directive", /* 255 */
313 "unterminated comment", /* 256 */
314 "extra characters in lint comment", /* 257 */
315 "unterminated string constant", /* 258 */
316 "argument #%d is converted from '%s' to '%s' due to prototype", /* 259 */
317 "previous declaration of %s", /* 260 */
318 "previous definition of %s", /* 261 */
319 "\\\" inside character constants undefined in traditional C", /* 262 */
320 "\\? undefined in traditional C", /* 263 */
321 "\\v undefined in traditional C", /* 264 */
322 "%s C does not support 'long long'", /* 265 */
323 "'long double' is illegal in traditional C", /* 266 */
324 "shift equal to size of object", /* 267 */
325 "variable declared inline: %s", /* 268 */
326 "argument declared inline: %s", /* 269 */
327 "function prototypes are illegal in traditional C", /* 270 */
328 "switch expression must be of type 'int' in traditional C", /* 271 */
329 "empty translation unit", /* 272 */
330 "bit-field type '%s' invalid in ANSI C", /* 273 */
331 "ANSI C forbids comparison of %s with %s", /* 274 */
332 "cast discards 'const' from type '%s'", /* 275 */
333 "__%s__ is illegal for type %s", /* 276 */
334 "initialization of '%s' with '%s'", /* 277 */
335 "combination of '%s' and '%s', arg #%d", /* 278 */
336 "combination of '%s' and '%s' in return", /* 279 */
337 "must be outside function: /* %s */", /* 280 */
338 "duplicate use of /* %s */", /* 281 */
339 "must precede function definition: /* %s */", /* 282 */
340 "argument number mismatch with directive: /* %s */", /* 283 */
341 "fallthrough on default statement", /* 284 */
342 "prototype declaration", /* 285 */
343 "function definition is not a prototype", /* 286 */
344 "function declaration is not a prototype", /* 287 */
345 "dubious use of /* VARARGS */ with /* %s */", /* 288 */
346 "can't be used together: /* PRINTFLIKE */ /* SCANFLIKE */", /* 289 */
347 "static function %s declared but not defined", /* 290 */
348 "invalid multibyte character", /* 291 */
349 "cannot concatenate wide and regular string literals", /* 292 */
350 "argument %d must be 'char *' for PRINTFLIKE/SCANFLIKE", /* 293 */
351 "multi-character character constant", /* 294 */
352 "conversion of '%s' to '%s' is out of range, arg #%d", /* 295 */
353 "conversion of negative constant to unsigned type, arg #%d", /* 296 */
354 "conversion to '%s' may sign-extend incorrectly, arg #%d", /* 297 */
355 "conversion from '%s' to '%s' may lose accuracy, arg #%d", /* 298 */
356 "prototype does not match old style definition, arg #%d", /* 299 */
357 "old style definition", /* 300 */
358 "array of incomplete type", /* 301 */
359 "%s returns pointer to automatic object", /* 302 */
360 "ANSI C forbids conversion of %s to %s", /* 303 */
361 "ANSI C forbids conversion of %s to %s, arg #%d", /* 304 */
362 "ANSI C forbids conversion of %s to %s, op %s", /* 305 */
363 "constant truncated by conversion, op %s", /* 306 */
364 "static variable %s set but not used", /* 307 */
365 "invalid type for _Complex", /* 308 */
366 "extra bits set to 0 in conversion of '%s' to '%s', op '%s'", /* 309 */
367 "symbol renaming can't be used on function arguments", /* 310 */
368 "symbol renaming can't be used on automatic variables", /* 311 */
369 "%s C does not support // comments", /* 312 */
370 "struct or union member name in initializer is a C9X feature",/* 313 */
371 "%s is not a structure or a union", /* 314 */
372 "GCC style struct or union member name in initializer", /* 315 */
373 "__FUNCTION__/__PRETTY_FUNCTION__ is a GCC extension", /* 316 */
374 "__func__ is a C9X feature", /* 317 */
375 "variable array dimension is a C99/GCC extension", /* 318 */
376 "compound literals are a C9X/GCC extension", /* 319 */
377 "({ }) is a GCC extension", /* 320 */
378 "array initializer with designators is a C9X feature", /* 321 */
379 "zero sized array is a C99 extension", /* 322 */
380 "continue in 'do ... while (0)' loop", /* 323 */
381 "suggest cast from '%s' to '%s' on op %s to avoid overflow", /* 324 */
382 "variable declaration in for loop", /* 325 */
383 "%s attribute ignored for %s", /* 326 */
384 "declarations after statements is a C99 feature", /* 327 */
385 "union cast is a GCC extension", /* 328 */
386 "type '%s' is not a member of '%s'", /* 329 */
387 "operand of '%s' must be bool, not '%s'", /* 330 */
388 "left operand of '%s' must be bool, not '%s'", /* 331 */
389 "right operand of '%s' must be bool, not '%s'", /* 332 */
390 "controlling expression must be bool, not '%s'", /* 333 */
391 "argument #%d expects '%s', gets passed '%s'", /* 334 */
392 "operand of '%s' must not be bool", /* 335 */
393 "left operand of '%s' must not be bool", /* 336 */
394 "right operand of '%s' must not be bool", /* 337 */
395 "option '%c' should be handled in the switch", /* 338 */
396 "option '%c' should be listed in the options string", /* 339 */
397 "initialization with '[a...b]' is a GCC extension", /* 340 */
398 "argument to '%s' must be 'unsigned char' or EOF, not '%s'", /* 341 */
399 "argument to '%s' must be cast to 'unsigned char', not to '%s'", /* 342 */
400 "static array size is a C11 extension", /* 343 */
401 "bit-field of type plain 'int' has implementation-defined signedness", /* 344 */
402 "generic selection requires C11 or later", /* 345 */
403 "call to '%s' effectively discards 'const' from argument", /* 346 */
404 };
405
406 static struct include_level {
407 const char *filename;
408 int lineno;
409 struct include_level *by;
410 } *includes;
411
412
413 void
414 update_location(const char *filename, int lineno, bool is_begin, bool is_end)
415 {
416 struct include_level *top;
417
418 top = includes;
419 if (is_begin && top != NULL)
420 top->lineno = curr_pos.p_line;
421
422 if (top == NULL || is_begin) {
423 top = xmalloc(sizeof(*top));
424 top->filename = filename;
425 top->lineno = lineno;
426 top->by = includes;
427 includes = top;
428 } else {
429 if (is_end) {
430 includes = top->by;
431 free(top);
432 top = includes;
433 }
434 if (top != NULL) {
435 top->filename = filename;
436 top->lineno = lineno;
437 }
438 }
439 }
440
441 static void
442 print_stack_trace(void)
443 {
444 const struct include_level *top;
445
446 if ((top = includes) == NULL)
447 return;
448 /*
449 * Skip the innermost include level since it is already listed in the
450 * diagnostic itself. Furthermore, its lineno is the line number of
451 * the last '#' line, not the current line.
452 */
453 for (top = top->by; top != NULL; top = top->by)
454 printf("\tincluded from %s(%d)\n", top->filename, top->lineno);
455 }
456
457 /*
458 * print a list of the messages with their ids
459 */
460 void
461 msglist(void)
462 {
463 size_t i;
464
465 for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++) {
466 if (msgs[i][0] != '\0')
467 printf("%zu\t%s\n", i, msgs[i]);
468 else
469 printf("---\t(no longer used)\n");
470 }
471 }
472
473 /*
474 * If Fflag is not set, lbasename() returns a pointer to the last
475 * component of the path, otherwise it returns the argument.
476 */
477 static const char *
478 lbasename(const char *path)
479 {
480 const char *p, *base, *dir;
481
482 if (Fflag)
483 return path;
484
485 p = base = dir = path;
486 while (*p != '\0') {
487 if (*p++ == '/') {
488 dir = base;
489 base = p;
490 }
491 }
492 return *base != '\0' ? base : dir;
493 }
494
495 static void
496 verror_at(int msgid, const pos_t *pos, va_list ap)
497 {
498 const char *fn;
499
500 if (ERR_ISSET(msgid, &msgset))
501 return;
502
503 fn = lbasename(pos->p_file);
504 (void)printf("%s(%d): error: ", fn, pos->p_line);
505 (void)vprintf(msgs[msgid], ap);
506 (void)printf(" [%d]\n", msgid);
507 nerr++;
508 print_stack_trace();
509 }
510
511 static void
512 vwarning_at(int msgid, const pos_t *pos, va_list ap)
513 {
514 const char *fn;
515
516 if (ERR_ISSET(msgid, &msgset))
517 return;
518
519 debug_step("%s: lwarn=%d msgid=%d", __func__, lwarn, msgid);
520 if (lwarn == LWARN_NONE || lwarn == msgid)
521 /* this warning is suppressed by a LINTED comment */
522 return;
523
524 fn = lbasename(pos->p_file);
525 (void)printf("%s(%d): warning: ", fn, pos->p_line);
526 (void)vprintf(msgs[msgid], ap);
527 (void)printf(" [%d]\n", msgid);
528 if (wflag)
529 nerr++;
530 print_stack_trace();
531 }
532
533 static void
534 vmessage_at(int msgid, const pos_t *pos, va_list ap)
535 {
536 const char *fn;
537
538 if (ERR_ISSET(msgid, &msgset))
539 return;
540
541 fn = lbasename(pos->p_file);
542 (void)printf("%s(%d): ", fn, pos->p_line);
543 (void)vprintf(msgs[msgid], ap);
544 (void)printf(" [%d]\n", msgid);
545 print_stack_trace();
546 }
547
548 void
549 (error_at)(int msgid, const pos_t *pos, ...)
550 {
551 va_list ap;
552
553 va_start(ap, pos);
554 verror_at(msgid, pos, ap);
555 va_end(ap);
556 }
557
558 void
559 (error)(int msgid, ...)
560 {
561 va_list ap;
562
563 va_start(ap, msgid);
564 verror_at(msgid, &curr_pos, ap);
565 va_end(ap);
566 }
567
568 void
569 internal_error(const char *file, int line, const char *msg, ...)
570 {
571 va_list ap;
572 const char *fn;
573
574 fn = lbasename(curr_pos.p_file);
575 (void)fflush(stdout);
576 (void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ",
577 file, line, fn, curr_pos.p_line);
578 va_start(ap, msg);
579 (void)vfprintf(stderr, msg, ap);
580 va_end(ap);
581 (void)fprintf(stderr, "\n");
582 print_stack_trace();
583 abort();
584 }
585
586 void
587 assert_failed(const char *file, int line, const char *func, const char *cond)
588 {
589 const char *fn;
590
591 fn = lbasename(curr_pos.p_file);
592 (void)fflush(stdout);
593 (void)fprintf(stderr,
594 "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
595 cond, func, file, line, fn, curr_pos.p_line);
596 print_stack_trace();
597 abort();
598 }
599
600 void
601 (warning_at)(int msgid, const pos_t *pos, ...)
602 {
603 va_list ap;
604
605 va_start(ap, pos);
606 vwarning_at(msgid, pos, ap);
607 va_end(ap);
608 }
609
610 void
611 (warning)(int msgid, ...)
612 {
613 va_list ap;
614
615 va_start(ap, msgid);
616 vwarning_at(msgid, &curr_pos, ap);
617 va_end(ap);
618 }
619
620 void
621 (message_at)(int msgid, const pos_t *pos, ...)
622 {
623 va_list ap;
624
625 va_start(ap, pos);
626 vmessage_at(msgid, pos, ap);
627 va_end(ap);
628 }
629
630 /*
631 * XXX I think the logic is possibly somewhat screwed up here. The
632 * question is, how do we want to interpret the -s and -S flags going
633 * forward? We need to answer that and then we can fix this to be
634 * "right"... [perry, 2 Nov 2002]
635 */
636 void
637 (c99ism)(int msgid, ...)
638 {
639 va_list ap;
640 bool extensions_ok = Sflag || gflag;
641
642 va_start(ap, msgid);
643 if (sflag && !extensions_ok) {
644 verror_at(msgid, &curr_pos, ap);
645 } else if (sflag || !extensions_ok) {
646 vwarning_at(msgid, &curr_pos, ap);
647 }
648 va_end(ap);
649 }
650
651 void
652 (c11ism)(int msgid, ...)
653 {
654 va_list ap;
655
656 if (c11flag || gflag)
657 return;
658 va_start(ap, msgid);
659 verror_at(msgid, &curr_pos, ap);
660 va_end(ap);
661 }
662
663 void
664 (gnuism)(int msgid, ...)
665 {
666 va_list ap;
667
668 va_start(ap, msgid);
669 if (sflag && !gflag) {
670 verror_at(msgid, &curr_pos, ap);
671 } else if (sflag || !gflag) {
672 vwarning_at(msgid, &curr_pos, ap);
673 }
674 va_end(ap);
675 }
676