1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
33 #include "tree-inline.h"
50 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
52 { NORMAL, /* Ordinary declaration */
53 FUNCDEF, /* Function definition */
54 PARM, /* Declaration of parm before function body */
55 FIELD, /* Declaration inside struct or union */
56 BITFIELD, /* Likewise but with specified width */
57 TYPENAME}; /* Typename (inside cast or sizeof) */
60 /* Nonzero if we have seen an invalid cross reference
61 to a struct, union, or enum, but not yet printed the message. */
63 tree pending_invalid_xref;
64 /* File and line to appear in the eventual error message. */
65 const char *pending_invalid_xref_file;
66 int pending_invalid_xref_line;
68 /* While defining an enum type, this is 1 plus the last enumerator
69 constant value. Note that will do not have to save this or `enum_overflow'
70 around nested function definition since such a definition could only
71 occur in an enum value expression and we don't use these variables in
74 static tree enum_next_value;
76 /* Nonzero means that there was overflow computing enum_next_value. */
78 static int enum_overflow;
80 /* Parsing a function declarator leaves a list of parameter names
81 or a chain or parameter decls here. */
83 static tree last_function_parms;
85 /* Parsing a function declarator leaves here a chain of structure
86 and enum types declared in the parmlist. */
88 static tree last_function_parm_tags;
90 /* After parsing the declarator that starts a function definition,
91 `start_function' puts here the list of parameter names or chain of decls.
92 `store_parm_decls' finds it here. */
94 static tree current_function_parms;
96 /* Similar, for last_function_parm_tags. */
97 static tree current_function_parm_tags;
99 /* Similar, for the file and line that the prototype came from if this is
100 an old-style definition. */
101 static const char *current_function_prototype_file;
102 static int current_function_prototype_line;
104 /* The current statement tree. */
106 static GTY(()) struct stmt_tree_s c_stmt_tree;
108 /* The current scope statement stack. */
110 static GTY(()) tree c_scope_stmt_stack;
112 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
113 that have names. Here so we can clear out their names' definitions
114 at the end of the function. */
116 static GTY(()) tree named_labels;
118 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
120 static GTY(()) tree shadowed_labels;
122 /* Set to 0 at beginning of a function definition, set to 1 if
123 a return statement that specifies a return value is seen. */
125 int current_function_returns_value;
127 /* Set to 0 at beginning of a function definition, set to 1 if
128 a return statement with no argument is seen. */
130 int current_function_returns_null;
132 /* Set to 0 at beginning of a function definition, set to 1 if
133 a call to a noreturn function is seen. */
135 int current_function_returns_abnormally;
137 /* Set to nonzero by `grokdeclarator' for a function
138 whose return type is defaulted, if warnings for this are desired. */
140 static int warn_about_return_type;
142 /* Nonzero when starting a function declared `extern inline'. */
144 static int current_extern_inline;
146 /* For each binding contour we allocate a binding_level structure
147 * which records the names defined in that contour.
150 * 1) one for each function definition,
151 * where internal declarations of the parameters appear.
152 * 2) one for each compound statement,
153 * to record its declarations.
155 * The current meaning of a name can be found by searching the levels from
156 * the current one out to the global one.
159 /* Note that the information in the `names' component of the global contour
160 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
162 struct binding_level GTY(())
164 /* A chain of _DECL nodes for all variables, constants, functions,
165 and typedef types. These are in the reverse of the order supplied.
169 /* A list of structure, union and enum definitions,
170 * for looking up tag names.
171 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
172 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
173 * or ENUMERAL_TYPE node.
177 /* For each level, a list of shadowed outer-level local definitions
178 to be restored when this level is popped.
179 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
180 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
183 /* For each level (except not the global one),
184 a chain of BLOCK nodes for all the levels
185 that were entered and exited one level down. */
188 /* The BLOCK node for this level, if one has been preallocated.
189 If 0, the BLOCK is allocated (if needed) when the level is popped. */
192 /* The binding level which this one is contained in (inherits from). */
193 struct binding_level *level_chain;
195 /* Nonzero for the level that holds the parameters of a function. */
198 /* Nonzero if this level "doesn't exist" for tags. */
199 char tag_transparent;
201 /* Nonzero if sublevels of this level "don't exist" for tags.
202 This is set in the parm level of a function definition
203 while reading the function body, so that the outermost block
204 of the function body will be tag-transparent. */
205 char subblocks_tag_transparent;
207 /* Nonzero means make a BLOCK for this level regardless of all else. */
210 /* Nonzero means make a BLOCK if this level has any subblocks. */
211 char keep_if_subblocks;
213 /* List of decls in `names' that have incomplete structure or
215 tree incomplete_list;
217 /* A list of decls giving the (reversed) specified order of parms,
218 not including any forward-decls in the parmlist.
219 This is so we can put the parms in proper order for assign_parms. */
223 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
225 /* The binding level currently in effect. */
227 static GTY(()) struct binding_level *current_binding_level;
229 /* A chain of binding_level structures awaiting reuse. */
231 static GTY((deletable (""))) struct binding_level *free_binding_level;
233 /* The outermost binding level, for names of file scope.
234 This is created when the compiler is started and exists
235 through the entire run. */
237 static GTY(()) struct binding_level *global_binding_level;
239 /* Binding level structures are initialized by copying this one. */
241 static struct binding_level clear_binding_level
242 = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, NULL,
245 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
247 static int keep_next_level_flag;
249 /* Nonzero means make a BLOCK for the next level pushed
250 if it has subblocks. */
252 static int keep_next_if_subblocks;
254 /* The chain of outer levels of label scopes.
255 This uses the same data structure used for binding levels,
256 but it works differently: each link in the chain records
257 saved values of named_labels and shadowed_labels for
258 a label binding level outside the current one. */
260 static GTY(()) struct binding_level *label_level_chain;
262 /* Functions called automatically at the beginning and end of execution. */
264 tree static_ctors, static_dtors;
266 /* Forward declarations. */
268 static struct binding_level * make_binding_level PARAMS ((void));
269 static void pop_binding_level PARAMS ((struct binding_level **));
270 static void clear_limbo_values PARAMS ((tree));
271 static int duplicate_decls PARAMS ((tree, tree, int));
272 static int redeclaration_error_message PARAMS ((tree, tree));
273 static void storedecls PARAMS ((tree));
274 static void storetags PARAMS ((tree));
275 static tree lookup_tag PARAMS ((enum tree_code, tree,
276 struct binding_level *, int));
277 static tree lookup_tag_reverse PARAMS ((tree));
278 static tree grokdeclarator PARAMS ((tree, tree, enum decl_context,
280 static tree grokparms PARAMS ((tree, int));
281 static void layout_array_type PARAMS ((tree));
282 static tree c_make_fname_decl PARAMS ((tree, int));
283 static void c_expand_body PARAMS ((tree, int, int));
284 static void warn_if_shadowing PARAMS ((tree, tree));
285 static bool flexible_array_type_p PARAMS ((tree));
287 /* States indicating how grokdeclarator() should handle declspecs marked
288 with __attribute__((deprecated)). An object declared as
289 __attribute__((deprecated)) suppresses warnings of uses of other
292 enum deprecated_states {
297 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
300 c_print_identifier (file, node, indent)
305 print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
306 print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
307 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
308 print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
309 print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
310 print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4);
311 if (C_IS_RESERVED_WORD (node))
313 tree rid = ridpointers[C_RID_CODE (node)];
314 indent_to (file, indent + 4);
315 fprintf (file, "rid ");
316 fprintf (file, HOST_PTR_PRINTF, (void *)rid);
317 fprintf (file, " \"%s\"", IDENTIFIER_POINTER (rid));
321 /* Hook called at end of compilation to assume 1 elt
322 for a top-level tentative array defn that wasn't complete before. */
325 c_finish_incomplete_decl (decl)
328 if (TREE_CODE (decl) == VAR_DECL)
330 tree type = TREE_TYPE (decl);
331 if (type != error_mark_node
332 && TREE_CODE (type) == ARRAY_TYPE
333 && ! DECL_EXTERNAL (decl)
334 && TYPE_DOMAIN (type) == 0)
336 warning_with_decl (decl, "array `%s' assumed to have one element");
338 complete_array_type (type, NULL_TREE, 1);
340 layout_decl (decl, 0);
345 /* Reuse or create a struct for this binding level. */
347 static struct binding_level *
348 make_binding_level ()
350 if (free_binding_level)
352 struct binding_level *result = free_binding_level;
353 free_binding_level = result->level_chain;
357 return (struct binding_level *) ggc_alloc (sizeof (struct binding_level));
360 /* Remove a binding level from a list and add it to the level chain. */
363 pop_binding_level (lp)
364 struct binding_level **lp;
366 struct binding_level *l = *lp;
367 *lp = l->level_chain;
369 memset (l, 0, sizeof (struct binding_level));
370 l->level_chain = free_binding_level;
371 free_binding_level = l;
374 /* Nonzero if we are currently in the global binding level. */
379 return current_binding_level == global_binding_level;
385 keep_next_level_flag = 1;
388 /* Nonzero if the current level needs to have a BLOCK made. */
393 return ((current_binding_level->keep_if_subblocks
394 && current_binding_level->blocks != 0)
395 || current_binding_level->keep
396 || current_binding_level->names != 0
397 || (current_binding_level->tags != 0
398 && !current_binding_level->tag_transparent));
401 /* Identify this binding level as a level of parameters.
402 DEFINITION_FLAG is 1 for a definition, 0 for a declaration.
403 But it turns out there is no way to pass the right value for
404 DEFINITION_FLAG, so we ignore it. */
407 declare_parm_level (definition_flag)
408 int definition_flag ATTRIBUTE_UNUSED;
410 current_binding_level->parm_flag = 1;
413 /* Nonzero if currently making parm declarations. */
418 return current_binding_level->parm_flag;
421 /* Enter a new binding level.
422 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
423 not for that of tags. */
426 pushlevel (tag_transparent)
429 struct binding_level *newlevel = NULL_BINDING_LEVEL;
431 /* If this is the top level of a function,
432 just make sure that NAMED_LABELS is 0. */
434 if (current_binding_level == global_binding_level)
439 newlevel = make_binding_level ();
441 /* Add this level to the front of the chain (stack) of levels that
444 *newlevel = clear_binding_level;
445 newlevel->tag_transparent
447 || (current_binding_level
448 ? current_binding_level->subblocks_tag_transparent
450 newlevel->level_chain = current_binding_level;
451 current_binding_level = newlevel;
452 newlevel->keep = keep_next_level_flag;
453 keep_next_level_flag = 0;
454 newlevel->keep_if_subblocks = keep_next_if_subblocks;
455 keep_next_if_subblocks = 0;
458 /* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */
461 clear_limbo_values (block)
466 for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem))
467 if (DECL_NAME (tem) != 0)
468 IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0;
470 for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem))
471 clear_limbo_values (tem);
474 /* Exit a binding level.
475 Pop the level off, and restore the state of the identifier-decl mappings
476 that were in effect when this level was entered.
478 If KEEP is nonzero, this level had explicit declarations, so
479 and create a "block" (a BLOCK node) for the level
480 to record its declarations and subblocks for symbol table output.
482 If FUNCTIONBODY is nonzero, this level is the body of a function,
483 so create a block as if KEEP were set and also clear out all
486 If REVERSE is nonzero, reverse the order of decls before putting
487 them into the BLOCK. */
490 poplevel (keep, reverse, functionbody)
496 /* The chain of decls was accumulated in reverse order.
497 Put it into forward order, just for cleanliness. */
499 tree tags = current_binding_level->tags;
500 tree subblocks = current_binding_level->blocks;
503 int block_previously_created;
505 keep |= current_binding_level->keep;
507 /* This warning is turned off because it causes warnings for
508 declarations like `extern struct foo *x'. */
510 /* Warn about incomplete structure types in this level. */
511 for (link = tags; link; link = TREE_CHAIN (link))
512 if (!COMPLETE_TYPE_P (TREE_VALUE (link)))
514 tree type = TREE_VALUE (link);
515 tree type_name = TYPE_NAME (type);
516 char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE
518 : DECL_NAME (type_name));
519 switch (TREE_CODE (type))
522 error ("`struct %s' incomplete in scope ending here", id);
525 error ("`union %s' incomplete in scope ending here", id);
528 error ("`enum %s' incomplete in scope ending here", id);
534 /* Get the decls in the order they were written.
535 Usually current_binding_level->names is in reverse order.
536 But parameter decls were previously put in forward order. */
539 current_binding_level->names
540 = decls = nreverse (current_binding_level->names);
542 decls = current_binding_level->names;
544 /* Output any nested inline functions within this block
545 if they weren't already output. */
547 for (decl = decls; decl; decl = TREE_CHAIN (decl))
548 if (TREE_CODE (decl) == FUNCTION_DECL
549 && ! TREE_ASM_WRITTEN (decl)
550 && DECL_INITIAL (decl) != 0
551 && TREE_ADDRESSABLE (decl))
553 /* If this decl was copied from a file-scope decl
554 on account of a block-scope extern decl,
555 propagate TREE_ADDRESSABLE to the file-scope decl.
557 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
558 true, since then the decl goes through save_for_inline_copying. */
559 if (DECL_ABSTRACT_ORIGIN (decl) != 0
560 && DECL_ABSTRACT_ORIGIN (decl) != decl)
561 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
564 /* We used to warn about unused variables in expand_end_bindings,
565 i.e. while generating RTL. But in function-at-a-time mode we may
566 choose to never expand a function at all (e.g. auto inlining), so
567 we do this explicitly now. */
568 warn_about_unused_variables (getdecls ());
570 /* If there were any declarations or structure tags in that level,
571 or if this level is a function body,
572 create a BLOCK to record them for the life of this function. */
575 block_previously_created = (current_binding_level->this_block != 0);
576 if (block_previously_created)
577 block = current_binding_level->this_block;
578 else if (keep || functionbody
579 || (current_binding_level->keep_if_subblocks && subblocks != 0))
580 block = make_node (BLOCK);
583 BLOCK_VARS (block) = decls;
584 BLOCK_SUBBLOCKS (block) = subblocks;
587 /* In each subblock, record that this is its superior. */
589 for (link = subblocks; link; link = TREE_CHAIN (link))
590 BLOCK_SUPERCONTEXT (link) = block;
592 /* Clear out the meanings of the local variables of this level. */
594 for (link = decls; link; link = TREE_CHAIN (link))
596 if (DECL_NAME (link) != 0)
598 /* If the ident. was used or addressed via a local extern decl,
599 don't forget that fact. */
600 if (DECL_EXTERNAL (link))
602 if (TREE_USED (link))
603 TREE_USED (DECL_NAME (link)) = 1;
604 if (TREE_ADDRESSABLE (link))
605 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
607 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
611 /* Restore all name-meanings of the outer levels
612 that were shadowed by this level. */
614 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
615 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
617 /* If the level being exited is the top level of a function,
618 check over all the labels, and clear out the current
619 (function local) meanings of their names. */
623 clear_limbo_values (block);
625 /* If this is the top level block of a function,
626 the vars are the function's parameters.
627 Don't leave them in the BLOCK because they are
628 found in the FUNCTION_DECL instead. */
630 BLOCK_VARS (block) = 0;
632 /* Clear out the definitions of all label names,
633 since their scopes end here,
634 and add them to BLOCK_VARS. */
636 for (link = named_labels; link; link = TREE_CHAIN (link))
638 tree label = TREE_VALUE (link);
640 if (DECL_INITIAL (label) == 0)
642 error_with_decl (label, "label `%s' used but not defined");
643 /* Avoid crashing later. */
644 define_label (input_filename, lineno,
647 else if (warn_unused_label && !TREE_USED (label))
648 warning_with_decl (label, "label `%s' defined but not used");
649 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
651 /* Put the labels into the "variables" of the
652 top-level block, so debugger can see them. */
653 TREE_CHAIN (label) = BLOCK_VARS (block);
654 BLOCK_VARS (block) = label;
658 /* Pop the current level, and free the structure for reuse. */
660 pop_binding_level (¤t_binding_level);
662 /* Dispose of the block that we just made inside some higher level. */
664 DECL_INITIAL (current_function_decl) = block;
667 if (!block_previously_created)
668 current_binding_level->blocks
669 = chainon (current_binding_level->blocks, block);
671 /* If we did not make a block for the level just exited,
672 any blocks made for inner levels
673 (since they cannot be recorded as subblocks in that level)
674 must be carried forward so they will later become subblocks
675 of something else. */
677 current_binding_level->blocks
678 = chainon (current_binding_level->blocks, subblocks);
680 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
681 binding contour so that they point to the appropriate construct, i.e.
682 either to the current FUNCTION_DECL node, or else to the BLOCK node
685 Note that for tagged types whose scope is just the formal parameter
686 list for some function type specification, we can't properly set
687 their TYPE_CONTEXTs here, because we don't have a pointer to the
688 appropriate FUNCTION_TYPE node readily available to us. For those
689 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
690 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
691 node which will represent the "scope" for these "parameter list local"
695 for (link = tags; link; link = TREE_CHAIN (link))
696 TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl;
698 for (link = tags; link; link = TREE_CHAIN (link))
699 TYPE_CONTEXT (TREE_VALUE (link)) = block;
702 TREE_USED (block) = 1;
707 /* Insert BLOCK at the end of the list of subblocks of the
708 current binding level. This is used when a BIND_EXPR is expanded,
709 to handle the BLOCK node inside the BIND_EXPR. */
715 TREE_USED (block) = 1;
716 current_binding_level->blocks
717 = chainon (current_binding_level->blocks, block);
720 /* Set the BLOCK node for the innermost scope
721 (the one we are currently in). */
727 current_binding_level->this_block = block;
728 current_binding_level->names = chainon (current_binding_level->names,
730 current_binding_level->blocks = chainon (current_binding_level->blocks,
731 BLOCK_SUBBLOCKS (block));
737 struct binding_level *newlevel;
739 newlevel = make_binding_level ();
741 /* Add this level to the front of the chain (stack) of label levels. */
743 newlevel->level_chain = label_level_chain;
744 label_level_chain = newlevel;
746 newlevel->names = named_labels;
747 newlevel->shadowed = shadowed_labels;
755 struct binding_level *level = label_level_chain;
758 /* Clear out the definitions of the declared labels in this level.
759 Leave in the list any ordinary, non-declared labels. */
760 for (link = named_labels, prev = 0; link;)
762 if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
764 if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
766 error_with_decl (TREE_VALUE (link),
767 "label `%s' used but not defined");
768 /* Avoid crashing later. */
769 define_label (input_filename, lineno,
770 DECL_NAME (TREE_VALUE (link)));
772 else if (warn_unused_label && !TREE_USED (TREE_VALUE (link)))
773 warning_with_decl (TREE_VALUE (link),
774 "label `%s' defined but not used");
775 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
777 /* Delete this element from the list. */
778 link = TREE_CHAIN (link);
780 TREE_CHAIN (prev) = link;
787 link = TREE_CHAIN (link);
791 /* Bring back all the labels that were shadowed. */
792 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
793 if (DECL_NAME (TREE_VALUE (link)) != 0)
794 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
797 named_labels = chainon (named_labels, level->names);
798 shadowed_labels = level->shadowed;
800 /* Pop the current level, and free the structure for reuse. */
801 pop_binding_level (&label_level_chain);
804 /* Push a definition or a declaration of struct, union or enum tag "name".
805 "type" should be the type node.
806 We assume that the tag "name" is not already defined.
808 Note that the definition may really be just a forward reference.
809 In that case, the TYPE_SIZE will be zero. */
815 struct binding_level *b;
817 /* Find the proper binding level for this type tag. */
819 for (b = current_binding_level; b->tag_transparent; b = b->level_chain)
824 /* Record the identifier as the type's name if it has none. */
826 if (TYPE_NAME (type) == 0)
827 TYPE_NAME (type) = name;
830 b->tags = tree_cons (name, type, b->tags);
832 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
833 tagged type we just added to the current binding level. This fake
834 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
835 to output a representation of a tagged type, and it also gives
836 us a convenient place to record the "scope start" address for the
839 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
841 /* An approximation for now, so we can tell this is a function-scope tag.
842 This will be updated in poplevel. */
843 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
846 /* Handle when a new declaration NEWDECL
847 has the same name as an old one OLDDECL
848 in the same binding contour.
849 Prints an error message if appropriate.
851 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
854 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration,
855 and OLDDECL is in an outer binding level and should thus not be changed. */
858 duplicate_decls (newdecl, olddecl, different_binding_level)
859 tree newdecl, olddecl;
860 int different_binding_level;
862 int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
863 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
864 && DECL_INITIAL (newdecl) != 0);
865 tree oldtype = TREE_TYPE (olddecl);
866 tree newtype = TREE_TYPE (newdecl);
869 if (DECL_P (olddecl))
871 if (TREE_CODE (newdecl) == FUNCTION_DECL
872 && TREE_CODE (olddecl) == FUNCTION_DECL
873 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
875 if (DECL_DECLARED_INLINE_P (newdecl)
876 && DECL_UNINLINABLE (newdecl)
877 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
878 /* Already warned elsewhere. */;
879 else if (DECL_DECLARED_INLINE_P (olddecl)
880 && DECL_UNINLINABLE (olddecl)
881 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
882 /* Already warned. */;
883 else if (DECL_DECLARED_INLINE_P (newdecl)
884 && ! DECL_DECLARED_INLINE_P (olddecl)
885 && DECL_UNINLINABLE (olddecl)
886 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
888 warning_with_decl (newdecl,
889 "function `%s' redeclared as inline");
890 warning_with_decl (olddecl,
891 "previous declaration of function `%s' with attribute noinline");
893 else if (DECL_DECLARED_INLINE_P (olddecl)
894 && DECL_UNINLINABLE (newdecl)
895 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
897 warning_with_decl (newdecl,
898 "function `%s' redeclared with attribute noinline");
899 warning_with_decl (olddecl,
900 "previous declaration of function `%s' was inline");
904 DECL_ATTRIBUTES (newdecl)
905 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
908 if (TREE_CODE (newtype) == ERROR_MARK
909 || TREE_CODE (oldtype) == ERROR_MARK)
912 /* New decl is completely inconsistent with the old one =>
913 tell caller to replace the old one.
914 This is always an error except in the case of shadowing a builtin. */
915 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
917 if (TREE_CODE (olddecl) == FUNCTION_DECL
918 && (DECL_BUILT_IN (olddecl)
919 || DECL_BUILT_IN_NONANSI (olddecl)))
921 /* If you declare a built-in or predefined function name as static,
922 the old definition is overridden,
923 but optionally warn this was a bad choice of name. */
924 if (!TREE_PUBLIC (newdecl))
928 else if (DECL_BUILT_IN (olddecl))
929 warning_with_decl (newdecl, "shadowing built-in function `%s'");
931 warning_with_decl (newdecl, "shadowing library function `%s'");
933 /* Likewise, if the built-in is not ansi, then programs can
934 override it even globally without an error. */
935 else if (! DECL_BUILT_IN (olddecl))
936 warning_with_decl (newdecl,
937 "library function `%s' declared as non-function");
939 else if (DECL_BUILT_IN_NONANSI (olddecl))
940 warning_with_decl (newdecl,
941 "built-in function `%s' declared as non-function");
943 warning_with_decl (newdecl,
944 "built-in function `%s' declared as non-function");
948 error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
949 error_with_decl (olddecl, "previous declaration of `%s'");
955 /* For real parm decl following a forward decl,
956 return 1 so old decl will be reused. */
957 if (types_match && TREE_CODE (newdecl) == PARM_DECL
958 && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
961 /* The new declaration is the same kind of object as the old one.
962 The declarations may partially match. Print warnings if they don't
963 match enough. Ultimately, copy most of the information from the new
964 decl to the old one, and keep using the old one. */
966 if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_BUILT_IN (olddecl))
968 /* A function declaration for a built-in function. */
969 if (!TREE_PUBLIC (newdecl))
971 /* If you declare a built-in function name as static, the
972 built-in definition is overridden,
973 but optionally warn this was a bad choice of name. */
975 warning_with_decl (newdecl, "shadowing built-in function `%s'");
976 /* Discard the old built-in function. */
979 else if (!types_match)
981 /* Accept the return type of the new declaration if same modes. */
982 tree oldreturntype = TREE_TYPE (oldtype);
983 tree newreturntype = TREE_TYPE (newtype);
985 if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
987 /* Function types may be shared, so we can't just modify
988 the return type of olddecl's function type. */
990 = build_function_type (newreturntype,
991 TYPE_ARG_TYPES (oldtype));
992 trytype = build_type_attribute_variant (trytype,
993 TYPE_ATTRIBUTES (oldtype));
995 types_match = comptypes (newtype, trytype);
999 /* Accept harmless mismatch in first argument type also.
1000 This is for the ffs and fprintf builtins. */
1001 if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0
1002 && TYPE_ARG_TYPES (oldtype) != 0
1003 && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0
1004 && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0
1005 && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype)))
1006 == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype)))))
1008 /* Function types may be shared, so we can't just modify
1009 the return type of olddecl's function type. */
1011 = build_function_type (TREE_TYPE (oldtype),
1012 tree_cons (NULL_TREE,
1013 TREE_VALUE (TYPE_ARG_TYPES (newtype)),
1014 TREE_CHAIN (TYPE_ARG_TYPES (oldtype))));
1015 trytype = build_type_attribute_variant (trytype,
1016 TYPE_ATTRIBUTES (oldtype));
1018 types_match = comptypes (newtype, trytype);
1022 if (! different_binding_level)
1023 TREE_TYPE (olddecl) = oldtype;
1025 else if (TYPE_ARG_TYPES (oldtype) == NULL
1026 && TYPE_ARG_TYPES (newtype) != NULL)
1028 /* For bcmp, bzero, fputs the builtin type has arguments not
1029 specified. Use the ones from the prototype so that type checking
1030 is done for them. */
1032 = build_function_type (TREE_TYPE (oldtype),
1033 TYPE_ARG_TYPES (newtype));
1034 trytype = build_type_attribute_variant (trytype,
1035 TYPE_ATTRIBUTES (oldtype));
1038 if (! different_binding_level)
1039 TREE_TYPE (olddecl) = oldtype;
1043 /* If types don't match for a built-in, throw away the built-in. */
1044 warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
1048 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1049 && DECL_SOURCE_LINE (olddecl) == 0)
1051 /* A function declaration for a predeclared function
1052 that isn't actually built in. */
1053 if (!TREE_PUBLIC (newdecl))
1055 /* If you declare it as static, the
1056 default definition is overridden. */
1059 else if (!types_match)
1061 /* If the types don't match, preserve volatility indication.
1062 Later on, we will discard everything else about the
1063 default declaration. */
1064 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1067 /* Permit char *foo () to match void *foo (...) if not pedantic,
1068 if one of them came from a system header file. */
1069 else if (!types_match
1070 && TREE_CODE (olddecl) == FUNCTION_DECL
1071 && TREE_CODE (newdecl) == FUNCTION_DECL
1072 && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
1073 && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
1074 && (DECL_IN_SYSTEM_HEADER (olddecl)
1075 || DECL_IN_SYSTEM_HEADER (newdecl))
1076 && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
1077 && TYPE_ARG_TYPES (oldtype) == 0
1078 && self_promoting_args_p (TYPE_ARG_TYPES (newtype))
1079 && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
1081 (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
1082 && TYPE_ARG_TYPES (newtype) == 0
1083 && self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
1084 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
1087 pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1088 /* Make sure we keep void * as ret type, not char *. */
1089 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
1090 TREE_TYPE (newdecl) = newtype = oldtype;
1092 /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration
1093 we will come back here again. */
1094 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1096 else if (!types_match
1097 /* Permit char *foo (int, ...); followed by char *foo ();
1099 && ! (TREE_CODE (olddecl) == FUNCTION_DECL
1101 /* Return types must still match. */
1102 && comptypes (TREE_TYPE (oldtype),
1103 TREE_TYPE (newtype))
1104 && TYPE_ARG_TYPES (newtype) == 0))
1106 error_with_decl (newdecl, "conflicting types for `%s'");
1107 /* Check for function type mismatch
1108 involving an empty arglist vs a nonempty one. */
1109 if (TREE_CODE (olddecl) == FUNCTION_DECL
1110 && comptypes (TREE_TYPE (oldtype),
1111 TREE_TYPE (newtype))
1112 && ((TYPE_ARG_TYPES (oldtype) == 0
1113 && DECL_INITIAL (olddecl) == 0)
1115 (TYPE_ARG_TYPES (newtype) == 0
1116 && DECL_INITIAL (newdecl) == 0)))
1118 /* Classify the problem further. */
1119 tree t = TYPE_ARG_TYPES (oldtype);
1121 t = TYPE_ARG_TYPES (newtype);
1122 for (; t; t = TREE_CHAIN (t))
1124 tree type = TREE_VALUE (t);
1126 if (TREE_CHAIN (t) == 0
1127 && TYPE_MAIN_VARIANT (type) != void_type_node)
1129 error ("a parameter list with an ellipsis can't match an empty parameter name list declaration");
1133 if (c_type_promotes_to (type) != type)
1135 error ("an argument type that has a default promotion can't match an empty parameter name list declaration");
1140 error_with_decl (olddecl, "previous declaration of `%s'");
1142 /* TLS cannot follow non-TLS declaration. */
1143 else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
1144 && !DECL_THREAD_LOCAL (olddecl) && DECL_THREAD_LOCAL (newdecl))
1146 error_with_decl (newdecl, "thread-local declaration of `%s' follows non thread-local declaration");
1147 error_with_decl (olddecl, "previous declaration of `%s'");
1149 /* non-TLS declaration cannot follow TLS declaration. */
1150 else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
1151 && DECL_THREAD_LOCAL (olddecl) && !DECL_THREAD_LOCAL (newdecl))
1153 error_with_decl (newdecl, "non thread-local declaration of `%s' follows thread-local declaration");
1154 error_with_decl (olddecl, "previous declaration of `%s'");
1158 errmsg = redeclaration_error_message (newdecl, olddecl);
1164 error_with_decl (newdecl, "redefinition of `%s'");
1167 error_with_decl (newdecl, "redeclaration of `%s'");
1170 error_with_decl (newdecl, "conflicting declarations of `%s'");
1176 error_with_decl (olddecl,
1177 ((DECL_INITIAL (olddecl)
1178 && current_binding_level == global_binding_level)
1179 ? "`%s' previously defined here"
1180 : "`%s' previously declared here"));
1183 else if (TREE_CODE (newdecl) == TYPE_DECL
1184 && (DECL_IN_SYSTEM_HEADER (olddecl)
1185 || DECL_IN_SYSTEM_HEADER (newdecl)))
1187 warning_with_decl (newdecl, "redefinition of `%s'");
1190 ((DECL_INITIAL (olddecl)
1191 && current_binding_level == global_binding_level)
1192 ? "`%s' previously defined here"
1193 : "`%s' previously declared here"));
1195 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1196 && DECL_INITIAL (olddecl) != 0
1197 && TYPE_ARG_TYPES (oldtype) == 0
1198 && TYPE_ARG_TYPES (newtype) != 0
1199 && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0)
1203 /* Prototype decl follows defn w/o prototype. */
1205 for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
1206 type = TYPE_ARG_TYPES (newtype),
1209 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
1211 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1212 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1214 warning_with_decl (newdecl, "prototype for `%s' follows");
1215 warning_with_decl (olddecl, "non-prototype definition here");
1218 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1219 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1221 error_with_decl (newdecl,
1222 "prototype for `%s' follows and number of arguments doesn't match");
1223 error_with_decl (olddecl, "non-prototype definition here");
1227 /* Type for passing arg must be consistent
1228 with that declared for the arg. */
1229 if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type)))
1231 error_with_decl (newdecl,
1232 "prototype for `%s' follows and argument %d doesn't match",
1234 error_with_decl (olddecl, "non-prototype definition here");
1240 /* Warn about mismatches in various flags. */
1243 /* Warn if function is now inline
1244 but was previously declared not inline and has been called. */
1245 if (TREE_CODE (olddecl) == FUNCTION_DECL
1246 && ! DECL_DECLARED_INLINE_P (olddecl)
1247 && DECL_DECLARED_INLINE_P (newdecl)
1248 && TREE_USED (olddecl))
1249 warning_with_decl (newdecl,
1250 "`%s' declared inline after being called");
1251 if (TREE_CODE (olddecl) == FUNCTION_DECL
1252 && ! DECL_DECLARED_INLINE_P (olddecl)
1253 && DECL_DECLARED_INLINE_P (newdecl)
1254 && DECL_INITIAL (olddecl) != 0)
1255 warning_with_decl (newdecl,
1256 "`%s' declared inline after its definition");
1258 /* If pedantic, warn when static declaration follows a non-static
1259 declaration. Otherwise, do so only for functions. */
1260 if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL)
1261 && TREE_PUBLIC (olddecl)
1262 && !TREE_PUBLIC (newdecl))
1263 warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
1265 /* If warn_traditional, warn when a non-static function
1266 declaration follows a static one. */
1267 if (warn_traditional && !in_system_header
1268 && TREE_CODE (olddecl) == FUNCTION_DECL
1269 && !TREE_PUBLIC (olddecl)
1270 && TREE_PUBLIC (newdecl))
1271 warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
1273 /* Warn when const declaration follows a non-const
1274 declaration, but not for functions. */
1275 if (TREE_CODE (olddecl) != FUNCTION_DECL
1276 && !TREE_READONLY (olddecl)
1277 && TREE_READONLY (newdecl))
1278 warning_with_decl (newdecl, "const declaration for `%s' follows non-const");
1279 /* These bits are logically part of the type, for variables.
1280 But not for functions
1281 (where qualifiers are not valid ANSI anyway). */
1282 else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
1283 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1284 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1285 pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1289 /* Optionally warn about more than one declaration for the same name. */
1290 if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
1291 /* Don't warn about a function declaration
1292 followed by a definition. */
1293 && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
1294 && DECL_INITIAL (olddecl) == 0)
1295 /* Don't warn about extern decl followed by (tentative) definition. */
1296 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
1298 warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
1299 warning_with_decl (olddecl, "previous declaration of `%s'");
1302 /* Copy all the DECL_... slots specified in the new decl
1303 except for any that we copy here from the old type.
1305 Past this point, we don't change OLDTYPE and NEWTYPE
1306 even if we change the types of NEWDECL and OLDDECL. */
1310 /* When copying info to olddecl, we store into write_olddecl
1311 instead. This allows us to avoid modifying olddecl when
1312 different_binding_level is true. */
1313 tree write_olddecl = different_binding_level ? newdecl : olddecl;
1315 /* Merge the data types specified in the two decls. */
1316 if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
1318 if (different_binding_level)
1320 if (TYPE_ARG_TYPES (oldtype) != 0
1321 && TYPE_ARG_TYPES (newtype) == 0)
1322 TREE_TYPE (newdecl) = common_type (newtype, oldtype);
1325 = build_type_attribute_variant
1327 merge_attributes (TYPE_ATTRIBUTES (newtype),
1328 TYPE_ATTRIBUTES (oldtype)));
1332 = TREE_TYPE (olddecl)
1333 = common_type (newtype, oldtype);
1336 /* Lay the type out, unless already done. */
1337 if (oldtype != TREE_TYPE (newdecl))
1339 if (TREE_TYPE (newdecl) != error_mark_node)
1340 layout_type (TREE_TYPE (newdecl));
1341 if (TREE_CODE (newdecl) != FUNCTION_DECL
1342 && TREE_CODE (newdecl) != TYPE_DECL
1343 && TREE_CODE (newdecl) != CONST_DECL)
1344 layout_decl (newdecl, 0);
1348 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1349 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1350 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
1351 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1352 if (TREE_CODE (olddecl) != FUNCTION_DECL)
1353 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1355 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1356 DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl);
1360 /* Keep the old rtl since we can safely use it. */
1361 COPY_DECL_RTL (olddecl, newdecl);
1363 /* Merge the type qualifiers. */
1364 if (TREE_READONLY (newdecl))
1365 TREE_READONLY (write_olddecl) = 1;
1367 if (TREE_THIS_VOLATILE (newdecl))
1369 TREE_THIS_VOLATILE (write_olddecl) = 1;
1370 if (TREE_CODE (newdecl) == VAR_DECL
1371 /* If an automatic variable is re-declared in the same
1372 function scope, but the old declaration was not
1373 volatile, make_var_volatile() would crash because the
1374 variable would have been assigned to a pseudo, not a
1375 MEM. Since this duplicate declaration is invalid
1376 anyway, we just skip the call. */
1378 make_var_volatile (newdecl);
1381 /* Keep source location of definition rather than declaration. */
1382 /* When called with different_binding_level set, keep the old
1383 information so that meaningful diagnostics can be given. */
1384 if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
1385 && ! different_binding_level)
1387 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
1388 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
1391 /* Merge the unused-warning information. */
1392 if (DECL_IN_SYSTEM_HEADER (olddecl))
1393 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1394 else if (DECL_IN_SYSTEM_HEADER (newdecl))
1395 DECL_IN_SYSTEM_HEADER (write_olddecl) = 1;
1397 /* Merge the initialization information. */
1398 /* When called with different_binding_level set, don't copy over
1399 DECL_INITIAL, so that we don't accidentally change function
1400 declarations into function definitions. */
1401 if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
1402 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1404 /* Merge the section attribute.
1405 We want to issue an error if the sections conflict but that must be
1406 done later in decl_attributes since we are called before attributes
1408 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1409 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1411 /* Copy the assembler name.
1412 Currently, it can only be defined in the prototype. */
1413 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
1415 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1417 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1418 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1419 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1420 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1421 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1424 /* If cannot merge, then use the new type and qualifiers,
1425 and don't preserve the old rtl. */
1426 else if (! different_binding_level)
1428 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1429 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1430 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1431 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1434 /* Merge the storage class information. */
1435 merge_weak (newdecl, olddecl);
1437 /* For functions, static overrides non-static. */
1438 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1440 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1441 /* This is since we don't automatically
1442 copy the attributes of NEWDECL into OLDDECL. */
1443 /* No need to worry about different_binding_level here because
1444 then TREE_PUBLIC (newdecl) was true. */
1445 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1446 /* If this clears `static', clear it in the identifier too. */
1447 if (! TREE_PUBLIC (olddecl))
1448 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1450 if (DECL_EXTERNAL (newdecl))
1452 if (! different_binding_level)
1454 /* Don't mess with these flags on local externs; they remain
1455 external even if there's a declaration at file scope which
1457 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
1458 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1460 /* An extern decl does not override previous storage class. */
1461 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1462 if (! DECL_EXTERNAL (newdecl))
1463 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1467 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1468 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1471 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1473 /* If we're redefining a function previously defined as extern
1474 inline, make sure we emit debug info for the inline before we
1475 throw it away, in case it was inlined into a function that hasn't
1476 been written out yet. */
1477 if (new_is_definition && DECL_INITIAL (olddecl))
1479 if (TREE_USED (olddecl))
1480 (*debug_hooks->outlining_inline_function) (olddecl);
1482 /* The new defn must not be inline. */
1483 DECL_INLINE (newdecl) = 0;
1484 DECL_UNINLINABLE (newdecl) = 1;
1488 /* If either decl says `inline', this fn is inline,
1489 unless its definition was passed already. */
1490 if (DECL_DECLARED_INLINE_P (newdecl)
1491 || DECL_DECLARED_INLINE_P (olddecl))
1492 DECL_DECLARED_INLINE_P (newdecl) = 1;
1494 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1495 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1498 if (DECL_BUILT_IN (olddecl))
1500 /* Get rid of any built-in function if new arg types don't match it
1501 or if we have a function definition. */
1502 if (! types_match || new_is_definition)
1504 if (! different_binding_level)
1506 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1507 DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN;
1512 /* If redeclaring a builtin function, and not a definition,
1513 it stays built in. */
1514 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1515 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1519 /* Also preserve various other info from the definition. */
1520 if (! new_is_definition)
1522 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1523 /* When called with different_binding_level set, don't copy over
1524 DECL_INITIAL, so that we don't accidentally change function
1525 declarations into function definitions. */
1526 if (! different_binding_level)
1527 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1528 DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
1529 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1530 DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl);
1531 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
1533 /* Set DECL_INLINE on the declaration if we've got a body
1534 from which to instantiate. */
1535 if (DECL_INLINE (olddecl) && ! DECL_UNINLINABLE (newdecl))
1537 DECL_INLINE (newdecl) = 1;
1538 DECL_ABSTRACT_ORIGIN (newdecl)
1539 = (different_binding_level
1540 ? DECL_ORIGIN (olddecl)
1541 : DECL_ABSTRACT_ORIGIN (olddecl));
1546 /* If a previous declaration said inline, mark the
1547 definition as inlinable. */
1548 if (DECL_DECLARED_INLINE_P (newdecl)
1549 && ! DECL_UNINLINABLE (newdecl))
1550 DECL_INLINE (newdecl) = 1;
1553 if (different_binding_level)
1556 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1557 But preserve OLDDECL's DECL_UID. */
1559 unsigned olddecl_uid = DECL_UID (olddecl);
1561 memcpy ((char *) olddecl + sizeof (struct tree_common),
1562 (char *) newdecl + sizeof (struct tree_common),
1563 sizeof (struct tree_decl) - sizeof (struct tree_common));
1564 DECL_UID (olddecl) = olddecl_uid;
1567 /* NEWDECL contains the merged attribute lists.
1568 Update OLDDECL to be the same. */
1569 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
1574 /* Check whether decl-node X shadows an existing declaration.
1575 OLDLOCAL is the old IDENTIFIER_LOCAL_VALUE of the DECL_NAME of X,
1576 which might be a NULL_TREE. */
1578 warn_if_shadowing (x, oldlocal)
1583 if (DECL_EXTERNAL (x))
1586 name = DECL_NAME (x);
1588 /* Warn if shadowing an argument at the top level of the body. */
1590 /* This warning doesn't apply to the parms of a nested fcn. */
1591 && ! current_binding_level->parm_flag
1592 /* Check that this is one level down from the parms. */
1593 && current_binding_level->level_chain->parm_flag
1594 /* Check that the decl being shadowed
1595 comes from the parm level, one level up. */
1596 && chain_member (oldlocal, current_binding_level->level_chain->names))
1598 if (TREE_CODE (oldlocal) == PARM_DECL)
1599 pedwarn ("declaration of `%s' shadows a parameter",
1600 IDENTIFIER_POINTER (name));
1602 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1603 IDENTIFIER_POINTER (name));
1605 /* Maybe warn if shadowing something else. */
1606 else if (warn_shadow
1607 /* No shadow warnings for internally generated vars. */
1608 && DECL_SOURCE_LINE (x) != 0
1609 /* No shadow warnings for vars made for inlining. */
1610 && ! DECL_FROM_INLINE (x))
1612 if (TREE_CODE (x) == PARM_DECL
1613 && current_binding_level->level_chain->parm_flag)
1614 /* Don't warn about the parm names in function declarator
1615 within a function declarator.
1616 It would be nice to avoid warning in any function
1617 declarator in a declaration, as opposed to a definition,
1618 but there is no way to tell it's not a definition. */
1622 if (TREE_CODE (oldlocal) == PARM_DECL)
1623 shadow_warning ("a parameter", name, oldlocal);
1625 shadow_warning ("a previous local", name, oldlocal);
1627 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1628 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1629 shadow_warning ("a global declaration", name,
1630 IDENTIFIER_GLOBAL_VALUE (name));
1634 /* Record a decl-node X as belonging to the current lexical scope.
1635 Check for errors (such as an incompatible declaration for the same
1636 name already seen in the same scope).
1638 Returns either X or an old decl for the same name.
1639 If an old decl is returned, it may have been smashed
1640 to agree with what X says. */
1647 tree name = DECL_NAME (x);
1648 struct binding_level *b = current_binding_level;
1650 /* Functions need the lang_decl data. */
1651 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x))
1652 DECL_LANG_SPECIFIC (x) = (struct lang_decl *)
1653 ggc_alloc_cleared (sizeof (struct lang_decl));
1655 DECL_CONTEXT (x) = current_function_decl;
1656 /* A local extern declaration for a function doesn't constitute nesting.
1657 A local auto declaration does, since it's a forward decl
1658 for a nested function coming later. */
1659 if ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
1660 && DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x))
1661 DECL_CONTEXT (x) = 0;
1665 int different_binding_level = 0;
1667 if (warn_nested_externs
1668 && DECL_EXTERNAL (x)
1669 && b != global_binding_level
1670 && x != IDENTIFIER_IMPLICIT_DECL (name)
1671 /* No error messages for __FUNCTION__ and __PRETTY_FUNCTION__. */
1672 && !DECL_IN_SYSTEM_HEADER (x))
1673 warning ("nested extern declaration of `%s'",
1674 IDENTIFIER_POINTER (name));
1676 t = lookup_name_current_level (name);
1677 if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
1679 t = IDENTIFIER_GLOBAL_VALUE (name);
1680 /* Type decls at global scope don't conflict with externs declared
1681 inside lexical blocks. */
1682 if (! t || TREE_CODE (t) == TYPE_DECL)
1683 /* If there's no visible global declaration, try for an
1685 t = IDENTIFIER_LIMBO_VALUE (name);
1686 different_binding_level = 1;
1688 if (t != 0 && t == error_mark_node)
1689 /* error_mark_node is 0 for a while during initialization! */
1692 error_with_decl (x, "`%s' used prior to declaration");
1695 /* If this decl is `static' and an implicit decl was seen previously,
1697 if (TREE_PUBLIC (name)
1698 /* Don't test for DECL_EXTERNAL, because grokdeclarator
1699 sets this for all functions. */
1700 && ! TREE_PUBLIC (x)
1701 && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level)
1702 /* We used to warn also for explicit extern followed by static,
1703 but sometimes you need to do it that way. */
1704 && IDENTIFIER_IMPLICIT_DECL (name) != 0)
1706 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
1707 IDENTIFIER_POINTER (name));
1708 pedwarn_with_file_and_line
1709 (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)),
1710 DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)),
1711 "previous declaration of `%s'",
1712 IDENTIFIER_POINTER (name));
1713 TREE_THIS_VOLATILE (name) = 1;
1716 if (t != 0 && duplicate_decls (x, t, different_binding_level))
1718 if (TREE_CODE (t) == PARM_DECL)
1720 /* Don't allow more than one "real" duplicate
1721 of a forward parm decl. */
1722 TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x);
1728 /* If we are processing a typedef statement, generate a whole new
1729 ..._TYPE node (which will be just a variant of the existing
1730 ..._TYPE node with identical properties) and then install the
1731 TYPE_DECL node generated to represent the typedef name as the
1732 TYPE_NAME of this brand new (duplicate) ..._TYPE node.
1734 The whole point here is to end up with a situation where each
1735 and every ..._TYPE node the compiler creates will be uniquely
1736 associated with AT MOST one node representing a typedef name.
1737 This way, even though the compiler substitutes corresponding
1738 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
1739 early on, later parts of the compiler can always do the reverse
1740 translation and get back the corresponding typedef name. For
1743 typedef struct S MY_TYPE;
1746 Later parts of the compiler might only know that `object' was of
1747 type `struct S' if it were not for code just below. With this
1748 code however, later parts of the compiler see something like:
1750 struct S' == struct S
1751 typedef struct S' MY_TYPE;
1754 And they can then deduce (from the node for type struct S') that
1755 the original object declaration was:
1759 Being able to do this is important for proper support of protoize,
1760 and also for generating precise symbolic debugging information
1761 which takes full account of the programmer's (typedef) vocabulary.
1763 Obviously, we don't want to generate a duplicate ..._TYPE node if
1764 the TYPE_DECL node that we are now processing really represents a
1765 standard built-in type.
1767 Since all standard types are effectively declared at line zero
1768 in the source file, we can easily check to see if we are working
1769 on a standard type by checking the current value of lineno. */
1771 if (TREE_CODE (x) == TYPE_DECL)
1773 if (DECL_SOURCE_LINE (x) == 0)
1775 if (TYPE_NAME (TREE_TYPE (x)) == 0)
1776 TYPE_NAME (TREE_TYPE (x)) = x;
1778 else if (TREE_TYPE (x) != error_mark_node
1779 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
1781 tree tt = TREE_TYPE (x);
1782 DECL_ORIGINAL_TYPE (x) = tt;
1783 tt = build_type_copy (tt);
1785 TREE_USED (tt) = TREE_USED (x);
1790 /* Multiple external decls of the same identifier ought to match.
1791 We get warnings about inline functions where they are defined.
1792 Avoid duplicate warnings where they are used. */
1794 && ! (TREE_CODE (x) == FUNCTION_DECL && DECL_INLINE (x)))
1798 if (IDENTIFIER_LIMBO_VALUE (name) != 0)
1799 /* Decls in limbo are always extern, so no need to check that. */
1800 decl = IDENTIFIER_LIMBO_VALUE (name);
1804 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl))
1805 /* If old decl is built-in, we already warned if we should. */
1806 && !DECL_BUILT_IN (decl))
1808 pedwarn_with_decl (x,
1809 "type mismatch with previous external decl");
1810 pedwarn_with_decl (decl, "previous external decl of `%s'");
1814 /* If a function has had an implicit declaration, and then is defined,
1815 make sure they are compatible. */
1817 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
1818 && IDENTIFIER_GLOBAL_VALUE (name) == 0
1819 && TREE_CODE (x) == FUNCTION_DECL
1820 && ! comptypes (TREE_TYPE (x),
1821 TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name))))
1823 warning_with_decl (x, "type mismatch with previous implicit declaration");
1824 warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name),
1825 "previous implicit declaration of `%s'");
1828 /* This name is new in its binding level.
1829 Install the new declaration and return it. */
1830 if (b == global_binding_level)
1832 /* Install a global value. */
1834 /* If the first global decl has external linkage,
1835 warn if we later see static one. */
1836 if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
1837 TREE_PUBLIC (name) = 1;
1839 IDENTIFIER_GLOBAL_VALUE (name) = x;
1841 /* We no longer care about any previous block level declarations. */
1842 IDENTIFIER_LIMBO_VALUE (name) = 0;
1844 /* Don't forget if the function was used via an implicit decl. */
1845 if (IDENTIFIER_IMPLICIT_DECL (name)
1846 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
1847 TREE_USED (x) = 1, TREE_USED (name) = 1;
1849 /* Don't forget if its address was taken in that way. */
1850 if (IDENTIFIER_IMPLICIT_DECL (name)
1851 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
1852 TREE_ADDRESSABLE (x) = 1;
1854 /* Warn about mismatches against previous implicit decl. */
1855 if (IDENTIFIER_IMPLICIT_DECL (name) != 0
1856 /* If this real decl matches the implicit, don't complain. */
1857 && ! (TREE_CODE (x) == FUNCTION_DECL
1858 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x)))
1859 == integer_type_node)))
1860 pedwarn ("`%s' was previously implicitly declared to return `int'",
1861 IDENTIFIER_POINTER (name));
1863 /* If this decl is `static' and an `extern' was seen previously,
1864 that is erroneous. */
1865 if (TREE_PUBLIC (name)
1866 && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
1868 /* Okay to redeclare an ANSI built-in as static. */
1869 if (t != 0 && DECL_BUILT_IN (t))
1871 /* Okay to declare a non-ANSI built-in as anything. */
1872 else if (t != 0 && DECL_BUILT_IN_NONANSI (t))
1874 /* Okay to have global type decl after an earlier extern
1875 declaration inside a lexical block. */
1876 else if (TREE_CODE (x) == TYPE_DECL)
1878 else if (IDENTIFIER_IMPLICIT_DECL (name))
1880 if (! TREE_THIS_VOLATILE (name))
1881 pedwarn ("`%s' was declared implicitly `extern' and later `static'",
1882 IDENTIFIER_POINTER (name));
1885 pedwarn ("`%s' was declared `extern' and later `static'",
1886 IDENTIFIER_POINTER (name));
1891 /* Here to install a non-global value. */
1892 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1893 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
1895 IDENTIFIER_LOCAL_VALUE (name) = x;
1897 /* If this is an extern function declaration, see if we
1898 have a global definition or declaration for the function. */
1901 && TREE_CODE (x) == FUNCTION_DECL
1902 && TREE_CODE (oldglobal) == FUNCTION_DECL
1903 && DECL_EXTERNAL (x)
1904 && ! DECL_DECLARED_INLINE_P (x))
1906 /* We have one. Their types must agree. */
1907 if (! comptypes (TREE_TYPE (x),
1908 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
1909 pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one");
1912 /* Inner extern decl is inline if global one is.
1913 Copy enough to really inline it. */
1914 if (DECL_DECLARED_INLINE_P (oldglobal))
1916 DECL_DECLARED_INLINE_P (x)
1917 = DECL_DECLARED_INLINE_P (oldglobal);
1918 DECL_INLINE (x) = DECL_INLINE (oldglobal);
1919 DECL_INITIAL (x) = (current_function_decl == oldglobal
1920 ? 0 : DECL_INITIAL (oldglobal));
1921 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
1922 DECL_NUM_STMTS (x) = DECL_NUM_STMTS (oldglobal);
1923 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
1924 DECL_RESULT (x) = DECL_RESULT (oldglobal);
1925 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
1926 DECL_ABSTRACT_ORIGIN (x)
1927 = DECL_ABSTRACT_ORIGIN (oldglobal);
1929 /* Inner extern decl is built-in if global one is. */
1930 if (DECL_BUILT_IN (oldglobal))
1932 DECL_BUILT_IN_CLASS (x) = DECL_BUILT_IN_CLASS (oldglobal);
1933 DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
1935 /* Keep the arg types from a file-scope fcn defn. */
1936 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
1937 && DECL_INITIAL (oldglobal)
1938 && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
1939 TREE_TYPE (x) = TREE_TYPE (oldglobal);
1944 /* This case is probably sometimes the right thing to do. */
1945 /* If we have a local external declaration,
1946 then any file-scope declaration should not
1947 have been static. */
1948 if (oldlocal == 0 && oldglobal != 0
1949 && !TREE_PUBLIC (oldglobal)
1950 && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
1951 warning ("`%s' locally external but globally static",
1952 IDENTIFIER_POINTER (name));
1955 /* If we have a local external declaration,
1956 and no file-scope declaration has yet been seen,
1957 then if we later have a file-scope decl it must not be static. */
1959 && DECL_EXTERNAL (x)
1963 TREE_PUBLIC (name) = 1;
1965 /* Save this decl, so that we can do type checking against
1966 other decls after it falls out of scope.
1968 Only save it once. This prevents temporary decls created in
1969 expand_inline_function from being used here, since this
1970 will have been set when the inline function was parsed.
1971 It also helps give slightly better warnings. */
1972 if (IDENTIFIER_LIMBO_VALUE (name) == 0)
1973 IDENTIFIER_LIMBO_VALUE (name) = x;
1976 warn_if_shadowing (x, oldlocal);
1978 /* If storing a local value, there may already be one (inherited).
1979 If so, record it for restoration when this binding level ends. */
1981 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1984 /* Keep list of variables in this level with incomplete type.
1985 If the input is erroneous, we can have error_mark in the type
1986 slot (e.g. "f(void a, ...)") - that doesn't count as an
1988 if (TREE_TYPE (x) != error_mark_node
1989 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
1991 tree element = TREE_TYPE (x);
1993 while (TREE_CODE (element) == ARRAY_TYPE)
1994 element = TREE_TYPE (element);
1995 if (TREE_CODE (element) == RECORD_TYPE
1996 || TREE_CODE (element) == UNION_TYPE)
1997 b->incomplete_list = tree_cons (NULL_TREE, x, b->incomplete_list);
2001 /* Put decls on list in reverse order.
2002 We will reverse them later if necessary. */
2003 TREE_CHAIN (x) = b->names;
2009 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
2012 pushdecl_top_level (x)
2016 struct binding_level *b = current_binding_level;
2018 current_binding_level = global_binding_level;
2020 current_binding_level = b;
2024 /* Generate an implicit declaration for identifier FUNCTIONID
2025 as a function of type int (). Print a warning if appropriate. */
2028 implicitly_declare (functionid)
2032 int traditional_warning = 0;
2033 /* Only one "implicit declaration" warning per identifier. */
2034 int implicit_warning;
2036 /* We used to reuse an old implicit decl here,
2037 but this loses with inline functions because it can clobber
2038 the saved decl chains. */
2040 if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
2041 decl = IDENTIFIER_IMPLICIT_DECL (functionid);
2044 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2046 /* Warn of implicit decl following explicit local extern decl.
2047 This is probably a program designed for traditional C. */
2048 if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0)
2049 traditional_warning = 1;
2051 /* Warn once of an implicit declaration. */
2052 implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0);
2054 DECL_EXTERNAL (decl) = 1;
2055 TREE_PUBLIC (decl) = 1;
2057 /* Record that we have an implicit decl and this is it. */
2058 IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
2060 /* ANSI standard says implicit declarations are in the innermost block.
2061 So we record the decl in the standard fashion. */
2064 /* This is a no-op in c-lang.c or something real in objc-act.c. */
2066 objc_check_decl (decl);
2068 rest_of_decl_compilation (decl, NULL, 0, 0);
2070 if (implicit_warning)
2071 implicit_decl_warning (functionid);
2072 else if (warn_traditional && traditional_warning)
2073 warning ("function `%s' was previously declared within a block",
2074 IDENTIFIER_POINTER (functionid));
2076 /* Write a record describing this implicit function declaration to the
2077 prototypes file (if requested). */
2079 gen_aux_info_record (decl, 0, 1, 0);
2081 /* Possibly apply some default attributes to this implicit declaration. */
2082 decl_attributes (&decl, NULL_TREE, 0);
2088 implicit_decl_warning (id)
2091 const char *name = IDENTIFIER_POINTER (id);
2092 if (mesg_implicit_function_declaration == 2)
2093 error ("implicit declaration of function `%s'", name);
2094 else if (mesg_implicit_function_declaration == 1)
2095 warning ("implicit declaration of function `%s'", name);
2098 /* Return zero if the declaration NEWDECL is valid
2099 when the declaration OLDDECL (assumed to be for the same name)
2100 has already been seen.
2101 Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration,
2102 and 3 if it is a conflicting declaration. */
2105 redeclaration_error_message (newdecl, olddecl)
2106 tree newdecl, olddecl;
2108 if (TREE_CODE (newdecl) == TYPE_DECL)
2110 /* Do not complain about type redeclarations where at least one
2111 declaration was in a system header. */
2112 if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl))
2116 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2118 /* Declarations of functions can insist on internal linkage
2119 but they can't be inconsistent with internal linkage,
2120 so there can be no error on that account.
2121 However defining the same name twice is no good. */
2122 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
2123 /* However, defining once as extern inline and a second
2124 time in another way is ok. */
2125 && ! (DECL_DECLARED_INLINE_P (olddecl) && DECL_EXTERNAL (olddecl)
2126 && ! (DECL_DECLARED_INLINE_P (newdecl)
2127 && DECL_EXTERNAL (newdecl))))
2131 else if (DECL_CONTEXT (newdecl) == NULL_TREE)
2133 /* Objects declared at top level: */
2134 /* If at least one is a reference, it's ok. */
2135 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2137 /* Reject two definitions. */
2138 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
2140 /* Now we have two tentative defs, or one tentative and one real def. */
2141 /* Insist that the linkage match. */
2142 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
2146 else if (current_binding_level->parm_flag
2147 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2151 /* Newdecl has block scope. If olddecl has block scope also, then
2152 reject two definitions, and reject a definition together with an
2153 external reference. Otherwise, it is OK, because newdecl must
2154 be an extern reference to olddecl. */
2155 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))
2156 && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl))
2162 /* Get the LABEL_DECL corresponding to identifier ID as a label.
2163 Create one if none exists so far for the current function.
2164 This function is called for both label definitions and label references. */
2170 tree decl = IDENTIFIER_LABEL_VALUE (id);
2172 if (current_function_decl == 0)
2174 error ("label %s referenced outside of any function",
2175 IDENTIFIER_POINTER (id));
2179 /* Use a label already defined or ref'd with this name. */
2182 /* But not if it is inherited and wasn't declared to be inheritable. */
2183 if (DECL_CONTEXT (decl) != current_function_decl
2184 && ! C_DECLARED_LABEL_FLAG (decl))
2185 return shadow_label (id);
2189 decl = build_decl (LABEL_DECL, id, void_type_node);
2191 /* A label not explicitly declared must be local to where it's ref'd. */
2192 DECL_CONTEXT (decl) = current_function_decl;
2194 DECL_MODE (decl) = VOIDmode;
2196 /* Say where one reference is to the label,
2197 for the sake of the error if it is not defined. */
2198 DECL_SOURCE_LINE (decl) = lineno;
2199 DECL_SOURCE_FILE (decl) = input_filename;
2201 IDENTIFIER_LABEL_VALUE (id) = decl;
2203 named_labels = tree_cons (NULL_TREE, decl, named_labels);
2208 /* Make a label named NAME in the current function,
2209 shadowing silently any that may be inherited from containing functions
2210 or containing scopes.
2212 Note that valid use, if the label being shadowed
2213 comes from another scope in the same function,
2214 requires calling declare_nonlocal_label right away. */
2220 tree decl = IDENTIFIER_LABEL_VALUE (name);
2226 /* Check to make sure that the label hasn't already been declared
2227 at this label scope */
2228 for (dup = named_labels; dup; dup = TREE_CHAIN (dup))
2229 if (TREE_VALUE (dup) == decl)
2231 error ("duplicate label declaration `%s'",
2232 IDENTIFIER_POINTER (name));
2233 error_with_decl (TREE_VALUE (dup),
2234 "this is a previous declaration");
2235 /* Just use the previous declaration. */
2236 return lookup_label (name);
2239 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2240 IDENTIFIER_LABEL_VALUE (name) = decl = 0;
2243 return lookup_label (name);
2246 /* Define a label, specifying the location in the source file.
2247 Return the LABEL_DECL node for the label, if the definition is valid.
2248 Otherwise return 0. */
2251 define_label (filename, line, name)
2252 const char *filename;
2256 tree decl = lookup_label (name);
2258 /* If label with this name is known from an outer context, shadow it. */
2259 if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
2261 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2262 IDENTIFIER_LABEL_VALUE (name) = 0;
2263 decl = lookup_label (name);
2266 if (warn_traditional && !in_system_header && lookup_name (name))
2267 warning_with_file_and_line (filename, line,
2268 "traditional C lacks a separate namespace for labels, identifier `%s' conflicts",
2269 IDENTIFIER_POINTER (name));
2271 if (DECL_INITIAL (decl) != 0)
2273 error_with_file_and_line (filename, line, "duplicate label `%s'",
2274 IDENTIFIER_POINTER (name));
2279 /* Mark label as having been defined. */
2280 DECL_INITIAL (decl) = error_mark_node;
2281 /* Say where in the source. */
2282 DECL_SOURCE_FILE (decl) = filename;
2283 DECL_SOURCE_LINE (decl) = line;
2288 /* Return the list of declarations of the current level.
2289 Note that this list is in reverse order unless/until
2290 you nreverse it; and when you do nreverse it, you must
2291 store the result back using `storedecls' or you will lose. */
2296 return current_binding_level->names;
2299 /* Return the list of type-tags (for structs, etc) of the current level. */
2304 return current_binding_level->tags;
2307 /* Store the list of declarations of the current level.
2308 This is done for the parameter declarations of a function being defined,
2309 after they are modified in the light of any missing parameters. */
2315 current_binding_level->names = decls;
2318 /* Similarly, store the list of tags of the current level. */
2324 current_binding_level->tags = tags;
2327 /* Given NAME, an IDENTIFIER_NODE,
2328 return the structure (or union or enum) definition for that name.
2329 Searches binding levels from BINDING_LEVEL up to the global level.
2330 If THISLEVEL_ONLY is nonzero, searches only the specified context
2331 (but skips any tag-transparent contexts to find one that is
2332 meaningful for tags).
2333 CODE says which kind of type the caller wants;
2334 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2335 If the wrong kind of type is found, an error is reported. */
2338 lookup_tag (code, name, binding_level, thislevel_only)
2339 enum tree_code code;
2340 struct binding_level *binding_level;
2344 struct binding_level *level;
2347 for (level = binding_level; level; level = level->level_chain)
2350 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2352 if (TREE_PURPOSE (tail) == name)
2354 if (TREE_CODE (TREE_VALUE (tail)) != code)
2356 /* Definition isn't the kind we were looking for. */
2357 pending_invalid_xref = name;
2358 pending_invalid_xref_file = input_filename;
2359 pending_invalid_xref_line = lineno;
2360 /* If in the same binding level as a declaration as a tag
2361 of a different type, this must not be allowed to
2362 shadow that tag, so give the error immediately.
2363 (For example, "struct foo; union foo;" is invalid.) */
2365 pending_xref_error ();
2367 return TREE_VALUE (tail);
2370 if (! level->tag_transparent)
2380 /* Print an error message now
2381 for a recent invalid struct, union or enum cross reference.
2382 We don't print them immediately because they are not invalid
2383 when used in the `struct foo;' construct for shadowing. */
2386 pending_xref_error ()
2388 if (pending_invalid_xref != 0)
2389 error_with_file_and_line (pending_invalid_xref_file,
2390 pending_invalid_xref_line,
2391 "`%s' defined as wrong kind of tag",
2392 IDENTIFIER_POINTER (pending_invalid_xref));
2393 pending_invalid_xref = 0;
2396 /* Given a type, find the tag that was defined for it and return the tag name.
2397 Otherwise return 0. */
2400 lookup_tag_reverse (type)
2403 struct binding_level *level;
2405 for (level = current_binding_level; level; level = level->level_chain)
2408 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2410 if (TREE_VALUE (tail) == type)
2411 return TREE_PURPOSE (tail);
2417 /* Look up NAME in the current binding level and its superiors
2418 in the namespace of variables, functions and typedefs.
2419 Return a ..._DECL node of some kind representing its definition,
2420 or return 0 if it is undefined. */
2428 if (current_binding_level != global_binding_level
2429 && IDENTIFIER_LOCAL_VALUE (name))
2430 val = IDENTIFIER_LOCAL_VALUE (name);
2432 val = IDENTIFIER_GLOBAL_VALUE (name);
2436 /* Similar to `lookup_name' but look only at current binding level. */
2439 lookup_name_current_level (name)
2444 if (current_binding_level == global_binding_level)
2445 return IDENTIFIER_GLOBAL_VALUE (name);
2447 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
2450 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
2451 if (DECL_NAME (t) == name)
2457 /* Create the predefined scalar types of C,
2458 and some nodes representing standard constants (0, 1, (void *) 0).
2459 Initialize the global binding level.
2460 Make definitions for built-in primitive functions. */
2463 c_init_decl_processing ()
2466 tree ptr_ftype_void, ptr_ftype_ptr;
2468 /* Adds some ggc roots, and reserved words for c-parse.in. */
2471 current_function_decl = NULL;
2472 named_labels = NULL;
2473 current_binding_level = NULL_BINDING_LEVEL;
2474 free_binding_level = NULL_BINDING_LEVEL;
2476 /* Make the binding_level structure for global names. */
2478 global_binding_level = current_binding_level;
2480 build_common_tree_nodes (flag_signed_char);
2482 c_common_nodes_and_builtins ();
2484 boolean_type_node = integer_type_node;
2485 boolean_true_node = integer_one_node;
2486 boolean_false_node = integer_zero_node;
2488 c_bool_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
2489 TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
2490 TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
2491 TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
2492 TYPE_PRECISION (c_bool_type_node) = 1;
2493 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
2495 c_bool_false_node = build_int_2 (0, 0);
2496 TREE_TYPE (c_bool_false_node) = c_bool_type_node;
2497 c_bool_true_node = build_int_2 (1, 0);
2498 TREE_TYPE (c_bool_true_node) = c_bool_type_node;
2500 endlink = void_list_node;
2501 ptr_ftype_void = build_function_type (ptr_type_node, endlink);
2503 = build_function_type (ptr_type_node,
2504 tree_cons (NULL_TREE, ptr_type_node, endlink));
2506 pedantic_lvalues = pedantic;
2508 make_fname_decl = c_make_fname_decl;
2509 start_fname_decls ();
2512 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2513 decl, NAME is the initialization string and TYPE_DEP indicates whether
2514 NAME depended on the type of the function. As we don't yet implement
2515 delayed emission of static data, we mark the decl as emitted
2516 so it is not placed in the output. Anything using it must therefore pull
2517 out the STRING_CST initializer directly. This does mean that these names
2518 are string merging candidates, which is wrong for C99's __func__. FIXME. */
2521 c_make_fname_decl (id, type_dep)
2525 const char *name = fname_as_string (type_dep);
2526 tree decl, type, init;
2527 size_t length = strlen (name);
2529 type = build_array_type
2530 (build_qualified_type (char_type_node, TYPE_QUAL_CONST),
2531 build_index_type (size_int (length)));
2533 decl = build_decl (VAR_DECL, id, type);
2534 /* We don't push the decl, so have to set its context here. */
2535 DECL_CONTEXT (decl) = current_function_decl;
2537 TREE_STATIC (decl) = 1;
2538 TREE_READONLY (decl) = 1;
2539 DECL_ARTIFICIAL (decl) = 1;
2541 init = build_string (length + 1, name);
2542 TREE_TYPE (init) = type;
2543 DECL_INITIAL (decl) = init;
2545 TREE_USED (decl) = 1;
2547 finish_decl (decl, init, NULL_TREE);
2552 /* Return a definition for a builtin function named NAME and whose data type
2553 is TYPE. TYPE should be a function type with argument types.
2554 FUNCTION_CODE tells later passes how to compile calls to this function.
2555 See tree.h for its possible values.
2557 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
2558 the name to be called if we can't opencode the function. If
2559 ATTRS is nonzero, use that for the function's attribute list. */
2562 builtin_function (name, type, function_code, class, library_name, attrs)
2566 enum built_in_class class;
2567 const char *library_name;
2570 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
2571 DECL_EXTERNAL (decl) = 1;
2572 TREE_PUBLIC (decl) = 1;
2574 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
2575 make_decl_rtl (decl, NULL);
2577 DECL_BUILT_IN_CLASS (decl) = class;
2578 DECL_FUNCTION_CODE (decl) = function_code;
2580 /* Warn if a function in the namespace for users
2581 is used without an occasion to consider it declared. */
2582 if (name[0] != '_' || name[1] != '_')
2583 C_DECL_ANTICIPATED (decl) = 1;
2585 /* Possibly apply some default attributes to this built-in function. */
2587 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
2589 decl_attributes (&decl, NULL_TREE, 0);
2594 /* Apply default attributes to a function, if a system function with default
2598 c_insert_default_attributes (decl)
2601 if (!TREE_PUBLIC (decl))
2603 c_common_insert_default_attributes (decl);
2606 /* Called when a declaration is seen that contains no names to declare.
2607 If its type is a reference to a structure, union or enum inherited
2608 from a containing scope, shadow that tag name for the current scope
2609 with a forward reference.
2610 If its type defines a new named structure or union
2611 or defines an enum, it is valid but we need not do anything here.
2612 Otherwise, it is an error. */
2615 shadow_tag (declspecs)
2618 shadow_tag_warned (declspecs, 0);
2622 shadow_tag_warned (declspecs, warned)
2625 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
2632 pending_invalid_xref = 0;
2634 /* Remove the attributes from declspecs, since they will confuse the
2636 split_specs_attrs (declspecs, &specs, &attrs);
2638 for (link = specs; link; link = TREE_CHAIN (link))
2640 tree value = TREE_VALUE (link);
2641 enum tree_code code = TREE_CODE (value);
2643 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
2644 /* Used to test also that TYPE_SIZE (value) != 0.
2645 That caused warning for `struct foo;' at top level in the file. */
2647 tree name = lookup_tag_reverse (value);
2654 if (warned != 1 && code != ENUMERAL_TYPE)
2655 /* Empty unnamed enum OK */
2657 pedwarn ("unnamed struct/union that defines no instances");
2663 t = lookup_tag (code, name, current_binding_level, 1);
2667 t = make_node (code);
2674 if (!warned && ! in_system_header)
2676 warning ("useless keyword or type name in empty declaration");
2683 error ("two types specified in one empty declaration");
2688 pedwarn ("empty declaration");
2692 /* Construct an array declarator. EXPR is the expression inside [], or
2693 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
2694 to the pointer to which a parameter array is converted). STATIC_P is
2695 nonzero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P
2696 is nonzero is the array is [*], a VLA of unspecified length which is
2697 nevertheless a complete type (not currently implemented by GCC),
2698 zero otherwise. The declarator is constructed as an ARRAY_REF
2699 (to be decoded by grokdeclarator), whose operand 0 is what's on the
2700 left of the [] (filled by in set_array_declarator_type) and operand 1
2701 is the expression inside; whose TREE_TYPE is the type qualifiers and
2702 which has TREE_STATIC set if "static" is used. */
2705 build_array_declarator (expr, quals, static_p, vla_unspec_p)
2712 decl = build_nt (ARRAY_REF, NULL_TREE, expr);
2713 TREE_TYPE (decl) = quals;
2714 TREE_STATIC (decl) = (static_p ? 1 : 0);
2715 if (pedantic && !flag_isoc99)
2717 if (static_p || quals != NULL_TREE)
2718 pedwarn ("ISO C90 does not support `static' or type qualifiers in parameter array declarators");
2720 pedwarn ("ISO C90 does not support `[*]' array declarators");
2723 warning ("GCC does not yet properly implement `[*]' array declarators");
2727 /* Set the type of an array declarator. DECL is the declarator, as
2728 constructed by build_array_declarator; TYPE is what appears on the left
2729 of the [] and goes in operand 0. ABSTRACT_P is nonzero if it is an
2730 abstract declarator, zero otherwise; this is used to reject static and
2731 type qualifiers in abstract declarators, where they are not in the
2735 set_array_declarator_type (decl, type, abstract_p)
2740 TREE_OPERAND (decl, 0) = type;
2741 if (abstract_p && (TREE_TYPE (decl) != NULL_TREE || TREE_STATIC (decl)))
2742 error ("static or type qualifiers in abstract declarator");
2746 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
2749 groktypename (typename)
2754 if (TREE_CODE (typename) != TREE_LIST)
2757 split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs);
2759 typename = grokdeclarator (TREE_VALUE (typename), specs, TYPENAME, 0);
2761 /* Apply attributes. */
2762 decl_attributes (&typename, attrs, 0);
2767 /* Return a PARM_DECL node for a given pair of specs and declarator. */
2770 groktypename_in_parm_context (typename)
2773 if (TREE_CODE (typename) != TREE_LIST)
2775 return grokdeclarator (TREE_VALUE (typename),
2776 TREE_PURPOSE (typename),
2780 /* Decode a declarator in an ordinary declaration or data definition.
2781 This is called as soon as the type information and variable name
2782 have been parsed, before parsing the initializer if any.
2783 Here we create the ..._DECL node, fill in its type,
2784 and put it on the list of decls for the current context.
2785 The ..._DECL node is returned as the value.
2787 Exception: for arrays where the length is not specified,
2788 the type is left null, to be filled in by `finish_decl'.
2790 Function definitions do not come here; they go to start_function
2791 instead. However, external and forward declarations of functions
2792 do go through here. Structure field declarations are done by
2793 grokfield and not through here. */
2796 start_decl (declarator, declspecs, initialized, attributes)
2797 tree declarator, declspecs;
2804 /* An object declared as __attribute__((deprecated)) suppresses
2805 warnings of uses of other deprecated items. */
2806 if (lookup_attribute ("deprecated", attributes))
2807 deprecated_state = DEPRECATED_SUPPRESS;
2809 decl = grokdeclarator (declarator, declspecs,
2810 NORMAL, initialized);
2812 deprecated_state = DEPRECATED_NORMAL;
2814 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
2815 && MAIN_NAME_P (DECL_NAME (decl)))
2816 warning_with_decl (decl, "`%s' is usually a function");
2819 /* Is it valid for this decl to have an initializer at all?
2820 If not, set INITIALIZED to zero, which will indirectly
2821 tell `finish_decl' to ignore the initializer once it is parsed. */
2822 switch (TREE_CODE (decl))
2825 error ("typedef `%s' is initialized (use __typeof__ instead)",
2826 IDENTIFIER_POINTER (DECL_NAME (decl)));
2831 error ("function `%s' is initialized like a variable",
2832 IDENTIFIER_POINTER (DECL_NAME (decl)));
2837 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
2838 error ("parameter `%s' is initialized",
2839 IDENTIFIER_POINTER (DECL_NAME (decl)));
2844 /* Don't allow initializations for incomplete types
2845 except for arrays which might be completed by the initialization. */
2847 /* This can happen if the array size is an undefined macro. We already
2848 gave a warning, so we don't need another one. */
2849 if (TREE_TYPE (decl) == error_mark_node)
2851 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
2853 /* A complete type is ok if size is fixed. */
2855 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
2856 || C_DECL_VARIABLE_SIZE (decl))
2858 error ("variable-sized object may not be initialized");
2862 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
2864 error ("variable `%s' has initializer but incomplete type",
2865 IDENTIFIER_POINTER (DECL_NAME (decl)));
2868 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
2870 error ("elements of array `%s' have incomplete type",
2871 IDENTIFIER_POINTER (DECL_NAME (decl)));
2879 /* Seems redundant with grokdeclarator. */
2880 if (current_binding_level != global_binding_level
2881 && DECL_EXTERNAL (decl)
2882 && TREE_CODE (decl) != FUNCTION_DECL)
2883 warning ("declaration of `%s' has `extern' and is initialized",
2884 IDENTIFIER_POINTER (DECL_NAME (decl)));
2886 DECL_EXTERNAL (decl) = 0;
2887 if (current_binding_level == global_binding_level)
2888 TREE_STATIC (decl) = 1;
2890 /* Tell `pushdecl' this is an initialized decl
2891 even though we don't yet have the initializer expression.
2892 Also tell `finish_decl' it may store the real initializer. */
2893 DECL_INITIAL (decl) = error_mark_node;
2896 /* If this is a function declaration, write a record describing it to the
2897 prototypes file (if requested). */
2899 if (TREE_CODE (decl) == FUNCTION_DECL)
2900 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
2902 /* ANSI specifies that a tentative definition which is not merged with
2903 a non-tentative definition behaves exactly like a definition with an
2904 initializer equal to zero. (Section 3.7.2)
2906 -fno-common gives strict ANSI behavior, though this tends to break
2907 a large body of code that grew up without this rule.
2909 Thread-local variables are never common, since there's no entrenched
2910 body of code to break, and it allows more efficient variable references
2911 in the presense of dynamic linking. */
2913 if (TREE_CODE (decl) == VAR_DECL
2915 && TREE_PUBLIC (decl)
2916 && !DECL_THREAD_LOCAL (decl)
2918 DECL_COMMON (decl) = 1;
2920 /* Set attributes here so if duplicate decl, will have proper attributes. */
2921 decl_attributes (&decl, attributes, 0);
2923 /* If #pragma weak was used, mark the decl weak now. */
2924 if (current_binding_level == global_binding_level)
2925 maybe_apply_pragma_weak (decl);
2927 if (TREE_CODE (decl) == FUNCTION_DECL
2928 && DECL_DECLARED_INLINE_P (decl)
2929 && DECL_UNINLINABLE (decl)
2930 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
2931 warning_with_decl (decl,
2932 "inline function `%s' given attribute noinline");
2934 /* Add this decl to the current binding level.
2935 TEM may equal DECL or it may be a previous decl of the same name. */
2936 tem = pushdecl (decl);
2938 /* For a local variable, define the RTL now. */
2939 if (current_binding_level != global_binding_level
2940 /* But not if this is a duplicate decl
2941 and we preserved the rtl from the previous one
2942 (which may or may not happen). */
2943 && !DECL_RTL_SET_P (tem)
2944 && !DECL_CONTEXT (tem))
2946 if (TREE_TYPE (tem) != error_mark_node
2947 && COMPLETE_TYPE_P (TREE_TYPE (tem)))
2949 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
2950 && DECL_INITIAL (tem) != 0)
2957 /* Finish processing of a declaration;
2958 install its initial value.
2959 If the length of an array type is not known before,
2960 it must be determined now, from the initial value, or it is an error. */
2963 finish_decl (decl, init, asmspec_tree)
2967 tree type = TREE_TYPE (decl);
2968 int was_incomplete = (DECL_SIZE (decl) == 0);
2969 const char *asmspec = 0;
2971 /* If a name was specified, get the string. */
2972 if (current_binding_level == global_binding_level)
2973 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
2975 asmspec = TREE_STRING_POINTER (asmspec_tree);
2977 /* If `start_decl' didn't like having an initialization, ignore it now. */
2978 if (init != 0 && DECL_INITIAL (decl) == 0)
2981 /* Don't crash if parm is initialized. */
2982 if (TREE_CODE (decl) == PARM_DECL)
2986 store_init_value (decl, init);
2988 /* Deduce size of array from initialization, if not already known */
2989 if (TREE_CODE (type) == ARRAY_TYPE
2990 && TYPE_DOMAIN (type) == 0
2991 && TREE_CODE (decl) != TYPE_DECL)
2994 = (TREE_STATIC (decl)
2995 /* Even if pedantic, an external linkage array
2996 may have incomplete type at first. */
2997 ? pedantic && !TREE_PUBLIC (decl)
2998 : !DECL_EXTERNAL (decl));
3000 = complete_array_type (type, DECL_INITIAL (decl), do_default);
3002 /* Get the completed type made by complete_array_type. */
3003 type = TREE_TYPE (decl);
3006 error_with_decl (decl, "initializer fails to determine size of `%s'");
3008 else if (failure == 2)
3011 error_with_decl (decl, "array size missing in `%s'");
3012 /* If a `static' var's size isn't known,
3013 make it extern as well as static, so it does not get
3015 If it is not `static', then do not mark extern;
3016 finish_incomplete_decl will give it a default size
3017 and it will get allocated. */
3018 else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl))
3019 DECL_EXTERNAL (decl) = 1;
3022 /* TYPE_MAX_VALUE is always one less than the number of elements
3023 in the array, because we start counting at zero. Therefore,
3024 warn only if the value is less than zero. */
3025 else if (pedantic && TYPE_DOMAIN (type) != 0
3026 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
3027 error_with_decl (decl, "zero or negative size array `%s'");
3029 layout_decl (decl, 0);
3032 if (TREE_CODE (decl) == VAR_DECL)
3034 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
3035 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
3036 layout_decl (decl, 0);
3038 if (DECL_SIZE (decl) == 0
3039 /* Don't give an error if we already gave one earlier. */
3040 && TREE_TYPE (decl) != error_mark_node
3041 && (TREE_STATIC (decl)
3043 /* A static variable with an incomplete type
3044 is an error if it is initialized.
3045 Also if it is not file scope.
3046 Otherwise, let it through, but if it is not `extern'
3047 then it may cause an error message later. */
3048 (DECL_INITIAL (decl) != 0
3049 || DECL_CONTEXT (decl) != 0)
3051 /* An automatic variable with an incomplete type
3053 !DECL_EXTERNAL (decl)))
3055 error_with_decl (decl, "storage size of `%s' isn't known");
3056 TREE_TYPE (decl) = error_mark_node;
3059 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
3060 && DECL_SIZE (decl) != 0)
3062 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3063 constant_expression_warning (DECL_SIZE (decl));
3065 error_with_decl (decl, "storage size of `%s' isn't constant");
3068 if (TREE_USED (type))
3069 TREE_USED (decl) = 1;
3072 /* If this is a function and an assembler name is specified, it isn't
3073 builtin any more. Also reset DECL_RTL so we can give it its new
3075 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
3077 DECL_BUILT_IN_CLASS (decl) = NOT_BUILT_IN;
3078 SET_DECL_RTL (decl, NULL_RTX);
3079 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
3082 /* Output the assembler code and/or RTL code for variables and functions,
3083 unless the type is an undefined structure or union.
3084 If not, it will get done when the type is completed. */
3086 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3088 /* This is a no-op in c-lang.c or something real in objc-act.c. */
3090 objc_check_decl (decl);
3092 if (!DECL_CONTEXT (decl))
3094 if (DECL_INITIAL (decl) == NULL_TREE
3095 || DECL_INITIAL (decl) == error_mark_node)
3096 /* Don't output anything
3097 when a tentative file-scope definition is seen.
3098 But at end of compilation, do output code for them. */
3099 DECL_DEFER_OUTPUT (decl) = 1;
3100 rest_of_decl_compilation (decl, asmspec,
3101 (DECL_CONTEXT (decl) == 0
3102 || TREE_ASM_WRITTEN (decl)), 0);
3106 /* This is a local variable. If there is an ASMSPEC, the
3107 user has requested that we handle it specially. */
3110 /* In conjunction with an ASMSPEC, the `register'
3111 keyword indicates that we should place the variable
3112 in a particular register. */
3113 if (DECL_REGISTER (decl))
3114 DECL_C_HARD_REGISTER (decl) = 1;
3116 /* If this is not a static variable, issue a warning.
3117 It doesn't make any sense to give an ASMSPEC for an
3118 ordinary, non-register local variable. Historically,
3119 GCC has accepted -- but ignored -- the ASMSPEC in
3121 if (TREE_CODE (decl) == VAR_DECL
3122 && !DECL_REGISTER (decl)
3123 && !TREE_STATIC (decl))
3124 warning_with_decl (decl,
3125 "ignoring asm-specifier for non-static local variable `%s'");
3127 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
3130 if (TREE_CODE (decl) != FUNCTION_DECL)
3131 add_decl_stmt (decl);
3134 if (DECL_CONTEXT (decl) != 0)
3136 /* Recompute the RTL of a local array now
3137 if it used to be an incomplete type. */
3139 && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
3141 /* If we used it already as memory, it must stay in memory. */
3142 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
3143 /* If it's still incomplete now, no init will save it. */
3144 if (DECL_SIZE (decl) == 0)
3145 DECL_INITIAL (decl) = 0;
3150 if (TREE_CODE (decl) == TYPE_DECL)
3152 /* This is a no-op in c-lang.c or something real in objc-act.c. */
3154 objc_check_decl (decl);
3155 rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0, 0);
3158 /* At the end of a declaration, throw away any variable type sizes
3159 of types defined inside that declaration. There is no use
3160 computing them in the following function definition. */
3161 if (current_binding_level == global_binding_level)
3162 get_pending_sizes ();
3165 /* Given a parsed parameter declaration,
3166 decode it into a PARM_DECL and push that on the current binding level.
3167 Also, for the sake of forward parm decls,
3168 record the given order of parms in `parm_order'. */
3171 push_parm_decl (parm)
3175 int old_immediate_size_expand = immediate_size_expand;
3176 /* Don't try computing parm sizes now -- wait till fn is called. */
3177 immediate_size_expand = 0;
3179 decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
3180 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
3181 decl_attributes (&decl, TREE_VALUE (parm), 0);
3184 if (DECL_NAME (decl))
3187 olddecl = lookup_name (DECL_NAME (decl));
3188 if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
3189 pedwarn_with_decl (decl,
3190 "ISO C forbids parameter `%s' shadowing typedef");
3194 decl = pushdecl (decl);
3196 immediate_size_expand = old_immediate_size_expand;
3198 current_binding_level->parm_order
3199 = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
3201 /* Add this decl to the current binding level. */
3202 finish_decl (decl, NULL_TREE, NULL_TREE);
3205 /* Clear the given order of parms in `parm_order'.
3206 Used at start of parm list,
3207 and also at semicolon terminating forward decls. */
3212 current_binding_level->parm_order = NULL_TREE;
3215 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3216 literal, which may be an incomplete array type completed by the
3217 initializer; INIT is a CONSTRUCTOR that initializes the compound
3221 build_compound_literal (type, init)
3225 /* We do not use start_decl here because we have a type, not a declarator;
3226 and do not use finish_decl because the decl should be stored inside
3227 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
3228 tree decl = build_decl (VAR_DECL, NULL_TREE, type);
3231 DECL_EXTERNAL (decl) = 0;
3232 TREE_PUBLIC (decl) = 0;
3233 TREE_STATIC (decl) = (current_binding_level == global_binding_level);
3234 DECL_CONTEXT (decl) = current_function_decl;
3235 TREE_USED (decl) = 1;
3236 TREE_TYPE (decl) = type;
3237 TREE_READONLY (decl) = TREE_READONLY (type);
3238 store_init_value (decl, init);
3240 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
3242 int failure = complete_array_type (type, DECL_INITIAL (decl), 1);
3247 type = TREE_TYPE (decl);
3248 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
3249 return error_mark_node;
3251 stmt = build_stmt (DECL_STMT, decl);
3252 complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt);
3253 TREE_SIDE_EFFECTS (complit) = 1;
3255 layout_decl (decl, 0);
3257 if (TREE_STATIC (decl))
3259 /* This decl needs a name for the assembler output. We also need
3260 a unique suffix to be added to the name. */
3262 extern int var_labelno;
3264 ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal", var_labelno);
3266 DECL_NAME (decl) = get_identifier (name);
3267 DECL_DEFER_OUTPUT (decl) = 1;
3268 DECL_COMDAT (decl) = 1;
3269 DECL_ARTIFICIAL (decl) = 1;
3271 rest_of_decl_compilation (decl, NULL, 1, 0);
3277 /* Make TYPE a complete type based on INITIAL_VALUE.
3278 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3279 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3282 complete_array_type (type, initial_value, do_default)
3287 tree maxindex = NULL_TREE;
3292 /* Note MAXINDEX is really the maximum index,
3293 one less than the size. */
3294 if (TREE_CODE (initial_value) == STRING_CST)
3297 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
3298 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
3301 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
3303 tree elts = CONSTRUCTOR_ELTS (initial_value);
3304 maxindex = build_int_2 (-1, -1);
3305 for (; elts; elts = TREE_CHAIN (elts))
3307 if (TREE_PURPOSE (elts))
3308 maxindex = TREE_PURPOSE (elts);
3310 maxindex = fold (build (PLUS_EXPR, integer_type_node,
3311 maxindex, integer_one_node));
3313 maxindex = copy_node (maxindex);
3317 /* Make an error message unless that happened already. */
3318 if (initial_value != error_mark_node)
3321 /* Prevent further error messages. */
3322 maxindex = build_int_2 (0, 0);
3329 maxindex = build_int_2 (0, 0);
3335 TYPE_DOMAIN (type) = build_index_type (maxindex);
3336 if (!TREE_TYPE (maxindex))
3337 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
3340 /* Lay out the type now that we can get the real answer. */
3347 /* Determine whether TYPE is a structure with a flexible array member,
3348 or a union containing such a structure (possibly recursively). */
3351 flexible_array_type_p (type)
3355 switch (TREE_CODE (type))
3358 x = TYPE_FIELDS (type);
3361 while (TREE_CHAIN (x) != NULL_TREE)
3363 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
3364 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3365 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
3366 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
3370 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
3372 if (flexible_array_type_p (TREE_TYPE (x)))
3381 /* Given declspecs and a declarator,
3382 determine the name and type of the object declared
3383 and construct a ..._DECL node for it.
3384 (In one case we can return a ..._TYPE node instead.
3385 For invalid input we sometimes return 0.)
3387 DECLSPECS is a chain of tree_list nodes whose value fields
3388 are the storage classes and type specifiers.
3390 DECL_CONTEXT says which syntactic context this declaration is in:
3391 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3392 FUNCDEF for a function definition. Like NORMAL but a few different
3393 error messages in each case. Return value may be zero meaning
3394 this definition is too screwy to try to parse.
3395 PARM for a parameter declaration (either within a function prototype
3396 or before a function body). Make a PARM_DECL, or return void_type_node.
3397 TYPENAME if for a typename (in a cast or sizeof).
3398 Don't make a DECL node; just return the ..._TYPE node.
3399 FIELD for a struct or union field; make a FIELD_DECL.
3400 BITFIELD for a field with specified width.
3401 INITIALIZED is 1 if the decl has an initializer.
3403 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3404 It may also be so in the PARM case, for a prototype where the
3405 argument type is specified but not the name.
3407 This function is where the complicated C meanings of `static'
3408 and `extern' are interpreted. */
3411 grokdeclarator (declarator, declspecs, decl_context, initialized)
3414 enum decl_context decl_context;
3419 tree type = NULL_TREE;
3424 int type_quals = TYPE_UNQUALIFIED;
3426 int explicit_int = 0;
3427 int explicit_char = 0;
3428 int defaulted_int = 0;
3429 tree typedef_decl = 0;
3431 tree typedef_type = 0;
3432 int funcdef_flag = 0;
3433 enum tree_code innermost_code = ERROR_MARK;
3435 int size_varies = 0;
3436 tree decl_attr = NULL_TREE;
3437 tree array_ptr_quals = NULL_TREE;
3438 int array_parm_static = 0;
3439 tree returned_attrs = NULL_TREE;
3441 if (decl_context == BITFIELD)
3442 bitfield = 1, decl_context = FIELD;
3444 if (decl_context == FUNCDEF)
3445 funcdef_flag = 1, decl_context = NORMAL;
3447 /* Look inside a declarator for the name being declared
3448 and get it as a string, for an error message. */
3450 tree decl = declarator;
3454 switch (TREE_CODE (decl))
3459 innermost_code = TREE_CODE (decl);
3460 decl = TREE_OPERAND (decl, 0);
3464 decl = TREE_VALUE (decl);
3467 case IDENTIFIER_NODE:
3468 name = IDENTIFIER_POINTER (decl);
3479 /* A function definition's declarator must have the form of
3480 a function declarator. */
3482 if (funcdef_flag && innermost_code != CALL_EXPR)
3485 /* Anything declared one level down from the top level
3486 must be one of the parameters of a function
3487 (because the body is at least two levels down). */
3489 /* If this looks like a function definition, make it one,
3490 even if it occurs where parms are expected.
3491 Then store_parm_decls will reject it and not use it as a parm. */
3492 if (decl_context == NORMAL && !funcdef_flag
3493 && current_binding_level->parm_flag)
3494 decl_context = PARM;
3496 /* Look through the decl specs and record which ones appear.
3497 Some typespecs are defined as built-in typenames.
3498 Others, the ones that are modifiers of other types,
3499 are represented by bits in SPECBITS: set the bits for
3500 the modifiers that appear. Storage class keywords are also in SPECBITS.
3502 If there is a typedef name or a type, store the type in TYPE.
3503 This includes builtin typedefs such as `int'.
3505 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3506 and did not come from a user typedef.
3508 Set LONGLONG if `long' is mentioned twice. */
3510 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
3512 tree id = TREE_VALUE (spec);
3514 /* If the entire declaration is itself tagged as deprecated then
3515 suppress reports of deprecated items. */
3516 if (id && TREE_DEPRECATED (id))
3518 if (deprecated_state != DEPRECATED_SUPPRESS)
3519 warn_deprecated_use (id);
3522 if (id == ridpointers[(int) RID_INT])
3524 if (id == ridpointers[(int) RID_CHAR])
3527 if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (id))
3529 enum rid i = C_RID_CODE (id);
3530 if ((int) i <= (int) RID_LAST_MODIFIER)
3532 if (i == RID_LONG && (specbits & (1 << (int) RID_LONG)))
3535 error ("`long long long' is too long for GCC");
3538 if (pedantic && !flag_isoc99 && ! in_system_header
3540 pedwarn ("ISO C90 does not support `long long'");
3544 else if (specbits & (1 << (int) i))
3546 if (i == RID_CONST || i == RID_VOLATILE || i == RID_RESTRICT)
3549 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
3552 error ("duplicate `%s'", IDENTIFIER_POINTER (id));
3555 /* Diagnose "__thread extern". Recall that this list
3556 is in the reverse order seen in the text. */
3558 && (specbits & (1 << (int) RID_EXTERN
3559 | 1 << (int) RID_STATIC)))
3561 if (specbits & 1 << (int) RID_EXTERN)
3562 error ("`__thread' before `extern'");
3564 error ("`__thread' before `static'");
3567 specbits |= 1 << (int) i;
3572 error ("two or more data types in declaration of `%s'", name);
3573 /* Actual typedefs come to us as TYPE_DECL nodes. */
3574 else if (TREE_CODE (id) == TYPE_DECL)
3576 if (TREE_TYPE (id) == error_mark_node)
3577 ; /* Allow the type to default to int to avoid cascading errors. */
3580 type = TREE_TYPE (id);
3581 decl_attr = DECL_ATTRIBUTES (id);
3585 /* Built-in types come as identifiers. */
3586 else if (TREE_CODE (id) == IDENTIFIER_NODE)
3588 tree t = lookup_name (id);
3589 if (TREE_TYPE (t) == error_mark_node)
3591 else if (!t || TREE_CODE (t) != TYPE_DECL)
3592 error ("`%s' fails to be a typedef or built in type",
3593 IDENTIFIER_POINTER (id));
3596 type = TREE_TYPE (t);
3600 else if (TREE_CODE (id) != ERROR_MARK)
3607 typedef_type = type;
3609 size_varies = C_TYPE_VARIABLE_SIZE (type);
3611 /* No type at all: default to `int', and set DEFAULTED_INT
3612 because it was not a user-defined typedef. */
3616 if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3617 | (1 << (int) RID_SIGNED)
3618 | (1 << (int) RID_UNSIGNED)
3619 | (1 << (int) RID_COMPLEX))))
3620 /* Don't warn about typedef foo = bar. */
3621 && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
3622 && ! in_system_header)
3624 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
3625 and this is a function, or if -Wimplicit; prefer the former
3626 warning since it is more explicit. */
3627 if ((warn_implicit_int || warn_return_type || flag_isoc99)
3629 warn_about_return_type = 1;
3630 else if (warn_implicit_int || flag_isoc99)
3631 pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
3636 type = integer_type_node;
3639 /* Now process the modifiers that were specified
3640 and check for invalid combinations. */
3642 /* Long double is a special combination. */
3644 if ((specbits & 1 << (int) RID_LONG) && ! longlong
3645 && TYPE_MAIN_VARIANT (type) == double_type_node)
3647 specbits &= ~(1 << (int) RID_LONG);
3648 type = long_double_type_node;
3651 /* Check all other uses of type modifiers. */
3653 if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3654 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
3658 if ((specbits & 1 << (int) RID_LONG)
3659 && (specbits & 1 << (int) RID_SHORT))
3660 error ("both long and short specified for `%s'", name);
3661 else if (((specbits & 1 << (int) RID_LONG)
3662 || (specbits & 1 << (int) RID_SHORT))
3664 error ("long or short specified with char for `%s'", name);
3665 else if (((specbits & 1 << (int) RID_LONG)
3666 || (specbits & 1 << (int) RID_SHORT))
3667 && TREE_CODE (type) == REAL_TYPE)
3669 static int already = 0;
3671 error ("long or short specified with floating type for `%s'", name);
3672 if (! already && ! pedantic)
3674 error ("the only valid combination is `long double'");
3678 else if ((specbits & 1 << (int) RID_SIGNED)
3679 && (specbits & 1 << (int) RID_UNSIGNED))
3680 error ("both signed and unsigned specified for `%s'", name);
3681 else if (TREE_CODE (type) != INTEGER_TYPE)
3682 error ("long, short, signed or unsigned invalid for `%s'", name);
3686 if (!explicit_int && !defaulted_int && !explicit_char)
3688 error ("long, short, signed or unsigned used invalidly for `%s'",
3694 /* Discard the type modifiers if they are invalid. */
3697 specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3698 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
3703 if ((specbits & (1 << (int) RID_COMPLEX))
3704 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
3706 error ("complex invalid for `%s'", name);
3707 specbits &= ~(1 << (int) RID_COMPLEX);
3710 /* Decide whether an integer type is signed or not.
3711 Optionally treat bitfields as signed by default. */
3712 if (specbits & 1 << (int) RID_UNSIGNED
3713 || (bitfield && ! flag_signed_bitfields
3714 && (explicit_int || defaulted_int || explicit_char
3715 /* A typedef for plain `int' without `signed'
3716 can be controlled just like plain `int'. */
3717 || ! (typedef_decl != 0
3718 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
3719 && TREE_CODE (type) != ENUMERAL_TYPE
3720 && !(specbits & 1 << (int) RID_SIGNED)))
3723 type = long_long_unsigned_type_node;
3724 else if (specbits & 1 << (int) RID_LONG)
3725 type = long_unsigned_type_node;
3726 else if (specbits & 1 << (int) RID_SHORT)
3727 type = short_unsigned_type_node;
3728 else if (type == char_type_node)
3729 type = unsigned_char_type_node;
3730 else if (typedef_decl)
3731 type = c_common_unsigned_type (type);
3733 type = unsigned_type_node;
3735 else if ((specbits & 1 << (int) RID_SIGNED)
3736 && type == char_type_node)
3737 type = signed_char_type_node;
3739 type = long_long_integer_type_node;
3740 else if (specbits & 1 << (int) RID_LONG)
3741 type = long_integer_type_node;
3742 else if (specbits & 1 << (int) RID_SHORT)
3743 type = short_integer_type_node;
3745 if (specbits & 1 << (int) RID_COMPLEX)
3747 if (pedantic && !flag_isoc99)
3748 pedwarn ("ISO C90 does not support complex types");
3749 /* If we just have "complex", it is equivalent to
3750 "complex double", but if any modifiers at all are specified it is
3751 the complex form of TYPE. E.g, "complex short" is
3752 "complex short int". */
3754 if (defaulted_int && ! longlong
3755 && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3756 | (1 << (int) RID_SIGNED)
3757 | (1 << (int) RID_UNSIGNED))))
3760 pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
3761 type = complex_double_type_node;
3763 else if (type == integer_type_node)
3766 pedwarn ("ISO C does not support complex integer types");
3767 type = complex_integer_type_node;
3769 else if (type == float_type_node)
3770 type = complex_float_type_node;
3771 else if (type == double_type_node)
3772 type = complex_double_type_node;
3773 else if (type == long_double_type_node)
3774 type = complex_long_double_type_node;
3778 pedwarn ("ISO C does not support complex integer types");
3779 type = build_complex_type (type);
3783 /* Figure out the type qualifiers for the declaration. There are
3784 two ways a declaration can become qualified. One is something
3785 like `const int i' where the `const' is explicit. Another is
3786 something like `typedef const int CI; CI i' where the type of the
3787 declaration contains the `const'. */
3788 constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
3789 restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
3790 volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
3791 inlinep = !! (specbits & (1 << (int) RID_INLINE));
3792 if (constp > 1 && ! flag_isoc99)
3793 pedwarn ("duplicate `const'");
3794 if (restrictp > 1 && ! flag_isoc99)
3795 pedwarn ("duplicate `restrict'");
3796 if (volatilep > 1 && ! flag_isoc99)
3797 pedwarn ("duplicate `volatile'");
3798 if (! flag_gen_aux_info && (TYPE_QUALS (type)))
3799 type = TYPE_MAIN_VARIANT (type);
3800 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
3801 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
3802 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
3804 /* Warn if two storage classes are given. Default to `auto'. */
3809 if (specbits & 1 << (int) RID_AUTO) nclasses++;
3810 if (specbits & 1 << (int) RID_STATIC) nclasses++;
3811 if (specbits & 1 << (int) RID_EXTERN) nclasses++;
3812 if (specbits & 1 << (int) RID_REGISTER) nclasses++;
3813 if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
3815 /* "static __thread" and "extern __thread" are allowed. */
3816 if ((specbits & (1 << (int) RID_THREAD
3817 | 1 << (int) RID_STATIC
3818 | 1 << (int) RID_EXTERN)) == (1 << (int) RID_THREAD))
3821 /* Warn about storage classes that are invalid for certain
3822 kinds of declarations (parameters, typenames, etc.). */
3825 error ("multiple storage classes in declaration of `%s'", name);
3826 else if (funcdef_flag
3828 & ((1 << (int) RID_REGISTER)
3829 | (1 << (int) RID_AUTO)
3830 | (1 << (int) RID_TYPEDEF)
3831 | (1 << (int) RID_THREAD))))
3833 if (specbits & 1 << (int) RID_AUTO
3834 && (pedantic || current_binding_level == global_binding_level))
3835 pedwarn ("function definition declared `auto'");
3836 if (specbits & 1 << (int) RID_REGISTER)
3837 error ("function definition declared `register'");
3838 if (specbits & 1 << (int) RID_TYPEDEF)
3839 error ("function definition declared `typedef'");
3840 if (specbits & 1 << (int) RID_THREAD)
3841 error ("function definition declared `__thread'");
3842 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
3843 | (1 << (int) RID_AUTO) | (1 << (int) RID_THREAD));
3845 else if (decl_context != NORMAL && nclasses > 0)
3847 if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
3851 switch (decl_context)
3854 error ("storage class specified for structure field `%s'",
3858 error ("storage class specified for parameter `%s'", name);
3861 error ("storage class specified for typename");
3864 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
3865 | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
3866 | (1 << (int) RID_EXTERN) | (1 << (int) RID_THREAD));
3869 else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
3871 /* `extern' with initialization is invalid if not at top level. */
3872 if (current_binding_level == global_binding_level)
3873 warning ("`%s' initialized and declared `extern'", name);
3875 error ("`%s' has both `extern' and initializer", name);
3877 else if (current_binding_level == global_binding_level)
3879 if (specbits & 1 << (int) RID_AUTO)
3880 error ("top-level declaration of `%s' specifies `auto'", name);
3884 if (specbits & 1 << (int) RID_EXTERN && funcdef_flag)
3885 error ("nested function `%s' declared `extern'", name);
3886 else if ((specbits & (1 << (int) RID_THREAD
3887 | 1 << (int) RID_EXTERN
3888 | 1 << (int) RID_STATIC))
3889 == (1 << (int) RID_THREAD))
3891 error ("function-scope `%s' implicitly auto and declared `__thread'",
3893 specbits &= ~(1 << (int) RID_THREAD);
3898 /* Now figure out the structure of the declarator proper.
3899 Descend through it, creating more complex types, until we reach
3900 the declared identifier (or NULL_TREE, in an absolute declarator). */
3902 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
3904 if (type == error_mark_node)
3906 declarator = TREE_OPERAND (declarator, 0);
3910 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
3911 an INDIRECT_REF (for *...),
3912 a CALL_EXPR (for ...(...)),
3913 a TREE_LIST (for nested attributes),
3914 an identifier (for the name being declared)
3915 or a null pointer (for the place in an absolute declarator
3916 where the name was omitted).
3917 For the last two cases, we have just exited the loop.
3919 At this point, TYPE is the type of elements of an array,
3920 or for a function to return, or for a pointer to point to.
3921 After this sequence of ifs, TYPE is the type of the
3922 array or function or pointer, and DECLARATOR has had its
3923 outermost layer removed. */
3925 if (array_ptr_quals != NULL_TREE || array_parm_static)
3927 /* Only the innermost declarator (making a parameter be of
3928 array type which is converted to pointer type)
3929 may have static or type qualifiers. */
3930 error ("static or type qualifiers in non-parameter array declarator");
3931 array_ptr_quals = NULL_TREE;
3932 array_parm_static = 0;
3935 if (TREE_CODE (declarator) == TREE_LIST)
3937 /* We encode a declarator with embedded attributes using
3939 tree attrs = TREE_PURPOSE (declarator);
3942 declarator = TREE_VALUE (declarator);
3943 inner_decl = declarator;
3944 while (inner_decl != NULL_TREE
3945 && TREE_CODE (inner_decl) == TREE_LIST)
3946 inner_decl = TREE_VALUE (inner_decl);
3947 if (inner_decl == NULL_TREE
3948 || TREE_CODE (inner_decl) == IDENTIFIER_NODE)
3949 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
3950 else if (TREE_CODE (inner_decl) == CALL_EXPR)
3951 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
3952 else if (TREE_CODE (inner_decl) == ARRAY_REF)
3953 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
3954 returned_attrs = decl_attributes (&type,
3955 chainon (returned_attrs, attrs),
3958 else if (TREE_CODE (declarator) == ARRAY_REF)
3960 tree itype = NULL_TREE;
3961 tree size = TREE_OPERAND (declarator, 1);
3962 /* The index is a signed object `sizetype' bits wide. */
3963 tree index_type = c_common_signed_type (sizetype);
3965 array_ptr_quals = TREE_TYPE (declarator);
3966 array_parm_static = TREE_STATIC (declarator);
3968 declarator = TREE_OPERAND (declarator, 0);
3970 /* Check for some types that there cannot be arrays of. */
3972 if (VOID_TYPE_P (type))
3974 error ("declaration of `%s' as array of voids", name);
3975 type = error_mark_node;
3978 if (TREE_CODE (type) == FUNCTION_TYPE)
3980 error ("declaration of `%s' as array of functions", name);
3981 type = error_mark_node;
3984 if (pedantic && flexible_array_type_p (type))
3985 pedwarn ("invalid use of structure with flexible array member");
3987 if (size == error_mark_node)
3988 type = error_mark_node;
3990 if (type == error_mark_node)
3993 /* If size was specified, set ITYPE to a range-type for that size.
3994 Otherwise, ITYPE remains null. finish_decl may figure it out
3995 from an initial value. */
3999 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4000 STRIP_TYPE_NOPS (size);
4002 if (! INTEGRAL_TYPE_P (TREE_TYPE (size)))
4004 error ("size of array `%s' has non-integer type", name);
4005 size = integer_one_node;
4008 if (pedantic && integer_zerop (size))
4009 pedwarn ("ISO C forbids zero-size array `%s'", name);
4011 if (TREE_CODE (size) == INTEGER_CST)
4013 constant_expression_warning (size);
4014 if (tree_int_cst_sgn (size) < 0)
4016 error ("size of array `%s' is negative", name);
4017 size = integer_one_node;
4022 /* Make sure the array size remains visibly nonconstant
4023 even if it is (eg) a const variable with known value. */
4026 if (!flag_isoc99 && pedantic)
4028 if (TREE_CONSTANT (size))
4029 pedwarn ("ISO C90 forbids array `%s' whose size can't be evaluated",
4032 pedwarn ("ISO C90 forbids variable-size array `%s'",
4037 if (integer_zerop (size))
4039 /* A zero-length array cannot be represented with an
4040 unsigned index type, which is what we'll get with
4041 build_index_type. Create an open-ended range instead. */
4042 itype = build_range_type (sizetype, size, NULL_TREE);
4046 /* Compute the maximum valid index, that is, size - 1.
4047 Do the calculation in index_type, so that if it is
4048 a variable the computations will be done in the
4050 itype = fold (build (MINUS_EXPR, index_type,
4051 convert (index_type, size),
4052 convert (index_type, size_one_node)));
4054 /* If that overflowed, the array is too big.
4055 ??? While a size of INT_MAX+1 technically shouldn't
4056 cause an overflow (because we subtract 1), the overflow
4057 is recorded during the conversion to index_type, before
4058 the subtraction. Handling this case seems like an
4059 unnecessary complication. */
4060 if (TREE_OVERFLOW (itype))
4062 error ("size of array `%s' is too large", name);
4063 type = error_mark_node;
4068 itype = variable_size (itype);
4069 itype = build_index_type (itype);
4072 else if (decl_context == FIELD)
4074 if (pedantic && !flag_isoc99 && !in_system_header)
4075 pedwarn ("ISO C90 does not support flexible array members");
4077 /* ISO C99 Flexible array members are effectively identical
4078 to GCC's zero-length array extension. */
4079 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
4082 /* If pedantic, complain about arrays of incomplete types. */
4084 if (pedantic && !COMPLETE_TYPE_P (type))
4085 pedwarn ("array type has incomplete element type");
4088 /* We shouldn't have a function type here at all!
4089 Functions aren't allowed as array elements. */
4090 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4091 && (constp || volatilep))
4092 pedwarn ("ISO C forbids const or volatile function types");
4095 /* Build the array type itself, then merge any constancy or
4096 volatility into the target type. We must do it in this order
4097 to ensure that the TYPE_MAIN_VARIANT field of the array type
4098 is set correctly. */
4100 type = build_array_type (type, itype);
4102 type = c_build_qualified_type (type, type_quals);
4105 C_TYPE_VARIABLE_SIZE (type) = 1;
4107 /* The GCC extension for zero-length arrays differs from
4108 ISO flexible array members in that sizeof yields zero. */
4109 if (size && integer_zerop (size))
4112 TYPE_SIZE (type) = bitsize_zero_node;
4113 TYPE_SIZE_UNIT (type) = size_zero_node;
4115 if (decl_context != PARM
4116 && (array_ptr_quals != NULL_TREE || array_parm_static))
4118 error ("static or type qualifiers in non-parameter array declarator");
4119 array_ptr_quals = NULL_TREE;
4120 array_parm_static = 0;
4123 else if (TREE_CODE (declarator) == CALL_EXPR)
4127 /* Declaring a function type.
4128 Make sure we have a valid type for the function to return. */
4129 if (type == error_mark_node)
4134 /* Warn about some types functions can't return. */
4136 if (TREE_CODE (type) == FUNCTION_TYPE)
4138 error ("`%s' declared as function returning a function", name);
4139 type = integer_type_node;
4141 if (TREE_CODE (type) == ARRAY_TYPE)
4143 error ("`%s' declared as function returning an array", name);
4144 type = integer_type_node;
4147 /* Construct the function type and go to the next
4148 inner layer of declarator. */
4150 arg_types = grokparms (TREE_OPERAND (declarator, 1),
4152 /* Say it's a definition
4153 only for the CALL_EXPR
4154 closest to the identifier. */
4155 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
4156 /* Type qualifiers before the return type of the function
4157 qualify the return type, not the function type. */
4160 /* Type qualifiers on a function return type are normally
4161 permitted by the standard but have no effect, so give a
4162 warning at -W. Qualifiers on a void return type have
4163 meaning as a GNU extension, and are banned on function
4164 definitions in ISO C. FIXME: strictly we shouldn't
4165 pedwarn for qualified void return types except on function
4166 definitions, but not doing so could lead to the undesirable
4167 state of a "volatile void" function return type not being
4168 warned about, and a use of the function being compiled
4169 with GNU semantics, with no diagnostics under -pedantic. */
4170 if (VOID_TYPE_P (type) && pedantic && !in_system_header)
4171 pedwarn ("ISO C forbids qualified void function return type");
4172 else if (extra_warnings
4173 && !(VOID_TYPE_P (type)
4174 && type_quals == TYPE_QUAL_VOLATILE))
4175 warning ("type qualifiers ignored on function return type");
4177 type = c_build_qualified_type (type, type_quals);
4179 type_quals = TYPE_UNQUALIFIED;
4181 type = build_function_type (type, arg_types);
4182 declarator = TREE_OPERAND (declarator, 0);
4184 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4185 the formal parameter list of this FUNCTION_TYPE to point to
4186 the FUNCTION_TYPE node itself. */
4191 for (link = last_function_parm_tags;
4193 link = TREE_CHAIN (link))
4194 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4197 else if (TREE_CODE (declarator) == INDIRECT_REF)
4199 /* Merge any constancy or volatility into the target type
4202 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4204 pedwarn ("ISO C forbids qualified function types");
4206 type = c_build_qualified_type (type, type_quals);
4207 type_quals = TYPE_UNQUALIFIED;
4210 type = build_pointer_type (type);
4212 /* Process a list of type modifier keywords
4213 (such as const or volatile) that were given inside the `*'. */
4215 if (TREE_TYPE (declarator))
4223 for (typemodlist = TREE_TYPE (declarator); typemodlist;
4224 typemodlist = TREE_CHAIN (typemodlist))
4226 tree qualifier = TREE_VALUE (typemodlist);
4228 if (C_IS_RESERVED_WORD (qualifier))
4230 if (C_RID_CODE (qualifier) == RID_CONST)
4232 else if (C_RID_CODE (qualifier) == RID_VOLATILE)
4234 else if (C_RID_CODE (qualifier) == RID_RESTRICT)
4244 error ("invalid type modifier within pointer declarator");
4245 if (constp > 1 && ! flag_isoc99)
4246 pedwarn ("duplicate `const'");
4247 if (volatilep > 1 && ! flag_isoc99)
4248 pedwarn ("duplicate `volatile'");
4249 if (restrictp > 1 && ! flag_isoc99)
4250 pedwarn ("duplicate `restrict'");
4252 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4253 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4254 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4257 declarator = TREE_OPERAND (declarator, 0);
4264 /* Now TYPE has the actual type. */
4266 /* Did array size calculations overflow? */
4268 if (TREE_CODE (type) == ARRAY_TYPE
4269 && COMPLETE_TYPE_P (type)
4270 && TREE_OVERFLOW (TYPE_SIZE (type)))
4272 error ("size of array `%s' is too large", name);
4273 /* If we proceed with the array type as it is, we'll eventually
4274 crash in tree_low_cst(). */
4275 type = error_mark_node;
4278 /* If this is declaring a typedef name, return a TYPE_DECL. */
4280 if (specbits & (1 << (int) RID_TYPEDEF))
4283 /* Note that the grammar rejects storage classes
4284 in typenames, fields or parameters */
4285 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4287 pedwarn ("ISO C forbids qualified function types");
4289 type = c_build_qualified_type (type, type_quals);
4290 decl = build_decl (TYPE_DECL, declarator, type);
4291 if ((specbits & (1 << (int) RID_SIGNED))
4292 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4293 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4294 decl_attributes (&decl, returned_attrs, 0);
4298 /* Detect the case of an array type of unspecified size
4299 which came, as such, direct from a typedef name.
4300 We must copy the type, so that each identifier gets
4301 a distinct type, so that each identifier's size can be
4302 controlled separately by its own initializer. */
4304 if (type != 0 && typedef_type != 0
4305 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
4306 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
4308 type = build_array_type (TREE_TYPE (type), 0);
4310 C_TYPE_VARIABLE_SIZE (type) = 1;
4313 /* If this is a type name (such as, in a cast or sizeof),
4314 compute the type and return it now. */
4316 if (decl_context == TYPENAME)
4318 /* Note that the grammar rejects storage classes
4319 in typenames, fields or parameters */
4320 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4322 pedwarn ("ISO C forbids const or volatile function types");
4324 type = c_build_qualified_type (type, type_quals);
4325 decl_attributes (&type, returned_attrs, 0);
4329 /* Aside from typedefs and type names (handle above),
4330 `void' at top level (not within pointer)
4331 is allowed only in public variables.
4332 We don't complain about parms either, but that is because
4333 a better error message can be made later. */
4335 if (VOID_TYPE_P (type) && decl_context != PARM
4336 && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4337 && ((specbits & (1 << (int) RID_EXTERN))
4338 || (current_binding_level == global_binding_level
4340 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
4342 error ("variable or field `%s' declared void", name);
4343 type = integer_type_node;
4346 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4347 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4352 if (decl_context == PARM)
4354 tree type_as_written;
4357 /* A parameter declared as an array of T is really a pointer to T.
4358 One declared as a function is really a pointer to a function. */
4360 if (TREE_CODE (type) == ARRAY_TYPE)
4362 /* Transfer const-ness of array into that of type pointed to. */
4363 type = TREE_TYPE (type);
4365 type = c_build_qualified_type (type, type_quals);
4366 type = build_pointer_type (type);
4367 type_quals = TYPE_UNQUALIFIED;
4368 if (array_ptr_quals)
4370 tree new_ptr_quals, new_ptr_attrs;
4372 split_specs_attrs (array_ptr_quals, &new_ptr_quals, &new_ptr_attrs);
4373 /* We don't yet implement attributes in this context. */
4374 if (new_ptr_attrs != NULL_TREE)
4375 warning ("attributes in parameter array declarator ignored");
4380 for (; new_ptr_quals; new_ptr_quals = TREE_CHAIN (new_ptr_quals))
4382 tree qualifier = TREE_VALUE (new_ptr_quals);
4384 if (C_IS_RESERVED_WORD (qualifier))
4386 if (C_RID_CODE (qualifier) == RID_CONST)
4388 else if (C_RID_CODE (qualifier) == RID_VOLATILE)
4390 else if (C_RID_CODE (qualifier) == RID_RESTRICT)
4400 error ("invalid type modifier within array declarator");
4402 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4403 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4404 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4408 else if (TREE_CODE (type) == FUNCTION_TYPE)
4410 if (pedantic && type_quals)
4411 pedwarn ("ISO C forbids qualified function types");
4413 type = c_build_qualified_type (type, type_quals);
4414 type = build_pointer_type (type);
4415 type_quals = TYPE_UNQUALIFIED;
4417 else if (type_quals)
4418 type = c_build_qualified_type (type, type_quals);
4420 type_as_written = type;
4422 decl = build_decl (PARM_DECL, declarator, type);
4424 C_DECL_VARIABLE_SIZE (decl) = 1;
4426 /* Compute the type actually passed in the parmlist,
4427 for the case where there is no prototype.
4428 (For example, shorts and chars are passed as ints.)
4429 When there is a prototype, this is overridden later. */
4431 if (type == error_mark_node)
4432 promoted_type = type;
4434 promoted_type = c_type_promotes_to (type);
4436 DECL_ARG_TYPE (decl) = promoted_type;
4437 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
4439 else if (decl_context == FIELD)
4441 /* Structure field. It may not be a function. */
4443 if (TREE_CODE (type) == FUNCTION_TYPE)
4445 error ("field `%s' declared as a function", name);
4446 type = build_pointer_type (type);
4448 else if (TREE_CODE (type) != ERROR_MARK
4449 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
4451 error ("field `%s' has incomplete type", name);
4452 type = error_mark_node;
4454 /* Move type qualifiers down to element of an array. */
4455 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4457 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4459 TYPE_DOMAIN (type));
4461 /* Leave the field const or volatile as well. */
4462 type_quals = TYPE_UNQUALIFIED;
4465 decl = build_decl (FIELD_DECL, declarator, type);
4466 DECL_NONADDRESSABLE_P (decl) = bitfield;
4469 C_DECL_VARIABLE_SIZE (decl) = 1;
4471 else if (TREE_CODE (type) == FUNCTION_TYPE)
4473 /* Every function declaration is "external"
4474 except for those which are inside a function body
4475 in which `auto' is used.
4476 That is a case not specified by ANSI C,
4477 and we use it for forward declarations for nested functions. */
4478 int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
4479 || current_binding_level == global_binding_level);
4481 if (specbits & (1 << (int) RID_AUTO)
4482 && (pedantic || current_binding_level == global_binding_level))
4483 pedwarn ("invalid storage class for function `%s'", name);
4484 if (specbits & (1 << (int) RID_REGISTER))
4485 error ("invalid storage class for function `%s'", name);
4486 if (specbits & (1 << (int) RID_THREAD))
4487 error ("invalid storage class for function `%s'", name);
4488 /* Function declaration not at top level.
4489 Storage classes other than `extern' are not allowed
4490 and `extern' makes no difference. */
4491 if (current_binding_level != global_binding_level
4492 && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
4494 pedwarn ("invalid storage class for function `%s'", name);
4496 decl = build_decl (FUNCTION_DECL, declarator, type);
4497 decl = build_decl_attribute_variant (decl, decl_attr);
4499 DECL_LANG_SPECIFIC (decl) = (struct lang_decl *)
4500 ggc_alloc_cleared (sizeof (struct lang_decl));
4502 if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
4503 pedwarn ("ISO C forbids qualified function types");
4505 /* GNU C interprets a `volatile void' return type to indicate
4506 that the function does not return. */
4507 if ((type_quals & TYPE_QUAL_VOLATILE)
4508 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
4509 warning ("`noreturn' function returns non-void value");
4512 DECL_EXTERNAL (decl) = 1;
4513 /* Record absence of global scope for `static' or `auto'. */
4515 = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
4518 C_FUNCTION_IMPLICIT_INT (decl) = 1;
4520 /* Record presence of `inline', if it is reasonable. */
4521 if (MAIN_NAME_P (declarator))
4524 warning ("cannot inline function `main'");
4528 /* Assume that otherwise the function can be inlined. */
4529 DECL_DECLARED_INLINE_P (decl) = 1;
4531 /* Do not mark bare declarations as DECL_INLINE. Doing so
4532 in the presence of multiple declarations can result in
4533 the abstract origin pointing between the declarations,
4534 which will confuse dwarf2out. */
4537 DECL_INLINE (decl) = 1;
4538 if (specbits & (1 << (int) RID_EXTERN))
4539 current_extern_inline = 1;
4542 /* If -finline-functions, assume it can be inlined. This does
4543 two things: let the function be deferred until it is actually
4544 needed, and let dwarf2 know that the function is inlinable. */
4545 else if (flag_inline_trees == 2 && initialized)
4547 DECL_INLINE (decl) = 1;
4548 DECL_DECLARED_INLINE_P (decl) = 0;
4553 /* It's a variable. */
4554 /* An uninitialized decl with `extern' is a reference. */
4555 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
4557 /* Move type qualifiers down to element of an array. */
4558 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4560 int saved_align = TYPE_ALIGN(type);
4561 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4563 TYPE_DOMAIN (type));
4564 TYPE_ALIGN (type) = saved_align;
4565 #if 0 /* Leave the variable const or volatile as well. */
4566 type_quals = TYPE_UNQUALIFIED;
4569 else if (type_quals)
4570 type = c_build_qualified_type (type, type_quals);
4572 decl = build_decl (VAR_DECL, declarator, type);
4574 C_DECL_VARIABLE_SIZE (decl) = 1;
4577 pedwarn_with_decl (decl, "variable `%s' declared `inline'");
4579 DECL_EXTERNAL (decl) = extern_ref;
4581 /* At top level, the presence of a `static' or `register' storage
4582 class specifier, or the absence of all storage class specifiers
4583 makes this declaration a definition (perhaps tentative). Also,
4584 the absence of both `static' and `register' makes it public. */
4585 if (current_binding_level == global_binding_level)
4587 TREE_PUBLIC (decl) = !(specbits & ((1 << (int) RID_STATIC)
4588 | (1 << (int) RID_REGISTER)));
4589 TREE_STATIC (decl) = !extern_ref;
4591 /* Not at top level, only `static' makes a static definition. */
4594 TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
4595 TREE_PUBLIC (decl) = extern_ref;
4598 if (specbits & 1 << (int) RID_THREAD)
4600 if (targetm.have_tls)
4601 DECL_THREAD_LOCAL (decl) = 1;
4603 /* A mere warning is sure to result in improper semantics
4604 at runtime. Don't bother to allow this to compile. */
4605 error ("thread-local storage not supported for this target");
4609 /* Record `register' declaration for warnings on &
4610 and in case doing stupid register allocation. */
4612 if (specbits & (1 << (int) RID_REGISTER))
4613 DECL_REGISTER (decl) = 1;
4615 /* Record constancy and volatility. */
4616 c_apply_type_quals_to_decl (type_quals, decl);
4618 /* If a type has volatile components, it should be stored in memory.
4619 Otherwise, the fact that those components are volatile
4620 will be ignored, and would even crash the compiler. */
4621 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
4622 c_mark_addressable (decl);
4624 decl_attributes (&decl, returned_attrs, 0);
4630 /* Decode the parameter-list info for a function type or function definition.
4631 The argument is the value returned by `get_parm_info' (or made in parse.y
4632 if there is an identifier list instead of a parameter decl list).
4633 These two functions are separate because when a function returns
4634 or receives functions then each is called multiple times but the order
4635 of calls is different. The last call to `grokparms' is always the one
4636 that contains the formal parameter names of a function definition.
4638 Store in `last_function_parms' a chain of the decls of parms.
4639 Also store in `last_function_parm_tags' a chain of the struct, union,
4640 and enum tags declared among the parms.
4642 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4644 FUNCDEF_FLAG is nonzero for a function definition, 0 for
4645 a mere declaration. A nonempty identifier-list gets an error message
4646 when FUNCDEF_FLAG is zero. */
4649 grokparms (parms_info, funcdef_flag)
4653 tree first_parm = TREE_CHAIN (parms_info);
4655 last_function_parms = TREE_PURPOSE (parms_info);
4656 last_function_parm_tags = TREE_VALUE (parms_info);
4658 if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
4659 && !in_system_header)
4660 warning ("function declaration isn't a prototype");
4663 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
4666 pedwarn ("parameter names (without types) in function declaration");
4668 last_function_parms = first_parm;
4675 /* We no longer test FUNCDEF_FLAG.
4676 If the arg types are incomplete in a declaration,
4677 they must include undefined tags.
4678 These tags can never be defined in the scope of the declaration,
4679 so the types can never be completed,
4680 and no call can be compiled successfully. */
4682 /* In a fcn definition, arg types must be complete. */
4685 for (parm = last_function_parms, typelt = first_parm;
4687 parm = TREE_CHAIN (parm))
4688 /* Skip over any enumeration constants declared here. */
4689 if (TREE_CODE (parm) == PARM_DECL)
4691 /* Barf if the parameter itself has an incomplete type. */
4692 tree type = TREE_VALUE (typelt);
4693 if (type == error_mark_node)
4695 if (!COMPLETE_TYPE_P (type))
4697 if (funcdef_flag && DECL_NAME (parm) != 0)
4698 error ("parameter `%s' has incomplete type",
4699 IDENTIFIER_POINTER (DECL_NAME (parm)));
4701 warning ("parameter has incomplete type");
4704 TREE_VALUE (typelt) = error_mark_node;
4705 TREE_TYPE (parm) = error_mark_node;
4709 /* This has been replaced by parm_tags_warning, which
4710 uses a more accurate criterion for what to warn
4714 /* Now warn if is a pointer to an incomplete type. */
4715 while (TREE_CODE (type) == POINTER_TYPE
4716 || TREE_CODE (type) == REFERENCE_TYPE)
4717 type = TREE_TYPE (type);
4718 type = TYPE_MAIN_VARIANT (type);
4719 if (!COMPLETE_TYPE_P (type))
4721 if (DECL_NAME (parm) != 0)
4722 warning ("parameter `%s' points to incomplete type",
4723 IDENTIFIER_POINTER (DECL_NAME (parm)));
4725 warning ("parameter points to incomplete type");
4729 typelt = TREE_CHAIN (typelt);
4736 /* Return a tree_list node with info on a parameter list just parsed.
4737 The TREE_PURPOSE is a chain of decls of those parms.
4738 The TREE_VALUE is a list of structure, union and enum tags defined.
4739 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
4740 This tree_list node is later fed to `grokparms'.
4742 VOID_AT_END nonzero means append `void' to the end of the type-list.
4743 Zero means the parmlist ended with an ellipsis so don't append `void'. */
4746 get_parm_info (void_at_end)
4752 tree tags = gettags ();
4753 tree parms = getdecls ();
4755 tree order = current_binding_level->parm_order;
4757 /* Just `void' (and no ellipsis) is special. There are really no parms.
4758 But if the `void' is qualified (by `const' or `volatile') or has a
4759 storage class specifier (`register'), then the behavior is undefined;
4760 by not counting it as the special case of `void' we will cause an
4761 error later. Typedefs for `void' are OK (see DR#157). */
4762 if (void_at_end && parms != 0
4763 && TREE_CHAIN (parms) == 0
4764 && VOID_TYPE_P (TREE_TYPE (parms))
4765 && ! TREE_THIS_VOLATILE (parms)
4766 && ! TREE_READONLY (parms)
4767 && ! DECL_REGISTER (parms)
4768 && DECL_NAME (parms) == 0)
4771 storedecls (NULL_TREE);
4772 return tree_cons (NULL_TREE, NULL_TREE,
4773 tree_cons (NULL_TREE, void_type_node, NULL_TREE));
4776 /* Extract enumerator values and other non-parms declared with the parms.
4777 Likewise any forward parm decls that didn't have real parm decls. */
4778 for (decl = parms; decl;)
4780 tree next = TREE_CHAIN (decl);
4782 if (TREE_CODE (decl) != PARM_DECL)
4784 TREE_CHAIN (decl) = new_parms;
4787 else if (TREE_ASM_WRITTEN (decl))
4789 error_with_decl (decl,
4790 "parameter `%s' has just a forward declaration");
4791 TREE_CHAIN (decl) = new_parms;
4797 /* Put the parm decls back in the order they were in in the parm list. */
4798 for (t = order; t; t = TREE_CHAIN (t))
4801 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
4803 TREE_CHAIN (TREE_VALUE (t)) = 0;
4806 new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
4809 /* Store the parmlist in the binding level since the old one
4810 is no longer a valid list. (We have changed the chain pointers.) */
4811 storedecls (new_parms);
4813 for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
4814 /* There may also be declarations for enumerators if an enumeration
4815 type is declared among the parms. Ignore them here. */
4816 if (TREE_CODE (decl) == PARM_DECL)
4818 /* Since there is a prototype,
4819 args are passed in their declared types. */
4820 tree type = TREE_TYPE (decl);
4821 DECL_ARG_TYPE (decl) = type;
4822 if (PROMOTE_PROTOTYPES
4823 && INTEGRAL_TYPE_P (type)
4824 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
4825 DECL_ARG_TYPE (decl) = integer_type_node;
4827 types = tree_cons (NULL_TREE, TREE_TYPE (decl), types);
4828 if (VOID_TYPE_P (TREE_VALUE (types)) && ! erred
4829 && DECL_NAME (decl) == 0)
4831 error ("`void' in parameter list must be the entire list");
4837 return tree_cons (new_parms, tags,
4838 nreverse (tree_cons (NULL_TREE, void_type_node, types)));
4840 return tree_cons (new_parms, tags, nreverse (types));
4843 /* At end of parameter list, warn about any struct, union or enum tags
4844 defined within. Do so because these types cannot ever become complete. */
4847 parmlist_tags_warning ()
4852 for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
4854 enum tree_code code = TREE_CODE (TREE_VALUE (elt));
4855 /* An anonymous union parm type is meaningful as a GNU extension.
4856 So don't warn for that. */
4857 if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic)
4859 if (TREE_PURPOSE (elt) != 0)
4861 if (code == RECORD_TYPE)
4862 warning ("`struct %s' declared inside parameter list",
4863 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4864 else if (code == UNION_TYPE)
4865 warning ("`union %s' declared inside parameter list",
4866 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4868 warning ("`enum %s' declared inside parameter list",
4869 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4873 /* For translation these need to be separate warnings */
4874 if (code == RECORD_TYPE)
4875 warning ("anonymous struct declared inside parameter list");
4876 else if (code == UNION_TYPE)
4877 warning ("anonymous union declared inside parameter list");
4879 warning ("anonymous enum declared inside parameter list");
4883 warning ("its scope is only this definition or declaration, which is probably not what you want");
4889 /* Get the struct, enum or union (CODE says which) with tag NAME.
4890 Define the tag as a forward-reference if it is not defined. */
4893 xref_tag (code, name)
4894 enum tree_code code;
4897 /* If a cross reference is requested, look up the type
4898 already defined for this tag and return it. */
4900 tree ref = lookup_tag (code, name, current_binding_level, 0);
4901 /* If this is the right type of tag, return what we found.
4902 (This reference will be shadowed by shadow_tag later if appropriate.)
4903 If this is the wrong type of tag, do not return it. If it was the
4904 wrong type in the same binding level, we will have had an error
4905 message already; if in a different binding level and declaring
4906 a name, pending_xref_error will give an error message; but if in a
4907 different binding level and not declaring a name, this tag should
4908 shadow the previous declaration of a different type of tag, and
4909 this would not work properly if we return the reference found.
4910 (For example, with "struct foo" in an outer scope, "union foo;"
4911 must shadow that tag with a new one of union type.) */
4912 if (ref && TREE_CODE (ref) == code)
4915 /* If no such tag is yet defined, create a forward-reference node
4916 and record it as the "definition".
4917 When a real declaration of this type is found,
4918 the forward-reference will be altered into a real type. */
4920 ref = make_node (code);
4921 if (code == ENUMERAL_TYPE)
4923 /* Give the type a default layout like unsigned int
4924 to avoid crashing if it does not get defined. */
4925 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
4926 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
4927 TYPE_USER_ALIGN (ref) = 0;
4928 TREE_UNSIGNED (ref) = 1;
4929 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
4930 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
4931 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
4934 pushtag (name, ref);
4939 /* Make sure that the tag NAME is defined *in the current binding level*
4940 at least as a forward reference.
4941 CODE says which kind of tag NAME ought to be. */
4944 start_struct (code, name)
4945 enum tree_code code;
4948 /* If there is already a tag defined at this binding level
4949 (as a forward reference), just return it. */
4954 ref = lookup_tag (code, name, current_binding_level, 1);
4955 if (ref && TREE_CODE (ref) == code)
4957 if (TYPE_FIELDS (ref))
4959 if (code == UNION_TYPE)
4960 error ("redefinition of `union %s'", IDENTIFIER_POINTER (name));
4962 error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name));
4967 /* Otherwise create a forward-reference just so the tag is in scope. */
4969 ref = make_node (code);
4970 pushtag (name, ref);
4973 C_TYPE_BEING_DEFINED (ref) = 1;
4974 TYPE_PACKED (ref) = flag_pack_struct;
4978 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
4979 of a structure component, returning a FIELD_DECL node.
4980 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
4982 This is done during the parsing of the struct declaration.
4983 The FIELD_DECL nodes are chained together and the lot of them
4984 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
4987 grokfield (filename, line, declarator, declspecs, width)
4988 const char *filename ATTRIBUTE_UNUSED;
4989 int line ATTRIBUTE_UNUSED;
4990 tree declarator, declspecs, width;
4994 if (declarator == NULL_TREE && width == NULL_TREE)
4996 /* This is an unnamed decl.
4998 If we have something of the form "union { list } ;" then this
4999 is the anonymous union extension. Similarly for struct.
5001 If this is something of the form "struct foo;", then
5002 If MS extensions are enabled, this is handled as an
5004 Otherwise this is a forward declaration of a structure tag.
5006 If this is something of the form "foo;" and foo is a TYPE_DECL, then
5007 If MS extensions are enabled and foo names a structure, then
5008 again this is an anonymous struct.
5009 Otherwise this is an error.
5011 Oh what a horrid tangled web we weave. I wonder if MS consiously
5012 took this from Plan 9 or if it was an accident of implementation
5013 that took root before someone noticed the bug... */
5015 tree type = TREE_VALUE (declspecs);
5017 if (flag_ms_extensions && TREE_CODE (type) == TYPE_DECL)
5018 type = TREE_TYPE (type);
5019 if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE)
5021 if (flag_ms_extensions)
5024 goto warn_unnamed_field;
5025 else if (TYPE_NAME (type) == NULL)
5028 goto warn_unnamed_field;
5033 warning ("declaration does not declare anything");
5038 value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
5040 finish_decl (value, NULL_TREE, NULL_TREE);
5041 DECL_INITIAL (value) = width;
5044 objc_check_decl (value);
5048 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5049 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5050 ATTRIBUTES are attributes to be applied to the structure. */
5053 finish_struct (t, fieldlist, attributes)
5059 int toplevel = global_binding_level == current_binding_level;
5060 int saw_named_field;
5062 /* If this type was previously laid out as a forward reference,
5063 make sure we lay it out again. */
5067 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5069 /* Nameless union parm types are useful as GCC extension. */
5070 if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
5071 /* Otherwise, warn about any struct or union def. in parmlist. */
5072 if (in_parm_level_p ())
5075 pedwarn ("%s defined inside parms",
5076 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure"));
5078 warning ("%s defined inside parms",
5079 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure"));
5084 for (x = fieldlist; x; x = TREE_CHAIN (x))
5085 if (DECL_NAME (x) != 0)
5089 pedwarn ("%s has no %s",
5090 TREE_CODE (t) == UNION_TYPE ? _("union") : _("struct"),
5091 fieldlist ? _("named members") : _("members"));
5094 /* Install struct as DECL_CONTEXT of each field decl.
5095 Also process specified field sizes,m which is found in the DECL_INITIAL.
5096 Store 0 there, except for ": 0" fields (so we can find them
5097 and delete them, below). */
5099 saw_named_field = 0;
5100 for (x = fieldlist; x; x = TREE_CHAIN (x))
5102 DECL_CONTEXT (x) = t;
5103 DECL_PACKED (x) |= TYPE_PACKED (t);
5105 /* If any field is const, the structure type is pseudo-const. */
5106 if (TREE_READONLY (x))
5107 C_TYPE_FIELDS_READONLY (t) = 1;
5110 /* A field that is pseudo-const makes the structure likewise. */
5111 tree t1 = TREE_TYPE (x);
5112 while (TREE_CODE (t1) == ARRAY_TYPE)
5113 t1 = TREE_TYPE (t1);
5114 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5115 && C_TYPE_FIELDS_READONLY (t1))
5116 C_TYPE_FIELDS_READONLY (t) = 1;
5119 /* Any field that is volatile means variables of this type must be
5120 treated in some ways as volatile. */
5121 if (TREE_THIS_VOLATILE (x))
5122 C_TYPE_FIELDS_VOLATILE (t) = 1;
5124 /* Any field of nominal variable size implies structure is too. */
5125 if (C_DECL_VARIABLE_SIZE (x))
5126 C_TYPE_VARIABLE_SIZE (t) = 1;
5128 /* Detect invalid nested redefinition. */
5129 if (TREE_TYPE (x) == t)
5130 error ("nested redefinition of `%s'",
5131 IDENTIFIER_POINTER (TYPE_NAME (t)));
5133 /* Detect invalid bit-field size. */
5134 if (DECL_INITIAL (x))
5135 STRIP_NOPS (DECL_INITIAL (x));
5136 if (DECL_INITIAL (x))
5138 if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST)
5139 constant_expression_warning (DECL_INITIAL (x));
5143 "bit-field `%s' width not an integer constant");
5144 DECL_INITIAL (x) = NULL;
5148 /* Detect invalid bit-field type. */
5149 if (DECL_INITIAL (x)
5150 && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
5151 && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE
5152 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
5154 error_with_decl (x, "bit-field `%s' has invalid type");
5155 DECL_INITIAL (x) = NULL;
5158 if (DECL_INITIAL (x) && pedantic
5159 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
5160 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
5161 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node
5162 /* Accept an enum that's equivalent to int or unsigned int. */
5163 && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5164 && (TYPE_PRECISION (TREE_TYPE (x))
5165 == TYPE_PRECISION (integer_type_node))))
5166 pedwarn_with_decl (x, "bit-field `%s' type invalid in ISO C");
5168 /* Detect and ignore out of range field width and process valid
5170 if (DECL_INITIAL (x))
5173 = (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node
5174 ? CHAR_TYPE_SIZE : TYPE_PRECISION (TREE_TYPE (x)));
5176 if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
5177 error_with_decl (x, "negative width in bit-field `%s'");
5178 else if (0 < compare_tree_int (DECL_INITIAL (x), max_width))
5179 pedwarn_with_decl (x, "width of `%s' exceeds its type");
5180 else if (integer_zerop (DECL_INITIAL (x)) && DECL_NAME (x) != 0)
5181 error_with_decl (x, "zero width for bit-field `%s'");
5184 /* The test above has assured us that TREE_INT_CST_HIGH is 0. */
5185 unsigned HOST_WIDE_INT width
5186 = tree_low_cst (DECL_INITIAL (x), 1);
5188 if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5189 && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
5190 TREE_UNSIGNED (TREE_TYPE (x)))
5192 < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
5193 TREE_UNSIGNED (TREE_TYPE (x))))))
5194 warning_with_decl (x,
5195 "`%s' is narrower than values of its type");
5197 DECL_SIZE (x) = bitsize_int (width);
5198 DECL_BIT_FIELD (x) = 1;
5199 SET_DECL_C_BIT_FIELD (x);
5202 && ! (* targetm.ms_bitfield_layout_p) (t))
5204 /* field size 0 => force desired amount of alignment. */
5205 #ifdef EMPTY_FIELD_BOUNDARY
5206 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
5208 #ifdef PCC_BITFIELD_TYPE_MATTERS
5209 if (PCC_BITFIELD_TYPE_MATTERS)
5211 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
5212 TYPE_ALIGN (TREE_TYPE (x)));
5213 DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
5220 else if (TREE_TYPE (x) != error_mark_node)
5222 unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
5223 : TYPE_ALIGN (TREE_TYPE (x)));
5225 /* Non-bit-fields are aligned for their type, except packed
5226 fields which require only BITS_PER_UNIT alignment. */
5227 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
5228 if (! DECL_PACKED (x))
5229 DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
5232 DECL_INITIAL (x) = 0;
5234 /* Detect flexible array member in an invalid context. */
5235 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5236 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
5237 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
5238 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
5240 if (TREE_CODE (t) == UNION_TYPE)
5241 error_with_decl (x, "flexible array member in union");
5242 else if (TREE_CHAIN (x) != NULL_TREE)
5243 error_with_decl (x, "flexible array member not at end of struct");
5244 else if (! saw_named_field)
5245 error_with_decl (x, "flexible array member in otherwise empty struct");
5248 if (pedantic && TREE_CODE (t) == RECORD_TYPE
5249 && flexible_array_type_p (TREE_TYPE (x)))
5250 pedwarn_with_decl (x, "invalid use of structure with flexible array member");
5253 saw_named_field = 1;
5256 /* Delete all duplicate fields from the fieldlist */
5257 for (x = fieldlist; x && TREE_CHAIN (x);)
5258 /* Anonymous fields aren't duplicates. */
5259 if (DECL_NAME (TREE_CHAIN (x)) == 0)
5267 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
5273 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
5275 error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
5276 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
5282 /* Now we have the nearly final fieldlist. Record it,
5283 then lay out the structure or union (including the fields). */
5285 TYPE_FIELDS (t) = fieldlist;
5289 /* Delete all zero-width bit-fields from the fieldlist */
5291 tree *fieldlistp = &fieldlist;
5293 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
5294 *fieldlistp = TREE_CHAIN (*fieldlistp);
5296 fieldlistp = &TREE_CHAIN (*fieldlistp);
5299 /* Now we have the truly final field list.
5300 Store it in this type and in the variants. */
5302 TYPE_FIELDS (t) = fieldlist;
5304 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5306 TYPE_FIELDS (x) = TYPE_FIELDS (t);
5307 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
5308 TYPE_ALIGN (x) = TYPE_ALIGN (t);
5309 TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t);
5312 /* If this was supposed to be a transparent union, but we can't
5313 make it one, warn and turn off the flag. */
5314 if (TREE_CODE (t) == UNION_TYPE
5315 && TYPE_TRANSPARENT_UNION (t)
5316 && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))
5318 TYPE_TRANSPARENT_UNION (t) = 0;
5319 warning ("union cannot be made transparent");
5322 /* If this structure or union completes the type of any previous
5323 variable declaration, lay it out and output its rtl. */
5325 if (current_binding_level->incomplete_list != NULL_TREE)
5327 tree prev = NULL_TREE;
5329 for (x = current_binding_level->incomplete_list; x; x = TREE_CHAIN (x))
5331 tree decl = TREE_VALUE (x);
5333 if (TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TYPE_MAIN_VARIANT (t)
5334 && TREE_CODE (decl) != TYPE_DECL)
5336 layout_decl (decl, 0);
5337 /* This is a no-op in c-lang.c or something real in objc-act.c. */
5339 objc_check_decl (decl);
5340 rest_of_decl_compilation (decl, NULL, toplevel, 0);
5343 /* Unlink X from the incomplete list. */
5345 TREE_CHAIN (prev) = TREE_CHAIN (x);
5347 current_binding_level->incomplete_list = TREE_CHAIN (x);
5349 else if (!COMPLETE_TYPE_P (TREE_TYPE (decl))
5350 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
5352 tree element = TREE_TYPE (decl);
5353 while (TREE_CODE (element) == ARRAY_TYPE)
5354 element = TREE_TYPE (element);
5357 layout_array_type (TREE_TYPE (decl));
5358 if (TREE_CODE (decl) != TYPE_DECL)
5360 layout_decl (decl, 0);
5362 objc_check_decl (decl);
5363 rest_of_decl_compilation (decl, NULL, toplevel, 0);
5367 /* Unlink X from the incomplete list. */
5369 TREE_CHAIN (prev) = TREE_CHAIN (x);
5371 current_binding_level->incomplete_list = TREE_CHAIN (x);
5377 /* Finish debugging output for this type. */
5378 rest_of_type_compilation (t, toplevel);
5383 /* Lay out the type T, and its element type, and so on. */
5386 layout_array_type (t)
5389 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5390 layout_array_type (TREE_TYPE (t));
5394 /* Begin compiling the definition of an enumeration type.
5395 NAME is its name (or null if anonymous).
5396 Returns the type object, as yet incomplete.
5397 Also records info about it so that build_enumerator
5398 may be used to declare the individual values as they are read. */
5406 /* If this is the real definition for a previous forward reference,
5407 fill in the contents in the same object that used to be the
5408 forward reference. */
5411 enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
5413 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
5415 enumtype = make_node (ENUMERAL_TYPE);
5416 pushtag (name, enumtype);
5419 C_TYPE_BEING_DEFINED (enumtype) = 1;
5421 if (TYPE_VALUES (enumtype) != 0)
5423 /* This enum is a named one that has been declared already. */
5424 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
5426 /* Completely replace its old definition.
5427 The old enumerators remain defined, however. */
5428 TYPE_VALUES (enumtype) = 0;
5431 enum_next_value = integer_zero_node;
5434 if (flag_short_enums)
5435 TYPE_PACKED (enumtype) = 1;
5440 /* After processing and defining all the values of an enumeration type,
5441 install their decls in the enumeration type and finish it off.
5442 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5443 and ATTRIBUTES are the specified attributes.
5444 Returns ENUMTYPE. */
5447 finish_enum (enumtype, values, attributes)
5453 tree minnode = 0, maxnode = 0, enum_value_type;
5454 int precision, unsign;
5455 int toplevel = (global_binding_level == current_binding_level);
5457 if (in_parm_level_p ())
5458 warning ("enum defined inside parms");
5460 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5462 /* Calculate the maximum value of any enumerator in this type. */
5464 if (values == error_mark_node)
5465 minnode = maxnode = integer_zero_node;
5468 minnode = maxnode = TREE_VALUE (values);
5469 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
5471 tree value = TREE_VALUE (pair);
5472 if (tree_int_cst_lt (maxnode, value))
5474 if (tree_int_cst_lt (value, minnode))
5479 /* Construct the final type of this enumeration. It is the same
5480 as one of the integral types - the narrowest one that fits, except
5481 that normally we only go as narrow as int - and signed iff any of
5482 the values are negative. */
5483 unsign = (tree_int_cst_sgn (minnode) >= 0);
5484 precision = MAX (min_precision (minnode, unsign),
5485 min_precision (maxnode, unsign));
5486 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
5488 tree narrowest = c_common_type_for_size (precision, unsign);
5491 warning ("enumeration values exceed range of largest integer");
5492 narrowest = long_long_integer_type_node;
5495 precision = TYPE_PRECISION (narrowest);
5498 precision = TYPE_PRECISION (integer_type_node);
5500 if (precision == TYPE_PRECISION (integer_type_node))
5501 enum_value_type = c_common_type_for_size (precision, 0);
5503 enum_value_type = enumtype;
5505 TYPE_MIN_VALUE (enumtype) = minnode;
5506 TYPE_MAX_VALUE (enumtype) = maxnode;
5507 TYPE_PRECISION (enumtype) = precision;
5508 TREE_UNSIGNED (enumtype) = unsign;
5509 TYPE_SIZE (enumtype) = 0;
5510 layout_type (enumtype);
5512 if (values != error_mark_node)
5514 /* Change the type of the enumerators to be the enum type. We
5515 need to do this irrespective of the size of the enum, for
5516 proper type checking. Replace the DECL_INITIALs of the
5517 enumerators, and the value slots of the list, with copies
5518 that have the enum type; they cannot be modified in place
5519 because they may be shared (e.g. integer_zero_node) Finally,
5520 change the purpose slots to point to the names of the decls. */
5521 for (pair = values; pair; pair = TREE_CHAIN (pair))
5523 tree enu = TREE_PURPOSE (pair);
5525 TREE_TYPE (enu) = enumtype;
5526 DECL_SIZE (enu) = TYPE_SIZE (enumtype);
5527 DECL_SIZE_UNIT (enu) = TYPE_SIZE_UNIT (enumtype);
5528 DECL_ALIGN (enu) = TYPE_ALIGN (enumtype);
5529 DECL_USER_ALIGN (enu) = TYPE_USER_ALIGN (enumtype);
5530 DECL_MODE (enu) = TYPE_MODE (enumtype);
5532 /* The ISO C Standard mandates enumerators to have type int,
5533 even though the underlying type of an enum type is
5534 unspecified. Here we convert any enumerators that fit in
5535 an int to type int, to avoid promotions to unsigned types
5536 when comparing integers with enumerators that fit in the
5537 int range. When -pedantic is given, build_enumerator()
5538 would have already taken care of those that don't fit. */
5539 if (int_fits_type_p (DECL_INITIAL (enu), enum_value_type))
5540 DECL_INITIAL (enu) = convert (enum_value_type, DECL_INITIAL (enu));
5542 DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu));
5544 TREE_PURPOSE (pair) = DECL_NAME (enu);
5545 TREE_VALUE (pair) = DECL_INITIAL (enu);
5548 TYPE_VALUES (enumtype) = values;
5551 /* Fix up all variant types of this enum type. */
5552 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
5554 if (tem == enumtype)
5556 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
5557 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
5558 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
5559 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
5560 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
5561 TYPE_MODE (tem) = TYPE_MODE (enumtype);
5562 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
5563 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
5564 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
5565 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
5568 /* Finish debugging output for this type. */
5569 rest_of_type_compilation (enumtype, toplevel);
5574 /* Build and install a CONST_DECL for one value of the
5575 current enumeration type (one that was begun with start_enum).
5576 Return a tree-list containing the CONST_DECL and its value.
5577 Assignment of sequential values by default is handled here. */
5580 build_enumerator (name, value)
5585 /* Validate and default VALUE. */
5587 /* Remove no-op casts from the value. */
5589 STRIP_TYPE_NOPS (value);
5593 if (TREE_CODE (value) == INTEGER_CST)
5595 value = default_conversion (value);
5596 constant_expression_warning (value);
5600 error ("enumerator value for `%s' not integer constant",
5601 IDENTIFIER_POINTER (name));
5606 /* Default based on previous value. */
5607 /* It should no longer be possible to have NON_LVALUE_EXPR
5611 value = enum_next_value;
5613 error ("overflow in enumeration values");
5616 if (pedantic && ! int_fits_type_p (value, integer_type_node))
5618 pedwarn ("ISO C restricts enumerator values to range of `int'");
5619 value = convert (integer_type_node, value);
5622 /* Set basis for default for next value. */
5623 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
5624 enum_overflow = tree_int_cst_lt (enum_next_value, value);
5626 /* Now create a declaration for the enum value name. */
5628 type = TREE_TYPE (value);
5629 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
5630 TYPE_PRECISION (integer_type_node)),
5631 (TYPE_PRECISION (type)
5632 >= TYPE_PRECISION (integer_type_node)
5633 && TREE_UNSIGNED (type)));
5635 decl = build_decl (CONST_DECL, name, type);
5636 DECL_INITIAL (decl) = convert (type, value);
5639 return tree_cons (decl, value, NULL_TREE);
5643 /* Create the FUNCTION_DECL for a function definition.
5644 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
5645 the declaration; they describe the function's name and the type it returns,
5646 but twisted together in a fashion that parallels the syntax of C.
5648 This function creates a binding context for the function body
5649 as well as setting up the FUNCTION_DECL in current_function_decl.
5651 Returns 1 on success. If the DECLARATOR is not suitable for a function
5652 (it defines a datum instead), we return 0, which tells
5653 yyparse to report a parse error. */
5656 start_function (declspecs, declarator, attributes)
5657 tree declarator, declspecs, attributes;
5659 tree decl1, old_decl;
5661 int old_immediate_size_expand = immediate_size_expand;
5663 current_function_returns_value = 0; /* Assume, until we see it does. */
5664 current_function_returns_null = 0;
5665 current_function_returns_abnormally = 0;
5666 warn_about_return_type = 0;
5667 current_extern_inline = 0;
5669 shadowed_labels = 0;
5671 /* Don't expand any sizes in the return type of the function. */
5672 immediate_size_expand = 0;
5674 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
5676 /* If the declarator is not suitable for a function definition,
5677 cause a syntax error. */
5680 immediate_size_expand = old_immediate_size_expand;
5684 decl_attributes (&decl1, attributes, 0);
5686 /* If #pragma weak was used, mark the decl weak now. */
5687 if (current_binding_level == global_binding_level)
5688 maybe_apply_pragma_weak (decl1);
5690 if (DECL_DECLARED_INLINE_P (decl1)
5691 && DECL_UNINLINABLE (decl1)
5692 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
5693 warning_with_decl (decl1,
5694 "inline function `%s' given attribute noinline");
5696 announce_function (decl1);
5698 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
5700 error ("return type is an incomplete type");
5701 /* Make it return void instead. */
5703 = build_function_type (void_type_node,
5704 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
5707 if (warn_about_return_type)
5708 pedwarn_c99 ("return type defaults to `int'");
5710 /* Save the parm names or decls from this function's declarator
5711 where store_parm_decls will find them. */
5712 current_function_parms = last_function_parms;
5713 current_function_parm_tags = last_function_parm_tags;
5715 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5716 error_mark_node is replaced below (in poplevel) with the BLOCK. */
5717 DECL_INITIAL (decl1) = error_mark_node;
5719 /* If this definition isn't a prototype and we had a prototype declaration
5720 before, copy the arg type info from that prototype.
5721 But not if what we had before was a builtin function. */
5722 old_decl = lookup_name_current_level (DECL_NAME (decl1));
5723 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
5724 && !DECL_BUILT_IN (old_decl)
5725 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5726 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
5727 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
5729 TREE_TYPE (decl1) = TREE_TYPE (old_decl);
5730 current_function_prototype_file = DECL_SOURCE_FILE (old_decl);
5731 current_function_prototype_line = DECL_SOURCE_LINE (old_decl);
5734 /* If there is no explicit declaration, look for any out-of-scope implicit
5737 old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1));
5739 /* Optionally warn of old-fashioned def with no previous prototype. */
5740 if (warn_strict_prototypes
5741 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
5743 && (TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0
5744 || (DECL_BUILT_IN (old_decl)
5745 && ! C_DECL_ANTICIPATED (old_decl)))))
5746 warning ("function declaration isn't a prototype");
5747 /* Optionally warn of any global def with no previous prototype. */
5748 else if (warn_missing_prototypes
5749 && TREE_PUBLIC (decl1)
5751 && (TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0
5752 || (DECL_BUILT_IN (old_decl)
5753 && ! C_DECL_ANTICIPATED (old_decl))))
5754 && ! MAIN_NAME_P (DECL_NAME (decl1)))
5755 warning_with_decl (decl1, "no previous prototype for `%s'");
5756 /* Optionally warn of any def with no previous prototype
5757 if the function has already been used. */
5758 else if (warn_missing_prototypes
5759 && old_decl != 0 && TREE_USED (old_decl)
5760 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
5761 warning_with_decl (decl1,
5762 "`%s' was used with no prototype before its definition");
5763 /* Optionally warn of any global def with no previous declaration. */
5764 else if (warn_missing_declarations
5765 && TREE_PUBLIC (decl1)
5767 && ! MAIN_NAME_P (DECL_NAME (decl1)))
5768 warning_with_decl (decl1, "no previous declaration for `%s'");
5769 /* Optionally warn of any def with no previous declaration
5770 if the function has already been used. */
5771 else if (warn_missing_declarations
5772 && old_decl != 0 && TREE_USED (old_decl)
5773 && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)))
5774 warning_with_decl (decl1,
5775 "`%s' was used with no declaration before its definition");
5777 /* This is a definition, not a reference.
5778 So normally clear DECL_EXTERNAL.
5779 However, `extern inline' acts like a declaration
5780 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5781 DECL_EXTERNAL (decl1) = current_extern_inline;
5783 /* This function exists in static storage.
5784 (This does not mean `static' in the C sense!) */
5785 TREE_STATIC (decl1) = 1;
5787 /* A nested function is not global. */
5788 if (current_function_decl != 0)
5789 TREE_PUBLIC (decl1) = 0;
5791 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5792 if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
5797 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5798 != integer_type_node)
5799 pedwarn_with_decl (decl1, "return type of `%s' is not `int'");
5801 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
5802 args = TREE_CHAIN (args))
5804 tree type = args ? TREE_VALUE (args) : 0;
5806 if (type == void_type_node)
5813 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
5814 pedwarn_with_decl (decl1,
5815 "first argument of `%s' should be `int'");
5819 if (TREE_CODE (type) != POINTER_TYPE
5820 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5821 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5823 pedwarn_with_decl (decl1,
5824 "second argument of `%s' should be `char **'");
5828 if (TREE_CODE (type) != POINTER_TYPE
5829 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5830 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5832 pedwarn_with_decl (decl1,
5833 "third argument of `%s' should probably be `char **'");
5838 /* It is intentional that this message does not mention the third
5839 argument because it's only mentioned in an appendix of the
5841 if (argct > 0 && (argct < 2 || argct > 3))
5842 pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments");
5844 if (! TREE_PUBLIC (decl1))
5845 pedwarn_with_decl (decl1, "`%s' is normally a non-static function");
5848 /* Record the decl so that the function name is defined.
5849 If we already have a decl for this name, and it is a FUNCTION_DECL,
5850 use the old decl. */
5852 current_function_decl = pushdecl (decl1);
5855 declare_parm_level (1);
5856 current_binding_level->subblocks_tag_transparent = 1;
5858 make_decl_rtl (current_function_decl, NULL);
5860 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
5861 /* Promote the value to int before returning it. */
5862 if (c_promoting_integer_type_p (restype))
5864 /* It retains unsignedness if not really getting wider. */
5865 if (TREE_UNSIGNED (restype)
5866 && (TYPE_PRECISION (restype)
5867 == TYPE_PRECISION (integer_type_node)))
5868 restype = unsigned_type_node;
5870 restype = integer_type_node;
5872 DECL_RESULT (current_function_decl)
5873 = build_decl (RESULT_DECL, NULL_TREE, restype);
5875 /* If this fcn was already referenced via a block-scope `extern' decl
5876 (or an implicit decl), propagate certain information about the usage. */
5877 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
5878 TREE_ADDRESSABLE (current_function_decl) = 1;
5880 immediate_size_expand = old_immediate_size_expand;
5882 start_fname_decls ();
5887 /* Store the parameter declarations into the current function declaration.
5888 This is called after parsing the parameter declarations, before
5889 digesting the body of the function.
5891 For an old-style definition, modify the function's type
5892 to specify at least the number of arguments. */
5897 tree fndecl = current_function_decl;
5900 /* This is either a chain of PARM_DECLs (if a prototype was used)
5901 or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */
5902 tree specparms = current_function_parms;
5904 /* This is a list of types declared among parms in a prototype. */
5905 tree parmtags = current_function_parm_tags;
5907 /* This is a chain of PARM_DECLs from old-style parm declarations. */
5908 tree parmdecls = getdecls ();
5910 /* This is a chain of any other decls that came in among the parm
5911 declarations. If a parm is declared with enum {foo, bar} x;
5912 then CONST_DECLs for foo and bar are put here. */
5915 /* The function containing FNDECL, if any. */
5916 tree context = decl_function_context (fndecl);
5918 /* Nonzero if this definition is written with a prototype. */
5921 int saved_warn_shadow = warn_shadow;
5923 /* Don't re-emit shadow warnings. */
5926 if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
5928 /* This case is when the function was defined with an ANSI prototype.
5929 The parms already have decls, so we need not do anything here
5930 except record them as in effect
5931 and complain if any redundant old-style parm decls were written. */
5942 error_with_decl (fndecl,
5943 "parm types given both in parmlist and separately");
5944 /* Get rid of the erroneous decls; don't keep them on
5945 the list of parms, since they might not be PARM_DECLs. */
5946 for (decl = current_binding_level->names;
5947 decl; decl = TREE_CHAIN (decl))
5948 if (DECL_NAME (decl))
5949 IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
5950 for (link = current_binding_level->shadowed;
5951 link; link = TREE_CHAIN (link))
5952 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
5953 current_binding_level->names = 0;
5954 current_binding_level->shadowed = 0;
5957 specparms = nreverse (specparms);
5958 for (parm = specparms; parm; parm = next)
5960 next = TREE_CHAIN (parm);
5961 if (TREE_CODE (parm) == PARM_DECL)
5963 if (DECL_NAME (parm) == 0)
5964 error_with_decl (parm, "parameter name omitted");
5965 else if (TREE_CODE (TREE_TYPE (parm)) != ERROR_MARK
5966 && VOID_TYPE_P (TREE_TYPE (parm)))
5968 error_with_decl (parm, "parameter `%s' declared void");
5969 /* Change the type to error_mark_node so this parameter
5970 will be ignored by assign_parms. */
5971 TREE_TYPE (parm) = error_mark_node;
5977 /* If we find an enum constant or a type tag,
5978 put it aside for the moment. */
5979 TREE_CHAIN (parm) = 0;
5980 others = chainon (others, parm);
5984 /* Get the decls in their original chain order
5985 and record in the function. */
5986 DECL_ARGUMENTS (fndecl) = getdecls ();
5989 /* If this function takes a variable number of arguments,
5990 add a phony parameter to the end of the parm list,
5991 to represent the position of the first unnamed argument. */
5992 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
5995 tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
5996 /* Let's hope the address of the unnamed parm
5997 won't depend on its type. */
5998 TREE_TYPE (dummy) = integer_type_node;
5999 DECL_ARG_TYPE (dummy) = integer_type_node;
6000 DECL_ARGUMENTS (fndecl) = chainon (DECL_ARGUMENTS (fndecl), dummy);
6004 /* Now pushdecl the enum constants. */
6005 for (parm = others; parm; parm = next)
6007 next = TREE_CHAIN (parm);
6008 if (DECL_NAME (parm) == 0)
6010 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
6012 else if (TREE_CODE (parm) != PARM_DECL)
6016 storetags (chainon (parmtags, gettags ()));
6020 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
6021 each with a parm name as the TREE_VALUE.
6023 PARMDECLS is a chain of declarations for parameters.
6024 Warning! It can also contain CONST_DECLs which are not parameters
6025 but are names of enumerators of any enum types
6026 declared among the parameters.
6028 First match each formal parameter name with its declaration.
6029 Associate decls with the names and store the decls
6030 into the TREE_PURPOSE slots. */
6032 /* We use DECL_WEAK as a flag to show which parameters have been
6033 seen already since it is not used on PARM_DECL or CONST_DECL. */
6034 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
6035 DECL_WEAK (parm) = 0;
6037 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
6039 tree tail, found = NULL;
6041 if (TREE_VALUE (parm) == 0)
6043 error_with_decl (fndecl,
6044 "parameter name missing from parameter list");
6045 TREE_PURPOSE (parm) = 0;
6049 /* See if any of the parmdecls specifies this parm by name.
6050 Ignore any enumerator decls. */
6051 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
6052 if (DECL_NAME (tail) == TREE_VALUE (parm)
6053 && TREE_CODE (tail) == PARM_DECL)
6059 /* If declaration already marked, we have a duplicate name.
6060 Complain, and don't use this decl twice. */
6061 if (found && DECL_WEAK (found))
6063 error_with_decl (found, "multiple parameters named `%s'");
6067 /* If the declaration says "void", complain and ignore it. */
6068 if (found && VOID_TYPE_P (TREE_TYPE (found)))
6070 error_with_decl (found, "parameter `%s' declared void");
6071 TREE_TYPE (found) = integer_type_node;
6072 DECL_ARG_TYPE (found) = integer_type_node;
6073 layout_decl (found, 0);
6076 /* If no declaration found, default to int. */
6079 found = build_decl (PARM_DECL, TREE_VALUE (parm),
6081 DECL_ARG_TYPE (found) = TREE_TYPE (found);
6082 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
6083 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
6085 pedwarn_with_decl (found, "type of `%s' defaults to `int'");
6086 else if (extra_warnings)
6087 warning_with_decl (found, "type of `%s' defaults to `int'");
6091 TREE_PURPOSE (parm) = found;
6093 /* Mark this decl as "already found". */
6094 DECL_WEAK (found) = 1;
6097 /* Put anything which is on the parmdecls chain and which is
6098 not a PARM_DECL onto the list NONPARMS. (The types of
6099 non-parm things which might appear on the list include
6100 enumerators and NULL-named TYPE_DECL nodes.) Complain about
6101 any actual PARM_DECLs not matched with any names. */
6104 for (parm = parmdecls; parm;)
6106 tree next = TREE_CHAIN (parm);
6107 TREE_CHAIN (parm) = 0;
6109 if (TREE_CODE (parm) != PARM_DECL)
6110 nonparms = chainon (nonparms, parm);
6113 /* Complain about args with incomplete types. */
6114 if (!COMPLETE_TYPE_P (TREE_TYPE (parm)))
6116 error_with_decl (parm, "parameter `%s' has incomplete type");
6117 TREE_TYPE (parm) = error_mark_node;
6120 if (! DECL_WEAK (parm))
6122 error_with_decl (parm,
6123 "declaration for parameter `%s' but no such parameter");
6124 /* Pretend the parameter was not missing.
6125 This gets us to a standard state and minimizes
6126 further error messages. */
6128 = chainon (specparms,
6129 tree_cons (parm, NULL_TREE, NULL_TREE));
6136 /* Chain the declarations together in the order of the list of
6137 names. Store that chain in the function decl, replacing the
6140 DECL_ARGUMENTS (fndecl) = 0;
6143 for (last = 0; parm; parm = TREE_CHAIN (parm))
6144 if (TREE_PURPOSE (parm))
6147 DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
6149 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6150 last = TREE_PURPOSE (parm);
6151 TREE_CHAIN (last) = 0;
6155 /* If there was a previous prototype,
6156 set the DECL_ARG_TYPE of each argument according to
6157 the type previously specified, and report any mismatches. */
6159 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
6162 for (parm = DECL_ARGUMENTS (fndecl),
6163 type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
6164 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
6165 != void_type_node));
6166 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6168 if (parm == 0 || type == 0
6169 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6171 error ("number of arguments doesn't match prototype");
6172 error_with_file_and_line (current_function_prototype_file,
6173 current_function_prototype_line,
6174 "prototype declaration");
6177 /* Type for passing arg must be consistent with that
6178 declared for the arg. ISO C says we take the unqualified
6179 type for parameters declared with qualified type. */
6180 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
6181 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
6183 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6184 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6186 /* Adjust argument to match prototype. E.g. a previous
6187 `int foo(float);' prototype causes
6188 `int foo(x) float x; {...}' to be treated like
6189 `int foo(float x) {...}'. This is particularly
6190 useful for argument types like uid_t. */
6191 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6193 if (PROMOTE_PROTOTYPES
6194 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
6195 && TYPE_PRECISION (TREE_TYPE (parm))
6196 < TYPE_PRECISION (integer_type_node))
6197 DECL_ARG_TYPE (parm) = integer_type_node;
6201 pedwarn ("promoted argument `%s' doesn't match prototype",
6202 IDENTIFIER_POINTER (DECL_NAME (parm)));
6203 warning_with_file_and_line
6204 (current_function_prototype_file,
6205 current_function_prototype_line,
6206 "prototype declaration");
6211 error ("argument `%s' doesn't match prototype",
6212 IDENTIFIER_POINTER (DECL_NAME (parm)));
6213 error_with_file_and_line (current_function_prototype_file,
6214 current_function_prototype_line,
6215 "prototype declaration");
6219 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6222 /* Otherwise, create a prototype that would match. */
6226 tree actual = 0, last = 0, type;
6228 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6230 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6232 TREE_CHAIN (last) = type;
6237 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6239 TREE_CHAIN (last) = type;
6243 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6244 of the type of this function, but we need to avoid having this
6245 affect the types of other similarly-typed functions, so we must
6246 first force the generation of an identical (but separate) type
6247 node for the relevant function type. The new node we create
6248 will be a variant of the main variant of the original function
6251 TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
6253 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6256 /* Now store the final chain of decls for the arguments
6257 as the decl-chain of the current lexical scope.
6258 Put the enumerators in as well, at the front so that
6259 DECL_ARGUMENTS is not modified. */
6261 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
6264 /* Make sure the binding level for the top of the function body
6265 gets a BLOCK if there are any in the function.
6266 Otherwise, the dbx output is wrong. */
6268 keep_next_if_subblocks = 1;
6270 /* ??? This might be an improvement,
6271 but needs to be thought about some more. */
6273 keep_next_level_flag = 1;
6276 /* Write a record describing this function definition to the prototypes
6277 file (if requested). */
6279 gen_aux_info_record (fndecl, 1, 0, prototype);
6281 /* Initialize the RTL code for the function. */
6282 init_function_start (fndecl, input_filename, lineno);
6284 /* Begin the statement tree for this function. */
6285 begin_stmt_tree (&DECL_SAVED_TREE (current_function_decl));
6287 /* If this is a nested function, save away the sizes of any
6288 variable-size types so that we can expand them when generating
6294 DECL_LANG_SPECIFIC (fndecl)->pending_sizes
6295 = nreverse (get_pending_sizes ());
6296 for (t = DECL_LANG_SPECIFIC (fndecl)->pending_sizes;
6299 SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = context;
6302 /* This function is being processed in whole-function mode. */
6303 cfun->x_whole_function_mode_p = 1;
6305 /* Even though we're inside a function body, we still don't want to
6306 call expand_expr to calculate the size of a variable-sized array.
6307 We haven't necessarily assigned RTL to all variables yet, so it's
6308 not safe to try to expand expressions involving them. */
6309 immediate_size_expand = 0;
6310 cfun->x_dont_save_pending_sizes_p = 1;
6312 warn_shadow = saved_warn_shadow;
6315 /* Finish up a function declaration and compile that function
6316 all the way to assembler language output. The free the storage
6317 for the function definition.
6319 This is called after parsing the body of the function definition.
6321 NESTED is nonzero if the function being finished is nested in another.
6322 CAN_DEFER_P is nonzero if the function may be deferred. */
6325 finish_function (nested, can_defer_p)
6329 tree fndecl = current_function_decl;
6332 /* This caused &foo to be of type ptr-to-const-function which then
6333 got a warning when stored in a ptr-to-function variable. */
6334 TREE_READONLY (fndecl) = 1;
6338 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6340 /* Must mark the RESULT_DECL as being in this function. */
6342 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
6344 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
6346 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6347 != integer_type_node)
6349 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6350 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6352 pedwarn_with_decl (fndecl, "return type of `%s' is not `int'");
6356 #ifdef DEFAULT_MAIN_RETURN
6357 /* Make it so that `main' always returns success by default. */
6358 DEFAULT_MAIN_RETURN;
6361 c_expand_return (integer_zero_node);
6366 finish_fname_decls ();
6368 /* Tie off the statement tree for this function. */
6369 finish_stmt_tree (&DECL_SAVED_TREE (fndecl));
6371 /* Complain if there's just no return statement. */
6372 if (warn_return_type
6373 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
6374 && !current_function_returns_value && !current_function_returns_null
6375 /* Don't complain if we abort. */
6376 && !current_function_returns_abnormally
6377 /* Don't warn for main(). */
6378 && !MAIN_NAME_P (DECL_NAME (fndecl))
6379 /* Or if they didn't actually specify a return type. */
6380 && !C_FUNCTION_IMPLICIT_INT (fndecl)
6381 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6382 inline function, as we might never be compiled separately. */
6383 && DECL_INLINE (fndecl))
6384 warning ("no return statement in function returning non-void");
6386 /* Clear out memory we no longer need. */
6387 free_after_parsing (cfun);
6388 /* Since we never call rest_of_compilation, we never clear
6389 CFUN. Do so explicitly. */
6390 free_after_compilation (cfun);
6395 /* Generate RTL for the body of this function. */
6396 c_expand_body (fndecl, nested, can_defer_p);
6398 /* Let the error reporting routines know that we're outside a
6399 function. For a nested function, this value is used in
6400 c_pop_function_context and then reset via pop_function_context. */
6401 current_function_decl = NULL;
6405 /* Generate the RTL for a deferred function FNDECL. */
6408 c_expand_deferred_function (fndecl)
6411 /* DECL_INLINE or DECL_RESULT might got cleared after the inline
6412 function was deferred, e.g. in duplicate_decls. */
6413 if (DECL_INLINE (fndecl) && DECL_RESULT (fndecl))
6415 c_expand_body (fndecl, 0, 0);
6416 current_function_decl = NULL;
6420 /* Generate the RTL for the body of FNDECL. If NESTED_P is nonzero,
6421 then we are already in the process of generating RTL for another
6422 function. If can_defer_p is zero, we won't attempt to defer the
6423 generation of RTL. */
6426 c_expand_body (fndecl, nested_p, can_defer_p)
6428 int nested_p, can_defer_p;
6430 int uninlinable = 1;
6432 /* There's no reason to do any of the work here if we're only doing
6433 semantic analysis; this code just generates RTL. */
6434 if (flag_syntax_only)
6437 if (flag_inline_trees)
6439 /* First, cache whether the current function is inlinable. Some
6440 predicates depend on cfun and current_function_decl to
6441 function completely. */
6442 timevar_push (TV_INTEGRATION);
6443 uninlinable = ! tree_inlinable_function_p (fndecl);
6445 if (! uninlinable && can_defer_p
6446 /* Save function tree for inlining. Should return 0 if the
6447 language does not support function deferring or the
6448 function could not be deferred. */
6449 && defer_fn (fndecl))
6451 /* Let the back-end know that this function exists. */
6452 (*debug_hooks->deferred_inline_function) (fndecl);
6453 timevar_pop (TV_INTEGRATION);
6457 /* Then, inline any functions called in it. */
6458 optimize_inline_calls (fndecl);
6459 timevar_pop (TV_INTEGRATION);
6462 timevar_push (TV_EXPAND);
6466 /* Make sure that we will evaluate variable-sized types involved
6467 in our function's type. */
6468 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes);
6469 /* Squirrel away our current state. */
6470 push_function_context ();
6473 /* Initialize the RTL code for the function. */
6474 current_function_decl = fndecl;
6475 input_filename = DECL_SOURCE_FILE (fndecl);
6476 init_function_start (fndecl, input_filename, DECL_SOURCE_LINE (fndecl));
6478 /* This function is being processed in whole-function mode. */
6479 cfun->x_whole_function_mode_p = 1;
6481 /* Even though we're inside a function body, we still don't want to
6482 call expand_expr to calculate the size of a variable-sized array.
6483 We haven't necessarily assigned RTL to all variables yet, so it's
6484 not safe to try to expand expressions involving them. */
6485 immediate_size_expand = 0;
6486 cfun->x_dont_save_pending_sizes_p = 1;
6488 /* Set up parameters and prepare for return, for the function. */
6489 expand_function_start (fndecl, 0);
6491 /* If this function is `main', emit a call to `__main'
6492 to run global initializers, etc. */
6493 if (DECL_NAME (fndecl)
6494 && MAIN_NAME_P (DECL_NAME (fndecl))
6495 && DECL_CONTEXT (fndecl) == NULL_TREE)
6496 expand_main_function ();
6498 /* Generate the RTL for this function. */
6499 expand_stmt (DECL_SAVED_TREE (fndecl));
6502 /* Allow the body of the function to be garbage collected. */
6503 DECL_SAVED_TREE (fndecl) = NULL_TREE;
6506 /* We hard-wired immediate_size_expand to zero above.
6507 expand_function_end will decrement this variable. So, we set the
6508 variable to one here, so that after the decrement it will remain
6510 immediate_size_expand = 1;
6512 /* Allow language dialects to perform special processing. */
6513 if (lang_expand_function_end)
6514 (*lang_expand_function_end) ();
6516 /* Generate rtl for function exit. */
6517 expand_function_end (input_filename, lineno, 0);
6519 /* If this is a nested function, protect the local variables in the stack
6520 above us from being collected while we're compiling this function. */
6522 ggc_push_context ();
6524 /* Run the optimizers and output the assembler code for this function. */
6525 rest_of_compilation (fndecl);
6527 /* Undo the GC context switch. */
6531 /* With just -W, complain only if function returns both with
6532 and without a value. */
6534 && current_function_returns_value
6535 && current_function_returns_null)
6536 warning ("this function may return with or without a value");
6538 /* If requested, warn about function definitions where the function will
6539 return a value (usually of some struct or union type) which itself will
6540 take up a lot of stack space. */
6542 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
6544 tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
6546 if (ret_type && TYPE_SIZE_UNIT (ret_type)
6547 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
6548 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
6551 unsigned int size_as_int
6552 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
6554 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
6555 warning_with_decl (fndecl,
6556 "size of return value of `%s' is %u bytes",
6559 warning_with_decl (fndecl,
6560 "size of return value of `%s' is larger than %d bytes",
6565 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested_p
6566 && ! flag_inline_trees)
6568 /* Stop pointing to the local nodes about to be freed.
6569 But DECL_INITIAL must remain nonzero so we know this
6570 was an actual function definition.
6571 For a nested function, this is done in c_pop_function_context.
6572 If rest_of_compilation set this to 0, leave it 0. */
6573 if (DECL_INITIAL (fndecl) != 0)
6574 DECL_INITIAL (fndecl) = error_mark_node;
6576 DECL_ARGUMENTS (fndecl) = 0;
6579 if (DECL_STATIC_CONSTRUCTOR (fndecl))
6581 if (targetm.have_ctors_dtors)
6582 (* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0),
6583 DEFAULT_INIT_PRIORITY);
6585 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
6588 if (DECL_STATIC_DESTRUCTOR (fndecl))
6590 if (targetm.have_ctors_dtors)
6591 (* targetm.asm_out.destructor) (XEXP (DECL_RTL (fndecl), 0),
6592 DEFAULT_INIT_PRIORITY);
6594 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
6598 /* Return to the enclosing function. */
6599 pop_function_context ();
6600 timevar_pop (TV_EXPAND);
6603 /* Check the declarations given in a for-loop for satisfying the C99
6606 check_for_loop_decls ()
6612 /* If we get here, declarations have been used in a for loop without
6613 the C99 for loop scope. This doesn't make much sense, so don't
6615 error ("`for' loop initial declaration used outside C99 mode");
6618 /* C99 subclause 6.8.5 paragraph 3:
6620 [#3] The declaration part of a for statement shall only
6621 declare identifiers for objects having storage class auto or
6624 It isn't clear whether, in this sentence, "identifiers" binds to
6625 "shall only declare" or to "objects" - that is, whether all identifiers
6626 declared must be identifiers for objects, or whether the restriction
6627 only applies to those that are. (A question on this in comp.std.c
6628 in November 2000 received no answer.) We implement the strictest
6629 interpretation, to avoid creating an extension which later causes
6632 for (t = gettags (); t; t = TREE_CHAIN (t))
6634 if (TREE_PURPOSE (t) != 0)
6636 enum tree_code code = TREE_CODE (TREE_VALUE (t));
6638 if (code == RECORD_TYPE)
6639 error ("`struct %s' declared in `for' loop initial declaration",
6640 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
6641 else if (code == UNION_TYPE)
6642 error ("`union %s' declared in `for' loop initial declaration",
6643 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
6645 error ("`enum %s' declared in `for' loop initial declaration",
6646 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
6650 for (t = getdecls (); t; t = TREE_CHAIN (t))
6652 if (TREE_CODE (t) != VAR_DECL && DECL_NAME (t))
6653 error_with_decl (t, "declaration of non-variable `%s' in `for' loop initial declaration");
6654 else if (TREE_STATIC (t))
6655 error_with_decl (t, "declaration of static variable `%s' in `for' loop initial declaration");
6656 else if (DECL_EXTERNAL (t))
6657 error_with_decl (t, "declaration of `extern' variable `%s' in `for' loop initial declaration");
6661 /* Save and restore the variables in this file and elsewhere
6662 that keep track of the progress of compilation of the current function.
6663 Used for nested functions. */
6665 struct language_function GTY(())
6667 struct c_language_function base;
6669 tree shadowed_labels;
6672 int returns_abnormally;
6673 int warn_about_return_type;
6675 struct binding_level *binding_level;
6678 /* Save and reinitialize the variables
6679 used during compilation of a C function. */
6682 c_push_function_context (f)
6685 struct language_function *p;
6686 p = ((struct language_function *)
6687 ggc_alloc (sizeof (struct language_function)));
6690 p->base.x_stmt_tree = c_stmt_tree;
6691 p->base.x_scope_stmt_stack = c_scope_stmt_stack;
6692 p->named_labels = named_labels;
6693 p->shadowed_labels = shadowed_labels;
6694 p->returns_value = current_function_returns_value;
6695 p->returns_null = current_function_returns_null;
6696 p->returns_abnormally = current_function_returns_abnormally;
6697 p->warn_about_return_type = warn_about_return_type;
6698 p->extern_inline = current_extern_inline;
6699 p->binding_level = current_binding_level;
6702 /* Restore the variables used during compilation of a C function. */
6705 c_pop_function_context (f)
6708 struct language_function *p = f->language;
6711 /* Bring back all the labels that were shadowed. */
6712 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
6713 if (DECL_NAME (TREE_VALUE (link)) != 0)
6714 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
6715 = TREE_VALUE (link);
6717 if (DECL_SAVED_INSNS (current_function_decl) == 0
6718 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
6720 /* Stop pointing to the local nodes about to be freed. */
6721 /* But DECL_INITIAL must remain nonzero so we know this
6722 was an actual function definition. */
6723 DECL_INITIAL (current_function_decl) = error_mark_node;
6724 DECL_ARGUMENTS (current_function_decl) = 0;
6727 c_stmt_tree = p->base.x_stmt_tree;
6728 c_scope_stmt_stack = p->base.x_scope_stmt_stack;
6729 named_labels = p->named_labels;
6730 shadowed_labels = p->shadowed_labels;
6731 current_function_returns_value = p->returns_value;
6732 current_function_returns_null = p->returns_null;
6733 current_function_returns_abnormally = p->returns_abnormally;
6734 warn_about_return_type = p->warn_about_return_type;
6735 current_extern_inline = p->extern_inline;
6736 current_binding_level = p->binding_level;
6741 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
6744 c_dup_lang_specific_decl (decl)
6747 struct lang_decl *ld;
6749 if (!DECL_LANG_SPECIFIC (decl))
6752 ld = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl));
6753 memcpy ((char *) ld, (char *) DECL_LANG_SPECIFIC (decl),
6754 sizeof (struct lang_decl));
6755 DECL_LANG_SPECIFIC (decl) = ld;
6758 /* The functions below are required for functionality of doing
6759 function at once processing in the C front end. Currently these
6760 functions are not called from anywhere in the C front end, but as
6761 these changes continue, that will change. */
6763 /* Returns nonzero if the current statement is a full expression,
6764 i.e. temporaries created during that statement should be destroyed
6765 at the end of the statement. */
6768 stmts_are_full_exprs_p ()
6773 /* Returns the stmt_tree (if any) to which statements are currently
6774 being added. If there is no active statement-tree, NULL is
6778 current_stmt_tree ()
6780 return &c_stmt_tree;
6783 /* Returns the stack of SCOPE_STMTs for the current function. */
6786 current_scope_stmt_stack ()
6788 return &c_scope_stmt_stack;
6791 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
6795 anon_aggr_type_p (node)
6796 tree node ATTRIBUTE_UNUSED;
6801 /* Dummy function in place of callback used by C++. */
6804 extract_interface_info ()
6808 /* Return a new COMPOUND_STMT, after adding it to the current
6812 c_begin_compound_stmt ()
6816 /* Create the COMPOUND_STMT. */
6817 stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE));
6822 /* Expand T (a DECL_STMT) if it declares an entity not handled by the
6826 c_expand_decl_stmt (t)
6829 tree decl = DECL_STMT_DECL (t);
6831 /* Expand nested functions. */
6832 if (TREE_CODE (decl) == FUNCTION_DECL
6833 && DECL_CONTEXT (decl) == current_function_decl
6834 && DECL_SAVED_TREE (decl))
6835 c_expand_body (decl, /*nested_p=*/1, /*can_defer_p=*/0);
6838 /* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since
6839 the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */
6842 identifier_global_value (t)
6845 return IDENTIFIER_GLOBAL_VALUE (t);
6848 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
6849 otherwise the name is found in ridpointers from RID_INDEX. */
6852 record_builtin_type (rid_index, name, type)
6859 id = ridpointers[(int) rid_index];
6861 id = get_identifier (name);
6862 pushdecl (build_decl (TYPE_DECL, id, type));
6865 /* Build the void_list_node (void_type_node having been created). */
6867 build_void_list_node ()
6869 tree t = build_tree_list (NULL_TREE, void_type_node);
6873 /* Return something to represent absolute declarators containing a *.
6874 TARGET is the absolute declarator that the * contains.
6875 TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile
6876 to apply to the pointer type, represented as identifiers, possible mixed
6879 We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST,
6880 if attributes are present) and whose type is the modifier list. */
6883 make_pointer_declarator (type_quals_attrs, target)
6884 tree type_quals_attrs, target;
6887 tree itarget = target;
6888 split_specs_attrs (type_quals_attrs, &quals, &attrs);
6889 if (attrs != NULL_TREE)
6890 itarget = tree_cons (attrs, target, NULL_TREE);
6891 return build1 (INDIRECT_REF, quals, itarget);
6894 #include "gt-c-decl.h"