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