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