| @@ -1,1297 +1,1297 @@ | | | @@ -1,1297 +1,1297 @@ |
1 | /* $NetBSD: func.c,v 1.47 2021/01/02 18:44:58 rillig Exp $ */ | | 1 | /* $NetBSD: func.c,v 1.48 2021/01/03 20:04:08 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994, 1995 Jochen Pohl | | 4 | * Copyright (c) 1994, 1995 Jochen Pohl |
5 | * All Rights Reserved. | | 5 | * All Rights Reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | | 15 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | | 16 | * must display the following acknowledgement: |
17 | * This product includes software developed by Jochen Pohl for | | 17 | * This product includes software developed by Jochen Pohl for |
18 | * The NetBSD Project. | | 18 | * The NetBSD Project. |
19 | * 4. The name of the author may not be used to endorse or promote products | | 19 | * 4. The name of the author may not be used to endorse or promote products |
20 | * derived from this software without specific prior written permission. | | 20 | * derived from this software without specific prior written permission. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #if HAVE_NBTOOL_CONFIG_H | | 34 | #if HAVE_NBTOOL_CONFIG_H |
35 | #include "nbtool_config.h" | | 35 | #include "nbtool_config.h" |
36 | #endif | | 36 | #endif |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | #if defined(__RCSID) && !defined(lint) | | 39 | #if defined(__RCSID) && !defined(lint) |
40 | __RCSID("$NetBSD: func.c,v 1.47 2021/01/02 18:44:58 rillig Exp $"); | | 40 | __RCSID("$NetBSD: func.c,v 1.48 2021/01/03 20:04:08 rillig Exp $"); |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <stdlib.h> | | 43 | #include <stdlib.h> |
44 | #include <string.h> | | 44 | #include <string.h> |
45 | | | 45 | |
46 | #include "lint1.h" | | 46 | #include "lint1.h" |
47 | #include "cgram.h" | | 47 | #include "cgram.h" |
48 | | | 48 | |
49 | /* | | 49 | /* |
50 | * Contains a pointer to the symbol table entry of the current function | | 50 | * Contains a pointer to the symbol table entry of the current function |
51 | * definition. | | 51 | * definition. |
52 | */ | | 52 | */ |
53 | sym_t *funcsym; | | 53 | sym_t *funcsym; |
54 | | | 54 | |
55 | /* Is set as long as a statement can be reached. Must be set at level 0. */ | | 55 | /* Is set as long as a statement can be reached. Must be set at level 0. */ |
56 | int reached = 1; | | 56 | int reached = 1; |
57 | | | 57 | |
58 | /* | | 58 | /* |
59 | * Is set as long as NOTREACHED is in effect. | | 59 | * Is set as long as NOTREACHED is in effect. |
60 | * Is reset everywhere where reached can become 0. | | 60 | * Is reset everywhere where reached can become 0. |
61 | */ | | 61 | */ |
62 | int rchflg; | | 62 | int rchflg; |
63 | | | 63 | |
64 | /* | | 64 | /* |
65 | * In conjunction with reached ontrols printing of "fallthrough on ..." | | 65 | * In conjunction with reached ontrols printing of "fallthrough on ..." |
66 | * warnings. | | 66 | * warnings. |
67 | * Reset by each statement and set by FALLTHROUGH, switch (switch1()) | | 67 | * Reset by each statement and set by FALLTHROUGH, switch (switch1()) |
68 | * and case (label()). | | 68 | * and case (label()). |
69 | * | | 69 | * |
70 | * Control statements if, for, while and switch do not reset ftflg because | | 70 | * Control statements if, for, while and switch do not reset ftflg because |
71 | * this must be done by the controlled statement. At least for if this is | | 71 | * this must be done by the controlled statement. At least for if this is |
72 | * important because ** FALLTHROUGH ** after "if (expr) stmnt" is evaluated | | 72 | * important because ** FALLTHROUGH ** after "if (expr) stmnt" is evaluated |
73 | * before the following token, wich causes reduction of above. | | 73 | * before the following token, wich causes reduction of above. |
74 | * This means that ** FALLTHROUGH ** after "if ..." would always be ignored. | | 74 | * This means that ** FALLTHROUGH ** after "if ..." would always be ignored. |
75 | */ | | 75 | */ |
76 | int ftflg; | | 76 | int ftflg; |
77 | | | 77 | |
78 | /* Top element of stack for control statements */ | | 78 | /* The innermost control statement */ |
79 | cstk_t *cstk; | | 79 | cstk_t *cstmt; |
80 | | | 80 | |
81 | /* | | 81 | /* |
82 | * Number of arguments which will be checked for usage in following | | 82 | * Number of arguments which will be checked for usage in following |
83 | * function definition. -1 stands for all arguments. | | 83 | * function definition. -1 stands for all arguments. |
84 | * | | 84 | * |
85 | * The position of the last ARGSUSED comment is stored in argsused_pos. | | 85 | * The position of the last ARGSUSED comment is stored in argsused_pos. |
86 | */ | | 86 | */ |
87 | int nargusg = -1; | | 87 | int nargusg = -1; |
88 | pos_t argsused_pos; | | 88 | pos_t argsused_pos; |
89 | | | 89 | |
90 | /* | | 90 | /* |
91 | * Number of arguments of the following function definition whose types | | 91 | * Number of arguments of the following function definition whose types |
92 | * shall be checked by lint2. -1 stands for all arguments. | | 92 | * shall be checked by lint2. -1 stands for all arguments. |
93 | * | | 93 | * |
94 | * The position of the last VARARGS comment is stored in vapos. | | 94 | * The position of the last VARARGS comment is stored in vapos. |
95 | */ | | 95 | */ |
96 | int nvararg = -1; | | 96 | int nvararg = -1; |
97 | pos_t vapos; | | 97 | pos_t vapos; |
98 | | | 98 | |
99 | /* | | 99 | /* |
100 | * Both prflstr and scflstrg contain the number of the argument which | | 100 | * Both prflstr and scflstrg contain the number of the argument which |
101 | * shall be used to check the types of remaining arguments (for PRINTFLIKE | | 101 | * shall be used to check the types of remaining arguments (for PRINTFLIKE |
102 | * and SCANFLIKE). | | 102 | * and SCANFLIKE). |
103 | * | | 103 | * |
104 | * printflike_pos and scanflike_pos are the positions of the last PRINTFLIKE | | 104 | * printflike_pos and scanflike_pos are the positions of the last PRINTFLIKE |
105 | * or SCANFLIKE comment. | | 105 | * or SCANFLIKE comment. |
106 | */ | | 106 | */ |
107 | int prflstrg = -1; | | 107 | int prflstrg = -1; |
108 | int scflstrg = -1; | | 108 | int scflstrg = -1; |
109 | pos_t printflike_pos; | | 109 | pos_t printflike_pos; |
110 | pos_t scanflike_pos; | | 110 | pos_t scanflike_pos; |
111 | | | 111 | |
112 | /* | | 112 | /* |
113 | * If both plibflg and llibflg are set, prototypes are written as function | | 113 | * If both plibflg and llibflg are set, prototypes are written as function |
114 | * definitions to the output file. | | 114 | * definitions to the output file. |
115 | */ | | 115 | */ |
116 | int plibflg; | | 116 | int plibflg; |
117 | | | 117 | |
118 | /* | | 118 | /* |
119 | * Nonzero means that no warnings about constants in conditional | | 119 | * Nonzero means that no warnings about constants in conditional |
120 | * context are printed. | | 120 | * context are printed. |
121 | */ | | 121 | */ |
122 | int constcond_flag; | | 122 | int constcond_flag; |
123 | | | 123 | |
124 | /* | | 124 | /* |
125 | * llibflg is set if a lint library shall be created. The effect of | | 125 | * llibflg is set if a lint library shall be created. The effect of |
126 | * llibflg is that all defined symbols are treated as used. | | 126 | * llibflg is that all defined symbols are treated as used. |
127 | * (The LINTLIBRARY comment also resets vflag.) | | 127 | * (The LINTLIBRARY comment also resets vflag.) |
128 | */ | | 128 | */ |
129 | int llibflg; | | 129 | int llibflg; |
130 | | | 130 | |
131 | /* | | 131 | /* |
132 | * Nonzero if warnings are suppressed by a LINTED directive | | 132 | * Nonzero if warnings are suppressed by a LINTED directive |
133 | * LWARN_BAD: error | | 133 | * LWARN_BAD: error |
134 | * LWARN_ALL: warnings on | | 134 | * LWARN_ALL: warnings on |
135 | * LWARN_NONE: all warnings ignored | | 135 | * LWARN_NONE: all warnings ignored |
136 | * 0..n: warning n ignored | | 136 | * 0..n: warning n ignored |
137 | */ | | 137 | */ |
138 | int lwarn = LWARN_ALL; | | 138 | int lwarn = LWARN_ALL; |
139 | | | 139 | |
140 | /* | | 140 | /* |
141 | * Whether bitfield type errors are suppressed by a BITFIELDTYPE | | 141 | * Whether bitfield type errors are suppressed by a BITFIELDTYPE |
142 | * directive. | | 142 | * directive. |
143 | */ | | 143 | */ |
144 | bool bitfieldtype_ok; | | 144 | bool bitfieldtype_ok; |
145 | | | 145 | |
146 | /* | | 146 | /* |
147 | * Nonzero if complaints about use of "long long" are suppressed in | | 147 | * Nonzero if complaints about use of "long long" are suppressed in |
148 | * the next statement or declaration. | | 148 | * the next statement or declaration. |
149 | */ | | 149 | */ |
150 | int quadflg; | | 150 | int quadflg; |
151 | | | 151 | |
152 | /* | | 152 | /* |
153 | * Puts a new element at the top of the stack used for control statements. | | 153 | * Puts a new element at the top of the stack used for control statements. |
154 | */ | | 154 | */ |
155 | void | | 155 | void |
156 | pushctrl(int env) | | 156 | pushctrl(int env) |
157 | { | | 157 | { |
158 | cstk_t *ci; | | 158 | cstk_t *ci; |
159 | | | 159 | |
160 | ci = xcalloc(1, sizeof (cstk_t)); | | 160 | ci = xcalloc(1, sizeof (cstk_t)); |
161 | ci->c_env = env; | | 161 | ci->c_env = env; |
162 | ci->c_next = cstk; | | 162 | ci->c_surrounding = cstmt; |
163 | cstk = ci; | | 163 | cstmt = ci; |
164 | } | | 164 | } |
165 | | | 165 | |
166 | /* | | 166 | /* |
167 | * Removes the top element of the stack used for control statements. | | 167 | * Removes the top element of the stack used for control statements. |
168 | */ | | 168 | */ |
169 | void | | 169 | void |
170 | popctrl(int env) | | 170 | popctrl(int env) |
171 | { | | 171 | { |
172 | cstk_t *ci; | | 172 | cstk_t *ci; |
173 | clst_t *cl; | | 173 | clst_t *cl; |
174 | | | 174 | |
175 | lint_assert(cstk != NULL); | | 175 | lint_assert(cstmt != NULL); |
176 | lint_assert(cstk->c_env == env); | | 176 | lint_assert(cstmt->c_env == env); |
177 | | | 177 | |
178 | cstk = (ci = cstk)->c_next; | | 178 | cstmt = (ci = cstmt)->c_surrounding; |
179 | | | 179 | |
180 | while ((cl = ci->c_clst) != NULL) { | | 180 | while ((cl = ci->c_clst) != NULL) { |
181 | ci->c_clst = cl->cl_next; | | 181 | ci->c_clst = cl->cl_next; |
182 | free(cl); | | 182 | free(cl); |
183 | } | | 183 | } |
184 | | | 184 | |
185 | if (ci->c_swtype != NULL) | | 185 | if (ci->c_swtype != NULL) |
186 | free(ci->c_swtype); | | 186 | free(ci->c_swtype); |
187 | | | 187 | |
188 | free(ci); | | 188 | free(ci); |
189 | } | | 189 | } |
190 | | | 190 | |
191 | /* | | 191 | /* |
192 | * Prints a warning if a statement cannot be reached. | | 192 | * Prints a warning if a statement cannot be reached. |
193 | */ | | 193 | */ |
194 | void | | 194 | void |
195 | check_statement_reachable(void) | | 195 | check_statement_reachable(void) |
196 | { | | 196 | { |
197 | if (!reached && !rchflg) { | | 197 | if (!reached && !rchflg) { |
198 | /* statement not reached */ | | 198 | /* statement not reached */ |
199 | warning(193); | | 199 | warning(193); |
200 | reached = 1; | | 200 | reached = 1; |
201 | } | | 201 | } |
202 | } | | 202 | } |
203 | | | 203 | |
204 | /* | | 204 | /* |
205 | * Called after a function declaration which introduces a function definition | | 205 | * Called after a function declaration which introduces a function definition |
206 | * and before an (optional) old style argument declaration list. | | 206 | * and before an (optional) old style argument declaration list. |
207 | * | | 207 | * |
208 | * Puts all symbols declared in the prototype or in an old style argument | | 208 | * Puts all symbols declared in the prototype or in an old style argument |
209 | * list back to the symbol table. | | 209 | * list back to the symbol table. |
210 | * | | 210 | * |
211 | * Does the usual checking of storage class, type (return value), | | 211 | * Does the usual checking of storage class, type (return value), |
212 | * redeclaration, etc. | | 212 | * redeclaration, etc. |
213 | */ | | 213 | */ |
214 | void | | 214 | void |
215 | funcdef(sym_t *fsym) | | 215 | funcdef(sym_t *fsym) |
216 | { | | 216 | { |
217 | int n, dowarn; | | 217 | int n, dowarn; |
218 | sym_t *arg, *sym, *rdsym; | | 218 | sym_t *arg, *sym, *rdsym; |
219 | | | 219 | |
220 | funcsym = fsym; | | 220 | funcsym = fsym; |
221 | | | 221 | |
222 | /* | | 222 | /* |
223 | * Put all symbols declared in the argument list back to the | | 223 | * Put all symbols declared in the argument list back to the |
224 | * symbol table. | | 224 | * symbol table. |
225 | */ | | 225 | */ |
226 | for (sym = dcs->d_fpsyms; sym != NULL; sym = sym->s_dlnxt) { | | 226 | for (sym = dcs->d_fpsyms; sym != NULL; sym = sym->s_dlnxt) { |
227 | if (sym->s_blklev != -1) { | | 227 | if (sym->s_blklev != -1) { |
228 | lint_assert(sym->s_blklev == 1); | | 228 | lint_assert(sym->s_blklev == 1); |
229 | inssym(1, sym); | | 229 | inssym(1, sym); |
230 | } | | 230 | } |
231 | } | | 231 | } |
232 | | | 232 | |
233 | /* | | 233 | /* |
234 | * In old_style_function() we did not know whether it is an old | | 234 | * In old_style_function() we did not know whether it is an old |
235 | * style function definition or only an old style declaration, | | 235 | * style function definition or only an old style declaration, |
236 | * if there are no arguments inside the argument list ("f()"). | | 236 | * if there are no arguments inside the argument list ("f()"). |
237 | */ | | 237 | */ |
238 | if (!fsym->s_type->t_proto && fsym->s_args == NULL) | | 238 | if (!fsym->s_type->t_proto && fsym->s_args == NULL) |
239 | fsym->s_osdef = 1; | | 239 | fsym->s_osdef = 1; |
240 | | | 240 | |
241 | check_type(fsym); | | 241 | check_type(fsym); |
242 | | | 242 | |
243 | /* | | 243 | /* |
244 | * check_type() checks for almost all possible errors, but not for | | 244 | * check_type() checks for almost all possible errors, but not for |
245 | * incomplete return values (these are allowed in declarations) | | 245 | * incomplete return values (these are allowed in declarations) |
246 | */ | | 246 | */ |
247 | if (fsym->s_type->t_subt->t_tspec != VOID && | | 247 | if (fsym->s_type->t_subt->t_tspec != VOID && |
248 | incompl(fsym->s_type->t_subt)) { | | 248 | incompl(fsym->s_type->t_subt)) { |
249 | /* cannot return incomplete type */ | | 249 | /* cannot return incomplete type */ |
250 | error(67); | | 250 | error(67); |
251 | } | | 251 | } |
252 | | | 252 | |
253 | fsym->s_def = DEF; | | 253 | fsym->s_def = DEF; |
254 | | | 254 | |
255 | if (fsym->s_scl == TYPEDEF) { | | 255 | if (fsym->s_scl == TYPEDEF) { |
256 | fsym->s_scl = EXTERN; | | 256 | fsym->s_scl = EXTERN; |
257 | /* illegal storage class */ | | 257 | /* illegal storage class */ |
258 | error(8); | | 258 | error(8); |
259 | } | | 259 | } |
260 | | | 260 | |
261 | if (dcs->d_inline) | | 261 | if (dcs->d_inline) |
262 | fsym->s_inline = 1; | | 262 | fsym->s_inline = 1; |
263 | | | 263 | |
264 | /* | | 264 | /* |
265 | * Arguments in new style function declarations need a name. | | 265 | * Arguments in new style function declarations need a name. |
266 | * (void is already removed from the list of arguments) | | 266 | * (void is already removed from the list of arguments) |
267 | */ | | 267 | */ |
268 | n = 1; | | 268 | n = 1; |
269 | for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_next) { | | 269 | for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_next) { |
270 | if (arg->s_scl == ABSTRACT) { | | 270 | if (arg->s_scl == ABSTRACT) { |
271 | lint_assert(arg->s_name == unnamed); | | 271 | lint_assert(arg->s_name == unnamed); |
272 | /* formal parameter lacks name: param #%d */ | | 272 | /* formal parameter lacks name: param #%d */ |
273 | error(59, n); | | 273 | error(59, n); |
274 | } else { | | 274 | } else { |
275 | lint_assert(arg->s_name != unnamed); | | 275 | lint_assert(arg->s_name != unnamed); |
276 | } | | 276 | } |
277 | n++; | | 277 | n++; |
278 | } | | 278 | } |
279 | | | 279 | |
280 | /* | | 280 | /* |
281 | * We must also remember the position. s_def_pos is overwritten | | 281 | * We must also remember the position. s_def_pos is overwritten |
282 | * if this is an old style definition and we had already a | | 282 | * if this is an old style definition and we had already a |
283 | * prototype. | | 283 | * prototype. |
284 | */ | | 284 | */ |
285 | dcs->d_fdpos = fsym->s_def_pos; | | 285 | dcs->d_fdpos = fsym->s_def_pos; |
286 | | | 286 | |
287 | if ((rdsym = dcs->d_rdcsym) != NULL) { | | 287 | if ((rdsym = dcs->d_rdcsym) != NULL) { |
288 | | | 288 | |
289 | if (!check_redeclaration(fsym, (dowarn = 0, &dowarn))) { | | 289 | if (!check_redeclaration(fsym, (dowarn = 0, &dowarn))) { |
290 | | | 290 | |
291 | /* | | 291 | /* |
292 | * Print nothing if the newly defined function | | 292 | * Print nothing if the newly defined function |
293 | * is defined in old style. A better warning will | | 293 | * is defined in old style. A better warning will |
294 | * be printed in check_func_lint_directives(). | | 294 | * be printed in check_func_lint_directives(). |
295 | */ | | 295 | */ |
296 | if (dowarn && !fsym->s_osdef) { | | 296 | if (dowarn && !fsym->s_osdef) { |
297 | /* redeclaration of %s */ | | 297 | /* redeclaration of %s */ |
298 | (*(sflag ? error : warning))(27, fsym->s_name); | | 298 | (*(sflag ? error : warning))(27, fsym->s_name); |
299 | print_previous_declaration(-1, rdsym); | | 299 | print_previous_declaration(-1, rdsym); |
300 | } | | 300 | } |
301 | | | 301 | |
302 | /* copy usage information */ | | 302 | /* copy usage information */ |
303 | copy_usage_info(fsym, rdsym); | | 303 | copy_usage_info(fsym, rdsym); |
304 | | | 304 | |
305 | /* | | 305 | /* |
306 | * If the old symbol was a prototype and the new | | 306 | * If the old symbol was a prototype and the new |
307 | * one is none, overtake the position of the | | 307 | * one is none, overtake the position of the |
308 | * declaration of the prototype. | | 308 | * declaration of the prototype. |
309 | */ | | 309 | */ |
310 | if (fsym->s_osdef && rdsym->s_type->t_proto) | | 310 | if (fsym->s_osdef && rdsym->s_type->t_proto) |
311 | fsym->s_def_pos = rdsym->s_def_pos; | | 311 | fsym->s_def_pos = rdsym->s_def_pos; |
312 | | | 312 | |
313 | /* complete the type */ | | 313 | /* complete the type */ |
314 | complete_type(fsym, rdsym); | | 314 | complete_type(fsym, rdsym); |
315 | | | 315 | |
316 | /* once a function is inline it remains inline */ | | 316 | /* once a function is inline it remains inline */ |
317 | if (rdsym->s_inline) | | 317 | if (rdsym->s_inline) |
318 | fsym->s_inline = 1; | | 318 | fsym->s_inline = 1; |
319 | | | 319 | |
320 | } | | 320 | } |
321 | | | 321 | |
322 | /* remove the old symbol from the symbol table */ | | 322 | /* remove the old symbol from the symbol table */ |
323 | rmsym(rdsym); | | 323 | rmsym(rdsym); |
324 | | | 324 | |
325 | } | | 325 | } |
326 | | | 326 | |
327 | if (fsym->s_osdef && !fsym->s_type->t_proto) { | | 327 | if (fsym->s_osdef && !fsym->s_type->t_proto) { |
328 | if (sflag && hflag && strcmp(fsym->s_name, "main") != 0) | | 328 | if (sflag && hflag && strcmp(fsym->s_name, "main") != 0) |
329 | /* function definition is not a prototype */ | | 329 | /* function definition is not a prototype */ |
330 | warning(286); | | 330 | warning(286); |
331 | } | | 331 | } |
332 | | | 332 | |
333 | if (dcs->d_notyp) | | 333 | if (dcs->d_notyp) |
334 | /* return value is implicitly declared to be int */ | | 334 | /* return value is implicitly declared to be int */ |
335 | fsym->s_rimpl = 1; | | 335 | fsym->s_rimpl = 1; |
336 | | | 336 | |
337 | reached = 1; | | 337 | reached = 1; |
338 | } | | 338 | } |
339 | | | 339 | |
340 | /* | | 340 | /* |
341 | * Called at the end of a function definition. | | 341 | * Called at the end of a function definition. |
342 | */ | | 342 | */ |
343 | void | | 343 | void |
344 | funcend(void) | | 344 | funcend(void) |
345 | { | | 345 | { |
346 | sym_t *arg; | | 346 | sym_t *arg; |
347 | int n; | | 347 | int n; |
348 | | | 348 | |
349 | if (reached) { | | 349 | if (reached) { |
350 | cstk->c_noretval = 1; | | 350 | cstmt->c_noretval = 1; |
351 | if (funcsym->s_type->t_subt->t_tspec != VOID && | | 351 | if (funcsym->s_type->t_subt->t_tspec != VOID && |
352 | !funcsym->s_rimpl) { | | 352 | !funcsym->s_rimpl) { |
353 | /* func. %s falls off bottom without returning value */ | | 353 | /* func. %s falls off bottom without returning value */ |
354 | warning(217, funcsym->s_name); | | 354 | warning(217, funcsym->s_name); |
355 | } | | 355 | } |
356 | } | | 356 | } |
357 | | | 357 | |
358 | /* | | 358 | /* |
359 | * This warning is printed only if the return value was implicitly | | 359 | * This warning is printed only if the return value was implicitly |
360 | * declared to be int. Otherwise the wrong return statement | | 360 | * declared to be int. Otherwise the wrong return statement |
361 | * has already printed a warning. | | 361 | * has already printed a warning. |
362 | */ | | 362 | */ |
363 | if (cstk->c_noretval && cstk->c_retval && funcsym->s_rimpl) | | 363 | if (cstmt->c_noretval && cstmt->c_retval && funcsym->s_rimpl) |
364 | /* function %s has return (e); and return; */ | | 364 | /* function %s has return (e); and return; */ |
365 | warning(216, funcsym->s_name); | | 365 | warning(216, funcsym->s_name); |
366 | | | 366 | |
367 | /* Print warnings for unused arguments */ | | 367 | /* Print warnings for unused arguments */ |
368 | arg = dcs->d_fargs; | | 368 | arg = dcs->d_fargs; |
369 | n = 0; | | 369 | n = 0; |
370 | while (arg != NULL && (nargusg == -1 || n < nargusg)) { | | 370 | while (arg != NULL && (nargusg == -1 || n < nargusg)) { |
371 | check_usage_sym(dcs->d_asm, arg); | | 371 | check_usage_sym(dcs->d_asm, arg); |
372 | arg = arg->s_next; | | 372 | arg = arg->s_next; |
373 | n++; | | 373 | n++; |
374 | } | | 374 | } |
375 | nargusg = -1; | | 375 | nargusg = -1; |
376 | | | 376 | |
377 | /* | | 377 | /* |
378 | * write the information about the function definition to the | | 378 | * write the information about the function definition to the |
379 | * output file | | 379 | * output file |
380 | * inline functions explicitly declared extern are written as | | 380 | * inline functions explicitly declared extern are written as |
381 | * declarations only. | | 381 | * declarations only. |
382 | */ | | 382 | */ |
383 | if (dcs->d_scl == EXTERN && funcsym->s_inline) { | | 383 | if (dcs->d_scl == EXTERN && funcsym->s_inline) { |
384 | outsym(funcsym, funcsym->s_scl, DECL); | | 384 | outsym(funcsym, funcsym->s_scl, DECL); |
385 | } else { | | 385 | } else { |
386 | outfdef(funcsym, &dcs->d_fdpos, cstk->c_retval, | | 386 | outfdef(funcsym, &dcs->d_fdpos, cstmt->c_retval, |
387 | funcsym->s_osdef, dcs->d_fargs); | | 387 | funcsym->s_osdef, dcs->d_fargs); |
388 | } | | 388 | } |
389 | | | 389 | |
390 | /* | | 390 | /* |
391 | * remove all symbols declared during argument declaration from | | 391 | * remove all symbols declared during argument declaration from |
392 | * the symbol table | | 392 | * the symbol table |
393 | */ | | 393 | */ |
394 | lint_assert(dcs->d_next == NULL); | | 394 | lint_assert(dcs->d_next == NULL); |
395 | lint_assert(dcs->d_ctx == EXTERN); | | 395 | lint_assert(dcs->d_ctx == EXTERN); |
396 | rmsyms(dcs->d_fpsyms); | | 396 | rmsyms(dcs->d_fpsyms); |
397 | | | 397 | |
398 | /* must be set on level 0 */ | | 398 | /* must be set on level 0 */ |
399 | reached = 1; | | 399 | reached = 1; |
400 | } | | 400 | } |
401 | | | 401 | |
402 | void | | 402 | void |
403 | named_label(sym_t *sym) | | 403 | named_label(sym_t *sym) |
404 | { | | 404 | { |
405 | | | 405 | |
406 | if (sym->s_set) { | | 406 | if (sym->s_set) { |
407 | /* label %s redefined */ | | 407 | /* label %s redefined */ |
408 | error(194, sym->s_name); | | 408 | error(194, sym->s_name); |
409 | } else { | | 409 | } else { |
410 | mark_as_set(sym); | | 410 | mark_as_set(sym); |
411 | } | | 411 | } |
412 | | | 412 | |
413 | reached = 1; | | 413 | reached = 1; |
414 | } | | 414 | } |
415 | | | 415 | |
416 | static void | | 416 | static void |
417 | check_case_label(tnode_t *tn, cstk_t *ci) | | 417 | check_case_label(tnode_t *tn, cstk_t *ci) |
418 | { | | 418 | { |
419 | clst_t *cl; | | 419 | clst_t *cl; |
420 | val_t *v; | | 420 | val_t *v; |
421 | val_t nv; | | 421 | val_t nv; |
422 | tspec_t t; | | 422 | tspec_t t; |
423 | | | 423 | |
424 | if (ci == NULL) { | | 424 | if (ci == NULL) { |
425 | /* case not in switch */ | | 425 | /* case not in switch */ |
426 | error(195); | | 426 | error(195); |
427 | return; | | 427 | return; |
428 | } | | 428 | } |
429 | | | 429 | |
430 | if (tn != NULL && tn->tn_op != CON) { | | 430 | if (tn != NULL && tn->tn_op != CON) { |
431 | /* non-constant case expression */ | | 431 | /* non-constant case expression */ |
432 | error(197); | | 432 | error(197); |
433 | return; | | 433 | return; |
434 | } | | 434 | } |
435 | | | 435 | |
436 | if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { | | 436 | if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { |
437 | /* non-integral case expression */ | | 437 | /* non-integral case expression */ |
438 | error(198); | | 438 | error(198); |
439 | return; | | 439 | return; |
440 | } | | 440 | } |
441 | | | 441 | |
442 | lint_assert(ci->c_swtype != NULL); | | 442 | lint_assert(ci->c_swtype != NULL); |
443 | | | 443 | |
444 | if (reached && !ftflg) { | | 444 | if (reached && !ftflg) { |
445 | if (hflag) | | 445 | if (hflag) |
446 | /* fallthrough on case statement */ | | 446 | /* fallthrough on case statement */ |
447 | warning(220); | | 447 | warning(220); |
448 | } | | 448 | } |
449 | | | 449 | |
450 | t = tn->tn_type->t_tspec; | | 450 | t = tn->tn_type->t_tspec; |
451 | if (t == LONG || t == ULONG || | | 451 | if (t == LONG || t == ULONG || |
452 | t == QUAD || t == UQUAD) { | | 452 | t == QUAD || t == UQUAD) { |
453 | if (tflag) | | 453 | if (tflag) |
454 | /* case label must be of type `int' in traditional C */ | | 454 | /* case label must be of type `int' in traditional C */ |
455 | warning(203); | | 455 | warning(203); |
456 | } | | 456 | } |
457 | | | 457 | |
458 | /* | | 458 | /* |
459 | * get the value of the expression and convert it | | 459 | * get the value of the expression and convert it |
460 | * to the type of the switch expression | | 460 | * to the type of the switch expression |
461 | */ | | 461 | */ |
462 | v = constant(tn, 1); | | 462 | v = constant(tn, 1); |
463 | (void) memset(&nv, 0, sizeof nv); | | 463 | (void) memset(&nv, 0, sizeof nv); |
464 | cvtcon(CASE, 0, ci->c_swtype, &nv, v); | | 464 | cvtcon(CASE, 0, ci->c_swtype, &nv, v); |
465 | free(v); | | 465 | free(v); |
466 | | | 466 | |
467 | /* look if we had this value already */ | | 467 | /* look if we had this value already */ |
468 | for (cl = ci->c_clst; cl != NULL; cl = cl->cl_next) { | | 468 | for (cl = ci->c_clst; cl != NULL; cl = cl->cl_next) { |
469 | if (cl->cl_val.v_quad == nv.v_quad) | | 469 | if (cl->cl_val.v_quad == nv.v_quad) |
470 | break; | | 470 | break; |
471 | } | | 471 | } |
472 | if (cl != NULL && tspec_is_uint(nv.v_tspec)) { | | 472 | if (cl != NULL && tspec_is_uint(nv.v_tspec)) { |
473 | /* duplicate case in switch: %lu */ | | 473 | /* duplicate case in switch: %lu */ |
474 | error(200, (u_long)nv.v_quad); | | 474 | error(200, (u_long)nv.v_quad); |
475 | } else if (cl != NULL) { | | 475 | } else if (cl != NULL) { |
476 | /* duplicate case in switch: %ld */ | | 476 | /* duplicate case in switch: %ld */ |
477 | error(199, (long)nv.v_quad); | | 477 | error(199, (long)nv.v_quad); |
478 | } else { | | 478 | } else { |
479 | /* | | 479 | /* |
480 | * append the value to the list of | | 480 | * append the value to the list of |
481 | * case values | | 481 | * case values |
482 | */ | | 482 | */ |
483 | cl = xcalloc(1, sizeof (clst_t)); | | 483 | cl = xcalloc(1, sizeof (clst_t)); |
484 | cl->cl_val = nv; | | 484 | cl->cl_val = nv; |
485 | cl->cl_next = ci->c_clst; | | 485 | cl->cl_next = ci->c_clst; |
486 | ci->c_clst = cl; | | 486 | ci->c_clst = cl; |
487 | } | | 487 | } |
488 | } | | 488 | } |
489 | | | 489 | |
490 | void | | 490 | void |
491 | case_label(tnode_t *tn) | | 491 | case_label(tnode_t *tn) |
492 | { | | 492 | { |
493 | cstk_t *ci; | | 493 | cstk_t *ci; |
494 | | | 494 | |
495 | /* find the stack entry for the innermost switch statement */ | | 495 | /* find the stack entry for the innermost switch statement */ |
496 | for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next) | | 496 | for (ci = cstmt; ci != NULL && !ci->c_switch; ci = ci->c_surrounding) |
497 | continue; | | 497 | continue; |
498 | | | 498 | |
499 | check_case_label(tn, ci); | | 499 | check_case_label(tn, ci); |
500 | | | 500 | |
501 | tfreeblk(); | | 501 | tfreeblk(); |
502 | | | 502 | |
503 | reached = 1; | | 503 | reached = 1; |
504 | } | | 504 | } |
505 | | | 505 | |
506 | void | | 506 | void |
507 | default_label(void) | | 507 | default_label(void) |
508 | { | | 508 | { |
509 | cstk_t *ci; | | 509 | cstk_t *ci; |
510 | | | 510 | |
511 | /* find the stack entry for the innermost switch statement */ | | 511 | /* find the stack entry for the innermost switch statement */ |
512 | for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next) | | 512 | for (ci = cstmt; ci != NULL && !ci->c_switch; ci = ci->c_surrounding) |
513 | continue; | | 513 | continue; |
514 | | | 514 | |
515 | if (ci == NULL) { | | 515 | if (ci == NULL) { |
516 | /* default outside switch */ | | 516 | /* default outside switch */ |
517 | error(201); | | 517 | error(201); |
518 | } else if (ci->c_default) { | | 518 | } else if (ci->c_default) { |
519 | /* duplicate default in switch */ | | 519 | /* duplicate default in switch */ |
520 | error(202); | | 520 | error(202); |
521 | } else { | | 521 | } else { |
522 | if (reached && !ftflg) { | | 522 | if (reached && !ftflg) { |
523 | if (hflag) | | 523 | if (hflag) |
524 | /* fallthrough on default statement */ | | 524 | /* fallthrough on default statement */ |
525 | warning(284); | | 525 | warning(284); |
526 | } | | 526 | } |
527 | ci->c_default = 1; | | 527 | ci->c_default = 1; |
528 | } | | 528 | } |
529 | | | 529 | |
530 | reached = 1; | | 530 | reached = 1; |
531 | } | | 531 | } |
532 | | | 532 | |
533 | static tnode_t * | | 533 | static tnode_t * |
534 | check_controlling_expression(tnode_t *tn) | | 534 | check_controlling_expression(tnode_t *tn) |
535 | { | | 535 | { |
536 | tspec_t t = tn->tn_type->t_tspec; | | 536 | tspec_t t = tn->tn_type->t_tspec; |
537 | | | 537 | |
538 | if (tn != NULL) | | 538 | if (tn != NULL) |
539 | tn = cconv(tn); | | 539 | tn = cconv(tn); |
540 | if (tn != NULL) | | 540 | if (tn != NULL) |
541 | tn = promote(NOOP, 0, tn); | | 541 | tn = promote(NOOP, 0, tn); |
542 | | | 542 | |
543 | if (tn != NULL && !tspec_is_scalar(t)) { | | 543 | if (tn != NULL && !tspec_is_scalar(t)) { |
544 | /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */ | | 544 | /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */ |
545 | /* C99 6.8.4.1p1 for if statements */ | | 545 | /* C99 6.8.4.1p1 for if statements */ |
546 | /* C99 6.8.5p2 for while, do and for loops */ | | 546 | /* C99 6.8.5p2 for while, do and for loops */ |
547 | /* controlling expressions must have scalar type */ | | 547 | /* controlling expressions must have scalar type */ |
548 | error(204); | | 548 | error(204); |
549 | return NULL; | | 549 | return NULL; |
550 | } | | 550 | } |
551 | | | 551 | |
552 | return tn; | | 552 | return tn; |
553 | } | | 553 | } |
554 | | | 554 | |
555 | /* | | 555 | /* |
556 | * T_IF T_LPAREN expr T_RPAREN | | 556 | * T_IF T_LPAREN expr T_RPAREN |
557 | */ | | 557 | */ |
558 | void | | 558 | void |
559 | if1(tnode_t *tn) | | 559 | if1(tnode_t *tn) |
560 | { | | 560 | { |
561 | | | 561 | |
562 | if (tn != NULL) | | 562 | if (tn != NULL) |
563 | tn = check_controlling_expression(tn); | | 563 | tn = check_controlling_expression(tn); |
564 | if (tn != NULL) | | 564 | if (tn != NULL) |
565 | expr(tn, 0, 1, 0); | | 565 | expr(tn, 0, 1, 0); |
566 | pushctrl(T_IF); | | 566 | pushctrl(T_IF); |
567 | } | | 567 | } |
568 | | | 568 | |
569 | /* | | 569 | /* |
570 | * if_without_else | | 570 | * if_without_else |
571 | * if_without_else T_ELSE | | 571 | * if_without_else T_ELSE |
572 | */ | | 572 | */ |
573 | void | | 573 | void |
574 | if2(void) | | 574 | if2(void) |
575 | { | | 575 | { |
576 | | | 576 | |
577 | cstk->c_rchif = reached ? 1 : 0; | | 577 | cstmt->c_rchif = reached ? 1 : 0; |
578 | reached = 1; | | 578 | reached = 1; |
579 | } | | 579 | } |
580 | | | 580 | |
581 | /* | | 581 | /* |
582 | * if_without_else | | 582 | * if_without_else |
583 | * if_without_else T_ELSE stmnt | | 583 | * if_without_else T_ELSE stmnt |
584 | */ | | 584 | */ |
585 | void | | 585 | void |
586 | if3(int els) | | 586 | if3(int els) |
587 | { | | 587 | { |
588 | | | 588 | |
589 | if (els) { | | 589 | if (els) { |
590 | reached |= cstk->c_rchif; | | 590 | reached |= cstmt->c_rchif; |
591 | } else { | | 591 | } else { |
592 | reached = 1; | | 592 | reached = 1; |
593 | } | | 593 | } |
594 | popctrl(T_IF); | | 594 | popctrl(T_IF); |
595 | } | | 595 | } |
596 | | | 596 | |
597 | /* | | 597 | /* |
598 | * T_SWITCH T_LPAREN expr T_RPAREN | | 598 | * T_SWITCH T_LPAREN expr T_RPAREN |
599 | */ | | 599 | */ |
600 | void | | 600 | void |
601 | switch1(tnode_t *tn) | | 601 | switch1(tnode_t *tn) |
602 | { | | 602 | { |
603 | tspec_t t; | | 603 | tspec_t t; |
604 | type_t *tp; | | 604 | type_t *tp; |
605 | | | 605 | |
606 | if (tn != NULL) | | 606 | if (tn != NULL) |
607 | tn = cconv(tn); | | 607 | tn = cconv(tn); |
608 | if (tn != NULL) | | 608 | if (tn != NULL) |
609 | tn = promote(NOOP, 0, tn); | | 609 | tn = promote(NOOP, 0, tn); |
610 | if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { | | 610 | if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { |
611 | /* switch expression must have integral type */ | | 611 | /* switch expression must have integral type */ |
612 | error(205); | | 612 | error(205); |
613 | tn = NULL; | | 613 | tn = NULL; |
614 | } | | 614 | } |
615 | if (tn != NULL && tflag) { | | 615 | if (tn != NULL && tflag) { |
616 | t = tn->tn_type->t_tspec; | | 616 | t = tn->tn_type->t_tspec; |
617 | if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) { | | 617 | if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) { |
618 | /* switch expr. must be of type `int' in trad. C */ | | 618 | /* switch expr. must be of type `int' in trad. C */ |
619 | warning(271); | | 619 | warning(271); |
620 | } | | 620 | } |
621 | } | | 621 | } |
622 | | | 622 | |
623 | /* | | 623 | /* |
624 | * Remember the type of the expression. Because it's possible | | 624 | * Remember the type of the expression. Because it's possible |
625 | * that (*tp) is allocated on tree memory, the type must be | | 625 | * that (*tp) is allocated on tree memory, the type must be |
626 | * duplicated. This is not too complicated because it is | | 626 | * duplicated. This is not too complicated because it is |
627 | * only an integer type. | | 627 | * only an integer type. |
628 | */ | | 628 | */ |
629 | tp = xcalloc(1, sizeof (type_t)); | | 629 | tp = xcalloc(1, sizeof (type_t)); |
630 | if (tn != NULL) { | | 630 | if (tn != NULL) { |
631 | tp->t_tspec = tn->tn_type->t_tspec; | | 631 | tp->t_tspec = tn->tn_type->t_tspec; |
632 | if ((tp->t_isenum = tn->tn_type->t_isenum) != 0) | | 632 | if ((tp->t_isenum = tn->tn_type->t_isenum) != 0) |
633 | tp->t_enum = tn->tn_type->t_enum; | | 633 | tp->t_enum = tn->tn_type->t_enum; |
634 | } else { | | 634 | } else { |
635 | tp->t_tspec = INT; | | 635 | tp->t_tspec = INT; |
636 | } | | 636 | } |
637 | | | 637 | |
638 | expr(tn, 1, 0, 1); | | 638 | expr(tn, 1, 0, 1); |
639 | | | 639 | |
640 | pushctrl(T_SWITCH); | | 640 | pushctrl(T_SWITCH); |
641 | cstk->c_switch = 1; | | 641 | cstmt->c_switch = 1; |
642 | cstk->c_swtype = tp; | | 642 | cstmt->c_swtype = tp; |
643 | | | 643 | |
644 | reached = rchflg = 0; | | 644 | reached = rchflg = 0; |
645 | ftflg = 1; | | 645 | ftflg = 1; |
646 | } | | 646 | } |
647 | | | 647 | |
648 | /* | | 648 | /* |
649 | * switch_expr stmnt | | 649 | * switch_expr stmnt |
650 | */ | | 650 | */ |
651 | void | | 651 | void |
652 | switch2(void) | | 652 | switch2(void) |
653 | { | | 653 | { |
654 | int nenum = 0, nclab = 0; | | 654 | int nenum = 0, nclab = 0; |
655 | sym_t *esym; | | 655 | sym_t *esym; |
656 | clst_t *cl; | | 656 | clst_t *cl; |
657 | | | 657 | |
658 | lint_assert(cstk->c_swtype != NULL); | | 658 | lint_assert(cstmt->c_swtype != NULL); |
659 | | | 659 | |
660 | /* | | 660 | /* |
661 | * If the switch expression was of type enumeration, count the case | | 661 | * If the switch expression was of type enumeration, count the case |
662 | * labels and the number of enumerators. If both counts are not | | 662 | * labels and the number of enumerators. If both counts are not |
663 | * equal print a warning. | | 663 | * equal print a warning. |
664 | */ | | 664 | */ |
665 | if (cstk->c_swtype->t_isenum) { | | 665 | if (cstmt->c_swtype->t_isenum) { |
666 | nenum = nclab = 0; | | 666 | nenum = nclab = 0; |
667 | lint_assert(cstk->c_swtype->t_enum != NULL); | | 667 | lint_assert(cstmt->c_swtype->t_enum != NULL); |
668 | for (esym = cstk->c_swtype->t_enum->elem; | | 668 | for (esym = cstmt->c_swtype->t_enum->elem; |
669 | esym != NULL; esym = esym->s_next) { | | 669 | esym != NULL; esym = esym->s_next) { |
670 | nenum++; | | 670 | nenum++; |
671 | } | | 671 | } |
672 | for (cl = cstk->c_clst; cl != NULL; cl = cl->cl_next) | | 672 | for (cl = cstmt->c_clst; cl != NULL; cl = cl->cl_next) |
673 | nclab++; | | 673 | nclab++; |
674 | if (hflag && eflag && nenum != nclab && !cstk->c_default) { | | 674 | if (hflag && eflag && nenum != nclab && !cstmt->c_default) { |
675 | /* enumeration value(s) not handled in switch */ | | 675 | /* enumeration value(s) not handled in switch */ |
676 | warning(206); | | 676 | warning(206); |
677 | } | | 677 | } |
678 | } | | 678 | } |
679 | | | 679 | |
680 | if (cstk->c_break) { | | 680 | if (cstmt->c_break) { |
681 | /* | | 681 | /* |
682 | * end of switch alway reached (c_break is only set if the | | 682 | * end of switch alway reached (c_break is only set if the |
683 | * break statement can be reached). | | 683 | * break statement can be reached). |
684 | */ | | 684 | */ |
685 | reached = 1; | | 685 | reached = 1; |
686 | } else if (!cstk->c_default && | | 686 | } else if (!cstmt->c_default && |
687 | (!hflag || !cstk->c_swtype->t_isenum || nenum != nclab)) { | | 687 | (!hflag || !cstmt->c_swtype->t_isenum || nenum != nclab)) { |
688 | /* | | 688 | /* |
689 | * there are possible values which are not handled in | | 689 | * there are possible values which are not handled in |
690 | * switch | | 690 | * switch |
691 | */ | | 691 | */ |
692 | reached = 1; | | 692 | reached = 1; |
693 | } /* | | 693 | } /* |
694 | * otherwise the end of the switch expression is reached | | 694 | * otherwise the end of the switch expression is reached |
695 | * if the end of the last statement inside it is reached. | | 695 | * if the end of the last statement inside it is reached. |
696 | */ | | 696 | */ |
697 | | | 697 | |
698 | popctrl(T_SWITCH); | | 698 | popctrl(T_SWITCH); |
699 | } | | 699 | } |
700 | | | 700 | |
701 | /* | | 701 | /* |
702 | * T_WHILE T_LPAREN expr T_RPAREN | | 702 | * T_WHILE T_LPAREN expr T_RPAREN |
703 | */ | | 703 | */ |
704 | void | | 704 | void |
705 | while1(tnode_t *tn) | | 705 | while1(tnode_t *tn) |
706 | { | | 706 | { |
707 | | | 707 | |
708 | if (!reached) { | | 708 | if (!reached) { |
709 | /* loop not entered at top */ | | 709 | /* loop not entered at top */ |
710 | warning(207); | | 710 | warning(207); |
711 | reached = 1; | | 711 | reached = 1; |
712 | } | | 712 | } |
713 | | | 713 | |
714 | if (tn != NULL) | | 714 | if (tn != NULL) |
715 | tn = check_controlling_expression(tn); | | 715 | tn = check_controlling_expression(tn); |
716 | | | 716 | |
717 | pushctrl(T_WHILE); | | 717 | pushctrl(T_WHILE); |
718 | cstk->c_loop = 1; | | 718 | cstmt->c_loop = 1; |
719 | if (tn != NULL && tn->tn_op == CON) { | | 719 | if (tn != NULL && tn->tn_op == CON) { |
720 | if (tspec_is_int(tn->tn_type->t_tspec)) { | | 720 | if (tspec_is_int(tn->tn_type->t_tspec)) { |
721 | cstk->c_infinite = tn->tn_val->v_quad != 0; | | 721 | cstmt->c_infinite = tn->tn_val->v_quad != 0; |
722 | } else { | | 722 | } else { |
723 | cstk->c_infinite = tn->tn_val->v_ldbl != 0.0; | | 723 | cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0; |
724 | } | | 724 | } |
725 | } | | 725 | } |
726 | | | 726 | |
727 | expr(tn, 0, 1, 1); | | 727 | expr(tn, 0, 1, 1); |
728 | } | | 728 | } |
729 | | | 729 | |
730 | /* | | 730 | /* |
731 | * while_expr stmnt | | 731 | * while_expr stmnt |
732 | * while_expr error | | 732 | * while_expr error |
733 | */ | | 733 | */ |
734 | void | | 734 | void |
735 | while2(void) | | 735 | while2(void) |
736 | { | | 736 | { |
737 | | | 737 | |
738 | /* | | 738 | /* |
739 | * The end of the loop can be reached if it is no endless loop | | 739 | * The end of the loop can be reached if it is no endless loop |
740 | * or there was a break statement which was reached. | | 740 | * or there was a break statement which was reached. |
741 | */ | | 741 | */ |
742 | reached = !cstk->c_infinite || cstk->c_break; | | 742 | reached = !cstmt->c_infinite || cstmt->c_break; |
743 | rchflg = 0; | | 743 | rchflg = 0; |
744 | | | 744 | |
745 | popctrl(T_WHILE); | | 745 | popctrl(T_WHILE); |
746 | } | | 746 | } |
747 | | | 747 | |
748 | /* | | 748 | /* |
749 | * T_DO | | 749 | * T_DO |
750 | */ | | 750 | */ |
751 | void | | 751 | void |
752 | do1(void) | | 752 | do1(void) |
753 | { | | 753 | { |
754 | | | 754 | |
755 | if (!reached) { | | 755 | if (!reached) { |
756 | /* loop not entered at top */ | | 756 | /* loop not entered at top */ |
757 | warning(207); | | 757 | warning(207); |
758 | reached = 1; | | 758 | reached = 1; |
759 | } | | 759 | } |
760 | | | 760 | |
761 | pushctrl(T_DO); | | 761 | pushctrl(T_DO); |
762 | cstk->c_loop = 1; | | 762 | cstmt->c_loop = 1; |
763 | } | | 763 | } |
764 | | | 764 | |
765 | /* | | 765 | /* |
766 | * do stmnt do_while_expr | | 766 | * do stmnt do_while_expr |
767 | * do error | | 767 | * do error |
768 | */ | | 768 | */ |
769 | void | | 769 | void |
770 | do2(tnode_t *tn) | | 770 | do2(tnode_t *tn) |
771 | { | | 771 | { |
772 | | | 772 | |
773 | /* | | 773 | /* |
774 | * If there was a continue statement, the expression controlling the | | 774 | * If there was a continue statement, the expression controlling the |
775 | * loop is reached. | | 775 | * loop is reached. |
776 | */ | | 776 | */ |
777 | if (cstk->c_cont) | | 777 | if (cstmt->c_cont) |
778 | reached = 1; | | 778 | reached = 1; |
779 | | | 779 | |
780 | if (tn != NULL) | | 780 | if (tn != NULL) |
781 | tn = check_controlling_expression(tn); | | 781 | tn = check_controlling_expression(tn); |
782 | | | 782 | |
783 | if (tn != NULL && tn->tn_op == CON) { | | 783 | if (tn != NULL && tn->tn_op == CON) { |
784 | if (tspec_is_int(tn->tn_type->t_tspec)) { | | 784 | if (tspec_is_int(tn->tn_type->t_tspec)) { |
785 | cstk->c_infinite = tn->tn_val->v_quad != 0; | | 785 | cstmt->c_infinite = tn->tn_val->v_quad != 0; |
786 | } else { | | 786 | } else { |
787 | cstk->c_infinite = tn->tn_val->v_ldbl != 0.0; | | 787 | cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0; |
788 | } | | 788 | } |
789 | if (!cstk->c_infinite && cstk->c_cont) | | 789 | if (!cstmt->c_infinite && cstmt->c_cont) |
790 | /* continue in 'do ... while (0)' loop */ | | 790 | /* continue in 'do ... while (0)' loop */ |
791 | error(323); | | 791 | error(323); |
792 | } | | 792 | } |
793 | | | 793 | |
794 | expr(tn, 0, 1, 1); | | 794 | expr(tn, 0, 1, 1); |
795 | | | 795 | |
796 | /* | | 796 | /* |
797 | * The end of the loop is only reached if it is no endless loop | | 797 | * The end of the loop is only reached if it is no endless loop |
798 | * or there was a break statement which could be reached. | | 798 | * or there was a break statement which could be reached. |
799 | */ | | 799 | */ |
800 | reached = !cstk->c_infinite || cstk->c_break; | | 800 | reached = !cstmt->c_infinite || cstmt->c_break; |
801 | rchflg = 0; | | 801 | rchflg = 0; |
802 | | | 802 | |
803 | popctrl(T_DO); | | 803 | popctrl(T_DO); |
804 | } | | 804 | } |
805 | | | 805 | |
806 | /* | | 806 | /* |
807 | * T_FOR T_LPAREN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPAREN | | 807 | * T_FOR T_LPAREN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPAREN |
808 | */ | | 808 | */ |
809 | void | | 809 | void |
810 | for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3) | | 810 | for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3) |
811 | { | | 811 | { |
812 | | | 812 | |
813 | /* | | 813 | /* |
814 | * If there is no initialisation expression it is possible that | | 814 | * If there is no initialisation expression it is possible that |
815 | * it is intended not to enter the loop at top. | | 815 | * it is intended not to enter the loop at top. |
816 | */ | | 816 | */ |
817 | if (tn1 != NULL && !reached) { | | 817 | if (tn1 != NULL && !reached) { |
818 | /* loop not entered at top */ | | 818 | /* loop not entered at top */ |
819 | warning(207); | | 819 | warning(207); |
820 | reached = 1; | | 820 | reached = 1; |
821 | } | | 821 | } |
822 | | | 822 | |
823 | pushctrl(T_FOR); | | 823 | pushctrl(T_FOR); |
824 | cstk->c_loop = 1; | | 824 | cstmt->c_loop = 1; |
825 | | | 825 | |
826 | /* | | 826 | /* |
827 | * Store the tree memory for the reinitialisation expression. | | 827 | * Store the tree memory for the reinitialisation expression. |
828 | * Also remember this expression itself. We must check it at | | 828 | * Also remember this expression itself. We must check it at |
829 | * the end of the loop to get "used but not set" warnings correct. | | 829 | * the end of the loop to get "used but not set" warnings correct. |
830 | */ | | 830 | */ |
831 | cstk->c_fexprm = tsave(); | | 831 | cstmt->c_fexprm = tsave(); |
832 | cstk->c_f3expr = tn3; | | 832 | cstmt->c_f3expr = tn3; |
833 | cstk->c_fpos = curr_pos; | | 833 | cstmt->c_fpos = curr_pos; |
834 | cstk->c_cfpos = csrc_pos; | | 834 | cstmt->c_cfpos = csrc_pos; |
835 | | | 835 | |
836 | if (tn1 != NULL) | | 836 | if (tn1 != NULL) |
837 | expr(tn1, 0, 0, 1); | | 837 | expr(tn1, 0, 0, 1); |
838 | | | 838 | |
839 | if (tn2 != NULL) | | 839 | if (tn2 != NULL) |
840 | tn2 = check_controlling_expression(tn2); | | 840 | tn2 = check_controlling_expression(tn2); |
841 | if (tn2 != NULL) | | 841 | if (tn2 != NULL) |
842 | expr(tn2, 0, 1, 1); | | 842 | expr(tn2, 0, 1, 1); |
843 | | | 843 | |
844 | if (tn2 == NULL) { | | 844 | if (tn2 == NULL) { |
845 | cstk->c_infinite = 1; | | 845 | cstmt->c_infinite = 1; |
846 | } else if (tn2->tn_op == CON) { | | 846 | } else if (tn2->tn_op == CON) { |
847 | if (tspec_is_int(tn2->tn_type->t_tspec)) { | | 847 | if (tspec_is_int(tn2->tn_type->t_tspec)) { |
848 | cstk->c_infinite = tn2->tn_val->v_quad != 0; | | 848 | cstmt->c_infinite = tn2->tn_val->v_quad != 0; |
849 | } else { | | 849 | } else { |
850 | cstk->c_infinite = tn2->tn_val->v_ldbl != 0.0; | | 850 | cstmt->c_infinite = tn2->tn_val->v_ldbl != 0.0; |
851 | } | | 851 | } |
852 | } | | 852 | } |
853 | | | 853 | |
854 | /* Checking the reinitialisation expression is done in for2() */ | | 854 | /* Checking the reinitialisation expression is done in for2() */ |
855 | | | 855 | |
856 | reached = 1; | | 856 | reached = 1; |
857 | } | | 857 | } |
858 | | | 858 | |
859 | /* | | 859 | /* |
860 | * for_exprs stmnt | | 860 | * for_exprs stmnt |
861 | * for_exprs error | | 861 | * for_exprs error |
862 | */ | | 862 | */ |
863 | void | | 863 | void |
864 | for2(void) | | 864 | for2(void) |
865 | { | | 865 | { |
866 | pos_t cpos, cspos; | | 866 | pos_t cpos, cspos; |
867 | tnode_t *tn3; | | 867 | tnode_t *tn3; |
868 | | | 868 | |
869 | if (cstk->c_cont) | | 869 | if (cstmt->c_cont) |
870 | reached = 1; | | 870 | reached = 1; |
871 | | | 871 | |
872 | cpos = curr_pos; | | 872 | cpos = curr_pos; |
873 | cspos = csrc_pos; | | 873 | cspos = csrc_pos; |
874 | | | 874 | |
875 | /* Restore the tree memory for the reinitialisation expression */ | | 875 | /* Restore the tree memory for the reinitialisation expression */ |
876 | trestor(cstk->c_fexprm); | | 876 | trestor(cstmt->c_fexprm); |
877 | tn3 = cstk->c_f3expr; | | 877 | tn3 = cstmt->c_f3expr; |
878 | curr_pos = cstk->c_fpos; | | 878 | curr_pos = cstmt->c_fpos; |
879 | csrc_pos = cstk->c_cfpos; | | 879 | csrc_pos = cstmt->c_cfpos; |
880 | | | 880 | |
881 | /* simply "statement not reached" would be confusing */ | | 881 | /* simply "statement not reached" would be confusing */ |
882 | if (!reached && !rchflg) { | | 882 | if (!reached && !rchflg) { |
883 | /* end-of-loop code not reached */ | | 883 | /* end-of-loop code not reached */ |
884 | warning(223); | | 884 | warning(223); |
885 | reached = 1; | | 885 | reached = 1; |
886 | } | | 886 | } |
887 | | | 887 | |
888 | if (tn3 != NULL) { | | 888 | if (tn3 != NULL) { |
889 | expr(tn3, 0, 0, 1); | | 889 | expr(tn3, 0, 0, 1); |
890 | } else { | | 890 | } else { |
891 | tfreeblk(); | | 891 | tfreeblk(); |
892 | } | | 892 | } |
893 | | | 893 | |
894 | curr_pos = cpos; | | 894 | curr_pos = cpos; |
895 | csrc_pos = cspos; | | 895 | csrc_pos = cspos; |
896 | | | 896 | |
897 | /* An endless loop without break will never terminate */ | | 897 | /* An endless loop without break will never terminate */ |
898 | reached = cstk->c_break || !cstk->c_infinite; | | 898 | reached = cstmt->c_break || !cstmt->c_infinite; |
899 | rchflg = 0; | | 899 | rchflg = 0; |
900 | | | 900 | |
901 | popctrl(T_FOR); | | 901 | popctrl(T_FOR); |
902 | } | | 902 | } |
903 | | | 903 | |
904 | /* | | 904 | /* |
905 | * T_GOTO identifier T_SEMI | | 905 | * T_GOTO identifier T_SEMI |
906 | * T_GOTO error T_SEMI | | 906 | * T_GOTO error T_SEMI |
907 | */ | | 907 | */ |
908 | void | | 908 | void |
909 | dogoto(sym_t *lab) | | 909 | dogoto(sym_t *lab) |
910 | { | | 910 | { |
911 | | | 911 | |
912 | mark_as_used(lab, 0, 0); | | 912 | mark_as_used(lab, 0, 0); |
913 | | | 913 | |
914 | check_statement_reachable(); | | 914 | check_statement_reachable(); |
915 | | | 915 | |
916 | reached = rchflg = 0; | | 916 | reached = rchflg = 0; |
917 | } | | 917 | } |
918 | | | 918 | |
919 | /* | | 919 | /* |
920 | * T_BREAK T_SEMI | | 920 | * T_BREAK T_SEMI |
921 | */ | | 921 | */ |
922 | void | | 922 | void |
923 | dobreak(void) | | 923 | dobreak(void) |
924 | { | | 924 | { |
925 | cstk_t *ci; | | 925 | cstk_t *ci; |
926 | | | 926 | |
927 | ci = cstk; | | 927 | ci = cstmt; |
928 | while (ci != NULL && !ci->c_loop && !ci->c_switch) | | 928 | while (ci != NULL && !ci->c_loop && !ci->c_switch) |
929 | ci = ci->c_next; | | 929 | ci = ci->c_surrounding; |
930 | | | 930 | |
931 | if (ci == NULL) { | | 931 | if (ci == NULL) { |
932 | /* break outside loop or switch */ | | 932 | /* break outside loop or switch */ |
933 | error(208); | | 933 | error(208); |
934 | } else { | | 934 | } else { |
935 | if (reached) | | 935 | if (reached) |
936 | ci->c_break = 1; | | 936 | ci->c_break = 1; |
937 | } | | 937 | } |
938 | | | 938 | |
939 | if (bflag) | | 939 | if (bflag) |
940 | check_statement_reachable(); | | 940 | check_statement_reachable(); |
941 | | | 941 | |
942 | reached = rchflg = 0; | | 942 | reached = rchflg = 0; |
943 | } | | 943 | } |
944 | | | 944 | |
945 | /* | | 945 | /* |
946 | * T_CONTINUE T_SEMI | | 946 | * T_CONTINUE T_SEMI |
947 | */ | | 947 | */ |
948 | void | | 948 | void |
949 | docont(void) | | 949 | docont(void) |
950 | { | | 950 | { |
951 | cstk_t *ci; | | 951 | cstk_t *ci; |
952 | | | 952 | |
953 | for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_next) | | 953 | for (ci = cstmt; ci != NULL && !ci->c_loop; ci = ci->c_surrounding) |
954 | continue; | | 954 | continue; |
955 | | | 955 | |
956 | if (ci == NULL) { | | 956 | if (ci == NULL) { |
957 | /* continue outside loop */ | | 957 | /* continue outside loop */ |
958 | error(209); | | 958 | error(209); |
959 | } else { | | 959 | } else { |
960 | ci->c_cont = 1; | | 960 | ci->c_cont = 1; |
961 | } | | 961 | } |
962 | | | 962 | |
963 | check_statement_reachable(); | | 963 | check_statement_reachable(); |
964 | | | 964 | |
965 | reached = rchflg = 0; | | 965 | reached = rchflg = 0; |
966 | } | | 966 | } |
967 | | | 967 | |
968 | /* | | 968 | /* |
969 | * T_RETURN T_SEMI | | 969 | * T_RETURN T_SEMI |
970 | * T_RETURN expr T_SEMI | | 970 | * T_RETURN expr T_SEMI |
971 | */ | | 971 | */ |
972 | void | | 972 | void |
973 | doreturn(tnode_t *tn) | | 973 | doreturn(tnode_t *tn) |
974 | { | | 974 | { |
975 | tnode_t *ln, *rn; | | 975 | tnode_t *ln, *rn; |
976 | cstk_t *ci; | | 976 | cstk_t *ci; |
977 | op_t op; | | 977 | op_t op; |
978 | | | 978 | |
979 | for (ci = cstk; ci->c_next != NULL; ci = ci->c_next) | | 979 | for (ci = cstmt; ci->c_surrounding != NULL; ci = ci->c_surrounding) |
980 | continue; | | 980 | continue; |
981 | | | 981 | |
982 | if (tn != NULL) { | | 982 | if (tn != NULL) { |
983 | ci->c_retval = 1; | | 983 | ci->c_retval = 1; |
984 | } else { | | 984 | } else { |
985 | ci->c_noretval = 1; | | 985 | ci->c_noretval = 1; |
986 | } | | 986 | } |
987 | | | 987 | |
988 | if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { | | 988 | if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { |
989 | /* void function %s cannot return value */ | | 989 | /* void function %s cannot return value */ |
990 | error(213, funcsym->s_name); | | 990 | error(213, funcsym->s_name); |
991 | tfreeblk(); | | 991 | tfreeblk(); |
992 | tn = NULL; | | 992 | tn = NULL; |
993 | } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) { | | 993 | } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) { |
994 | /* | | 994 | /* |
995 | * Assume that the function has a return value only if it | | 995 | * Assume that the function has a return value only if it |
996 | * is explicitly declared. | | 996 | * is explicitly declared. |
997 | */ | | 997 | */ |
998 | if (!funcsym->s_rimpl) | | 998 | if (!funcsym->s_rimpl) |
999 | /* function %s expects to return value */ | | 999 | /* function %s expects to return value */ |
1000 | warning(214, funcsym->s_name); | | 1000 | warning(214, funcsym->s_name); |
1001 | } | | 1001 | } |
1002 | | | 1002 | |
1003 | if (tn != NULL) { | | 1003 | if (tn != NULL) { |
1004 | | | 1004 | |
1005 | /* Create a temporary node for the left side */ | | 1005 | /* Create a temporary node for the left side */ |
1006 | ln = tgetblk(sizeof (tnode_t)); | | 1006 | ln = tgetblk(sizeof (tnode_t)); |
1007 | ln->tn_op = NAME; | | 1007 | ln->tn_op = NAME; |
1008 | ln->tn_type = tduptyp(funcsym->s_type->t_subt); | | 1008 | ln->tn_type = tduptyp(funcsym->s_type->t_subt); |
1009 | ln->tn_type->t_const = 0; | | 1009 | ln->tn_type->t_const = 0; |
1010 | ln->tn_lvalue = 1; | | 1010 | ln->tn_lvalue = 1; |
1011 | ln->tn_sym = funcsym; /* better than nothing */ | | 1011 | ln->tn_sym = funcsym; /* better than nothing */ |
1012 | | | 1012 | |
1013 | tn = build(RETURN, ln, tn); | | 1013 | tn = build(RETURN, ln, tn); |
1014 | | | 1014 | |
1015 | if (tn != NULL) { | | 1015 | if (tn != NULL) { |
1016 | rn = tn->tn_right; | | 1016 | rn = tn->tn_right; |
1017 | while ((op = rn->tn_op) == CVT || op == PLUS) | | 1017 | while ((op = rn->tn_op) == CVT || op == PLUS) |
1018 | rn = rn->tn_left; | | 1018 | rn = rn->tn_left; |
1019 | if (rn->tn_op == AMPER && rn->tn_left->tn_op == NAME && | | 1019 | if (rn->tn_op == AMPER && rn->tn_left->tn_op == NAME && |
1020 | rn->tn_left->tn_sym->s_scl == AUTO) { | | 1020 | rn->tn_left->tn_sym->s_scl == AUTO) { |
1021 | /* %s returns pointer to automatic object */ | | 1021 | /* %s returns pointer to automatic object */ |
1022 | warning(302, funcsym->s_name); | | 1022 | warning(302, funcsym->s_name); |
1023 | } | | 1023 | } |
1024 | } | | 1024 | } |
1025 | | | 1025 | |
1026 | expr(tn, 1, 0, 1); | | 1026 | expr(tn, 1, 0, 1); |
1027 | | | 1027 | |
1028 | } else { | | 1028 | } else { |
1029 | | | 1029 | |
1030 | check_statement_reachable(); | | 1030 | check_statement_reachable(); |
1031 | | | 1031 | |
1032 | } | | 1032 | } |
1033 | | | 1033 | |
1034 | reached = rchflg = 0; | | 1034 | reached = rchflg = 0; |
1035 | } | | 1035 | } |
1036 | | | 1036 | |
1037 | /* | | 1037 | /* |
1038 | * Do some cleanup after a global declaration or definition. | | 1038 | * Do some cleanup after a global declaration or definition. |
1039 | * Especially remove information about unused lint comments. | | 1039 | * Especially remove information about unused lint comments. |
1040 | */ | | 1040 | */ |
1041 | void | | 1041 | void |
1042 | global_clean_up_decl(int silent) | | 1042 | global_clean_up_decl(int silent) |
1043 | { | | 1043 | { |
1044 | pos_t cpos; | | 1044 | pos_t cpos; |
1045 | | | 1045 | |
1046 | cpos = curr_pos; | | 1046 | cpos = curr_pos; |
1047 | | | 1047 | |
1048 | if (nargusg != -1) { | | 1048 | if (nargusg != -1) { |
1049 | if (!silent) { | | 1049 | if (!silent) { |
1050 | curr_pos = argsused_pos; | | 1050 | curr_pos = argsused_pos; |
1051 | /* must precede function definition: ** %s ** */ | | 1051 | /* must precede function definition: ** %s ** */ |
1052 | warning(282, "ARGSUSED"); | | 1052 | warning(282, "ARGSUSED"); |
1053 | } | | 1053 | } |
1054 | nargusg = -1; | | 1054 | nargusg = -1; |
1055 | } | | 1055 | } |
1056 | if (nvararg != -1) { | | 1056 | if (nvararg != -1) { |
1057 | if (!silent) { | | 1057 | if (!silent) { |
1058 | curr_pos = vapos; | | 1058 | curr_pos = vapos; |
1059 | /* must precede function definition: ** %s ** */ | | 1059 | /* must precede function definition: ** %s ** */ |
1060 | warning(282, "VARARGS"); | | 1060 | warning(282, "VARARGS"); |
1061 | } | | 1061 | } |
1062 | nvararg = -1; | | 1062 | nvararg = -1; |
1063 | } | | 1063 | } |
1064 | if (prflstrg != -1) { | | 1064 | if (prflstrg != -1) { |
1065 | if (!silent) { | | 1065 | if (!silent) { |
1066 | curr_pos = printflike_pos; | | 1066 | curr_pos = printflike_pos; |
1067 | /* must precede function definition: ** %s ** */ | | 1067 | /* must precede function definition: ** %s ** */ |
1068 | warning(282, "PRINTFLIKE"); | | 1068 | warning(282, "PRINTFLIKE"); |
1069 | } | | 1069 | } |
1070 | prflstrg = -1; | | 1070 | prflstrg = -1; |
1071 | } | | 1071 | } |
1072 | if (scflstrg != -1) { | | 1072 | if (scflstrg != -1) { |
1073 | if (!silent) { | | 1073 | if (!silent) { |
1074 | curr_pos = scanflike_pos; | | 1074 | curr_pos = scanflike_pos; |
1075 | /* must precede function definition: ** %s ** */ | | 1075 | /* must precede function definition: ** %s ** */ |
1076 | warning(282, "SCANFLIKE"); | | 1076 | warning(282, "SCANFLIKE"); |
1077 | } | | 1077 | } |
1078 | scflstrg = -1; | | 1078 | scflstrg = -1; |
1079 | } | | 1079 | } |
1080 | | | 1080 | |
1081 | curr_pos = cpos; | | 1081 | curr_pos = cpos; |
1082 | | | 1082 | |
1083 | dcs->d_asm = 0; | | 1083 | dcs->d_asm = 0; |
1084 | } | | 1084 | } |
1085 | | | 1085 | |
1086 | /* | | 1086 | /* |
1087 | * ARGSUSED comment | | 1087 | * ARGSUSED comment |
1088 | * | | 1088 | * |
1089 | * Only the first n arguments of the following function are checked | | 1089 | * Only the first n arguments of the following function are checked |
1090 | * for usage. A missing argument is taken to be 0. | | 1090 | * for usage. A missing argument is taken to be 0. |
1091 | */ | | 1091 | */ |
1092 | void | | 1092 | void |
1093 | argsused(int n) | | 1093 | argsused(int n) |
1094 | { | | 1094 | { |
1095 | | | 1095 | |
1096 | if (n == -1) | | 1096 | if (n == -1) |
1097 | n = 0; | | 1097 | n = 0; |
1098 | | | 1098 | |
1099 | if (dcs->d_ctx != EXTERN) { | | 1099 | if (dcs->d_ctx != EXTERN) { |
1100 | /* must be outside function: ** %s ** */ | | 1100 | /* must be outside function: ** %s ** */ |
1101 | warning(280, "ARGSUSED"); | | 1101 | warning(280, "ARGSUSED"); |
1102 | return; | | 1102 | return; |
1103 | } | | 1103 | } |
1104 | if (nargusg != -1) { | | 1104 | if (nargusg != -1) { |
1105 | /* duplicate use of ** %s ** */ | | 1105 | /* duplicate use of ** %s ** */ |
1106 | warning(281, "ARGSUSED"); | | 1106 | warning(281, "ARGSUSED"); |
1107 | } | | 1107 | } |
1108 | nargusg = n; | | 1108 | nargusg = n; |
1109 | argsused_pos = curr_pos; | | 1109 | argsused_pos = curr_pos; |
1110 | } | | 1110 | } |
1111 | | | 1111 | |
1112 | /* | | 1112 | /* |
1113 | * VARARGS comment | | 1113 | * VARARGS comment |
1114 | * | | 1114 | * |
1115 | * Causes lint2 to check only the first n arguments for compatibility | | 1115 | * Causes lint2 to check only the first n arguments for compatibility |
1116 | * with the function definition. A missing argument is taken to be 0. | | 1116 | * with the function definition. A missing argument is taken to be 0. |
1117 | */ | | 1117 | */ |
1118 | void | | 1118 | void |
1119 | varargs(int n) | | 1119 | varargs(int n) |
1120 | { | | 1120 | { |
1121 | | | 1121 | |
1122 | if (n == -1) | | 1122 | if (n == -1) |
1123 | n = 0; | | 1123 | n = 0; |
1124 | | | 1124 | |
1125 | if (dcs->d_ctx != EXTERN) { | | 1125 | if (dcs->d_ctx != EXTERN) { |
1126 | /* must be outside function: ** %s ** */ | | 1126 | /* must be outside function: ** %s ** */ |
1127 | warning(280, "VARARGS"); | | 1127 | warning(280, "VARARGS"); |
1128 | return; | | 1128 | return; |
1129 | } | | 1129 | } |
1130 | if (nvararg != -1) { | | 1130 | if (nvararg != -1) { |
1131 | /* duplicate use of ** %s ** */ | | 1131 | /* duplicate use of ** %s ** */ |
1132 | warning(281, "VARARGS"); | | 1132 | warning(281, "VARARGS"); |
1133 | } | | 1133 | } |
1134 | nvararg = n; | | 1134 | nvararg = n; |
1135 | vapos = curr_pos; | | 1135 | vapos = curr_pos; |
1136 | } | | 1136 | } |
1137 | | | 1137 | |
1138 | /* | | 1138 | /* |
1139 | * PRINTFLIKE comment | | 1139 | * PRINTFLIKE comment |
1140 | * | | 1140 | * |
1141 | * Check all arguments until the (n-1)-th as usual. The n-th argument is | | 1141 | * Check all arguments until the (n-1)-th as usual. The n-th argument is |
1142 | * used the check the types of remaining arguments. | | 1142 | * used the check the types of remaining arguments. |
1143 | */ | | 1143 | */ |
1144 | void | | 1144 | void |
1145 | printflike(int n) | | 1145 | printflike(int n) |
1146 | { | | 1146 | { |
1147 | | | 1147 | |
1148 | if (n == -1) | | 1148 | if (n == -1) |
1149 | n = 0; | | 1149 | n = 0; |
1150 | | | 1150 | |
1151 | if (dcs->d_ctx != EXTERN) { | | 1151 | if (dcs->d_ctx != EXTERN) { |
1152 | /* must be outside function: ** %s ** */ | | 1152 | /* must be outside function: ** %s ** */ |
1153 | warning(280, "PRINTFLIKE"); | | 1153 | warning(280, "PRINTFLIKE"); |
1154 | return; | | 1154 | return; |
1155 | } | | 1155 | } |
1156 | if (prflstrg != -1) { | | 1156 | if (prflstrg != -1) { |
1157 | /* duplicate use of ** %s ** */ | | 1157 | /* duplicate use of ** %s ** */ |
1158 | warning(281, "PRINTFLIKE"); | | 1158 | warning(281, "PRINTFLIKE"); |
1159 | } | | 1159 | } |
1160 | prflstrg = n; | | 1160 | prflstrg = n; |
1161 | printflike_pos = curr_pos; | | 1161 | printflike_pos = curr_pos; |
1162 | } | | 1162 | } |
1163 | | | 1163 | |
1164 | /* | | 1164 | /* |
1165 | * SCANFLIKE comment | | 1165 | * SCANFLIKE comment |
1166 | * | | 1166 | * |
1167 | * Check all arguments until the (n-1)-th as usual. The n-th argument is | | 1167 | * Check all arguments until the (n-1)-th as usual. The n-th argument is |
1168 | * used the check the types of remaining arguments. | | 1168 | * used the check the types of remaining arguments. |
1169 | */ | | 1169 | */ |
1170 | void | | 1170 | void |
1171 | scanflike(int n) | | 1171 | scanflike(int n) |
1172 | { | | 1172 | { |
1173 | | | 1173 | |
1174 | if (n == -1) | | 1174 | if (n == -1) |
1175 | n = 0; | | 1175 | n = 0; |
1176 | | | 1176 | |
1177 | if (dcs->d_ctx != EXTERN) { | | 1177 | if (dcs->d_ctx != EXTERN) { |
1178 | /* must be outside function: ** %s ** */ | | 1178 | /* must be outside function: ** %s ** */ |
1179 | warning(280, "SCANFLIKE"); | | 1179 | warning(280, "SCANFLIKE"); |
1180 | return; | | 1180 | return; |
1181 | } | | 1181 | } |
1182 | if (scflstrg != -1) { | | 1182 | if (scflstrg != -1) { |
1183 | /* duplicate use of ** %s ** */ | | 1183 | /* duplicate use of ** %s ** */ |
1184 | warning(281, "SCANFLIKE"); | | 1184 | warning(281, "SCANFLIKE"); |
1185 | } | | 1185 | } |
1186 | scflstrg = n; | | 1186 | scflstrg = n; |
1187 | scanflike_pos = curr_pos; | | 1187 | scanflike_pos = curr_pos; |
1188 | } | | 1188 | } |
1189 | | | 1189 | |
1190 | /* | | 1190 | /* |
1191 | * Set the linenumber for a CONSTCOND comment. At this and the following | | 1191 | * Set the linenumber for a CONSTCOND comment. At this and the following |
1192 | * line no warnings about constants in conditional contexts are printed. | | 1192 | * line no warnings about constants in conditional contexts are printed. |
1193 | */ | | 1193 | */ |
1194 | /* ARGSUSED */ | | 1194 | /* ARGSUSED */ |
1195 | void | | 1195 | void |
1196 | constcond(int n) | | 1196 | constcond(int n) |
1197 | { | | 1197 | { |
1198 | | | 1198 | |
1199 | constcond_flag = 1; | | 1199 | constcond_flag = 1; |
1200 | } | | 1200 | } |
1201 | | | 1201 | |
1202 | /* | | 1202 | /* |
1203 | * Suppress printing of "fallthrough on ..." warnings until next | | 1203 | * Suppress printing of "fallthrough on ..." warnings until next |
1204 | * statement. | | 1204 | * statement. |
1205 | */ | | 1205 | */ |
1206 | /* ARGSUSED */ | | 1206 | /* ARGSUSED */ |
1207 | void | | 1207 | void |
1208 | fallthru(int n) | | 1208 | fallthru(int n) |
1209 | { | | 1209 | { |
1210 | | | 1210 | |
1211 | ftflg = 1; | | 1211 | ftflg = 1; |
1212 | } | | 1212 | } |
1213 | | | 1213 | |
1214 | /* | | 1214 | /* |
1215 | * Stop warnings about statements which cannot be reached. Also tells lint | | 1215 | * Stop warnings about statements which cannot be reached. Also tells lint |
1216 | * that the following statements cannot be reached (e.g. after exit()). | | 1216 | * that the following statements cannot be reached (e.g. after exit()). |
1217 | */ | | 1217 | */ |
1218 | /* ARGSUSED */ | | 1218 | /* ARGSUSED */ |
1219 | void | | 1219 | void |
1220 | notreach(int n) | | 1220 | notreach(int n) |
1221 | { | | 1221 | { |
1222 | | | 1222 | |
1223 | reached = 0; | | 1223 | reached = 0; |
1224 | rchflg = 1; | | 1224 | rchflg = 1; |
1225 | } | | 1225 | } |
1226 | | | 1226 | |
1227 | /* ARGSUSED */ | | 1227 | /* ARGSUSED */ |
1228 | void | | 1228 | void |
1229 | lintlib(int n) | | 1229 | lintlib(int n) |
1230 | { | | 1230 | { |
1231 | | | 1231 | |
1232 | if (dcs->d_ctx != EXTERN) { | | 1232 | if (dcs->d_ctx != EXTERN) { |
1233 | /* must be outside function: ** %s ** */ | | 1233 | /* must be outside function: ** %s ** */ |
1234 | warning(280, "LINTLIBRARY"); | | 1234 | warning(280, "LINTLIBRARY"); |
1235 | return; | | 1235 | return; |
1236 | } | | 1236 | } |
1237 | llibflg = 1; | | 1237 | llibflg = 1; |
1238 | vflag = 0; | | 1238 | vflag = 0; |
1239 | } | | 1239 | } |
1240 | | | 1240 | |
1241 | /* | | 1241 | /* |
1242 | * Suppress most warnings at the current and the following line. | | 1242 | * Suppress most warnings at the current and the following line. |
1243 | */ | | 1243 | */ |
1244 | /* ARGSUSED */ | | 1244 | /* ARGSUSED */ |
1245 | void | | 1245 | void |
1246 | linted(int n) | | 1246 | linted(int n) |
1247 | { | | 1247 | { |
1248 | | | 1248 | |
1249 | #ifdef DEBUG | | 1249 | #ifdef DEBUG |
1250 | printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, n); | | 1250 | printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, n); |
1251 | #endif | | 1251 | #endif |
1252 | lwarn = n; | | 1252 | lwarn = n; |
1253 | } | | 1253 | } |
1254 | | | 1254 | |
1255 | /* | | 1255 | /* |
1256 | * Suppress bitfield type errors on the current line. | | 1256 | * Suppress bitfield type errors on the current line. |
1257 | */ | | 1257 | */ |
1258 | /* ARGSUSED */ | | 1258 | /* ARGSUSED */ |
1259 | void | | 1259 | void |
1260 | bitfieldtype(int n) | | 1260 | bitfieldtype(int n) |
1261 | { | | 1261 | { |
1262 | | | 1262 | |
1263 | #ifdef DEBUG | | 1263 | #ifdef DEBUG |
1264 | printf("%s, %d: bitfieldtype_ok = true\n", curr_pos.p_file, | | 1264 | printf("%s, %d: bitfieldtype_ok = true\n", curr_pos.p_file, |
1265 | curr_pos.p_line); | | 1265 | curr_pos.p_line); |
1266 | #endif | | 1266 | #endif |
1267 | bitfieldtype_ok = true; | | 1267 | bitfieldtype_ok = true; |
1268 | } | | 1268 | } |
1269 | | | 1269 | |
1270 | /* | | 1270 | /* |
1271 | * PROTOLIB in conjunction with LINTLIBRARY can be used to handle | | 1271 | * PROTOLIB in conjunction with LINTLIBRARY can be used to handle |
1272 | * prototypes like function definitions. This is done if the argument | | 1272 | * prototypes like function definitions. This is done if the argument |
1273 | * to PROTOLIB is nonzero. Otherwise prototypes are handled normally. | | 1273 | * to PROTOLIB is nonzero. Otherwise prototypes are handled normally. |
1274 | */ | | 1274 | */ |
1275 | void | | 1275 | void |
1276 | protolib(int n) | | 1276 | protolib(int n) |
1277 | { | | 1277 | { |
1278 | | | 1278 | |
1279 | if (dcs->d_ctx != EXTERN) { | | 1279 | if (dcs->d_ctx != EXTERN) { |
1280 | /* must be outside function: ** %s ** */ | | 1280 | /* must be outside function: ** %s ** */ |
1281 | warning(280, "PROTOLIB"); | | 1281 | warning(280, "PROTOLIB"); |
1282 | return; | | 1282 | return; |
1283 | } | | 1283 | } |
1284 | plibflg = n == 0 ? 0 : 1; | | 1284 | plibflg = n == 0 ? 0 : 1; |
1285 | } | | 1285 | } |
1286 | | | 1286 | |
1287 | /* | | 1287 | /* |
1288 | * Set quadflg to nonzero which means that the next statement/declaration | | 1288 | * Set quadflg to nonzero which means that the next statement/declaration |
1289 | * may use "long long" without an error or warning. | | 1289 | * may use "long long" without an error or warning. |
1290 | */ | | 1290 | */ |
1291 | /* ARGSUSED */ | | 1291 | /* ARGSUSED */ |
1292 | void | | 1292 | void |
1293 | longlong(int n) | | 1293 | longlong(int n) |
1294 | { | | 1294 | { |
1295 | | | 1295 | |
1296 | quadflg = 1; | | 1296 | quadflg = 1; |
1297 | } | | 1297 | } |