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