Home | History | Annotate | Line # | Download | only in lint1
err.c revision 1.125
      1 /*	$NetBSD: err.c,v 1.125 2021/07/04 17:01:58 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.125 2021/07/04 17:01:58 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 	"argument '%s' has 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 redeclared",					      /* 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 	"syntax requires ';' after last struct/union member",	      /* 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 	"nonportable character escape",				      /* 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 pointer combination (%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 expression",				      /* 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 	"cannot initialize struct/union with no named member",	      /* 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 pointer combination",				      /* 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 C9X feature",				      /* 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 GNU 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 };
    404 
    405 static struct include_level {
    406 	const char *filename;
    407 	int lineno;
    408 	struct include_level *by;
    409 } *includes;
    410 
    411 
    412 void
    413 update_location(const char *filename, int lineno, bool is_begin, bool is_end)
    414 {
    415 	struct include_level *top;
    416 
    417 	top = includes;
    418 	if (is_begin && top != NULL)
    419 		top->lineno = curr_pos.p_line;
    420 
    421 	if (top == NULL || is_begin) {
    422 		top = xmalloc(sizeof(*top));
    423 		top->filename = filename;
    424 		top->lineno = lineno;
    425 		top->by = includes;
    426 		includes = top;
    427 	} else {
    428 		if (is_end) {
    429 			includes = top->by;
    430 			free(top);
    431 			top = includes;
    432 		}
    433 		if (top != NULL) {
    434 			top->filename = filename;
    435 			top->lineno = lineno;
    436 		}
    437 	}
    438 }
    439 
    440 static void
    441 print_stack_trace(void)
    442 {
    443 	const struct include_level *top;
    444 
    445 	if ((top = includes) == NULL)
    446 		return;
    447 	/*
    448 	 * Skip the innermost include level since it is already listed in the
    449 	 * diagnostic itself.  Furthermore, its lineno is the line number of
    450 	 * the last '#' line, not the current line.
    451 	 */
    452 	for (top = top->by; top != NULL; top = top->by)
    453 		printf("\tincluded from %s(%d)\n", top->filename, top->lineno);
    454 }
    455 
    456 /*
    457  * print a list of the messages with their ids
    458  */
    459 void
    460 msglist(void)
    461 {
    462 	size_t i;
    463 
    464 	for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
    465 		printf("%zu\t%s\n", i, msgs[i]);
    466 }
    467 
    468 /*
    469  * If Fflag is not set, lbasename() returns a pointer to the last
    470  * component of the path, otherwise it returns the argument.
    471  */
    472 static const char *
    473 lbasename(const char *path)
    474 {
    475 	const char *p, *base, *dir;
    476 
    477 	if (Fflag)
    478 		return path;
    479 
    480 	p = base = dir = path;
    481 	while (*p != '\0') {
    482 		if (*p++ == '/') {
    483 			dir = base;
    484 			base = p;
    485 		}
    486 	}
    487 	return *base != '\0' ? base : dir;
    488 }
    489 
    490 static void
    491 verror_at(int msgid, const pos_t *pos, va_list ap)
    492 {
    493 	const	char *fn;
    494 
    495 	if (ERR_ISSET(msgid, &msgset))
    496 		return;
    497 
    498 	fn = lbasename(pos->p_file);
    499 	(void)printf("%s(%d): error: ", fn, pos->p_line);
    500 	(void)vprintf(msgs[msgid], ap);
    501 	(void)printf(" [%d]\n", msgid);
    502 	nerr++;
    503 	print_stack_trace();
    504 }
    505 
    506 static void
    507 vwarning_at(int msgid, const pos_t *pos, va_list ap)
    508 {
    509 	const	char *fn;
    510 
    511 	if (ERR_ISSET(msgid, &msgset))
    512 		return;
    513 
    514 #ifdef DEBUG
    515 	printf("%s: lwarn=%d msgid=%d\n", __func__, lwarn, msgid);
    516 #endif
    517 	if (lwarn == LWARN_NONE || lwarn == msgid)
    518 		/* this warning is suppressed by a LINTED comment */
    519 		return;
    520 
    521 	fn = lbasename(pos->p_file);
    522 	(void)printf("%s(%d): warning: ", fn, pos->p_line);
    523 	(void)vprintf(msgs[msgid], ap);
    524 	(void)printf(" [%d]\n", msgid);
    525 	if (wflag)
    526 		nerr++;
    527 	print_stack_trace();
    528 }
    529 
    530 static void
    531 vmessage_at(int msgid, const pos_t *pos, va_list ap)
    532 {
    533 	const char *fn;
    534 
    535 	if (ERR_ISSET(msgid, &msgset))
    536 		return;
    537 
    538 	fn = lbasename(pos->p_file);
    539 	(void)printf("%s(%d): ", fn, pos->p_line);
    540 	(void)vprintf(msgs[msgid], ap);
    541 	(void)printf(" [%d]\n", msgid);
    542 	print_stack_trace();
    543 }
    544 
    545 void
    546 (error_at)(int msgid, const pos_t *pos, ...)
    547 {
    548 	va_list	ap;
    549 
    550 	va_start(ap, pos);
    551 	verror_at(msgid, pos, ap);
    552 	va_end(ap);
    553 }
    554 
    555 void
    556 (error)(int msgid, ...)
    557 {
    558 	va_list	ap;
    559 
    560 	va_start(ap, msgid);
    561 	verror_at(msgid, &curr_pos, ap);
    562 	va_end(ap);
    563 }
    564 
    565 void
    566 internal_error(const char *file, int line, const char *msg, ...)
    567 {
    568 	va_list	ap;
    569 	const	char *fn;
    570 
    571 	fn = lbasename(curr_pos.p_file);
    572 	(void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ",
    573 	    file, line, fn, curr_pos.p_line);
    574 	va_start(ap, msg);
    575 	(void)vfprintf(stderr, msg, ap);
    576 	va_end(ap);
    577 	(void)fprintf(stderr, "\n");
    578 	print_stack_trace();
    579 	abort();
    580 }
    581 
    582 void
    583 assert_failed(const char *file, int line, const char *func, const char *cond)
    584 {
    585 	const	char *fn;
    586 
    587 	fn = lbasename(curr_pos.p_file);
    588 	(void)fprintf(stderr,
    589 	    "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
    590 	    cond, func, file, line, fn, curr_pos.p_line);
    591 	print_stack_trace();
    592 	abort();
    593 }
    594 
    595 void
    596 (warning_at)(int msgid, const pos_t *pos, ...)
    597 {
    598 	va_list	ap;
    599 
    600 	va_start(ap, pos);
    601 	vwarning_at(msgid, pos, ap);
    602 	va_end(ap);
    603 }
    604 
    605 void
    606 (warning)(int msgid, ...)
    607 {
    608 	va_list	ap;
    609 
    610 	va_start(ap, msgid);
    611 	vwarning_at(msgid, &curr_pos, ap);
    612 	va_end(ap);
    613 }
    614 
    615 void
    616 (message_at)(int msgid, const pos_t *pos, ...)
    617 {
    618 	va_list ap;
    619 
    620 	va_start(ap, pos);
    621 	vmessage_at(msgid, pos, ap);
    622 	va_end(ap);
    623 }
    624 
    625 void
    626 (message)(int msgid, ...)
    627 {
    628 	va_list	ap;
    629 
    630 	va_start(ap, msgid);
    631 	vmessage_at(msgid, &curr_pos, ap);
    632 	va_end(ap);
    633 }
    634 
    635 /*
    636  * XXX I think the logic is possibly somewhat screwed up here. The
    637  * question is, how do we want to interpret the -s and -S flags going
    638  * forward? We need to answer that and then we can fix this to be
    639  * "right"... [perry, 2 Nov 2002]
    640 */
    641 void
    642 (c99ism)(int msgid, ...)
    643 {
    644 	va_list	ap;
    645 	bool extensions_ok = Sflag || gflag;
    646 
    647 	va_start(ap, msgid);
    648 	if (sflag && !extensions_ok) {
    649 		verror_at(msgid, &curr_pos, ap);
    650 	} else if (sflag || !extensions_ok) {
    651 		vwarning_at(msgid, &curr_pos, ap);
    652 	}
    653 	va_end(ap);
    654 }
    655 
    656 void
    657 (c11ism)(int msgid, ...)
    658 {
    659 	va_list	ap;
    660 
    661 	if (c11flag || gflag)
    662 		return;
    663 	va_start(ap, msgid);
    664 	verror_at(msgid, &curr_pos, ap);
    665 	va_end(ap);
    666 }
    667 
    668 void
    669 (gnuism)(int msgid, ...)
    670 {
    671 	va_list	ap;
    672 
    673 	va_start(ap, msgid);
    674 	if (sflag && !gflag) {
    675 		verror_at(msgid, &curr_pos, ap);
    676 	} else if (sflag || !gflag) {
    677 		vwarning_at(msgid, &curr_pos, ap);
    678 	}
    679 	va_end(ap);
    680 }
    681