Initial revision
[official-gcc.git] / gcc / c-decl.c
blob5f9d2faf29c42fcb588379b04a7fea1b5c0dffd9
1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
29 #include "config.h"
30 #include "system.h"
31 #include "tree.h"
32 #include "flags.h"
33 #include "output.h"
34 #include "c-tree.h"
35 #include "c-lex.h"
36 #include "toplev.h"
38 #if USE_CPPLIB
39 #include "cpplib.h"
40 extern cpp_reader parse_in;
41 #endif
43 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
44 enum decl_context
45 { NORMAL, /* Ordinary declaration */
46 FUNCDEF, /* Function definition */
47 PARM, /* Declaration of parm before function body */
48 FIELD, /* Declaration inside struct or union */
49 BITFIELD, /* Likewise but with specified width */
50 TYPENAME}; /* Typename (inside cast or sizeof) */
52 #ifndef CHAR_TYPE_SIZE
53 #define CHAR_TYPE_SIZE BITS_PER_UNIT
54 #endif
56 #ifndef SHORT_TYPE_SIZE
57 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
58 #endif
60 #ifndef INT_TYPE_SIZE
61 #define INT_TYPE_SIZE BITS_PER_WORD
62 #endif
64 #ifndef LONG_TYPE_SIZE
65 #define LONG_TYPE_SIZE BITS_PER_WORD
66 #endif
68 #ifndef LONG_LONG_TYPE_SIZE
69 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
70 #endif
72 #ifndef WCHAR_UNSIGNED
73 #define WCHAR_UNSIGNED 0
74 #endif
76 #ifndef FLOAT_TYPE_SIZE
77 #define FLOAT_TYPE_SIZE BITS_PER_WORD
78 #endif
80 #ifndef DOUBLE_TYPE_SIZE
81 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
82 #endif
84 #ifndef LONG_DOUBLE_TYPE_SIZE
85 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
86 #endif
88 /* We let tm.h override the types used here, to handle trivial differences
89 such as the choice of unsigned int or long unsigned int for size_t.
90 When machines start needing nontrivial differences in the size type,
91 it would be best to do something here to figure out automatically
92 from other information what type to use. */
94 #ifndef SIZE_TYPE
95 #define SIZE_TYPE "long unsigned int"
96 #endif
98 #ifndef PTRDIFF_TYPE
99 #define PTRDIFF_TYPE "long int"
100 #endif
102 #ifndef WCHAR_TYPE
103 #define WCHAR_TYPE "int"
104 #endif
106 /* a node which has tree code ERROR_MARK, and whose type is itself.
107 All erroneous expressions are replaced with this node. All functions
108 that accept nodes as arguments should avoid generating error messages
109 if this node is one of the arguments, since it is undesirable to get
110 multiple error messages from one error in the input. */
112 tree error_mark_node;
114 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
116 tree short_integer_type_node;
117 tree integer_type_node;
118 tree long_integer_type_node;
119 tree long_long_integer_type_node;
121 tree short_unsigned_type_node;
122 tree unsigned_type_node;
123 tree long_unsigned_type_node;
124 tree long_long_unsigned_type_node;
126 tree boolean_type_node;
127 tree boolean_false_node;
128 tree boolean_true_node;
130 tree ptrdiff_type_node;
132 tree unsigned_char_type_node;
133 tree signed_char_type_node;
134 tree char_type_node;
135 tree wchar_type_node;
136 tree signed_wchar_type_node;
137 tree unsigned_wchar_type_node;
139 tree float_type_node;
140 tree double_type_node;
141 tree long_double_type_node;
143 tree complex_integer_type_node;
144 tree complex_float_type_node;
145 tree complex_double_type_node;
146 tree complex_long_double_type_node;
148 tree intQI_type_node;
149 tree intHI_type_node;
150 tree intSI_type_node;
151 tree intDI_type_node;
152 #if HOST_BITS_PER_WIDE_INT >= 64
153 tree intTI_type_node;
154 #endif
156 tree unsigned_intQI_type_node;
157 tree unsigned_intHI_type_node;
158 tree unsigned_intSI_type_node;
159 tree unsigned_intDI_type_node;
160 #if HOST_BITS_PER_WIDE_INT >= 64
161 tree unsigned_intTI_type_node;
162 #endif
164 /* a VOID_TYPE node. */
166 tree void_type_node;
168 /* Nodes for types `void *' and `const void *'. */
170 tree ptr_type_node, const_ptr_type_node;
172 /* Nodes for types `char *' and `const char *'. */
174 tree string_type_node, const_string_type_node;
176 /* Type `char[SOMENUMBER]'.
177 Used when an array of char is needed and the size is irrelevant. */
179 tree char_array_type_node;
181 /* Type `int[SOMENUMBER]' or something like it.
182 Used when an array of int needed and the size is irrelevant. */
184 tree int_array_type_node;
186 /* Type `wchar_t[SOMENUMBER]' or something like it.
187 Used when a wide string literal is created. */
189 tree wchar_array_type_node;
191 /* type `int ()' -- used for implicit declaration of functions. */
193 tree default_function_type;
195 /* function types `double (double)' and `double (double, double)', etc. */
197 tree double_ftype_double, double_ftype_double_double;
198 tree int_ftype_int, long_ftype_long;
199 tree float_ftype_float;
200 tree ldouble_ftype_ldouble;
202 /* Function type `void (void *, void *, int)' and similar ones */
204 tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
206 /* Function type `char *(char *, char *)' and similar ones */
207 tree string_ftype_ptr_ptr, int_ftype_string_string;
209 /* Function type `int (const void *, const void *, size_t)' */
210 tree int_ftype_cptr_cptr_sizet;
212 /* Two expressions that are constants with value zero.
213 The first is of type `int', the second of type `void *'. */
215 tree integer_zero_node;
216 tree null_pointer_node;
218 /* A node for the integer constant 1. */
220 tree integer_one_node;
222 /* Nonzero if we have seen an invalid cross reference
223 to a struct, union, or enum, but not yet printed the message. */
225 tree pending_invalid_xref;
226 /* File and line to appear in the eventual error message. */
227 char *pending_invalid_xref_file;
228 int pending_invalid_xref_line;
230 /* While defining an enum type, this is 1 plus the last enumerator
231 constant value. Note that will do not have to save this or `enum_overflow'
232 around nested function definition since such a definition could only
233 occur in an enum value expression and we don't use these variables in
234 that case. */
236 static tree enum_next_value;
238 /* Nonzero means that there was overflow computing enum_next_value. */
240 static int enum_overflow;
242 /* Parsing a function declarator leaves a list of parameter names
243 or a chain or parameter decls here. */
245 static tree last_function_parms;
247 /* Parsing a function declarator leaves here a chain of structure
248 and enum types declared in the parmlist. */
250 static tree last_function_parm_tags;
252 /* After parsing the declarator that starts a function definition,
253 `start_function' puts here the list of parameter names or chain of decls.
254 `store_parm_decls' finds it here. */
256 static tree current_function_parms;
258 /* Similar, for last_function_parm_tags. */
259 static tree current_function_parm_tags;
261 /* Similar, for the file and line that the prototype came from if this is
262 an old-style definition. */
263 static char *current_function_prototype_file;
264 static int current_function_prototype_line;
266 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
267 that have names. Here so we can clear out their names' definitions
268 at the end of the function. */
270 static tree named_labels;
272 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
274 static tree shadowed_labels;
276 /* Nonzero when store_parm_decls is called indicates a varargs function.
277 Value not meaningful after store_parm_decls. */
279 static int c_function_varargs;
281 /* The FUNCTION_DECL for the function currently being compiled,
282 or 0 if between functions. */
283 tree current_function_decl;
285 /* Set to 0 at beginning of a function definition, set to 1 if
286 a return statement that specifies a return value is seen. */
288 int current_function_returns_value;
290 /* Set to 0 at beginning of a function definition, set to 1 if
291 a return statement with no argument is seen. */
293 int current_function_returns_null;
295 /* Set to nonzero by `grokdeclarator' for a function
296 whose return type is defaulted, if warnings for this are desired. */
298 static int warn_about_return_type;
300 /* Nonzero when starting a function declared `extern inline'. */
302 static int current_extern_inline;
304 /* For each binding contour we allocate a binding_level structure
305 * which records the names defined in that contour.
306 * Contours include:
307 * 0) the global one
308 * 1) one for each function definition,
309 * where internal declarations of the parameters appear.
310 * 2) one for each compound statement,
311 * to record its declarations.
313 * The current meaning of a name can be found by searching the levels from
314 * the current one out to the global one.
317 /* Note that the information in the `names' component of the global contour
318 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
320 struct binding_level
322 /* A chain of _DECL nodes for all variables, constants, functions,
323 and typedef types. These are in the reverse of the order supplied.
325 tree names;
327 /* A list of structure, union and enum definitions,
328 * for looking up tag names.
329 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
330 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
331 * or ENUMERAL_TYPE node.
333 tree tags;
335 /* For each level, a list of shadowed outer-level local definitions
336 to be restored when this level is popped.
337 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
338 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
339 tree shadowed;
341 /* For each level (except not the global one),
342 a chain of BLOCK nodes for all the levels
343 that were entered and exited one level down. */
344 tree blocks;
346 /* The BLOCK node for this level, if one has been preallocated.
347 If 0, the BLOCK is allocated (if needed) when the level is popped. */
348 tree this_block;
350 /* The binding level which this one is contained in (inherits from). */
351 struct binding_level *level_chain;
353 /* Nonzero for the level that holds the parameters of a function. */
354 char parm_flag;
356 /* Nonzero if this level "doesn't exist" for tags. */
357 char tag_transparent;
359 /* Nonzero if sublevels of this level "don't exist" for tags.
360 This is set in the parm level of a function definition
361 while reading the function body, so that the outermost block
362 of the function body will be tag-transparent. */
363 char subblocks_tag_transparent;
365 /* Nonzero means make a BLOCK for this level regardless of all else. */
366 char keep;
368 /* Nonzero means make a BLOCK if this level has any subblocks. */
369 char keep_if_subblocks;
371 /* Number of decls in `names' that have incomplete
372 structure or union types. */
373 int n_incomplete;
375 /* A list of decls giving the (reversed) specified order of parms,
376 not including any forward-decls in the parmlist.
377 This is so we can put the parms in proper order for assign_parms. */
378 tree parm_order;
381 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
383 /* The binding level currently in effect. */
385 static struct binding_level *current_binding_level;
387 /* A chain of binding_level structures awaiting reuse. */
389 static struct binding_level *free_binding_level;
391 /* The outermost binding level, for names of file scope.
392 This is created when the compiler is started and exists
393 through the entire run. */
395 static struct binding_level *global_binding_level;
397 /* Binding level structures are initialized by copying this one. */
399 static struct binding_level clear_binding_level
400 = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0,
401 NULL};
403 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
405 static int keep_next_level_flag;
407 /* Nonzero means make a BLOCK for the next level pushed
408 if it has subblocks. */
410 static int keep_next_if_subblocks;
412 /* The chain of outer levels of label scopes.
413 This uses the same data structure used for binding levels,
414 but it works differently: each link in the chain records
415 saved values of named_labels and shadowed_labels for
416 a label binding level outside the current one. */
418 static struct binding_level *label_level_chain;
420 /* Functions called automatically at the beginning and end of execution. */
422 tree static_ctors, static_dtors;
424 /* Forward declarations. */
426 static struct binding_level * make_binding_level PROTO((void));
427 static void clear_limbo_values PROTO((tree));
428 static int duplicate_decls PROTO((tree, tree, int));
429 static int redeclaration_error_message PROTO((tree, tree));
430 static void storedecls PROTO((tree));
431 static void storetags PROTO((tree));
432 static tree lookup_tag PROTO((enum tree_code, tree,
433 struct binding_level *, int));
434 static tree lookup_tag_reverse PROTO((tree));
435 static tree grokdeclarator PROTO((tree, tree, enum decl_context,
436 int));
437 static tree grokparms PROTO((tree, int));
438 static int field_decl_cmp PROTO((const GENERIC_PTR, const GENERIC_PTR));
439 static void layout_array_type PROTO((tree));
441 /* C-specific option variables. */
443 /* Nonzero means allow type mismatches in conditional expressions;
444 just make their values `void'. */
446 int flag_cond_mismatch;
448 /* Nonzero means give `double' the same size as `float'. */
450 int flag_short_double;
452 /* Nonzero means don't recognize the keyword `asm'. */
454 int flag_no_asm;
456 /* Nonzero means don't recognize any builtin functions. */
458 int flag_no_builtin;
460 /* Nonzero means don't recognize the non-ANSI builtin functions.
461 -ansi sets this. */
463 int flag_no_nonansi_builtin;
465 /* Nonzero means do some things the same way PCC does. */
467 int flag_traditional;
469 /* Nonzero means use the ISO C9x dialect of C. */
471 int flag_isoc9x = 0;
473 /* Nonzero means that we have builtin functions, and main is an int */
475 int flag_hosted = 1;
477 /* Nonzero means to allow single precision math even if we're generally
478 being traditional. */
479 int flag_allow_single_precision = 0;
481 /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
483 int flag_signed_bitfields = 1;
484 int explicit_flag_signed_bitfields = 0;
486 /* Nonzero means warn about use of implicit int. */
488 int warn_implicit_int;
490 /* Nonzero means warn about usage of long long when `-pedantic'. */
492 int warn_long_long = 1;
494 /* Nonzero means message about use of implicit function declarations;
495 1 means warning; 2 means error. */
497 int mesg_implicit_function_declaration;
499 /* Nonzero means give string constants the type `const char *'
500 to get extra warnings from them. These warnings will be too numerous
501 to be useful, except in thoroughly ANSIfied programs. */
503 int flag_const_strings;
505 /* Nonzero means warn about pointer casts that can drop a type qualifier
506 from the pointer target type. */
508 int warn_cast_qual;
510 /* Nonzero means warn when casting a function call to a type that does
511 not match the return type (e.g. (float)sqrt() or (anything*)malloc()
512 when there is no previous declaration of sqrt or malloc. */
514 int warn_bad_function_cast;
516 /* Warn about functions which might be candidates for attribute noreturn. */
518 int warn_missing_noreturn;
520 /* Warn about traditional constructs whose meanings changed in ANSI C. */
522 int warn_traditional;
524 /* Nonzero means warn about sizeof(function) or addition/subtraction
525 of function pointers. */
527 int warn_pointer_arith;
529 /* Nonzero means warn for non-prototype function decls
530 or non-prototyped defs without previous prototype. */
532 int warn_strict_prototypes;
534 /* Nonzero means warn for any global function def
535 without separate previous prototype decl. */
537 int warn_missing_prototypes;
539 /* Nonzero means warn for any global function def
540 without separate previous decl. */
542 int warn_missing_declarations;
544 /* Nonzero means warn about multiple (redundant) decls for the same single
545 variable or function. */
547 int warn_redundant_decls = 0;
549 /* Nonzero means warn about extern declarations of objects not at
550 file-scope level and about *all* declarations of functions (whether
551 extern or static) not at file-scope level. Note that we exclude
552 implicit function declarations. To get warnings about those, use
553 -Wimplicit. */
555 int warn_nested_externs = 0;
557 /* Warn about *printf or *scanf format/argument anomalies. */
559 int warn_format;
561 /* Warn about a subscript that has type char. */
563 int warn_char_subscripts = 0;
565 /* Warn if a type conversion is done that might have confusing results. */
567 int warn_conversion;
569 /* Warn if adding () is suggested. */
571 int warn_parentheses;
573 /* Warn if initializer is not completely bracketed. */
575 int warn_missing_braces;
577 /* Warn if main is suspicious. */
579 int warn_main;
581 /* Warn about #pragma directives that are not recognised. */
583 int warn_unknown_pragmas = 0; /* Tri state variable. */
585 /* Warn about comparison of signed and unsigned values.
586 If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */
588 int warn_sign_compare = -1;
590 /* Nonzero means warn about use of multicharacter literals. */
592 int warn_multichar = 1;
594 /* Nonzero means `$' can be in an identifier. */
596 #ifndef DOLLARS_IN_IDENTIFIERS
597 #define DOLLARS_IN_IDENTIFIERS 1
598 #endif
599 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
601 /* Decode the string P as a language-specific option for C.
602 Return the number of strings consumed. */
605 c_decode_option (argc, argv)
606 int argc ATTRIBUTE_UNUSED;
607 char **argv;
609 int strings_processed;
610 char *p = argv[0];
611 #if USE_CPPLIB
612 strings_processed = cpp_handle_option (&parse_in, argc, argv);
613 #else
614 strings_processed = 0;
615 #endif /* ! USE_CPPLIB */
617 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
619 flag_traditional = 1;
620 flag_writable_strings = 1;
622 else if (!strcmp (p, "-fallow-single-precision"))
623 flag_allow_single_precision = 1;
624 else if (!strcmp (p, "-fhosted") || !strcmp (p, "-fno-freestanding"))
626 flag_hosted = 1;
627 flag_no_builtin = 0;
629 else if (!strcmp (p, "-ffreestanding") || !strcmp (p, "-fno-hosted"))
631 flag_hosted = 0;
632 flag_no_builtin = 1;
633 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
634 if (warn_main == 2)
635 warn_main = 0;
637 else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional"))
639 flag_traditional = 0;
640 flag_writable_strings = 0;
642 else if (!strncmp (p, "-std=", 5))
644 /* Select the appropriate language standard. We currently
645 recognize:
646 -std=iso9899:1990 same as -ansi
647 -std=iso9899:199409 ISO C as modified in amend. 1
648 -std=iso9899:199x ISO C 9x
649 -std=c89 same as -std=iso9899:1990
650 -std=c9x same as -std=iso9899:199x
651 -std=gnu89 default, iso9899:1990 + gnu extensions
652 -std=gnu9x iso9899:199x + gnu extensions
654 const char *argstart = &p[5];
656 if (!strcmp (argstart, "iso9899:1990")
657 || !strcmp (argstart, "c89"))
659 iso_1990:
660 flag_traditional = 0;
661 flag_writable_strings = 0;
662 flag_no_asm = 1;
663 flag_no_nonansi_builtin = 1;
664 flag_isoc9x = 0;
666 else if (!strcmp (argstart, "iso9899:199409"))
668 /* ??? The changes since ISO C 1990 are not supported. */
669 goto iso_1990;
671 else if (!strcmp (argstart, "iso9899:199x")
672 || !strcmp (argstart, "c9x"))
674 flag_traditional = 0;
675 flag_writable_strings = 0;
676 flag_no_asm = 1;
677 flag_no_nonansi_builtin = 1;
678 flag_isoc9x = 1;
680 else if (!strcmp (argstart, "gnu89"))
682 flag_traditional = 0;
683 flag_writable_strings = 0;
684 flag_no_asm = 0;
685 flag_no_nonansi_builtin = 0;
686 flag_isoc9x = 0;
688 else if (!strcmp (argstart, "gnu9x"))
690 flag_traditional = 0;
691 flag_writable_strings = 0;
692 flag_no_asm = 0;
693 flag_no_nonansi_builtin = 0;
694 flag_isoc9x = 1;
696 else
697 error ("unknown C standard `%s'", argstart);
699 else if (!strcmp (p, "-fdollars-in-identifiers"))
700 dollars_in_ident = 1;
701 else if (!strcmp (p, "-fno-dollars-in-identifiers"))
702 dollars_in_ident = 0;
703 else if (!strcmp (p, "-fsigned-char"))
704 flag_signed_char = 1;
705 else if (!strcmp (p, "-funsigned-char"))
706 flag_signed_char = 0;
707 else if (!strcmp (p, "-fno-signed-char"))
708 flag_signed_char = 0;
709 else if (!strcmp (p, "-fno-unsigned-char"))
710 flag_signed_char = 1;
711 else if (!strcmp (p, "-fsigned-bitfields")
712 || !strcmp (p, "-fno-unsigned-bitfields"))
714 flag_signed_bitfields = 1;
715 explicit_flag_signed_bitfields = 1;
717 else if (!strcmp (p, "-funsigned-bitfields")
718 || !strcmp (p, "-fno-signed-bitfields"))
720 flag_signed_bitfields = 0;
721 explicit_flag_signed_bitfields = 1;
723 else if (!strcmp (p, "-fshort-enums"))
724 flag_short_enums = 1;
725 else if (!strcmp (p, "-fno-short-enums"))
726 flag_short_enums = 0;
727 else if (!strcmp (p, "-fcond-mismatch"))
728 flag_cond_mismatch = 1;
729 else if (!strcmp (p, "-fno-cond-mismatch"))
730 flag_cond_mismatch = 0;
731 else if (!strcmp (p, "-fshort-double"))
732 flag_short_double = 1;
733 else if (!strcmp (p, "-fno-short-double"))
734 flag_short_double = 0;
735 else if (!strcmp (p, "-fasm"))
736 flag_no_asm = 0;
737 else if (!strcmp (p, "-fno-asm"))
738 flag_no_asm = 1;
739 else if (!strcmp (p, "-fbuiltin"))
740 flag_no_builtin = 0;
741 else if (!strcmp (p, "-fno-builtin"))
742 flag_no_builtin = 1;
743 else if (!strcmp (p, "-ansi"))
744 goto iso_1990;
745 else if (!strcmp (p, "-Werror-implicit-function-declaration"))
746 mesg_implicit_function_declaration = 2;
747 else if (!strcmp (p, "-Wimplicit-function-declaration"))
748 mesg_implicit_function_declaration = 1;
749 else if (!strcmp (p, "-Wno-implicit-function-declaration"))
750 mesg_implicit_function_declaration = 0;
751 else if (!strcmp (p, "-Wimplicit-int"))
752 warn_implicit_int = 1;
753 else if (!strcmp (p, "-Wno-implicit-int"))
754 warn_implicit_int = 0;
755 else if (!strcmp (p, "-Wimplicit"))
757 warn_implicit_int = 1;
758 if (mesg_implicit_function_declaration != 2)
759 mesg_implicit_function_declaration = 1;
761 else if (!strcmp (p, "-Wno-implicit"))
762 warn_implicit_int = 0, mesg_implicit_function_declaration = 0;
763 else if (!strcmp (p, "-Wlong-long"))
764 warn_long_long = 1;
765 else if (!strcmp (p, "-Wno-long-long"))
766 warn_long_long = 0;
767 else if (!strcmp (p, "-Wwrite-strings"))
768 flag_const_strings = 1;
769 else if (!strcmp (p, "-Wno-write-strings"))
770 flag_const_strings = 0;
771 else if (!strcmp (p, "-Wcast-qual"))
772 warn_cast_qual = 1;
773 else if (!strcmp (p, "-Wno-cast-qual"))
774 warn_cast_qual = 0;
775 else if (!strcmp (p, "-Wbad-function-cast"))
776 warn_bad_function_cast = 1;
777 else if (!strcmp (p, "-Wno-bad-function-cast"))
778 warn_bad_function_cast = 0;
779 else if (!strcmp (p, "-Wmissing-noreturn"))
780 warn_missing_noreturn = 1;
781 else if (!strcmp (p, "-Wno-missing-noreturn"))
782 warn_missing_noreturn = 0;
783 else if (!strcmp (p, "-Wpointer-arith"))
784 warn_pointer_arith = 1;
785 else if (!strcmp (p, "-Wno-pointer-arith"))
786 warn_pointer_arith = 0;
787 else if (!strcmp (p, "-Wstrict-prototypes"))
788 warn_strict_prototypes = 1;
789 else if (!strcmp (p, "-Wno-strict-prototypes"))
790 warn_strict_prototypes = 0;
791 else if (!strcmp (p, "-Wmissing-prototypes"))
792 warn_missing_prototypes = 1;
793 else if (!strcmp (p, "-Wno-missing-prototypes"))
794 warn_missing_prototypes = 0;
795 else if (!strcmp (p, "-Wmissing-declarations"))
796 warn_missing_declarations = 1;
797 else if (!strcmp (p, "-Wno-missing-declarations"))
798 warn_missing_declarations = 0;
799 else if (!strcmp (p, "-Wredundant-decls"))
800 warn_redundant_decls = 1;
801 else if (!strcmp (p, "-Wno-redundant-decls"))
802 warn_redundant_decls = 0;
803 else if (!strcmp (p, "-Wnested-externs"))
804 warn_nested_externs = 1;
805 else if (!strcmp (p, "-Wno-nested-externs"))
806 warn_nested_externs = 0;
807 else if (!strcmp (p, "-Wtraditional"))
808 warn_traditional = 1;
809 else if (!strcmp (p, "-Wno-traditional"))
810 warn_traditional = 0;
811 else if (!strcmp (p, "-Wformat"))
812 warn_format = 1;
813 else if (!strcmp (p, "-Wno-format"))
814 warn_format = 0;
815 else if (!strcmp (p, "-Wchar-subscripts"))
816 warn_char_subscripts = 1;
817 else if (!strcmp (p, "-Wno-char-subscripts"))
818 warn_char_subscripts = 0;
819 else if (!strcmp (p, "-Wconversion"))
820 warn_conversion = 1;
821 else if (!strcmp (p, "-Wno-conversion"))
822 warn_conversion = 0;
823 else if (!strcmp (p, "-Wparentheses"))
824 warn_parentheses = 1;
825 else if (!strcmp (p, "-Wno-parentheses"))
826 warn_parentheses = 0;
827 else if (!strcmp (p, "-Wreturn-type"))
828 warn_return_type = 1;
829 else if (!strcmp (p, "-Wno-return-type"))
830 warn_return_type = 0;
831 else if (!strcmp (p, "-Wcomment"))
832 ; /* cpp handles this one. */
833 else if (!strcmp (p, "-Wno-comment"))
834 ; /* cpp handles this one. */
835 else if (!strcmp (p, "-Wcomments"))
836 ; /* cpp handles this one. */
837 else if (!strcmp (p, "-Wno-comments"))
838 ; /* cpp handles this one. */
839 else if (!strcmp (p, "-Wtrigraphs"))
840 ; /* cpp handles this one. */
841 else if (!strcmp (p, "-Wno-trigraphs"))
842 ; /* cpp handles this one. */
843 else if (!strcmp (p, "-Wundef"))
844 ; /* cpp handles this one. */
845 else if (!strcmp (p, "-Wno-undef"))
846 ; /* cpp handles this one. */
847 else if (!strcmp (p, "-Wimport"))
848 ; /* cpp handles this one. */
849 else if (!strcmp (p, "-Wno-import"))
850 ; /* cpp handles this one. */
851 else if (!strcmp (p, "-Wmissing-braces"))
852 warn_missing_braces = 1;
853 else if (!strcmp (p, "-Wno-missing-braces"))
854 warn_missing_braces = 0;
855 else if (!strcmp (p, "-Wmain"))
856 warn_main = 1;
857 else if (!strcmp (p, "-Wno-main"))
858 warn_main = 0;
859 else if (!strcmp (p, "-Wsign-compare"))
860 warn_sign_compare = 1;
861 else if (!strcmp (p, "-Wno-sign-compare"))
862 warn_sign_compare = 0;
863 else if (!strcmp (p, "-Wmultichar"))
864 warn_multichar = 1;
865 else if (!strcmp (p, "-Wno-multichar"))
866 warn_multichar = 0;
867 else if (!strcmp (p, "-Wunknown-pragmas"))
868 /* Set to greater than 1, so that even unknown pragmas in system
869 headers will be warned about. */
870 warn_unknown_pragmas = 2;
871 else if (!strcmp (p, "-Wno-unknown-pragmas"))
872 warn_unknown_pragmas = 0;
873 else if (!strcmp (p, "-Wall"))
875 /* We save the value of warn_uninitialized, since if they put
876 -Wuninitialized on the command line, we need to generate a
877 warning about not using it without also specifying -O. */
878 if (warn_uninitialized != 1)
879 warn_uninitialized = 2;
880 warn_implicit_int = 1;
881 mesg_implicit_function_declaration = 1;
882 warn_return_type = 1;
883 warn_unused = 1;
884 warn_switch = 1;
885 warn_format = 1;
886 warn_char_subscripts = 1;
887 warn_parentheses = 1;
888 warn_missing_braces = 1;
889 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn
890 it off only if it's not explicit. */
891 warn_main = 2;
892 /* Only warn about unknown pragmas that are not in system headers. */
893 warn_unknown_pragmas = 1;
895 else
896 return strings_processed;
898 return 1;
901 /* Hooks for print_node. */
903 void
904 print_lang_decl (file, node, indent)
905 FILE *file ATTRIBUTE_UNUSED;
906 tree node ATTRIBUTE_UNUSED;
907 int indent ATTRIBUTE_UNUSED;
911 void
912 print_lang_type (file, node, indent)
913 FILE *file ATTRIBUTE_UNUSED;
914 tree node ATTRIBUTE_UNUSED;
915 int indent ATTRIBUTE_UNUSED;
919 void
920 print_lang_identifier (file, node, indent)
921 FILE *file;
922 tree node;
923 int indent;
925 print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
926 print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
927 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
928 print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
929 print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
930 print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4);
933 /* Hook called at end of compilation to assume 1 elt
934 for a top-level array decl that wasn't complete before. */
936 void
937 finish_incomplete_decl (decl)
938 tree decl;
940 if (TREE_CODE (decl) == VAR_DECL)
942 tree type = TREE_TYPE (decl);
943 if (type != error_mark_node
944 && TREE_CODE (type) == ARRAY_TYPE
945 && TYPE_DOMAIN (type) == 0)
947 if (! DECL_EXTERNAL (decl))
948 warning_with_decl (decl, "array `%s' assumed to have one element");
950 complete_array_type (type, NULL_TREE, 1);
952 layout_decl (decl, 0);
957 /* Create a new `struct binding_level'. */
959 static
960 struct binding_level *
961 make_binding_level ()
963 /* NOSTRICT */
964 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
967 /* Nonzero if we are currently in the global binding level. */
970 global_bindings_p ()
972 return current_binding_level == global_binding_level;
975 void
976 keep_next_level ()
978 keep_next_level_flag = 1;
981 /* Nonzero if the current level needs to have a BLOCK made. */
984 kept_level_p ()
986 return ((current_binding_level->keep_if_subblocks
987 && current_binding_level->blocks != 0)
988 || current_binding_level->keep
989 || current_binding_level->names != 0
990 || (current_binding_level->tags != 0
991 && !current_binding_level->tag_transparent));
994 /* Identify this binding level as a level of parameters.
995 DEFINITION_FLAG is 1 for a definition, 0 for a declaration.
996 But it turns out there is no way to pass the right value for
997 DEFINITION_FLAG, so we ignore it. */
999 void
1000 declare_parm_level (definition_flag)
1001 int definition_flag ATTRIBUTE_UNUSED;
1003 current_binding_level->parm_flag = 1;
1006 /* Nonzero if currently making parm declarations. */
1009 in_parm_level_p ()
1011 return current_binding_level->parm_flag;
1014 /* Enter a new binding level.
1015 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
1016 not for that of tags. */
1018 void
1019 pushlevel (tag_transparent)
1020 int tag_transparent;
1022 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1024 /* If this is the top level of a function,
1025 just make sure that NAMED_LABELS is 0. */
1027 if (current_binding_level == global_binding_level)
1029 named_labels = 0;
1032 /* Reuse or create a struct for this binding level. */
1034 if (free_binding_level)
1036 newlevel = free_binding_level;
1037 free_binding_level = free_binding_level->level_chain;
1039 else
1041 newlevel = make_binding_level ();
1044 /* Add this level to the front of the chain (stack) of levels that
1045 are active. */
1047 *newlevel = clear_binding_level;
1048 newlevel->tag_transparent
1049 = (tag_transparent
1050 || (current_binding_level
1051 ? current_binding_level->subblocks_tag_transparent
1052 : 0));
1053 newlevel->level_chain = current_binding_level;
1054 current_binding_level = newlevel;
1055 newlevel->keep = keep_next_level_flag;
1056 keep_next_level_flag = 0;
1057 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1058 keep_next_if_subblocks = 0;
1061 /* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */
1063 static void
1064 clear_limbo_values (block)
1065 tree block;
1067 tree tem;
1069 for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem))
1070 if (DECL_NAME (tem) != 0)
1071 IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0;
1073 for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem))
1074 clear_limbo_values (tem);
1077 /* Exit a binding level.
1078 Pop the level off, and restore the state of the identifier-decl mappings
1079 that were in effect when this level was entered.
1081 If KEEP is nonzero, this level had explicit declarations, so
1082 and create a "block" (a BLOCK node) for the level
1083 to record its declarations and subblocks for symbol table output.
1085 If FUNCTIONBODY is nonzero, this level is the body of a function,
1086 so create a block as if KEEP were set and also clear out all
1087 label names.
1089 If REVERSE is nonzero, reverse the order of decls before putting
1090 them into the BLOCK. */
1092 tree
1093 poplevel (keep, reverse, functionbody)
1094 int keep;
1095 int reverse;
1096 int functionbody;
1098 register tree link;
1099 /* The chain of decls was accumulated in reverse order.
1100 Put it into forward order, just for cleanliness. */
1101 tree decls;
1102 tree tags = current_binding_level->tags;
1103 tree subblocks = current_binding_level->blocks;
1104 tree block = 0;
1105 tree decl;
1106 int block_previously_created;
1108 keep |= current_binding_level->keep;
1110 /* This warning is turned off because it causes warnings for
1111 declarations like `extern struct foo *x'. */
1112 #if 0
1113 /* Warn about incomplete structure types in this level. */
1114 for (link = tags; link; link = TREE_CHAIN (link))
1115 if (TYPE_SIZE (TREE_VALUE (link)) == 0)
1117 tree type = TREE_VALUE (link);
1118 tree type_name = TYPE_NAME (type);
1119 char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE
1120 ? type_name
1121 : DECL_NAME (type_name));
1122 switch (TREE_CODE (type))
1124 case RECORD_TYPE:
1125 error ("`struct %s' incomplete in scope ending here", id);
1126 break;
1127 case UNION_TYPE:
1128 error ("`union %s' incomplete in scope ending here", id);
1129 break;
1130 case ENUMERAL_TYPE:
1131 error ("`enum %s' incomplete in scope ending here", id);
1132 break;
1135 #endif /* 0 */
1137 /* Get the decls in the order they were written.
1138 Usually current_binding_level->names is in reverse order.
1139 But parameter decls were previously put in forward order. */
1141 if (reverse)
1142 current_binding_level->names
1143 = decls = nreverse (current_binding_level->names);
1144 else
1145 decls = current_binding_level->names;
1147 /* Output any nested inline functions within this block
1148 if they weren't already output. */
1150 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1151 if (TREE_CODE (decl) == FUNCTION_DECL
1152 && ! TREE_ASM_WRITTEN (decl)
1153 && DECL_INITIAL (decl) != 0
1154 && TREE_ADDRESSABLE (decl))
1156 /* If this decl was copied from a file-scope decl
1157 on account of a block-scope extern decl,
1158 propagate TREE_ADDRESSABLE to the file-scope decl.
1160 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1161 true, since then the decl goes through save_for_inline_copying. */
1162 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1163 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1164 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1165 else if (DECL_SAVED_INSNS (decl) != 0)
1167 push_function_context ();
1168 output_inline_function (decl);
1169 pop_function_context ();
1173 /* If there were any declarations or structure tags in that level,
1174 or if this level is a function body,
1175 create a BLOCK to record them for the life of this function. */
1177 block = 0;
1178 block_previously_created = (current_binding_level->this_block != 0);
1179 if (block_previously_created)
1180 block = current_binding_level->this_block;
1181 else if (keep || functionbody
1182 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1183 block = make_node (BLOCK);
1184 if (block != 0)
1186 BLOCK_VARS (block) = decls;
1187 BLOCK_TYPE_TAGS (block) = tags;
1188 BLOCK_SUBBLOCKS (block) = subblocks;
1189 remember_end_note (block);
1192 /* In each subblock, record that this is its superior. */
1194 for (link = subblocks; link; link = TREE_CHAIN (link))
1195 BLOCK_SUPERCONTEXT (link) = block;
1197 /* Clear out the meanings of the local variables of this level. */
1199 for (link = decls; link; link = TREE_CHAIN (link))
1201 if (DECL_NAME (link) != 0)
1203 /* If the ident. was used or addressed via a local extern decl,
1204 don't forget that fact. */
1205 if (DECL_EXTERNAL (link))
1207 if (TREE_USED (link))
1208 TREE_USED (DECL_NAME (link)) = 1;
1209 if (TREE_ADDRESSABLE (link))
1210 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1212 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
1216 /* Restore all name-meanings of the outer levels
1217 that were shadowed by this level. */
1219 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1220 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1222 /* If the level being exited is the top level of a function,
1223 check over all the labels, and clear out the current
1224 (function local) meanings of their names. */
1226 if (functionbody)
1228 clear_limbo_values (block);
1230 /* If this is the top level block of a function,
1231 the vars are the function's parameters.
1232 Don't leave them in the BLOCK because they are
1233 found in the FUNCTION_DECL instead. */
1235 BLOCK_VARS (block) = 0;
1237 /* Clear out the definitions of all label names,
1238 since their scopes end here,
1239 and add them to BLOCK_VARS. */
1241 for (link = named_labels; link; link = TREE_CHAIN (link))
1243 register tree label = TREE_VALUE (link);
1245 if (DECL_INITIAL (label) == 0)
1247 error_with_decl (label, "label `%s' used but not defined");
1248 /* Avoid crashing later. */
1249 define_label (input_filename, lineno,
1250 DECL_NAME (label));
1252 else if (warn_unused && !TREE_USED (label))
1253 warning_with_decl (label, "label `%s' defined but not used");
1254 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1256 /* Put the labels into the "variables" of the
1257 top-level block, so debugger can see them. */
1258 TREE_CHAIN (label) = BLOCK_VARS (block);
1259 BLOCK_VARS (block) = label;
1263 /* Pop the current level, and free the structure for reuse. */
1266 register struct binding_level *level = current_binding_level;
1267 current_binding_level = current_binding_level->level_chain;
1269 level->level_chain = free_binding_level;
1270 free_binding_level = level;
1273 /* Dispose of the block that we just made inside some higher level. */
1274 if (functionbody)
1275 DECL_INITIAL (current_function_decl) = block;
1276 else if (block)
1278 if (!block_previously_created)
1279 current_binding_level->blocks
1280 = chainon (current_binding_level->blocks, block);
1282 /* If we did not make a block for the level just exited,
1283 any blocks made for inner levels
1284 (since they cannot be recorded as subblocks in that level)
1285 must be carried forward so they will later become subblocks
1286 of something else. */
1287 else if (subblocks)
1288 current_binding_level->blocks
1289 = chainon (current_binding_level->blocks, subblocks);
1291 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1292 binding contour so that they point to the appropriate construct, i.e.
1293 either to the current FUNCTION_DECL node, or else to the BLOCK node
1294 we just constructed.
1296 Note that for tagged types whose scope is just the formal parameter
1297 list for some function type specification, we can't properly set
1298 their TYPE_CONTEXTs here, because we don't have a pointer to the
1299 appropriate FUNCTION_TYPE node readily available to us. For those
1300 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1301 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1302 node which will represent the "scope" for these "parameter list local"
1303 tagged types.
1306 if (functionbody)
1307 for (link = tags; link; link = TREE_CHAIN (link))
1308 TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl;
1309 else if (block)
1310 for (link = tags; link; link = TREE_CHAIN (link))
1311 TYPE_CONTEXT (TREE_VALUE (link)) = block;
1313 if (block)
1314 TREE_USED (block) = 1;
1315 return block;
1318 /* Delete the node BLOCK from the current binding level.
1319 This is used for the block inside a stmt expr ({...})
1320 so that the block can be reinserted where appropriate. */
1322 void
1323 delete_block (block)
1324 tree block;
1326 tree t;
1327 if (current_binding_level->blocks == block)
1328 current_binding_level->blocks = TREE_CHAIN (block);
1329 for (t = current_binding_level->blocks; t;)
1331 if (TREE_CHAIN (t) == block)
1332 TREE_CHAIN (t) = TREE_CHAIN (block);
1333 else
1334 t = TREE_CHAIN (t);
1336 TREE_CHAIN (block) = NULL;
1337 /* Clear TREE_USED which is always set by poplevel.
1338 The flag is set again if insert_block is called. */
1339 TREE_USED (block) = 0;
1342 /* Insert BLOCK at the end of the list of subblocks of the
1343 current binding level. This is used when a BIND_EXPR is expanded,
1344 to handle the BLOCK node inside the BIND_EXPR. */
1346 void
1347 insert_block (block)
1348 tree block;
1350 TREE_USED (block) = 1;
1351 current_binding_level->blocks
1352 = chainon (current_binding_level->blocks, block);
1355 /* Set the BLOCK node for the innermost scope
1356 (the one we are currently in). */
1358 void
1359 set_block (block)
1360 register tree block;
1362 current_binding_level->this_block = block;
1365 void
1366 push_label_level ()
1368 register struct binding_level *newlevel;
1370 /* Reuse or create a struct for this binding level. */
1372 if (free_binding_level)
1374 newlevel = free_binding_level;
1375 free_binding_level = free_binding_level->level_chain;
1377 else
1379 newlevel = make_binding_level ();
1382 /* Add this level to the front of the chain (stack) of label levels. */
1384 newlevel->level_chain = label_level_chain;
1385 label_level_chain = newlevel;
1387 newlevel->names = named_labels;
1388 newlevel->shadowed = shadowed_labels;
1389 named_labels = 0;
1390 shadowed_labels = 0;
1393 void
1394 pop_label_level ()
1396 register struct binding_level *level = label_level_chain;
1397 tree link, prev;
1399 /* Clear out the definitions of the declared labels in this level.
1400 Leave in the list any ordinary, non-declared labels. */
1401 for (link = named_labels, prev = 0; link;)
1403 if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
1405 if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
1407 error_with_decl (TREE_VALUE (link),
1408 "label `%s' used but not defined");
1409 /* Avoid crashing later. */
1410 define_label (input_filename, lineno,
1411 DECL_NAME (TREE_VALUE (link)));
1413 else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
1414 warning_with_decl (TREE_VALUE (link),
1415 "label `%s' defined but not used");
1416 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
1418 /* Delete this element from the list. */
1419 link = TREE_CHAIN (link);
1420 if (prev)
1421 TREE_CHAIN (prev) = link;
1422 else
1423 named_labels = link;
1425 else
1427 prev = link;
1428 link = TREE_CHAIN (link);
1432 /* Bring back all the labels that were shadowed. */
1433 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
1434 if (DECL_NAME (TREE_VALUE (link)) != 0)
1435 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
1436 = TREE_VALUE (link);
1438 named_labels = chainon (named_labels, level->names);
1439 shadowed_labels = level->shadowed;
1441 /* Pop the current level, and free the structure for reuse. */
1442 label_level_chain = label_level_chain->level_chain;
1443 level->level_chain = free_binding_level;
1444 free_binding_level = level;
1447 /* Push a definition or a declaration of struct, union or enum tag "name".
1448 "type" should be the type node.
1449 We assume that the tag "name" is not already defined.
1451 Note that the definition may really be just a forward reference.
1452 In that case, the TYPE_SIZE will be zero. */
1454 void
1455 pushtag (name, type)
1456 tree name, type;
1458 register struct binding_level *b;
1460 /* Find the proper binding level for this type tag. */
1462 for (b = current_binding_level; b->tag_transparent; b = b->level_chain)
1463 continue;
1465 if (name)
1467 /* Record the identifier as the type's name if it has none. */
1469 if (TYPE_NAME (type) == 0)
1470 TYPE_NAME (type) = name;
1473 if (b == global_binding_level)
1474 b->tags = perm_tree_cons (name, type, b->tags);
1475 else
1476 b->tags = saveable_tree_cons (name, type, b->tags);
1478 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1479 tagged type we just added to the current binding level. This fake
1480 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1481 to output a representation of a tagged type, and it also gives
1482 us a convenient place to record the "scope start" address for the
1483 tagged type. */
1485 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
1487 /* An approximation for now, so we can tell this is a function-scope tag.
1488 This will be updated in poplevel. */
1489 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1492 /* Handle when a new declaration NEWDECL
1493 has the same name as an old one OLDDECL
1494 in the same binding contour.
1495 Prints an error message if appropriate.
1497 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
1498 Otherwise, return 0.
1500 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration,
1501 and OLDDECL is in an outer binding level and should thus not be changed. */
1503 static int
1504 duplicate_decls (newdecl, olddecl, different_binding_level)
1505 register tree newdecl, olddecl;
1506 int different_binding_level;
1508 int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1509 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1510 && DECL_INITIAL (newdecl) != 0);
1511 tree oldtype = TREE_TYPE (olddecl);
1512 tree newtype = TREE_TYPE (newdecl);
1513 int errmsg = 0;
1515 if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
1516 DECL_MACHINE_ATTRIBUTES (newdecl)
1517 = merge_machine_decl_attributes (olddecl, newdecl);
1519 if (TREE_CODE (newtype) == ERROR_MARK
1520 || TREE_CODE (oldtype) == ERROR_MARK)
1521 types_match = 0;
1523 /* New decl is completely inconsistent with the old one =>
1524 tell caller to replace the old one.
1525 This is always an error except in the case of shadowing a builtin. */
1526 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1528 if (TREE_CODE (olddecl) == FUNCTION_DECL
1529 && (DECL_BUILT_IN (olddecl)
1530 || DECL_BUILT_IN_NONANSI (olddecl)))
1532 /* If you declare a built-in or predefined function name as static,
1533 the old definition is overridden,
1534 but optionally warn this was a bad choice of name. */
1535 if (!TREE_PUBLIC (newdecl))
1537 if (!warn_shadow)
1539 else if (DECL_BUILT_IN (olddecl))
1540 warning_with_decl (newdecl, "shadowing built-in function `%s'");
1541 else
1542 warning_with_decl (newdecl, "shadowing library function `%s'");
1544 /* Likewise, if the built-in is not ansi, then programs can
1545 override it even globally without an error. */
1546 else if (! DECL_BUILT_IN (olddecl))
1547 warning_with_decl (newdecl,
1548 "library function `%s' declared as non-function");
1550 else if (DECL_BUILT_IN_NONANSI (olddecl))
1551 warning_with_decl (newdecl,
1552 "built-in function `%s' declared as non-function");
1553 else
1554 warning_with_decl (newdecl,
1555 "built-in function `%s' declared as non-function");
1557 else
1559 error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
1560 error_with_decl (olddecl, "previous declaration of `%s'");
1563 return 0;
1566 /* For real parm decl following a forward decl,
1567 return 1 so old decl will be reused. */
1568 if (types_match && TREE_CODE (newdecl) == PARM_DECL
1569 && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
1570 return 1;
1572 /* The new declaration is the same kind of object as the old one.
1573 The declarations may partially match. Print warnings if they don't
1574 match enough. Ultimately, copy most of the information from the new
1575 decl to the old one, and keep using the old one. */
1577 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
1578 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl
1579 && DECL_INITIAL (olddecl) == 0)
1580 /* If -traditional, avoid error for redeclaring fcn
1581 after implicit decl. */
1583 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1584 && DECL_BUILT_IN (olddecl))
1586 /* A function declaration for a built-in function. */
1587 if (!TREE_PUBLIC (newdecl))
1589 /* If you declare a built-in function name as static, the
1590 built-in definition is overridden,
1591 but optionally warn this was a bad choice of name. */
1592 if (warn_shadow)
1593 warning_with_decl (newdecl, "shadowing built-in function `%s'");
1594 /* Discard the old built-in function. */
1595 return 0;
1597 else if (!types_match)
1599 /* Accept the return type of the new declaration if same modes. */
1600 tree oldreturntype = TREE_TYPE (oldtype);
1601 tree newreturntype = TREE_TYPE (newtype);
1603 /* Make sure we put the new type in the same obstack as the old ones.
1604 If the old types are not both in the same obstack, use the
1605 permanent one. */
1606 if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
1607 push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
1608 else
1610 push_obstacks_nochange ();
1611 end_temporary_allocation ();
1614 if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
1616 /* Function types may be shared, so we can't just modify
1617 the return type of olddecl's function type. */
1618 tree trytype
1619 = build_function_type (newreturntype,
1620 TYPE_ARG_TYPES (oldtype));
1622 types_match = comptypes (newtype, trytype);
1623 if (types_match)
1624 oldtype = trytype;
1626 /* Accept harmless mismatch in first argument type also.
1627 This is for ffs. */
1628 if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0
1629 && TYPE_ARG_TYPES (oldtype) != 0
1630 && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0
1631 && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0
1632 && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype)))
1633 == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype)))))
1635 /* Function types may be shared, so we can't just modify
1636 the return type of olddecl's function type. */
1637 tree trytype
1638 = build_function_type (TREE_TYPE (oldtype),
1639 tree_cons (NULL_TREE,
1640 TREE_VALUE (TYPE_ARG_TYPES (newtype)),
1641 TREE_CHAIN (TYPE_ARG_TYPES (oldtype))));
1643 types_match = comptypes (newtype, trytype);
1644 if (types_match)
1645 oldtype = trytype;
1647 if (! different_binding_level)
1648 TREE_TYPE (olddecl) = oldtype;
1650 pop_obstacks ();
1652 if (!types_match)
1654 /* If types don't match for a built-in, throw away the built-in. */
1655 warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
1656 return 0;
1659 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1660 && DECL_SOURCE_LINE (olddecl) == 0)
1662 /* A function declaration for a predeclared function
1663 that isn't actually built in. */
1664 if (!TREE_PUBLIC (newdecl))
1666 /* If you declare it as static, the
1667 default definition is overridden. */
1668 return 0;
1670 else if (!types_match)
1672 /* If the types don't match, preserve volatility indication.
1673 Later on, we will discard everything else about the
1674 default declaration. */
1675 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1678 /* Permit char *foo () to match void *foo (...) if not pedantic,
1679 if one of them came from a system header file. */
1680 else if (!types_match
1681 && TREE_CODE (olddecl) == FUNCTION_DECL
1682 && TREE_CODE (newdecl) == FUNCTION_DECL
1683 && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
1684 && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
1685 && (DECL_IN_SYSTEM_HEADER (olddecl)
1686 || DECL_IN_SYSTEM_HEADER (newdecl))
1687 && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
1688 && TYPE_ARG_TYPES (oldtype) == 0
1689 && self_promoting_args_p (TYPE_ARG_TYPES (newtype))
1690 && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
1692 (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
1693 && TYPE_ARG_TYPES (newtype) == 0
1694 && self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
1695 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
1697 if (pedantic)
1698 pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1699 /* Make sure we keep void * as ret type, not char *. */
1700 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
1701 TREE_TYPE (newdecl) = newtype = oldtype;
1703 /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration
1704 we will come back here again. */
1705 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1707 else if (!types_match
1708 /* Permit char *foo (int, ...); followed by char *foo ();
1709 if not pedantic. */
1710 && ! (TREE_CODE (olddecl) == FUNCTION_DECL
1711 && ! pedantic
1712 /* Return types must still match. */
1713 && comptypes (TREE_TYPE (oldtype),
1714 TREE_TYPE (newtype))
1715 && TYPE_ARG_TYPES (newtype) == 0))
1717 error_with_decl (newdecl, "conflicting types for `%s'");
1718 /* Check for function type mismatch
1719 involving an empty arglist vs a nonempty one. */
1720 if (TREE_CODE (olddecl) == FUNCTION_DECL
1721 && comptypes (TREE_TYPE (oldtype),
1722 TREE_TYPE (newtype))
1723 && ((TYPE_ARG_TYPES (oldtype) == 0
1724 && DECL_INITIAL (olddecl) == 0)
1726 (TYPE_ARG_TYPES (newtype) == 0
1727 && DECL_INITIAL (newdecl) == 0)))
1729 /* Classify the problem further. */
1730 register tree t = TYPE_ARG_TYPES (oldtype);
1731 if (t == 0)
1732 t = TYPE_ARG_TYPES (newtype);
1733 for (; t; t = TREE_CHAIN (t))
1735 register tree type = TREE_VALUE (t);
1737 if (TREE_CHAIN (t) == 0
1738 && TYPE_MAIN_VARIANT (type) != void_type_node)
1740 error ("A parameter list with an ellipsis can't match an empty parameter name list declaration.");
1741 break;
1744 if (TYPE_MAIN_VARIANT (type) == float_type_node
1745 || C_PROMOTING_INTEGER_TYPE_P (type))
1747 error ("An argument type that has a default promotion can't match an empty parameter name list declaration.");
1748 break;
1752 error_with_decl (olddecl, "previous declaration of `%s'");
1754 else
1756 errmsg = redeclaration_error_message (newdecl, olddecl);
1757 if (errmsg)
1759 switch (errmsg)
1761 case 1:
1762 error_with_decl (newdecl, "redefinition of `%s'");
1763 break;
1764 case 2:
1765 error_with_decl (newdecl, "redeclaration of `%s'");
1766 break;
1767 case 3:
1768 error_with_decl (newdecl, "conflicting declarations of `%s'");
1769 break;
1770 default:
1771 abort ();
1774 error_with_decl (olddecl,
1775 ((DECL_INITIAL (olddecl)
1776 && current_binding_level == global_binding_level)
1777 ? "`%s' previously defined here"
1778 : "`%s' previously declared here"));
1780 else if (TREE_CODE (newdecl) == TYPE_DECL
1781 && (DECL_IN_SYSTEM_HEADER (olddecl)
1782 || DECL_IN_SYSTEM_HEADER (newdecl)))
1784 warning_with_decl (newdecl, "redefinition of `%s'");
1785 warning_with_decl
1786 (olddecl,
1787 ((DECL_INITIAL (olddecl)
1788 && current_binding_level == global_binding_level)
1789 ? "`%s' previously defined here"
1790 : "`%s' previously declared here"));
1792 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1793 && DECL_INITIAL (olddecl) != 0
1794 && TYPE_ARG_TYPES (oldtype) == 0
1795 && TYPE_ARG_TYPES (newtype) != 0
1796 && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0)
1798 register tree type, parm;
1799 register int nargs;
1800 /* Prototype decl follows defn w/o prototype. */
1802 for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
1803 type = TYPE_ARG_TYPES (newtype),
1804 nargs = 1;
1806 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
1808 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1809 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1811 warning_with_decl (newdecl, "prototype for `%s' follows");
1812 warning_with_decl (olddecl, "non-prototype definition here");
1813 break;
1815 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1816 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1818 error_with_decl (newdecl, "prototype for `%s' follows and number of arguments doesn't match");
1819 error_with_decl (olddecl, "non-prototype definition here");
1820 errmsg = 1;
1821 break;
1823 /* Type for passing arg must be consistent
1824 with that declared for the arg. */
1825 if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type))
1826 /* If -traditional, allow `unsigned int' instead of `int'
1827 in the prototype. */
1828 && (! (flag_traditional
1829 && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node
1830 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)))
1832 error_with_decl (newdecl,
1833 "prototype for `%s' follows and argument %d doesn't match",
1834 nargs);
1835 error_with_decl (olddecl, "non-prototype definition here");
1836 errmsg = 1;
1837 break;
1841 /* Warn about mismatches in various flags. */
1842 else
1844 /* Warn if function is now inline
1845 but was previously declared not inline and has been called. */
1846 if (TREE_CODE (olddecl) == FUNCTION_DECL
1847 && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
1848 && TREE_USED (olddecl))
1849 warning_with_decl (newdecl,
1850 "`%s' declared inline after being called");
1851 if (TREE_CODE (olddecl) == FUNCTION_DECL
1852 && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
1853 && DECL_INITIAL (olddecl) != 0)
1854 warning_with_decl (newdecl,
1855 "`%s' declared inline after its definition");
1857 /* If pedantic, warn when static declaration follows a non-static
1858 declaration. Otherwise, do so only for functions. */
1859 if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL)
1860 && TREE_PUBLIC (olddecl)
1861 && !TREE_PUBLIC (newdecl))
1862 warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
1864 /* If warn_traditional, warn when a non-static function
1865 declaration follows a static one. */
1866 if (warn_traditional
1867 && TREE_CODE (olddecl) == FUNCTION_DECL
1868 && !TREE_PUBLIC (olddecl)
1869 && TREE_PUBLIC (newdecl))
1870 warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
1872 /* Warn when const declaration follows a non-const
1873 declaration, but not for functions. */
1874 if (TREE_CODE (olddecl) != FUNCTION_DECL
1875 && !TREE_READONLY (olddecl)
1876 && TREE_READONLY (newdecl))
1877 warning_with_decl (newdecl, "const declaration for `%s' follows non-const");
1878 /* These bits are logically part of the type, for variables.
1879 But not for functions
1880 (where qualifiers are not valid ANSI anyway). */
1881 else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
1882 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1883 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1884 pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1888 /* Optionally warn about more than one declaration for the same name. */
1889 if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
1890 /* Don't warn about a function declaration
1891 followed by a definition. */
1892 && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
1893 && DECL_INITIAL (olddecl) == 0)
1894 /* Don't warn about extern decl followed by (tentative) definition. */
1895 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
1897 warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
1898 warning_with_decl (olddecl, "previous declaration of `%s'");
1901 /* Copy all the DECL_... slots specified in the new decl
1902 except for any that we copy here from the old type.
1904 Past this point, we don't change OLDTYPE and NEWTYPE
1905 even if we change the types of NEWDECL and OLDDECL. */
1907 if (types_match)
1909 /* When copying info to olddecl, we store into write_olddecl
1910 instead. This allows us to avoid modifying olddecl when
1911 different_binding_level is true. */
1912 tree write_olddecl = different_binding_level ? newdecl : olddecl;
1914 /* Make sure we put the new type in the same obstack as the old ones.
1915 If the old types are not both in the same obstack, use the permanent
1916 one. */
1917 if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
1918 push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
1919 else
1921 push_obstacks_nochange ();
1922 end_temporary_allocation ();
1925 /* Merge the data types specified in the two decls. */
1926 if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
1928 if (different_binding_level)
1929 TREE_TYPE (newdecl)
1930 = build_type_attribute_variant
1931 (newtype,
1932 merge_attributes (TYPE_ATTRIBUTES (newtype),
1933 TYPE_ATTRIBUTES (oldtype)));
1934 else
1935 TREE_TYPE (newdecl)
1936 = TREE_TYPE (olddecl)
1937 = common_type (newtype, oldtype);
1940 /* Lay the type out, unless already done. */
1941 if (oldtype != TREE_TYPE (newdecl))
1943 if (TREE_TYPE (newdecl) != error_mark_node)
1944 layout_type (TREE_TYPE (newdecl));
1945 if (TREE_CODE (newdecl) != FUNCTION_DECL
1946 && TREE_CODE (newdecl) != TYPE_DECL
1947 && TREE_CODE (newdecl) != CONST_DECL)
1948 layout_decl (newdecl, 0);
1950 else
1952 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1953 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1954 if (TREE_CODE (olddecl) != FUNCTION_DECL)
1955 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1956 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1959 /* Keep the old rtl since we can safely use it. */
1960 DECL_RTL (newdecl) = DECL_RTL (olddecl);
1962 /* Merge the type qualifiers. */
1963 if (DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl)
1964 && !TREE_THIS_VOLATILE (newdecl))
1965 TREE_THIS_VOLATILE (write_olddecl) = 0;
1966 if (TREE_READONLY (newdecl))
1967 TREE_READONLY (write_olddecl) = 1;
1968 if (TREE_THIS_VOLATILE (newdecl))
1970 TREE_THIS_VOLATILE (write_olddecl) = 1;
1971 if (TREE_CODE (newdecl) == VAR_DECL)
1972 make_var_volatile (newdecl);
1975 /* Keep source location of definition rather than declaration. */
1976 /* When called with different_binding_level set, keep the old
1977 information so that meaningful diagnostics can be given. */
1978 if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
1979 && ! different_binding_level)
1981 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
1982 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
1985 /* Merge the unused-warning information. */
1986 if (DECL_IN_SYSTEM_HEADER (olddecl))
1987 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1988 else if (DECL_IN_SYSTEM_HEADER (newdecl))
1989 DECL_IN_SYSTEM_HEADER (write_olddecl) = 1;
1991 /* Merge the initialization information. */
1992 /* When called with different_binding_level set, don't copy over
1993 DECL_INITIAL, so that we don't accidentally change function
1994 declarations into function definitions. */
1995 if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
1996 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1998 /* Merge the section attribute.
1999 We want to issue an error if the sections conflict but that must be
2000 done later in decl_attributes since we are called before attributes
2001 are assigned. */
2002 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2003 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2005 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2007 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
2008 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2010 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2011 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2012 DECL_NO_CHECK_MEMORY_USAGE (newdecl)
2013 |= DECL_NO_CHECK_MEMORY_USAGE (olddecl);
2016 pop_obstacks ();
2018 /* If cannot merge, then use the new type and qualifiers,
2019 and don't preserve the old rtl. */
2020 else if (! different_binding_level)
2022 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2023 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2024 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2025 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2028 /* Merge the storage class information. */
2029 DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
2030 /* For functions, static overrides non-static. */
2031 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2033 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2034 /* This is since we don't automatically
2035 copy the attributes of NEWDECL into OLDDECL. */
2036 /* No need to worry about different_binding_level here because
2037 then TREE_PUBLIC (newdecl) was true. */
2038 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2039 /* If this clears `static', clear it in the identifier too. */
2040 if (! TREE_PUBLIC (olddecl))
2041 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
2043 if (DECL_EXTERNAL (newdecl))
2045 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2046 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2047 /* An extern decl does not override previous storage class. */
2048 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2049 if (! DECL_EXTERNAL (newdecl))
2050 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2052 else
2054 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2055 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2058 /* If either decl says `inline', this fn is inline,
2059 unless its definition was passed already. */
2060 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0)
2061 DECL_INLINE (olddecl) = 1;
2062 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2064 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2066 if (DECL_BUILT_IN (olddecl))
2068 /* Get rid of any built-in function if new arg types don't match it
2069 or if we have a function definition. */
2070 if (! types_match || new_is_definition)
2072 if (! different_binding_level)
2074 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2075 DECL_BUILT_IN (olddecl) = 0;
2078 else
2080 /* If redeclaring a builtin function, and not a definition,
2081 it stays built in. */
2082 DECL_BUILT_IN (newdecl) = 1;
2083 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2086 /* Also preserve various other info from the definition. */
2087 else if (! new_is_definition)
2088 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2089 if (! new_is_definition)
2091 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2092 /* When called with different_binding_level set, don't copy over
2093 DECL_INITIAL, so that we don't accidentally change function
2094 declarations into function definitions. */
2095 if (! different_binding_level)
2096 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2097 DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
2098 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2099 if (DECL_INLINE (newdecl))
2100 DECL_ABSTRACT_ORIGIN (newdecl) = DECL_ORIGIN (olddecl);
2103 if (different_binding_level)
2105 /* Don't output a duplicate symbol or debugging information for this
2106 declaration.
2108 Do not set TREE_ASM_WRITTEN for a FUNCTION_DECL since we may actually
2109 just have two declarations without a definition. VAR_DECLs may need
2110 the same treatment, I'm not sure. */
2111 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2112 DECL_IGNORED_P (newdecl) = 1;
2113 else
2114 TREE_ASM_WRITTEN (newdecl) = DECL_IGNORED_P (newdecl) = 1;
2115 return 0;
2118 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
2119 But preserve OLDDECL's DECL_UID. */
2121 register unsigned olddecl_uid = DECL_UID (olddecl);
2123 bcopy ((char *) newdecl + sizeof (struct tree_common),
2124 (char *) olddecl + sizeof (struct tree_common),
2125 sizeof (struct tree_decl) - sizeof (struct tree_common));
2126 DECL_UID (olddecl) = olddecl_uid;
2129 /* NEWDECL contains the merged attribute lists.
2130 Update OLDDECL to be the same. */
2131 DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl);
2133 return 1;
2136 /* Record a decl-node X as belonging to the current lexical scope.
2137 Check for errors (such as an incompatible declaration for the same
2138 name already seen in the same scope).
2140 Returns either X or an old decl for the same name.
2141 If an old decl is returned, it may have been smashed
2142 to agree with what X says. */
2144 tree
2145 pushdecl (x)
2146 tree x;
2148 register tree t;
2149 register tree name = DECL_NAME (x);
2150 register struct binding_level *b = current_binding_level;
2152 DECL_CONTEXT (x) = current_function_decl;
2153 /* A local extern declaration for a function doesn't constitute nesting.
2154 A local auto declaration does, since it's a forward decl
2155 for a nested function coming later. */
2156 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0
2157 && DECL_EXTERNAL (x))
2158 DECL_CONTEXT (x) = 0;
2160 if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level
2161 && x != IDENTIFIER_IMPLICIT_DECL (name)
2162 /* Don't print error messages for __FUNCTION__ and __PRETTY_FUNCTION__ */
2163 && !DECL_IN_SYSTEM_HEADER (x))
2164 warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name));
2166 if (name)
2168 char *file;
2169 int line;
2170 int different_binding_level = 0;
2172 t = lookup_name_current_level (name);
2173 /* Don't type check externs here when -traditional. This is so that
2174 code with conflicting declarations inside blocks will get warnings
2175 not errors. X11 for instance depends on this. */
2176 if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x) && ! flag_traditional)
2178 t = IDENTIFIER_GLOBAL_VALUE (name);
2179 /* Type decls at global scope don't conflict with externs declared
2180 inside lexical blocks. */
2181 if (t && TREE_CODE (t) == TYPE_DECL)
2182 t = 0;
2183 different_binding_level = 1;
2185 if (t != 0 && t == error_mark_node)
2186 /* error_mark_node is 0 for a while during initialization! */
2188 t = 0;
2189 error_with_decl (x, "`%s' used prior to declaration");
2192 if (t != 0)
2194 file = DECL_SOURCE_FILE (t);
2195 line = DECL_SOURCE_LINE (t);
2198 /* If this decl is `static' and an implicit decl was seen previously,
2199 warn. But don't complain if -traditional,
2200 since traditional compilers don't complain. */
2201 if (! flag_traditional && TREE_PUBLIC (name)
2202 /* Don't test for DECL_EXTERNAL, because grokdeclarator
2203 sets this for all functions. */
2204 && ! TREE_PUBLIC (x)
2205 && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level)
2206 /* We used to warn also for explicit extern followed by static,
2207 but sometimes you need to do it that way. */
2208 && IDENTIFIER_IMPLICIT_DECL (name) != 0)
2210 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2211 IDENTIFIER_POINTER (name));
2212 pedwarn_with_file_and_line
2213 (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)),
2214 DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)),
2215 "previous declaration of `%s'",
2216 IDENTIFIER_POINTER (name));
2217 TREE_THIS_VOLATILE (name) = 1;
2220 if (t != 0 && duplicate_decls (x, t, different_binding_level))
2222 if (TREE_CODE (t) == PARM_DECL)
2224 /* Don't allow more than one "real" duplicate
2225 of a forward parm decl. */
2226 TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x);
2227 return t;
2229 return t;
2232 /* If we are processing a typedef statement, generate a whole new
2233 ..._TYPE node (which will be just an variant of the existing
2234 ..._TYPE node with identical properties) and then install the
2235 TYPE_DECL node generated to represent the typedef name as the
2236 TYPE_NAME of this brand new (duplicate) ..._TYPE node.
2238 The whole point here is to end up with a situation where each
2239 and every ..._TYPE node the compiler creates will be uniquely
2240 associated with AT MOST one node representing a typedef name.
2241 This way, even though the compiler substitutes corresponding
2242 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
2243 early on, later parts of the compiler can always do the reverse
2244 translation and get back the corresponding typedef name. For
2245 example, given:
2247 typedef struct S MY_TYPE;
2248 MY_TYPE object;
2250 Later parts of the compiler might only know that `object' was of
2251 type `struct S' if it were not for code just below. With this
2252 code however, later parts of the compiler see something like:
2254 struct S' == struct S
2255 typedef struct S' MY_TYPE;
2256 struct S' object;
2258 And they can then deduce (from the node for type struct S') that
2259 the original object declaration was:
2261 MY_TYPE object;
2263 Being able to do this is important for proper support of protoize,
2264 and also for generating precise symbolic debugging information
2265 which takes full account of the programmer's (typedef) vocabulary.
2267 Obviously, we don't want to generate a duplicate ..._TYPE node if
2268 the TYPE_DECL node that we are now processing really represents a
2269 standard built-in type.
2271 Since all standard types are effectively declared at line zero
2272 in the source file, we can easily check to see if we are working
2273 on a standard type by checking the current value of lineno. */
2275 if (TREE_CODE (x) == TYPE_DECL)
2277 if (DECL_SOURCE_LINE (x) == 0)
2279 if (TYPE_NAME (TREE_TYPE (x)) == 0)
2280 TYPE_NAME (TREE_TYPE (x)) = x;
2282 else if (TREE_TYPE (x) != error_mark_node
2283 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
2285 tree tt = TREE_TYPE (x);
2286 DECL_ORIGINAL_TYPE (x) = tt;
2287 tt = build_type_copy (tt);
2288 TYPE_NAME (tt) = x;
2289 TREE_TYPE (x) = tt;
2293 /* Multiple external decls of the same identifier ought to match.
2294 Check against both global declarations (when traditional) and out of
2295 scope (limbo) block level declarations.
2297 We get warnings about inline functions where they are defined.
2298 Avoid duplicate warnings where they are used. */
2299 if (TREE_PUBLIC (x) && ! DECL_INLINE (x))
2301 tree decl;
2303 if (flag_traditional && IDENTIFIER_GLOBAL_VALUE (name) != 0
2304 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2305 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2306 decl = IDENTIFIER_GLOBAL_VALUE (name);
2307 else if (IDENTIFIER_LIMBO_VALUE (name) != 0)
2308 /* Decls in limbo are always extern, so no need to check that. */
2309 decl = IDENTIFIER_LIMBO_VALUE (name);
2310 else
2311 decl = 0;
2313 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl))
2314 /* If old decl is built-in, we already warned if we should. */
2315 && !DECL_BUILT_IN (decl))
2317 pedwarn_with_decl (x,
2318 "type mismatch with previous external decl");
2319 pedwarn_with_decl (decl, "previous external decl of `%s'");
2323 /* If a function has had an implicit declaration, and then is defined,
2324 make sure they are compatible. */
2326 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2327 && IDENTIFIER_GLOBAL_VALUE (name) == 0
2328 && TREE_CODE (x) == FUNCTION_DECL
2329 && ! comptypes (TREE_TYPE (x),
2330 TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name))))
2332 warning_with_decl (x, "type mismatch with previous implicit declaration");
2333 warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name),
2334 "previous implicit declaration of `%s'");
2337 /* In PCC-compatibility mode, extern decls of vars with no current decl
2338 take effect at top level no matter where they are. */
2339 if (flag_traditional && DECL_EXTERNAL (x)
2340 && lookup_name (name) == 0)
2342 tree type = TREE_TYPE (x);
2344 /* But don't do this if the type contains temporary nodes. */
2345 while (type)
2347 if (type == error_mark_node)
2348 break;
2349 if (! TREE_PERMANENT (type))
2351 warning_with_decl (x, "type of external `%s' is not global");
2352 /* By exiting the loop early, we leave TYPE nonzero,
2353 and thus prevent globalization of the decl. */
2354 break;
2356 else if (TREE_CODE (type) == FUNCTION_TYPE
2357 && TYPE_ARG_TYPES (type) != 0)
2358 /* The types might not be truly local,
2359 but the list of arg types certainly is temporary.
2360 Since prototypes are nontraditional,
2361 ok not to do the traditional thing. */
2362 break;
2363 type = TREE_TYPE (type);
2366 if (type == 0)
2367 b = global_binding_level;
2370 /* This name is new in its binding level.
2371 Install the new declaration and return it. */
2372 if (b == global_binding_level)
2374 /* Install a global value. */
2376 /* If the first global decl has external linkage,
2377 warn if we later see static one. */
2378 if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
2379 TREE_PUBLIC (name) = 1;
2381 IDENTIFIER_GLOBAL_VALUE (name) = x;
2383 /* We no longer care about any previous block level declarations. */
2384 IDENTIFIER_LIMBO_VALUE (name) = 0;
2386 /* Don't forget if the function was used via an implicit decl. */
2387 if (IDENTIFIER_IMPLICIT_DECL (name)
2388 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2389 TREE_USED (x) = 1, TREE_USED (name) = 1;
2391 /* Don't forget if its address was taken in that way. */
2392 if (IDENTIFIER_IMPLICIT_DECL (name)
2393 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2394 TREE_ADDRESSABLE (x) = 1;
2396 /* Warn about mismatches against previous implicit decl. */
2397 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2398 /* If this real decl matches the implicit, don't complain. */
2399 && ! (TREE_CODE (x) == FUNCTION_DECL
2400 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x)))
2401 == integer_type_node)))
2402 pedwarn ("`%s' was previously implicitly declared to return `int'",
2403 IDENTIFIER_POINTER (name));
2405 /* If this decl is `static' and an `extern' was seen previously,
2406 that is erroneous. */
2407 if (TREE_PUBLIC (name)
2408 && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
2410 /* Okay to redeclare an ANSI built-in as static. */
2411 if (t != 0 && DECL_BUILT_IN (t))
2413 /* Okay to declare a non-ANSI built-in as anything. */
2414 else if (t != 0 && DECL_BUILT_IN_NONANSI (t))
2416 /* Okay to have global type decl after an earlier extern
2417 declaration inside a lexical block. */
2418 else if (TREE_CODE (x) == TYPE_DECL)
2420 else if (IDENTIFIER_IMPLICIT_DECL (name))
2422 if (! TREE_THIS_VOLATILE (name))
2423 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2424 IDENTIFIER_POINTER (name));
2426 else
2427 pedwarn ("`%s' was declared `extern' and later `static'",
2428 IDENTIFIER_POINTER (name));
2431 else
2433 /* Here to install a non-global value. */
2434 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2435 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2436 IDENTIFIER_LOCAL_VALUE (name) = x;
2438 /* If this is an extern function declaration, see if we
2439 have a global definition or declaration for the function. */
2440 if (oldlocal == 0
2441 && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2442 && oldglobal != 0
2443 && TREE_CODE (x) == FUNCTION_DECL
2444 && TREE_CODE (oldglobal) == FUNCTION_DECL)
2446 /* We have one. Their types must agree. */
2447 if (! comptypes (TREE_TYPE (x),
2448 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
2449 pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one");
2450 else
2452 /* Inner extern decl is inline if global one is.
2453 Copy enough to really inline it. */
2454 if (DECL_INLINE (oldglobal))
2456 DECL_INLINE (x) = DECL_INLINE (oldglobal);
2457 DECL_INITIAL (x) = (current_function_decl == oldglobal
2458 ? 0 : DECL_INITIAL (oldglobal));
2459 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2460 DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2461 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2462 DECL_RESULT (x) = DECL_RESULT (oldglobal);
2463 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2464 DECL_ABSTRACT_ORIGIN (x) = DECL_ORIGIN (oldglobal);
2466 /* Inner extern decl is built-in if global one is. */
2467 if (DECL_BUILT_IN (oldglobal))
2469 DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
2470 DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
2472 /* Keep the arg types from a file-scope fcn defn. */
2473 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
2474 && DECL_INITIAL (oldglobal)
2475 && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
2476 TREE_TYPE (x) = TREE_TYPE (oldglobal);
2480 #if 0 /* This case is probably sometimes the right thing to do. */
2481 /* If we have a local external declaration,
2482 then any file-scope declaration should not
2483 have been static. */
2484 if (oldlocal == 0 && oldglobal != 0
2485 && !TREE_PUBLIC (oldglobal)
2486 && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
2487 warning ("`%s' locally external but globally static",
2488 IDENTIFIER_POINTER (name));
2489 #endif
2491 /* If we have a local external declaration,
2492 and no file-scope declaration has yet been seen,
2493 then if we later have a file-scope decl it must not be static. */
2494 if (oldlocal == 0
2495 && DECL_EXTERNAL (x)
2496 && TREE_PUBLIC (x))
2498 if (oldglobal == 0)
2499 TREE_PUBLIC (name) = 1;
2501 /* Save this decl, so that we can do type checking against
2502 other decls after it falls out of scope.
2504 Only save it once. This prevents temporary decls created in
2505 expand_inline_function from being used here, since this
2506 will have been set when the inline function was parsed.
2507 It also helps give slightly better warnings. */
2508 if (IDENTIFIER_LIMBO_VALUE (name) == 0)
2509 IDENTIFIER_LIMBO_VALUE (name) = x;
2512 /* Warn if shadowing an argument at the top level of the body. */
2513 if (oldlocal != 0 && !DECL_EXTERNAL (x)
2514 /* This warning doesn't apply to the parms of a nested fcn. */
2515 && ! current_binding_level->parm_flag
2516 /* Check that this is one level down from the parms. */
2517 && current_binding_level->level_chain->parm_flag
2518 /* Check that the decl being shadowed
2519 comes from the parm level, one level up. */
2520 && chain_member (oldlocal, current_binding_level->level_chain->names))
2522 if (TREE_CODE (oldlocal) == PARM_DECL)
2523 pedwarn ("declaration of `%s' shadows a parameter",
2524 IDENTIFIER_POINTER (name));
2525 else
2526 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
2527 IDENTIFIER_POINTER (name));
2530 /* Maybe warn if shadowing something else. */
2531 else if (warn_shadow && !DECL_EXTERNAL (x)
2532 /* No shadow warnings for internally generated vars. */
2533 && DECL_SOURCE_LINE (x) != 0
2534 /* No shadow warnings for vars made for inlining. */
2535 && ! DECL_FROM_INLINE (x))
2537 char *id = IDENTIFIER_POINTER (name);
2539 if (TREE_CODE (x) == PARM_DECL
2540 && current_binding_level->level_chain->parm_flag)
2541 /* Don't warn about the parm names in function declarator
2542 within a function declarator.
2543 It would be nice to avoid warning in any function
2544 declarator in a declaration, as opposed to a definition,
2545 but there is no way to tell it's not a definition. */
2547 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
2548 warning ("declaration of `%s' shadows a parameter", id);
2549 else if (oldlocal != 0)
2550 warning ("declaration of `%s' shadows previous local", id);
2551 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
2552 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
2553 warning ("declaration of `%s' shadows global declaration", id);
2556 /* If storing a local value, there may already be one (inherited).
2557 If so, record it for restoration when this binding level ends. */
2558 if (oldlocal != 0)
2559 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2562 /* Keep count of variables in this level with incomplete type. */
2563 if (TYPE_SIZE (TREE_TYPE (x)) == 0)
2564 ++b->n_incomplete;
2567 /* Put decls on list in reverse order.
2568 We will reverse them later if necessary. */
2569 TREE_CHAIN (x) = b->names;
2570 b->names = x;
2572 return x;
2575 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
2577 tree
2578 pushdecl_top_level (x)
2579 tree x;
2581 register tree t;
2582 register struct binding_level *b = current_binding_level;
2584 current_binding_level = global_binding_level;
2585 t = pushdecl (x);
2586 current_binding_level = b;
2587 return t;
2590 /* Generate an implicit declaration for identifier FUNCTIONID
2591 as a function of type int (). Print a warning if appropriate. */
2593 tree
2594 implicitly_declare (functionid)
2595 tree functionid;
2597 register tree decl;
2598 int traditional_warning = 0;
2599 /* Only one "implicit declaration" warning per identifier. */
2600 int implicit_warning;
2602 /* Save the decl permanently so we can warn if definition follows. */
2603 push_obstacks_nochange ();
2604 end_temporary_allocation ();
2606 /* We used to reuse an old implicit decl here,
2607 but this loses with inline functions because it can clobber
2608 the saved decl chains. */
2609 /* if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
2610 decl = IDENTIFIER_IMPLICIT_DECL (functionid);
2611 else */
2612 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2614 /* Warn of implicit decl following explicit local extern decl.
2615 This is probably a program designed for traditional C. */
2616 if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0)
2617 traditional_warning = 1;
2619 /* Warn once of an implicit declaration. */
2620 implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0);
2622 DECL_EXTERNAL (decl) = 1;
2623 TREE_PUBLIC (decl) = 1;
2625 /* Record that we have an implicit decl and this is it. */
2626 IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
2628 /* ANSI standard says implicit declarations are in the innermost block.
2629 So we record the decl in the standard fashion.
2630 If flag_traditional is set, pushdecl does it top-level. */
2631 pushdecl (decl);
2633 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
2634 maybe_objc_check_decl (decl);
2636 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
2638 if (mesg_implicit_function_declaration && implicit_warning)
2640 if (mesg_implicit_function_declaration == 2)
2641 error ("implicit declaration of function `%s'",
2642 IDENTIFIER_POINTER (functionid));
2643 else
2644 warning ("implicit declaration of function `%s'",
2645 IDENTIFIER_POINTER (functionid));
2647 else if (warn_traditional && traditional_warning)
2648 warning ("function `%s' was previously declared within a block",
2649 IDENTIFIER_POINTER (functionid));
2651 /* Write a record describing this implicit function declaration to the
2652 prototypes file (if requested). */
2654 gen_aux_info_record (decl, 0, 1, 0);
2656 pop_obstacks ();
2658 return decl;
2661 /* Return zero if the declaration NEWDECL is valid
2662 when the declaration OLDDECL (assumed to be for the same name)
2663 has already been seen.
2664 Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration,
2665 and 3 if it is a conflicting declaration. */
2667 static int
2668 redeclaration_error_message (newdecl, olddecl)
2669 tree newdecl, olddecl;
2671 if (TREE_CODE (newdecl) == TYPE_DECL)
2673 if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl))
2674 return 0;
2675 /* pushdecl creates distinct types for TYPE_DECLs by calling
2676 build_type_copy, so the above comparison generally fails. We do
2677 another test against the TYPE_MAIN_VARIANT of the olddecl, which
2678 is equivalent to what this code used to do before the build_type_copy
2679 call. The variant type distinction should not matter for traditional
2680 code, because it doesn't have type qualifiers. */
2681 if (flag_traditional
2682 && TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)) == TREE_TYPE (newdecl))
2683 return 0;
2684 if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl))
2685 return 0;
2686 return 1;
2688 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2690 /* Declarations of functions can insist on internal linkage
2691 but they can't be inconsistent with internal linkage,
2692 so there can be no error on that account.
2693 However defining the same name twice is no good. */
2694 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
2695 /* However, defining once as extern inline and a second
2696 time in another way is ok. */
2697 && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
2698 && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
2699 return 1;
2700 return 0;
2702 else if (current_binding_level == global_binding_level)
2704 /* Objects declared at top level: */
2705 /* If at least one is a reference, it's ok. */
2706 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2707 return 0;
2708 /* Reject two definitions. */
2709 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
2710 return 1;
2711 /* Now we have two tentative defs, or one tentative and one real def. */
2712 /* Insist that the linkage match. */
2713 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
2714 return 3;
2715 return 0;
2717 else if (current_binding_level->parm_flag
2718 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2719 return 0;
2720 else
2722 /* Newdecl has block scope. If olddecl has block scope also, then
2723 reject two definitions, and reject a definition together with an
2724 external reference. Otherwise, it is OK, because newdecl must
2725 be an extern reference to olddecl. */
2726 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))
2727 && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl))
2728 return 2;
2729 return 0;
2733 /* Get the LABEL_DECL corresponding to identifier ID as a label.
2734 Create one if none exists so far for the current function.
2735 This function is called for both label definitions and label references. */
2737 tree
2738 lookup_label (id)
2739 tree id;
2741 register tree decl = IDENTIFIER_LABEL_VALUE (id);
2743 if (current_function_decl == 0)
2745 error ("label %s referenced outside of any function",
2746 IDENTIFIER_POINTER (id));
2747 return 0;
2750 /* Use a label already defined or ref'd with this name. */
2751 if (decl != 0)
2753 /* But not if it is inherited and wasn't declared to be inheritable. */
2754 if (DECL_CONTEXT (decl) != current_function_decl
2755 && ! C_DECLARED_LABEL_FLAG (decl))
2756 return shadow_label (id);
2757 return decl;
2760 decl = build_decl (LABEL_DECL, id, void_type_node);
2762 /* Make sure every label has an rtx. */
2763 label_rtx (decl);
2765 /* A label not explicitly declared must be local to where it's ref'd. */
2766 DECL_CONTEXT (decl) = current_function_decl;
2768 DECL_MODE (decl) = VOIDmode;
2770 /* Say where one reference is to the label,
2771 for the sake of the error if it is not defined. */
2772 DECL_SOURCE_LINE (decl) = lineno;
2773 DECL_SOURCE_FILE (decl) = input_filename;
2775 IDENTIFIER_LABEL_VALUE (id) = decl;
2777 named_labels = tree_cons (NULL_TREE, decl, named_labels);
2779 return decl;
2782 /* Make a label named NAME in the current function,
2783 shadowing silently any that may be inherited from containing functions
2784 or containing scopes.
2786 Note that valid use, if the label being shadowed
2787 comes from another scope in the same function,
2788 requires calling declare_nonlocal_label right away. */
2790 tree
2791 shadow_label (name)
2792 tree name;
2794 register tree decl = IDENTIFIER_LABEL_VALUE (name);
2796 if (decl != 0)
2798 register tree dup;
2800 /* Check to make sure that the label hasn't already been declared
2801 at this label scope */
2802 for (dup = named_labels; dup; dup = TREE_CHAIN (dup))
2803 if (TREE_VALUE (dup) == decl)
2805 error ("duplicate label declaration `%s'",
2806 IDENTIFIER_POINTER (name));
2807 error_with_decl (TREE_VALUE (dup),
2808 "this is a previous declaration");
2809 /* Just use the previous declaration. */
2810 return lookup_label (name);
2813 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2814 IDENTIFIER_LABEL_VALUE (name) = decl = 0;
2817 return lookup_label (name);
2820 /* Define a label, specifying the location in the source file.
2821 Return the LABEL_DECL node for the label, if the definition is valid.
2822 Otherwise return 0. */
2824 tree
2825 define_label (filename, line, name)
2826 char *filename;
2827 int line;
2828 tree name;
2830 tree decl = lookup_label (name);
2832 /* If label with this name is known from an outer context, shadow it. */
2833 if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
2835 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2836 IDENTIFIER_LABEL_VALUE (name) = 0;
2837 decl = lookup_label (name);
2840 if (DECL_INITIAL (decl) != 0)
2842 error ("duplicate label `%s'", IDENTIFIER_POINTER (name));
2843 return 0;
2845 else
2847 /* Mark label as having been defined. */
2848 DECL_INITIAL (decl) = error_mark_node;
2849 /* Say where in the source. */
2850 DECL_SOURCE_FILE (decl) = filename;
2851 DECL_SOURCE_LINE (decl) = line;
2852 return decl;
2856 /* Return the list of declarations of the current level.
2857 Note that this list is in reverse order unless/until
2858 you nreverse it; and when you do nreverse it, you must
2859 store the result back using `storedecls' or you will lose. */
2861 tree
2862 getdecls ()
2864 return current_binding_level->names;
2867 /* Return the list of type-tags (for structs, etc) of the current level. */
2869 tree
2870 gettags ()
2872 return current_binding_level->tags;
2875 /* Store the list of declarations of the current level.
2876 This is done for the parameter declarations of a function being defined,
2877 after they are modified in the light of any missing parameters. */
2879 static void
2880 storedecls (decls)
2881 tree decls;
2883 current_binding_level->names = decls;
2886 /* Similarly, store the list of tags of the current level. */
2888 static void
2889 storetags (tags)
2890 tree tags;
2892 current_binding_level->tags = tags;
2895 /* Given NAME, an IDENTIFIER_NODE,
2896 return the structure (or union or enum) definition for that name.
2897 Searches binding levels from BINDING_LEVEL up to the global level.
2898 If THISLEVEL_ONLY is nonzero, searches only the specified context
2899 (but skips any tag-transparent contexts to find one that is
2900 meaningful for tags).
2901 CODE says which kind of type the caller wants;
2902 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2903 If the wrong kind of type is found, an error is reported. */
2905 static tree
2906 lookup_tag (code, name, binding_level, thislevel_only)
2907 enum tree_code code;
2908 struct binding_level *binding_level;
2909 tree name;
2910 int thislevel_only;
2912 register struct binding_level *level;
2914 for (level = binding_level; level; level = level->level_chain)
2916 register tree tail;
2917 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2919 if (TREE_PURPOSE (tail) == name)
2921 if (TREE_CODE (TREE_VALUE (tail)) != code)
2923 /* Definition isn't the kind we were looking for. */
2924 pending_invalid_xref = name;
2925 pending_invalid_xref_file = input_filename;
2926 pending_invalid_xref_line = lineno;
2928 return TREE_VALUE (tail);
2931 if (thislevel_only && ! level->tag_transparent)
2932 return NULL_TREE;
2934 return NULL_TREE;
2937 /* Print an error message now
2938 for a recent invalid struct, union or enum cross reference.
2939 We don't print them immediately because they are not invalid
2940 when used in the `struct foo;' construct for shadowing. */
2942 void
2943 pending_xref_error ()
2945 if (pending_invalid_xref != 0)
2946 error_with_file_and_line (pending_invalid_xref_file,
2947 pending_invalid_xref_line,
2948 "`%s' defined as wrong kind of tag",
2949 IDENTIFIER_POINTER (pending_invalid_xref));
2950 pending_invalid_xref = 0;
2953 /* Given a type, find the tag that was defined for it and return the tag name.
2954 Otherwise return 0. */
2956 static tree
2957 lookup_tag_reverse (type)
2958 tree type;
2960 register struct binding_level *level;
2962 for (level = current_binding_level; level; level = level->level_chain)
2964 register tree tail;
2965 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2967 if (TREE_VALUE (tail) == type)
2968 return TREE_PURPOSE (tail);
2971 return NULL_TREE;
2974 /* Look up NAME in the current binding level and its superiors
2975 in the namespace of variables, functions and typedefs.
2976 Return a ..._DECL node of some kind representing its definition,
2977 or return 0 if it is undefined. */
2979 tree
2980 lookup_name (name)
2981 tree name;
2983 register tree val;
2984 if (current_binding_level != global_binding_level
2985 && IDENTIFIER_LOCAL_VALUE (name))
2986 val = IDENTIFIER_LOCAL_VALUE (name);
2987 else
2988 val = IDENTIFIER_GLOBAL_VALUE (name);
2989 return val;
2992 /* Similar to `lookup_name' but look only at current binding level. */
2994 tree
2995 lookup_name_current_level (name)
2996 tree name;
2998 register tree t;
3000 if (current_binding_level == global_binding_level)
3001 return IDENTIFIER_GLOBAL_VALUE (name);
3003 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
3004 return 0;
3006 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
3007 if (DECL_NAME (t) == name)
3008 break;
3010 return t;
3013 /* Create the predefined scalar types of C,
3014 and some nodes representing standard constants (0, 1, (void *) 0).
3015 Initialize the global binding level.
3016 Make definitions for built-in primitive functions. */
3018 void
3019 init_decl_processing ()
3021 register tree endlink;
3022 /* Either char* or void*. */
3023 tree traditional_ptr_type_node;
3024 /* Data types of memcpy and strlen. */
3025 tree memcpy_ftype, memset_ftype, strlen_ftype;
3026 tree void_ftype_any, ptr_ftype_void, ptr_ftype_ptr;
3027 int wchar_type_size;
3028 tree temp;
3029 tree array_domain_type;
3031 current_function_decl = NULL;
3032 named_labels = NULL;
3033 current_binding_level = NULL_BINDING_LEVEL;
3034 free_binding_level = NULL_BINDING_LEVEL;
3035 pushlevel (0); /* make the binding_level structure for global names */
3036 global_binding_level = current_binding_level;
3038 /* Define `int' and `char' first so that dbx will output them first. */
3040 integer_type_node = make_signed_type (INT_TYPE_SIZE);
3041 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
3042 integer_type_node));
3044 /* Define `char', which is like either `signed char' or `unsigned char'
3045 but not the same as either. */
3047 char_type_node
3048 = (flag_signed_char
3049 ? make_signed_type (CHAR_TYPE_SIZE)
3050 : make_unsigned_type (CHAR_TYPE_SIZE));
3051 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
3052 char_type_node));
3054 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
3055 pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
3056 long_integer_type_node));
3058 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
3059 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
3060 unsigned_type_node));
3062 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
3063 pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
3064 long_unsigned_type_node));
3066 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
3067 pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),
3068 long_long_integer_type_node));
3070 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
3071 pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),
3072 long_long_unsigned_type_node));
3074 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
3075 pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
3076 short_integer_type_node));
3078 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
3079 pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),
3080 short_unsigned_type_node));
3082 /* `unsigned long' is the standard type for sizeof.
3083 Traditionally, use a signed type.
3084 Note that stddef.h uses `unsigned long',
3085 and this must agree, even if long and int are the same size. */
3086 set_sizetype
3087 (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))));
3088 if (flag_traditional && TREE_UNSIGNED (sizetype))
3089 set_sizetype (signed_type (sizetype));
3091 ptrdiff_type_node
3092 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
3094 error_mark_node = make_node (ERROR_MARK);
3095 TREE_TYPE (error_mark_node) = error_mark_node;
3097 /* Define both `signed char' and `unsigned char'. */
3098 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
3099 pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
3100 signed_char_type_node));
3102 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
3103 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
3104 unsigned_char_type_node));
3106 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
3107 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
3109 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
3110 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
3112 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
3113 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
3115 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
3116 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
3118 #if HOST_BITS_PER_WIDE_INT >= 64
3119 intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
3120 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intTI_type_node));
3121 #endif
3123 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
3124 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
3126 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
3127 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
3129 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
3130 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
3132 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
3133 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
3135 #if HOST_BITS_PER_WIDE_INT >= 64
3136 unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
3137 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intTI_type_node));
3138 #endif
3140 float_type_node = make_node (REAL_TYPE);
3141 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
3142 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
3143 float_type_node));
3144 layout_type (float_type_node);
3146 double_type_node = make_node (REAL_TYPE);
3147 if (flag_short_double)
3148 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
3149 else
3150 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
3151 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
3152 double_type_node));
3153 layout_type (double_type_node);
3155 long_double_type_node = make_node (REAL_TYPE);
3156 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
3157 pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
3158 long_double_type_node));
3159 layout_type (long_double_type_node);
3161 complex_integer_type_node = make_node (COMPLEX_TYPE);
3162 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
3163 complex_integer_type_node));
3164 TREE_TYPE (complex_integer_type_node) = integer_type_node;
3165 layout_type (complex_integer_type_node);
3167 complex_float_type_node = make_node (COMPLEX_TYPE);
3168 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
3169 complex_float_type_node));
3170 TREE_TYPE (complex_float_type_node) = float_type_node;
3171 layout_type (complex_float_type_node);
3173 complex_double_type_node = make_node (COMPLEX_TYPE);
3174 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
3175 complex_double_type_node));
3176 TREE_TYPE (complex_double_type_node) = double_type_node;
3177 layout_type (complex_double_type_node);
3179 complex_long_double_type_node = make_node (COMPLEX_TYPE);
3180 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
3181 complex_long_double_type_node));
3182 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
3183 layout_type (complex_long_double_type_node);
3185 wchar_type_node
3186 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
3187 wchar_type_size = TYPE_PRECISION (wchar_type_node);
3188 signed_wchar_type_node = signed_type (wchar_type_node);
3189 unsigned_wchar_type_node = unsigned_type (wchar_type_node);
3191 integer_zero_node = build_int_2 (0, 0);
3192 TREE_TYPE (integer_zero_node) = integer_type_node;
3193 integer_one_node = build_int_2 (1, 0);
3194 TREE_TYPE (integer_one_node) = integer_type_node;
3196 boolean_type_node = integer_type_node;
3197 boolean_true_node = integer_one_node;
3198 boolean_false_node = integer_zero_node;
3200 size_zero_node = build_int_2 (0, 0);
3201 TREE_TYPE (size_zero_node) = sizetype;
3202 size_one_node = build_int_2 (1, 0);
3203 TREE_TYPE (size_one_node) = sizetype;
3205 void_type_node = make_node (VOID_TYPE);
3206 pushdecl (build_decl (TYPE_DECL,
3207 ridpointers[(int) RID_VOID], void_type_node));
3208 layout_type (void_type_node); /* Uses integer_zero_node */
3209 /* We are not going to have real types in C with less than byte alignment,
3210 so we might as well not have any types that claim to have it. */
3211 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
3213 null_pointer_node = build_int_2 (0, 0);
3214 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
3215 layout_type (TREE_TYPE (null_pointer_node));
3217 string_type_node = build_pointer_type (char_type_node);
3218 const_string_type_node
3219 = build_pointer_type (build_type_variant (char_type_node, 1, 0));
3221 /* Make a type to be the domain of a few array types
3222 whose domains don't really matter.
3223 200 is small enough that it always fits in size_t
3224 and large enough that it can hold most function names for the
3225 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
3226 array_domain_type = build_index_type (build_int_2 (200, 0));
3228 /* make a type for arrays of characters.
3229 With luck nothing will ever really depend on the length of this
3230 array type. */
3231 char_array_type_node
3232 = build_array_type (char_type_node, array_domain_type);
3233 /* Likewise for arrays of ints. */
3234 int_array_type_node
3235 = build_array_type (integer_type_node, array_domain_type);
3236 /* This is for wide string constants. */
3237 wchar_array_type_node
3238 = build_array_type (wchar_type_node, array_domain_type);
3240 default_function_type
3241 = build_function_type (integer_type_node, NULL_TREE);
3243 ptr_type_node = build_pointer_type (void_type_node);
3244 const_ptr_type_node
3245 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
3247 endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
3249 void_ftype_any
3250 = build_function_type (void_type_node, NULL_TREE);
3252 float_ftype_float
3253 = build_function_type (float_type_node,
3254 tree_cons (NULL_TREE, float_type_node, endlink));
3256 double_ftype_double
3257 = build_function_type (double_type_node,
3258 tree_cons (NULL_TREE, double_type_node, endlink));
3260 ldouble_ftype_ldouble
3261 = build_function_type (long_double_type_node,
3262 tree_cons (NULL_TREE, long_double_type_node,
3263 endlink));
3265 double_ftype_double_double
3266 = build_function_type (double_type_node,
3267 tree_cons (NULL_TREE, double_type_node,
3268 tree_cons (NULL_TREE,
3269 double_type_node, endlink)));
3271 int_ftype_int
3272 = build_function_type (integer_type_node,
3273 tree_cons (NULL_TREE, integer_type_node, endlink));
3275 long_ftype_long
3276 = build_function_type (long_integer_type_node,
3277 tree_cons (NULL_TREE,
3278 long_integer_type_node, endlink));
3280 void_ftype_ptr_ptr_int
3281 = build_function_type (void_type_node,
3282 tree_cons (NULL_TREE, ptr_type_node,
3283 tree_cons (NULL_TREE, ptr_type_node,
3284 tree_cons (NULL_TREE,
3285 integer_type_node,
3286 endlink))));
3288 int_ftype_cptr_cptr_sizet
3289 = build_function_type (integer_type_node,
3290 tree_cons (NULL_TREE, const_ptr_type_node,
3291 tree_cons (NULL_TREE, const_ptr_type_node,
3292 tree_cons (NULL_TREE,
3293 sizetype,
3294 endlink))));
3296 void_ftype_ptr_int_int
3297 = build_function_type (void_type_node,
3298 tree_cons (NULL_TREE, ptr_type_node,
3299 tree_cons (NULL_TREE, integer_type_node,
3300 tree_cons (NULL_TREE,
3301 integer_type_node,
3302 endlink))));
3304 string_ftype_ptr_ptr /* strcpy prototype */
3305 = build_function_type (string_type_node,
3306 tree_cons (NULL_TREE, string_type_node,
3307 tree_cons (NULL_TREE,
3308 const_string_type_node,
3309 endlink)));
3311 int_ftype_string_string /* strcmp prototype */
3312 = build_function_type (integer_type_node,
3313 tree_cons (NULL_TREE, const_string_type_node,
3314 tree_cons (NULL_TREE,
3315 const_string_type_node,
3316 endlink)));
3318 strlen_ftype /* strlen prototype */
3319 = build_function_type (flag_traditional ? integer_type_node : sizetype,
3320 tree_cons (NULL_TREE, const_string_type_node,
3321 endlink));
3323 traditional_ptr_type_node
3324 = (flag_traditional ? string_type_node : ptr_type_node);
3326 memcpy_ftype /* memcpy prototype */
3327 = build_function_type (traditional_ptr_type_node,
3328 tree_cons (NULL_TREE, ptr_type_node,
3329 tree_cons (NULL_TREE, const_ptr_type_node,
3330 tree_cons (NULL_TREE,
3331 sizetype,
3332 endlink))));
3334 memset_ftype /* memset prototype */
3335 = build_function_type (traditional_ptr_type_node,
3336 tree_cons (NULL_TREE, ptr_type_node,
3337 tree_cons (NULL_TREE, integer_type_node,
3338 tree_cons (NULL_TREE,
3339 sizetype,
3340 endlink))));
3342 ptr_ftype_void = build_function_type (ptr_type_node, endlink);
3343 ptr_ftype_ptr
3344 = build_function_type (ptr_type_node,
3345 tree_cons (NULL_TREE, ptr_type_node, endlink));
3347 builtin_function ("__builtin_constant_p", default_function_type,
3348 BUILT_IN_CONSTANT_P, NULL_PTR);
3350 builtin_function ("__builtin_return_address",
3351 build_function_type (ptr_type_node,
3352 tree_cons (NULL_TREE,
3353 unsigned_type_node,
3354 endlink)),
3355 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
3357 builtin_function ("__builtin_frame_address",
3358 build_function_type (ptr_type_node,
3359 tree_cons (NULL_TREE,
3360 unsigned_type_node,
3361 endlink)),
3362 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
3364 builtin_function ("__builtin_aggregate_incoming_address",
3365 build_function_type (ptr_type_node, NULL_TREE),
3366 BUILT_IN_AGGREGATE_INCOMING_ADDRESS, NULL_PTR);
3368 /* Hooks for the DWARF 2 __throw routine. */
3369 builtin_function ("__builtin_unwind_init",
3370 build_function_type (void_type_node, endlink),
3371 BUILT_IN_UNWIND_INIT, NULL_PTR);
3372 builtin_function ("__builtin_dwarf_cfa", ptr_ftype_void,
3373 BUILT_IN_DWARF_CFA, NULL_PTR);
3374 builtin_function ("__builtin_dwarf_fp_regnum",
3375 build_function_type (unsigned_type_node, endlink),
3376 BUILT_IN_DWARF_FP_REGNUM, NULL_PTR);
3377 builtin_function ("__builtin_dwarf_reg_size", int_ftype_int,
3378 BUILT_IN_DWARF_REG_SIZE, NULL_PTR);
3379 builtin_function ("__builtin_frob_return_addr", ptr_ftype_ptr,
3380 BUILT_IN_FROB_RETURN_ADDR, NULL_PTR);
3381 builtin_function ("__builtin_extract_return_addr", ptr_ftype_ptr,
3382 BUILT_IN_EXTRACT_RETURN_ADDR, NULL_PTR);
3383 builtin_function
3384 ("__builtin_eh_return",
3385 build_function_type (void_type_node,
3386 tree_cons (NULL_TREE, ptr_type_node,
3387 tree_cons (NULL_TREE,
3388 type_for_mode (ptr_mode, 0),
3389 tree_cons (NULL_TREE,
3390 ptr_type_node,
3391 endlink)))),
3392 BUILT_IN_EH_RETURN, NULL_PTR);
3394 builtin_function ("__builtin_alloca",
3395 build_function_type (ptr_type_node,
3396 tree_cons (NULL_TREE,
3397 sizetype,
3398 endlink)),
3399 BUILT_IN_ALLOCA, "alloca");
3400 builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
3401 /* Define alloca, ffs as builtins.
3402 Declare _exit just to mark it as volatile. */
3403 if (! flag_no_builtin && !flag_no_nonansi_builtin)
3405 temp = builtin_function ("alloca",
3406 build_function_type (ptr_type_node,
3407 tree_cons (NULL_TREE,
3408 sizetype,
3409 endlink)),
3410 BUILT_IN_ALLOCA, NULL_PTR);
3411 /* Suppress error if redefined as a non-function. */
3412 DECL_BUILT_IN_NONANSI (temp) = 1;
3413 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
3414 /* Suppress error if redefined as a non-function. */
3415 DECL_BUILT_IN_NONANSI (temp) = 1;
3416 temp = builtin_function ("_exit", void_ftype_any, NOT_BUILT_IN,
3417 NULL_PTR);
3418 TREE_THIS_VOLATILE (temp) = 1;
3419 TREE_SIDE_EFFECTS (temp) = 1;
3420 /* Suppress error if redefined as a non-function. */
3421 DECL_BUILT_IN_NONANSI (temp) = 1;
3424 builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
3425 builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
3426 NULL_PTR);
3427 builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
3428 NULL_PTR);
3429 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3430 NULL_PTR);
3431 builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS,
3432 NULL_PTR);
3433 builtin_function ("__builtin_saveregs",
3434 build_function_type (ptr_type_node, NULL_TREE),
3435 BUILT_IN_SAVEREGS, NULL_PTR);
3436 /* EXPAND_BUILTIN_VARARGS is obsolete. */
3437 #if 0
3438 builtin_function ("__builtin_varargs",
3439 build_function_type (ptr_type_node,
3440 tree_cons (NULL_TREE,
3441 integer_type_node,
3442 endlink)),
3443 BUILT_IN_VARARGS, NULL_PTR);
3444 #endif
3445 builtin_function ("__builtin_classify_type", default_function_type,
3446 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
3447 builtin_function ("__builtin_next_arg",
3448 build_function_type (ptr_type_node, NULL_TREE),
3449 BUILT_IN_NEXT_ARG, NULL_PTR);
3450 builtin_function ("__builtin_args_info",
3451 build_function_type (integer_type_node,
3452 tree_cons (NULL_TREE,
3453 integer_type_node,
3454 endlink)),
3455 BUILT_IN_ARGS_INFO, NULL_PTR);
3457 /* Untyped call and return. */
3458 builtin_function ("__builtin_apply_args",
3459 build_function_type (ptr_type_node, NULL_TREE),
3460 BUILT_IN_APPLY_ARGS, NULL_PTR);
3462 temp = tree_cons (NULL_TREE,
3463 build_pointer_type (build_function_type (void_type_node,
3464 NULL_TREE)),
3465 tree_cons (NULL_TREE,
3466 ptr_type_node,
3467 tree_cons (NULL_TREE,
3468 sizetype,
3469 endlink)));
3470 builtin_function ("__builtin_apply",
3471 build_function_type (ptr_type_node, temp),
3472 BUILT_IN_APPLY, NULL_PTR);
3473 builtin_function ("__builtin_return",
3474 build_function_type (void_type_node,
3475 tree_cons (NULL_TREE,
3476 ptr_type_node,
3477 endlink)),
3478 BUILT_IN_RETURN, NULL_PTR);
3480 /* Currently under experimentation. */
3481 builtin_function ("__builtin_memcpy", memcpy_ftype,
3482 BUILT_IN_MEMCPY, "memcpy");
3483 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
3484 BUILT_IN_MEMCMP, "memcmp");
3485 builtin_function ("__builtin_memset", memset_ftype,
3486 BUILT_IN_MEMSET, "memset");
3487 builtin_function ("__builtin_strcmp", int_ftype_string_string,
3488 BUILT_IN_STRCMP, "strcmp");
3489 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
3490 BUILT_IN_STRCPY, "strcpy");
3491 builtin_function ("__builtin_strlen", strlen_ftype,
3492 BUILT_IN_STRLEN, "strlen");
3493 builtin_function ("__builtin_sqrtf", float_ftype_float,
3494 BUILT_IN_FSQRT, "sqrtf");
3495 builtin_function ("__builtin_fsqrt", double_ftype_double,
3496 BUILT_IN_FSQRT, "sqrt");
3497 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
3498 BUILT_IN_FSQRT, "sqrtl");
3499 builtin_function ("__builtin_sinf", float_ftype_float,
3500 BUILT_IN_SIN, "sinf");
3501 builtin_function ("__builtin_sin", double_ftype_double,
3502 BUILT_IN_SIN, "sin");
3503 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
3504 BUILT_IN_SIN, "sinl");
3505 builtin_function ("__builtin_cosf", float_ftype_float,
3506 BUILT_IN_COS, "cosf");
3507 builtin_function ("__builtin_cos", double_ftype_double,
3508 BUILT_IN_COS, "cos");
3509 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
3510 BUILT_IN_COS, "cosl");
3511 builtin_function ("__builtin_setjmp",
3512 build_function_type (integer_type_node,
3513 tree_cons (NULL_TREE,
3514 ptr_type_node, endlink)),
3515 BUILT_IN_SETJMP, NULL_PTR);
3516 builtin_function ("__builtin_longjmp",
3517 build_function_type
3518 (void_type_node,
3519 tree_cons (NULL, ptr_type_node,
3520 tree_cons (NULL_TREE,
3521 integer_type_node,
3522 endlink))),
3523 BUILT_IN_LONGJMP, NULL_PTR);
3524 builtin_function ("__builtin_trap",
3525 build_function_type (void_type_node, endlink),
3526 BUILT_IN_TRAP, NULL_PTR);
3528 /* In an ANSI C program, it is okay to supply built-in meanings
3529 for these functions, since applications cannot validly use them
3530 with any other meaning.
3531 However, honor the -fno-builtin option. */
3532 if (!flag_no_builtin)
3534 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
3535 builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR);
3536 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
3537 builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3538 NULL_PTR);
3539 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
3540 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
3541 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
3542 NULL_PTR);
3543 builtin_function ("memset", memset_ftype, BUILT_IN_MEMSET, NULL_PTR);
3544 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
3545 NULL_PTR);
3546 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
3547 NULL_PTR);
3548 builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR);
3549 builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR);
3550 builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR);
3551 builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
3552 NULL_PTR);
3553 builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR);
3554 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
3555 builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR);
3556 builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR);
3557 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
3558 builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR);
3560 /* Declare these functions volatile
3561 to avoid spurious "control drops through" warnings. */
3562 /* Don't specify the argument types, to avoid errors
3563 from certain code which isn't valid in ANSI but which exists. */
3564 temp = builtin_function ("abort", void_ftype_any, NOT_BUILT_IN,
3565 NULL_PTR);
3566 TREE_THIS_VOLATILE (temp) = 1;
3567 TREE_SIDE_EFFECTS (temp) = 1;
3568 temp = builtin_function ("exit", void_ftype_any, NOT_BUILT_IN, NULL_PTR);
3569 TREE_THIS_VOLATILE (temp) = 1;
3570 TREE_SIDE_EFFECTS (temp) = 1;
3573 #if 0
3574 /* Support for these has not been written in either expand_builtin
3575 or build_function_call. */
3576 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
3577 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
3578 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
3579 NULL_PTR);
3580 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
3581 NULL_PTR);
3582 builtin_function ("__builtin_fmod", double_ftype_double_double,
3583 BUILT_IN_FMOD, NULL_PTR);
3584 builtin_function ("__builtin_frem", double_ftype_double_double,
3585 BUILT_IN_FREM, NULL_PTR);
3586 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
3587 NULL_PTR);
3588 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
3589 NULL_PTR);
3590 #endif
3592 pedantic_lvalues = pedantic;
3594 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
3595 declare_function_name ();
3597 start_identifier_warnings ();
3599 /* Prepare to check format strings against argument lists. */
3600 init_function_format_info ();
3602 init_iterators ();
3604 incomplete_decl_finalize_hook = finish_incomplete_decl;
3606 lang_get_alias_set = c_get_alias_set;
3609 /* Return a definition for a builtin function named NAME and whose data type
3610 is TYPE. TYPE should be a function type with argument types.
3611 FUNCTION_CODE tells later passes how to compile calls to this function.
3612 See tree.h for its possible values.
3614 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
3615 the name to be called if we can't opencode the function. */
3617 tree
3618 builtin_function (name, type, function_code, library_name)
3619 const char *name;
3620 tree type;
3621 enum built_in_function function_code;
3622 const char *library_name;
3624 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
3625 DECL_EXTERNAL (decl) = 1;
3626 TREE_PUBLIC (decl) = 1;
3627 /* If -traditional, permit redefining a builtin function any way you like.
3628 (Though really, if the program redefines these functions,
3629 it probably won't work right unless compiled with -fno-builtin.) */
3630 if (flag_traditional && name[0] != '_')
3631 DECL_BUILT_IN_NONANSI (decl) = 1;
3632 if (library_name)
3633 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
3634 make_decl_rtl (decl, NULL_PTR, 1);
3635 pushdecl (decl);
3636 if (function_code != NOT_BUILT_IN)
3638 DECL_BUILT_IN (decl) = 1;
3639 DECL_FUNCTION_CODE (decl) = function_code;
3641 /* Warn if a function in the namespace for users
3642 is used without an occasion to consider it declared. */
3643 if (name[0] != '_' || name[1] != '_')
3644 C_DECL_ANTICIPATED (decl) = 1;
3646 return decl;
3649 /* Called when a declaration is seen that contains no names to declare.
3650 If its type is a reference to a structure, union or enum inherited
3651 from a containing scope, shadow that tag name for the current scope
3652 with a forward reference.
3653 If its type defines a new named structure or union
3654 or defines an enum, it is valid but we need not do anything here.
3655 Otherwise, it is an error. */
3657 void
3658 shadow_tag (declspecs)
3659 tree declspecs;
3661 shadow_tag_warned (declspecs, 0);
3664 void
3665 shadow_tag_warned (declspecs, warned)
3666 tree declspecs;
3667 int warned;
3668 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
3669 no pedwarn. */
3671 int found_tag = 0;
3672 register tree link;
3673 tree specs, attrs;
3675 pending_invalid_xref = 0;
3677 /* Remove the attributes from declspecs, since they will confuse the
3678 following code. */
3679 split_specs_attrs (declspecs, &specs, &attrs);
3681 for (link = specs; link; link = TREE_CHAIN (link))
3683 register tree value = TREE_VALUE (link);
3684 register enum tree_code code = TREE_CODE (value);
3686 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
3687 /* Used to test also that TYPE_SIZE (value) != 0.
3688 That caused warning for `struct foo;' at top level in the file. */
3690 register tree name = lookup_tag_reverse (value);
3691 register tree t;
3693 found_tag++;
3695 if (name == 0)
3697 if (warned != 1 && code != ENUMERAL_TYPE)
3698 /* Empty unnamed enum OK */
3700 pedwarn ("unnamed struct/union that defines no instances");
3701 warned = 1;
3704 else
3706 t = lookup_tag (code, name, current_binding_level, 1);
3708 if (t == 0)
3710 t = make_node (code);
3711 pushtag (name, t);
3715 else
3717 if (!warned && ! in_system_header)
3719 warning ("useless keyword or type name in empty declaration");
3720 warned = 2;
3725 if (found_tag > 1)
3726 error ("two types specified in one empty declaration");
3728 if (warned != 1)
3730 if (found_tag == 0)
3731 pedwarn ("empty declaration");
3735 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
3737 tree
3738 groktypename (typename)
3739 tree typename;
3741 if (TREE_CODE (typename) != TREE_LIST)
3742 return typename;
3743 return grokdeclarator (TREE_VALUE (typename),
3744 TREE_PURPOSE (typename),
3745 TYPENAME, 0);
3748 /* Return a PARM_DECL node for a given pair of specs and declarator. */
3750 tree
3751 groktypename_in_parm_context (typename)
3752 tree typename;
3754 if (TREE_CODE (typename) != TREE_LIST)
3755 return typename;
3756 return grokdeclarator (TREE_VALUE (typename),
3757 TREE_PURPOSE (typename),
3758 PARM, 0);
3761 /* Decode a declarator in an ordinary declaration or data definition.
3762 This is called as soon as the type information and variable name
3763 have been parsed, before parsing the initializer if any.
3764 Here we create the ..._DECL node, fill in its type,
3765 and put it on the list of decls for the current context.
3766 The ..._DECL node is returned as the value.
3768 Exception: for arrays where the length is not specified,
3769 the type is left null, to be filled in by `finish_decl'.
3771 Function definitions do not come here; they go to start_function
3772 instead. However, external and forward declarations of functions
3773 do go through here. Structure field declarations are done by
3774 grokfield and not through here. */
3776 /* Set this to zero to debug not using the temporary obstack
3777 to parse initializers. */
3778 int debug_temp_inits = 1;
3780 tree
3781 start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
3782 tree declarator, declspecs;
3783 int initialized;
3784 tree attributes, prefix_attributes;
3786 register tree decl = grokdeclarator (declarator, declspecs,
3787 NORMAL, initialized);
3788 register tree tem;
3789 int init_written = initialized;
3791 /* The corresponding pop_obstacks is in finish_decl. */
3792 push_obstacks_nochange ();
3794 if (warn_main && TREE_CODE (decl) != FUNCTION_DECL
3795 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "main"))
3796 warning_with_decl (decl, "`%s' is usually a function");
3798 if (initialized)
3799 /* Is it valid for this decl to have an initializer at all?
3800 If not, set INITIALIZED to zero, which will indirectly
3801 tell `finish_decl' to ignore the initializer once it is parsed. */
3802 switch (TREE_CODE (decl))
3804 case TYPE_DECL:
3805 /* typedef foo = bar means give foo the same type as bar.
3806 We haven't parsed bar yet, so `finish_decl' will fix that up.
3807 Any other case of an initialization in a TYPE_DECL is an error. */
3808 if (pedantic || list_length (declspecs) > 1)
3810 error ("typedef `%s' is initialized",
3811 IDENTIFIER_POINTER (DECL_NAME (decl)));
3812 initialized = 0;
3814 break;
3816 case FUNCTION_DECL:
3817 error ("function `%s' is initialized like a variable",
3818 IDENTIFIER_POINTER (DECL_NAME (decl)));
3819 initialized = 0;
3820 break;
3822 case PARM_DECL:
3823 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3824 error ("parameter `%s' is initialized",
3825 IDENTIFIER_POINTER (DECL_NAME (decl)));
3826 initialized = 0;
3827 break;
3829 default:
3830 /* Don't allow initializations for incomplete types
3831 except for arrays which might be completed by the initialization. */
3832 if (TYPE_SIZE (TREE_TYPE (decl)) != 0)
3834 /* A complete type is ok if size is fixed. */
3836 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3837 || C_DECL_VARIABLE_SIZE (decl))
3839 error ("variable-sized object may not be initialized");
3840 initialized = 0;
3843 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3845 error ("variable `%s' has initializer but incomplete type",
3846 IDENTIFIER_POINTER (DECL_NAME (decl)));
3847 initialized = 0;
3849 else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0)
3851 error ("elements of array `%s' have incomplete type",
3852 IDENTIFIER_POINTER (DECL_NAME (decl)));
3853 initialized = 0;
3857 if (initialized)
3859 #if 0 /* Seems redundant with grokdeclarator. */
3860 if (current_binding_level != global_binding_level
3861 && DECL_EXTERNAL (decl)
3862 && TREE_CODE (decl) != FUNCTION_DECL)
3863 warning ("declaration of `%s' has `extern' and is initialized",
3864 IDENTIFIER_POINTER (DECL_NAME (decl)));
3865 #endif
3866 DECL_EXTERNAL (decl) = 0;
3867 if (current_binding_level == global_binding_level)
3868 TREE_STATIC (decl) = 1;
3870 /* Tell `pushdecl' this is an initialized decl
3871 even though we don't yet have the initializer expression.
3872 Also tell `finish_decl' it may store the real initializer. */
3873 DECL_INITIAL (decl) = error_mark_node;
3876 /* If this is a function declaration, write a record describing it to the
3877 prototypes file (if requested). */
3879 if (TREE_CODE (decl) == FUNCTION_DECL)
3880 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
3882 /* ANSI specifies that a tentative definition which is not merged with
3883 a non-tentative definition behaves exactly like a definition with an
3884 initializer equal to zero. (Section 3.7.2)
3885 -fno-common gives strict ANSI behavior. Usually you don't want it.
3886 This matters only for variables with external linkage. */
3887 if (! flag_no_common || ! TREE_PUBLIC (decl))
3888 DECL_COMMON (decl) = 1;
3890 #ifdef SET_DEFAULT_DECL_ATTRIBUTES
3891 SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes);
3892 #endif
3894 /* Set attributes here so if duplicate decl, will have proper attributes. */
3895 decl_attributes (decl, attributes, prefix_attributes);
3897 /* Add this decl to the current binding level.
3898 TEM may equal DECL or it may be a previous decl of the same name. */
3899 tem = pushdecl (decl);
3901 /* For a local variable, define the RTL now. */
3902 if (current_binding_level != global_binding_level
3903 /* But not if this is a duplicate decl
3904 and we preserved the rtl from the previous one
3905 (which may or may not happen). */
3906 && DECL_RTL (tem) == 0)
3908 if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
3909 expand_decl (tem);
3910 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
3911 && DECL_INITIAL (tem) != 0)
3912 expand_decl (tem);
3915 if (init_written)
3917 /* When parsing and digesting the initializer,
3918 use temporary storage. Do this even if we will ignore the value. */
3919 if (current_binding_level == global_binding_level && debug_temp_inits)
3920 temporary_allocation ();
3923 return tem;
3926 /* Finish processing of a declaration;
3927 install its initial value.
3928 If the length of an array type is not known before,
3929 it must be determined now, from the initial value, or it is an error. */
3931 void
3932 finish_decl (decl, init, asmspec_tree)
3933 tree decl, init;
3934 tree asmspec_tree;
3936 register tree type = TREE_TYPE (decl);
3937 int was_incomplete = (DECL_SIZE (decl) == 0);
3938 int temporary = allocation_temporary_p ();
3939 char *asmspec = 0;
3941 /* If a name was specified, get the string. */
3942 if (asmspec_tree)
3943 asmspec = TREE_STRING_POINTER (asmspec_tree);
3945 /* If `start_decl' didn't like having an initialization, ignore it now. */
3947 if (init != 0 && DECL_INITIAL (decl) == 0)
3948 init = 0;
3949 /* Don't crash if parm is initialized. */
3950 if (TREE_CODE (decl) == PARM_DECL)
3951 init = 0;
3953 if (ITERATOR_P (decl))
3955 if (init == 0)
3956 error_with_decl (decl, "iterator has no initial value");
3957 else
3958 init = save_expr (init);
3961 if (init)
3963 if (TREE_CODE (decl) != TYPE_DECL)
3964 store_init_value (decl, init);
3965 else
3967 /* typedef foo = bar; store the type of bar as the type of foo. */
3968 TREE_TYPE (decl) = TREE_TYPE (init);
3969 DECL_INITIAL (decl) = init = 0;
3973 /* Pop back to the obstack that is current for this binding level.
3974 This is because MAXINDEX, rtl, etc. to be made below
3975 must go in the permanent obstack. But don't discard the
3976 temporary data yet. */
3977 pop_obstacks ();
3978 #if 0 /* pop_obstacks was near the end; this is what was here. */
3979 if (current_binding_level == global_binding_level && temporary)
3980 end_temporary_allocation ();
3981 #endif
3983 /* Deduce size of array from initialization, if not already known */
3985 if (TREE_CODE (type) == ARRAY_TYPE
3986 && TYPE_DOMAIN (type) == 0
3987 && TREE_CODE (decl) != TYPE_DECL)
3989 int do_default
3990 = (TREE_STATIC (decl)
3991 /* Even if pedantic, an external linkage array
3992 may have incomplete type at first. */
3993 ? pedantic && !TREE_PUBLIC (decl)
3994 : !DECL_EXTERNAL (decl));
3995 int failure
3996 = complete_array_type (type, DECL_INITIAL (decl), do_default);
3998 /* Get the completed type made by complete_array_type. */
3999 type = TREE_TYPE (decl);
4001 if (failure == 1)
4002 error_with_decl (decl, "initializer fails to determine size of `%s'");
4004 if (failure == 2)
4006 if (do_default)
4007 error_with_decl (decl, "array size missing in `%s'");
4008 /* If a `static' var's size isn't known,
4009 make it extern as well as static, so it does not get
4010 allocated.
4011 If it is not `static', then do not mark extern;
4012 finish_incomplete_decl will give it a default size
4013 and it will get allocated. */
4014 else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl))
4015 DECL_EXTERNAL (decl) = 1;
4018 /* TYPE_MAX_VALUE is always one less than the number of elements
4019 in the array, because we start counting at zero. Therefore,
4020 warn only if the value is less than zero. */
4021 if (pedantic && TYPE_DOMAIN (type) != 0
4022 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
4023 error_with_decl (decl, "zero or negative size array `%s'");
4025 layout_decl (decl, 0);
4028 if (TREE_CODE (decl) == VAR_DECL)
4030 if (DECL_SIZE (decl) == 0
4031 && TYPE_SIZE (TREE_TYPE (decl)) != 0)
4032 layout_decl (decl, 0);
4034 if (DECL_SIZE (decl) == 0
4035 && (TREE_STATIC (decl)
4037 /* A static variable with an incomplete type
4038 is an error if it is initialized.
4039 Also if it is not file scope.
4040 Otherwise, let it through, but if it is not `extern'
4041 then it may cause an error message later. */
4042 /* A duplicate_decls call could have changed an extern
4043 declaration into a file scope one. This can be detected
4044 by TREE_ASM_WRITTEN being set. */
4045 (DECL_INITIAL (decl) != 0
4046 || (DECL_CONTEXT (decl) != 0 && ! TREE_ASM_WRITTEN (decl)))
4048 /* An automatic variable with an incomplete type
4049 is an error. */
4050 !DECL_EXTERNAL (decl)))
4052 error_with_decl (decl, "storage size of `%s' isn't known");
4053 TREE_TYPE (decl) = error_mark_node;
4056 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
4057 && DECL_SIZE (decl) != 0)
4059 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
4060 constant_expression_warning (DECL_SIZE (decl));
4061 else
4062 error_with_decl (decl, "storage size of `%s' isn't constant");
4065 if (TREE_USED (type))
4066 TREE_USED (decl) = 1;
4069 /* If this is a function and an assembler name is specified, it isn't
4070 builtin any more. Also reset DECL_RTL so we can give it its new
4071 name. */
4072 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
4074 DECL_BUILT_IN (decl) = 0;
4075 DECL_RTL (decl) = 0;
4078 /* Output the assembler code and/or RTL code for variables and functions,
4079 unless the type is an undefined structure or union.
4080 If not, it will get done when the type is completed. */
4082 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
4084 if ((flag_traditional || TREE_PERMANENT (decl))
4085 && allocation_temporary_p ())
4087 push_obstacks_nochange ();
4088 end_temporary_allocation ();
4089 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
4090 maybe_objc_check_decl (decl);
4091 rest_of_decl_compilation (decl, asmspec,
4092 (DECL_CONTEXT (decl) == 0
4093 || TREE_ASM_WRITTEN (decl)),
4095 pop_obstacks ();
4097 else
4099 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
4100 maybe_objc_check_decl (decl);
4101 rest_of_decl_compilation (decl, asmspec, DECL_CONTEXT (decl) == 0,
4104 if (DECL_CONTEXT (decl) != 0)
4106 /* Recompute the RTL of a local array now
4107 if it used to be an incomplete type. */
4108 if (was_incomplete
4109 && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
4111 /* If we used it already as memory, it must stay in memory. */
4112 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
4113 /* If it's still incomplete now, no init will save it. */
4114 if (DECL_SIZE (decl) == 0)
4115 DECL_INITIAL (decl) = 0;
4116 expand_decl (decl);
4118 /* Compute and store the initial value. */
4119 if (TREE_CODE (decl) != FUNCTION_DECL)
4120 expand_decl_init (decl);
4124 if (TREE_CODE (decl) == TYPE_DECL)
4126 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
4127 maybe_objc_check_decl (decl);
4128 rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == 0,
4132 /* ??? After 2.3, test (init != 0) instead of TREE_CODE. */
4133 /* This test used to include TREE_PERMANENT, however, we have the same
4134 problem with initializers at the function level. Such initializers get
4135 saved until the end of the function on the momentary_obstack. */
4136 if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
4137 && temporary
4138 /* DECL_INITIAL is not defined in PARM_DECLs, since it shares
4139 space with DECL_ARG_TYPE. */
4140 && TREE_CODE (decl) != PARM_DECL)
4142 /* We need to remember that this array HAD an initialization,
4143 but discard the actual temporary nodes,
4144 since we can't have a permanent node keep pointing to them. */
4145 /* We make an exception for inline functions, since it's
4146 normal for a local extern redeclaration of an inline function
4147 to have a copy of the top-level decl's DECL_INLINE. */
4148 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
4150 /* If this is a const variable, then preserve the
4151 initializer instead of discarding it so that we can optimize
4152 references to it. */
4153 /* This test used to include TREE_STATIC, but this won't be set
4154 for function level initializers. */
4155 if (TREE_READONLY (decl) || ITERATOR_P (decl))
4157 preserve_initializer ();
4158 /* Hack? Set the permanent bit for something that is permanent,
4159 but not on the permanent obstack, so as to convince
4160 output_constant_def to make its rtl on the permanent
4161 obstack. */
4162 TREE_PERMANENT (DECL_INITIAL (decl)) = 1;
4164 /* The initializer and DECL must have the same (or equivalent
4165 types), but if the initializer is a STRING_CST, its type
4166 might not be on the right obstack, so copy the type
4167 of DECL. */
4168 TREE_TYPE (DECL_INITIAL (decl)) = type;
4170 else
4171 DECL_INITIAL (decl) = error_mark_node;
4175 /* If requested, warn about definitions of large data objects. */
4177 if (warn_larger_than
4178 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
4179 && !DECL_EXTERNAL (decl))
4181 register tree decl_size = DECL_SIZE (decl);
4183 if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
4185 unsigned units = TREE_INT_CST_LOW(decl_size) / BITS_PER_UNIT;
4187 if (units > larger_than_size)
4188 warning_with_decl (decl, "size of `%s' is %u bytes", units);
4192 #if 0
4193 /* Resume permanent allocation, if not within a function. */
4194 /* The corresponding push_obstacks_nochange is in start_decl,
4195 and in push_parm_decl and in grokfield. */
4196 pop_obstacks ();
4197 #endif
4199 /* If we have gone back from temporary to permanent allocation,
4200 actually free the temporary space that we no longer need. */
4201 if (temporary && !allocation_temporary_p ())
4202 permanent_allocation (0);
4204 /* At the end of a declaration, throw away any variable type sizes
4205 of types defined inside that declaration. There is no use
4206 computing them in the following function definition. */
4207 if (current_binding_level == global_binding_level)
4208 get_pending_sizes ();
4211 /* If DECL has a cleanup, build and return that cleanup here.
4212 This is a callback called by expand_expr. */
4214 tree
4215 maybe_build_cleanup (decl)
4216 tree decl ATTRIBUTE_UNUSED;
4218 /* There are no cleanups in C. */
4219 return NULL_TREE;
4222 /* Given a parsed parameter declaration,
4223 decode it into a PARM_DECL and push that on the current binding level.
4224 Also, for the sake of forward parm decls,
4225 record the given order of parms in `parm_order'. */
4227 void
4228 push_parm_decl (parm)
4229 tree parm;
4231 tree decl;
4232 int old_immediate_size_expand = immediate_size_expand;
4233 /* Don't try computing parm sizes now -- wait till fn is called. */
4234 immediate_size_expand = 0;
4236 /* The corresponding pop_obstacks is in finish_decl. */
4237 push_obstacks_nochange ();
4239 decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
4240 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
4241 decl_attributes (decl, TREE_VALUE (TREE_VALUE (parm)),
4242 TREE_PURPOSE (TREE_VALUE (parm)));
4244 #if 0
4245 if (DECL_NAME (decl))
4247 tree olddecl;
4248 olddecl = lookup_name (DECL_NAME (decl));
4249 if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
4250 pedwarn_with_decl (decl, "ANSI C forbids parameter `%s' shadowing typedef");
4252 #endif
4254 decl = pushdecl (decl);
4256 immediate_size_expand = old_immediate_size_expand;
4258 current_binding_level->parm_order
4259 = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
4261 /* Add this decl to the current binding level. */
4262 finish_decl (decl, NULL_TREE, NULL_TREE);
4265 /* Clear the given order of parms in `parm_order'.
4266 Used at start of parm list,
4267 and also at semicolon terminating forward decls. */
4269 void
4270 clear_parm_order ()
4272 current_binding_level->parm_order = NULL_TREE;
4275 /* Make TYPE a complete type based on INITIAL_VALUE.
4276 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
4277 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
4280 complete_array_type (type, initial_value, do_default)
4281 tree type;
4282 tree initial_value;
4283 int do_default;
4285 register tree maxindex = NULL_TREE;
4286 int value = 0;
4288 if (initial_value)
4290 /* Note MAXINDEX is really the maximum index,
4291 one less than the size. */
4292 if (TREE_CODE (initial_value) == STRING_CST)
4294 int eltsize
4295 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
4296 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
4297 / eltsize) - 1, 0);
4299 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
4301 tree elts = CONSTRUCTOR_ELTS (initial_value);
4302 maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
4303 for (; elts; elts = TREE_CHAIN (elts))
4305 if (TREE_PURPOSE (elts))
4306 maxindex = TREE_PURPOSE (elts);
4307 else
4308 maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
4310 maxindex = copy_node (maxindex);
4312 else
4314 /* Make an error message unless that happened already. */
4315 if (initial_value != error_mark_node)
4316 value = 1;
4318 /* Prevent further error messages. */
4319 maxindex = build_int_2 (0, 0);
4323 if (!maxindex)
4325 if (do_default)
4326 maxindex = build_int_2 (0, 0);
4327 value = 2;
4330 if (maxindex)
4332 TYPE_DOMAIN (type) = build_index_type (maxindex);
4333 if (!TREE_TYPE (maxindex))
4334 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
4337 /* Lay out the type now that we can get the real answer. */
4339 layout_type (type);
4341 return value;
4344 /* Given declspecs and a declarator,
4345 determine the name and type of the object declared
4346 and construct a ..._DECL node for it.
4347 (In one case we can return a ..._TYPE node instead.
4348 For invalid input we sometimes return 0.)
4350 DECLSPECS is a chain of tree_list nodes whose value fields
4351 are the storage classes and type specifiers.
4353 DECL_CONTEXT says which syntactic context this declaration is in:
4354 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
4355 FUNCDEF for a function definition. Like NORMAL but a few different
4356 error messages in each case. Return value may be zero meaning
4357 this definition is too screwy to try to parse.
4358 PARM for a parameter declaration (either within a function prototype
4359 or before a function body). Make a PARM_DECL, or return void_type_node.
4360 TYPENAME if for a typename (in a cast or sizeof).
4361 Don't make a DECL node; just return the ..._TYPE node.
4362 FIELD for a struct or union field; make a FIELD_DECL.
4363 BITFIELD for a field with specified width.
4364 INITIALIZED is 1 if the decl has an initializer.
4366 In the TYPENAME case, DECLARATOR is really an absolute declarator.
4367 It may also be so in the PARM case, for a prototype where the
4368 argument type is specified but not the name.
4370 This function is where the complicated C meanings of `static'
4371 and `extern' are interpreted. */
4373 static tree
4374 grokdeclarator (declarator, declspecs, decl_context, initialized)
4375 tree declspecs;
4376 tree declarator;
4377 enum decl_context decl_context;
4378 int initialized;
4380 int specbits = 0;
4381 tree spec;
4382 tree type = NULL_TREE;
4383 int longlong = 0;
4384 int constp;
4385 int restrictp;
4386 int volatilep;
4387 int type_quals = TYPE_UNQUALIFIED;
4388 int inlinep;
4389 int explicit_int = 0;
4390 int explicit_char = 0;
4391 int defaulted_int = 0;
4392 tree typedef_decl = 0;
4393 const char *name;
4394 tree typedef_type = 0;
4395 int funcdef_flag = 0;
4396 enum tree_code innermost_code = ERROR_MARK;
4397 int bitfield = 0;
4398 int size_varies = 0;
4399 tree decl_machine_attr = NULL_TREE;
4401 if (decl_context == BITFIELD)
4402 bitfield = 1, decl_context = FIELD;
4404 if (decl_context == FUNCDEF)
4405 funcdef_flag = 1, decl_context = NORMAL;
4407 push_obstacks_nochange ();
4409 if (flag_traditional && allocation_temporary_p ())
4410 end_temporary_allocation ();
4412 /* Look inside a declarator for the name being declared
4413 and get it as a string, for an error message. */
4415 register tree decl = declarator;
4416 name = 0;
4418 while (decl)
4419 switch (TREE_CODE (decl))
4421 case ARRAY_REF:
4422 case INDIRECT_REF:
4423 case CALL_EXPR:
4424 innermost_code = TREE_CODE (decl);
4425 decl = TREE_OPERAND (decl, 0);
4426 break;
4428 case IDENTIFIER_NODE:
4429 name = IDENTIFIER_POINTER (decl);
4430 decl = 0;
4431 break;
4433 default:
4434 abort ();
4436 if (name == 0)
4437 name = "type name";
4440 /* A function definition's declarator must have the form of
4441 a function declarator. */
4443 if (funcdef_flag && innermost_code != CALL_EXPR)
4444 return 0;
4446 /* Anything declared one level down from the top level
4447 must be one of the parameters of a function
4448 (because the body is at least two levels down). */
4450 /* If this looks like a function definition, make it one,
4451 even if it occurs where parms are expected.
4452 Then store_parm_decls will reject it and not use it as a parm. */
4453 if (decl_context == NORMAL && !funcdef_flag
4454 && current_binding_level->parm_flag)
4455 decl_context = PARM;
4457 /* Look through the decl specs and record which ones appear.
4458 Some typespecs are defined as built-in typenames.
4459 Others, the ones that are modifiers of other types,
4460 are represented by bits in SPECBITS: set the bits for
4461 the modifiers that appear. Storage class keywords are also in SPECBITS.
4463 If there is a typedef name or a type, store the type in TYPE.
4464 This includes builtin typedefs such as `int'.
4466 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
4467 and did not come from a user typedef.
4469 Set LONGLONG if `long' is mentioned twice. */
4471 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
4473 register int i;
4474 register tree id = TREE_VALUE (spec);
4476 if (id == ridpointers[(int) RID_INT])
4477 explicit_int = 1;
4478 if (id == ridpointers[(int) RID_CHAR])
4479 explicit_char = 1;
4481 if (TREE_CODE (id) == IDENTIFIER_NODE)
4482 for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
4484 if (ridpointers[i] == id)
4486 if (i == (int) RID_LONG && specbits & (1<<i))
4488 if (longlong)
4489 error ("`long long long' is too long for GCC");
4490 else
4492 if (pedantic && ! in_system_header && warn_long_long)
4493 pedwarn ("ANSI C does not support `long long'");
4494 longlong = 1;
4497 else if (specbits & (1 << i))
4498 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
4499 specbits |= 1 << i;
4500 goto found;
4503 if (type)
4504 error ("two or more data types in declaration of `%s'", name);
4505 /* Actual typedefs come to us as TYPE_DECL nodes. */
4506 else if (TREE_CODE (id) == TYPE_DECL)
4508 type = TREE_TYPE (id);
4509 decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
4510 typedef_decl = id;
4512 /* Built-in types come as identifiers. */
4513 else if (TREE_CODE (id) == IDENTIFIER_NODE)
4515 register tree t = lookup_name (id);
4516 if (TREE_TYPE (t) == error_mark_node)
4518 else if (!t || TREE_CODE (t) != TYPE_DECL)
4519 error ("`%s' fails to be a typedef or built in type",
4520 IDENTIFIER_POINTER (id));
4521 else
4523 type = TREE_TYPE (t);
4524 typedef_decl = t;
4527 else if (TREE_CODE (id) != ERROR_MARK)
4528 type = id;
4530 found: {}
4533 typedef_type = type;
4534 if (type)
4535 size_varies = C_TYPE_VARIABLE_SIZE (type);
4537 /* No type at all: default to `int', and set DEFAULTED_INT
4538 because it was not a user-defined typedef. */
4540 if (type == 0)
4542 if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4543 | (1 << (int) RID_SIGNED)
4544 | (1 << (int) RID_UNSIGNED))))
4545 /* Don't warn about typedef foo = bar. */
4546 && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
4547 && ! (in_system_header && ! allocation_temporary_p ()))
4549 /* Issue a warning if this is an ISO C 9x program or if -Wreturn-type
4550 and this is a function, or if -Wimplicit; prefer the former
4551 warning since it is more explicit. */
4552 if ((warn_implicit_int || warn_return_type) && funcdef_flag)
4553 warn_about_return_type = 1;
4554 else if (warn_implicit_int || flag_isoc9x)
4555 warning ("type defaults to `int' in declaration of `%s'", name);
4558 defaulted_int = 1;
4559 type = integer_type_node;
4562 /* Now process the modifiers that were specified
4563 and check for invalid combinations. */
4565 /* Long double is a special combination. */
4567 if ((specbits & 1 << (int) RID_LONG) && ! longlong
4568 && TYPE_MAIN_VARIANT (type) == double_type_node)
4570 specbits &= ~ (1 << (int) RID_LONG);
4571 type = long_double_type_node;
4574 /* Check all other uses of type modifiers. */
4576 if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4577 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
4579 int ok = 0;
4581 if ((specbits & 1 << (int) RID_LONG)
4582 && (specbits & 1 << (int) RID_SHORT))
4583 error ("both long and short specified for `%s'", name);
4584 else if (((specbits & 1 << (int) RID_LONG)
4585 || (specbits & 1 << (int) RID_SHORT))
4586 && explicit_char)
4587 error ("long or short specified with char for `%s'", name);
4588 else if (((specbits & 1 << (int) RID_LONG)
4589 || (specbits & 1 << (int) RID_SHORT))
4590 && TREE_CODE (type) == REAL_TYPE)
4592 static int already = 0;
4594 error ("long or short specified with floating type for `%s'", name);
4595 if (! already && ! pedantic)
4597 error ("the only valid combination is `long double'");
4598 already = 1;
4601 else if ((specbits & 1 << (int) RID_SIGNED)
4602 && (specbits & 1 << (int) RID_UNSIGNED))
4603 error ("both signed and unsigned specified for `%s'", name);
4604 else if (TREE_CODE (type) != INTEGER_TYPE)
4605 error ("long, short, signed or unsigned invalid for `%s'", name);
4606 else
4608 ok = 1;
4609 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
4611 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
4612 name);
4613 if (flag_pedantic_errors)
4614 ok = 0;
4618 /* Discard the type modifiers if they are invalid. */
4619 if (! ok)
4621 specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4622 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
4623 longlong = 0;
4627 if ((specbits & (1 << (int) RID_COMPLEX))
4628 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
4630 error ("complex invalid for `%s'", name);
4631 specbits &= ~ (1 << (int) RID_COMPLEX);
4634 /* Decide whether an integer type is signed or not.
4635 Optionally treat bitfields as signed by default. */
4636 if (specbits & 1 << (int) RID_UNSIGNED
4637 /* Traditionally, all bitfields are unsigned. */
4638 || (bitfield && flag_traditional
4639 && (! explicit_flag_signed_bitfields || !flag_signed_bitfields))
4640 || (bitfield && ! flag_signed_bitfields
4641 && (explicit_int || defaulted_int || explicit_char
4642 /* A typedef for plain `int' without `signed'
4643 can be controlled just like plain `int'. */
4644 || ! (typedef_decl != 0
4645 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4646 && TREE_CODE (type) != ENUMERAL_TYPE
4647 && !(specbits & 1 << (int) RID_SIGNED)))
4649 if (longlong)
4650 type = long_long_unsigned_type_node;
4651 else if (specbits & 1 << (int) RID_LONG)
4652 type = long_unsigned_type_node;
4653 else if (specbits & 1 << (int) RID_SHORT)
4654 type = short_unsigned_type_node;
4655 else if (type == char_type_node)
4656 type = unsigned_char_type_node;
4657 else if (typedef_decl)
4658 type = unsigned_type (type);
4659 else
4660 type = unsigned_type_node;
4662 else if ((specbits & 1 << (int) RID_SIGNED)
4663 && type == char_type_node)
4664 type = signed_char_type_node;
4665 else if (longlong)
4666 type = long_long_integer_type_node;
4667 else if (specbits & 1 << (int) RID_LONG)
4668 type = long_integer_type_node;
4669 else if (specbits & 1 << (int) RID_SHORT)
4670 type = short_integer_type_node;
4672 if (specbits & 1 << (int) RID_COMPLEX)
4674 /* If we just have "complex", it is equivalent to
4675 "complex double", but if any modifiers at all are specified it is
4676 the complex form of TYPE. E.g, "complex short" is
4677 "complex short int". */
4679 if (defaulted_int && ! longlong
4680 && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4681 | (1 << (int) RID_SIGNED)
4682 | (1 << (int) RID_UNSIGNED))))
4683 type = complex_double_type_node;
4684 else if (type == integer_type_node)
4685 type = complex_integer_type_node;
4686 else if (type == float_type_node)
4687 type = complex_float_type_node;
4688 else if (type == double_type_node)
4689 type = complex_double_type_node;
4690 else if (type == long_double_type_node)
4691 type = complex_long_double_type_node;
4692 else
4693 type = build_complex_type (type);
4696 /* Figure out the type qualifiers for the declaration. There are
4697 two ways a declaration can become qualified. One is something
4698 like `const int i' where the `const' is explicit. Another is
4699 something like `typedef const int CI; CI i' where the type of the
4700 declaration contains the `const'. */
4701 constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
4702 restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
4703 volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
4704 inlinep = !! (specbits & (1 << (int) RID_INLINE));
4705 if (constp > 1)
4706 pedwarn ("duplicate `const'");
4707 if (restrictp > 1)
4708 pedwarn ("duplicate `restrict'");
4709 if (volatilep > 1)
4710 pedwarn ("duplicate `volatile'");
4711 if (! flag_gen_aux_info && (TYPE_QUALS (type)))
4712 type = TYPE_MAIN_VARIANT (type);
4713 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4714 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4715 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4717 /* Warn if two storage classes are given. Default to `auto'. */
4720 int nclasses = 0;
4722 if (specbits & 1 << (int) RID_AUTO) nclasses++;
4723 if (specbits & 1 << (int) RID_STATIC) nclasses++;
4724 if (specbits & 1 << (int) RID_EXTERN) nclasses++;
4725 if (specbits & 1 << (int) RID_REGISTER) nclasses++;
4726 if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
4727 if (specbits & 1 << (int) RID_ITERATOR) nclasses++;
4729 /* Warn about storage classes that are invalid for certain
4730 kinds of declarations (parameters, typenames, etc.). */
4732 if (nclasses > 1)
4733 error ("multiple storage classes in declaration of `%s'", name);
4734 else if (funcdef_flag
4735 && (specbits
4736 & ((1 << (int) RID_REGISTER)
4737 | (1 << (int) RID_AUTO)
4738 | (1 << (int) RID_TYPEDEF))))
4740 if (specbits & 1 << (int) RID_AUTO
4741 && (pedantic || current_binding_level == global_binding_level))
4742 pedwarn ("function definition declared `auto'");
4743 if (specbits & 1 << (int) RID_REGISTER)
4744 error ("function definition declared `register'");
4745 if (specbits & 1 << (int) RID_TYPEDEF)
4746 error ("function definition declared `typedef'");
4747 specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4748 | (1 << (int) RID_AUTO));
4750 else if (decl_context != NORMAL && nclasses > 0)
4752 if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
4754 else
4756 error ((decl_context == FIELD
4757 ? "storage class specified for structure field `%s'"
4758 : (decl_context == PARM
4759 ? "storage class specified for parameter `%s'"
4760 : "storage class specified for typename")),
4761 name);
4762 specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4763 | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
4764 | (1 << (int) RID_EXTERN));
4767 else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
4769 /* `extern' with initialization is invalid if not at top level. */
4770 if (current_binding_level == global_binding_level)
4771 warning ("`%s' initialized and declared `extern'", name);
4772 else
4773 error ("`%s' has both `extern' and initializer", name);
4775 else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
4776 && current_binding_level != global_binding_level)
4777 error ("nested function `%s' declared `extern'", name);
4778 else if (current_binding_level == global_binding_level
4779 && specbits & (1 << (int) RID_AUTO))
4780 error ("top-level declaration of `%s' specifies `auto'", name);
4781 else if ((specbits & 1 << (int) RID_ITERATOR)
4782 && TREE_CODE (declarator) != IDENTIFIER_NODE)
4784 error ("iterator `%s' has derived type", name);
4785 type = error_mark_node;
4787 else if ((specbits & 1 << (int) RID_ITERATOR)
4788 && TREE_CODE (type) != INTEGER_TYPE)
4790 error ("iterator `%s' has noninteger type", name);
4791 type = error_mark_node;
4795 /* Now figure out the structure of the declarator proper.
4796 Descend through it, creating more complex types, until we reach
4797 the declared identifier (or NULL_TREE, in an absolute declarator). */
4799 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
4801 if (type == error_mark_node)
4803 declarator = TREE_OPERAND (declarator, 0);
4804 continue;
4807 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
4808 an INDIRECT_REF (for *...),
4809 a CALL_EXPR (for ...(...)),
4810 an identifier (for the name being declared)
4811 or a null pointer (for the place in an absolute declarator
4812 where the name was omitted).
4813 For the last two cases, we have just exited the loop.
4815 At this point, TYPE is the type of elements of an array,
4816 or for a function to return, or for a pointer to point to.
4817 After this sequence of ifs, TYPE is the type of the
4818 array or function or pointer, and DECLARATOR has had its
4819 outermost layer removed. */
4821 if (TREE_CODE (declarator) == ARRAY_REF)
4823 register tree itype = NULL_TREE;
4824 register tree size = TREE_OPERAND (declarator, 1);
4825 /* An uninitialized decl with `extern' is a reference. */
4826 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
4827 /* The index is a signed object `sizetype' bits wide. */
4828 tree index_type = signed_type (sizetype);
4830 declarator = TREE_OPERAND (declarator, 0);
4832 /* Check for some types that there cannot be arrays of. */
4834 if (TYPE_MAIN_VARIANT (type) == void_type_node)
4836 error ("declaration of `%s' as array of voids", name);
4837 type = error_mark_node;
4840 if (TREE_CODE (type) == FUNCTION_TYPE)
4842 error ("declaration of `%s' as array of functions", name);
4843 type = error_mark_node;
4846 if (size == error_mark_node)
4847 type = error_mark_node;
4849 if (type == error_mark_node)
4850 continue;
4852 /* If this is a block level extern, it must live past the end
4853 of the function so that we can check it against other extern
4854 declarations (IDENTIFIER_LIMBO_VALUE). */
4855 if (extern_ref && allocation_temporary_p ())
4856 end_temporary_allocation ();
4858 /* If size was specified, set ITYPE to a range-type for that size.
4859 Otherwise, ITYPE remains null. finish_decl may figure it out
4860 from an initial value. */
4862 if (size)
4864 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4865 STRIP_TYPE_NOPS (size);
4867 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
4868 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
4870 error ("size of array `%s' has non-integer type", name);
4871 size = integer_one_node;
4874 if (pedantic && integer_zerop (size))
4875 pedwarn ("ANSI C forbids zero-size array `%s'", name);
4877 if (TREE_CODE (size) == INTEGER_CST)
4879 constant_expression_warning (size);
4880 if (tree_int_cst_sgn (size) < 0)
4882 error ("size of array `%s' is negative", name);
4883 size = integer_one_node;
4886 else
4888 /* Make sure the array size remains visibly nonconstant
4889 even if it is (eg) a const variable with known value. */
4890 size_varies = 1;
4892 if (pedantic)
4894 if (TREE_CONSTANT (size))
4895 pedwarn ("ANSI C forbids array `%s' whose size can't be evaluated", name);
4896 else
4897 pedwarn ("ANSI C forbids variable-size array `%s'", name);
4901 /* Convert size to index_type, so that if it is a variable
4902 the computations will be done in the proper mode. */
4903 itype = fold (build (MINUS_EXPR, index_type,
4904 convert (index_type, size),
4905 convert (index_type, size_one_node)));
4907 /* If that overflowed, the array is too big.
4908 ??? While a size of INT_MAX+1 technically shouldn't cause
4909 an overflow (because we subtract 1), the overflow is recorded
4910 during the conversion to index_type, before the subtraction.
4911 Handling this case seems like an unnecessary complication. */
4912 if (TREE_OVERFLOW (itype))
4914 error ("size of array `%s' is too large", name);
4915 type = error_mark_node;
4916 continue;
4919 if (size_varies)
4920 itype = variable_size (itype);
4921 itype = build_index_type (itype);
4924 #if 0 /* This had bad results for pointers to arrays, as in
4925 union incomplete (*foo)[4]; */
4926 /* Complain about arrays of incomplete types, except in typedefs. */
4928 if (TYPE_SIZE (type) == 0
4929 /* Avoid multiple warnings for nested array types. */
4930 && TREE_CODE (type) != ARRAY_TYPE
4931 && !(specbits & (1 << (int) RID_TYPEDEF))
4932 && !C_TYPE_BEING_DEFINED (type))
4933 warning ("array type has incomplete element type");
4934 #endif
4936 #if 0 /* We shouldn't have a function type here at all!
4937 Functions aren't allowed as array elements. */
4938 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4939 && (constp || volatilep))
4940 pedwarn ("ANSI C forbids const or volatile function types");
4941 #endif
4943 /* Build the array type itself, then merge any constancy or
4944 volatility into the target type. We must do it in this order
4945 to ensure that the TYPE_MAIN_VARIANT field of the array type
4946 is set correctly. */
4948 type = build_array_type (type, itype);
4949 if (type_quals)
4950 type = c_build_qualified_type (type, type_quals);
4952 #if 0 /* don't clear these; leave them set so that the array type
4953 or the variable is itself const or volatile. */
4954 type_quals = TYPE_UNQUALIFIED;
4955 #endif
4957 if (size_varies)
4958 C_TYPE_VARIABLE_SIZE (type) = 1;
4960 else if (TREE_CODE (declarator) == CALL_EXPR)
4962 int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
4963 || current_binding_level == global_binding_level);
4964 tree arg_types;
4966 /* Declaring a function type.
4967 Make sure we have a valid type for the function to return. */
4968 if (type == error_mark_node)
4969 continue;
4971 size_varies = 0;
4973 /* Warn about some types functions can't return. */
4975 if (TREE_CODE (type) == FUNCTION_TYPE)
4977 error ("`%s' declared as function returning a function", name);
4978 type = integer_type_node;
4980 if (TREE_CODE (type) == ARRAY_TYPE)
4982 error ("`%s' declared as function returning an array", name);
4983 type = integer_type_node;
4986 #ifndef TRADITIONAL_RETURN_FLOAT
4987 /* Traditionally, declaring return type float means double. */
4989 if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node)
4990 type = double_type_node;
4991 #endif /* TRADITIONAL_RETURN_FLOAT */
4993 /* If this is a block level extern, it must live past the end
4994 of the function so that we can check it against other extern
4995 declarations (IDENTIFIER_LIMBO_VALUE). */
4996 if (extern_ref && allocation_temporary_p ())
4997 end_temporary_allocation ();
4999 /* Construct the function type and go to the next
5000 inner layer of declarator. */
5002 arg_types = grokparms (TREE_OPERAND (declarator, 1),
5003 funcdef_flag
5004 /* Say it's a definition
5005 only for the CALL_EXPR
5006 closest to the identifier. */
5007 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
5008 #if 0 /* This seems to be false. We turn off temporary allocation
5009 above in this function if -traditional.
5010 And this code caused inconsistent results with prototypes:
5011 callers would ignore them, and pass arguments wrong. */
5013 /* Omit the arg types if -traditional, since the arg types
5014 and the list links might not be permanent. */
5015 type = build_function_type (type,
5016 flag_traditional
5017 ? NULL_TREE : arg_types);
5018 #endif
5019 /* Type qualifiers before the return type of the function
5020 qualify the return type, not the function type. */
5021 if (type_quals)
5022 type = c_build_qualified_type (type, type_quals);
5023 type_quals = TYPE_UNQUALIFIED;
5025 type = build_function_type (type, arg_types);
5026 declarator = TREE_OPERAND (declarator, 0);
5028 /* Set the TYPE_CONTEXTs for each tagged type which is local to
5029 the formal parameter list of this FUNCTION_TYPE to point to
5030 the FUNCTION_TYPE node itself. */
5033 register tree link;
5035 for (link = last_function_parm_tags;
5036 link;
5037 link = TREE_CHAIN (link))
5038 TYPE_CONTEXT (TREE_VALUE (link)) = type;
5041 else if (TREE_CODE (declarator) == INDIRECT_REF)
5043 /* Merge any constancy or volatility into the target type
5044 for the pointer. */
5046 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5047 && type_quals)
5048 pedwarn ("ANSI C forbids qualified function types");
5049 if (type_quals)
5050 type = c_build_qualified_type (type, type_quals);
5051 type_quals = TYPE_UNQUALIFIED;
5052 size_varies = 0;
5054 type = build_pointer_type (type);
5056 /* Process a list of type modifier keywords
5057 (such as const or volatile) that were given inside the `*'. */
5059 if (TREE_TYPE (declarator))
5061 register tree typemodlist;
5062 int erred = 0;
5064 constp = 0;
5065 volatilep = 0;
5066 restrictp = 0;
5067 for (typemodlist = TREE_TYPE (declarator); typemodlist;
5068 typemodlist = TREE_CHAIN (typemodlist))
5070 tree qualifier = TREE_VALUE (typemodlist);
5072 if (qualifier == ridpointers[(int) RID_CONST])
5073 constp++;
5074 else if (qualifier == ridpointers[(int) RID_VOLATILE])
5075 volatilep++;
5076 else if (qualifier == ridpointers[(int) RID_RESTRICT])
5077 restrictp++;
5078 else if (!erred)
5080 erred = 1;
5081 error ("invalid type modifier within pointer declarator");
5084 if (constp > 1)
5085 pedwarn ("duplicate `const'");
5086 if (volatilep > 1)
5087 pedwarn ("duplicate `volatile'");
5088 if (restrictp > 1)
5089 pedwarn ("duplicate `restrict'");
5091 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
5092 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
5093 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
5096 declarator = TREE_OPERAND (declarator, 0);
5098 else
5099 abort ();
5103 /* Now TYPE has the actual type. */
5105 /* Did array size calculations overflow? */
5107 if (TREE_CODE (type) == ARRAY_TYPE
5108 && TYPE_SIZE (type)
5109 && TREE_OVERFLOW (TYPE_SIZE (type)))
5110 error ("size of array `%s' is too large", name);
5112 /* If this is declaring a typedef name, return a TYPE_DECL. */
5114 if (specbits & (1 << (int) RID_TYPEDEF))
5116 tree decl;
5117 /* Note that the grammar rejects storage classes
5118 in typenames, fields or parameters */
5119 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5120 && type_quals)
5121 pedwarn ("ANSI C forbids qualified function types");
5122 if (type_quals)
5123 type = c_build_qualified_type (type, type_quals);
5124 decl = build_decl (TYPE_DECL, declarator, type);
5125 if ((specbits & (1 << (int) RID_SIGNED))
5126 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
5127 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
5128 pop_obstacks ();
5129 return decl;
5132 /* Detect the case of an array type of unspecified size
5133 which came, as such, direct from a typedef name.
5134 We must copy the type, so that each identifier gets
5135 a distinct type, so that each identifier's size can be
5136 controlled separately by its own initializer. */
5138 if (type != 0 && typedef_type != 0
5139 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)
5140 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0)
5142 type = build_array_type (TREE_TYPE (type), 0);
5143 if (size_varies)
5144 C_TYPE_VARIABLE_SIZE (type) = 1;
5147 /* If this is a type name (such as, in a cast or sizeof),
5148 compute the type and return it now. */
5150 if (decl_context == TYPENAME)
5152 /* Note that the grammar rejects storage classes
5153 in typenames, fields or parameters */
5154 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5155 && type_quals)
5156 pedwarn ("ANSI C forbids const or volatile function types");
5157 if (type_quals)
5158 type = c_build_qualified_type (type, type_quals);
5159 pop_obstacks ();
5160 return type;
5163 /* Aside from typedefs and type names (handle above),
5164 `void' at top level (not within pointer)
5165 is allowed only in public variables.
5166 We don't complain about parms either, but that is because
5167 a better error message can be made later. */
5169 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM
5170 && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
5171 && ((specbits & (1 << (int) RID_EXTERN))
5172 || (current_binding_level == global_binding_level
5173 && !(specbits
5174 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
5176 error ("variable or field `%s' declared void", name);
5177 type = integer_type_node;
5180 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
5181 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
5184 register tree decl;
5186 if (decl_context == PARM)
5188 tree type_as_written = type;
5189 tree main_type;
5191 /* A parameter declared as an array of T is really a pointer to T.
5192 One declared as a function is really a pointer to a function. */
5194 if (TREE_CODE (type) == ARRAY_TYPE)
5196 /* Transfer const-ness of array into that of type pointed to. */
5197 type = TREE_TYPE (type);
5198 if (type_quals)
5199 type = c_build_qualified_type (type, type_quals);
5200 type = build_pointer_type (type);
5201 type_quals = TYPE_UNQUALIFIED;
5202 size_varies = 0;
5204 else if (TREE_CODE (type) == FUNCTION_TYPE)
5206 if (pedantic && type_quals)
5207 pedwarn ("ANSI C forbids qualified function types");
5208 if (type_quals)
5209 type = c_build_qualified_type (type, type_quals);
5210 type = build_pointer_type (type);
5211 type_quals = TYPE_UNQUALIFIED;
5214 decl = build_decl (PARM_DECL, declarator, type);
5215 if (size_varies)
5216 C_DECL_VARIABLE_SIZE (decl) = 1;
5218 /* Compute the type actually passed in the parmlist,
5219 for the case where there is no prototype.
5220 (For example, shorts and chars are passed as ints.)
5221 When there is a prototype, this is overridden later. */
5223 DECL_ARG_TYPE (decl) = type;
5224 main_type = (type == error_mark_node
5225 ? error_mark_node
5226 : TYPE_MAIN_VARIANT (type));
5227 if (main_type == float_type_node)
5228 DECL_ARG_TYPE (decl) = double_type_node;
5229 /* Don't use TYPE_PRECISION to decide whether to promote,
5230 because we should convert short if it's the same size as int,
5231 but we should not convert long if it's the same size as int. */
5232 else if (TREE_CODE (main_type) != ERROR_MARK
5233 && C_PROMOTING_INTEGER_TYPE_P (main_type))
5235 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
5236 && TREE_UNSIGNED (type))
5237 DECL_ARG_TYPE (decl) = unsigned_type_node;
5238 else
5239 DECL_ARG_TYPE (decl) = integer_type_node;
5242 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
5244 else if (decl_context == FIELD)
5246 /* Structure field. It may not be a function. */
5248 if (TREE_CODE (type) == FUNCTION_TYPE)
5250 error ("field `%s' declared as a function", name);
5251 type = build_pointer_type (type);
5253 else if (TREE_CODE (type) != ERROR_MARK && TYPE_SIZE (type) == 0)
5255 error ("field `%s' has incomplete type", name);
5256 type = error_mark_node;
5258 /* Move type qualifiers down to element of an array. */
5259 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
5261 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
5262 type_quals),
5263 TYPE_DOMAIN (type));
5264 #if 0 /* Leave the field const or volatile as well. */
5265 type_quals = TYPE_UNQUALIFIED;
5266 #endif
5268 decl = build_decl (FIELD_DECL, declarator, type);
5269 if (size_varies)
5270 C_DECL_VARIABLE_SIZE (decl) = 1;
5272 else if (TREE_CODE (type) == FUNCTION_TYPE)
5274 /* Every function declaration is "external"
5275 except for those which are inside a function body
5276 in which `auto' is used.
5277 That is a case not specified by ANSI C,
5278 and we use it for forward declarations for nested functions. */
5279 int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
5280 || current_binding_level == global_binding_level);
5282 if (specbits & (1 << (int) RID_AUTO)
5283 && (pedantic || current_binding_level == global_binding_level))
5284 pedwarn ("invalid storage class for function `%s'", name);
5285 if (specbits & (1 << (int) RID_REGISTER))
5286 error ("invalid storage class for function `%s'", name);
5287 /* Function declaration not at top level.
5288 Storage classes other than `extern' are not allowed
5289 and `extern' makes no difference. */
5290 if (current_binding_level != global_binding_level
5291 && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
5292 && pedantic)
5293 pedwarn ("invalid storage class for function `%s'", name);
5295 /* If this is a block level extern, it must live past the end
5296 of the function so that we can check it against other
5297 extern declarations (IDENTIFIER_LIMBO_VALUE). */
5298 if (extern_ref && allocation_temporary_p ())
5299 end_temporary_allocation ();
5301 decl = build_decl (FUNCTION_DECL, declarator, type);
5302 decl = build_decl_attribute_variant (decl, decl_machine_attr);
5304 if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
5305 pedwarn ("ANSI C forbids qualified function types");
5307 if (pedantic
5308 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl))) == void_type_node
5309 && TYPE_QUALS (TREE_TYPE (TREE_TYPE (decl)))
5310 && ! DECL_IN_SYSTEM_HEADER (decl))
5311 pedwarn ("ANSI C forbids qualified void function return type");
5313 /* GNU C interprets a `volatile void' return type to indicate
5314 that the function does not return. */
5315 if ((type_quals & TYPE_QUAL_VOLATILE)
5316 && TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
5317 warning ("`noreturn' function returns non-void value");
5319 if (extern_ref)
5320 DECL_EXTERNAL (decl) = 1;
5321 /* Record absence of global scope for `static' or `auto'. */
5322 TREE_PUBLIC (decl)
5323 = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
5325 /* Record presence of `inline', if it is reasonable. */
5326 if (inlinep)
5328 if (! strcmp (IDENTIFIER_POINTER (declarator), "main"))
5329 warning ("cannot inline function `main'");
5330 else
5331 /* Assume that otherwise the function can be inlined. */
5332 DECL_INLINE (decl) = 1;
5334 if (specbits & (1 << (int) RID_EXTERN))
5335 current_extern_inline = 1;
5338 else
5340 /* It's a variable. */
5341 /* An uninitialized decl with `extern' is a reference. */
5342 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
5344 /* Move type qualifiers down to element of an array. */
5345 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
5347 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
5348 type_quals),
5349 TYPE_DOMAIN (type));
5350 #if 0 /* Leave the variable const or volatile as well. */
5351 type_quals = TYPE_UNQUALIFIED;
5352 #endif
5355 /* If this is a block level extern, it must live past the end
5356 of the function so that we can check it against other
5357 extern declarations (IDENTIFIER_LIMBO_VALUE). */
5358 if (extern_ref && allocation_temporary_p ())
5359 end_temporary_allocation ();
5361 decl = build_decl (VAR_DECL, declarator, type);
5362 if (size_varies)
5363 C_DECL_VARIABLE_SIZE (decl) = 1;
5365 if (inlinep)
5366 pedwarn_with_decl (decl, "variable `%s' declared `inline'");
5368 DECL_EXTERNAL (decl) = extern_ref;
5369 /* At top level, the presence of a `static' or `register' storage
5370 class specifier, or the absence of all storage class specifiers
5371 makes this declaration a definition (perhaps tentative). Also,
5372 the absence of both `static' and `register' makes it public. */
5373 if (current_binding_level == global_binding_level)
5375 TREE_PUBLIC (decl)
5376 = !(specbits
5377 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)));
5378 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
5380 /* Not at top level, only `static' makes a static definition. */
5381 else
5383 TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
5384 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
5387 if (specbits & 1 << (int) RID_ITERATOR)
5388 ITERATOR_P (decl) = 1;
5391 /* Record `register' declaration for warnings on &
5392 and in case doing stupid register allocation. */
5394 if (specbits & (1 << (int) RID_REGISTER))
5395 DECL_REGISTER (decl) = 1;
5397 /* Record constancy and volatility. */
5398 c_apply_type_quals_to_decl (type_quals, decl);
5400 /* If a type has volatile components, it should be stored in memory.
5401 Otherwise, the fact that those components are volatile
5402 will be ignored, and would even crash the compiler. */
5403 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
5404 mark_addressable (decl);
5406 pop_obstacks ();
5408 return decl;
5412 /* Decode the parameter-list info for a function type or function definition.
5413 The argument is the value returned by `get_parm_info' (or made in parse.y
5414 if there is an identifier list instead of a parameter decl list).
5415 These two functions are separate because when a function returns
5416 or receives functions then each is called multiple times but the order
5417 of calls is different. The last call to `grokparms' is always the one
5418 that contains the formal parameter names of a function definition.
5420 Store in `last_function_parms' a chain of the decls of parms.
5421 Also store in `last_function_parm_tags' a chain of the struct, union,
5422 and enum tags declared among the parms.
5424 Return a list of arg types to use in the FUNCTION_TYPE for this function.
5426 FUNCDEF_FLAG is nonzero for a function definition, 0 for
5427 a mere declaration. A nonempty identifier-list gets an error message
5428 when FUNCDEF_FLAG is zero. */
5430 static tree
5431 grokparms (parms_info, funcdef_flag)
5432 tree parms_info;
5433 int funcdef_flag;
5435 tree first_parm = TREE_CHAIN (parms_info);
5437 last_function_parms = TREE_PURPOSE (parms_info);
5438 last_function_parm_tags = TREE_VALUE (parms_info);
5440 if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
5441 && !in_system_header)
5442 warning ("function declaration isn't a prototype");
5444 if (first_parm != 0
5445 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
5447 if (! funcdef_flag)
5448 pedwarn ("parameter names (without types) in function declaration");
5450 last_function_parms = first_parm;
5451 return 0;
5453 else
5455 tree parm;
5456 tree typelt;
5457 /* We no longer test FUNCDEF_FLAG.
5458 If the arg types are incomplete in a declaration,
5459 they must include undefined tags.
5460 These tags can never be defined in the scope of the declaration,
5461 so the types can never be completed,
5462 and no call can be compiled successfully. */
5463 #if 0
5464 /* In a fcn definition, arg types must be complete. */
5465 if (funcdef_flag)
5466 #endif
5467 for (parm = last_function_parms, typelt = first_parm;
5468 parm;
5469 parm = TREE_CHAIN (parm))
5470 /* Skip over any enumeration constants declared here. */
5471 if (TREE_CODE (parm) == PARM_DECL)
5473 /* Barf if the parameter itself has an incomplete type. */
5474 tree type = TREE_VALUE (typelt);
5475 if (TYPE_SIZE (type) == 0)
5477 if (funcdef_flag && DECL_NAME (parm) != 0)
5478 error ("parameter `%s' has incomplete type",
5479 IDENTIFIER_POINTER (DECL_NAME (parm)));
5480 else
5481 warning ("parameter has incomplete type");
5482 if (funcdef_flag)
5484 TREE_VALUE (typelt) = error_mark_node;
5485 TREE_TYPE (parm) = error_mark_node;
5488 #if 0 /* This has been replaced by parm_tags_warning
5489 which uses a more accurate criterion for what to warn about. */
5490 else
5492 /* Now warn if is a pointer to an incomplete type. */
5493 while (TREE_CODE (type) == POINTER_TYPE
5494 || TREE_CODE (type) == REFERENCE_TYPE)
5495 type = TREE_TYPE (type);
5496 type = TYPE_MAIN_VARIANT (type);
5497 if (TYPE_SIZE (type) == 0)
5499 if (DECL_NAME (parm) != 0)
5500 warning ("parameter `%s' points to incomplete type",
5501 IDENTIFIER_POINTER (DECL_NAME (parm)));
5502 else
5503 warning ("parameter points to incomplete type");
5506 #endif
5507 typelt = TREE_CHAIN (typelt);
5510 /* Allocate the list of types the way we allocate a type. */
5511 if (first_parm && ! TREE_PERMANENT (first_parm))
5513 /* Construct a copy of the list of types
5514 on the saveable obstack. */
5515 tree result = NULL;
5516 for (typelt = first_parm; typelt; typelt = TREE_CHAIN (typelt))
5517 result = saveable_tree_cons (NULL_TREE, TREE_VALUE (typelt),
5518 result);
5519 return nreverse (result);
5521 else
5522 /* The list we have is permanent already. */
5523 return first_parm;
5528 /* Return a tree_list node with info on a parameter list just parsed.
5529 The TREE_PURPOSE is a chain of decls of those parms.
5530 The TREE_VALUE is a list of structure, union and enum tags defined.
5531 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
5532 This tree_list node is later fed to `grokparms'.
5534 VOID_AT_END nonzero means append `void' to the end of the type-list.
5535 Zero means the parmlist ended with an ellipsis so don't append `void'. */
5537 tree
5538 get_parm_info (void_at_end)
5539 int void_at_end;
5541 register tree decl, t;
5542 register tree types = 0;
5543 int erred = 0;
5544 tree tags = gettags ();
5545 tree parms = getdecls ();
5546 tree new_parms = 0;
5547 tree order = current_binding_level->parm_order;
5549 /* Just `void' (and no ellipsis) is special. There are really no parms. */
5550 if (void_at_end && parms != 0
5551 && TREE_CHAIN (parms) == 0
5552 && TYPE_MAIN_VARIANT (TREE_TYPE (parms)) == void_type_node
5553 && DECL_NAME (parms) == 0)
5555 parms = NULL_TREE;
5556 storedecls (NULL_TREE);
5557 return saveable_tree_cons (NULL_TREE, NULL_TREE,
5558 saveable_tree_cons (NULL_TREE, void_type_node, NULL_TREE));
5561 /* Extract enumerator values and other non-parms declared with the parms.
5562 Likewise any forward parm decls that didn't have real parm decls. */
5563 for (decl = parms; decl; )
5565 tree next = TREE_CHAIN (decl);
5567 if (TREE_CODE (decl) != PARM_DECL)
5569 TREE_CHAIN (decl) = new_parms;
5570 new_parms = decl;
5572 else if (TREE_ASM_WRITTEN (decl))
5574 error_with_decl (decl, "parameter `%s' has just a forward declaration");
5575 TREE_CHAIN (decl) = new_parms;
5576 new_parms = decl;
5578 decl = next;
5581 /* Put the parm decls back in the order they were in in the parm list. */
5582 for (t = order; t; t = TREE_CHAIN (t))
5584 if (TREE_CHAIN (t))
5585 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
5586 else
5587 TREE_CHAIN (TREE_VALUE (t)) = 0;
5590 new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
5591 new_parms);
5593 /* Store the parmlist in the binding level since the old one
5594 is no longer a valid list. (We have changed the chain pointers.) */
5595 storedecls (new_parms);
5597 for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
5598 /* There may also be declarations for enumerators if an enumeration
5599 type is declared among the parms. Ignore them here. */
5600 if (TREE_CODE (decl) == PARM_DECL)
5602 /* Since there is a prototype,
5603 args are passed in their declared types. */
5604 tree type = TREE_TYPE (decl);
5605 DECL_ARG_TYPE (decl) = type;
5606 #ifdef PROMOTE_PROTOTYPES
5607 if ((TREE_CODE (type) == INTEGER_TYPE
5608 || TREE_CODE (type) == ENUMERAL_TYPE)
5609 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
5610 DECL_ARG_TYPE (decl) = integer_type_node;
5611 #endif
5613 types = saveable_tree_cons (NULL_TREE, TREE_TYPE (decl), types);
5614 if (TYPE_MAIN_VARIANT (TREE_VALUE (types)) == void_type_node && ! erred
5615 && DECL_NAME (decl) == 0)
5617 error ("`void' in parameter list must be the entire list");
5618 erred = 1;
5622 if (void_at_end)
5623 return saveable_tree_cons (new_parms, tags,
5624 nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types)));
5626 return saveable_tree_cons (new_parms, tags, nreverse (types));
5629 /* At end of parameter list, warn about any struct, union or enum tags
5630 defined within. Do so because these types cannot ever become complete. */
5632 void
5633 parmlist_tags_warning ()
5635 tree elt;
5636 static int already;
5638 for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
5640 enum tree_code code = TREE_CODE (TREE_VALUE (elt));
5641 /* An anonymous union parm type is meaningful as a GNU extension.
5642 So don't warn for that. */
5643 if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic)
5644 continue;
5645 if (TREE_PURPOSE (elt) != 0)
5646 warning ("`%s %s' declared inside parameter list",
5647 (code == RECORD_TYPE ? "struct"
5648 : code == UNION_TYPE ? "union"
5649 : "enum"),
5650 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
5651 else
5652 warning ("anonymous %s declared inside parameter list",
5653 (code == RECORD_TYPE ? "struct"
5654 : code == UNION_TYPE ? "union"
5655 : "enum"));
5657 if (! already)
5659 warning ("its scope is only this definition or declaration, which is probably not what you want.");
5660 already = 1;
5665 /* Get the struct, enum or union (CODE says which) with tag NAME.
5666 Define the tag as a forward-reference if it is not defined. */
5668 tree
5669 xref_tag (code, name)
5670 enum tree_code code;
5671 tree name;
5673 int temporary = allocation_temporary_p ();
5675 /* If a cross reference is requested, look up the type
5676 already defined for this tag and return it. */
5678 register tree ref = lookup_tag (code, name, current_binding_level, 0);
5679 /* Even if this is the wrong type of tag, return what we found.
5680 There will be an error message anyway, from pending_xref_error.
5681 If we create an empty xref just for an invalid use of the type,
5682 the main result is to create lots of superfluous error messages. */
5683 if (ref)
5684 return ref;
5686 push_obstacks_nochange ();
5688 if (current_binding_level == global_binding_level && temporary)
5689 end_temporary_allocation ();
5691 /* If no such tag is yet defined, create a forward-reference node
5692 and record it as the "definition".
5693 When a real declaration of this type is found,
5694 the forward-reference will be altered into a real type. */
5696 ref = make_node (code);
5697 if (code == ENUMERAL_TYPE)
5699 /* (In ANSI, Enums can be referred to only if already defined.) */
5700 if (pedantic)
5701 pedwarn ("ANSI C forbids forward references to `enum' types");
5702 /* Give the type a default layout like unsigned int
5703 to avoid crashing if it does not get defined. */
5704 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
5705 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5706 TREE_UNSIGNED (ref) = 1;
5707 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5708 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5709 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5712 pushtag (name, ref);
5714 pop_obstacks ();
5716 return ref;
5719 /* Make sure that the tag NAME is defined *in the current binding level*
5720 at least as a forward reference.
5721 CODE says which kind of tag NAME ought to be.
5723 We also do a push_obstacks_nochange
5724 whose matching pop is in finish_struct. */
5726 tree
5727 start_struct (code, name)
5728 enum tree_code code;
5729 tree name;
5731 /* If there is already a tag defined at this binding level
5732 (as a forward reference), just return it. */
5734 register tree ref = 0;
5736 push_obstacks_nochange ();
5737 if (current_binding_level == global_binding_level)
5738 end_temporary_allocation ();
5740 if (name != 0)
5741 ref = lookup_tag (code, name, current_binding_level, 1);
5742 if (ref && TREE_CODE (ref) == code)
5744 C_TYPE_BEING_DEFINED (ref) = 1;
5745 TYPE_PACKED (ref) = flag_pack_struct;
5746 if (TYPE_FIELDS (ref))
5747 error ((code == UNION_TYPE ? "redefinition of `union %s'"
5748 : "redefinition of `struct %s'"),
5749 IDENTIFIER_POINTER (name));
5751 return ref;
5754 /* Otherwise create a forward-reference just so the tag is in scope. */
5756 ref = make_node (code);
5757 pushtag (name, ref);
5758 C_TYPE_BEING_DEFINED (ref) = 1;
5759 TYPE_PACKED (ref) = flag_pack_struct;
5760 return ref;
5763 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
5764 of a structure component, returning a FIELD_DECL node.
5765 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
5767 This is done during the parsing of the struct declaration.
5768 The FIELD_DECL nodes are chained together and the lot of them
5769 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5771 tree
5772 grokfield (filename, line, declarator, declspecs, width)
5773 const char *filename ATTRIBUTE_UNUSED;
5774 int line ATTRIBUTE_UNUSED;
5775 tree declarator, declspecs, width;
5777 tree value;
5779 /* The corresponding pop_obstacks is in finish_decl. */
5780 push_obstacks_nochange ();
5782 value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
5784 finish_decl (value, NULL_TREE, NULL_TREE);
5785 DECL_INITIAL (value) = width;
5787 maybe_objc_check_decl (value);
5788 return value;
5791 /* Function to help qsort sort FIELD_DECLs by name order. */
5793 static int
5794 field_decl_cmp (xp, yp)
5795 const GENERIC_PTR xp;
5796 const GENERIC_PTR yp;
5798 tree *x = (tree *)xp, *y = (tree *)yp;
5800 if (DECL_NAME (*x) == DECL_NAME (*y))
5801 return 0;
5802 if (DECL_NAME (*x) == NULL)
5803 return -1;
5804 if (DECL_NAME (*y) == NULL)
5805 return 1;
5806 if (DECL_NAME (*x) < DECL_NAME (*y))
5807 return -1;
5808 return 1;
5811 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5812 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5813 ATTRIBUTES are attributes to be applied to the structure.
5815 We also do a pop_obstacks to match the push in start_struct. */
5817 tree
5818 finish_struct (t, fieldlist, attributes)
5819 tree t;
5820 tree fieldlist;
5821 tree attributes;
5823 register tree x;
5824 int old_momentary;
5825 int toplevel = global_binding_level == current_binding_level;
5827 /* If this type was previously laid out as a forward reference,
5828 make sure we lay it out again. */
5830 TYPE_SIZE (t) = 0;
5832 decl_attributes (t, attributes, NULL_TREE);
5834 /* Nameless union parm types are useful as GCC extension. */
5835 if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
5836 /* Otherwise, warn about any struct or union def. in parmlist. */
5837 if (in_parm_level_p ())
5839 if (pedantic)
5840 pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms"
5841 : "structure defined inside parms"));
5842 else if (! flag_traditional)
5843 warning ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms"
5844 : "structure defined inside parms"));
5847 old_momentary = suspend_momentary ();
5849 if (pedantic)
5851 for (x = fieldlist; x; x = TREE_CHAIN (x))
5852 if (DECL_NAME (x) != 0)
5853 break;
5855 if (x == 0)
5856 pedwarn ((fieldlist
5857 ? "%s has no named members"
5858 : "%s has no members"),
5859 TREE_CODE (t) == UNION_TYPE ? "union" : "struct");
5862 /* Install struct as DECL_CONTEXT of each field decl.
5863 Also process specified field sizes.
5864 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
5865 The specified size is found in the DECL_INITIAL.
5866 Store 0 there, except for ": 0" fields (so we can find them
5867 and delete them, below). */
5869 for (x = fieldlist; x; x = TREE_CHAIN (x))
5871 DECL_CONTEXT (x) = t;
5872 DECL_PACKED (x) |= TYPE_PACKED (t);
5873 DECL_FIELD_SIZE (x) = 0;
5875 /* If any field is const, the structure type is pseudo-const. */
5876 if (TREE_READONLY (x))
5877 C_TYPE_FIELDS_READONLY (t) = 1;
5878 else
5880 /* A field that is pseudo-const makes the structure likewise. */
5881 tree t1 = TREE_TYPE (x);
5882 while (TREE_CODE (t1) == ARRAY_TYPE)
5883 t1 = TREE_TYPE (t1);
5884 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5885 && C_TYPE_FIELDS_READONLY (t1))
5886 C_TYPE_FIELDS_READONLY (t) = 1;
5889 /* Any field that is volatile means variables of this type must be
5890 treated in some ways as volatile. */
5891 if (TREE_THIS_VOLATILE (x))
5892 C_TYPE_FIELDS_VOLATILE (t) = 1;
5894 /* Any field of nominal variable size implies structure is too. */
5895 if (C_DECL_VARIABLE_SIZE (x))
5896 C_TYPE_VARIABLE_SIZE (t) = 1;
5898 /* Detect invalid nested redefinition. */
5899 if (TREE_TYPE (x) == t)
5900 error ("nested redefinition of `%s'",
5901 IDENTIFIER_POINTER (TYPE_NAME (t)));
5903 /* Detect invalid bit-field size. */
5904 if (DECL_INITIAL (x))
5905 STRIP_NOPS (DECL_INITIAL (x));
5906 if (DECL_INITIAL (x))
5908 if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST)
5909 constant_expression_warning (DECL_INITIAL (x));
5910 else
5912 error_with_decl (x, "bit-field `%s' width not an integer constant");
5913 DECL_INITIAL (x) = NULL;
5917 /* Detect invalid bit-field type. */
5918 if (DECL_INITIAL (x)
5919 && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
5920 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
5922 error_with_decl (x, "bit-field `%s' has invalid type");
5923 DECL_INITIAL (x) = NULL;
5925 if (DECL_INITIAL (x) && pedantic
5926 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
5927 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
5928 /* Accept an enum that's equivalent to int or unsigned int. */
5929 && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5930 && (TYPE_PRECISION (TREE_TYPE (x))
5931 == TYPE_PRECISION (integer_type_node))))
5932 pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C");
5934 /* Detect and ignore out of range field width. */
5935 if (DECL_INITIAL (x))
5937 unsigned HOST_WIDE_INT width = TREE_INT_CST_LOW (DECL_INITIAL (x));
5939 if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
5941 DECL_INITIAL (x) = NULL;
5942 error_with_decl (x, "negative width in bit-field `%s'");
5944 else if (TREE_INT_CST_HIGH (DECL_INITIAL (x)) != 0
5945 || width > TYPE_PRECISION (TREE_TYPE (x)))
5947 DECL_INITIAL (x) = NULL;
5948 pedwarn_with_decl (x, "width of `%s' exceeds its type");
5950 else if (width == 0 && DECL_NAME (x) != 0)
5952 error_with_decl (x, "zero width for bit-field `%s'");
5953 DECL_INITIAL (x) = NULL;
5957 /* Process valid field width. */
5958 if (DECL_INITIAL (x))
5960 register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
5962 if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5963 && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
5964 TREE_UNSIGNED (TREE_TYPE (x)))
5965 || width < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
5966 TREE_UNSIGNED (TREE_TYPE (x)))))
5967 warning_with_decl (x, "`%s' is narrower than values of its type");
5969 DECL_FIELD_SIZE (x) = width;
5970 DECL_BIT_FIELD (x) = DECL_C_BIT_FIELD (x) = 1;
5971 DECL_INITIAL (x) = NULL;
5973 if (width == 0)
5975 /* field size 0 => force desired amount of alignment. */
5976 #ifdef EMPTY_FIELD_BOUNDARY
5977 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
5978 #endif
5979 #ifdef PCC_BITFIELD_TYPE_MATTERS
5980 if (PCC_BITFIELD_TYPE_MATTERS)
5981 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
5982 TYPE_ALIGN (TREE_TYPE (x)));
5983 #endif
5986 else if (TREE_TYPE (x) != error_mark_node)
5988 unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
5989 : TYPE_ALIGN (TREE_TYPE (x)));
5990 /* Non-bit-fields are aligned for their type, except packed
5991 fields which require only BITS_PER_UNIT alignment. */
5992 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
5996 /* Now DECL_INITIAL is null on all members. */
5998 /* Delete all duplicate fields from the fieldlist */
5999 for (x = fieldlist; x && TREE_CHAIN (x);)
6000 /* Anonymous fields aren't duplicates. */
6001 if (DECL_NAME (TREE_CHAIN (x)) == 0)
6002 x = TREE_CHAIN (x);
6003 else
6005 register tree y = fieldlist;
6007 while (1)
6009 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
6010 break;
6011 if (y == x)
6012 break;
6013 y = TREE_CHAIN (y);
6015 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
6017 error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
6018 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
6020 else x = TREE_CHAIN (x);
6023 /* Now we have the nearly final fieldlist. Record it,
6024 then lay out the structure or union (including the fields). */
6026 TYPE_FIELDS (t) = fieldlist;
6028 layout_type (t);
6030 /* Delete all zero-width bit-fields from the front of the fieldlist */
6031 while (fieldlist
6032 && DECL_INITIAL (fieldlist))
6033 fieldlist = TREE_CHAIN (fieldlist);
6034 /* Delete all such members from the rest of the fieldlist */
6035 for (x = fieldlist; x;)
6037 if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x)))
6038 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
6039 else x = TREE_CHAIN (x);
6042 /* Now we have the truly final field list.
6043 Store it in this type and in the variants. */
6045 TYPE_FIELDS (t) = fieldlist;
6047 /* If there are lots of fields, sort so we can look through them fast.
6048 We arbitrarily consider 16 or more elts to be "a lot". */
6050 int len = 0;
6052 for (x = fieldlist; x; x = TREE_CHAIN (x))
6054 if (len > 15)
6055 break;
6056 len += 1;
6058 if (len > 15)
6060 tree *field_array;
6061 char *space;
6063 len += list_length (x);
6064 /* Use the same allocation policy here that make_node uses, to
6065 ensure that this lives as long as the rest of the struct decl.
6066 All decls in an inline function need to be saved. */
6067 if (allocation_temporary_p ())
6068 space = savealloc (sizeof (struct lang_type) + len * sizeof (tree));
6069 else
6070 space = oballoc (sizeof (struct lang_type) + len * sizeof (tree));
6072 TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space;
6073 TYPE_LANG_SPECIFIC (t)->len = len;
6075 field_array = &TYPE_LANG_SPECIFIC (t)->elts[0];
6076 len = 0;
6077 for (x = fieldlist; x; x = TREE_CHAIN (x))
6078 field_array[len++] = x;
6080 qsort (field_array, len, sizeof (tree), field_decl_cmp);
6084 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
6086 TYPE_FIELDS (x) = TYPE_FIELDS (t);
6087 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
6088 TYPE_ALIGN (x) = TYPE_ALIGN (t);
6091 /* If this was supposed to be a transparent union, but we can't
6092 make it one, warn and turn off the flag. */
6093 if (TREE_CODE (t) == UNION_TYPE
6094 && TYPE_TRANSPARENT_UNION (t)
6095 && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))
6097 TYPE_TRANSPARENT_UNION (t) = 0;
6098 warning ("union cannot be made transparent");
6101 /* If this structure or union completes the type of any previous
6102 variable declaration, lay it out and output its rtl. */
6104 if (current_binding_level->n_incomplete != 0)
6106 tree decl;
6107 for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
6109 if (TREE_TYPE (decl) == t
6110 && TREE_CODE (decl) != TYPE_DECL)
6112 layout_decl (decl, 0);
6113 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
6114 maybe_objc_check_decl (decl);
6115 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
6116 if (! toplevel)
6117 expand_decl (decl);
6118 --current_binding_level->n_incomplete;
6120 else if (TYPE_SIZE (TREE_TYPE (decl)) == 0
6121 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
6123 tree element = TREE_TYPE (decl);
6124 while (TREE_CODE (element) == ARRAY_TYPE)
6125 element = TREE_TYPE (element);
6126 if (element == t)
6127 layout_array_type (TREE_TYPE (decl));
6132 resume_momentary (old_momentary);
6134 /* Finish debugging output for this type. */
6135 rest_of_type_compilation (t, toplevel);
6137 /* The matching push is in start_struct. */
6138 pop_obstacks ();
6140 return t;
6143 /* Lay out the type T, and its element type, and so on. */
6145 static void
6146 layout_array_type (t)
6147 tree t;
6149 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6150 layout_array_type (TREE_TYPE (t));
6151 layout_type (t);
6154 /* Begin compiling the definition of an enumeration type.
6155 NAME is its name (or null if anonymous).
6156 Returns the type object, as yet incomplete.
6157 Also records info about it so that build_enumerator
6158 may be used to declare the individual values as they are read. */
6160 tree
6161 start_enum (name)
6162 tree name;
6164 register tree enumtype = 0;
6166 /* If this is the real definition for a previous forward reference,
6167 fill in the contents in the same object that used to be the
6168 forward reference. */
6170 if (name != 0)
6171 enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
6173 /* The corresponding pop_obstacks is in finish_enum. */
6174 push_obstacks_nochange ();
6175 /* If these symbols and types are global, make them permanent. */
6176 if (current_binding_level == global_binding_level)
6177 end_temporary_allocation ();
6179 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
6181 enumtype = make_node (ENUMERAL_TYPE);
6182 pushtag (name, enumtype);
6185 C_TYPE_BEING_DEFINED (enumtype) = 1;
6187 if (TYPE_VALUES (enumtype) != 0)
6189 /* This enum is a named one that has been declared already. */
6190 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
6192 /* Completely replace its old definition.
6193 The old enumerators remain defined, however. */
6194 TYPE_VALUES (enumtype) = 0;
6197 enum_next_value = integer_zero_node;
6198 enum_overflow = 0;
6200 if (flag_short_enums)
6201 TYPE_PACKED (enumtype) = 1;
6203 return enumtype;
6206 /* After processing and defining all the values of an enumeration type,
6207 install their decls in the enumeration type and finish it off.
6208 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
6209 and ATTRIBUTES are the specified attributes.
6210 Returns ENUMTYPE. */
6212 tree
6213 finish_enum (enumtype, values, attributes)
6214 tree enumtype;
6215 tree values;
6216 tree attributes;
6218 register tree pair, tem;
6219 tree minnode = 0, maxnode = 0;
6220 int lowprec, highprec, precision;
6221 int toplevel = global_binding_level == current_binding_level;
6223 if (in_parm_level_p ())
6224 warning ("enum defined inside parms");
6226 decl_attributes (enumtype, attributes, NULL_TREE);
6228 /* Calculate the maximum value of any enumerator in this type. */
6230 if (values == error_mark_node)
6231 minnode = maxnode = integer_zero_node;
6232 else
6233 for (pair = values; pair; pair = TREE_CHAIN (pair))
6235 tree value = TREE_VALUE (pair);
6236 if (pair == values)
6237 minnode = maxnode = TREE_VALUE (pair);
6238 else
6240 if (tree_int_cst_lt (maxnode, value))
6241 maxnode = value;
6242 if (tree_int_cst_lt (value, minnode))
6243 minnode = value;
6247 TYPE_MIN_VALUE (enumtype) = minnode;
6248 TYPE_MAX_VALUE (enumtype) = maxnode;
6250 /* An enum can have some negative values; then it is signed. */
6251 TREE_UNSIGNED (enumtype) = tree_int_cst_sgn (minnode) >= 0;
6253 /* Determine the precision this type needs. */
6255 lowprec = min_precision (minnode, TREE_UNSIGNED (enumtype));
6256 highprec = min_precision (maxnode, TREE_UNSIGNED (enumtype));
6257 precision = MAX (lowprec, highprec);
6259 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
6261 tree narrowest = type_for_size (precision, 1);
6262 if (narrowest == 0)
6264 warning ("enumeration values exceed range of largest integer");
6265 narrowest = long_long_integer_type_node;
6268 TYPE_PRECISION (enumtype) = TYPE_PRECISION (narrowest);
6270 else
6271 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
6273 TYPE_SIZE (enumtype) = 0;
6274 layout_type (enumtype);
6276 if (values != error_mark_node)
6278 /* Change the type of the enumerators to be the enum type.
6279 Formerly this was done only for enums that fit in an int,
6280 but the comment said it was done only for enums wider than int.
6281 It seems necessary to do this for wide enums,
6282 and best not to change what's done for ordinary narrower ones. */
6283 for (pair = values; pair; pair = TREE_CHAIN (pair))
6285 TREE_TYPE (TREE_PURPOSE (pair)) = enumtype;
6286 DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype);
6287 if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL)
6288 DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype);
6291 /* Replace the decl nodes in VALUES with their names. */
6292 for (pair = values; pair; pair = TREE_CHAIN (pair))
6293 TREE_PURPOSE (pair) = DECL_NAME (TREE_PURPOSE (pair));
6295 TYPE_VALUES (enumtype) = values;
6298 /* Fix up all variant types of this enum type. */
6299 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
6301 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
6302 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
6303 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
6304 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
6305 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
6306 TYPE_MODE (tem) = TYPE_MODE (enumtype);
6307 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
6308 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
6309 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
6312 /* Finish debugging output for this type. */
6313 rest_of_type_compilation (enumtype, toplevel);
6315 /* This matches a push in start_enum. */
6316 pop_obstacks ();
6318 return enumtype;
6321 /* Build and install a CONST_DECL for one value of the
6322 current enumeration type (one that was begun with start_enum).
6323 Return a tree-list containing the CONST_DECL and its value.
6324 Assignment of sequential values by default is handled here. */
6326 tree
6327 build_enumerator (name, value)
6328 tree name, value;
6330 register tree decl, type;
6332 /* Validate and default VALUE. */
6334 /* Remove no-op casts from the value. */
6335 if (value)
6336 STRIP_TYPE_NOPS (value);
6338 if (value != 0)
6340 if (TREE_CODE (value) == INTEGER_CST)
6342 value = default_conversion (value);
6343 constant_expression_warning (value);
6345 else
6347 error ("enumerator value for `%s' not integer constant",
6348 IDENTIFIER_POINTER (name));
6349 value = 0;
6353 /* Default based on previous value. */
6354 /* It should no longer be possible to have NON_LVALUE_EXPR
6355 in the default. */
6356 if (value == 0)
6358 value = enum_next_value;
6359 if (enum_overflow)
6360 error ("overflow in enumeration values");
6363 if (pedantic && ! int_fits_type_p (value, integer_type_node))
6365 pedwarn ("ANSI C restricts enumerator values to range of `int'");
6366 value = integer_zero_node;
6369 /* Set basis for default for next value. */
6370 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
6371 enum_overflow = tree_int_cst_lt (enum_next_value, value);
6373 /* Now create a declaration for the enum value name. */
6375 type = TREE_TYPE (value);
6376 type = type_for_size (MAX (TYPE_PRECISION (type),
6377 TYPE_PRECISION (integer_type_node)),
6378 ((flag_traditional
6379 || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
6380 && TREE_UNSIGNED (type)));
6382 decl = build_decl (CONST_DECL, name, type);
6383 DECL_INITIAL (decl) = value;
6384 TREE_TYPE (value) = type;
6385 pushdecl (decl);
6387 return saveable_tree_cons (decl, value, NULL_TREE);
6390 /* Create the FUNCTION_DECL for a function definition.
6391 DECLSPECS, DECLARATOR, PREFIX_ATTRIBUTES and ATTRIBUTES are the parts of
6392 the declaration; they describe the function's name and the type it returns,
6393 but twisted together in a fashion that parallels the syntax of C.
6395 This function creates a binding context for the function body
6396 as well as setting up the FUNCTION_DECL in current_function_decl.
6398 Returns 1 on success. If the DECLARATOR is not suitable for a function
6399 (it defines a datum instead), we return 0, which tells
6400 yyparse to report a parse error.
6402 NESTED is nonzero for a function nested within another function. */
6405 start_function (declspecs, declarator, prefix_attributes, attributes, nested)
6406 tree declarator, declspecs, prefix_attributes, attributes;
6407 int nested;
6409 tree decl1, old_decl;
6410 tree restype;
6411 int old_immediate_size_expand = immediate_size_expand;
6413 current_function_returns_value = 0; /* Assume, until we see it does. */
6414 current_function_returns_null = 0;
6415 warn_about_return_type = 0;
6416 current_extern_inline = 0;
6417 c_function_varargs = 0;
6418 named_labels = 0;
6419 shadowed_labels = 0;
6421 /* Don't expand any sizes in the return type of the function. */
6422 immediate_size_expand = 0;
6424 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
6426 /* If the declarator is not suitable for a function definition,
6427 cause a syntax error. */
6428 if (decl1 == 0)
6430 immediate_size_expand = old_immediate_size_expand;
6431 return 0;
6434 decl_attributes (decl1, prefix_attributes, attributes);
6436 announce_function (decl1);
6438 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
6440 error ("return-type is an incomplete type");
6441 /* Make it return void instead. */
6442 TREE_TYPE (decl1)
6443 = build_function_type (void_type_node,
6444 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
6447 if (warn_about_return_type)
6448 warning ("return-type defaults to `int'");
6450 /* Save the parm names or decls from this function's declarator
6451 where store_parm_decls will find them. */
6452 current_function_parms = last_function_parms;
6453 current_function_parm_tags = last_function_parm_tags;
6455 /* Make the init_value nonzero so pushdecl knows this is not tentative.
6456 error_mark_node is replaced below (in poplevel) with the BLOCK. */
6457 DECL_INITIAL (decl1) = error_mark_node;
6459 /* If this definition isn't a prototype and we had a prototype declaration
6460 before, copy the arg type info from that prototype.
6461 But not if what we had before was a builtin function. */
6462 old_decl = lookup_name_current_level (DECL_NAME (decl1));
6463 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
6464 && !DECL_BUILT_IN (old_decl)
6465 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6466 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
6467 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
6469 TREE_TYPE (decl1) = TREE_TYPE (old_decl);
6470 current_function_prototype_file = DECL_SOURCE_FILE (old_decl);
6471 current_function_prototype_line = DECL_SOURCE_LINE (old_decl);
6474 /* If there is no explicit declaration, look for any out-of-scope implicit
6475 declarations. */
6476 if (old_decl == 0)
6477 old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1));
6479 /* Optionally warn of old-fashioned def with no previous prototype. */
6480 if (warn_strict_prototypes
6481 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
6482 && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0))
6483 warning ("function declaration isn't a prototype");
6484 /* Optionally warn of any global def with no previous prototype. */
6485 else if (warn_missing_prototypes
6486 && TREE_PUBLIC (decl1)
6487 && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)
6488 && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
6489 warning_with_decl (decl1, "no previous prototype for `%s'");
6490 /* Optionally warn of any def with no previous prototype
6491 if the function has already been used. */
6492 else if (warn_missing_prototypes
6493 && old_decl != 0 && TREE_USED (old_decl)
6494 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
6495 warning_with_decl (decl1,
6496 "`%s' was used with no prototype before its definition");
6497 /* Optionally warn of any global def with no previous declaration. */
6498 else if (warn_missing_declarations
6499 && TREE_PUBLIC (decl1)
6500 && old_decl == 0
6501 && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
6502 warning_with_decl (decl1, "no previous declaration for `%s'");
6503 /* Optionally warn of any def with no previous declaration
6504 if the function has already been used. */
6505 else if (warn_missing_declarations
6506 && old_decl != 0 && TREE_USED (old_decl)
6507 && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)))
6508 warning_with_decl (decl1,
6509 "`%s' was used with no declaration before its definition");
6511 /* This is a definition, not a reference.
6512 So normally clear DECL_EXTERNAL.
6513 However, `extern inline' acts like a declaration
6514 except for defining how to inline. So set DECL_EXTERNAL in that case. */
6515 DECL_EXTERNAL (decl1) = current_extern_inline;
6517 #ifdef SET_DEFAULT_DECL_ATTRIBUTES
6518 SET_DEFAULT_DECL_ATTRIBUTES (decl1, attributes);
6519 #endif
6521 /* This function exists in static storage.
6522 (This does not mean `static' in the C sense!) */
6523 TREE_STATIC (decl1) = 1;
6525 /* A nested function is not global. */
6526 if (current_function_decl != 0)
6527 TREE_PUBLIC (decl1) = 0;
6529 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
6530 if (warn_main
6531 && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))) == 0)
6533 tree args;
6534 int argct = 0;
6536 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6537 != integer_type_node)
6538 pedwarn_with_decl (decl1, "return type of `%s' is not `int'");
6540 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
6541 args = TREE_CHAIN (args))
6543 tree type = args ? TREE_VALUE (args) : 0;
6545 if (type == void_type_node)
6546 break;
6548 ++argct;
6549 switch (argct)
6551 case 1:
6552 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
6553 pedwarn_with_decl (decl1,
6554 "first argument of `%s' should be `int'");
6555 break;
6557 case 2:
6558 if (TREE_CODE (type) != POINTER_TYPE
6559 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
6560 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
6561 != char_type_node))
6562 pedwarn_with_decl (decl1,
6563 "second argument of `%s' should be `char **'");
6564 break;
6566 case 3:
6567 if (TREE_CODE (type) != POINTER_TYPE
6568 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
6569 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
6570 != char_type_node))
6571 pedwarn_with_decl (decl1,
6572 "third argument of `%s' should probably be `char **'");
6573 break;
6577 /* It is intentional that this message does not mention the third
6578 argument, which is warned for only pedantically, because it's
6579 blessed by mention in an appendix of the standard. */
6580 if (argct > 0 && (argct < 2 || argct > 3))
6581 pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments");
6583 if (argct == 3 && pedantic)
6584 pedwarn_with_decl (decl1, "third argument of `%s' is deprecated");
6586 if (! TREE_PUBLIC (decl1))
6587 pedwarn_with_decl (decl1, "`%s' is normally a non-static function");
6590 /* Record the decl so that the function name is defined.
6591 If we already have a decl for this name, and it is a FUNCTION_DECL,
6592 use the old decl. */
6594 current_function_decl = pushdecl (decl1);
6596 pushlevel (0);
6597 declare_parm_level (1);
6598 current_binding_level->subblocks_tag_transparent = 1;
6600 make_function_rtl (current_function_decl);
6602 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
6603 /* Promote the value to int before returning it. */
6604 if (C_PROMOTING_INTEGER_TYPE_P (restype))
6606 /* It retains unsignedness if traditional
6607 or if not really getting wider. */
6608 if (TREE_UNSIGNED (restype)
6609 && (flag_traditional
6610 || (TYPE_PRECISION (restype)
6611 == TYPE_PRECISION (integer_type_node))))
6612 restype = unsigned_type_node;
6613 else
6614 restype = integer_type_node;
6616 DECL_RESULT (current_function_decl)
6617 = build_decl (RESULT_DECL, NULL_TREE, restype);
6619 if (!nested)
6620 /* Allocate further tree nodes temporarily during compilation
6621 of this function only. */
6622 temporary_allocation ();
6624 /* If this fcn was already referenced via a block-scope `extern' decl
6625 (or an implicit decl), propagate certain information about the usage. */
6626 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
6627 TREE_ADDRESSABLE (current_function_decl) = 1;
6629 immediate_size_expand = old_immediate_size_expand;
6631 return 1;
6634 /* Record that this function is going to be a varargs function.
6635 This is called before store_parm_decls, which is too early
6636 to call mark_varargs directly. */
6638 void
6639 c_mark_varargs ()
6641 c_function_varargs = 1;
6644 /* Store the parameter declarations into the current function declaration.
6645 This is called after parsing the parameter declarations, before
6646 digesting the body of the function.
6648 For an old-style definition, modify the function's type
6649 to specify at least the number of arguments. */
6651 void
6652 store_parm_decls ()
6654 register tree fndecl = current_function_decl;
6655 register tree parm;
6657 /* This is either a chain of PARM_DECLs (if a prototype was used)
6658 or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */
6659 tree specparms = current_function_parms;
6661 /* This is a list of types declared among parms in a prototype. */
6662 tree parmtags = current_function_parm_tags;
6664 /* This is a chain of PARM_DECLs from old-style parm declarations. */
6665 register tree parmdecls = getdecls ();
6667 /* This is a chain of any other decls that came in among the parm
6668 declarations. If a parm is declared with enum {foo, bar} x;
6669 then CONST_DECLs for foo and bar are put here. */
6670 tree nonparms = 0;
6672 /* Nonzero if this definition is written with a prototype. */
6673 int prototype = 0;
6675 if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
6677 /* This case is when the function was defined with an ANSI prototype.
6678 The parms already have decls, so we need not do anything here
6679 except record them as in effect
6680 and complain if any redundant old-style parm decls were written. */
6682 register tree next;
6683 tree others = 0;
6685 prototype = 1;
6687 if (parmdecls != 0)
6689 tree decl, link;
6691 error_with_decl (fndecl,
6692 "parm types given both in parmlist and separately");
6693 /* Get rid of the erroneous decls; don't keep them on
6694 the list of parms, since they might not be PARM_DECLs. */
6695 for (decl = current_binding_level->names;
6696 decl; decl = TREE_CHAIN (decl))
6697 if (DECL_NAME (decl))
6698 IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
6699 for (link = current_binding_level->shadowed;
6700 link; link = TREE_CHAIN (link))
6701 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
6702 current_binding_level->names = 0;
6703 current_binding_level->shadowed = 0;
6706 specparms = nreverse (specparms);
6707 for (parm = specparms; parm; parm = next)
6709 next = TREE_CHAIN (parm);
6710 if (TREE_CODE (parm) == PARM_DECL)
6712 if (DECL_NAME (parm) == 0)
6713 error_with_decl (parm, "parameter name omitted");
6714 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
6716 error_with_decl (parm, "parameter `%s' declared void");
6717 /* Change the type to error_mark_node so this parameter
6718 will be ignored by assign_parms. */
6719 TREE_TYPE (parm) = error_mark_node;
6721 pushdecl (parm);
6723 else
6725 /* If we find an enum constant or a type tag,
6726 put it aside for the moment. */
6727 TREE_CHAIN (parm) = 0;
6728 others = chainon (others, parm);
6732 /* Get the decls in their original chain order
6733 and record in the function. */
6734 DECL_ARGUMENTS (fndecl) = getdecls ();
6736 #if 0
6737 /* If this function takes a variable number of arguments,
6738 add a phony parameter to the end of the parm list,
6739 to represent the position of the first unnamed argument. */
6740 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
6741 != void_type_node)
6743 tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
6744 /* Let's hope the address of the unnamed parm
6745 won't depend on its type. */
6746 TREE_TYPE (dummy) = integer_type_node;
6747 DECL_ARG_TYPE (dummy) = integer_type_node;
6748 DECL_ARGUMENTS (fndecl)
6749 = chainon (DECL_ARGUMENTS (fndecl), dummy);
6751 #endif
6753 /* Now pushdecl the enum constants. */
6754 for (parm = others; parm; parm = next)
6756 next = TREE_CHAIN (parm);
6757 if (DECL_NAME (parm) == 0)
6759 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
6761 else if (TREE_CODE (parm) != PARM_DECL)
6762 pushdecl (parm);
6765 storetags (chainon (parmtags, gettags ()));
6767 else
6769 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
6770 each with a parm name as the TREE_VALUE.
6772 PARMDECLS is a chain of declarations for parameters.
6773 Warning! It can also contain CONST_DECLs which are not parameters
6774 but are names of enumerators of any enum types
6775 declared among the parameters.
6777 First match each formal parameter name with its declaration.
6778 Associate decls with the names and store the decls
6779 into the TREE_PURPOSE slots. */
6781 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
6782 DECL_RESULT (parm) = 0;
6784 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
6786 register tree tail, found = NULL;
6788 if (TREE_VALUE (parm) == 0)
6790 error_with_decl (fndecl, "parameter name missing from parameter list");
6791 TREE_PURPOSE (parm) = 0;
6792 continue;
6795 /* See if any of the parmdecls specifies this parm by name.
6796 Ignore any enumerator decls. */
6797 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
6798 if (DECL_NAME (tail) == TREE_VALUE (parm)
6799 && TREE_CODE (tail) == PARM_DECL)
6801 found = tail;
6802 break;
6805 /* If declaration already marked, we have a duplicate name.
6806 Complain, and don't use this decl twice. */
6807 if (found && DECL_RESULT (found) != 0)
6809 error_with_decl (found, "multiple parameters named `%s'");
6810 found = 0;
6813 /* If the declaration says "void", complain and ignore it. */
6814 if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
6816 error_with_decl (found, "parameter `%s' declared void");
6817 TREE_TYPE (found) = integer_type_node;
6818 DECL_ARG_TYPE (found) = integer_type_node;
6819 layout_decl (found, 0);
6822 /* Traditionally, a parm declared float is actually a double. */
6823 if (found && flag_traditional
6824 && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
6826 TREE_TYPE (found) = double_type_node;
6827 DECL_ARG_TYPE (found) = double_type_node;
6828 layout_decl (found, 0);
6831 /* If no declaration found, default to int. */
6832 if (!found)
6834 found = build_decl (PARM_DECL, TREE_VALUE (parm),
6835 integer_type_node);
6836 DECL_ARG_TYPE (found) = TREE_TYPE (found);
6837 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
6838 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
6839 if (extra_warnings)
6840 warning_with_decl (found, "type of `%s' defaults to `int'");
6841 pushdecl (found);
6844 TREE_PURPOSE (parm) = found;
6846 /* Mark this decl as "already found" -- see test, above.
6847 It is safe to use DECL_RESULT for this
6848 since it is not used in PARM_DECLs or CONST_DECLs. */
6849 DECL_RESULT (found) = error_mark_node;
6852 /* Put anything which is on the parmdecls chain and which is
6853 not a PARM_DECL onto the list NONPARMS. (The types of
6854 non-parm things which might appear on the list include
6855 enumerators and NULL-named TYPE_DECL nodes.) Complain about
6856 any actual PARM_DECLs not matched with any names. */
6858 nonparms = 0;
6859 for (parm = parmdecls; parm; )
6861 tree next = TREE_CHAIN (parm);
6862 TREE_CHAIN (parm) = 0;
6864 if (TREE_CODE (parm) != PARM_DECL)
6865 nonparms = chainon (nonparms, parm);
6866 else
6868 /* Complain about args with incomplete types. */
6869 if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
6871 error_with_decl (parm, "parameter `%s' has incomplete type");
6872 TREE_TYPE (parm) = error_mark_node;
6875 if (DECL_RESULT (parm) == 0)
6877 error_with_decl (parm,
6878 "declaration for parameter `%s' but no such parameter");
6879 /* Pretend the parameter was not missing.
6880 This gets us to a standard state and minimizes
6881 further error messages. */
6882 specparms
6883 = chainon (specparms,
6884 tree_cons (parm, NULL_TREE, NULL_TREE));
6888 parm = next;
6891 /* Chain the declarations together in the order of the list of names. */
6892 /* Store that chain in the function decl, replacing the list of names. */
6893 parm = specparms;
6894 DECL_ARGUMENTS (fndecl) = 0;
6896 register tree last;
6897 for (last = 0; parm; parm = TREE_CHAIN (parm))
6898 if (TREE_PURPOSE (parm))
6900 if (last == 0)
6901 DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
6902 else
6903 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6904 last = TREE_PURPOSE (parm);
6905 TREE_CHAIN (last) = 0;
6909 /* If there was a previous prototype,
6910 set the DECL_ARG_TYPE of each argument according to
6911 the type previously specified, and report any mismatches. */
6913 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
6915 register tree type;
6916 for (parm = DECL_ARGUMENTS (fndecl),
6917 type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
6918 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
6919 != void_type_node));
6920 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6922 if (parm == 0 || type == 0
6923 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6925 error ("number of arguments doesn't match prototype");
6926 error_with_file_and_line (current_function_prototype_file,
6927 current_function_prototype_line,
6928 "prototype declaration");
6929 break;
6931 /* Type for passing arg must be consistent
6932 with that declared for the arg. */
6933 if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type)))
6935 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6936 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6938 /* Adjust argument to match prototype. E.g. a previous
6939 `int foo(float);' prototype causes
6940 `int foo(x) float x; {...}' to be treated like
6941 `int foo(float x) {...}'. This is particularly
6942 useful for argument types like uid_t. */
6943 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6944 #ifdef PROMOTE_PROTOTYPES
6945 if ((TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
6946 || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE)
6947 && TYPE_PRECISION (TREE_TYPE (parm))
6948 < TYPE_PRECISION (integer_type_node))
6949 DECL_ARG_TYPE (parm) = integer_type_node;
6950 #endif
6951 if (pedantic)
6953 pedwarn ("promoted argument `%s' doesn't match prototype",
6954 IDENTIFIER_POINTER (DECL_NAME (parm)));
6955 warning_with_file_and_line
6956 (current_function_prototype_file,
6957 current_function_prototype_line,
6958 "prototype declaration");
6961 /* If -traditional, allow `int' argument to match
6962 `unsigned' prototype. */
6963 else if (! (flag_traditional
6964 && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node
6965 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))
6967 error ("argument `%s' doesn't match prototype",
6968 IDENTIFIER_POINTER (DECL_NAME (parm)));
6969 error_with_file_and_line (current_function_prototype_file,
6970 current_function_prototype_line,
6971 "prototype declaration");
6975 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6978 /* Otherwise, create a prototype that would match. */
6980 else
6982 tree actual = 0, last = 0, type;
6984 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6986 type = perm_tree_cons (NULL_TREE, DECL_ARG_TYPE (parm),
6987 NULL_TREE);
6988 if (last)
6989 TREE_CHAIN (last) = type;
6990 else
6991 actual = type;
6992 last = type;
6994 type = perm_tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6995 if (last)
6996 TREE_CHAIN (last) = type;
6997 else
6998 actual = type;
7000 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
7001 of the type of this function, but we need to avoid having this
7002 affect the types of other similarly-typed functions, so we must
7003 first force the generation of an identical (but separate) type
7004 node for the relevant function type. The new node we create
7005 will be a variant of the main variant of the original function
7006 type. */
7008 TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
7010 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
7013 /* Now store the final chain of decls for the arguments
7014 as the decl-chain of the current lexical scope.
7015 Put the enumerators in as well, at the front so that
7016 DECL_ARGUMENTS is not modified. */
7018 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
7021 /* Make sure the binding level for the top of the function body
7022 gets a BLOCK if there are any in the function.
7023 Otherwise, the dbx output is wrong. */
7025 keep_next_if_subblocks = 1;
7027 /* ??? This might be an improvement,
7028 but needs to be thought about some more. */
7029 #if 0
7030 keep_next_level_flag = 1;
7031 #endif
7033 /* Write a record describing this function definition to the prototypes
7034 file (if requested). */
7036 gen_aux_info_record (fndecl, 1, 0, prototype);
7038 /* Initialize the RTL code for the function. */
7040 init_function_start (fndecl, input_filename, lineno);
7042 /* If this is a varargs function, inform function.c. */
7044 if (c_function_varargs)
7045 mark_varargs ();
7047 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
7049 declare_function_name ();
7051 /* Set up parameters and prepare for return, for the function. */
7053 expand_function_start (fndecl, 0);
7055 /* If this function is `main', emit a call to `__main'
7056 to run global initializers, etc. */
7057 if (DECL_NAME (fndecl)
7058 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
7059 && DECL_CONTEXT (fndecl) == NULL_TREE)
7060 expand_main_function ();
7063 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
7064 each with a parm name as the TREE_VALUE. A null pointer as TREE_VALUE
7065 stands for an ellipsis in the identifier list.
7067 PARMLIST is the data returned by get_parm_info for the
7068 parmlist that follows the semicolon.
7070 We return a value of the same sort that get_parm_info returns,
7071 except that it describes the combination of identifiers and parmlist. */
7073 tree
7074 combine_parm_decls (specparms, parmlist, void_at_end)
7075 tree specparms, parmlist;
7076 int void_at_end;
7078 register tree fndecl = current_function_decl;
7079 register tree parm;
7081 tree parmdecls = TREE_PURPOSE (parmlist);
7083 /* This is a chain of any other decls that came in among the parm
7084 declarations. They were separated already by get_parm_info,
7085 so we just need to keep them separate. */
7086 tree nonparms = TREE_VALUE (parmlist);
7088 tree types = 0;
7090 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
7091 DECL_RESULT (parm) = 0;
7093 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
7095 register tree tail, found = NULL;
7097 /* See if any of the parmdecls specifies this parm by name. */
7098 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
7099 if (DECL_NAME (tail) == TREE_VALUE (parm))
7101 found = tail;
7102 break;
7105 /* If declaration already marked, we have a duplicate name.
7106 Complain, and don't use this decl twice. */
7107 if (found && DECL_RESULT (found) != 0)
7109 error_with_decl (found, "multiple parameters named `%s'");
7110 found = 0;
7113 /* If the declaration says "void", complain and ignore it. */
7114 if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
7116 error_with_decl (found, "parameter `%s' declared void");
7117 TREE_TYPE (found) = integer_type_node;
7118 DECL_ARG_TYPE (found) = integer_type_node;
7119 layout_decl (found, 0);
7122 /* Traditionally, a parm declared float is actually a double. */
7123 if (found && flag_traditional
7124 && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
7126 TREE_TYPE (found) = double_type_node;
7127 DECL_ARG_TYPE (found) = double_type_node;
7128 layout_decl (found, 0);
7131 /* If no declaration found, default to int. */
7132 if (!found)
7134 found = build_decl (PARM_DECL, TREE_VALUE (parm),
7135 integer_type_node);
7136 DECL_ARG_TYPE (found) = TREE_TYPE (found);
7137 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
7138 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
7139 error_with_decl (found, "type of parameter `%s' is not declared");
7140 pushdecl (found);
7143 TREE_PURPOSE (parm) = found;
7145 /* Mark this decl as "already found" -- see test, above.
7146 It is safe to use DECL_RESULT for this
7147 since it is not used in PARM_DECLs or CONST_DECLs. */
7148 DECL_RESULT (found) = error_mark_node;
7151 /* Complain about any actual PARM_DECLs not matched with any names. */
7153 for (parm = parmdecls; parm; )
7155 tree next = TREE_CHAIN (parm);
7156 TREE_CHAIN (parm) = 0;
7158 /* Complain about args with incomplete types. */
7159 if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
7161 error_with_decl (parm, "parameter `%s' has incomplete type");
7162 TREE_TYPE (parm) = error_mark_node;
7165 if (DECL_RESULT (parm) == 0)
7167 error_with_decl (parm,
7168 "declaration for parameter `%s' but no such parameter");
7169 /* Pretend the parameter was not missing.
7170 This gets us to a standard state and minimizes
7171 further error messages. */
7172 specparms
7173 = chainon (specparms,
7174 tree_cons (parm, NULL_TREE, NULL_TREE));
7177 parm = next;
7180 /* Chain the declarations together in the order of the list of names.
7181 At the same time, build up a list of their types, in reverse order. */
7183 parm = specparms;
7184 parmdecls = 0;
7186 register tree last;
7187 for (last = 0; parm; parm = TREE_CHAIN (parm))
7188 if (TREE_PURPOSE (parm))
7190 if (last == 0)
7191 parmdecls = TREE_PURPOSE (parm);
7192 else
7193 TREE_CHAIN (last) = TREE_PURPOSE (parm);
7194 last = TREE_PURPOSE (parm);
7195 TREE_CHAIN (last) = 0;
7197 types = saveable_tree_cons (NULL_TREE, TREE_TYPE (parm), types);
7201 if (void_at_end)
7202 return saveable_tree_cons (parmdecls, nonparms,
7203 nreverse (saveable_tree_cons (NULL_TREE,
7204 void_type_node,
7205 types)));
7207 return saveable_tree_cons (parmdecls, nonparms, nreverse (types));
7210 /* Finish up a function declaration and compile that function
7211 all the way to assembler language output. The free the storage
7212 for the function definition.
7214 This is called after parsing the body of the function definition.
7216 NESTED is nonzero if the function being finished is nested in another. */
7218 void
7219 finish_function (nested)
7220 int nested;
7222 register tree fndecl = current_function_decl;
7224 /* TREE_READONLY (fndecl) = 1;
7225 This caused &foo to be of type ptr-to-const-function
7226 which then got a warning when stored in a ptr-to-function variable. */
7228 poplevel (1, 0, 1);
7229 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
7231 /* Must mark the RESULT_DECL as being in this function. */
7233 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
7235 /* Obey `register' declarations if `setjmp' is called in this fn. */
7236 if (flag_traditional && current_function_calls_setjmp)
7238 setjmp_protect (DECL_INITIAL (fndecl));
7239 setjmp_protect_args ();
7242 if (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main"))
7244 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
7245 != integer_type_node)
7247 /* You would expect the sense of this test to be the other way
7248 around, but if warn_main is set, we will already have warned,
7249 so this would be a duplicate. This is the warning you get
7250 in some environments even if you *don't* ask for it, because
7251 these are environments where it may be more of a problem than
7252 usual. */
7253 if (! warn_main)
7254 pedwarn_with_decl (fndecl, "return type of `%s' is not `int'");
7256 else
7258 #ifdef DEFAULT_MAIN_RETURN
7259 /* Make it so that `main' always returns success by default. */
7260 DEFAULT_MAIN_RETURN;
7261 #endif
7265 /* Generate rtl for function exit. */
7266 expand_function_end (input_filename, lineno, 0);
7268 /* So we can tell if jump_optimize sets it to 1. */
7269 can_reach_end = 0;
7271 /* Run the optimizers and output the assembler code for this function. */
7272 rest_of_compilation (fndecl);
7274 current_function_returns_null |= can_reach_end;
7276 if (warn_missing_noreturn
7277 && !TREE_THIS_VOLATILE (fndecl)
7278 && !current_function_returns_null
7279 && !current_function_returns_value)
7280 warning ("function might be possible candidate for attribute `noreturn'");
7282 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
7283 warning ("`noreturn' function does return");
7284 else if (warn_return_type && can_reach_end
7285 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != void_type_node)
7286 /* If this function returns non-void and control can drop through,
7287 complain. */
7288 warning ("control reaches end of non-void function");
7289 /* With just -W, complain only if function returns both with
7290 and without a value. */
7291 else if (extra_warnings
7292 && current_function_returns_value && current_function_returns_null)
7293 warning ("this function may return with or without a value");
7295 /* If requested, warn about function definitions where the function will
7296 return a value (usually of some struct or union type) which itself will
7297 take up a lot of stack space. */
7299 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
7301 register tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
7303 if (ret_type)
7305 register tree ret_type_size = TYPE_SIZE (ret_type);
7307 if (TREE_CODE (ret_type_size) == INTEGER_CST)
7309 unsigned units
7310 = TREE_INT_CST_LOW (ret_type_size) / BITS_PER_UNIT;
7312 if (units > larger_than_size)
7313 warning_with_decl (fndecl,
7314 "size of return value of `%s' is %u bytes",
7315 units);
7320 /* Free all the tree nodes making up this function. */
7321 /* Switch back to allocating nodes permanently
7322 until we start another function. */
7323 if (! nested)
7324 permanent_allocation (1);
7326 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested)
7328 /* Stop pointing to the local nodes about to be freed. */
7329 /* But DECL_INITIAL must remain nonzero so we know this
7330 was an actual function definition. */
7331 /* For a nested function, this is done in pop_c_function_context. */
7332 /* If rest_of_compilation set this to 0, leave it 0. */
7333 if (DECL_INITIAL (fndecl) != 0)
7334 DECL_INITIAL (fndecl) = error_mark_node;
7335 DECL_ARGUMENTS (fndecl) = 0;
7338 if (DECL_STATIC_CONSTRUCTOR (fndecl))
7340 #ifndef ASM_OUTPUT_CONSTRUCTOR
7341 if (! flag_gnu_linker)
7342 static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
7343 else
7344 #endif
7345 assemble_constructor (IDENTIFIER_POINTER (DECL_NAME (fndecl)));
7347 if (DECL_STATIC_DESTRUCTOR (fndecl))
7349 #ifndef ASM_OUTPUT_DESTRUCTOR
7350 if (! flag_gnu_linker)
7351 static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
7352 else
7353 #endif
7354 assemble_destructor (IDENTIFIER_POINTER (DECL_NAME (fndecl)));
7357 if (! nested)
7359 /* Let the error reporting routines know that we're outside a
7360 function. For a nested function, this value is used in
7361 pop_c_function_context and then reset via pop_function_context. */
7362 current_function_decl = NULL;
7366 /* Save and restore the variables in this file and elsewhere
7367 that keep track of the progress of compilation of the current function.
7368 Used for nested functions. */
7370 struct c_function
7372 struct c_function *next;
7373 tree named_labels;
7374 tree shadowed_labels;
7375 int returns_value;
7376 int returns_null;
7377 int warn_about_return_type;
7378 int extern_inline;
7379 struct binding_level *binding_level;
7382 struct c_function *c_function_chain;
7384 /* Save and reinitialize the variables
7385 used during compilation of a C function. */
7387 void
7388 push_c_function_context ()
7390 struct c_function *p
7391 = (struct c_function *) xmalloc (sizeof (struct c_function));
7393 if (pedantic)
7394 pedwarn ("ANSI C forbids nested functions");
7396 push_function_context ();
7398 p->next = c_function_chain;
7399 c_function_chain = p;
7401 p->named_labels = named_labels;
7402 p->shadowed_labels = shadowed_labels;
7403 p->returns_value = current_function_returns_value;
7404 p->returns_null = current_function_returns_null;
7405 p->warn_about_return_type = warn_about_return_type;
7406 p->extern_inline = current_extern_inline;
7407 p->binding_level = current_binding_level;
7410 /* Restore the variables used during compilation of a C function. */
7412 void
7413 pop_c_function_context ()
7415 struct c_function *p = c_function_chain;
7416 tree link;
7418 /* Bring back all the labels that were shadowed. */
7419 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
7420 if (DECL_NAME (TREE_VALUE (link)) != 0)
7421 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
7422 = TREE_VALUE (link);
7424 if (DECL_SAVED_INSNS (current_function_decl) == 0)
7426 /* Stop pointing to the local nodes about to be freed. */
7427 /* But DECL_INITIAL must remain nonzero so we know this
7428 was an actual function definition. */
7429 DECL_INITIAL (current_function_decl) = error_mark_node;
7430 DECL_ARGUMENTS (current_function_decl) = 0;
7433 pop_function_context ();
7435 c_function_chain = p->next;
7437 named_labels = p->named_labels;
7438 shadowed_labels = p->shadowed_labels;
7439 current_function_returns_value = p->returns_value;
7440 current_function_returns_null = p->returns_null;
7441 warn_about_return_type = p->warn_about_return_type;
7442 current_extern_inline = p->extern_inline;
7443 current_binding_level = p->binding_level;
7445 free (p);
7448 /* integrate_decl_tree calls this function, but since we don't use the
7449 DECL_LANG_SPECIFIC field, this is a no-op. */
7451 void
7452 copy_lang_decl (node)
7453 tree node ATTRIBUTE_UNUSED;