Home | History | Annotate | Line # | Download | only in lint1
err.c revision 1.144
      1  1.144    rillig /*	$NetBSD: err.c,v 1.144 2021/09/05 16:15:05 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.17        tv #if defined(__RCSID) && !defined(lint)
     40  1.144    rillig __RCSID("$NetBSD: err.c,v 1.144 2021/09/05 16:15:05 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.112    rillig 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.1       cgd 	"incomplete enum type: %s",				      /* 13 */
     71    1.1       cgd 	"compiler takes alignment of function",			      /* 14 */
     72    1.1       cgd 	"function returns illegal type",			      /* 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.1       cgd 	"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.1       cgd 	"cannot initialize function: %s",			      /* 24 */
     82    1.1       cgd 	"cannot initialize typedef: %s",			      /* 25 */
     83    1.1       cgd 	"cannot initialize extern declaration: %s",		      /* 26 */
     84    1.1       cgd 	"redeclaration of %s",					      /* 27 */
     85    1.1       cgd 	"redefinition of %s",					      /* 28 */
     86    1.1       cgd 	"previously declared extern, becomes static: %s",	      /* 29 */
     87    1.1       cgd 	"redeclaration of %s; ANSI C requires static",		      /* 30 */
     88  1.129    rillig 	"'%s' has incomplete type '%s'",			      /* 31 */
     89    1.1       cgd 	"argument type defaults to 'int': %s",			      /* 32 */
     90    1.1       cgd 	"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.30  christos 	"zero sized array in struct is a C99 extension: %s",	      /* 39 */
     97    1.1       cgd 	"unknown size: %s",					      /* 40 */
     98    1.1       cgd 	"illegal use of bit-field",				      /* 41 */
     99    1.1       cgd 	"forward reference to enum type",			      /* 42 */
    100    1.1       cgd 	"redefinition hides earlier one: %s",			      /* 43 */
    101    1.1       cgd 	"declaration introduces new type in ANSI C: %s %s",	      /* 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.31  christos 	"zero sized %s is a C9X feature",			      /* 47 */
    105    1.1       cgd 	"overflow in enumeration values: %s",			      /* 48 */
    106   1.50  christos 	"anonymous struct/union members is a C9X feature",	      /* 49 */
    107    1.1       cgd 	"a function is declared as an argument: %s",		      /* 50 */
    108    1.1       cgd 	"parameter mismatch: %d declared, %d defined",		      /* 51 */
    109    1.1       cgd 	"cannot initialize parameter: %s",			      /* 52 */
    110    1.1       cgd 	"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.1       cgd 	"enumeration constant hides parameter: %s",		      /* 57 */
    115    1.1       cgd 	"type does not match prototype: %s",			      /* 58 */
    116    1.1       cgd 	"formal parameter lacks name: param #%d",		      /* 59 */
    117    1.1       cgd 	"void must be sole parameter",				      /* 60 */
    118    1.1       cgd 	"void parameter cannot have name: %s",			      /* 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.1       cgd 	"%soperand of '%s' is unsigned in ANSI C",		      /* 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.1       cgd 	"automatic hides external declaration: %s",		      /* 86 */
    144    1.1       cgd 	"static hides external declaration: %s",		      /* 87 */
    145    1.1       cgd 	"typedef hides external declaration: %s",		      /* 88 */
    146    1.1       cgd 	"typedef redeclared: %s",				      /* 89 */
    147    1.1       cgd 	"inconsistent redeclaration of extern: %s",		      /* 90 */
    148    1.1       cgd 	"declaration hides parameter: %s",			      /* 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.1       cgd 	"unary + is illegal in traditional C",			      /* 100 */
    158   1.99    rillig 	"type '%s' does not have member '%s'",			      /* 101 */
    159    1.1       cgd 	"illegal member use: %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.52  christos 	"operands of '%s' have incompatible types (%s != %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.49  christos 	"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.42  christos 	"cannot take size/alignment of function",		      /* 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.140    rillig 	"",			/* unused since 2021-03-29 */	      /* 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.1       cgd 	"non-null byte ignored in string initializer",		      /* 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.1       cgd 	"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.11   mycroft 	"nonportable character comparison, op %s",		      /* 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.1       cgd 	"struct %s never defined",				      /* 233 */
    291    1.1       cgd 	"union %s never defined",				      /* 234 */
    292    1.1       cgd 	"enum %s never defined",				      /* 235 */
    293    1.1       cgd 	"static function %s unused",				      /* 236 */
    294    1.1       cgd 	"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.1       cgd 	"previous declaration of %s",				      /* 260 */
    318    1.1       cgd 	"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.5       jpo 	"%s C 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.4       jpo 	"variable declared inline: %s",				      /* 268 */
    326    1.4       jpo 	"argument declared inline: %s",				      /* 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.1       cgd 	"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.14     lukem 	"%s C does not support // comments",			      /* 312 */
    370   1.20  christos 	"struct or union member name in initializer is a C9X feature",/* 313 */
    371   1.20  christos 	"%s is not a structure or a union",			      /* 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.21  christos 	"__func__ is a C9X feature",				      /* 317 */
    375   1.32  christos 	"variable array dimension is a C99/GCC extension",	      /* 318 */
    376   1.23  christos 	"compound literals are a C9X/GCC extension",		      /* 319 */
    377   1.24  christos 	"({ }) is a GCC extension",				      /* 320 */
    378   1.28      yamt 	"array initializer with designators is a C9X 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.1       cgd };
    405    1.1       cgd 
    406  1.104    rillig static struct include_level {
    407  1.104    rillig 	const char *filename;
    408  1.104    rillig 	int lineno;
    409  1.104    rillig 	struct include_level *by;
    410  1.104    rillig } *includes;
    411  1.104    rillig 
    412  1.104    rillig 
    413  1.104    rillig void
    414  1.105    rillig update_location(const char *filename, int lineno, bool is_begin, bool is_end)
    415  1.104    rillig {
    416  1.104    rillig 	struct include_level *top;
    417  1.104    rillig 
    418  1.104    rillig 	top = includes;
    419  1.104    rillig 	if (is_begin && top != NULL)
    420  1.104    rillig 		top->lineno = curr_pos.p_line;
    421  1.104    rillig 
    422  1.104    rillig 	if (top == NULL || is_begin) {
    423  1.104    rillig 		top = xmalloc(sizeof(*top));
    424  1.104    rillig 		top->filename = filename;
    425  1.104    rillig 		top->lineno = lineno;
    426  1.104    rillig 		top->by = includes;
    427  1.104    rillig 		includes = top;
    428  1.104    rillig 	} else {
    429  1.109    rillig 		if (is_end) {
    430  1.104    rillig 			includes = top->by;
    431  1.104    rillig 			free(top);
    432  1.104    rillig 			top = includes;
    433  1.104    rillig 		}
    434  1.123    rillig 		if (top != NULL) {
    435  1.123    rillig 			top->filename = filename;
    436  1.123    rillig 			top->lineno = lineno;
    437  1.123    rillig 		}
    438  1.104    rillig 	}
    439  1.104    rillig }
    440  1.104    rillig 
    441  1.104    rillig static void
    442  1.104    rillig print_stack_trace(void)
    443  1.104    rillig {
    444  1.105    rillig 	const struct include_level *top;
    445  1.104    rillig 
    446  1.104    rillig 	if ((top = includes) == NULL)
    447  1.104    rillig 		return;
    448  1.105    rillig 	/*
    449  1.105    rillig 	 * Skip the innermost include level since it is already listed in the
    450  1.105    rillig 	 * diagnostic itself.  Furthermore, its lineno is the line number of
    451  1.105    rillig 	 * the last '#' line, not the current line.
    452  1.105    rillig 	 */
    453  1.104    rillig 	for (top = top->by; top != NULL; top = top->by)
    454  1.104    rillig 		printf("\tincluded from %s(%d)\n", top->filename, top->lineno);
    455  1.104    rillig }
    456  1.104    rillig 
    457    1.1       cgd /*
    458   1.12  christos  * print a list of the messages with their ids
    459   1.12  christos  */
    460   1.12  christos void
    461   1.15     lukem msglist(void)
    462   1.12  christos {
    463   1.40  christos 	size_t i;
    464   1.12  christos 
    465  1.143    rillig 	for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++) {
    466  1.143    rillig 		if (msgs[i][0] != '\0')
    467  1.143    rillig 			printf("%zu\t%s\n", i, msgs[i]);
    468  1.143    rillig 		else
    469  1.143    rillig 			printf("---\t(no longer used)\n");
    470  1.143    rillig 	}
    471   1.12  christos }
    472   1.12  christos 
    473   1.12  christos /*
    474   1.56    rillig  * If Fflag is not set, lbasename() returns a pointer to the last
    475    1.1       cgd  * component of the path, otherwise it returns the argument.
    476    1.1       cgd  */
    477    1.1       cgd static const char *
    478   1.18        tv lbasename(const char *path)
    479    1.1       cgd {
    480   1.68    rillig 	const char *p, *base, *dir;
    481    1.1       cgd 
    482    1.1       cgd 	if (Fflag)
    483   1.57    rillig 		return path;
    484    1.1       cgd 
    485   1.68    rillig 	p = base = dir = path;
    486   1.68    rillig 	while (*p != '\0') {
    487   1.68    rillig 		if (*p++ == '/') {
    488   1.68    rillig 			dir = base;
    489   1.68    rillig 			base = p;
    490    1.1       cgd 		}
    491    1.1       cgd 	}
    492   1.68    rillig 	return *base != '\0' ? base : dir;
    493    1.1       cgd }
    494    1.1       cgd 
    495    1.3       jpo static void
    496  1.116    rillig verror_at(int msgid, const pos_t *pos, va_list ap)
    497    1.3       jpo {
    498    1.3       jpo 	const	char *fn;
    499    1.3       jpo 
    500  1.115    rillig 	if (ERR_ISSET(msgid, &msgset))
    501   1.12  christos 		return;
    502   1.12  christos 
    503  1.116    rillig 	fn = lbasename(pos->p_file);
    504  1.116    rillig 	(void)printf("%s(%d): error: ", fn, pos->p_line);
    505  1.115    rillig 	(void)vprintf(msgs[msgid], ap);
    506  1.115    rillig 	(void)printf(" [%d]\n", msgid);
    507    1.3       jpo 	nerr++;
    508  1.104    rillig 	print_stack_trace();
    509    1.3       jpo }
    510    1.3       jpo 
    511    1.3       jpo static void
    512  1.116    rillig vwarning_at(int msgid, const pos_t *pos, va_list ap)
    513    1.3       jpo {
    514    1.3       jpo 	const	char *fn;
    515    1.3       jpo 
    516  1.115    rillig 	if (ERR_ISSET(msgid, &msgset))
    517   1.12  christos 		return;
    518   1.12  christos 
    519  1.132    rillig 	debug_step("%s: lwarn=%d msgid=%d", __func__, lwarn, msgid);
    520  1.115    rillig 	if (lwarn == LWARN_NONE || lwarn == msgid)
    521    1.3       jpo 		/* this warning is suppressed by a LINTED comment */
    522    1.3       jpo 		return;
    523    1.3       jpo 
    524  1.116    rillig 	fn = lbasename(pos->p_file);
    525  1.116    rillig 	(void)printf("%s(%d): warning: ", fn, pos->p_line);
    526  1.115    rillig 	(void)vprintf(msgs[msgid], ap);
    527  1.115    rillig 	(void)printf(" [%d]\n", msgid);
    528   1.12  christos 	if (wflag)
    529   1.12  christos 		nerr++;
    530  1.104    rillig 	print_stack_trace();
    531    1.3       jpo }
    532    1.3       jpo 
    533  1.113    rillig static void
    534  1.116    rillig vmessage_at(int msgid, const pos_t *pos, va_list ap)
    535  1.113    rillig {
    536  1.113    rillig 	const char *fn;
    537  1.113    rillig 
    538  1.115    rillig 	if (ERR_ISSET(msgid, &msgset))
    539  1.113    rillig 		return;
    540  1.113    rillig 
    541  1.116    rillig 	fn = lbasename(pos->p_file);
    542  1.116    rillig 	(void)printf("%s(%d): ", fn, pos->p_line);
    543  1.115    rillig 	(void)vprintf(msgs[msgid], ap);
    544  1.115    rillig 	(void)printf(" [%d]\n", msgid);
    545  1.113    rillig 	print_stack_trace();
    546  1.113    rillig }
    547  1.113    rillig 
    548  1.113    rillig void
    549  1.116    rillig (error_at)(int msgid, const pos_t *pos, ...)
    550  1.113    rillig {
    551  1.113    rillig 	va_list	ap;
    552  1.113    rillig 
    553  1.113    rillig 	va_start(ap, pos);
    554  1.115    rillig 	verror_at(msgid, pos, ap);
    555  1.113    rillig 	va_end(ap);
    556  1.113    rillig }
    557  1.113    rillig 
    558    1.3       jpo void
    559  1.115    rillig (error)(int msgid, ...)
    560    1.1       cgd {
    561    1.1       cgd 	va_list	ap;
    562    1.1       cgd 
    563  1.115    rillig 	va_start(ap, msgid);
    564  1.116    rillig 	verror_at(msgid, &curr_pos, ap);
    565    1.1       cgd 	va_end(ap);
    566    1.1       cgd }
    567    1.1       cgd 
    568    1.3       jpo void
    569   1.96    rillig internal_error(const char *file, int line, const char *msg, ...)
    570    1.1       cgd {
    571    1.1       cgd 	va_list	ap;
    572    1.1       cgd 	const	char *fn;
    573    1.1       cgd 
    574   1.94    rillig 	fn = lbasename(curr_pos.p_file);
    575  1.144    rillig 	(void)fflush(stdout);
    576   1.94    rillig 	(void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ",
    577   1.94    rillig 	    file, line, fn, curr_pos.p_line);
    578    1.1       cgd 	va_start(ap, msg);
    579    1.1       cgd 	(void)vfprintf(stderr, msg, ap);
    580   1.94    rillig 	va_end(ap);
    581    1.1       cgd 	(void)fprintf(stderr, "\n");
    582  1.104    rillig 	print_stack_trace();
    583   1.45  christos 	abort();
    584    1.1       cgd }
    585    1.1       cgd 
    586    1.3       jpo void
    587   1.59    rillig assert_failed(const char *file, int line, const char *func, const char *cond)
    588   1.59    rillig {
    589   1.59    rillig 	const	char *fn;
    590   1.59    rillig 
    591   1.59    rillig 	fn = lbasename(curr_pos.p_file);
    592  1.144    rillig 	(void)fflush(stdout);
    593   1.59    rillig 	(void)fprintf(stderr,
    594   1.59    rillig 	    "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
    595   1.59    rillig 	    cond, func, file, line, fn, curr_pos.p_line);
    596  1.104    rillig 	print_stack_trace();
    597   1.59    rillig 	abort();
    598   1.59    rillig }
    599   1.59    rillig 
    600   1.59    rillig void
    601  1.116    rillig (warning_at)(int msgid, const pos_t *pos, ...)
    602  1.113    rillig {
    603  1.113    rillig 	va_list	ap;
    604  1.113    rillig 
    605  1.113    rillig 	va_start(ap, pos);
    606  1.115    rillig 	vwarning_at(msgid, pos, ap);
    607  1.113    rillig 	va_end(ap);
    608  1.113    rillig }
    609  1.113    rillig 
    610  1.113    rillig void
    611  1.115    rillig (warning)(int msgid, ...)
    612    1.1       cgd {
    613    1.3       jpo 	va_list	ap;
    614    1.3       jpo 
    615  1.115    rillig 	va_start(ap, msgid);
    616  1.116    rillig 	vwarning_at(msgid, &curr_pos, ap);
    617  1.113    rillig 	va_end(ap);
    618  1.113    rillig }
    619  1.113    rillig 
    620  1.113    rillig void
    621  1.116    rillig (message_at)(int msgid, const pos_t *pos, ...)
    622  1.113    rillig {
    623  1.113    rillig 	va_list ap;
    624  1.113    rillig 
    625  1.113    rillig 	va_start(ap, pos);
    626  1.115    rillig 	vmessage_at(msgid, pos, ap);
    627    1.3       jpo 	va_end(ap);
    628    1.3       jpo }
    629    1.3       jpo 
    630   1.26     perry /*
    631   1.26     perry  * XXX I think the logic is possibly somewhat screwed up here. The
    632   1.26     perry  * question is, how do we want to interpret the -s and -S flags going
    633   1.26     perry  * forward? We need to answer that and then we can fix this to be
    634   1.26     perry  * "right"... [perry, 2 Nov 2002]
    635   1.26     perry */
    636   1.63    rillig void
    637  1.115    rillig (c99ism)(int msgid, ...)
    638   1.25     perry {
    639   1.25     perry 	va_list	ap;
    640   1.63    rillig 	bool extensions_ok = Sflag || gflag;
    641   1.25     perry 
    642  1.115    rillig 	va_start(ap, msgid);
    643   1.63    rillig 	if (sflag && !extensions_ok) {
    644  1.116    rillig 		verror_at(msgid, &curr_pos, ap);
    645   1.63    rillig 	} else if (sflag || !extensions_ok) {
    646  1.116    rillig 		vwarning_at(msgid, &curr_pos, ap);
    647   1.25     perry 	}
    648   1.25     perry 	va_end(ap);
    649    1.1       cgd }
    650    1.1       cgd 
    651  1.108    rillig void
    652  1.115    rillig (c11ism)(int msgid, ...)
    653  1.108    rillig {
    654  1.108    rillig 	va_list	ap;
    655  1.108    rillig 
    656  1.111  christos 	if (c11flag || gflag)
    657  1.110    rillig 		return;
    658  1.115    rillig 	va_start(ap, msgid);
    659  1.116    rillig 	verror_at(msgid, &curr_pos, ap);
    660  1.108    rillig 	va_end(ap);
    661  1.108    rillig }
    662  1.108    rillig 
    663   1.63    rillig void
    664  1.115    rillig (gnuism)(int msgid, ...)
    665    1.1       cgd {
    666    1.1       cgd 	va_list	ap;
    667    1.1       cgd 
    668  1.115    rillig 	va_start(ap, msgid);
    669    1.3       jpo 	if (sflag && !gflag) {
    670  1.116    rillig 		verror_at(msgid, &curr_pos, ap);
    671   1.63    rillig 	} else if (sflag || !gflag) {
    672  1.116    rillig 		vwarning_at(msgid, &curr_pos, ap);
    673    1.3       jpo 	}
    674    1.1       cgd 	va_end(ap);
    675    1.1       cgd }
    676