1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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. */
33 #include "tree-inline.h"
50 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
52 { NORMAL, /* Ordinary declaration */
53 FUNCDEF, /* Function definition */
54 PARM, /* Declaration of parm before function body */
55 FIELD, /* Declaration inside struct or union */
56 BITFIELD, /* Likewise but with specified width */
57 TYPENAME}; /* Typename (inside cast or sizeof) */
60 /* Nonzero if we have seen an invalid cross reference
61 to a struct, union, or enum, but not yet printed the message. */
63 tree pending_invalid_xref;
64 /* File and line to appear in the eventual error message. */
65 const char *pending_invalid_xref_file;
66 int pending_invalid_xref_line;
68 /* While defining an enum type, this is 1 plus the last enumerator
69 constant value. Note that will do not have to save this or `enum_overflow'
70 around nested function definition since such a definition could only
71 occur in an enum value expression and we don't use these variables in
74 static tree enum_next_value;
76 /* Nonzero means that there was overflow computing enum_next_value. */
78 static int enum_overflow;
80 /* Parsing a function declarator leaves a list of parameter names
81 or a chain or parameter decls here. */
83 static tree last_function_parms;
85 /* Parsing a function declarator leaves here a chain of structure
86 and enum types declared in the parmlist. */
88 static tree last_function_parm_tags;
90 /* After parsing the declarator that starts a function definition,
91 `start_function' puts here the list of parameter names or chain of decls.
92 `store_parm_decls' finds it here. */
94 static tree current_function_parms;
96 /* Similar, for last_function_parm_tags. */
97 static tree current_function_parm_tags;
99 /* Similar, for the file and line that the prototype came from if this is
100 an old-style definition. */
101 static const char *current_function_prototype_file;
102 static int current_function_prototype_line;
104 /* The current statement tree. */
106 static struct stmt_tree_s c_stmt_tree;
108 /* The current scope statement stack. */
110 static tree c_scope_stmt_stack;
112 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
113 that have names. Here so we can clear out their names' definitions
114 at the end of the function. */
116 static tree named_labels;
118 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
120 static tree shadowed_labels;
122 /* Nonzero when store_parm_decls is called indicates a varargs function.
123 Value not meaningful after store_parm_decls. */
125 static int c_function_varargs;
127 /* Set to 0 at beginning of a function definition, set to 1 if
128 a return statement that specifies a return value is seen. */
130 int current_function_returns_value;
132 /* Set to 0 at beginning of a function definition, set to 1 if
133 a return statement with no argument is seen. */
135 int current_function_returns_null;
137 /* Set to 0 at beginning of a function definition, set to 1 if
138 a call to a noreturn function is seen. */
140 int current_function_returns_abnormally;
142 /* Set to nonzero by `grokdeclarator' for a function
143 whose return type is defaulted, if warnings for this are desired. */
145 static int warn_about_return_type;
147 /* Nonzero when starting a function declared `extern inline'. */
149 static int current_extern_inline;
151 /* For each binding contour we allocate a binding_level structure
152 * which records the names defined in that contour.
155 * 1) one for each function definition,
156 * where internal declarations of the parameters appear.
157 * 2) one for each compound statement,
158 * to record its declarations.
160 * The current meaning of a name can be found by searching the levels from
161 * the current one out to the global one.
164 /* Note that the information in the `names' component of the global contour
165 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
169 /* A chain of _DECL nodes for all variables, constants, functions,
170 and typedef types. These are in the reverse of the order supplied.
174 /* A list of structure, union and enum definitions,
175 * for looking up tag names.
176 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
177 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
178 * or ENUMERAL_TYPE node.
182 /* For each level, a list of shadowed outer-level local definitions
183 to be restored when this level is popped.
184 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
185 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
188 /* For each level (except not the global one),
189 a chain of BLOCK nodes for all the levels
190 that were entered and exited one level down. */
193 /* The BLOCK node for this level, if one has been preallocated.
194 If 0, the BLOCK is allocated (if needed) when the level is popped. */
197 /* The binding level which this one is contained in (inherits from). */
198 struct binding_level *level_chain;
200 /* Nonzero for the level that holds the parameters of a function. */
203 /* Nonzero if this level "doesn't exist" for tags. */
204 char tag_transparent;
206 /* Nonzero if sublevels of this level "don't exist" for tags.
207 This is set in the parm level of a function definition
208 while reading the function body, so that the outermost block
209 of the function body will be tag-transparent. */
210 char subblocks_tag_transparent;
212 /* Nonzero means make a BLOCK for this level regardless of all else. */
215 /* Nonzero means make a BLOCK if this level has any subblocks. */
216 char keep_if_subblocks;
218 /* Number of decls in `names' that have incomplete
219 structure or union types. */
222 /* A list of decls giving the (reversed) specified order of parms,
223 not including any forward-decls in the parmlist.
224 This is so we can put the parms in proper order for assign_parms. */
228 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
230 /* The binding level currently in effect. */
232 static struct binding_level *current_binding_level;
234 /* A chain of binding_level structures awaiting reuse. */
236 static struct binding_level *free_binding_level;
238 /* The outermost binding level, for names of file scope.
239 This is created when the compiler is started and exists
240 through the entire run. */
242 static struct binding_level *global_binding_level;
244 /* Binding level structures are initialized by copying this one. */
246 static struct binding_level clear_binding_level
247 = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0,
250 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
252 static int keep_next_level_flag;
254 /* Nonzero means make a BLOCK for the next level pushed
255 if it has subblocks. */
257 static int keep_next_if_subblocks;
259 /* The chain of outer levels of label scopes.
260 This uses the same data structure used for binding levels,
261 but it works differently: each link in the chain records
262 saved values of named_labels and shadowed_labels for
263 a label binding level outside the current one. */
265 static struct binding_level *label_level_chain;
267 /* Functions called automatically at the beginning and end of execution. */
269 tree static_ctors, static_dtors;
271 /* Forward declarations. */
273 static struct binding_level * make_binding_level PARAMS ((void));
274 static void mark_binding_level PARAMS ((void *));
275 static void clear_limbo_values PARAMS ((tree));
276 static int duplicate_decls PARAMS ((tree, tree, int));
277 static int redeclaration_error_message PARAMS ((tree, tree));
278 static void storedecls PARAMS ((tree));
279 static void storetags PARAMS ((tree));
280 static tree lookup_tag PARAMS ((enum tree_code, tree,
281 struct binding_level *, int));
282 static tree lookup_tag_reverse PARAMS ((tree));
283 static tree grokdeclarator PARAMS ((tree, tree, enum decl_context,
285 static tree grokparms PARAMS ((tree, int));
286 static void layout_array_type PARAMS ((tree));
287 static tree c_make_fname_decl PARAMS ((tree, int));
288 static void c_expand_body PARAMS ((tree, int, int));
289 static void warn_if_shadowing PARAMS ((tree, tree));
291 /* C-specific option variables. */
293 /* Nonzero means allow type mismatches in conditional expressions;
294 just make their values `void'. */
296 int flag_cond_mismatch;
298 /* Nonzero means don't recognize the keyword `asm'. */
302 /* Nonzero means enable C89 Amendment 1 features. */
306 /* Nonzero means use the ISO C99 dialect of C. */
310 /* Nonzero means that we have builtin functions, and main is an int */
314 /* Nonzero means add default format_arg attributes for functions not
317 int flag_noniso_default_format_attributes = 1;
319 /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
321 int flag_signed_bitfields = 1;
322 int explicit_flag_signed_bitfields = 0;
324 /* Nonzero means warn about use of implicit int. */
326 int warn_implicit_int;
328 /* Nonzero means warn about usage of long long when `-pedantic'. */
330 int warn_long_long = 1;
332 /* Nonzero means message about use of implicit function declarations;
333 1 means warning; 2 means error. */
335 int mesg_implicit_function_declaration = -1;
337 /* Nonzero means give string constants the type `const char *'
338 to get extra warnings from them. These warnings will be too numerous
339 to be useful, except in thoroughly ANSIfied programs. */
341 int flag_const_strings;
343 /* Nonzero means warn about pointer casts that can drop a type qualifier
344 from the pointer target type. */
348 /* Nonzero means warn when casting a function call to a type that does
349 not match the return type (e.g. (float)sqrt() or (anything*)malloc()
350 when there is no previous declaration of sqrt or malloc. */
352 int warn_bad_function_cast;
354 /* Warn about functions which might be candidates for format attributes. */
356 int warn_missing_format_attribute;
358 /* Warn about traditional constructs whose meanings changed in ANSI C. */
360 int warn_traditional;
362 /* Nonzero means warn about sizeof(function) or addition/subtraction
363 of function pointers. */
365 int warn_pointer_arith;
367 /* Nonzero means warn for non-prototype function decls
368 or non-prototyped defs without previous prototype. */
370 int warn_strict_prototypes;
372 /* Nonzero means warn for any global function def
373 without separate previous prototype decl. */
375 int warn_missing_prototypes;
377 /* Nonzero means warn for any global function def
378 without separate previous decl. */
380 int warn_missing_declarations;
382 /* Nonzero means warn about multiple (redundant) decls for the same single
383 variable or function. */
385 int warn_redundant_decls = 0;
387 /* Nonzero means warn about extern declarations of objects not at
388 file-scope level and about *all* declarations of functions (whether
389 extern or static) not at file-scope level. Note that we exclude
390 implicit function declarations. To get warnings about those, use
393 int warn_nested_externs = 0;
395 /* Warn about a subscript that has type char. */
397 int warn_char_subscripts = 0;
399 /* Warn if a type conversion is done that might have confusing results. */
403 /* Warn if adding () is suggested. */
405 int warn_parentheses;
407 /* Warn if initializer is not completely bracketed. */
409 int warn_missing_braces;
411 /* Warn if main is suspicious. */
415 /* Warn about #pragma directives that are not recognised. */
417 int warn_unknown_pragmas = 0; /* Tri state variable. */
419 /* Warn about comparison of signed and unsigned values.
420 If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */
422 int warn_sign_compare = -1;
424 /* Warn about testing equality of floating point numbers. */
426 int warn_float_equal = 0;
428 /* Nonzero means warn about use of multicharacter literals. */
430 int warn_multichar = 1;
432 /* Nonzero means `$' can be in an identifier. */
434 #ifndef DOLLARS_IN_IDENTIFIERS
435 #define DOLLARS_IN_IDENTIFIERS 1
437 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
439 /* States indicating how grokdeclarator() should handle declspecs marked
440 with __attribute__((deprecated)). An object declared as
441 __attribute__((deprecated)) suppresses warnings of uses of other
444 enum deprecated_states {
449 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
451 /* Decode the string P as a language-specific option for C.
452 Return the number of strings consumed. Should not complain
453 if it does not recognise the option. */
456 c_decode_option (argc, argv)
457 int argc ATTRIBUTE_UNUSED;
460 int strings_processed;
463 static const struct {
464 /* The name of the option. */
466 /* If non-NULL, a flag variable to set to 0 or 1. If NULL,
467 this means that cpp handles this option. */
470 /* This list is in alphabetical order. Keep it like that. */
471 { "bad-function-cast", &warn_bad_function_cast },
472 { "cast-qual", &warn_cast_qual },
473 { "char-subscripts", &warn_char_subscripts },
475 { "comments", NULL },
476 { "conversion", &warn_conversion },
477 { "div-by-zero", &warn_div_by_zero },
478 { "float-equal", &warn_float_equal },
479 { "format-extra-args", &warn_format_extra_args },
480 { "format-nonliteral", &warn_format_nonliteral },
481 { "format-security", &warn_format_security },
482 { "format-y2k", &warn_format_y2k },
483 { "implicit-function-declaration", &mesg_implicit_function_declaration },
484 { "implicit-int", &warn_implicit_int },
486 { "long-long", &warn_long_long },
487 { "main", &warn_main },
488 { "missing-braces", &warn_missing_braces },
489 { "missing-declarations", &warn_missing_declarations },
490 { "missing-format-attribute", &warn_missing_format_attribute },
491 { "missing-prototypes", &warn_missing_prototypes },
492 { "multichar", &warn_multichar },
493 { "nested-externs", &warn_nested_externs },
494 { "parentheses", &warn_parentheses },
495 { "pointer-arith", &warn_pointer_arith },
496 { "redundant-decls", &warn_redundant_decls },
497 { "return-type", &warn_return_type },
498 { "sequence-point", &warn_sequence_point },
499 { "sign-compare", &warn_sign_compare },
500 { "strict-prototypes", &warn_strict_prototypes },
501 { "traditional", &warn_traditional },
502 { "trigraphs", NULL },
504 { "write-strings", &flag_const_strings }
507 strings_processed = cpp_handle_option (parse_in, argc, argv, 0);
509 if (!strcmp (p, "-fhosted") || !strcmp (p, "-fno-freestanding"))
514 else if (!strcmp (p, "-ffreestanding") || !strcmp (p, "-fno-hosted"))
518 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
522 else if (!strncmp (p, "-std=", 5))
524 /* Select the appropriate language standard. We currently
526 -std=iso9899:1990 same as -ansi
527 -std=iso9899:199409 ISO C as modified in amend. 1
528 -std=iso9899:1999 ISO C 99
529 -std=c89 same as -std=iso9899:1990
530 -std=c99 same as -std=iso9899:1999
531 -std=gnu89 default, iso9899:1990 + gnu extensions
532 -std=gnu99 iso9899:1999 + gnu extensions
534 const char *const argstart = &p[5];
536 if (!strcmp (argstart, "iso9899:1990")
537 || !strcmp (argstart, "c89"))
542 flag_writable_strings = 0;
544 flag_no_nonansi_builtin = 1;
545 flag_noniso_default_format_attributes = 0;
548 else if (!strcmp (argstart, "iso9899:199409"))
553 else if (!strcmp (argstart, "iso9899:199x")
554 || !strcmp (argstart, "iso9899:1999")
555 || !strcmp (argstart, "c9x")
556 || !strcmp (argstart, "c99"))
558 flag_writable_strings = 0;
560 flag_no_nonansi_builtin = 1;
561 flag_noniso_default_format_attributes = 0;
565 else if (!strcmp (argstart, "gnu89"))
567 flag_writable_strings = 0;
569 flag_no_nonansi_builtin = 0;
570 flag_noniso_default_format_attributes = 1;
574 else if (!strcmp (argstart, "gnu9x") || !strcmp (argstart, "gnu99"))
576 flag_writable_strings = 0;
578 flag_no_nonansi_builtin = 0;
579 flag_noniso_default_format_attributes = 1;
584 error ("unknown C standard `%s'", argstart);
586 else if (!strcmp (p, "-fdollars-in-identifiers"))
587 dollars_in_ident = 1;
588 else if (!strcmp (p, "-fno-dollars-in-identifiers"))
589 dollars_in_ident = 0;
590 else if (!strcmp (p, "-fsigned-char"))
591 flag_signed_char = 1;
592 else if (!strcmp (p, "-funsigned-char"))
593 flag_signed_char = 0;
594 else if (!strcmp (p, "-fno-signed-char"))
595 flag_signed_char = 0;
596 else if (!strcmp (p, "-fno-unsigned-char"))
597 flag_signed_char = 1;
598 else if (!strcmp (p, "-fsigned-bitfields")
599 || !strcmp (p, "-fno-unsigned-bitfields"))
601 flag_signed_bitfields = 1;
602 explicit_flag_signed_bitfields = 1;
604 else if (!strcmp (p, "-funsigned-bitfields")
605 || !strcmp (p, "-fno-signed-bitfields"))
607 flag_signed_bitfields = 0;
608 explicit_flag_signed_bitfields = 1;
610 else if (!strcmp (p, "-fshort-enums"))
611 flag_short_enums = 1;
612 else if (!strcmp (p, "-fno-short-enums"))
613 flag_short_enums = 0;
614 else if (!strcmp (p, "-fshort-wchar"))
615 flag_short_wchar = 1;
616 else if (!strcmp (p, "-fno-short-wchar"))
617 flag_short_wchar = 0;
618 else if (!strcmp (p, "-fcond-mismatch"))
619 flag_cond_mismatch = 1;
620 else if (!strcmp (p, "-fno-cond-mismatch"))
621 flag_cond_mismatch = 0;
622 else if (!strcmp (p, "-fshort-double"))
623 flag_short_double = 1;
624 else if (!strcmp (p, "-fno-short-double"))
625 flag_short_double = 0;
626 else if (!strcmp (p, "-fasm"))
628 else if (!strcmp (p, "-fno-asm"))
630 else if (!strcmp (p, "-fbuiltin"))
632 else if (!strcmp (p, "-fno-builtin"))
634 else if (!strncmp (p, "-fno-builtin-", strlen ("-fno-builtin-")))
635 disable_builtin_function (p + strlen ("-fno-builtin-"));
636 else if (p[0] == '-' && p[1] == 'f' && dump_switch_p (p + 2))
638 else if (!strcmp (p, "-ansi"))
640 else if (!strcmp (p, "-Werror-implicit-function-declaration"))
641 mesg_implicit_function_declaration = 2;
642 else if (!strncmp (p, "-Wformat=", 9))
643 set_Wformat (atoi (p + 9));
644 else if (!strcmp (p, "-Wformat"))
646 else if (!strcmp (p, "-Wno-format"))
648 else if (!strcmp (p, "-Wimplicit"))
650 warn_implicit_int = 1;
651 if (mesg_implicit_function_declaration != 2)
652 mesg_implicit_function_declaration = 1;
654 else if (!strcmp (p, "-Wno-implicit"))
655 warn_implicit_int = 0, mesg_implicit_function_declaration = 0;
656 else if (!strcmp (p, "-Wno-main"))
658 else if (!strcmp (p, "-Wunknown-pragmas"))
659 /* Set to greater than 1, so that even unknown pragmas in system
660 headers will be warned about. */
661 warn_unknown_pragmas = 2;
662 else if (!strcmp (p, "-Wno-unknown-pragmas"))
663 warn_unknown_pragmas = 0;
664 else if (!strcmp (p, "-Wall"))
666 /* We save the value of warn_uninitialized, since if they put
667 -Wuninitialized on the command line, we need to generate a
668 warning about not using it without also specifying -O. */
669 if (warn_uninitialized != 1)
670 warn_uninitialized = 2;
671 warn_implicit_int = 1;
672 mesg_implicit_function_declaration = 1;
673 warn_return_type = 1;
677 warn_char_subscripts = 1;
678 warn_parentheses = 1;
679 warn_sequence_point = 1;
680 warn_missing_braces = 1;
681 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn
682 it off only if it's not explicit. */
684 /* Only warn about unknown pragmas that are not in system headers. */
685 warn_unknown_pragmas = 1;
690 for (i = 0; i < sizeof (warn_options) / sizeof (warn_options[0]); i++)
691 if (strncmp (p, "-W", 2) == 0
692 && warn_options[i].flag
693 && (strcmp (p+2, warn_options[i].option) == 0
694 || (strncmp (p+2, "no-", 3) == 0
695 && strcmp (p+5, warn_options[i].option) == 0)))
697 *(warn_options[i].flag) = strncmp (p+2, "no-", 3) != 0;
700 return strings_processed;
707 c_print_identifier (file, node, indent)
712 print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
713 print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
714 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
715 print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
716 print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
717 print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4);
718 if (C_IS_RESERVED_WORD (node))
720 tree rid = ridpointers[C_RID_CODE (node)];
721 indent_to (file, indent + 4);
722 fprintf (file, "rid ");
723 fprintf (file, HOST_PTR_PRINTF, (void *)rid);
724 fprintf (file, " \"%s\"", IDENTIFIER_POINTER (rid));
728 /* Hook called at end of compilation to assume 1 elt
729 for a top-level tentative array defn that wasn't complete before. */
732 finish_incomplete_decl (decl)
735 if (TREE_CODE (decl) == VAR_DECL)
737 tree type = TREE_TYPE (decl);
738 if (type != error_mark_node
739 && TREE_CODE (type) == ARRAY_TYPE
740 && ! DECL_EXTERNAL (decl)
741 && TYPE_DOMAIN (type) == 0)
743 warning_with_decl (decl, "array `%s' assumed to have one element");
745 complete_array_type (type, NULL_TREE, 1);
747 layout_decl (decl, 0);
752 /* Create a new `struct binding_level'. */
754 static struct binding_level *
755 make_binding_level ()
758 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
761 /* Nonzero if we are currently in the global binding level. */
766 return current_binding_level == global_binding_level;
772 keep_next_level_flag = 1;
775 /* Nonzero if the current level needs to have a BLOCK made. */
780 return ((current_binding_level->keep_if_subblocks
781 && current_binding_level->blocks != 0)
782 || current_binding_level->keep
783 || current_binding_level->names != 0
784 || (current_binding_level->tags != 0
785 && !current_binding_level->tag_transparent));
788 /* Identify this binding level as a level of parameters.
789 DEFINITION_FLAG is 1 for a definition, 0 for a declaration.
790 But it turns out there is no way to pass the right value for
791 DEFINITION_FLAG, so we ignore it. */
794 declare_parm_level (definition_flag)
795 int definition_flag ATTRIBUTE_UNUSED;
797 current_binding_level->parm_flag = 1;
800 /* Nonzero if currently making parm declarations. */
805 return current_binding_level->parm_flag;
808 /* Enter a new binding level.
809 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
810 not for that of tags. */
813 pushlevel (tag_transparent)
816 struct binding_level *newlevel = NULL_BINDING_LEVEL;
818 /* If this is the top level of a function,
819 just make sure that NAMED_LABELS is 0. */
821 if (current_binding_level == global_binding_level)
826 /* Reuse or create a struct for this binding level. */
828 if (free_binding_level)
830 newlevel = free_binding_level;
831 free_binding_level = free_binding_level->level_chain;
835 newlevel = make_binding_level ();
838 /* Add this level to the front of the chain (stack) of levels that
841 *newlevel = clear_binding_level;
842 newlevel->tag_transparent
844 || (current_binding_level
845 ? current_binding_level->subblocks_tag_transparent
847 newlevel->level_chain = current_binding_level;
848 current_binding_level = newlevel;
849 newlevel->keep = keep_next_level_flag;
850 keep_next_level_flag = 0;
851 newlevel->keep_if_subblocks = keep_next_if_subblocks;
852 keep_next_if_subblocks = 0;
855 /* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */
858 clear_limbo_values (block)
863 for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem))
864 if (DECL_NAME (tem) != 0)
865 IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0;
867 for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem))
868 clear_limbo_values (tem);
871 /* Exit a binding level.
872 Pop the level off, and restore the state of the identifier-decl mappings
873 that were in effect when this level was entered.
875 If KEEP is nonzero, this level had explicit declarations, so
876 and create a "block" (a BLOCK node) for the level
877 to record its declarations and subblocks for symbol table output.
879 If FUNCTIONBODY is nonzero, this level is the body of a function,
880 so create a block as if KEEP were set and also clear out all
883 If REVERSE is nonzero, reverse the order of decls before putting
884 them into the BLOCK. */
887 poplevel (keep, reverse, functionbody)
893 /* The chain of decls was accumulated in reverse order.
894 Put it into forward order, just for cleanliness. */
896 tree tags = current_binding_level->tags;
897 tree subblocks = current_binding_level->blocks;
900 int block_previously_created;
902 keep |= current_binding_level->keep;
904 /* This warning is turned off because it causes warnings for
905 declarations like `extern struct foo *x'. */
907 /* Warn about incomplete structure types in this level. */
908 for (link = tags; link; link = TREE_CHAIN (link))
909 if (!COMPLETE_TYPE_P (TREE_VALUE (link)))
911 tree type = TREE_VALUE (link);
912 tree type_name = TYPE_NAME (type);
913 char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE
915 : DECL_NAME (type_name));
916 switch (TREE_CODE (type))
919 error ("`struct %s' incomplete in scope ending here", id);
922 error ("`union %s' incomplete in scope ending here", id);
925 error ("`enum %s' incomplete in scope ending here", id);
931 /* Get the decls in the order they were written.
932 Usually current_binding_level->names is in reverse order.
933 But parameter decls were previously put in forward order. */
936 current_binding_level->names
937 = decls = nreverse (current_binding_level->names);
939 decls = current_binding_level->names;
941 /* Output any nested inline functions within this block
942 if they weren't already output. */
944 for (decl = decls; decl; decl = TREE_CHAIN (decl))
945 if (TREE_CODE (decl) == FUNCTION_DECL
946 && ! TREE_ASM_WRITTEN (decl)
947 && DECL_INITIAL (decl) != 0
948 && TREE_ADDRESSABLE (decl))
950 /* If this decl was copied from a file-scope decl
951 on account of a block-scope extern decl,
952 propagate TREE_ADDRESSABLE to the file-scope decl.
954 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
955 true, since then the decl goes through save_for_inline_copying. */
956 if (DECL_ABSTRACT_ORIGIN (decl) != 0
957 && DECL_ABSTRACT_ORIGIN (decl) != decl)
958 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
961 /* We used to warn about unused variables in expand_end_bindings,
962 i.e. while generating RTL. But in function-at-a-time mode we may
963 choose to never expand a function at all (e.g. auto inlining), so
964 we do this explicitly now. */
965 warn_about_unused_variables (getdecls ());
967 /* If there were any declarations or structure tags in that level,
968 or if this level is a function body,
969 create a BLOCK to record them for the life of this function. */
972 block_previously_created = (current_binding_level->this_block != 0);
973 if (block_previously_created)
974 block = current_binding_level->this_block;
975 else if (keep || functionbody
976 || (current_binding_level->keep_if_subblocks && subblocks != 0))
977 block = make_node (BLOCK);
980 BLOCK_VARS (block) = decls;
981 BLOCK_SUBBLOCKS (block) = subblocks;
984 /* In each subblock, record that this is its superior. */
986 for (link = subblocks; link; link = TREE_CHAIN (link))
987 BLOCK_SUPERCONTEXT (link) = block;
989 /* Clear out the meanings of the local variables of this level. */
991 for (link = decls; link; link = TREE_CHAIN (link))
993 if (DECL_NAME (link) != 0)
995 /* If the ident. was used or addressed via a local extern decl,
996 don't forget that fact. */
997 if (DECL_EXTERNAL (link))
999 if (TREE_USED (link))
1000 TREE_USED (DECL_NAME (link)) = 1;
1001 if (TREE_ADDRESSABLE (link))
1002 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1004 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
1008 /* Restore all name-meanings of the outer levels
1009 that were shadowed by this level. */
1011 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1012 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1014 /* If the level being exited is the top level of a function,
1015 check over all the labels, and clear out the current
1016 (function local) meanings of their names. */
1020 clear_limbo_values (block);
1022 /* If this is the top level block of a function,
1023 the vars are the function's parameters.
1024 Don't leave them in the BLOCK because they are
1025 found in the FUNCTION_DECL instead. */
1027 BLOCK_VARS (block) = 0;
1029 /* Clear out the definitions of all label names,
1030 since their scopes end here,
1031 and add them to BLOCK_VARS. */
1033 for (link = named_labels; link; link = TREE_CHAIN (link))
1035 tree label = TREE_VALUE (link);
1037 if (DECL_INITIAL (label) == 0)
1039 error_with_decl (label, "label `%s' used but not defined");
1040 /* Avoid crashing later. */
1041 define_label (input_filename, lineno,
1044 else if (warn_unused_label && !TREE_USED (label))
1045 warning_with_decl (label, "label `%s' defined but not used");
1046 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1048 /* Put the labels into the "variables" of the
1049 top-level block, so debugger can see them. */
1050 TREE_CHAIN (label) = BLOCK_VARS (block);
1051 BLOCK_VARS (block) = label;
1055 /* Pop the current level, and free the structure for reuse. */
1058 struct binding_level *level = current_binding_level;
1059 current_binding_level = current_binding_level->level_chain;
1061 level->level_chain = free_binding_level;
1062 free_binding_level = level;
1065 /* Dispose of the block that we just made inside some higher level. */
1067 DECL_INITIAL (current_function_decl) = block;
1070 if (!block_previously_created)
1071 current_binding_level->blocks
1072 = chainon (current_binding_level->blocks, block);
1074 /* If we did not make a block for the level just exited,
1075 any blocks made for inner levels
1076 (since they cannot be recorded as subblocks in that level)
1077 must be carried forward so they will later become subblocks
1078 of something else. */
1080 current_binding_level->blocks
1081 = chainon (current_binding_level->blocks, subblocks);
1083 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1084 binding contour so that they point to the appropriate construct, i.e.
1085 either to the current FUNCTION_DECL node, or else to the BLOCK node
1086 we just constructed.
1088 Note that for tagged types whose scope is just the formal parameter
1089 list for some function type specification, we can't properly set
1090 their TYPE_CONTEXTs here, because we don't have a pointer to the
1091 appropriate FUNCTION_TYPE node readily available to us. For those
1092 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1093 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1094 node which will represent the "scope" for these "parameter list local"
1098 for (link = tags; link; link = TREE_CHAIN (link))
1099 TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl;
1101 for (link = tags; link; link = TREE_CHAIN (link))
1102 TYPE_CONTEXT (TREE_VALUE (link)) = block;
1105 TREE_USED (block) = 1;
1110 /* Insert BLOCK at the end of the list of subblocks of the
1111 current binding level. This is used when a BIND_EXPR is expanded,
1112 to handle the BLOCK node inside the BIND_EXPR. */
1115 insert_block (block)
1118 TREE_USED (block) = 1;
1119 current_binding_level->blocks
1120 = chainon (current_binding_level->blocks, block);
1123 /* Set the BLOCK node for the innermost scope
1124 (the one we are currently in). */
1130 current_binding_level->this_block = block;
1131 current_binding_level->names = chainon (current_binding_level->names,
1132 BLOCK_VARS (block));
1133 current_binding_level->blocks = chainon (current_binding_level->blocks,
1134 BLOCK_SUBBLOCKS (block));
1140 struct binding_level *newlevel;
1142 /* Reuse or create a struct for this binding level. */
1144 if (free_binding_level)
1146 newlevel = free_binding_level;
1147 free_binding_level = free_binding_level->level_chain;
1151 newlevel = make_binding_level ();
1154 /* Add this level to the front of the chain (stack) of label levels. */
1156 newlevel->level_chain = label_level_chain;
1157 label_level_chain = newlevel;
1159 newlevel->names = named_labels;
1160 newlevel->shadowed = shadowed_labels;
1162 shadowed_labels = 0;
1168 struct binding_level *level = label_level_chain;
1171 /* Clear out the definitions of the declared labels in this level.
1172 Leave in the list any ordinary, non-declared labels. */
1173 for (link = named_labels, prev = 0; link;)
1175 if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
1177 if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
1179 error_with_decl (TREE_VALUE (link),
1180 "label `%s' used but not defined");
1181 /* Avoid crashing later. */
1182 define_label (input_filename, lineno,
1183 DECL_NAME (TREE_VALUE (link)));
1185 else if (warn_unused_label && !TREE_USED (TREE_VALUE (link)))
1186 warning_with_decl (TREE_VALUE (link),
1187 "label `%s' defined but not used");
1188 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
1190 /* Delete this element from the list. */
1191 link = TREE_CHAIN (link);
1193 TREE_CHAIN (prev) = link;
1195 named_labels = link;
1200 link = TREE_CHAIN (link);
1204 /* Bring back all the labels that were shadowed. */
1205 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
1206 if (DECL_NAME (TREE_VALUE (link)) != 0)
1207 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
1208 = TREE_VALUE (link);
1210 named_labels = chainon (named_labels, level->names);
1211 shadowed_labels = level->shadowed;
1213 /* Pop the current level, and free the structure for reuse. */
1214 label_level_chain = label_level_chain->level_chain;
1215 level->level_chain = free_binding_level;
1216 free_binding_level = level;
1219 /* Push a definition or a declaration of struct, union or enum tag "name".
1220 "type" should be the type node.
1221 We assume that the tag "name" is not already defined.
1223 Note that the definition may really be just a forward reference.
1224 In that case, the TYPE_SIZE will be zero. */
1227 pushtag (name, type)
1230 struct binding_level *b;
1232 /* Find the proper binding level for this type tag. */
1234 for (b = current_binding_level; b->tag_transparent; b = b->level_chain)
1239 /* Record the identifier as the type's name if it has none. */
1241 if (TYPE_NAME (type) == 0)
1242 TYPE_NAME (type) = name;
1245 b->tags = tree_cons (name, type, b->tags);
1247 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1248 tagged type we just added to the current binding level. This fake
1249 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1250 to output a representation of a tagged type, and it also gives
1251 us a convenient place to record the "scope start" address for the
1254 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
1256 /* An approximation for now, so we can tell this is a function-scope tag.
1257 This will be updated in poplevel. */
1258 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1261 /* Handle when a new declaration NEWDECL
1262 has the same name as an old one OLDDECL
1263 in the same binding contour.
1264 Prints an error message if appropriate.
1266 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
1267 Otherwise, return 0.
1269 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration,
1270 and OLDDECL is in an outer binding level and should thus not be changed. */
1273 duplicate_decls (newdecl, olddecl, different_binding_level)
1274 tree newdecl, olddecl;
1275 int different_binding_level;
1277 int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1278 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1279 && DECL_INITIAL (newdecl) != 0);
1280 tree oldtype = TREE_TYPE (olddecl);
1281 tree newtype = TREE_TYPE (newdecl);
1284 if (DECL_P (olddecl))
1286 if (TREE_CODE (newdecl) == FUNCTION_DECL
1287 && TREE_CODE (olddecl) == FUNCTION_DECL
1288 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
1290 if (DECL_DECLARED_INLINE_P (newdecl)
1291 && DECL_UNINLINABLE (newdecl)
1292 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1293 /* Already warned elsewhere. */;
1294 else if (DECL_DECLARED_INLINE_P (olddecl)
1295 && DECL_UNINLINABLE (olddecl)
1296 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1297 /* Already warned. */;
1298 else if (DECL_DECLARED_INLINE_P (newdecl)
1299 && ! DECL_DECLARED_INLINE_P (olddecl)
1300 && DECL_UNINLINABLE (olddecl)
1301 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1303 warning_with_decl (newdecl,
1304 "function `%s' redeclared as inline");
1305 warning_with_decl (olddecl,
1306 "previous declaration of function `%s' with attribute noinline");
1308 else if (DECL_DECLARED_INLINE_P (olddecl)
1309 && DECL_UNINLINABLE (newdecl)
1310 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1312 warning_with_decl (newdecl,
1313 "function `%s' redeclared with attribute noinline");
1314 warning_with_decl (olddecl,
1315 "previous declaration of function `%s' was inline");
1319 DECL_ATTRIBUTES (newdecl)
1320 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
1323 if (TREE_CODE (newtype) == ERROR_MARK
1324 || TREE_CODE (oldtype) == ERROR_MARK)
1327 /* New decl is completely inconsistent with the old one =>
1328 tell caller to replace the old one.
1329 This is always an error except in the case of shadowing a builtin. */
1330 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1332 if (TREE_CODE (olddecl) == FUNCTION_DECL
1333 && (DECL_BUILT_IN (olddecl)
1334 || DECL_BUILT_IN_NONANSI (olddecl)))
1336 /* If you declare a built-in or predefined function name as static,
1337 the old definition is overridden,
1338 but optionally warn this was a bad choice of name. */
1339 if (!TREE_PUBLIC (newdecl))
1343 else if (DECL_BUILT_IN (olddecl))
1344 warning_with_decl (newdecl, "shadowing built-in function `%s'");
1346 warning_with_decl (newdecl, "shadowing library function `%s'");
1348 /* Likewise, if the built-in is not ansi, then programs can
1349 override it even globally without an error. */
1350 else if (! DECL_BUILT_IN (olddecl))
1351 warning_with_decl (newdecl,
1352 "library function `%s' declared as non-function");
1354 else if (DECL_BUILT_IN_NONANSI (olddecl))
1355 warning_with_decl (newdecl,
1356 "built-in function `%s' declared as non-function");
1358 warning_with_decl (newdecl,
1359 "built-in function `%s' declared as non-function");
1363 error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
1364 error_with_decl (olddecl, "previous declaration of `%s'");
1370 /* For real parm decl following a forward decl,
1371 return 1 so old decl will be reused. */
1372 if (types_match && TREE_CODE (newdecl) == PARM_DECL
1373 && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
1376 /* The new declaration is the same kind of object as the old one.
1377 The declarations may partially match. Print warnings if they don't
1378 match enough. Ultimately, copy most of the information from the new
1379 decl to the old one, and keep using the old one. */
1381 if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_BUILT_IN (olddecl))
1383 /* A function declaration for a built-in function. */
1384 if (!TREE_PUBLIC (newdecl))
1386 /* If you declare a built-in function name as static, the
1387 built-in definition is overridden,
1388 but optionally warn this was a bad choice of name. */
1390 warning_with_decl (newdecl, "shadowing built-in function `%s'");
1391 /* Discard the old built-in function. */
1394 else if (!types_match)
1396 /* Accept the return type of the new declaration if same modes. */
1397 tree oldreturntype = TREE_TYPE (oldtype);
1398 tree newreturntype = TREE_TYPE (newtype);
1400 if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
1402 /* Function types may be shared, so we can't just modify
1403 the return type of olddecl's function type. */
1405 = build_function_type (newreturntype,
1406 TYPE_ARG_TYPES (oldtype));
1407 trytype = build_type_attribute_variant (trytype,
1408 TYPE_ATTRIBUTES (oldtype));
1410 types_match = comptypes (newtype, trytype);
1414 /* Accept harmless mismatch in first argument type also.
1415 This is for the ffs and fprintf builtins. */
1416 if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0
1417 && TYPE_ARG_TYPES (oldtype) != 0
1418 && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0
1419 && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0
1420 && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype)))
1421 == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype)))))
1423 /* Function types may be shared, so we can't just modify
1424 the return type of olddecl's function type. */
1426 = build_function_type (TREE_TYPE (oldtype),
1427 tree_cons (NULL_TREE,
1428 TREE_VALUE (TYPE_ARG_TYPES (newtype)),
1429 TREE_CHAIN (TYPE_ARG_TYPES (oldtype))));
1430 trytype = build_type_attribute_variant (trytype,
1431 TYPE_ATTRIBUTES (oldtype));
1433 types_match = comptypes (newtype, trytype);
1437 if (! different_binding_level)
1438 TREE_TYPE (olddecl) = oldtype;
1440 else if (TYPE_ARG_TYPES (oldtype) == NULL
1441 && TYPE_ARG_TYPES (newtype) != NULL)
1443 /* For bcmp, bzero, fputs the builtin type has arguments not
1444 specified. Use the ones from the prototype so that type checking
1445 is done for them. */
1447 = build_function_type (TREE_TYPE (oldtype),
1448 TYPE_ARG_TYPES (newtype));
1449 trytype = build_type_attribute_variant (trytype,
1450 TYPE_ATTRIBUTES (oldtype));
1453 if (! different_binding_level)
1454 TREE_TYPE (olddecl) = oldtype;
1458 /* If types don't match for a built-in, throw away the built-in. */
1459 warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
1463 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1464 && DECL_SOURCE_LINE (olddecl) == 0)
1466 /* A function declaration for a predeclared function
1467 that isn't actually built in. */
1468 if (!TREE_PUBLIC (newdecl))
1470 /* If you declare it as static, the
1471 default definition is overridden. */
1474 else if (!types_match)
1476 /* If the types don't match, preserve volatility indication.
1477 Later on, we will discard everything else about the
1478 default declaration. */
1479 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1482 /* Permit char *foo () to match void *foo (...) if not pedantic,
1483 if one of them came from a system header file. */
1484 else if (!types_match
1485 && TREE_CODE (olddecl) == FUNCTION_DECL
1486 && TREE_CODE (newdecl) == FUNCTION_DECL
1487 && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
1488 && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
1489 && (DECL_IN_SYSTEM_HEADER (olddecl)
1490 || DECL_IN_SYSTEM_HEADER (newdecl))
1491 && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
1492 && TYPE_ARG_TYPES (oldtype) == 0
1493 && self_promoting_args_p (TYPE_ARG_TYPES (newtype))
1494 && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
1496 (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
1497 && TYPE_ARG_TYPES (newtype) == 0
1498 && self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
1499 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
1502 pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1503 /* Make sure we keep void * as ret type, not char *. */
1504 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
1505 TREE_TYPE (newdecl) = newtype = oldtype;
1507 /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration
1508 we will come back here again. */
1509 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1511 else if (!types_match
1512 /* Permit char *foo (int, ...); followed by char *foo ();
1514 && ! (TREE_CODE (olddecl) == FUNCTION_DECL
1516 /* Return types must still match. */
1517 && comptypes (TREE_TYPE (oldtype),
1518 TREE_TYPE (newtype))
1519 && TYPE_ARG_TYPES (newtype) == 0))
1521 error_with_decl (newdecl, "conflicting types for `%s'");
1522 /* Check for function type mismatch
1523 involving an empty arglist vs a nonempty one. */
1524 if (TREE_CODE (olddecl) == FUNCTION_DECL
1525 && comptypes (TREE_TYPE (oldtype),
1526 TREE_TYPE (newtype))
1527 && ((TYPE_ARG_TYPES (oldtype) == 0
1528 && DECL_INITIAL (olddecl) == 0)
1530 (TYPE_ARG_TYPES (newtype) == 0
1531 && DECL_INITIAL (newdecl) == 0)))
1533 /* Classify the problem further. */
1534 tree t = TYPE_ARG_TYPES (oldtype);
1536 t = TYPE_ARG_TYPES (newtype);
1537 for (; t; t = TREE_CHAIN (t))
1539 tree type = TREE_VALUE (t);
1541 if (TREE_CHAIN (t) == 0
1542 && TYPE_MAIN_VARIANT (type) != void_type_node)
1544 error ("a parameter list with an ellipsis can't match an empty parameter name list declaration");
1548 if (simple_type_promotes_to (type) != NULL_TREE)
1550 error ("an argument type that has a default promotion can't match an empty parameter name list declaration");
1555 error_with_decl (olddecl, "previous declaration of `%s'");
1559 errmsg = redeclaration_error_message (newdecl, olddecl);
1565 error_with_decl (newdecl, "redefinition of `%s'");
1568 error_with_decl (newdecl, "redeclaration of `%s'");
1571 error_with_decl (newdecl, "conflicting declarations of `%s'");
1577 error_with_decl (olddecl,
1578 ((DECL_INITIAL (olddecl)
1579 && current_binding_level == global_binding_level)
1580 ? "`%s' previously defined here"
1581 : "`%s' previously declared here"));
1584 else if (TREE_CODE (newdecl) == TYPE_DECL
1585 && (DECL_IN_SYSTEM_HEADER (olddecl)
1586 || DECL_IN_SYSTEM_HEADER (newdecl)))
1588 warning_with_decl (newdecl, "redefinition of `%s'");
1591 ((DECL_INITIAL (olddecl)
1592 && current_binding_level == global_binding_level)
1593 ? "`%s' previously defined here"
1594 : "`%s' previously declared here"));
1596 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1597 && DECL_INITIAL (olddecl) != 0
1598 && TYPE_ARG_TYPES (oldtype) == 0
1599 && TYPE_ARG_TYPES (newtype) != 0
1600 && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0)
1604 /* Prototype decl follows defn w/o prototype. */
1606 for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
1607 type = TYPE_ARG_TYPES (newtype),
1610 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
1612 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1613 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1615 warning_with_decl (newdecl, "prototype for `%s' follows");
1616 warning_with_decl (olddecl, "non-prototype definition here");
1619 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1620 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1622 error_with_decl (newdecl,
1623 "prototype for `%s' follows and number of arguments doesn't match");
1624 error_with_decl (olddecl, "non-prototype definition here");
1628 /* Type for passing arg must be consistent
1629 with that declared for the arg. */
1630 if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type)))
1632 error_with_decl (newdecl,
1633 "prototype for `%s' follows and argument %d doesn't match",
1635 error_with_decl (olddecl, "non-prototype definition here");
1641 /* Warn about mismatches in various flags. */
1644 /* Warn if function is now inline
1645 but was previously declared not inline and has been called. */
1646 if (TREE_CODE (olddecl) == FUNCTION_DECL
1647 && ! DECL_DECLARED_INLINE_P (olddecl)
1648 && DECL_DECLARED_INLINE_P (newdecl)
1649 && TREE_USED (olddecl))
1650 warning_with_decl (newdecl,
1651 "`%s' declared inline after being called");
1652 if (TREE_CODE (olddecl) == FUNCTION_DECL
1653 && ! DECL_DECLARED_INLINE_P (olddecl)
1654 && DECL_DECLARED_INLINE_P (newdecl)
1655 && DECL_INITIAL (olddecl) != 0)
1656 warning_with_decl (newdecl,
1657 "`%s' declared inline after its definition");
1659 /* If pedantic, warn when static declaration follows a non-static
1660 declaration. Otherwise, do so only for functions. */
1661 if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL)
1662 && TREE_PUBLIC (olddecl)
1663 && !TREE_PUBLIC (newdecl))
1664 warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
1666 /* If warn_traditional, warn when a non-static function
1667 declaration follows a static one. */
1668 if (warn_traditional && !in_system_header
1669 && TREE_CODE (olddecl) == FUNCTION_DECL
1670 && !TREE_PUBLIC (olddecl)
1671 && TREE_PUBLIC (newdecl))
1672 warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
1674 /* Warn when const declaration follows a non-const
1675 declaration, but not for functions. */
1676 if (TREE_CODE (olddecl) != FUNCTION_DECL
1677 && !TREE_READONLY (olddecl)
1678 && TREE_READONLY (newdecl))
1679 warning_with_decl (newdecl, "const declaration for `%s' follows non-const");
1680 /* These bits are logically part of the type, for variables.
1681 But not for functions
1682 (where qualifiers are not valid ANSI anyway). */
1683 else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
1684 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1685 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1686 pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1690 /* Optionally warn about more than one declaration for the same name. */
1691 if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
1692 /* Don't warn about a function declaration
1693 followed by a definition. */
1694 && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
1695 && DECL_INITIAL (olddecl) == 0)
1696 /* Don't warn about extern decl followed by (tentative) definition. */
1697 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
1699 warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
1700 warning_with_decl (olddecl, "previous declaration of `%s'");
1703 /* Copy all the DECL_... slots specified in the new decl
1704 except for any that we copy here from the old type.
1706 Past this point, we don't change OLDTYPE and NEWTYPE
1707 even if we change the types of NEWDECL and OLDDECL. */
1711 /* When copying info to olddecl, we store into write_olddecl
1712 instead. This allows us to avoid modifying olddecl when
1713 different_binding_level is true. */
1714 tree write_olddecl = different_binding_level ? newdecl : olddecl;
1716 /* Merge the data types specified in the two decls. */
1717 if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
1719 if (different_binding_level)
1721 if (TYPE_ARG_TYPES (oldtype) != 0
1722 && TYPE_ARG_TYPES (newtype) == 0)
1723 TREE_TYPE (newdecl) = common_type (newtype, oldtype);
1726 = build_type_attribute_variant
1728 merge_attributes (TYPE_ATTRIBUTES (newtype),
1729 TYPE_ATTRIBUTES (oldtype)));
1733 = TREE_TYPE (olddecl)
1734 = common_type (newtype, oldtype);
1737 /* Lay the type out, unless already done. */
1738 if (oldtype != TREE_TYPE (newdecl))
1740 if (TREE_TYPE (newdecl) != error_mark_node)
1741 layout_type (TREE_TYPE (newdecl));
1742 if (TREE_CODE (newdecl) != FUNCTION_DECL
1743 && TREE_CODE (newdecl) != TYPE_DECL
1744 && TREE_CODE (newdecl) != CONST_DECL)
1745 layout_decl (newdecl, 0);
1749 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1750 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1751 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
1752 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1753 if (TREE_CODE (olddecl) != FUNCTION_DECL)
1754 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1756 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1757 DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl);
1761 /* Keep the old rtl since we can safely use it. */
1762 COPY_DECL_RTL (olddecl, newdecl);
1764 /* Merge the type qualifiers. */
1765 if (TREE_CODE (olddecl) == FUNCTION_DECL
1766 && DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl)
1767 && ! TREE_THIS_VOLATILE (newdecl))
1768 TREE_THIS_VOLATILE (write_olddecl) = 0;
1770 if (TREE_READONLY (newdecl))
1771 TREE_READONLY (write_olddecl) = 1;
1773 if (TREE_THIS_VOLATILE (newdecl))
1775 TREE_THIS_VOLATILE (write_olddecl) = 1;
1776 if (TREE_CODE (newdecl) == VAR_DECL
1777 /* If an automatic variable is re-declared in the same
1778 function scope, but the old declaration was not
1779 volatile, make_var_volatile() would crash because the
1780 variable would have been assigned to a pseudo, not a
1781 MEM. Since this duplicate declaration is invalid
1782 anyway, we just skip the call. */
1784 make_var_volatile (newdecl);
1787 /* Keep source location of definition rather than declaration. */
1788 /* When called with different_binding_level set, keep the old
1789 information so that meaningful diagnostics can be given. */
1790 if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
1791 && ! different_binding_level)
1793 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
1794 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
1797 /* Merge the unused-warning information. */
1798 if (DECL_IN_SYSTEM_HEADER (olddecl))
1799 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1800 else if (DECL_IN_SYSTEM_HEADER (newdecl))
1801 DECL_IN_SYSTEM_HEADER (write_olddecl) = 1;
1803 /* Merge the initialization information. */
1804 /* When called with different_binding_level set, don't copy over
1805 DECL_INITIAL, so that we don't accidentally change function
1806 declarations into function definitions. */
1807 if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
1808 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1810 /* Merge the section attribute.
1811 We want to issue an error if the sections conflict but that must be
1812 done later in decl_attributes since we are called before attributes
1814 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1815 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1817 /* Copy the assembler name.
1818 Currently, it can only be defined in the prototype. */
1819 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
1821 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1823 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1824 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1825 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1826 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1827 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1830 /* If cannot merge, then use the new type and qualifiers,
1831 and don't preserve the old rtl. */
1832 else if (! different_binding_level)
1834 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1835 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1836 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1837 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1840 /* Merge the storage class information. */
1841 DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
1842 /* For functions, static overrides non-static. */
1843 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1845 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1846 /* This is since we don't automatically
1847 copy the attributes of NEWDECL into OLDDECL. */
1848 /* No need to worry about different_binding_level here because
1849 then TREE_PUBLIC (newdecl) was true. */
1850 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1851 /* If this clears `static', clear it in the identifier too. */
1852 if (! TREE_PUBLIC (olddecl))
1853 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1855 if (DECL_EXTERNAL (newdecl))
1857 if (! different_binding_level)
1859 /* Don't mess with these flags on local externs; they remain
1860 external even if there's a declaration at file scope which
1862 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
1863 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1865 /* An extern decl does not override previous storage class. */
1866 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1867 if (! DECL_EXTERNAL (newdecl))
1868 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1872 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1873 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1876 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1878 /* If we're redefining a function previously defined as extern
1879 inline, make sure we emit debug info for the inline before we
1880 throw it away, in case it was inlined into a function that hasn't
1881 been written out yet. */
1882 if (new_is_definition && DECL_INITIAL (olddecl) && TREE_USED (olddecl))
1884 (*debug_hooks->outlining_inline_function) (olddecl);
1886 /* The new defn must not be inline. */
1887 DECL_INLINE (newdecl) = 0;
1888 DECL_UNINLINABLE (newdecl) = 1;
1892 /* If either decl says `inline', this fn is inline,
1893 unless its definition was passed already. */
1894 if (DECL_DECLARED_INLINE_P (newdecl)
1895 || DECL_DECLARED_INLINE_P (olddecl))
1896 DECL_DECLARED_INLINE_P (newdecl) = 1;
1898 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1899 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1902 if (DECL_BUILT_IN (olddecl))
1904 /* Get rid of any built-in function if new arg types don't match it
1905 or if we have a function definition. */
1906 if (! types_match || new_is_definition)
1908 if (! different_binding_level)
1910 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1911 DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN;
1916 /* If redeclaring a builtin function, and not a definition,
1917 it stays built in. */
1918 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1919 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1923 /* Also preserve various other info from the definition. */
1924 if (! new_is_definition)
1926 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1927 /* When called with different_binding_level set, don't copy over
1928 DECL_INITIAL, so that we don't accidentally change function
1929 declarations into function definitions. */
1930 if (! different_binding_level)
1931 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1932 DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
1933 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1934 DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl);
1935 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
1937 /* Set DECL_INLINE on the declaration if we've got a body
1938 from which to instantiate. */
1939 if (DECL_INLINE (olddecl) && ! DECL_UNINLINABLE (newdecl))
1941 DECL_INLINE (newdecl) = 1;
1942 DECL_ABSTRACT_ORIGIN (newdecl)
1943 = (different_binding_level
1944 ? DECL_ORIGIN (olddecl)
1945 : DECL_ABSTRACT_ORIGIN (olddecl));
1950 /* If a previous declaration said inline, mark the
1951 definition as inlinable. */
1952 if (DECL_DECLARED_INLINE_P (newdecl)
1953 && ! DECL_UNINLINABLE (newdecl))
1954 DECL_INLINE (newdecl) = 1;
1957 if (different_binding_level)
1960 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1961 But preserve OLDDECL's DECL_UID. */
1963 unsigned olddecl_uid = DECL_UID (olddecl);
1965 memcpy ((char *) olddecl + sizeof (struct tree_common),
1966 (char *) newdecl + sizeof (struct tree_common),
1967 sizeof (struct tree_decl) - sizeof (struct tree_common));
1968 DECL_UID (olddecl) = olddecl_uid;
1971 /* NEWDECL contains the merged attribute lists.
1972 Update OLDDECL to be the same. */
1973 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
1978 /* Check whether decl-node X shadows an existing declaration.
1979 OLDLOCAL is the old IDENTIFIER_LOCAL_VALUE of the DECL_NAME of X,
1980 which might be a NULL_TREE. */
1982 warn_if_shadowing (x, oldlocal)
1987 if (DECL_EXTERNAL (x))
1990 name = DECL_NAME (x);
1992 /* Warn if shadowing an argument at the top level of the body. */
1994 /* This warning doesn't apply to the parms of a nested fcn. */
1995 && ! current_binding_level->parm_flag
1996 /* Check that this is one level down from the parms. */
1997 && current_binding_level->level_chain->parm_flag
1998 /* Check that the decl being shadowed
1999 comes from the parm level, one level up. */
2000 && chain_member (oldlocal, current_binding_level->level_chain->names))
2002 if (TREE_CODE (oldlocal) == PARM_DECL)
2003 pedwarn ("declaration of `%s' shadows a parameter",
2004 IDENTIFIER_POINTER (name));
2006 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
2007 IDENTIFIER_POINTER (name));
2009 /* Maybe warn if shadowing something else. */
2010 else if (warn_shadow
2011 /* No shadow warnings for internally generated vars. */
2012 && DECL_SOURCE_LINE (x) != 0
2013 /* No shadow warnings for vars made for inlining. */
2014 && ! DECL_FROM_INLINE (x))
2016 if (TREE_CODE (x) == PARM_DECL
2017 && current_binding_level->level_chain->parm_flag)
2018 /* Don't warn about the parm names in function declarator
2019 within a function declarator.
2020 It would be nice to avoid warning in any function
2021 declarator in a declaration, as opposed to a definition,
2022 but there is no way to tell it's not a definition. */
2026 if (TREE_CODE (oldlocal) == PARM_DECL)
2027 shadow_warning ("a parameter", name, oldlocal);
2029 shadow_warning ("a previous local", name, oldlocal);
2031 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
2032 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
2033 shadow_warning ("a global declaration", name,
2034 IDENTIFIER_GLOBAL_VALUE (name));
2038 /* Record a decl-node X as belonging to the current lexical scope.
2039 Check for errors (such as an incompatible declaration for the same
2040 name already seen in the same scope).
2042 Returns either X or an old decl for the same name.
2043 If an old decl is returned, it may have been smashed
2044 to agree with what X says. */
2051 tree name = DECL_NAME (x);
2052 struct binding_level *b = current_binding_level;
2054 /* Functions need the lang_decl data. */
2055 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x))
2056 DECL_LANG_SPECIFIC (x) = (struct lang_decl *)
2057 ggc_alloc_cleared (sizeof (struct lang_decl));
2059 DECL_CONTEXT (x) = current_function_decl;
2060 /* A local extern declaration for a function doesn't constitute nesting.
2061 A local auto declaration does, since it's a forward decl
2062 for a nested function coming later. */
2063 if ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
2064 && DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x))
2065 DECL_CONTEXT (x) = 0;
2069 int different_binding_level = 0;
2071 if (warn_nested_externs
2072 && DECL_EXTERNAL (x)
2073 && b != global_binding_level
2074 && x != IDENTIFIER_IMPLICIT_DECL (name)
2075 /* No error messages for __FUNCTION__ and __PRETTY_FUNCTION__. */
2076 && !DECL_IN_SYSTEM_HEADER (x))
2077 warning ("nested extern declaration of `%s'",
2078 IDENTIFIER_POINTER (name));
2080 t = lookup_name_current_level (name);
2081 if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
2083 t = IDENTIFIER_GLOBAL_VALUE (name);
2084 /* Type decls at global scope don't conflict with externs declared
2085 inside lexical blocks. */
2086 if (! t || TREE_CODE (t) == TYPE_DECL)
2087 /* If there's no visible global declaration, try for an
2089 t = IDENTIFIER_LIMBO_VALUE (name);
2090 different_binding_level = 1;
2092 if (t != 0 && t == error_mark_node)
2093 /* error_mark_node is 0 for a while during initialization! */
2096 error_with_decl (x, "`%s' used prior to declaration");
2099 /* If this decl is `static' and an implicit decl was seen previously,
2101 if (TREE_PUBLIC (name)
2102 /* Don't test for DECL_EXTERNAL, because grokdeclarator
2103 sets this for all functions. */
2104 && ! TREE_PUBLIC (x)
2105 && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level)
2106 /* We used to warn also for explicit extern followed by static,
2107 but sometimes you need to do it that way. */
2108 && IDENTIFIER_IMPLICIT_DECL (name) != 0)
2110 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2111 IDENTIFIER_POINTER (name));
2112 pedwarn_with_file_and_line
2113 (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)),
2114 DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)),
2115 "previous declaration of `%s'",
2116 IDENTIFIER_POINTER (name));
2117 TREE_THIS_VOLATILE (name) = 1;
2120 if (t != 0 && duplicate_decls (x, t, different_binding_level))
2122 if (TREE_CODE (t) == PARM_DECL)
2124 /* Don't allow more than one "real" duplicate
2125 of a forward parm decl. */
2126 TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x);
2132 /* If we are processing a typedef statement, generate a whole new
2133 ..._TYPE node (which will be just an variant of the existing
2134 ..._TYPE node with identical properties) and then install the
2135 TYPE_DECL node generated to represent the typedef name as the
2136 TYPE_NAME of this brand new (duplicate) ..._TYPE node.
2138 The whole point here is to end up with a situation where each
2139 and every ..._TYPE node the compiler creates will be uniquely
2140 associated with AT MOST one node representing a typedef name.
2141 This way, even though the compiler substitutes corresponding
2142 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
2143 early on, later parts of the compiler can always do the reverse
2144 translation and get back the corresponding typedef name. For
2147 typedef struct S MY_TYPE;
2150 Later parts of the compiler might only know that `object' was of
2151 type `struct S' if it were not for code just below. With this
2152 code however, later parts of the compiler see something like:
2154 struct S' == struct S
2155 typedef struct S' MY_TYPE;
2158 And they can then deduce (from the node for type struct S') that
2159 the original object declaration was:
2163 Being able to do this is important for proper support of protoize,
2164 and also for generating precise symbolic debugging information
2165 which takes full account of the programmer's (typedef) vocabulary.
2167 Obviously, we don't want to generate a duplicate ..._TYPE node if
2168 the TYPE_DECL node that we are now processing really represents a
2169 standard built-in type.
2171 Since all standard types are effectively declared at line zero
2172 in the source file, we can easily check to see if we are working
2173 on a standard type by checking the current value of lineno. */
2175 if (TREE_CODE (x) == TYPE_DECL)
2177 if (DECL_SOURCE_LINE (x) == 0)
2179 if (TYPE_NAME (TREE_TYPE (x)) == 0)
2180 TYPE_NAME (TREE_TYPE (x)) = x;
2182 else if (TREE_TYPE (x) != error_mark_node
2183 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
2185 tree tt = TREE_TYPE (x);
2186 DECL_ORIGINAL_TYPE (x) = tt;
2187 tt = build_type_copy (tt);
2189 TREE_USED (tt) = TREE_USED (x);
2194 /* Multiple external decls of the same identifier ought to match.
2195 We get warnings about inline functions where they are defined.
2196 Avoid duplicate warnings where they are used. */
2198 && ! (TREE_CODE (x) == FUNCTION_DECL && DECL_INLINE (x)))
2202 if (IDENTIFIER_LIMBO_VALUE (name) != 0)
2203 /* Decls in limbo are always extern, so no need to check that. */
2204 decl = IDENTIFIER_LIMBO_VALUE (name);
2208 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl))
2209 /* If old decl is built-in, we already warned if we should. */
2210 && !DECL_BUILT_IN (decl))
2212 pedwarn_with_decl (x,
2213 "type mismatch with previous external decl");
2214 pedwarn_with_decl (decl, "previous external decl of `%s'");
2218 /* If a function has had an implicit declaration, and then is defined,
2219 make sure they are compatible. */
2221 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2222 && IDENTIFIER_GLOBAL_VALUE (name) == 0
2223 && TREE_CODE (x) == FUNCTION_DECL
2224 && ! comptypes (TREE_TYPE (x),
2225 TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name))))
2227 warning_with_decl (x, "type mismatch with previous implicit declaration");
2228 warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name),
2229 "previous implicit declaration of `%s'");
2232 /* This name is new in its binding level.
2233 Install the new declaration and return it. */
2234 if (b == global_binding_level)
2236 /* Install a global value. */
2238 /* If the first global decl has external linkage,
2239 warn if we later see static one. */
2240 if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
2241 TREE_PUBLIC (name) = 1;
2243 IDENTIFIER_GLOBAL_VALUE (name) = x;
2245 /* We no longer care about any previous block level declarations. */
2246 IDENTIFIER_LIMBO_VALUE (name) = 0;
2248 /* Don't forget if the function was used via an implicit decl. */
2249 if (IDENTIFIER_IMPLICIT_DECL (name)
2250 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2251 TREE_USED (x) = 1, TREE_USED (name) = 1;
2253 /* Don't forget if its address was taken in that way. */
2254 if (IDENTIFIER_IMPLICIT_DECL (name)
2255 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2256 TREE_ADDRESSABLE (x) = 1;
2258 /* Warn about mismatches against previous implicit decl. */
2259 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2260 /* If this real decl matches the implicit, don't complain. */
2261 && ! (TREE_CODE (x) == FUNCTION_DECL
2262 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x)))
2263 == integer_type_node)))
2264 pedwarn ("`%s' was previously implicitly declared to return `int'",
2265 IDENTIFIER_POINTER (name));
2267 /* If this decl is `static' and an `extern' was seen previously,
2268 that is erroneous. */
2269 if (TREE_PUBLIC (name)
2270 && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
2272 /* Okay to redeclare an ANSI built-in as static. */
2273 if (t != 0 && DECL_BUILT_IN (t))
2275 /* Okay to declare a non-ANSI built-in as anything. */
2276 else if (t != 0 && DECL_BUILT_IN_NONANSI (t))
2278 /* Okay to have global type decl after an earlier extern
2279 declaration inside a lexical block. */
2280 else if (TREE_CODE (x) == TYPE_DECL)
2282 else if (IDENTIFIER_IMPLICIT_DECL (name))
2284 if (! TREE_THIS_VOLATILE (name))
2285 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2286 IDENTIFIER_POINTER (name));
2289 pedwarn ("`%s' was declared `extern' and later `static'",
2290 IDENTIFIER_POINTER (name));
2295 /* Here to install a non-global value. */
2296 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2297 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2299 IDENTIFIER_LOCAL_VALUE (name) = x;
2301 /* If this is an extern function declaration, see if we
2302 have a global definition or declaration for the function. */
2305 && TREE_CODE (x) == FUNCTION_DECL
2306 && TREE_CODE (oldglobal) == FUNCTION_DECL
2307 && DECL_EXTERNAL (x)
2308 && ! DECL_DECLARED_INLINE_P (x))
2310 /* We have one. Their types must agree. */
2311 if (! comptypes (TREE_TYPE (x),
2312 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
2313 pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one");
2316 /* Inner extern decl is inline if global one is.
2317 Copy enough to really inline it. */
2318 if (DECL_DECLARED_INLINE_P (oldglobal))
2320 DECL_DECLARED_INLINE_P (x)
2321 = DECL_DECLARED_INLINE_P (oldglobal);
2322 DECL_INLINE (x) = DECL_INLINE (oldglobal);
2323 DECL_INITIAL (x) = (current_function_decl == oldglobal
2324 ? 0 : DECL_INITIAL (oldglobal));
2325 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2326 DECL_NUM_STMTS (x) = DECL_NUM_STMTS (oldglobal);
2327 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2328 DECL_RESULT (x) = DECL_RESULT (oldglobal);
2329 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2330 DECL_ABSTRACT_ORIGIN (x)
2331 = DECL_ABSTRACT_ORIGIN (oldglobal);
2333 /* Inner extern decl is built-in if global one is. */
2334 if (DECL_BUILT_IN (oldglobal))
2336 DECL_BUILT_IN_CLASS (x) = DECL_BUILT_IN_CLASS (oldglobal);
2337 DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
2339 /* Keep the arg types from a file-scope fcn defn. */
2340 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
2341 && DECL_INITIAL (oldglobal)
2342 && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
2343 TREE_TYPE (x) = TREE_TYPE (oldglobal);
2348 /* This case is probably sometimes the right thing to do. */
2349 /* If we have a local external declaration,
2350 then any file-scope declaration should not
2351 have been static. */
2352 if (oldlocal == 0 && oldglobal != 0
2353 && !TREE_PUBLIC (oldglobal)
2354 && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
2355 warning ("`%s' locally external but globally static",
2356 IDENTIFIER_POINTER (name));
2359 /* If we have a local external declaration,
2360 and no file-scope declaration has yet been seen,
2361 then if we later have a file-scope decl it must not be static. */
2363 && DECL_EXTERNAL (x)
2367 TREE_PUBLIC (name) = 1;
2369 /* Save this decl, so that we can do type checking against
2370 other decls after it falls out of scope.
2372 Only save it once. This prevents temporary decls created in
2373 expand_inline_function from being used here, since this
2374 will have been set when the inline function was parsed.
2375 It also helps give slightly better warnings. */
2376 if (IDENTIFIER_LIMBO_VALUE (name) == 0)
2377 IDENTIFIER_LIMBO_VALUE (name) = x;
2380 warn_if_shadowing (x, oldlocal);
2382 /* If storing a local value, there may already be one (inherited).
2383 If so, record it for restoration when this binding level ends. */
2385 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2388 /* Keep count of variables in this level with incomplete type.
2389 If the input is erroneous, we can have error_mark in the type
2390 slot (e.g. "f(void a, ...)") - that doesn't count as an
2392 if (TREE_TYPE (x) != error_mark_node
2393 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
2395 tree element = TREE_TYPE (x);
2397 while (TREE_CODE (element) == ARRAY_TYPE)
2398 element = TREE_TYPE (element);
2399 if (TREE_CODE (element) == RECORD_TYPE
2400 || TREE_CODE (element) == UNION_TYPE)
2405 /* Put decls on list in reverse order.
2406 We will reverse them later if necessary. */
2407 TREE_CHAIN (x) = b->names;
2413 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
2416 pushdecl_top_level (x)
2420 struct binding_level *b = current_binding_level;
2422 current_binding_level = global_binding_level;
2424 current_binding_level = b;
2428 /* Generate an implicit declaration for identifier FUNCTIONID
2429 as a function of type int (). Print a warning if appropriate. */
2432 implicitly_declare (functionid)
2436 int traditional_warning = 0;
2437 /* Only one "implicit declaration" warning per identifier. */
2438 int implicit_warning;
2440 /* We used to reuse an old implicit decl here,
2441 but this loses with inline functions because it can clobber
2442 the saved decl chains. */
2444 if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
2445 decl = IDENTIFIER_IMPLICIT_DECL (functionid);
2448 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2450 /* Warn of implicit decl following explicit local extern decl.
2451 This is probably a program designed for traditional C. */
2452 if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0)
2453 traditional_warning = 1;
2455 /* Warn once of an implicit declaration. */
2456 implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0);
2458 DECL_EXTERNAL (decl) = 1;
2459 TREE_PUBLIC (decl) = 1;
2461 /* Record that we have an implicit decl and this is it. */
2462 IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
2464 /* ANSI standard says implicit declarations are in the innermost block.
2465 So we record the decl in the standard fashion. */
2468 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
2469 maybe_objc_check_decl (decl);
2471 rest_of_decl_compilation (decl, NULL, 0, 0);
2473 if (implicit_warning)
2474 implicit_decl_warning (functionid);
2475 else if (warn_traditional && traditional_warning)
2476 warning ("function `%s' was previously declared within a block",
2477 IDENTIFIER_POINTER (functionid));
2479 /* Write a record describing this implicit function declaration to the
2480 prototypes file (if requested). */
2482 gen_aux_info_record (decl, 0, 1, 0);
2484 /* Possibly apply some default attributes to this implicit declaration. */
2485 decl_attributes (&decl, NULL_TREE, 0);
2491 implicit_decl_warning (id)
2494 const char *name = IDENTIFIER_POINTER (id);
2495 if (mesg_implicit_function_declaration == 2)
2496 error ("implicit declaration of function `%s'", name);
2497 else if (mesg_implicit_function_declaration == 1)
2498 warning ("implicit declaration of function `%s'", name);
2501 /* Return zero if the declaration NEWDECL is valid
2502 when the declaration OLDDECL (assumed to be for the same name)
2503 has already been seen.
2504 Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration,
2505 and 3 if it is a conflicting declaration. */
2508 redeclaration_error_message (newdecl, olddecl)
2509 tree newdecl, olddecl;
2511 if (TREE_CODE (newdecl) == TYPE_DECL)
2513 /* Do not complain about type redeclarations where at least one
2514 declaration was in a system header. */
2515 if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl))
2519 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2521 /* Declarations of functions can insist on internal linkage
2522 but they can't be inconsistent with internal linkage,
2523 so there can be no error on that account.
2524 However defining the same name twice is no good. */
2525 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
2526 /* However, defining once as extern inline and a second
2527 time in another way is ok. */
2528 && ! (DECL_DECLARED_INLINE_P (olddecl) && DECL_EXTERNAL (olddecl)
2529 && ! (DECL_DECLARED_INLINE_P (newdecl)
2530 && DECL_EXTERNAL (newdecl))))
2534 else if (DECL_CONTEXT (newdecl) == NULL_TREE)
2536 /* Objects declared at top level: */
2537 /* If at least one is a reference, it's ok. */
2538 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2540 /* Reject two definitions. */
2541 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
2543 /* Now we have two tentative defs, or one tentative and one real def. */
2544 /* Insist that the linkage match. */
2545 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
2549 else if (current_binding_level->parm_flag
2550 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2554 /* Newdecl has block scope. If olddecl has block scope also, then
2555 reject two definitions, and reject a definition together with an
2556 external reference. Otherwise, it is OK, because newdecl must
2557 be an extern reference to olddecl. */
2558 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))
2559 && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl))
2565 /* Get the LABEL_DECL corresponding to identifier ID as a label.
2566 Create one if none exists so far for the current function.
2567 This function is called for both label definitions and label references. */
2573 tree decl = IDENTIFIER_LABEL_VALUE (id);
2575 if (current_function_decl == 0)
2577 error ("label %s referenced outside of any function",
2578 IDENTIFIER_POINTER (id));
2582 /* Use a label already defined or ref'd with this name. */
2585 /* But not if it is inherited and wasn't declared to be inheritable. */
2586 if (DECL_CONTEXT (decl) != current_function_decl
2587 && ! C_DECLARED_LABEL_FLAG (decl))
2588 return shadow_label (id);
2592 decl = build_decl (LABEL_DECL, id, void_type_node);
2594 /* A label not explicitly declared must be local to where it's ref'd. */
2595 DECL_CONTEXT (decl) = current_function_decl;
2597 DECL_MODE (decl) = VOIDmode;
2599 /* Say where one reference is to the label,
2600 for the sake of the error if it is not defined. */
2601 DECL_SOURCE_LINE (decl) = lineno;
2602 DECL_SOURCE_FILE (decl) = input_filename;
2604 IDENTIFIER_LABEL_VALUE (id) = decl;
2606 named_labels = tree_cons (NULL_TREE, decl, named_labels);
2611 /* Make a label named NAME in the current function,
2612 shadowing silently any that may be inherited from containing functions
2613 or containing scopes.
2615 Note that valid use, if the label being shadowed
2616 comes from another scope in the same function,
2617 requires calling declare_nonlocal_label right away. */
2623 tree decl = IDENTIFIER_LABEL_VALUE (name);
2629 /* Check to make sure that the label hasn't already been declared
2630 at this label scope */
2631 for (dup = named_labels; dup; dup = TREE_CHAIN (dup))
2632 if (TREE_VALUE (dup) == decl)
2634 error ("duplicate label declaration `%s'",
2635 IDENTIFIER_POINTER (name));
2636 error_with_decl (TREE_VALUE (dup),
2637 "this is a previous declaration");
2638 /* Just use the previous declaration. */
2639 return lookup_label (name);
2642 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2643 IDENTIFIER_LABEL_VALUE (name) = decl = 0;
2646 return lookup_label (name);
2649 /* Define a label, specifying the location in the source file.
2650 Return the LABEL_DECL node for the label, if the definition is valid.
2651 Otherwise return 0. */
2654 define_label (filename, line, name)
2655 const char *filename;
2659 tree decl = lookup_label (name);
2661 /* If label with this name is known from an outer context, shadow it. */
2662 if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
2664 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2665 IDENTIFIER_LABEL_VALUE (name) = 0;
2666 decl = lookup_label (name);
2669 if (warn_traditional && !in_system_header && lookup_name (name))
2670 warning_with_file_and_line (filename, line,
2671 "traditional C lacks a separate namespace for labels, identifier `%s' conflicts",
2672 IDENTIFIER_POINTER (name));
2674 if (DECL_INITIAL (decl) != 0)
2676 error_with_file_and_line (filename, line, "duplicate label `%s'",
2677 IDENTIFIER_POINTER (name));
2682 /* Mark label as having been defined. */
2683 DECL_INITIAL (decl) = error_mark_node;
2684 /* Say where in the source. */
2685 DECL_SOURCE_FILE (decl) = filename;
2686 DECL_SOURCE_LINE (decl) = line;
2691 /* Return the list of declarations of the current level.
2692 Note that this list is in reverse order unless/until
2693 you nreverse it; and when you do nreverse it, you must
2694 store the result back using `storedecls' or you will lose. */
2699 return current_binding_level->names;
2702 /* Return the list of type-tags (for structs, etc) of the current level. */
2707 return current_binding_level->tags;
2710 /* Store the list of declarations of the current level.
2711 This is done for the parameter declarations of a function being defined,
2712 after they are modified in the light of any missing parameters. */
2718 current_binding_level->names = decls;
2721 /* Similarly, store the list of tags of the current level. */
2727 current_binding_level->tags = tags;
2730 /* Given NAME, an IDENTIFIER_NODE,
2731 return the structure (or union or enum) definition for that name.
2732 Searches binding levels from BINDING_LEVEL up to the global level.
2733 If THISLEVEL_ONLY is nonzero, searches only the specified context
2734 (but skips any tag-transparent contexts to find one that is
2735 meaningful for tags).
2736 CODE says which kind of type the caller wants;
2737 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2738 If the wrong kind of type is found, an error is reported. */
2741 lookup_tag (code, name, binding_level, thislevel_only)
2742 enum tree_code code;
2743 struct binding_level *binding_level;
2747 struct binding_level *level;
2750 for (level = binding_level; level; level = level->level_chain)
2753 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2755 if (TREE_PURPOSE (tail) == name)
2757 if (TREE_CODE (TREE_VALUE (tail)) != code)
2759 /* Definition isn't the kind we were looking for. */
2760 pending_invalid_xref = name;
2761 pending_invalid_xref_file = input_filename;
2762 pending_invalid_xref_line = lineno;
2763 /* If in the same binding level as a declaration as a tag
2764 of a different type, this must not be allowed to
2765 shadow that tag, so give the error immediately.
2766 (For example, "struct foo; union foo;" is invalid.) */
2768 pending_xref_error ();
2770 return TREE_VALUE (tail);
2773 if (! level->tag_transparent)
2783 /* Print an error message now
2784 for a recent invalid struct, union or enum cross reference.
2785 We don't print them immediately because they are not invalid
2786 when used in the `struct foo;' construct for shadowing. */
2789 pending_xref_error ()
2791 if (pending_invalid_xref != 0)
2792 error_with_file_and_line (pending_invalid_xref_file,
2793 pending_invalid_xref_line,
2794 "`%s' defined as wrong kind of tag",
2795 IDENTIFIER_POINTER (pending_invalid_xref));
2796 pending_invalid_xref = 0;
2799 /* Given a type, find the tag that was defined for it and return the tag name.
2800 Otherwise return 0. */
2803 lookup_tag_reverse (type)
2806 struct binding_level *level;
2808 for (level = current_binding_level; level; level = level->level_chain)
2811 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2813 if (TREE_VALUE (tail) == type)
2814 return TREE_PURPOSE (tail);
2820 /* Look up NAME in the current binding level and its superiors
2821 in the namespace of variables, functions and typedefs.
2822 Return a ..._DECL node of some kind representing its definition,
2823 or return 0 if it is undefined. */
2831 if (current_binding_level != global_binding_level
2832 && IDENTIFIER_LOCAL_VALUE (name))
2833 val = IDENTIFIER_LOCAL_VALUE (name);
2835 val = IDENTIFIER_GLOBAL_VALUE (name);
2839 /* Similar to `lookup_name' but look only at current binding level. */
2842 lookup_name_current_level (name)
2847 if (current_binding_level == global_binding_level)
2848 return IDENTIFIER_GLOBAL_VALUE (name);
2850 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
2853 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
2854 if (DECL_NAME (t) == name)
2860 /* Mark ARG for GC. */
2863 mark_binding_level (arg)
2866 struct binding_level *level = *(struct binding_level **) arg;
2868 for (; level != 0; level = level->level_chain)
2870 ggc_mark_tree (level->names);
2871 ggc_mark_tree (level->tags);
2872 ggc_mark_tree (level->shadowed);
2873 ggc_mark_tree (level->blocks);
2874 ggc_mark_tree (level->this_block);
2875 ggc_mark_tree (level->parm_order);
2879 /* Create the predefined scalar types of C,
2880 and some nodes representing standard constants (0, 1, (void *) 0).
2881 Initialize the global binding level.
2882 Make definitions for built-in primitive functions. */
2885 c_init_decl_processing ()
2888 tree ptr_ftype_void, ptr_ftype_ptr;
2890 /* Adds some ggc roots, and reserved words for c-parse.in. */
2893 current_function_decl = NULL;
2894 named_labels = NULL;
2895 current_binding_level = NULL_BINDING_LEVEL;
2896 free_binding_level = NULL_BINDING_LEVEL;
2898 /* Make the binding_level structure for global names. */
2900 global_binding_level = current_binding_level;
2902 build_common_tree_nodes (flag_signed_char);
2904 c_common_nodes_and_builtins ();
2906 boolean_type_node = integer_type_node;
2907 boolean_true_node = integer_one_node;
2908 boolean_false_node = integer_zero_node;
2910 /* With GCC, C99's _Bool is always of size 1. */
2911 c_bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
2912 TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
2913 TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
2914 TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
2915 TYPE_PRECISION (c_bool_type_node) = 1;
2916 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
2918 c_bool_false_node = build_int_2 (0, 0);
2919 TREE_TYPE (c_bool_false_node) = c_bool_type_node;
2920 c_bool_true_node = build_int_2 (1, 0);
2921 TREE_TYPE (c_bool_true_node) = c_bool_type_node;
2923 endlink = void_list_node;
2924 ptr_ftype_void = build_function_type (ptr_type_node, endlink);
2926 = build_function_type (ptr_type_node,
2927 tree_cons (NULL_TREE, ptr_type_node, endlink));
2929 /* Types which are common to the fortran compiler and libf2c. When
2930 changing these, you also need to be concerned with f/com.h. */
2932 if (TYPE_PRECISION (float_type_node)
2933 == TYPE_PRECISION (long_integer_type_node))
2935 g77_integer_type_node = long_integer_type_node;
2936 g77_uinteger_type_node = long_unsigned_type_node;
2938 else if (TYPE_PRECISION (float_type_node)
2939 == TYPE_PRECISION (integer_type_node))
2941 g77_integer_type_node = integer_type_node;
2942 g77_uinteger_type_node = unsigned_type_node;
2945 g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
2947 if (g77_integer_type_node != NULL_TREE)
2949 pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_integer"),
2950 g77_integer_type_node));
2951 pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_uinteger"),
2952 g77_uinteger_type_node));
2955 if (TYPE_PRECISION (float_type_node) * 2
2956 == TYPE_PRECISION (long_integer_type_node))
2958 g77_longint_type_node = long_integer_type_node;
2959 g77_ulongint_type_node = long_unsigned_type_node;
2961 else if (TYPE_PRECISION (float_type_node) * 2
2962 == TYPE_PRECISION (long_long_integer_type_node))
2964 g77_longint_type_node = long_long_integer_type_node;
2965 g77_ulongint_type_node = long_long_unsigned_type_node;
2968 g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
2970 if (g77_longint_type_node != NULL_TREE)
2972 pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_longint"),
2973 g77_longint_type_node));
2974 pushdecl (build_decl (TYPE_DECL, get_identifier ("__g77_ulongint"),
2975 g77_ulongint_type_node));
2978 pedantic_lvalues = pedantic;
2980 make_fname_decl = c_make_fname_decl;
2981 start_fname_decls ();
2983 incomplete_decl_finalize_hook = finish_incomplete_decl;
2985 /* Record our roots. */
2987 ggc_add_tree_root (c_global_trees, CTI_MAX);
2988 ggc_add_root (&c_stmt_tree, 1, sizeof c_stmt_tree, mark_stmt_tree);
2989 ggc_add_tree_root (&c_scope_stmt_stack, 1);
2990 ggc_add_tree_root (&named_labels, 1);
2991 ggc_add_tree_root (&shadowed_labels, 1);
2992 ggc_add_root (¤t_binding_level, 1, sizeof current_binding_level,
2993 mark_binding_level);
2994 ggc_add_root (&label_level_chain, 1, sizeof label_level_chain,
2995 mark_binding_level);
2996 ggc_add_tree_root (&static_ctors, 1);
2997 ggc_add_tree_root (&static_dtors, 1);
3000 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
3001 decl, NAME is the initialization string and TYPE_DEP indicates whether
3002 NAME depended on the type of the function. As we don't yet implement
3003 delayed emission of static data, we mark the decl as emitted
3004 so it is not placed in the output. Anything using it must therefore pull
3005 out the STRING_CST initializer directly. This does mean that these names
3006 are string merging candidates, which is wrong for C99's __func__. FIXME. */
3009 c_make_fname_decl (id, type_dep)
3013 const char *name = fname_as_string (type_dep);
3014 tree decl, type, init;
3015 size_t length = strlen (name);
3017 type = build_array_type
3018 (build_qualified_type (char_type_node, TYPE_QUAL_CONST),
3019 build_index_type (size_int (length)));
3021 decl = build_decl (VAR_DECL, id, type);
3022 /* We don't push the decl, so have to set its context here. */
3023 DECL_CONTEXT (decl) = current_function_decl;
3025 TREE_STATIC (decl) = 1;
3026 TREE_READONLY (decl) = 1;
3027 DECL_ARTIFICIAL (decl) = 1;
3029 init = build_string (length + 1, name);
3030 TREE_TYPE (init) = type;
3031 DECL_INITIAL (decl) = init;
3033 TREE_USED (decl) = 1;
3035 finish_decl (decl, init, NULL_TREE);
3040 /* Return a definition for a builtin function named NAME and whose data type
3041 is TYPE. TYPE should be a function type with argument types.
3042 FUNCTION_CODE tells later passes how to compile calls to this function.
3043 See tree.h for its possible values.
3045 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
3046 the name to be called if we can't opencode the function. */
3049 builtin_function (name, type, function_code, class, library_name)
3053 enum built_in_class class;
3054 const char *library_name;
3056 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
3057 DECL_EXTERNAL (decl) = 1;
3058 TREE_PUBLIC (decl) = 1;
3060 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
3061 make_decl_rtl (decl, NULL);
3063 DECL_BUILT_IN_CLASS (decl) = class;
3064 DECL_FUNCTION_CODE (decl) = function_code;
3066 /* The return builtins leave the current function. */
3067 if (function_code == BUILT_IN_RETURN || function_code == BUILT_IN_EH_RETURN)
3068 TREE_THIS_VOLATILE (decl) = 1;
3070 /* Warn if a function in the namespace for users
3071 is used without an occasion to consider it declared. */
3072 if (name[0] != '_' || name[1] != '_')
3073 C_DECL_ANTICIPATED (decl) = 1;
3075 /* Possibly apply some default attributes to this built-in function. */
3076 decl_attributes (&decl, NULL_TREE, 0);
3081 /* Apply default attributes to a function, if a system function with default
3085 insert_default_attributes (decl)
3088 if (!TREE_PUBLIC (decl))
3090 c_common_insert_default_attributes (decl);
3093 /* Called when a declaration is seen that contains no names to declare.
3094 If its type is a reference to a structure, union or enum inherited
3095 from a containing scope, shadow that tag name for the current scope
3096 with a forward reference.
3097 If its type defines a new named structure or union
3098 or defines an enum, it is valid but we need not do anything here.
3099 Otherwise, it is an error. */
3102 shadow_tag (declspecs)
3105 shadow_tag_warned (declspecs, 0);
3109 shadow_tag_warned (declspecs, warned)
3112 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
3119 pending_invalid_xref = 0;
3121 /* Remove the attributes from declspecs, since they will confuse the
3123 split_specs_attrs (declspecs, &specs, &attrs);
3125 for (link = specs; link; link = TREE_CHAIN (link))
3127 tree value = TREE_VALUE (link);
3128 enum tree_code code = TREE_CODE (value);
3130 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
3131 /* Used to test also that TYPE_SIZE (value) != 0.
3132 That caused warning for `struct foo;' at top level in the file. */
3134 tree name = lookup_tag_reverse (value);
3141 if (warned != 1 && code != ENUMERAL_TYPE)
3142 /* Empty unnamed enum OK */
3144 pedwarn ("unnamed struct/union that defines no instances");
3150 t = lookup_tag (code, name, current_binding_level, 1);
3154 t = make_node (code);
3161 if (!warned && ! in_system_header)
3163 warning ("useless keyword or type name in empty declaration");
3170 error ("two types specified in one empty declaration");
3175 pedwarn ("empty declaration");
3179 /* Construct an array declarator. EXPR is the expression inside [], or
3180 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
3181 to the pointer to which a parameter array is converted). STATIC_P is
3182 non-zero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P
3183 is non-zero is the array is [*], a VLA of unspecified length which is
3184 nevertheless a complete type (not currently implemented by GCC),
3185 zero otherwise. The declarator is constructed as an ARRAY_REF
3186 (to be decoded by grokdeclarator), whose operand 0 is what's on the
3187 left of the [] (filled by in set_array_declarator_type) and operand 1
3188 is the expression inside; whose TREE_TYPE is the type qualifiers and
3189 which has TREE_STATIC set if "static" is used. */
3192 build_array_declarator (expr, quals, static_p, vla_unspec_p)
3199 decl = build_nt (ARRAY_REF, NULL_TREE, expr);
3200 TREE_TYPE (decl) = quals;
3201 TREE_STATIC (decl) = (static_p ? 1 : 0);
3202 if (pedantic && !flag_isoc99)
3204 if (static_p || quals != NULL_TREE)
3205 pedwarn ("ISO C89 does not support `static' or type qualifiers in parameter array declarators");
3207 pedwarn ("ISO C89 does not support `[*]' array declarators");
3210 warning ("GCC does not yet properly implement `[*]' array declarators");
3214 /* Set the type of an array declarator. DECL is the declarator, as
3215 constructed by build_array_declarator; TYPE is what appears on the left
3216 of the [] and goes in operand 0. ABSTRACT_P is non-zero if it is an
3217 abstract declarator, zero otherwise; this is used to reject static and
3218 type qualifiers in abstract declarators, where they are not in the
3222 set_array_declarator_type (decl, type, abstract_p)
3227 TREE_OPERAND (decl, 0) = type;
3228 if (abstract_p && (TREE_TYPE (decl) != NULL_TREE || TREE_STATIC (decl)))
3229 error ("static or type qualifiers in abstract declarator");
3233 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
3236 groktypename (typename)
3241 if (TREE_CODE (typename) != TREE_LIST)
3244 split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs);
3246 typename = grokdeclarator (TREE_VALUE (typename), specs, TYPENAME, 0);
3248 /* Apply attributes. */
3249 decl_attributes (&typename, attrs, 0);
3254 /* Return a PARM_DECL node for a given pair of specs and declarator. */
3257 groktypename_in_parm_context (typename)
3260 if (TREE_CODE (typename) != TREE_LIST)
3262 return grokdeclarator (TREE_VALUE (typename),
3263 TREE_PURPOSE (typename),
3267 /* Decode a declarator in an ordinary declaration or data definition.
3268 This is called as soon as the type information and variable name
3269 have been parsed, before parsing the initializer if any.
3270 Here we create the ..._DECL node, fill in its type,
3271 and put it on the list of decls for the current context.
3272 The ..._DECL node is returned as the value.
3274 Exception: for arrays where the length is not specified,
3275 the type is left null, to be filled in by `finish_decl'.
3277 Function definitions do not come here; they go to start_function
3278 instead. However, external and forward declarations of functions
3279 do go through here. Structure field declarations are done by
3280 grokfield and not through here. */
3283 start_decl (declarator, declspecs, initialized, attributes)
3284 tree declarator, declspecs;
3291 /* An object declared as __attribute__((deprecated)) suppresses
3292 warnings of uses of other deprecated items. */
3293 if (lookup_attribute ("deprecated", attributes))
3294 deprecated_state = DEPRECATED_SUPPRESS;
3296 decl = grokdeclarator (declarator, declspecs,
3297 NORMAL, initialized);
3299 deprecated_state = DEPRECATED_NORMAL;
3301 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
3302 && MAIN_NAME_P (DECL_NAME (decl)))
3303 warning_with_decl (decl, "`%s' is usually a function");
3306 /* Is it valid for this decl to have an initializer at all?
3307 If not, set INITIALIZED to zero, which will indirectly
3308 tell `finish_decl' to ignore the initializer once it is parsed. */
3309 switch (TREE_CODE (decl))
3312 /* typedef foo = bar means give foo the same type as bar.
3313 We haven't parsed bar yet, so `finish_decl' will fix that up.
3314 Any other case of an initialization in a TYPE_DECL is an error. */
3315 if (pedantic || list_length (declspecs) > 1)
3317 error ("typedef `%s' is initialized",
3318 IDENTIFIER_POINTER (DECL_NAME (decl)));
3324 error ("function `%s' is initialized like a variable",
3325 IDENTIFIER_POINTER (DECL_NAME (decl)));
3330 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3331 error ("parameter `%s' is initialized",
3332 IDENTIFIER_POINTER (DECL_NAME (decl)));
3337 /* Don't allow initializations for incomplete types
3338 except for arrays which might be completed by the initialization. */
3340 /* This can happen if the array size is an undefined macro. We already
3341 gave a warning, so we don't need another one. */
3342 if (TREE_TYPE (decl) == error_mark_node)
3344 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
3346 /* A complete type is ok if size is fixed. */
3348 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3349 || C_DECL_VARIABLE_SIZE (decl))
3351 error ("variable-sized object may not be initialized");
3355 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3357 error ("variable `%s' has initializer but incomplete type",
3358 IDENTIFIER_POINTER (DECL_NAME (decl)));
3361 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
3363 error ("elements of array `%s' have incomplete type",
3364 IDENTIFIER_POINTER (DECL_NAME (decl)));
3372 /* Seems redundant with grokdeclarator. */
3373 if (current_binding_level != global_binding_level
3374 && DECL_EXTERNAL (decl)
3375 && TREE_CODE (decl) != FUNCTION_DECL)
3376 warning ("declaration of `%s' has `extern' and is initialized",
3377 IDENTIFIER_POINTER (DECL_NAME (decl)));
3379 DECL_EXTERNAL (decl) = 0;
3380 if (current_binding_level == global_binding_level)
3381 TREE_STATIC (decl) = 1;
3383 /* Tell `pushdecl' this is an initialized decl
3384 even though we don't yet have the initializer expression.
3385 Also tell `finish_decl' it may store the real initializer. */
3386 DECL_INITIAL (decl) = error_mark_node;
3389 /* If this is a function declaration, write a record describing it to the
3390 prototypes file (if requested). */
3392 if (TREE_CODE (decl) == FUNCTION_DECL)
3393 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
3395 /* ANSI specifies that a tentative definition which is not merged with
3396 a non-tentative definition behaves exactly like a definition with an
3397 initializer equal to zero. (Section 3.7.2)
3398 -fno-common gives strict ANSI behavior. Usually you don't want it.
3399 This matters only for variables with external linkage. */
3400 if (!initialized && (! flag_no_common || ! TREE_PUBLIC (decl)))
3401 DECL_COMMON (decl) = 1;
3403 /* Set attributes here so if duplicate decl, will have proper attributes. */
3404 decl_attributes (&decl, attributes, 0);
3406 if (TREE_CODE (decl) == FUNCTION_DECL
3407 && DECL_DECLARED_INLINE_P (decl)
3408 && DECL_UNINLINABLE (decl)
3409 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
3410 warning_with_decl (decl,
3411 "inline function `%s' given attribute noinline");
3413 /* Add this decl to the current binding level.
3414 TEM may equal DECL or it may be a previous decl of the same name. */
3415 tem = pushdecl (decl);
3417 /* For a local variable, define the RTL now. */
3418 if (current_binding_level != global_binding_level
3419 /* But not if this is a duplicate decl
3420 and we preserved the rtl from the previous one
3421 (which may or may not happen). */
3422 && !DECL_RTL_SET_P (tem)
3423 && !DECL_CONTEXT (tem))
3425 if (TREE_TYPE (tem) != error_mark_node
3426 && COMPLETE_TYPE_P (TREE_TYPE (tem)))
3428 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
3429 && DECL_INITIAL (tem) != 0)
3436 /* Finish processing of a declaration;
3437 install its initial value.
3438 If the length of an array type is not known before,
3439 it must be determined now, from the initial value, or it is an error. */
3442 finish_decl (decl, init, asmspec_tree)
3446 tree type = TREE_TYPE (decl);
3447 int was_incomplete = (DECL_SIZE (decl) == 0);
3448 const char *asmspec = 0;
3450 /* If a name was specified, get the string. */
3452 asmspec = TREE_STRING_POINTER (asmspec_tree);
3454 /* If `start_decl' didn't like having an initialization, ignore it now. */
3455 if (init != 0 && DECL_INITIAL (decl) == 0)
3458 /* Don't crash if parm is initialized. */
3459 if (TREE_CODE (decl) == PARM_DECL)
3464 if (TREE_CODE (decl) != TYPE_DECL)
3465 store_init_value (decl, init);
3468 /* typedef foo = bar; store the type of bar as the type of foo. */
3469 TREE_TYPE (decl) = TREE_TYPE (init);
3470 DECL_INITIAL (decl) = init = 0;
3474 /* Deduce size of array from initialization, if not already known */
3475 if (TREE_CODE (type) == ARRAY_TYPE
3476 && TYPE_DOMAIN (type) == 0
3477 && TREE_CODE (decl) != TYPE_DECL)
3480 = (TREE_STATIC (decl)
3481 /* Even if pedantic, an external linkage array
3482 may have incomplete type at first. */
3483 ? pedantic && !TREE_PUBLIC (decl)
3484 : !DECL_EXTERNAL (decl));
3486 = complete_array_type (type, DECL_INITIAL (decl), do_default);
3488 /* Get the completed type made by complete_array_type. */
3489 type = TREE_TYPE (decl);
3492 error_with_decl (decl, "initializer fails to determine size of `%s'");
3494 else if (failure == 2)
3497 error_with_decl (decl, "array size missing in `%s'");
3498 /* If a `static' var's size isn't known,
3499 make it extern as well as static, so it does not get
3501 If it is not `static', then do not mark extern;
3502 finish_incomplete_decl will give it a default size
3503 and it will get allocated. */
3504 else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl))
3505 DECL_EXTERNAL (decl) = 1;
3508 /* TYPE_MAX_VALUE is always one less than the number of elements
3509 in the array, because we start counting at zero. Therefore,
3510 warn only if the value is less than zero. */
3511 else if (pedantic && TYPE_DOMAIN (type) != 0
3512 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
3513 error_with_decl (decl, "zero or negative size array `%s'");
3515 layout_decl (decl, 0);
3518 if (TREE_CODE (decl) == VAR_DECL)
3520 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
3521 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
3522 layout_decl (decl, 0);
3524 if (DECL_SIZE (decl) == 0
3525 /* Don't give an error if we already gave one earlier. */
3526 && TREE_TYPE (decl) != error_mark_node
3527 && (TREE_STATIC (decl)
3529 /* A static variable with an incomplete type
3530 is an error if it is initialized.
3531 Also if it is not file scope.
3532 Otherwise, let it through, but if it is not `extern'
3533 then it may cause an error message later. */
3534 (DECL_INITIAL (decl) != 0
3535 || DECL_CONTEXT (decl) != 0)
3537 /* An automatic variable with an incomplete type
3539 !DECL_EXTERNAL (decl)))
3541 error_with_decl (decl, "storage size of `%s' isn't known");
3542 TREE_TYPE (decl) = error_mark_node;
3545 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
3546 && DECL_SIZE (decl) != 0)
3548 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3549 constant_expression_warning (DECL_SIZE (decl));
3551 error_with_decl (decl, "storage size of `%s' isn't constant");
3554 if (TREE_USED (type))
3555 TREE_USED (decl) = 1;
3558 /* If this is a function and an assembler name is specified, it isn't
3559 builtin any more. Also reset DECL_RTL so we can give it its new
3561 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
3563 DECL_BUILT_IN_CLASS (decl) = NOT_BUILT_IN;
3564 SET_DECL_RTL (decl, NULL_RTX);
3565 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
3568 /* Output the assembler code and/or RTL code for variables and functions,
3569 unless the type is an undefined structure or union.
3570 If not, it will get done when the type is completed. */
3572 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3574 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
3575 maybe_objc_check_decl (decl);
3577 if (!DECL_CONTEXT (decl))
3579 if (DECL_INITIAL (decl) == NULL_TREE
3580 || DECL_INITIAL (decl) == error_mark_node)
3581 /* Don't output anything
3582 when a tentative file-scope definition is seen.
3583 But at end of compilation, do output code for them. */
3584 DECL_DEFER_OUTPUT (decl) = 1;
3585 rest_of_decl_compilation (decl, asmspec,
3586 (DECL_CONTEXT (decl) == 0
3587 || TREE_ASM_WRITTEN (decl)), 0);
3591 /* This is a local variable. If there is an ASMSPEC, the
3592 user has requested that we handle it specially. */
3595 /* In conjunction with an ASMSPEC, the `register'
3596 keyword indicates that we should place the variable
3597 in a particular register. */
3598 if (DECL_REGISTER (decl))
3599 DECL_C_HARD_REGISTER (decl) = 1;
3601 /* If this is not a static variable, issue a warning.
3602 It doesn't make any sense to give an ASMSPEC for an
3603 ordinary, non-register local variable. Historically,
3604 GCC has accepted -- but ignored -- the ASMSPEC in
3606 if (TREE_CODE (decl) == VAR_DECL
3607 && !DECL_REGISTER (decl)
3608 && !TREE_STATIC (decl))
3609 warning_with_decl (decl,
3610 "ignoring asm-specifier for non-static local variable `%s'");
3612 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
3615 if (TREE_CODE (decl) != FUNCTION_DECL)
3616 add_decl_stmt (decl);
3619 if (DECL_CONTEXT (decl) != 0)
3621 /* Recompute the RTL of a local array now
3622 if it used to be an incomplete type. */
3624 && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
3626 /* If we used it already as memory, it must stay in memory. */
3627 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
3628 /* If it's still incomplete now, no init will save it. */
3629 if (DECL_SIZE (decl) == 0)
3630 DECL_INITIAL (decl) = 0;
3635 if (TREE_CODE (decl) == TYPE_DECL)
3637 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
3638 maybe_objc_check_decl (decl);
3639 rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0, 0);
3642 /* At the end of a declaration, throw away any variable type sizes
3643 of types defined inside that declaration. There is no use
3644 computing them in the following function definition. */
3645 if (current_binding_level == global_binding_level)
3646 get_pending_sizes ();
3649 /* If DECL has a cleanup, build and return that cleanup here.
3650 This is a callback called by expand_expr. */
3653 maybe_build_cleanup (decl)
3654 tree decl ATTRIBUTE_UNUSED;
3656 /* There are no cleanups in C. */
3660 /* Given a parsed parameter declaration,
3661 decode it into a PARM_DECL and push that on the current binding level.
3662 Also, for the sake of forward parm decls,
3663 record the given order of parms in `parm_order'. */
3666 push_parm_decl (parm)
3670 int old_immediate_size_expand = immediate_size_expand;
3671 /* Don't try computing parm sizes now -- wait till fn is called. */
3672 immediate_size_expand = 0;
3674 decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
3675 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
3676 decl_attributes (&decl, TREE_VALUE (parm), 0);
3679 if (DECL_NAME (decl))
3682 olddecl = lookup_name (DECL_NAME (decl));
3683 if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
3684 pedwarn_with_decl (decl,
3685 "ISO C forbids parameter `%s' shadowing typedef");
3689 decl = pushdecl (decl);
3691 immediate_size_expand = old_immediate_size_expand;
3693 current_binding_level->parm_order
3694 = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
3696 /* Add this decl to the current binding level. */
3697 finish_decl (decl, NULL_TREE, NULL_TREE);
3700 /* Clear the given order of parms in `parm_order'.
3701 Used at start of parm list,
3702 and also at semicolon terminating forward decls. */
3707 current_binding_level->parm_order = NULL_TREE;
3710 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3711 literal, which may be an incomplete array type completed by the
3712 initializer; INIT is a CONSTRUCTOR that initializes the compound
3716 build_compound_literal (type, init)
3720 /* We do not use start_decl here because we have a type, not a declarator;
3721 and do not use finish_decl because the decl should be stored inside
3722 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
3723 tree decl = build_decl (VAR_DECL, NULL_TREE, type);
3726 DECL_EXTERNAL (decl) = 0;
3727 TREE_PUBLIC (decl) = 0;
3728 TREE_STATIC (decl) = (current_binding_level == global_binding_level);
3729 DECL_CONTEXT (decl) = current_function_decl;
3730 TREE_USED (decl) = 1;
3731 TREE_TYPE (decl) = type;
3732 store_init_value (decl, init);
3734 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
3736 int failure = complete_array_type (type, DECL_INITIAL (decl), 1);
3741 type = TREE_TYPE (decl);
3742 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
3743 return error_mark_node;
3745 stmt = build_stmt (DECL_STMT, decl);
3746 complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt);
3747 TREE_SIDE_EFFECTS (complit) = 1;
3749 layout_decl (decl, 0);
3751 if (TREE_STATIC (decl))
3753 /* This decl needs a name for the assembler output. We also need
3754 a unique suffix to be added to the name, for which DECL_CONTEXT
3756 DECL_NAME (decl) = get_identifier ("__compound_literal");
3757 DECL_CONTEXT (decl) = complit;
3758 rest_of_decl_compilation (decl, NULL, 1, 0);
3759 DECL_CONTEXT (decl) = NULL_TREE;
3765 /* Make TYPE a complete type based on INITIAL_VALUE.
3766 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3767 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3770 complete_array_type (type, initial_value, do_default)
3775 tree maxindex = NULL_TREE;
3780 /* Note MAXINDEX is really the maximum index,
3781 one less than the size. */
3782 if (TREE_CODE (initial_value) == STRING_CST)
3785 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
3786 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
3789 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
3791 tree elts = CONSTRUCTOR_ELTS (initial_value);
3792 maxindex = build_int_2 (-1, -1);
3793 for (; elts; elts = TREE_CHAIN (elts))
3795 if (TREE_PURPOSE (elts))
3796 maxindex = TREE_PURPOSE (elts);
3798 maxindex = fold (build (PLUS_EXPR, integer_type_node,
3799 maxindex, integer_one_node));
3801 maxindex = copy_node (maxindex);
3805 /* Make an error message unless that happened already. */
3806 if (initial_value != error_mark_node)
3809 /* Prevent further error messages. */
3810 maxindex = build_int_2 (0, 0);
3817 maxindex = build_int_2 (0, 0);
3823 TYPE_DOMAIN (type) = build_index_type (maxindex);
3824 if (!TREE_TYPE (maxindex))
3825 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
3828 /* Lay out the type now that we can get the real answer. */
3835 /* Given declspecs and a declarator,
3836 determine the name and type of the object declared
3837 and construct a ..._DECL node for it.
3838 (In one case we can return a ..._TYPE node instead.
3839 For invalid input we sometimes return 0.)
3841 DECLSPECS is a chain of tree_list nodes whose value fields
3842 are the storage classes and type specifiers.
3844 DECL_CONTEXT says which syntactic context this declaration is in:
3845 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3846 FUNCDEF for a function definition. Like NORMAL but a few different
3847 error messages in each case. Return value may be zero meaning
3848 this definition is too screwy to try to parse.
3849 PARM for a parameter declaration (either within a function prototype
3850 or before a function body). Make a PARM_DECL, or return void_type_node.
3851 TYPENAME if for a typename (in a cast or sizeof).
3852 Don't make a DECL node; just return the ..._TYPE node.
3853 FIELD for a struct or union field; make a FIELD_DECL.
3854 BITFIELD for a field with specified width.
3855 INITIALIZED is 1 if the decl has an initializer.
3857 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3858 It may also be so in the PARM case, for a prototype where the
3859 argument type is specified but not the name.
3861 This function is where the complicated C meanings of `static'
3862 and `extern' are interpreted. */
3865 grokdeclarator (declarator, declspecs, decl_context, initialized)
3868 enum decl_context decl_context;
3873 tree type = NULL_TREE;
3878 int type_quals = TYPE_UNQUALIFIED;
3880 int explicit_int = 0;
3881 int explicit_char = 0;
3882 int defaulted_int = 0;
3883 tree typedef_decl = 0;
3885 tree typedef_type = 0;
3886 int funcdef_flag = 0;
3887 enum tree_code innermost_code = ERROR_MARK;
3889 int size_varies = 0;
3890 tree decl_attr = NULL_TREE;
3891 tree array_ptr_quals = NULL_TREE;
3892 int array_parm_static = 0;
3893 tree returned_attrs = NULL_TREE;
3895 if (decl_context == BITFIELD)
3896 bitfield = 1, decl_context = FIELD;
3898 if (decl_context == FUNCDEF)
3899 funcdef_flag = 1, decl_context = NORMAL;
3901 /* Look inside a declarator for the name being declared
3902 and get it as a string, for an error message. */
3904 tree decl = declarator;
3908 switch (TREE_CODE (decl))
3913 innermost_code = TREE_CODE (decl);
3914 decl = TREE_OPERAND (decl, 0);
3918 decl = TREE_VALUE (decl);
3921 case IDENTIFIER_NODE:
3922 name = IDENTIFIER_POINTER (decl);
3933 /* A function definition's declarator must have the form of
3934 a function declarator. */
3936 if (funcdef_flag && innermost_code != CALL_EXPR)
3939 /* Anything declared one level down from the top level
3940 must be one of the parameters of a function
3941 (because the body is at least two levels down). */
3943 /* If this looks like a function definition, make it one,
3944 even if it occurs where parms are expected.
3945 Then store_parm_decls will reject it and not use it as a parm. */
3946 if (decl_context == NORMAL && !funcdef_flag
3947 && current_binding_level->parm_flag)
3948 decl_context = PARM;
3950 /* Look through the decl specs and record which ones appear.
3951 Some typespecs are defined as built-in typenames.
3952 Others, the ones that are modifiers of other types,
3953 are represented by bits in SPECBITS: set the bits for
3954 the modifiers that appear. Storage class keywords are also in SPECBITS.
3956 If there is a typedef name or a type, store the type in TYPE.
3957 This includes builtin typedefs such as `int'.
3959 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3960 and did not come from a user typedef.
3962 Set LONGLONG if `long' is mentioned twice. */
3964 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
3966 tree id = TREE_VALUE (spec);
3968 /* If the entire declaration is itself tagged as deprecated then
3969 suppress reports of deprecated items. */
3970 if (id && TREE_DEPRECATED (id))
3972 if (deprecated_state != DEPRECATED_SUPPRESS)
3973 warn_deprecated_use (id);
3976 if (id == ridpointers[(int) RID_INT])
3978 if (id == ridpointers[(int) RID_CHAR])
3981 if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (id))
3983 enum rid i = C_RID_CODE (id);
3984 if ((int) i <= (int) RID_LAST_MODIFIER)
3986 if (i == RID_LONG && (specbits & (1 << (int) i)))
3989 error ("`long long long' is too long for GCC");
3992 if (pedantic && !flag_isoc99 && ! in_system_header
3994 pedwarn ("ISO C89 does not support `long long'");
3998 else if (specbits & (1 << (int) i))
3999 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
4000 specbits |= 1 << (int) i;
4005 error ("two or more data types in declaration of `%s'", name);
4006 /* Actual typedefs come to us as TYPE_DECL nodes. */
4007 else if (TREE_CODE (id) == TYPE_DECL)
4009 if (TREE_TYPE (id) == error_mark_node)
4010 ; /* Allow the type to default to int to avoid cascading errors. */
4013 type = TREE_TYPE (id);
4014 decl_attr = DECL_ATTRIBUTES (id);
4018 /* Built-in types come as identifiers. */
4019 else if (TREE_CODE (id) == IDENTIFIER_NODE)
4021 tree t = lookup_name (id);
4022 if (TREE_TYPE (t) == error_mark_node)
4024 else if (!t || TREE_CODE (t) != TYPE_DECL)
4025 error ("`%s' fails to be a typedef or built in type",
4026 IDENTIFIER_POINTER (id));
4029 type = TREE_TYPE (t);
4033 else if (TREE_CODE (id) != ERROR_MARK)
4040 typedef_type = type;
4042 size_varies = C_TYPE_VARIABLE_SIZE (type);
4044 /* No type at all: default to `int', and set DEFAULTED_INT
4045 because it was not a user-defined typedef. */
4049 if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4050 | (1 << (int) RID_SIGNED)
4051 | (1 << (int) RID_UNSIGNED)
4052 | (1 << (int) RID_COMPLEX))))
4053 /* Don't warn about typedef foo = bar. */
4054 && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
4055 && ! in_system_header)
4057 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
4058 and this is a function, or if -Wimplicit; prefer the former
4059 warning since it is more explicit. */
4060 if ((warn_implicit_int || warn_return_type || flag_isoc99)
4062 warn_about_return_type = 1;
4063 else if (warn_implicit_int || flag_isoc99)
4064 pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
4069 type = integer_type_node;
4072 /* Now process the modifiers that were specified
4073 and check for invalid combinations. */
4075 /* Long double is a special combination. */
4077 if ((specbits & 1 << (int) RID_LONG) && ! longlong
4078 && TYPE_MAIN_VARIANT (type) == double_type_node)
4080 specbits &= ~(1 << (int) RID_LONG);
4081 type = long_double_type_node;
4084 /* Check all other uses of type modifiers. */
4086 if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4087 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
4091 if ((specbits & 1 << (int) RID_LONG)
4092 && (specbits & 1 << (int) RID_SHORT))
4093 error ("both long and short specified for `%s'", name);
4094 else if (((specbits & 1 << (int) RID_LONG)
4095 || (specbits & 1 << (int) RID_SHORT))
4097 error ("long or short specified with char for `%s'", name);
4098 else if (((specbits & 1 << (int) RID_LONG)
4099 || (specbits & 1 << (int) RID_SHORT))
4100 && TREE_CODE (type) == REAL_TYPE)
4102 static int already = 0;
4104 error ("long or short specified with floating type for `%s'", name);
4105 if (! already && ! pedantic)
4107 error ("the only valid combination is `long double'");
4111 else if ((specbits & 1 << (int) RID_SIGNED)
4112 && (specbits & 1 << (int) RID_UNSIGNED))
4113 error ("both signed and unsigned specified for `%s'", name);
4114 else if (TREE_CODE (type) != INTEGER_TYPE)
4115 error ("long, short, signed or unsigned invalid for `%s'", name);
4119 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
4121 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
4123 if (flag_pedantic_errors)
4128 /* Discard the type modifiers if they are invalid. */
4131 specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4132 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
4137 if ((specbits & (1 << (int) RID_COMPLEX))
4138 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
4140 error ("complex invalid for `%s'", name);
4141 specbits &= ~(1 << (int) RID_COMPLEX);
4144 /* Decide whether an integer type is signed or not.
4145 Optionally treat bitfields as signed by default. */
4146 if (specbits & 1 << (int) RID_UNSIGNED
4147 || (bitfield && ! flag_signed_bitfields
4148 && (explicit_int || defaulted_int || explicit_char
4149 /* A typedef for plain `int' without `signed'
4150 can be controlled just like plain `int'. */
4151 || ! (typedef_decl != 0
4152 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4153 && TREE_CODE (type) != ENUMERAL_TYPE
4154 && !(specbits & 1 << (int) RID_SIGNED)))
4157 type = long_long_unsigned_type_node;
4158 else if (specbits & 1 << (int) RID_LONG)
4159 type = long_unsigned_type_node;
4160 else if (specbits & 1 << (int) RID_SHORT)
4161 type = short_unsigned_type_node;
4162 else if (type == char_type_node)
4163 type = unsigned_char_type_node;
4164 else if (typedef_decl)
4165 type = unsigned_type (type);
4167 type = unsigned_type_node;
4169 else if ((specbits & 1 << (int) RID_SIGNED)
4170 && type == char_type_node)
4171 type = signed_char_type_node;
4173 type = long_long_integer_type_node;
4174 else if (specbits & 1 << (int) RID_LONG)
4175 type = long_integer_type_node;
4176 else if (specbits & 1 << (int) RID_SHORT)
4177 type = short_integer_type_node;
4179 if (specbits & 1 << (int) RID_COMPLEX)
4181 if (pedantic && !flag_isoc99)
4182 pedwarn ("ISO C89 does not support complex types");
4183 /* If we just have "complex", it is equivalent to
4184 "complex double", but if any modifiers at all are specified it is
4185 the complex form of TYPE. E.g, "complex short" is
4186 "complex short int". */
4188 if (defaulted_int && ! longlong
4189 && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4190 | (1 << (int) RID_SIGNED)
4191 | (1 << (int) RID_UNSIGNED))))
4194 pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
4195 type = complex_double_type_node;
4197 else if (type == integer_type_node)
4200 pedwarn ("ISO C does not support complex integer types");
4201 type = complex_integer_type_node;
4203 else if (type == float_type_node)
4204 type = complex_float_type_node;
4205 else if (type == double_type_node)
4206 type = complex_double_type_node;
4207 else if (type == long_double_type_node)
4208 type = complex_long_double_type_node;
4212 pedwarn ("ISO C does not support complex integer types");
4213 type = build_complex_type (type);
4217 /* Figure out the type qualifiers for the declaration. There are
4218 two ways a declaration can become qualified. One is something
4219 like `const int i' where the `const' is explicit. Another is
4220 something like `typedef const int CI; CI i' where the type of the
4221 declaration contains the `const'. */
4222 constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
4223 restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
4224 volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
4225 inlinep = !! (specbits & (1 << (int) RID_INLINE));
4226 if (constp > 1 && ! flag_isoc99)
4227 pedwarn ("duplicate `const'");
4228 if (restrictp > 1 && ! flag_isoc99)
4229 pedwarn ("duplicate `restrict'");
4230 if (volatilep > 1 && ! flag_isoc99)
4231 pedwarn ("duplicate `volatile'");
4232 if (! flag_gen_aux_info && (TYPE_QUALS (type)))
4233 type = TYPE_MAIN_VARIANT (type);
4234 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4235 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4236 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4238 /* Warn if two storage classes are given. Default to `auto'. */
4243 if (specbits & 1 << (int) RID_AUTO) nclasses++;
4244 if (specbits & 1 << (int) RID_STATIC) nclasses++;
4245 if (specbits & 1 << (int) RID_EXTERN) nclasses++;
4246 if (specbits & 1 << (int) RID_REGISTER) nclasses++;
4247 if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
4249 /* Warn about storage classes that are invalid for certain
4250 kinds of declarations (parameters, typenames, etc.). */
4253 error ("multiple storage classes in declaration of `%s'", name);
4254 else if (funcdef_flag
4256 & ((1 << (int) RID_REGISTER)
4257 | (1 << (int) RID_AUTO)
4258 | (1 << (int) RID_TYPEDEF))))
4260 if (specbits & 1 << (int) RID_AUTO
4261 && (pedantic || current_binding_level == global_binding_level))
4262 pedwarn ("function definition declared `auto'");
4263 if (specbits & 1 << (int) RID_REGISTER)
4264 error ("function definition declared `register'");
4265 if (specbits & 1 << (int) RID_TYPEDEF)
4266 error ("function definition declared `typedef'");
4267 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4268 | (1 << (int) RID_AUTO));
4270 else if (decl_context != NORMAL && nclasses > 0)
4272 if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
4276 switch (decl_context)
4279 error ("storage class specified for structure field `%s'",
4283 error ("storage class specified for parameter `%s'", name);
4286 error ("storage class specified for typename");
4289 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4290 | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
4291 | (1 << (int) RID_EXTERN));
4294 else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
4296 /* `extern' with initialization is invalid if not at top level. */
4297 if (current_binding_level == global_binding_level)
4298 warning ("`%s' initialized and declared `extern'", name);
4300 error ("`%s' has both `extern' and initializer", name);
4302 else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
4303 && current_binding_level != global_binding_level)
4304 error ("nested function `%s' declared `extern'", name);
4305 else if (current_binding_level == global_binding_level
4306 && specbits & (1 << (int) RID_AUTO))
4307 error ("top-level declaration of `%s' specifies `auto'", name);
4310 /* Now figure out the structure of the declarator proper.
4311 Descend through it, creating more complex types, until we reach
4312 the declared identifier (or NULL_TREE, in an absolute declarator). */
4314 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
4316 if (type == error_mark_node)
4318 declarator = TREE_OPERAND (declarator, 0);
4322 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
4323 an INDIRECT_REF (for *...),
4324 a CALL_EXPR (for ...(...)),
4325 a TREE_LIST (for nested attributes),
4326 an identifier (for the name being declared)
4327 or a null pointer (for the place in an absolute declarator
4328 where the name was omitted).
4329 For the last two cases, we have just exited the loop.
4331 At this point, TYPE is the type of elements of an array,
4332 or for a function to return, or for a pointer to point to.
4333 After this sequence of ifs, TYPE is the type of the
4334 array or function or pointer, and DECLARATOR has had its
4335 outermost layer removed. */
4337 if (array_ptr_quals != NULL_TREE || array_parm_static)
4339 /* Only the innermost declarator (making a parameter be of
4340 array type which is converted to pointer type)
4341 may have static or type qualifiers. */
4342 error ("static or type qualifiers in non-parameter array declarator");
4343 array_ptr_quals = NULL_TREE;
4344 array_parm_static = 0;
4347 if (TREE_CODE (declarator) == TREE_LIST)
4349 /* We encode a declarator with embedded attributes using
4351 tree attrs = TREE_PURPOSE (declarator);
4354 declarator = TREE_VALUE (declarator);
4355 inner_decl = declarator;
4356 while (inner_decl != NULL_TREE
4357 && TREE_CODE (inner_decl) == TREE_LIST)
4358 inner_decl = TREE_VALUE (inner_decl);
4359 if (inner_decl == NULL_TREE
4360 || TREE_CODE (inner_decl) == IDENTIFIER_NODE)
4361 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
4362 else if (TREE_CODE (inner_decl) == CALL_EXPR)
4363 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
4364 else if (TREE_CODE (inner_decl) == ARRAY_REF)
4365 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
4366 returned_attrs = decl_attributes (&type,
4367 chainon (returned_attrs, attrs),
4370 else if (TREE_CODE (declarator) == ARRAY_REF)
4372 tree itype = NULL_TREE;
4373 tree size = TREE_OPERAND (declarator, 1);
4374 /* The index is a signed object `sizetype' bits wide. */
4375 tree index_type = signed_type (sizetype);
4377 array_ptr_quals = TREE_TYPE (declarator);
4378 array_parm_static = TREE_STATIC (declarator);
4380 declarator = TREE_OPERAND (declarator, 0);
4382 /* Check for some types that there cannot be arrays of. */
4384 if (VOID_TYPE_P (type))
4386 error ("declaration of `%s' as array of voids", name);
4387 type = error_mark_node;
4390 if (TREE_CODE (type) == FUNCTION_TYPE)
4392 error ("declaration of `%s' as array of functions", name);
4393 type = error_mark_node;
4396 if (size == error_mark_node)
4397 type = error_mark_node;
4399 if (type == error_mark_node)
4402 /* If size was specified, set ITYPE to a range-type for that size.
4403 Otherwise, ITYPE remains null. finish_decl may figure it out
4404 from an initial value. */
4408 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4409 STRIP_TYPE_NOPS (size);
4411 if (! INTEGRAL_TYPE_P (TREE_TYPE (size)))
4413 error ("size of array `%s' has non-integer type", name);
4414 size = integer_one_node;
4417 if (pedantic && integer_zerop (size))
4418 pedwarn ("ISO C forbids zero-size array `%s'", name);
4420 if (TREE_CODE (size) == INTEGER_CST)
4422 constant_expression_warning (size);
4423 if (tree_int_cst_sgn (size) < 0)
4425 error ("size of array `%s' is negative", name);
4426 size = integer_one_node;
4431 /* Make sure the array size remains visibly nonconstant
4432 even if it is (eg) a const variable with known value. */
4437 if (TREE_CONSTANT (size))
4438 pedwarn ("ISO C89 forbids array `%s' whose size can't be evaluated",
4441 pedwarn ("ISO C89 forbids variable-size array `%s'",
4446 if (integer_zerop (size))
4448 /* A zero-length array cannot be represented with an
4449 unsigned index type, which is what we'll get with
4450 build_index_type. Create an open-ended range instead. */
4451 itype = build_range_type (sizetype, size, NULL_TREE);
4455 /* Compute the maximum valid index, that is, size - 1.
4456 Do the calculation in index_type, so that if it is
4457 a variable the computations will be done in the
4459 itype = fold (build (MINUS_EXPR, index_type,
4460 convert (index_type, size),
4461 convert (index_type, size_one_node)));
4463 /* If that overflowed, the array is too big.
4464 ??? While a size of INT_MAX+1 technically shouldn't
4465 cause an overflow (because we subtract 1), the overflow
4466 is recorded during the conversion to index_type, before
4467 the subtraction. Handling this case seems like an
4468 unnecessary complication. */
4469 if (TREE_OVERFLOW (itype))
4471 error ("size of array `%s' is too large", name);
4472 type = error_mark_node;
4477 itype = variable_size (itype);
4478 itype = build_index_type (itype);
4481 else if (decl_context == FIELD)
4483 /* ??? Need to check somewhere that this is a structure
4484 and not a union, that this field is last, and that
4485 this structure has at least one other named member. */
4487 if (pedantic && !flag_isoc99 && !in_system_header)
4488 pedwarn ("ISO C89 does not support flexible array members");
4490 /* ISO C99 Flexible array members are effectively identical
4491 to GCC's zero-length array extension. */
4492 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
4495 /* If pedantic, complain about arrays of incomplete types. */
4497 if (pedantic && !COMPLETE_TYPE_P (type))
4498 pedwarn ("array type has incomplete element type");
4501 /* We shouldn't have a function type here at all!
4502 Functions aren't allowed as array elements. */
4503 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4504 && (constp || volatilep))
4505 pedwarn ("ISO C forbids const or volatile function types");
4508 /* Build the array type itself, then merge any constancy or
4509 volatility into the target type. We must do it in this order
4510 to ensure that the TYPE_MAIN_VARIANT field of the array type
4511 is set correctly. */
4513 type = build_array_type (type, itype);
4515 type = c_build_qualified_type (type, type_quals);
4518 C_TYPE_VARIABLE_SIZE (type) = 1;
4520 /* The GCC extension for zero-length arrays differs from
4521 ISO flexible array members in that sizeof yields zero. */
4522 if (size && integer_zerop (size))
4525 TYPE_SIZE (type) = bitsize_zero_node;
4526 TYPE_SIZE_UNIT (type) = size_zero_node;
4528 if (decl_context != PARM
4529 && (array_ptr_quals != NULL_TREE || array_parm_static))
4531 error ("static or type qualifiers in non-parameter array declarator");
4532 array_ptr_quals = NULL_TREE;
4533 array_parm_static = 0;
4536 else if (TREE_CODE (declarator) == CALL_EXPR)
4540 /* Declaring a function type.
4541 Make sure we have a valid type for the function to return. */
4542 if (type == error_mark_node)
4547 /* Warn about some types functions can't return. */
4549 if (TREE_CODE (type) == FUNCTION_TYPE)
4551 error ("`%s' declared as function returning a function", name);
4552 type = integer_type_node;
4554 if (TREE_CODE (type) == ARRAY_TYPE)
4556 error ("`%s' declared as function returning an array", name);
4557 type = integer_type_node;
4560 /* Construct the function type and go to the next
4561 inner layer of declarator. */
4563 arg_types = grokparms (TREE_OPERAND (declarator, 1),
4565 /* Say it's a definition
4566 only for the CALL_EXPR
4567 closest to the identifier. */
4568 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
4569 /* Type qualifiers before the return type of the function
4570 qualify the return type, not the function type. */
4573 /* Type qualifiers on a function return type are normally
4574 permitted by the standard but have no effect, so give a
4575 warning at -W. Qualifiers on a void return type have
4576 meaning as a GNU extension, and are banned on function
4577 definitions in ISO C. FIXME: strictly we shouldn't
4578 pedwarn for qualified void return types except on function
4579 definitions, but not doing so could lead to the undesirable
4580 state of a "volatile void" function return type not being
4581 warned about, and a use of the function being compiled
4582 with GNU semantics, with no diagnostics under -pedantic. */
4583 if (VOID_TYPE_P (type) && pedantic && !in_system_header)
4584 pedwarn ("ISO C forbids qualified void function return type");
4585 else if (extra_warnings
4586 && !(VOID_TYPE_P (type)
4587 && type_quals == TYPE_QUAL_VOLATILE))
4588 warning ("type qualifiers ignored on function return type");
4590 type = c_build_qualified_type (type, type_quals);
4592 type_quals = TYPE_UNQUALIFIED;
4594 type = build_function_type (type, arg_types);
4595 declarator = TREE_OPERAND (declarator, 0);
4597 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4598 the formal parameter list of this FUNCTION_TYPE to point to
4599 the FUNCTION_TYPE node itself. */
4604 for (link = last_function_parm_tags;
4606 link = TREE_CHAIN (link))
4607 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4610 else if (TREE_CODE (declarator) == INDIRECT_REF)
4612 /* Merge any constancy or volatility into the target type
4615 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4617 pedwarn ("ISO C forbids qualified function types");
4619 type = c_build_qualified_type (type, type_quals);
4620 type_quals = TYPE_UNQUALIFIED;
4623 type = build_pointer_type (type);
4625 /* Process a list of type modifier keywords
4626 (such as const or volatile) that were given inside the `*'. */
4628 if (TREE_TYPE (declarator))
4636 for (typemodlist = TREE_TYPE (declarator); typemodlist;
4637 typemodlist = TREE_CHAIN (typemodlist))
4639 tree qualifier = TREE_VALUE (typemodlist);
4641 if (C_IS_RESERVED_WORD (qualifier))
4643 if (C_RID_CODE (qualifier) == RID_CONST)
4645 else if (C_RID_CODE (qualifier) == RID_VOLATILE)
4647 else if (C_RID_CODE (qualifier) == RID_RESTRICT)
4657 error ("invalid type modifier within pointer declarator");
4658 if (constp > 1 && ! flag_isoc99)
4659 pedwarn ("duplicate `const'");
4660 if (volatilep > 1 && ! flag_isoc99)
4661 pedwarn ("duplicate `volatile'");
4662 if (restrictp > 1 && ! flag_isoc99)
4663 pedwarn ("duplicate `restrict'");
4665 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4666 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4667 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4670 declarator = TREE_OPERAND (declarator, 0);
4677 /* Now TYPE has the actual type. */
4679 /* Did array size calculations overflow? */
4681 if (TREE_CODE (type) == ARRAY_TYPE
4682 && COMPLETE_TYPE_P (type)
4683 && TREE_OVERFLOW (TYPE_SIZE (type)))
4685 error ("size of array `%s' is too large", name);
4686 /* If we proceed with the array type as it is, we'll eventually
4687 crash in tree_low_cst(). */
4688 type = error_mark_node;
4691 /* If this is declaring a typedef name, return a TYPE_DECL. */
4693 if (specbits & (1 << (int) RID_TYPEDEF))
4696 /* Note that the grammar rejects storage classes
4697 in typenames, fields or parameters */
4698 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4700 pedwarn ("ISO C forbids qualified function types");
4702 type = c_build_qualified_type (type, type_quals);
4703 decl = build_decl (TYPE_DECL, declarator, type);
4704 if ((specbits & (1 << (int) RID_SIGNED))
4705 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4706 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4707 decl_attributes (&decl, returned_attrs, 0);
4711 /* Detect the case of an array type of unspecified size
4712 which came, as such, direct from a typedef name.
4713 We must copy the type, so that each identifier gets
4714 a distinct type, so that each identifier's size can be
4715 controlled separately by its own initializer. */
4717 if (type != 0 && typedef_type != 0
4718 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
4719 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
4721 type = build_array_type (TREE_TYPE (type), 0);
4723 C_TYPE_VARIABLE_SIZE (type) = 1;
4726 /* If this is a type name (such as, in a cast or sizeof),
4727 compute the type and return it now. */
4729 if (decl_context == TYPENAME)
4731 /* Note that the grammar rejects storage classes
4732 in typenames, fields or parameters */
4733 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4735 pedwarn ("ISO C forbids const or volatile function types");
4737 type = c_build_qualified_type (type, type_quals);
4738 decl_attributes (&type, returned_attrs, 0);
4742 /* Aside from typedefs and type names (handle above),
4743 `void' at top level (not within pointer)
4744 is allowed only in public variables.
4745 We don't complain about parms either, but that is because
4746 a better error message can be made later. */
4748 if (VOID_TYPE_P (type) && decl_context != PARM
4749 && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4750 && ((specbits & (1 << (int) RID_EXTERN))
4751 || (current_binding_level == global_binding_level
4753 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
4755 error ("variable or field `%s' declared void", name);
4756 type = integer_type_node;
4759 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4760 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4765 if (decl_context == PARM)
4767 tree type_as_written;
4770 /* A parameter declared as an array of T is really a pointer to T.
4771 One declared as a function is really a pointer to a function. */
4773 if (TREE_CODE (type) == ARRAY_TYPE)
4775 /* Transfer const-ness of array into that of type pointed to. */
4776 type = TREE_TYPE (type);
4778 type = c_build_qualified_type (type, type_quals);
4779 type = build_pointer_type (type);
4780 type_quals = TYPE_UNQUALIFIED;
4781 if (array_ptr_quals)
4783 tree new_ptr_quals, new_ptr_attrs;
4785 split_specs_attrs (array_ptr_quals, &new_ptr_quals, &new_ptr_attrs);
4786 /* We don't yet implement attributes in this context. */
4787 if (new_ptr_attrs != NULL_TREE)
4788 warning ("attributes in parameter array declarator ignored");
4793 for (; new_ptr_quals; new_ptr_quals = TREE_CHAIN (new_ptr_quals))
4795 tree qualifier = TREE_VALUE (new_ptr_quals);
4797 if (C_IS_RESERVED_WORD (qualifier))
4799 if (C_RID_CODE (qualifier) == RID_CONST)
4801 else if (C_RID_CODE (qualifier) == RID_VOLATILE)
4803 else if (C_RID_CODE (qualifier) == RID_RESTRICT)
4813 error ("invalid type modifier within array declarator");
4815 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4816 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4817 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4821 else if (TREE_CODE (type) == FUNCTION_TYPE)
4823 if (pedantic && type_quals)
4824 pedwarn ("ISO C forbids qualified function types");
4826 type = c_build_qualified_type (type, type_quals);
4827 type = build_pointer_type (type);
4828 type_quals = TYPE_UNQUALIFIED;
4830 else if (type_quals)
4831 type = c_build_qualified_type (type, type_quals);
4833 type_as_written = type;
4835 decl = build_decl (PARM_DECL, declarator, type);
4837 C_DECL_VARIABLE_SIZE (decl) = 1;
4839 /* Compute the type actually passed in the parmlist,
4840 for the case where there is no prototype.
4841 (For example, shorts and chars are passed as ints.)
4842 When there is a prototype, this is overridden later. */
4844 if (type == error_mark_node)
4845 promoted_type = type;
4848 promoted_type = simple_type_promotes_to (type);
4849 if (! promoted_type)
4850 promoted_type = type;
4853 DECL_ARG_TYPE (decl) = promoted_type;
4854 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
4856 else if (decl_context == FIELD)
4858 /* Structure field. It may not be a function. */
4860 if (TREE_CODE (type) == FUNCTION_TYPE)
4862 error ("field `%s' declared as a function", name);
4863 type = build_pointer_type (type);
4865 else if (TREE_CODE (type) != ERROR_MARK
4866 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
4868 error ("field `%s' has incomplete type", name);
4869 type = error_mark_node;
4871 /* Move type qualifiers down to element of an array. */
4872 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4874 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4876 TYPE_DOMAIN (type));
4878 /* Leave the field const or volatile as well. */
4879 type_quals = TYPE_UNQUALIFIED;
4882 decl = build_decl (FIELD_DECL, declarator, type);
4883 DECL_NONADDRESSABLE_P (decl) = bitfield;
4886 C_DECL_VARIABLE_SIZE (decl) = 1;
4888 else if (TREE_CODE (type) == FUNCTION_TYPE)
4890 /* Every function declaration is "external"
4891 except for those which are inside a function body
4892 in which `auto' is used.
4893 That is a case not specified by ANSI C,
4894 and we use it for forward declarations for nested functions. */
4895 int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
4896 || current_binding_level == global_binding_level);
4898 if (specbits & (1 << (int) RID_AUTO)
4899 && (pedantic || current_binding_level == global_binding_level))
4900 pedwarn ("invalid storage class for function `%s'", name);
4901 if (specbits & (1 << (int) RID_REGISTER))
4902 error ("invalid storage class for function `%s'", name);
4903 /* Function declaration not at top level.
4904 Storage classes other than `extern' are not allowed
4905 and `extern' makes no difference. */
4906 if (current_binding_level != global_binding_level
4907 && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
4909 pedwarn ("invalid storage class for function `%s'", name);
4911 decl = build_decl (FUNCTION_DECL, declarator, type);
4912 decl = build_decl_attribute_variant (decl, decl_attr);
4914 DECL_LANG_SPECIFIC (decl) = (struct lang_decl *)
4915 ggc_alloc_cleared (sizeof (struct lang_decl));
4917 if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
4918 pedwarn ("ISO C forbids qualified function types");
4920 /* GNU C interprets a `volatile void' return type to indicate
4921 that the function does not return. */
4922 if ((type_quals & TYPE_QUAL_VOLATILE)
4923 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
4924 warning ("`noreturn' function returns non-void value");
4927 DECL_EXTERNAL (decl) = 1;
4928 /* Record absence of global scope for `static' or `auto'. */
4930 = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
4933 C_FUNCTION_IMPLICIT_INT (decl) = 1;
4935 /* Record presence of `inline', if it is reasonable. */
4936 if (MAIN_NAME_P (declarator))
4939 warning ("cannot inline function `main'");
4943 /* Assume that otherwise the function can be inlined. */
4944 DECL_DECLARED_INLINE_P (decl) = 1;
4946 /* Do not mark bare declarations as DECL_INLINE. Doing so
4947 in the presence of multiple declarations can result in
4948 the abstract origin pointing between the declarations,
4949 which will confuse dwarf2out. */
4952 DECL_INLINE (decl) = 1;
4953 if (specbits & (1 << (int) RID_EXTERN))
4954 current_extern_inline = 1;
4957 /* If -finline-functions, assume it can be inlined. This does
4958 two things: let the function be deferred until it is actually
4959 needed, and let dwarf2 know that the function is inlinable. */
4960 else if (flag_inline_trees == 2 && initialized)
4962 DECL_INLINE (decl) = 1;
4963 DECL_DECLARED_INLINE_P (decl) = 0;
4968 /* It's a variable. */
4969 /* An uninitialized decl with `extern' is a reference. */
4970 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
4972 /* Move type qualifiers down to element of an array. */
4973 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4975 int saved_align = TYPE_ALIGN(type);
4976 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4978 TYPE_DOMAIN (type));
4979 TYPE_ALIGN (type) = saved_align;
4980 #if 0 /* Leave the variable const or volatile as well. */
4981 type_quals = TYPE_UNQUALIFIED;
4984 else if (type_quals)
4985 type = c_build_qualified_type (type, type_quals);
4987 decl = build_decl (VAR_DECL, declarator, type);
4989 C_DECL_VARIABLE_SIZE (decl) = 1;
4992 pedwarn_with_decl (decl, "variable `%s' declared `inline'");
4994 DECL_EXTERNAL (decl) = extern_ref;
4995 /* At top level, the presence of a `static' or `register' storage
4996 class specifier, or the absence of all storage class specifiers
4997 makes this declaration a definition (perhaps tentative). Also,
4998 the absence of both `static' and `register' makes it public. */
4999 if (current_binding_level == global_binding_level)
5003 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)));
5004 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
5006 /* Not at top level, only `static' makes a static definition. */
5009 TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
5010 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
5014 /* Record `register' declaration for warnings on &
5015 and in case doing stupid register allocation. */
5017 if (specbits & (1 << (int) RID_REGISTER))
5018 DECL_REGISTER (decl) = 1;
5020 /* Record constancy and volatility. */
5021 c_apply_type_quals_to_decl (type_quals, decl);
5023 /* If a type has volatile components, it should be stored in memory.
5024 Otherwise, the fact that those components are volatile
5025 will be ignored, and would even crash the compiler. */
5026 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
5027 mark_addressable (decl);
5029 decl_attributes (&decl, returned_attrs, 0);
5035 /* Decode the parameter-list info for a function type or function definition.
5036 The argument is the value returned by `get_parm_info' (or made in parse.y
5037 if there is an identifier list instead of a parameter decl list).
5038 These two functions are separate because when a function returns
5039 or receives functions then each is called multiple times but the order
5040 of calls is different. The last call to `grokparms' is always the one
5041 that contains the formal parameter names of a function definition.
5043 Store in `last_function_parms' a chain of the decls of parms.
5044 Also store in `last_function_parm_tags' a chain of the struct, union,
5045 and enum tags declared among the parms.
5047 Return a list of arg types to use in the FUNCTION_TYPE for this function.
5049 FUNCDEF_FLAG is nonzero for a function definition, 0 for
5050 a mere declaration. A nonempty identifier-list gets an error message
5051 when FUNCDEF_FLAG is zero. */
5054 grokparms (parms_info, funcdef_flag)
5058 tree first_parm = TREE_CHAIN (parms_info);
5060 last_function_parms = TREE_PURPOSE (parms_info);
5061 last_function_parm_tags = TREE_VALUE (parms_info);
5063 if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
5064 && !in_system_header)
5065 warning ("function declaration isn't a prototype");
5068 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
5071 pedwarn ("parameter names (without types) in function declaration");
5073 last_function_parms = first_parm;
5080 /* We no longer test FUNCDEF_FLAG.
5081 If the arg types are incomplete in a declaration,
5082 they must include undefined tags.
5083 These tags can never be defined in the scope of the declaration,
5084 so the types can never be completed,
5085 and no call can be compiled successfully. */
5087 /* In a fcn definition, arg types must be complete. */
5090 for (parm = last_function_parms, typelt = first_parm;
5092 parm = TREE_CHAIN (parm))
5093 /* Skip over any enumeration constants declared here. */
5094 if (TREE_CODE (parm) == PARM_DECL)
5096 /* Barf if the parameter itself has an incomplete type. */
5097 tree type = TREE_VALUE (typelt);
5098 if (type == error_mark_node)
5100 if (!COMPLETE_TYPE_P (type))
5102 if (funcdef_flag && DECL_NAME (parm) != 0)
5103 error ("parameter `%s' has incomplete type",
5104 IDENTIFIER_POINTER (DECL_NAME (parm)));
5106 warning ("parameter has incomplete type");
5109 TREE_VALUE (typelt) = error_mark_node;
5110 TREE_TYPE (parm) = error_mark_node;
5114 /* This has been replaced by parm_tags_warning, which
5115 uses a more accurate criterion for what to warn
5119 /* Now warn if is a pointer to an incomplete type. */
5120 while (TREE_CODE (type) == POINTER_TYPE
5121 || TREE_CODE (type) == REFERENCE_TYPE)
5122 type = TREE_TYPE (type);
5123 type = TYPE_MAIN_VARIANT (type);
5124 if (!COMPLETE_TYPE_P (type))
5126 if (DECL_NAME (parm) != 0)
5127 warning ("parameter `%s' points to incomplete type",
5128 IDENTIFIER_POINTER (DECL_NAME (parm)));
5130 warning ("parameter points to incomplete type");
5134 typelt = TREE_CHAIN (typelt);
5141 /* Return a tree_list node with info on a parameter list just parsed.
5142 The TREE_PURPOSE is a chain of decls of those parms.
5143 The TREE_VALUE is a list of structure, union and enum tags defined.
5144 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
5145 This tree_list node is later fed to `grokparms'.
5147 VOID_AT_END nonzero means append `void' to the end of the type-list.
5148 Zero means the parmlist ended with an ellipsis so don't append `void'. */
5151 get_parm_info (void_at_end)
5157 tree tags = gettags ();
5158 tree parms = getdecls ();
5160 tree order = current_binding_level->parm_order;
5162 /* Just `void' (and no ellipsis) is special. There are really no parms.
5163 But if the `void' is qualified (by `const' or `volatile') or has a
5164 storage class specifier (`register'), then the behavior is undefined;
5165 by not counting it as the special case of `void' we will cause an
5166 error later. Typedefs for `void' are OK (see DR#157). */
5167 if (void_at_end && parms != 0
5168 && TREE_CHAIN (parms) == 0
5169 && VOID_TYPE_P (TREE_TYPE (parms))
5170 && ! TREE_THIS_VOLATILE (parms)
5171 && ! TREE_READONLY (parms)
5172 && ! DECL_REGISTER (parms)
5173 && DECL_NAME (parms) == 0)
5176 storedecls (NULL_TREE);
5177 return tree_cons (NULL_TREE, NULL_TREE,
5178 tree_cons (NULL_TREE, void_type_node, NULL_TREE));
5181 /* Extract enumerator values and other non-parms declared with the parms.
5182 Likewise any forward parm decls that didn't have real parm decls. */
5183 for (decl = parms; decl;)
5185 tree next = TREE_CHAIN (decl);
5187 if (TREE_CODE (decl) != PARM_DECL)
5189 TREE_CHAIN (decl) = new_parms;
5192 else if (TREE_ASM_WRITTEN (decl))
5194 error_with_decl (decl,
5195 "parameter `%s' has just a forward declaration");
5196 TREE_CHAIN (decl) = new_parms;
5202 /* Put the parm decls back in the order they were in in the parm list. */
5203 for (t = order; t; t = TREE_CHAIN (t))
5206 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
5208 TREE_CHAIN (TREE_VALUE (t)) = 0;
5211 new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
5214 /* Store the parmlist in the binding level since the old one
5215 is no longer a valid list. (We have changed the chain pointers.) */
5216 storedecls (new_parms);
5218 for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
5219 /* There may also be declarations for enumerators if an enumeration
5220 type is declared among the parms. Ignore them here. */
5221 if (TREE_CODE (decl) == PARM_DECL)
5223 /* Since there is a prototype,
5224 args are passed in their declared types. */
5225 tree type = TREE_TYPE (decl);
5226 DECL_ARG_TYPE (decl) = type;
5227 if (PROMOTE_PROTOTYPES
5228 && INTEGRAL_TYPE_P (type)
5229 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
5230 DECL_ARG_TYPE (decl) = integer_type_node;
5232 types = tree_cons (NULL_TREE, TREE_TYPE (decl), types);
5233 if (VOID_TYPE_P (TREE_VALUE (types)) && ! erred
5234 && DECL_NAME (decl) == 0)
5236 error ("`void' in parameter list must be the entire list");
5242 return tree_cons (new_parms, tags,
5243 nreverse (tree_cons (NULL_TREE, void_type_node, types)));
5245 return tree_cons (new_parms, tags, nreverse (types));
5248 /* At end of parameter list, warn about any struct, union or enum tags
5249 defined within. Do so because these types cannot ever become complete. */
5252 parmlist_tags_warning ()
5257 for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
5259 enum tree_code code = TREE_CODE (TREE_VALUE (elt));
5260 /* An anonymous union parm type is meaningful as a GNU extension.
5261 So don't warn for that. */
5262 if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic)
5264 if (TREE_PURPOSE (elt) != 0)
5266 if (code == RECORD_TYPE)
5267 warning ("`struct %s' declared inside parameter list",
5268 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
5269 else if (code == UNION_TYPE)
5270 warning ("`union %s' declared inside parameter list",
5271 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
5273 warning ("`enum %s' declared inside parameter list",
5274 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
5278 /* For translation these need to be separate warnings */
5279 if (code == RECORD_TYPE)
5280 warning ("anonymous struct declared inside parameter list");
5281 else if (code == UNION_TYPE)
5282 warning ("anonymous union declared inside parameter list");
5284 warning ("anonymous enum declared inside parameter list");
5288 warning ("its scope is only this definition or declaration, which is probably not what you want");
5294 /* Get the struct, enum or union (CODE says which) with tag NAME.
5295 Define the tag as a forward-reference if it is not defined. */
5298 xref_tag (code, name)
5299 enum tree_code code;
5302 /* If a cross reference is requested, look up the type
5303 already defined for this tag and return it. */
5305 tree ref = lookup_tag (code, name, current_binding_level, 0);
5306 /* If this is the right type of tag, return what we found.
5307 (This reference will be shadowed by shadow_tag later if appropriate.)
5308 If this is the wrong type of tag, do not return it. If it was the
5309 wrong type in the same binding level, we will have had an error
5310 message already; if in a different binding level and declaring
5311 a name, pending_xref_error will give an error message; but if in a
5312 different binding level and not declaring a name, this tag should
5313 shadow the previous declaration of a different type of tag, and
5314 this would not work properly if we return the reference found.
5315 (For example, with "struct foo" in an outer scope, "union foo;"
5316 must shadow that tag with a new one of union type.) */
5317 if (ref && TREE_CODE (ref) == code)
5320 /* If no such tag is yet defined, create a forward-reference node
5321 and record it as the "definition".
5322 When a real declaration of this type is found,
5323 the forward-reference will be altered into a real type. */
5325 ref = make_node (code);
5326 if (code == ENUMERAL_TYPE)
5328 /* Give the type a default layout like unsigned int
5329 to avoid crashing if it does not get defined. */
5330 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
5331 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5332 TYPE_USER_ALIGN (ref) = 0;
5333 TREE_UNSIGNED (ref) = 1;
5334 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5335 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5336 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5339 pushtag (name, ref);
5344 /* Make sure that the tag NAME is defined *in the current binding level*
5345 at least as a forward reference.
5346 CODE says which kind of tag NAME ought to be. */
5349 start_struct (code, name)
5350 enum tree_code code;
5353 /* If there is already a tag defined at this binding level
5354 (as a forward reference), just return it. */
5359 ref = lookup_tag (code, name, current_binding_level, 1);
5360 if (ref && TREE_CODE (ref) == code)
5362 C_TYPE_BEING_DEFINED (ref) = 1;
5363 TYPE_PACKED (ref) = flag_pack_struct;
5364 if (TYPE_FIELDS (ref))
5366 if (code == UNION_TYPE)
5367 error ("redefinition of `union %s'",
5368 IDENTIFIER_POINTER (name));
5370 error ("redefinition of `struct %s'",
5371 IDENTIFIER_POINTER (name));
5377 /* Otherwise create a forward-reference just so the tag is in scope. */
5379 ref = make_node (code);
5380 pushtag (name, ref);
5381 C_TYPE_BEING_DEFINED (ref) = 1;
5382 TYPE_PACKED (ref) = flag_pack_struct;
5386 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
5387 of a structure component, returning a FIELD_DECL node.
5388 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
5390 This is done during the parsing of the struct declaration.
5391 The FIELD_DECL nodes are chained together and the lot of them
5392 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5395 grokfield (filename, line, declarator, declspecs, width)
5396 const char *filename ATTRIBUTE_UNUSED;
5397 int line ATTRIBUTE_UNUSED;
5398 tree declarator, declspecs, width;
5402 if (declarator == NULL_TREE && width == NULL_TREE)
5404 /* This is an unnamed decl. We only support unnamed
5405 structs/unions, so check for other things and refuse them. */
5406 if (TREE_CODE (TREE_VALUE (declspecs)) != RECORD_TYPE
5407 && TREE_CODE (TREE_VALUE (declspecs)) != UNION_TYPE)
5409 error ("unnamed fields of type other than struct or union are not allowed");
5414 value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
5416 finish_decl (value, NULL_TREE, NULL_TREE);
5417 DECL_INITIAL (value) = width;
5419 maybe_objc_check_decl (value);
5423 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5424 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5425 ATTRIBUTES are attributes to be applied to the structure. */
5428 finish_struct (t, fieldlist, attributes)
5434 int toplevel = global_binding_level == current_binding_level;
5435 int saw_named_field;
5437 /* If this type was previously laid out as a forward reference,
5438 make sure we lay it out again. */
5442 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5444 /* Nameless union parm types are useful as GCC extension. */
5445 if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
5446 /* Otherwise, warn about any struct or union def. in parmlist. */
5447 if (in_parm_level_p ())
5450 pedwarn ("%s defined inside parms",
5451 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure"));
5453 warning ("%s defined inside parms",
5454 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure"));
5459 for (x = fieldlist; x; x = TREE_CHAIN (x))
5460 if (DECL_NAME (x) != 0)
5464 pedwarn ("%s has no %s",
5465 TREE_CODE (t) == UNION_TYPE ? _("union") : _("struct"),
5466 fieldlist ? _("named members") : _("members"));
5469 /* Install struct as DECL_CONTEXT of each field decl.
5470 Also process specified field sizes,m which is found in the DECL_INITIAL.
5471 Store 0 there, except for ": 0" fields (so we can find them
5472 and delete them, below). */
5474 saw_named_field = 0;
5475 for (x = fieldlist; x; x = TREE_CHAIN (x))
5477 DECL_CONTEXT (x) = t;
5478 DECL_PACKED (x) |= TYPE_PACKED (t);
5480 /* If any field is const, the structure type is pseudo-const. */
5481 if (TREE_READONLY (x))
5482 C_TYPE_FIELDS_READONLY (t) = 1;
5485 /* A field that is pseudo-const makes the structure likewise. */
5486 tree t1 = TREE_TYPE (x);
5487 while (TREE_CODE (t1) == ARRAY_TYPE)
5488 t1 = TREE_TYPE (t1);
5489 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5490 && C_TYPE_FIELDS_READONLY (t1))
5491 C_TYPE_FIELDS_READONLY (t) = 1;
5494 /* Any field that is volatile means variables of this type must be
5495 treated in some ways as volatile. */
5496 if (TREE_THIS_VOLATILE (x))
5497 C_TYPE_FIELDS_VOLATILE (t) = 1;
5499 /* Any field of nominal variable size implies structure is too. */
5500 if (C_DECL_VARIABLE_SIZE (x))
5501 C_TYPE_VARIABLE_SIZE (t) = 1;
5503 /* Detect invalid nested redefinition. */
5504 if (TREE_TYPE (x) == t)
5505 error ("nested redefinition of `%s'",
5506 IDENTIFIER_POINTER (TYPE_NAME (t)));
5508 /* Detect invalid bit-field size. */
5509 if (DECL_INITIAL (x))
5510 STRIP_NOPS (DECL_INITIAL (x));
5511 if (DECL_INITIAL (x))
5513 if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST)
5514 constant_expression_warning (DECL_INITIAL (x));
5518 "bit-field `%s' width not an integer constant");
5519 DECL_INITIAL (x) = NULL;
5523 /* Detect invalid bit-field type. */
5524 if (DECL_INITIAL (x)
5525 && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
5526 && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE
5527 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
5529 error_with_decl (x, "bit-field `%s' has invalid type");
5530 DECL_INITIAL (x) = NULL;
5533 if (DECL_INITIAL (x) && pedantic
5534 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
5535 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
5536 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node
5537 /* Accept an enum that's equivalent to int or unsigned int. */
5538 && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5539 && (TYPE_PRECISION (TREE_TYPE (x))
5540 == TYPE_PRECISION (integer_type_node))))
5541 pedwarn_with_decl (x, "bit-field `%s' type invalid in ISO C");
5543 /* Detect and ignore out of range field width and process valid
5545 if (DECL_INITIAL (x))
5548 = (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node
5549 ? CHAR_TYPE_SIZE : TYPE_PRECISION (TREE_TYPE (x)));
5551 if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
5552 error_with_decl (x, "negative width in bit-field `%s'");
5553 else if (0 < compare_tree_int (DECL_INITIAL (x), max_width))
5554 pedwarn_with_decl (x, "width of `%s' exceeds its type");
5555 else if (integer_zerop (DECL_INITIAL (x)) && DECL_NAME (x) != 0)
5556 error_with_decl (x, "zero width for bit-field `%s'");
5559 /* The test above has assured us that TREE_INT_CST_HIGH is 0. */
5560 unsigned HOST_WIDE_INT width
5561 = tree_low_cst (DECL_INITIAL (x), 1);
5563 if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5564 && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
5565 TREE_UNSIGNED (TREE_TYPE (x)))
5567 < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
5568 TREE_UNSIGNED (TREE_TYPE (x))))))
5569 warning_with_decl (x,
5570 "`%s' is narrower than values of its type");
5572 DECL_SIZE (x) = bitsize_int (width);
5573 DECL_BIT_FIELD (x) = 1;
5574 SET_DECL_C_BIT_FIELD (x);
5577 && ! (* targetm.ms_bitfield_layout_p) (t))
5579 /* field size 0 => force desired amount of alignment. */
5580 #ifdef EMPTY_FIELD_BOUNDARY
5581 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
5583 #ifdef PCC_BITFIELD_TYPE_MATTERS
5584 if (PCC_BITFIELD_TYPE_MATTERS)
5586 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
5587 TYPE_ALIGN (TREE_TYPE (x)));
5588 DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
5595 else if (TREE_TYPE (x) != error_mark_node)
5597 unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
5598 : TYPE_ALIGN (TREE_TYPE (x)));
5600 /* Non-bit-fields are aligned for their type, except packed
5601 fields which require only BITS_PER_UNIT alignment. */
5602 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
5603 if (! DECL_PACKED (x))
5604 DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
5607 DECL_INITIAL (x) = 0;
5609 /* Detect flexible array member in an invalid context. */
5610 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5611 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
5612 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
5613 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
5615 if (TREE_CODE (t) == UNION_TYPE)
5616 error_with_decl (x, "flexible array member in union");
5617 else if (TREE_CHAIN (x) != NULL_TREE)
5618 error_with_decl (x, "flexible array member not at end of struct");
5619 else if (! saw_named_field)
5620 error_with_decl (x, "flexible array member in otherwise empty struct");
5623 saw_named_field = 1;
5626 /* Delete all duplicate fields from the fieldlist */
5627 for (x = fieldlist; x && TREE_CHAIN (x);)
5628 /* Anonymous fields aren't duplicates. */
5629 if (DECL_NAME (TREE_CHAIN (x)) == 0)
5637 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
5643 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
5645 error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
5646 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
5652 /* Now we have the nearly final fieldlist. Record it,
5653 then lay out the structure or union (including the fields). */
5655 TYPE_FIELDS (t) = fieldlist;
5659 /* Delete all zero-width bit-fields from the fieldlist */
5661 tree *fieldlistp = &fieldlist;
5663 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
5664 *fieldlistp = TREE_CHAIN (*fieldlistp);
5666 fieldlistp = &TREE_CHAIN (*fieldlistp);
5669 /* Now we have the truly final field list.
5670 Store it in this type and in the variants. */
5672 TYPE_FIELDS (t) = fieldlist;
5674 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5676 TYPE_FIELDS (x) = TYPE_FIELDS (t);
5677 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
5678 TYPE_ALIGN (x) = TYPE_ALIGN (t);
5679 TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t);
5682 /* If this was supposed to be a transparent union, but we can't
5683 make it one, warn and turn off the flag. */
5684 if (TREE_CODE (t) == UNION_TYPE
5685 && TYPE_TRANSPARENT_UNION (t)
5686 && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))
5688 TYPE_TRANSPARENT_UNION (t) = 0;
5689 warning ("union cannot be made transparent");
5692 /* If this structure or union completes the type of any previous
5693 variable declaration, lay it out and output its rtl. */
5695 if (current_binding_level->n_incomplete != 0)
5698 for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
5700 if (TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TYPE_MAIN_VARIANT (t)
5701 && TREE_CODE (decl) != TYPE_DECL)
5703 layout_decl (decl, 0);
5704 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
5705 maybe_objc_check_decl (decl);
5706 rest_of_decl_compilation (decl, NULL, toplevel, 0);
5709 if (--current_binding_level->n_incomplete == 0)
5712 else if (!COMPLETE_TYPE_P (TREE_TYPE (decl))
5713 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
5715 tree element = TREE_TYPE (decl);
5716 while (TREE_CODE (element) == ARRAY_TYPE)
5717 element = TREE_TYPE (element);
5720 layout_array_type (TREE_TYPE (decl));
5721 if (TREE_CODE (decl) != TYPE_DECL)
5723 layout_decl (decl, 0);
5724 maybe_objc_check_decl (decl);
5725 rest_of_decl_compilation (decl, NULL, toplevel, 0);
5729 if (--current_binding_level->n_incomplete == 0)
5736 /* Finish debugging output for this type. */
5737 rest_of_type_compilation (t, toplevel);
5742 /* Lay out the type T, and its element type, and so on. */
5745 layout_array_type (t)
5748 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5749 layout_array_type (TREE_TYPE (t));
5753 /* Begin compiling the definition of an enumeration type.
5754 NAME is its name (or null if anonymous).
5755 Returns the type object, as yet incomplete.
5756 Also records info about it so that build_enumerator
5757 may be used to declare the individual values as they are read. */
5765 /* If this is the real definition for a previous forward reference,
5766 fill in the contents in the same object that used to be the
5767 forward reference. */
5770 enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
5772 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
5774 enumtype = make_node (ENUMERAL_TYPE);
5775 pushtag (name, enumtype);
5778 C_TYPE_BEING_DEFINED (enumtype) = 1;
5780 if (TYPE_VALUES (enumtype) != 0)
5782 /* This enum is a named one that has been declared already. */
5783 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
5785 /* Completely replace its old definition.
5786 The old enumerators remain defined, however. */
5787 TYPE_VALUES (enumtype) = 0;
5790 enum_next_value = integer_zero_node;
5793 if (flag_short_enums)
5794 TYPE_PACKED (enumtype) = 1;
5799 /* After processing and defining all the values of an enumeration type,
5800 install their decls in the enumeration type and finish it off.
5801 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5802 and ATTRIBUTES are the specified attributes.
5803 Returns ENUMTYPE. */
5806 finish_enum (enumtype, values, attributes)
5812 tree minnode = 0, maxnode = 0, enum_value_type;
5813 int precision, unsign;
5814 int toplevel = (global_binding_level == current_binding_level);
5816 if (in_parm_level_p ())
5817 warning ("enum defined inside parms");
5819 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5821 /* Calculate the maximum value of any enumerator in this type. */
5823 if (values == error_mark_node)
5824 minnode = maxnode = integer_zero_node;
5827 minnode = maxnode = TREE_VALUE (values);
5828 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
5830 tree value = TREE_VALUE (pair);
5831 if (tree_int_cst_lt (maxnode, value))
5833 if (tree_int_cst_lt (value, minnode))
5838 /* Construct the final type of this enumeration. It is the same
5839 as one of the integral types - the narrowest one that fits, except
5840 that normally we only go as narrow as int - and signed iff any of
5841 the values are negative. */
5842 unsign = (tree_int_cst_sgn (minnode) >= 0);
5843 precision = MAX (min_precision (minnode, unsign),
5844 min_precision (maxnode, unsign));
5845 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
5847 tree narrowest = type_for_size (precision, unsign);
5850 warning ("enumeration values exceed range of largest integer");
5851 narrowest = long_long_integer_type_node;
5854 precision = TYPE_PRECISION (narrowest);
5857 precision = TYPE_PRECISION (integer_type_node);
5859 if (precision == TYPE_PRECISION (integer_type_node))
5860 enum_value_type = type_for_size (precision, 0);
5862 enum_value_type = enumtype;
5864 TYPE_MIN_VALUE (enumtype) = minnode;
5865 TYPE_MAX_VALUE (enumtype) = maxnode;
5866 TYPE_PRECISION (enumtype) = precision;
5867 TREE_UNSIGNED (enumtype) = unsign;
5868 TYPE_SIZE (enumtype) = 0;
5869 layout_type (enumtype);
5871 if (values != error_mark_node)
5873 /* Change the type of the enumerators to be the enum type. We
5874 need to do this irrespective of the size of the enum, for
5875 proper type checking. Replace the DECL_INITIALs of the
5876 enumerators, and the value slots of the list, with copies
5877 that have the enum type; they cannot be modified in place
5878 because they may be shared (e.g. integer_zero_node) Finally,
5879 change the purpose slots to point to the names of the decls. */
5880 for (pair = values; pair; pair = TREE_CHAIN (pair))
5882 tree enu = TREE_PURPOSE (pair);
5884 TREE_TYPE (enu) = enumtype;
5885 DECL_SIZE (enu) = TYPE_SIZE (enumtype);
5886 DECL_SIZE_UNIT (enu) = TYPE_SIZE_UNIT (enumtype);
5887 DECL_ALIGN (enu) = TYPE_ALIGN (enumtype);
5888 DECL_USER_ALIGN (enu) = TYPE_USER_ALIGN (enumtype);
5889 DECL_MODE (enu) = TYPE_MODE (enumtype);
5891 /* The ISO C Standard mandates enumerators to have type int,
5892 even though the underlying type of an enum type is
5893 unspecified. Here we convert any enumerators that fit in
5894 an int to type int, to avoid promotions to unsigned types
5895 when comparing integers with enumerators that fit in the
5896 int range. When -pedantic is given, build_enumerator()
5897 would have already taken care of those that don't fit. */
5898 if (int_fits_type_p (DECL_INITIAL (enu), enum_value_type))
5899 DECL_INITIAL (enu) = convert (enum_value_type, DECL_INITIAL (enu));
5901 DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu));
5903 TREE_PURPOSE (pair) = DECL_NAME (enu);
5904 TREE_VALUE (pair) = DECL_INITIAL (enu);
5907 TYPE_VALUES (enumtype) = values;
5910 /* Fix up all variant types of this enum type. */
5911 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
5913 if (tem == enumtype)
5915 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
5916 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
5917 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
5918 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
5919 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
5920 TYPE_MODE (tem) = TYPE_MODE (enumtype);
5921 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
5922 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
5923 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
5924 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
5927 /* Finish debugging output for this type. */
5928 rest_of_type_compilation (enumtype, toplevel);
5933 /* Build and install a CONST_DECL for one value of the
5934 current enumeration type (one that was begun with start_enum).
5935 Return a tree-list containing the CONST_DECL and its value.
5936 Assignment of sequential values by default is handled here. */
5939 build_enumerator (name, value)
5944 /* Validate and default VALUE. */
5946 /* Remove no-op casts from the value. */
5948 STRIP_TYPE_NOPS (value);
5952 if (TREE_CODE (value) == INTEGER_CST)
5954 value = default_conversion (value);
5955 constant_expression_warning (value);
5959 error ("enumerator value for `%s' not integer constant",
5960 IDENTIFIER_POINTER (name));
5965 /* Default based on previous value. */
5966 /* It should no longer be possible to have NON_LVALUE_EXPR
5970 value = enum_next_value;
5972 error ("overflow in enumeration values");
5975 if (pedantic && ! int_fits_type_p (value, integer_type_node))
5977 pedwarn ("ISO C restricts enumerator values to range of `int'");
5978 value = convert (integer_type_node, value);
5981 /* Set basis for default for next value. */
5982 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
5983 enum_overflow = tree_int_cst_lt (enum_next_value, value);
5985 /* Now create a declaration for the enum value name. */
5987 type = TREE_TYPE (value);
5988 type = type_for_size (MAX (TYPE_PRECISION (type),
5989 TYPE_PRECISION (integer_type_node)),
5990 (TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node)
5991 && TREE_UNSIGNED (type)));
5993 decl = build_decl (CONST_DECL, name, type);
5994 DECL_INITIAL (decl) = convert (type, value);
5997 return tree_cons (decl, value, NULL_TREE);
6001 /* Create the FUNCTION_DECL for a function definition.
6002 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
6003 the declaration; they describe the function's name and the type it returns,
6004 but twisted together in a fashion that parallels the syntax of C.
6006 This function creates a binding context for the function body
6007 as well as setting up the FUNCTION_DECL in current_function_decl.
6009 Returns 1 on success. If the DECLARATOR is not suitable for a function
6010 (it defines a datum instead), we return 0, which tells
6011 yyparse to report a parse error. */
6014 start_function (declspecs, declarator, attributes)
6015 tree declarator, declspecs, attributes;
6017 tree decl1, old_decl;
6019 int old_immediate_size_expand = immediate_size_expand;
6021 current_function_returns_value = 0; /* Assume, until we see it does. */
6022 current_function_returns_null = 0;
6023 current_function_returns_abnormally = 0;
6024 warn_about_return_type = 0;
6025 current_extern_inline = 0;
6026 c_function_varargs = 0;
6028 shadowed_labels = 0;
6030 /* Don't expand any sizes in the return type of the function. */
6031 immediate_size_expand = 0;
6033 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
6035 /* If the declarator is not suitable for a function definition,
6036 cause a syntax error. */
6039 immediate_size_expand = old_immediate_size_expand;
6043 decl_attributes (&decl1, attributes, 0);
6045 if (DECL_DECLARED_INLINE_P (decl1)
6046 && DECL_UNINLINABLE (decl1)
6047 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
6048 warning_with_decl (decl1,
6049 "inline function `%s' given attribute noinline");
6051 announce_function (decl1);
6053 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
6055 error ("return type is an incomplete type");
6056 /* Make it return void instead. */
6058 = build_function_type (void_type_node,
6059 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
6062 if (warn_about_return_type)
6063 pedwarn_c99 ("return type defaults to `int'");
6065 /* Save the parm names or decls from this function's declarator
6066 where store_parm_decls will find them. */
6067 current_function_parms = last_function_parms;
6068 current_function_parm_tags = last_function_parm_tags;
6070 /* Make the init_value nonzero so pushdecl knows this is not tentative.
6071 error_mark_node is replaced below (in poplevel) with the BLOCK. */
6072 DECL_INITIAL (decl1) = error_mark_node;
6074 /* If this definition isn't a prototype and we had a prototype declaration
6075 before, copy the arg type info from that prototype.
6076 But not if what we had before was a builtin function. */
6077 old_decl = lookup_name_current_level (DECL_NAME (decl1));
6078 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
6079 && !DECL_BUILT_IN (old_decl)
6080 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6081 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
6082 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
6084 TREE_TYPE (decl1) = TREE_TYPE (old_decl);
6085 current_function_prototype_file = DECL_SOURCE_FILE (old_decl);
6086 current_function_prototype_line = DECL_SOURCE_LINE (old_decl);
6089 /* If there is no explicit declaration, look for any out-of-scope implicit
6092 old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1));
6094 /* Optionally warn of old-fashioned def with no previous prototype. */
6095 if (warn_strict_prototypes
6096 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
6098 && (TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0
6099 || (DECL_BUILT_IN (old_decl)
6100 && ! C_DECL_ANTICIPATED (old_decl)))))
6101 warning ("function declaration isn't a prototype");
6102 /* Optionally warn of any global def with no previous prototype. */
6103 else if (warn_missing_prototypes
6104 && TREE_PUBLIC (decl1)
6106 && (TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0
6107 || (DECL_BUILT_IN (old_decl)
6108 && ! C_DECL_ANTICIPATED (old_decl))))
6109 && ! MAIN_NAME_P (DECL_NAME (decl1)))
6110 warning_with_decl (decl1, "no previous prototype for `%s'");
6111 /* Optionally warn of any def with no previous prototype
6112 if the function has already been used. */
6113 else if (warn_missing_prototypes
6114 && old_decl != 0 && TREE_USED (old_decl)
6115 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
6116 warning_with_decl (decl1,
6117 "`%s' was used with no prototype before its definition");
6118 /* Optionally warn of any global def with no previous declaration. */
6119 else if (warn_missing_declarations
6120 && TREE_PUBLIC (decl1)
6122 && ! MAIN_NAME_P (DECL_NAME (decl1)))
6123 warning_with_decl (decl1, "no previous declaration for `%s'");
6124 /* Optionally warn of any def with no previous declaration
6125 if the function has already been used. */
6126 else if (warn_missing_declarations
6127 && old_decl != 0 && TREE_USED (old_decl)
6128 && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)))
6129 warning_with_decl (decl1,
6130 "`%s' was used with no declaration before its definition");
6132 /* This is a definition, not a reference.
6133 So normally clear DECL_EXTERNAL.
6134 However, `extern inline' acts like a declaration
6135 except for defining how to inline. So set DECL_EXTERNAL in that case. */
6136 DECL_EXTERNAL (decl1) = current_extern_inline;
6138 /* This function exists in static storage.
6139 (This does not mean `static' in the C sense!) */
6140 TREE_STATIC (decl1) = 1;
6142 /* A nested function is not global. */
6143 if (current_function_decl != 0)
6144 TREE_PUBLIC (decl1) = 0;
6146 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
6147 if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
6152 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6153 != integer_type_node)
6154 pedwarn_with_decl (decl1, "return type of `%s' is not `int'");
6156 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
6157 args = TREE_CHAIN (args))
6159 tree type = args ? TREE_VALUE (args) : 0;
6161 if (type == void_type_node)
6168 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
6169 pedwarn_with_decl (decl1,
6170 "first argument of `%s' should be `int'");
6174 if (TREE_CODE (type) != POINTER_TYPE
6175 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
6176 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
6178 pedwarn_with_decl (decl1,
6179 "second argument of `%s' should be `char **'");
6183 if (TREE_CODE (type) != POINTER_TYPE
6184 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
6185 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
6187 pedwarn_with_decl (decl1,
6188 "third argument of `%s' should probably be `char **'");
6193 /* It is intentional that this message does not mention the third
6194 argument because it's only mentioned in an appendix of the
6196 if (argct > 0 && (argct < 2 || argct > 3))
6197 pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments");
6199 if (! TREE_PUBLIC (decl1))
6200 pedwarn_with_decl (decl1, "`%s' is normally a non-static function");
6203 /* Record the decl so that the function name is defined.
6204 If we already have a decl for this name, and it is a FUNCTION_DECL,
6205 use the old decl. */
6207 current_function_decl = pushdecl (decl1);
6210 declare_parm_level (1);
6211 current_binding_level->subblocks_tag_transparent = 1;
6213 make_decl_rtl (current_function_decl, NULL);
6215 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
6216 /* Promote the value to int before returning it. */
6217 if (c_promoting_integer_type_p (restype))
6219 /* It retains unsignedness if not really getting wider. */
6220 if (TREE_UNSIGNED (restype)
6221 && (TYPE_PRECISION (restype)
6222 == TYPE_PRECISION (integer_type_node)))
6223 restype = unsigned_type_node;
6225 restype = integer_type_node;
6227 DECL_RESULT (current_function_decl)
6228 = build_decl (RESULT_DECL, NULL_TREE, restype);
6230 /* If this fcn was already referenced via a block-scope `extern' decl
6231 (or an implicit decl), propagate certain information about the usage. */
6232 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
6233 TREE_ADDRESSABLE (current_function_decl) = 1;
6235 immediate_size_expand = old_immediate_size_expand;
6237 start_fname_decls ();
6242 /* Record that this function is going to be a varargs function.
6243 This is called before store_parm_decls, which is too early
6244 to call mark_varargs directly. */
6249 c_function_varargs = 1;
6252 /* Store the parameter declarations into the current function declaration.
6253 This is called after parsing the parameter declarations, before
6254 digesting the body of the function.
6256 For an old-style definition, modify the function's type
6257 to specify at least the number of arguments. */
6262 tree fndecl = current_function_decl;
6265 /* This is either a chain of PARM_DECLs (if a prototype was used)
6266 or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */
6267 tree specparms = current_function_parms;
6269 /* This is a list of types declared among parms in a prototype. */
6270 tree parmtags = current_function_parm_tags;
6272 /* This is a chain of PARM_DECLs from old-style parm declarations. */
6273 tree parmdecls = getdecls ();
6275 /* This is a chain of any other decls that came in among the parm
6276 declarations. If a parm is declared with enum {foo, bar} x;
6277 then CONST_DECLs for foo and bar are put here. */
6280 /* The function containing FNDECL, if any. */
6281 tree context = decl_function_context (fndecl);
6283 /* Nonzero if this definition is written with a prototype. */
6286 int saved_warn_shadow = warn_shadow;
6288 /* Don't re-emit shadow warnings. */
6291 if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
6293 /* This case is when the function was defined with an ANSI prototype.
6294 The parms already have decls, so we need not do anything here
6295 except record them as in effect
6296 and complain if any redundant old-style parm decls were written. */
6307 error_with_decl (fndecl,
6308 "parm types given both in parmlist and separately");
6309 /* Get rid of the erroneous decls; don't keep them on
6310 the list of parms, since they might not be PARM_DECLs. */
6311 for (decl = current_binding_level->names;
6312 decl; decl = TREE_CHAIN (decl))
6313 if (DECL_NAME (decl))
6314 IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
6315 for (link = current_binding_level->shadowed;
6316 link; link = TREE_CHAIN (link))
6317 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
6318 current_binding_level->names = 0;
6319 current_binding_level->shadowed = 0;
6322 specparms = nreverse (specparms);
6323 for (parm = specparms; parm; parm = next)
6325 next = TREE_CHAIN (parm);
6326 if (TREE_CODE (parm) == PARM_DECL)
6328 if (DECL_NAME (parm) == 0)
6329 error_with_decl (parm, "parameter name omitted");
6330 else if (TREE_CODE (TREE_TYPE (parm)) != ERROR_MARK
6331 && VOID_TYPE_P (TREE_TYPE (parm)))
6333 error_with_decl (parm, "parameter `%s' declared void");
6334 /* Change the type to error_mark_node so this parameter
6335 will be ignored by assign_parms. */
6336 TREE_TYPE (parm) = error_mark_node;
6342 /* If we find an enum constant or a type tag,
6343 put it aside for the moment. */
6344 TREE_CHAIN (parm) = 0;
6345 others = chainon (others, parm);
6349 /* Get the decls in their original chain order
6350 and record in the function. */
6351 DECL_ARGUMENTS (fndecl) = getdecls ();
6354 /* If this function takes a variable number of arguments,
6355 add a phony parameter to the end of the parm list,
6356 to represent the position of the first unnamed argument. */
6357 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
6360 tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
6361 /* Let's hope the address of the unnamed parm
6362 won't depend on its type. */
6363 TREE_TYPE (dummy) = integer_type_node;
6364 DECL_ARG_TYPE (dummy) = integer_type_node;
6365 DECL_ARGUMENTS (fndecl) = chainon (DECL_ARGUMENTS (fndecl), dummy);
6369 /* Now pushdecl the enum constants. */
6370 for (parm = others; parm; parm = next)
6372 next = TREE_CHAIN (parm);
6373 if (DECL_NAME (parm) == 0)
6375 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
6377 else if (TREE_CODE (parm) != PARM_DECL)
6381 storetags (chainon (parmtags, gettags ()));
6385 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
6386 each with a parm name as the TREE_VALUE.
6388 PARMDECLS is a chain of declarations for parameters.
6389 Warning! It can also contain CONST_DECLs which are not parameters
6390 but are names of enumerators of any enum types
6391 declared among the parameters.
6393 First match each formal parameter name with its declaration.
6394 Associate decls with the names and store the decls
6395 into the TREE_PURPOSE slots. */
6397 /* We use DECL_WEAK as a flag to show which parameters have been
6398 seen already since it is not used on PARM_DECL or CONST_DECL. */
6399 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
6400 DECL_WEAK (parm) = 0;
6402 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
6404 tree tail, found = NULL;
6406 if (TREE_VALUE (parm) == 0)
6408 error_with_decl (fndecl,
6409 "parameter name missing from parameter list");
6410 TREE_PURPOSE (parm) = 0;
6414 /* See if any of the parmdecls specifies this parm by name.
6415 Ignore any enumerator decls. */
6416 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
6417 if (DECL_NAME (tail) == TREE_VALUE (parm)
6418 && TREE_CODE (tail) == PARM_DECL)
6424 /* If declaration already marked, we have a duplicate name.
6425 Complain, and don't use this decl twice. */
6426 if (found && DECL_WEAK (found))
6428 error_with_decl (found, "multiple parameters named `%s'");
6432 /* If the declaration says "void", complain and ignore it. */
6433 if (found && VOID_TYPE_P (TREE_TYPE (found)))
6435 error_with_decl (found, "parameter `%s' declared void");
6436 TREE_TYPE (found) = integer_type_node;
6437 DECL_ARG_TYPE (found) = integer_type_node;
6438 layout_decl (found, 0);
6441 /* If no declaration found, default to int. */
6444 found = build_decl (PARM_DECL, TREE_VALUE (parm),
6446 DECL_ARG_TYPE (found) = TREE_TYPE (found);
6447 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
6448 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
6450 pedwarn_with_decl (found, "type of `%s' defaults to `int'");
6451 else if (extra_warnings)
6452 warning_with_decl (found, "type of `%s' defaults to `int'");
6456 TREE_PURPOSE (parm) = found;
6458 /* Mark this decl as "already found". */
6459 DECL_WEAK (found) = 1;
6462 /* Put anything which is on the parmdecls chain and which is
6463 not a PARM_DECL onto the list NONPARMS. (The types of
6464 non-parm things which might appear on the list include
6465 enumerators and NULL-named TYPE_DECL nodes.) Complain about
6466 any actual PARM_DECLs not matched with any names. */
6469 for (parm = parmdecls; parm;)
6471 tree next = TREE_CHAIN (parm);
6472 TREE_CHAIN (parm) = 0;
6474 if (TREE_CODE (parm) != PARM_DECL)
6475 nonparms = chainon (nonparms, parm);
6478 /* Complain about args with incomplete types. */
6479 if (!COMPLETE_TYPE_P (TREE_TYPE (parm)))
6481 error_with_decl (parm, "parameter `%s' has incomplete type");
6482 TREE_TYPE (parm) = error_mark_node;
6485 if (! DECL_WEAK (parm))
6487 error_with_decl (parm,
6488 "declaration for parameter `%s' but no such parameter");
6489 /* Pretend the parameter was not missing.
6490 This gets us to a standard state and minimizes
6491 further error messages. */
6493 = chainon (specparms,
6494 tree_cons (parm, NULL_TREE, NULL_TREE));
6501 /* Chain the declarations together in the order of the list of
6502 names. Store that chain in the function decl, replacing the
6505 DECL_ARGUMENTS (fndecl) = 0;
6508 for (last = 0; parm; parm = TREE_CHAIN (parm))
6509 if (TREE_PURPOSE (parm))
6512 DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
6514 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6515 last = TREE_PURPOSE (parm);
6516 TREE_CHAIN (last) = 0;
6520 /* If there was a previous prototype,
6521 set the DECL_ARG_TYPE of each argument according to
6522 the type previously specified, and report any mismatches. */
6524 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
6527 for (parm = DECL_ARGUMENTS (fndecl),
6528 type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
6529 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
6530 != void_type_node));
6531 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6533 if (parm == 0 || type == 0
6534 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6536 error ("number of arguments doesn't match prototype");
6537 error_with_file_and_line (current_function_prototype_file,
6538 current_function_prototype_line,
6539 "prototype declaration");
6542 /* Type for passing arg must be consistent with that
6543 declared for the arg. ISO C says we take the unqualified
6544 type for parameters declared with qualified type. */
6545 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
6546 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
6548 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6549 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6551 /* Adjust argument to match prototype. E.g. a previous
6552 `int foo(float);' prototype causes
6553 `int foo(x) float x; {...}' to be treated like
6554 `int foo(float x) {...}'. This is particularly
6555 useful for argument types like uid_t. */
6556 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6558 if (PROMOTE_PROTOTYPES
6559 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
6560 && TYPE_PRECISION (TREE_TYPE (parm))
6561 < TYPE_PRECISION (integer_type_node))
6562 DECL_ARG_TYPE (parm) = integer_type_node;
6566 pedwarn ("promoted argument `%s' doesn't match prototype",
6567 IDENTIFIER_POINTER (DECL_NAME (parm)));
6568 warning_with_file_and_line
6569 (current_function_prototype_file,
6570 current_function_prototype_line,
6571 "prototype declaration");
6576 error ("argument `%s' doesn't match prototype",
6577 IDENTIFIER_POINTER (DECL_NAME (parm)));
6578 error_with_file_and_line (current_function_prototype_file,
6579 current_function_prototype_line,
6580 "prototype declaration");
6584 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6587 /* Otherwise, create a prototype that would match. */
6591 tree actual = 0, last = 0, type;
6593 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6595 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6597 TREE_CHAIN (last) = type;
6602 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6604 TREE_CHAIN (last) = type;
6608 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6609 of the type of this function, but we need to avoid having this
6610 affect the types of other similarly-typed functions, so we must
6611 first force the generation of an identical (but separate) type
6612 node for the relevant function type. The new node we create
6613 will be a variant of the main variant of the original function
6616 TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
6618 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6621 /* Now store the final chain of decls for the arguments
6622 as the decl-chain of the current lexical scope.
6623 Put the enumerators in as well, at the front so that
6624 DECL_ARGUMENTS is not modified. */
6626 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
6629 /* Make sure the binding level for the top of the function body
6630 gets a BLOCK if there are any in the function.
6631 Otherwise, the dbx output is wrong. */
6633 keep_next_if_subblocks = 1;
6635 /* ??? This might be an improvement,
6636 but needs to be thought about some more. */
6638 keep_next_level_flag = 1;
6641 /* Write a record describing this function definition to the prototypes
6642 file (if requested). */
6644 gen_aux_info_record (fndecl, 1, 0, prototype);
6646 /* Initialize the RTL code for the function. */
6647 init_function_start (fndecl, input_filename, lineno);
6649 /* Begin the statement tree for this function. */
6650 begin_stmt_tree (&DECL_SAVED_TREE (current_function_decl));
6652 /* If this is a nested function, save away the sizes of any
6653 variable-size types so that we can expand them when generating
6659 DECL_LANG_SPECIFIC (fndecl)->pending_sizes
6660 = nreverse (get_pending_sizes ());
6661 for (t = DECL_LANG_SPECIFIC (fndecl)->pending_sizes;
6664 SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = context;
6667 /* This function is being processed in whole-function mode. */
6668 cfun->x_whole_function_mode_p = 1;
6670 /* Even though we're inside a function body, we still don't want to
6671 call expand_expr to calculate the size of a variable-sized array.
6672 We haven't necessarily assigned RTL to all variables yet, so it's
6673 not safe to try to expand expressions involving them. */
6674 immediate_size_expand = 0;
6675 cfun->x_dont_save_pending_sizes_p = 1;
6677 warn_shadow = saved_warn_shadow;
6680 /* Finish up a function declaration and compile that function
6681 all the way to assembler language output. The free the storage
6682 for the function definition.
6684 This is called after parsing the body of the function definition.
6686 NESTED is nonzero if the function being finished is nested in another. */
6689 finish_function (nested)
6692 tree fndecl = current_function_decl;
6694 /* TREE_READONLY (fndecl) = 1;
6695 This caused &foo to be of type ptr-to-const-function
6696 which then got a warning when stored in a ptr-to-function variable. */
6699 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6701 /* Must mark the RESULT_DECL as being in this function. */
6703 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
6705 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
6707 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6708 != integer_type_node)
6710 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6711 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6713 pedwarn_with_decl (fndecl, "return type of `%s' is not `int'");
6717 #ifdef DEFAULT_MAIN_RETURN
6718 /* Make it so that `main' always returns success by default. */
6719 DEFAULT_MAIN_RETURN;
6722 c_expand_return (integer_zero_node);
6727 finish_fname_decls ();
6729 /* Tie off the statement tree for this function. */
6730 finish_stmt_tree (&DECL_SAVED_TREE (fndecl));
6732 /* Complain if there's just no return statement. */
6733 if (warn_return_type
6734 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
6735 && !current_function_returns_value && !current_function_returns_null
6736 /* Don't complain if we abort. */
6737 && !current_function_returns_abnormally
6738 /* Don't warn for main(). */
6739 && !MAIN_NAME_P (DECL_NAME (fndecl))
6740 /* Or if they didn't actually specify a return type. */
6741 && !C_FUNCTION_IMPLICIT_INT (fndecl)
6742 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6743 inline function, as we might never be compiled separately. */
6744 && DECL_INLINE (fndecl))
6745 warning ("no return statement in function returning non-void");
6747 /* Clear out memory we no longer need. */
6748 free_after_parsing (cfun);
6749 /* Since we never call rest_of_compilation, we never clear
6750 CFUN. Do so explicitly. */
6751 free_after_compilation (cfun);
6756 /* Generate RTL for the body of this function. */
6757 c_expand_body (fndecl, nested, 1);
6758 /* Let the error reporting routines know that we're outside a
6759 function. For a nested function, this value is used in
6760 pop_c_function_context and then reset via pop_function_context. */
6761 current_function_decl = NULL;
6765 /* Generate the RTL for a deferred function FNDECL. */
6768 c_expand_deferred_function (fndecl)
6771 /* DECL_INLINE or DECL_RESULT might got cleared after the inline
6772 function was deferred, e.g. in duplicate_decls. */
6773 if (DECL_INLINE (fndecl) && DECL_RESULT (fndecl))
6775 c_expand_body (fndecl, 0, 0);
6776 current_function_decl = NULL;
6780 /* Generate the RTL for the body of FNDECL. If NESTED_P is non-zero,
6781 then we are already in the process of generating RTL for another
6782 function. If can_defer_p is zero, we won't attempt to defer the
6783 generation of RTL. */
6786 c_expand_body (fndecl, nested_p, can_defer_p)
6788 int nested_p, can_defer_p;
6790 int uninlinable = 1;
6792 /* There's no reason to do any of the work here if we're only doing
6793 semantic analysis; this code just generates RTL. */
6794 if (flag_syntax_only)
6797 if (flag_inline_trees)
6799 /* First, cache whether the current function is inlinable. Some
6800 predicates depend on cfun and current_function_decl to
6801 function completely. */
6802 timevar_push (TV_INTEGRATION);
6803 uninlinable = ! tree_inlinable_function_p (fndecl);
6805 if (! uninlinable && can_defer_p
6806 /* Save function tree for inlining. Should return 0 if the
6807 language does not support function deferring or the
6808 function could not be deferred. */
6809 && defer_fn (fndecl))
6811 /* Let the back-end know that this function exists. */
6812 (*debug_hooks->deferred_inline_function) (fndecl);
6813 timevar_pop (TV_INTEGRATION);
6817 /* Then, inline any functions called in it. */
6818 optimize_inline_calls (fndecl);
6819 timevar_pop (TV_INTEGRATION);
6822 timevar_push (TV_EXPAND);
6826 /* Make sure that we will evaluate variable-sized types involved
6827 in our function's type. */
6828 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes);
6829 /* Squirrel away our current state. */
6830 push_function_context ();
6833 /* Initialize the RTL code for the function. */
6834 current_function_decl = fndecl;
6835 input_filename = DECL_SOURCE_FILE (fndecl);
6836 init_function_start (fndecl, input_filename, DECL_SOURCE_LINE (fndecl));
6838 /* This function is being processed in whole-function mode. */
6839 cfun->x_whole_function_mode_p = 1;
6841 /* Even though we're inside a function body, we still don't want to
6842 call expand_expr to calculate the size of a variable-sized array.
6843 We haven't necessarily assigned RTL to all variables yet, so it's
6844 not safe to try to expand expressions involving them. */
6845 immediate_size_expand = 0;
6846 cfun->x_dont_save_pending_sizes_p = 1;
6848 /* If this is a varargs function, inform function.c. */
6849 if (c_function_varargs)
6852 /* Set up parameters and prepare for return, for the function. */
6853 expand_function_start (fndecl, 0);
6855 /* If this function is `main', emit a call to `__main'
6856 to run global initializers, etc. */
6857 if (DECL_NAME (fndecl)
6858 && MAIN_NAME_P (DECL_NAME (fndecl))
6859 && DECL_CONTEXT (fndecl) == NULL_TREE)
6860 expand_main_function ();
6862 /* Generate the RTL for this function. */
6863 expand_stmt (DECL_SAVED_TREE (fndecl));
6866 /* Allow the body of the function to be garbage collected. */
6867 DECL_SAVED_TREE (fndecl) = NULL_TREE;
6870 /* We hard-wired immediate_size_expand to zero above.
6871 expand_function_end will decrement this variable. So, we set the
6872 variable to one here, so that after the decrement it will remain
6874 immediate_size_expand = 1;
6876 /* Allow language dialects to perform special processing. */
6877 if (lang_expand_function_end)
6878 (*lang_expand_function_end) ();
6880 /* Generate rtl for function exit. */
6881 expand_function_end (input_filename, lineno, 0);
6883 /* If this is a nested function, protect the local variables in the stack
6884 above us from being collected while we're compiling this function. */
6886 ggc_push_context ();
6888 /* Run the optimizers and output the assembler code for this function. */
6889 rest_of_compilation (fndecl);
6891 /* Undo the GC context switch. */
6895 /* With just -W, complain only if function returns both with
6896 and without a value. */
6898 && current_function_returns_value
6899 && current_function_returns_null)
6900 warning ("this function may return with or without a value");
6902 /* If requested, warn about function definitions where the function will
6903 return a value (usually of some struct or union type) which itself will
6904 take up a lot of stack space. */
6906 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
6908 tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
6910 if (ret_type && TYPE_SIZE_UNIT (ret_type)
6911 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
6912 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
6915 unsigned int size_as_int
6916 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
6918 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
6919 warning_with_decl (fndecl,
6920 "size of return value of `%s' is %u bytes",
6923 warning_with_decl (fndecl,
6924 "size of return value of `%s' is larger than %d bytes",
6929 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested_p
6930 && ! flag_inline_trees)
6932 /* Stop pointing to the local nodes about to be freed.
6933 But DECL_INITIAL must remain nonzero so we know this
6934 was an actual function definition.
6935 For a nested function, this is done in pop_c_function_context.
6936 If rest_of_compilation set this to 0, leave it 0. */
6937 if (DECL_INITIAL (fndecl) != 0)
6938 DECL_INITIAL (fndecl) = error_mark_node;
6940 DECL_ARGUMENTS (fndecl) = 0;
6943 if (DECL_STATIC_CONSTRUCTOR (fndecl))
6945 if (targetm.have_ctors_dtors)
6946 (* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0),
6947 DEFAULT_INIT_PRIORITY);
6949 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
6952 if (DECL_STATIC_DESTRUCTOR (fndecl))
6954 if (targetm.have_ctors_dtors)
6955 (* targetm.asm_out.destructor) (XEXP (DECL_RTL (fndecl), 0),
6956 DEFAULT_INIT_PRIORITY);
6958 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
6962 /* Return to the enclosing function. */
6963 pop_function_context ();
6964 timevar_pop (TV_EXPAND);
6967 /* Check the declarations given in a for-loop for satisfying the C99
6970 check_for_loop_decls ()
6976 /* If we get here, declarations have been used in a for loop without
6977 the C99 for loop scope. This doesn't make much sense, so don't
6979 error ("`for' loop initial declaration used outside C99 mode");
6982 /* C99 subclause 6.8.5 paragraph 3:
6984 [#3] The declaration part of a for statement shall only
6985 declare identifiers for objects having storage class auto or
6988 It isn't clear whether, in this sentence, "identifiers" binds to
6989 "shall only declare" or to "objects" - that is, whether all identifiers
6990 declared must be identifiers for objects, or whether the restriction
6991 only applies to those that are. (A question on this in comp.std.c
6992 in November 2000 received no answer.) We implement the strictest
6993 interpretation, to avoid creating an extension which later causes
6996 for (t = gettags (); t; t = TREE_CHAIN (t))
6998 if (TREE_PURPOSE (t) != 0)
7000 enum tree_code code = TREE_CODE (TREE_VALUE (t));
7002 if (code == RECORD_TYPE)
7003 error ("`struct %s' declared in `for' loop initial declaration",
7004 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
7005 else if (code == UNION_TYPE)
7006 error ("`union %s' declared in `for' loop initial declaration",
7007 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
7009 error ("`enum %s' declared in `for' loop initial declaration",
7010 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
7014 for (t = getdecls (); t; t = TREE_CHAIN (t))
7016 if (TREE_CODE (t) != VAR_DECL && DECL_NAME (t))
7017 error_with_decl (t, "declaration of non-variable `%s' in `for' loop initial declaration");
7018 else if (TREE_STATIC (t))
7019 error_with_decl (t, "declaration of static variable `%s' in `for' loop initial declaration");
7020 else if (DECL_EXTERNAL (t))
7021 error_with_decl (t, "declaration of `extern' variable `%s' in `for' loop initial declaration");
7025 /* Save and restore the variables in this file and elsewhere
7026 that keep track of the progress of compilation of the current function.
7027 Used for nested functions. */
7029 struct c_language_function
7031 struct language_function base;
7033 tree shadowed_labels;
7036 int returns_abnormally;
7037 int warn_about_return_type;
7039 struct binding_level *binding_level;
7042 /* Save and reinitialize the variables
7043 used during compilation of a C function. */
7046 push_c_function_context (f)
7049 struct c_language_function *p;
7050 p = ((struct c_language_function *)
7051 xmalloc (sizeof (struct c_language_function)));
7052 f->language = (struct language_function *) p;
7054 p->base.x_stmt_tree = c_stmt_tree;
7055 p->base.x_scope_stmt_stack = c_scope_stmt_stack;
7056 p->named_labels = named_labels;
7057 p->shadowed_labels = shadowed_labels;
7058 p->returns_value = current_function_returns_value;
7059 p->returns_null = current_function_returns_null;
7060 p->returns_abnormally = current_function_returns_abnormally;
7061 p->warn_about_return_type = warn_about_return_type;
7062 p->extern_inline = current_extern_inline;
7063 p->binding_level = current_binding_level;
7066 /* Restore the variables used during compilation of a C function. */
7069 pop_c_function_context (f)
7072 struct c_language_function *p
7073 = (struct c_language_function *) f->language;
7076 /* Bring back all the labels that were shadowed. */
7077 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
7078 if (DECL_NAME (TREE_VALUE (link)) != 0)
7079 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
7080 = TREE_VALUE (link);
7082 if (DECL_SAVED_INSNS (current_function_decl) == 0
7083 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
7085 /* Stop pointing to the local nodes about to be freed. */
7086 /* But DECL_INITIAL must remain nonzero so we know this
7087 was an actual function definition. */
7088 DECL_INITIAL (current_function_decl) = error_mark_node;
7089 DECL_ARGUMENTS (current_function_decl) = 0;
7092 c_stmt_tree = p->base.x_stmt_tree;
7093 c_scope_stmt_stack = p->base.x_scope_stmt_stack;
7094 named_labels = p->named_labels;
7095 shadowed_labels = p->shadowed_labels;
7096 current_function_returns_value = p->returns_value;
7097 current_function_returns_null = p->returns_null;
7098 current_function_returns_abnormally = p->returns_abnormally;
7099 warn_about_return_type = p->warn_about_return_type;
7100 current_extern_inline = p->extern_inline;
7101 current_binding_level = p->binding_level;
7107 /* Mark the language specific parts of F for GC. */
7110 mark_c_function_context (f)
7113 struct c_language_function *p
7114 = (struct c_language_function *) f->language;
7119 mark_c_language_function (&p->base);
7120 ggc_mark_tree (p->shadowed_labels);
7121 ggc_mark_tree (p->named_labels);
7122 mark_binding_level (&p->binding_level);
7125 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
7128 c_dup_lang_specific_decl (decl)
7131 struct lang_decl *ld;
7133 if (!DECL_LANG_SPECIFIC (decl))
7136 ld = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl));
7137 memcpy ((char *) ld, (char *) DECL_LANG_SPECIFIC (decl),
7138 sizeof (struct lang_decl));
7139 DECL_LANG_SPECIFIC (decl) = ld;
7142 /* Mark the language specific bits in T for GC. */
7148 if (TREE_CODE (t) == IDENTIFIER_NODE)
7150 struct lang_identifier *i = (struct lang_identifier *) t;
7151 ggc_mark_tree (i->global_value);
7152 ggc_mark_tree (i->local_value);
7153 ggc_mark_tree (i->label_value);
7154 ggc_mark_tree (i->implicit_decl);
7155 ggc_mark_tree (i->error_locus);
7156 ggc_mark_tree (i->limbo_value);
7158 else if (TYPE_P (t) && TYPE_LANG_SPECIFIC (t))
7159 ggc_mark (TYPE_LANG_SPECIFIC (t));
7160 else if (DECL_P (t) && DECL_LANG_SPECIFIC (t))
7162 ggc_mark (DECL_LANG_SPECIFIC (t));
7163 c_mark_lang_decl (&DECL_LANG_SPECIFIC (t)->base);
7164 ggc_mark_tree (DECL_LANG_SPECIFIC (t)->pending_sizes);
7168 /* The functions below are required for functionality of doing
7169 function at once processing in the C front end. Currently these
7170 functions are not called from anywhere in the C front end, but as
7171 these changes continue, that will change. */
7173 /* Returns non-zero if the current statement is a full expression,
7174 i.e. temporaries created during that statement should be destroyed
7175 at the end of the statement. */
7178 stmts_are_full_exprs_p ()
7183 /* Returns the stmt_tree (if any) to which statements are currently
7184 being added. If there is no active statement-tree, NULL is
7188 current_stmt_tree ()
7190 return &c_stmt_tree;
7193 /* Returns the stack of SCOPE_STMTs for the current function. */
7196 current_scope_stmt_stack ()
7198 return &c_scope_stmt_stack;
7201 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
7205 anon_aggr_type_p (node)
7206 tree node ATTRIBUTE_UNUSED;
7211 /* Dummy function in place of callback used by C++. */
7214 extract_interface_info ()
7218 /* Return a new COMPOUND_STMT, after adding it to the current
7222 c_begin_compound_stmt ()
7226 /* Create the COMPOUND_STMT. */
7227 stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE));
7232 /* Expand T (a DECL_STMT) if it declares an entity not handled by the
7236 c_expand_decl_stmt (t)
7239 tree decl = DECL_STMT_DECL (t);
7241 /* Expand nested functions. */
7242 if (TREE_CODE (decl) == FUNCTION_DECL
7243 && DECL_CONTEXT (decl) == current_function_decl
7244 && DECL_SAVED_TREE (decl))
7245 c_expand_body (decl, /*nested_p=*/1, /*can_defer_p=*/0);
7248 /* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since
7249 the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */
7252 identifier_global_value (t)
7255 return IDENTIFIER_GLOBAL_VALUE (t);
7258 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
7259 otherwise the name is found in ridpointers from RID_INDEX. */
7262 record_builtin_type (rid_index, name, type)
7269 id = ridpointers[(int) rid_index];
7271 id = get_identifier (name);
7272 pushdecl (build_decl (TYPE_DECL, id, type));
7275 /* Build the void_list_node (void_type_node having been created). */
7277 build_void_list_node ()
7279 tree t = build_tree_list (NULL_TREE, void_type_node);