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