]>
Commit | Line | Data |
---|---|---|
51e29401 | 1 | /* Process declarations and variables for C compiler. |
06ceef4e RK |
2 | Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 |
3 | Free Software Foundation, Inc. | |
51e29401 RS |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
940d9d63 RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
51e29401 | 21 | |
51e29401 RS |
22 | /* Process declarations and symbol lookup for C front end. |
23 | Also constructs types; the standard scalar types at initialization, | |
24 | and structure, union, array and enum types when they are declared. */ | |
25 | ||
26 | /* ??? not all decl nodes are given the most useful possible | |
27 | line numbers. For example, the CONST_DECLs for enum values. */ | |
28 | ||
29 | #include "config.h" | |
670ee920 | 30 | #include "system.h" |
993c790e | 31 | #include "intl.h" |
51e29401 | 32 | #include "tree.h" |
051c57da | 33 | #include "rtl.h" |
51e29401 | 34 | #include "flags.h" |
49ad7cfa | 35 | #include "function.h" |
e14417fa | 36 | #include "output.h" |
051c57da | 37 | #include "expr.h" |
51e29401 RS |
38 | #include "c-tree.h" |
39 | #include "c-lex.h" | |
5f6da302 | 40 | #include "toplev.h" |
246833ac | 41 | #include "defaults.h" |
1526a060 | 42 | #include "ggc.h" |
809d4ef1 | 43 | #include "tm_p.h" |
a0d85b75 | 44 | #include "cpplib.h" |
a0d85b75 | 45 | |
51e29401 RS |
46 | /* In grokdeclarator, distinguish syntactic contexts of declarators. */ |
47 | enum decl_context | |
48 | { NORMAL, /* Ordinary declaration */ | |
49 | FUNCDEF, /* Function definition */ | |
50 | PARM, /* Declaration of parm before function body */ | |
51 | FIELD, /* Declaration inside struct or union */ | |
52 | BITFIELD, /* Likewise but with specified width */ | |
53 | TYPENAME}; /* Typename (inside cast or sizeof) */ | |
54 | ||
51e29401 RS |
55 | /* We let tm.h override the types used here, to handle trivial differences |
56 | such as the choice of unsigned int or long unsigned int for size_t. | |
57 | When machines start needing nontrivial differences in the size type, | |
58 | it would be best to do something here to figure out automatically | |
59 | from other information what type to use. */ | |
60 | ||
61 | #ifndef SIZE_TYPE | |
62 | #define SIZE_TYPE "long unsigned int" | |
63 | #endif | |
64 | ||
65 | #ifndef PTRDIFF_TYPE | |
66 | #define PTRDIFF_TYPE "long int" | |
67 | #endif | |
68 | ||
69 | #ifndef WCHAR_TYPE | |
70 | #define WCHAR_TYPE "int" | |
71 | #endif | |
c5ab7f91 | 72 | |
51e29401 | 73 | \f |
51e29401 RS |
74 | /* Nonzero if we have seen an invalid cross reference |
75 | to a struct, union, or enum, but not yet printed the message. */ | |
76 | ||
77 | tree pending_invalid_xref; | |
78 | /* File and line to appear in the eventual error message. */ | |
3b304f5b | 79 | const char *pending_invalid_xref_file; |
51e29401 RS |
80 | int pending_invalid_xref_line; |
81 | ||
82 | /* While defining an enum type, this is 1 plus the last enumerator | |
18192b41 RK |
83 | constant value. Note that will do not have to save this or `enum_overflow' |
84 | around nested function definition since such a definition could only | |
85 | occur in an enum value expression and we don't use these variables in | |
86 | that case. */ | |
51e29401 RS |
87 | |
88 | static tree enum_next_value; | |
89 | ||
93e3ba4f RS |
90 | /* Nonzero means that there was overflow computing enum_next_value. */ |
91 | ||
92 | static int enum_overflow; | |
93 | ||
51e29401 RS |
94 | /* Parsing a function declarator leaves a list of parameter names |
95 | or a chain or parameter decls here. */ | |
96 | ||
97 | static tree last_function_parms; | |
98 | ||
99 | /* Parsing a function declarator leaves here a chain of structure | |
100 | and enum types declared in the parmlist. */ | |
101 | ||
102 | static tree last_function_parm_tags; | |
103 | ||
104 | /* After parsing the declarator that starts a function definition, | |
105 | `start_function' puts here the list of parameter names or chain of decls. | |
106 | `store_parm_decls' finds it here. */ | |
107 | ||
108 | static tree current_function_parms; | |
109 | ||
110 | /* Similar, for last_function_parm_tags. */ | |
111 | static tree current_function_parm_tags; | |
112 | ||
50a9145c JW |
113 | /* Similar, for the file and line that the prototype came from if this is |
114 | an old-style definition. */ | |
3b304f5b | 115 | static const char *current_function_prototype_file; |
50a9145c JW |
116 | static int current_function_prototype_line; |
117 | ||
8f17b5c5 MM |
118 | /* The current statement tree. */ |
119 | ||
120 | static struct stmt_tree_s c_stmt_tree; | |
121 | ||
122 | /* The current scope statement stack. */ | |
123 | ||
124 | static tree c_scope_stmt_stack; | |
125 | ||
126 | /* Nonzero if __FUNCTION__ and its ilk have been declared in this | |
127 | function. */ | |
128 | ||
129 | static int c_function_name_declared_p; | |
130 | ||
51e29401 RS |
131 | /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function |
132 | that have names. Here so we can clear out their names' definitions | |
133 | at the end of the function. */ | |
134 | ||
c9c30903 | 135 | static tree named_labels; |
51e29401 RS |
136 | |
137 | /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ | |
138 | ||
139 | static tree shadowed_labels; | |
140 | ||
141 | /* Nonzero when store_parm_decls is called indicates a varargs function. | |
142 | Value not meaningful after store_parm_decls. */ | |
143 | ||
144 | static int c_function_varargs; | |
145 | ||
51e29401 RS |
146 | /* Set to 0 at beginning of a function definition, set to 1 if |
147 | a return statement that specifies a return value is seen. */ | |
148 | ||
149 | int current_function_returns_value; | |
150 | ||
151 | /* Set to 0 at beginning of a function definition, set to 1 if | |
152 | a return statement with no argument is seen. */ | |
153 | ||
154 | int current_function_returns_null; | |
155 | ||
156 | /* Set to nonzero by `grokdeclarator' for a function | |
157 | whose return type is defaulted, if warnings for this are desired. */ | |
158 | ||
159 | static int warn_about_return_type; | |
160 | ||
929f3671 | 161 | /* Nonzero when starting a function declared `extern inline'. */ |
51e29401 RS |
162 | |
163 | static int current_extern_inline; | |
164 | \f | |
165 | /* For each binding contour we allocate a binding_level structure | |
166 | * which records the names defined in that contour. | |
167 | * Contours include: | |
168 | * 0) the global one | |
169 | * 1) one for each function definition, | |
170 | * where internal declarations of the parameters appear. | |
171 | * 2) one for each compound statement, | |
172 | * to record its declarations. | |
173 | * | |
174 | * The current meaning of a name can be found by searching the levels from | |
175 | * the current one out to the global one. | |
176 | */ | |
177 | ||
178 | /* Note that the information in the `names' component of the global contour | |
179 | is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ | |
180 | ||
181 | struct binding_level | |
182 | { | |
183 | /* A chain of _DECL nodes for all variables, constants, functions, | |
184 | and typedef types. These are in the reverse of the order supplied. | |
185 | */ | |
186 | tree names; | |
187 | ||
188 | /* A list of structure, union and enum definitions, | |
189 | * for looking up tag names. | |
190 | * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, | |
191 | * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, | |
192 | * or ENUMERAL_TYPE node. | |
193 | */ | |
194 | tree tags; | |
195 | ||
196 | /* For each level, a list of shadowed outer-level local definitions | |
197 | to be restored when this level is popped. | |
198 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
199 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
200 | tree shadowed; | |
201 | ||
202 | /* For each level (except not the global one), | |
203 | a chain of BLOCK nodes for all the levels | |
204 | that were entered and exited one level down. */ | |
205 | tree blocks; | |
206 | ||
3bf40d18 RS |
207 | /* The BLOCK node for this level, if one has been preallocated. |
208 | If 0, the BLOCK is allocated (if needed) when the level is popped. */ | |
209 | tree this_block; | |
210 | ||
51e29401 RS |
211 | /* The binding level which this one is contained in (inherits from). */ |
212 | struct binding_level *level_chain; | |
213 | ||
214 | /* Nonzero for the level that holds the parameters of a function. */ | |
51e29401 RS |
215 | char parm_flag; |
216 | ||
217 | /* Nonzero if this level "doesn't exist" for tags. */ | |
218 | char tag_transparent; | |
219 | ||
220 | /* Nonzero if sublevels of this level "don't exist" for tags. | |
221 | This is set in the parm level of a function definition | |
222 | while reading the function body, so that the outermost block | |
223 | of the function body will be tag-transparent. */ | |
224 | char subblocks_tag_transparent; | |
225 | ||
226 | /* Nonzero means make a BLOCK for this level regardless of all else. */ | |
227 | char keep; | |
228 | ||
229 | /* Nonzero means make a BLOCK if this level has any subblocks. */ | |
230 | char keep_if_subblocks; | |
231 | ||
6645c3fa | 232 | /* Number of decls in `names' that have incomplete |
51e29401 RS |
233 | structure or union types. */ |
234 | int n_incomplete; | |
235 | ||
236 | /* A list of decls giving the (reversed) specified order of parms, | |
237 | not including any forward-decls in the parmlist. | |
238 | This is so we can put the parms in proper order for assign_parms. */ | |
239 | tree parm_order; | |
240 | }; | |
241 | ||
242 | #define NULL_BINDING_LEVEL (struct binding_level *) NULL | |
6645c3fa | 243 | |
51e29401 RS |
244 | /* The binding level currently in effect. */ |
245 | ||
246 | static struct binding_level *current_binding_level; | |
247 | ||
248 | /* A chain of binding_level structures awaiting reuse. */ | |
249 | ||
250 | static struct binding_level *free_binding_level; | |
251 | ||
252 | /* The outermost binding level, for names of file scope. | |
253 | This is created when the compiler is started and exists | |
254 | through the entire run. */ | |
255 | ||
256 | static struct binding_level *global_binding_level; | |
257 | ||
258 | /* Binding level structures are initialized by copying this one. */ | |
259 | ||
260 | static struct binding_level clear_binding_level | |
014aa47e RK |
261 | = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0, |
262 | NULL}; | |
51e29401 RS |
263 | |
264 | /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ | |
265 | ||
266 | static int keep_next_level_flag; | |
267 | ||
268 | /* Nonzero means make a BLOCK for the next level pushed | |
269 | if it has subblocks. */ | |
270 | ||
271 | static int keep_next_if_subblocks; | |
6645c3fa | 272 | |
51e29401 RS |
273 | /* The chain of outer levels of label scopes. |
274 | This uses the same data structure used for binding levels, | |
275 | but it works differently: each link in the chain records | |
276 | saved values of named_labels and shadowed_labels for | |
277 | a label binding level outside the current one. */ | |
278 | ||
279 | static struct binding_level *label_level_chain; | |
280 | ||
2c5f4139 JM |
281 | /* Functions called automatically at the beginning and end of execution. */ |
282 | ||
283 | tree static_ctors, static_dtors; | |
284 | ||
51e29401 RS |
285 | /* Forward declarations. */ |
286 | ||
6e090c76 KG |
287 | static struct binding_level * make_binding_level PARAMS ((void)); |
288 | static void mark_binding_level PARAMS ((void *)); | |
289 | static void clear_limbo_values PARAMS ((tree)); | |
290 | static int duplicate_decls PARAMS ((tree, tree, int)); | |
291 | static int redeclaration_error_message PARAMS ((tree, tree)); | |
292 | static void storedecls PARAMS ((tree)); | |
293 | static void storetags PARAMS ((tree)); | |
294 | static tree lookup_tag PARAMS ((enum tree_code, tree, | |
295 | struct binding_level *, int)); | |
296 | static tree lookup_tag_reverse PARAMS ((tree)); | |
297 | static tree grokdeclarator PARAMS ((tree, tree, enum decl_context, | |
298 | int)); | |
299 | static tree grokparms PARAMS ((tree, int)); | |
300 | static void layout_array_type PARAMS ((tree)); | |
2ce07e2d | 301 | static tree c_make_fname_decl PARAMS ((tree, const char *, int)); |
8f17b5c5 | 302 | static void c_expand_body PARAMS ((tree, int)); |
51e29401 RS |
303 | \f |
304 | /* C-specific option variables. */ | |
305 | ||
306 | /* Nonzero means allow type mismatches in conditional expressions; | |
307 | just make their values `void'. */ | |
308 | ||
309 | int flag_cond_mismatch; | |
310 | ||
311 | /* Nonzero means give `double' the same size as `float'. */ | |
312 | ||
313 | int flag_short_double; | |
314 | ||
12a39b12 JM |
315 | /* Nonzero means give `wchar_t' the same size as `short'. */ |
316 | ||
317 | int flag_short_wchar; | |
318 | ||
51e29401 RS |
319 | /* Nonzero means don't recognize the keyword `asm'. */ |
320 | ||
321 | int flag_no_asm; | |
322 | ||
51e29401 RS |
323 | /* Nonzero means do some things the same way PCC does. */ |
324 | ||
325 | int flag_traditional; | |
326 | ||
eaf299c6 | 327 | /* Nonzero means enable C89 Amendment 1 features. */ |
b8458e3e JM |
328 | |
329 | int flag_isoc94 = 0; | |
330 | ||
916269ab | 331 | /* Nonzero means use the ISO C99 dialect of C. */ |
3932261a | 332 | |
916269ab | 333 | int flag_isoc99 = 0; |
3932261a | 334 | |
b8705e61 RK |
335 | /* Nonzero means that we have builtin functions, and main is an int */ |
336 | ||
337 | int flag_hosted = 1; | |
338 | ||
93e2382f JM |
339 | /* Nonzero means add default format_arg attributes for functions not |
340 | in ISO C. */ | |
341 | ||
342 | int flag_noniso_default_format_attributes = 1; | |
343 | ||
55b4742b | 344 | /* Nonzero means to allow single precision math even if we're generally |
0f41302f | 345 | being traditional. */ |
55b4742b RS |
346 | int flag_allow_single_precision = 0; |
347 | ||
51e29401 RS |
348 | /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */ |
349 | ||
350 | int flag_signed_bitfields = 1; | |
7a0347ff | 351 | int explicit_flag_signed_bitfields = 0; |
51e29401 | 352 | |
6645c3fa | 353 | /* Nonzero means warn about use of implicit int. */ |
e9a25f70 JL |
354 | |
355 | int warn_implicit_int; | |
51e29401 | 356 | |
795add94 VM |
357 | /* Nonzero means warn about usage of long long when `-pedantic'. */ |
358 | ||
359 | int warn_long_long = 1; | |
360 | ||
e9a25f70 | 361 | /* Nonzero means message about use of implicit function declarations; |
6645c3fa | 362 | 1 means warning; 2 means error. */ |
e9a25f70 | 363 | |
111458f1 | 364 | int mesg_implicit_function_declaration = -1; |
51e29401 RS |
365 | |
366 | /* Nonzero means give string constants the type `const char *' | |
367 | to get extra warnings from them. These warnings will be too numerous | |
368 | to be useful, except in thoroughly ANSIfied programs. */ | |
369 | ||
d9cf7c82 | 370 | int flag_const_strings; |
51e29401 RS |
371 | |
372 | /* Nonzero means warn about pointer casts that can drop a type qualifier | |
373 | from the pointer target type. */ | |
374 | ||
375 | int warn_cast_qual; | |
376 | ||
5c8902bb RK |
377 | /* Nonzero means warn when casting a function call to a type that does |
378 | not match the return type (e.g. (float)sqrt() or (anything*)malloc() | |
379 | when there is no previous declaration of sqrt or malloc. */ | |
380 | ||
381 | int warn_bad_function_cast; | |
382 | ||
74ff4629 JM |
383 | /* Warn about functions which might be candidates for format attributes. */ |
384 | ||
385 | int warn_missing_format_attribute; | |
386 | ||
51e29401 RS |
387 | /* Warn about traditional constructs whose meanings changed in ANSI C. */ |
388 | ||
389 | int warn_traditional; | |
390 | ||
391 | /* Nonzero means warn about sizeof(function) or addition/subtraction | |
392 | of function pointers. */ | |
393 | ||
394 | int warn_pointer_arith; | |
395 | ||
396 | /* Nonzero means warn for non-prototype function decls | |
397 | or non-prototyped defs without previous prototype. */ | |
398 | ||
399 | int warn_strict_prototypes; | |
400 | ||
401 | /* Nonzero means warn for any global function def | |
402 | without separate previous prototype decl. */ | |
403 | ||
404 | int warn_missing_prototypes; | |
405 | ||
1474fe46 RK |
406 | /* Nonzero means warn for any global function def |
407 | without separate previous decl. */ | |
408 | ||
409 | int warn_missing_declarations; | |
410 | ||
51e29401 RS |
411 | /* Nonzero means warn about multiple (redundant) decls for the same single |
412 | variable or function. */ | |
413 | ||
414 | int warn_redundant_decls = 0; | |
415 | ||
416 | /* Nonzero means warn about extern declarations of objects not at | |
417 | file-scope level and about *all* declarations of functions (whether | |
418 | extern or static) not at file-scope level. Note that we exclude | |
419 | implicit function declarations. To get warnings about those, use | |
420 | -Wimplicit. */ | |
421 | ||
422 | int warn_nested_externs = 0; | |
423 | ||
0f41302f | 424 | /* Warn about *printf or *scanf format/argument anomalies. */ |
51e29401 RS |
425 | |
426 | int warn_format; | |
427 | ||
428 | /* Warn about a subscript that has type char. */ | |
429 | ||
430 | int warn_char_subscripts = 0; | |
431 | ||
432 | /* Warn if a type conversion is done that might have confusing results. */ | |
433 | ||
434 | int warn_conversion; | |
435 | ||
436 | /* Warn if adding () is suggested. */ | |
437 | ||
929f3671 | 438 | int warn_parentheses; |
51e29401 | 439 | |
36e6fa69 RS |
440 | /* Warn if initializer is not completely bracketed. */ |
441 | ||
442 | int warn_missing_braces; | |
443 | ||
b8705e61 RK |
444 | /* Warn if main is suspicious. */ |
445 | ||
446 | int warn_main; | |
447 | ||
d300e551 NC |
448 | /* Warn about #pragma directives that are not recognised. */ |
449 | ||
6645c3fa | 450 | int warn_unknown_pragmas = 0; /* Tri state variable. */ |
d300e551 | 451 | |
407cb092 PE |
452 | /* Warn about comparison of signed and unsigned values. |
453 | If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */ | |
d51f9363 | 454 | |
407cb092 | 455 | int warn_sign_compare = -1; |
d51f9363 | 456 | |
6645c3fa | 457 | /* Warn about testing equality of floating point numbers. */ |
b843d210 DZ |
458 | |
459 | int warn_float_equal = 0; | |
460 | ||
4a870dba JM |
461 | /* Nonzero means warn about use of multicharacter literals. */ |
462 | ||
463 | int warn_multichar = 1; | |
464 | ||
5b2abab8 MM |
465 | /* The variant of the C language being processed. */ |
466 | ||
467 | c_language_kind c_language = clk_c; | |
468 | ||
39b3bed7 | 469 | /* Nonzero means `$' can be in an identifier. */ |
51e29401 RS |
470 | |
471 | #ifndef DOLLARS_IN_IDENTIFIERS | |
472 | #define DOLLARS_IN_IDENTIFIERS 1 | |
473 | #endif | |
39b3bed7 | 474 | int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; |
51e29401 | 475 | |
51e29401 | 476 | /* Decode the string P as a language-specific option for C. |
03d32d1a NC |
477 | Return the number of strings consumed. Should not complain |
478 | if it does not recognise the option. */ | |
6645c3fa | 479 | |
51e29401 | 480 | int |
a0d85b75 | 481 | c_decode_option (argc, argv) |
c84e2712 | 482 | int argc ATTRIBUTE_UNUSED; |
a0d85b75 | 483 | char **argv; |
51e29401 | 484 | { |
a0d85b75 | 485 | int strings_processed; |
0a7394bc | 486 | const char *option_value = NULL; |
a0d85b75 | 487 | char *p = argv[0]; |
a32f2771 | 488 | |
cf44ea52 | 489 | strings_processed = cpp_handle_option (parse_in, argc, argv); |
a0d85b75 | 490 | |
0eaed3c6 | 491 | if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) |
51e29401 RS |
492 | { |
493 | flag_traditional = 1; | |
494 | flag_writable_strings = 1; | |
51e29401 | 495 | } |
55b4742b RS |
496 | else if (!strcmp (p, "-fallow-single-precision")) |
497 | flag_allow_single_precision = 1; | |
b8705e61 RK |
498 | else if (!strcmp (p, "-fhosted") || !strcmp (p, "-fno-freestanding")) |
499 | { | |
500 | flag_hosted = 1; | |
501 | flag_no_builtin = 0; | |
502 | } | |
503 | else if (!strcmp (p, "-ffreestanding") || !strcmp (p, "-fno-hosted")) | |
504 | { | |
505 | flag_hosted = 0; | |
506 | flag_no_builtin = 1; | |
507 | /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */ | |
508 | if (warn_main == 2) | |
509 | warn_main = 0; | |
510 | } | |
4ecc65ac RS |
511 | else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional")) |
512 | { | |
513 | flag_traditional = 0; | |
514 | flag_writable_strings = 0; | |
4ecc65ac | 515 | } |
6f4d7222 UD |
516 | else if (!strncmp (p, "-std=", 5)) |
517 | { | |
518 | /* Select the appropriate language standard. We currently | |
519 | recognize: | |
520 | -std=iso9899:1990 same as -ansi | |
6f4d7222 | 521 | -std=iso9899:199409 ISO C as modified in amend. 1 |
916269ab | 522 | -std=iso9899:1999 ISO C 99 |
6f4d7222 | 523 | -std=c89 same as -std=iso9899:1990 |
916269ab | 524 | -std=c99 same as -std=iso9899:1999 |
6271b191 | 525 | -std=gnu89 default, iso9899:1990 + gnu extensions |
916269ab | 526 | -std=gnu99 iso9899:1999 + gnu extensions |
6f4d7222 UD |
527 | */ |
528 | const char *argstart = &p[5]; | |
529 | ||
530 | if (!strcmp (argstart, "iso9899:1990") | |
531 | || !strcmp (argstart, "c89")) | |
532 | { | |
533 | iso_1990: | |
b8458e3e | 534 | flag_isoc94 = 0; |
eaf299c6 | 535 | iso_1994: |
6f4d7222 UD |
536 | flag_traditional = 0; |
537 | flag_writable_strings = 0; | |
538 | flag_no_asm = 1; | |
539 | flag_no_nonansi_builtin = 1; | |
93e2382f | 540 | flag_noniso_default_format_attributes = 0; |
916269ab | 541 | flag_isoc99 = 0; |
6f4d7222 UD |
542 | } |
543 | else if (!strcmp (argstart, "iso9899:199409")) | |
544 | { | |
b8458e3e | 545 | flag_isoc94 = 1; |
eaf299c6 | 546 | goto iso_1994; |
6f4d7222 UD |
547 | } |
548 | else if (!strcmp (argstart, "iso9899:199x") | |
916269ab UD |
549 | || !strcmp (argstart, "iso9899:1999") |
550 | || !strcmp (argstart, "c9x") | |
551 | || !strcmp (argstart, "c99")) | |
6f4d7222 UD |
552 | { |
553 | flag_traditional = 0; | |
554 | flag_writable_strings = 0; | |
555 | flag_no_asm = 1; | |
556 | flag_no_nonansi_builtin = 1; | |
93e2382f | 557 | flag_noniso_default_format_attributes = 0; |
916269ab | 558 | flag_isoc99 = 1; |
b8458e3e | 559 | flag_isoc94 = 1; |
6f4d7222 | 560 | } |
6271b191 RH |
561 | else if (!strcmp (argstart, "gnu89")) |
562 | { | |
563 | flag_traditional = 0; | |
564 | flag_writable_strings = 0; | |
565 | flag_no_asm = 0; | |
566 | flag_no_nonansi_builtin = 0; | |
93e2382f | 567 | flag_noniso_default_format_attributes = 1; |
916269ab | 568 | flag_isoc99 = 0; |
b8458e3e | 569 | flag_isoc94 = 0; |
6271b191 | 570 | } |
916269ab | 571 | else if (!strcmp (argstart, "gnu9x") || !strcmp (argstart, "gnu99")) |
6f4d7222 UD |
572 | { |
573 | flag_traditional = 0; | |
574 | flag_writable_strings = 0; | |
575 | flag_no_asm = 0; | |
576 | flag_no_nonansi_builtin = 0; | |
93e2382f | 577 | flag_noniso_default_format_attributes = 1; |
916269ab | 578 | flag_isoc99 = 1; |
b8458e3e | 579 | flag_isoc94 = 1; |
6f4d7222 UD |
580 | } |
581 | else | |
582 | error ("unknown C standard `%s'", argstart); | |
583 | } | |
a419ff54 | 584 | else if (!strcmp (p, "-fdollars-in-identifiers")) |
39b3bed7 | 585 | dollars_in_ident = 1; |
014aa47e | 586 | else if (!strcmp (p, "-fno-dollars-in-identifiers")) |
a419ff54 | 587 | dollars_in_ident = 0; |
51e29401 RS |
588 | else if (!strcmp (p, "-fsigned-char")) |
589 | flag_signed_char = 1; | |
590 | else if (!strcmp (p, "-funsigned-char")) | |
591 | flag_signed_char = 0; | |
592 | else if (!strcmp (p, "-fno-signed-char")) | |
593 | flag_signed_char = 0; | |
594 | else if (!strcmp (p, "-fno-unsigned-char")) | |
595 | flag_signed_char = 1; | |
7a0347ff RS |
596 | else if (!strcmp (p, "-fsigned-bitfields") |
597 | || !strcmp (p, "-fno-unsigned-bitfields")) | |
598 | { | |
599 | flag_signed_bitfields = 1; | |
600 | explicit_flag_signed_bitfields = 1; | |
601 | } | |
602 | else if (!strcmp (p, "-funsigned-bitfields") | |
603 | || !strcmp (p, "-fno-signed-bitfields")) | |
604 | { | |
605 | flag_signed_bitfields = 0; | |
606 | explicit_flag_signed_bitfields = 1; | |
607 | } | |
51e29401 RS |
608 | else if (!strcmp (p, "-fshort-enums")) |
609 | flag_short_enums = 1; | |
610 | else if (!strcmp (p, "-fno-short-enums")) | |
611 | flag_short_enums = 0; | |
12a39b12 JM |
612 | else if (!strcmp (p, "-fshort-wchar")) |
613 | flag_short_wchar = 1; | |
614 | else if (!strcmp (p, "-fno-short-wchar")) | |
615 | flag_short_wchar = 0; | |
51e29401 RS |
616 | else if (!strcmp (p, "-fcond-mismatch")) |
617 | flag_cond_mismatch = 1; | |
618 | else if (!strcmp (p, "-fno-cond-mismatch")) | |
619 | flag_cond_mismatch = 0; | |
620 | else if (!strcmp (p, "-fshort-double")) | |
621 | flag_short_double = 1; | |
622 | else if (!strcmp (p, "-fno-short-double")) | |
623 | flag_short_double = 0; | |
624 | else if (!strcmp (p, "-fasm")) | |
625 | flag_no_asm = 0; | |
626 | else if (!strcmp (p, "-fno-asm")) | |
627 | flag_no_asm = 1; | |
628 | else if (!strcmp (p, "-fbuiltin")) | |
629 | flag_no_builtin = 0; | |
630 | else if (!strcmp (p, "-fno-builtin")) | |
631 | flag_no_builtin = 1; | |
0a7394bc MM |
632 | else if ((option_value |
633 | = skip_leading_substring (p, "-fdump-translation-unit-"))) | |
634 | { | |
635 | if (p[22] == '\0') | |
636 | error ("no file specified with -fdump-translation-unit"); | |
637 | else | |
638 | flag_dump_translation_unit = option_value; | |
639 | } | |
51e29401 | 640 | else if (!strcmp (p, "-ansi")) |
6f4d7222 | 641 | goto iso_1990; |
e9a25f70 JL |
642 | else if (!strcmp (p, "-Werror-implicit-function-declaration")) |
643 | mesg_implicit_function_declaration = 2; | |
644 | else if (!strcmp (p, "-Wimplicit-function-declaration")) | |
645 | mesg_implicit_function_declaration = 1; | |
646 | else if (!strcmp (p, "-Wno-implicit-function-declaration")) | |
647 | mesg_implicit_function_declaration = 0; | |
648 | else if (!strcmp (p, "-Wimplicit-int")) | |
649 | warn_implicit_int = 1; | |
650 | else if (!strcmp (p, "-Wno-implicit-int")) | |
651 | warn_implicit_int = 0; | |
51e29401 | 652 | else if (!strcmp (p, "-Wimplicit")) |
e9a25f70 JL |
653 | { |
654 | warn_implicit_int = 1; | |
655 | if (mesg_implicit_function_declaration != 2) | |
6645c3fa | 656 | mesg_implicit_function_declaration = 1; |
e9a25f70 | 657 | } |
51e29401 | 658 | else if (!strcmp (p, "-Wno-implicit")) |
e9a25f70 | 659 | warn_implicit_int = 0, mesg_implicit_function_declaration = 0; |
795add94 VM |
660 | else if (!strcmp (p, "-Wlong-long")) |
661 | warn_long_long = 1; | |
662 | else if (!strcmp (p, "-Wno-long-long")) | |
663 | warn_long_long = 0; | |
51e29401 | 664 | else if (!strcmp (p, "-Wwrite-strings")) |
d9cf7c82 | 665 | flag_const_strings = 1; |
51e29401 | 666 | else if (!strcmp (p, "-Wno-write-strings")) |
d9cf7c82 | 667 | flag_const_strings = 0; |
51e29401 RS |
668 | else if (!strcmp (p, "-Wcast-qual")) |
669 | warn_cast_qual = 1; | |
670 | else if (!strcmp (p, "-Wno-cast-qual")) | |
671 | warn_cast_qual = 0; | |
5c8902bb RK |
672 | else if (!strcmp (p, "-Wbad-function-cast")) |
673 | warn_bad_function_cast = 1; | |
674 | else if (!strcmp (p, "-Wno-bad-function-cast")) | |
675 | warn_bad_function_cast = 0; | |
0ca3fb0a KG |
676 | else if (!strcmp (p, "-Wmissing-noreturn")) |
677 | warn_missing_noreturn = 1; | |
678 | else if (!strcmp (p, "-Wno-missing-noreturn")) | |
679 | warn_missing_noreturn = 0; | |
74ff4629 JM |
680 | else if (!strcmp (p, "-Wmissing-format-attribute")) |
681 | warn_missing_format_attribute = 1; | |
682 | else if (!strcmp (p, "-Wno-missing-format-attribute")) | |
683 | warn_missing_format_attribute = 0; | |
51e29401 RS |
684 | else if (!strcmp (p, "-Wpointer-arith")) |
685 | warn_pointer_arith = 1; | |
686 | else if (!strcmp (p, "-Wno-pointer-arith")) | |
687 | warn_pointer_arith = 0; | |
688 | else if (!strcmp (p, "-Wstrict-prototypes")) | |
689 | warn_strict_prototypes = 1; | |
690 | else if (!strcmp (p, "-Wno-strict-prototypes")) | |
691 | warn_strict_prototypes = 0; | |
692 | else if (!strcmp (p, "-Wmissing-prototypes")) | |
693 | warn_missing_prototypes = 1; | |
694 | else if (!strcmp (p, "-Wno-missing-prototypes")) | |
695 | warn_missing_prototypes = 0; | |
1474fe46 RK |
696 | else if (!strcmp (p, "-Wmissing-declarations")) |
697 | warn_missing_declarations = 1; | |
698 | else if (!strcmp (p, "-Wno-missing-declarations")) | |
699 | warn_missing_declarations = 0; | |
51e29401 RS |
700 | else if (!strcmp (p, "-Wredundant-decls")) |
701 | warn_redundant_decls = 1; | |
ec2343c4 | 702 | else if (!strcmp (p, "-Wno-redundant-decls")) |
51e29401 RS |
703 | warn_redundant_decls = 0; |
704 | else if (!strcmp (p, "-Wnested-externs")) | |
705 | warn_nested_externs = 1; | |
706 | else if (!strcmp (p, "-Wno-nested-externs")) | |
707 | warn_nested_externs = 0; | |
708 | else if (!strcmp (p, "-Wtraditional")) | |
709 | warn_traditional = 1; | |
710 | else if (!strcmp (p, "-Wno-traditional")) | |
711 | warn_traditional = 0; | |
1d682cca UD |
712 | else if (!strncmp (p, "-Wformat=", 9)) |
713 | warn_format = atol (p + 9); | |
51e29401 RS |
714 | else if (!strcmp (p, "-Wformat")) |
715 | warn_format = 1; | |
716 | else if (!strcmp (p, "-Wno-format")) | |
717 | warn_format = 0; | |
718 | else if (!strcmp (p, "-Wchar-subscripts")) | |
719 | warn_char_subscripts = 1; | |
720 | else if (!strcmp (p, "-Wno-char-subscripts")) | |
721 | warn_char_subscripts = 0; | |
722 | else if (!strcmp (p, "-Wconversion")) | |
723 | warn_conversion = 1; | |
724 | else if (!strcmp (p, "-Wno-conversion")) | |
725 | warn_conversion = 0; | |
726 | else if (!strcmp (p, "-Wparentheses")) | |
727 | warn_parentheses = 1; | |
728 | else if (!strcmp (p, "-Wno-parentheses")) | |
729 | warn_parentheses = 0; | |
57916f61 RS |
730 | else if (!strcmp (p, "-Wreturn-type")) |
731 | warn_return_type = 1; | |
732 | else if (!strcmp (p, "-Wno-return-type")) | |
733 | warn_return_type = 0; | |
bb58bec5 JM |
734 | else if (!strcmp (p, "-Wsequence-point")) |
735 | warn_sequence_point = 1; | |
736 | else if (!strcmp (p, "-Wno-sequence-point")) | |
737 | warn_sequence_point = 0; | |
51e29401 RS |
738 | else if (!strcmp (p, "-Wcomment")) |
739 | ; /* cpp handles this one. */ | |
740 | else if (!strcmp (p, "-Wno-comment")) | |
741 | ; /* cpp handles this one. */ | |
742 | else if (!strcmp (p, "-Wcomments")) | |
743 | ; /* cpp handles this one. */ | |
744 | else if (!strcmp (p, "-Wno-comments")) | |
745 | ; /* cpp handles this one. */ | |
746 | else if (!strcmp (p, "-Wtrigraphs")) | |
747 | ; /* cpp handles this one. */ | |
748 | else if (!strcmp (p, "-Wno-trigraphs")) | |
749 | ; /* cpp handles this one. */ | |
dab9b3bf RK |
750 | else if (!strcmp (p, "-Wundef")) |
751 | ; /* cpp handles this one. */ | |
752 | else if (!strcmp (p, "-Wno-undef")) | |
753 | ; /* cpp handles this one. */ | |
fc3ffe83 RK |
754 | else if (!strcmp (p, "-Wimport")) |
755 | ; /* cpp handles this one. */ | |
756 | else if (!strcmp (p, "-Wno-import")) | |
757 | ; /* cpp handles this one. */ | |
36e6fa69 RS |
758 | else if (!strcmp (p, "-Wmissing-braces")) |
759 | warn_missing_braces = 1; | |
760 | else if (!strcmp (p, "-Wno-missing-braces")) | |
761 | warn_missing_braces = 0; | |
b8705e61 RK |
762 | else if (!strcmp (p, "-Wmain")) |
763 | warn_main = 1; | |
764 | else if (!strcmp (p, "-Wno-main")) | |
007aaed0 | 765 | warn_main = -1; |
d51f9363 JM |
766 | else if (!strcmp (p, "-Wsign-compare")) |
767 | warn_sign_compare = 1; | |
768 | else if (!strcmp (p, "-Wno-sign-compare")) | |
769 | warn_sign_compare = 0; | |
b843d210 DZ |
770 | else if (!strcmp (p, "-Wfloat-equal")) |
771 | warn_float_equal = 1; | |
772 | else if (!strcmp (p, "-Wno-float-equal")) | |
773 | warn_float_equal = 0; | |
4a870dba JM |
774 | else if (!strcmp (p, "-Wmultichar")) |
775 | warn_multichar = 1; | |
776 | else if (!strcmp (p, "-Wno-multichar")) | |
777 | warn_multichar = 0; | |
d300e551 NC |
778 | else if (!strcmp (p, "-Wunknown-pragmas")) |
779 | /* Set to greater than 1, so that even unknown pragmas in system | |
780 | headers will be warned about. */ | |
781 | warn_unknown_pragmas = 2; | |
782 | else if (!strcmp (p, "-Wno-unknown-pragmas")) | |
783 | warn_unknown_pragmas = 0; | |
51e29401 RS |
784 | else if (!strcmp (p, "-Wall")) |
785 | { | |
a2468e45 BK |
786 | /* We save the value of warn_uninitialized, since if they put |
787 | -Wuninitialized on the command line, we need to generate a | |
788 | warning about not using it without also specifying -O. */ | |
789 | if (warn_uninitialized != 1) | |
790 | warn_uninitialized = 2; | |
e9a25f70 JL |
791 | warn_implicit_int = 1; |
792 | mesg_implicit_function_declaration = 1; | |
51e29401 | 793 | warn_return_type = 1; |
078721e1 | 794 | set_Wunused (1); |
51e29401 RS |
795 | warn_switch = 1; |
796 | warn_format = 1; | |
797 | warn_char_subscripts = 1; | |
929f3671 | 798 | warn_parentheses = 1; |
bb58bec5 | 799 | warn_sequence_point = 1; |
36e6fa69 | 800 | warn_missing_braces = 1; |
b8705e61 RK |
801 | /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn |
802 | it off only if it's not explicit. */ | |
803 | warn_main = 2; | |
d300e551 NC |
804 | /* Only warn about unknown pragmas that are not in system headers. */ |
805 | warn_unknown_pragmas = 1; | |
51e29401 RS |
806 | } |
807 | else | |
a0d85b75 | 808 | return strings_processed; |
51e29401 RS |
809 | |
810 | return 1; | |
811 | } | |
812 | ||
813 | /* Hooks for print_node. */ | |
814 | ||
815 | void | |
27d433a2 | 816 | print_lang_decl (file, node, indent) |
d6f4ec51 KG |
817 | FILE *file ATTRIBUTE_UNUSED; |
818 | tree node ATTRIBUTE_UNUSED; | |
819 | int indent ATTRIBUTE_UNUSED; | |
51e29401 RS |
820 | { |
821 | } | |
822 | ||
823 | void | |
27d433a2 | 824 | print_lang_type (file, node, indent) |
d6f4ec51 KG |
825 | FILE *file ATTRIBUTE_UNUSED; |
826 | tree node ATTRIBUTE_UNUSED; | |
827 | int indent ATTRIBUTE_UNUSED; | |
51e29401 RS |
828 | { |
829 | } | |
830 | ||
831 | void | |
832 | print_lang_identifier (file, node, indent) | |
833 | FILE *file; | |
834 | tree node; | |
835 | int indent; | |
836 | { | |
837 | print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4); | |
838 | print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); | |
839 | print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); | |
840 | print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); | |
841 | print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); | |
fd0b8fce | 842 | print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4); |
0e5921e8 ZW |
843 | if (C_IS_RESERVED_WORD (node)) |
844 | { | |
845 | tree rid = ridpointers[C_RID_CODE (node)]; | |
846 | indent_to (file, indent + 4); | |
847 | fprintf (file, "rid "); | |
848 | fprintf (file, HOST_PTR_PRINTF, (void *)rid); | |
849 | fprintf (file, " \"%s\"", IDENTIFIER_POINTER (rid)); | |
850 | } | |
51e29401 RS |
851 | } |
852 | \f | |
b4892310 | 853 | /* Hook called at end of compilation to assume 1 elt |
53c5b5d7 | 854 | for a top-level tentative array defn that wasn't complete before. */ |
6645c3fa | 855 | |
b4892310 RS |
856 | void |
857 | finish_incomplete_decl (decl) | |
858 | tree decl; | |
859 | { | |
5cfac96e | 860 | if (TREE_CODE (decl) == VAR_DECL) |
b4892310 RS |
861 | { |
862 | tree type = TREE_TYPE (decl); | |
5cfac96e RK |
863 | if (type != error_mark_node |
864 | && TREE_CODE (type) == ARRAY_TYPE | |
53c5b5d7 | 865 | && ! DECL_EXTERNAL (decl) |
5cfac96e | 866 | && TYPE_DOMAIN (type) == 0) |
b4892310 | 867 | { |
53c5b5d7 | 868 | warning_with_decl (decl, "array `%s' assumed to have one element"); |
5cfac96e | 869 | |
b4892310 RS |
870 | complete_array_type (type, NULL_TREE, 1); |
871 | ||
872 | layout_decl (decl, 0); | |
873 | } | |
874 | } | |
875 | } | |
876 | \f | |
51e29401 RS |
877 | /* Create a new `struct binding_level'. */ |
878 | ||
6645c3fa | 879 | static struct binding_level * |
51e29401 RS |
880 | make_binding_level () |
881 | { | |
882 | /* NOSTRICT */ | |
883 | return (struct binding_level *) xmalloc (sizeof (struct binding_level)); | |
884 | } | |
885 | ||
886 | /* Nonzero if we are currently in the global binding level. */ | |
887 | ||
888 | int | |
889 | global_bindings_p () | |
890 | { | |
891 | return current_binding_level == global_binding_level; | |
892 | } | |
893 | ||
894 | void | |
895 | keep_next_level () | |
896 | { | |
897 | keep_next_level_flag = 1; | |
898 | } | |
899 | ||
900 | /* Nonzero if the current level needs to have a BLOCK made. */ | |
901 | ||
902 | int | |
903 | kept_level_p () | |
904 | { | |
905 | return ((current_binding_level->keep_if_subblocks | |
906 | && current_binding_level->blocks != 0) | |
907 | || current_binding_level->keep | |
908 | || current_binding_level->names != 0 | |
909 | || (current_binding_level->tags != 0 | |
910 | && !current_binding_level->tag_transparent)); | |
911 | } | |
912 | ||
913 | /* Identify this binding level as a level of parameters. | |
89d7540d RS |
914 | DEFINITION_FLAG is 1 for a definition, 0 for a declaration. |
915 | But it turns out there is no way to pass the right value for | |
916 | DEFINITION_FLAG, so we ignore it. */ | |
51e29401 RS |
917 | |
918 | void | |
919 | declare_parm_level (definition_flag) | |
c84e2712 | 920 | int definition_flag ATTRIBUTE_UNUSED; |
51e29401 | 921 | { |
89d7540d | 922 | current_binding_level->parm_flag = 1; |
51e29401 RS |
923 | } |
924 | ||
925 | /* Nonzero if currently making parm declarations. */ | |
926 | ||
927 | int | |
928 | in_parm_level_p () | |
929 | { | |
930 | return current_binding_level->parm_flag; | |
931 | } | |
932 | ||
933 | /* Enter a new binding level. | |
934 | If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, | |
935 | not for that of tags. */ | |
936 | ||
937 | void | |
938 | pushlevel (tag_transparent) | |
939 | int tag_transparent; | |
940 | { | |
941 | register struct binding_level *newlevel = NULL_BINDING_LEVEL; | |
942 | ||
943 | /* If this is the top level of a function, | |
944 | just make sure that NAMED_LABELS is 0. */ | |
945 | ||
946 | if (current_binding_level == global_binding_level) | |
947 | { | |
948 | named_labels = 0; | |
949 | } | |
950 | ||
951 | /* Reuse or create a struct for this binding level. */ | |
952 | ||
953 | if (free_binding_level) | |
954 | { | |
955 | newlevel = free_binding_level; | |
956 | free_binding_level = free_binding_level->level_chain; | |
957 | } | |
958 | else | |
959 | { | |
960 | newlevel = make_binding_level (); | |
961 | } | |
962 | ||
963 | /* Add this level to the front of the chain (stack) of levels that | |
964 | are active. */ | |
965 | ||
966 | *newlevel = clear_binding_level; | |
967 | newlevel->tag_transparent | |
968 | = (tag_transparent | |
969 | || (current_binding_level | |
970 | ? current_binding_level->subblocks_tag_transparent | |
971 | : 0)); | |
972 | newlevel->level_chain = current_binding_level; | |
973 | current_binding_level = newlevel; | |
974 | newlevel->keep = keep_next_level_flag; | |
975 | keep_next_level_flag = 0; | |
976 | newlevel->keep_if_subblocks = keep_next_if_subblocks; | |
977 | keep_next_if_subblocks = 0; | |
978 | } | |
979 | ||
6645c3fa | 980 | /* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */ |
0500d6f9 RK |
981 | |
982 | static void | |
983 | clear_limbo_values (block) | |
984 | tree block; | |
985 | { | |
986 | tree tem; | |
987 | ||
988 | for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem)) | |
989 | if (DECL_NAME (tem) != 0) | |
990 | IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0; | |
991 | ||
992 | for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem)) | |
993 | clear_limbo_values (tem); | |
994 | } | |
6645c3fa | 995 | |
51e29401 RS |
996 | /* Exit a binding level. |
997 | Pop the level off, and restore the state of the identifier-decl mappings | |
998 | that were in effect when this level was entered. | |
999 | ||
1000 | If KEEP is nonzero, this level had explicit declarations, so | |
1001 | and create a "block" (a BLOCK node) for the level | |
1002 | to record its declarations and subblocks for symbol table output. | |
1003 | ||
1004 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
1005 | so create a block as if KEEP were set and also clear out all | |
1006 | label names. | |
1007 | ||
1008 | If REVERSE is nonzero, reverse the order of decls before putting | |
1009 | them into the BLOCK. */ | |
1010 | ||
1011 | tree | |
1012 | poplevel (keep, reverse, functionbody) | |
1013 | int keep; | |
1014 | int reverse; | |
1015 | int functionbody; | |
1016 | { | |
1017 | register tree link; | |
1018 | /* The chain of decls was accumulated in reverse order. | |
1019 | Put it into forward order, just for cleanliness. */ | |
1020 | tree decls; | |
1021 | tree tags = current_binding_level->tags; | |
1022 | tree subblocks = current_binding_level->blocks; | |
1023 | tree block = 0; | |
1024 | tree decl; | |
968e5643 | 1025 | int block_previously_created; |
51e29401 RS |
1026 | |
1027 | keep |= current_binding_level->keep; | |
1028 | ||
1029 | /* This warning is turned off because it causes warnings for | |
1030 | declarations like `extern struct foo *x'. */ | |
1031 | #if 0 | |
1032 | /* Warn about incomplete structure types in this level. */ | |
1033 | for (link = tags; link; link = TREE_CHAIN (link)) | |
d0f062fb | 1034 | if (!COMPLETE_TYPE_P (TREE_VALUE (link))) |
51e29401 RS |
1035 | { |
1036 | tree type = TREE_VALUE (link); | |
ab87f8c8 JL |
1037 | tree type_name = TYPE_NAME (type); |
1038 | char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE | |
1039 | ? type_name | |
1040 | : DECL_NAME (type_name)); | |
51e29401 RS |
1041 | switch (TREE_CODE (type)) |
1042 | { | |
1043 | case RECORD_TYPE: | |
ab87f8c8 | 1044 | error ("`struct %s' incomplete in scope ending here", id); |
51e29401 RS |
1045 | break; |
1046 | case UNION_TYPE: | |
ab87f8c8 | 1047 | error ("`union %s' incomplete in scope ending here", id); |
51e29401 RS |
1048 | break; |
1049 | case ENUMERAL_TYPE: | |
ab87f8c8 | 1050 | error ("`enum %s' incomplete in scope ending here", id); |
51e29401 RS |
1051 | break; |
1052 | } | |
51e29401 RS |
1053 | } |
1054 | #endif /* 0 */ | |
1055 | ||
1056 | /* Get the decls in the order they were written. | |
1057 | Usually current_binding_level->names is in reverse order. | |
1058 | But parameter decls were previously put in forward order. */ | |
1059 | ||
1060 | if (reverse) | |
1061 | current_binding_level->names | |
1062 | = decls = nreverse (current_binding_level->names); | |
1063 | else | |
1064 | decls = current_binding_level->names; | |
1065 | ||
1066 | /* Output any nested inline functions within this block | |
1067 | if they weren't already output. */ | |
1068 | ||
1069 | for (decl = decls; decl; decl = TREE_CHAIN (decl)) | |
1070 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1071 | && ! TREE_ASM_WRITTEN (decl) | |
1072 | && DECL_INITIAL (decl) != 0 | |
1073 | && TREE_ADDRESSABLE (decl)) | |
42dfa47f RS |
1074 | { |
1075 | /* If this decl was copied from a file-scope decl | |
1076 | on account of a block-scope extern decl, | |
6272a449 JW |
1077 | propagate TREE_ADDRESSABLE to the file-scope decl. |
1078 | ||
1079 | DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is | |
1080 | true, since then the decl goes through save_for_inline_copying. */ | |
1081 | if (DECL_ABSTRACT_ORIGIN (decl) != 0 | |
1082 | && DECL_ABSTRACT_ORIGIN (decl) != decl) | |
42dfa47f | 1083 | TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; |
42dfa47f | 1084 | } |
51e29401 | 1085 | |
8e5a0fcb RH |
1086 | /* We used to warn about unused variables in expand_end_bindings, |
1087 | i.e. while generating RTL. But in function-at-a-time mode we may | |
1088 | choose to never expand a function at all (e.g. auto inlining), so | |
1089 | we do this explicitly now. */ | |
1090 | warn_about_unused_variables (getdecls ()); | |
1091 | ||
51e29401 RS |
1092 | /* If there were any declarations or structure tags in that level, |
1093 | or if this level is a function body, | |
1094 | create a BLOCK to record them for the life of this function. */ | |
1095 | ||
3bf40d18 | 1096 | block = 0; |
968e5643 RS |
1097 | block_previously_created = (current_binding_level->this_block != 0); |
1098 | if (block_previously_created) | |
3bf40d18 RS |
1099 | block = current_binding_level->this_block; |
1100 | else if (keep || functionbody | |
1101 | || (current_binding_level->keep_if_subblocks && subblocks != 0)) | |
1102 | block = make_node (BLOCK); | |
1103 | if (block != 0) | |
1104 | { | |
1105 | BLOCK_VARS (block) = decls; | |
3bf40d18 RS |
1106 | BLOCK_SUBBLOCKS (block) = subblocks; |
1107 | } | |
51e29401 RS |
1108 | |
1109 | /* In each subblock, record that this is its superior. */ | |
1110 | ||
1111 | for (link = subblocks; link; link = TREE_CHAIN (link)) | |
1112 | BLOCK_SUPERCONTEXT (link) = block; | |
1113 | ||
1114 | /* Clear out the meanings of the local variables of this level. */ | |
1115 | ||
1116 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1117 | { | |
1118 | if (DECL_NAME (link) != 0) | |
1119 | { | |
1120 | /* If the ident. was used or addressed via a local extern decl, | |
1121 | don't forget that fact. */ | |
1394aabd | 1122 | if (DECL_EXTERNAL (link)) |
51e29401 RS |
1123 | { |
1124 | if (TREE_USED (link)) | |
1125 | TREE_USED (DECL_NAME (link)) = 1; | |
1126 | if (TREE_ADDRESSABLE (link)) | |
1127 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1128 | } | |
1129 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; | |
1130 | } | |
1131 | } | |
1132 | ||
1133 | /* Restore all name-meanings of the outer levels | |
1134 | that were shadowed by this level. */ | |
1135 | ||
1136 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1137 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1138 | ||
1139 | /* If the level being exited is the top level of a function, | |
1140 | check over all the labels, and clear out the current | |
1141 | (function local) meanings of their names. */ | |
1142 | ||
1143 | if (functionbody) | |
1144 | { | |
0500d6f9 RK |
1145 | clear_limbo_values (block); |
1146 | ||
51e29401 RS |
1147 | /* If this is the top level block of a function, |
1148 | the vars are the function's parameters. | |
1149 | Don't leave them in the BLOCK because they are | |
1150 | found in the FUNCTION_DECL instead. */ | |
1151 | ||
1152 | BLOCK_VARS (block) = 0; | |
1153 | ||
1154 | /* Clear out the definitions of all label names, | |
1155 | since their scopes end here, | |
1156 | and add them to BLOCK_VARS. */ | |
1157 | ||
1158 | for (link = named_labels; link; link = TREE_CHAIN (link)) | |
1159 | { | |
1160 | register tree label = TREE_VALUE (link); | |
1161 | ||
1162 | if (DECL_INITIAL (label) == 0) | |
1163 | { | |
1164 | error_with_decl (label, "label `%s' used but not defined"); | |
1165 | /* Avoid crashing later. */ | |
1166 | define_label (input_filename, lineno, | |
1167 | DECL_NAME (label)); | |
1168 | } | |
078721e1 | 1169 | else if (warn_unused_label && !TREE_USED (label)) |
51e29401 RS |
1170 | warning_with_decl (label, "label `%s' defined but not used"); |
1171 | IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0; | |
1172 | ||
1173 | /* Put the labels into the "variables" of the | |
1174 | top-level block, so debugger can see them. */ | |
1175 | TREE_CHAIN (label) = BLOCK_VARS (block); | |
1176 | BLOCK_VARS (block) = label; | |
1177 | } | |
1178 | } | |
1179 | ||
1180 | /* Pop the current level, and free the structure for reuse. */ | |
1181 | ||
1182 | { | |
1183 | register struct binding_level *level = current_binding_level; | |
1184 | current_binding_level = current_binding_level->level_chain; | |
1185 | ||
1186 | level->level_chain = free_binding_level; | |
1187 | free_binding_level = level; | |
1188 | } | |
1189 | ||
1190 | /* Dispose of the block that we just made inside some higher level. */ | |
1191 | if (functionbody) | |
1192 | DECL_INITIAL (current_function_decl) = block; | |
1193 | else if (block) | |
968e5643 RS |
1194 | { |
1195 | if (!block_previously_created) | |
6645c3fa KH |
1196 | current_binding_level->blocks |
1197 | = chainon (current_binding_level->blocks, block); | |
968e5643 | 1198 | } |
51e29401 RS |
1199 | /* If we did not make a block for the level just exited, |
1200 | any blocks made for inner levels | |
1201 | (since they cannot be recorded as subblocks in that level) | |
1202 | must be carried forward so they will later become subblocks | |
1203 | of something else. */ | |
1204 | else if (subblocks) | |
1205 | current_binding_level->blocks | |
1206 | = chainon (current_binding_level->blocks, subblocks); | |
1207 | ||
1208 | /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this | |
1209 | binding contour so that they point to the appropriate construct, i.e. | |
1210 | either to the current FUNCTION_DECL node, or else to the BLOCK node | |
1211 | we just constructed. | |
1212 | ||
1213 | Note that for tagged types whose scope is just the formal parameter | |
1214 | list for some function type specification, we can't properly set | |
1215 | their TYPE_CONTEXTs here, because we don't have a pointer to the | |
1216 | appropriate FUNCTION_TYPE node readily available to us. For those | |
1217 | cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set | |
1218 | in `grokdeclarator' as soon as we have created the FUNCTION_TYPE | |
1219 | node which will represent the "scope" for these "parameter list local" | |
6645c3fa | 1220 | tagged types. */ |
51e29401 RS |
1221 | |
1222 | if (functionbody) | |
1223 | for (link = tags; link; link = TREE_CHAIN (link)) | |
1224 | TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl; | |
1225 | else if (block) | |
1226 | for (link = tags; link; link = TREE_CHAIN (link)) | |
1227 | TYPE_CONTEXT (TREE_VALUE (link)) = block; | |
1228 | ||
1229 | if (block) | |
1230 | TREE_USED (block) = 1; | |
8f17b5c5 | 1231 | |
51e29401 RS |
1232 | return block; |
1233 | } | |
3bf40d18 RS |
1234 | |
1235 | /* Delete the node BLOCK from the current binding level. | |
1236 | This is used for the block inside a stmt expr ({...}) | |
1237 | so that the block can be reinserted where appropriate. */ | |
1238 | ||
1239 | void | |
1240 | delete_block (block) | |
1241 | tree block; | |
1242 | { | |
1243 | tree t; | |
1244 | if (current_binding_level->blocks == block) | |
1245 | current_binding_level->blocks = TREE_CHAIN (block); | |
1246 | for (t = current_binding_level->blocks; t;) | |
1247 | { | |
1248 | if (TREE_CHAIN (t) == block) | |
1249 | TREE_CHAIN (t) = TREE_CHAIN (block); | |
1250 | else | |
1251 | t = TREE_CHAIN (t); | |
1252 | } | |
1253 | TREE_CHAIN (block) = NULL; | |
1254 | /* Clear TREE_USED which is always set by poplevel. | |
1255 | The flag is set again if insert_block is called. */ | |
1256 | TREE_USED (block) = 0; | |
1257 | } | |
1258 | ||
1259 | /* Insert BLOCK at the end of the list of subblocks of the | |
1260 | current binding level. This is used when a BIND_EXPR is expanded, | |
6f65afb0 | 1261 | to handle the BLOCK node inside the BIND_EXPR. */ |
3bf40d18 RS |
1262 | |
1263 | void | |
1264 | insert_block (block) | |
1265 | tree block; | |
1266 | { | |
1267 | TREE_USED (block) = 1; | |
1268 | current_binding_level->blocks | |
1269 | = chainon (current_binding_level->blocks, block); | |
1270 | } | |
1271 | ||
968e5643 | 1272 | /* Set the BLOCK node for the innermost scope |
3bf40d18 RS |
1273 | (the one we are currently in). */ |
1274 | ||
968e5643 RS |
1275 | void |
1276 | set_block (block) | |
1277 | register tree block; | |
3bf40d18 | 1278 | { |
968e5643 | 1279 | current_binding_level->this_block = block; |
3bf40d18 | 1280 | } |
51e29401 RS |
1281 | \f |
1282 | void | |
1283 | push_label_level () | |
1284 | { | |
1285 | register struct binding_level *newlevel; | |
1286 | ||
1287 | /* Reuse or create a struct for this binding level. */ | |
1288 | ||
1289 | if (free_binding_level) | |
1290 | { | |
1291 | newlevel = free_binding_level; | |
1292 | free_binding_level = free_binding_level->level_chain; | |
1293 | } | |
1294 | else | |
1295 | { | |
1296 | newlevel = make_binding_level (); | |
1297 | } | |
1298 | ||
1299 | /* Add this level to the front of the chain (stack) of label levels. */ | |
1300 | ||
1301 | newlevel->level_chain = label_level_chain; | |
1302 | label_level_chain = newlevel; | |
1303 | ||
1304 | newlevel->names = named_labels; | |
1305 | newlevel->shadowed = shadowed_labels; | |
1306 | named_labels = 0; | |
1307 | shadowed_labels = 0; | |
1308 | } | |
1309 | ||
1310 | void | |
1311 | pop_label_level () | |
1312 | { | |
1313 | register struct binding_level *level = label_level_chain; | |
1314 | tree link, prev; | |
1315 | ||
1316 | /* Clear out the definitions of the declared labels in this level. | |
1317 | Leave in the list any ordinary, non-declared labels. */ | |
1318 | for (link = named_labels, prev = 0; link;) | |
1319 | { | |
1320 | if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link))) | |
1321 | { | |
1322 | if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0) | |
1323 | { | |
6b2a374b RK |
1324 | error_with_decl (TREE_VALUE (link), |
1325 | "label `%s' used but not defined"); | |
51e29401 RS |
1326 | /* Avoid crashing later. */ |
1327 | define_label (input_filename, lineno, | |
1328 | DECL_NAME (TREE_VALUE (link))); | |
1329 | } | |
078721e1 | 1330 | else if (warn_unused_label && !TREE_USED (TREE_VALUE (link))) |
6645c3fa | 1331 | warning_with_decl (TREE_VALUE (link), |
51e29401 RS |
1332 | "label `%s' defined but not used"); |
1333 | IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0; | |
1334 | ||
1335 | /* Delete this element from the list. */ | |
1336 | link = TREE_CHAIN (link); | |
1337 | if (prev) | |
1338 | TREE_CHAIN (prev) = link; | |
1339 | else | |
1340 | named_labels = link; | |
1341 | } | |
1342 | else | |
1343 | { | |
1344 | prev = link; | |
1345 | link = TREE_CHAIN (link); | |
1346 | } | |
1347 | } | |
1348 | ||
1349 | /* Bring back all the labels that were shadowed. */ | |
1350 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
1351 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
1352 | IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) | |
1353 | = TREE_VALUE (link); | |
1354 | ||
1355 | named_labels = chainon (named_labels, level->names); | |
1356 | shadowed_labels = level->shadowed; | |
1357 | ||
1358 | /* Pop the current level, and free the structure for reuse. */ | |
1359 | label_level_chain = label_level_chain->level_chain; | |
1360 | level->level_chain = free_binding_level; | |
1361 | free_binding_level = level; | |
1362 | } | |
1363 | \f | |
1364 | /* Push a definition or a declaration of struct, union or enum tag "name". | |
1365 | "type" should be the type node. | |
1366 | We assume that the tag "name" is not already defined. | |
1367 | ||
1368 | Note that the definition may really be just a forward reference. | |
1369 | In that case, the TYPE_SIZE will be zero. */ | |
1370 | ||
1371 | void | |
1372 | pushtag (name, type) | |
1373 | tree name, type; | |
1374 | { | |
1375 | register struct binding_level *b; | |
1376 | ||
1377 | /* Find the proper binding level for this type tag. */ | |
1378 | ||
1379 | for (b = current_binding_level; b->tag_transparent; b = b->level_chain) | |
1380 | continue; | |
1381 | ||
1382 | if (name) | |
1383 | { | |
1384 | /* Record the identifier as the type's name if it has none. */ | |
1385 | ||
1386 | if (TYPE_NAME (type) == 0) | |
1387 | TYPE_NAME (type) = name; | |
51e29401 RS |
1388 | } |
1389 | ||
4dd7201e | 1390 | b->tags = tree_cons (name, type, b->tags); |
c138f328 | 1391 | |
51e29401 RS |
1392 | /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the |
1393 | tagged type we just added to the current binding level. This fake | |
1394 | NULL-named TYPE_DECL node helps dwarfout.c to know when it needs | |
858a47b1 | 1395 | to output a representation of a tagged type, and it also gives |
51e29401 RS |
1396 | us a convenient place to record the "scope start" address for the |
1397 | tagged type. */ | |
1398 | ||
8d9bfdc5 | 1399 | TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); |
88dad228 JM |
1400 | |
1401 | /* An approximation for now, so we can tell this is a function-scope tag. | |
1402 | This will be updated in poplevel. */ | |
1403 | TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type)); | |
51e29401 RS |
1404 | } |
1405 | \f | |
1406 | /* Handle when a new declaration NEWDECL | |
1407 | has the same name as an old one OLDDECL | |
1408 | in the same binding contour. | |
1409 | Prints an error message if appropriate. | |
1410 | ||
1411 | If safely possible, alter OLDDECL to look like NEWDECL, and return 1. | |
bf44f7de JW |
1412 | Otherwise, return 0. |
1413 | ||
1414 | When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration, | |
1415 | and OLDDECL is in an outer binding level and should thus not be changed. */ | |
51e29401 RS |
1416 | |
1417 | static int | |
bf44f7de | 1418 | duplicate_decls (newdecl, olddecl, different_binding_level) |
51e29401 | 1419 | register tree newdecl, olddecl; |
bf44f7de | 1420 | int different_binding_level; |
51e29401 RS |
1421 | { |
1422 | int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); | |
1423 | int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL | |
1424 | && DECL_INITIAL (newdecl) != 0); | |
664b4b1e RS |
1425 | tree oldtype = TREE_TYPE (olddecl); |
1426 | tree newtype = TREE_TYPE (newdecl); | |
ab87f8c8 | 1427 | int errmsg = 0; |
51e29401 | 1428 | |
2f939d94 | 1429 | if (DECL_P (olddecl)) |
d9525bec | 1430 | DECL_MACHINE_ATTRIBUTES (newdecl) |
6645c3fa | 1431 | = merge_machine_decl_attributes (olddecl, newdecl); |
4b4e3407 | 1432 | |
664b4b1e RS |
1433 | if (TREE_CODE (newtype) == ERROR_MARK |
1434 | || TREE_CODE (oldtype) == ERROR_MARK) | |
51e29401 RS |
1435 | types_match = 0; |
1436 | ||
1437 | /* New decl is completely inconsistent with the old one => | |
1438 | tell caller to replace the old one. | |
1439 | This is always an error except in the case of shadowing a builtin. */ | |
1440 | if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | |
1441 | { | |
1442 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
70efc776 RS |
1443 | && (DECL_BUILT_IN (olddecl) |
1444 | || DECL_BUILT_IN_NONANSI (olddecl))) | |
51e29401 | 1445 | { |
70efc776 RS |
1446 | /* If you declare a built-in or predefined function name as static, |
1447 | the old definition is overridden, | |
51e29401 RS |
1448 | but optionally warn this was a bad choice of name. */ |
1449 | if (!TREE_PUBLIC (newdecl)) | |
1450 | { | |
70efc776 RS |
1451 | if (!warn_shadow) |
1452 | ; | |
1453 | else if (DECL_BUILT_IN (olddecl)) | |
51e29401 | 1454 | warning_with_decl (newdecl, "shadowing built-in function `%s'"); |
70efc776 RS |
1455 | else |
1456 | warning_with_decl (newdecl, "shadowing library function `%s'"); | |
51e29401 RS |
1457 | } |
1458 | /* Likewise, if the built-in is not ansi, then programs can | |
929f3671 | 1459 | override it even globally without an error. */ |
70efc776 RS |
1460 | else if (! DECL_BUILT_IN (olddecl)) |
1461 | warning_with_decl (newdecl, | |
1462 | "library function `%s' declared as non-function"); | |
1463 | ||
51e29401 RS |
1464 | else if (DECL_BUILT_IN_NONANSI (olddecl)) |
1465 | warning_with_decl (newdecl, | |
1466 | "built-in function `%s' declared as non-function"); | |
51e29401 RS |
1467 | else |
1468 | warning_with_decl (newdecl, | |
6645c3fa | 1469 | "built-in function `%s' declared as non-function"); |
51e29401 RS |
1470 | } |
1471 | else | |
1472 | { | |
1473 | error_with_decl (newdecl, "`%s' redeclared as different kind of symbol"); | |
1474 | error_with_decl (olddecl, "previous declaration of `%s'"); | |
1475 | } | |
1476 | ||
1477 | return 0; | |
1478 | } | |
1479 | ||
1480 | /* For real parm decl following a forward decl, | |
1481 | return 1 so old decl will be reused. */ | |
1482 | if (types_match && TREE_CODE (newdecl) == PARM_DECL | |
1483 | && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl)) | |
1484 | return 1; | |
1485 | ||
1486 | /* The new declaration is the same kind of object as the old one. | |
1487 | The declarations may partially match. Print warnings if they don't | |
1488 | match enough. Ultimately, copy most of the information from the new | |
1489 | decl to the old one, and keep using the old one. */ | |
1490 | ||
1491 | if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL | |
1492 | && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl | |
1493 | && DECL_INITIAL (olddecl) == 0) | |
1494 | /* If -traditional, avoid error for redeclaring fcn | |
1495 | after implicit decl. */ | |
1496 | ; | |
1497 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
1498 | && DECL_BUILT_IN (olddecl)) | |
1499 | { | |
e841f997 | 1500 | /* A function declaration for a built-in function. */ |
51e29401 RS |
1501 | if (!TREE_PUBLIC (newdecl)) |
1502 | { | |
1503 | /* If you declare a built-in function name as static, the | |
1504 | built-in definition is overridden, | |
1505 | but optionally warn this was a bad choice of name. */ | |
1506 | if (warn_shadow) | |
1507 | warning_with_decl (newdecl, "shadowing built-in function `%s'"); | |
1508 | /* Discard the old built-in function. */ | |
1509 | return 0; | |
1510 | } | |
1511 | else if (!types_match) | |
4c41bbfa | 1512 | { |
6645c3fa | 1513 | /* Accept the return type of the new declaration if same modes. */ |
bf44f7de JW |
1514 | tree oldreturntype = TREE_TYPE (oldtype); |
1515 | tree newreturntype = TREE_TYPE (newtype); | |
4fc7cf69 | 1516 | |
6645c3fa KH |
1517 | if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype)) |
1518 | { | |
32436219 RS |
1519 | /* Function types may be shared, so we can't just modify |
1520 | the return type of olddecl's function type. */ | |
bf44f7de | 1521 | tree trytype |
32436219 | 1522 | = build_function_type (newreturntype, |
bf44f7de | 1523 | TYPE_ARG_TYPES (oldtype)); |
6645c3fa | 1524 | |
bf44f7de | 1525 | types_match = comptypes (newtype, trytype); |
1f7586c1 | 1526 | if (types_match) |
bf44f7de | 1527 | oldtype = trytype; |
1f7586c1 RS |
1528 | } |
1529 | /* Accept harmless mismatch in first argument type also. | |
1530 | This is for ffs. */ | |
1531 | if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0 | |
bf44f7de JW |
1532 | && TYPE_ARG_TYPES (oldtype) != 0 |
1533 | && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0 | |
1534 | && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0 | |
1535 | && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype))) | |
1536 | == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype))))) | |
1f7586c1 RS |
1537 | { |
1538 | /* Function types may be shared, so we can't just modify | |
1539 | the return type of olddecl's function type. */ | |
bf44f7de JW |
1540 | tree trytype |
1541 | = build_function_type (TREE_TYPE (oldtype), | |
6645c3fa | 1542 | tree_cons (NULL_TREE, |
bf44f7de JW |
1543 | TREE_VALUE (TYPE_ARG_TYPES (newtype)), |
1544 | TREE_CHAIN (TYPE_ARG_TYPES (oldtype)))); | |
6645c3fa KH |
1545 | |
1546 | types_match = comptypes (newtype, trytype); | |
32436219 | 1547 | if (types_match) |
bf44f7de | 1548 | oldtype = trytype; |
4c41bbfa | 1549 | } |
bf44f7de JW |
1550 | if (! different_binding_level) |
1551 | TREE_TYPE (olddecl) = oldtype; | |
4c41bbfa RS |
1552 | } |
1553 | if (!types_match) | |
52b6a22f RS |
1554 | { |
1555 | /* If types don't match for a built-in, throw away the built-in. */ | |
1556 | warning_with_decl (newdecl, "conflicting types for built-in function `%s'"); | |
1557 | return 0; | |
1558 | } | |
51e29401 RS |
1559 | } |
1560 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
e841f997 | 1561 | && DECL_SOURCE_LINE (olddecl) == 0) |
51e29401 | 1562 | { |
e841f997 RS |
1563 | /* A function declaration for a predeclared function |
1564 | that isn't actually built in. */ | |
51e29401 RS |
1565 | if (!TREE_PUBLIC (newdecl)) |
1566 | { | |
858a47b1 | 1567 | /* If you declare it as static, the |
e841f997 | 1568 | default definition is overridden. */ |
51e29401 RS |
1569 | return 0; |
1570 | } | |
1571 | else if (!types_match) | |
e841f997 | 1572 | { |
4d06f145 RS |
1573 | /* If the types don't match, preserve volatility indication. |
1574 | Later on, we will discard everything else about the | |
1575 | default declaration. */ | |
e841f997 | 1576 | TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); |
e841f997 | 1577 | } |
51e29401 | 1578 | } |
592252ad RS |
1579 | /* Permit char *foo () to match void *foo (...) if not pedantic, |
1580 | if one of them came from a system header file. */ | |
a4219ac7 RS |
1581 | else if (!types_match |
1582 | && TREE_CODE (olddecl) == FUNCTION_DECL | |
1583 | && TREE_CODE (newdecl) == FUNCTION_DECL | |
664b4b1e RS |
1584 | && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE |
1585 | && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE | |
592252ad RS |
1586 | && (DECL_IN_SYSTEM_HEADER (olddecl) |
1587 | || DECL_IN_SYSTEM_HEADER (newdecl)) | |
5fe86b8b | 1588 | && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node |
664b4b1e RS |
1589 | && TYPE_ARG_TYPES (oldtype) == 0 |
1590 | && self_promoting_args_p (TYPE_ARG_TYPES (newtype)) | |
1591 | && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node) | |
a4219ac7 | 1592 | || |
664b4b1e RS |
1593 | (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node |
1594 | && TYPE_ARG_TYPES (newtype) == 0 | |
1595 | && self_promoting_args_p (TYPE_ARG_TYPES (oldtype)) | |
5fe86b8b | 1596 | && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node))) |
a4219ac7 RS |
1597 | { |
1598 | if (pedantic) | |
1599 | pedwarn_with_decl (newdecl, "conflicting types for `%s'"); | |
664b4b1e | 1600 | /* Make sure we keep void * as ret type, not char *. */ |
5fe86b8b | 1601 | if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node) |
664b4b1e | 1602 | TREE_TYPE (newdecl) = newtype = oldtype; |
1d00bef8 JW |
1603 | |
1604 | /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration | |
1605 | we will come back here again. */ | |
1606 | DECL_IN_SYSTEM_HEADER (newdecl) = 1; | |
a4219ac7 | 1607 | } |
51e29401 RS |
1608 | else if (!types_match |
1609 | /* Permit char *foo (int, ...); followed by char *foo (); | |
1610 | if not pedantic. */ | |
1611 | && ! (TREE_CODE (olddecl) == FUNCTION_DECL | |
1612 | && ! pedantic | |
1613 | /* Return types must still match. */ | |
664b4b1e RS |
1614 | && comptypes (TREE_TYPE (oldtype), |
1615 | TREE_TYPE (newtype)) | |
1616 | && TYPE_ARG_TYPES (newtype) == 0)) | |
51e29401 RS |
1617 | { |
1618 | error_with_decl (newdecl, "conflicting types for `%s'"); | |
1619 | /* Check for function type mismatch | |
1620 | involving an empty arglist vs a nonempty one. */ | |
1621 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
664b4b1e RS |
1622 | && comptypes (TREE_TYPE (oldtype), |
1623 | TREE_TYPE (newtype)) | |
1624 | && ((TYPE_ARG_TYPES (oldtype) == 0 | |
51e29401 RS |
1625 | && DECL_INITIAL (olddecl) == 0) |
1626 | || | |
664b4b1e | 1627 | (TYPE_ARG_TYPES (newtype) == 0 |
51e29401 RS |
1628 | && DECL_INITIAL (newdecl) == 0))) |
1629 | { | |
1630 | /* Classify the problem further. */ | |
664b4b1e | 1631 | register tree t = TYPE_ARG_TYPES (oldtype); |
51e29401 | 1632 | if (t == 0) |
664b4b1e | 1633 | t = TYPE_ARG_TYPES (newtype); |
51e29401 RS |
1634 | for (; t; t = TREE_CHAIN (t)) |
1635 | { | |
1636 | register tree type = TREE_VALUE (t); | |
1637 | ||
5fe86b8b RS |
1638 | if (TREE_CHAIN (t) == 0 |
1639 | && TYPE_MAIN_VARIANT (type) != void_type_node) | |
51e29401 | 1640 | { |
ab87f8c8 | 1641 | error ("A parameter list with an ellipsis can't match an empty parameter name list declaration."); |
51e29401 RS |
1642 | break; |
1643 | } | |
1644 | ||
c530479e | 1645 | if (simple_type_promotes_to (type) != NULL_TREE) |
51e29401 | 1646 | { |
ab87f8c8 | 1647 | error ("An argument type that has a default promotion can't match an empty parameter name list declaration."); |
51e29401 RS |
1648 | break; |
1649 | } | |
1650 | } | |
1651 | } | |
1652 | error_with_decl (olddecl, "previous declaration of `%s'"); | |
1653 | } | |
1654 | else | |
1655 | { | |
8e5e53da | 1656 | errmsg = redeclaration_error_message (newdecl, olddecl); |
51e29401 RS |
1657 | if (errmsg) |
1658 | { | |
ab87f8c8 JL |
1659 | switch (errmsg) |
1660 | { | |
1661 | case 1: | |
1662 | error_with_decl (newdecl, "redefinition of `%s'"); | |
1663 | break; | |
1664 | case 2: | |
1665 | error_with_decl (newdecl, "redeclaration of `%s'"); | |
1666 | break; | |
1667 | case 3: | |
1668 | error_with_decl (newdecl, "conflicting declarations of `%s'"); | |
1669 | break; | |
1670 | default: | |
1671 | abort (); | |
1672 | } | |
1673 | ||
51e29401 | 1674 | error_with_decl (olddecl, |
d847e6a7 RS |
1675 | ((DECL_INITIAL (olddecl) |
1676 | && current_binding_level == global_binding_level) | |
1677 | ? "`%s' previously defined here" | |
1678 | : "`%s' previously declared here")); | |
51e29401 | 1679 | } |
4b4e3407 | 1680 | else if (TREE_CODE (newdecl) == TYPE_DECL |
6645c3fa | 1681 | && (DECL_IN_SYSTEM_HEADER (olddecl) |
4b4e3407 RK |
1682 | || DECL_IN_SYSTEM_HEADER (newdecl))) |
1683 | { | |
1684 | warning_with_decl (newdecl, "redefinition of `%s'"); | |
6645c3fa | 1685 | warning_with_decl |
4b4e3407 RK |
1686 | (olddecl, |
1687 | ((DECL_INITIAL (olddecl) | |
1688 | && current_binding_level == global_binding_level) | |
1689 | ? "`%s' previously defined here" | |
1690 | : "`%s' previously declared here")); | |
1691 | } | |
51e29401 RS |
1692 | else if (TREE_CODE (olddecl) == FUNCTION_DECL |
1693 | && DECL_INITIAL (olddecl) != 0 | |
664b4b1e | 1694 | && TYPE_ARG_TYPES (oldtype) == 0 |
f5ec0026 RK |
1695 | && TYPE_ARG_TYPES (newtype) != 0 |
1696 | && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0) | |
51e29401 RS |
1697 | { |
1698 | register tree type, parm; | |
1699 | register int nargs; | |
1700 | /* Prototype decl follows defn w/o prototype. */ | |
1701 | ||
664b4b1e RS |
1702 | for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype), |
1703 | type = TYPE_ARG_TYPES (newtype), | |
51e29401 | 1704 | nargs = 1; |
ab87f8c8 | 1705 | ; |
51e29401 RS |
1706 | parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++) |
1707 | { | |
ab87f8c8 JL |
1708 | if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node |
1709 | && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) | |
1710 | { | |
1711 | warning_with_decl (newdecl, "prototype for `%s' follows"); | |
1712 | warning_with_decl (olddecl, "non-prototype definition here"); | |
1713 | break; | |
1714 | } | |
5fe86b8b RS |
1715 | if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node |
1716 | || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) | |
51e29401 | 1717 | { |
6645c3fa KH |
1718 | error_with_decl (newdecl, |
1719 | "prototype for `%s' follows and number of arguments doesn't match"); | |
ab87f8c8 JL |
1720 | error_with_decl (olddecl, "non-prototype definition here"); |
1721 | errmsg = 1; | |
51e29401 RS |
1722 | break; |
1723 | } | |
1724 | /* Type for passing arg must be consistent | |
1725 | with that declared for the arg. */ | |
1726 | if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type)) | |
1727 | /* If -traditional, allow `unsigned int' instead of `int' | |
1728 | in the prototype. */ | |
1729 | && (! (flag_traditional | |
90d56da8 RS |
1730 | && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node |
1731 | && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))) | |
51e29401 | 1732 | { |
ab87f8c8 JL |
1733 | error_with_decl (newdecl, |
1734 | "prototype for `%s' follows and argument %d doesn't match", | |
1735 | nargs); | |
1736 | error_with_decl (olddecl, "non-prototype definition here"); | |
1737 | errmsg = 1; | |
51e29401 RS |
1738 | break; |
1739 | } | |
1740 | } | |
51e29401 | 1741 | } |
8eebb258 | 1742 | /* Warn about mismatches in various flags. */ |
51e29401 RS |
1743 | else |
1744 | { | |
8eebb258 RS |
1745 | /* Warn if function is now inline |
1746 | but was previously declared not inline and has been called. */ | |
51e29401 | 1747 | if (TREE_CODE (olddecl) == FUNCTION_DECL |
1394aabd | 1748 | && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl) |
51e29401 RS |
1749 | && TREE_USED (olddecl)) |
1750 | warning_with_decl (newdecl, | |
1751 | "`%s' declared inline after being called"); | |
1752 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
1394aabd | 1753 | && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl) |
960a2eb1 | 1754 | && DECL_INITIAL (olddecl) != 0) |
51e29401 | 1755 | warning_with_decl (newdecl, |
960a2eb1 | 1756 | "`%s' declared inline after its definition"); |
a1a77352 JW |
1757 | |
1758 | /* If pedantic, warn when static declaration follows a non-static | |
1759 | declaration. Otherwise, do so only for functions. */ | |
1760 | if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL) | |
51e29401 RS |
1761 | && TREE_PUBLIC (olddecl) |
1762 | && !TREE_PUBLIC (newdecl)) | |
1763 | warning_with_decl (newdecl, "static declaration for `%s' follows non-static"); | |
1764 | ||
db838bb8 | 1765 | /* If warn_traditional, warn when a non-static function |
6645c3fa | 1766 | declaration follows a static one. */ |
cde6e684 | 1767 | if (warn_traditional && !in_system_header |
db838bb8 KG |
1768 | && TREE_CODE (olddecl) == FUNCTION_DECL |
1769 | && !TREE_PUBLIC (olddecl) | |
1770 | && TREE_PUBLIC (newdecl)) | |
1771 | warning_with_decl (newdecl, "non-static declaration for `%s' follows static"); | |
1772 | ||
2af6a433 RK |
1773 | /* Warn when const declaration follows a non-const |
1774 | declaration, but not for functions. */ | |
1775 | if (TREE_CODE (olddecl) != FUNCTION_DECL | |
1776 | && !TREE_READONLY (olddecl) | |
1777 | && TREE_READONLY (newdecl)) | |
1778 | warning_with_decl (newdecl, "const declaration for `%s' follows non-const"); | |
8eebb258 RS |
1779 | /* These bits are logically part of the type, for variables. |
1780 | But not for functions | |
1781 | (where qualifiers are not valid ANSI anyway). */ | |
2af6a433 | 1782 | else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL |
51e29401 RS |
1783 | && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) |
1784 | || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) | |
1785 | pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl"); | |
1786 | } | |
1787 | } | |
1788 | ||
27f427f8 | 1789 | /* Optionally warn about more than one declaration for the same name. */ |
5ce574f2 | 1790 | if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0 |
956d6950 | 1791 | /* Don't warn about a function declaration |
27f427f8 RS |
1792 | followed by a definition. */ |
1793 | && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0 | |
ec820a12 RS |
1794 | && DECL_INITIAL (olddecl) == 0) |
1795 | /* Don't warn about extern decl followed by (tentative) definition. */ | |
1796 | && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) | |
27f427f8 RS |
1797 | { |
1798 | warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope"); | |
1799 | warning_with_decl (olddecl, "previous declaration of `%s'"); | |
1800 | } | |
1801 | ||
51e29401 | 1802 | /* Copy all the DECL_... slots specified in the new decl |
664b4b1e RS |
1803 | except for any that we copy here from the old type. |
1804 | ||
1805 | Past this point, we don't change OLDTYPE and NEWTYPE | |
1806 | even if we change the types of NEWDECL and OLDDECL. */ | |
51e29401 RS |
1807 | |
1808 | if (types_match) | |
1809 | { | |
bf44f7de JW |
1810 | /* When copying info to olddecl, we store into write_olddecl |
1811 | instead. This allows us to avoid modifying olddecl when | |
1812 | different_binding_level is true. */ | |
1813 | tree write_olddecl = different_binding_level ? newdecl : olddecl; | |
1814 | ||
51e29401 RS |
1815 | /* Merge the data types specified in the two decls. */ |
1816 | if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl)) | |
bf44f7de JW |
1817 | { |
1818 | if (different_binding_level) | |
1819 | TREE_TYPE (newdecl) | |
1820 | = build_type_attribute_variant | |
1821 | (newtype, | |
1822 | merge_attributes (TYPE_ATTRIBUTES (newtype), | |
1823 | TYPE_ATTRIBUTES (oldtype))); | |
1824 | else | |
1825 | TREE_TYPE (newdecl) | |
1826 | = TREE_TYPE (olddecl) | |
1827 | = common_type (newtype, oldtype); | |
1828 | } | |
51e29401 RS |
1829 | |
1830 | /* Lay the type out, unless already done. */ | |
1831 | if (oldtype != TREE_TYPE (newdecl)) | |
1832 | { | |
1833 | if (TREE_TYPE (newdecl) != error_mark_node) | |
1834 | layout_type (TREE_TYPE (newdecl)); | |
1835 | if (TREE_CODE (newdecl) != FUNCTION_DECL | |
1836 | && TREE_CODE (newdecl) != TYPE_DECL | |
1837 | && TREE_CODE (newdecl) != CONST_DECL) | |
1838 | layout_decl (newdecl, 0); | |
1839 | } | |
1840 | else | |
1841 | { | |
1842 | /* Since the type is OLDDECL's, make OLDDECL's size go with. */ | |
1843 | DECL_SIZE (newdecl) = DECL_SIZE (olddecl); | |
06ceef4e | 1844 | DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl); |
efd67b42 | 1845 | DECL_MODE (newdecl) = DECL_MODE (olddecl); |
ec2343c4 MM |
1846 | if (TREE_CODE (olddecl) != FUNCTION_DECL) |
1847 | if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) | |
11cf4d18 JJ |
1848 | { |
1849 | DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); | |
1850 | DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl); | |
1851 | } | |
51e29401 RS |
1852 | } |
1853 | ||
fc542d3c RS |
1854 | /* Keep the old rtl since we can safely use it. */ |
1855 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
1856 | ||
51e29401 | 1857 | /* Merge the type qualifiers. */ |
17aec3eb RK |
1858 | if (TREE_CODE (olddecl) == FUNCTION_DECL |
1859 | && DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl) | |
1860 | && ! TREE_THIS_VOLATILE (newdecl)) | |
bf44f7de | 1861 | TREE_THIS_VOLATILE (write_olddecl) = 0; |
17aec3eb | 1862 | |
51e29401 | 1863 | if (TREE_READONLY (newdecl)) |
bf44f7de | 1864 | TREE_READONLY (write_olddecl) = 1; |
17aec3eb | 1865 | |
51e29401 | 1866 | if (TREE_THIS_VOLATILE (newdecl)) |
e2f6a3cf | 1867 | { |
bf44f7de | 1868 | TREE_THIS_VOLATILE (write_olddecl) = 1; |
79c28203 AO |
1869 | if (TREE_CODE (newdecl) == VAR_DECL |
1870 | /* If an automatic variable is re-declared in the same | |
1871 | function scope, but the old declaration was not | |
1872 | volatile, make_var_volatile() would crash because the | |
1873 | variable would have been assigned to a pseudo, not a | |
1874 | MEM. Since this duplicate declaration is invalid | |
1875 | anyway, we just skip the call. */ | |
1876 | && errmsg == 0) | |
e2f6a3cf RS |
1877 | make_var_volatile (newdecl); |
1878 | } | |
51e29401 | 1879 | |
bf44f7de JW |
1880 | /* Keep source location of definition rather than declaration. */ |
1881 | /* When called with different_binding_level set, keep the old | |
1882 | information so that meaningful diagnostics can be given. */ | |
1883 | if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0 | |
1884 | && ! different_binding_level) | |
51e29401 RS |
1885 | { |
1886 | DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); | |
1887 | DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); | |
1888 | } | |
1889 | ||
e2f6a3cf RS |
1890 | /* Merge the unused-warning information. */ |
1891 | if (DECL_IN_SYSTEM_HEADER (olddecl)) | |
1892 | DECL_IN_SYSTEM_HEADER (newdecl) = 1; | |
1893 | else if (DECL_IN_SYSTEM_HEADER (newdecl)) | |
bf44f7de | 1894 | DECL_IN_SYSTEM_HEADER (write_olddecl) = 1; |
e2f6a3cf | 1895 | |
51e29401 | 1896 | /* Merge the initialization information. */ |
bf44f7de JW |
1897 | /* When called with different_binding_level set, don't copy over |
1898 | DECL_INITIAL, so that we don't accidentally change function | |
1899 | declarations into function definitions. */ | |
1900 | if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level) | |
51e29401 | 1901 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); |
1e50b042 DE |
1902 | |
1903 | /* Merge the section attribute. | |
1904 | We want to issue an error if the sections conflict but that must be | |
1905 | done later in decl_attributes since we are called before attributes | |
1906 | are assigned. */ | |
1907 | if (DECL_SECTION_NAME (newdecl) == NULL_TREE) | |
1908 | DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); | |
46b1c393 | 1909 | |
c5c76735 JL |
1910 | /* Copy the assembler name. |
1911 | Currently, it can only be defined in the prototype. */ | |
1912 | DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); | |
1913 | ||
2c5f4139 JM |
1914 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
1915 | { | |
1916 | DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); | |
1917 | DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); | |
07417085 KR |
1918 | |
1919 | DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) | |
1920 | |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); | |
7d384cc0 KR |
1921 | DECL_NO_CHECK_MEMORY_USAGE (newdecl) |
1922 | |= DECL_NO_CHECK_MEMORY_USAGE (olddecl); | |
a157febd GK |
1923 | DECL_NO_LIMIT_STACK (newdecl) |
1924 | |= DECL_NO_LIMIT_STACK (olddecl); | |
2c5f4139 | 1925 | } |
51e29401 RS |
1926 | } |
1927 | /* If cannot merge, then use the new type and qualifiers, | |
1928 | and don't preserve the old rtl. */ | |
bf44f7de | 1929 | else if (! different_binding_level) |
51e29401 RS |
1930 | { |
1931 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
1932 | TREE_READONLY (olddecl) = TREE_READONLY (newdecl); | |
1933 | TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); | |
1934 | TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); | |
1935 | } | |
1936 | ||
1937 | /* Merge the storage class information. */ | |
6645c3fa | 1938 | DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); |
51e29401 RS |
1939 | /* For functions, static overrides non-static. */ |
1940 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
1941 | { | |
1942 | TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); | |
1943 | /* This is since we don't automatically | |
1944 | copy the attributes of NEWDECL into OLDDECL. */ | |
bf44f7de JW |
1945 | /* No need to worry about different_binding_level here because |
1946 | then TREE_PUBLIC (newdecl) was true. */ | |
51e29401 RS |
1947 | TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); |
1948 | /* If this clears `static', clear it in the identifier too. */ | |
1949 | if (! TREE_PUBLIC (olddecl)) | |
1950 | TREE_PUBLIC (DECL_NAME (olddecl)) = 0; | |
1951 | } | |
1394aabd | 1952 | if (DECL_EXTERNAL (newdecl)) |
51e29401 | 1953 | { |
edb4c415 JM |
1954 | if (! different_binding_level) |
1955 | { | |
1956 | /* Don't mess with these flags on local externs; they remain | |
1957 | external even if there's a declaration at file scope which | |
1958 | isn't. */ | |
1959 | TREE_STATIC (newdecl) = TREE_STATIC (olddecl); | |
1960 | DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); | |
1961 | } | |
51e29401 RS |
1962 | /* An extern decl does not override previous storage class. */ |
1963 | TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); | |
0ecef3cf RK |
1964 | if (! DECL_EXTERNAL (newdecl)) |
1965 | DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); | |
51e29401 RS |
1966 | } |
1967 | else | |
1968 | { | |
1969 | TREE_STATIC (olddecl) = TREE_STATIC (newdecl); | |
51e29401 RS |
1970 | TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); |
1971 | } | |
850cba29 | 1972 | |
bf44f7de | 1973 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
51e29401 | 1974 | { |
17aec3eb RK |
1975 | /* If either decl says `inline', this fn is inline, |
1976 | unless its definition was passed already. */ | |
1977 | if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0) | |
1978 | DECL_INLINE (olddecl) = 1; | |
1979 | ||
1980 | DECL_INLINE (newdecl) = DECL_INLINE (olddecl); | |
1981 | ||
51e29401 RS |
1982 | if (DECL_BUILT_IN (olddecl)) |
1983 | { | |
bf44f7de JW |
1984 | /* Get rid of any built-in function if new arg types don't match it |
1985 | or if we have a function definition. */ | |
1986 | if (! types_match || new_is_definition) | |
1987 | { | |
1988 | if (! different_binding_level) | |
1989 | { | |
1990 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
26db82d8 | 1991 | DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN; |
bf44f7de JW |
1992 | } |
1993 | } | |
1994 | else | |
1995 | { | |
1996 | /* If redeclaring a builtin function, and not a definition, | |
1997 | it stays built in. */ | |
26db82d8 | 1998 | DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); |
bf44f7de JW |
1999 | DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); |
2000 | } | |
51e29401 | 2001 | } |
bf44f7de JW |
2002 | /* Also preserve various other info from the definition. */ |
2003 | else if (! new_is_definition) | |
51e29401 | 2004 | DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); |
bf44f7de JW |
2005 | if (! new_is_definition) |
2006 | { | |
2007 | DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | |
2008 | /* When called with different_binding_level set, don't copy over | |
2009 | DECL_INITIAL, so that we don't accidentally change function | |
2010 | declarations into function definitions. */ | |
2011 | if (! different_binding_level) | |
2012 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
2013 | DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl); | |
2014 | DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | |
bb8eaf4a | 2015 | if (DECL_INLINE (newdecl)) |
9a6bb3f7 | 2016 | DECL_ABSTRACT_ORIGIN (newdecl) = DECL_ABSTRACT_ORIGIN (olddecl); |
bf44f7de JW |
2017 | } |
2018 | } | |
2019 | if (different_binding_level) | |
edb4c415 | 2020 | return 0; |
51e29401 | 2021 | |
850cba29 | 2022 | /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. |
e5e809f4 | 2023 | But preserve OLDDECL's DECL_UID. */ |
850cba29 RS |
2024 | { |
2025 | register unsigned olddecl_uid = DECL_UID (olddecl); | |
2026 | ||
da61dec9 JM |
2027 | memcpy ((char *) olddecl + sizeof (struct tree_common), |
2028 | (char *) newdecl + sizeof (struct tree_common), | |
2029 | sizeof (struct tree_decl) - sizeof (struct tree_common)); | |
850cba29 RS |
2030 | DECL_UID (olddecl) = olddecl_uid; |
2031 | } | |
51e29401 | 2032 | |
d9525bec BK |
2033 | /* NEWDECL contains the merged attribute lists. |
2034 | Update OLDDECL to be the same. */ | |
2035 | DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl); | |
2036 | ||
51e29401 RS |
2037 | return 1; |
2038 | } | |
2039 | ||
2040 | /* Record a decl-node X as belonging to the current lexical scope. | |
2041 | Check for errors (such as an incompatible declaration for the same | |
2042 | name already seen in the same scope). | |
2043 | ||
2044 | Returns either X or an old decl for the same name. | |
2045 | If an old decl is returned, it may have been smashed | |
2046 | to agree with what X says. */ | |
2047 | ||
2048 | tree | |
2049 | pushdecl (x) | |
2050 | tree x; | |
2051 | { | |
2052 | register tree t; | |
2053 | register tree name = DECL_NAME (x); | |
2054 | register struct binding_level *b = current_binding_level; | |
2055 | ||
2056 | DECL_CONTEXT (x) = current_function_decl; | |
89d7540d RS |
2057 | /* A local extern declaration for a function doesn't constitute nesting. |
2058 | A local auto declaration does, since it's a forward decl | |
2059 | for a nested function coming later. */ | |
8f17b5c5 MM |
2060 | if ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) |
2061 | && DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x)) | |
51e29401 RS |
2062 | DECL_CONTEXT (x) = 0; |
2063 | ||
1394aabd | 2064 | if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level |
6e026f48 MM |
2065 | && x != IDENTIFIER_IMPLICIT_DECL (name) |
2066 | /* Don't print error messages for __FUNCTION__ and __PRETTY_FUNCTION__ */ | |
2067 | && !DECL_IN_SYSTEM_HEADER (x)) | |
51e29401 RS |
2068 | warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name)); |
2069 | ||
2070 | if (name) | |
2071 | { | |
3b304f5b | 2072 | const char *file; |
51e29401 | 2073 | int line; |
bf44f7de | 2074 | int different_binding_level = 0; |
51e29401 | 2075 | |
bf44f7de | 2076 | t = lookup_name_current_level (name); |
93f623fa JW |
2077 | /* Don't type check externs here when -traditional. This is so that |
2078 | code with conflicting declarations inside blocks will get warnings | |
2079 | not errors. X11 for instance depends on this. */ | |
bf44f7de JW |
2080 | if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x) && ! flag_traditional) |
2081 | { | |
2082 | t = IDENTIFIER_GLOBAL_VALUE (name); | |
2083 | /* Type decls at global scope don't conflict with externs declared | |
2084 | inside lexical blocks. */ | |
2085 | if (t && TREE_CODE (t) == TYPE_DECL) | |
2086 | t = 0; | |
2087 | different_binding_level = 1; | |
2088 | } | |
51e29401 RS |
2089 | if (t != 0 && t == error_mark_node) |
2090 | /* error_mark_node is 0 for a while during initialization! */ | |
2091 | { | |
2092 | t = 0; | |
2093 | error_with_decl (x, "`%s' used prior to declaration"); | |
2094 | } | |
2095 | ||
2096 | if (t != 0) | |
2097 | { | |
2098 | file = DECL_SOURCE_FILE (t); | |
2099 | line = DECL_SOURCE_LINE (t); | |
2100 | } | |
2101 | ||
bf44f7de JW |
2102 | /* If this decl is `static' and an implicit decl was seen previously, |
2103 | warn. But don't complain if -traditional, | |
2104 | since traditional compilers don't complain. */ | |
2105 | if (! flag_traditional && TREE_PUBLIC (name) | |
2106 | /* Don't test for DECL_EXTERNAL, because grokdeclarator | |
2107 | sets this for all functions. */ | |
2108 | && ! TREE_PUBLIC (x) | |
d20ae480 | 2109 | && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level) |
bf44f7de JW |
2110 | /* We used to warn also for explicit extern followed by static, |
2111 | but sometimes you need to do it that way. */ | |
2112 | && IDENTIFIER_IMPLICIT_DECL (name) != 0) | |
2113 | { | |
2114 | pedwarn ("`%s' was declared implicitly `extern' and later `static'", | |
2115 | IDENTIFIER_POINTER (name)); | |
2116 | pedwarn_with_file_and_line | |
2117 | (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)), | |
2118 | DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)), | |
2119 | "previous declaration of `%s'", | |
2120 | IDENTIFIER_POINTER (name)); | |
f5963e61 | 2121 | TREE_THIS_VOLATILE (name) = 1; |
bf44f7de JW |
2122 | } |
2123 | ||
2124 | if (t != 0 && duplicate_decls (x, t, different_binding_level)) | |
51e29401 RS |
2125 | { |
2126 | if (TREE_CODE (t) == PARM_DECL) | |
2127 | { | |
2128 | /* Don't allow more than one "real" duplicate | |
2129 | of a forward parm decl. */ | |
2130 | TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x); | |
2131 | return t; | |
2132 | } | |
bf44f7de | 2133 | return t; |
51e29401 RS |
2134 | } |
2135 | ||
1ce634c3 RS |
2136 | /* If we are processing a typedef statement, generate a whole new |
2137 | ..._TYPE node (which will be just an variant of the existing | |
2138 | ..._TYPE node with identical properties) and then install the | |
2139 | TYPE_DECL node generated to represent the typedef name as the | |
2140 | TYPE_NAME of this brand new (duplicate) ..._TYPE node. | |
2141 | ||
2142 | The whole point here is to end up with a situation where each | |
2143 | and every ..._TYPE node the compiler creates will be uniquely | |
2144 | associated with AT MOST one node representing a typedef name. | |
2145 | This way, even though the compiler substitutes corresponding | |
2146 | ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very | |
2147 | early on, later parts of the compiler can always do the reverse | |
2148 | translation and get back the corresponding typedef name. For | |
2149 | example, given: | |
2150 | ||
2151 | typedef struct S MY_TYPE; | |
2152 | MY_TYPE object; | |
2153 | ||
2154 | Later parts of the compiler might only know that `object' was of | |
38e01259 | 2155 | type `struct S' if it were not for code just below. With this |
1ce634c3 RS |
2156 | code however, later parts of the compiler see something like: |
2157 | ||
2158 | struct S' == struct S | |
2159 | typedef struct S' MY_TYPE; | |
2160 | struct S' object; | |
2161 | ||
2162 | And they can then deduce (from the node for type struct S') that | |
2163 | the original object declaration was: | |
2164 | ||
2165 | MY_TYPE object; | |
2166 | ||
2167 | Being able to do this is important for proper support of protoize, | |
2168 | and also for generating precise symbolic debugging information | |
2169 | which takes full account of the programmer's (typedef) vocabulary. | |
2170 | ||
2171 | Obviously, we don't want to generate a duplicate ..._TYPE node if | |
2172 | the TYPE_DECL node that we are now processing really represents a | |
2173 | standard built-in type. | |
2174 | ||
51e29401 RS |
2175 | Since all standard types are effectively declared at line zero |
2176 | in the source file, we can easily check to see if we are working | |
2177 | on a standard type by checking the current value of lineno. */ | |
2178 | ||
2179 | if (TREE_CODE (x) == TYPE_DECL) | |
6645c3fa KH |
2180 | { |
2181 | if (DECL_SOURCE_LINE (x) == 0) | |
2182 | { | |
51e29401 | 2183 | if (TYPE_NAME (TREE_TYPE (x)) == 0) |
6645c3fa KH |
2184 | TYPE_NAME (TREE_TYPE (x)) = x; |
2185 | } | |
2186 | else if (TREE_TYPE (x) != error_mark_node | |
6553db01 | 2187 | && DECL_ORIGINAL_TYPE (x) == NULL_TREE) |
6645c3fa KH |
2188 | { |
2189 | tree tt = TREE_TYPE (x); | |
8ee15cd7 | 2190 | DECL_ORIGINAL_TYPE (x) = tt; |
6645c3fa KH |
2191 | tt = build_type_copy (tt); |
2192 | TYPE_NAME (tt) = x; | |
d20a70b4 | 2193 | TREE_USED (tt) = TREE_USED (x); |
6645c3fa KH |
2194 | TREE_TYPE (x) = tt; |
2195 | } | |
2196 | } | |
51e29401 | 2197 | |
fd0b8fce | 2198 | /* Multiple external decls of the same identifier ought to match. |
93f623fa JW |
2199 | Check against both global declarations (when traditional) and out of |
2200 | scope (limbo) block level declarations. | |
51e29401 | 2201 | |
fd0b8fce JW |
2202 | We get warnings about inline functions where they are defined. |
2203 | Avoid duplicate warnings where they are used. */ | |
17aec3eb RK |
2204 | if (TREE_PUBLIC (x) |
2205 | && ! (TREE_CODE (x) == FUNCTION_DECL && DECL_INLINE (x))) | |
51e29401 | 2206 | { |
93f623fa JW |
2207 | tree decl; |
2208 | ||
2209 | if (flag_traditional && IDENTIFIER_GLOBAL_VALUE (name) != 0 | |
2210 | && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) | |
2211 | || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) | |
2212 | decl = IDENTIFIER_GLOBAL_VALUE (name); | |
2213 | else if (IDENTIFIER_LIMBO_VALUE (name) != 0) | |
2214 | /* Decls in limbo are always extern, so no need to check that. */ | |
2215 | decl = IDENTIFIER_LIMBO_VALUE (name); | |
2216 | else | |
2217 | decl = 0; | |
fd0b8fce | 2218 | |
93f623fa | 2219 | if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl)) |
58811315 RS |
2220 | /* If old decl is built-in, we already warned if we should. */ |
2221 | && !DECL_BUILT_IN (decl)) | |
51e29401 RS |
2222 | { |
2223 | pedwarn_with_decl (x, | |
2224 | "type mismatch with previous external decl"); | |
fd0b8fce | 2225 | pedwarn_with_decl (decl, "previous external decl of `%s'"); |
51e29401 RS |
2226 | } |
2227 | } | |
2228 | ||
2229 | /* If a function has had an implicit declaration, and then is defined, | |
2230 | make sure they are compatible. */ | |
2231 | ||
2232 | if (IDENTIFIER_IMPLICIT_DECL (name) != 0 | |
2233 | && IDENTIFIER_GLOBAL_VALUE (name) == 0 | |
2234 | && TREE_CODE (x) == FUNCTION_DECL | |
2235 | && ! comptypes (TREE_TYPE (x), | |
2236 | TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name)))) | |
2237 | { | |
2238 | warning_with_decl (x, "type mismatch with previous implicit declaration"); | |
929f3671 RS |
2239 | warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name), |
2240 | "previous implicit declaration of `%s'"); | |
51e29401 RS |
2241 | } |
2242 | ||
2243 | /* In PCC-compatibility mode, extern decls of vars with no current decl | |
2244 | take effect at top level no matter where they are. */ | |
1394aabd | 2245 | if (flag_traditional && DECL_EXTERNAL (x) |
51e29401 RS |
2246 | && lookup_name (name) == 0) |
2247 | { | |
2248 | tree type = TREE_TYPE (x); | |
2249 | ||
2250 | /* But don't do this if the type contains temporary nodes. */ | |
2251 | while (type) | |
2252 | { | |
2253 | if (type == error_mark_node) | |
2254 | break; | |
04de7314 | 2255 | if (TYPE_CONTEXT (type)) |
51e29401 RS |
2256 | { |
2257 | warning_with_decl (x, "type of external `%s' is not global"); | |
2258 | /* By exiting the loop early, we leave TYPE nonzero, | |
2259 | and thus prevent globalization of the decl. */ | |
2260 | break; | |
2261 | } | |
2262 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
2263 | && TYPE_ARG_TYPES (type) != 0) | |
2264 | /* The types might not be truly local, | |
2265 | but the list of arg types certainly is temporary. | |
2266 | Since prototypes are nontraditional, | |
2267 | ok not to do the traditional thing. */ | |
2268 | break; | |
2269 | type = TREE_TYPE (type); | |
2270 | } | |
2271 | ||
2272 | if (type == 0) | |
2273 | b = global_binding_level; | |
2274 | } | |
2275 | ||
2276 | /* This name is new in its binding level. | |
2277 | Install the new declaration and return it. */ | |
2278 | if (b == global_binding_level) | |
2279 | { | |
2280 | /* Install a global value. */ | |
6645c3fa | 2281 | |
51e29401 RS |
2282 | /* If the first global decl has external linkage, |
2283 | warn if we later see static one. */ | |
2284 | if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x)) | |
2285 | TREE_PUBLIC (name) = 1; | |
2286 | ||
2287 | IDENTIFIER_GLOBAL_VALUE (name) = x; | |
2288 | ||
fd0b8fce JW |
2289 | /* We no longer care about any previous block level declarations. */ |
2290 | IDENTIFIER_LIMBO_VALUE (name) = 0; | |
2291 | ||
51e29401 RS |
2292 | /* Don't forget if the function was used via an implicit decl. */ |
2293 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
2294 | && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) | |
2295 | TREE_USED (x) = 1, TREE_USED (name) = 1; | |
2296 | ||
2297 | /* Don't forget if its address was taken in that way. */ | |
2298 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
2299 | && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) | |
2300 | TREE_ADDRESSABLE (x) = 1; | |
2301 | ||
2302 | /* Warn about mismatches against previous implicit decl. */ | |
2303 | if (IDENTIFIER_IMPLICIT_DECL (name) != 0 | |
2304 | /* If this real decl matches the implicit, don't complain. */ | |
2305 | && ! (TREE_CODE (x) == FUNCTION_DECL | |
90d56da8 RS |
2306 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x))) |
2307 | == integer_type_node))) | |
51e29401 RS |
2308 | pedwarn ("`%s' was previously implicitly declared to return `int'", |
2309 | IDENTIFIER_POINTER (name)); | |
2310 | ||
2311 | /* If this decl is `static' and an `extern' was seen previously, | |
2312 | that is erroneous. */ | |
2313 | if (TREE_PUBLIC (name) | |
1394aabd | 2314 | && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)) |
51e29401 | 2315 | { |
b0e919de RS |
2316 | /* Okay to redeclare an ANSI built-in as static. */ |
2317 | if (t != 0 && DECL_BUILT_IN (t)) | |
929f3671 RS |
2318 | ; |
2319 | /* Okay to declare a non-ANSI built-in as anything. */ | |
2320 | else if (t != 0 && DECL_BUILT_IN_NONANSI (t)) | |
2321 | ; | |
bf44f7de JW |
2322 | /* Okay to have global type decl after an earlier extern |
2323 | declaration inside a lexical block. */ | |
2324 | else if (TREE_CODE (x) == TYPE_DECL) | |
2325 | ; | |
929f3671 | 2326 | else if (IDENTIFIER_IMPLICIT_DECL (name)) |
f5963e61 JL |
2327 | { |
2328 | if (! TREE_THIS_VOLATILE (name)) | |
2329 | pedwarn ("`%s' was declared implicitly `extern' and later `static'", | |
2330 | IDENTIFIER_POINTER (name)); | |
2331 | } | |
51e29401 RS |
2332 | else |
2333 | pedwarn ("`%s' was declared `extern' and later `static'", | |
2334 | IDENTIFIER_POINTER (name)); | |
2335 | } | |
2336 | } | |
2337 | else | |
2338 | { | |
2339 | /* Here to install a non-global value. */ | |
2340 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
2341 | tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); | |
17aec3eb | 2342 | |
51e29401 RS |
2343 | IDENTIFIER_LOCAL_VALUE (name) = x; |
2344 | ||
2345 | /* If this is an extern function declaration, see if we | |
fc542d3c | 2346 | have a global definition or declaration for the function. */ |
51e29401 | 2347 | if (oldlocal == 0 |
51e29401 RS |
2348 | && oldglobal != 0 |
2349 | && TREE_CODE (x) == FUNCTION_DECL | |
17aec3eb RK |
2350 | && TREE_CODE (oldglobal) == FUNCTION_DECL |
2351 | && DECL_EXTERNAL (x) && ! DECL_INLINE (x)) | |
51e29401 RS |
2352 | { |
2353 | /* We have one. Their types must agree. */ | |
2354 | if (! comptypes (TREE_TYPE (x), | |
2355 | TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)))) | |
fc542d3c RS |
2356 | pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one"); |
2357 | else | |
2358 | { | |
2359 | /* Inner extern decl is inline if global one is. | |
2360 | Copy enough to really inline it. */ | |
2361 | if (DECL_INLINE (oldglobal)) | |
2362 | { | |
2363 | DECL_INLINE (x) = DECL_INLINE (oldglobal); | |
4135e766 RS |
2364 | DECL_INITIAL (x) = (current_function_decl == oldglobal |
2365 | ? 0 : DECL_INITIAL (oldglobal)); | |
fc542d3c | 2366 | DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal); |
a2469305 | 2367 | DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal); |
fc542d3c | 2368 | DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal); |
42dfa47f RS |
2369 | DECL_RESULT (x) = DECL_RESULT (oldglobal); |
2370 | TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal); | |
edb4c415 JM |
2371 | DECL_ABSTRACT_ORIGIN (x) |
2372 | = DECL_ABSTRACT_ORIGIN (oldglobal); | |
fc542d3c RS |
2373 | } |
2374 | /* Inner extern decl is built-in if global one is. */ | |
2375 | if (DECL_BUILT_IN (oldglobal)) | |
2376 | { | |
26db82d8 | 2377 | DECL_BUILT_IN_CLASS (x) = DECL_BUILT_IN_CLASS (oldglobal); |
678566a5 | 2378 | DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal); |
fc542d3c RS |
2379 | } |
2380 | /* Keep the arg types from a file-scope fcn defn. */ | |
2381 | if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0 | |
2382 | && DECL_INITIAL (oldglobal) | |
2383 | && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0) | |
2384 | TREE_TYPE (x) = TREE_TYPE (oldglobal); | |
2385 | } | |
51e29401 RS |
2386 | } |
2387 | ||
6645c3fa KH |
2388 | #if 0 |
2389 | /* This case is probably sometimes the right thing to do. */ | |
51e29401 RS |
2390 | /* If we have a local external declaration, |
2391 | then any file-scope declaration should not | |
2392 | have been static. */ | |
2393 | if (oldlocal == 0 && oldglobal != 0 | |
2394 | && !TREE_PUBLIC (oldglobal) | |
1394aabd | 2395 | && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) |
51e29401 RS |
2396 | warning ("`%s' locally external but globally static", |
2397 | IDENTIFIER_POINTER (name)); | |
2398 | #endif | |
2399 | ||
2400 | /* If we have a local external declaration, | |
2401 | and no file-scope declaration has yet been seen, | |
2402 | then if we later have a file-scope decl it must not be static. */ | |
2403 | if (oldlocal == 0 | |
1394aabd | 2404 | && DECL_EXTERNAL (x) |
51e29401 RS |
2405 | && TREE_PUBLIC (x)) |
2406 | { | |
bf44f7de | 2407 | if (oldglobal == 0) |
6645c3fa | 2408 | TREE_PUBLIC (name) = 1; |
fd0b8fce JW |
2409 | |
2410 | /* Save this decl, so that we can do type checking against | |
2411 | other decls after it falls out of scope. | |
2412 | ||
2413 | Only save it once. This prevents temporary decls created in | |
2414 | expand_inline_function from being used here, since this | |
2415 | will have been set when the inline function was parsed. | |
2416 | It also helps give slightly better warnings. */ | |
2417 | if (IDENTIFIER_LIMBO_VALUE (name) == 0) | |
2418 | IDENTIFIER_LIMBO_VALUE (name) = x; | |
51e29401 RS |
2419 | } |
2420 | ||
2421 | /* Warn if shadowing an argument at the top level of the body. */ | |
1394aabd | 2422 | if (oldlocal != 0 && !DECL_EXTERNAL (x) |
51e29401 RS |
2423 | /* This warning doesn't apply to the parms of a nested fcn. */ |
2424 | && ! current_binding_level->parm_flag | |
2425 | /* Check that this is one level down from the parms. */ | |
2426 | && current_binding_level->level_chain->parm_flag | |
2427 | /* Check that the decl being shadowed | |
2428 | comes from the parm level, one level up. */ | |
2429 | && chain_member (oldlocal, current_binding_level->level_chain->names)) | |
2430 | { | |
2431 | if (TREE_CODE (oldlocal) == PARM_DECL) | |
2432 | pedwarn ("declaration of `%s' shadows a parameter", | |
2433 | IDENTIFIER_POINTER (name)); | |
2434 | else | |
2435 | pedwarn ("declaration of `%s' shadows a symbol from the parameter list", | |
2436 | IDENTIFIER_POINTER (name)); | |
2437 | } | |
2438 | ||
2439 | /* Maybe warn if shadowing something else. */ | |
1394aabd | 2440 | else if (warn_shadow && !DECL_EXTERNAL (x) |
2bae939e | 2441 | /* No shadow warnings for internally generated vars. */ |
7a0347ff | 2442 | && DECL_SOURCE_LINE (x) != 0 |
51e29401 | 2443 | /* No shadow warnings for vars made for inlining. */ |
b032c74c | 2444 | && ! DECL_FROM_INLINE (x)) |
51e29401 | 2445 | { |
63ad61ed | 2446 | const char *id = IDENTIFIER_POINTER (name); |
51e29401 RS |
2447 | |
2448 | if (TREE_CODE (x) == PARM_DECL | |
89d7540d RS |
2449 | && current_binding_level->level_chain->parm_flag) |
2450 | /* Don't warn about the parm names in function declarator | |
2451 | within a function declarator. | |
2452 | It would be nice to avoid warning in any function | |
2453 | declarator in a declaration, as opposed to a definition, | |
2454 | but there is no way to tell it's not a definition. */ | |
51e29401 RS |
2455 | ; |
2456 | else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL) | |
ab87f8c8 | 2457 | warning ("declaration of `%s' shadows a parameter", id); |
51e29401 | 2458 | else if (oldlocal != 0) |
ab87f8c8 | 2459 | warning ("declaration of `%s' shadows previous local", id); |
51e29401 RS |
2460 | else if (IDENTIFIER_GLOBAL_VALUE (name) != 0 |
2461 | && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node) | |
ab87f8c8 | 2462 | warning ("declaration of `%s' shadows global declaration", id); |
51e29401 RS |
2463 | } |
2464 | ||
2465 | /* If storing a local value, there may already be one (inherited). | |
2466 | If so, record it for restoration when this binding level ends. */ | |
2467 | if (oldlocal != 0) | |
2468 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
2469 | } | |
2470 | ||
5667abce ZW |
2471 | /* Keep count of variables in this level with incomplete type. |
2472 | If the input is erroneous, we can have error_mark in the type | |
2473 | slot (e.g. "f(void a, ...)") - that doesn't count as an | |
2474 | incomplete type. */ | |
2475 | if (TREE_TYPE (x) != error_mark_node | |
2476 | && !COMPLETE_TYPE_P (TREE_TYPE (x))) | |
51e29401 RS |
2477 | ++b->n_incomplete; |
2478 | } | |
2479 | ||
2480 | /* Put decls on list in reverse order. | |
2481 | We will reverse them later if necessary. */ | |
2482 | TREE_CHAIN (x) = b->names; | |
2483 | b->names = x; | |
2484 | ||
2485 | return x; | |
2486 | } | |
2487 | ||
2488 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ | |
2489 | ||
2490 | tree | |
2491 | pushdecl_top_level (x) | |
2492 | tree x; | |
2493 | { | |
2494 | register tree t; | |
2495 | register struct binding_level *b = current_binding_level; | |
2496 | ||
2497 | current_binding_level = global_binding_level; | |
2498 | t = pushdecl (x); | |
2499 | current_binding_level = b; | |
2500 | return t; | |
2501 | } | |
2502 | \f | |
2503 | /* Generate an implicit declaration for identifier FUNCTIONID | |
2504 | as a function of type int (). Print a warning if appropriate. */ | |
2505 | ||
2506 | tree | |
2507 | implicitly_declare (functionid) | |
2508 | tree functionid; | |
2509 | { | |
2510 | register tree decl; | |
2511 | int traditional_warning = 0; | |
2512 | /* Only one "implicit declaration" warning per identifier. */ | |
2513 | int implicit_warning; | |
2514 | ||
51e29401 RS |
2515 | /* We used to reuse an old implicit decl here, |
2516 | but this loses with inline functions because it can clobber | |
2517 | the saved decl chains. */ | |
6645c3fa KH |
2518 | #if 0 |
2519 | if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0) | |
51e29401 | 2520 | decl = IDENTIFIER_IMPLICIT_DECL (functionid); |
6645c3fa KH |
2521 | else |
2522 | #endif | |
51e29401 RS |
2523 | decl = build_decl (FUNCTION_DECL, functionid, default_function_type); |
2524 | ||
2525 | /* Warn of implicit decl following explicit local extern decl. | |
2526 | This is probably a program designed for traditional C. */ | |
2527 | if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0) | |
2528 | traditional_warning = 1; | |
2529 | ||
2530 | /* Warn once of an implicit declaration. */ | |
2531 | implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0); | |
2532 | ||
1394aabd | 2533 | DECL_EXTERNAL (decl) = 1; |
51e29401 RS |
2534 | TREE_PUBLIC (decl) = 1; |
2535 | ||
2536 | /* Record that we have an implicit decl and this is it. */ | |
2537 | IDENTIFIER_IMPLICIT_DECL (functionid) = decl; | |
2538 | ||
2539 | /* ANSI standard says implicit declarations are in the innermost block. | |
2540 | So we record the decl in the standard fashion. | |
2541 | If flag_traditional is set, pushdecl does it top-level. */ | |
2542 | pushdecl (decl); | |
2543 | ||
2544 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
2545 | maybe_objc_check_decl (decl); | |
2546 | ||
8d9bfdc5 | 2547 | rest_of_decl_compilation (decl, NULL_PTR, 0, 0); |
51e29401 | 2548 | |
111458f1 ZW |
2549 | if (implicit_warning) |
2550 | implicit_decl_warning (functionid); | |
51e29401 RS |
2551 | else if (warn_traditional && traditional_warning) |
2552 | warning ("function `%s' was previously declared within a block", | |
2553 | IDENTIFIER_POINTER (functionid)); | |
2554 | ||
2555 | /* Write a record describing this implicit function declaration to the | |
2556 | prototypes file (if requested). */ | |
2557 | ||
2558 | gen_aux_info_record (decl, 0, 1, 0); | |
2559 | ||
51e29401 RS |
2560 | return decl; |
2561 | } | |
2562 | ||
111458f1 ZW |
2563 | void |
2564 | implicit_decl_warning (id) | |
2565 | tree id; | |
2566 | { | |
63ad61ed | 2567 | const char *name = IDENTIFIER_POINTER (id); |
111458f1 ZW |
2568 | if (mesg_implicit_function_declaration == 2) |
2569 | error ("implicit declaration of function `%s'", name); | |
2570 | else if (mesg_implicit_function_declaration == 1) | |
2571 | warning ("implicit declaration of function `%s'", name); | |
2572 | } | |
2573 | ||
51e29401 RS |
2574 | /* Return zero if the declaration NEWDECL is valid |
2575 | when the declaration OLDDECL (assumed to be for the same name) | |
2576 | has already been seen. | |
ab87f8c8 JL |
2577 | Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration, |
2578 | and 3 if it is a conflicting declaration. */ | |
51e29401 | 2579 | |
ab87f8c8 | 2580 | static int |
51e29401 RS |
2581 | redeclaration_error_message (newdecl, olddecl) |
2582 | tree newdecl, olddecl; | |
2583 | { | |
2584 | if (TREE_CODE (newdecl) == TYPE_DECL) | |
2585 | { | |
2586 | if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl)) | |
2587 | return 0; | |
692ce0fd RK |
2588 | /* pushdecl creates distinct types for TYPE_DECLs by calling |
2589 | build_type_copy, so the above comparison generally fails. We do | |
2590 | another test against the TYPE_MAIN_VARIANT of the olddecl, which | |
2591 | is equivalent to what this code used to do before the build_type_copy | |
2592 | call. The variant type distinction should not matter for traditional | |
2593 | code, because it doesn't have type qualifiers. */ | |
6645c3fa | 2594 | if (flag_traditional |
692ce0fd RK |
2595 | && TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)) == TREE_TYPE (newdecl)) |
2596 | return 0; | |
4b4e3407 RK |
2597 | if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl)) |
2598 | return 0; | |
ab87f8c8 | 2599 | return 1; |
51e29401 RS |
2600 | } |
2601 | else if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2602 | { | |
2603 | /* Declarations of functions can insist on internal linkage | |
2604 | but they can't be inconsistent with internal linkage, | |
2605 | so there can be no error on that account. | |
2606 | However defining the same name twice is no good. */ | |
2607 | if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0 | |
2608 | /* However, defining once as extern inline and a second | |
2609 | time in another way is ok. */ | |
17aec3eb RK |
2610 | && ! (DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl) |
2611 | && ! (DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl)))) | |
ab87f8c8 | 2612 | return 1; |
51e29401 RS |
2613 | return 0; |
2614 | } | |
8f17b5c5 | 2615 | else if (DECL_CONTEXT (newdecl) == NULL_TREE) |
51e29401 RS |
2616 | { |
2617 | /* Objects declared at top level: */ | |
2618 | /* If at least one is a reference, it's ok. */ | |
1394aabd | 2619 | if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) |
51e29401 RS |
2620 | return 0; |
2621 | /* Reject two definitions. */ | |
2622 | if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0) | |
ab87f8c8 | 2623 | return 1; |
51e29401 RS |
2624 | /* Now we have two tentative defs, or one tentative and one real def. */ |
2625 | /* Insist that the linkage match. */ | |
2626 | if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl)) | |
ab87f8c8 | 2627 | return 3; |
51e29401 RS |
2628 | return 0; |
2629 | } | |
2630 | else if (current_binding_level->parm_flag | |
2631 | && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) | |
2632 | return 0; | |
2633 | else | |
2634 | { | |
7dcf01c2 JW |
2635 | /* Newdecl has block scope. If olddecl has block scope also, then |
2636 | reject two definitions, and reject a definition together with an | |
2637 | external reference. Otherwise, it is OK, because newdecl must | |
2638 | be an extern reference to olddecl. */ | |
2639 | if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)) | |
cd681d1f | 2640 | && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)) |
ab87f8c8 | 2641 | return 2; |
51e29401 RS |
2642 | return 0; |
2643 | } | |
2644 | } | |
2645 | \f | |
2646 | /* Get the LABEL_DECL corresponding to identifier ID as a label. | |
2647 | Create one if none exists so far for the current function. | |
2648 | This function is called for both label definitions and label references. */ | |
2649 | ||
2650 | tree | |
2651 | lookup_label (id) | |
2652 | tree id; | |
2653 | { | |
2654 | register tree decl = IDENTIFIER_LABEL_VALUE (id); | |
2655 | ||
7d9795e5 RS |
2656 | if (current_function_decl == 0) |
2657 | { | |
2658 | error ("label %s referenced outside of any function", | |
2659 | IDENTIFIER_POINTER (id)); | |
2660 | return 0; | |
2661 | } | |
2662 | ||
51e29401 RS |
2663 | /* Use a label already defined or ref'd with this name. */ |
2664 | if (decl != 0) | |
2665 | { | |
2666 | /* But not if it is inherited and wasn't declared to be inheritable. */ | |
2667 | if (DECL_CONTEXT (decl) != current_function_decl | |
2668 | && ! C_DECLARED_LABEL_FLAG (decl)) | |
2669 | return shadow_label (id); | |
2670 | return decl; | |
2671 | } | |
2672 | ||
2673 | decl = build_decl (LABEL_DECL, id, void_type_node); | |
2674 | ||
2675 | /* A label not explicitly declared must be local to where it's ref'd. */ | |
2676 | DECL_CONTEXT (decl) = current_function_decl; | |
2677 | ||
2678 | DECL_MODE (decl) = VOIDmode; | |
2679 | ||
2680 | /* Say where one reference is to the label, | |
2681 | for the sake of the error if it is not defined. */ | |
2682 | DECL_SOURCE_LINE (decl) = lineno; | |
2683 | DECL_SOURCE_FILE (decl) = input_filename; | |
2684 | ||
2685 | IDENTIFIER_LABEL_VALUE (id) = decl; | |
2686 | ||
2687 | named_labels = tree_cons (NULL_TREE, decl, named_labels); | |
2688 | ||
2689 | return decl; | |
2690 | } | |
2691 | ||
2692 | /* Make a label named NAME in the current function, | |
2693 | shadowing silently any that may be inherited from containing functions | |
2694 | or containing scopes. | |
2695 | ||
2696 | Note that valid use, if the label being shadowed | |
2697 | comes from another scope in the same function, | |
2698 | requires calling declare_nonlocal_label right away. */ | |
2699 | ||
2700 | tree | |
2701 | shadow_label (name) | |
2702 | tree name; | |
2703 | { | |
2704 | register tree decl = IDENTIFIER_LABEL_VALUE (name); | |
2705 | ||
2706 | if (decl != 0) | |
2707 | { | |
a784882b RE |
2708 | register tree dup; |
2709 | ||
2710 | /* Check to make sure that the label hasn't already been declared | |
2711 | at this label scope */ | |
2712 | for (dup = named_labels; dup; dup = TREE_CHAIN (dup)) | |
2713 | if (TREE_VALUE (dup) == decl) | |
2714 | { | |
6645c3fa | 2715 | error ("duplicate label declaration `%s'", |
a784882b RE |
2716 | IDENTIFIER_POINTER (name)); |
2717 | error_with_decl (TREE_VALUE (dup), | |
2718 | "this is a previous declaration"); | |
2719 | /* Just use the previous declaration. */ | |
2720 | return lookup_label (name); | |
2721 | } | |
2722 | ||
51e29401 RS |
2723 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); |
2724 | IDENTIFIER_LABEL_VALUE (name) = decl = 0; | |
2725 | } | |
2726 | ||
2727 | return lookup_label (name); | |
2728 | } | |
2729 | ||
2730 | /* Define a label, specifying the location in the source file. | |
2731 | Return the LABEL_DECL node for the label, if the definition is valid. | |
2732 | Otherwise return 0. */ | |
2733 | ||
2734 | tree | |
2735 | define_label (filename, line, name) | |
3b304f5b | 2736 | const char *filename; |
51e29401 RS |
2737 | int line; |
2738 | tree name; | |
2739 | { | |
2740 | tree decl = lookup_label (name); | |
2741 | ||
2742 | /* If label with this name is known from an outer context, shadow it. */ | |
2743 | if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl) | |
2744 | { | |
2745 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
2746 | IDENTIFIER_LABEL_VALUE (name) = 0; | |
2747 | decl = lookup_label (name); | |
2748 | } | |
2749 | ||
cde6e684 | 2750 | if (warn_traditional && !in_system_header && lookup_name (name)) |
6ad79f1b KG |
2751 | warning_with_file_and_line (filename, line, |
2752 | "traditional C lacks a separate namespace for labels, identifier `%s' conflicts", | |
2753 | IDENTIFIER_POINTER (name)); | |
6645c3fa | 2754 | |
51e29401 RS |
2755 | if (DECL_INITIAL (decl) != 0) |
2756 | { | |
6ad79f1b KG |
2757 | error_with_file_and_line (filename, line, "duplicate label `%s'", |
2758 | IDENTIFIER_POINTER (name)); | |
51e29401 RS |
2759 | return 0; |
2760 | } | |
2761 | else | |
2762 | { | |
2763 | /* Mark label as having been defined. */ | |
2764 | DECL_INITIAL (decl) = error_mark_node; | |
2765 | /* Say where in the source. */ | |
2766 | DECL_SOURCE_FILE (decl) = filename; | |
2767 | DECL_SOURCE_LINE (decl) = line; | |
2768 | return decl; | |
2769 | } | |
2770 | } | |
2771 | \f | |
2772 | /* Return the list of declarations of the current level. | |
2773 | Note that this list is in reverse order unless/until | |
2774 | you nreverse it; and when you do nreverse it, you must | |
2775 | store the result back using `storedecls' or you will lose. */ | |
2776 | ||
2777 | tree | |
2778 | getdecls () | |
2779 | { | |
2780 | return current_binding_level->names; | |
2781 | } | |
2782 | ||
2783 | /* Return the list of type-tags (for structs, etc) of the current level. */ | |
2784 | ||
2785 | tree | |
2786 | gettags () | |
2787 | { | |
2788 | return current_binding_level->tags; | |
2789 | } | |
2790 | ||
2791 | /* Store the list of declarations of the current level. | |
2792 | This is done for the parameter declarations of a function being defined, | |
2793 | after they are modified in the light of any missing parameters. */ | |
2794 | ||
2795 | static void | |
2796 | storedecls (decls) | |
2797 | tree decls; | |
2798 | { | |
2799 | current_binding_level->names = decls; | |
2800 | } | |
2801 | ||
2802 | /* Similarly, store the list of tags of the current level. */ | |
2803 | ||
2804 | static void | |
2805 | storetags (tags) | |
2806 | tree tags; | |
2807 | { | |
2808 | current_binding_level->tags = tags; | |
2809 | } | |
2810 | \f | |
2811 | /* Given NAME, an IDENTIFIER_NODE, | |
2812 | return the structure (or union or enum) definition for that name. | |
2813 | Searches binding levels from BINDING_LEVEL up to the global level. | |
2814 | If THISLEVEL_ONLY is nonzero, searches only the specified context | |
2815 | (but skips any tag-transparent contexts to find one that is | |
2816 | meaningful for tags). | |
2817 | CODE says which kind of type the caller wants; | |
2818 | it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | |
2819 | If the wrong kind of type is found, an error is reported. */ | |
2820 | ||
2821 | static tree | |
2822 | lookup_tag (code, name, binding_level, thislevel_only) | |
2823 | enum tree_code code; | |
2824 | struct binding_level *binding_level; | |
2825 | tree name; | |
2826 | int thislevel_only; | |
2827 | { | |
2828 | register struct binding_level *level; | |
2829 | ||
2830 | for (level = binding_level; level; level = level->level_chain) | |
2831 | { | |
2832 | register tree tail; | |
2833 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
2834 | { | |
2835 | if (TREE_PURPOSE (tail) == name) | |
2836 | { | |
2837 | if (TREE_CODE (TREE_VALUE (tail)) != code) | |
2838 | { | |
2839 | /* Definition isn't the kind we were looking for. */ | |
2840 | pending_invalid_xref = name; | |
2841 | pending_invalid_xref_file = input_filename; | |
2842 | pending_invalid_xref_line = lineno; | |
2843 | } | |
2844 | return TREE_VALUE (tail); | |
2845 | } | |
2846 | } | |
2847 | if (thislevel_only && ! level->tag_transparent) | |
2848 | return NULL_TREE; | |
2849 | } | |
2850 | return NULL_TREE; | |
2851 | } | |
2852 | ||
2853 | /* Print an error message now | |
2854 | for a recent invalid struct, union or enum cross reference. | |
2855 | We don't print them immediately because they are not invalid | |
2856 | when used in the `struct foo;' construct for shadowing. */ | |
2857 | ||
2858 | void | |
2859 | pending_xref_error () | |
2860 | { | |
2861 | if (pending_invalid_xref != 0) | |
2862 | error_with_file_and_line (pending_invalid_xref_file, | |
2863 | pending_invalid_xref_line, | |
2864 | "`%s' defined as wrong kind of tag", | |
2865 | IDENTIFIER_POINTER (pending_invalid_xref)); | |
2866 | pending_invalid_xref = 0; | |
2867 | } | |
2868 | ||
2869 | /* Given a type, find the tag that was defined for it and return the tag name. | |
2870 | Otherwise return 0. */ | |
2871 | ||
2872 | static tree | |
2873 | lookup_tag_reverse (type) | |
2874 | tree type; | |
2875 | { | |
2876 | register struct binding_level *level; | |
2877 | ||
2878 | for (level = current_binding_level; level; level = level->level_chain) | |
2879 | { | |
2880 | register tree tail; | |
2881 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
2882 | { | |
2883 | if (TREE_VALUE (tail) == type) | |
2884 | return TREE_PURPOSE (tail); | |
2885 | } | |
2886 | } | |
2887 | return NULL_TREE; | |
2888 | } | |
2889 | \f | |
2890 | /* Look up NAME in the current binding level and its superiors | |
2891 | in the namespace of variables, functions and typedefs. | |
2892 | Return a ..._DECL node of some kind representing its definition, | |
2893 | or return 0 if it is undefined. */ | |
2894 | ||
2895 | tree | |
2896 | lookup_name (name) | |
2897 | tree name; | |
2898 | { | |
2899 | register tree val; | |
0e5921e8 | 2900 | |
51e29401 RS |
2901 | if (current_binding_level != global_binding_level |
2902 | && IDENTIFIER_LOCAL_VALUE (name)) | |
2903 | val = IDENTIFIER_LOCAL_VALUE (name); | |
2904 | else | |
2905 | val = IDENTIFIER_GLOBAL_VALUE (name); | |
2906 | return val; | |
2907 | } | |
2908 | ||
2909 | /* Similar to `lookup_name' but look only at current binding level. */ | |
2910 | ||
f062da04 | 2911 | tree |
51e29401 RS |
2912 | lookup_name_current_level (name) |
2913 | tree name; | |
2914 | { | |
2915 | register tree t; | |
2916 | ||
2917 | if (current_binding_level == global_binding_level) | |
2918 | return IDENTIFIER_GLOBAL_VALUE (name); | |
2919 | ||
2920 | if (IDENTIFIER_LOCAL_VALUE (name) == 0) | |
2921 | return 0; | |
2922 | ||
2923 | for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) | |
2924 | if (DECL_NAME (t) == name) | |
2925 | break; | |
2926 | ||
2927 | return t; | |
2928 | } | |
2929 | \f | |
1526a060 | 2930 | /* Mark ARG for GC. */ |
749a2da1 | 2931 | |
6645c3fa | 2932 | static void |
1526a060 BS |
2933 | mark_binding_level (arg) |
2934 | void *arg; | |
2935 | { | |
2936 | struct binding_level *level = *(struct binding_level **) arg; | |
2937 | ||
749a2da1 | 2938 | for (; level != 0; level = level->level_chain) |
1526a060 BS |
2939 | { |
2940 | ggc_mark_tree (level->names); | |
2941 | ggc_mark_tree (level->tags); | |
2942 | ggc_mark_tree (level->shadowed); | |
2943 | ggc_mark_tree (level->blocks); | |
2944 | ggc_mark_tree (level->this_block); | |
2945 | ggc_mark_tree (level->parm_order); | |
1526a060 BS |
2946 | } |
2947 | } | |
2948 | ||
51e29401 | 2949 | /* Create the predefined scalar types of C, |
0f41302f | 2950 | and some nodes representing standard constants (0, 1, (void *) 0). |
51e29401 RS |
2951 | Initialize the global binding level. |
2952 | Make definitions for built-in primitive functions. */ | |
2953 | ||
2954 | void | |
2955 | init_decl_processing () | |
2956 | { | |
2957 | register tree endlink; | |
7f4edbcb | 2958 | tree ptr_ftype_void, ptr_ftype_ptr; |
51e29401 | 2959 | int wchar_type_size; |
fba9adc6 | 2960 | tree array_domain_type; |
fed3cef0 | 2961 | tree t; |
51e29401 RS |
2962 | |
2963 | current_function_decl = NULL; | |
2964 | named_labels = NULL; | |
2965 | current_binding_level = NULL_BINDING_LEVEL; | |
2966 | free_binding_level = NULL_BINDING_LEVEL; | |
6645c3fa KH |
2967 | |
2968 | /* Make the binding_level structure for global names. */ | |
2969 | pushlevel (0); | |
51e29401 RS |
2970 | global_binding_level = current_binding_level; |
2971 | ||
81b3411c | 2972 | build_common_tree_nodes (flag_signed_char); |
51e29401 | 2973 | |
81b3411c | 2974 | /* Define `int' and `char' first so that dbx will output them first. */ |
51e29401 RS |
2975 | pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT], |
2976 | integer_type_node)); | |
51e29401 RS |
2977 | pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), |
2978 | char_type_node)); | |
51e29401 RS |
2979 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"), |
2980 | long_integer_type_node)); | |
51e29401 RS |
2981 | pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"), |
2982 | unsigned_type_node)); | |
51e29401 RS |
2983 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"), |
2984 | long_unsigned_type_node)); | |
6706083e DE |
2985 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"), |
2986 | long_long_integer_type_node)); | |
6706083e DE |
2987 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"), |
2988 | long_long_unsigned_type_node)); | |
9787ad71 MM |
2989 | pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"), |
2990 | short_integer_type_node)); | |
9787ad71 MM |
2991 | pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"), |
2992 | short_unsigned_type_node)); | |
51e29401 RS |
2993 | pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"), |
2994 | signed_char_type_node)); | |
51e29401 RS |
2995 | pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"), |
2996 | unsigned_char_type_node)); | |
ac4f24e7 | 2997 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); |
ac4f24e7 | 2998 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); |
ac4f24e7 | 2999 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); |
ac4f24e7 | 3000 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); |
21a9616b | 3001 | #if HOST_BITS_PER_WIDE_INT >= 64 |
07fb7f79 | 3002 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intTI_type_node)); |
21a9616b | 3003 | #endif |
ac4f24e7 | 3004 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); |
ac4f24e7 | 3005 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); |
ac4f24e7 | 3006 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); |
ac4f24e7 | 3007 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); |
21a9616b | 3008 | #if HOST_BITS_PER_WIDE_INT >= 64 |
a6d7e156 | 3009 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intTI_type_node)); |
21a9616b | 3010 | #endif |
a6d7e156 | 3011 | |
81b3411c BS |
3012 | /* `unsigned long' is the standard type for sizeof. |
3013 | Traditionally, use a signed type. | |
3014 | Note that stddef.h uses `unsigned long', | |
3015 | and this must agree, even if long and int are the same size. */ | |
fed3cef0 | 3016 | t = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); |
cd732418 | 3017 | signed_size_type_node = signed_type (t); |
fed3cef0 RK |
3018 | if (flag_traditional && TREE_UNSIGNED (t)) |
3019 | t = signed_type (t); | |
6645c3fa | 3020 | |
3c786c69 | 3021 | c_size_type_node = t; |
fed3cef0 | 3022 | set_sizetype (t); |
81b3411c | 3023 | |
6645c3fa | 3024 | /* Create the widest literal types. */ |
fed3cef0 RK |
3025 | widest_integer_literal_type_node |
3026 | = make_signed_type (HOST_BITS_PER_WIDE_INT * 2); | |
3027 | widest_unsigned_literal_type_node | |
3028 | = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2); | |
6645c3fa | 3029 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, |
81b3411c | 3030 | widest_integer_literal_type_node)); |
6645c3fa | 3031 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, |
81b3411c BS |
3032 | widest_unsigned_literal_type_node)); |
3033 | ||
3034 | build_common_tree_nodes_2 (flag_short_double); | |
3035 | ||
51e29401 RS |
3036 | pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT], |
3037 | float_type_node)); | |
51e29401 RS |
3038 | pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE], |
3039 | double_type_node)); | |
51e29401 RS |
3040 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"), |
3041 | long_double_type_node)); | |
5ab10c42 RS |
3042 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), |
3043 | complex_integer_type_node)); | |
5ab10c42 RS |
3044 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), |
3045 | complex_float_type_node)); | |
5ab10c42 RS |
3046 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), |
3047 | complex_double_type_node)); | |
5ab10c42 RS |
3048 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), |
3049 | complex_long_double_type_node)); | |
81b3411c BS |
3050 | pushdecl (build_decl (TYPE_DECL, |
3051 | ridpointers[(int) RID_VOID], void_type_node)); | |
5ab10c42 | 3052 | |
d25cf633 BS |
3053 | #ifdef MD_INIT_BUILTINS |
3054 | MD_INIT_BUILTINS; | |
3055 | #endif | |
3056 | ||
12a39b12 JM |
3057 | wchar_type_node = get_identifier (flag_short_wchar |
3058 | ? "short unsigned int" | |
3059 | : WCHAR_TYPE); | |
3060 | wchar_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (wchar_type_node)); | |
51e29401 | 3061 | wchar_type_size = TYPE_PRECISION (wchar_type_node); |
7e4849da RS |
3062 | signed_wchar_type_node = signed_type (wchar_type_node); |
3063 | unsigned_wchar_type_node = unsigned_type (wchar_type_node); | |
51e29401 | 3064 | |
f444e553 JM |
3065 | boolean_type_node = integer_type_node; |
3066 | boolean_true_node = integer_one_node; | |
3067 | boolean_false_node = integer_zero_node; | |
3068 | ||
19552aa5 JM |
3069 | /* With GCC, C99's _Bool is always of size 1. */ |
3070 | c_bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
3071 | TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE); | |
3072 | TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0); | |
3073 | TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node; | |
3074 | TYPE_PRECISION (c_bool_type_node) = 1; | |
3075 | pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"), | |
3076 | c_bool_type_node)); | |
3077 | c_bool_false_node = build_int_2 (0, 0); | |
3078 | TREE_TYPE (c_bool_false_node) = c_bool_type_node; | |
3079 | c_bool_true_node = build_int_2 (1, 0); | |
3080 | TREE_TYPE (c_bool_true_node) = c_bool_type_node; | |
3081 | ||
fba9adc6 | 3082 | /* Make a type to be the domain of a few array types |
c81fe25d RK |
3083 | whose domains don't really matter. |
3084 | 200 is small enough that it always fits in size_t | |
3085 | and large enough that it can hold most function names for the | |
3086 | initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
3087 | array_domain_type = build_index_type (build_int_2 (200, 0)); | |
fba9adc6 RS |
3088 | |
3089 | /* make a type for arrays of characters. | |
51e29401 RS |
3090 | With luck nothing will ever really depend on the length of this |
3091 | array type. */ | |
6645c3fa | 3092 | char_array_type_node = build_array_type (char_type_node, array_domain_type); |
051c57da | 3093 | |
51e29401 RS |
3094 | /* Likewise for arrays of ints. */ |
3095 | int_array_type_node | |
fba9adc6 | 3096 | = build_array_type (integer_type_node, array_domain_type); |
051c57da | 3097 | |
51e29401 RS |
3098 | /* This is for wide string constants. */ |
3099 | wchar_array_type_node | |
fba9adc6 | 3100 | = build_array_type (wchar_type_node, array_domain_type); |
51e29401 | 3101 | |
7f4edbcb BS |
3102 | void_list_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE); |
3103 | ||
6bcedb4e | 3104 | c_common_nodes_and_builtins (); |
b71e9de0 | 3105 | |
7f4edbcb | 3106 | endlink = void_list_node; |
0021b564 JM |
3107 | ptr_ftype_void = build_function_type (ptr_type_node, endlink); |
3108 | ptr_ftype_ptr | |
3109 | = build_function_type (ptr_type_node, | |
3110 | tree_cons (NULL_TREE, ptr_type_node, endlink)); | |
3111 | ||
7aba5a5f | 3112 | /* Types which are common to the fortran compiler and libf2c. When |
6645c3fa | 3113 | changing these, you also need to be concerned with f/com.h. */ |
7aba5a5f CD |
3114 | |
3115 | if (TYPE_PRECISION (float_type_node) | |
3116 | == TYPE_PRECISION (long_integer_type_node)) | |
3117 | { | |
3118 | g77_integer_type_node = long_integer_type_node; | |
3119 | g77_uinteger_type_node = long_unsigned_type_node; | |
3120 | } | |
3121 | else if (TYPE_PRECISION (float_type_node) | |
3122 | == TYPE_PRECISION (integer_type_node)) | |
3123 | { | |
3124 | g77_integer_type_node = integer_type_node; | |
3125 | g77_uinteger_type_node = unsigned_type_node; | |
3126 | } | |
3127 | else | |
3128 | g77_integer_type_node = g77_uinteger_type_node = NULL_TREE; | |
3129 | ||
3130 | if (g77_integer_type_node != NULL_TREE) | |
3131 | { | |
3132 | pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_integer"), | |
3133 | g77_integer_type_node)); | |
3134 | pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_uinteger"), | |
3135 | g77_uinteger_type_node)); | |
3136 | } | |
3137 | ||
3138 | if (TYPE_PRECISION (float_type_node) * 2 | |
3139 | == TYPE_PRECISION (long_integer_type_node)) | |
3140 | { | |
3141 | g77_longint_type_node = long_integer_type_node; | |
3142 | g77_ulongint_type_node = long_unsigned_type_node; | |
3143 | } | |
3144 | else if (TYPE_PRECISION (float_type_node) * 2 | |
3145 | == TYPE_PRECISION (long_long_integer_type_node)) | |
3146 | { | |
3147 | g77_longint_type_node = long_long_integer_type_node; | |
3148 | g77_ulongint_type_node = long_long_unsigned_type_node; | |
3149 | } | |
3150 | else | |
3151 | g77_longint_type_node = g77_ulongint_type_node = NULL_TREE; | |
3152 | ||
3153 | if (g77_longint_type_node != NULL_TREE) | |
3154 | { | |
3155 | pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_longint"), | |
3156 | g77_longint_type_node)); | |
3157 | pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_ulongint"), | |
3158 | g77_ulongint_type_node)); | |
3159 | } | |
3160 | ||
18989c57 RK |
3161 | builtin_function ("__builtin_aggregate_incoming_address", |
3162 | build_function_type (ptr_type_node, NULL_TREE), | |
26db82d8 BS |
3163 | BUILT_IN_AGGREGATE_INCOMING_ADDRESS, |
3164 | BUILT_IN_NORMAL, NULL_PTR); | |
18989c57 | 3165 | |
0021b564 JM |
3166 | /* Hooks for the DWARF 2 __throw routine. */ |
3167 | builtin_function ("__builtin_unwind_init", | |
3168 | build_function_type (void_type_node, endlink), | |
26db82d8 | 3169 | BUILT_IN_UNWIND_INIT, BUILT_IN_NORMAL, NULL_PTR); |
71038426 | 3170 | builtin_function ("__builtin_dwarf_cfa", ptr_ftype_void, |
26db82d8 | 3171 | BUILT_IN_DWARF_CFA, BUILT_IN_NORMAL, NULL_PTR); |
0021b564 JM |
3172 | builtin_function ("__builtin_dwarf_fp_regnum", |
3173 | build_function_type (unsigned_type_node, endlink), | |
26db82d8 | 3174 | BUILT_IN_DWARF_FP_REGNUM, BUILT_IN_NORMAL, NULL_PTR); |
d9d5c9de BS |
3175 | builtin_function ("__builtin_init_dwarf_reg_size_table", void_ftype_ptr, |
3176 | BUILT_IN_INIT_DWARF_REG_SIZES, BUILT_IN_NORMAL, NULL_PTR); | |
0021b564 | 3177 | builtin_function ("__builtin_frob_return_addr", ptr_ftype_ptr, |
26db82d8 | 3178 | BUILT_IN_FROB_RETURN_ADDR, BUILT_IN_NORMAL, NULL_PTR); |
0021b564 | 3179 | builtin_function ("__builtin_extract_return_addr", ptr_ftype_ptr, |
26db82d8 | 3180 | BUILT_IN_EXTRACT_RETURN_ADDR, BUILT_IN_NORMAL, NULL_PTR); |
0021b564 | 3181 | builtin_function |
71038426 | 3182 | ("__builtin_eh_return", |
0021b564 JM |
3183 | build_function_type (void_type_node, |
3184 | tree_cons (NULL_TREE, ptr_type_node, | |
3185 | tree_cons (NULL_TREE, | |
3186 | type_for_mode (ptr_mode, 0), | |
6645c3fa | 3187 | tree_cons (NULL_TREE, |
71038426 RH |
3188 | ptr_type_node, |
3189 | endlink)))), | |
26db82d8 | 3190 | BUILT_IN_EH_RETURN, BUILT_IN_NORMAL, NULL_PTR); |
0021b564 | 3191 | |
f444e553 JM |
3192 | pedantic_lvalues = pedantic; |
3193 | ||
63ad61ed ZW |
3194 | /* Create the global bindings for __FUNCTION__, __PRETTY_FUNCTION__, |
3195 | and __func__. */ | |
3196 | function_id_node = get_identifier ("__FUNCTION__"); | |
3197 | pretty_function_id_node = get_identifier ("__PRETTY_FUNCTION__"); | |
3198 | func_id_node = get_identifier ("__func__"); | |
2ce07e2d | 3199 | make_fname_decl = c_make_fname_decl; |
7da551a2 | 3200 | declare_function_name (); |
64309441 | 3201 | |
51e29401 RS |
3202 | start_identifier_warnings (); |
3203 | ||
561d994f RK |
3204 | /* Prepare to check format strings against argument lists. */ |
3205 | init_function_format_info (); | |
75621238 | 3206 | |
b4892310 | 3207 | incomplete_decl_finalize_hook = finish_incomplete_decl; |
41472af8 | 3208 | |
1526a060 BS |
3209 | /* Record our roots. */ |
3210 | ||
3211 | ggc_add_tree_root (c_global_trees, CTI_MAX); | |
8f17b5c5 MM |
3212 | ggc_add_root (&c_stmt_tree, 1, sizeof c_stmt_tree, mark_stmt_tree); |
3213 | ggc_add_tree_root (&c_scope_stmt_stack, 1); | |
1526a060 | 3214 | ggc_add_tree_root (&named_labels, 1); |
1526a060 BS |
3215 | ggc_add_tree_root (&shadowed_labels, 1); |
3216 | ggc_add_root (¤t_binding_level, 1, sizeof current_binding_level, | |
3217 | mark_binding_level); | |
3218 | ggc_add_root (&label_level_chain, 1, sizeof label_level_chain, | |
3219 | mark_binding_level); | |
3220 | ggc_add_tree_root (&static_ctors, 1); | |
3221 | ggc_add_tree_root (&static_dtors, 1); | |
51e29401 RS |
3222 | } |
3223 | ||
2ce07e2d NS |
3224 | /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the |
3225 | decl, NAME is the initialization string and TYPE_DEP indicates whether | |
3226 | NAME depended on the type of the function. As we don't yet implement | |
3227 | delayed emission of static data, we mark the decl as emitted | |
3228 | so it is not placed in the output. Anything using it must therefore pull | |
3229 | out the STRING_CST initializer directly. This does mean that these names | |
63ad61ed | 3230 | are string merging candidates, which is wrong for C99's __func__. FIXME. */ |
2ce07e2d NS |
3231 | |
3232 | static tree | |
3233 | c_make_fname_decl (id, name, type_dep) | |
3234 | tree id; | |
3235 | const char *name; | |
3236 | int type_dep ATTRIBUTE_UNUSED; | |
3237 | { | |
3238 | tree decl, type, init; | |
3239 | size_t length = strlen (name); | |
3240 | ||
3241 | type = build_array_type | |
3242 | (build_qualified_type (char_type_node, TYPE_QUAL_CONST), | |
3243 | build_index_type (build_int_2 (length, 0))); | |
3244 | ||
3245 | decl = build_decl (VAR_DECL, id, type); | |
3246 | TREE_STATIC (decl) = 1; | |
3247 | TREE_READONLY (decl) = 1; | |
3248 | TREE_ASM_WRITTEN (decl) = 1; | |
3249 | DECL_SOURCE_LINE (decl) = 0; | |
3250 | DECL_ARTIFICIAL (decl) = 1; | |
3251 | DECL_IN_SYSTEM_HEADER (decl) = 1; | |
3252 | DECL_IGNORED_P (decl) = 1; | |
3253 | init = build_string (length + 1, name); | |
3254 | TREE_TYPE (init) = type; | |
3255 | DECL_INITIAL (decl) = init; | |
3256 | finish_decl (pushdecl (decl), init, NULL_TREE); | |
6645c3fa | 3257 | |
2ce07e2d NS |
3258 | return decl; |
3259 | } | |
3260 | ||
51e29401 RS |
3261 | /* Return a definition for a builtin function named NAME and whose data type |
3262 | is TYPE. TYPE should be a function type with argument types. | |
3263 | FUNCTION_CODE tells later passes how to compile calls to this function. | |
3264 | See tree.h for its possible values. | |
3265 | ||
3266 | If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, | |
3267 | the name to be called if we can't opencode the function. */ | |
3268 | ||
929f3671 | 3269 | tree |
26db82d8 | 3270 | builtin_function (name, type, function_code, class, library_name) |
5d5993dd | 3271 | const char *name; |
51e29401 | 3272 | tree type; |
26db82d8 BS |
3273 | int function_code; |
3274 | enum built_in_class class; | |
5d5993dd | 3275 | const char *library_name; |
51e29401 RS |
3276 | { |
3277 | tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type); | |
1394aabd | 3278 | DECL_EXTERNAL (decl) = 1; |
51e29401 | 3279 | TREE_PUBLIC (decl) = 1; |
9a509bfe RS |
3280 | /* If -traditional, permit redefining a builtin function any way you like. |
3281 | (Though really, if the program redefines these functions, | |
3282 | it probably won't work right unless compiled with -fno-builtin.) */ | |
3283 | if (flag_traditional && name[0] != '_') | |
3284 | DECL_BUILT_IN_NONANSI (decl) = 1; | |
51e29401 RS |
3285 | if (library_name) |
3286 | DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); | |
8d9bfdc5 | 3287 | make_decl_rtl (decl, NULL_PTR, 1); |
51e29401 | 3288 | pushdecl (decl); |
26db82d8 BS |
3289 | DECL_BUILT_IN_CLASS (decl) = class; |
3290 | DECL_FUNCTION_CODE (decl) = function_code; | |
3291 | ||
6b19af32 RS |
3292 | /* Warn if a function in the namespace for users |
3293 | is used without an occasion to consider it declared. */ | |
3294 | if (name[0] != '_' || name[1] != '_') | |
3295 | C_DECL_ANTICIPATED (decl) = 1; | |
51e29401 RS |
3296 | |
3297 | return decl; | |
3298 | } | |
3299 | \f | |
3300 | /* Called when a declaration is seen that contains no names to declare. | |
3301 | If its type is a reference to a structure, union or enum inherited | |
3302 | from a containing scope, shadow that tag name for the current scope | |
3303 | with a forward reference. | |
3304 | If its type defines a new named structure or union | |
3305 | or defines an enum, it is valid but we need not do anything here. | |
3306 | Otherwise, it is an error. */ | |
3307 | ||
3308 | void | |
3309 | shadow_tag (declspecs) | |
3310 | tree declspecs; | |
9282f2f9 RS |
3311 | { |
3312 | shadow_tag_warned (declspecs, 0); | |
3313 | } | |
3314 | ||
3315 | void | |
3316 | shadow_tag_warned (declspecs, warned) | |
3317 | tree declspecs; | |
3318 | int warned; | |
773edaef RK |
3319 | /* 1 => we have done a pedwarn. 2 => we have done a warning, but |
3320 | no pedwarn. */ | |
51e29401 RS |
3321 | { |
3322 | int found_tag = 0; | |
51e29401 | 3323 | register tree link; |
d9525bec | 3324 | tree specs, attrs; |
51e29401 RS |
3325 | |
3326 | pending_invalid_xref = 0; | |
3327 | ||
d9525bec BK |
3328 | /* Remove the attributes from declspecs, since they will confuse the |
3329 | following code. */ | |
3330 | split_specs_attrs (declspecs, &specs, &attrs); | |
3331 | ||
3bd89472 | 3332 | for (link = specs; link; link = TREE_CHAIN (link)) |
51e29401 RS |
3333 | { |
3334 | register tree value = TREE_VALUE (link); | |
3335 | register enum tree_code code = TREE_CODE (value); | |
3336 | ||
3337 | if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) | |
3338 | /* Used to test also that TYPE_SIZE (value) != 0. | |
3339 | That caused warning for `struct foo;' at top level in the file. */ | |
3340 | { | |
3341 | register tree name = lookup_tag_reverse (value); | |
3342 | register tree t; | |
3343 | ||
3344 | found_tag++; | |
3345 | ||
3346 | if (name == 0) | |
3347 | { | |
773edaef RK |
3348 | if (warned != 1 && code != ENUMERAL_TYPE) |
3349 | /* Empty unnamed enum OK */ | |
51e29401 RS |
3350 | { |
3351 | pedwarn ("unnamed struct/union that defines no instances"); | |
3352 | warned = 1; | |
3353 | } | |
3354 | } | |
3355 | else | |
3356 | { | |
3357 | t = lookup_tag (code, name, current_binding_level, 1); | |
3358 | ||
3359 | if (t == 0) | |
3360 | { | |
3361 | t = make_node (code); | |
3362 | pushtag (name, t); | |
3363 | } | |
3364 | } | |
3365 | } | |
3366 | else | |
3367 | { | |
efffbf71 | 3368 | if (!warned && ! in_system_header) |
773edaef RK |
3369 | { |
3370 | warning ("useless keyword or type name in empty declaration"); | |
3371 | warned = 2; | |
3372 | } | |
51e29401 RS |
3373 | } |
3374 | } | |
3375 | ||
773edaef RK |
3376 | if (found_tag > 1) |
3377 | error ("two types specified in one empty declaration"); | |
3378 | ||
3379 | if (warned != 1) | |
51e29401 | 3380 | { |
51e29401 RS |
3381 | if (found_tag == 0) |
3382 | pedwarn ("empty declaration"); | |
3383 | } | |
3384 | } | |
3385 | \f | |
3386 | /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | |
3387 | ||
3388 | tree | |
3389 | groktypename (typename) | |
3390 | tree typename; | |
3391 | { | |
3392 | if (TREE_CODE (typename) != TREE_LIST) | |
3393 | return typename; | |
3394 | return grokdeclarator (TREE_VALUE (typename), | |
3395 | TREE_PURPOSE (typename), | |
3396 | TYPENAME, 0); | |
3397 | } | |
3398 | ||
3399 | /* Return a PARM_DECL node for a given pair of specs and declarator. */ | |
3400 | ||
3401 | tree | |
3402 | groktypename_in_parm_context (typename) | |
3403 | tree typename; | |
3404 | { | |
3405 | if (TREE_CODE (typename) != TREE_LIST) | |
3406 | return typename; | |
3407 | return grokdeclarator (TREE_VALUE (typename), | |
3408 | TREE_PURPOSE (typename), | |
3409 | PARM, 0); | |
3410 | } | |
3411 | ||
3412 | /* Decode a declarator in an ordinary declaration or data definition. | |
3413 | This is called as soon as the type information and variable name | |
3414 | have been parsed, before parsing the initializer if any. | |
3415 | Here we create the ..._DECL node, fill in its type, | |
3416 | and put it on the list of decls for the current context. | |
3417 | The ..._DECL node is returned as the value. | |
3418 | ||
3419 | Exception: for arrays where the length is not specified, | |
3420 | the type is left null, to be filled in by `finish_decl'. | |
3421 | ||
3422 | Function definitions do not come here; they go to start_function | |
3423 | instead. However, external and forward declarations of functions | |
3424 | do go through here. Structure field declarations are done by | |
3425 | grokfield and not through here. */ | |
3426 | ||
51e29401 | 3427 | tree |
daa6d5ff | 3428 | start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) |
eaa81144 | 3429 | tree declarator, declspecs; |
51e29401 | 3430 | int initialized; |
daa6d5ff | 3431 | tree attributes, prefix_attributes; |
51e29401 RS |
3432 | { |
3433 | register tree decl = grokdeclarator (declarator, declspecs, | |
3434 | NORMAL, initialized); | |
3435 | register tree tem; | |
51e29401 | 3436 | |
6645c3fa | 3437 | if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL |
5b47282c | 3438 | && MAIN_NAME_P (DECL_NAME (decl))) |
b8705e61 RK |
3439 | warning_with_decl (decl, "`%s' is usually a function"); |
3440 | ||
51e29401 RS |
3441 | if (initialized) |
3442 | /* Is it valid for this decl to have an initializer at all? | |
3443 | If not, set INITIALIZED to zero, which will indirectly | |
3444 | tell `finish_decl' to ignore the initializer once it is parsed. */ | |
3445 | switch (TREE_CODE (decl)) | |
3446 | { | |
3447 | case TYPE_DECL: | |
3448 | /* typedef foo = bar means give foo the same type as bar. | |
3449 | We haven't parsed bar yet, so `finish_decl' will fix that up. | |
3450 | Any other case of an initialization in a TYPE_DECL is an error. */ | |
3451 | if (pedantic || list_length (declspecs) > 1) | |
3452 | { | |
3453 | error ("typedef `%s' is initialized", | |
3454 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3455 | initialized = 0; | |
3456 | } | |
3457 | break; | |
3458 | ||
3459 | case FUNCTION_DECL: | |
3460 | error ("function `%s' is initialized like a variable", | |
3461 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3462 | initialized = 0; | |
3463 | break; | |
3464 | ||
3465 | case PARM_DECL: | |
3466 | /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ | |
3467 | error ("parameter `%s' is initialized", | |
3468 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3469 | initialized = 0; | |
3470 | break; | |
3471 | ||
3472 | default: | |
3473 | /* Don't allow initializations for incomplete types | |
3474 | except for arrays which might be completed by the initialization. */ | |
f4fce7ed JW |
3475 | |
3476 | /* This can happen if the array size is an undefined macro. We already | |
3477 | gave a warning, so we don't need another one. */ | |
3478 | if (TREE_TYPE (decl) == error_mark_node) | |
3479 | initialized = 0; | |
3480 | else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) | |
51e29401 RS |
3481 | { |
3482 | /* A complete type is ok if size is fixed. */ | |
3483 | ||
3484 | if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST | |
3485 | || C_DECL_VARIABLE_SIZE (decl)) | |
3486 | { | |
3487 | error ("variable-sized object may not be initialized"); | |
3488 | initialized = 0; | |
3489 | } | |
3490 | } | |
3491 | else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) | |
3492 | { | |
3493 | error ("variable `%s' has initializer but incomplete type", | |
3494 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3495 | initialized = 0; | |
3496 | } | |
d0f062fb | 3497 | else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) |
51e29401 RS |
3498 | { |
3499 | error ("elements of array `%s' have incomplete type", | |
3500 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3501 | initialized = 0; | |
3502 | } | |
3503 | } | |
3504 | ||
3505 | if (initialized) | |
3506 | { | |
6645c3fa KH |
3507 | #if 0 |
3508 | /* Seems redundant with grokdeclarator. */ | |
51e29401 | 3509 | if (current_binding_level != global_binding_level |
1394aabd | 3510 | && DECL_EXTERNAL (decl) |
51e29401 RS |
3511 | && TREE_CODE (decl) != FUNCTION_DECL) |
3512 | warning ("declaration of `%s' has `extern' and is initialized", | |
3513 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3514 | #endif | |
1394aabd | 3515 | DECL_EXTERNAL (decl) = 0; |
51e29401 RS |
3516 | if (current_binding_level == global_binding_level) |
3517 | TREE_STATIC (decl) = 1; | |
3518 | ||
3519 | /* Tell `pushdecl' this is an initialized decl | |
3520 | even though we don't yet have the initializer expression. | |
3521 | Also tell `finish_decl' it may store the real initializer. */ | |
3522 | DECL_INITIAL (decl) = error_mark_node; | |
3523 | } | |
3524 | ||
3525 | /* If this is a function declaration, write a record describing it to the | |
3526 | prototypes file (if requested). */ | |
3527 | ||
3528 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3529 | gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0); | |
3530 | ||
2786cbad JM |
3531 | /* ANSI specifies that a tentative definition which is not merged with |
3532 | a non-tentative definition behaves exactly like a definition with an | |
3533 | initializer equal to zero. (Section 3.7.2) | |
3534 | -fno-common gives strict ANSI behavior. Usually you don't want it. | |
3535 | This matters only for variables with external linkage. */ | |
f537695d | 3536 | if (! flag_no_common || ! TREE_PUBLIC (decl)) |
2786cbad | 3537 | DECL_COMMON (decl) = 1; |
8615176a | 3538 | |
9ec36da5 JL |
3539 | #ifdef SET_DEFAULT_DECL_ATTRIBUTES |
3540 | SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes); | |
3541 | #endif | |
3542 | ||
daa6d5ff RK |
3543 | /* Set attributes here so if duplicate decl, will have proper attributes. */ |
3544 | decl_attributes (decl, attributes, prefix_attributes); | |
3545 | ||
51e29401 RS |
3546 | /* Add this decl to the current binding level. |
3547 | TEM may equal DECL or it may be a previous decl of the same name. */ | |
3548 | tem = pushdecl (decl); | |
3549 | ||
3550 | /* For a local variable, define the RTL now. */ | |
3551 | if (current_binding_level != global_binding_level | |
3552 | /* But not if this is a duplicate decl | |
3553 | and we preserved the rtl from the previous one | |
3554 | (which may or may not happen). */ | |
8f17b5c5 MM |
3555 | && DECL_RTL (tem) == 0 |
3556 | && !DECL_CONTEXT (tem)) | |
51e29401 | 3557 | { |
f4fce7ed JW |
3558 | if (TREE_TYPE (tem) != error_mark_node |
3559 | && COMPLETE_TYPE_P (TREE_TYPE (tem))) | |
51e29401 RS |
3560 | expand_decl (tem); |
3561 | else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE | |
3562 | && DECL_INITIAL (tem) != 0) | |
3563 | expand_decl (tem); | |
3564 | } | |
3565 | ||
51e29401 RS |
3566 | return tem; |
3567 | } | |
3568 | ||
3569 | /* Finish processing of a declaration; | |
3570 | install its initial value. | |
3571 | If the length of an array type is not known before, | |
3572 | it must be determined now, from the initial value, or it is an error. */ | |
3573 | ||
3574 | void | |
3575 | finish_decl (decl, init, asmspec_tree) | |
3576 | tree decl, init; | |
3577 | tree asmspec_tree; | |
3578 | { | |
3579 | register tree type = TREE_TYPE (decl); | |
3580 | int was_incomplete = (DECL_SIZE (decl) == 0); | |
520a57c8 | 3581 | const char *asmspec = 0; |
51e29401 | 3582 | |
72f5a12b | 3583 | /* If a name was specified, get the string. */ |
51e29401 | 3584 | if (asmspec_tree) |
72f5a12b | 3585 | asmspec = TREE_STRING_POINTER (asmspec_tree); |
51e29401 RS |
3586 | |
3587 | /* If `start_decl' didn't like having an initialization, ignore it now. */ | |
3588 | ||
3589 | if (init != 0 && DECL_INITIAL (decl) == 0) | |
3590 | init = 0; | |
3591 | /* Don't crash if parm is initialized. */ | |
3592 | if (TREE_CODE (decl) == PARM_DECL) | |
3593 | init = 0; | |
3594 | ||
3595 | if (init) | |
3596 | { | |
3597 | if (TREE_CODE (decl) != TYPE_DECL) | |
3598 | store_init_value (decl, init); | |
3599 | else | |
3600 | { | |
3601 | /* typedef foo = bar; store the type of bar as the type of foo. */ | |
3602 | TREE_TYPE (decl) = TREE_TYPE (init); | |
3603 | DECL_INITIAL (decl) = init = 0; | |
3604 | } | |
3605 | } | |
3606 | ||
51e29401 RS |
3607 | /* Deduce size of array from initialization, if not already known */ |
3608 | ||
3609 | if (TREE_CODE (type) == ARRAY_TYPE | |
3610 | && TYPE_DOMAIN (type) == 0 | |
3611 | && TREE_CODE (decl) != TYPE_DECL) | |
3612 | { | |
3613 | int do_default | |
3614 | = (TREE_STATIC (decl) | |
3615 | /* Even if pedantic, an external linkage array | |
3616 | may have incomplete type at first. */ | |
3617 | ? pedantic && !TREE_PUBLIC (decl) | |
1394aabd | 3618 | : !DECL_EXTERNAL (decl)); |
51e29401 RS |
3619 | int failure |
3620 | = complete_array_type (type, DECL_INITIAL (decl), do_default); | |
3621 | ||
3622 | /* Get the completed type made by complete_array_type. */ | |
3623 | type = TREE_TYPE (decl); | |
3624 | ||
3625 | if (failure == 1) | |
3626 | error_with_decl (decl, "initializer fails to determine size of `%s'"); | |
3627 | ||
5fa7c8ce | 3628 | else if (failure == 2) |
51e29401 RS |
3629 | { |
3630 | if (do_default) | |
3631 | error_with_decl (decl, "array size missing in `%s'"); | |
b4892310 RS |
3632 | /* If a `static' var's size isn't known, |
3633 | make it extern as well as static, so it does not get | |
3634 | allocated. | |
3635 | If it is not `static', then do not mark extern; | |
3636 | finish_incomplete_decl will give it a default size | |
3637 | and it will get allocated. */ | |
3638 | else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl)) | |
1394aabd | 3639 | DECL_EXTERNAL (decl) = 1; |
51e29401 RS |
3640 | } |
3641 | ||
7e44eda6 JW |
3642 | /* TYPE_MAX_VALUE is always one less than the number of elements |
3643 | in the array, because we start counting at zero. Therefore, | |
3644 | warn only if the value is less than zero. */ | |
5fa7c8ce RK |
3645 | else if (pedantic && TYPE_DOMAIN (type) != 0 |
3646 | && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0) | |
6aa10371 | 3647 | error_with_decl (decl, "zero or negative size array `%s'"); |
51e29401 RS |
3648 | |
3649 | layout_decl (decl, 0); | |
3650 | } | |
3651 | ||
3652 | if (TREE_CODE (decl) == VAR_DECL) | |
3653 | { | |
f4fce7ed JW |
3654 | if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node |
3655 | && COMPLETE_TYPE_P (TREE_TYPE (decl))) | |
d575f110 RS |
3656 | layout_decl (decl, 0); |
3657 | ||
a7f64d52 | 3658 | if (DECL_SIZE (decl) == 0 |
f4fce7ed JW |
3659 | /* Don't give an error if we already gave one earlier. */ |
3660 | && TREE_TYPE (decl) != error_mark_node | |
a7f64d52 RS |
3661 | && (TREE_STATIC (decl) |
3662 | ? | |
3663 | /* A static variable with an incomplete type | |
f3b4fb6e | 3664 | is an error if it is initialized. |
70efc776 | 3665 | Also if it is not file scope. |
a7f64d52 RS |
3666 | Otherwise, let it through, but if it is not `extern' |
3667 | then it may cause an error message later. */ | |
e3b776dc | 3668 | (DECL_INITIAL (decl) != 0 |
edb4c415 | 3669 | || DECL_CONTEXT (decl) != 0) |
a7f64d52 RS |
3670 | : |
3671 | /* An automatic variable with an incomplete type | |
3672 | is an error. */ | |
70038ec9 | 3673 | !DECL_EXTERNAL (decl))) |
51e29401 | 3674 | { |
51e29401 RS |
3675 | error_with_decl (decl, "storage size of `%s' isn't known"); |
3676 | TREE_TYPE (decl) = error_mark_node; | |
3677 | } | |
3678 | ||
1394aabd | 3679 | if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) |
90374cc2 | 3680 | && DECL_SIZE (decl) != 0) |
e681c5a1 RS |
3681 | { |
3682 | if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) | |
3683 | constant_expression_warning (DECL_SIZE (decl)); | |
3684 | else | |
3685 | error_with_decl (decl, "storage size of `%s' isn't constant"); | |
3686 | } | |
e9a25f70 | 3687 | |
6645c3fa | 3688 | if (TREE_USED (type)) |
e9a25f70 | 3689 | TREE_USED (decl) = 1; |
51e29401 RS |
3690 | } |
3691 | ||
3c4afaa5 | 3692 | /* If this is a function and an assembler name is specified, it isn't |
72f5a12b RK |
3693 | builtin any more. Also reset DECL_RTL so we can give it its new |
3694 | name. */ | |
3c4afaa5 | 3695 | if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) |
6645c3fa KH |
3696 | { |
3697 | DECL_BUILT_IN_CLASS (decl) = NOT_BUILT_IN; | |
3698 | DECL_RTL (decl) = 0; | |
3699 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
3700 | } | |
3c4afaa5 | 3701 | |
51e29401 RS |
3702 | /* Output the assembler code and/or RTL code for variables and functions, |
3703 | unless the type is an undefined structure or union. | |
3704 | If not, it will get done when the type is completed. */ | |
3705 | ||
3706 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) | |
3707 | { | |
4dd7201e ZW |
3708 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ |
3709 | maybe_objc_check_decl (decl); | |
8f17b5c5 MM |
3710 | |
3711 | if (!DECL_CONTEXT (decl)) | |
3712 | rest_of_decl_compilation (decl, asmspec, | |
3713 | (DECL_CONTEXT (decl) == 0 | |
3714 | || TREE_ASM_WRITTEN (decl)), 0); | |
3715 | else | |
3716 | { | |
3717 | if (asmspec) | |
3645c4dc RH |
3718 | { |
3719 | DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); | |
3720 | DECL_C_HARD_REGISTER (decl) = 1; | |
3721 | } | |
8f17b5c5 MM |
3722 | add_decl_stmt (decl); |
3723 | } | |
4dd7201e | 3724 | |
15317f89 | 3725 | if (DECL_CONTEXT (decl) != 0) |
51e29401 RS |
3726 | { |
3727 | /* Recompute the RTL of a local array now | |
3728 | if it used to be an incomplete type. */ | |
3729 | if (was_incomplete | |
1394aabd | 3730 | && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl)) |
51e29401 RS |
3731 | { |
3732 | /* If we used it already as memory, it must stay in memory. */ | |
3733 | TREE_ADDRESSABLE (decl) = TREE_USED (decl); | |
3734 | /* If it's still incomplete now, no init will save it. */ | |
3735 | if (DECL_SIZE (decl) == 0) | |
3736 | DECL_INITIAL (decl) = 0; | |
51e29401 | 3737 | } |
51e29401 RS |
3738 | } |
3739 | } | |
3740 | ||
3741 | if (TREE_CODE (decl) == TYPE_DECL) | |
3742 | { | |
3743 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
3744 | maybe_objc_check_decl (decl); | |
4dd7201e | 3745 | rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == 0, 0); |
51e29401 RS |
3746 | } |
3747 | ||
51e29401 RS |
3748 | /* At the end of a declaration, throw away any variable type sizes |
3749 | of types defined inside that declaration. There is no use | |
3750 | computing them in the following function definition. */ | |
3751 | if (current_binding_level == global_binding_level) | |
3752 | get_pending_sizes (); | |
3753 | } | |
3754 | ||
3755 | /* If DECL has a cleanup, build and return that cleanup here. | |
3756 | This is a callback called by expand_expr. */ | |
3757 | ||
3758 | tree | |
3759 | maybe_build_cleanup (decl) | |
d6f4ec51 | 3760 | tree decl ATTRIBUTE_UNUSED; |
51e29401 RS |
3761 | { |
3762 | /* There are no cleanups in C. */ | |
3763 | return NULL_TREE; | |
3764 | } | |
3765 | ||
3766 | /* Given a parsed parameter declaration, | |
3767 | decode it into a PARM_DECL and push that on the current binding level. | |
3768 | Also, for the sake of forward parm decls, | |
3769 | record the given order of parms in `parm_order'. */ | |
3770 | ||
3771 | void | |
3772 | push_parm_decl (parm) | |
3773 | tree parm; | |
3774 | { | |
6cc902a1 | 3775 | tree decl; |
929f3671 RS |
3776 | int old_immediate_size_expand = immediate_size_expand; |
3777 | /* Don't try computing parm sizes now -- wait till fn is called. */ | |
3778 | immediate_size_expand = 0; | |
51e29401 | 3779 | |
005979f2 RK |
3780 | decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)), |
3781 | TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0); | |
3782 | decl_attributes (decl, TREE_VALUE (TREE_VALUE (parm)), | |
3783 | TREE_PURPOSE (TREE_VALUE (parm))); | |
6a5ed5bf RK |
3784 | |
3785 | #if 0 | |
93e3ba4f RS |
3786 | if (DECL_NAME (decl)) |
3787 | { | |
6cc902a1 | 3788 | tree olddecl; |
93e3ba4f RS |
3789 | olddecl = lookup_name (DECL_NAME (decl)); |
3790 | if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL) | |
6645c3fa KH |
3791 | pedwarn_with_decl (decl, |
3792 | "ANSI C forbids parameter `%s' shadowing typedef"); | |
93e3ba4f | 3793 | } |
6a5ed5bf RK |
3794 | #endif |
3795 | ||
51e29401 RS |
3796 | decl = pushdecl (decl); |
3797 | ||
929f3671 RS |
3798 | immediate_size_expand = old_immediate_size_expand; |
3799 | ||
51e29401 RS |
3800 | current_binding_level->parm_order |
3801 | = tree_cons (NULL_TREE, decl, current_binding_level->parm_order); | |
3802 | ||
3803 | /* Add this decl to the current binding level. */ | |
3804 | finish_decl (decl, NULL_TREE, NULL_TREE); | |
3805 | } | |
3806 | ||
3807 | /* Clear the given order of parms in `parm_order'. | |
3808 | Used at start of parm list, | |
3809 | and also at semicolon terminating forward decls. */ | |
3810 | ||
3811 | void | |
3812 | clear_parm_order () | |
3813 | { | |
3814 | current_binding_level->parm_order = NULL_TREE; | |
3815 | } | |
3816 | \f | |
3817 | /* Make TYPE a complete type based on INITIAL_VALUE. | |
929f3671 | 3818 | Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, |
51e29401 RS |
3819 | 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ |
3820 | ||
3821 | int | |
3822 | complete_array_type (type, initial_value, do_default) | |
3823 | tree type; | |
3824 | tree initial_value; | |
3825 | int do_default; | |
3826 | { | |
3827 | register tree maxindex = NULL_TREE; | |
3828 | int value = 0; | |
3829 | ||
3830 | if (initial_value) | |
3831 | { | |
3832 | /* Note MAXINDEX is really the maximum index, | |
3833 | one less than the size. */ | |
3834 | if (TREE_CODE (initial_value) == STRING_CST) | |
3835 | { | |
3836 | int eltsize | |
3837 | = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); | |
20bf3fac RS |
3838 | maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) |
3839 | / eltsize) - 1, 0); | |
51e29401 RS |
3840 | } |
3841 | else if (TREE_CODE (initial_value) == CONSTRUCTOR) | |
3842 | { | |
ecd4cee0 | 3843 | tree elts = CONSTRUCTOR_ELTS (initial_value); |
fed3cef0 | 3844 | maxindex = build_int_2 (-1, -1); |
ecd4cee0 RS |
3845 | for (; elts; elts = TREE_CHAIN (elts)) |
3846 | { | |
3847 | if (TREE_PURPOSE (elts)) | |
3848 | maxindex = TREE_PURPOSE (elts); | |
3849 | else | |
fed3cef0 RK |
3850 | maxindex = fold (build (PLUS_EXPR, integer_type_node, |
3851 | maxindex, integer_one_node)); | |
ecd4cee0 RS |
3852 | } |
3853 | maxindex = copy_node (maxindex); | |
51e29401 RS |
3854 | } |
3855 | else | |
3856 | { | |
3857 | /* Make an error message unless that happened already. */ | |
3858 | if (initial_value != error_mark_node) | |
3859 | value = 1; | |
3860 | ||
3861 | /* Prevent further error messages. */ | |
b4892310 | 3862 | maxindex = build_int_2 (0, 0); |
51e29401 RS |
3863 | } |
3864 | } | |
3865 | ||
3866 | if (!maxindex) | |
3867 | { | |
3868 | if (do_default) | |
b4892310 | 3869 | maxindex = build_int_2 (0, 0); |
51e29401 RS |
3870 | value = 2; |
3871 | } | |
3872 | ||
3873 | if (maxindex) | |
3874 | { | |
3875 | TYPE_DOMAIN (type) = build_index_type (maxindex); | |
3876 | if (!TREE_TYPE (maxindex)) | |
3877 | TREE_TYPE (maxindex) = TYPE_DOMAIN (type); | |
3878 | } | |
3879 | ||
3880 | /* Lay out the type now that we can get the real answer. */ | |
3881 | ||
3882 | layout_type (type); | |
3883 | ||
3884 | return value; | |
3885 | } | |
3886 | \f | |
3887 | /* Given declspecs and a declarator, | |
3888 | determine the name and type of the object declared | |
3889 | and construct a ..._DECL node for it. | |
3890 | (In one case we can return a ..._TYPE node instead. | |
3891 | For invalid input we sometimes return 0.) | |
3892 | ||
3893 | DECLSPECS is a chain of tree_list nodes whose value fields | |
3894 | are the storage classes and type specifiers. | |
3895 | ||
3896 | DECL_CONTEXT says which syntactic context this declaration is in: | |
3897 | NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. | |
3898 | FUNCDEF for a function definition. Like NORMAL but a few different | |
3899 | error messages in each case. Return value may be zero meaning | |
3900 | this definition is too screwy to try to parse. | |
3901 | PARM for a parameter declaration (either within a function prototype | |
3902 | or before a function body). Make a PARM_DECL, or return void_type_node. | |
3903 | TYPENAME if for a typename (in a cast or sizeof). | |
3904 | Don't make a DECL node; just return the ..._TYPE node. | |
3905 | FIELD for a struct or union field; make a FIELD_DECL. | |
3906 | BITFIELD for a field with specified width. | |
3907 | INITIALIZED is 1 if the decl has an initializer. | |
3908 | ||
3909 | In the TYPENAME case, DECLARATOR is really an absolute declarator. | |
3910 | It may also be so in the PARM case, for a prototype where the | |
3911 | argument type is specified but not the name. | |
3912 | ||
3913 | This function is where the complicated C meanings of `static' | |
929f3671 | 3914 | and `extern' are interpreted. */ |
51e29401 RS |
3915 | |
3916 | static tree | |
3917 | grokdeclarator (declarator, declspecs, decl_context, initialized) | |
3918 | tree declspecs; | |
3919 | tree declarator; | |
3920 | enum decl_context decl_context; | |
3921 | int initialized; | |
3922 | { | |
3923 | int specbits = 0; | |
3924 | tree spec; | |
3925 | tree type = NULL_TREE; | |
3926 | int longlong = 0; | |
3927 | int constp; | |
3932261a | 3928 | int restrictp; |
51e29401 | 3929 | int volatilep; |
3932261a | 3930 | int type_quals = TYPE_UNQUALIFIED; |
51e29401 RS |
3931 | int inlinep; |
3932 | int explicit_int = 0; | |
3933 | int explicit_char = 0; | |
5ab10c42 | 3934 | int defaulted_int = 0; |
51e29401 | 3935 | tree typedef_decl = 0; |
5d5993dd | 3936 | const char *name; |
51e29401 RS |
3937 | tree typedef_type = 0; |
3938 | int funcdef_flag = 0; | |
3939 | enum tree_code innermost_code = ERROR_MARK; | |
3940 | int bitfield = 0; | |
929f3671 | 3941 | int size_varies = 0; |
4b4e3407 | 3942 | tree decl_machine_attr = NULL_TREE; |
51e29401 RS |
3943 | |
3944 | if (decl_context == BITFIELD) | |
3945 | bitfield = 1, decl_context = FIELD; | |
3946 | ||
3947 | if (decl_context == FUNCDEF) | |
3948 | funcdef_flag = 1, decl_context = NORMAL; | |
3949 | ||
51e29401 RS |
3950 | /* Look inside a declarator for the name being declared |
3951 | and get it as a string, for an error message. */ | |
3952 | { | |
3953 | register tree decl = declarator; | |
3954 | name = 0; | |
3955 | ||
3956 | while (decl) | |
3957 | switch (TREE_CODE (decl)) | |
3958 | { | |
3959 | case ARRAY_REF: | |
3960 | case INDIRECT_REF: | |
3961 | case CALL_EXPR: | |
3962 | innermost_code = TREE_CODE (decl); | |
3963 | decl = TREE_OPERAND (decl, 0); | |
3964 | break; | |
3965 | ||
3966 | case IDENTIFIER_NODE: | |
3967 | name = IDENTIFIER_POINTER (decl); | |
3968 | decl = 0; | |
3969 | break; | |
3970 | ||
3971 | default: | |
3972 | abort (); | |
3973 | } | |
3974 | if (name == 0) | |
3975 | name = "type name"; | |
3976 | } | |
3977 | ||
3978 | /* A function definition's declarator must have the form of | |
3979 | a function declarator. */ | |
3980 | ||
3981 | if (funcdef_flag && innermost_code != CALL_EXPR) | |
3982 | return 0; | |
3983 | ||
3984 | /* Anything declared one level down from the top level | |
3985 | must be one of the parameters of a function | |
3986 | (because the body is at least two levels down). */ | |
3987 | ||
3988 | /* If this looks like a function definition, make it one, | |
3989 | even if it occurs where parms are expected. | |
3990 | Then store_parm_decls will reject it and not use it as a parm. */ | |
3991 | if (decl_context == NORMAL && !funcdef_flag | |
9a381dd4 | 3992 | && current_binding_level->parm_flag) |
51e29401 RS |
3993 | decl_context = PARM; |
3994 | ||
3995 | /* Look through the decl specs and record which ones appear. | |
3996 | Some typespecs are defined as built-in typenames. | |
3997 | Others, the ones that are modifiers of other types, | |
3998 | are represented by bits in SPECBITS: set the bits for | |
3999 | the modifiers that appear. Storage class keywords are also in SPECBITS. | |
4000 | ||
4001 | If there is a typedef name or a type, store the type in TYPE. | |
4002 | This includes builtin typedefs such as `int'. | |
4003 | ||
4004 | Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char' | |
4005 | and did not come from a user typedef. | |
4006 | ||
4007 | Set LONGLONG if `long' is mentioned twice. */ | |
4008 | ||
4009 | for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) | |
4010 | { | |
51e29401 RS |
4011 | register tree id = TREE_VALUE (spec); |
4012 | ||
4013 | if (id == ridpointers[(int) RID_INT]) | |
4014 | explicit_int = 1; | |
4015 | if (id == ridpointers[(int) RID_CHAR]) | |
4016 | explicit_char = 1; | |
4017 | ||
0e5921e8 ZW |
4018 | if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (id)) |
4019 | { | |
4020 | enum rid i = C_RID_CODE (id); | |
4021 | if (i <= RID_LAST_MODIFIER) | |
4022 | { | |
4023 | if (i == RID_LONG && specbits & (1<<i)) | |
4024 | { | |
4025 | if (longlong) | |
4026 | error ("`long long long' is too long for GCC"); | |
4027 | else | |
4028 | { | |
4029 | if (pedantic && !flag_isoc99 && ! in_system_header | |
4030 | && warn_long_long) | |
4031 | pedwarn ("ISO C89 does not support `long long'"); | |
4032 | longlong = 1; | |
4033 | } | |
4034 | } | |
4035 | else if (specbits & (1 << i)) | |
4036 | pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); | |
4037 | specbits |= 1 << i; | |
4038 | goto found; | |
4039 | } | |
4040 | } | |
51e29401 RS |
4041 | if (type) |
4042 | error ("two or more data types in declaration of `%s'", name); | |
4043 | /* Actual typedefs come to us as TYPE_DECL nodes. */ | |
4044 | else if (TREE_CODE (id) == TYPE_DECL) | |
4045 | { | |
4046 | type = TREE_TYPE (id); | |
6645c3fa | 4047 | decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); |
51e29401 RS |
4048 | typedef_decl = id; |
4049 | } | |
4050 | /* Built-in types come as identifiers. */ | |
4051 | else if (TREE_CODE (id) == IDENTIFIER_NODE) | |
4052 | { | |
4053 | register tree t = lookup_name (id); | |
4054 | if (TREE_TYPE (t) == error_mark_node) | |
4055 | ; | |
4056 | else if (!t || TREE_CODE (t) != TYPE_DECL) | |
4057 | error ("`%s' fails to be a typedef or built in type", | |
4058 | IDENTIFIER_POINTER (id)); | |
4059 | else | |
4060 | { | |
4061 | type = TREE_TYPE (t); | |
4062 | typedef_decl = t; | |
4063 | } | |
4064 | } | |
4065 | else if (TREE_CODE (id) != ERROR_MARK) | |
4066 | type = id; | |
4067 | ||
6645c3fa KH |
4068 | found: |
4069 | ; | |
51e29401 RS |
4070 | } |
4071 | ||
4072 | typedef_type = type; | |
4073 | if (type) | |
929f3671 | 4074 | size_varies = C_TYPE_VARIABLE_SIZE (type); |
51e29401 | 4075 | |
5ab10c42 | 4076 | /* No type at all: default to `int', and set DEFAULTED_INT |
51e29401 RS |
4077 | because it was not a user-defined typedef. */ |
4078 | ||
4079 | if (type == 0) | |
4080 | { | |
f5963e61 JL |
4081 | if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) |
4082 | | (1 << (int) RID_SIGNED) | |
60e9d01c JM |
4083 | | (1 << (int) RID_UNSIGNED) |
4084 | | (1 << (int) RID_COMPLEX)))) | |
03369c93 AS |
4085 | /* Don't warn about typedef foo = bar. */ |
4086 | && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized) | |
4dd7201e | 4087 | && ! in_system_header) |
720283f2 | 4088 | { |
916269ab | 4089 | /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type |
6f4d7222 UD |
4090 | and this is a function, or if -Wimplicit; prefer the former |
4091 | warning since it is more explicit. */ | |
e9a25f70 | 4092 | if ((warn_implicit_int || warn_return_type) && funcdef_flag) |
720283f2 | 4093 | warn_about_return_type = 1; |
916269ab | 4094 | else if (warn_implicit_int || flag_isoc99) |
6645c3fa KH |
4095 | pedwarn_c99 ("type defaults to `int' in declaration of `%s'", |
4096 | name); | |
720283f2 RK |
4097 | } |
4098 | ||
5ab10c42 | 4099 | defaulted_int = 1; |
51e29401 RS |
4100 | type = integer_type_node; |
4101 | } | |
4102 | ||
4103 | /* Now process the modifiers that were specified | |
4104 | and check for invalid combinations. */ | |
4105 | ||
4106 | /* Long double is a special combination. */ | |
4107 | ||
861bb6c1 | 4108 | if ((specbits & 1 << (int) RID_LONG) && ! longlong |
90d56da8 | 4109 | && TYPE_MAIN_VARIANT (type) == double_type_node) |
51e29401 | 4110 | { |
6645c3fa | 4111 | specbits &= ~(1 << (int) RID_LONG); |
51e29401 RS |
4112 | type = long_double_type_node; |
4113 | } | |
4114 | ||
4115 | /* Check all other uses of type modifiers. */ | |
4116 | ||
4117 | if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4118 | | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED))) | |
4119 | { | |
4120 | int ok = 0; | |
4121 | ||
861bb6c1 JL |
4122 | if ((specbits & 1 << (int) RID_LONG) |
4123 | && (specbits & 1 << (int) RID_SHORT)) | |
4124 | error ("both long and short specified for `%s'", name); | |
51e29401 RS |
4125 | else if (((specbits & 1 << (int) RID_LONG) |
4126 | || (specbits & 1 << (int) RID_SHORT)) | |
4127 | && explicit_char) | |
4128 | error ("long or short specified with char for `%s'", name); | |
4129 | else if (((specbits & 1 << (int) RID_LONG) | |
4130 | || (specbits & 1 << (int) RID_SHORT)) | |
4131 | && TREE_CODE (type) == REAL_TYPE) | |
861bb6c1 JL |
4132 | { |
4133 | static int already = 0; | |
4134 | ||
4135 | error ("long or short specified with floating type for `%s'", name); | |
4136 | if (! already && ! pedantic) | |
4137 | { | |
4138 | error ("the only valid combination is `long double'"); | |
4139 | already = 1; | |
4140 | } | |
4141 | } | |
51e29401 RS |
4142 | else if ((specbits & 1 << (int) RID_SIGNED) |
4143 | && (specbits & 1 << (int) RID_UNSIGNED)) | |
861bb6c1 JL |
4144 | error ("both signed and unsigned specified for `%s'", name); |
4145 | else if (TREE_CODE (type) != INTEGER_TYPE) | |
4146 | error ("long, short, signed or unsigned invalid for `%s'", name); | |
51e29401 RS |
4147 | else |
4148 | { | |
4149 | ok = 1; | |
5ab10c42 | 4150 | if (!explicit_int && !defaulted_int && !explicit_char && pedantic) |
51e29401 RS |
4151 | { |
4152 | pedwarn ("long, short, signed or unsigned used invalidly for `%s'", | |
4153 | name); | |
4154 | if (flag_pedantic_errors) | |
4155 | ok = 0; | |
4156 | } | |
4157 | } | |
4158 | ||
4159 | /* Discard the type modifiers if they are invalid. */ | |
4160 | if (! ok) | |
4161 | { | |
4162 | specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4163 | | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)); | |
4164 | longlong = 0; | |
4165 | } | |
4166 | } | |
4167 | ||
c470260b RK |
4168 | if ((specbits & (1 << (int) RID_COMPLEX)) |
4169 | && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) | |
4170 | { | |
4171 | error ("complex invalid for `%s'", name); | |
6645c3fa | 4172 | specbits &= ~(1 << (int) RID_COMPLEX); |
c470260b RK |
4173 | } |
4174 | ||
51e29401 RS |
4175 | /* Decide whether an integer type is signed or not. |
4176 | Optionally treat bitfields as signed by default. */ | |
4177 | if (specbits & 1 << (int) RID_UNSIGNED | |
4178 | /* Traditionally, all bitfields are unsigned. */ | |
7a0347ff RS |
4179 | || (bitfield && flag_traditional |
4180 | && (! explicit_flag_signed_bitfields || !flag_signed_bitfields)) | |
51e29401 | 4181 | || (bitfield && ! flag_signed_bitfields |
5ab10c42 | 4182 | && (explicit_int || defaulted_int || explicit_char |
51e29401 RS |
4183 | /* A typedef for plain `int' without `signed' |
4184 | can be controlled just like plain `int'. */ | |
4185 | || ! (typedef_decl != 0 | |
4186 | && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
4187 | && TREE_CODE (type) != ENUMERAL_TYPE | |
4188 | && !(specbits & 1 << (int) RID_SIGNED))) | |
4189 | { | |
4190 | if (longlong) | |
4191 | type = long_long_unsigned_type_node; | |
4192 | else if (specbits & 1 << (int) RID_LONG) | |
4193 | type = long_unsigned_type_node; | |
4194 | else if (specbits & 1 << (int) RID_SHORT) | |
4195 | type = short_unsigned_type_node; | |
4196 | else if (type == char_type_node) | |
4197 | type = unsigned_char_type_node; | |
4198 | else if (typedef_decl) | |
4199 | type = unsigned_type (type); | |
4200 | else | |
4201 | type = unsigned_type_node; | |
4202 | } | |
4203 | else if ((specbits & 1 << (int) RID_SIGNED) | |
4204 | && type == char_type_node) | |
4205 | type = signed_char_type_node; | |
4206 | else if (longlong) | |
4207 | type = long_long_integer_type_node; | |
4208 | else if (specbits & 1 << (int) RID_LONG) | |
4209 | type = long_integer_type_node; | |
4210 | else if (specbits & 1 << (int) RID_SHORT) | |
4211 | type = short_integer_type_node; | |
c470260b RK |
4212 | |
4213 | if (specbits & 1 << (int) RID_COMPLEX) | |
5ab10c42 | 4214 | { |
60e9d01c JM |
4215 | if (pedantic && !flag_isoc99) |
4216 | pedwarn ("ISO C89 does not support complex types"); | |
c470260b RK |
4217 | /* If we just have "complex", it is equivalent to |
4218 | "complex double", but if any modifiers at all are specified it is | |
4219 | the complex form of TYPE. E.g, "complex short" is | |
4220 | "complex short int". */ | |
4221 | ||
4222 | if (defaulted_int && ! longlong | |
4223 | && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4224 | | (1 << (int) RID_SIGNED) | |
4225 | | (1 << (int) RID_UNSIGNED)))) | |
60e9d01c JM |
4226 | { |
4227 | if (pedantic) | |
4228 | pedwarn ("ISO C does not support plain `complex' meaning `double complex'"); | |
4229 | type = complex_double_type_node; | |
4230 | } | |
5ab10c42 | 4231 | else if (type == integer_type_node) |
60e9d01c JM |
4232 | { |
4233 | if (pedantic) | |
4234 | pedwarn ("ISO C does not support complex integer types"); | |
4235 | type = complex_integer_type_node; | |
4236 | } | |
5ab10c42 RS |
4237 | else if (type == float_type_node) |
4238 | type = complex_float_type_node; | |
4239 | else if (type == double_type_node) | |
4240 | type = complex_double_type_node; | |
4241 | else if (type == long_double_type_node) | |
4242 | type = complex_long_double_type_node; | |
4243 | else | |
60e9d01c JM |
4244 | { |
4245 | if (pedantic) | |
4246 | pedwarn ("ISO C does not support complex integer types"); | |
4247 | type = build_complex_type (type); | |
4248 | } | |
5ab10c42 | 4249 | } |
51e29401 | 4250 | |
3932261a MM |
4251 | /* Figure out the type qualifiers for the declaration. There are |
4252 | two ways a declaration can become qualified. One is something | |
4253 | like `const int i' where the `const' is explicit. Another is | |
4254 | something like `typedef const int CI; CI i' where the type of the | |
4255 | declaration contains the `const'. */ | |
51e29401 | 4256 | constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type); |
3932261a | 4257 | restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type); |
51e29401 RS |
4258 | volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type); |
4259 | inlinep = !! (specbits & (1 << (int) RID_INLINE)); | |
903f51d9 | 4260 | if (constp > 1 && ! flag_isoc99) |
93e3ba4f | 4261 | pedwarn ("duplicate `const'"); |
903f51d9 | 4262 | if (restrictp > 1 && ! flag_isoc99) |
3932261a | 4263 | pedwarn ("duplicate `restrict'"); |
903f51d9 | 4264 | if (volatilep > 1 && ! flag_isoc99) |
93e3ba4f | 4265 | pedwarn ("duplicate `volatile'"); |
3932261a | 4266 | if (! flag_gen_aux_info && (TYPE_QUALS (type))) |
51e29401 | 4267 | type = TYPE_MAIN_VARIANT (type); |
3932261a MM |
4268 | type_quals = ((constp ? TYPE_QUAL_CONST : 0) |
4269 | | (restrictp ? TYPE_QUAL_RESTRICT : 0) | |
4270 | | (volatilep ? TYPE_QUAL_VOLATILE : 0)); | |
51e29401 RS |
4271 | |
4272 | /* Warn if two storage classes are given. Default to `auto'. */ | |
4273 | ||
4274 | { | |
4275 | int nclasses = 0; | |
4276 | ||
4277 | if (specbits & 1 << (int) RID_AUTO) nclasses++; | |
4278 | if (specbits & 1 << (int) RID_STATIC) nclasses++; | |
4279 | if (specbits & 1 << (int) RID_EXTERN) nclasses++; | |
4280 | if (specbits & 1 << (int) RID_REGISTER) nclasses++; | |
4281 | if (specbits & 1 << (int) RID_TYPEDEF) nclasses++; | |
4282 | ||
4283 | /* Warn about storage classes that are invalid for certain | |
4284 | kinds of declarations (parameters, typenames, etc.). */ | |
4285 | ||
4286 | if (nclasses > 1) | |
4287 | error ("multiple storage classes in declaration of `%s'", name); | |
4288 | else if (funcdef_flag | |
4289 | && (specbits | |
4290 | & ((1 << (int) RID_REGISTER) | |
4291 | | (1 << (int) RID_AUTO) | |
4292 | | (1 << (int) RID_TYPEDEF)))) | |
4293 | { | |
4294 | if (specbits & 1 << (int) RID_AUTO | |
4295 | && (pedantic || current_binding_level == global_binding_level)) | |
4296 | pedwarn ("function definition declared `auto'"); | |
4297 | if (specbits & 1 << (int) RID_REGISTER) | |
4298 | error ("function definition declared `register'"); | |
4299 | if (specbits & 1 << (int) RID_TYPEDEF) | |
4300 | error ("function definition declared `typedef'"); | |
6645c3fa KH |
4301 | specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) |
4302 | | (1 << (int) RID_AUTO)); | |
51e29401 RS |
4303 | } |
4304 | else if (decl_context != NORMAL && nclasses > 0) | |
4305 | { | |
4306 | if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER) | |
4307 | ; | |
4308 | else | |
4309 | { | |
913d0833 KG |
4310 | switch (decl_context) |
4311 | { | |
4312 | case FIELD: | |
6645c3fa KH |
4313 | error ("storage class specified for structure field `%s'", |
4314 | name); | |
913d0833 KG |
4315 | break; |
4316 | case PARM: | |
4317 | error ("storage class specified for parameter `%s'", name); | |
4318 | break; | |
4319 | default: | |
4320 | error ("storage class specified for typename"); | |
4321 | break; | |
4322 | } | |
6645c3fa KH |
4323 | specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) |
4324 | | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC) | |
4325 | | (1 << (int) RID_EXTERN)); | |
51e29401 RS |
4326 | } |
4327 | } | |
4328 | else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag) | |
4329 | { | |
4330 | /* `extern' with initialization is invalid if not at top level. */ | |
4331 | if (current_binding_level == global_binding_level) | |
4332 | warning ("`%s' initialized and declared `extern'", name); | |
4333 | else | |
4334 | error ("`%s' has both `extern' and initializer", name); | |
4335 | } | |
4336 | else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag | |
4337 | && current_binding_level != global_binding_level) | |
4338 | error ("nested function `%s' declared `extern'", name); | |
4339 | else if (current_binding_level == global_binding_level | |
4340 | && specbits & (1 << (int) RID_AUTO)) | |
4341 | error ("top-level declaration of `%s' specifies `auto'", name); | |
4342 | } | |
4343 | ||
4344 | /* Now figure out the structure of the declarator proper. | |
4345 | Descend through it, creating more complex types, until we reach | |
4346 | the declared identifier (or NULL_TREE, in an absolute declarator). */ | |
4347 | ||
4348 | while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) | |
4349 | { | |
4350 | if (type == error_mark_node) | |
4351 | { | |
4352 | declarator = TREE_OPERAND (declarator, 0); | |
4353 | continue; | |
4354 | } | |
4355 | ||
4356 | /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), | |
4357 | an INDIRECT_REF (for *...), | |
4358 | a CALL_EXPR (for ...(...)), | |
4359 | an identifier (for the name being declared) | |
4360 | or a null pointer (for the place in an absolute declarator | |
4361 | where the name was omitted). | |
4362 | For the last two cases, we have just exited the loop. | |
4363 | ||
4364 | At this point, TYPE is the type of elements of an array, | |
4365 | or for a function to return, or for a pointer to point to. | |
4366 | After this sequence of ifs, TYPE is the type of the | |
4367 | array or function or pointer, and DECLARATOR has had its | |
4368 | outermost layer removed. */ | |
4369 | ||
4370 | if (TREE_CODE (declarator) == ARRAY_REF) | |
4371 | { | |
4372 | register tree itype = NULL_TREE; | |
4373 | register tree size = TREE_OPERAND (declarator, 1); | |
1ff1a2d2 RK |
4374 | /* The index is a signed object `sizetype' bits wide. */ |
4375 | tree index_type = signed_type (sizetype); | |
51e29401 RS |
4376 | |
4377 | declarator = TREE_OPERAND (declarator, 0); | |
4378 | ||
4379 | /* Check for some types that there cannot be arrays of. */ | |
4380 | ||
71653180 | 4381 | if (VOID_TYPE_P (type)) |
51e29401 RS |
4382 | { |
4383 | error ("declaration of `%s' as array of voids", name); | |
4384 | type = error_mark_node; | |
4385 | } | |
4386 | ||
4387 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
4388 | { | |
4389 | error ("declaration of `%s' as array of functions", name); | |
4390 | type = error_mark_node; | |
4391 | } | |
4392 | ||
4393 | if (size == error_mark_node) | |
4394 | type = error_mark_node; | |
4395 | ||
4396 | if (type == error_mark_node) | |
4397 | continue; | |
4398 | ||
4399 | /* If size was specified, set ITYPE to a range-type for that size. | |
4400 | Otherwise, ITYPE remains null. finish_decl may figure it out | |
4401 | from an initial value. */ | |
4402 | ||
4403 | if (size) | |
4404 | { | |
4405 | /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ | |
874a7be1 | 4406 | STRIP_TYPE_NOPS (size); |
51e29401 RS |
4407 | |
4408 | if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE | |
4409 | && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) | |
4410 | { | |
4411 | error ("size of array `%s' has non-integer type", name); | |
4412 | size = integer_one_node; | |
4413 | } | |
0a43d680 | 4414 | |
51e29401 | 4415 | if (pedantic && integer_zerop (size)) |
89abf8d1 | 4416 | pedwarn ("ISO C forbids zero-size array `%s'", name); |
0a43d680 | 4417 | |
51e29401 RS |
4418 | if (TREE_CODE (size) == INTEGER_CST) |
4419 | { | |
90374cc2 | 4420 | constant_expression_warning (size); |
0a43d680 | 4421 | if (tree_int_cst_sgn (size) < 0) |
51e29401 RS |
4422 | { |
4423 | error ("size of array `%s' is negative", name); | |
4424 | size = integer_one_node; | |
4425 | } | |
51e29401 RS |
4426 | } |
4427 | else | |
4428 | { | |
0a43d680 RK |
4429 | /* Make sure the array size remains visibly nonconstant |
4430 | even if it is (eg) a const variable with known value. */ | |
4431 | size_varies = 1; | |
4432 | ||
51e29401 | 4433 | if (pedantic) |
1a6603da RS |
4434 | { |
4435 | if (TREE_CONSTANT (size)) | |
6645c3fa KH |
4436 | pedwarn ("ISO C89 forbids array `%s' whose size can't be evaluated", |
4437 | name); | |
1a6603da | 4438 | else |
6645c3fa KH |
4439 | pedwarn ("ISO C89 forbids variable-size array `%s'", |
4440 | name); | |
1a6603da | 4441 | } |
51e29401 | 4442 | } |
0a43d680 | 4443 | |
967e627a | 4444 | if (integer_zerop (size)) |
e9a25f70 | 4445 | { |
967e627a RH |
4446 | /* A zero-length array cannot be represented with an |
4447 | unsigned index type, which is what we'll get with | |
a25f1211 RH |
4448 | build_index_type. Create an open-ended range instead. */ |
4449 | itype = build_range_type (sizetype, size, NULL_TREE); | |
e9a25f70 | 4450 | } |
967e627a RH |
4451 | else |
4452 | { | |
4453 | /* Compute the maximum valid index, that is, size - 1. | |
4454 | Do the calculation in index_type, so that if it is | |
4455 | a variable the computations will be done in the | |
4456 | proper mode. */ | |
4457 | itype = fold (build (MINUS_EXPR, index_type, | |
4458 | convert (index_type, size), | |
4459 | convert (index_type, size_one_node))); | |
4460 | ||
4461 | /* If that overflowed, the array is too big. | |
4462 | ??? While a size of INT_MAX+1 technically shouldn't | |
4463 | cause an overflow (because we subtract 1), the overflow | |
4464 | is recorded during the conversion to index_type, before | |
4465 | the subtraction. Handling this case seems like an | |
4466 | unnecessary complication. */ | |
4467 | if (TREE_OVERFLOW (itype)) | |
4468 | { | |
4469 | error ("size of array `%s' is too large", name); | |
4470 | type = error_mark_node; | |
4471 | continue; | |
4472 | } | |
e9a25f70 | 4473 | |
967e627a RH |
4474 | if (size_varies) |
4475 | itype = variable_size (itype); | |
4476 | itype = build_index_type (itype); | |
4477 | } | |
51e29401 | 4478 | } |
a25f1211 RH |
4479 | else if (decl_context == FIELD) |
4480 | { | |
4481 | /* ??? Need to check somewhere that this is a structure | |
4482 | and not a union, that this field is last, and that | |
4483 | this structure has at least one other named member. */ | |
4484 | ||
4485 | if (pedantic && !flag_isoc99 && !in_system_header) | |
4486 | pedwarn ("ISO C89 does not support flexible array members"); | |
4487 | ||
4488 | /* ISO C99 Flexible array members are effectively identical | |
4489 | to GCC's zero-length array extension. */ | |
4490 | itype = build_range_type (sizetype, size_zero_node, NULL_TREE); | |
4491 | } | |
51e29401 | 4492 | |
c7b82833 JM |
4493 | /* If pedantic, complain about arrays of incomplete types. */ |
4494 | ||
4495 | if (pedantic && !COMPLETE_TYPE_P (type)) | |
4496 | pedwarn ("array type has incomplete element type"); | |
51e29401 | 4497 | |
6645c3fa KH |
4498 | #if 0 |
4499 | /* We shouldn't have a function type here at all! | |
4500 | Functions aren't allowed as array elements. */ | |
51e29401 RS |
4501 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE |
4502 | && (constp || volatilep)) | |
4503 | pedwarn ("ANSI C forbids const or volatile function types"); | |
4504 | #endif | |
50e65854 JW |
4505 | |
4506 | /* Build the array type itself, then merge any constancy or | |
4507 | volatility into the target type. We must do it in this order | |
4508 | to ensure that the TYPE_MAIN_VARIANT field of the array type | |
4509 | is set correctly. */ | |
4510 | ||
4511 | type = build_array_type (type, itype); | |
3932261a MM |
4512 | if (type_quals) |
4513 | type = c_build_qualified_type (type, type_quals); | |
51e29401 | 4514 | |
6645c3fa KH |
4515 | #if 0 |
4516 | /* Don't clear these; leave them set so that the array type | |
4517 | or the variable is itself const or volatile. */ | |
3932261a | 4518 | type_quals = TYPE_UNQUALIFIED; |
51e29401 RS |
4519 | #endif |
4520 | ||
929f3671 | 4521 | if (size_varies) |
51e29401 RS |
4522 | C_TYPE_VARIABLE_SIZE (type) = 1; |
4523 | } | |
4524 | else if (TREE_CODE (declarator) == CALL_EXPR) | |
4525 | { | |
4526 | tree arg_types; | |
4527 | ||
4528 | /* Declaring a function type. | |
4529 | Make sure we have a valid type for the function to return. */ | |
4530 | if (type == error_mark_node) | |
4531 | continue; | |
4532 | ||
929f3671 | 4533 | size_varies = 0; |
51e29401 RS |
4534 | |
4535 | /* Warn about some types functions can't return. */ | |
4536 | ||
4537 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
4538 | { | |
4539 | error ("`%s' declared as function returning a function", name); | |
4540 | type = integer_type_node; | |
4541 | } | |
4542 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4543 | { | |
4544 | error ("`%s' declared as function returning an array", name); | |
4545 | type = integer_type_node; | |
4546 | } | |
4547 | ||
4548 | #ifndef TRADITIONAL_RETURN_FLOAT | |
4549 | /* Traditionally, declaring return type float means double. */ | |
4550 | ||
90d56da8 | 4551 | if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node) |
51e29401 RS |
4552 | type = double_type_node; |
4553 | #endif /* TRADITIONAL_RETURN_FLOAT */ | |
4554 | ||
4555 | /* Construct the function type and go to the next | |
4556 | inner layer of declarator. */ | |
4557 | ||
4558 | arg_types = grokparms (TREE_OPERAND (declarator, 1), | |
4559 | funcdef_flag | |
4560 | /* Say it's a definition | |
4561 | only for the CALL_EXPR | |
4562 | closest to the identifier. */ | |
4563 | && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE); | |
3932261a MM |
4564 | /* Type qualifiers before the return type of the function |
4565 | qualify the return type, not the function type. */ | |
4566 | if (type_quals) | |
e0c9fbb7 JM |
4567 | { |
4568 | /* Type qualifiers on a function return type are normally | |
4569 | permitted by the standard but have no effect, so give a | |
4570 | warning at -W. Qualifiers on a void return type have | |
4571 | meaning as a GNU extension, and are banned on function | |
4572 | definitions in ISO C. FIXME: strictly we shouldn't | |
4573 | pedwarn for qualified void return types except on function | |
4574 | definitions, but not doing so could lead to the undesirable | |
4575 | state of a "volatile void" function return type not being | |
4576 | warned about, and a use of the function being compiled | |
4577 | with GNU semantics, with no diagnostics under -pedantic. */ | |
4578 | if (VOID_TYPE_P (type) && pedantic && !in_system_header) | |
4579 | pedwarn ("ISO C forbids qualified void function return type"); | |
4580 | else if (extra_warnings | |
4581 | && !(VOID_TYPE_P (type) | |
4582 | && type_quals == TYPE_QUAL_VOLATILE)) | |
4583 | warning ("type qualifiers ignored on function return type"); | |
4584 | ||
4585 | type = c_build_qualified_type (type, type_quals); | |
4586 | } | |
3932261a | 4587 | type_quals = TYPE_UNQUALIFIED; |
61df2ee2 | 4588 | |
51e29401 RS |
4589 | type = build_function_type (type, arg_types); |
4590 | declarator = TREE_OPERAND (declarator, 0); | |
4591 | ||
4592 | /* Set the TYPE_CONTEXTs for each tagged type which is local to | |
4593 | the formal parameter list of this FUNCTION_TYPE to point to | |
4594 | the FUNCTION_TYPE node itself. */ | |
4595 | ||
4596 | { | |
4597 | register tree link; | |
4598 | ||
2a851b5c | 4599 | for (link = last_function_parm_tags; |
51e29401 RS |
4600 | link; |
4601 | link = TREE_CHAIN (link)) | |
4602 | TYPE_CONTEXT (TREE_VALUE (link)) = type; | |
4603 | } | |
4604 | } | |
4605 | else if (TREE_CODE (declarator) == INDIRECT_REF) | |
4606 | { | |
4607 | /* Merge any constancy or volatility into the target type | |
4608 | for the pointer. */ | |
4609 | ||
4610 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
3932261a | 4611 | && type_quals) |
89abf8d1 | 4612 | pedwarn ("ISO C forbids qualified function types"); |
3932261a MM |
4613 | if (type_quals) |
4614 | type = c_build_qualified_type (type, type_quals); | |
4615 | type_quals = TYPE_UNQUALIFIED; | |
929f3671 | 4616 | size_varies = 0; |
51e29401 RS |
4617 | |
4618 | type = build_pointer_type (type); | |
4619 | ||
4620 | /* Process a list of type modifier keywords | |
4621 | (such as const or volatile) that were given inside the `*'. */ | |
4622 | ||
4623 | if (TREE_TYPE (declarator)) | |
4624 | { | |
4625 | register tree typemodlist; | |
4626 | int erred = 0; | |
3932261a MM |
4627 | |
4628 | constp = 0; | |
4629 | volatilep = 0; | |
4630 | restrictp = 0; | |
51e29401 RS |
4631 | for (typemodlist = TREE_TYPE (declarator); typemodlist; |
4632 | typemodlist = TREE_CHAIN (typemodlist)) | |
4633 | { | |
3932261a MM |
4634 | tree qualifier = TREE_VALUE (typemodlist); |
4635 | ||
0e5921e8 | 4636 | if (C_IS_RESERVED_WORD (qualifier)) |
51e29401 | 4637 | { |
0e5921e8 ZW |
4638 | if (C_RID_CODE (qualifier) == RID_CONST) |
4639 | constp++; | |
4640 | else if (C_RID_CODE (qualifier) == RID_VOLATILE) | |
4641 | volatilep++; | |
4642 | else if (C_RID_CODE (qualifier) == RID_RESTRICT) | |
4643 | restrictp++; | |
4644 | else | |
4645 | erred++; | |
51e29401 | 4646 | } |
0e5921e8 ZW |
4647 | else |
4648 | erred++; | |
51e29401 | 4649 | } |
0e5921e8 ZW |
4650 | |
4651 | if (erred) | |
4652 | error ("invalid type modifier within pointer declarator"); | |
903f51d9 | 4653 | if (constp > 1 && ! flag_isoc99) |
47429a02 | 4654 | pedwarn ("duplicate `const'"); |
903f51d9 | 4655 | if (volatilep > 1 && ! flag_isoc99) |
47429a02 | 4656 | pedwarn ("duplicate `volatile'"); |
903f51d9 | 4657 | if (restrictp > 1 && ! flag_isoc99) |
3932261a MM |
4658 | pedwarn ("duplicate `restrict'"); |
4659 | ||
4660 | type_quals = ((constp ? TYPE_QUAL_CONST : 0) | |
4661 | | (restrictp ? TYPE_QUAL_RESTRICT : 0) | |
4662 | | (volatilep ? TYPE_QUAL_VOLATILE : 0)); | |
51e29401 RS |
4663 | } |
4664 | ||
4665 | declarator = TREE_OPERAND (declarator, 0); | |
4666 | } | |
4667 | else | |
4668 | abort (); | |
4669 | ||
4670 | } | |
4671 | ||
4672 | /* Now TYPE has the actual type. */ | |
4673 | ||
e9a25f70 JL |
4674 | /* Did array size calculations overflow? */ |
4675 | ||
4676 | if (TREE_CODE (type) == ARRAY_TYPE | |
d0f062fb | 4677 | && COMPLETE_TYPE_P (type) |
e9a25f70 JL |
4678 | && TREE_OVERFLOW (TYPE_SIZE (type))) |
4679 | error ("size of array `%s' is too large", name); | |
4680 | ||
51e29401 RS |
4681 | /* If this is declaring a typedef name, return a TYPE_DECL. */ |
4682 | ||
4683 | if (specbits & (1 << (int) RID_TYPEDEF)) | |
4684 | { | |
4685 | tree decl; | |
4686 | /* Note that the grammar rejects storage classes | |
4687 | in typenames, fields or parameters */ | |
4688 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
3932261a | 4689 | && type_quals) |
89abf8d1 | 4690 | pedwarn ("ISO C forbids qualified function types"); |
3932261a MM |
4691 | if (type_quals) |
4692 | type = c_build_qualified_type (type, type_quals); | |
51e29401 RS |
4693 | decl = build_decl (TYPE_DECL, declarator, type); |
4694 | if ((specbits & (1 << (int) RID_SIGNED)) | |
4695 | || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
4696 | C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | |
4697 | return decl; | |
4698 | } | |
4699 | ||
4700 | /* Detect the case of an array type of unspecified size | |
4701 | which came, as such, direct from a typedef name. | |
4702 | We must copy the type, so that each identifier gets | |
4703 | a distinct type, so that each identifier's size can be | |
4704 | controlled separately by its own initializer. */ | |
4705 | ||
4706 | if (type != 0 && typedef_type != 0 | |
a52fb89b RK |
4707 | && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0 |
4708 | && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)) | |
51e29401 RS |
4709 | { |
4710 | type = build_array_type (TREE_TYPE (type), 0); | |
929f3671 | 4711 | if (size_varies) |
51e29401 RS |
4712 | C_TYPE_VARIABLE_SIZE (type) = 1; |
4713 | } | |
4714 | ||
4715 | /* If this is a type name (such as, in a cast or sizeof), | |
4716 | compute the type and return it now. */ | |
4717 | ||
4718 | if (decl_context == TYPENAME) | |
4719 | { | |
4720 | /* Note that the grammar rejects storage classes | |
4721 | in typenames, fields or parameters */ | |
4722 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
3932261a | 4723 | && type_quals) |
89abf8d1 | 4724 | pedwarn ("ISO C forbids const or volatile function types"); |
3932261a MM |
4725 | if (type_quals) |
4726 | type = c_build_qualified_type (type, type_quals); | |
51e29401 RS |
4727 | return type; |
4728 | } | |
4729 | ||
61df2ee2 RS |
4730 | /* Aside from typedefs and type names (handle above), |
4731 | `void' at top level (not within pointer) | |
4732 | is allowed only in public variables. | |
51e29401 RS |
4733 | We don't complain about parms either, but that is because |
4734 | a better error message can be made later. */ | |
4735 | ||
71653180 | 4736 | if (VOID_TYPE_P (type) && decl_context != PARM |
61df2ee2 RS |
4737 | && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE) |
4738 | && ((specbits & (1 << (int) RID_EXTERN)) | |
4739 | || (current_binding_level == global_binding_level | |
4740 | && !(specbits | |
4741 | & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))))))) | |
51e29401 | 4742 | { |
c40f7b33 | 4743 | error ("variable or field `%s' declared void", name); |
51e29401 RS |
4744 | type = integer_type_node; |
4745 | } | |
4746 | ||
4747 | /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | |
4748 | or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | |
4749 | ||
4750 | { | |
4751 | register tree decl; | |
4752 | ||
4753 | if (decl_context == PARM) | |
4754 | { | |
4755 | tree type_as_written = type; | |
c530479e | 4756 | tree promoted_type; |
51e29401 RS |
4757 | |
4758 | /* A parameter declared as an array of T is really a pointer to T. | |
4759 | One declared as a function is really a pointer to a function. */ | |
4760 | ||
4761 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4762 | { | |
4763 | /* Transfer const-ness of array into that of type pointed to. */ | |
eaf2e788 | 4764 | type = TREE_TYPE (type); |
3932261a MM |
4765 | if (type_quals) |
4766 | type = c_build_qualified_type (type, type_quals); | |
eaf2e788 | 4767 | type = build_pointer_type (type); |
3932261a | 4768 | type_quals = TYPE_UNQUALIFIED; |
929f3671 | 4769 | size_varies = 0; |
51e29401 RS |
4770 | } |
4771 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
4772 | { | |
3932261a | 4773 | if (pedantic && type_quals) |
89abf8d1 | 4774 | pedwarn ("ISO C forbids qualified function types"); |
3932261a MM |
4775 | if (type_quals) |
4776 | type = c_build_qualified_type (type, type_quals); | |
eaf2e788 | 4777 | type = build_pointer_type (type); |
3932261a | 4778 | type_quals = TYPE_UNQUALIFIED; |
51e29401 RS |
4779 | } |
4780 | ||
51e29401 | 4781 | decl = build_decl (PARM_DECL, declarator, type); |
929f3671 | 4782 | if (size_varies) |
51e29401 RS |
4783 | C_DECL_VARIABLE_SIZE (decl) = 1; |
4784 | ||
4785 | /* Compute the type actually passed in the parmlist, | |
4786 | for the case where there is no prototype. | |
4787 | (For example, shorts and chars are passed as ints.) | |
4788 | When there is a prototype, this is overridden later. */ | |
4789 | ||
c530479e RH |
4790 | if (type == error_mark_node) |
4791 | promoted_type = type; | |
4792 | else | |
8eebb258 | 4793 | { |
c530479e RH |
4794 | promoted_type = simple_type_promotes_to (type); |
4795 | if (! promoted_type) | |
4796 | promoted_type = type; | |
8eebb258 | 4797 | } |
51e29401 | 4798 | |
c530479e | 4799 | DECL_ARG_TYPE (decl) = promoted_type; |
51e29401 RS |
4800 | DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written; |
4801 | } | |
4802 | else if (decl_context == FIELD) | |
4803 | { | |
4804 | /* Structure field. It may not be a function. */ | |
4805 | ||
4806 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
4807 | { | |
c40f7b33 | 4808 | error ("field `%s' declared as a function", name); |
51e29401 RS |
4809 | type = build_pointer_type (type); |
4810 | } | |
d0f062fb NS |
4811 | else if (TREE_CODE (type) != ERROR_MARK |
4812 | && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) | |
51e29401 | 4813 | { |
c40f7b33 | 4814 | error ("field `%s' has incomplete type", name); |
51e29401 RS |
4815 | type = error_mark_node; |
4816 | } | |
4817 | /* Move type qualifiers down to element of an array. */ | |
3932261a | 4818 | if (TREE_CODE (type) == ARRAY_TYPE && type_quals) |
51e29401 | 4819 | { |
3932261a MM |
4820 | type = build_array_type (c_build_qualified_type (TREE_TYPE (type), |
4821 | type_quals), | |
51e29401 | 4822 | TYPE_DOMAIN (type)); |
6645c3fa KH |
4823 | #if 0 |
4824 | /* Leave the field const or volatile as well. */ | |
3932261a | 4825 | type_quals = TYPE_UNQUALIFIED; |
51e29401 RS |
4826 | #endif |
4827 | } | |
4828 | decl = build_decl (FIELD_DECL, declarator, type); | |
2bf105ab RK |
4829 | DECL_NONADDRESSABLE_P (decl) = bitfield; |
4830 | ||
929f3671 | 4831 | if (size_varies) |
51e29401 RS |
4832 | C_DECL_VARIABLE_SIZE (decl) = 1; |
4833 | } | |
4834 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
4835 | { | |
fd0b8fce JW |
4836 | /* Every function declaration is "external" |
4837 | except for those which are inside a function body | |
4838 | in which `auto' is used. | |
4839 | That is a case not specified by ANSI C, | |
4840 | and we use it for forward declarations for nested functions. */ | |
4841 | int extern_ref = (!(specbits & (1 << (int) RID_AUTO)) | |
4842 | || current_binding_level == global_binding_level); | |
4843 | ||
51e29401 RS |
4844 | if (specbits & (1 << (int) RID_AUTO) |
4845 | && (pedantic || current_binding_level == global_binding_level)) | |
c40f7b33 | 4846 | pedwarn ("invalid storage class for function `%s'", name); |
51e29401 | 4847 | if (specbits & (1 << (int) RID_REGISTER)) |
c40f7b33 | 4848 | error ("invalid storage class for function `%s'", name); |
51e29401 RS |
4849 | /* Function declaration not at top level. |
4850 | Storage classes other than `extern' are not allowed | |
4851 | and `extern' makes no difference. */ | |
4852 | if (current_binding_level != global_binding_level | |
4853 | && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE))) | |
4854 | && pedantic) | |
c40f7b33 | 4855 | pedwarn ("invalid storage class for function `%s'", name); |
fd0b8fce | 4856 | |
51e29401 | 4857 | decl = build_decl (FUNCTION_DECL, declarator, type); |
4b4e3407 | 4858 | decl = build_decl_attribute_variant (decl, decl_machine_attr); |
51e29401 | 4859 | |
3932261a | 4860 | if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl)) |
89abf8d1 | 4861 | pedwarn ("ISO C forbids qualified function types"); |
51e29401 | 4862 | |
3932261a MM |
4863 | /* GNU C interprets a `volatile void' return type to indicate |
4864 | that the function does not return. */ | |
4865 | if ((type_quals & TYPE_QUAL_VOLATILE) | |
71653180 | 4866 | && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) |
11433f42 | 4867 | warning ("`noreturn' function returns non-void value"); |
61df2ee2 | 4868 | |
fd0b8fce | 4869 | if (extern_ref) |
1394aabd | 4870 | DECL_EXTERNAL (decl) = 1; |
51e29401 RS |
4871 | /* Record absence of global scope for `static' or `auto'. */ |
4872 | TREE_PUBLIC (decl) | |
4873 | = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO))); | |
c40f7b33 | 4874 | |
51e29401 RS |
4875 | /* Record presence of `inline', if it is reasonable. */ |
4876 | if (inlinep) | |
4877 | { | |
5b47282c | 4878 | if (MAIN_NAME_P (declarator)) |
51e29401 | 4879 | warning ("cannot inline function `main'"); |
51e29401 RS |
4880 | else |
4881 | /* Assume that otherwise the function can be inlined. */ | |
1394aabd | 4882 | DECL_INLINE (decl) = 1; |
51e29401 RS |
4883 | |
4884 | if (specbits & (1 << (int) RID_EXTERN)) | |
4885 | current_extern_inline = 1; | |
4886 | } | |
4887 | } | |
4888 | else | |
4889 | { | |
4890 | /* It's a variable. */ | |
fd0b8fce JW |
4891 | /* An uninitialized decl with `extern' is a reference. */ |
4892 | int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN)); | |
51e29401 RS |
4893 | |
4894 | /* Move type qualifiers down to element of an array. */ | |
3932261a | 4895 | if (TREE_CODE (type) == ARRAY_TYPE && type_quals) |
51e29401 | 4896 | { |
3932261a MM |
4897 | type = build_array_type (c_build_qualified_type (TREE_TYPE (type), |
4898 | type_quals), | |
51e29401 RS |
4899 | TYPE_DOMAIN (type)); |
4900 | #if 0 /* Leave the variable const or volatile as well. */ | |
3932261a | 4901 | type_quals = TYPE_UNQUALIFIED; |
51e29401 RS |
4902 | #endif |
4903 | } | |
4904 | ||
4905 | decl = build_decl (VAR_DECL, declarator, type); | |
929f3671 | 4906 | if (size_varies) |
51e29401 RS |
4907 | C_DECL_VARIABLE_SIZE (decl) = 1; |
4908 | ||
4909 | if (inlinep) | |
4910 | pedwarn_with_decl (decl, "variable `%s' declared `inline'"); | |
4911 | ||
fd0b8fce | 4912 | DECL_EXTERNAL (decl) = extern_ref; |
ee534ebf RS |
4913 | /* At top level, the presence of a `static' or `register' storage |
4914 | class specifier, or the absence of all storage class specifiers | |
4915 | makes this declaration a definition (perhaps tentative). Also, | |
4916 | the absence of both `static' and `register' makes it public. */ | |
51e29401 RS |
4917 | if (current_binding_level == global_binding_level) |
4918 | { | |
ee534ebf RS |
4919 | TREE_PUBLIC (decl) |
4920 | = !(specbits | |
4921 | & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))); | |
1394aabd | 4922 | TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); |
51e29401 RS |
4923 | } |
4924 | /* Not at top level, only `static' makes a static definition. */ | |
4925 | else | |
4926 | { | |
4927 | TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0; | |
1394aabd | 4928 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); |
51e29401 RS |
4929 | } |
4930 | } | |
4931 | ||
4932 | /* Record `register' declaration for warnings on & | |
4933 | and in case doing stupid register allocation. */ | |
4934 | ||
4935 | if (specbits & (1 << (int) RID_REGISTER)) | |
1394aabd | 4936 | DECL_REGISTER (decl) = 1; |
51e29401 RS |
4937 | |
4938 | /* Record constancy and volatility. */ | |
3932261a | 4939 | c_apply_type_quals_to_decl (type_quals, decl); |
51e29401 | 4940 | |
51e29401 RS |
4941 | /* If a type has volatile components, it should be stored in memory. |
4942 | Otherwise, the fact that those components are volatile | |
4943 | will be ignored, and would even crash the compiler. */ | |
4944 | if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))) | |
4945 | mark_addressable (decl); | |
4946 | ||
51e29401 RS |
4947 | return decl; |
4948 | } | |
4949 | } | |
4950 | \f | |
51e29401 RS |
4951 | /* Decode the parameter-list info for a function type or function definition. |
4952 | The argument is the value returned by `get_parm_info' (or made in parse.y | |
4953 | if there is an identifier list instead of a parameter decl list). | |
4954 | These two functions are separate because when a function returns | |
4955 | or receives functions then each is called multiple times but the order | |
4956 | of calls is different. The last call to `grokparms' is always the one | |
4957 | that contains the formal parameter names of a function definition. | |
4958 | ||
4959 | Store in `last_function_parms' a chain of the decls of parms. | |
4960 | Also store in `last_function_parm_tags' a chain of the struct, union, | |
4961 | and enum tags declared among the parms. | |
4962 | ||
4963 | Return a list of arg types to use in the FUNCTION_TYPE for this function. | |
4964 | ||
4965 | FUNCDEF_FLAG is nonzero for a function definition, 0 for | |
4966 | a mere declaration. A nonempty identifier-list gets an error message | |
4967 | when FUNCDEF_FLAG is zero. */ | |
4968 | ||
4969 | static tree | |
4970 | grokparms (parms_info, funcdef_flag) | |
4971 | tree parms_info; | |
4972 | int funcdef_flag; | |
4973 | { | |
4974 | tree first_parm = TREE_CHAIN (parms_info); | |
4975 | ||
4976 | last_function_parms = TREE_PURPOSE (parms_info); | |
4977 | last_function_parm_tags = TREE_VALUE (parms_info); | |
4978 | ||
27f427f8 RS |
4979 | if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag |
4980 | && !in_system_header) | |
51e29401 RS |
4981 | warning ("function declaration isn't a prototype"); |
4982 | ||
4983 | if (first_parm != 0 | |
4984 | && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) | |
4985 | { | |
4986 | if (! funcdef_flag) | |
4987 | pedwarn ("parameter names (without types) in function declaration"); | |
4988 | ||
4989 | last_function_parms = first_parm; | |
4990 | return 0; | |
4991 | } | |
4992 | else | |
4993 | { | |
4994 | tree parm; | |
4995 | tree typelt; | |
4996 | /* We no longer test FUNCDEF_FLAG. | |
4997 | If the arg types are incomplete in a declaration, | |
4998 | they must include undefined tags. | |
4999 | These tags can never be defined in the scope of the declaration, | |
5000 | so the types can never be completed, | |
5001 | and no call can be compiled successfully. */ | |
5002 | #if 0 | |
5003 | /* In a fcn definition, arg types must be complete. */ | |
5004 | if (funcdef_flag) | |
5005 | #endif | |
5006 | for (parm = last_function_parms, typelt = first_parm; | |
5007 | parm; | |
5008 | parm = TREE_CHAIN (parm)) | |
5009 | /* Skip over any enumeration constants declared here. */ | |
5010 | if (TREE_CODE (parm) == PARM_DECL) | |
5011 | { | |
5012 | /* Barf if the parameter itself has an incomplete type. */ | |
5013 | tree type = TREE_VALUE (typelt); | |
c7b82833 JM |
5014 | if (type == error_mark_node) |
5015 | continue; | |
d0f062fb | 5016 | if (!COMPLETE_TYPE_P (type)) |
51e29401 RS |
5017 | { |
5018 | if (funcdef_flag && DECL_NAME (parm) != 0) | |
5019 | error ("parameter `%s' has incomplete type", | |
5020 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
5021 | else | |
5022 | warning ("parameter has incomplete type"); | |
5023 | if (funcdef_flag) | |
5024 | { | |
5025 | TREE_VALUE (typelt) = error_mark_node; | |
5026 | TREE_TYPE (parm) = error_mark_node; | |
5027 | } | |
5028 | } | |
6645c3fa KH |
5029 | #if 0 |
5030 | /* This has been replaced by parm_tags_warning, which | |
5031 | uses a more accurate criterion for what to warn | |
5032 | about. */ | |
51e29401 RS |
5033 | else |
5034 | { | |
5035 | /* Now warn if is a pointer to an incomplete type. */ | |
5036 | while (TREE_CODE (type) == POINTER_TYPE | |
5037 | || TREE_CODE (type) == REFERENCE_TYPE) | |
5038 | type = TREE_TYPE (type); | |
5039 | type = TYPE_MAIN_VARIANT (type); | |
d0f062fb | 5040 | if (!COMPLETE_TYPE_P (type)) |
51e29401 RS |
5041 | { |
5042 | if (DECL_NAME (parm) != 0) | |
5043 | warning ("parameter `%s' points to incomplete type", | |
5044 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
5045 | else | |
5046 | warning ("parameter points to incomplete type"); | |
5047 | } | |
5048 | } | |
5049 | #endif | |
5050 | typelt = TREE_CHAIN (typelt); | |
5051 | } | |
5052 | ||
6645c3fa | 5053 | return first_parm; |
51e29401 RS |
5054 | } |
5055 | } | |
5056 | ||
51e29401 RS |
5057 | /* Return a tree_list node with info on a parameter list just parsed. |
5058 | The TREE_PURPOSE is a chain of decls of those parms. | |
5059 | The TREE_VALUE is a list of structure, union and enum tags defined. | |
5060 | The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE. | |
5061 | This tree_list node is later fed to `grokparms'. | |
5062 | ||
5063 | VOID_AT_END nonzero means append `void' to the end of the type-list. | |
5064 | Zero means the parmlist ended with an ellipsis so don't append `void'. */ | |
5065 | ||
5066 | tree | |
5067 | get_parm_info (void_at_end) | |
5068 | int void_at_end; | |
5069 | { | |
5070 | register tree decl, t; | |
5071 | register tree types = 0; | |
5072 | int erred = 0; | |
5073 | tree tags = gettags (); | |
5074 | tree parms = getdecls (); | |
5075 | tree new_parms = 0; | |
5076 | tree order = current_binding_level->parm_order; | |
5077 | ||
bbe65572 JM |
5078 | /* Just `void' (and no ellipsis) is special. There are really no parms. |
5079 | But if the `void' is qualified (by `const' or `volatile') or has a | |
5080 | storage class specifier (`register'), then the behavior is undefined; | |
5081 | by not counting it as the special case of `void' we will cause an | |
6645c3fa | 5082 | error later. Typedefs for `void' are OK (see DR#157). */ |
51e29401 RS |
5083 | if (void_at_end && parms != 0 |
5084 | && TREE_CHAIN (parms) == 0 | |
71653180 | 5085 | && VOID_TYPE_P (TREE_TYPE (parms)) |
bbe65572 JM |
5086 | && ! TREE_THIS_VOLATILE (parms) |
5087 | && ! TREE_READONLY (parms) | |
5088 | && ! DECL_REGISTER (parms) | |
51e29401 RS |
5089 | && DECL_NAME (parms) == 0) |
5090 | { | |
5091 | parms = NULL_TREE; | |
5092 | storedecls (NULL_TREE); | |
4dd7201e ZW |
5093 | return tree_cons (NULL_TREE, NULL_TREE, |
5094 | tree_cons (NULL_TREE, void_type_node, NULL_TREE)); | |
51e29401 RS |
5095 | } |
5096 | ||
fc3ffe83 RK |
5097 | /* Extract enumerator values and other non-parms declared with the parms. |
5098 | Likewise any forward parm decls that didn't have real parm decls. */ | |
6645c3fa | 5099 | for (decl = parms; decl;) |
51e29401 RS |
5100 | { |
5101 | tree next = TREE_CHAIN (decl); | |
5102 | ||
e38e5ba8 | 5103 | if (TREE_CODE (decl) != PARM_DECL) |
fc3ffe83 | 5104 | { |
fc3ffe83 RK |
5105 | TREE_CHAIN (decl) = new_parms; |
5106 | new_parms = decl; | |
5107 | } | |
e38e5ba8 | 5108 | else if (TREE_ASM_WRITTEN (decl)) |
51e29401 | 5109 | { |
6645c3fa KH |
5110 | error_with_decl (decl, |
5111 | "parameter `%s' has just a forward declaration"); | |
51e29401 RS |
5112 | TREE_CHAIN (decl) = new_parms; |
5113 | new_parms = decl; | |
5114 | } | |
5115 | decl = next; | |
5116 | } | |
5117 | ||
5118 | /* Put the parm decls back in the order they were in in the parm list. */ | |
5119 | for (t = order; t; t = TREE_CHAIN (t)) | |
5120 | { | |
5121 | if (TREE_CHAIN (t)) | |
5122 | TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t)); | |
5123 | else | |
5124 | TREE_CHAIN (TREE_VALUE (t)) = 0; | |
5125 | } | |
5126 | ||
5127 | new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0, | |
5128 | new_parms); | |
5129 | ||
5130 | /* Store the parmlist in the binding level since the old one | |
5131 | is no longer a valid list. (We have changed the chain pointers.) */ | |
5132 | storedecls (new_parms); | |
5133 | ||
5134 | for (decl = new_parms; decl; decl = TREE_CHAIN (decl)) | |
5135 | /* There may also be declarations for enumerators if an enumeration | |
5136 | type is declared among the parms. Ignore them here. */ | |
5137 | if (TREE_CODE (decl) == PARM_DECL) | |
5138 | { | |
5139 | /* Since there is a prototype, | |
5140 | args are passed in their declared types. */ | |
5141 | tree type = TREE_TYPE (decl); | |
5142 | DECL_ARG_TYPE (decl) = type; | |
7d473569 JJ |
5143 | if (PROMOTE_PROTOTYPES |
5144 | && (TREE_CODE (type) == INTEGER_TYPE | |
5145 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
51e29401 RS |
5146 | && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) |
5147 | DECL_ARG_TYPE (decl) = integer_type_node; | |
51e29401 | 5148 | |
4dd7201e | 5149 | types = tree_cons (NULL_TREE, TREE_TYPE (decl), types); |
71653180 | 5150 | if (VOID_TYPE_P (TREE_VALUE (types)) && ! erred |
51e29401 RS |
5151 | && DECL_NAME (decl) == 0) |
5152 | { | |
5153 | error ("`void' in parameter list must be the entire list"); | |
5154 | erred = 1; | |
5155 | } | |
5156 | } | |
5157 | ||
5158 | if (void_at_end) | |
4dd7201e ZW |
5159 | return tree_cons (new_parms, tags, |
5160 | nreverse (tree_cons (NULL_TREE, void_type_node, types))); | |
51e29401 | 5161 | |
4dd7201e | 5162 | return tree_cons (new_parms, tags, nreverse (types)); |
51e29401 RS |
5163 | } |
5164 | ||
5165 | /* At end of parameter list, warn about any struct, union or enum tags | |
5166 | defined within. Do so because these types cannot ever become complete. */ | |
5167 | ||
5168 | void | |
5169 | parmlist_tags_warning () | |
5170 | { | |
5171 | tree elt; | |
5172 | static int already; | |
5173 | ||
5174 | for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt)) | |
5175 | { | |
5176 | enum tree_code code = TREE_CODE (TREE_VALUE (elt)); | |
27301b30 RS |
5177 | /* An anonymous union parm type is meaningful as a GNU extension. |
5178 | So don't warn for that. */ | |
293facbc | 5179 | if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic) |
27301b30 | 5180 | continue; |
c138f328 RS |
5181 | if (TREE_PURPOSE (elt) != 0) |
5182 | warning ("`%s %s' declared inside parameter list", | |
5183 | (code == RECORD_TYPE ? "struct" | |
5184 | : code == UNION_TYPE ? "union" | |
5185 | : "enum"), | |
5186 | IDENTIFIER_POINTER (TREE_PURPOSE (elt))); | |
5187 | else | |
6645c3fa KH |
5188 | { |
5189 | /* For translation these need to be seperate warnings */ | |
5190 | if (code == RECORD_TYPE) | |
5e4adfba PT |
5191 | warning ("anonymous struct declared inside parameter list"); |
5192 | else if (code == UNION_TYPE) | |
5193 | warning ("anonymous union declared inside parameter list"); | |
6645c3fa | 5194 | else |
5e4adfba PT |
5195 | warning ("anonymous enum declared inside parameter list"); |
5196 | } | |
51e29401 RS |
5197 | if (! already) |
5198 | { | |
ab87f8c8 | 5199 | warning ("its scope is only this definition or declaration, which is probably not what you want."); |
51e29401 RS |
5200 | already = 1; |
5201 | } | |
5202 | } | |
5203 | } | |
5204 | \f | |
5205 | /* Get the struct, enum or union (CODE says which) with tag NAME. | |
5206 | Define the tag as a forward-reference if it is not defined. */ | |
5207 | ||
5208 | tree | |
5209 | xref_tag (code, name) | |
5210 | enum tree_code code; | |
5211 | tree name; | |
5212 | { | |
51e29401 RS |
5213 | /* If a cross reference is requested, look up the type |
5214 | already defined for this tag and return it. */ | |
5215 | ||
5216 | register tree ref = lookup_tag (code, name, current_binding_level, 0); | |
5217 | /* Even if this is the wrong type of tag, return what we found. | |
5218 | There will be an error message anyway, from pending_xref_error. | |
5219 | If we create an empty xref just for an invalid use of the type, | |
929f3671 | 5220 | the main result is to create lots of superfluous error messages. */ |
51e29401 RS |
5221 | if (ref) |
5222 | return ref; | |
5223 | ||
51e29401 RS |
5224 | /* If no such tag is yet defined, create a forward-reference node |
5225 | and record it as the "definition". | |
5226 | When a real declaration of this type is found, | |
5227 | the forward-reference will be altered into a real type. */ | |
5228 | ||
5229 | ref = make_node (code); | |
5230 | if (code == ENUMERAL_TYPE) | |
5231 | { | |
5232 | /* (In ANSI, Enums can be referred to only if already defined.) */ | |
5233 | if (pedantic) | |
89abf8d1 | 5234 | pedwarn ("ISO C forbids forward references to `enum' types"); |
51e29401 RS |
5235 | /* Give the type a default layout like unsigned int |
5236 | to avoid crashing if it does not get defined. */ | |
5237 | TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); | |
5238 | TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); | |
11cf4d18 | 5239 | TYPE_USER_ALIGN (ref) = 0; |
51e29401 RS |
5240 | TREE_UNSIGNED (ref) = 1; |
5241 | TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | |
5242 | TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | |
5243 | TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | |
5244 | } | |
5245 | ||
5246 | pushtag (name, ref); | |
5247 | ||
51e29401 RS |
5248 | return ref; |
5249 | } | |
5250 | \f | |
5251 | /* Make sure that the tag NAME is defined *in the current binding level* | |
5252 | at least as a forward reference. | |
4dd7201e | 5253 | CODE says which kind of tag NAME ought to be. */ |
51e29401 RS |
5254 | |
5255 | tree | |
5256 | start_struct (code, name) | |
5257 | enum tree_code code; | |
5258 | tree name; | |
5259 | { | |
5260 | /* If there is already a tag defined at this binding level | |
5261 | (as a forward reference), just return it. */ | |
5262 | ||
5263 | register tree ref = 0; | |
5264 | ||
5265 | if (name != 0) | |
5266 | ref = lookup_tag (code, name, current_binding_level, 1); | |
5267 | if (ref && TREE_CODE (ref) == code) | |
5268 | { | |
5269 | C_TYPE_BEING_DEFINED (ref) = 1; | |
5c19a356 | 5270 | TYPE_PACKED (ref) = flag_pack_struct; |
51e29401 | 5271 | if (TYPE_FIELDS (ref)) |
913d0833 KG |
5272 | error ("redefinition of `%s %s'", |
5273 | code == UNION_TYPE ? "union" : "struct", | |
51e29401 RS |
5274 | IDENTIFIER_POINTER (name)); |
5275 | ||
5276 | return ref; | |
5277 | } | |
5278 | ||
5279 | /* Otherwise create a forward-reference just so the tag is in scope. */ | |
5280 | ||
5281 | ref = make_node (code); | |
5282 | pushtag (name, ref); | |
5283 | C_TYPE_BEING_DEFINED (ref) = 1; | |
02eb6e90 | 5284 | TYPE_PACKED (ref) = flag_pack_struct; |
51e29401 RS |
5285 | return ref; |
5286 | } | |
5287 | ||
5288 | /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) | |
5289 | of a structure component, returning a FIELD_DECL node. | |
5290 | WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. | |
5291 | ||
5292 | This is done during the parsing of the struct declaration. | |
5293 | The FIELD_DECL nodes are chained together and the lot of them | |
5294 | are ultimately passed to `build_struct' to make the RECORD_TYPE node. */ | |
5295 | ||
5296 | tree | |
5297 | grokfield (filename, line, declarator, declspecs, width) | |
5d5993dd KG |
5298 | const char *filename ATTRIBUTE_UNUSED; |
5299 | int line ATTRIBUTE_UNUSED; | |
51e29401 RS |
5300 | tree declarator, declspecs, width; |
5301 | { | |
5302 | tree value; | |
5303 | ||
51e29401 RS |
5304 | value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0); |
5305 | ||
8d9bfdc5 | 5306 | finish_decl (value, NULL_TREE, NULL_TREE); |
51e29401 RS |
5307 | DECL_INITIAL (value) = width; |
5308 | ||
abe31bf8 | 5309 | maybe_objc_check_decl (value); |
51e29401 RS |
5310 | return value; |
5311 | } | |
5312 | \f | |
51e29401 | 5313 | /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. |
7a0347ff | 5314 | FIELDLIST is a chain of FIELD_DECL nodes for the fields. |
4dd7201e | 5315 | ATTRIBUTES are attributes to be applied to the structure. */ |
51e29401 RS |
5316 | |
5317 | tree | |
10861e9a RK |
5318 | finish_struct (t, fieldlist, attributes) |
5319 | tree t; | |
5320 | tree fieldlist; | |
5321 | tree attributes; | |
51e29401 RS |
5322 | { |
5323 | register tree x; | |
51e29401 RS |
5324 | int toplevel = global_binding_level == current_binding_level; |
5325 | ||
5326 | /* If this type was previously laid out as a forward reference, | |
5327 | make sure we lay it out again. */ | |
5328 | ||
5329 | TYPE_SIZE (t) = 0; | |
5330 | ||
10861e9a RK |
5331 | decl_attributes (t, attributes, NULL_TREE); |
5332 | ||
51e29401 RS |
5333 | /* Nameless union parm types are useful as GCC extension. */ |
5334 | if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic) | |
5335 | /* Otherwise, warn about any struct or union def. in parmlist. */ | |
5336 | if (in_parm_level_p ()) | |
5337 | { | |
5338 | if (pedantic) | |
913d0833 | 5339 | pedwarn ("%s defined inside parms", |
5e4adfba | 5340 | TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure")); |
f3c2c111 | 5341 | else if (! flag_traditional) |
913d0833 | 5342 | warning ("%s defined inside parms", |
5e4adfba | 5343 | TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure")); |
51e29401 RS |
5344 | } |
5345 | ||
9590fa72 RK |
5346 | if (pedantic) |
5347 | { | |
5348 | for (x = fieldlist; x; x = TREE_CHAIN (x)) | |
5349 | if (DECL_NAME (x) != 0) | |
5350 | break; | |
5351 | ||
5352 | if (x == 0) | |
5e4adfba PT |
5353 | pedwarn ("%s has no %s", |
5354 | TREE_CODE (t) == UNION_TYPE ? _("union") : _("struct"), | |
5355 | fieldlist ? _("named members") : _("members")); | |
9590fa72 | 5356 | } |
51e29401 RS |
5357 | |
5358 | /* Install struct as DECL_CONTEXT of each field decl. | |
9df2c88c | 5359 | Also process specified field sizes,m which is found in the DECL_INITIAL. |
51e29401 RS |
5360 | Store 0 there, except for ": 0" fields (so we can find them |
5361 | and delete them, below). */ | |
5362 | ||
5363 | for (x = fieldlist; x; x = TREE_CHAIN (x)) | |
5364 | { | |
5365 | DECL_CONTEXT (x) = t; | |
5be1df77 | 5366 | DECL_PACKED (x) |= TYPE_PACKED (t); |
51e29401 RS |
5367 | |
5368 | /* If any field is const, the structure type is pseudo-const. */ | |
5369 | if (TREE_READONLY (x)) | |
5370 | C_TYPE_FIELDS_READONLY (t) = 1; | |
5371 | else | |
5372 | { | |
5373 | /* A field that is pseudo-const makes the structure likewise. */ | |
5374 | tree t1 = TREE_TYPE (x); | |
5375 | while (TREE_CODE (t1) == ARRAY_TYPE) | |
5376 | t1 = TREE_TYPE (t1); | |
5377 | if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) | |
5378 | && C_TYPE_FIELDS_READONLY (t1)) | |
5379 | C_TYPE_FIELDS_READONLY (t) = 1; | |
5380 | } | |
5381 | ||
5382 | /* Any field that is volatile means variables of this type must be | |
5383 | treated in some ways as volatile. */ | |
5384 | if (TREE_THIS_VOLATILE (x)) | |
5385 | C_TYPE_FIELDS_VOLATILE (t) = 1; | |
5386 | ||
5387 | /* Any field of nominal variable size implies structure is too. */ | |
5388 | if (C_DECL_VARIABLE_SIZE (x)) | |
5389 | C_TYPE_VARIABLE_SIZE (t) = 1; | |
5390 | ||
8d7bbe5f RS |
5391 | /* Detect invalid nested redefinition. */ |
5392 | if (TREE_TYPE (x) == t) | |
5393 | error ("nested redefinition of `%s'", | |
5394 | IDENTIFIER_POINTER (TYPE_NAME (t))); | |
5395 | ||
51e29401 | 5396 | /* Detect invalid bit-field size. */ |
07c5ab55 RS |
5397 | if (DECL_INITIAL (x)) |
5398 | STRIP_NOPS (DECL_INITIAL (x)); | |
90374cc2 | 5399 | if (DECL_INITIAL (x)) |
e681c5a1 RS |
5400 | { |
5401 | if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST) | |
5402 | constant_expression_warning (DECL_INITIAL (x)); | |
5403 | else | |
5404 | { | |
9df2c88c RK |
5405 | error_with_decl (x, |
5406 | "bit-field `%s' width not an integer constant"); | |
e681c5a1 RS |
5407 | DECL_INITIAL (x) = NULL; |
5408 | } | |
5409 | } | |
51e29401 RS |
5410 | |
5411 | /* Detect invalid bit-field type. */ | |
5412 | if (DECL_INITIAL (x) | |
5413 | && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE | |
19552aa5 | 5414 | && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE |
51e29401 RS |
5415 | && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) |
5416 | { | |
5417 | error_with_decl (x, "bit-field `%s' has invalid type"); | |
5418 | DECL_INITIAL (x) = NULL; | |
5419 | } | |
9df2c88c | 5420 | |
51e29401 RS |
5421 | if (DECL_INITIAL (x) && pedantic |
5422 | && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node | |
61df2ee2 | 5423 | && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node |
19552aa5 | 5424 | && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node |
61df2ee2 RS |
5425 | /* Accept an enum that's equivalent to int or unsigned int. */ |
5426 | && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE | |
5427 | && (TYPE_PRECISION (TREE_TYPE (x)) | |
5428 | == TYPE_PRECISION (integer_type_node)))) | |
89abf8d1 | 5429 | pedwarn_with_decl (x, "bit-field `%s' type invalid in ISO C"); |
51e29401 | 5430 | |
05bccae2 RK |
5431 | /* Detect and ignore out of range field width and process valid |
5432 | field widths. */ | |
51e29401 RS |
5433 | if (DECL_INITIAL (x)) |
5434 | { | |
19552aa5 JM |
5435 | int max_width; |
5436 | if (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node) | |
5437 | max_width = CHAR_TYPE_SIZE; | |
5438 | else | |
5439 | max_width = TYPE_PRECISION (TREE_TYPE (x)); | |
6aa10371 | 5440 | if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0) |
05bccae2 | 5441 | error_with_decl (x, "negative width in bit-field `%s'"); |
19552aa5 | 5442 | else if (0 < compare_tree_int (DECL_INITIAL (x), max_width)) |
05bccae2 | 5443 | pedwarn_with_decl (x, "width of `%s' exceeds its type"); |
9df2c88c | 5444 | else if (integer_zerop (DECL_INITIAL (x)) && DECL_NAME (x) != 0) |
05bccae2 RK |
5445 | error_with_decl (x, "zero width for bit-field `%s'"); |
5446 | else | |
51e29401 | 5447 | { |
05bccae2 RK |
5448 | /* The test above has assured us that TREE_INT_CST_HIGH is 0. */ |
5449 | unsigned HOST_WIDE_INT width | |
5450 | = TREE_INT_CST_LOW (DECL_INITIAL (x)); | |
5451 | ||
5452 | if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE | |
5453 | && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)), | |
5454 | TREE_UNSIGNED (TREE_TYPE (x))) | |
5455 | || (width | |
5456 | < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)), | |
5457 | TREE_UNSIGNED (TREE_TYPE (x)))))) | |
5458 | warning_with_decl (x, | |
5459 | "`%s' is narrower than values of its type"); | |
5460 | ||
5461 | DECL_SIZE (x) = bitsize_int (width); | |
0a7394bc MM |
5462 | DECL_BIT_FIELD (x) = 1; |
5463 | SET_DECL_C_BIT_FIELD (x); | |
05bccae2 RK |
5464 | |
5465 | if (width == 0) | |
5466 | { | |
5467 | /* field size 0 => force desired amount of alignment. */ | |
51e29401 | 5468 | #ifdef EMPTY_FIELD_BOUNDARY |
05bccae2 | 5469 | DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY); |
51e29401 RS |
5470 | #endif |
5471 | #ifdef PCC_BITFIELD_TYPE_MATTERS | |
05bccae2 | 5472 | if (PCC_BITFIELD_TYPE_MATTERS) |
11cf4d18 JJ |
5473 | { |
5474 | DECL_ALIGN (x) = MAX (DECL_ALIGN (x), | |
5475 | TYPE_ALIGN (TREE_TYPE (x))); | |
5476 | DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x)); | |
5477 | } | |
51e29401 | 5478 | #endif |
05bccae2 | 5479 | } |
51e29401 RS |
5480 | } |
5481 | } | |
05bccae2 | 5482 | |
34322499 | 5483 | else if (TREE_TYPE (x) != error_mark_node) |
ec2343c4 | 5484 | { |
f8344bea | 5485 | unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT |
9df2c88c RK |
5486 | : TYPE_ALIGN (TREE_TYPE (x))); |
5487 | ||
ec2343c4 MM |
5488 | /* Non-bit-fields are aligned for their type, except packed |
5489 | fields which require only BITS_PER_UNIT alignment. */ | |
5490 | DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align); | |
11cf4d18 JJ |
5491 | if (! DECL_PACKED (x)) |
5492 | DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x)); | |
ec2343c4 | 5493 | } |
51e29401 | 5494 | |
05bccae2 RK |
5495 | DECL_INITIAL (x) = 0; |
5496 | } | |
51e29401 RS |
5497 | |
5498 | /* Delete all duplicate fields from the fieldlist */ | |
5499 | for (x = fieldlist; x && TREE_CHAIN (x);) | |
5500 | /* Anonymous fields aren't duplicates. */ | |
5501 | if (DECL_NAME (TREE_CHAIN (x)) == 0) | |
5502 | x = TREE_CHAIN (x); | |
5503 | else | |
5504 | { | |
5505 | register tree y = fieldlist; | |
6645c3fa | 5506 | |
51e29401 RS |
5507 | while (1) |
5508 | { | |
5509 | if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) | |
5510 | break; | |
5511 | if (y == x) | |
5512 | break; | |
5513 | y = TREE_CHAIN (y); | |
5514 | } | |
5515 | if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) | |
5516 | { | |
5517 | error_with_decl (TREE_CHAIN (x), "duplicate member `%s'"); | |
5518 | TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); | |
5519 | } | |
6645c3fa KH |
5520 | else |
5521 | x = TREE_CHAIN (x); | |
51e29401 RS |
5522 | } |
5523 | ||
5524 | /* Now we have the nearly final fieldlist. Record it, | |
5525 | then lay out the structure or union (including the fields). */ | |
5526 | ||
5527 | TYPE_FIELDS (t) = fieldlist; | |
5528 | ||
5529 | layout_type (t); | |
5530 | ||
6fbfac92 JM |
5531 | /* Delete all zero-width bit-fields from the fieldlist */ |
5532 | { | |
5533 | tree *fieldlistp = &fieldlist; | |
07b983cd JM |
5534 | while (*fieldlistp) |
5535 | if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)) | |
6fbfac92 JM |
5536 | *fieldlistp = TREE_CHAIN (*fieldlistp); |
5537 | else | |
5538 | fieldlistp = &TREE_CHAIN (*fieldlistp); | |
5539 | } | |
51e29401 RS |
5540 | |
5541 | /* Now we have the truly final field list. | |
5542 | Store it in this type and in the variants. */ | |
5543 | ||
5544 | TYPE_FIELDS (t) = fieldlist; | |
5545 | ||
51e29401 RS |
5546 | for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) |
5547 | { | |
5548 | TYPE_FIELDS (x) = TYPE_FIELDS (t); | |
5549 | TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t); | |
5550 | TYPE_ALIGN (x) = TYPE_ALIGN (t); | |
11cf4d18 | 5551 | TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t); |
51e29401 RS |
5552 | } |
5553 | ||
1604422c RK |
5554 | /* If this was supposed to be a transparent union, but we can't |
5555 | make it one, warn and turn off the flag. */ | |
5556 | if (TREE_CODE (t) == UNION_TYPE | |
5557 | && TYPE_TRANSPARENT_UNION (t) | |
5558 | && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))) | |
5559 | { | |
5560 | TYPE_TRANSPARENT_UNION (t) = 0; | |
d787aad9 | 5561 | warning ("union cannot be made transparent"); |
1604422c RK |
5562 | } |
5563 | ||
51e29401 RS |
5564 | /* If this structure or union completes the type of any previous |
5565 | variable declaration, lay it out and output its rtl. */ | |
5566 | ||
5567 | if (current_binding_level->n_incomplete != 0) | |
5568 | { | |
5569 | tree decl; | |
5570 | for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl)) | |
5571 | { | |
b52114d2 | 5572 | if (TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TYPE_MAIN_VARIANT (t) |
51e29401 RS |
5573 | && TREE_CODE (decl) != TYPE_DECL) |
5574 | { | |
5575 | layout_decl (decl, 0); | |
5576 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
5577 | maybe_objc_check_decl (decl); | |
8d9bfdc5 | 5578 | rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); |
51e29401 RS |
5579 | if (! toplevel) |
5580 | expand_decl (decl); | |
5581 | --current_binding_level->n_incomplete; | |
5582 | } | |
d0f062fb | 5583 | else if (!COMPLETE_TYPE_P (TREE_TYPE (decl)) |
51e29401 RS |
5584 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) |
5585 | { | |
5586 | tree element = TREE_TYPE (decl); | |
5587 | while (TREE_CODE (element) == ARRAY_TYPE) | |
5588 | element = TREE_TYPE (element); | |
5589 | if (element == t) | |
5590 | layout_array_type (TREE_TYPE (decl)); | |
5591 | } | |
5592 | } | |
5593 | } | |
5594 | ||
51e29401 RS |
5595 | /* Finish debugging output for this type. */ |
5596 | rest_of_type_compilation (t, toplevel); | |
5597 | ||
5598 | return t; | |
5599 | } | |
5600 | ||
5601 | /* Lay out the type T, and its element type, and so on. */ | |
5602 | ||
5603 | static void | |
5604 | layout_array_type (t) | |
5605 | tree t; | |
5606 | { | |
5607 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) | |
5608 | layout_array_type (TREE_TYPE (t)); | |
5609 | layout_type (t); | |
5610 | } | |
5611 | \f | |
5612 | /* Begin compiling the definition of an enumeration type. | |
5613 | NAME is its name (or null if anonymous). | |
5614 | Returns the type object, as yet incomplete. | |
5615 | Also records info about it so that build_enumerator | |
5616 | may be used to declare the individual values as they are read. */ | |
5617 | ||
5618 | tree | |
5619 | start_enum (name) | |
5620 | tree name; | |
5621 | { | |
5622 | register tree enumtype = 0; | |
5623 | ||
5624 | /* If this is the real definition for a previous forward reference, | |
5625 | fill in the contents in the same object that used to be the | |
5626 | forward reference. */ | |
5627 | ||
5628 | if (name != 0) | |
5629 | enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1); | |
5630 | ||
5631 | if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) | |
5632 | { | |
5633 | enumtype = make_node (ENUMERAL_TYPE); | |
5634 | pushtag (name, enumtype); | |
5635 | } | |
5636 | ||
5637 | C_TYPE_BEING_DEFINED (enumtype) = 1; | |
5638 | ||
5639 | if (TYPE_VALUES (enumtype) != 0) | |
5640 | { | |
5641 | /* This enum is a named one that has been declared already. */ | |
5642 | error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name)); | |
5643 | ||
5644 | /* Completely replace its old definition. | |
5645 | The old enumerators remain defined, however. */ | |
5646 | TYPE_VALUES (enumtype) = 0; | |
5647 | } | |
5648 | ||
5649 | enum_next_value = integer_zero_node; | |
93e3ba4f | 5650 | enum_overflow = 0; |
51e29401 | 5651 | |
02eb6e90 RK |
5652 | if (flag_short_enums) |
5653 | TYPE_PACKED (enumtype) = 1; | |
5654 | ||
51e29401 RS |
5655 | return enumtype; |
5656 | } | |
5657 | ||
5658 | /* After processing and defining all the values of an enumeration type, | |
5659 | install their decls in the enumeration type and finish it off. | |
10861e9a RK |
5660 | ENUMTYPE is the type object, VALUES a list of decl-value pairs, |
5661 | and ATTRIBUTES are the specified attributes. | |
51e29401 RS |
5662 | Returns ENUMTYPE. */ |
5663 | ||
5664 | tree | |
10861e9a RK |
5665 | finish_enum (enumtype, values, attributes) |
5666 | tree enumtype; | |
5667 | tree values; | |
5668 | tree attributes; | |
51e29401 | 5669 | { |
fbe23ee7 | 5670 | register tree pair, tem; |
736f85c7 | 5671 | tree minnode = 0, maxnode = 0, enum_value_type; |
cb3ca04e ZW |
5672 | int precision, unsign; |
5673 | int toplevel = (global_binding_level == current_binding_level); | |
51e29401 RS |
5674 | |
5675 | if (in_parm_level_p ()) | |
5676 | warning ("enum defined inside parms"); | |
5677 | ||
10861e9a RK |
5678 | decl_attributes (enumtype, attributes, NULL_TREE); |
5679 | ||
51e29401 RS |
5680 | /* Calculate the maximum value of any enumerator in this type. */ |
5681 | ||
59116212 RK |
5682 | if (values == error_mark_node) |
5683 | minnode = maxnode = integer_zero_node; | |
5684 | else | |
f500253d | 5685 | { |
cb3ca04e ZW |
5686 | minnode = maxnode = TREE_VALUE (values); |
5687 | for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) | |
f500253d | 5688 | { |
cb3ca04e ZW |
5689 | tree value = TREE_VALUE (pair); |
5690 | if (tree_int_cst_lt (maxnode, value)) | |
5691 | maxnode = value; | |
5692 | if (tree_int_cst_lt (value, minnode)) | |
5693 | minnode = value; | |
f500253d | 5694 | } |
cb3ca04e | 5695 | } |
f500253d | 5696 | |
cb3ca04e ZW |
5697 | /* Construct the final type of this enumeration. It is the same |
5698 | as one of the integral types - the narrowest one that fits, except | |
5699 | that normally we only go as narrow as int - and signed iff any of | |
5700 | the values are negative. */ | |
5701 | unsign = (tree_int_cst_sgn (minnode) >= 0); | |
5702 | precision = MAX (min_precision (minnode, unsign), | |
5703 | min_precision (maxnode, unsign)); | |
5704 | if (!TYPE_PACKED (enumtype)) | |
5705 | precision = MAX (precision, TYPE_PRECISION (integer_type_node)); | |
5706 | if (type_for_size (precision, unsign) == 0) | |
5707 | { | |
5708 | warning ("enumeration values exceed range of largest integer"); | |
5709 | precision = TYPE_PRECISION (long_long_integer_type_node); | |
f500253d | 5710 | } |
51e29401 | 5711 | |
736f85c7 AO |
5712 | if (precision == TYPE_PRECISION (integer_type_node)) |
5713 | enum_value_type = type_for_size (precision, 0); | |
5714 | else | |
5715 | enum_value_type = enumtype; | |
5716 | ||
cb3ca04e ZW |
5717 | TYPE_MIN_VALUE (enumtype) = minnode; |
5718 | TYPE_MAX_VALUE (enumtype) = maxnode; | |
5719 | TYPE_PRECISION (enumtype) = precision; | |
5720 | TREE_UNSIGNED (enumtype) = unsign; | |
51e29401 RS |
5721 | TYPE_SIZE (enumtype) = 0; |
5722 | layout_type (enumtype); | |
5723 | ||
59116212 | 5724 | if (values != error_mark_node) |
75b46437 | 5725 | { |
cb3ca04e ZW |
5726 | /* Change the type of the enumerators to be the enum type. We |
5727 | need to do this irrespective of the size of the enum, for | |
5728 | proper type checking. Replace the DECL_INITIALs of the | |
5729 | enumerators, and the value slots of the list, with copies | |
5730 | that have the enum type; they cannot be modified in place | |
5731 | because they may be shared (e.g. integer_zero_node) Finally, | |
5732 | change the purpose slots to point to the names of the decls. */ | |
59116212 RK |
5733 | for (pair = values; pair; pair = TREE_CHAIN (pair)) |
5734 | { | |
cb3ca04e | 5735 | tree enu = TREE_PURPOSE (pair); |
51e29401 | 5736 | |
cb3ca04e ZW |
5737 | TREE_TYPE (enu) = enumtype; |
5738 | DECL_SIZE (enu) = TYPE_SIZE (enumtype); | |
06ceef4e | 5739 | DECL_SIZE_UNIT (enu) = TYPE_SIZE_UNIT (enumtype); |
cb3ca04e | 5740 | DECL_ALIGN (enu) = TYPE_ALIGN (enumtype); |
11cf4d18 | 5741 | DECL_USER_ALIGN (enu) = TYPE_USER_ALIGN (enumtype); |
cb3ca04e | 5742 | DECL_MODE (enu) = TYPE_MODE (enumtype); |
736f85c7 AO |
5743 | |
5744 | /* The ISO C Standard mandates enumerators to have type int, | |
5745 | even though the underlying type of an enum type is | |
5746 | unspecified. Here we convert any enumerators that fit in | |
5747 | an int to type int, to avoid promotions to unsigned types | |
5748 | when comparing integers with enumerators that fit in the | |
5749 | int range. When -pedantic is given, build_enumerator() | |
5750 | would have already taken care of those that don't fit. */ | |
5751 | if (int_fits_type_p (DECL_INITIAL (enu), enum_value_type)) | |
5752 | DECL_INITIAL (enu) = convert (enum_value_type, DECL_INITIAL (enu)); | |
5753 | else | |
5754 | DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu)); | |
cb3ca04e ZW |
5755 | |
5756 | TREE_PURPOSE (pair) = DECL_NAME (enu); | |
5757 | TREE_VALUE (pair) = DECL_INITIAL (enu); | |
5758 | } | |
51e29401 | 5759 | |
59116212 RK |
5760 | TYPE_VALUES (enumtype) = values; |
5761 | } | |
51e29401 | 5762 | |
fbe23ee7 RS |
5763 | /* Fix up all variant types of this enum type. */ |
5764 | for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) | |
5765 | { | |
cb3ca04e ZW |
5766 | if (tem == enumtype) |
5767 | continue; | |
fbe23ee7 RS |
5768 | TYPE_VALUES (tem) = TYPE_VALUES (enumtype); |
5769 | TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); | |
5770 | TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); | |
5771 | TYPE_SIZE (tem) = TYPE_SIZE (enumtype); | |
def9b006 | 5772 | TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype); |
fbe23ee7 RS |
5773 | TYPE_MODE (tem) = TYPE_MODE (enumtype); |
5774 | TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); | |
5775 | TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); | |
11cf4d18 | 5776 | TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype); |
fbe23ee7 RS |
5777 | TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); |
5778 | } | |
5779 | ||
51e29401 RS |
5780 | /* Finish debugging output for this type. */ |
5781 | rest_of_type_compilation (enumtype, toplevel); | |
5782 | ||
5783 | return enumtype; | |
5784 | } | |
5785 | ||
5786 | /* Build and install a CONST_DECL for one value of the | |
5787 | current enumeration type (one that was begun with start_enum). | |
5788 | Return a tree-list containing the CONST_DECL and its value. | |
5789 | Assignment of sequential values by default is handled here. */ | |
5790 | ||
5791 | tree | |
5792 | build_enumerator (name, value) | |
5793 | tree name, value; | |
5794 | { | |
75b46437 | 5795 | register tree decl, type; |
51e29401 RS |
5796 | |
5797 | /* Validate and default VALUE. */ | |
5798 | ||
5799 | /* Remove no-op casts from the value. */ | |
cd7a1451 | 5800 | if (value) |
874a7be1 | 5801 | STRIP_TYPE_NOPS (value); |
51e29401 | 5802 | |
90374cc2 | 5803 | if (value != 0) |
e681c5a1 RS |
5804 | { |
5805 | if (TREE_CODE (value) == INTEGER_CST) | |
25a1019f RK |
5806 | { |
5807 | value = default_conversion (value); | |
5808 | constant_expression_warning (value); | |
5809 | } | |
e681c5a1 RS |
5810 | else |
5811 | { | |
5812 | error ("enumerator value for `%s' not integer constant", | |
5813 | IDENTIFIER_POINTER (name)); | |
5814 | value = 0; | |
5815 | } | |
5816 | } | |
51e29401 RS |
5817 | |
5818 | /* Default based on previous value. */ | |
5819 | /* It should no longer be possible to have NON_LVALUE_EXPR | |
5820 | in the default. */ | |
5821 | if (value == 0) | |
93e3ba4f RS |
5822 | { |
5823 | value = enum_next_value; | |
5824 | if (enum_overflow) | |
5825 | error ("overflow in enumeration values"); | |
5826 | } | |
51e29401 RS |
5827 | |
5828 | if (pedantic && ! int_fits_type_p (value, integer_type_node)) | |
5829 | { | |
89abf8d1 | 5830 | pedwarn ("ISO C restricts enumerator values to range of `int'"); |
736f85c7 | 5831 | value = convert (integer_type_node, value); |
51e29401 RS |
5832 | } |
5833 | ||
5834 | /* Set basis for default for next value. */ | |
5835 | enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0); | |
93e3ba4f | 5836 | enum_overflow = tree_int_cst_lt (enum_next_value, value); |
51e29401 RS |
5837 | |
5838 | /* Now create a declaration for the enum value name. */ | |
5839 | ||
75b46437 RS |
5840 | type = TREE_TYPE (value); |
5841 | type = type_for_size (MAX (TYPE_PRECISION (type), | |
5842 | TYPE_PRECISION (integer_type_node)), | |
5843 | ((flag_traditional | |
5844 | || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node)) | |
5845 | && TREE_UNSIGNED (type))); | |
5846 | ||
5847 | decl = build_decl (CONST_DECL, name, type); | |
0543d026 | 5848 | DECL_INITIAL (decl) = convert (type, value); |
51e29401 RS |
5849 | pushdecl (decl); |
5850 | ||
4dd7201e | 5851 | return tree_cons (decl, value, NULL_TREE); |
51e29401 | 5852 | } |
8f17b5c5 | 5853 | |
51e29401 RS |
5854 | \f |
5855 | /* Create the FUNCTION_DECL for a function definition. | |
5730cf69 RK |
5856 | DECLSPECS, DECLARATOR, PREFIX_ATTRIBUTES and ATTRIBUTES are the parts of |
5857 | the declaration; they describe the function's name and the type it returns, | |
51e29401 RS |
5858 | but twisted together in a fashion that parallels the syntax of C. |
5859 | ||
5860 | This function creates a binding context for the function body | |
5861 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
5862 | ||
5863 | Returns 1 on success. If the DECLARATOR is not suitable for a function | |
5864 | (it defines a datum instead), we return 0, which tells | |
4dd7201e | 5865 | yyparse to report a parse error. */ |
51e29401 RS |
5866 | |
5867 | int | |
4dd7201e | 5868 | start_function (declspecs, declarator, prefix_attributes, attributes) |
5730cf69 | 5869 | tree declarator, declspecs, prefix_attributes, attributes; |
51e29401 RS |
5870 | { |
5871 | tree decl1, old_decl; | |
5872 | tree restype; | |
5415b705 | 5873 | int old_immediate_size_expand = immediate_size_expand; |
51e29401 | 5874 | |
0f41302f | 5875 | current_function_returns_value = 0; /* Assume, until we see it does. */ |
51e29401 RS |
5876 | current_function_returns_null = 0; |
5877 | warn_about_return_type = 0; | |
5878 | current_extern_inline = 0; | |
5879 | c_function_varargs = 0; | |
5880 | named_labels = 0; | |
5881 | shadowed_labels = 0; | |
5882 | ||
5415b705 RK |
5883 | /* Don't expand any sizes in the return type of the function. */ |
5884 | immediate_size_expand = 0; | |
5885 | ||
51e29401 RS |
5886 | decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1); |
5887 | ||
5888 | /* If the declarator is not suitable for a function definition, | |
5889 | cause a syntax error. */ | |
5890 | if (decl1 == 0) | |
e9a25f70 JL |
5891 | { |
5892 | immediate_size_expand = old_immediate_size_expand; | |
5893 | return 0; | |
5894 | } | |
51e29401 | 5895 | |
5730cf69 | 5896 | decl_attributes (decl1, prefix_attributes, attributes); |
7665dfd4 | 5897 | |
51e29401 RS |
5898 | announce_function (decl1); |
5899 | ||
d0f062fb | 5900 | if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1)))) |
51e29401 | 5901 | { |
903f51d9 | 5902 | error ("return type is an incomplete type"); |
51e29401 RS |
5903 | /* Make it return void instead. */ |
5904 | TREE_TYPE (decl1) | |
5905 | = build_function_type (void_type_node, | |
5906 | TYPE_ARG_TYPES (TREE_TYPE (decl1))); | |
5907 | } | |
5908 | ||
5909 | if (warn_about_return_type) | |
903f51d9 | 5910 | pedwarn_c99 ("return type defaults to `int'"); |
51e29401 RS |
5911 | |
5912 | /* Save the parm names or decls from this function's declarator | |
5913 | where store_parm_decls will find them. */ | |
5914 | current_function_parms = last_function_parms; | |
5915 | current_function_parm_tags = last_function_parm_tags; | |
5916 | ||
5917 | /* Make the init_value nonzero so pushdecl knows this is not tentative. | |
5918 | error_mark_node is replaced below (in poplevel) with the BLOCK. */ | |
5919 | DECL_INITIAL (decl1) = error_mark_node; | |
5920 | ||
5921 | /* If this definition isn't a prototype and we had a prototype declaration | |
5922 | before, copy the arg type info from that prototype. | |
5923 | But not if what we had before was a builtin function. */ | |
5924 | old_decl = lookup_name_current_level (DECL_NAME (decl1)); | |
5925 | if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE | |
5926 | && !DECL_BUILT_IN (old_decl) | |
fa7d8b92 RK |
5927 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) |
5928 | == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl)))) | |
51e29401 | 5929 | && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) |
50a9145c JW |
5930 | { |
5931 | TREE_TYPE (decl1) = TREE_TYPE (old_decl); | |
5932 | current_function_prototype_file = DECL_SOURCE_FILE (old_decl); | |
5933 | current_function_prototype_line = DECL_SOURCE_LINE (old_decl); | |
5934 | } | |
51e29401 | 5935 | |
6fc7c517 JW |
5936 | /* If there is no explicit declaration, look for any out-of-scope implicit |
5937 | declarations. */ | |
5938 | if (old_decl == 0) | |
5939 | old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)); | |
5940 | ||
51e29401 RS |
5941 | /* Optionally warn of old-fashioned def with no previous prototype. */ |
5942 | if (warn_strict_prototypes | |
5943 | && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 | |
5944 | && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)) | |
5945 | warning ("function declaration isn't a prototype"); | |
5946 | /* Optionally warn of any global def with no previous prototype. */ | |
5947 | else if (warn_missing_prototypes | |
5948 | && TREE_PUBLIC (decl1) | |
39ab948e | 5949 | && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0) |
5b47282c | 5950 | && ! MAIN_NAME_P (DECL_NAME (decl1))) |
51e29401 RS |
5951 | warning_with_decl (decl1, "no previous prototype for `%s'"); |
5952 | /* Optionally warn of any def with no previous prototype | |
5953 | if the function has already been used. */ | |
5954 | else if (warn_missing_prototypes | |
5955 | && old_decl != 0 && TREE_USED (old_decl) | |
6fc7c517 | 5956 | && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) |
1474fe46 | 5957 | warning_with_decl (decl1, |
6645c3fa | 5958 | "`%s' was used with no prototype before its definition"); |
1474fe46 RK |
5959 | /* Optionally warn of any global def with no previous declaration. */ |
5960 | else if (warn_missing_declarations | |
5961 | && TREE_PUBLIC (decl1) | |
5962 | && old_decl == 0 | |
5b47282c | 5963 | && ! MAIN_NAME_P (DECL_NAME (decl1))) |
1474fe46 RK |
5964 | warning_with_decl (decl1, "no previous declaration for `%s'"); |
5965 | /* Optionally warn of any def with no previous declaration | |
5966 | if the function has already been used. */ | |
5967 | else if (warn_missing_declarations | |
6fc7c517 JW |
5968 | && old_decl != 0 && TREE_USED (old_decl) |
5969 | && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))) | |
1474fe46 | 5970 | warning_with_decl (decl1, |
6645c3fa | 5971 | "`%s' was used with no declaration before its definition"); |
51e29401 RS |
5972 | |
5973 | /* This is a definition, not a reference. | |
1394aabd | 5974 | So normally clear DECL_EXTERNAL. |
51e29401 | 5975 | However, `extern inline' acts like a declaration |
1394aabd RS |
5976 | except for defining how to inline. So set DECL_EXTERNAL in that case. */ |
5977 | DECL_EXTERNAL (decl1) = current_extern_inline; | |
51e29401 | 5978 | |
3a846e6e NC |
5979 | #ifdef SET_DEFAULT_DECL_ATTRIBUTES |
5980 | SET_DEFAULT_DECL_ATTRIBUTES (decl1, attributes); | |
5981 | #endif | |
6645c3fa | 5982 | |
51e29401 RS |
5983 | /* This function exists in static storage. |
5984 | (This does not mean `static' in the C sense!) */ | |
5985 | TREE_STATIC (decl1) = 1; | |
5986 | ||
5987 | /* A nested function is not global. */ | |
5988 | if (current_function_decl != 0) | |
5989 | TREE_PUBLIC (decl1) = 0; | |
5990 | ||
6645c3fa | 5991 | /* Warn for unlikely, improbable, or stupid declarations of `main'. */ |
5b47282c | 5992 | if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1))) |
b8705e61 RK |
5993 | { |
5994 | tree args; | |
5995 | int argct = 0; | |
5996 | ||
5997 | if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) | |
6645c3fa | 5998 | != integer_type_node) |
a01dce9a | 5999 | pedwarn_with_decl (decl1, "return type of `%s' is not `int'"); |
b8705e61 RK |
6000 | |
6001 | for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args; | |
6002 | args = TREE_CHAIN (args)) | |
6003 | { | |
6004 | tree type = args ? TREE_VALUE (args) : 0; | |
6005 | ||
6006 | if (type == void_type_node) | |
6007 | break; | |
6008 | ||
6009 | ++argct; | |
6010 | switch (argct) | |
6011 | { | |
6012 | case 1: | |
6013 | if (TYPE_MAIN_VARIANT (type) != integer_type_node) | |
6014 | pedwarn_with_decl (decl1, | |
6015 | "first argument of `%s' should be `int'"); | |
6016 | break; | |
6017 | ||
6018 | case 2: | |
6019 | if (TREE_CODE (type) != POINTER_TYPE | |
6020 | || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE | |
6021 | || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) | |
6022 | != char_type_node)) | |
6023 | pedwarn_with_decl (decl1, | |
6645c3fa | 6024 | "second argument of `%s' should be `char **'"); |
b8705e61 RK |
6025 | break; |
6026 | ||
6027 | case 3: | |
6028 | if (TREE_CODE (type) != POINTER_TYPE | |
6029 | || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE | |
6030 | || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) | |
6031 | != char_type_node)) | |
6032 | pedwarn_with_decl (decl1, | |
6645c3fa | 6033 | "third argument of `%s' should probably be `char **'"); |
b8705e61 RK |
6034 | break; |
6035 | } | |
d71f83ca | 6036 | } |
b8705e61 | 6037 | |
d71f83ca RK |
6038 | /* It is intentional that this message does not mention the third |
6039 | argument, which is warned for only pedantically, because it's | |
6645c3fa | 6040 | blessed by mention in an appendix of the standard. */ |
d71f83ca RK |
6041 | if (argct > 0 && (argct < 2 || argct > 3)) |
6042 | pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments"); | |
b8705e61 | 6043 | |
d71f83ca RK |
6044 | if (argct == 3 && pedantic) |
6045 | pedwarn_with_decl (decl1, "third argument of `%s' is deprecated"); | |
b8705e61 RK |
6046 | |
6047 | if (! TREE_PUBLIC (decl1)) | |
6048 | pedwarn_with_decl (decl1, "`%s' is normally a non-static function"); | |
6049 | } | |
6050 | ||
51e29401 RS |
6051 | /* Record the decl so that the function name is defined. |
6052 | If we already have a decl for this name, and it is a FUNCTION_DECL, | |
6053 | use the old decl. */ | |
6054 | ||
6055 | current_function_decl = pushdecl (decl1); | |
6056 | ||
6057 | pushlevel (0); | |
6058 | declare_parm_level (1); | |
6059 | current_binding_level->subblocks_tag_transparent = 1; | |
6060 | ||
6061 | make_function_rtl (current_function_decl); | |
6062 | ||
6063 | restype = TREE_TYPE (TREE_TYPE (current_function_decl)); | |
6064 | /* Promote the value to int before returning it. */ | |
24bc4c7f | 6065 | if (C_PROMOTING_INTEGER_TYPE_P (restype)) |
42dfa47f RS |
6066 | { |
6067 | /* It retains unsignedness if traditional | |
6068 | or if not really getting wider. */ | |
6069 | if (TREE_UNSIGNED (restype) | |
6070 | && (flag_traditional | |
6071 | || (TYPE_PRECISION (restype) | |
6072 | == TYPE_PRECISION (integer_type_node)))) | |
6073 | restype = unsigned_type_node; | |
6074 | else | |
6075 | restype = integer_type_node; | |
6076 | } | |
8d9bfdc5 RK |
6077 | DECL_RESULT (current_function_decl) |
6078 | = build_decl (RESULT_DECL, NULL_TREE, restype); | |
51e29401 | 6079 | |
51e29401 RS |
6080 | /* If this fcn was already referenced via a block-scope `extern' decl |
6081 | (or an implicit decl), propagate certain information about the usage. */ | |
6082 | if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl))) | |
6083 | TREE_ADDRESSABLE (current_function_decl) = 1; | |
6084 | ||
5415b705 RK |
6085 | immediate_size_expand = old_immediate_size_expand; |
6086 | ||
51e29401 RS |
6087 | return 1; |
6088 | } | |
6089 | ||
6090 | /* Record that this function is going to be a varargs function. | |
6091 | This is called before store_parm_decls, which is too early | |
6092 | to call mark_varargs directly. */ | |
6093 | ||
6094 | void | |
6095 | c_mark_varargs () | |
6096 | { | |
6097 | c_function_varargs = 1; | |
6098 | } | |
6099 | \f | |
6100 | /* Store the parameter declarations into the current function declaration. | |
6101 | This is called after parsing the parameter declarations, before | |
6102 | digesting the body of the function. | |
6103 | ||
6104 | For an old-style definition, modify the function's type | |
6105 | to specify at least the number of arguments. */ | |
6106 | ||
6107 | void | |
6108 | store_parm_decls () | |
6109 | { | |
6110 | register tree fndecl = current_function_decl; | |
6111 | register tree parm; | |
6112 | ||
6113 | /* This is either a chain of PARM_DECLs (if a prototype was used) | |
6114 | or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */ | |
6115 | tree specparms = current_function_parms; | |
6116 | ||
6117 | /* This is a list of types declared among parms in a prototype. */ | |
6118 | tree parmtags = current_function_parm_tags; | |
6119 | ||
6120 | /* This is a chain of PARM_DECLs from old-style parm declarations. */ | |
6121 | register tree parmdecls = getdecls (); | |
6122 | ||
6123 | /* This is a chain of any other decls that came in among the parm | |
6124 | declarations. If a parm is declared with enum {foo, bar} x; | |
6125 | then CONST_DECLs for foo and bar are put here. */ | |
6126 | tree nonparms = 0; | |
6127 | ||
6128 | /* Nonzero if this definition is written with a prototype. */ | |
6129 | int prototype = 0; | |
6130 | ||
6131 | if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST) | |
6132 | { | |
6133 | /* This case is when the function was defined with an ANSI prototype. | |
6134 | The parms already have decls, so we need not do anything here | |
6135 | except record them as in effect | |
6136 | and complain if any redundant old-style parm decls were written. */ | |
6137 | ||
6138 | register tree next; | |
6139 | tree others = 0; | |
6140 | ||
6141 | prototype = 1; | |
6142 | ||
6143 | if (parmdecls != 0) | |
7a0347ff RS |
6144 | { |
6145 | tree decl, link; | |
6146 | ||
6147 | error_with_decl (fndecl, | |
6148 | "parm types given both in parmlist and separately"); | |
6149 | /* Get rid of the erroneous decls; don't keep them on | |
6150 | the list of parms, since they might not be PARM_DECLs. */ | |
6151 | for (decl = current_binding_level->names; | |
6152 | decl; decl = TREE_CHAIN (decl)) | |
6153 | if (DECL_NAME (decl)) | |
6154 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0; | |
6155 | for (link = current_binding_level->shadowed; | |
6156 | link; link = TREE_CHAIN (link)) | |
6157 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
6158 | current_binding_level->names = 0; | |
6159 | current_binding_level->shadowed = 0; | |
6160 | } | |
51e29401 RS |
6161 | |
6162 | specparms = nreverse (specparms); | |
6163 | for (parm = specparms; parm; parm = next) | |
6164 | { | |
6165 | next = TREE_CHAIN (parm); | |
6166 | if (TREE_CODE (parm) == PARM_DECL) | |
6167 | { | |
6168 | if (DECL_NAME (parm) == 0) | |
6169 | error_with_decl (parm, "parameter name omitted"); | |
17aec3eb | 6170 | else if (TREE_CODE (TREE_TYPE (parm)) != ERROR_MARK |
71653180 | 6171 | && VOID_TYPE_P (TREE_TYPE (parm))) |
a4faa7cc JW |
6172 | { |
6173 | error_with_decl (parm, "parameter `%s' declared void"); | |
6174 | /* Change the type to error_mark_node so this parameter | |
6175 | will be ignored by assign_parms. */ | |
6176 | TREE_TYPE (parm) = error_mark_node; | |
6177 | } | |
51e29401 RS |
6178 | pushdecl (parm); |
6179 | } | |
6180 | else | |
6181 | { | |
6182 | /* If we find an enum constant or a type tag, | |
6183 | put it aside for the moment. */ | |
6184 | TREE_CHAIN (parm) = 0; | |
6185 | others = chainon (others, parm); | |
6186 | } | |
6187 | } | |
6188 | ||
6189 | /* Get the decls in their original chain order | |
6190 | and record in the function. */ | |
6191 | DECL_ARGUMENTS (fndecl) = getdecls (); | |
6192 | ||
6193 | #if 0 | |
6194 | /* If this function takes a variable number of arguments, | |
6195 | add a phony parameter to the end of the parm list, | |
6196 | to represent the position of the first unnamed argument. */ | |
6197 | if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))) | |
6198 | != void_type_node) | |
6199 | { | |
6200 | tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node); | |
6201 | /* Let's hope the address of the unnamed parm | |
6202 | won't depend on its type. */ | |
6203 | TREE_TYPE (dummy) = integer_type_node; | |
6204 | DECL_ARG_TYPE (dummy) = integer_type_node; | |
6645c3fa | 6205 | DECL_ARGUMENTS (fndecl) = chainon (DECL_ARGUMENTS (fndecl), dummy); |
51e29401 RS |
6206 | } |
6207 | #endif | |
6208 | ||
6209 | /* Now pushdecl the enum constants. */ | |
6210 | for (parm = others; parm; parm = next) | |
6211 | { | |
6212 | next = TREE_CHAIN (parm); | |
6213 | if (DECL_NAME (parm) == 0) | |
6214 | ; | |
5fe86b8b | 6215 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) |
51e29401 RS |
6216 | ; |
6217 | else if (TREE_CODE (parm) != PARM_DECL) | |
6218 | pushdecl (parm); | |
6219 | } | |
6220 | ||
6221 | storetags (chainon (parmtags, gettags ())); | |
6222 | } | |
6223 | else | |
6224 | { | |
6225 | /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes | |
6226 | each with a parm name as the TREE_VALUE. | |
6227 | ||
6228 | PARMDECLS is a chain of declarations for parameters. | |
6229 | Warning! It can also contain CONST_DECLs which are not parameters | |
6230 | but are names of enumerators of any enum types | |
6231 | declared among the parameters. | |
6232 | ||
6233 | First match each formal parameter name with its declaration. | |
6234 | Associate decls with the names and store the decls | |
6235 | into the TREE_PURPOSE slots. */ | |
6236 | ||
17aec3eb RK |
6237 | /* We use DECL_WEAK as a flag to show which parameters have been |
6238 | seen already since it is not used on PARM_DECL or CONST_DECL. */ | |
51e29401 | 6239 | for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) |
17aec3eb | 6240 | DECL_WEAK (parm) = 0; |
51e29401 RS |
6241 | |
6242 | for (parm = specparms; parm; parm = TREE_CHAIN (parm)) | |
6243 | { | |
6244 | register tree tail, found = NULL; | |
6245 | ||
6246 | if (TREE_VALUE (parm) == 0) | |
6247 | { | |
17aec3eb RK |
6248 | error_with_decl (fndecl, |
6249 | "parameter name missing from parameter list"); | |
51e29401 RS |
6250 | TREE_PURPOSE (parm) = 0; |
6251 | continue; | |
6252 | } | |
6253 | ||
6254 | /* See if any of the parmdecls specifies this parm by name. | |
6255 | Ignore any enumerator decls. */ | |
6256 | for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) | |
6257 | if (DECL_NAME (tail) == TREE_VALUE (parm) | |
6258 | && TREE_CODE (tail) == PARM_DECL) | |
6259 | { | |
6260 | found = tail; | |
6261 | break; | |
6262 | } | |
6263 | ||
6264 | /* If declaration already marked, we have a duplicate name. | |
6265 | Complain, and don't use this decl twice. */ | |
17aec3eb | 6266 | if (found && DECL_WEAK (found)) |
51e29401 RS |
6267 | { |
6268 | error_with_decl (found, "multiple parameters named `%s'"); | |
6269 | found = 0; | |
6270 | } | |
6271 | ||
6272 | /* If the declaration says "void", complain and ignore it. */ | |
71653180 | 6273 | if (found && VOID_TYPE_P (TREE_TYPE (found))) |
51e29401 RS |
6274 | { |
6275 | error_with_decl (found, "parameter `%s' declared void"); | |
6276 | TREE_TYPE (found) = integer_type_node; | |
6277 | DECL_ARG_TYPE (found) = integer_type_node; | |
6278 | layout_decl (found, 0); | |
6279 | } | |
6280 | ||
6281 | /* Traditionally, a parm declared float is actually a double. */ | |
6282 | if (found && flag_traditional | |
90d56da8 | 6283 | && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node) |
6d142a10 RS |
6284 | { |
6285 | TREE_TYPE (found) = double_type_node; | |
6286 | DECL_ARG_TYPE (found) = double_type_node; | |
6287 | layout_decl (found, 0); | |
6288 | } | |
51e29401 RS |
6289 | |
6290 | /* If no declaration found, default to int. */ | |
6291 | if (!found) | |
6292 | { | |
6293 | found = build_decl (PARM_DECL, TREE_VALUE (parm), | |
6294 | integer_type_node); | |
6295 | DECL_ARG_TYPE (found) = TREE_TYPE (found); | |
6296 | DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); | |
6297 | DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); | |
46ca739c JM |
6298 | if (flag_isoc99) |
6299 | pedwarn_with_decl (found, "type of `%s' defaults to `int'"); | |
6300 | else if (extra_warnings) | |
51e29401 RS |
6301 | warning_with_decl (found, "type of `%s' defaults to `int'"); |
6302 | pushdecl (found); | |
6303 | } | |
6304 | ||
6305 | TREE_PURPOSE (parm) = found; | |
6306 | ||
6645c3fa | 6307 | /* Mark this decl as "already found". */ |
17aec3eb | 6308 | DECL_WEAK (found) = 1; |
51e29401 RS |
6309 | } |
6310 | ||
6311 | /* Put anything which is on the parmdecls chain and which is | |
6312 | not a PARM_DECL onto the list NONPARMS. (The types of | |
6313 | non-parm things which might appear on the list include | |
6314 | enumerators and NULL-named TYPE_DECL nodes.) Complain about | |
6315 | any actual PARM_DECLs not matched with any names. */ | |
6316 | ||
6317 | nonparms = 0; | |
6645c3fa | 6318 | for (parm = parmdecls; parm;) |
51e29401 RS |
6319 | { |
6320 | tree next = TREE_CHAIN (parm); | |
6321 | TREE_CHAIN (parm) = 0; | |
6322 | ||
6323 | if (TREE_CODE (parm) != PARM_DECL) | |
6324 | nonparms = chainon (nonparms, parm); | |
6325 | else | |
6326 | { | |
6327 | /* Complain about args with incomplete types. */ | |
d0f062fb | 6328 | if (!COMPLETE_TYPE_P (TREE_TYPE (parm))) |
6645c3fa KH |
6329 | { |
6330 | error_with_decl (parm, "parameter `%s' has incomplete type"); | |
6331 | TREE_TYPE (parm) = error_mark_node; | |
6332 | } | |
51e29401 | 6333 | |
17aec3eb | 6334 | if (! DECL_WEAK (parm)) |
6645c3fa KH |
6335 | { |
6336 | error_with_decl (parm, | |
6337 | "declaration for parameter `%s' but no such parameter"); | |
51e29401 RS |
6338 | /* Pretend the parameter was not missing. |
6339 | This gets us to a standard state and minimizes | |
6340 | further error messages. */ | |
6645c3fa | 6341 | specparms |
51e29401 RS |
6342 | = chainon (specparms, |
6343 | tree_cons (parm, NULL_TREE, NULL_TREE)); | |
6344 | } | |
6345 | } | |
6346 | ||
6347 | parm = next; | |
6348 | } | |
6349 | ||
6645c3fa KH |
6350 | /* Chain the declarations together in the order of the list of |
6351 | names. Store that chain in the function decl, replacing the | |
6352 | list of names. */ | |
51e29401 RS |
6353 | parm = specparms; |
6354 | DECL_ARGUMENTS (fndecl) = 0; | |
6355 | { | |
6356 | register tree last; | |
6357 | for (last = 0; parm; parm = TREE_CHAIN (parm)) | |
6358 | if (TREE_PURPOSE (parm)) | |
6359 | { | |
6360 | if (last == 0) | |
6361 | DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm); | |
6362 | else | |
6363 | TREE_CHAIN (last) = TREE_PURPOSE (parm); | |
6364 | last = TREE_PURPOSE (parm); | |
6365 | TREE_CHAIN (last) = 0; | |
6366 | } | |
6367 | } | |
6368 | ||
6369 | /* If there was a previous prototype, | |
6370 | set the DECL_ARG_TYPE of each argument according to | |
6371 | the type previously specified, and report any mismatches. */ | |
6372 | ||
6373 | if (TYPE_ARG_TYPES (TREE_TYPE (fndecl))) | |
6374 | { | |
6375 | register tree type; | |
6376 | for (parm = DECL_ARGUMENTS (fndecl), | |
6377 | type = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); | |
5fe86b8b RS |
6378 | parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) |
6379 | != void_type_node)); | |
51e29401 RS |
6380 | parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) |
6381 | { | |
6382 | if (parm == 0 || type == 0 | |
5fe86b8b | 6383 | || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) |
51e29401 RS |
6384 | { |
6385 | error ("number of arguments doesn't match prototype"); | |
50a9145c JW |
6386 | error_with_file_and_line (current_function_prototype_file, |
6387 | current_function_prototype_line, | |
6388 | "prototype declaration"); | |
51e29401 RS |
6389 | break; |
6390 | } | |
6391 | /* Type for passing arg must be consistent | |
6392 | with that declared for the arg. */ | |
ec2343c4 | 6393 | if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type))) |
51e29401 | 6394 | { |
b3fc0c98 RS |
6395 | if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) |
6396 | == TYPE_MAIN_VARIANT (TREE_VALUE (type))) | |
51e29401 | 6397 | { |
ec2343c4 MM |
6398 | /* Adjust argument to match prototype. E.g. a previous |
6399 | `int foo(float);' prototype causes | |
6400 | `int foo(x) float x; {...}' to be treated like | |
6401 | `int foo(float x) {...}'. This is particularly | |
6402 | useful for argument types like uid_t. */ | |
6403 | DECL_ARG_TYPE (parm) = TREE_TYPE (parm); | |
7d473569 JJ |
6404 | |
6405 | if (PROMOTE_PROTOTYPES | |
6406 | && (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE | |
6407 | || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE) | |
ec2343c4 MM |
6408 | && TYPE_PRECISION (TREE_TYPE (parm)) |
6409 | < TYPE_PRECISION (integer_type_node)) | |
6410 | DECL_ARG_TYPE (parm) = integer_type_node; | |
7d473569 | 6411 | |
ec2343c4 | 6412 | if (pedantic) |
50a9145c | 6413 | { |
42f00318 | 6414 | pedwarn ("promoted argument `%s' doesn't match prototype", |
50a9145c JW |
6415 | IDENTIFIER_POINTER (DECL_NAME (parm))); |
6416 | warning_with_file_and_line | |
6417 | (current_function_prototype_file, | |
6418 | current_function_prototype_line, | |
6419 | "prototype declaration"); | |
6420 | } | |
51e29401 | 6421 | } |
ec2343c4 MM |
6422 | /* If -traditional, allow `int' argument to match |
6423 | `unsigned' prototype. */ | |
6424 | else if (! (flag_traditional | |
90d56da8 RS |
6425 | && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node |
6426 | && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)) | |
50a9145c JW |
6427 | { |
6428 | error ("argument `%s' doesn't match prototype", | |
6429 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
6430 | error_with_file_and_line (current_function_prototype_file, | |
6431 | current_function_prototype_line, | |
6432 | "prototype declaration"); | |
6433 | } | |
51e29401 RS |
6434 | } |
6435 | } | |
6436 | TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; | |
6437 | } | |
6438 | ||
6439 | /* Otherwise, create a prototype that would match. */ | |
6440 | ||
6441 | else | |
6442 | { | |
b8e605ab | 6443 | tree actual = 0, last = 0, type; |
51e29401 RS |
6444 | |
6445 | for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) | |
6446 | { | |
4dd7201e | 6447 | type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); |
51e29401 RS |
6448 | if (last) |
6449 | TREE_CHAIN (last) = type; | |
6450 | else | |
6451 | actual = type; | |
6452 | last = type; | |
6453 | } | |
4dd7201e | 6454 | type = tree_cons (NULL_TREE, void_type_node, NULL_TREE); |
51e29401 RS |
6455 | if (last) |
6456 | TREE_CHAIN (last) = type; | |
6457 | else | |
6458 | actual = type; | |
6459 | ||
c138f328 RS |
6460 | /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES |
6461 | of the type of this function, but we need to avoid having this | |
6462 | affect the types of other similarly-typed functions, so we must | |
6463 | first force the generation of an identical (but separate) type | |
6464 | node for the relevant function type. The new node we create | |
6465 | will be a variant of the main variant of the original function | |
6466 | type. */ | |
6467 | ||
929f3671 | 6468 | TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl)); |
c138f328 | 6469 | |
51e29401 RS |
6470 | TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual; |
6471 | } | |
6472 | ||
6473 | /* Now store the final chain of decls for the arguments | |
6474 | as the decl-chain of the current lexical scope. | |
6475 | Put the enumerators in as well, at the front so that | |
6476 | DECL_ARGUMENTS is not modified. */ | |
6477 | ||
6478 | storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); | |
6479 | } | |
6480 | ||
6481 | /* Make sure the binding level for the top of the function body | |
6482 | gets a BLOCK if there are any in the function. | |
6483 | Otherwise, the dbx output is wrong. */ | |
6484 | ||
6485 | keep_next_if_subblocks = 1; | |
6486 | ||
6487 | /* ??? This might be an improvement, | |
6488 | but needs to be thought about some more. */ | |
6489 | #if 0 | |
6490 | keep_next_level_flag = 1; | |
6491 | #endif | |
6492 | ||
6493 | /* Write a record describing this function definition to the prototypes | |
6494 | file (if requested). */ | |
6495 | ||
6496 | gen_aux_info_record (fndecl, 1, 0, prototype); | |
6497 | ||
6498 | /* Initialize the RTL code for the function. */ | |
6499 | ||
6500 | init_function_start (fndecl, input_filename, lineno); | |
6501 | ||
8f17b5c5 MM |
6502 | /* Begin the statement tree for this function. */ |
6503 | DECL_LANG_SPECIFIC (current_function_decl) | |
6504 | =((struct lang_decl *) ggc_alloc (sizeof (struct lang_decl))); | |
6505 | begin_stmt_tree (&DECL_SAVED_TREE (current_function_decl)); | |
51e29401 | 6506 | |
8f17b5c5 MM |
6507 | /* This function is being processed in whole-function mode. */ |
6508 | cfun->x_whole_function_mode_p = 1; | |
93e3ba4f | 6509 | |
8f17b5c5 MM |
6510 | /* Even though we're inside a function body, we still don't want to |
6511 | call expand_expr to calculate the size of a variable-sized array. | |
6512 | We haven't necessarily assigned RTL to all variables yet, so it's | |
6513 | not safe to try to expand expressions involving them. */ | |
6514 | immediate_size_expand = 0; | |
6515 | cfun->x_dont_save_pending_sizes_p = 1; | |
51e29401 RS |
6516 | } |
6517 | \f | |
6518 | /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes | |
6519 | each with a parm name as the TREE_VALUE. A null pointer as TREE_VALUE | |
6520 | stands for an ellipsis in the identifier list. | |
6521 | ||
6522 | PARMLIST is the data returned by get_parm_info for the | |
6523 | parmlist that follows the semicolon. | |
6524 | ||
6525 | We return a value of the same sort that get_parm_info returns, | |
6526 | except that it describes the combination of identifiers and parmlist. */ | |
6527 | ||
6528 | tree | |
6529 | combine_parm_decls (specparms, parmlist, void_at_end) | |
6530 | tree specparms, parmlist; | |
6531 | int void_at_end; | |
6532 | { | |
6533 | register tree fndecl = current_function_decl; | |
6534 | register tree parm; | |
6535 | ||
6536 | tree parmdecls = TREE_PURPOSE (parmlist); | |
6537 | ||
6538 | /* This is a chain of any other decls that came in among the parm | |
6539 | declarations. They were separated already by get_parm_info, | |
6540 | so we just need to keep them separate. */ | |
6541 | tree nonparms = TREE_VALUE (parmlist); | |
6542 | ||
6543 | tree types = 0; | |
6544 | ||
6545 | for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) | |
17aec3eb | 6546 | DECL_WEAK (parm) = 0; |
51e29401 RS |
6547 | |
6548 | for (parm = specparms; parm; parm = TREE_CHAIN (parm)) | |
6549 | { | |
6550 | register tree tail, found = NULL; | |
6551 | ||
6552 | /* See if any of the parmdecls specifies this parm by name. */ | |
6553 | for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) | |
6554 | if (DECL_NAME (tail) == TREE_VALUE (parm)) | |
6555 | { | |
6556 | found = tail; | |
6557 | break; | |
6558 | } | |
6559 | ||
6560 | /* If declaration already marked, we have a duplicate name. | |
6561 | Complain, and don't use this decl twice. */ | |
17aec3eb | 6562 | if (found && DECL_WEAK (found)) |
51e29401 RS |
6563 | { |
6564 | error_with_decl (found, "multiple parameters named `%s'"); | |
6565 | found = 0; | |
6566 | } | |
6567 | ||
6568 | /* If the declaration says "void", complain and ignore it. */ | |
71653180 | 6569 | if (found && VOID_TYPE_P (TREE_TYPE (found))) |
51e29401 RS |
6570 | { |
6571 | error_with_decl (found, "parameter `%s' declared void"); | |
6572 | TREE_TYPE (found) = integer_type_node; | |
6573 | DECL_ARG_TYPE (found) = integer_type_node; | |
6574 | layout_decl (found, 0); | |
6575 | } | |
6576 | ||
6577 | /* Traditionally, a parm declared float is actually a double. */ | |
6578 | if (found && flag_traditional | |
90d56da8 | 6579 | && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node) |
6d142a10 RS |
6580 | { |
6581 | TREE_TYPE (found) = double_type_node; | |
6582 | DECL_ARG_TYPE (found) = double_type_node; | |
6583 | layout_decl (found, 0); | |
6584 | } | |
51e29401 RS |
6585 | |
6586 | /* If no declaration found, default to int. */ | |
6587 | if (!found) | |
6588 | { | |
6589 | found = build_decl (PARM_DECL, TREE_VALUE (parm), | |
6590 | integer_type_node); | |
6591 | DECL_ARG_TYPE (found) = TREE_TYPE (found); | |
6592 | DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); | |
6593 | DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); | |
6b2a374b | 6594 | error_with_decl (found, "type of parameter `%s' is not declared"); |
51e29401 RS |
6595 | pushdecl (found); |
6596 | } | |
6597 | ||
6598 | TREE_PURPOSE (parm) = found; | |
6599 | ||
17aec3eb RK |
6600 | /* Mark this decl as "already found". */ |
6601 | DECL_WEAK (found) = 1; | |
51e29401 RS |
6602 | } |
6603 | ||
6604 | /* Complain about any actual PARM_DECLs not matched with any names. */ | |
6605 | ||
6645c3fa | 6606 | for (parm = parmdecls; parm;) |
51e29401 RS |
6607 | { |
6608 | tree next = TREE_CHAIN (parm); | |
6609 | TREE_CHAIN (parm) = 0; | |
6610 | ||
6611 | /* Complain about args with incomplete types. */ | |
d0f062fb | 6612 | if (!COMPLETE_TYPE_P (TREE_TYPE (parm))) |
51e29401 RS |
6613 | { |
6614 | error_with_decl (parm, "parameter `%s' has incomplete type"); | |
6615 | TREE_TYPE (parm) = error_mark_node; | |
6616 | } | |
6617 | ||
17aec3eb | 6618 | if (! DECL_WEAK (parm)) |
51e29401 RS |
6619 | { |
6620 | error_with_decl (parm, | |
6621 | "declaration for parameter `%s' but no such parameter"); | |
6622 | /* Pretend the parameter was not missing. | |
6623 | This gets us to a standard state and minimizes | |
6624 | further error messages. */ | |
6625 | specparms | |
6626 | = chainon (specparms, | |
6627 | tree_cons (parm, NULL_TREE, NULL_TREE)); | |
6628 | } | |
6629 | ||
6630 | parm = next; | |
6631 | } | |
6632 | ||
6633 | /* Chain the declarations together in the order of the list of names. | |
6634 | At the same time, build up a list of their types, in reverse order. */ | |
6635 | ||
6636 | parm = specparms; | |
6637 | parmdecls = 0; | |
6638 | { | |
6639 | register tree last; | |
6640 | for (last = 0; parm; parm = TREE_CHAIN (parm)) | |
6641 | if (TREE_PURPOSE (parm)) | |
6642 | { | |
6643 | if (last == 0) | |
6644 | parmdecls = TREE_PURPOSE (parm); | |
6645 | else | |
6646 | TREE_CHAIN (last) = TREE_PURPOSE (parm); | |
6647 | last = TREE_PURPOSE (parm); | |
6648 | TREE_CHAIN (last) = 0; | |
6649 | ||
4dd7201e | 6650 | types = tree_cons (NULL_TREE, TREE_TYPE (parm), types); |
51e29401 RS |
6651 | } |
6652 | } | |
6645c3fa | 6653 | |
51e29401 | 6654 | if (void_at_end) |
4dd7201e ZW |
6655 | return tree_cons (parmdecls, nonparms, |
6656 | nreverse (tree_cons (NULL_TREE, void_type_node, types))); | |
51e29401 | 6657 | |
4dd7201e | 6658 | return tree_cons (parmdecls, nonparms, nreverse (types)); |
51e29401 RS |
6659 | } |
6660 | \f | |
6661 | /* Finish up a function declaration and compile that function | |
6662 | all the way to assembler language output. The free the storage | |
6663 | for the function definition. | |
6664 | ||
6665 | This is called after parsing the body of the function definition. | |
6666 | ||
6667 | NESTED is nonzero if the function being finished is nested in another. */ | |
6668 | ||
6669 | void | |
6670 | finish_function (nested) | |
6671 | int nested; | |
6672 | { | |
6673 | register tree fndecl = current_function_decl; | |
6674 | ||
6675 | /* TREE_READONLY (fndecl) = 1; | |
6676 | This caused &foo to be of type ptr-to-const-function | |
6677 | which then got a warning when stored in a ptr-to-function variable. */ | |
6678 | ||
6679 | poplevel (1, 0, 1); | |
960a2eb1 | 6680 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; |
51e29401 RS |
6681 | |
6682 | /* Must mark the RESULT_DECL as being in this function. */ | |
6683 | ||
6684 | DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; | |
6685 | ||
6686 | /* Obey `register' declarations if `setjmp' is called in this fn. */ | |
6687 | if (flag_traditional && current_function_calls_setjmp) | |
6688 | { | |
6689 | setjmp_protect (DECL_INITIAL (fndecl)); | |
6690 | setjmp_protect_args (); | |
6691 | } | |
6692 | ||
5b47282c | 6693 | if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted) |
51e29401 | 6694 | { |
90d56da8 RS |
6695 | if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) |
6696 | != integer_type_node) | |
b8705e61 | 6697 | { |
007aaed0 | 6698 | /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned. |
6645c3fa | 6699 | If warn_main is -1 (-Wno-main) we don't want to be warned. */ |
b8705e61 RK |
6700 | if (! warn_main) |
6701 | pedwarn_with_decl (fndecl, "return type of `%s' is not `int'"); | |
6702 | } | |
8e077183 RS |
6703 | else |
6704 | { | |
cd4aafd5 | 6705 | #ifdef DEFAULT_MAIN_RETURN |
8e077183 RS |
6706 | /* Make it so that `main' always returns success by default. */ |
6707 | DEFAULT_MAIN_RETURN; | |
98be7846 JM |
6708 | #else |
6709 | if (flag_isoc99) | |
6710 | c_expand_return (integer_zero_node); | |
cd4aafd5 | 6711 | #endif |
8e077183 | 6712 | } |
51e29401 | 6713 | } |
51e29401 | 6714 | |
8f17b5c5 MM |
6715 | /* Tie off the statement tree for this function. */ |
6716 | finish_stmt_tree (&DECL_SAVED_TREE (fndecl)); | |
6717 | /* Clear out memory we no longer need. */ | |
6718 | free_after_parsing (cfun); | |
6719 | /* Since we never call rest_of_compilation, we never clear | |
6720 | CFUN. Do so explicitly. */ | |
6721 | free_after_compilation (cfun); | |
6722 | cfun = NULL; | |
6723 | ||
6724 | if (! nested) | |
6725 | { | |
6726 | /* Generate RTL for the body of this function. */ | |
6727 | c_expand_body (fndecl, nested); | |
6728 | /* Let the error reporting routines know that we're outside a | |
6729 | function. For a nested function, this value is used in | |
6730 | pop_c_function_context and then reset via pop_function_context. */ | |
6731 | current_function_decl = NULL; | |
69f4cc4b | 6732 | c_function_name_declared_p = 0; |
8f17b5c5 MM |
6733 | } |
6734 | } | |
6735 | ||
6736 | /* Generate the RTL for the body of FNDECL. If NESTED_P is non-zero, | |
6737 | then we are already in the process of generating RTL for another | |
6738 | function. */ | |
6739 | ||
6740 | static void | |
6741 | c_expand_body (fndecl, nested_p) | |
6742 | tree fndecl; | |
6743 | int nested_p; | |
6744 | { | |
f15b9af9 MM |
6745 | /* There's no reason to do any of the work here if we're only doing |
6746 | semantic analysis; this code just generates RTL. */ | |
6747 | if (flag_syntax_only) | |
6748 | return; | |
6749 | ||
8f17b5c5 MM |
6750 | /* Squirrel away our current state. */ |
6751 | if (nested_p) | |
6752 | push_function_context (); | |
6753 | ||
6754 | /* Initialize the RTL code for the function. */ | |
6755 | current_function_decl = fndecl; | |
a17a5850 | 6756 | init_function_start (fndecl, input_filename, DECL_SOURCE_LINE (fndecl)); |
8f17b5c5 MM |
6757 | |
6758 | /* This function is being processed in whole-function mode. */ | |
6759 | cfun->x_whole_function_mode_p = 1; | |
6760 | ||
6761 | /* Even though we're inside a function body, we still don't want to | |
6762 | call expand_expr to calculate the size of a variable-sized array. | |
6763 | We haven't necessarily assigned RTL to all variables yet, so it's | |
6764 | not safe to try to expand expressions involving them. */ | |
6765 | immediate_size_expand = 0; | |
6766 | cfun->x_dont_save_pending_sizes_p = 1; | |
6767 | ||
cfbd829c RH |
6768 | /* If this is a varargs function, inform function.c. */ |
6769 | if (c_function_varargs) | |
6770 | mark_varargs (); | |
6771 | ||
8f17b5c5 MM |
6772 | /* Set up parameters and prepare for return, for the function. */ |
6773 | expand_function_start (fndecl, 0); | |
6774 | ||
6775 | /* If this function is `main', emit a call to `__main' | |
6776 | to run global initializers, etc. */ | |
6777 | if (DECL_NAME (fndecl) | |
6778 | && MAIN_NAME_P (DECL_NAME (fndecl)) | |
6779 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
6780 | expand_main_function (); | |
6781 | ||
8f17b5c5 MM |
6782 | /* Generate the RTL for this function. */ |
6783 | expand_stmt (DECL_SAVED_TREE (fndecl)); | |
6784 | /* Allow the body of the function to be garbage collected. */ | |
6785 | DECL_SAVED_TREE (fndecl) = NULL_TREE; | |
6786 | ||
6787 | /* We hard-wired immediate_size_expand to zero in start_function. | |
6788 | expand_function_end will decrement this variable. So, we set the | |
6789 | variable to one here, so that after the decrement it will remain | |
6790 | zero. */ | |
6791 | immediate_size_expand = 1; | |
6792 | ||
6793 | /* Allow language dialects to perform special processing. */ | |
6794 | if (lang_expand_function_end) | |
6795 | (*lang_expand_function_end) (); | |
6796 | ||
51e29401 | 6797 | /* Generate rtl for function exit. */ |
0e5eedfe | 6798 | expand_function_end (input_filename, lineno, 0); |
51e29401 | 6799 | |
f4e5c65b RH |
6800 | /* If this is a nested function, protect the local variables in the stack |
6801 | above us from being collected while we're compiling this function. */ | |
8f17b5c5 | 6802 | if (nested_p) |
f4e5c65b RH |
6803 | ggc_push_context (); |
6804 | ||
51e29401 RS |
6805 | /* Run the optimizers and output the assembler code for this function. */ |
6806 | rest_of_compilation (fndecl); | |
6807 | ||
f4e5c65b | 6808 | /* Undo the GC context switch. */ |
8f17b5c5 | 6809 | if (nested_p) |
f4e5c65b RH |
6810 | ggc_pop_context (); |
6811 | ||
51e29401 RS |
6812 | /* With just -W, complain only if function returns both with |
6813 | and without a value. */ | |
b313a0fe RH |
6814 | if (extra_warnings |
6815 | && current_function_returns_value | |
6816 | && current_function_returns_null) | |
51e29401 RS |
6817 | warning ("this function may return with or without a value"); |
6818 | ||
739d15ab RK |
6819 | /* If requested, warn about function definitions where the function will |
6820 | return a value (usually of some struct or union type) which itself will | |
6821 | take up a lot of stack space. */ | |
6822 | ||
6823 | if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl)) | |
6824 | { | |
05bccae2 | 6825 | tree ret_type = TREE_TYPE (TREE_TYPE (fndecl)); |
739d15ab | 6826 | |
05bccae2 RK |
6827 | if (ret_type && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST |
6828 | && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type), | |
6829 | larger_than_size)) | |
739d15ab | 6830 | { |
05bccae2 RK |
6831 | unsigned int size_as_int |
6832 | = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type)); | |
739d15ab | 6833 | |
05bccae2 RK |
6834 | if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0) |
6835 | warning_with_decl (fndecl, | |
6836 | "size of return value of `%s' is %u bytes", | |
6837 | size_as_int); | |
6838 | else | |
6839 | warning_with_decl (fndecl, | |
6645c3fa | 6840 | "size of return value of `%s' is larger than %d bytes", |
05bccae2 | 6841 | larger_than_size); |
739d15ab RK |
6842 | } |
6843 | } | |
6844 | ||
8f17b5c5 | 6845 | if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested_p) |
51e29401 | 6846 | { |
6645c3fa | 6847 | /* Stop pointing to the local nodes about to be freed. |
05bccae2 | 6848 | But DECL_INITIAL must remain nonzero so we know this |
6645c3fa | 6849 | was an actual function definition. |
05bccae2 RK |
6850 | For a nested function, this is done in pop_c_function_context. |
6851 | If rest_of_compilation set this to 0, leave it 0. */ | |
708e813b RS |
6852 | if (DECL_INITIAL (fndecl) != 0) |
6853 | DECL_INITIAL (fndecl) = error_mark_node; | |
05bccae2 | 6854 | |
51e29401 RS |
6855 | DECL_ARGUMENTS (fndecl) = 0; |
6856 | } | |
6857 | ||
2c5f4139 JM |
6858 | if (DECL_STATIC_CONSTRUCTOR (fndecl)) |
6859 | { | |
6860 | #ifndef ASM_OUTPUT_CONSTRUCTOR | |
6861 | if (! flag_gnu_linker) | |
4dd7201e | 6862 | static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors); |
2c5f4139 JM |
6863 | else |
6864 | #endif | |
6645c3fa | 6865 | assemble_constructor (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))); |
c5c76735 | 6866 | |
2c5f4139 JM |
6867 | } |
6868 | if (DECL_STATIC_DESTRUCTOR (fndecl)) | |
6869 | { | |
6870 | #ifndef ASM_OUTPUT_DESTRUCTOR | |
6871 | if (! flag_gnu_linker) | |
4dd7201e | 6872 | static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors); |
2c5f4139 JM |
6873 | else |
6874 | #endif | |
c5c76735 | 6875 | assemble_destructor (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))); |
2c5f4139 JM |
6876 | } |
6877 | ||
8f17b5c5 | 6878 | if (nested_p) |
51e29401 | 6879 | { |
8f17b5c5 MM |
6880 | /* Return to the enclosing function. */ |
6881 | pop_function_context (); | |
6882 | /* If the nested function was inline, write it out if that is | |
6883 | necessary. */ | |
6884 | if (!TREE_ASM_WRITTEN (fndecl) && TREE_ADDRESSABLE (fndecl)) | |
6885 | { | |
6886 | push_function_context (); | |
6887 | output_inline_function (fndecl); | |
6888 | pop_function_context (); | |
6889 | } | |
51e29401 | 6890 | } |
8f17b5c5 | 6891 | |
51e29401 RS |
6892 | } |
6893 | \f | |
77c4d6c0 JM |
6894 | /* Check the declarations given in a for-loop for satisfying the C99 |
6895 | constraints. */ | |
6896 | void | |
6897 | check_for_loop_decls () | |
6898 | { | |
6899 | tree t; | |
6900 | ||
6901 | if (!flag_isoc99) | |
6902 | { | |
6903 | /* If we get here, declarations have been used in a for loop without | |
6904 | the C99 for loop scope. This doesn't make much sense, so don't | |
6905 | allow it. */ | |
6906 | error ("`for' loop initial declaration used outside C99 mode"); | |
6907 | return; | |
6908 | } | |
6909 | /* C99 subclause 6.8.5 paragraph 3: | |
6910 | ||
6911 | [#3] The declaration part of a for statement shall only | |
6912 | declare identifiers for objects having storage class auto or | |
6913 | register. | |
6914 | ||
6915 | It isn't clear whether, in this sentence, "identifiers" binds to | |
6916 | "shall only declare" or to "objects" - that is, whether all identifiers | |
6917 | declared must be identifiers for objects, or whether the restriction | |
6918 | only applies to those that are. (A question on this in comp.std.c | |
6919 | in November 2000 received no answer.) We implement the strictest | |
6920 | interpretation, to avoid creating an extension which later causes | |
6921 | problems. */ | |
6922 | ||
6923 | for (t = gettags (); t; t = TREE_CHAIN (t)) | |
6924 | { | |
6925 | if (TREE_PURPOSE (t) != 0) | |
6926 | error ("`%s %s' declared in `for' loop initial declaration", | |
6927 | (TREE_CODE (TREE_VALUE (t)) == RECORD_TYPE ? "struct" | |
6928 | : TREE_CODE (TREE_VALUE (t)) == UNION_TYPE ? "union" | |
6929 | : "enum"), | |
6930 | IDENTIFIER_POINTER (TREE_PURPOSE (t))); | |
6931 | } | |
6932 | for (t = getdecls (); t; t = TREE_CHAIN (t)) | |
6933 | { | |
6934 | if (TREE_CODE (t) != VAR_DECL && DECL_NAME (t)) | |
6935 | error_with_decl (t, "declaration of non-variable `%s' in `for' loop initial declaration"); | |
6936 | else if (TREE_STATIC (t)) | |
6937 | error_with_decl (t, "declaration of static variable `%s' in `for' loop initial declaration"); | |
6938 | else if (DECL_EXTERNAL (t)) | |
6939 | error_with_decl (t, "declaration of `extern' variable `%s' in `for' loop initial declaration"); | |
6940 | } | |
6941 | } | |
6942 | \f | |
51e29401 RS |
6943 | /* Save and restore the variables in this file and elsewhere |
6944 | that keep track of the progress of compilation of the current function. | |
6945 | Used for nested functions. */ | |
6946 | ||
ae499cce | 6947 | struct c_language_function |
51e29401 | 6948 | { |
ae499cce | 6949 | struct language_function base; |
51e29401 RS |
6950 | tree named_labels; |
6951 | tree shadowed_labels; | |
6952 | int returns_value; | |
6953 | int returns_null; | |
6954 | int warn_about_return_type; | |
6955 | int extern_inline; | |
6956 | struct binding_level *binding_level; | |
6957 | }; | |
6958 | ||
51e29401 RS |
6959 | /* Save and reinitialize the variables |
6960 | used during compilation of a C function. */ | |
6961 | ||
6962 | void | |
e2ecd91c BS |
6963 | push_c_function_context (f) |
6964 | struct function *f; | |
51e29401 | 6965 | { |
ae499cce MM |
6966 | struct c_language_function *p; |
6967 | p = ((struct c_language_function *) | |
6968 | xmalloc (sizeof (struct c_language_function))); | |
6969 | f->language = (struct language_function *) p; | |
51e29401 | 6970 | |
8f17b5c5 MM |
6971 | p->base.x_stmt_tree = c_stmt_tree; |
6972 | p->base.x_scope_stmt_stack = c_scope_stmt_stack; | |
6973 | p->base.x_function_name_declared_p = c_function_name_declared_p; | |
51e29401 RS |
6974 | p->named_labels = named_labels; |
6975 | p->shadowed_labels = shadowed_labels; | |
6976 | p->returns_value = current_function_returns_value; | |
6977 | p->returns_null = current_function_returns_null; | |
6978 | p->warn_about_return_type = warn_about_return_type; | |
6979 | p->extern_inline = current_extern_inline; | |
6980 | p->binding_level = current_binding_level; | |
6981 | } | |
6982 | ||
6983 | /* Restore the variables used during compilation of a C function. */ | |
6984 | ||
6985 | void | |
e2ecd91c BS |
6986 | pop_c_function_context (f) |
6987 | struct function *f; | |
51e29401 | 6988 | { |
ae499cce MM |
6989 | struct c_language_function *p |
6990 | = (struct c_language_function *) f->language; | |
51e29401 RS |
6991 | tree link; |
6992 | ||
6993 | /* Bring back all the labels that were shadowed. */ | |
6994 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
6995 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
6996 | IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) | |
6997 | = TREE_VALUE (link); | |
6998 | ||
8f17b5c5 MM |
6999 | if (DECL_SAVED_INSNS (current_function_decl) == 0 |
7000 | && DECL_SAVED_TREE (current_function_decl) == NULL_TREE) | |
51e29401 RS |
7001 | { |
7002 | /* Stop pointing to the local nodes about to be freed. */ | |
7003 | /* But DECL_INITIAL must remain nonzero so we know this | |
7004 | was an actual function definition. */ | |
7005 | DECL_INITIAL (current_function_decl) = error_mark_node; | |
7006 | DECL_ARGUMENTS (current_function_decl) = 0; | |
7007 | } | |
7008 | ||
8f17b5c5 MM |
7009 | c_stmt_tree = p->base.x_stmt_tree; |
7010 | c_scope_stmt_stack = p->base.x_scope_stmt_stack; | |
7011 | c_function_name_declared_p = p->base.x_function_name_declared_p; | |
51e29401 RS |
7012 | named_labels = p->named_labels; |
7013 | shadowed_labels = p->shadowed_labels; | |
7014 | current_function_returns_value = p->returns_value; | |
7015 | current_function_returns_null = p->returns_null; | |
7016 | warn_about_return_type = p->warn_about_return_type; | |
7017 | current_extern_inline = p->extern_inline; | |
7018 | current_binding_level = p->binding_level; | |
7019 | ||
7020 | free (p); | |
e2ecd91c | 7021 | f->language = 0; |
51e29401 | 7022 | } |
37105beb | 7023 | |
1526a060 | 7024 | /* Mark the language specific parts of F for GC. */ |
6645c3fa | 7025 | |
1526a060 BS |
7026 | void |
7027 | mark_c_function_context (f) | |
7028 | struct function *f; | |
7029 | { | |
ae499cce MM |
7030 | struct c_language_function *p |
7031 | = (struct c_language_function *) f->language; | |
1526a060 BS |
7032 | |
7033 | if (p == 0) | |
7034 | return; | |
7035 | ||
8f17b5c5 | 7036 | mark_c_language_function (&p->base); |
1526a060 BS |
7037 | ggc_mark_tree (p->shadowed_labels); |
7038 | ggc_mark_tree (p->named_labels); | |
7039 | mark_binding_level (&p->binding_level); | |
7040 | } | |
7041 | ||
8f17b5c5 | 7042 | /* Copy the DECL_LANG_SEPECIFIC data associated with NODE. */ |
37105beb JM |
7043 | |
7044 | void | |
8f17b5c5 MM |
7045 | copy_lang_decl (decl) |
7046 | tree decl; | |
37105beb | 7047 | { |
8f17b5c5 MM |
7048 | struct lang_decl *ld; |
7049 | ||
7050 | if (!DECL_LANG_SPECIFIC (decl)) | |
7051 | return; | |
7052 | ||
7053 | ld = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl)); | |
da61dec9 JM |
7054 | memcpy ((char *) ld, (char *) DECL_LANG_SPECIFIC (decl), |
7055 | sizeof (struct lang_decl)); | |
8f17b5c5 | 7056 | DECL_LANG_SPECIFIC (decl) = ld; |
37105beb | 7057 | } |
1526a060 | 7058 | |
1526a060 | 7059 | /* Mark the language specific bits in T for GC. */ |
6645c3fa | 7060 | |
1526a060 BS |
7061 | void |
7062 | lang_mark_tree (t) | |
7063 | tree t; | |
7064 | { | |
7065 | if (TREE_CODE (t) == IDENTIFIER_NODE) | |
7066 | { | |
7067 | struct lang_identifier *i = (struct lang_identifier *) t; | |
7068 | ggc_mark_tree (i->global_value); | |
7069 | ggc_mark_tree (i->local_value); | |
7070 | ggc_mark_tree (i->label_value); | |
7071 | ggc_mark_tree (i->implicit_decl); | |
7072 | ggc_mark_tree (i->error_locus); | |
7073 | ggc_mark_tree (i->limbo_value); | |
7074 | } | |
96603b4c MM |
7075 | else if (TYPE_P (t) && TYPE_LANG_SPECIFIC (t)) |
7076 | ggc_mark (TYPE_LANG_SPECIFIC (t)); | |
8f17b5c5 MM |
7077 | else if (DECL_P (t) && DECL_LANG_SPECIFIC (t)) |
7078 | { | |
7079 | ggc_mark (DECL_LANG_SPECIFIC (t)); | |
7080 | c_mark_lang_decl (&DECL_LANG_SPECIFIC (t)->base); | |
7081 | } | |
1526a060 | 7082 | } |
f2c5f623 BC |
7083 | |
7084 | /* The functions below are required for functionality of doing | |
7085 | function at once processing in the C front end. Currently these | |
7086 | functions are not called from anywhere in the C front end, but as | |
6645c3fa | 7087 | these changes continue, that will change. */ |
f2c5f623 BC |
7088 | |
7089 | /* Returns non-zero if the current statement is a full expression, | |
7090 | i.e. temporaries created during that statement should be destroyed | |
7091 | at the end of the statement. */ | |
7092 | ||
7093 | int | |
7094 | stmts_are_full_exprs_p () | |
7095 | { | |
7096 | return 0; | |
7097 | } | |
7098 | ||
ae499cce MM |
7099 | /* Returns the stmt_tree (if any) to which statements are currently |
7100 | being added. If there is no active statement-tree, NULL is | |
7101 | returned. */ | |
7102 | ||
7103 | stmt_tree | |
7104 | current_stmt_tree () | |
7105 | { | |
8f17b5c5 MM |
7106 | return &c_stmt_tree; |
7107 | } | |
7108 | ||
7109 | /* Returns the stack of SCOPE_STMTs for the current function. */ | |
7110 | ||
7111 | tree * | |
7112 | current_scope_stmt_stack () | |
7113 | { | |
7114 | return &c_scope_stmt_stack; | |
ae499cce MM |
7115 | } |
7116 | ||
f2c5f623 | 7117 | /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in |
6645c3fa | 7118 | C. */ |
f2c5f623 | 7119 | |
6645c3fa | 7120 | int |
f2c5f623 | 7121 | anon_aggr_type_p (node) |
20217ac1 | 7122 | tree node ATTRIBUTE_UNUSED; |
f2c5f623 BC |
7123 | { |
7124 | return 0; | |
7125 | } | |
7126 | ||
8f17b5c5 | 7127 | /* Dummy function in place of callback used by C++. */ |
f2c5f623 | 7128 | |
8f17b5c5 MM |
7129 | void |
7130 | extract_interface_info () | |
f2c5f623 | 7131 | { |
f2c5f623 BC |
7132 | } |
7133 | ||
8f17b5c5 MM |
7134 | /* Return a new COMPOUND_STMT, after adding it to the current |
7135 | statement tree. */ | |
f2c5f623 | 7136 | |
8f17b5c5 MM |
7137 | tree |
7138 | c_begin_compound_stmt () | |
f2c5f623 | 7139 | { |
8f17b5c5 | 7140 | tree stmt; |
6645c3fa | 7141 | |
8f17b5c5 MM |
7142 | /* Create the COMPOUND_STMT. */ |
7143 | stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE)); | |
7144 | /* If we haven't already declared __FUNCTION__ and its ilk then this | |
7145 | is the opening curly brace of the function. Declare them now. */ | |
7146 | if (!c_function_name_declared_p) | |
0dfdeca6 | 7147 | { |
8f17b5c5 MM |
7148 | c_function_name_declared_p = 1; |
7149 | declare_function_name (); | |
0dfdeca6 | 7150 | } |
8f17b5c5 MM |
7151 | |
7152 | return stmt; | |
f2c5f623 BC |
7153 | } |
7154 | ||
8f17b5c5 MM |
7155 | /* Expand T (a DECL_STMT) if it declares an entity not handled by the |
7156 | common code. */ | |
f2c5f623 BC |
7157 | |
7158 | void | |
8f17b5c5 MM |
7159 | c_expand_decl_stmt (t) |
7160 | tree t; | |
0e5921e8 | 7161 | { |
8f17b5c5 MM |
7162 | tree decl = DECL_STMT_DECL (t); |
7163 | ||
7164 | /* Expand nested functions. */ | |
7165 | if (TREE_CODE (decl) == FUNCTION_DECL | |
7166 | && DECL_CONTEXT (decl) == current_function_decl | |
7167 | && DECL_SAVED_TREE (decl)) | |
7168 | c_expand_body (decl, /*nested_p=*/1); | |
0e5921e8 | 7169 | } |
5fd8e536 JM |
7170 | |
7171 | /* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since | |
7172 | the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */ | |
7173 | ||
7174 | tree | |
7175 | identifier_global_value (t) | |
7176 | tree t; | |
7177 | { | |
7178 | return IDENTIFIER_GLOBAL_VALUE (t); | |
7179 | } |