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