1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92-99, 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
43 extern cpp_reader parse_in;
46 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
48 { NORMAL, /* Ordinary declaration */
49 FUNCDEF, /* Function definition */
50 PARM, /* Declaration of parm before function body */
51 FIELD, /* Declaration inside struct or union */
52 BITFIELD, /* Likewise but with specified width */
53 TYPENAME}; /* Typename (inside cast or sizeof) */
55 /* We let tm.h override the types used here, to handle trivial differences
56 such as the choice of unsigned int or long unsigned int for size_t.
57 When machines start needing nontrivial differences in the size type,
58 it would be best to do something here to figure out automatically
59 from other information what type to use. */
62 #define SIZE_TYPE "long unsigned int"
66 #define PTRDIFF_TYPE "long int"
70 #define WCHAR_TYPE "int"
76 /* Nonzero if we have seen an invalid cross reference
77 to a struct, union, or enum, but not yet printed the message. */
79 tree pending_invalid_xref;
80 /* File and line to appear in the eventual error message. */
81 char *pending_invalid_xref_file;
82 int pending_invalid_xref_line;
84 /* While defining an enum type, this is 1 plus the last enumerator
85 constant value. Note that will do not have to save this or `enum_overflow'
86 around nested function definition since such a definition could only
87 occur in an enum value expression and we don't use these variables in
90 static tree enum_next_value;
92 /* Nonzero means that there was overflow computing enum_next_value. */
94 static int enum_overflow;
96 /* Parsing a function declarator leaves a list of parameter names
97 or a chain or parameter decls here. */
99 static tree last_function_parms;
101 /* Parsing a function declarator leaves here a chain of structure
102 and enum types declared in the parmlist. */
104 static tree last_function_parm_tags;
106 /* After parsing the declarator that starts a function definition,
107 `start_function' puts here the list of parameter names or chain of decls.
108 `store_parm_decls' finds it here. */
110 static tree current_function_parms;
112 /* Similar, for last_function_parm_tags. */
113 static tree current_function_parm_tags;
115 /* Similar, for the file and line that the prototype came from if this is
116 an old-style definition. */
117 static char *current_function_prototype_file;
118 static int current_function_prototype_line;
120 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
121 that have names. Here so we can clear out their names' definitions
122 at the end of the function. */
124 static tree named_labels;
126 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
128 static tree shadowed_labels;
130 /* Nonzero when store_parm_decls is called indicates a varargs function.
131 Value not meaningful after store_parm_decls. */
133 static int c_function_varargs;
135 /* The FUNCTION_DECL for the function currently being compiled,
136 or 0 if between functions. */
137 tree current_function_decl;
139 /* Set to 0 at beginning of a function definition, set to 1 if
140 a return statement that specifies a return value is seen. */
142 int current_function_returns_value;
144 /* Set to 0 at beginning of a function definition, set to 1 if
145 a return statement with no argument is seen. */
147 int current_function_returns_null;
149 /* Set to nonzero by `grokdeclarator' for a function
150 whose return type is defaulted, if warnings for this are desired. */
152 static int warn_about_return_type;
154 /* Nonzero when starting a function declared `extern inline'. */
156 static int current_extern_inline;
158 /* For each binding contour we allocate a binding_level structure
159 * which records the names defined in that contour.
162 * 1) one for each function definition,
163 * where internal declarations of the parameters appear.
164 * 2) one for each compound statement,
165 * to record its declarations.
167 * The current meaning of a name can be found by searching the levels from
168 * the current one out to the global one.
171 /* Note that the information in the `names' component of the global contour
172 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
176 /* A chain of _DECL nodes for all variables, constants, functions,
177 and typedef types. These are in the reverse of the order supplied.
181 /* A list of structure, union and enum definitions,
182 * for looking up tag names.
183 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
184 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
185 * or ENUMERAL_TYPE node.
189 /* For each level, a list of shadowed outer-level local definitions
190 to be restored when this level is popped.
191 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
192 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
195 /* For each level (except not the global one),
196 a chain of BLOCK nodes for all the levels
197 that were entered and exited one level down. */
200 /* The BLOCK node for this level, if one has been preallocated.
201 If 0, the BLOCK is allocated (if needed) when the level is popped. */
204 /* The binding level which this one is contained in (inherits from). */
205 struct binding_level *level_chain;
207 /* Nonzero for the level that holds the parameters of a function. */
210 /* Nonzero if this level "doesn't exist" for tags. */
211 char tag_transparent;
213 /* Nonzero if sublevels of this level "don't exist" for tags.
214 This is set in the parm level of a function definition
215 while reading the function body, so that the outermost block
216 of the function body will be tag-transparent. */
217 char subblocks_tag_transparent;
219 /* Nonzero means make a BLOCK for this level regardless of all else. */
222 /* Nonzero means make a BLOCK if this level has any subblocks. */
223 char keep_if_subblocks;
225 /* Number of decls in `names' that have incomplete
226 structure or union types. */
229 /* A list of decls giving the (reversed) specified order of parms,
230 not including any forward-decls in the parmlist.
231 This is so we can put the parms in proper order for assign_parms. */
235 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
237 /* The binding level currently in effect. */
239 static struct binding_level *current_binding_level;
241 /* A chain of binding_level structures awaiting reuse. */
243 static struct binding_level *free_binding_level;
245 /* The outermost binding level, for names of file scope.
246 This is created when the compiler is started and exists
247 through the entire run. */
249 static struct binding_level *global_binding_level;
251 /* Binding level structures are initialized by copying this one. */
253 static struct binding_level clear_binding_level
254 = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0,
257 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
259 static int keep_next_level_flag;
261 /* Nonzero means make a BLOCK for the next level pushed
262 if it has subblocks. */
264 static int keep_next_if_subblocks;
266 /* The chain of outer levels of label scopes.
267 This uses the same data structure used for binding levels,
268 but it works differently: each link in the chain records
269 saved values of named_labels and shadowed_labels for
270 a label binding level outside the current one. */
272 static struct binding_level *label_level_chain;
274 /* Functions called automatically at the beginning and end of execution. */
276 tree static_ctors, static_dtors;
278 /* Forward declarations. */
280 static struct binding_level * make_binding_level PARAMS ((void));
281 static void mark_binding_level PARAMS ((void *));
282 static void clear_limbo_values PARAMS ((tree));
283 static int duplicate_decls PARAMS ((tree, tree, int));
284 static int redeclaration_error_message PARAMS ((tree, tree));
285 static void storedecls PARAMS ((tree));
286 static void storetags PARAMS ((tree));
287 static tree lookup_tag PARAMS ((enum tree_code, tree,
288 struct binding_level *, int));
289 static tree lookup_tag_reverse PARAMS ((tree));
290 static tree grokdeclarator PARAMS ((tree, tree, enum decl_context,
292 static tree grokparms PARAMS ((tree, int));
293 static void layout_array_type PARAMS ((tree));
295 /* C-specific option variables. */
297 /* Nonzero means allow type mismatches in conditional expressions;
298 just make their values `void'. */
300 int flag_cond_mismatch;
302 /* Nonzero means give `double' the same size as `float'. */
304 int flag_short_double;
306 /* Nonzero means give `wchar_t' the same size as `short'. */
308 int flag_short_wchar;
310 /* Nonzero means don't recognize the keyword `asm'. */
314 /* Nonzero means don't recognize any builtin functions. */
318 /* Nonzero means don't recognize the non-ANSI builtin functions.
321 int flag_no_nonansi_builtin;
323 /* Nonzero means do some things the same way PCC does. */
325 int flag_traditional;
327 /* Nonzero means use the ISO C9x dialect of C. */
331 /* Nonzero means that we have builtin functions, and main is an int */
335 /* Nonzero means to allow single precision math even if we're generally
336 being traditional. */
337 int flag_allow_single_precision = 0;
339 /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
341 int flag_signed_bitfields = 1;
342 int explicit_flag_signed_bitfields = 0;
344 /* Nonzero means warn about use of implicit int. */
346 int warn_implicit_int;
348 /* Nonzero means warn about usage of long long when `-pedantic'. */
350 int warn_long_long = 1;
352 /* Nonzero means message about use of implicit function declarations;
353 1 means warning; 2 means error. */
355 int mesg_implicit_function_declaration;
357 /* Nonzero means give string constants the type `const char *'
358 to get extra warnings from them. These warnings will be too numerous
359 to be useful, except in thoroughly ANSIfied programs. */
361 int flag_const_strings;
363 /* Nonzero means warn about pointer casts that can drop a type qualifier
364 from the pointer target type. */
368 /* Nonzero means warn when casting a function call to a type that does
369 not match the return type (e.g. (float)sqrt() or (anything*)malloc()
370 when there is no previous declaration of sqrt or malloc. */
372 int warn_bad_function_cast;
374 /* Warn about functions which might be candidates for attribute noreturn. */
376 int warn_missing_noreturn;
378 /* Warn about traditional constructs whose meanings changed in ANSI C. */
380 int warn_traditional;
382 /* Nonzero means warn about sizeof(function) or addition/subtraction
383 of function pointers. */
385 int warn_pointer_arith;
387 /* Nonzero means warn for non-prototype function decls
388 or non-prototyped defs without previous prototype. */
390 int warn_strict_prototypes;
392 /* Nonzero means warn for any global function def
393 without separate previous prototype decl. */
395 int warn_missing_prototypes;
397 /* Nonzero means warn for any global function def
398 without separate previous decl. */
400 int warn_missing_declarations;
402 /* Nonzero means warn about multiple (redundant) decls for the same single
403 variable or function. */
405 int warn_redundant_decls = 0;
407 /* Nonzero means warn about extern declarations of objects not at
408 file-scope level and about *all* declarations of functions (whether
409 extern or static) not at file-scope level. Note that we exclude
410 implicit function declarations. To get warnings about those, use
413 int warn_nested_externs = 0;
415 /* Warn about *printf or *scanf format/argument anomalies. */
419 /* Warn about a subscript that has type char. */
421 int warn_char_subscripts = 0;
423 /* Warn if a type conversion is done that might have confusing results. */
427 /* Warn if adding () is suggested. */
429 int warn_parentheses;
431 /* Warn if initializer is not completely bracketed. */
433 int warn_missing_braces;
435 /* Warn if main is suspicious. */
439 /* Warn about #pragma directives that are not recognised. */
441 int warn_unknown_pragmas = 0; /* Tri state variable. */
443 /* Warn about comparison of signed and unsigned values.
444 If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */
446 int warn_sign_compare = -1;
448 /* Warn about testing equality of floating point numbers. */
450 int warn_float_equal = 0;
452 /* Nonzero means warn about use of multicharacter literals. */
454 int warn_multichar = 1;
456 /* Nonzero means `$' can be in an identifier. */
458 #ifndef DOLLARS_IN_IDENTIFIERS
459 #define DOLLARS_IN_IDENTIFIERS 1
461 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
463 /* Decode the string P as a language-specific option for C.
464 Return the number of strings consumed. Should not complain
465 if it does not recognise the option. */
468 c_decode_option (argc, argv)
469 int argc ATTRIBUTE_UNUSED;
472 int strings_processed;
475 strings_processed = cpp_handle_option (&parse_in, argc, argv);
477 strings_processed = 0;
478 #endif /* ! USE_CPPLIB */
480 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
482 flag_traditional = 1;
483 flag_writable_strings = 1;
485 else if (!strcmp (p, "-fallow-single-precision"))
486 flag_allow_single_precision = 1;
487 else if (!strcmp (p, "-fhosted") || !strcmp (p, "-fno-freestanding"))
492 else if (!strcmp (p, "-ffreestanding") || !strcmp (p, "-fno-hosted"))
496 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
500 else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional"))
502 flag_traditional = 0;
503 flag_writable_strings = 0;
505 else if (!strncmp (p, "-std=", 5))
507 /* Select the appropriate language standard. We currently
509 -std=iso9899:1990 same as -ansi
510 -std=iso9899:199409 ISO C as modified in amend. 1
511 -std=iso9899:199x ISO C 9x
512 -std=c89 same as -std=iso9899:1990
513 -std=c9x same as -std=iso9899:199x
514 -std=gnu89 default, iso9899:1990 + gnu extensions
515 -std=gnu9x iso9899:199x + gnu extensions
517 const char *argstart = &p[5];
519 if (!strcmp (argstart, "iso9899:1990")
520 || !strcmp (argstart, "c89"))
523 flag_traditional = 0;
524 flag_writable_strings = 0;
526 flag_no_nonansi_builtin = 1;
529 else if (!strcmp (argstart, "iso9899:199409"))
531 /* ??? The changes since ISO C 1990 are not supported. */
534 else if (!strcmp (argstart, "iso9899:199x")
535 || !strcmp (argstart, "c9x"))
537 flag_traditional = 0;
538 flag_writable_strings = 0;
540 flag_no_nonansi_builtin = 1;
543 else if (!strcmp (argstart, "gnu89"))
545 flag_traditional = 0;
546 flag_writable_strings = 0;
548 flag_no_nonansi_builtin = 0;
551 else if (!strcmp (argstart, "gnu9x"))
553 flag_traditional = 0;
554 flag_writable_strings = 0;
556 flag_no_nonansi_builtin = 0;
560 error ("unknown C standard `%s'", argstart);
562 else if (!strcmp (p, "-fdollars-in-identifiers"))
563 dollars_in_ident = 1;
564 else if (!strcmp (p, "-fno-dollars-in-identifiers"))
565 dollars_in_ident = 0;
566 else if (!strcmp (p, "-fsigned-char"))
567 flag_signed_char = 1;
568 else if (!strcmp (p, "-funsigned-char"))
569 flag_signed_char = 0;
570 else if (!strcmp (p, "-fno-signed-char"))
571 flag_signed_char = 0;
572 else if (!strcmp (p, "-fno-unsigned-char"))
573 flag_signed_char = 1;
574 else if (!strcmp (p, "-fsigned-bitfields")
575 || !strcmp (p, "-fno-unsigned-bitfields"))
577 flag_signed_bitfields = 1;
578 explicit_flag_signed_bitfields = 1;
580 else if (!strcmp (p, "-funsigned-bitfields")
581 || !strcmp (p, "-fno-signed-bitfields"))
583 flag_signed_bitfields = 0;
584 explicit_flag_signed_bitfields = 1;
586 else if (!strcmp (p, "-fshort-enums"))
587 flag_short_enums = 1;
588 else if (!strcmp (p, "-fno-short-enums"))
589 flag_short_enums = 0;
590 else if (!strcmp (p, "-fshort-wchar"))
591 flag_short_wchar = 1;
592 else if (!strcmp (p, "-fno-short-wchar"))
593 flag_short_wchar = 0;
594 else if (!strcmp (p, "-fcond-mismatch"))
595 flag_cond_mismatch = 1;
596 else if (!strcmp (p, "-fno-cond-mismatch"))
597 flag_cond_mismatch = 0;
598 else if (!strcmp (p, "-fshort-double"))
599 flag_short_double = 1;
600 else if (!strcmp (p, "-fno-short-double"))
601 flag_short_double = 0;
602 else if (!strcmp (p, "-fasm"))
604 else if (!strcmp (p, "-fno-asm"))
606 else if (!strcmp (p, "-fbuiltin"))
608 else if (!strcmp (p, "-fno-builtin"))
610 else if (!strcmp (p, "-ansi"))
612 else if (!strcmp (p, "-Werror-implicit-function-declaration"))
613 mesg_implicit_function_declaration = 2;
614 else if (!strcmp (p, "-Wimplicit-function-declaration"))
615 mesg_implicit_function_declaration = 1;
616 else if (!strcmp (p, "-Wno-implicit-function-declaration"))
617 mesg_implicit_function_declaration = 0;
618 else if (!strcmp (p, "-Wimplicit-int"))
619 warn_implicit_int = 1;
620 else if (!strcmp (p, "-Wno-implicit-int"))
621 warn_implicit_int = 0;
622 else if (!strcmp (p, "-Wimplicit"))
624 warn_implicit_int = 1;
625 if (mesg_implicit_function_declaration != 2)
626 mesg_implicit_function_declaration = 1;
628 else if (!strcmp (p, "-Wno-implicit"))
629 warn_implicit_int = 0, mesg_implicit_function_declaration = 0;
630 else if (!strcmp (p, "-Wlong-long"))
632 else if (!strcmp (p, "-Wno-long-long"))
634 else if (!strcmp (p, "-Wwrite-strings"))
635 flag_const_strings = 1;
636 else if (!strcmp (p, "-Wno-write-strings"))
637 flag_const_strings = 0;
638 else if (!strcmp (p, "-Wcast-qual"))
640 else if (!strcmp (p, "-Wno-cast-qual"))
642 else if (!strcmp (p, "-Wbad-function-cast"))
643 warn_bad_function_cast = 1;
644 else if (!strcmp (p, "-Wno-bad-function-cast"))
645 warn_bad_function_cast = 0;
646 else if (!strcmp (p, "-Wmissing-noreturn"))
647 warn_missing_noreturn = 1;
648 else if (!strcmp (p, "-Wno-missing-noreturn"))
649 warn_missing_noreturn = 0;
650 else if (!strcmp (p, "-Wpointer-arith"))
651 warn_pointer_arith = 1;
652 else if (!strcmp (p, "-Wno-pointer-arith"))
653 warn_pointer_arith = 0;
654 else if (!strcmp (p, "-Wstrict-prototypes"))
655 warn_strict_prototypes = 1;
656 else if (!strcmp (p, "-Wno-strict-prototypes"))
657 warn_strict_prototypes = 0;
658 else if (!strcmp (p, "-Wmissing-prototypes"))
659 warn_missing_prototypes = 1;
660 else if (!strcmp (p, "-Wno-missing-prototypes"))
661 warn_missing_prototypes = 0;
662 else if (!strcmp (p, "-Wmissing-declarations"))
663 warn_missing_declarations = 1;
664 else if (!strcmp (p, "-Wno-missing-declarations"))
665 warn_missing_declarations = 0;
666 else if (!strcmp (p, "-Wredundant-decls"))
667 warn_redundant_decls = 1;
668 else if (!strcmp (p, "-Wno-redundant-decls"))
669 warn_redundant_decls = 0;
670 else if (!strcmp (p, "-Wnested-externs"))
671 warn_nested_externs = 1;
672 else if (!strcmp (p, "-Wno-nested-externs"))
673 warn_nested_externs = 0;
674 else if (!strcmp (p, "-Wtraditional"))
675 warn_traditional = 1;
676 else if (!strcmp (p, "-Wno-traditional"))
677 warn_traditional = 0;
678 else if (!strcmp (p, "-Wformat"))
680 else if (!strcmp (p, "-Wno-format"))
682 else if (!strcmp (p, "-Wchar-subscripts"))
683 warn_char_subscripts = 1;
684 else if (!strcmp (p, "-Wno-char-subscripts"))
685 warn_char_subscripts = 0;
686 else if (!strcmp (p, "-Wconversion"))
688 else if (!strcmp (p, "-Wno-conversion"))
690 else if (!strcmp (p, "-Wparentheses"))
691 warn_parentheses = 1;
692 else if (!strcmp (p, "-Wno-parentheses"))
693 warn_parentheses = 0;
694 else if (!strcmp (p, "-Wreturn-type"))
695 warn_return_type = 1;
696 else if (!strcmp (p, "-Wno-return-type"))
697 warn_return_type = 0;
698 else if (!strcmp (p, "-Wcomment"))
699 ; /* cpp handles this one. */
700 else if (!strcmp (p, "-Wno-comment"))
701 ; /* cpp handles this one. */
702 else if (!strcmp (p, "-Wcomments"))
703 ; /* cpp handles this one. */
704 else if (!strcmp (p, "-Wno-comments"))
705 ; /* cpp handles this one. */
706 else if (!strcmp (p, "-Wtrigraphs"))
707 ; /* cpp handles this one. */
708 else if (!strcmp (p, "-Wno-trigraphs"))
709 ; /* cpp handles this one. */
710 else if (!strcmp (p, "-Wundef"))
711 ; /* cpp handles this one. */
712 else if (!strcmp (p, "-Wno-undef"))
713 ; /* cpp handles this one. */
714 else if (!strcmp (p, "-Wimport"))
715 ; /* cpp handles this one. */
716 else if (!strcmp (p, "-Wno-import"))
717 ; /* cpp handles this one. */
718 else if (!strcmp (p, "-Wmissing-braces"))
719 warn_missing_braces = 1;
720 else if (!strcmp (p, "-Wno-missing-braces"))
721 warn_missing_braces = 0;
722 else if (!strcmp (p, "-Wmain"))
724 else if (!strcmp (p, "-Wno-main"))
726 else if (!strcmp (p, "-Wsign-compare"))
727 warn_sign_compare = 1;
728 else if (!strcmp (p, "-Wno-sign-compare"))
729 warn_sign_compare = 0;
730 else if (!strcmp (p, "-Wfloat-equal"))
731 warn_float_equal = 1;
732 else if (!strcmp (p, "-Wno-float-equal"))
733 warn_float_equal = 0;
734 else if (!strcmp (p, "-Wmultichar"))
736 else if (!strcmp (p, "-Wno-multichar"))
738 else if (!strcmp (p, "-Wunknown-pragmas"))
739 /* Set to greater than 1, so that even unknown pragmas in system
740 headers will be warned about. */
741 warn_unknown_pragmas = 2;
742 else if (!strcmp (p, "-Wno-unknown-pragmas"))
743 warn_unknown_pragmas = 0;
744 else if (!strcmp (p, "-Wall"))
746 /* We save the value of warn_uninitialized, since if they put
747 -Wuninitialized on the command line, we need to generate a
748 warning about not using it without also specifying -O. */
749 if (warn_uninitialized != 1)
750 warn_uninitialized = 2;
751 warn_implicit_int = 1;
752 mesg_implicit_function_declaration = 1;
753 warn_return_type = 1;
757 warn_char_subscripts = 1;
758 warn_parentheses = 1;
759 warn_missing_braces = 1;
760 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn
761 it off only if it's not explicit. */
763 /* Only warn about unknown pragmas that are not in system headers. */
764 warn_unknown_pragmas = 1;
767 return strings_processed;
772 /* Hooks for print_node. */
775 print_lang_decl (file, node, indent)
776 FILE *file ATTRIBUTE_UNUSED;
777 tree node ATTRIBUTE_UNUSED;
778 int indent ATTRIBUTE_UNUSED;
783 print_lang_type (file, node, indent)
784 FILE *file ATTRIBUTE_UNUSED;
785 tree node ATTRIBUTE_UNUSED;
786 int indent ATTRIBUTE_UNUSED;
791 print_lang_identifier (file, node, indent)
796 print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
797 print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
798 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
799 print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
800 print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
801 print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4);
804 /* Hook called at end of compilation to assume 1 elt
805 for a top-level array decl that wasn't complete before. */
808 finish_incomplete_decl (decl)
811 if (TREE_CODE (decl) == VAR_DECL)
813 tree type = TREE_TYPE (decl);
814 if (type != error_mark_node
815 && TREE_CODE (type) == ARRAY_TYPE
816 && TYPE_DOMAIN (type) == 0)
818 if (! DECL_EXTERNAL (decl))
819 warning_with_decl (decl, "array `%s' assumed to have one element");
821 complete_array_type (type, NULL_TREE, 1);
823 layout_decl (decl, 0);
828 /* Create a new `struct binding_level'. */
831 struct binding_level *
832 make_binding_level ()
835 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
838 /* Nonzero if we are currently in the global binding level. */
843 return current_binding_level == global_binding_level;
849 keep_next_level_flag = 1;
852 /* Nonzero if the current level needs to have a BLOCK made. */
857 return ((current_binding_level->keep_if_subblocks
858 && current_binding_level->blocks != 0)
859 || current_binding_level->keep
860 || current_binding_level->names != 0
861 || (current_binding_level->tags != 0
862 && !current_binding_level->tag_transparent));
865 /* Identify this binding level as a level of parameters.
866 DEFINITION_FLAG is 1 for a definition, 0 for a declaration.
867 But it turns out there is no way to pass the right value for
868 DEFINITION_FLAG, so we ignore it. */
871 declare_parm_level (definition_flag)
872 int definition_flag ATTRIBUTE_UNUSED;
874 current_binding_level->parm_flag = 1;
877 /* Nonzero if currently making parm declarations. */
882 return current_binding_level->parm_flag;
885 /* Enter a new binding level.
886 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
887 not for that of tags. */
890 pushlevel (tag_transparent)
893 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
895 /* If this is the top level of a function,
896 just make sure that NAMED_LABELS is 0. */
898 if (current_binding_level == global_binding_level)
903 /* Reuse or create a struct for this binding level. */
905 if (free_binding_level)
907 newlevel = free_binding_level;
908 free_binding_level = free_binding_level->level_chain;
912 newlevel = make_binding_level ();
915 /* Add this level to the front of the chain (stack) of levels that
918 *newlevel = clear_binding_level;
919 newlevel->tag_transparent
921 || (current_binding_level
922 ? current_binding_level->subblocks_tag_transparent
924 newlevel->level_chain = current_binding_level;
925 current_binding_level = newlevel;
926 newlevel->keep = keep_next_level_flag;
927 keep_next_level_flag = 0;
928 newlevel->keep_if_subblocks = keep_next_if_subblocks;
929 keep_next_if_subblocks = 0;
932 /* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */
935 clear_limbo_values (block)
940 for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem))
941 if (DECL_NAME (tem) != 0)
942 IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0;
944 for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem))
945 clear_limbo_values (tem);
948 /* Exit a binding level.
949 Pop the level off, and restore the state of the identifier-decl mappings
950 that were in effect when this level was entered.
952 If KEEP is nonzero, this level had explicit declarations, so
953 and create a "block" (a BLOCK node) for the level
954 to record its declarations and subblocks for symbol table output.
956 If FUNCTIONBODY is nonzero, this level is the body of a function,
957 so create a block as if KEEP were set and also clear out all
960 If REVERSE is nonzero, reverse the order of decls before putting
961 them into the BLOCK. */
964 poplevel (keep, reverse, functionbody)
970 /* The chain of decls was accumulated in reverse order.
971 Put it into forward order, just for cleanliness. */
973 tree tags = current_binding_level->tags;
974 tree subblocks = current_binding_level->blocks;
977 int block_previously_created;
979 keep |= current_binding_level->keep;
981 /* This warning is turned off because it causes warnings for
982 declarations like `extern struct foo *x'. */
984 /* Warn about incomplete structure types in this level. */
985 for (link = tags; link; link = TREE_CHAIN (link))
986 if (TYPE_SIZE (TREE_VALUE (link)) == 0)
988 tree type = TREE_VALUE (link);
989 tree type_name = TYPE_NAME (type);
990 char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE
992 : DECL_NAME (type_name));
993 switch (TREE_CODE (type))
996 error ("`struct %s' incomplete in scope ending here", id);
999 error ("`union %s' incomplete in scope ending here", id);
1002 error ("`enum %s' incomplete in scope ending here", id);
1008 /* Get the decls in the order they were written.
1009 Usually current_binding_level->names is in reverse order.
1010 But parameter decls were previously put in forward order. */
1013 current_binding_level->names
1014 = decls = nreverse (current_binding_level->names);
1016 decls = current_binding_level->names;
1018 /* Output any nested inline functions within this block
1019 if they weren't already output. */
1021 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1022 if (TREE_CODE (decl) == FUNCTION_DECL
1023 && ! TREE_ASM_WRITTEN (decl)
1024 && DECL_INITIAL (decl) != 0
1025 && TREE_ADDRESSABLE (decl))
1027 /* If this decl was copied from a file-scope decl
1028 on account of a block-scope extern decl,
1029 propagate TREE_ADDRESSABLE to the file-scope decl.
1031 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1032 true, since then the decl goes through save_for_inline_copying. */
1033 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1034 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1035 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1036 else if (DECL_SAVED_INSNS (decl) != 0)
1038 push_function_context ();
1039 output_inline_function (decl);
1040 pop_function_context ();
1044 /* If there were any declarations or structure tags in that level,
1045 or if this level is a function body,
1046 create a BLOCK to record them for the life of this function. */
1049 block_previously_created = (current_binding_level->this_block != 0);
1050 if (block_previously_created)
1051 block = current_binding_level->this_block;
1052 else if (keep || functionbody
1053 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1054 block = make_node (BLOCK);
1057 BLOCK_VARS (block) = decls;
1058 BLOCK_SUBBLOCKS (block) = subblocks;
1061 /* In each subblock, record that this is its superior. */
1063 for (link = subblocks; link; link = TREE_CHAIN (link))
1064 BLOCK_SUPERCONTEXT (link) = block;
1066 /* Clear out the meanings of the local variables of this level. */
1068 for (link = decls; link; link = TREE_CHAIN (link))
1070 if (DECL_NAME (link) != 0)
1072 /* If the ident. was used or addressed via a local extern decl,
1073 don't forget that fact. */
1074 if (DECL_EXTERNAL (link))
1076 if (TREE_USED (link))
1077 TREE_USED (DECL_NAME (link)) = 1;
1078 if (TREE_ADDRESSABLE (link))
1079 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1081 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
1085 /* Restore all name-meanings of the outer levels
1086 that were shadowed by this level. */
1088 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1089 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1091 /* If the level being exited is the top level of a function,
1092 check over all the labels, and clear out the current
1093 (function local) meanings of their names. */
1097 clear_limbo_values (block);
1099 /* If this is the top level block of a function,
1100 the vars are the function's parameters.
1101 Don't leave them in the BLOCK because they are
1102 found in the FUNCTION_DECL instead. */
1104 BLOCK_VARS (block) = 0;
1106 /* Clear out the definitions of all label names,
1107 since their scopes end here,
1108 and add them to BLOCK_VARS. */
1110 for (link = named_labels; link; link = TREE_CHAIN (link))
1112 register tree label = TREE_VALUE (link);
1114 if (DECL_INITIAL (label) == 0)
1116 error_with_decl (label, "label `%s' used but not defined");
1117 /* Avoid crashing later. */
1118 define_label (input_filename, lineno,
1121 else if (warn_unused && !TREE_USED (label))
1122 warning_with_decl (label, "label `%s' defined but not used");
1123 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1125 /* Put the labels into the "variables" of the
1126 top-level block, so debugger can see them. */
1127 TREE_CHAIN (label) = BLOCK_VARS (block);
1128 BLOCK_VARS (block) = label;
1132 /* Pop the current level, and free the structure for reuse. */
1135 register struct binding_level *level = current_binding_level;
1136 current_binding_level = current_binding_level->level_chain;
1138 level->level_chain = free_binding_level;
1139 free_binding_level = level;
1142 /* Dispose of the block that we just made inside some higher level. */
1144 DECL_INITIAL (current_function_decl) = block;
1147 if (!block_previously_created)
1148 current_binding_level->blocks
1149 = chainon (current_binding_level->blocks, block);
1151 /* If we did not make a block for the level just exited,
1152 any blocks made for inner levels
1153 (since they cannot be recorded as subblocks in that level)
1154 must be carried forward so they will later become subblocks
1155 of something else. */
1157 current_binding_level->blocks
1158 = chainon (current_binding_level->blocks, subblocks);
1160 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1161 binding contour so that they point to the appropriate construct, i.e.
1162 either to the current FUNCTION_DECL node, or else to the BLOCK node
1163 we just constructed.
1165 Note that for tagged types whose scope is just the formal parameter
1166 list for some function type specification, we can't properly set
1167 their TYPE_CONTEXTs here, because we don't have a pointer to the
1168 appropriate FUNCTION_TYPE node readily available to us. For those
1169 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1170 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1171 node which will represent the "scope" for these "parameter list local"
1176 for (link = tags; link; link = TREE_CHAIN (link))
1177 TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl;
1179 for (link = tags; link; link = TREE_CHAIN (link))
1180 TYPE_CONTEXT (TREE_VALUE (link)) = block;
1183 TREE_USED (block) = 1;
1187 /* Delete the node BLOCK from the current binding level.
1188 This is used for the block inside a stmt expr ({...})
1189 so that the block can be reinserted where appropriate. */
1192 delete_block (block)
1196 if (current_binding_level->blocks == block)
1197 current_binding_level->blocks = TREE_CHAIN (block);
1198 for (t = current_binding_level->blocks; t;)
1200 if (TREE_CHAIN (t) == block)
1201 TREE_CHAIN (t) = TREE_CHAIN (block);
1205 TREE_CHAIN (block) = NULL;
1206 /* Clear TREE_USED which is always set by poplevel.
1207 The flag is set again if insert_block is called. */
1208 TREE_USED (block) = 0;
1211 /* Insert BLOCK at the end of the list of subblocks of the
1212 current binding level. This is used when a BIND_EXPR is expanded,
1213 to handle the BLOCK node inside the BIND_EXPR. */
1216 insert_block (block)
1219 TREE_USED (block) = 1;
1220 current_binding_level->blocks
1221 = chainon (current_binding_level->blocks, block);
1224 /* Set the BLOCK node for the innermost scope
1225 (the one we are currently in). */
1229 register tree block;
1231 current_binding_level->this_block = block;
1237 register struct binding_level *newlevel;
1239 /* Reuse or create a struct for this binding level. */
1241 if (free_binding_level)
1243 newlevel = free_binding_level;
1244 free_binding_level = free_binding_level->level_chain;
1248 newlevel = make_binding_level ();
1251 /* Add this level to the front of the chain (stack) of label levels. */
1253 newlevel->level_chain = label_level_chain;
1254 label_level_chain = newlevel;
1256 newlevel->names = named_labels;
1257 newlevel->shadowed = shadowed_labels;
1259 shadowed_labels = 0;
1265 register struct binding_level *level = label_level_chain;
1268 /* Clear out the definitions of the declared labels in this level.
1269 Leave in the list any ordinary, non-declared labels. */
1270 for (link = named_labels, prev = 0; link;)
1272 if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
1274 if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
1276 error_with_decl (TREE_VALUE (link),
1277 "label `%s' used but not defined");
1278 /* Avoid crashing later. */
1279 define_label (input_filename, lineno,
1280 DECL_NAME (TREE_VALUE (link)));
1282 else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
1283 warning_with_decl (TREE_VALUE (link),
1284 "label `%s' defined but not used");
1285 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
1287 /* Delete this element from the list. */
1288 link = TREE_CHAIN (link);
1290 TREE_CHAIN (prev) = link;
1292 named_labels = link;
1297 link = TREE_CHAIN (link);
1301 /* Bring back all the labels that were shadowed. */
1302 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
1303 if (DECL_NAME (TREE_VALUE (link)) != 0)
1304 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
1305 = TREE_VALUE (link);
1307 named_labels = chainon (named_labels, level->names);
1308 shadowed_labels = level->shadowed;
1310 /* Pop the current level, and free the structure for reuse. */
1311 label_level_chain = label_level_chain->level_chain;
1312 level->level_chain = free_binding_level;
1313 free_binding_level = level;
1316 /* Push a definition or a declaration of struct, union or enum tag "name".
1317 "type" should be the type node.
1318 We assume that the tag "name" is not already defined.
1320 Note that the definition may really be just a forward reference.
1321 In that case, the TYPE_SIZE will be zero. */
1324 pushtag (name, type)
1327 register struct binding_level *b;
1329 /* Find the proper binding level for this type tag. */
1331 for (b = current_binding_level; b->tag_transparent; b = b->level_chain)
1336 /* Record the identifier as the type's name if it has none. */
1338 if (TYPE_NAME (type) == 0)
1339 TYPE_NAME (type) = name;
1342 b->tags = tree_cons (name, type, b->tags);
1344 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1345 tagged type we just added to the current binding level. This fake
1346 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1347 to output a representation of a tagged type, and it also gives
1348 us a convenient place to record the "scope start" address for the
1351 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
1353 /* An approximation for now, so we can tell this is a function-scope tag.
1354 This will be updated in poplevel. */
1355 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1358 /* Handle when a new declaration NEWDECL
1359 has the same name as an old one OLDDECL
1360 in the same binding contour.
1361 Prints an error message if appropriate.
1363 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
1364 Otherwise, return 0.
1366 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration,
1367 and OLDDECL is in an outer binding level and should thus not be changed. */
1370 duplicate_decls (newdecl, olddecl, different_binding_level)
1371 register tree newdecl, olddecl;
1372 int different_binding_level;
1374 int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1375 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1376 && DECL_INITIAL (newdecl) != 0);
1377 tree oldtype = TREE_TYPE (olddecl);
1378 tree newtype = TREE_TYPE (newdecl);
1381 if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
1382 DECL_MACHINE_ATTRIBUTES (newdecl)
1383 = merge_machine_decl_attributes (olddecl, newdecl);
1385 if (TREE_CODE (newtype) == ERROR_MARK
1386 || TREE_CODE (oldtype) == ERROR_MARK)
1389 /* New decl is completely inconsistent with the old one =>
1390 tell caller to replace the old one.
1391 This is always an error except in the case of shadowing a builtin. */
1392 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1394 if (TREE_CODE (olddecl) == FUNCTION_DECL
1395 && (DECL_BUILT_IN (olddecl)
1396 || DECL_BUILT_IN_NONANSI (olddecl)))
1398 /* If you declare a built-in or predefined function name as static,
1399 the old definition is overridden,
1400 but optionally warn this was a bad choice of name. */
1401 if (!TREE_PUBLIC (newdecl))
1405 else if (DECL_BUILT_IN (olddecl))
1406 warning_with_decl (newdecl, "shadowing built-in function `%s'");
1408 warning_with_decl (newdecl, "shadowing library function `%s'");
1410 /* Likewise, if the built-in is not ansi, then programs can
1411 override it even globally without an error. */
1412 else if (! DECL_BUILT_IN (olddecl))
1413 warning_with_decl (newdecl,
1414 "library function `%s' declared as non-function");
1416 else if (DECL_BUILT_IN_NONANSI (olddecl))
1417 warning_with_decl (newdecl,
1418 "built-in function `%s' declared as non-function");
1420 warning_with_decl (newdecl,
1421 "built-in function `%s' declared as non-function");
1425 error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
1426 error_with_decl (olddecl, "previous declaration of `%s'");
1432 /* For real parm decl following a forward decl,
1433 return 1 so old decl will be reused. */
1434 if (types_match && TREE_CODE (newdecl) == PARM_DECL
1435 && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
1438 /* The new declaration is the same kind of object as the old one.
1439 The declarations may partially match. Print warnings if they don't
1440 match enough. Ultimately, copy most of the information from the new
1441 decl to the old one, and keep using the old one. */
1443 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
1444 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl
1445 && DECL_INITIAL (olddecl) == 0)
1446 /* If -traditional, avoid error for redeclaring fcn
1447 after implicit decl. */
1449 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1450 && DECL_BUILT_IN (olddecl))
1452 /* A function declaration for a built-in function. */
1453 if (!TREE_PUBLIC (newdecl))
1455 /* If you declare a built-in function name as static, the
1456 built-in definition is overridden,
1457 but optionally warn this was a bad choice of name. */
1459 warning_with_decl (newdecl, "shadowing built-in function `%s'");
1460 /* Discard the old built-in function. */
1463 else if (!types_match)
1465 /* Accept the return type of the new declaration if same modes. */
1466 tree oldreturntype = TREE_TYPE (oldtype);
1467 tree newreturntype = TREE_TYPE (newtype);
1469 if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
1471 /* Function types may be shared, so we can't just modify
1472 the return type of olddecl's function type. */
1474 = build_function_type (newreturntype,
1475 TYPE_ARG_TYPES (oldtype));
1477 types_match = comptypes (newtype, trytype);
1481 /* Accept harmless mismatch in first argument type also.
1483 if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0
1484 && TYPE_ARG_TYPES (oldtype) != 0
1485 && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0
1486 && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0
1487 && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype)))
1488 == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype)))))
1490 /* Function types may be shared, so we can't just modify
1491 the return type of olddecl's function type. */
1493 = build_function_type (TREE_TYPE (oldtype),
1494 tree_cons (NULL_TREE,
1495 TREE_VALUE (TYPE_ARG_TYPES (newtype)),
1496 TREE_CHAIN (TYPE_ARG_TYPES (oldtype))));
1498 types_match = comptypes (newtype, trytype);
1502 if (! different_binding_level)
1503 TREE_TYPE (olddecl) = oldtype;
1507 /* If types don't match for a built-in, throw away the built-in. */
1508 warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
1512 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1513 && DECL_SOURCE_LINE (olddecl) == 0)
1515 /* A function declaration for a predeclared function
1516 that isn't actually built in. */
1517 if (!TREE_PUBLIC (newdecl))
1519 /* If you declare it as static, the
1520 default definition is overridden. */
1523 else if (!types_match)
1525 /* If the types don't match, preserve volatility indication.
1526 Later on, we will discard everything else about the
1527 default declaration. */
1528 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1531 /* Permit char *foo () to match void *foo (...) if not pedantic,
1532 if one of them came from a system header file. */
1533 else if (!types_match
1534 && TREE_CODE (olddecl) == FUNCTION_DECL
1535 && TREE_CODE (newdecl) == FUNCTION_DECL
1536 && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
1537 && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
1538 && (DECL_IN_SYSTEM_HEADER (olddecl)
1539 || DECL_IN_SYSTEM_HEADER (newdecl))
1540 && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
1541 && TYPE_ARG_TYPES (oldtype) == 0
1542 && self_promoting_args_p (TYPE_ARG_TYPES (newtype))
1543 && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
1545 (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
1546 && TYPE_ARG_TYPES (newtype) == 0
1547 && self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
1548 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
1551 pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1552 /* Make sure we keep void * as ret type, not char *. */
1553 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
1554 TREE_TYPE (newdecl) = newtype = oldtype;
1556 /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration
1557 we will come back here again. */
1558 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1560 else if (!types_match
1561 /* Permit char *foo (int, ...); followed by char *foo ();
1563 && ! (TREE_CODE (olddecl) == FUNCTION_DECL
1565 /* Return types must still match. */
1566 && comptypes (TREE_TYPE (oldtype),
1567 TREE_TYPE (newtype))
1568 && TYPE_ARG_TYPES (newtype) == 0))
1570 error_with_decl (newdecl, "conflicting types for `%s'");
1571 /* Check for function type mismatch
1572 involving an empty arglist vs a nonempty one. */
1573 if (TREE_CODE (olddecl) == FUNCTION_DECL
1574 && comptypes (TREE_TYPE (oldtype),
1575 TREE_TYPE (newtype))
1576 && ((TYPE_ARG_TYPES (oldtype) == 0
1577 && DECL_INITIAL (olddecl) == 0)
1579 (TYPE_ARG_TYPES (newtype) == 0
1580 && DECL_INITIAL (newdecl) == 0)))
1582 /* Classify the problem further. */
1583 register tree t = TYPE_ARG_TYPES (oldtype);
1585 t = TYPE_ARG_TYPES (newtype);
1586 for (; t; t = TREE_CHAIN (t))
1588 register tree type = TREE_VALUE (t);
1590 if (TREE_CHAIN (t) == 0
1591 && TYPE_MAIN_VARIANT (type) != void_type_node)
1593 error ("A parameter list with an ellipsis can't match an empty parameter name list declaration.");
1597 if (simple_type_promotes_to (type) != NULL_TREE)
1599 error ("An argument type that has a default promotion can't match an empty parameter name list declaration.");
1604 error_with_decl (olddecl, "previous declaration of `%s'");
1608 errmsg = redeclaration_error_message (newdecl, olddecl);
1614 error_with_decl (newdecl, "redefinition of `%s'");
1617 error_with_decl (newdecl, "redeclaration of `%s'");
1620 error_with_decl (newdecl, "conflicting declarations of `%s'");
1626 error_with_decl (olddecl,
1627 ((DECL_INITIAL (olddecl)
1628 && current_binding_level == global_binding_level)
1629 ? "`%s' previously defined here"
1630 : "`%s' previously declared here"));
1632 else if (TREE_CODE (newdecl) == TYPE_DECL
1633 && (DECL_IN_SYSTEM_HEADER (olddecl)
1634 || DECL_IN_SYSTEM_HEADER (newdecl)))
1636 warning_with_decl (newdecl, "redefinition of `%s'");
1639 ((DECL_INITIAL (olddecl)
1640 && current_binding_level == global_binding_level)
1641 ? "`%s' previously defined here"
1642 : "`%s' previously declared here"));
1644 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1645 && DECL_INITIAL (olddecl) != 0
1646 && TYPE_ARG_TYPES (oldtype) == 0
1647 && TYPE_ARG_TYPES (newtype) != 0
1648 && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0)
1650 register tree type, parm;
1652 /* Prototype decl follows defn w/o prototype. */
1654 for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
1655 type = TYPE_ARG_TYPES (newtype),
1658 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
1660 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1661 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1663 warning_with_decl (newdecl, "prototype for `%s' follows");
1664 warning_with_decl (olddecl, "non-prototype definition here");
1667 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1668 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1670 error_with_decl (newdecl, "prototype for `%s' follows and number of arguments doesn't match");
1671 error_with_decl (olddecl, "non-prototype definition here");
1675 /* Type for passing arg must be consistent
1676 with that declared for the arg. */
1677 if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type))
1678 /* If -traditional, allow `unsigned int' instead of `int'
1679 in the prototype. */
1680 && (! (flag_traditional
1681 && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node
1682 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)))
1684 error_with_decl (newdecl,
1685 "prototype for `%s' follows and argument %d doesn't match",
1687 error_with_decl (olddecl, "non-prototype definition here");
1693 /* Warn about mismatches in various flags. */
1696 /* Warn if function is now inline
1697 but was previously declared not inline and has been called. */
1698 if (TREE_CODE (olddecl) == FUNCTION_DECL
1699 && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
1700 && TREE_USED (olddecl))
1701 warning_with_decl (newdecl,
1702 "`%s' declared inline after being called");
1703 if (TREE_CODE (olddecl) == FUNCTION_DECL
1704 && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
1705 && DECL_INITIAL (olddecl) != 0)
1706 warning_with_decl (newdecl,
1707 "`%s' declared inline after its definition");
1709 /* If pedantic, warn when static declaration follows a non-static
1710 declaration. Otherwise, do so only for functions. */
1711 if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL)
1712 && TREE_PUBLIC (olddecl)
1713 && !TREE_PUBLIC (newdecl))
1714 warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
1716 /* If warn_traditional, warn when a non-static function
1717 declaration follows a static one. */
1718 if (warn_traditional
1719 && TREE_CODE (olddecl) == FUNCTION_DECL
1720 && !TREE_PUBLIC (olddecl)
1721 && TREE_PUBLIC (newdecl))
1722 warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
1724 /* Warn when const declaration follows a non-const
1725 declaration, but not for functions. */
1726 if (TREE_CODE (olddecl) != FUNCTION_DECL
1727 && !TREE_READONLY (olddecl)
1728 && TREE_READONLY (newdecl))
1729 warning_with_decl (newdecl, "const declaration for `%s' follows non-const");
1730 /* These bits are logically part of the type, for variables.
1731 But not for functions
1732 (where qualifiers are not valid ANSI anyway). */
1733 else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
1734 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1735 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1736 pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1740 /* Optionally warn about more than one declaration for the same name. */
1741 if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
1742 /* Don't warn about a function declaration
1743 followed by a definition. */
1744 && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
1745 && DECL_INITIAL (olddecl) == 0)
1746 /* Don't warn about extern decl followed by (tentative) definition. */
1747 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
1749 warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
1750 warning_with_decl (olddecl, "previous declaration of `%s'");
1753 /* Copy all the DECL_... slots specified in the new decl
1754 except for any that we copy here from the old type.
1756 Past this point, we don't change OLDTYPE and NEWTYPE
1757 even if we change the types of NEWDECL and OLDDECL. */
1761 /* When copying info to olddecl, we store into write_olddecl
1762 instead. This allows us to avoid modifying olddecl when
1763 different_binding_level is true. */
1764 tree write_olddecl = different_binding_level ? newdecl : olddecl;
1766 /* Merge the data types specified in the two decls. */
1767 if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
1769 if (different_binding_level)
1771 = build_type_attribute_variant
1773 merge_attributes (TYPE_ATTRIBUTES (newtype),
1774 TYPE_ATTRIBUTES (oldtype)));
1777 = TREE_TYPE (olddecl)
1778 = common_type (newtype, oldtype);
1781 /* Lay the type out, unless already done. */
1782 if (oldtype != TREE_TYPE (newdecl))
1784 if (TREE_TYPE (newdecl) != error_mark_node)
1785 layout_type (TREE_TYPE (newdecl));
1786 if (TREE_CODE (newdecl) != FUNCTION_DECL
1787 && TREE_CODE (newdecl) != TYPE_DECL
1788 && TREE_CODE (newdecl) != CONST_DECL)
1789 layout_decl (newdecl, 0);
1793 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1794 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1795 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1796 if (TREE_CODE (olddecl) != FUNCTION_DECL)
1797 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1798 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1801 /* Keep the old rtl since we can safely use it. */
1802 DECL_RTL (newdecl) = DECL_RTL (olddecl);
1804 /* Merge the type qualifiers. */
1805 if (DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl)
1806 && !TREE_THIS_VOLATILE (newdecl))
1807 TREE_THIS_VOLATILE (write_olddecl) = 0;
1808 if (TREE_READONLY (newdecl))
1809 TREE_READONLY (write_olddecl) = 1;
1810 if (TREE_THIS_VOLATILE (newdecl))
1812 TREE_THIS_VOLATILE (write_olddecl) = 1;
1813 if (TREE_CODE (newdecl) == VAR_DECL)
1814 make_var_volatile (newdecl);
1817 /* Keep source location of definition rather than declaration. */
1818 /* When called with different_binding_level set, keep the old
1819 information so that meaningful diagnostics can be given. */
1820 if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
1821 && ! different_binding_level)
1823 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
1824 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
1827 /* Merge the unused-warning information. */
1828 if (DECL_IN_SYSTEM_HEADER (olddecl))
1829 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1830 else if (DECL_IN_SYSTEM_HEADER (newdecl))
1831 DECL_IN_SYSTEM_HEADER (write_olddecl) = 1;
1833 /* Merge the initialization information. */
1834 /* When called with different_binding_level set, don't copy over
1835 DECL_INITIAL, so that we don't accidentally change function
1836 declarations into function definitions. */
1837 if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
1838 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1840 /* Merge the section attribute.
1841 We want to issue an error if the sections conflict but that must be
1842 done later in decl_attributes since we are called before attributes
1844 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1845 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1847 /* Copy the assembler name.
1848 Currently, it can only be defined in the prototype. */
1849 DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
1851 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1853 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1854 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1856 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1857 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1858 DECL_NO_CHECK_MEMORY_USAGE (newdecl)
1859 |= DECL_NO_CHECK_MEMORY_USAGE (olddecl);
1860 DECL_NO_LIMIT_STACK (newdecl)
1861 |= DECL_NO_LIMIT_STACK (olddecl);
1864 /* If cannot merge, then use the new type and qualifiers,
1865 and don't preserve the old rtl. */
1866 else if (! different_binding_level)
1868 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1869 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1870 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1871 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1874 /* Merge the storage class information. */
1875 DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
1876 /* For functions, static overrides non-static. */
1877 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1879 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1880 /* This is since we don't automatically
1881 copy the attributes of NEWDECL into OLDDECL. */
1882 /* No need to worry about different_binding_level here because
1883 then TREE_PUBLIC (newdecl) was true. */
1884 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1885 /* If this clears `static', clear it in the identifier too. */
1886 if (! TREE_PUBLIC (olddecl))
1887 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1889 if (DECL_EXTERNAL (newdecl))
1891 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
1892 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1893 /* An extern decl does not override previous storage class. */
1894 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1895 if (! DECL_EXTERNAL (newdecl))
1896 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1900 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1901 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1904 /* If either decl says `inline', this fn is inline,
1905 unless its definition was passed already. */
1906 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0)
1907 DECL_INLINE (olddecl) = 1;
1908 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
1910 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1912 if (DECL_BUILT_IN (olddecl))
1914 /* Get rid of any built-in function if new arg types don't match it
1915 or if we have a function definition. */
1916 if (! types_match || new_is_definition)
1918 if (! different_binding_level)
1920 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1921 DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN;
1926 /* If redeclaring a builtin function, and not a definition,
1927 it stays built in. */
1928 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1929 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1932 /* Also preserve various other info from the definition. */
1933 else if (! new_is_definition)
1934 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
1935 if (! new_is_definition)
1937 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1938 /* When called with different_binding_level set, don't copy over
1939 DECL_INITIAL, so that we don't accidentally change function
1940 declarations into function definitions. */
1941 if (! different_binding_level)
1942 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1943 DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
1944 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
1945 if (DECL_INLINE (newdecl))
1946 DECL_ABSTRACT_ORIGIN (newdecl) = DECL_ORIGIN (olddecl);
1949 if (different_binding_level)
1951 /* Don't output a duplicate symbol or debugging information for this
1954 Do not set TREE_ASM_WRITTEN for a FUNCTION_DECL since we may actually
1955 just have two declarations without a definition. VAR_DECLs may need
1956 the same treatment, I'm not sure. */
1957 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1958 DECL_IGNORED_P (newdecl) = 1;
1960 TREE_ASM_WRITTEN (newdecl) = DECL_IGNORED_P (newdecl) = 1;
1964 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1965 But preserve OLDDECL's DECL_UID. */
1967 register unsigned olddecl_uid = DECL_UID (olddecl);
1969 bcopy ((char *) newdecl + sizeof (struct tree_common),
1970 (char *) olddecl + sizeof (struct tree_common),
1971 sizeof (struct tree_decl) - sizeof (struct tree_common));
1972 DECL_UID (olddecl) = olddecl_uid;
1975 /* NEWDECL contains the merged attribute lists.
1976 Update OLDDECL to be the same. */
1977 DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl);
1982 /* Record a decl-node X as belonging to the current lexical scope.
1983 Check for errors (such as an incompatible declaration for the same
1984 name already seen in the same scope).
1986 Returns either X or an old decl for the same name.
1987 If an old decl is returned, it may have been smashed
1988 to agree with what X says. */
1995 register tree name = DECL_NAME (x);
1996 register struct binding_level *b = current_binding_level;
1998 DECL_CONTEXT (x) = current_function_decl;
1999 /* A local extern declaration for a function doesn't constitute nesting.
2000 A local auto declaration does, since it's a forward decl
2001 for a nested function coming later. */
2002 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0
2003 && DECL_EXTERNAL (x))
2004 DECL_CONTEXT (x) = 0;
2006 if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level
2007 && x != IDENTIFIER_IMPLICIT_DECL (name)
2008 /* Don't print error messages for __FUNCTION__ and __PRETTY_FUNCTION__ */
2009 && !DECL_IN_SYSTEM_HEADER (x))
2010 warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name));
2016 int different_binding_level = 0;
2018 t = lookup_name_current_level (name);
2019 /* Don't type check externs here when -traditional. This is so that
2020 code with conflicting declarations inside blocks will get warnings
2021 not errors. X11 for instance depends on this. */
2022 if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x) && ! flag_traditional)
2024 t = IDENTIFIER_GLOBAL_VALUE (name);
2025 /* Type decls at global scope don't conflict with externs declared
2026 inside lexical blocks. */
2027 if (t && TREE_CODE (t) == TYPE_DECL)
2029 different_binding_level = 1;
2031 if (t != 0 && t == error_mark_node)
2032 /* error_mark_node is 0 for a while during initialization! */
2035 error_with_decl (x, "`%s' used prior to declaration");
2040 file = DECL_SOURCE_FILE (t);
2041 line = DECL_SOURCE_LINE (t);
2044 /* If this decl is `static' and an implicit decl was seen previously,
2045 warn. But don't complain if -traditional,
2046 since traditional compilers don't complain. */
2047 if (! flag_traditional && TREE_PUBLIC (name)
2048 /* Don't test for DECL_EXTERNAL, because grokdeclarator
2049 sets this for all functions. */
2050 && ! TREE_PUBLIC (x)
2051 && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level)
2052 /* We used to warn also for explicit extern followed by static,
2053 but sometimes you need to do it that way. */
2054 && IDENTIFIER_IMPLICIT_DECL (name) != 0)
2056 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2057 IDENTIFIER_POINTER (name));
2058 pedwarn_with_file_and_line
2059 (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)),
2060 DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)),
2061 "previous declaration of `%s'",
2062 IDENTIFIER_POINTER (name));
2063 TREE_THIS_VOLATILE (name) = 1;
2066 if (t != 0 && duplicate_decls (x, t, different_binding_level))
2068 if (TREE_CODE (t) == PARM_DECL)
2070 /* Don't allow more than one "real" duplicate
2071 of a forward parm decl. */
2072 TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x);
2078 /* If we are processing a typedef statement, generate a whole new
2079 ..._TYPE node (which will be just an variant of the existing
2080 ..._TYPE node with identical properties) and then install the
2081 TYPE_DECL node generated to represent the typedef name as the
2082 TYPE_NAME of this brand new (duplicate) ..._TYPE node.
2084 The whole point here is to end up with a situation where each
2085 and every ..._TYPE node the compiler creates will be uniquely
2086 associated with AT MOST one node representing a typedef name.
2087 This way, even though the compiler substitutes corresponding
2088 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
2089 early on, later parts of the compiler can always do the reverse
2090 translation and get back the corresponding typedef name. For
2093 typedef struct S MY_TYPE;
2096 Later parts of the compiler might only know that `object' was of
2097 type `struct S' if it were not for code just below. With this
2098 code however, later parts of the compiler see something like:
2100 struct S' == struct S
2101 typedef struct S' MY_TYPE;
2104 And they can then deduce (from the node for type struct S') that
2105 the original object declaration was:
2109 Being able to do this is important for proper support of protoize,
2110 and also for generating precise symbolic debugging information
2111 which takes full account of the programmer's (typedef) vocabulary.
2113 Obviously, we don't want to generate a duplicate ..._TYPE node if
2114 the TYPE_DECL node that we are now processing really represents a
2115 standard built-in type.
2117 Since all standard types are effectively declared at line zero
2118 in the source file, we can easily check to see if we are working
2119 on a standard type by checking the current value of lineno. */
2121 if (TREE_CODE (x) == TYPE_DECL)
2123 if (DECL_SOURCE_LINE (x) == 0)
2125 if (TYPE_NAME (TREE_TYPE (x)) == 0)
2126 TYPE_NAME (TREE_TYPE (x)) = x;
2128 else if (TREE_TYPE (x) != error_mark_node
2129 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
2131 tree tt = TREE_TYPE (x);
2132 DECL_ORIGINAL_TYPE (x) = tt;
2133 tt = build_type_copy (tt);
2139 /* Multiple external decls of the same identifier ought to match.
2140 Check against both global declarations (when traditional) and out of
2141 scope (limbo) block level declarations.
2143 We get warnings about inline functions where they are defined.
2144 Avoid duplicate warnings where they are used. */
2145 if (TREE_PUBLIC (x) && ! DECL_INLINE (x))
2149 if (flag_traditional && IDENTIFIER_GLOBAL_VALUE (name) != 0
2150 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2151 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2152 decl = IDENTIFIER_GLOBAL_VALUE (name);
2153 else if (IDENTIFIER_LIMBO_VALUE (name) != 0)
2154 /* Decls in limbo are always extern, so no need to check that. */
2155 decl = IDENTIFIER_LIMBO_VALUE (name);
2159 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl))
2160 /* If old decl is built-in, we already warned if we should. */
2161 && !DECL_BUILT_IN (decl))
2163 pedwarn_with_decl (x,
2164 "type mismatch with previous external decl");
2165 pedwarn_with_decl (decl, "previous external decl of `%s'");
2169 /* If a function has had an implicit declaration, and then is defined,
2170 make sure they are compatible. */
2172 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2173 && IDENTIFIER_GLOBAL_VALUE (name) == 0
2174 && TREE_CODE (x) == FUNCTION_DECL
2175 && ! comptypes (TREE_TYPE (x),
2176 TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name))))
2178 warning_with_decl (x, "type mismatch with previous implicit declaration");
2179 warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name),
2180 "previous implicit declaration of `%s'");
2183 /* In PCC-compatibility mode, extern decls of vars with no current decl
2184 take effect at top level no matter where they are. */
2185 if (flag_traditional && DECL_EXTERNAL (x)
2186 && lookup_name (name) == 0)
2188 tree type = TREE_TYPE (x);
2190 /* But don't do this if the type contains temporary nodes. */
2193 if (type == error_mark_node)
2195 if (! TYPE_CONTEXT (type))
2197 warning_with_decl (x, "type of external `%s' is not global");
2198 /* By exiting the loop early, we leave TYPE nonzero,
2199 and thus prevent globalization of the decl. */
2202 else if (TREE_CODE (type) == FUNCTION_TYPE
2203 && TYPE_ARG_TYPES (type) != 0)
2204 /* The types might not be truly local,
2205 but the list of arg types certainly is temporary.
2206 Since prototypes are nontraditional,
2207 ok not to do the traditional thing. */
2209 type = TREE_TYPE (type);
2213 b = global_binding_level;
2216 /* This name is new in its binding level.
2217 Install the new declaration and return it. */
2218 if (b == global_binding_level)
2220 /* Install a global value. */
2222 /* If the first global decl has external linkage,
2223 warn if we later see static one. */
2224 if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
2225 TREE_PUBLIC (name) = 1;
2227 IDENTIFIER_GLOBAL_VALUE (name) = x;
2229 /* We no longer care about any previous block level declarations. */
2230 IDENTIFIER_LIMBO_VALUE (name) = 0;
2232 /* Don't forget if the function was used via an implicit decl. */
2233 if (IDENTIFIER_IMPLICIT_DECL (name)
2234 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2235 TREE_USED (x) = 1, TREE_USED (name) = 1;
2237 /* Don't forget if its address was taken in that way. */
2238 if (IDENTIFIER_IMPLICIT_DECL (name)
2239 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2240 TREE_ADDRESSABLE (x) = 1;
2242 /* Warn about mismatches against previous implicit decl. */
2243 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2244 /* If this real decl matches the implicit, don't complain. */
2245 && ! (TREE_CODE (x) == FUNCTION_DECL
2246 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x)))
2247 == integer_type_node)))
2248 pedwarn ("`%s' was previously implicitly declared to return `int'",
2249 IDENTIFIER_POINTER (name));
2251 /* If this decl is `static' and an `extern' was seen previously,
2252 that is erroneous. */
2253 if (TREE_PUBLIC (name)
2254 && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
2256 /* Okay to redeclare an ANSI built-in as static. */
2257 if (t != 0 && DECL_BUILT_IN (t))
2259 /* Okay to declare a non-ANSI built-in as anything. */
2260 else if (t != 0 && DECL_BUILT_IN_NONANSI (t))
2262 /* Okay to have global type decl after an earlier extern
2263 declaration inside a lexical block. */
2264 else if (TREE_CODE (x) == TYPE_DECL)
2266 else if (IDENTIFIER_IMPLICIT_DECL (name))
2268 if (! TREE_THIS_VOLATILE (name))
2269 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2270 IDENTIFIER_POINTER (name));
2273 pedwarn ("`%s' was declared `extern' and later `static'",
2274 IDENTIFIER_POINTER (name));
2279 /* Here to install a non-global value. */
2280 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2281 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2282 IDENTIFIER_LOCAL_VALUE (name) = x;
2284 /* If this is an extern function declaration, see if we
2285 have a global definition or declaration for the function. */
2287 && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2289 && TREE_CODE (x) == FUNCTION_DECL
2290 && TREE_CODE (oldglobal) == FUNCTION_DECL)
2292 /* We have one. Their types must agree. */
2293 if (! comptypes (TREE_TYPE (x),
2294 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
2295 pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one");
2298 /* Inner extern decl is inline if global one is.
2299 Copy enough to really inline it. */
2300 if (DECL_INLINE (oldglobal))
2302 DECL_INLINE (x) = DECL_INLINE (oldglobal);
2303 DECL_INITIAL (x) = (current_function_decl == oldglobal
2304 ? 0 : DECL_INITIAL (oldglobal));
2305 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2306 DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2307 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2308 DECL_RESULT (x) = DECL_RESULT (oldglobal);
2309 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2310 DECL_ABSTRACT_ORIGIN (x) = DECL_ORIGIN (oldglobal);
2312 /* Inner extern decl is built-in if global one is. */
2313 if (DECL_BUILT_IN (oldglobal))
2315 DECL_BUILT_IN_CLASS (x) = DECL_BUILT_IN_CLASS (oldglobal);
2316 DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
2318 /* Keep the arg types from a file-scope fcn defn. */
2319 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
2320 && DECL_INITIAL (oldglobal)
2321 && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
2322 TREE_TYPE (x) = TREE_TYPE (oldglobal);
2326 #if 0 /* This case is probably sometimes the right thing to do. */
2327 /* If we have a local external declaration,
2328 then any file-scope declaration should not
2329 have been static. */
2330 if (oldlocal == 0 && oldglobal != 0
2331 && !TREE_PUBLIC (oldglobal)
2332 && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
2333 warning ("`%s' locally external but globally static",
2334 IDENTIFIER_POINTER (name));
2337 /* If we have a local external declaration,
2338 and no file-scope declaration has yet been seen,
2339 then if we later have a file-scope decl it must not be static. */
2341 && DECL_EXTERNAL (x)
2345 TREE_PUBLIC (name) = 1;
2347 /* Save this decl, so that we can do type checking against
2348 other decls after it falls out of scope.
2350 Only save it once. This prevents temporary decls created in
2351 expand_inline_function from being used here, since this
2352 will have been set when the inline function was parsed.
2353 It also helps give slightly better warnings. */
2354 if (IDENTIFIER_LIMBO_VALUE (name) == 0)
2355 IDENTIFIER_LIMBO_VALUE (name) = x;
2358 /* Warn if shadowing an argument at the top level of the body. */
2359 if (oldlocal != 0 && !DECL_EXTERNAL (x)
2360 /* This warning doesn't apply to the parms of a nested fcn. */
2361 && ! current_binding_level->parm_flag
2362 /* Check that this is one level down from the parms. */
2363 && current_binding_level->level_chain->parm_flag
2364 /* Check that the decl being shadowed
2365 comes from the parm level, one level up. */
2366 && chain_member (oldlocal, current_binding_level->level_chain->names))
2368 if (TREE_CODE (oldlocal) == PARM_DECL)
2369 pedwarn ("declaration of `%s' shadows a parameter",
2370 IDENTIFIER_POINTER (name));
2372 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
2373 IDENTIFIER_POINTER (name));
2376 /* Maybe warn if shadowing something else. */
2377 else if (warn_shadow && !DECL_EXTERNAL (x)
2378 /* No shadow warnings for internally generated vars. */
2379 && DECL_SOURCE_LINE (x) != 0
2380 /* No shadow warnings for vars made for inlining. */
2381 && ! DECL_FROM_INLINE (x))
2383 char *id = IDENTIFIER_POINTER (name);
2385 if (TREE_CODE (x) == PARM_DECL
2386 && current_binding_level->level_chain->parm_flag)
2387 /* Don't warn about the parm names in function declarator
2388 within a function declarator.
2389 It would be nice to avoid warning in any function
2390 declarator in a declaration, as opposed to a definition,
2391 but there is no way to tell it's not a definition. */
2393 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
2394 warning ("declaration of `%s' shadows a parameter", id);
2395 else if (oldlocal != 0)
2396 warning ("declaration of `%s' shadows previous local", id);
2397 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
2398 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
2399 warning ("declaration of `%s' shadows global declaration", id);
2402 /* If storing a local value, there may already be one (inherited).
2403 If so, record it for restoration when this binding level ends. */
2405 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2408 /* Keep count of variables in this level with incomplete type. */
2409 if (TYPE_SIZE (TREE_TYPE (x)) == 0)
2413 /* Put decls on list in reverse order.
2414 We will reverse them later if necessary. */
2415 TREE_CHAIN (x) = b->names;
2421 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
2424 pushdecl_top_level (x)
2428 register struct binding_level *b = current_binding_level;
2430 current_binding_level = global_binding_level;
2432 current_binding_level = b;
2436 /* Generate an implicit declaration for identifier FUNCTIONID
2437 as a function of type int (). Print a warning if appropriate. */
2440 implicitly_declare (functionid)
2444 int traditional_warning = 0;
2445 /* Only one "implicit declaration" warning per identifier. */
2446 int implicit_warning;
2448 /* We used to reuse an old implicit decl here,
2449 but this loses with inline functions because it can clobber
2450 the saved decl chains. */
2451 /* if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
2452 decl = IDENTIFIER_IMPLICIT_DECL (functionid);
2454 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2456 /* Warn of implicit decl following explicit local extern decl.
2457 This is probably a program designed for traditional C. */
2458 if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0)
2459 traditional_warning = 1;
2461 /* Warn once of an implicit declaration. */
2462 implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0);
2464 DECL_EXTERNAL (decl) = 1;
2465 TREE_PUBLIC (decl) = 1;
2467 /* Record that we have an implicit decl and this is it. */
2468 IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
2470 /* ANSI standard says implicit declarations are in the innermost block.
2471 So we record the decl in the standard fashion.
2472 If flag_traditional is set, pushdecl does it top-level. */
2475 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
2476 maybe_objc_check_decl (decl);
2478 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
2480 if (mesg_implicit_function_declaration && implicit_warning)
2482 if (mesg_implicit_function_declaration == 2)
2483 error ("implicit declaration of function `%s'",
2484 IDENTIFIER_POINTER (functionid));
2486 warning ("implicit declaration of function `%s'",
2487 IDENTIFIER_POINTER (functionid));
2489 else if (warn_traditional && traditional_warning)
2490 warning ("function `%s' was previously declared within a block",
2491 IDENTIFIER_POINTER (functionid));
2493 /* Write a record describing this implicit function declaration to the
2494 prototypes file (if requested). */
2496 gen_aux_info_record (decl, 0, 1, 0);
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 if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl))
2515 /* pushdecl creates distinct types for TYPE_DECLs by calling
2516 build_type_copy, so the above comparison generally fails. We do
2517 another test against the TYPE_MAIN_VARIANT of the olddecl, which
2518 is equivalent to what this code used to do before the build_type_copy
2519 call. The variant type distinction should not matter for traditional
2520 code, because it doesn't have type qualifiers. */
2521 if (flag_traditional
2522 && TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)) == TREE_TYPE (newdecl))
2524 if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl))
2528 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2530 /* Declarations of functions can insist on internal linkage
2531 but they can't be inconsistent with internal linkage,
2532 so there can be no error on that account.
2533 However defining the same name twice is no good. */
2534 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
2535 /* However, defining once as extern inline and a second
2536 time in another way is ok. */
2537 && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
2538 && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
2542 else if (current_binding_level == global_binding_level)
2544 /* Objects declared at top level: */
2545 /* If at least one is a reference, it's ok. */
2546 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2548 /* Reject two definitions. */
2549 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
2551 /* Now we have two tentative defs, or one tentative and one real def. */
2552 /* Insist that the linkage match. */
2553 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
2557 else if (current_binding_level->parm_flag
2558 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2562 /* Newdecl has block scope. If olddecl has block scope also, then
2563 reject two definitions, and reject a definition together with an
2564 external reference. Otherwise, it is OK, because newdecl must
2565 be an extern reference to olddecl. */
2566 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))
2567 && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl))
2573 /* Get the LABEL_DECL corresponding to identifier ID as a label.
2574 Create one if none exists so far for the current function.
2575 This function is called for both label definitions and label references. */
2581 register tree decl = IDENTIFIER_LABEL_VALUE (id);
2583 if (current_function_decl == 0)
2585 error ("label %s referenced outside of any function",
2586 IDENTIFIER_POINTER (id));
2590 /* Use a label already defined or ref'd with this name. */
2593 /* But not if it is inherited and wasn't declared to be inheritable. */
2594 if (DECL_CONTEXT (decl) != current_function_decl
2595 && ! C_DECLARED_LABEL_FLAG (decl))
2596 return shadow_label (id);
2600 decl = build_decl (LABEL_DECL, id, void_type_node);
2602 /* Make sure every label has an rtx. */
2605 /* A label not explicitly declared must be local to where it's ref'd. */
2606 DECL_CONTEXT (decl) = current_function_decl;
2608 DECL_MODE (decl) = VOIDmode;
2610 /* Say where one reference is to the label,
2611 for the sake of the error if it is not defined. */
2612 DECL_SOURCE_LINE (decl) = lineno;
2613 DECL_SOURCE_FILE (decl) = input_filename;
2615 IDENTIFIER_LABEL_VALUE (id) = decl;
2617 named_labels = tree_cons (NULL_TREE, decl, named_labels);
2622 /* Make a label named NAME in the current function,
2623 shadowing silently any that may be inherited from containing functions
2624 or containing scopes.
2626 Note that valid use, if the label being shadowed
2627 comes from another scope in the same function,
2628 requires calling declare_nonlocal_label right away. */
2634 register tree decl = IDENTIFIER_LABEL_VALUE (name);
2640 /* Check to make sure that the label hasn't already been declared
2641 at this label scope */
2642 for (dup = named_labels; dup; dup = TREE_CHAIN (dup))
2643 if (TREE_VALUE (dup) == decl)
2645 error ("duplicate label declaration `%s'",
2646 IDENTIFIER_POINTER (name));
2647 error_with_decl (TREE_VALUE (dup),
2648 "this is a previous declaration");
2649 /* Just use the previous declaration. */
2650 return lookup_label (name);
2653 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2654 IDENTIFIER_LABEL_VALUE (name) = decl = 0;
2657 return lookup_label (name);
2660 /* Define a label, specifying the location in the source file.
2661 Return the LABEL_DECL node for the label, if the definition is valid.
2662 Otherwise return 0. */
2665 define_label (filename, line, name)
2670 tree decl = lookup_label (name);
2672 /* If label with this name is known from an outer context, shadow it. */
2673 if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
2675 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2676 IDENTIFIER_LABEL_VALUE (name) = 0;
2677 decl = lookup_label (name);
2680 if (DECL_INITIAL (decl) != 0)
2682 error ("duplicate label `%s'", IDENTIFIER_POINTER (name));
2687 /* Mark label as having been defined. */
2688 DECL_INITIAL (decl) = error_mark_node;
2689 /* Say where in the source. */
2690 DECL_SOURCE_FILE (decl) = filename;
2691 DECL_SOURCE_LINE (decl) = line;
2696 /* Return the list of declarations of the current level.
2697 Note that this list is in reverse order unless/until
2698 you nreverse it; and when you do nreverse it, you must
2699 store the result back using `storedecls' or you will lose. */
2704 return current_binding_level->names;
2707 /* Return the list of type-tags (for structs, etc) of the current level. */
2712 return current_binding_level->tags;
2715 /* Store the list of declarations of the current level.
2716 This is done for the parameter declarations of a function being defined,
2717 after they are modified in the light of any missing parameters. */
2723 current_binding_level->names = decls;
2726 /* Similarly, store the list of tags of the current level. */
2732 current_binding_level->tags = tags;
2735 /* Given NAME, an IDENTIFIER_NODE,
2736 return the structure (or union or enum) definition for that name.
2737 Searches binding levels from BINDING_LEVEL up to the global level.
2738 If THISLEVEL_ONLY is nonzero, searches only the specified context
2739 (but skips any tag-transparent contexts to find one that is
2740 meaningful for tags).
2741 CODE says which kind of type the caller wants;
2742 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2743 If the wrong kind of type is found, an error is reported. */
2746 lookup_tag (code, name, binding_level, thislevel_only)
2747 enum tree_code code;
2748 struct binding_level *binding_level;
2752 register struct binding_level *level;
2754 for (level = binding_level; level; level = level->level_chain)
2757 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2759 if (TREE_PURPOSE (tail) == name)
2761 if (TREE_CODE (TREE_VALUE (tail)) != code)
2763 /* Definition isn't the kind we were looking for. */
2764 pending_invalid_xref = name;
2765 pending_invalid_xref_file = input_filename;
2766 pending_invalid_xref_line = lineno;
2768 return TREE_VALUE (tail);
2771 if (thislevel_only && ! level->tag_transparent)
2777 /* Print an error message now
2778 for a recent invalid struct, union or enum cross reference.
2779 We don't print them immediately because they are not invalid
2780 when used in the `struct foo;' construct for shadowing. */
2783 pending_xref_error ()
2785 if (pending_invalid_xref != 0)
2786 error_with_file_and_line (pending_invalid_xref_file,
2787 pending_invalid_xref_line,
2788 "`%s' defined as wrong kind of tag",
2789 IDENTIFIER_POINTER (pending_invalid_xref));
2790 pending_invalid_xref = 0;
2793 /* Given a type, find the tag that was defined for it and return the tag name.
2794 Otherwise return 0. */
2797 lookup_tag_reverse (type)
2800 register struct binding_level *level;
2802 for (level = current_binding_level; level; level = level->level_chain)
2805 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2807 if (TREE_VALUE (tail) == type)
2808 return TREE_PURPOSE (tail);
2814 /* Look up NAME in the current binding level and its superiors
2815 in the namespace of variables, functions and typedefs.
2816 Return a ..._DECL node of some kind representing its definition,
2817 or return 0 if it is undefined. */
2824 if (current_binding_level != global_binding_level
2825 && IDENTIFIER_LOCAL_VALUE (name))
2826 val = IDENTIFIER_LOCAL_VALUE (name);
2828 val = IDENTIFIER_GLOBAL_VALUE (name);
2832 /* Similar to `lookup_name' but look only at current binding level. */
2835 lookup_name_current_level (name)
2840 if (current_binding_level == global_binding_level)
2841 return IDENTIFIER_GLOBAL_VALUE (name);
2843 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
2846 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
2847 if (DECL_NAME (t) == name)
2853 /* Mark ARG for GC. */
2855 mark_binding_level (arg)
2858 struct binding_level *level = *(struct binding_level **) arg;
2862 ggc_mark_tree (level->names);
2863 ggc_mark_tree (level->tags);
2864 ggc_mark_tree (level->shadowed);
2865 ggc_mark_tree (level->blocks);
2866 ggc_mark_tree (level->this_block);
2867 ggc_mark_tree (level->parm_order);
2868 level = level->level_chain;
2872 /* Create the predefined scalar types of C,
2873 and some nodes representing standard constants (0, 1, (void *) 0).
2874 Initialize the global binding level.
2875 Make definitions for built-in primitive functions. */
2878 init_decl_processing ()
2880 register tree endlink;
2881 tree ptr_ftype_void, ptr_ftype_ptr;
2882 int wchar_type_size;
2883 tree array_domain_type;
2885 current_function_decl = NULL;
2886 named_labels = NULL;
2887 current_binding_level = NULL_BINDING_LEVEL;
2888 free_binding_level = NULL_BINDING_LEVEL;
2889 pushlevel (0); /* make the binding_level structure for global names */
2890 global_binding_level = current_binding_level;
2892 build_common_tree_nodes (flag_signed_char);
2894 /* Define `int' and `char' first so that dbx will output them first. */
2895 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
2896 integer_type_node));
2897 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
2899 pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
2900 long_integer_type_node));
2901 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
2902 unsigned_type_node));
2903 pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
2904 long_unsigned_type_node));
2905 pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),
2906 long_long_integer_type_node));
2907 pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),
2908 long_long_unsigned_type_node));
2909 pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
2910 short_integer_type_node));
2911 pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),
2912 short_unsigned_type_node));
2913 pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
2914 signed_char_type_node));
2915 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
2916 unsigned_char_type_node));
2917 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
2918 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
2919 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
2920 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
2921 #if HOST_BITS_PER_WIDE_INT >= 64
2922 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intTI_type_node));
2924 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
2925 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
2926 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
2927 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
2928 #if HOST_BITS_PER_WIDE_INT >= 64
2929 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intTI_type_node));
2932 /* `unsigned long' is the standard type for sizeof.
2933 Traditionally, use a signed type.
2934 Note that stddef.h uses `unsigned long',
2935 and this must agree, even if long and int are the same size. */
2937 (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))));
2938 if (flag_traditional && TREE_UNSIGNED (sizetype))
2939 set_sizetype (signed_type (sizetype));
2941 /* Create the widest literal types. */
2942 widest_integer_literal_type_node = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
2943 widest_unsigned_literal_type_node = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
2944 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2945 widest_integer_literal_type_node));
2946 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2947 widest_unsigned_literal_type_node));
2949 build_common_tree_nodes_2 (flag_short_double);
2951 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
2953 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
2955 pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
2956 long_double_type_node));
2957 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
2958 complex_integer_type_node));
2959 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
2960 complex_float_type_node));
2961 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
2962 complex_double_type_node));
2963 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
2964 complex_long_double_type_node));
2965 pushdecl (build_decl (TYPE_DECL,
2966 ridpointers[(int) RID_VOID], void_type_node));
2968 #ifdef MD_INIT_BUILTINS
2972 wchar_type_node = get_identifier (flag_short_wchar
2973 ? "short unsigned int"
2975 wchar_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (wchar_type_node));
2976 wchar_type_size = TYPE_PRECISION (wchar_type_node);
2977 signed_wchar_type_node = signed_type (wchar_type_node);
2978 unsigned_wchar_type_node = unsigned_type (wchar_type_node);
2980 boolean_type_node = integer_type_node;
2981 boolean_true_node = integer_one_node;
2982 boolean_false_node = integer_zero_node;
2984 string_type_node = build_pointer_type (char_type_node);
2985 const_string_type_node
2986 = build_pointer_type (build_type_variant (char_type_node, 1, 0));
2988 /* Make a type to be the domain of a few array types
2989 whose domains don't really matter.
2990 200 is small enough that it always fits in size_t
2991 and large enough that it can hold most function names for the
2992 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
2993 array_domain_type = build_index_type (build_int_2 (200, 0));
2995 /* make a type for arrays of characters.
2996 With luck nothing will ever really depend on the length of this
2998 char_array_type_node
2999 = build_array_type (char_type_node, array_domain_type);
3000 /* Likewise for arrays of ints. */
3002 = build_array_type (integer_type_node, array_domain_type);
3003 /* This is for wide string constants. */
3004 wchar_array_type_node
3005 = build_array_type (wchar_type_node, array_domain_type);
3007 void_list_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
3009 default_function_type
3010 = build_function_type (integer_type_node, NULL_TREE);
3012 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
3014 c_common_nodes_and_builtins (0, flag_no_builtin, flag_no_nonansi_builtin);
3016 endlink = void_list_node;
3017 ptr_ftype_void = build_function_type (ptr_type_node, endlink);
3019 = build_function_type (ptr_type_node,
3020 tree_cons (NULL_TREE, ptr_type_node, endlink));
3022 builtin_function ("__builtin_aggregate_incoming_address",
3023 build_function_type (ptr_type_node, NULL_TREE),
3024 BUILT_IN_AGGREGATE_INCOMING_ADDRESS,
3025 BUILT_IN_NORMAL, NULL_PTR);
3027 /* Hooks for the DWARF 2 __throw routine. */
3028 builtin_function ("__builtin_unwind_init",
3029 build_function_type (void_type_node, endlink),
3030 BUILT_IN_UNWIND_INIT, BUILT_IN_NORMAL, NULL_PTR);
3031 builtin_function ("__builtin_dwarf_cfa", ptr_ftype_void,
3032 BUILT_IN_DWARF_CFA, BUILT_IN_NORMAL, NULL_PTR);
3033 builtin_function ("__builtin_dwarf_fp_regnum",
3034 build_function_type (unsigned_type_node, endlink),
3035 BUILT_IN_DWARF_FP_REGNUM, BUILT_IN_NORMAL, NULL_PTR);
3036 builtin_function ("__builtin_init_dwarf_reg_size_table", void_ftype_ptr,
3037 BUILT_IN_INIT_DWARF_REG_SIZES, BUILT_IN_NORMAL, NULL_PTR);
3038 builtin_function ("__builtin_frob_return_addr", ptr_ftype_ptr,
3039 BUILT_IN_FROB_RETURN_ADDR, BUILT_IN_NORMAL, NULL_PTR);
3040 builtin_function ("__builtin_extract_return_addr", ptr_ftype_ptr,
3041 BUILT_IN_EXTRACT_RETURN_ADDR, BUILT_IN_NORMAL, NULL_PTR);
3043 ("__builtin_eh_return",
3044 build_function_type (void_type_node,
3045 tree_cons (NULL_TREE, ptr_type_node,
3046 tree_cons (NULL_TREE,
3047 type_for_mode (ptr_mode, 0),
3048 tree_cons (NULL_TREE,
3051 BUILT_IN_EH_RETURN, BUILT_IN_NORMAL, NULL_PTR);
3053 pedantic_lvalues = pedantic;
3055 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
3056 declare_function_name ();
3058 start_identifier_warnings ();
3060 /* Prepare to check format strings against argument lists. */
3061 init_function_format_info ();
3065 incomplete_decl_finalize_hook = finish_incomplete_decl;
3067 lang_get_alias_set = c_get_alias_set;
3069 /* Record our roots. */
3071 ggc_add_tree_root (c_global_trees, CTI_MAX);
3072 ggc_add_tree_root (¤t_function_decl, 1);
3073 ggc_add_tree_root (&named_labels, 1);
3074 ggc_add_tree_root (&shadowed_labels, 1);
3075 ggc_add_root (¤t_binding_level, 1, sizeof current_binding_level,
3076 mark_binding_level);
3077 ggc_add_root (&label_level_chain, 1, sizeof label_level_chain,
3078 mark_binding_level);
3079 ggc_add_tree_root (&static_ctors, 1);
3080 ggc_add_tree_root (&static_dtors, 1);
3083 /* Return a definition for a builtin function named NAME and whose data type
3084 is TYPE. TYPE should be a function type with argument types.
3085 FUNCTION_CODE tells later passes how to compile calls to this function.
3086 See tree.h for its possible values.
3088 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
3089 the name to be called if we can't opencode the function. */
3092 builtin_function (name, type, function_code, class, library_name)
3096 enum built_in_class class;
3097 const char *library_name;
3099 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
3100 DECL_EXTERNAL (decl) = 1;
3101 TREE_PUBLIC (decl) = 1;
3102 /* If -traditional, permit redefining a builtin function any way you like.
3103 (Though really, if the program redefines these functions,
3104 it probably won't work right unless compiled with -fno-builtin.) */
3105 if (flag_traditional && name[0] != '_')
3106 DECL_BUILT_IN_NONANSI (decl) = 1;
3108 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
3109 make_decl_rtl (decl, NULL_PTR, 1);
3111 DECL_BUILT_IN_CLASS (decl) = class;
3112 DECL_FUNCTION_CODE (decl) = function_code;
3114 /* Warn if a function in the namespace for users
3115 is used without an occasion to consider it declared. */
3116 if (name[0] != '_' || name[1] != '_')
3117 C_DECL_ANTICIPATED (decl) = 1;
3122 /* Called when a declaration is seen that contains no names to declare.
3123 If its type is a reference to a structure, union or enum inherited
3124 from a containing scope, shadow that tag name for the current scope
3125 with a forward reference.
3126 If its type defines a new named structure or union
3127 or defines an enum, it is valid but we need not do anything here.
3128 Otherwise, it is an error. */
3131 shadow_tag (declspecs)
3134 shadow_tag_warned (declspecs, 0);
3138 shadow_tag_warned (declspecs, warned)
3141 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
3148 pending_invalid_xref = 0;
3150 /* Remove the attributes from declspecs, since they will confuse the
3152 split_specs_attrs (declspecs, &specs, &attrs);
3154 for (link = specs; link; link = TREE_CHAIN (link))
3156 register tree value = TREE_VALUE (link);
3157 register enum tree_code code = TREE_CODE (value);
3159 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
3160 /* Used to test also that TYPE_SIZE (value) != 0.
3161 That caused warning for `struct foo;' at top level in the file. */
3163 register tree name = lookup_tag_reverse (value);
3170 if (warned != 1 && code != ENUMERAL_TYPE)
3171 /* Empty unnamed enum OK */
3173 pedwarn ("unnamed struct/union that defines no instances");
3179 t = lookup_tag (code, name, current_binding_level, 1);
3183 t = make_node (code);
3190 if (!warned && ! in_system_header)
3192 warning ("useless keyword or type name in empty declaration");
3199 error ("two types specified in one empty declaration");
3204 pedwarn ("empty declaration");
3208 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
3211 groktypename (typename)
3214 if (TREE_CODE (typename) != TREE_LIST)
3216 return grokdeclarator (TREE_VALUE (typename),
3217 TREE_PURPOSE (typename),
3221 /* Return a PARM_DECL node for a given pair of specs and declarator. */
3224 groktypename_in_parm_context (typename)
3227 if (TREE_CODE (typename) != TREE_LIST)
3229 return grokdeclarator (TREE_VALUE (typename),
3230 TREE_PURPOSE (typename),
3234 /* Decode a declarator in an ordinary declaration or data definition.
3235 This is called as soon as the type information and variable name
3236 have been parsed, before parsing the initializer if any.
3237 Here we create the ..._DECL node, fill in its type,
3238 and put it on the list of decls for the current context.
3239 The ..._DECL node is returned as the value.
3241 Exception: for arrays where the length is not specified,
3242 the type is left null, to be filled in by `finish_decl'.
3244 Function definitions do not come here; they go to start_function
3245 instead. However, external and forward declarations of functions
3246 do go through here. Structure field declarations are done by
3247 grokfield and not through here. */
3250 start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
3251 tree declarator, declspecs;
3253 tree attributes, prefix_attributes;
3255 register tree decl = grokdeclarator (declarator, declspecs,
3256 NORMAL, initialized);
3259 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
3260 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "main"))
3261 warning_with_decl (decl, "`%s' is usually a function");
3264 /* Is it valid for this decl to have an initializer at all?
3265 If not, set INITIALIZED to zero, which will indirectly
3266 tell `finish_decl' to ignore the initializer once it is parsed. */
3267 switch (TREE_CODE (decl))
3270 /* typedef foo = bar means give foo the same type as bar.
3271 We haven't parsed bar yet, so `finish_decl' will fix that up.
3272 Any other case of an initialization in a TYPE_DECL is an error. */
3273 if (pedantic || list_length (declspecs) > 1)
3275 error ("typedef `%s' is initialized",
3276 IDENTIFIER_POINTER (DECL_NAME (decl)));
3282 error ("function `%s' is initialized like a variable",
3283 IDENTIFIER_POINTER (DECL_NAME (decl)));
3288 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3289 error ("parameter `%s' is initialized",
3290 IDENTIFIER_POINTER (DECL_NAME (decl)));
3295 /* Don't allow initializations for incomplete types
3296 except for arrays which might be completed by the initialization. */
3297 if (TYPE_SIZE (TREE_TYPE (decl)) != 0)
3299 /* A complete type is ok if size is fixed. */
3301 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3302 || C_DECL_VARIABLE_SIZE (decl))
3304 error ("variable-sized object may not be initialized");
3308 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3310 error ("variable `%s' has initializer but incomplete type",
3311 IDENTIFIER_POINTER (DECL_NAME (decl)));
3314 else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0)
3316 error ("elements of array `%s' have incomplete type",
3317 IDENTIFIER_POINTER (DECL_NAME (decl)));
3324 #if 0 /* Seems redundant with grokdeclarator. */
3325 if (current_binding_level != global_binding_level
3326 && DECL_EXTERNAL (decl)
3327 && TREE_CODE (decl) != FUNCTION_DECL)
3328 warning ("declaration of `%s' has `extern' and is initialized",
3329 IDENTIFIER_POINTER (DECL_NAME (decl)));
3331 DECL_EXTERNAL (decl) = 0;
3332 if (current_binding_level == global_binding_level)
3333 TREE_STATIC (decl) = 1;
3335 /* Tell `pushdecl' this is an initialized decl
3336 even though we don't yet have the initializer expression.
3337 Also tell `finish_decl' it may store the real initializer. */
3338 DECL_INITIAL (decl) = error_mark_node;
3341 /* If this is a function declaration, write a record describing it to the
3342 prototypes file (if requested). */
3344 if (TREE_CODE (decl) == FUNCTION_DECL)
3345 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
3347 /* ANSI specifies that a tentative definition which is not merged with
3348 a non-tentative definition behaves exactly like a definition with an
3349 initializer equal to zero. (Section 3.7.2)
3350 -fno-common gives strict ANSI behavior. Usually you don't want it.
3351 This matters only for variables with external linkage. */
3352 if (! flag_no_common || ! TREE_PUBLIC (decl))
3353 DECL_COMMON (decl) = 1;
3355 #ifdef SET_DEFAULT_DECL_ATTRIBUTES
3356 SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes);
3359 /* Set attributes here so if duplicate decl, will have proper attributes. */
3360 decl_attributes (decl, attributes, prefix_attributes);
3362 /* Add this decl to the current binding level.
3363 TEM may equal DECL or it may be a previous decl of the same name. */
3364 tem = pushdecl (decl);
3366 /* For a local variable, define the RTL now. */
3367 if (current_binding_level != global_binding_level
3368 /* But not if this is a duplicate decl
3369 and we preserved the rtl from the previous one
3370 (which may or may not happen). */
3371 && DECL_RTL (tem) == 0)
3373 if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
3375 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
3376 && DECL_INITIAL (tem) != 0)
3383 /* Finish processing of a declaration;
3384 install its initial value.
3385 If the length of an array type is not known before,
3386 it must be determined now, from the initial value, or it is an error. */
3389 finish_decl (decl, init, asmspec_tree)
3393 register tree type = TREE_TYPE (decl);
3394 int was_incomplete = (DECL_SIZE (decl) == 0);
3397 /* If a name was specified, get the string. */
3399 asmspec = TREE_STRING_POINTER (asmspec_tree);
3401 /* If `start_decl' didn't like having an initialization, ignore it now. */
3403 if (init != 0 && DECL_INITIAL (decl) == 0)
3405 /* Don't crash if parm is initialized. */
3406 if (TREE_CODE (decl) == PARM_DECL)
3409 if (ITERATOR_P (decl))
3412 error_with_decl (decl, "iterator has no initial value");
3414 init = save_expr (init);
3419 if (TREE_CODE (decl) != TYPE_DECL)
3420 store_init_value (decl, init);
3423 /* typedef foo = bar; store the type of bar as the type of foo. */
3424 TREE_TYPE (decl) = TREE_TYPE (init);
3425 DECL_INITIAL (decl) = init = 0;
3429 /* Deduce size of array from initialization, if not already known */
3431 if (TREE_CODE (type) == ARRAY_TYPE
3432 && TYPE_DOMAIN (type) == 0
3433 && TREE_CODE (decl) != TYPE_DECL)
3436 = (TREE_STATIC (decl)
3437 /* Even if pedantic, an external linkage array
3438 may have incomplete type at first. */
3439 ? pedantic && !TREE_PUBLIC (decl)
3440 : !DECL_EXTERNAL (decl));
3442 = complete_array_type (type, DECL_INITIAL (decl), do_default);
3444 /* Get the completed type made by complete_array_type. */
3445 type = TREE_TYPE (decl);
3448 error_with_decl (decl, "initializer fails to determine size of `%s'");
3453 error_with_decl (decl, "array size missing in `%s'");
3454 /* If a `static' var's size isn't known,
3455 make it extern as well as static, so it does not get
3457 If it is not `static', then do not mark extern;
3458 finish_incomplete_decl will give it a default size
3459 and it will get allocated. */
3460 else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl))
3461 DECL_EXTERNAL (decl) = 1;
3464 /* TYPE_MAX_VALUE is always one less than the number of elements
3465 in the array, because we start counting at zero. Therefore,
3466 warn only if the value is less than zero. */
3467 if (pedantic && TYPE_DOMAIN (type) != 0
3468 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
3469 error_with_decl (decl, "zero or negative size array `%s'");
3471 layout_decl (decl, 0);
3474 if (TREE_CODE (decl) == VAR_DECL)
3476 if (DECL_SIZE (decl) == 0
3477 && TYPE_SIZE (TREE_TYPE (decl)) != 0)
3478 layout_decl (decl, 0);
3480 if (DECL_SIZE (decl) == 0
3481 && (TREE_STATIC (decl)
3483 /* A static variable with an incomplete type
3484 is an error if it is initialized.
3485 Also if it is not file scope.
3486 Otherwise, let it through, but if it is not `extern'
3487 then it may cause an error message later. */
3488 /* A duplicate_decls call could have changed an extern
3489 declaration into a file scope one. This can be detected
3490 by TREE_ASM_WRITTEN being set. */
3491 (DECL_INITIAL (decl) != 0
3492 || (DECL_CONTEXT (decl) != 0 && ! TREE_ASM_WRITTEN (decl)))
3494 /* An automatic variable with an incomplete type
3496 !DECL_EXTERNAL (decl)))
3498 error_with_decl (decl, "storage size of `%s' isn't known");
3499 TREE_TYPE (decl) = error_mark_node;
3502 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
3503 && DECL_SIZE (decl) != 0)
3505 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3506 constant_expression_warning (DECL_SIZE (decl));
3508 error_with_decl (decl, "storage size of `%s' isn't constant");
3511 if (TREE_USED (type))
3512 TREE_USED (decl) = 1;
3515 /* If this is a function and an assembler name is specified, it isn't
3516 builtin any more. Also reset DECL_RTL so we can give it its new
3518 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
3520 DECL_BUILT_IN_CLASS (decl) = NOT_BUILT_IN;
3521 DECL_RTL (decl) = 0;
3522 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
3525 /* Output the assembler code and/or RTL code for variables and functions,
3526 unless the type is an undefined structure or union.
3527 If not, it will get done when the type is completed. */
3529 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3531 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
3532 maybe_objc_check_decl (decl);
3533 rest_of_decl_compilation (decl, asmspec,
3534 (DECL_CONTEXT (decl) == 0
3535 || TREE_ASM_WRITTEN (decl)), 0);
3537 if (DECL_CONTEXT (decl) != 0)
3539 /* Recompute the RTL of a local array now
3540 if it used to be an incomplete type. */
3542 && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
3544 /* If we used it already as memory, it must stay in memory. */
3545 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
3546 /* If it's still incomplete now, no init will save it. */
3547 if (DECL_SIZE (decl) == 0)
3548 DECL_INITIAL (decl) = 0;
3551 /* Compute and store the initial value. */
3552 if (TREE_CODE (decl) != FUNCTION_DECL)
3553 expand_decl_init (decl);
3557 if (TREE_CODE (decl) == TYPE_DECL)
3559 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
3560 maybe_objc_check_decl (decl);
3561 rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == 0, 0);
3564 /* If requested, warn about definitions of large data objects. */
3566 if (warn_larger_than
3567 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
3568 && !DECL_EXTERNAL (decl))
3570 register tree decl_size = DECL_SIZE (decl);
3572 if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
3574 unsigned units = TREE_INT_CST_LOW(decl_size) / BITS_PER_UNIT;
3576 if (units > larger_than_size)
3577 warning_with_decl (decl, "size of `%s' is %u bytes", units);
3581 /* At the end of a declaration, throw away any variable type sizes
3582 of types defined inside that declaration. There is no use
3583 computing them in the following function definition. */
3584 if (current_binding_level == global_binding_level)
3585 get_pending_sizes ();
3588 /* If DECL has a cleanup, build and return that cleanup here.
3589 This is a callback called by expand_expr. */
3592 maybe_build_cleanup (decl)
3593 tree decl ATTRIBUTE_UNUSED;
3595 /* There are no cleanups in C. */
3599 /* Given a parsed parameter declaration,
3600 decode it into a PARM_DECL and push that on the current binding level.
3601 Also, for the sake of forward parm decls,
3602 record the given order of parms in `parm_order'. */
3605 push_parm_decl (parm)
3609 int old_immediate_size_expand = immediate_size_expand;
3610 /* Don't try computing parm sizes now -- wait till fn is called. */
3611 immediate_size_expand = 0;
3613 decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
3614 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
3615 decl_attributes (decl, TREE_VALUE (TREE_VALUE (parm)),
3616 TREE_PURPOSE (TREE_VALUE (parm)));
3619 if (DECL_NAME (decl))
3622 olddecl = lookup_name (DECL_NAME (decl));
3623 if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
3624 pedwarn_with_decl (decl, "ANSI C forbids parameter `%s' shadowing typedef");
3628 decl = pushdecl (decl);
3630 immediate_size_expand = old_immediate_size_expand;
3632 current_binding_level->parm_order
3633 = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
3635 /* Add this decl to the current binding level. */
3636 finish_decl (decl, NULL_TREE, NULL_TREE);
3639 /* Clear the given order of parms in `parm_order'.
3640 Used at start of parm list,
3641 and also at semicolon terminating forward decls. */
3646 current_binding_level->parm_order = NULL_TREE;
3649 /* Make TYPE a complete type based on INITIAL_VALUE.
3650 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3651 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3654 complete_array_type (type, initial_value, do_default)
3659 register tree maxindex = NULL_TREE;
3664 /* Note MAXINDEX is really the maximum index,
3665 one less than the size. */
3666 if (TREE_CODE (initial_value) == STRING_CST)
3669 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
3670 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
3673 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
3675 tree elts = CONSTRUCTOR_ELTS (initial_value);
3676 maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
3677 for (; elts; elts = TREE_CHAIN (elts))
3679 if (TREE_PURPOSE (elts))
3680 maxindex = TREE_PURPOSE (elts);
3682 maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
3684 maxindex = copy_node (maxindex);
3688 /* Make an error message unless that happened already. */
3689 if (initial_value != error_mark_node)
3692 /* Prevent further error messages. */
3693 maxindex = build_int_2 (0, 0);
3700 maxindex = build_int_2 (0, 0);
3706 TYPE_DOMAIN (type) = build_index_type (maxindex);
3707 if (!TREE_TYPE (maxindex))
3708 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
3711 /* Lay out the type now that we can get the real answer. */
3718 /* Given declspecs and a declarator,
3719 determine the name and type of the object declared
3720 and construct a ..._DECL node for it.
3721 (In one case we can return a ..._TYPE node instead.
3722 For invalid input we sometimes return 0.)
3724 DECLSPECS is a chain of tree_list nodes whose value fields
3725 are the storage classes and type specifiers.
3727 DECL_CONTEXT says which syntactic context this declaration is in:
3728 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3729 FUNCDEF for a function definition. Like NORMAL but a few different
3730 error messages in each case. Return value may be zero meaning
3731 this definition is too screwy to try to parse.
3732 PARM for a parameter declaration (either within a function prototype
3733 or before a function body). Make a PARM_DECL, or return void_type_node.
3734 TYPENAME if for a typename (in a cast or sizeof).
3735 Don't make a DECL node; just return the ..._TYPE node.
3736 FIELD for a struct or union field; make a FIELD_DECL.
3737 BITFIELD for a field with specified width.
3738 INITIALIZED is 1 if the decl has an initializer.
3740 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3741 It may also be so in the PARM case, for a prototype where the
3742 argument type is specified but not the name.
3744 This function is where the complicated C meanings of `static'
3745 and `extern' are interpreted. */
3748 grokdeclarator (declarator, declspecs, decl_context, initialized)
3751 enum decl_context decl_context;
3756 tree type = NULL_TREE;
3761 int type_quals = TYPE_UNQUALIFIED;
3763 int explicit_int = 0;
3764 int explicit_char = 0;
3765 int defaulted_int = 0;
3766 tree typedef_decl = 0;
3768 tree typedef_type = 0;
3769 int funcdef_flag = 0;
3770 enum tree_code innermost_code = ERROR_MARK;
3772 int size_varies = 0;
3773 tree decl_machine_attr = NULL_TREE;
3775 if (decl_context == BITFIELD)
3776 bitfield = 1, decl_context = FIELD;
3778 if (decl_context == FUNCDEF)
3779 funcdef_flag = 1, decl_context = NORMAL;
3781 /* Look inside a declarator for the name being declared
3782 and get it as a string, for an error message. */
3784 register tree decl = declarator;
3788 switch (TREE_CODE (decl))
3793 innermost_code = TREE_CODE (decl);
3794 decl = TREE_OPERAND (decl, 0);
3797 case IDENTIFIER_NODE:
3798 name = IDENTIFIER_POINTER (decl);
3809 /* A function definition's declarator must have the form of
3810 a function declarator. */
3812 if (funcdef_flag && innermost_code != CALL_EXPR)
3815 /* Anything declared one level down from the top level
3816 must be one of the parameters of a function
3817 (because the body is at least two levels down). */
3819 /* If this looks like a function definition, make it one,
3820 even if it occurs where parms are expected.
3821 Then store_parm_decls will reject it and not use it as a parm. */
3822 if (decl_context == NORMAL && !funcdef_flag
3823 && current_binding_level->parm_flag)
3824 decl_context = PARM;
3826 /* Look through the decl specs and record which ones appear.
3827 Some typespecs are defined as built-in typenames.
3828 Others, the ones that are modifiers of other types,
3829 are represented by bits in SPECBITS: set the bits for
3830 the modifiers that appear. Storage class keywords are also in SPECBITS.
3832 If there is a typedef name or a type, store the type in TYPE.
3833 This includes builtin typedefs such as `int'.
3835 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3836 and did not come from a user typedef.
3838 Set LONGLONG if `long' is mentioned twice. */
3840 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
3843 register tree id = TREE_VALUE (spec);
3845 if (id == ridpointers[(int) RID_INT])
3847 if (id == ridpointers[(int) RID_CHAR])
3850 if (TREE_CODE (id) == IDENTIFIER_NODE)
3851 for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
3853 if (ridpointers[i] == id)
3855 if (i == (int) RID_LONG && specbits & (1<<i))
3858 error ("`long long long' is too long for GCC");
3861 if (pedantic && ! in_system_header && warn_long_long)
3862 pedwarn ("ANSI C does not support `long long'");
3866 else if (specbits & (1 << i))
3867 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
3873 error ("two or more data types in declaration of `%s'", name);
3874 /* Actual typedefs come to us as TYPE_DECL nodes. */
3875 else if (TREE_CODE (id) == TYPE_DECL)
3877 type = TREE_TYPE (id);
3878 decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
3881 /* Built-in types come as identifiers. */
3882 else if (TREE_CODE (id) == IDENTIFIER_NODE)
3884 register tree t = lookup_name (id);
3885 if (TREE_TYPE (t) == error_mark_node)
3887 else if (!t || TREE_CODE (t) != TYPE_DECL)
3888 error ("`%s' fails to be a typedef or built in type",
3889 IDENTIFIER_POINTER (id));
3892 type = TREE_TYPE (t);
3896 else if (TREE_CODE (id) != ERROR_MARK)
3902 typedef_type = type;
3904 size_varies = C_TYPE_VARIABLE_SIZE (type);
3906 /* No type at all: default to `int', and set DEFAULTED_INT
3907 because it was not a user-defined typedef. */
3911 if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3912 | (1 << (int) RID_SIGNED)
3913 | (1 << (int) RID_UNSIGNED))))
3914 /* Don't warn about typedef foo = bar. */
3915 && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
3916 && ! in_system_header)
3918 /* Issue a warning if this is an ISO C 9x program or if -Wreturn-type
3919 and this is a function, or if -Wimplicit; prefer the former
3920 warning since it is more explicit. */
3921 if ((warn_implicit_int || warn_return_type) && funcdef_flag)
3922 warn_about_return_type = 1;
3923 else if (warn_implicit_int || flag_isoc9x)
3924 warning ("type defaults to `int' in declaration of `%s'", name);
3928 type = integer_type_node;
3931 /* Now process the modifiers that were specified
3932 and check for invalid combinations. */
3934 /* Long double is a special combination. */
3936 if ((specbits & 1 << (int) RID_LONG) && ! longlong
3937 && TYPE_MAIN_VARIANT (type) == double_type_node)
3939 specbits &= ~ (1 << (int) RID_LONG);
3940 type = long_double_type_node;
3943 /* Check all other uses of type modifiers. */
3945 if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3946 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
3950 if ((specbits & 1 << (int) RID_LONG)
3951 && (specbits & 1 << (int) RID_SHORT))
3952 error ("both long and short specified for `%s'", name);
3953 else if (((specbits & 1 << (int) RID_LONG)
3954 || (specbits & 1 << (int) RID_SHORT))
3956 error ("long or short specified with char for `%s'", name);
3957 else if (((specbits & 1 << (int) RID_LONG)
3958 || (specbits & 1 << (int) RID_SHORT))
3959 && TREE_CODE (type) == REAL_TYPE)
3961 static int already = 0;
3963 error ("long or short specified with floating type for `%s'", name);
3964 if (! already && ! pedantic)
3966 error ("the only valid combination is `long double'");
3970 else if ((specbits & 1 << (int) RID_SIGNED)
3971 && (specbits & 1 << (int) RID_UNSIGNED))
3972 error ("both signed and unsigned specified for `%s'", name);
3973 else if (TREE_CODE (type) != INTEGER_TYPE)
3974 error ("long, short, signed or unsigned invalid for `%s'", name);
3978 if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
3980 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
3982 if (flag_pedantic_errors)
3987 /* Discard the type modifiers if they are invalid. */
3990 specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3991 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
3996 if ((specbits & (1 << (int) RID_COMPLEX))
3997 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
3999 error ("complex invalid for `%s'", name);
4000 specbits &= ~ (1 << (int) RID_COMPLEX);
4003 /* Decide whether an integer type is signed or not.
4004 Optionally treat bitfields as signed by default. */
4005 if (specbits & 1 << (int) RID_UNSIGNED
4006 /* Traditionally, all bitfields are unsigned. */
4007 || (bitfield && flag_traditional
4008 && (! explicit_flag_signed_bitfields || !flag_signed_bitfields))
4009 || (bitfield && ! flag_signed_bitfields
4010 && (explicit_int || defaulted_int || explicit_char
4011 /* A typedef for plain `int' without `signed'
4012 can be controlled just like plain `int'. */
4013 || ! (typedef_decl != 0
4014 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4015 && TREE_CODE (type) != ENUMERAL_TYPE
4016 && !(specbits & 1 << (int) RID_SIGNED)))
4019 type = long_long_unsigned_type_node;
4020 else if (specbits & 1 << (int) RID_LONG)
4021 type = long_unsigned_type_node;
4022 else if (specbits & 1 << (int) RID_SHORT)
4023 type = short_unsigned_type_node;
4024 else if (type == char_type_node)
4025 type = unsigned_char_type_node;
4026 else if (typedef_decl)
4027 type = unsigned_type (type);
4029 type = unsigned_type_node;
4031 else if ((specbits & 1 << (int) RID_SIGNED)
4032 && type == char_type_node)
4033 type = signed_char_type_node;
4035 type = long_long_integer_type_node;
4036 else if (specbits & 1 << (int) RID_LONG)
4037 type = long_integer_type_node;
4038 else if (specbits & 1 << (int) RID_SHORT)
4039 type = short_integer_type_node;
4041 if (specbits & 1 << (int) RID_COMPLEX)
4043 /* If we just have "complex", it is equivalent to
4044 "complex double", but if any modifiers at all are specified it is
4045 the complex form of TYPE. E.g, "complex short" is
4046 "complex short int". */
4048 if (defaulted_int && ! longlong
4049 && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4050 | (1 << (int) RID_SIGNED)
4051 | (1 << (int) RID_UNSIGNED))))
4052 type = complex_double_type_node;
4053 else if (type == integer_type_node)
4054 type = complex_integer_type_node;
4055 else if (type == float_type_node)
4056 type = complex_float_type_node;
4057 else if (type == double_type_node)
4058 type = complex_double_type_node;
4059 else if (type == long_double_type_node)
4060 type = complex_long_double_type_node;
4062 type = build_complex_type (type);
4065 /* Figure out the type qualifiers for the declaration. There are
4066 two ways a declaration can become qualified. One is something
4067 like `const int i' where the `const' is explicit. Another is
4068 something like `typedef const int CI; CI i' where the type of the
4069 declaration contains the `const'. */
4070 constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
4071 restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
4072 volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
4073 inlinep = !! (specbits & (1 << (int) RID_INLINE));
4075 pedwarn ("duplicate `const'");
4077 pedwarn ("duplicate `restrict'");
4079 pedwarn ("duplicate `volatile'");
4080 if (! flag_gen_aux_info && (TYPE_QUALS (type)))
4081 type = TYPE_MAIN_VARIANT (type);
4082 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4083 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4084 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4086 /* Warn if two storage classes are given. Default to `auto'. */
4091 if (specbits & 1 << (int) RID_AUTO) nclasses++;
4092 if (specbits & 1 << (int) RID_STATIC) nclasses++;
4093 if (specbits & 1 << (int) RID_EXTERN) nclasses++;
4094 if (specbits & 1 << (int) RID_REGISTER) nclasses++;
4095 if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
4096 if (specbits & 1 << (int) RID_ITERATOR) nclasses++;
4098 /* Warn about storage classes that are invalid for certain
4099 kinds of declarations (parameters, typenames, etc.). */
4102 error ("multiple storage classes in declaration of `%s'", name);
4103 else if (funcdef_flag
4105 & ((1 << (int) RID_REGISTER)
4106 | (1 << (int) RID_AUTO)
4107 | (1 << (int) RID_TYPEDEF))))
4109 if (specbits & 1 << (int) RID_AUTO
4110 && (pedantic || current_binding_level == global_binding_level))
4111 pedwarn ("function definition declared `auto'");
4112 if (specbits & 1 << (int) RID_REGISTER)
4113 error ("function definition declared `register'");
4114 if (specbits & 1 << (int) RID_TYPEDEF)
4115 error ("function definition declared `typedef'");
4116 specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4117 | (1 << (int) RID_AUTO));
4119 else if (decl_context != NORMAL && nclasses > 0)
4121 if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
4125 switch (decl_context)
4128 error ("storage class specified for structure field `%s'", name);
4131 error ("storage class specified for parameter `%s'", name);
4134 error ("storage class specified for typename");
4137 specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4138 | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
4139 | (1 << (int) RID_EXTERN));
4142 else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
4144 /* `extern' with initialization is invalid if not at top level. */
4145 if (current_binding_level == global_binding_level)
4146 warning ("`%s' initialized and declared `extern'", name);
4148 error ("`%s' has both `extern' and initializer", name);
4150 else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
4151 && current_binding_level != global_binding_level)
4152 error ("nested function `%s' declared `extern'", name);
4153 else if (current_binding_level == global_binding_level
4154 && specbits & (1 << (int) RID_AUTO))
4155 error ("top-level declaration of `%s' specifies `auto'", name);
4156 else if ((specbits & 1 << (int) RID_ITERATOR)
4157 && TREE_CODE (declarator) != IDENTIFIER_NODE)
4159 error ("iterator `%s' has derived type", name);
4160 type = error_mark_node;
4162 else if ((specbits & 1 << (int) RID_ITERATOR)
4163 && TREE_CODE (type) != INTEGER_TYPE)
4165 error ("iterator `%s' has noninteger type", name);
4166 type = error_mark_node;
4170 /* Now figure out the structure of the declarator proper.
4171 Descend through it, creating more complex types, until we reach
4172 the declared identifier (or NULL_TREE, in an absolute declarator). */
4174 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
4176 if (type == error_mark_node)
4178 declarator = TREE_OPERAND (declarator, 0);
4182 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
4183 an INDIRECT_REF (for *...),
4184 a CALL_EXPR (for ...(...)),
4185 an identifier (for the name being declared)
4186 or a null pointer (for the place in an absolute declarator
4187 where the name was omitted).
4188 For the last two cases, we have just exited the loop.
4190 At this point, TYPE is the type of elements of an array,
4191 or for a function to return, or for a pointer to point to.
4192 After this sequence of ifs, TYPE is the type of the
4193 array or function or pointer, and DECLARATOR has had its
4194 outermost layer removed. */
4196 if (TREE_CODE (declarator) == ARRAY_REF)
4198 register tree itype = NULL_TREE;
4199 register tree size = TREE_OPERAND (declarator, 1);
4200 /* The index is a signed object `sizetype' bits wide. */
4201 tree index_type = signed_type (sizetype);
4203 declarator = TREE_OPERAND (declarator, 0);
4205 /* Check for some types that there cannot be arrays of. */
4207 if (TYPE_MAIN_VARIANT (type) == void_type_node)
4209 error ("declaration of `%s' as array of voids", name);
4210 type = error_mark_node;
4213 if (TREE_CODE (type) == FUNCTION_TYPE)
4215 error ("declaration of `%s' as array of functions", name);
4216 type = error_mark_node;
4219 if (size == error_mark_node)
4220 type = error_mark_node;
4222 if (type == error_mark_node)
4225 /* If size was specified, set ITYPE to a range-type for that size.
4226 Otherwise, ITYPE remains null. finish_decl may figure it out
4227 from an initial value. */
4231 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4232 STRIP_TYPE_NOPS (size);
4234 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
4235 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
4237 error ("size of array `%s' has non-integer type", name);
4238 size = integer_one_node;
4241 if (pedantic && integer_zerop (size))
4242 pedwarn ("ANSI C forbids zero-size array `%s'", name);
4244 if (TREE_CODE (size) == INTEGER_CST)
4246 constant_expression_warning (size);
4247 if (tree_int_cst_sgn (size) < 0)
4249 error ("size of array `%s' is negative", name);
4250 size = integer_one_node;
4255 /* Make sure the array size remains visibly nonconstant
4256 even if it is (eg) a const variable with known value. */
4261 if (TREE_CONSTANT (size))
4262 pedwarn ("ANSI C forbids array `%s' whose size can't be evaluated", name);
4264 pedwarn ("ANSI C forbids variable-size array `%s'", name);
4268 /* Convert size to index_type, so that if it is a variable
4269 the computations will be done in the proper mode. */
4270 itype = fold (build (MINUS_EXPR, index_type,
4271 convert (index_type, size),
4272 convert (index_type, size_one_node)));
4274 /* If that overflowed, the array is too big.
4275 ??? While a size of INT_MAX+1 technically shouldn't cause
4276 an overflow (because we subtract 1), the overflow is recorded
4277 during the conversion to index_type, before the subtraction.
4278 Handling this case seems like an unnecessary complication. */
4279 if (TREE_OVERFLOW (itype))
4281 error ("size of array `%s' is too large", name);
4282 type = error_mark_node;
4287 itype = variable_size (itype);
4288 itype = build_index_type (itype);
4291 #if 0 /* This had bad results for pointers to arrays, as in
4292 union incomplete (*foo)[4]; */
4293 /* Complain about arrays of incomplete types, except in typedefs. */
4295 if (TYPE_SIZE (type) == 0
4296 /* Avoid multiple warnings for nested array types. */
4297 && TREE_CODE (type) != ARRAY_TYPE
4298 && !(specbits & (1 << (int) RID_TYPEDEF))
4299 && !C_TYPE_BEING_DEFINED (type))
4300 warning ("array type has incomplete element type");
4303 #if 0 /* We shouldn't have a function type here at all!
4304 Functions aren't allowed as array elements. */
4305 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4306 && (constp || volatilep))
4307 pedwarn ("ANSI C forbids const or volatile function types");
4310 /* Build the array type itself, then merge any constancy or
4311 volatility into the target type. We must do it in this order
4312 to ensure that the TYPE_MAIN_VARIANT field of the array type
4313 is set correctly. */
4315 type = build_array_type (type, itype);
4317 type = c_build_qualified_type (type, type_quals);
4319 #if 0 /* don't clear these; leave them set so that the array type
4320 or the variable is itself const or volatile. */
4321 type_quals = TYPE_UNQUALIFIED;
4325 C_TYPE_VARIABLE_SIZE (type) = 1;
4327 else if (TREE_CODE (declarator) == CALL_EXPR)
4331 /* Declaring a function type.
4332 Make sure we have a valid type for the function to return. */
4333 if (type == error_mark_node)
4338 /* Warn about some types functions can't return. */
4340 if (TREE_CODE (type) == FUNCTION_TYPE)
4342 error ("`%s' declared as function returning a function", name);
4343 type = integer_type_node;
4345 if (TREE_CODE (type) == ARRAY_TYPE)
4347 error ("`%s' declared as function returning an array", name);
4348 type = integer_type_node;
4351 #ifndef TRADITIONAL_RETURN_FLOAT
4352 /* Traditionally, declaring return type float means double. */
4354 if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node)
4355 type = double_type_node;
4356 #endif /* TRADITIONAL_RETURN_FLOAT */
4358 /* Construct the function type and go to the next
4359 inner layer of declarator. */
4361 arg_types = grokparms (TREE_OPERAND (declarator, 1),
4363 /* Say it's a definition
4364 only for the CALL_EXPR
4365 closest to the identifier. */
4366 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
4367 /* Type qualifiers before the return type of the function
4368 qualify the return type, not the function type. */
4370 type = c_build_qualified_type (type, type_quals);
4371 type_quals = TYPE_UNQUALIFIED;
4373 type = build_function_type (type, arg_types);
4374 declarator = TREE_OPERAND (declarator, 0);
4376 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4377 the formal parameter list of this FUNCTION_TYPE to point to
4378 the FUNCTION_TYPE node itself. */
4383 for (link = last_function_parm_tags;
4385 link = TREE_CHAIN (link))
4386 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4389 else if (TREE_CODE (declarator) == INDIRECT_REF)
4391 /* Merge any constancy or volatility into the target type
4394 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4396 pedwarn ("ANSI C forbids qualified function types");
4398 type = c_build_qualified_type (type, type_quals);
4399 type_quals = TYPE_UNQUALIFIED;
4402 type = build_pointer_type (type);
4404 /* Process a list of type modifier keywords
4405 (such as const or volatile) that were given inside the `*'. */
4407 if (TREE_TYPE (declarator))
4409 register tree typemodlist;
4415 for (typemodlist = TREE_TYPE (declarator); typemodlist;
4416 typemodlist = TREE_CHAIN (typemodlist))
4418 tree qualifier = TREE_VALUE (typemodlist);
4420 if (qualifier == ridpointers[(int) RID_CONST])
4422 else if (qualifier == ridpointers[(int) RID_VOLATILE])
4424 else if (qualifier == ridpointers[(int) RID_RESTRICT])
4429 error ("invalid type modifier within pointer declarator");
4433 pedwarn ("duplicate `const'");
4435 pedwarn ("duplicate `volatile'");
4437 pedwarn ("duplicate `restrict'");
4439 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4440 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4441 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4444 declarator = TREE_OPERAND (declarator, 0);
4451 /* Now TYPE has the actual type. */
4453 /* Did array size calculations overflow? */
4455 if (TREE_CODE (type) == ARRAY_TYPE
4457 && TREE_OVERFLOW (TYPE_SIZE (type)))
4458 error ("size of array `%s' is too large", name);
4460 /* If this is declaring a typedef name, return a TYPE_DECL. */
4462 if (specbits & (1 << (int) RID_TYPEDEF))
4465 /* Note that the grammar rejects storage classes
4466 in typenames, fields or parameters */
4467 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4469 pedwarn ("ANSI C forbids qualified function types");
4471 type = c_build_qualified_type (type, type_quals);
4472 decl = build_decl (TYPE_DECL, declarator, type);
4473 if ((specbits & (1 << (int) RID_SIGNED))
4474 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4475 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4479 /* Detect the case of an array type of unspecified size
4480 which came, as such, direct from a typedef name.
4481 We must copy the type, so that each identifier gets
4482 a distinct type, so that each identifier's size can be
4483 controlled separately by its own initializer. */
4485 if (type != 0 && typedef_type != 0
4486 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)
4487 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0)
4489 type = build_array_type (TREE_TYPE (type), 0);
4491 C_TYPE_VARIABLE_SIZE (type) = 1;
4494 /* If this is a type name (such as, in a cast or sizeof),
4495 compute the type and return it now. */
4497 if (decl_context == TYPENAME)
4499 /* Note that the grammar rejects storage classes
4500 in typenames, fields or parameters */
4501 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4503 pedwarn ("ANSI C forbids const or volatile function types");
4505 type = c_build_qualified_type (type, type_quals);
4509 /* Aside from typedefs and type names (handle above),
4510 `void' at top level (not within pointer)
4511 is allowed only in public variables.
4512 We don't complain about parms either, but that is because
4513 a better error message can be made later. */
4515 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM
4516 && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4517 && ((specbits & (1 << (int) RID_EXTERN))
4518 || (current_binding_level == global_binding_level
4520 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
4522 error ("variable or field `%s' declared void", name);
4523 type = integer_type_node;
4526 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4527 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4532 if (decl_context == PARM)
4534 tree type_as_written = type;
4537 /* A parameter declared as an array of T is really a pointer to T.
4538 One declared as a function is really a pointer to a function. */
4540 if (TREE_CODE (type) == ARRAY_TYPE)
4542 /* Transfer const-ness of array into that of type pointed to. */
4543 type = TREE_TYPE (type);
4545 type = c_build_qualified_type (type, type_quals);
4546 type = build_pointer_type (type);
4547 type_quals = TYPE_UNQUALIFIED;
4550 else if (TREE_CODE (type) == FUNCTION_TYPE)
4552 if (pedantic && type_quals)
4553 pedwarn ("ANSI C forbids qualified function types");
4555 type = c_build_qualified_type (type, type_quals);
4556 type = build_pointer_type (type);
4557 type_quals = TYPE_UNQUALIFIED;
4560 decl = build_decl (PARM_DECL, declarator, type);
4562 C_DECL_VARIABLE_SIZE (decl) = 1;
4564 /* Compute the type actually passed in the parmlist,
4565 for the case where there is no prototype.
4566 (For example, shorts and chars are passed as ints.)
4567 When there is a prototype, this is overridden later. */
4569 if (type == error_mark_node)
4570 promoted_type = type;
4573 promoted_type = simple_type_promotes_to (type);
4574 if (! promoted_type)
4575 promoted_type = type;
4578 DECL_ARG_TYPE (decl) = promoted_type;
4579 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
4581 else if (decl_context == FIELD)
4583 /* Structure field. It may not be a function. */
4585 if (TREE_CODE (type) == FUNCTION_TYPE)
4587 error ("field `%s' declared as a function", name);
4588 type = build_pointer_type (type);
4590 else if (TREE_CODE (type) != ERROR_MARK && TYPE_SIZE (type) == 0)
4592 error ("field `%s' has incomplete type", name);
4593 type = error_mark_node;
4595 /* Move type qualifiers down to element of an array. */
4596 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4598 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4600 TYPE_DOMAIN (type));
4601 #if 0 /* Leave the field const or volatile as well. */
4602 type_quals = TYPE_UNQUALIFIED;
4605 decl = build_decl (FIELD_DECL, declarator, type);
4607 C_DECL_VARIABLE_SIZE (decl) = 1;
4609 else if (TREE_CODE (type) == FUNCTION_TYPE)
4611 /* Every function declaration is "external"
4612 except for those which are inside a function body
4613 in which `auto' is used.
4614 That is a case not specified by ANSI C,
4615 and we use it for forward declarations for nested functions. */
4616 int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
4617 || current_binding_level == global_binding_level);
4619 if (specbits & (1 << (int) RID_AUTO)
4620 && (pedantic || current_binding_level == global_binding_level))
4621 pedwarn ("invalid storage class for function `%s'", name);
4622 if (specbits & (1 << (int) RID_REGISTER))
4623 error ("invalid storage class for function `%s'", name);
4624 /* Function declaration not at top level.
4625 Storage classes other than `extern' are not allowed
4626 and `extern' makes no difference. */
4627 if (current_binding_level != global_binding_level
4628 && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
4630 pedwarn ("invalid storage class for function `%s'", name);
4632 decl = build_decl (FUNCTION_DECL, declarator, type);
4633 decl = build_decl_attribute_variant (decl, decl_machine_attr);
4635 if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
4636 pedwarn ("ANSI C forbids qualified function types");
4639 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl))) == void_type_node
4640 && TYPE_QUALS (TREE_TYPE (TREE_TYPE (decl)))
4641 && ! DECL_IN_SYSTEM_HEADER (decl))
4642 pedwarn ("ANSI C forbids qualified void function return type");
4644 /* GNU C interprets a `volatile void' return type to indicate
4645 that the function does not return. */
4646 if ((type_quals & TYPE_QUAL_VOLATILE)
4647 && TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
4648 warning ("`noreturn' function returns non-void value");
4651 DECL_EXTERNAL (decl) = 1;
4652 /* Record absence of global scope for `static' or `auto'. */
4654 = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
4656 /* Record presence of `inline', if it is reasonable. */
4659 if (! strcmp (IDENTIFIER_POINTER (declarator), "main"))
4660 warning ("cannot inline function `main'");
4662 /* Assume that otherwise the function can be inlined. */
4663 DECL_INLINE (decl) = 1;
4665 if (specbits & (1 << (int) RID_EXTERN))
4666 current_extern_inline = 1;
4671 /* It's a variable. */
4672 /* An uninitialized decl with `extern' is a reference. */
4673 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
4675 /* Move type qualifiers down to element of an array. */
4676 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4678 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4680 TYPE_DOMAIN (type));
4681 #if 0 /* Leave the variable const or volatile as well. */
4682 type_quals = TYPE_UNQUALIFIED;
4686 decl = build_decl (VAR_DECL, declarator, type);
4688 C_DECL_VARIABLE_SIZE (decl) = 1;
4691 pedwarn_with_decl (decl, "variable `%s' declared `inline'");
4693 DECL_EXTERNAL (decl) = extern_ref;
4694 /* At top level, the presence of a `static' or `register' storage
4695 class specifier, or the absence of all storage class specifiers
4696 makes this declaration a definition (perhaps tentative). Also,
4697 the absence of both `static' and `register' makes it public. */
4698 if (current_binding_level == global_binding_level)
4702 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)));
4703 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
4705 /* Not at top level, only `static' makes a static definition. */
4708 TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
4709 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
4712 if (specbits & 1 << (int) RID_ITERATOR)
4713 ITERATOR_P (decl) = 1;
4716 /* Record `register' declaration for warnings on &
4717 and in case doing stupid register allocation. */
4719 if (specbits & (1 << (int) RID_REGISTER))
4720 DECL_REGISTER (decl) = 1;
4722 /* Record constancy and volatility. */
4723 c_apply_type_quals_to_decl (type_quals, decl);
4725 /* If a type has volatile components, it should be stored in memory.
4726 Otherwise, the fact that those components are volatile
4727 will be ignored, and would even crash the compiler. */
4728 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
4729 mark_addressable (decl);
4735 /* Decode the parameter-list info for a function type or function definition.
4736 The argument is the value returned by `get_parm_info' (or made in parse.y
4737 if there is an identifier list instead of a parameter decl list).
4738 These two functions are separate because when a function returns
4739 or receives functions then each is called multiple times but the order
4740 of calls is different. The last call to `grokparms' is always the one
4741 that contains the formal parameter names of a function definition.
4743 Store in `last_function_parms' a chain of the decls of parms.
4744 Also store in `last_function_parm_tags' a chain of the struct, union,
4745 and enum tags declared among the parms.
4747 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4749 FUNCDEF_FLAG is nonzero for a function definition, 0 for
4750 a mere declaration. A nonempty identifier-list gets an error message
4751 when FUNCDEF_FLAG is zero. */
4754 grokparms (parms_info, funcdef_flag)
4758 tree first_parm = TREE_CHAIN (parms_info);
4760 last_function_parms = TREE_PURPOSE (parms_info);
4761 last_function_parm_tags = TREE_VALUE (parms_info);
4763 if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
4764 && !in_system_header)
4765 warning ("function declaration isn't a prototype");
4768 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
4771 pedwarn ("parameter names (without types) in function declaration");
4773 last_function_parms = first_parm;
4780 /* We no longer test FUNCDEF_FLAG.
4781 If the arg types are incomplete in a declaration,
4782 they must include undefined tags.
4783 These tags can never be defined in the scope of the declaration,
4784 so the types can never be completed,
4785 and no call can be compiled successfully. */
4787 /* In a fcn definition, arg types must be complete. */
4790 for (parm = last_function_parms, typelt = first_parm;
4792 parm = TREE_CHAIN (parm))
4793 /* Skip over any enumeration constants declared here. */
4794 if (TREE_CODE (parm) == PARM_DECL)
4796 /* Barf if the parameter itself has an incomplete type. */
4797 tree type = TREE_VALUE (typelt);
4798 if (TYPE_SIZE (type) == 0)
4800 if (funcdef_flag && DECL_NAME (parm) != 0)
4801 error ("parameter `%s' has incomplete type",
4802 IDENTIFIER_POINTER (DECL_NAME (parm)));
4804 warning ("parameter has incomplete type");
4807 TREE_VALUE (typelt) = error_mark_node;
4808 TREE_TYPE (parm) = error_mark_node;
4811 #if 0 /* This has been replaced by parm_tags_warning
4812 which uses a more accurate criterion for what to warn about. */
4815 /* Now warn if is a pointer to an incomplete type. */
4816 while (TREE_CODE (type) == POINTER_TYPE
4817 || TREE_CODE (type) == REFERENCE_TYPE)
4818 type = TREE_TYPE (type);
4819 type = TYPE_MAIN_VARIANT (type);
4820 if (TYPE_SIZE (type) == 0)
4822 if (DECL_NAME (parm) != 0)
4823 warning ("parameter `%s' points to incomplete type",
4824 IDENTIFIER_POINTER (DECL_NAME (parm)));
4826 warning ("parameter points to incomplete type");
4830 typelt = TREE_CHAIN (typelt);
4838 /* Return a tree_list node with info on a parameter list just parsed.
4839 The TREE_PURPOSE is a chain of decls of those parms.
4840 The TREE_VALUE is a list of structure, union and enum tags defined.
4841 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
4842 This tree_list node is later fed to `grokparms'.
4844 VOID_AT_END nonzero means append `void' to the end of the type-list.
4845 Zero means the parmlist ended with an ellipsis so don't append `void'. */
4848 get_parm_info (void_at_end)
4851 register tree decl, t;
4852 register tree types = 0;
4854 tree tags = gettags ();
4855 tree parms = getdecls ();
4857 tree order = current_binding_level->parm_order;
4859 /* Just `void' (and no ellipsis) is special. There are really no parms. */
4860 if (void_at_end && parms != 0
4861 && TREE_CHAIN (parms) == 0
4862 && TYPE_MAIN_VARIANT (TREE_TYPE (parms)) == void_type_node
4863 && DECL_NAME (parms) == 0)
4866 storedecls (NULL_TREE);
4867 return tree_cons (NULL_TREE, NULL_TREE,
4868 tree_cons (NULL_TREE, void_type_node, NULL_TREE));
4871 /* Extract enumerator values and other non-parms declared with the parms.
4872 Likewise any forward parm decls that didn't have real parm decls. */
4873 for (decl = parms; decl; )
4875 tree next = TREE_CHAIN (decl);
4877 if (TREE_CODE (decl) != PARM_DECL)
4879 TREE_CHAIN (decl) = new_parms;
4882 else if (TREE_ASM_WRITTEN (decl))
4884 error_with_decl (decl, "parameter `%s' has just a forward declaration");
4885 TREE_CHAIN (decl) = new_parms;
4891 /* Put the parm decls back in the order they were in in the parm list. */
4892 for (t = order; t; t = TREE_CHAIN (t))
4895 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
4897 TREE_CHAIN (TREE_VALUE (t)) = 0;
4900 new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
4903 /* Store the parmlist in the binding level since the old one
4904 is no longer a valid list. (We have changed the chain pointers.) */
4905 storedecls (new_parms);
4907 for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
4908 /* There may also be declarations for enumerators if an enumeration
4909 type is declared among the parms. Ignore them here. */
4910 if (TREE_CODE (decl) == PARM_DECL)
4912 /* Since there is a prototype,
4913 args are passed in their declared types. */
4914 tree type = TREE_TYPE (decl);
4915 DECL_ARG_TYPE (decl) = type;
4916 if (PROMOTE_PROTOTYPES
4917 && (TREE_CODE (type) == INTEGER_TYPE
4918 || TREE_CODE (type) == ENUMERAL_TYPE)
4919 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
4920 DECL_ARG_TYPE (decl) = integer_type_node;
4922 types = tree_cons (NULL_TREE, TREE_TYPE (decl), types);
4923 if (TYPE_MAIN_VARIANT (TREE_VALUE (types)) == void_type_node && ! erred
4924 && DECL_NAME (decl) == 0)
4926 error ("`void' in parameter list must be the entire list");
4932 return tree_cons (new_parms, tags,
4933 nreverse (tree_cons (NULL_TREE, void_type_node, types)));
4935 return tree_cons (new_parms, tags, nreverse (types));
4938 /* At end of parameter list, warn about any struct, union or enum tags
4939 defined within. Do so because these types cannot ever become complete. */
4942 parmlist_tags_warning ()
4947 for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
4949 enum tree_code code = TREE_CODE (TREE_VALUE (elt));
4950 /* An anonymous union parm type is meaningful as a GNU extension.
4951 So don't warn for that. */
4952 if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic)
4954 if (TREE_PURPOSE (elt) != 0)
4955 warning ("`%s %s' declared inside parameter list",
4956 (code == RECORD_TYPE ? "struct"
4957 : code == UNION_TYPE ? "union"
4959 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4961 warning ("anonymous %s declared inside parameter list",
4962 (code == RECORD_TYPE ? "struct"
4963 : code == UNION_TYPE ? "union"
4968 warning ("its scope is only this definition or declaration, which is probably not what you want.");
4974 /* Get the struct, enum or union (CODE says which) with tag NAME.
4975 Define the tag as a forward-reference if it is not defined. */
4978 xref_tag (code, name)
4979 enum tree_code code;
4982 /* If a cross reference is requested, look up the type
4983 already defined for this tag and return it. */
4985 register tree ref = lookup_tag (code, name, current_binding_level, 0);
4986 /* Even if this is the wrong type of tag, return what we found.
4987 There will be an error message anyway, from pending_xref_error.
4988 If we create an empty xref just for an invalid use of the type,
4989 the main result is to create lots of superfluous error messages. */
4993 /* If no such tag is yet defined, create a forward-reference node
4994 and record it as the "definition".
4995 When a real declaration of this type is found,
4996 the forward-reference will be altered into a real type. */
4998 ref = make_node (code);
4999 if (code == ENUMERAL_TYPE)
5001 /* (In ANSI, Enums can be referred to only if already defined.) */
5003 pedwarn ("ANSI C forbids forward references to `enum' types");
5004 /* Give the type a default layout like unsigned int
5005 to avoid crashing if it does not get defined. */
5006 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
5007 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5008 TREE_UNSIGNED (ref) = 1;
5009 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5010 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5011 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5014 pushtag (name, ref);
5019 /* Make sure that the tag NAME is defined *in the current binding level*
5020 at least as a forward reference.
5021 CODE says which kind of tag NAME ought to be. */
5024 start_struct (code, name)
5025 enum tree_code code;
5028 /* If there is already a tag defined at this binding level
5029 (as a forward reference), just return it. */
5031 register tree ref = 0;
5034 ref = lookup_tag (code, name, current_binding_level, 1);
5035 if (ref && TREE_CODE (ref) == code)
5037 C_TYPE_BEING_DEFINED (ref) = 1;
5038 TYPE_PACKED (ref) = flag_pack_struct;
5039 if (TYPE_FIELDS (ref))
5040 error ("redefinition of `%s %s'",
5041 code == UNION_TYPE ? "union" : "struct",
5042 IDENTIFIER_POINTER (name));
5047 /* Otherwise create a forward-reference just so the tag is in scope. */
5049 ref = make_node (code);
5050 pushtag (name, ref);
5051 C_TYPE_BEING_DEFINED (ref) = 1;
5052 TYPE_PACKED (ref) = flag_pack_struct;
5056 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
5057 of a structure component, returning a FIELD_DECL node.
5058 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
5060 This is done during the parsing of the struct declaration.
5061 The FIELD_DECL nodes are chained together and the lot of them
5062 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5065 grokfield (filename, line, declarator, declspecs, width)
5066 const char *filename ATTRIBUTE_UNUSED;
5067 int line ATTRIBUTE_UNUSED;
5068 tree declarator, declspecs, width;
5072 value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
5074 finish_decl (value, NULL_TREE, NULL_TREE);
5075 DECL_INITIAL (value) = width;
5077 maybe_objc_check_decl (value);
5081 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5082 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5083 ATTRIBUTES are attributes to be applied to the structure. */
5086 finish_struct (t, fieldlist, attributes)
5092 int toplevel = global_binding_level == current_binding_level;
5094 /* If this type was previously laid out as a forward reference,
5095 make sure we lay it out again. */
5099 decl_attributes (t, attributes, NULL_TREE);
5101 /* Nameless union parm types are useful as GCC extension. */
5102 if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
5103 /* Otherwise, warn about any struct or union def. in parmlist. */
5104 if (in_parm_level_p ())
5107 pedwarn ("%s defined inside parms",
5108 TREE_CODE (t) == UNION_TYPE ? "union" : "structure");
5109 else if (! flag_traditional)
5110 warning ("%s defined inside parms",
5111 TREE_CODE (t) == UNION_TYPE ? "union" : "structure");
5116 for (x = fieldlist; x; x = TREE_CHAIN (x))
5117 if (DECL_NAME (x) != 0)
5121 pedwarn ("%s has no %smembers",
5122 TREE_CODE (t) == UNION_TYPE ? "union" : "struct",
5123 fieldlist ? "named " : "");
5126 /* Install struct as DECL_CONTEXT of each field decl.
5127 Also process specified field sizes.
5128 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
5129 The specified size is found in the DECL_INITIAL.
5130 Store 0 there, except for ": 0" fields (so we can find them
5131 and delete them, below). */
5133 for (x = fieldlist; x; x = TREE_CHAIN (x))
5135 DECL_CONTEXT (x) = t;
5136 DECL_PACKED (x) |= TYPE_PACKED (t);
5137 DECL_FIELD_SIZE (x) = 0;
5139 /* If any field is const, the structure type is pseudo-const. */
5140 if (TREE_READONLY (x))
5141 C_TYPE_FIELDS_READONLY (t) = 1;
5144 /* A field that is pseudo-const makes the structure likewise. */
5145 tree t1 = TREE_TYPE (x);
5146 while (TREE_CODE (t1) == ARRAY_TYPE)
5147 t1 = TREE_TYPE (t1);
5148 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5149 && C_TYPE_FIELDS_READONLY (t1))
5150 C_TYPE_FIELDS_READONLY (t) = 1;
5153 /* Any field that is volatile means variables of this type must be
5154 treated in some ways as volatile. */
5155 if (TREE_THIS_VOLATILE (x))
5156 C_TYPE_FIELDS_VOLATILE (t) = 1;
5158 /* Any field of nominal variable size implies structure is too. */
5159 if (C_DECL_VARIABLE_SIZE (x))
5160 C_TYPE_VARIABLE_SIZE (t) = 1;
5162 /* Detect invalid nested redefinition. */
5163 if (TREE_TYPE (x) == t)
5164 error ("nested redefinition of `%s'",
5165 IDENTIFIER_POINTER (TYPE_NAME (t)));
5167 /* Detect invalid bit-field size. */
5168 if (DECL_INITIAL (x))
5169 STRIP_NOPS (DECL_INITIAL (x));
5170 if (DECL_INITIAL (x))
5172 if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST)
5173 constant_expression_warning (DECL_INITIAL (x));
5176 error_with_decl (x, "bit-field `%s' width not an integer constant");
5177 DECL_INITIAL (x) = NULL;
5181 /* Detect invalid bit-field type. */
5182 if (DECL_INITIAL (x)
5183 && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
5184 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
5186 error_with_decl (x, "bit-field `%s' has invalid type");
5187 DECL_INITIAL (x) = NULL;
5189 if (DECL_INITIAL (x) && pedantic
5190 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
5191 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
5192 /* Accept an enum that's equivalent to int or unsigned int. */
5193 && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5194 && (TYPE_PRECISION (TREE_TYPE (x))
5195 == TYPE_PRECISION (integer_type_node))))
5196 pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C");
5198 /* Detect and ignore out of range field width. */
5199 if (DECL_INITIAL (x))
5201 unsigned HOST_WIDE_INT width = TREE_INT_CST_LOW (DECL_INITIAL (x));
5203 if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
5205 DECL_INITIAL (x) = NULL;
5206 error_with_decl (x, "negative width in bit-field `%s'");
5208 else if (TREE_INT_CST_HIGH (DECL_INITIAL (x)) != 0
5209 || width > TYPE_PRECISION (TREE_TYPE (x)))
5211 DECL_INITIAL (x) = NULL;
5212 pedwarn_with_decl (x, "width of `%s' exceeds its type");
5214 else if (width == 0 && DECL_NAME (x) != 0)
5216 error_with_decl (x, "zero width for bit-field `%s'");
5217 DECL_INITIAL (x) = NULL;
5221 /* Process valid field width. */
5222 if (DECL_INITIAL (x))
5224 register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
5226 if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5227 && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
5228 TREE_UNSIGNED (TREE_TYPE (x)))
5229 || width < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
5230 TREE_UNSIGNED (TREE_TYPE (x)))))
5231 warning_with_decl (x, "`%s' is narrower than values of its type");
5233 DECL_FIELD_SIZE (x) = width;
5234 DECL_BIT_FIELD (x) = DECL_C_BIT_FIELD (x) = 1;
5235 DECL_INITIAL (x) = NULL;
5239 /* field size 0 => force desired amount of alignment. */
5240 #ifdef EMPTY_FIELD_BOUNDARY
5241 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
5243 #ifdef PCC_BITFIELD_TYPE_MATTERS
5244 if (PCC_BITFIELD_TYPE_MATTERS)
5245 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
5246 TYPE_ALIGN (TREE_TYPE (x)));
5250 else if (TREE_TYPE (x) != error_mark_node)
5252 unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
5253 : TYPE_ALIGN (TREE_TYPE (x)));
5254 /* Non-bit-fields are aligned for their type, except packed
5255 fields which require only BITS_PER_UNIT alignment. */
5256 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
5260 /* Now DECL_INITIAL is null on all members. */
5262 /* Delete all duplicate fields from the fieldlist */
5263 for (x = fieldlist; x && TREE_CHAIN (x);)
5264 /* Anonymous fields aren't duplicates. */
5265 if (DECL_NAME (TREE_CHAIN (x)) == 0)
5269 register tree y = fieldlist;
5273 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
5279 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
5281 error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
5282 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
5284 else x = TREE_CHAIN (x);
5287 /* Now we have the nearly final fieldlist. Record it,
5288 then lay out the structure or union (including the fields). */
5290 TYPE_FIELDS (t) = fieldlist;
5294 /* Delete all zero-width bit-fields from the fieldlist */
5296 tree *fieldlistp = &fieldlist;
5298 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
5299 *fieldlistp = TREE_CHAIN (*fieldlistp);
5301 fieldlistp = &TREE_CHAIN (*fieldlistp);
5304 /* Now we have the truly final field list.
5305 Store it in this type and in the variants. */
5307 TYPE_FIELDS (t) = fieldlist;
5309 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5311 TYPE_FIELDS (x) = TYPE_FIELDS (t);
5312 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
5313 TYPE_ALIGN (x) = TYPE_ALIGN (t);
5316 /* If this was supposed to be a transparent union, but we can't
5317 make it one, warn and turn off the flag. */
5318 if (TREE_CODE (t) == UNION_TYPE
5319 && TYPE_TRANSPARENT_UNION (t)
5320 && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))
5322 TYPE_TRANSPARENT_UNION (t) = 0;
5323 warning ("union cannot be made transparent");
5326 /* If this structure or union completes the type of any previous
5327 variable declaration, lay it out and output its rtl. */
5329 if (current_binding_level->n_incomplete != 0)
5332 for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
5334 if (TREE_TYPE (decl) == t
5335 && TREE_CODE (decl) != TYPE_DECL)
5337 layout_decl (decl, 0);
5338 /* This is a no-op in c-lang.c or something real in objc-actions.c. */
5339 maybe_objc_check_decl (decl);
5340 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
5343 --current_binding_level->n_incomplete;
5345 else if (TYPE_SIZE (TREE_TYPE (decl)) == 0
5346 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
5348 tree element = TREE_TYPE (decl);
5349 while (TREE_CODE (element) == ARRAY_TYPE)
5350 element = TREE_TYPE (element);
5352 layout_array_type (TREE_TYPE (decl));
5357 /* Finish debugging output for this type. */
5358 rest_of_type_compilation (t, toplevel);
5363 /* Lay out the type T, and its element type, and so on. */
5366 layout_array_type (t)
5369 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5370 layout_array_type (TREE_TYPE (t));
5374 /* Begin compiling the definition of an enumeration type.
5375 NAME is its name (or null if anonymous).
5376 Returns the type object, as yet incomplete.
5377 Also records info about it so that build_enumerator
5378 may be used to declare the individual values as they are read. */
5384 register tree enumtype = 0;
5386 /* If this is the real definition for a previous forward reference,
5387 fill in the contents in the same object that used to be the
5388 forward reference. */
5391 enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
5393 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
5395 enumtype = make_node (ENUMERAL_TYPE);
5396 pushtag (name, enumtype);
5399 C_TYPE_BEING_DEFINED (enumtype) = 1;
5401 if (TYPE_VALUES (enumtype) != 0)
5403 /* This enum is a named one that has been declared already. */
5404 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
5406 /* Completely replace its old definition.
5407 The old enumerators remain defined, however. */
5408 TYPE_VALUES (enumtype) = 0;
5411 enum_next_value = integer_zero_node;
5414 if (flag_short_enums)
5415 TYPE_PACKED (enumtype) = 1;
5420 /* After processing and defining all the values of an enumeration type,
5421 install their decls in the enumeration type and finish it off.
5422 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5423 and ATTRIBUTES are the specified attributes.
5424 Returns ENUMTYPE. */
5427 finish_enum (enumtype, values, attributes)
5432 register tree pair, tem;
5433 tree minnode = 0, maxnode = 0;
5434 int precision, unsign;
5435 int toplevel = (global_binding_level == current_binding_level);
5437 if (in_parm_level_p ())
5438 warning ("enum defined inside parms");
5440 decl_attributes (enumtype, attributes, NULL_TREE);
5442 /* Calculate the maximum value of any enumerator in this type. */
5444 if (values == error_mark_node)
5445 minnode = maxnode = integer_zero_node;
5448 minnode = maxnode = TREE_VALUE (values);
5449 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
5451 tree value = TREE_VALUE (pair);
5452 if (tree_int_cst_lt (maxnode, value))
5454 if (tree_int_cst_lt (value, minnode))
5459 /* Construct the final type of this enumeration. It is the same
5460 as one of the integral types - the narrowest one that fits, except
5461 that normally we only go as narrow as int - and signed iff any of
5462 the values are negative. */
5463 unsign = (tree_int_cst_sgn (minnode) >= 0);
5464 precision = MAX (min_precision (minnode, unsign),
5465 min_precision (maxnode, unsign));
5466 if (!TYPE_PACKED (enumtype))
5467 precision = MAX (precision, TYPE_PRECISION (integer_type_node));
5468 if (type_for_size (precision, unsign) == 0)
5470 warning ("enumeration values exceed range of largest integer");
5471 precision = TYPE_PRECISION (long_long_integer_type_node);
5474 TYPE_MIN_VALUE (enumtype) = minnode;
5475 TYPE_MAX_VALUE (enumtype) = maxnode;
5476 TYPE_PRECISION (enumtype) = precision;
5477 TREE_UNSIGNED (enumtype) = unsign;
5478 TYPE_SIZE (enumtype) = 0;
5479 layout_type (enumtype);
5481 if (values != error_mark_node)
5483 /* Change the type of the enumerators to be the enum type. We
5484 need to do this irrespective of the size of the enum, for
5485 proper type checking. Replace the DECL_INITIALs of the
5486 enumerators, and the value slots of the list, with copies
5487 that have the enum type; they cannot be modified in place
5488 because they may be shared (e.g. integer_zero_node) Finally,
5489 change the purpose slots to point to the names of the decls. */
5490 for (pair = values; pair; pair = TREE_CHAIN (pair))
5492 tree enu = TREE_PURPOSE (pair);
5494 TREE_TYPE (enu) = enumtype;
5495 DECL_SIZE (enu) = TYPE_SIZE (enumtype);
5496 DECL_ALIGN (enu) = TYPE_ALIGN (enumtype);
5497 DECL_MODE (enu) = TYPE_MODE (enumtype);
5498 DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu));
5500 TREE_PURPOSE (pair) = DECL_NAME (enu);
5501 TREE_VALUE (pair) = DECL_INITIAL (enu);
5504 TYPE_VALUES (enumtype) = values;
5507 /* Fix up all variant types of this enum type. */
5508 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
5510 if (tem == enumtype)
5512 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
5513 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
5514 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
5515 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
5516 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
5517 TYPE_MODE (tem) = TYPE_MODE (enumtype);
5518 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
5519 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
5520 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
5523 /* Finish debugging output for this type. */
5524 rest_of_type_compilation (enumtype, toplevel);
5529 /* Build and install a CONST_DECL for one value of the
5530 current enumeration type (one that was begun with start_enum).
5531 Return a tree-list containing the CONST_DECL and its value.
5532 Assignment of sequential values by default is handled here. */
5535 build_enumerator (name, value)
5538 register tree decl, type;
5540 /* Validate and default VALUE. */
5542 /* Remove no-op casts from the value. */
5544 STRIP_TYPE_NOPS (value);
5548 if (TREE_CODE (value) == INTEGER_CST)
5550 value = default_conversion (value);
5551 constant_expression_warning (value);
5555 error ("enumerator value for `%s' not integer constant",
5556 IDENTIFIER_POINTER (name));
5561 /* Default based on previous value. */
5562 /* It should no longer be possible to have NON_LVALUE_EXPR
5566 value = enum_next_value;
5568 error ("overflow in enumeration values");
5571 if (pedantic && ! int_fits_type_p (value, integer_type_node))
5573 pedwarn ("ANSI C restricts enumerator values to range of `int'");
5574 value = integer_zero_node;
5577 /* Set basis for default for next value. */
5578 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
5579 enum_overflow = tree_int_cst_lt (enum_next_value, value);
5581 /* Now create a declaration for the enum value name. */
5583 type = TREE_TYPE (value);
5584 type = type_for_size (MAX (TYPE_PRECISION (type),
5585 TYPE_PRECISION (integer_type_node)),
5587 || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
5588 && TREE_UNSIGNED (type)));
5590 decl = build_decl (CONST_DECL, name, type);
5591 DECL_INITIAL (decl) = value;
5592 TREE_TYPE (value) = type;
5595 return tree_cons (decl, value, NULL_TREE);
5598 /* Create the FUNCTION_DECL for a function definition.
5599 DECLSPECS, DECLARATOR, PREFIX_ATTRIBUTES and ATTRIBUTES are the parts of
5600 the declaration; they describe the function's name and the type it returns,
5601 but twisted together in a fashion that parallels the syntax of C.
5603 This function creates a binding context for the function body
5604 as well as setting up the FUNCTION_DECL in current_function_decl.
5606 Returns 1 on success. If the DECLARATOR is not suitable for a function
5607 (it defines a datum instead), we return 0, which tells
5608 yyparse to report a parse error. */
5611 start_function (declspecs, declarator, prefix_attributes, attributes)
5612 tree declarator, declspecs, prefix_attributes, attributes;
5614 tree decl1, old_decl;
5616 int old_immediate_size_expand = immediate_size_expand;
5618 current_function_returns_value = 0; /* Assume, until we see it does. */
5619 current_function_returns_null = 0;
5620 warn_about_return_type = 0;
5621 current_extern_inline = 0;
5622 c_function_varargs = 0;
5624 shadowed_labels = 0;
5626 /* Don't expand any sizes in the return type of the function. */
5627 immediate_size_expand = 0;
5629 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
5631 /* If the declarator is not suitable for a function definition,
5632 cause a syntax error. */
5635 immediate_size_expand = old_immediate_size_expand;
5639 decl_attributes (decl1, prefix_attributes, attributes);
5641 announce_function (decl1);
5643 if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
5645 error ("return-type is an incomplete type");
5646 /* Make it return void instead. */
5648 = build_function_type (void_type_node,
5649 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
5652 if (warn_about_return_type)
5653 warning ("return-type defaults to `int'");
5655 /* Save the parm names or decls from this function's declarator
5656 where store_parm_decls will find them. */
5657 current_function_parms = last_function_parms;
5658 current_function_parm_tags = last_function_parm_tags;
5660 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5661 error_mark_node is replaced below (in poplevel) with the BLOCK. */
5662 DECL_INITIAL (decl1) = error_mark_node;
5664 /* If this definition isn't a prototype and we had a prototype declaration
5665 before, copy the arg type info from that prototype.
5666 But not if what we had before was a builtin function. */
5667 old_decl = lookup_name_current_level (DECL_NAME (decl1));
5668 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
5669 && !DECL_BUILT_IN (old_decl)
5670 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5671 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
5672 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
5674 TREE_TYPE (decl1) = TREE_TYPE (old_decl);
5675 current_function_prototype_file = DECL_SOURCE_FILE (old_decl);
5676 current_function_prototype_line = DECL_SOURCE_LINE (old_decl);
5679 /* If there is no explicit declaration, look for any out-of-scope implicit
5682 old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1));
5684 /* Optionally warn of old-fashioned def with no previous prototype. */
5685 if (warn_strict_prototypes
5686 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
5687 && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0))
5688 warning ("function declaration isn't a prototype");
5689 /* Optionally warn of any global def with no previous prototype. */
5690 else if (warn_missing_prototypes
5691 && TREE_PUBLIC (decl1)
5692 && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)
5693 && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
5694 warning_with_decl (decl1, "no previous prototype for `%s'");
5695 /* Optionally warn of any def with no previous prototype
5696 if the function has already been used. */
5697 else if (warn_missing_prototypes
5698 && old_decl != 0 && TREE_USED (old_decl)
5699 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
5700 warning_with_decl (decl1,
5701 "`%s' was used with no prototype before its definition");
5702 /* Optionally warn of any global def with no previous declaration. */
5703 else if (warn_missing_declarations
5704 && TREE_PUBLIC (decl1)
5706 && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
5707 warning_with_decl (decl1, "no previous declaration for `%s'");
5708 /* Optionally warn of any def with no previous declaration
5709 if the function has already been used. */
5710 else if (warn_missing_declarations
5711 && old_decl != 0 && TREE_USED (old_decl)
5712 && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)))
5713 warning_with_decl (decl1,
5714 "`%s' was used with no declaration before its definition");
5716 /* This is a definition, not a reference.
5717 So normally clear DECL_EXTERNAL.
5718 However, `extern inline' acts like a declaration
5719 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5720 DECL_EXTERNAL (decl1) = current_extern_inline;
5722 #ifdef SET_DEFAULT_DECL_ATTRIBUTES
5723 SET_DEFAULT_DECL_ATTRIBUTES (decl1, attributes);
5726 /* This function exists in static storage.
5727 (This does not mean `static' in the C sense!) */
5728 TREE_STATIC (decl1) = 1;
5730 /* A nested function is not global. */
5731 if (current_function_decl != 0)
5732 TREE_PUBLIC (decl1) = 0;
5734 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5736 && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))) == 0)
5741 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5742 != integer_type_node)
5743 pedwarn_with_decl (decl1, "return type of `%s' is not `int'");
5745 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
5746 args = TREE_CHAIN (args))
5748 tree type = args ? TREE_VALUE (args) : 0;
5750 if (type == void_type_node)
5757 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
5758 pedwarn_with_decl (decl1,
5759 "first argument of `%s' should be `int'");
5763 if (TREE_CODE (type) != POINTER_TYPE
5764 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5765 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5767 pedwarn_with_decl (decl1,
5768 "second argument of `%s' should be `char **'");
5772 if (TREE_CODE (type) != POINTER_TYPE
5773 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5774 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5776 pedwarn_with_decl (decl1,
5777 "third argument of `%s' should probably be `char **'");
5782 /* It is intentional that this message does not mention the third
5783 argument, which is warned for only pedantically, because it's
5784 blessed by mention in an appendix of the standard. */
5785 if (argct > 0 && (argct < 2 || argct > 3))
5786 pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments");
5788 if (argct == 3 && pedantic)
5789 pedwarn_with_decl (decl1, "third argument of `%s' is deprecated");
5791 if (! TREE_PUBLIC (decl1))
5792 pedwarn_with_decl (decl1, "`%s' is normally a non-static function");
5795 /* Record the decl so that the function name is defined.
5796 If we already have a decl for this name, and it is a FUNCTION_DECL,
5797 use the old decl. */
5799 current_function_decl = pushdecl (decl1);
5802 declare_parm_level (1);
5803 current_binding_level->subblocks_tag_transparent = 1;
5805 make_function_rtl (current_function_decl);
5807 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
5808 /* Promote the value to int before returning it. */
5809 if (C_PROMOTING_INTEGER_TYPE_P (restype))
5811 /* It retains unsignedness if traditional
5812 or if not really getting wider. */
5813 if (TREE_UNSIGNED (restype)
5814 && (flag_traditional
5815 || (TYPE_PRECISION (restype)
5816 == TYPE_PRECISION (integer_type_node))))
5817 restype = unsigned_type_node;
5819 restype = integer_type_node;
5821 DECL_RESULT (current_function_decl)
5822 = build_decl (RESULT_DECL, NULL_TREE, restype);
5824 /* If this fcn was already referenced via a block-scope `extern' decl
5825 (or an implicit decl), propagate certain information about the usage. */
5826 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
5827 TREE_ADDRESSABLE (current_function_decl) = 1;
5829 immediate_size_expand = old_immediate_size_expand;
5834 /* Record that this function is going to be a varargs function.
5835 This is called before store_parm_decls, which is too early
5836 to call mark_varargs directly. */
5841 c_function_varargs = 1;
5844 /* Store the parameter declarations into the current function declaration.
5845 This is called after parsing the parameter declarations, before
5846 digesting the body of the function.
5848 For an old-style definition, modify the function's type
5849 to specify at least the number of arguments. */
5854 register tree fndecl = current_function_decl;
5857 /* This is either a chain of PARM_DECLs (if a prototype was used)
5858 or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */
5859 tree specparms = current_function_parms;
5861 /* This is a list of types declared among parms in a prototype. */
5862 tree parmtags = current_function_parm_tags;
5864 /* This is a chain of PARM_DECLs from old-style parm declarations. */
5865 register tree parmdecls = getdecls ();
5867 /* This is a chain of any other decls that came in among the parm
5868 declarations. If a parm is declared with enum {foo, bar} x;
5869 then CONST_DECLs for foo and bar are put here. */
5872 /* Nonzero if this definition is written with a prototype. */
5875 if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
5877 /* This case is when the function was defined with an ANSI prototype.
5878 The parms already have decls, so we need not do anything here
5879 except record them as in effect
5880 and complain if any redundant old-style parm decls were written. */
5891 error_with_decl (fndecl,
5892 "parm types given both in parmlist and separately");
5893 /* Get rid of the erroneous decls; don't keep them on
5894 the list of parms, since they might not be PARM_DECLs. */
5895 for (decl = current_binding_level->names;
5896 decl; decl = TREE_CHAIN (decl))
5897 if (DECL_NAME (decl))
5898 IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
5899 for (link = current_binding_level->shadowed;
5900 link; link = TREE_CHAIN (link))
5901 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
5902 current_binding_level->names = 0;
5903 current_binding_level->shadowed = 0;
5906 specparms = nreverse (specparms);
5907 for (parm = specparms; parm; parm = next)
5909 next = TREE_CHAIN (parm);
5910 if (TREE_CODE (parm) == PARM_DECL)
5912 if (DECL_NAME (parm) == 0)
5913 error_with_decl (parm, "parameter name omitted");
5914 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
5916 error_with_decl (parm, "parameter `%s' declared void");
5917 /* Change the type to error_mark_node so this parameter
5918 will be ignored by assign_parms. */
5919 TREE_TYPE (parm) = error_mark_node;
5925 /* If we find an enum constant or a type tag,
5926 put it aside for the moment. */
5927 TREE_CHAIN (parm) = 0;
5928 others = chainon (others, parm);
5932 /* Get the decls in their original chain order
5933 and record in the function. */
5934 DECL_ARGUMENTS (fndecl) = getdecls ();
5937 /* If this function takes a variable number of arguments,
5938 add a phony parameter to the end of the parm list,
5939 to represent the position of the first unnamed argument. */
5940 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
5943 tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
5944 /* Let's hope the address of the unnamed parm
5945 won't depend on its type. */
5946 TREE_TYPE (dummy) = integer_type_node;
5947 DECL_ARG_TYPE (dummy) = integer_type_node;
5948 DECL_ARGUMENTS (fndecl)
5949 = chainon (DECL_ARGUMENTS (fndecl), dummy);
5953 /* Now pushdecl the enum constants. */
5954 for (parm = others; parm; parm = next)
5956 next = TREE_CHAIN (parm);
5957 if (DECL_NAME (parm) == 0)
5959 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
5961 else if (TREE_CODE (parm) != PARM_DECL)
5965 storetags (chainon (parmtags, gettags ()));
5969 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
5970 each with a parm name as the TREE_VALUE.
5972 PARMDECLS is a chain of declarations for parameters.
5973 Warning! It can also contain CONST_DECLs which are not parameters
5974 but are names of enumerators of any enum types
5975 declared among the parameters.
5977 First match each formal parameter name with its declaration.
5978 Associate decls with the names and store the decls
5979 into the TREE_PURPOSE slots. */
5981 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
5982 DECL_RESULT (parm) = 0;
5984 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
5986 register tree tail, found = NULL;
5988 if (TREE_VALUE (parm) == 0)
5990 error_with_decl (fndecl, "parameter name missing from parameter list");
5991 TREE_PURPOSE (parm) = 0;
5995 /* See if any of the parmdecls specifies this parm by name.
5996 Ignore any enumerator decls. */
5997 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
5998 if (DECL_NAME (tail) == TREE_VALUE (parm)
5999 && TREE_CODE (tail) == PARM_DECL)
6005 /* If declaration already marked, we have a duplicate name.
6006 Complain, and don't use this decl twice. */
6007 if (found && DECL_RESULT (found) != 0)
6009 error_with_decl (found, "multiple parameters named `%s'");
6013 /* If the declaration says "void", complain and ignore it. */
6014 if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
6016 error_with_decl (found, "parameter `%s' declared void");
6017 TREE_TYPE (found) = integer_type_node;
6018 DECL_ARG_TYPE (found) = integer_type_node;
6019 layout_decl (found, 0);
6022 /* Traditionally, a parm declared float is actually a double. */
6023 if (found && flag_traditional
6024 && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
6026 TREE_TYPE (found) = double_type_node;
6027 DECL_ARG_TYPE (found) = double_type_node;
6028 layout_decl (found, 0);
6031 /* If no declaration found, default to int. */
6034 found = build_decl (PARM_DECL, TREE_VALUE (parm),
6036 DECL_ARG_TYPE (found) = TREE_TYPE (found);
6037 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
6038 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
6040 warning_with_decl (found, "type of `%s' defaults to `int'");
6044 TREE_PURPOSE (parm) = found;
6046 /* Mark this decl as "already found" -- see test, above.
6047 It is safe to use DECL_RESULT for this
6048 since it is not used in PARM_DECLs or CONST_DECLs. */
6049 DECL_RESULT (found) = error_mark_node;
6052 /* Put anything which is on the parmdecls chain and which is
6053 not a PARM_DECL onto the list NONPARMS. (The types of
6054 non-parm things which might appear on the list include
6055 enumerators and NULL-named TYPE_DECL nodes.) Complain about
6056 any actual PARM_DECLs not matched with any names. */
6059 for (parm = parmdecls; parm; )
6061 tree next = TREE_CHAIN (parm);
6062 TREE_CHAIN (parm) = 0;
6064 if (TREE_CODE (parm) != PARM_DECL)
6065 nonparms = chainon (nonparms, parm);
6068 /* Complain about args with incomplete types. */
6069 if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
6071 error_with_decl (parm, "parameter `%s' has incomplete type");
6072 TREE_TYPE (parm) = error_mark_node;
6075 if (DECL_RESULT (parm) == 0)
6077 error_with_decl (parm,
6078 "declaration for parameter `%s' but no such parameter");
6079 /* Pretend the parameter was not missing.
6080 This gets us to a standard state and minimizes
6081 further error messages. */
6083 = chainon (specparms,
6084 tree_cons (parm, NULL_TREE, NULL_TREE));
6091 /* Chain the declarations together in the order of the list of names. */
6092 /* Store that chain in the function decl, replacing the list of names. */
6094 DECL_ARGUMENTS (fndecl) = 0;
6097 for (last = 0; parm; parm = TREE_CHAIN (parm))
6098 if (TREE_PURPOSE (parm))
6101 DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
6103 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6104 last = TREE_PURPOSE (parm);
6105 TREE_CHAIN (last) = 0;
6109 /* If there was a previous prototype,
6110 set the DECL_ARG_TYPE of each argument according to
6111 the type previously specified, and report any mismatches. */
6113 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
6116 for (parm = DECL_ARGUMENTS (fndecl),
6117 type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
6118 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
6119 != void_type_node));
6120 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6122 if (parm == 0 || type == 0
6123 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6125 error ("number of arguments doesn't match prototype");
6126 error_with_file_and_line (current_function_prototype_file,
6127 current_function_prototype_line,
6128 "prototype declaration");
6131 /* Type for passing arg must be consistent
6132 with that declared for the arg. */
6133 if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type)))
6135 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6136 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6138 /* Adjust argument to match prototype. E.g. a previous
6139 `int foo(float);' prototype causes
6140 `int foo(x) float x; {...}' to be treated like
6141 `int foo(float x) {...}'. This is particularly
6142 useful for argument types like uid_t. */
6143 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6145 if (PROMOTE_PROTOTYPES
6146 && (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
6147 || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE)
6148 && TYPE_PRECISION (TREE_TYPE (parm))
6149 < TYPE_PRECISION (integer_type_node))
6150 DECL_ARG_TYPE (parm) = integer_type_node;
6154 pedwarn ("promoted argument `%s' doesn't match prototype",
6155 IDENTIFIER_POINTER (DECL_NAME (parm)));
6156 warning_with_file_and_line
6157 (current_function_prototype_file,
6158 current_function_prototype_line,
6159 "prototype declaration");
6162 /* If -traditional, allow `int' argument to match
6163 `unsigned' prototype. */
6164 else if (! (flag_traditional
6165 && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node
6166 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))
6168 error ("argument `%s' doesn't match prototype",
6169 IDENTIFIER_POINTER (DECL_NAME (parm)));
6170 error_with_file_and_line (current_function_prototype_file,
6171 current_function_prototype_line,
6172 "prototype declaration");
6176 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6179 /* Otherwise, create a prototype that would match. */
6183 tree actual = 0, last = 0, type;
6185 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6187 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6189 TREE_CHAIN (last) = type;
6194 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6196 TREE_CHAIN (last) = type;
6200 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6201 of the type of this function, but we need to avoid having this
6202 affect the types of other similarly-typed functions, so we must
6203 first force the generation of an identical (but separate) type
6204 node for the relevant function type. The new node we create
6205 will be a variant of the main variant of the original function
6208 TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
6210 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6213 /* Now store the final chain of decls for the arguments
6214 as the decl-chain of the current lexical scope.
6215 Put the enumerators in as well, at the front so that
6216 DECL_ARGUMENTS is not modified. */
6218 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
6221 /* Make sure the binding level for the top of the function body
6222 gets a BLOCK if there are any in the function.
6223 Otherwise, the dbx output is wrong. */
6225 keep_next_if_subblocks = 1;
6227 /* ??? This might be an improvement,
6228 but needs to be thought about some more. */
6230 keep_next_level_flag = 1;
6233 /* Write a record describing this function definition to the prototypes
6234 file (if requested). */
6236 gen_aux_info_record (fndecl, 1, 0, prototype);
6238 /* Initialize the RTL code for the function. */
6240 init_function_start (fndecl, input_filename, lineno);
6242 /* If this is a varargs function, inform function.c. */
6244 if (c_function_varargs)
6247 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
6249 declare_function_name ();
6251 /* Set up parameters and prepare for return, for the function. */
6253 expand_function_start (fndecl, 0);
6255 /* If this function is `main', emit a call to `__main'
6256 to run global initializers, etc. */
6257 if (DECL_NAME (fndecl)
6258 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
6259 && DECL_CONTEXT (fndecl) == NULL_TREE)
6260 expand_main_function ();
6263 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
6264 each with a parm name as the TREE_VALUE. A null pointer as TREE_VALUE
6265 stands for an ellipsis in the identifier list.
6267 PARMLIST is the data returned by get_parm_info for the
6268 parmlist that follows the semicolon.
6270 We return a value of the same sort that get_parm_info returns,
6271 except that it describes the combination of identifiers and parmlist. */
6274 combine_parm_decls (specparms, parmlist, void_at_end)
6275 tree specparms, parmlist;
6278 register tree fndecl = current_function_decl;
6281 tree parmdecls = TREE_PURPOSE (parmlist);
6283 /* This is a chain of any other decls that came in among the parm
6284 declarations. They were separated already by get_parm_info,
6285 so we just need to keep them separate. */
6286 tree nonparms = TREE_VALUE (parmlist);
6290 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
6291 DECL_RESULT (parm) = 0;
6293 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
6295 register tree tail, found = NULL;
6297 /* See if any of the parmdecls specifies this parm by name. */
6298 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
6299 if (DECL_NAME (tail) == TREE_VALUE (parm))
6305 /* If declaration already marked, we have a duplicate name.
6306 Complain, and don't use this decl twice. */
6307 if (found && DECL_RESULT (found) != 0)
6309 error_with_decl (found, "multiple parameters named `%s'");
6313 /* If the declaration says "void", complain and ignore it. */
6314 if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
6316 error_with_decl (found, "parameter `%s' declared void");
6317 TREE_TYPE (found) = integer_type_node;
6318 DECL_ARG_TYPE (found) = integer_type_node;
6319 layout_decl (found, 0);
6322 /* Traditionally, a parm declared float is actually a double. */
6323 if (found && flag_traditional
6324 && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
6326 TREE_TYPE (found) = double_type_node;
6327 DECL_ARG_TYPE (found) = double_type_node;
6328 layout_decl (found, 0);
6331 /* If no declaration found, default to int. */
6334 found = build_decl (PARM_DECL, TREE_VALUE (parm),
6336 DECL_ARG_TYPE (found) = TREE_TYPE (found);
6337 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
6338 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
6339 error_with_decl (found, "type of parameter `%s' is not declared");
6343 TREE_PURPOSE (parm) = found;
6345 /* Mark this decl as "already found" -- see test, above.
6346 It is safe to use DECL_RESULT for this
6347 since it is not used in PARM_DECLs or CONST_DECLs. */
6348 DECL_RESULT (found) = error_mark_node;
6351 /* Complain about any actual PARM_DECLs not matched with any names. */
6353 for (parm = parmdecls; parm; )
6355 tree next = TREE_CHAIN (parm);
6356 TREE_CHAIN (parm) = 0;
6358 /* Complain about args with incomplete types. */
6359 if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
6361 error_with_decl (parm, "parameter `%s' has incomplete type");
6362 TREE_TYPE (parm) = error_mark_node;
6365 if (DECL_RESULT (parm) == 0)
6367 error_with_decl (parm,
6368 "declaration for parameter `%s' but no such parameter");
6369 /* Pretend the parameter was not missing.
6370 This gets us to a standard state and minimizes
6371 further error messages. */
6373 = chainon (specparms,
6374 tree_cons (parm, NULL_TREE, NULL_TREE));
6380 /* Chain the declarations together in the order of the list of names.
6381 At the same time, build up a list of their types, in reverse order. */
6387 for (last = 0; parm; parm = TREE_CHAIN (parm))
6388 if (TREE_PURPOSE (parm))
6391 parmdecls = TREE_PURPOSE (parm);
6393 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6394 last = TREE_PURPOSE (parm);
6395 TREE_CHAIN (last) = 0;
6397 types = tree_cons (NULL_TREE, TREE_TYPE (parm), types);
6402 return tree_cons (parmdecls, nonparms,
6403 nreverse (tree_cons (NULL_TREE, void_type_node, types)));
6405 return tree_cons (parmdecls, nonparms, nreverse (types));
6408 /* Finish up a function declaration and compile that function
6409 all the way to assembler language output. The free the storage
6410 for the function definition.
6412 This is called after parsing the body of the function definition.
6414 NESTED is nonzero if the function being finished is nested in another. */
6417 finish_function (nested)
6420 register tree fndecl = current_function_decl;
6422 /* TREE_READONLY (fndecl) = 1;
6423 This caused &foo to be of type ptr-to-const-function
6424 which then got a warning when stored in a ptr-to-function variable. */
6427 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6429 /* Must mark the RESULT_DECL as being in this function. */
6431 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
6433 /* Obey `register' declarations if `setjmp' is called in this fn. */
6434 if (flag_traditional && current_function_calls_setjmp)
6436 setjmp_protect (DECL_INITIAL (fndecl));
6437 setjmp_protect_args ();
6440 if (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main"))
6442 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6443 != integer_type_node)
6445 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6446 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6448 pedwarn_with_decl (fndecl, "return type of `%s' is not `int'");
6452 #ifdef DEFAULT_MAIN_RETURN
6453 /* Make it so that `main' always returns success by default. */
6454 DEFAULT_MAIN_RETURN;
6459 /* Generate rtl for function exit. */
6460 expand_function_end (input_filename, lineno, 0);
6462 /* So we can tell if jump_optimize sets it to 1. */
6465 /* If this is a nested function, protect the local variables in the stack
6466 above us from being collected while we're compiling this function. */
6468 ggc_push_context ();
6470 /* Run the optimizers and output the assembler code for this function. */
6471 rest_of_compilation (fndecl);
6473 /* Undo the GC context switch. */
6477 current_function_returns_null |= can_reach_end;
6479 if (warn_missing_noreturn
6480 && !TREE_THIS_VOLATILE (fndecl)
6481 && !current_function_returns_null
6482 && !current_function_returns_value)
6483 warning ("function might be possible candidate for attribute `noreturn'");
6485 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
6486 warning ("`noreturn' function does return");
6487 else if (warn_return_type && can_reach_end
6488 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != void_type_node)
6489 /* If this function returns non-void and control can drop through,
6491 warning ("control reaches end of non-void function");
6492 /* With just -W, complain only if function returns both with
6493 and without a value. */
6494 else if (extra_warnings
6495 && current_function_returns_value && current_function_returns_null)
6496 warning ("this function may return with or without a value");
6498 /* If requested, warn about function definitions where the function will
6499 return a value (usually of some struct or union type) which itself will
6500 take up a lot of stack space. */
6502 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
6504 register tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
6508 register tree ret_type_size = TYPE_SIZE (ret_type);
6510 if (TREE_CODE (ret_type_size) == INTEGER_CST)
6513 = TREE_INT_CST_LOW (ret_type_size) / BITS_PER_UNIT;
6515 if (units > larger_than_size)
6516 warning_with_decl (fndecl,
6517 "size of return value of `%s' is %u bytes",
6523 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested)
6525 /* Stop pointing to the local nodes about to be freed. */
6526 /* But DECL_INITIAL must remain nonzero so we know this
6527 was an actual function definition. */
6528 /* For a nested function, this is done in pop_c_function_context. */
6529 /* If rest_of_compilation set this to 0, leave it 0. */
6530 if (DECL_INITIAL (fndecl) != 0)
6531 DECL_INITIAL (fndecl) = error_mark_node;
6532 DECL_ARGUMENTS (fndecl) = 0;
6535 if (DECL_STATIC_CONSTRUCTOR (fndecl))
6537 #ifndef ASM_OUTPUT_CONSTRUCTOR
6538 if (! flag_gnu_linker)
6539 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
6542 assemble_constructor (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)));
6545 if (DECL_STATIC_DESTRUCTOR (fndecl))
6547 #ifndef ASM_OUTPUT_DESTRUCTOR
6548 if (! flag_gnu_linker)
6549 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
6552 assemble_destructor (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)));
6557 /* Let the error reporting routines know that we're outside a
6558 function. For a nested function, this value is used in
6559 pop_c_function_context and then reset via pop_function_context. */
6560 current_function_decl = NULL;
6564 /* Save and restore the variables in this file and elsewhere
6565 that keep track of the progress of compilation of the current function.
6566 Used for nested functions. */
6568 struct language_function
6571 tree shadowed_labels;
6574 int warn_about_return_type;
6576 struct binding_level *binding_level;
6579 /* Save and reinitialize the variables
6580 used during compilation of a C function. */
6583 push_c_function_context (f)
6586 struct language_function *p;
6587 p = (struct language_function *) xmalloc (sizeof (struct language_function));
6590 p->named_labels = named_labels;
6591 p->shadowed_labels = shadowed_labels;
6592 p->returns_value = current_function_returns_value;
6593 p->returns_null = current_function_returns_null;
6594 p->warn_about_return_type = warn_about_return_type;
6595 p->extern_inline = current_extern_inline;
6596 p->binding_level = current_binding_level;
6599 /* Restore the variables used during compilation of a C function. */
6602 pop_c_function_context (f)
6605 struct language_function *p = f->language;
6608 /* Bring back all the labels that were shadowed. */
6609 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
6610 if (DECL_NAME (TREE_VALUE (link)) != 0)
6611 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
6612 = TREE_VALUE (link);
6614 if (DECL_SAVED_INSNS (current_function_decl) == 0)
6616 /* Stop pointing to the local nodes about to be freed. */
6617 /* But DECL_INITIAL must remain nonzero so we know this
6618 was an actual function definition. */
6619 DECL_INITIAL (current_function_decl) = error_mark_node;
6620 DECL_ARGUMENTS (current_function_decl) = 0;
6623 named_labels = p->named_labels;
6624 shadowed_labels = p->shadowed_labels;
6625 current_function_returns_value = p->returns_value;
6626 current_function_returns_null = p->returns_null;
6627 warn_about_return_type = p->warn_about_return_type;
6628 current_extern_inline = p->extern_inline;
6629 current_binding_level = p->binding_level;
6635 /* Mark the language specific parts of F for GC. */
6637 mark_c_function_context (f)
6640 struct language_function *p = f->language;
6645 ggc_mark_tree (p->shadowed_labels);
6646 ggc_mark_tree (p->named_labels);
6647 mark_binding_level (&p->binding_level);
6650 /* integrate_decl_tree calls this function, but since we don't use the
6651 DECL_LANG_SPECIFIC field, this is a no-op. */
6654 copy_lang_decl (node)
6655 tree node ATTRIBUTE_UNUSED;
6659 /* Mark ARG for GC. */
6661 lang_mark_false_label_stack (arg)
6662 struct label_node *arg;
6664 /* C doesn't use false_label_stack. It better be NULL. */
6669 /* Mark the language specific bits in T for GC. */
6674 if (TREE_CODE (t) == IDENTIFIER_NODE)
6676 struct lang_identifier *i = (struct lang_identifier *) t;
6677 ggc_mark_tree (i->global_value);
6678 ggc_mark_tree (i->local_value);
6679 ggc_mark_tree (i->label_value);
6680 ggc_mark_tree (i->implicit_decl);
6681 ggc_mark_tree (i->error_locus);
6682 ggc_mark_tree (i->limbo_value);
6684 else if (TYPE_P (t) && TYPE_LANG_SPECIFIC (t))
6685 ggc_mark (TYPE_LANG_SPECIFIC (t));