Missed one in last change.
[official-gcc.git] / gcc / c-decl.c
blob557438b935ab10caba5f77131e186517a47df708
1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003 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
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "intl.h"
34 #include "tree.h"
35 #include "tree-inline.h"
36 #include "rtl.h"
37 #include "flags.h"
38 #include "function.h"
39 #include "output.h"
40 #include "expr.h"
41 #include "c-tree.h"
42 #include "toplev.h"
43 #include "ggc.h"
44 #include "tm_p.h"
45 #include "cpplib.h"
46 #include "target.h"
47 #include "debug.h"
48 #include "timevar.h"
49 #include "c-common.h"
50 #include "c-pragma.h"
51 #include "cgraph.h"
52 #include "hashtab.h"
53 #include "libfuncs.h"
54 #include "except.h"
56 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
57 enum decl_context
58 { NORMAL, /* Ordinary declaration */
59 FUNCDEF, /* Function definition */
60 PARM, /* Declaration of parm before function body */
61 FIELD, /* Declaration inside struct or union */
62 BITFIELD, /* Likewise but with specified width */
63 TYPENAME}; /* Typename (inside cast or sizeof) */
66 /* Nonzero if we have seen an invalid cross reference
67 to a struct, union, or enum, but not yet printed the message. */
69 tree pending_invalid_xref;
70 /* File and line to appear in the eventual error message. */
71 location_t pending_invalid_xref_location;
73 /* While defining an enum type, this is 1 plus the last enumerator
74 constant value. Note that will do not have to save this or `enum_overflow'
75 around nested function definition since such a definition could only
76 occur in an enum value expression and we don't use these variables in
77 that case. */
79 static tree enum_next_value;
81 /* Nonzero means that there was overflow computing enum_next_value. */
83 static int enum_overflow;
85 /* Parsing a function declarator leaves a list of parameter names
86 or a chain or parameter decls here. */
88 static tree last_function_parms;
90 /* Parsing a function declarator leaves here a chain of structure
91 and enum types declared in the parmlist. */
93 static tree last_function_parm_tags;
95 /* After parsing the declarator that starts a function definition,
96 `start_function' puts here the list of parameter names or chain of decls.
97 `store_parm_decls' finds it here. */
99 static tree current_function_parms;
101 /* Similar, for last_function_parm_tags. */
102 static tree current_function_parm_tags;
104 /* Similar, for the file and line that the prototype came from if this is
105 an old-style definition. */
106 static location_t current_function_prototype_locus;
108 /* The current statement tree. */
110 static GTY(()) struct stmt_tree_s c_stmt_tree;
112 /* The current scope statement stack. */
114 static GTY(()) tree c_scope_stmt_stack;
116 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
117 that have names. Here so we can clear out their names' definitions
118 at the end of the function. */
120 static GTY(()) tree named_labels;
122 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
124 static GTY(()) tree shadowed_labels;
126 /* A list of external DECLs that appeared at block scope when there was
127 some other global meaning for that identifier. */
128 static GTY(()) tree truly_local_externals;
130 /* Set to 0 at beginning of a function definition, set to 1 if
131 a return statement that specifies a return value is seen. */
133 int current_function_returns_value;
135 /* Set to 0 at beginning of a function definition, set to 1 if
136 a return statement with no argument is seen. */
138 int current_function_returns_null;
140 /* Set to 0 at beginning of a function definition, set to 1 if
141 a call to a noreturn function is seen. */
143 int current_function_returns_abnormally;
145 /* Set to nonzero by `grokdeclarator' for a function
146 whose return type is defaulted, if warnings for this are desired. */
148 static int warn_about_return_type;
150 /* Nonzero when starting a function declared `extern inline'. */
152 static int current_extern_inline;
154 /* For each binding contour we allocate a binding_level structure
155 * which records the names defined in that contour.
156 * Contours include:
157 * 0) the global one
158 * 1) one for each function definition,
159 * where internal declarations of the parameters appear.
160 * 2) one for each compound statement,
161 * to record its declarations.
163 * The current meaning of a name can be found by searching the levels from
164 * the current one out to the global one.
167 struct binding_level GTY(())
169 /* A chain of _DECL nodes for all variables, constants, functions,
170 and typedef types. These are in the reverse of the order supplied.
172 tree names;
174 /* A list of structure, union and enum definitions,
175 * for looking up tag names.
176 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
177 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
178 * or ENUMERAL_TYPE node.
180 tree tags;
182 /* For each level, a list of shadowed outer-level definitions
183 to be restored when this level is popped.
184 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
185 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
186 tree shadowed;
188 /* For each level, a list of shadowed outer-level tag definitions
189 to be restored when this level is popped.
190 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
191 whose TREE_VALUE is its old definition (a kind of ..._TYPE node). */
192 tree shadowed_tags;
194 /* For each level (except not the global one),
195 a chain of BLOCK nodes for all the levels
196 that were entered and exited one level down. */
197 tree blocks;
199 /* The binding level which this one is contained in (inherits from). */
200 struct binding_level *level_chain;
202 /* Nonzero if we are currently filling this level with parameter
203 declarations. */
204 char parm_flag;
206 /* Nonzero if this is the outermost block scope of a function body.
207 This scope contains both the parameters and the local variables
208 declared in the outermost block. */
209 char function_body;
211 /* Nonzero means make a BLOCK for this level regardless of all else. */
212 char keep;
214 /* Nonzero means make a BLOCK if this level has any subblocks. */
215 char keep_if_subblocks;
217 /* List of decls in `names' that have incomplete structure or
218 union types. */
219 tree incomplete_list;
221 /* A list of decls giving the (reversed) specified order of parms,
222 not including any forward-decls in the parmlist.
223 This is so we can put the parms in proper order for assign_parms. */
224 tree parm_order;
227 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
229 /* The binding level currently in effect. */
231 static GTY(()) struct binding_level *current_binding_level;
233 /* A chain of binding_level structures awaiting reuse. */
235 static GTY((deletable (""))) struct binding_level *free_binding_level;
237 /* The outermost binding level, for names of file scope.
238 This is created when the compiler is started and exists
239 through the entire run. */
241 static GTY(()) struct binding_level *global_binding_level;
243 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
245 static int keep_next_level_flag;
247 /* Nonzero means make a BLOCK for the next level pushed
248 if it has subblocks. */
250 static int keep_next_if_subblocks;
252 /* The chain of outer levels of label scopes.
253 This uses the same data structure used for binding levels,
254 but it works differently: each link in the chain records
255 saved values of named_labels and shadowed_labels for
256 a label binding level outside the current one. */
258 static GTY(()) struct binding_level *label_level_chain;
260 /* Functions called automatically at the beginning and end of execution. */
262 tree static_ctors, static_dtors;
264 /* Forward declarations. */
266 static struct binding_level *make_binding_level (void);
267 static void pop_binding_level (struct binding_level **);
268 static int duplicate_decls (tree, tree, int);
269 static int redeclaration_error_message (tree, tree);
270 static void implicit_decl_warning (tree);
271 static void storedecls (tree);
272 static void storetags (tree);
273 static tree lookup_tag (enum tree_code, tree, int);
274 static tree lookup_name_current_level (tree);
275 static tree grokdeclarator (tree, tree, enum decl_context, int);
276 static tree grokparms (tree, int);
277 static void layout_array_type (tree);
278 static tree c_make_fname_decl (tree, int);
279 static void c_expand_body_1 (tree, int);
280 static tree any_external_decl (tree);
281 static void record_external_decl (tree);
282 static void warn_if_shadowing (tree, tree);
283 static void clone_underlying_type (tree);
284 static bool flexible_array_type_p (tree);
286 /* States indicating how grokdeclarator() should handle declspecs marked
287 with __attribute__((deprecated)). An object declared as
288 __attribute__((deprecated)) suppresses warnings of uses of other
289 deprecated items. */
291 enum deprecated_states {
292 DEPRECATED_NORMAL,
293 DEPRECATED_SUPPRESS
296 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
298 void
299 c_print_identifier (FILE *file, tree node, int indent)
301 print_node (file, "symbol", IDENTIFIER_SYMBOL_VALUE (node), indent + 4);
302 print_node (file, "tag", IDENTIFIER_TAG_VALUE (node), indent + 4);
303 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
304 if (C_IS_RESERVED_WORD (node))
306 tree rid = ridpointers[C_RID_CODE (node)];
307 indent_to (file, indent + 4);
308 fprintf (file, "rid ");
309 fprintf (file, HOST_PTR_PRINTF, (void *)rid);
310 fprintf (file, " \"%s\"", IDENTIFIER_POINTER (rid));
314 /* Hook called at end of compilation to assume 1 elt
315 for a top-level tentative array defn that wasn't complete before. */
317 void
318 c_finish_incomplete_decl (tree decl)
320 if (TREE_CODE (decl) == VAR_DECL)
322 tree type = TREE_TYPE (decl);
323 if (type != error_mark_node
324 && TREE_CODE (type) == ARRAY_TYPE
325 && ! DECL_EXTERNAL (decl)
326 && TYPE_DOMAIN (type) == 0)
328 warning_with_decl (decl, "array `%s' assumed to have one element");
330 complete_array_type (type, NULL_TREE, 1);
332 layout_decl (decl, 0);
337 /* Reuse or create a struct for this binding level. */
339 static struct binding_level *
340 make_binding_level (void)
342 struct binding_level *result;
343 if (free_binding_level)
345 result = free_binding_level;
346 free_binding_level = result->level_chain;
347 memset (result, 0, sizeof(struct binding_level));
349 else
350 result = (struct binding_level *)
351 ggc_alloc_cleared (sizeof (struct binding_level));
353 return result;
356 /* Remove a binding level from a list and add it to the level chain. */
358 static void
359 pop_binding_level (struct binding_level **lp)
361 struct binding_level *l = *lp;
362 *lp = l->level_chain;
364 memset (l, 0, sizeof (struct binding_level));
365 l->level_chain = free_binding_level;
366 free_binding_level = l;
369 /* Nonzero if we are currently in the global binding level. */
372 global_bindings_p (void)
374 return current_binding_level == global_binding_level;
377 void
378 keep_next_level (void)
380 keep_next_level_flag = 1;
383 /* Nonzero if the current level needs to have a BLOCK made. */
386 kept_level_p (void)
388 return ((current_binding_level->keep_if_subblocks
389 && current_binding_level->blocks != 0)
390 || current_binding_level->keep
391 || current_binding_level->names != 0
392 || current_binding_level->tags != 0);
395 /* Identify this binding level as a level of parameters.
396 DEFINITION_FLAG is 1 for a definition, 0 for a declaration.
397 But it turns out there is no way to pass the right value for
398 DEFINITION_FLAG, so we ignore it. */
400 void
401 declare_parm_level (int definition_flag ATTRIBUTE_UNUSED)
403 current_binding_level->parm_flag = 1;
406 /* Nonzero if currently making parm declarations. */
409 in_parm_level_p (void)
411 return current_binding_level->parm_flag;
414 /* Enter a new binding level. */
416 void
417 pushlevel (int dummy ATTRIBUTE_UNUSED)
419 /* If this is the top level of a function, make sure that
420 NAMED_LABELS is 0. */
422 if (current_binding_level == global_binding_level)
423 named_labels = 0;
425 if (keep_next_if_subblocks)
427 /* This is the transition from the parameters to the top level
428 of the function body. These are the same scope
429 (C99 6.2.1p4,6) so we do not push another binding level.
431 XXX Note kludge - keep_next_if_subblocks is set only by
432 store_parm_decls, which in turn is called when and only
433 when we are about to encounter the opening curly brace for
434 the function body. */
435 current_binding_level->parm_flag = 0;
436 current_binding_level->function_body = 1;
437 current_binding_level->keep |= keep_next_level_flag;
438 current_binding_level->keep_if_subblocks = 1;
440 keep_next_level_flag = 0;
441 keep_next_if_subblocks = 0;
443 else
445 struct binding_level *newlevel = make_binding_level ();
447 newlevel->keep = keep_next_level_flag;
448 newlevel->level_chain = current_binding_level;
449 current_binding_level = newlevel;
450 keep_next_level_flag = 0;
454 /* Exit a binding level.
455 Pop the level off, and restore the state of the identifier-decl mappings
456 that were in effect when this level was entered.
458 If KEEP is nonzero, this level had explicit declarations, so
459 and create a "block" (a BLOCK node) for the level
460 to record its declarations and subblocks for symbol table output.
462 If FUNCTIONBODY is nonzero, this level is the body of a function,
463 so create a block as if KEEP were set and also clear out all
464 label names.
466 If REVERSE is nonzero, reverse the order of decls before putting
467 them into the BLOCK. */
469 tree
470 poplevel (int keep, int reverse, int functionbody)
472 tree link;
473 tree block;
474 tree decl;
475 tree decls = current_binding_level->names;
476 tree tags = current_binding_level->tags;
477 tree subblocks = current_binding_level->blocks;
479 functionbody |= current_binding_level->function_body;
480 keep |= (current_binding_level->keep || functionbody
481 || (current_binding_level->keep_if_subblocks && subblocks != 0));
483 /* We used to warn about unused variables in expand_end_bindings,
484 i.e. while generating RTL. But in function-at-a-time mode we may
485 choose to never expand a function at all (e.g. auto inlining), so
486 we do this explicitly now. */
487 warn_about_unused_variables (decls);
489 /* Clear out the name-meanings declared on this level.
490 Propagate TREE_ADDRESSABLE from nested functions to their
491 containing functions. */
492 for (link = decls; link; link = TREE_CHAIN (link))
494 if (DECL_NAME (link) != 0)
496 if (DECL_EXTERNAL (link))
497 /* External decls stay in the symbol-value slot but are
498 inaccessible. */
499 C_DECL_INVISIBLE (link) = 1;
500 else
501 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (link)) = 0;
504 if (TREE_CODE (link) == FUNCTION_DECL
505 && ! TREE_ASM_WRITTEN (link)
506 && DECL_INITIAL (link) != 0
507 && TREE_ADDRESSABLE (link)
508 && DECL_ABSTRACT_ORIGIN (link) != 0
509 && DECL_ABSTRACT_ORIGIN (link) != link)
510 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (link)) = 1;
513 /* Clear out the tag-meanings declared on this level. */
514 for (link = tags; link; link = TREE_CHAIN (link))
515 if (TREE_PURPOSE (link))
516 IDENTIFIER_TAG_VALUE (TREE_PURPOSE (link)) = 0;
518 /* Restore all name-meanings of the outer levels
519 that were shadowed by this level. */
521 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
522 IDENTIFIER_SYMBOL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
524 /* Restore all tag-meanings of the outer levels
525 that were shadowed by this level. */
527 for (link = current_binding_level->shadowed_tags; link;
528 link = TREE_CHAIN (link))
529 IDENTIFIER_TAG_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
531 /* If this is the top level block of a function, remove all
532 PARM_DECLs from current_binding_level->names; they are already
533 stored in DECL_ARGUMENTS of cfun->decl in proper order, should
534 not be put in BLOCK_VARS, and furthermore reversing them will
535 cause trouble later. They are all together at the end of the
536 list. */
537 if (functionbody && decls)
539 if (TREE_CODE (decls) == PARM_DECL)
540 decls = 0;
541 else
543 link = decls;
544 while (TREE_CHAIN (link)
545 && TREE_CODE (TREE_CHAIN (link)) != PARM_DECL)
546 link = TREE_CHAIN (link);
548 TREE_CHAIN (link) = 0;
552 /* Get the decls in the order they were written.
553 Usually current_binding_level->names is in reverse order.
554 But parameter decls were previously put in forward order. */
556 if (reverse)
557 decls = nreverse (decls);
559 /* If there were any declarations or structure tags in that level,
560 or if this level is a function body,
561 create a BLOCK to record them for the life of this function. */
563 block = 0;
564 if (keep)
566 block = make_node (BLOCK);
567 BLOCK_VARS (block) = decls;
568 BLOCK_SUBBLOCKS (block) = subblocks;
569 TREE_USED (block) = 1;
572 /* In each subblock, record that this is its superior. */
574 for (link = subblocks; link; link = TREE_CHAIN (link))
575 BLOCK_SUPERCONTEXT (link) = block;
577 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
578 binding contour so that they point to the appropriate construct, i.e.
579 either to the current FUNCTION_DECL node, or else to the BLOCK node
580 we just constructed.
582 Note that for tagged types whose scope is just the formal parameter
583 list for some function type specification, we can't properly set
584 their TYPE_CONTEXTs here, because we don't have a pointer to the
585 appropriate FUNCTION_TYPE node readily available to us. For those
586 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
587 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
588 node which will represent the "scope" for these "parameter list local"
589 tagged types. */
591 decl = functionbody ? current_function_decl : block;
592 if (decl)
593 for (link = tags; link; link = TREE_CHAIN (link))
594 TYPE_CONTEXT (TREE_VALUE (link)) = decl;
596 /* If the level being exited is the top level of a function, check
597 over all the labels, and clear out the current (function local)
598 meanings of their names. Then add them to BLOCK_VARS. */
600 if (functionbody)
602 for (link = named_labels; link; link = TREE_CHAIN (link))
604 tree label = TREE_VALUE (link);
606 if (DECL_INITIAL (label) == 0)
608 error_with_decl (label, "label `%s' used but not defined");
609 /* Avoid crashing later. */
610 define_label (input_location, DECL_NAME (label));
612 else if (warn_unused_label && !TREE_USED (label))
613 warning_with_decl (label, "label `%s' defined but not used");
614 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
616 /* Put the labels into the "variables" of the
617 top-level block, so debugger can see them. */
618 TREE_CHAIN (label) = BLOCK_VARS (block);
619 BLOCK_VARS (block) = label;
623 /* Pop the current level, and free the structure for reuse. */
625 pop_binding_level (&current_binding_level);
627 /* Dispose of the block that we just made inside some higher level. */
628 if (functionbody)
629 DECL_INITIAL (current_function_decl) = block;
630 else if (block)
631 current_binding_level->blocks
632 = chainon (current_binding_level->blocks, block);
633 /* If we did not make a block for the level just exited,
634 any blocks made for inner levels
635 (since they cannot be recorded as subblocks in that level)
636 must be carried forward so they will later become subblocks
637 of something else. */
638 else if (subblocks)
639 current_binding_level->blocks
640 = chainon (current_binding_level->blocks, subblocks);
642 return block;
645 /* Insert BLOCK at the end of the list of subblocks of the
646 current binding level. This is used when a BIND_EXPR is expanded,
647 to handle the BLOCK node inside the BIND_EXPR. */
649 void
650 insert_block (tree block)
652 TREE_USED (block) = 1;
653 current_binding_level->blocks
654 = chainon (current_binding_level->blocks, block);
657 /* Set the BLOCK node for the innermost scope (the one we are
658 currently in). The RTL expansion machinery requires us to provide
659 this hook, but it is not useful in function-at-a-time mode. */
661 void
662 set_block (tree block ATTRIBUTE_UNUSED)
666 void
667 push_label_level (void)
669 struct binding_level *newlevel;
671 newlevel = make_binding_level ();
673 /* Add this level to the front of the chain (stack) of label levels. */
675 newlevel->level_chain = label_level_chain;
676 label_level_chain = newlevel;
678 newlevel->names = named_labels;
679 newlevel->shadowed = shadowed_labels;
680 named_labels = 0;
681 shadowed_labels = 0;
684 void
685 pop_label_level (void)
687 struct binding_level *level = label_level_chain;
688 tree link, prev;
690 /* Clear out the definitions of the declared labels in this level.
691 Leave in the list any ordinary, non-declared labels. */
692 for (link = named_labels, prev = 0; link;)
694 if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
696 if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
698 error_with_decl (TREE_VALUE (link),
699 "label `%s' used but not defined");
700 /* Avoid crashing later. */
701 define_label (input_location, DECL_NAME (TREE_VALUE (link)));
703 else if (warn_unused_label && !TREE_USED (TREE_VALUE (link)))
704 warning_with_decl (TREE_VALUE (link),
705 "label `%s' defined but not used");
706 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
708 /* Delete this element from the list. */
709 link = TREE_CHAIN (link);
710 if (prev)
711 TREE_CHAIN (prev) = link;
712 else
713 named_labels = link;
715 else
717 prev = link;
718 link = TREE_CHAIN (link);
722 /* Bring back all the labels that were shadowed. */
723 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
724 if (DECL_NAME (TREE_VALUE (link)) != 0)
725 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
726 = TREE_VALUE (link);
728 named_labels = chainon (named_labels, level->names);
729 shadowed_labels = level->shadowed;
731 /* Pop the current level, and free the structure for reuse. */
732 pop_binding_level (&label_level_chain);
735 /* Push a definition or a declaration of struct, union or enum tag "name".
736 "type" should be the type node.
737 We assume that the tag "name" is not already defined.
739 Note that the definition may really be just a forward reference.
740 In that case, the TYPE_SIZE will be zero. */
742 void
743 pushtag (tree name, tree type)
745 struct binding_level *b = current_binding_level;
747 if (name)
749 /* Record the identifier as the type's name if it has none. */
751 if (TYPE_NAME (type) == 0)
752 TYPE_NAME (type) = name;
754 if (IDENTIFIER_TAG_VALUE (name))
755 b->shadowed_tags = tree_cons (name, IDENTIFIER_TAG_VALUE (name),
756 b->shadowed_tags);
757 IDENTIFIER_TAG_VALUE (name) = type;
760 b->tags = tree_cons (name, type, b->tags);
762 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
763 tagged type we just added to the current binding level. This fake
764 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
765 to output a representation of a tagged type, and it also gives
766 us a convenient place to record the "scope start" address for the
767 tagged type. */
769 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
771 /* An approximation for now, so we can tell this is a function-scope tag.
772 This will be updated in poplevel. */
773 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
776 /* Handle when a new declaration NEWDECL
777 has the same name as an old one OLDDECL
778 in the same binding contour.
779 Prints an error message if appropriate.
781 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
782 Otherwise, return 0.
784 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration,
785 and OLDDECL is in an outer binding level and should thus not be changed. */
787 static int
788 duplicate_decls (tree newdecl, tree olddecl, int different_binding_level)
790 int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
791 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
792 && DECL_INITIAL (newdecl) != 0);
793 tree oldtype = TREE_TYPE (olddecl);
794 tree newtype = TREE_TYPE (newdecl);
795 int errmsg = 0;
797 if (DECL_P (olddecl))
799 if (TREE_CODE (newdecl) == FUNCTION_DECL
800 && TREE_CODE (olddecl) == FUNCTION_DECL
801 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)))
803 if (DECL_DECLARED_INLINE_P (newdecl)
804 && DECL_UNINLINABLE (newdecl)
805 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
806 /* Already warned elsewhere. */;
807 else if (DECL_DECLARED_INLINE_P (olddecl)
808 && DECL_UNINLINABLE (olddecl)
809 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
810 /* Already warned. */;
811 else if (DECL_DECLARED_INLINE_P (newdecl)
812 && ! DECL_DECLARED_INLINE_P (olddecl)
813 && DECL_UNINLINABLE (olddecl)
814 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
816 warning_with_decl (newdecl,
817 "function `%s' redeclared as inline");
818 warning_with_decl (olddecl,
819 "previous declaration of function `%s' with attribute noinline");
821 else if (DECL_DECLARED_INLINE_P (olddecl)
822 && DECL_UNINLINABLE (newdecl)
823 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
825 warning_with_decl (newdecl,
826 "function `%s' redeclared with attribute noinline");
827 warning_with_decl (olddecl,
828 "previous declaration of function `%s' was inline");
832 DECL_ATTRIBUTES (newdecl)
833 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
836 if (TREE_CODE (newtype) == ERROR_MARK
837 || TREE_CODE (oldtype) == ERROR_MARK)
838 types_match = 0;
840 /* New decl is completely inconsistent with the old one =>
841 tell caller to replace the old one.
842 This is always an error except in the case of shadowing a builtin. */
843 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
845 if (TREE_CODE (olddecl) == FUNCTION_DECL
846 && DECL_BUILT_IN (olddecl))
848 /* If you declare a built-in or predefined function name as static,
849 the old definition is overridden,
850 but optionally warn this was a bad choice of name. */
851 if (!TREE_PUBLIC (newdecl))
853 if (warn_shadow)
854 warning_with_decl (newdecl, "shadowing built-in function `%s'");
856 else
857 warning_with_decl (newdecl,
858 "built-in function `%s' declared as non-function");
860 else
862 error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
863 error_with_decl (olddecl, "previous declaration of `%s'");
866 return 0;
869 /* For real parm decl following a forward decl, return 1 so old decl
870 will be reused. Only allow this to happen once. */
871 if (types_match && TREE_CODE (newdecl) == PARM_DECL
872 && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
874 TREE_ASM_WRITTEN (olddecl) = 0;
875 return 1;
878 /* The new declaration is the same kind of object as the old one.
879 The declarations may partially match. Print warnings if they don't
880 match enough. Ultimately, copy most of the information from the new
881 decl to the old one, and keep using the old one. */
883 if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_BUILT_IN (olddecl))
885 /* A function declaration for a built-in function. */
886 if (!TREE_PUBLIC (newdecl))
888 /* If you declare a built-in function name as static, the
889 built-in definition is overridden,
890 but optionally warn this was a bad choice of name. */
891 if (warn_shadow)
892 warning_with_decl (newdecl, "shadowing built-in function `%s'");
893 /* Discard the old built-in function. */
894 return 0;
896 else if (!types_match)
898 /* Accept the return type of the new declaration if same modes. */
899 tree oldreturntype = TREE_TYPE (oldtype);
900 tree newreturntype = TREE_TYPE (newtype);
902 if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
904 /* Function types may be shared, so we can't just modify
905 the return type of olddecl's function type. */
906 tree trytype
907 = build_function_type (newreturntype,
908 TYPE_ARG_TYPES (oldtype));
909 trytype = build_type_attribute_variant (trytype,
910 TYPE_ATTRIBUTES (oldtype));
912 types_match = comptypes (newtype, trytype);
913 if (types_match)
914 oldtype = trytype;
916 /* Accept harmless mismatch in first argument type also.
917 This is for the ffs and fprintf builtins. */
918 if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0
919 && TYPE_ARG_TYPES (oldtype) != 0
920 && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0
921 && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0
922 && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype)))
923 == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype)))))
925 /* Function types may be shared, so we can't just modify
926 the return type of olddecl's function type. */
927 tree trytype
928 = build_function_type (TREE_TYPE (oldtype),
929 tree_cons (NULL_TREE,
930 TREE_VALUE (TYPE_ARG_TYPES (newtype)),
931 TREE_CHAIN (TYPE_ARG_TYPES (oldtype))));
932 trytype = build_type_attribute_variant (trytype,
933 TYPE_ATTRIBUTES (oldtype));
935 types_match = comptypes (newtype, trytype);
936 if (types_match)
937 oldtype = trytype;
939 if (! different_binding_level)
940 TREE_TYPE (olddecl) = oldtype;
942 else if (TYPE_ARG_TYPES (oldtype) == NULL
943 && TYPE_ARG_TYPES (newtype) != NULL)
945 /* For bcmp, bzero, fputs the builtin type has arguments not
946 specified. Use the ones from the prototype so that type checking
947 is done for them. */
948 tree trytype
949 = build_function_type (TREE_TYPE (oldtype),
950 TYPE_ARG_TYPES (newtype));
951 trytype = build_type_attribute_variant (trytype,
952 TYPE_ATTRIBUTES (oldtype));
954 oldtype = trytype;
955 if (! different_binding_level)
956 TREE_TYPE (olddecl) = oldtype;
958 if (!types_match)
960 /* If types don't match for a built-in, throw away the built-in. */
961 warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
962 return 0;
965 else if (TREE_CODE (olddecl) == FUNCTION_DECL
966 && DECL_SOURCE_LINE (olddecl) == 0)
968 /* A function declaration for a predeclared function
969 that isn't actually built in. */
970 if (!TREE_PUBLIC (newdecl))
972 /* If you declare it as static, the
973 default definition is overridden. */
974 return 0;
976 else if (!types_match)
978 /* If the types don't match, preserve volatility indication.
979 Later on, we will discard everything else about the
980 default declaration. */
981 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
984 /* Permit char *foo () to match void *foo (...) if not pedantic,
985 if one of them came from a system header file. */
986 else if (!types_match
987 && TREE_CODE (olddecl) == FUNCTION_DECL
988 && TREE_CODE (newdecl) == FUNCTION_DECL
989 && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
990 && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
991 && (DECL_IN_SYSTEM_HEADER (olddecl)
992 || DECL_IN_SYSTEM_HEADER (newdecl))
993 && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
994 && TYPE_ARG_TYPES (oldtype) == 0
995 && self_promoting_args_p (TYPE_ARG_TYPES (newtype))
996 && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
998 (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
999 && TYPE_ARG_TYPES (newtype) == 0
1000 && self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
1001 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
1003 if (pedantic)
1004 pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1005 /* Make sure we keep void * as ret type, not char *. */
1006 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
1007 TREE_TYPE (newdecl) = newtype = oldtype;
1009 /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration
1010 we will come back here again. */
1011 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1013 /* Permit void foo (...) to match int foo (...) if the latter is the
1014 definition and implicit int was used. See c-torture/compile/920625-2.c. */
1015 else if (!types_match && new_is_definition
1016 && TREE_CODE (olddecl) == FUNCTION_DECL
1017 && TREE_CODE (newdecl) == FUNCTION_DECL
1018 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
1019 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
1020 && C_FUNCTION_IMPLICIT_INT (newdecl))
1022 pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1023 /* Make sure we keep void as the return type. */
1024 TREE_TYPE (newdecl) = newtype = oldtype;
1025 C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
1027 else if (!types_match
1028 /* Permit char *foo (int, ...); followed by char *foo ();
1029 if not pedantic. */
1030 && ! (TREE_CODE (olddecl) == FUNCTION_DECL
1031 && ! pedantic
1032 /* Return types must still match. */
1033 && comptypes (TREE_TYPE (oldtype),
1034 TREE_TYPE (newtype))
1035 && TYPE_ARG_TYPES (newtype) == 0))
1037 error_with_decl (newdecl, "conflicting types for `%s'");
1038 /* Check for function type mismatch
1039 involving an empty arglist vs a nonempty one. */
1040 if (TREE_CODE (olddecl) == FUNCTION_DECL
1041 && comptypes (TREE_TYPE (oldtype),
1042 TREE_TYPE (newtype))
1043 && ((TYPE_ARG_TYPES (oldtype) == 0
1044 && DECL_INITIAL (olddecl) == 0)
1046 (TYPE_ARG_TYPES (newtype) == 0
1047 && DECL_INITIAL (newdecl) == 0)))
1049 /* Classify the problem further. */
1050 tree t = TYPE_ARG_TYPES (oldtype);
1051 if (t == 0)
1052 t = TYPE_ARG_TYPES (newtype);
1053 for (; t; t = TREE_CHAIN (t))
1055 tree type = TREE_VALUE (t);
1057 if (TREE_CHAIN (t) == 0
1058 && TYPE_MAIN_VARIANT (type) != void_type_node)
1060 error ("a parameter list with an ellipsis can't match an empty parameter name list declaration");
1061 break;
1064 if (c_type_promotes_to (type) != type)
1066 error ("an argument type that has a default promotion can't match an empty parameter name list declaration");
1067 break;
1071 if (C_DECL_IMPLICIT (olddecl))
1072 error_with_decl (olddecl, "previous implicit declaration of `%s'");
1073 else
1074 error_with_decl (olddecl, "previous declaration of `%s'");
1076 /* This is safer because the initializer might contain references
1077 to variables that were declared between olddecl and newdecl. This
1078 will make the initializer invalid for olddecl in case it gets
1079 assigned to olddecl below. */
1080 if (TREE_CODE (newdecl) == VAR_DECL)
1081 DECL_INITIAL (newdecl) = 0;
1083 /* TLS cannot follow non-TLS declaration. */
1084 else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
1085 && !DECL_THREAD_LOCAL (olddecl) && DECL_THREAD_LOCAL (newdecl))
1087 error_with_decl (newdecl, "thread-local declaration of `%s' follows non thread-local declaration");
1088 error_with_decl (olddecl, "previous declaration of `%s'");
1090 /* non-TLS declaration cannot follow TLS declaration. */
1091 else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
1092 && DECL_THREAD_LOCAL (olddecl) && !DECL_THREAD_LOCAL (newdecl))
1094 error_with_decl (newdecl, "non thread-local declaration of `%s' follows thread-local declaration");
1095 error_with_decl (olddecl, "previous declaration of `%s'");
1097 else
1099 errmsg = redeclaration_error_message (newdecl, olddecl);
1100 if (errmsg)
1102 switch (errmsg)
1104 case 1:
1105 error_with_decl (newdecl, "redefinition of `%s'");
1106 break;
1107 case 2:
1108 error_with_decl (newdecl, "redeclaration of `%s'");
1109 break;
1110 case 3:
1111 error_with_decl (newdecl, "conflicting declarations of `%s'");
1112 break;
1113 default:
1114 abort ();
1117 error_with_decl (olddecl,
1118 ((DECL_INITIAL (olddecl)
1119 && current_binding_level == global_binding_level)
1120 ? "`%s' previously defined here"
1121 : "`%s' previously declared here"));
1122 return 0;
1124 else if (TREE_CODE (newdecl) == TYPE_DECL
1125 && (DECL_IN_SYSTEM_HEADER (olddecl)
1126 || DECL_IN_SYSTEM_HEADER (newdecl)))
1128 warning_with_decl (newdecl, "redefinition of `%s'");
1129 warning_with_decl
1130 (olddecl,
1131 ((DECL_INITIAL (olddecl)
1132 && current_binding_level == global_binding_level)
1133 ? "`%s' previously defined here"
1134 : "`%s' previously declared here"));
1136 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1137 && DECL_INITIAL (olddecl) != 0
1138 && TYPE_ARG_TYPES (oldtype) == 0
1139 && TYPE_ARG_TYPES (newtype) != 0
1140 && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0)
1142 tree type, parm;
1143 int nargs;
1144 /* Prototype decl follows defn w/o prototype. */
1146 for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
1147 type = TYPE_ARG_TYPES (newtype),
1148 nargs = 1;
1150 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
1152 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1153 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1155 warning_with_decl (newdecl, "prototype for `%s' follows");
1156 warning_with_decl (olddecl, "non-prototype definition here");
1157 break;
1159 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1160 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1162 error_with_decl (newdecl,
1163 "prototype for `%s' follows and number of arguments doesn't match");
1164 error_with_decl (olddecl, "non-prototype definition here");
1165 errmsg = 1;
1166 break;
1168 /* Type for passing arg must be consistent
1169 with that declared for the arg. */
1170 if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type)))
1172 error_with_decl (newdecl,
1173 "prototype for `%s' follows and argument %d doesn't match",
1174 nargs);
1175 error_with_decl (olddecl, "non-prototype definition here");
1176 errmsg = 1;
1177 break;
1181 /* Warn about mismatches in various flags. */
1182 else
1184 /* Warn if function is now inline
1185 but was previously declared not inline and has been called. */
1186 if (TREE_CODE (olddecl) == FUNCTION_DECL
1187 && ! DECL_DECLARED_INLINE_P (olddecl)
1188 && DECL_DECLARED_INLINE_P (newdecl)
1189 && TREE_USED (olddecl))
1190 warning_with_decl (newdecl,
1191 "`%s' declared inline after being called");
1192 if (TREE_CODE (olddecl) == FUNCTION_DECL
1193 && ! DECL_DECLARED_INLINE_P (olddecl)
1194 && DECL_DECLARED_INLINE_P (newdecl)
1195 && DECL_INITIAL (olddecl) != 0)
1196 warning_with_decl (newdecl,
1197 "`%s' declared inline after its definition");
1199 /* If pedantic, warn when static declaration follows a non-static
1200 declaration. Otherwise, do so only for functions. */
1201 if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL)
1202 && TREE_PUBLIC (olddecl)
1203 && !TREE_PUBLIC (newdecl))
1204 warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
1206 /* If warn_traditional, warn when a non-static function
1207 declaration follows a static one. */
1208 if (warn_traditional && !in_system_header
1209 && TREE_CODE (olddecl) == FUNCTION_DECL
1210 && !TREE_PUBLIC (olddecl)
1211 && TREE_PUBLIC (newdecl))
1212 warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
1214 /* Warn when const declaration follows a non-const
1215 declaration, but not for functions. */
1216 if (TREE_CODE (olddecl) != FUNCTION_DECL
1217 && !TREE_READONLY (olddecl)
1218 && TREE_READONLY (newdecl))
1219 warning_with_decl (newdecl, "const declaration for `%s' follows non-const");
1220 /* These bits are logically part of the type, for variables.
1221 But not for functions
1222 (where qualifiers are not valid ANSI anyway). */
1223 else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
1224 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1225 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1226 pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1230 /* Optionally warn about more than one declaration for the same name. */
1231 if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
1232 /* Don't warn about a function declaration
1233 followed by a definition. */
1234 && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
1235 && DECL_INITIAL (olddecl) == 0)
1236 /* Don't warn about extern decl followed by (tentative) definition. */
1237 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
1239 warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
1240 warning_with_decl (olddecl, "previous declaration of `%s'");
1243 /* Copy all the DECL_... slots specified in the new decl
1244 except for any that we copy here from the old type.
1246 Past this point, we don't change OLDTYPE and NEWTYPE
1247 even if we change the types of NEWDECL and OLDDECL. */
1249 if (types_match)
1251 /* When copying info to olddecl, we store into write_olddecl
1252 instead. This allows us to avoid modifying olddecl when
1253 different_binding_level is true. */
1254 tree write_olddecl = different_binding_level ? newdecl : olddecl;
1256 /* Merge the data types specified in the two decls. */
1257 if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
1259 if (different_binding_level)
1261 if (TYPE_ARG_TYPES (oldtype) != 0
1262 && TYPE_ARG_TYPES (newtype) == 0)
1263 TREE_TYPE (newdecl) = common_type (newtype, oldtype);
1264 else
1265 TREE_TYPE (newdecl)
1266 = build_type_attribute_variant
1267 (newtype,
1268 merge_attributes (TYPE_ATTRIBUTES (newtype),
1269 TYPE_ATTRIBUTES (oldtype)));
1271 else
1272 TREE_TYPE (newdecl)
1273 = TREE_TYPE (olddecl)
1274 = common_type (newtype, oldtype);
1277 /* Lay the type out, unless already done. */
1278 if (oldtype != TREE_TYPE (newdecl))
1280 if (TREE_TYPE (newdecl) != error_mark_node)
1281 layout_type (TREE_TYPE (newdecl));
1282 if (TREE_CODE (newdecl) != FUNCTION_DECL
1283 && TREE_CODE (newdecl) != TYPE_DECL
1284 && TREE_CODE (newdecl) != CONST_DECL)
1285 layout_decl (newdecl, 0);
1287 else
1289 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1290 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1291 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
1292 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1293 if (TREE_CODE (olddecl) != FUNCTION_DECL)
1294 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1296 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1297 DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl);
1301 /* Keep the old rtl since we can safely use it. */
1302 COPY_DECL_RTL (olddecl, newdecl);
1304 /* Merge the type qualifiers. */
1305 if (TREE_READONLY (newdecl))
1306 TREE_READONLY (write_olddecl) = 1;
1308 if (TREE_THIS_VOLATILE (newdecl))
1310 TREE_THIS_VOLATILE (write_olddecl) = 1;
1311 if (TREE_CODE (newdecl) == VAR_DECL
1312 /* If an automatic variable is re-declared in the same
1313 function scope, but the old declaration was not
1314 volatile, make_var_volatile() would crash because the
1315 variable would have been assigned to a pseudo, not a
1316 MEM. Since this duplicate declaration is invalid
1317 anyway, we just skip the call. */
1318 && errmsg == 0)
1319 make_var_volatile (newdecl);
1322 /* Keep source location of definition rather than declaration. */
1323 /* When called with different_binding_level set, keep the old
1324 information so that meaningful diagnostics can be given. */
1325 if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
1326 && ! different_binding_level)
1328 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
1329 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
1332 /* Merge the unused-warning information. */
1333 if (DECL_IN_SYSTEM_HEADER (olddecl))
1334 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1335 else if (DECL_IN_SYSTEM_HEADER (newdecl))
1336 DECL_IN_SYSTEM_HEADER (write_olddecl) = 1;
1338 /* Merge the initialization information. */
1339 /* When called with different_binding_level set, don't copy over
1340 DECL_INITIAL, so that we don't accidentally change function
1341 declarations into function definitions. */
1342 if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
1343 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1345 /* Merge the section attribute.
1346 We want to issue an error if the sections conflict but that must be
1347 done later in decl_attributes since we are called before attributes
1348 are assigned. */
1349 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1350 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1352 /* Copy the assembler name.
1353 Currently, it can only be defined in the prototype. */
1354 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
1356 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1358 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1359 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1360 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1361 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1362 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1363 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1364 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1365 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1366 DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
1369 /* If cannot merge, then use the new type and qualifiers,
1370 and don't preserve the old rtl. */
1371 else if (! different_binding_level)
1373 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1374 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
1375 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
1376 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
1379 /* Merge the storage class information. */
1380 merge_weak (newdecl, olddecl);
1382 /* For functions, static overrides non-static. */
1383 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1385 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1386 /* This is since we don't automatically
1387 copy the attributes of NEWDECL into OLDDECL. */
1388 /* No need to worry about different_binding_level here because
1389 then TREE_PUBLIC (newdecl) was true. */
1390 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1391 /* If this clears `static', clear it in the identifier too. */
1392 if (! TREE_PUBLIC (olddecl))
1393 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1395 if (DECL_EXTERNAL (newdecl))
1397 if (! different_binding_level)
1399 /* Don't mess with these flags on local externs; they remain
1400 external even if there's a declaration at file scope which
1401 isn't. */
1402 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
1403 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1405 /* An extern decl does not override previous storage class. */
1406 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1407 if (! DECL_EXTERNAL (newdecl))
1408 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1410 else
1412 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1413 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1416 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1418 /* If we're redefining a function previously defined as extern
1419 inline, make sure we emit debug info for the inline before we
1420 throw it away, in case it was inlined into a function that hasn't
1421 been written out yet. */
1422 if (new_is_definition && DECL_INITIAL (olddecl))
1424 if (TREE_USED (olddecl))
1425 (*debug_hooks->outlining_inline_function) (olddecl);
1427 /* The new defn must not be inline. */
1428 DECL_INLINE (newdecl) = 0;
1429 DECL_UNINLINABLE (newdecl) = 1;
1431 else
1433 /* If either decl says `inline', this fn is inline,
1434 unless its definition was passed already. */
1435 if (DECL_DECLARED_INLINE_P (newdecl)
1436 || DECL_DECLARED_INLINE_P (olddecl))
1437 DECL_DECLARED_INLINE_P (newdecl) = 1;
1439 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1440 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1443 if (DECL_BUILT_IN (olddecl))
1445 /* Get rid of any built-in function if new arg types don't match it
1446 or if we have a function definition. */
1447 if (! types_match || new_is_definition)
1449 if (! different_binding_level)
1451 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
1452 DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN;
1455 else
1457 /* If redeclaring a builtin function, and not a definition,
1458 it stays built in. */
1459 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1460 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1464 /* Also preserve various other info from the definition. */
1465 if (! new_is_definition)
1467 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1468 /* When called with different_binding_level set, don't copy over
1469 DECL_INITIAL, so that we don't accidentally change function
1470 declarations into function definitions. */
1471 if (! different_binding_level)
1472 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1473 DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
1474 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1475 DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl);
1476 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
1478 /* Set DECL_INLINE on the declaration if we've got a body
1479 from which to instantiate. */
1480 if (DECL_INLINE (olddecl) && ! DECL_UNINLINABLE (newdecl))
1482 DECL_INLINE (newdecl) = 1;
1483 DECL_ABSTRACT_ORIGIN (newdecl)
1484 = (different_binding_level
1485 ? DECL_ORIGIN (olddecl)
1486 : DECL_ABSTRACT_ORIGIN (olddecl));
1489 else
1491 /* If a previous declaration said inline, mark the
1492 definition as inlinable. */
1493 if (DECL_DECLARED_INLINE_P (newdecl)
1494 && ! DECL_UNINLINABLE (newdecl))
1495 DECL_INLINE (newdecl) = 1;
1498 if (different_binding_level)
1499 return 0;
1501 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1502 But preserve OLDDECL's DECL_UID. */
1504 unsigned olddecl_uid = DECL_UID (olddecl);
1506 memcpy ((char *) olddecl + sizeof (struct tree_common),
1507 (char *) newdecl + sizeof (struct tree_common),
1508 sizeof (struct tree_decl) - sizeof (struct tree_common));
1509 DECL_UID (olddecl) = olddecl_uid;
1512 /* NEWDECL contains the merged attribute lists.
1513 Update OLDDECL to be the same. */
1514 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
1516 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1517 so that encode_section_info has a chance to look at the new decl
1518 flags and attributes. */
1519 if (DECL_RTL_SET_P (olddecl)
1520 && (TREE_CODE (olddecl) == FUNCTION_DECL
1521 || (TREE_CODE (olddecl) == VAR_DECL
1522 && TREE_STATIC (olddecl))))
1523 make_decl_rtl (olddecl, NULL);
1525 return 1;
1528 /* Return any external DECL associated with ID, whether or not it is
1529 currently in scope. */
1531 static tree
1532 any_external_decl (tree id)
1534 tree decl = IDENTIFIER_SYMBOL_VALUE (id);
1535 tree t;
1537 if (decl == 0 || TREE_CODE (decl) == ERROR_MARK)
1538 return 0;
1539 else if (TREE_CODE (decl) != TYPE_DECL && DECL_EXTERNAL (decl))
1540 return decl;
1542 t = purpose_member (id, truly_local_externals);
1543 if (t)
1544 return TREE_VALUE (t);
1546 return 0;
1549 /* Record an external decl DECL. This only does something if a
1550 shadowing decl already exists. */
1551 static void
1552 record_external_decl (tree decl)
1554 tree name = DECL_NAME (decl);
1555 if (!IDENTIFIER_SYMBOL_VALUE (name))
1556 return;
1558 truly_local_externals = tree_cons (name, decl, truly_local_externals);
1561 /* Check whether decl-node X shadows an existing declaration.
1562 OLD is the old IDENTIFIER_SYMBOL_VALUE of the DECL_NAME of X,
1563 which might be a NULL_TREE. */
1564 static void
1565 warn_if_shadowing (tree x, tree old)
1567 const char *name;
1569 /* Nothing to shadow? */
1570 if (old == 0
1571 /* Shadow warnings not wanted? */
1572 || !warn_shadow
1573 /* No shadow warnings for internally generated vars. */
1574 || DECL_SOURCE_LINE (x) == 0
1575 /* No shadow warnings for vars made for inlining. */
1576 || DECL_FROM_INLINE (x)
1577 /* Don't warn about the parm names in function declarator
1578 within a function declarator.
1579 It would be nice to avoid warning in any function
1580 declarator in a declaration, as opposed to a definition,
1581 but there is no way to tell it's not a definition. */
1582 || (TREE_CODE (x) == PARM_DECL
1583 && current_binding_level->level_chain->parm_flag))
1584 return;
1586 name = IDENTIFIER_POINTER (DECL_NAME (x));
1588 if (TREE_CODE (old) == PARM_DECL)
1589 shadow_warning (SW_PARAM, name, old);
1590 else if (DECL_CONTEXT (old) == 0)
1591 shadow_warning (SW_GLOBAL, name, old);
1592 else
1593 shadow_warning (SW_LOCAL, name, old);
1597 /* Subroutine of pushdecl.
1599 X is a TYPE_DECL for a typedef statement. Create a brand new
1600 ..._TYPE node (which will be just a variant of the existing
1601 ..._TYPE node with identical properties) and then install X
1602 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
1604 The whole point here is to end up with a situation where each
1605 and every ..._TYPE node the compiler creates will be uniquely
1606 associated with AT MOST one node representing a typedef name.
1607 This way, even though the compiler substitutes corresponding
1608 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
1609 early on, later parts of the compiler can always do the reverse
1610 translation and get back the corresponding typedef name. For
1611 example, given:
1613 typedef struct S MY_TYPE;
1614 MY_TYPE object;
1616 Later parts of the compiler might only know that `object' was of
1617 type `struct S' if it were not for code just below. With this
1618 code however, later parts of the compiler see something like:
1620 struct S' == struct S
1621 typedef struct S' MY_TYPE;
1622 struct S' object;
1624 And they can then deduce (from the node for type struct S') that
1625 the original object declaration was:
1627 MY_TYPE object;
1629 Being able to do this is important for proper support of protoize,
1630 and also for generating precise symbolic debugging information
1631 which takes full account of the programmer's (typedef) vocabulary.
1633 Obviously, we don't want to generate a duplicate ..._TYPE node if
1634 the TYPE_DECL node that we are now processing really represents a
1635 standard built-in type.
1637 Since all standard types are effectively declared at line zero
1638 in the source file, we can easily check to see if we are working
1639 on a standard type by checking the current value of lineno. */
1641 static void
1642 clone_underlying_type (tree x)
1644 if (DECL_SOURCE_LINE (x) == 0)
1646 if (TYPE_NAME (TREE_TYPE (x)) == 0)
1647 TYPE_NAME (TREE_TYPE (x)) = x;
1649 else if (TREE_TYPE (x) != error_mark_node
1650 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
1652 tree tt = TREE_TYPE (x);
1653 DECL_ORIGINAL_TYPE (x) = tt;
1654 tt = build_type_copy (tt);
1655 TYPE_NAME (tt) = x;
1656 TREE_USED (tt) = TREE_USED (x);
1657 TREE_TYPE (x) = tt;
1661 /* Record a decl-node X as belonging to the current lexical scope.
1662 Check for errors (such as an incompatible declaration for the same
1663 name already seen in the same scope).
1665 Returns either X or an old decl for the same name.
1666 If an old decl is returned, it may have been smashed
1667 to agree with what X says. */
1669 tree
1670 pushdecl (tree x)
1672 tree name = DECL_NAME (x);
1673 struct binding_level *scope = current_binding_level;
1675 #ifdef ENABLE_CHECKING
1676 if (error_mark_node == 0)
1677 /* Called too early. */
1678 abort ();
1679 #endif
1681 /* Functions need the lang_decl data. */
1682 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x))
1683 DECL_LANG_SPECIFIC (x) = (struct lang_decl *)
1684 ggc_alloc_cleared (sizeof (struct lang_decl));
1686 /* A local extern declaration for a function doesn't constitute nesting.
1687 A local auto declaration does, since it's a forward decl
1688 for a nested function coming later. */
1689 if ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
1690 && DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x))
1691 DECL_CONTEXT (x) = 0;
1692 else
1693 DECL_CONTEXT (x) = current_function_decl;
1695 if (name)
1697 tree old;
1699 if (warn_nested_externs
1700 && scope != global_binding_level
1701 && DECL_EXTERNAL (x)
1702 && !DECL_IN_SYSTEM_HEADER (x))
1703 warning ("nested extern declaration of `%s'",
1704 IDENTIFIER_POINTER (name));
1706 old = lookup_name_current_level (name);
1707 if (old && duplicate_decls (x, old, 0))
1708 return old;
1709 if (DECL_EXTERNAL (x) || scope == global_binding_level)
1711 /* Find and check against a previous, not-in-scope, external
1712 decl for this identifier. (C99 s???: If two declarations
1713 with external linkage, referring to the same object, have
1714 incompatible types, the behavior is undefined). */
1715 tree ext = any_external_decl (name);
1716 if (ext)
1718 if (duplicate_decls (x, ext, scope != global_binding_level))
1719 x = copy_node (ext);
1721 else
1722 record_external_decl (x);
1725 if (TREE_CODE (x) == TYPE_DECL)
1726 clone_underlying_type (x);
1728 /* If storing a local value, there may already be one
1729 (inherited). If so, record it for restoration when this
1730 binding level ends. Take care not to do this if we are
1731 replacing an older decl in the same binding level (i.e.
1732 duplicate_decls returned false, above). */
1733 if (scope != global_binding_level
1734 && IDENTIFIER_SYMBOL_VALUE (name)
1735 && IDENTIFIER_SYMBOL_VALUE (name) != old)
1737 warn_if_shadowing (x, IDENTIFIER_SYMBOL_VALUE (name));
1738 scope->shadowed = tree_cons (name, IDENTIFIER_SYMBOL_VALUE (name),
1739 scope->shadowed);
1742 /* Install the new declaration in the requested binding level. */
1743 IDENTIFIER_SYMBOL_VALUE (name) = x;
1744 C_DECL_INVISIBLE (x) = 0;
1746 /* Keep list of variables in this level with incomplete type.
1747 If the input is erroneous, we can have error_mark in the type
1748 slot (e.g. "f(void a, ...)") - that doesn't count as an
1749 incomplete type. */
1750 if (TREE_TYPE (x) != error_mark_node
1751 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
1753 tree element = TREE_TYPE (x);
1755 while (TREE_CODE (element) == ARRAY_TYPE)
1756 element = TREE_TYPE (element);
1757 if (TREE_CODE (element) == RECORD_TYPE
1758 || TREE_CODE (element) == UNION_TYPE)
1759 scope->incomplete_list = tree_cons (NULL_TREE, x,
1760 scope->incomplete_list);
1764 /* Put decls on list in reverse order.
1765 We will reverse them later if necessary. */
1766 TREE_CHAIN (x) = scope->names;
1767 scope->names = x;
1769 return x;
1772 /* Record X as belonging to the global scope (C99 "file scope").
1773 This is used only internally by the Objective-C front end,
1774 and is limited to its needs. It will hork if there is _any_
1775 visible binding for X (not just a global one). */
1776 tree
1777 pushdecl_top_level (tree x)
1779 tree name, old;
1781 if (TREE_CODE (x) != VAR_DECL)
1782 abort ();
1784 name = DECL_NAME (x);
1785 old = IDENTIFIER_SYMBOL_VALUE (name);
1787 if (old)
1789 if (DECL_CONTEXT (old))
1790 abort ();
1792 if (!duplicate_decls (x, old, 0))
1793 abort ();
1795 return old;
1798 DECL_CONTEXT (x) = 0;
1799 IDENTIFIER_SYMBOL_VALUE (name) = x;
1800 TREE_CHAIN (x) = global_binding_level->names;
1801 global_binding_level->names = x;
1802 return x;
1805 /* Record X as belonging to the outermost scope of the current
1806 function. This is used only internally, by c_make_fname_decl and
1807 build_external_ref, and is limited to their needs. The NAME is
1808 provided as a separate argument because build_external_ref wants to
1809 use error_mark_node for X. For VAR_DECLs, duplicate_decls is not
1810 called; if there is any preexisting decl for this identifier, it is
1811 an ICE. */
1812 tree
1813 pushdecl_function_level (tree x, tree name)
1815 struct binding_level *scope;
1817 scope = current_binding_level;
1818 while (scope->function_body == 0)
1819 scope = scope->level_chain;
1820 if (!scope)
1821 abort ();
1823 if (x == error_mark_node)
1824 scope->shadowed = tree_cons (name, IDENTIFIER_SYMBOL_VALUE (name),
1825 scope->shadowed);
1826 else if (TREE_CODE (x) == VAR_DECL)
1828 if (name != DECL_NAME (x))
1829 abort ();
1830 if (IDENTIFIER_SYMBOL_VALUE (name))
1831 abort ();
1833 DECL_CONTEXT (x) = current_function_decl;
1834 TREE_CHAIN (x) = scope->names;
1835 scope->names = x;
1838 IDENTIFIER_SYMBOL_VALUE (name) = x;
1839 return x;
1842 /* Generate an implicit declaration for identifier FUNCTIONID as a
1843 function of type int (). */
1845 tree
1846 implicitly_declare (tree functionid)
1848 tree decl = any_external_decl (functionid);
1850 if (decl && decl != error_mark_node)
1852 /* Implicit declaration of a function already declared
1853 (somehow) in a different scope, or as a built-in.
1854 If this is the first time this has happened, warn;
1855 then recycle the old declaration. */
1856 if (!C_DECL_IMPLICIT (decl))
1858 implicit_decl_warning (DECL_NAME (decl));
1859 if (DECL_CONTEXT (decl))
1860 warning_with_decl (decl, "previous declaration of `%s'");
1861 C_DECL_IMPLICIT (decl) = 1;
1863 /* If this function is global, then it must already be in the
1864 global binding level, so there's no need to push it again. */
1865 if (current_binding_level == global_binding_level)
1866 return decl;
1867 /* If this is a local declaration, make a copy; we can't have
1868 the same DECL listed in two different binding levels. */
1869 return pushdecl (copy_node (decl));
1872 /* Not seen before. */
1873 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
1874 DECL_EXTERNAL (decl) = 1;
1875 TREE_PUBLIC (decl) = 1;
1876 C_DECL_IMPLICIT (decl) = 1;
1877 implicit_decl_warning (functionid);
1879 /* ANSI standard says implicit declarations are in the innermost block.
1880 So we record the decl in the standard fashion. */
1881 decl = pushdecl (decl);
1883 /* No need to call objc_check_decl here - it's a function type. */
1884 rest_of_decl_compilation (decl, NULL, 0, 0);
1886 /* Write a record describing this implicit function declaration to the
1887 prototypes file (if requested). */
1889 gen_aux_info_record (decl, 0, 1, 0);
1891 /* Possibly apply some default attributes to this implicit declaration. */
1892 decl_attributes (&decl, NULL_TREE, 0);
1894 return decl;
1897 static void
1898 implicit_decl_warning (tree id)
1900 const char *name = IDENTIFIER_POINTER (id);
1901 if (mesg_implicit_function_declaration == 2)
1902 error ("implicit declaration of function `%s'", name);
1903 else if (mesg_implicit_function_declaration == 1)
1904 warning ("implicit declaration of function `%s'", name);
1907 /* Return zero if the declaration NEWDECL is valid
1908 when the declaration OLDDECL (assumed to be for the same name)
1909 has already been seen.
1910 Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration,
1911 and 3 if it is a conflicting declaration. */
1913 static int
1914 redeclaration_error_message (tree newdecl, tree olddecl)
1916 if (TREE_CODE (newdecl) == TYPE_DECL)
1918 /* Do not complain about type redeclarations where at least one
1919 declaration was in a system header. */
1920 if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl))
1921 return 0;
1922 return 1;
1924 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1926 /* Declarations of functions can insist on internal linkage
1927 but they can't be inconsistent with internal linkage,
1928 so there can be no error on that account.
1929 However defining the same name twice is no good. */
1930 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
1931 /* However, defining once as extern inline and a second
1932 time in another way is ok. */
1933 && ! (DECL_DECLARED_INLINE_P (olddecl) && DECL_EXTERNAL (olddecl)
1934 && ! (DECL_DECLARED_INLINE_P (newdecl)
1935 && DECL_EXTERNAL (newdecl))))
1936 return 1;
1937 return 0;
1939 else if (DECL_CONTEXT (newdecl) == NULL_TREE)
1941 /* Objects declared at top level: */
1942 /* If at least one is a reference, it's ok. */
1943 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
1944 return 0;
1945 /* Reject two definitions. */
1946 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
1947 return 1;
1948 /* Now we have two tentative defs, or one tentative and one real def. */
1949 /* Insist that the linkage match. */
1950 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
1951 return 3;
1952 return 0;
1954 else if (current_binding_level->parm_flag
1955 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
1956 return 0;
1957 else
1959 /* Newdecl has block scope. If olddecl has block scope also, then
1960 reject two definitions, and reject a definition together with an
1961 external reference. Otherwise, it is OK, because newdecl must
1962 be an extern reference to olddecl. */
1963 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))
1964 && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl))
1965 return 2;
1966 return 0;
1970 /* Get the LABEL_DECL corresponding to identifier ID as a label.
1971 Create one if none exists so far for the current function.
1972 This function is called for both label definitions and label references. */
1974 tree
1975 lookup_label (tree id)
1977 tree decl = IDENTIFIER_LABEL_VALUE (id);
1979 if (current_function_decl == 0)
1981 error ("label %s referenced outside of any function",
1982 IDENTIFIER_POINTER (id));
1983 return 0;
1986 /* Use a label already defined or ref'd with this name. */
1987 if (decl != 0)
1989 /* But not if it is inherited and wasn't declared to be inheritable. */
1990 if (DECL_CONTEXT (decl) != current_function_decl
1991 && ! C_DECLARED_LABEL_FLAG (decl))
1992 return shadow_label (id);
1993 return decl;
1996 decl = build_decl (LABEL_DECL, id, void_type_node);
1998 /* A label not explicitly declared must be local to where it's ref'd. */
1999 DECL_CONTEXT (decl) = current_function_decl;
2001 DECL_MODE (decl) = VOIDmode;
2003 /* Say where one reference is to the label,
2004 for the sake of the error if it is not defined. */
2005 DECL_SOURCE_LOCATION (decl) = input_location;
2007 IDENTIFIER_LABEL_VALUE (id) = decl;
2009 named_labels = tree_cons (NULL_TREE, decl, named_labels);
2011 return decl;
2014 /* Make a label named NAME in the current function,
2015 shadowing silently any that may be inherited from containing functions
2016 or containing scopes.
2018 Note that valid use, if the label being shadowed
2019 comes from another scope in the same function,
2020 requires calling declare_nonlocal_label right away. */
2022 tree
2023 shadow_label (tree name)
2025 tree decl = IDENTIFIER_LABEL_VALUE (name);
2027 if (decl != 0)
2029 tree dup;
2031 /* Check to make sure that the label hasn't already been declared
2032 at this label scope */
2033 for (dup = named_labels; dup; dup = TREE_CHAIN (dup))
2034 if (TREE_VALUE (dup) == decl)
2036 error ("duplicate label declaration `%s'",
2037 IDENTIFIER_POINTER (name));
2038 error_with_decl (TREE_VALUE (dup),
2039 "this is a previous declaration");
2040 /* Just use the previous declaration. */
2041 return lookup_label (name);
2044 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2045 IDENTIFIER_LABEL_VALUE (name) = decl = 0;
2048 return lookup_label (name);
2051 /* Define a label, specifying the location in the source file.
2052 Return the LABEL_DECL node for the label, if the definition is valid.
2053 Otherwise return 0. */
2055 tree
2056 define_label (location_t location, tree name)
2058 tree decl = lookup_label (name);
2060 /* If label with this name is known from an outer context, shadow it. */
2061 if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
2063 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2064 IDENTIFIER_LABEL_VALUE (name) = 0;
2065 decl = lookup_label (name);
2068 if (warn_traditional && !in_system_header && lookup_name (name))
2069 warning ("%Htraditional C lacks a separate namespace for labels, "
2070 "identifier `%s' conflicts", &location, IDENTIFIER_POINTER (name));
2072 if (DECL_INITIAL (decl) != 0)
2074 error ("%Hduplicate label `%s'", &location, IDENTIFIER_POINTER (name));
2075 return 0;
2077 else
2079 /* Mark label as having been defined. */
2080 DECL_INITIAL (decl) = error_mark_node;
2081 /* Say where in the source. */
2082 DECL_SOURCE_LOCATION (decl) = location;
2083 return decl;
2087 /* Return the list of declarations of the current level.
2088 Note that this list is in reverse order unless/until
2089 you nreverse it; and when you do nreverse it, you must
2090 store the result back using `storedecls' or you will lose. */
2092 tree
2093 getdecls (void)
2095 return current_binding_level->names;
2098 /* Return the list of type-tags (for structs, etc) of the current level. */
2100 tree
2101 gettags (void)
2103 return current_binding_level->tags;
2106 /* Store the list of declarations of the current level.
2107 This is done for the parameter declarations of a function being defined,
2108 after they are modified in the light of any missing parameters. */
2110 static void
2111 storedecls (tree decls)
2113 current_binding_level->names = decls;
2116 /* Similarly, store the list of tags of the current level. */
2118 static void
2119 storetags (tree tags)
2121 current_binding_level->tags = tags;
2124 /* Given NAME, an IDENTIFIER_NODE,
2125 return the structure (or union or enum) definition for that name.
2126 If THISLEVEL_ONLY is nonzero, searches only the current_binding_level.
2127 CODE says which kind of type the caller wants;
2128 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2129 If the wrong kind of type is found, an error is reported. */
2131 static tree
2132 lookup_tag (enum tree_code code, tree name, int thislevel_only)
2134 tree tag = IDENTIFIER_TAG_VALUE (name);
2135 int thislevel = 0;
2137 if (!tag)
2138 return 0;
2140 /* We only care about whether it's in this level if
2141 thislevel_only was set or it might be a type clash. */
2142 if (thislevel_only || TREE_CODE (tag) != code)
2144 if (current_binding_level == global_binding_level
2145 || purpose_member (name, current_binding_level->tags))
2146 thislevel = 1;
2149 if (thislevel_only && !thislevel)
2150 return 0;
2152 if (TREE_CODE (tag) != code)
2154 /* Definition isn't the kind we were looking for. */
2155 pending_invalid_xref = name;
2156 pending_invalid_xref_location = input_location;
2158 /* If in the same binding level as a declaration as a tag
2159 of a different type, this must not be allowed to
2160 shadow that tag, so give the error immediately.
2161 (For example, "struct foo; union foo;" is invalid.) */
2162 if (thislevel)
2163 pending_xref_error ();
2165 return tag;
2168 /* Print an error message now
2169 for a recent invalid struct, union or enum cross reference.
2170 We don't print them immediately because they are not invalid
2171 when used in the `struct foo;' construct for shadowing. */
2173 void
2174 pending_xref_error (void)
2176 if (pending_invalid_xref != 0)
2177 error ("%H`%s' defined as wrong kind of tag",
2178 &pending_invalid_xref_location,
2179 IDENTIFIER_POINTER (pending_invalid_xref));
2180 pending_invalid_xref = 0;
2184 /* Look up NAME in the current binding level and its superiors
2185 in the namespace of variables, functions and typedefs.
2186 Return a ..._DECL node of some kind representing its definition,
2187 or return 0 if it is undefined. */
2189 tree
2190 lookup_name (tree name)
2192 tree decl = IDENTIFIER_SYMBOL_VALUE (name);
2193 if (decl == 0 || decl == error_mark_node)
2194 return decl;
2195 if (C_DECL_INVISIBLE (decl))
2196 return 0;
2197 return decl;
2200 /* Similar to `lookup_name' but look only at the current binding level. */
2202 static tree
2203 lookup_name_current_level (tree name)
2205 tree decl = IDENTIFIER_SYMBOL_VALUE (name);
2207 if (decl == 0 || decl == error_mark_node || C_DECL_INVISIBLE (decl))
2208 return 0;
2210 if (current_binding_level == global_binding_level)
2211 return decl;
2213 /* Scan the current scope for a decl with name NAME. */
2214 if (chain_member (decl, current_binding_level->names))
2215 return decl;
2217 return 0;
2220 /* Create the predefined scalar types of C,
2221 and some nodes representing standard constants (0, 1, (void *) 0).
2222 Initialize the global binding level.
2223 Make definitions for built-in primitive functions. */
2225 void
2226 c_init_decl_processing (void)
2228 tree endlink;
2229 tree ptr_ftype_void, ptr_ftype_ptr;
2230 location_t save_loc = input_location;
2232 /* Adds some ggc roots, and reserved words for c-parse.in. */
2233 c_parse_init ();
2235 current_function_decl = NULL;
2236 named_labels = NULL;
2237 current_binding_level = NULL_BINDING_LEVEL;
2238 free_binding_level = NULL_BINDING_LEVEL;
2240 /* Make the binding_level structure for global names. */
2241 pushlevel (0);
2242 global_binding_level = current_binding_level;
2243 /* Declarations from c_common_nodes_and_builtins must not be associated
2244 with this input file, lest we get differences between using and not
2245 using preprocessed headers. */
2246 input_location.file = "<internal>";
2247 input_location.line = 0;
2249 build_common_tree_nodes (flag_signed_char);
2251 c_common_nodes_and_builtins ();
2253 boolean_type_node = integer_type_node;
2254 boolean_true_node = integer_one_node;
2255 boolean_false_node = integer_zero_node;
2257 c_bool_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
2258 TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
2259 TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
2260 TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
2261 TYPE_PRECISION (c_bool_type_node) = 1;
2262 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
2263 c_bool_type_node));
2264 c_bool_false_node = build_int_2 (0, 0);
2265 TREE_TYPE (c_bool_false_node) = c_bool_type_node;
2266 c_bool_true_node = build_int_2 (1, 0);
2267 TREE_TYPE (c_bool_true_node) = c_bool_type_node;
2269 endlink = void_list_node;
2270 ptr_ftype_void = build_function_type (ptr_type_node, endlink);
2271 ptr_ftype_ptr
2272 = build_function_type (ptr_type_node,
2273 tree_cons (NULL_TREE, ptr_type_node, endlink));
2275 input_location = save_loc;
2277 pedantic_lvalues = pedantic;
2279 make_fname_decl = c_make_fname_decl;
2280 start_fname_decls ();
2283 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2284 decl, NAME is the initialization string and TYPE_DEP indicates whether
2285 NAME depended on the type of the function. As we don't yet implement
2286 delayed emission of static data, we mark the decl as emitted
2287 so it is not placed in the output. Anything using it must therefore pull
2288 out the STRING_CST initializer directly. This does mean that these names
2289 are string merging candidates, which is wrong for C99's __func__. FIXME. */
2291 static tree
2292 c_make_fname_decl (tree id, int type_dep)
2294 const char *name = fname_as_string (type_dep);
2295 tree decl, type, init;
2296 size_t length = strlen (name);
2298 type = build_array_type
2299 (build_qualified_type (char_type_node, TYPE_QUAL_CONST),
2300 build_index_type (size_int (length)));
2302 decl = build_decl (VAR_DECL, id, type);
2304 TREE_STATIC (decl) = 1;
2305 TREE_READONLY (decl) = 1;
2306 DECL_ARTIFICIAL (decl) = 1;
2308 init = build_string (length + 1, name);
2309 TREE_TYPE (init) = type;
2310 DECL_INITIAL (decl) = init;
2312 TREE_USED (decl) = 1;
2314 if (current_function_decl)
2315 pushdecl_function_level (decl, DECL_NAME (decl));
2317 finish_decl (decl, init, NULL_TREE);
2319 return decl;
2322 /* Return a definition for a builtin function named NAME and whose data type
2323 is TYPE. TYPE should be a function type with argument types.
2324 FUNCTION_CODE tells later passes how to compile calls to this function.
2325 See tree.h for its possible values.
2327 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
2328 the name to be called if we can't opencode the function. If
2329 ATTRS is nonzero, use that for the function's attribute list. */
2331 tree
2332 builtin_function (const char *name, tree type, int function_code,
2333 enum built_in_class class, const char *library_name,
2334 tree attrs)
2336 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
2337 DECL_EXTERNAL (decl) = 1;
2338 TREE_PUBLIC (decl) = 1;
2339 if (library_name)
2340 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
2341 make_decl_rtl (decl, NULL);
2342 pushdecl (decl);
2343 DECL_BUILT_IN_CLASS (decl) = class;
2344 DECL_FUNCTION_CODE (decl) = function_code;
2346 /* Warn if a function in the namespace for users
2347 is used without an occasion to consider it declared. */
2348 if (name[0] != '_' || name[1] != '_')
2349 C_DECL_INVISIBLE (decl) = 1;
2351 /* Possibly apply some default attributes to this built-in function. */
2352 if (attrs)
2353 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
2354 else
2355 decl_attributes (&decl, NULL_TREE, 0);
2357 return decl;
2360 /* Apply default attributes to a function, if a system function with default
2361 attributes. */
2363 void
2364 c_insert_default_attributes (tree decl)
2366 if (!TREE_PUBLIC (decl))
2367 return;
2368 c_common_insert_default_attributes (decl);
2371 /* Called when a declaration is seen that contains no names to declare.
2372 If its type is a reference to a structure, union or enum inherited
2373 from a containing scope, shadow that tag name for the current scope
2374 with a forward reference.
2375 If its type defines a new named structure or union
2376 or defines an enum, it is valid but we need not do anything here.
2377 Otherwise, it is an error. */
2379 void
2380 shadow_tag (tree declspecs)
2382 shadow_tag_warned (declspecs, 0);
2385 void
2386 shadow_tag_warned (tree declspecs, int warned)
2389 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
2390 no pedwarn. */
2392 int found_tag = 0;
2393 tree link;
2394 tree specs, attrs;
2396 pending_invalid_xref = 0;
2398 /* Remove the attributes from declspecs, since they will confuse the
2399 following code. */
2400 split_specs_attrs (declspecs, &specs, &attrs);
2402 for (link = specs; link; link = TREE_CHAIN (link))
2404 tree value = TREE_VALUE (link);
2405 enum tree_code code = TREE_CODE (value);
2407 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
2408 /* Used to test also that TYPE_SIZE (value) != 0.
2409 That caused warning for `struct foo;' at top level in the file. */
2411 tree name = TYPE_NAME (value);
2412 tree t;
2414 found_tag++;
2416 if (name == 0)
2418 if (warned != 1 && code != ENUMERAL_TYPE)
2419 /* Empty unnamed enum OK */
2421 pedwarn ("unnamed struct/union that defines no instances");
2422 warned = 1;
2425 else
2427 t = lookup_tag (code, name, 1);
2429 if (t == 0)
2431 t = make_node (code);
2432 pushtag (name, t);
2436 else
2438 if (!warned && ! in_system_header)
2440 warning ("useless keyword or type name in empty declaration");
2441 warned = 2;
2446 if (found_tag > 1)
2447 error ("two types specified in one empty declaration");
2449 if (warned != 1)
2451 if (found_tag == 0)
2452 pedwarn ("empty declaration");
2456 /* Construct an array declarator. EXPR is the expression inside [], or
2457 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
2458 to the pointer to which a parameter array is converted). STATIC_P is
2459 nonzero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P
2460 is nonzero is the array is [*], a VLA of unspecified length which is
2461 nevertheless a complete type (not currently implemented by GCC),
2462 zero otherwise. The declarator is constructed as an ARRAY_REF
2463 (to be decoded by grokdeclarator), whose operand 0 is what's on the
2464 left of the [] (filled by in set_array_declarator_type) and operand 1
2465 is the expression inside; whose TREE_TYPE is the type qualifiers and
2466 which has TREE_STATIC set if "static" is used. */
2468 tree
2469 build_array_declarator (tree expr, tree quals, int static_p, int vla_unspec_p)
2471 tree decl;
2472 decl = build_nt (ARRAY_REF, NULL_TREE, expr);
2473 TREE_TYPE (decl) = quals;
2474 TREE_STATIC (decl) = (static_p ? 1 : 0);
2475 if (pedantic && !flag_isoc99)
2477 if (static_p || quals != NULL_TREE)
2478 pedwarn ("ISO C90 does not support `static' or type qualifiers in parameter array declarators");
2479 if (vla_unspec_p)
2480 pedwarn ("ISO C90 does not support `[*]' array declarators");
2482 if (vla_unspec_p)
2483 warning ("GCC does not yet properly implement `[*]' array declarators");
2484 return decl;
2487 /* Set the type of an array declarator. DECL is the declarator, as
2488 constructed by build_array_declarator; TYPE is what appears on the left
2489 of the [] and goes in operand 0. ABSTRACT_P is nonzero if it is an
2490 abstract declarator, zero otherwise; this is used to reject static and
2491 type qualifiers in abstract declarators, where they are not in the
2492 C99 grammar. */
2494 tree
2495 set_array_declarator_type (tree decl, tree type, int abstract_p)
2497 TREE_OPERAND (decl, 0) = type;
2498 if (abstract_p && (TREE_TYPE (decl) != NULL_TREE || TREE_STATIC (decl)))
2499 error ("static or type qualifiers in abstract declarator");
2500 return decl;
2503 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
2505 tree
2506 groktypename (tree typename)
2508 tree specs, attrs;
2510 if (TREE_CODE (typename) != TREE_LIST)
2511 return typename;
2513 split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs);
2515 typename = grokdeclarator (TREE_VALUE (typename), specs, TYPENAME, 0);
2517 /* Apply attributes. */
2518 decl_attributes (&typename, attrs, 0);
2520 return typename;
2523 /* Return a PARM_DECL node for a given pair of specs and declarator. */
2525 tree
2526 groktypename_in_parm_context (tree typename)
2528 if (TREE_CODE (typename) != TREE_LIST)
2529 return typename;
2530 return grokdeclarator (TREE_VALUE (typename),
2531 TREE_PURPOSE (typename),
2532 PARM, 0);
2535 /* Decode a declarator in an ordinary declaration or data definition.
2536 This is called as soon as the type information and variable name
2537 have been parsed, before parsing the initializer if any.
2538 Here we create the ..._DECL node, fill in its type,
2539 and put it on the list of decls for the current context.
2540 The ..._DECL node is returned as the value.
2542 Exception: for arrays where the length is not specified,
2543 the type is left null, to be filled in by `finish_decl'.
2545 Function definitions do not come here; they go to start_function
2546 instead. However, external and forward declarations of functions
2547 do go through here. Structure field declarations are done by
2548 grokfield and not through here. */
2550 tree
2551 start_decl (tree declarator, tree declspecs, int initialized, tree attributes)
2553 tree decl;
2554 tree tem;
2556 /* An object declared as __attribute__((deprecated)) suppresses
2557 warnings of uses of other deprecated items. */
2558 if (lookup_attribute ("deprecated", attributes))
2559 deprecated_state = DEPRECATED_SUPPRESS;
2561 decl = grokdeclarator (declarator, declspecs,
2562 NORMAL, initialized);
2564 deprecated_state = DEPRECATED_NORMAL;
2566 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
2567 && MAIN_NAME_P (DECL_NAME (decl)))
2568 warning_with_decl (decl, "`%s' is usually a function");
2570 if (initialized)
2571 /* Is it valid for this decl to have an initializer at all?
2572 If not, set INITIALIZED to zero, which will indirectly
2573 tell `finish_decl' to ignore the initializer once it is parsed. */
2574 switch (TREE_CODE (decl))
2576 case TYPE_DECL:
2577 error ("typedef `%s' is initialized (use __typeof__ instead)",
2578 IDENTIFIER_POINTER (DECL_NAME (decl)));
2579 initialized = 0;
2580 break;
2582 case FUNCTION_DECL:
2583 error ("function `%s' is initialized like a variable",
2584 IDENTIFIER_POINTER (DECL_NAME (decl)));
2585 initialized = 0;
2586 break;
2588 case PARM_DECL:
2589 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
2590 error ("parameter `%s' is initialized",
2591 IDENTIFIER_POINTER (DECL_NAME (decl)));
2592 initialized = 0;
2593 break;
2595 default:
2596 /* Don't allow initializations for incomplete types
2597 except for arrays which might be completed by the initialization. */
2599 /* This can happen if the array size is an undefined macro. We already
2600 gave a warning, so we don't need another one. */
2601 if (TREE_TYPE (decl) == error_mark_node)
2602 initialized = 0;
2603 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
2605 /* A complete type is ok if size is fixed. */
2607 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
2608 || C_DECL_VARIABLE_SIZE (decl))
2610 error ("variable-sized object may not be initialized");
2611 initialized = 0;
2614 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
2616 error ("variable `%s' has initializer but incomplete type",
2617 IDENTIFIER_POINTER (DECL_NAME (decl)));
2618 initialized = 0;
2620 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
2622 error ("elements of array `%s' have incomplete type",
2623 IDENTIFIER_POINTER (DECL_NAME (decl)));
2624 initialized = 0;
2628 if (initialized)
2630 #if 0
2631 /* Seems redundant with grokdeclarator. */
2632 if (current_binding_level != global_binding_level
2633 && DECL_EXTERNAL (decl)
2634 && TREE_CODE (decl) != FUNCTION_DECL)
2635 warning ("declaration of `%s' has `extern' and is initialized",
2636 IDENTIFIER_POINTER (DECL_NAME (decl)));
2637 #endif
2638 DECL_EXTERNAL (decl) = 0;
2639 if (current_binding_level == global_binding_level)
2640 TREE_STATIC (decl) = 1;
2642 /* Tell `pushdecl' this is an initialized decl
2643 even though we don't yet have the initializer expression.
2644 Also tell `finish_decl' it may store the real initializer. */
2645 DECL_INITIAL (decl) = error_mark_node;
2648 /* If this is a function declaration, write a record describing it to the
2649 prototypes file (if requested). */
2651 if (TREE_CODE (decl) == FUNCTION_DECL)
2652 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
2654 /* ANSI specifies that a tentative definition which is not merged with
2655 a non-tentative definition behaves exactly like a definition with an
2656 initializer equal to zero. (Section 3.7.2)
2658 -fno-common gives strict ANSI behavior, though this tends to break
2659 a large body of code that grew up without this rule.
2661 Thread-local variables are never common, since there's no entrenched
2662 body of code to break, and it allows more efficient variable references
2663 in the presence of dynamic linking. */
2665 if (TREE_CODE (decl) == VAR_DECL
2666 && !initialized
2667 && TREE_PUBLIC (decl)
2668 && !DECL_THREAD_LOCAL (decl)
2669 && !flag_no_common)
2670 DECL_COMMON (decl) = 1;
2672 /* Set attributes here so if duplicate decl, will have proper attributes. */
2673 decl_attributes (&decl, attributes, 0);
2675 /* If #pragma weak was used, mark the decl weak now. */
2676 if (current_binding_level == global_binding_level)
2677 maybe_apply_pragma_weak (decl);
2679 if (TREE_CODE (decl) == FUNCTION_DECL
2680 && DECL_DECLARED_INLINE_P (decl)
2681 && DECL_UNINLINABLE (decl)
2682 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
2683 warning_with_decl (decl,
2684 "inline function `%s' given attribute noinline");
2686 /* Add this decl to the current binding level.
2687 TEM may equal DECL or it may be a previous decl of the same name. */
2688 tem = pushdecl (decl);
2690 /* For a local variable, define the RTL now. */
2691 if (current_binding_level != global_binding_level
2692 /* But not if this is a duplicate decl
2693 and we preserved the rtl from the previous one
2694 (which may or may not happen). */
2695 && !DECL_RTL_SET_P (tem)
2696 && !DECL_CONTEXT (tem))
2698 if (TREE_TYPE (tem) != error_mark_node
2699 && COMPLETE_TYPE_P (TREE_TYPE (tem)))
2700 expand_decl (tem);
2701 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
2702 && DECL_INITIAL (tem) != 0)
2703 expand_decl (tem);
2706 return tem;
2709 /* Finish processing of a declaration;
2710 install its initial value.
2711 If the length of an array type is not known before,
2712 it must be determined now, from the initial value, or it is an error. */
2714 void
2715 finish_decl (tree decl, tree init, tree asmspec_tree)
2717 tree type = TREE_TYPE (decl);
2718 int was_incomplete = (DECL_SIZE (decl) == 0);
2719 const char *asmspec = 0;
2721 /* If a name was specified, get the string. */
2722 if (current_binding_level == global_binding_level)
2723 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
2724 if (asmspec_tree)
2725 asmspec = TREE_STRING_POINTER (asmspec_tree);
2727 /* If `start_decl' didn't like having an initialization, ignore it now. */
2728 if (init != 0 && DECL_INITIAL (decl) == 0)
2729 init = 0;
2731 /* Don't crash if parm is initialized. */
2732 if (TREE_CODE (decl) == PARM_DECL)
2733 init = 0;
2735 if (init)
2736 store_init_value (decl, init);
2738 /* Deduce size of array from initialization, if not already known */
2739 if (TREE_CODE (type) == ARRAY_TYPE
2740 && TYPE_DOMAIN (type) == 0
2741 && TREE_CODE (decl) != TYPE_DECL)
2743 int do_default
2744 = (TREE_STATIC (decl)
2745 /* Even if pedantic, an external linkage array
2746 may have incomplete type at first. */
2747 ? pedantic && !TREE_PUBLIC (decl)
2748 : !DECL_EXTERNAL (decl));
2749 int failure
2750 = complete_array_type (type, DECL_INITIAL (decl), do_default);
2752 /* Get the completed type made by complete_array_type. */
2753 type = TREE_TYPE (decl);
2755 if (failure == 1)
2756 error_with_decl (decl, "initializer fails to determine size of `%s'");
2758 else if (failure == 2)
2760 if (do_default)
2761 error_with_decl (decl, "array size missing in `%s'");
2762 /* If a `static' var's size isn't known,
2763 make it extern as well as static, so it does not get
2764 allocated.
2765 If it is not `static', then do not mark extern;
2766 finish_incomplete_decl will give it a default size
2767 and it will get allocated. */
2768 else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl))
2769 DECL_EXTERNAL (decl) = 1;
2772 /* TYPE_MAX_VALUE is always one less than the number of elements
2773 in the array, because we start counting at zero. Therefore,
2774 warn only if the value is less than zero. */
2775 else if (pedantic && TYPE_DOMAIN (type) != 0
2776 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
2777 error_with_decl (decl, "zero or negative size array `%s'");
2779 layout_decl (decl, 0);
2782 if (TREE_CODE (decl) == VAR_DECL)
2784 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
2785 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
2786 layout_decl (decl, 0);
2788 if (DECL_SIZE (decl) == 0
2789 /* Don't give an error if we already gave one earlier. */
2790 && TREE_TYPE (decl) != error_mark_node
2791 && (TREE_STATIC (decl)
2793 /* A static variable with an incomplete type
2794 is an error if it is initialized.
2795 Also if it is not file scope.
2796 Otherwise, let it through, but if it is not `extern'
2797 then it may cause an error message later. */
2798 (DECL_INITIAL (decl) != 0
2799 || DECL_CONTEXT (decl) != 0)
2801 /* An automatic variable with an incomplete type
2802 is an error. */
2803 !DECL_EXTERNAL (decl)))
2805 error_with_decl (decl, "storage size of `%s' isn't known");
2806 TREE_TYPE (decl) = error_mark_node;
2809 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
2810 && DECL_SIZE (decl) != 0)
2812 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
2813 constant_expression_warning (DECL_SIZE (decl));
2814 else
2815 error_with_decl (decl, "storage size of `%s' isn't constant");
2818 if (TREE_USED (type))
2819 TREE_USED (decl) = 1;
2822 /* If this is a function and an assembler name is specified, reset DECL_RTL
2823 so we can give it its new name. Also, update built_in_decls if it
2824 was a normal built-in. */
2825 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
2827 /* ASMSPEC is given, and not the name of a register. Mark the
2828 name with a star so assemble_name won't munge it. */
2829 char *starred = alloca (strlen (asmspec) + 2);
2830 starred[0] = '*';
2831 strcpy (starred + 1, asmspec);
2833 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
2835 tree builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
2836 SET_DECL_RTL (builtin, NULL_RTX);
2837 SET_DECL_ASSEMBLER_NAME (builtin, get_identifier (starred));
2838 #ifdef TARGET_MEM_FUNCTIONS
2839 if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMCPY)
2840 init_block_move_fn (starred);
2841 else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMSET)
2842 init_block_clear_fn (starred);
2843 #else
2844 if (DECL_FUNCTION_CODE (decl) == BUILT_IN_BCOPY)
2845 init_block_move_fn (starred);
2846 else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_BZERO)
2847 init_block_clear_fn (starred);
2848 #endif
2850 SET_DECL_RTL (decl, NULL_RTX);
2851 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (starred));
2854 /* Output the assembler code and/or RTL code for variables and functions,
2855 unless the type is an undefined structure or union.
2856 If not, it will get done when the type is completed. */
2858 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
2860 /* This is a no-op in c-lang.c or something real in objc-act.c. */
2861 if (c_dialect_objc ())
2862 objc_check_decl (decl);
2864 if (!DECL_CONTEXT (decl))
2866 if (DECL_INITIAL (decl) == NULL_TREE
2867 || DECL_INITIAL (decl) == error_mark_node)
2868 /* Don't output anything
2869 when a tentative file-scope definition is seen.
2870 But at end of compilation, do output code for them. */
2871 DECL_DEFER_OUTPUT (decl) = 1;
2872 rest_of_decl_compilation (decl, asmspec,
2873 (DECL_CONTEXT (decl) == 0
2874 || TREE_ASM_WRITTEN (decl)), 0);
2876 else
2878 /* This is a local variable. If there is an ASMSPEC, the
2879 user has requested that we handle it specially. */
2880 if (asmspec)
2882 /* In conjunction with an ASMSPEC, the `register'
2883 keyword indicates that we should place the variable
2884 in a particular register. */
2885 if (DECL_REGISTER (decl))
2886 DECL_C_HARD_REGISTER (decl) = 1;
2888 /* If this is not a static variable, issue a warning.
2889 It doesn't make any sense to give an ASMSPEC for an
2890 ordinary, non-register local variable. Historically,
2891 GCC has accepted -- but ignored -- the ASMSPEC in
2892 this case. */
2893 if (TREE_CODE (decl) == VAR_DECL
2894 && !DECL_REGISTER (decl)
2895 && !TREE_STATIC (decl))
2896 warning_with_decl (decl,
2897 "ignoring asm-specifier for non-static local variable `%s'");
2898 else
2899 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
2902 if (TREE_CODE (decl) != FUNCTION_DECL)
2903 add_decl_stmt (decl);
2906 if (DECL_CONTEXT (decl) != 0)
2908 /* Recompute the RTL of a local array now
2909 if it used to be an incomplete type. */
2910 if (was_incomplete
2911 && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
2913 /* If we used it already as memory, it must stay in memory. */
2914 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
2915 /* If it's still incomplete now, no init will save it. */
2916 if (DECL_SIZE (decl) == 0)
2917 DECL_INITIAL (decl) = 0;
2922 if (TREE_CODE (decl) == TYPE_DECL)
2924 /* This is a no-op in c-lang.c or something real in objc-act.c. */
2925 if (c_dialect_objc ())
2926 objc_check_decl (decl);
2927 rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0, 0);
2930 /* At the end of a declaration, throw away any variable type sizes
2931 of types defined inside that declaration. There is no use
2932 computing them in the following function definition. */
2933 if (current_binding_level == global_binding_level)
2934 get_pending_sizes ();
2936 /* Install a cleanup (aka destructor) if one was given. */
2937 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
2939 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
2940 if (attr)
2942 static bool eh_initialized_p;
2944 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
2945 tree cleanup_decl = lookup_name (cleanup_id);
2946 tree cleanup;
2948 /* Build "cleanup(&decl)" for the destructor. */
2949 cleanup = build_unary_op (ADDR_EXPR, decl, 0);
2950 cleanup = build_tree_list (NULL_TREE, cleanup);
2951 cleanup = build_function_call (cleanup_decl, cleanup);
2953 /* Don't warn about decl unused; the cleanup uses it. */
2954 TREE_USED (decl) = 1;
2956 /* Initialize EH, if we've been told to do so. */
2957 if (flag_exceptions && !eh_initialized_p)
2959 eh_initialized_p = true;
2960 eh_personality_libfunc
2961 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
2962 ? "__gcc_personality_sj0"
2963 : "__gcc_personality_v0");
2964 using_eh_for_cleanups ();
2967 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
2972 /* Given a parsed parameter declaration,
2973 decode it into a PARM_DECL and push that on the current binding level.
2974 Also, for the sake of forward parm decls,
2975 record the given order of parms in `parm_order'. */
2977 void
2978 push_parm_decl (tree parm)
2980 tree decl;
2981 int old_immediate_size_expand = immediate_size_expand;
2982 /* Don't try computing parm sizes now -- wait till fn is called. */
2983 immediate_size_expand = 0;
2985 decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
2986 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
2987 decl_attributes (&decl, TREE_VALUE (parm), 0);
2989 #if 0
2990 if (DECL_NAME (decl))
2992 tree olddecl;
2993 olddecl = lookup_name (DECL_NAME (decl));
2994 if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
2995 pedwarn_with_decl (decl,
2996 "ISO C forbids parameter `%s' shadowing typedef");
2998 #endif
3000 decl = pushdecl (decl);
3002 immediate_size_expand = old_immediate_size_expand;
3004 current_binding_level->parm_order
3005 = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
3007 /* Add this decl to the current binding level. */
3008 finish_decl (decl, NULL_TREE, NULL_TREE);
3011 /* Clear the given order of parms in `parm_order'.
3012 Used at start of parm list,
3013 and also at semicolon terminating forward decls. */
3015 void
3016 clear_parm_order (void)
3018 current_binding_level->parm_order = NULL_TREE;
3021 static GTY(()) int compound_literal_number;
3023 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3024 literal, which may be an incomplete array type completed by the
3025 initializer; INIT is a CONSTRUCTOR that initializes the compound
3026 literal. */
3028 tree
3029 build_compound_literal (tree type, tree init)
3031 /* We do not use start_decl here because we have a type, not a declarator;
3032 and do not use finish_decl because the decl should be stored inside
3033 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
3034 tree decl = build_decl (VAR_DECL, NULL_TREE, type);
3035 tree complit;
3036 tree stmt;
3037 DECL_EXTERNAL (decl) = 0;
3038 TREE_PUBLIC (decl) = 0;
3039 TREE_STATIC (decl) = (current_binding_level == global_binding_level);
3040 DECL_CONTEXT (decl) = current_function_decl;
3041 TREE_USED (decl) = 1;
3042 TREE_TYPE (decl) = type;
3043 TREE_READONLY (decl) = TREE_READONLY (type);
3044 store_init_value (decl, init);
3046 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
3048 int failure = complete_array_type (type, DECL_INITIAL (decl), 1);
3049 if (failure)
3050 abort ();
3053 type = TREE_TYPE (decl);
3054 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
3055 return error_mark_node;
3057 stmt = build_stmt (DECL_STMT, decl);
3058 complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt);
3059 TREE_SIDE_EFFECTS (complit) = 1;
3061 layout_decl (decl, 0);
3063 if (TREE_STATIC (decl))
3065 /* This decl needs a name for the assembler output. We also need
3066 a unique suffix to be added to the name. */
3067 char *name;
3069 ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
3070 compound_literal_number);
3071 compound_literal_number++;
3072 DECL_NAME (decl) = get_identifier (name);
3073 DECL_DEFER_OUTPUT (decl) = 1;
3074 DECL_COMDAT (decl) = 1;
3075 DECL_ARTIFICIAL (decl) = 1;
3076 pushdecl (decl);
3077 rest_of_decl_compilation (decl, NULL, 1, 0);
3080 return complit;
3083 /* Make TYPE a complete type based on INITIAL_VALUE.
3084 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3085 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3088 complete_array_type (tree type, tree initial_value, int do_default)
3090 tree maxindex = NULL_TREE;
3091 int value = 0;
3093 if (initial_value)
3095 /* Note MAXINDEX is really the maximum index,
3096 one less than the size. */
3097 if (TREE_CODE (initial_value) == STRING_CST)
3099 int eltsize
3100 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
3101 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
3102 / eltsize) - 1, 0);
3104 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
3106 tree elts = CONSTRUCTOR_ELTS (initial_value);
3107 maxindex = build_int_2 (-1, -1);
3108 for (; elts; elts = TREE_CHAIN (elts))
3110 if (TREE_PURPOSE (elts))
3111 maxindex = TREE_PURPOSE (elts);
3112 else
3113 maxindex = fold (build (PLUS_EXPR, integer_type_node,
3114 maxindex, integer_one_node));
3116 maxindex = copy_node (maxindex);
3118 else
3120 /* Make an error message unless that happened already. */
3121 if (initial_value != error_mark_node)
3122 value = 1;
3124 /* Prevent further error messages. */
3125 maxindex = build_int_2 (0, 0);
3129 if (!maxindex)
3131 if (do_default)
3132 maxindex = build_int_2 (0, 0);
3133 value = 2;
3136 if (maxindex)
3138 TYPE_DOMAIN (type) = build_index_type (maxindex);
3139 if (!TREE_TYPE (maxindex))
3140 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
3143 /* Lay out the type now that we can get the real answer. */
3145 layout_type (type);
3147 return value;
3150 /* Determine whether TYPE is a structure with a flexible array member,
3151 or a union containing such a structure (possibly recursively). */
3153 static bool
3154 flexible_array_type_p (tree type)
3156 tree x;
3157 switch (TREE_CODE (type))
3159 case RECORD_TYPE:
3160 x = TYPE_FIELDS (type);
3161 if (x == NULL_TREE)
3162 return false;
3163 while (TREE_CHAIN (x) != NULL_TREE)
3164 x = TREE_CHAIN (x);
3165 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
3166 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3167 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
3168 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
3169 return true;
3170 return false;
3171 case UNION_TYPE:
3172 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
3174 if (flexible_array_type_p (TREE_TYPE (x)))
3175 return true;
3177 return false;
3178 default:
3179 return false;
3183 /* Given declspecs and a declarator,
3184 determine the name and type of the object declared
3185 and construct a ..._DECL node for it.
3186 (In one case we can return a ..._TYPE node instead.
3187 For invalid input we sometimes return 0.)
3189 DECLSPECS is a chain of tree_list nodes whose value fields
3190 are the storage classes and type specifiers.
3192 DECL_CONTEXT says which syntactic context this declaration is in:
3193 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3194 FUNCDEF for a function definition. Like NORMAL but a few different
3195 error messages in each case. Return value may be zero meaning
3196 this definition is too screwy to try to parse.
3197 PARM for a parameter declaration (either within a function prototype
3198 or before a function body). Make a PARM_DECL, or return void_type_node.
3199 TYPENAME if for a typename (in a cast or sizeof).
3200 Don't make a DECL node; just return the ..._TYPE node.
3201 FIELD for a struct or union field; make a FIELD_DECL.
3202 BITFIELD for a field with specified width.
3203 INITIALIZED is 1 if the decl has an initializer.
3205 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3206 It may also be so in the PARM case, for a prototype where the
3207 argument type is specified but not the name.
3209 This function is where the complicated C meanings of `static'
3210 and `extern' are interpreted. */
3212 static tree
3213 grokdeclarator (tree declarator, tree declspecs,
3214 enum decl_context decl_context, int initialized)
3216 int specbits = 0;
3217 tree spec;
3218 tree type = NULL_TREE;
3219 int longlong = 0;
3220 int constp;
3221 int restrictp;
3222 int volatilep;
3223 int type_quals = TYPE_UNQUALIFIED;
3224 int inlinep;
3225 int explicit_int = 0;
3226 int explicit_char = 0;
3227 int defaulted_int = 0;
3228 tree typedef_decl = 0;
3229 const char *name;
3230 tree typedef_type = 0;
3231 int funcdef_flag = 0;
3232 enum tree_code innermost_code = ERROR_MARK;
3233 int bitfield = 0;
3234 int size_varies = 0;
3235 tree decl_attr = NULL_TREE;
3236 tree array_ptr_quals = NULL_TREE;
3237 int array_parm_static = 0;
3238 tree returned_attrs = NULL_TREE;
3240 if (decl_context == BITFIELD)
3241 bitfield = 1, decl_context = FIELD;
3243 if (decl_context == FUNCDEF)
3244 funcdef_flag = 1, decl_context = NORMAL;
3246 /* Look inside a declarator for the name being declared
3247 and get it as a string, for an error message. */
3249 tree decl = declarator;
3250 name = 0;
3252 while (decl)
3253 switch (TREE_CODE (decl))
3255 case ARRAY_REF:
3256 case INDIRECT_REF:
3257 case CALL_EXPR:
3258 innermost_code = TREE_CODE (decl);
3259 decl = TREE_OPERAND (decl, 0);
3260 break;
3262 case TREE_LIST:
3263 decl = TREE_VALUE (decl);
3264 break;
3266 case IDENTIFIER_NODE:
3267 name = IDENTIFIER_POINTER (decl);
3268 decl = 0;
3269 break;
3271 default:
3272 abort ();
3274 if (name == 0)
3275 name = "type name";
3278 /* A function definition's declarator must have the form of
3279 a function declarator. */
3281 if (funcdef_flag && innermost_code != CALL_EXPR)
3282 return 0;
3284 /* Anything declared one level down from the top level
3285 must be one of the parameters of a function
3286 (because the body is at least two levels down). */
3288 /* If this looks like a function definition, make it one,
3289 even if it occurs where parms are expected.
3290 Then store_parm_decls will reject it and not use it as a parm. */
3291 if (decl_context == NORMAL && !funcdef_flag
3292 && current_binding_level->parm_flag)
3293 decl_context = PARM;
3295 /* Look through the decl specs and record which ones appear.
3296 Some typespecs are defined as built-in typenames.
3297 Others, the ones that are modifiers of other types,
3298 are represented by bits in SPECBITS: set the bits for
3299 the modifiers that appear. Storage class keywords are also in SPECBITS.
3301 If there is a typedef name or a type, store the type in TYPE.
3302 This includes builtin typedefs such as `int'.
3304 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3305 and did not come from a user typedef.
3307 Set LONGLONG if `long' is mentioned twice. */
3309 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
3311 tree id = TREE_VALUE (spec);
3313 /* If the entire declaration is itself tagged as deprecated then
3314 suppress reports of deprecated items. */
3315 if (id && TREE_DEPRECATED (id))
3317 if (deprecated_state != DEPRECATED_SUPPRESS)
3318 warn_deprecated_use (id);
3321 if (id == ridpointers[(int) RID_INT])
3322 explicit_int = 1;
3323 if (id == ridpointers[(int) RID_CHAR])
3324 explicit_char = 1;
3326 if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (id))
3328 enum rid i = C_RID_CODE (id);
3329 if ((int) i <= (int) RID_LAST_MODIFIER)
3331 if (i == RID_LONG && (specbits & (1 << (int) RID_LONG)))
3333 if (longlong)
3334 error ("`long long long' is too long for GCC");
3335 else
3337 if (pedantic && !flag_isoc99 && ! in_system_header
3338 && warn_long_long)
3339 pedwarn ("ISO C90 does not support `long long'");
3340 longlong = 1;
3343 else if (specbits & (1 << (int) i))
3345 if (i == RID_CONST || i == RID_VOLATILE || i == RID_RESTRICT)
3347 if (!flag_isoc99)
3348 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
3350 else
3351 error ("duplicate `%s'", IDENTIFIER_POINTER (id));
3354 /* Diagnose "__thread extern". Recall that this list
3355 is in the reverse order seen in the text. */
3356 if (i == RID_THREAD
3357 && (specbits & (1 << (int) RID_EXTERN
3358 | 1 << (int) RID_STATIC)))
3360 if (specbits & 1 << (int) RID_EXTERN)
3361 error ("`__thread' before `extern'");
3362 else
3363 error ("`__thread' before `static'");
3366 specbits |= 1 << (int) i;
3367 goto found;
3370 if (type)
3371 error ("two or more data types in declaration of `%s'", name);
3372 /* Actual typedefs come to us as TYPE_DECL nodes. */
3373 else if (TREE_CODE (id) == TYPE_DECL)
3375 if (TREE_TYPE (id) == error_mark_node)
3376 ; /* Allow the type to default to int to avoid cascading errors. */
3377 else
3379 type = TREE_TYPE (id);
3380 decl_attr = DECL_ATTRIBUTES (id);
3381 typedef_decl = id;
3384 /* Built-in types come as identifiers. */
3385 else if (TREE_CODE (id) == IDENTIFIER_NODE)
3387 tree t = lookup_name (id);
3388 if (TREE_TYPE (t) == error_mark_node)
3390 else if (!t || TREE_CODE (t) != TYPE_DECL)
3391 error ("`%s' fails to be a typedef or built in type",
3392 IDENTIFIER_POINTER (id));
3393 else
3395 type = TREE_TYPE (t);
3396 typedef_decl = t;
3399 else if (TREE_CODE (id) != ERROR_MARK)
3400 type = id;
3402 found:
3406 typedef_type = type;
3407 if (type)
3408 size_varies = C_TYPE_VARIABLE_SIZE (type);
3410 /* No type at all: default to `int', and set DEFAULTED_INT
3411 because it was not a user-defined typedef. */
3413 if (type == 0)
3415 if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3416 | (1 << (int) RID_SIGNED)
3417 | (1 << (int) RID_UNSIGNED)
3418 | (1 << (int) RID_COMPLEX))))
3419 /* Don't warn about typedef foo = bar. */
3420 && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
3421 && ! in_system_header)
3423 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
3424 and this is a function, or if -Wimplicit; prefer the former
3425 warning since it is more explicit. */
3426 if ((warn_implicit_int || warn_return_type || flag_isoc99)
3427 && funcdef_flag)
3428 warn_about_return_type = 1;
3429 else if (warn_implicit_int || flag_isoc99)
3430 pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
3431 name);
3434 defaulted_int = 1;
3435 type = integer_type_node;
3438 /* Now process the modifiers that were specified
3439 and check for invalid combinations. */
3441 /* Long double is a special combination. */
3443 if ((specbits & 1 << (int) RID_LONG) && ! longlong
3444 && TYPE_MAIN_VARIANT (type) == double_type_node)
3446 specbits &= ~(1 << (int) RID_LONG);
3447 type = long_double_type_node;
3450 /* Check all other uses of type modifiers. */
3452 if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3453 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
3455 int ok = 0;
3457 if ((specbits & 1 << (int) RID_LONG)
3458 && (specbits & 1 << (int) RID_SHORT))
3459 error ("both long and short specified for `%s'", name);
3460 else if (((specbits & 1 << (int) RID_LONG)
3461 || (specbits & 1 << (int) RID_SHORT))
3462 && explicit_char)
3463 error ("long or short specified with char for `%s'", name);
3464 else if (((specbits & 1 << (int) RID_LONG)
3465 || (specbits & 1 << (int) RID_SHORT))
3466 && TREE_CODE (type) == REAL_TYPE)
3468 static int already = 0;
3470 error ("long or short specified with floating type for `%s'", name);
3471 if (! already && ! pedantic)
3473 error ("the only valid combination is `long double'");
3474 already = 1;
3477 else if ((specbits & 1 << (int) RID_SIGNED)
3478 && (specbits & 1 << (int) RID_UNSIGNED))
3479 error ("both signed and unsigned specified for `%s'", name);
3480 else if (TREE_CODE (type) != INTEGER_TYPE)
3481 error ("long, short, signed or unsigned invalid for `%s'", name);
3482 else
3484 ok = 1;
3485 if (!explicit_int && !defaulted_int && !explicit_char)
3487 error ("long, short, signed or unsigned used invalidly for `%s'",
3488 name);
3489 ok = 0;
3493 /* Discard the type modifiers if they are invalid. */
3494 if (! ok)
3496 specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3497 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
3498 longlong = 0;
3502 if ((specbits & (1 << (int) RID_COMPLEX))
3503 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
3505 error ("complex invalid for `%s'", name);
3506 specbits &= ~(1 << (int) RID_COMPLEX);
3509 /* Decide whether an integer type is signed or not.
3510 Optionally treat bitfields as signed by default. */
3511 if (specbits & 1 << (int) RID_UNSIGNED
3512 || (bitfield && ! flag_signed_bitfields
3513 && (explicit_int || defaulted_int || explicit_char
3514 /* A typedef for plain `int' without `signed'
3515 can be controlled just like plain `int'. */
3516 || ! (typedef_decl != 0
3517 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
3518 && TREE_CODE (type) != ENUMERAL_TYPE
3519 && !(specbits & 1 << (int) RID_SIGNED)))
3521 if (longlong)
3522 type = long_long_unsigned_type_node;
3523 else if (specbits & 1 << (int) RID_LONG)
3524 type = long_unsigned_type_node;
3525 else if (specbits & 1 << (int) RID_SHORT)
3526 type = short_unsigned_type_node;
3527 else if (type == char_type_node)
3528 type = unsigned_char_type_node;
3529 else if (typedef_decl)
3530 type = c_common_unsigned_type (type);
3531 else
3532 type = unsigned_type_node;
3534 else if ((specbits & 1 << (int) RID_SIGNED)
3535 && type == char_type_node)
3536 type = signed_char_type_node;
3537 else if (longlong)
3538 type = long_long_integer_type_node;
3539 else if (specbits & 1 << (int) RID_LONG)
3540 type = long_integer_type_node;
3541 else if (specbits & 1 << (int) RID_SHORT)
3542 type = short_integer_type_node;
3544 if (specbits & 1 << (int) RID_COMPLEX)
3546 if (pedantic && !flag_isoc99)
3547 pedwarn ("ISO C90 does not support complex types");
3548 /* If we just have "complex", it is equivalent to
3549 "complex double", but if any modifiers at all are specified it is
3550 the complex form of TYPE. E.g, "complex short" is
3551 "complex short int". */
3553 if (defaulted_int && ! longlong
3554 && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
3555 | (1 << (int) RID_SIGNED)
3556 | (1 << (int) RID_UNSIGNED))))
3558 if (pedantic)
3559 pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
3560 type = complex_double_type_node;
3562 else if (type == integer_type_node)
3564 if (pedantic)
3565 pedwarn ("ISO C does not support complex integer types");
3566 type = complex_integer_type_node;
3568 else if (type == float_type_node)
3569 type = complex_float_type_node;
3570 else if (type == double_type_node)
3571 type = complex_double_type_node;
3572 else if (type == long_double_type_node)
3573 type = complex_long_double_type_node;
3574 else
3576 if (pedantic)
3577 pedwarn ("ISO C does not support complex integer types");
3578 type = build_complex_type (type);
3582 /* Figure out the type qualifiers for the declaration. There are
3583 two ways a declaration can become qualified. One is something
3584 like `const int i' where the `const' is explicit. Another is
3585 something like `typedef const int CI; CI i' where the type of the
3586 declaration contains the `const'. */
3587 constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
3588 restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
3589 volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
3590 inlinep = !! (specbits & (1 << (int) RID_INLINE));
3591 if (constp > 1 && ! flag_isoc99)
3592 pedwarn ("duplicate `const'");
3593 if (restrictp > 1 && ! flag_isoc99)
3594 pedwarn ("duplicate `restrict'");
3595 if (volatilep > 1 && ! flag_isoc99)
3596 pedwarn ("duplicate `volatile'");
3597 if (! flag_gen_aux_info && (TYPE_QUALS (type)))
3598 type = TYPE_MAIN_VARIANT (type);
3599 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
3600 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
3601 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
3603 /* Warn if two storage classes are given. Default to `auto'. */
3606 int nclasses = 0;
3608 if (specbits & 1 << (int) RID_AUTO) nclasses++;
3609 if (specbits & 1 << (int) RID_STATIC) nclasses++;
3610 if (specbits & 1 << (int) RID_EXTERN) nclasses++;
3611 if (specbits & 1 << (int) RID_REGISTER) nclasses++;
3612 if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
3614 /* "static __thread" and "extern __thread" are allowed. */
3615 if ((specbits & (1 << (int) RID_THREAD
3616 | 1 << (int) RID_STATIC
3617 | 1 << (int) RID_EXTERN)) == (1 << (int) RID_THREAD))
3618 nclasses++;
3620 /* Warn about storage classes that are invalid for certain
3621 kinds of declarations (parameters, typenames, etc.). */
3623 if (nclasses > 1)
3624 error ("multiple storage classes in declaration of `%s'", name);
3625 else if (funcdef_flag
3626 && (specbits
3627 & ((1 << (int) RID_REGISTER)
3628 | (1 << (int) RID_AUTO)
3629 | (1 << (int) RID_TYPEDEF)
3630 | (1 << (int) RID_THREAD))))
3632 if (specbits & 1 << (int) RID_AUTO
3633 && (pedantic || current_binding_level == global_binding_level))
3634 pedwarn ("function definition declared `auto'");
3635 if (specbits & 1 << (int) RID_REGISTER)
3636 error ("function definition declared `register'");
3637 if (specbits & 1 << (int) RID_TYPEDEF)
3638 error ("function definition declared `typedef'");
3639 if (specbits & 1 << (int) RID_THREAD)
3640 error ("function definition declared `__thread'");
3641 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
3642 | (1 << (int) RID_AUTO) | (1 << (int) RID_THREAD));
3644 else if (decl_context != NORMAL && nclasses > 0)
3646 if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
3648 else
3650 switch (decl_context)
3652 case FIELD:
3653 error ("storage class specified for structure field `%s'",
3654 name);
3655 break;
3656 case PARM:
3657 error ("storage class specified for parameter `%s'", name);
3658 break;
3659 default:
3660 error ("storage class specified for typename");
3661 break;
3663 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
3664 | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
3665 | (1 << (int) RID_EXTERN) | (1 << (int) RID_THREAD));
3668 else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
3670 /* `extern' with initialization is invalid if not at top level. */
3671 if (current_binding_level == global_binding_level)
3672 warning ("`%s' initialized and declared `extern'", name);
3673 else
3674 error ("`%s' has both `extern' and initializer", name);
3676 else if (current_binding_level == global_binding_level)
3678 if (specbits & 1 << (int) RID_AUTO)
3679 error ("top-level declaration of `%s' specifies `auto'", name);
3681 else
3683 if (specbits & 1 << (int) RID_EXTERN && funcdef_flag)
3684 error ("nested function `%s' declared `extern'", name);
3685 else if ((specbits & (1 << (int) RID_THREAD
3686 | 1 << (int) RID_EXTERN
3687 | 1 << (int) RID_STATIC))
3688 == (1 << (int) RID_THREAD))
3690 error ("function-scope `%s' implicitly auto and declared `__thread'",
3691 name);
3692 specbits &= ~(1 << (int) RID_THREAD);
3697 /* Now figure out the structure of the declarator proper.
3698 Descend through it, creating more complex types, until we reach
3699 the declared identifier (or NULL_TREE, in an absolute declarator). */
3701 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
3703 if (type == error_mark_node)
3705 declarator = TREE_OPERAND (declarator, 0);
3706 continue;
3709 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
3710 an INDIRECT_REF (for *...),
3711 a CALL_EXPR (for ...(...)),
3712 a TREE_LIST (for nested attributes),
3713 an identifier (for the name being declared)
3714 or a null pointer (for the place in an absolute declarator
3715 where the name was omitted).
3716 For the last two cases, we have just exited the loop.
3718 At this point, TYPE is the type of elements of an array,
3719 or for a function to return, or for a pointer to point to.
3720 After this sequence of ifs, TYPE is the type of the
3721 array or function or pointer, and DECLARATOR has had its
3722 outermost layer removed. */
3724 if (array_ptr_quals != NULL_TREE || array_parm_static)
3726 /* Only the innermost declarator (making a parameter be of
3727 array type which is converted to pointer type)
3728 may have static or type qualifiers. */
3729 error ("static or type qualifiers in non-parameter array declarator");
3730 array_ptr_quals = NULL_TREE;
3731 array_parm_static = 0;
3734 if (TREE_CODE (declarator) == TREE_LIST)
3736 /* We encode a declarator with embedded attributes using
3737 a TREE_LIST. */
3738 tree attrs = TREE_PURPOSE (declarator);
3739 tree inner_decl;
3740 int attr_flags = 0;
3741 declarator = TREE_VALUE (declarator);
3742 inner_decl = declarator;
3743 while (inner_decl != NULL_TREE
3744 && TREE_CODE (inner_decl) == TREE_LIST)
3745 inner_decl = TREE_VALUE (inner_decl);
3746 if (inner_decl == NULL_TREE
3747 || TREE_CODE (inner_decl) == IDENTIFIER_NODE)
3748 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
3749 else if (TREE_CODE (inner_decl) == CALL_EXPR)
3750 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
3751 else if (TREE_CODE (inner_decl) == ARRAY_REF)
3752 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
3753 returned_attrs = decl_attributes (&type,
3754 chainon (returned_attrs, attrs),
3755 attr_flags);
3757 else if (TREE_CODE (declarator) == ARRAY_REF)
3759 tree itype = NULL_TREE;
3760 tree size = TREE_OPERAND (declarator, 1);
3761 /* The index is a signed object `sizetype' bits wide. */
3762 tree index_type = c_common_signed_type (sizetype);
3764 array_ptr_quals = TREE_TYPE (declarator);
3765 array_parm_static = TREE_STATIC (declarator);
3767 declarator = TREE_OPERAND (declarator, 0);
3769 /* Check for some types that there cannot be arrays of. */
3771 if (VOID_TYPE_P (type))
3773 error ("declaration of `%s' as array of voids", name);
3774 type = error_mark_node;
3777 if (TREE_CODE (type) == FUNCTION_TYPE)
3779 error ("declaration of `%s' as array of functions", name);
3780 type = error_mark_node;
3783 if (pedantic && flexible_array_type_p (type))
3784 pedwarn ("invalid use of structure with flexible array member");
3786 if (size == error_mark_node)
3787 type = error_mark_node;
3789 if (type == error_mark_node)
3790 continue;
3792 /* If size was specified, set ITYPE to a range-type for that size.
3793 Otherwise, ITYPE remains null. finish_decl may figure it out
3794 from an initial value. */
3796 if (size)
3798 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3799 STRIP_TYPE_NOPS (size);
3801 if (! INTEGRAL_TYPE_P (TREE_TYPE (size)))
3803 error ("size of array `%s' has non-integer type", name);
3804 size = integer_one_node;
3807 if (pedantic && integer_zerop (size))
3808 pedwarn ("ISO C forbids zero-size array `%s'", name);
3810 if (TREE_CODE (size) == INTEGER_CST)
3812 constant_expression_warning (size);
3813 if (tree_int_cst_sgn (size) < 0)
3815 error ("size of array `%s' is negative", name);
3816 size = integer_one_node;
3819 else
3821 /* Make sure the array size remains visibly nonconstant
3822 even if it is (eg) a const variable with known value. */
3823 size_varies = 1;
3825 if (!flag_isoc99 && pedantic)
3827 if (TREE_CONSTANT (size))
3828 pedwarn ("ISO C90 forbids array `%s' whose size can't be evaluated",
3829 name);
3830 else
3831 pedwarn ("ISO C90 forbids variable-size array `%s'",
3832 name);
3836 if (integer_zerop (size))
3838 /* A zero-length array cannot be represented with an
3839 unsigned index type, which is what we'll get with
3840 build_index_type. Create an open-ended range instead. */
3841 itype = build_range_type (sizetype, size, NULL_TREE);
3843 else
3845 /* Compute the maximum valid index, that is, size - 1.
3846 Do the calculation in index_type, so that if it is
3847 a variable the computations will be done in the
3848 proper mode. */
3849 itype = fold (build (MINUS_EXPR, index_type,
3850 convert (index_type, size),
3851 convert (index_type, size_one_node)));
3853 /* If that overflowed, the array is too big.
3854 ??? While a size of INT_MAX+1 technically shouldn't
3855 cause an overflow (because we subtract 1), the overflow
3856 is recorded during the conversion to index_type, before
3857 the subtraction. Handling this case seems like an
3858 unnecessary complication. */
3859 if (TREE_OVERFLOW (itype))
3861 error ("size of array `%s' is too large", name);
3862 type = error_mark_node;
3863 continue;
3866 if (size_varies)
3868 /* We must be able to distinguish the
3869 SAVE_EXPR_CONTEXT for the variably-sized type
3870 so that we can set it correctly in
3871 set_save_expr_context. The convention is
3872 that all SAVE_EXPRs that need to be reset
3873 have NULL_TREE for their SAVE_EXPR_CONTEXT. */
3874 tree cfd = current_function_decl;
3875 if (decl_context == PARM)
3876 current_function_decl = NULL_TREE;
3877 itype = variable_size (itype);
3878 if (decl_context == PARM)
3879 current_function_decl = cfd;
3881 itype = build_index_type (itype);
3884 else if (decl_context == FIELD)
3886 if (pedantic && !flag_isoc99 && !in_system_header)
3887 pedwarn ("ISO C90 does not support flexible array members");
3889 /* ISO C99 Flexible array members are effectively identical
3890 to GCC's zero-length array extension. */
3891 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
3894 /* If pedantic, complain about arrays of incomplete types. */
3896 if (pedantic && !COMPLETE_TYPE_P (type))
3897 pedwarn ("array type has incomplete element type");
3899 #if 0
3900 /* We shouldn't have a function type here at all!
3901 Functions aren't allowed as array elements. */
3902 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
3903 && (constp || volatilep))
3904 pedwarn ("ISO C forbids const or volatile function types");
3905 #endif
3907 /* Build the array type itself, then merge any constancy or
3908 volatility into the target type. We must do it in this order
3909 to ensure that the TYPE_MAIN_VARIANT field of the array type
3910 is set correctly. */
3912 type = build_array_type (type, itype);
3913 if (type_quals)
3914 type = c_build_qualified_type (type, type_quals);
3916 if (size_varies)
3917 C_TYPE_VARIABLE_SIZE (type) = 1;
3919 /* The GCC extension for zero-length arrays differs from
3920 ISO flexible array members in that sizeof yields zero. */
3921 if (size && integer_zerop (size))
3923 layout_type (type);
3924 TYPE_SIZE (type) = bitsize_zero_node;
3925 TYPE_SIZE_UNIT (type) = size_zero_node;
3927 if (decl_context != PARM
3928 && (array_ptr_quals != NULL_TREE || array_parm_static))
3930 error ("static or type qualifiers in non-parameter array declarator");
3931 array_ptr_quals = NULL_TREE;
3932 array_parm_static = 0;
3935 else if (TREE_CODE (declarator) == CALL_EXPR)
3937 tree arg_types;
3939 /* Declaring a function type.
3940 Make sure we have a valid type for the function to return. */
3941 if (type == error_mark_node)
3942 continue;
3944 size_varies = 0;
3946 /* Warn about some types functions can't return. */
3948 if (TREE_CODE (type) == FUNCTION_TYPE)
3950 error ("`%s' declared as function returning a function", name);
3951 type = integer_type_node;
3953 if (TREE_CODE (type) == ARRAY_TYPE)
3955 error ("`%s' declared as function returning an array", name);
3956 type = integer_type_node;
3959 /* Construct the function type and go to the next
3960 inner layer of declarator. */
3962 arg_types = grokparms (TREE_OPERAND (declarator, 1),
3963 funcdef_flag
3964 /* Say it's a definition
3965 only for the CALL_EXPR
3966 closest to the identifier. */
3967 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
3968 /* Type qualifiers before the return type of the function
3969 qualify the return type, not the function type. */
3970 if (type_quals)
3972 /* Type qualifiers on a function return type are normally
3973 permitted by the standard but have no effect, so give a
3974 warning at -Wextra. Qualifiers on a void return type have
3975 meaning as a GNU extension, and are banned on function
3976 definitions in ISO C. FIXME: strictly we shouldn't
3977 pedwarn for qualified void return types except on function
3978 definitions, but not doing so could lead to the undesirable
3979 state of a "volatile void" function return type not being
3980 warned about, and a use of the function being compiled
3981 with GNU semantics, with no diagnostics under -pedantic. */
3982 if (VOID_TYPE_P (type) && pedantic && !in_system_header)
3983 pedwarn ("ISO C forbids qualified void function return type");
3984 else if (extra_warnings
3985 && !(VOID_TYPE_P (type)
3986 && type_quals == TYPE_QUAL_VOLATILE))
3987 warning ("type qualifiers ignored on function return type");
3989 type = c_build_qualified_type (type, type_quals);
3991 type_quals = TYPE_UNQUALIFIED;
3993 type = build_function_type (type, arg_types);
3994 declarator = TREE_OPERAND (declarator, 0);
3996 /* Set the TYPE_CONTEXTs for each tagged type which is local to
3997 the formal parameter list of this FUNCTION_TYPE to point to
3998 the FUNCTION_TYPE node itself. */
4001 tree link;
4003 for (link = last_function_parm_tags;
4004 link;
4005 link = TREE_CHAIN (link))
4006 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4009 else if (TREE_CODE (declarator) == INDIRECT_REF)
4011 /* Merge any constancy or volatility into the target type
4012 for the pointer. */
4014 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4015 && type_quals)
4016 pedwarn ("ISO C forbids qualified function types");
4017 if (type_quals)
4018 type = c_build_qualified_type (type, type_quals);
4019 type_quals = TYPE_UNQUALIFIED;
4020 size_varies = 0;
4022 type = build_pointer_type (type);
4024 /* Process a list of type modifier keywords
4025 (such as const or volatile) that were given inside the `*'. */
4027 if (TREE_TYPE (declarator))
4029 tree typemodlist;
4030 int erred = 0;
4032 constp = 0;
4033 volatilep = 0;
4034 restrictp = 0;
4035 for (typemodlist = TREE_TYPE (declarator); typemodlist;
4036 typemodlist = TREE_CHAIN (typemodlist))
4038 tree qualifier = TREE_VALUE (typemodlist);
4040 if (C_IS_RESERVED_WORD (qualifier))
4042 if (C_RID_CODE (qualifier) == RID_CONST)
4043 constp++;
4044 else if (C_RID_CODE (qualifier) == RID_VOLATILE)
4045 volatilep++;
4046 else if (C_RID_CODE (qualifier) == RID_RESTRICT)
4047 restrictp++;
4048 else
4049 erred++;
4051 else
4052 erred++;
4055 if (erred)
4056 error ("invalid type modifier within pointer declarator");
4057 if (constp > 1 && ! flag_isoc99)
4058 pedwarn ("duplicate `const'");
4059 if (volatilep > 1 && ! flag_isoc99)
4060 pedwarn ("duplicate `volatile'");
4061 if (restrictp > 1 && ! flag_isoc99)
4062 pedwarn ("duplicate `restrict'");
4064 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4065 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4066 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4069 declarator = TREE_OPERAND (declarator, 0);
4071 else
4072 abort ();
4076 /* Now TYPE has the actual type. */
4078 /* Did array size calculations overflow? */
4080 if (TREE_CODE (type) == ARRAY_TYPE
4081 && COMPLETE_TYPE_P (type)
4082 && TREE_OVERFLOW (TYPE_SIZE (type)))
4084 error ("size of array `%s' is too large", name);
4085 /* If we proceed with the array type as it is, we'll eventually
4086 crash in tree_low_cst(). */
4087 type = error_mark_node;
4090 /* If this is declaring a typedef name, return a TYPE_DECL. */
4092 if (specbits & (1 << (int) RID_TYPEDEF))
4094 tree decl;
4095 /* Note that the grammar rejects storage classes
4096 in typenames, fields or parameters */
4097 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4098 && type_quals)
4099 pedwarn ("ISO C forbids qualified function types");
4100 if (type_quals)
4101 type = c_build_qualified_type (type, type_quals);
4102 decl = build_decl (TYPE_DECL, declarator, type);
4103 if ((specbits & (1 << (int) RID_SIGNED))
4104 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4105 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4106 decl_attributes (&decl, returned_attrs, 0);
4107 return decl;
4110 /* Detect the case of an array type of unspecified size
4111 which came, as such, direct from a typedef name.
4112 We must copy the type, so that each identifier gets
4113 a distinct type, so that each identifier's size can be
4114 controlled separately by its own initializer. */
4116 if (type != 0 && typedef_type != 0
4117 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
4118 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
4120 type = build_array_type (TREE_TYPE (type), 0);
4121 if (size_varies)
4122 C_TYPE_VARIABLE_SIZE (type) = 1;
4125 /* If this is a type name (such as, in a cast or sizeof),
4126 compute the type and return it now. */
4128 if (decl_context == TYPENAME)
4130 /* Note that the grammar rejects storage classes
4131 in typenames, fields or parameters */
4132 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4133 && type_quals)
4134 pedwarn ("ISO C forbids const or volatile function types");
4135 if (type_quals)
4136 type = c_build_qualified_type (type, type_quals);
4137 decl_attributes (&type, returned_attrs, 0);
4138 return type;
4141 /* Aside from typedefs and type names (handle above),
4142 `void' at top level (not within pointer)
4143 is allowed only in public variables.
4144 We don't complain about parms either, but that is because
4145 a better error message can be made later. */
4147 if (VOID_TYPE_P (type) && decl_context != PARM
4148 && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4149 && ((specbits & (1 << (int) RID_EXTERN))
4150 || (current_binding_level == global_binding_level
4151 && !(specbits
4152 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
4154 error ("variable or field `%s' declared void", name);
4155 type = integer_type_node;
4158 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4159 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4162 tree decl;
4164 if (decl_context == PARM)
4166 tree type_as_written;
4167 tree promoted_type;
4169 /* A parameter declared as an array of T is really a pointer to T.
4170 One declared as a function is really a pointer to a function. */
4172 if (TREE_CODE (type) == ARRAY_TYPE)
4174 /* Transfer const-ness of array into that of type pointed to. */
4175 type = TREE_TYPE (type);
4176 if (type_quals)
4177 type = c_build_qualified_type (type, type_quals);
4178 type = build_pointer_type (type);
4179 type_quals = TYPE_UNQUALIFIED;
4180 if (array_ptr_quals)
4182 tree new_ptr_quals, new_ptr_attrs;
4183 int erred = 0;
4184 split_specs_attrs (array_ptr_quals, &new_ptr_quals, &new_ptr_attrs);
4185 /* We don't yet implement attributes in this context. */
4186 if (new_ptr_attrs != NULL_TREE)
4187 warning ("attributes in parameter array declarator ignored");
4189 constp = 0;
4190 volatilep = 0;
4191 restrictp = 0;
4192 for (; new_ptr_quals; new_ptr_quals = TREE_CHAIN (new_ptr_quals))
4194 tree qualifier = TREE_VALUE (new_ptr_quals);
4196 if (C_IS_RESERVED_WORD (qualifier))
4198 if (C_RID_CODE (qualifier) == RID_CONST)
4199 constp++;
4200 else if (C_RID_CODE (qualifier) == RID_VOLATILE)
4201 volatilep++;
4202 else if (C_RID_CODE (qualifier) == RID_RESTRICT)
4203 restrictp++;
4204 else
4205 erred++;
4207 else
4208 erred++;
4211 if (erred)
4212 error ("invalid type modifier within array declarator");
4214 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4215 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4216 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4218 size_varies = 0;
4220 else if (TREE_CODE (type) == FUNCTION_TYPE)
4222 if (pedantic && type_quals)
4223 pedwarn ("ISO C forbids qualified function types");
4224 if (type_quals)
4225 type = c_build_qualified_type (type, type_quals);
4226 type = build_pointer_type (type);
4227 type_quals = TYPE_UNQUALIFIED;
4229 else if (type_quals)
4230 type = c_build_qualified_type (type, type_quals);
4232 type_as_written = type;
4234 decl = build_decl (PARM_DECL, declarator, type);
4235 if (size_varies)
4236 C_DECL_VARIABLE_SIZE (decl) = 1;
4238 /* Compute the type actually passed in the parmlist,
4239 for the case where there is no prototype.
4240 (For example, shorts and chars are passed as ints.)
4241 When there is a prototype, this is overridden later. */
4243 if (type == error_mark_node)
4244 promoted_type = type;
4245 else
4246 promoted_type = c_type_promotes_to (type);
4248 DECL_ARG_TYPE (decl) = promoted_type;
4249 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
4251 else if (decl_context == FIELD)
4253 /* Structure field. It may not be a function. */
4255 if (TREE_CODE (type) == FUNCTION_TYPE)
4257 error ("field `%s' declared as a function", name);
4258 type = build_pointer_type (type);
4260 else if (TREE_CODE (type) != ERROR_MARK
4261 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
4263 error ("field `%s' has incomplete type", name);
4264 type = error_mark_node;
4266 /* Move type qualifiers down to element of an array. */
4267 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4269 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4270 type_quals),
4271 TYPE_DOMAIN (type));
4272 #if 0
4273 /* Leave the field const or volatile as well. */
4274 type_quals = TYPE_UNQUALIFIED;
4275 #endif
4277 decl = build_decl (FIELD_DECL, declarator, type);
4278 DECL_NONADDRESSABLE_P (decl) = bitfield;
4280 if (size_varies)
4281 C_DECL_VARIABLE_SIZE (decl) = 1;
4283 else if (TREE_CODE (type) == FUNCTION_TYPE)
4285 /* Every function declaration is "external"
4286 except for those which are inside a function body
4287 in which `auto' is used.
4288 That is a case not specified by ANSI C,
4289 and we use it for forward declarations for nested functions. */
4290 int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
4291 || current_binding_level == global_binding_level);
4293 if (specbits & (1 << (int) RID_AUTO)
4294 && (pedantic || current_binding_level == global_binding_level))
4295 pedwarn ("invalid storage class for function `%s'", name);
4296 if (specbits & (1 << (int) RID_REGISTER))
4297 error ("invalid storage class for function `%s'", name);
4298 if (specbits & (1 << (int) RID_THREAD))
4299 error ("invalid storage class for function `%s'", name);
4300 /* Function declaration not at top level.
4301 Storage classes other than `extern' are not allowed
4302 and `extern' makes no difference. */
4303 if (current_binding_level != global_binding_level
4304 && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
4305 && pedantic)
4306 pedwarn ("invalid storage class for function `%s'", name);
4308 decl = build_decl (FUNCTION_DECL, declarator, type);
4309 decl = build_decl_attribute_variant (decl, decl_attr);
4311 DECL_LANG_SPECIFIC (decl) = (struct lang_decl *)
4312 ggc_alloc_cleared (sizeof (struct lang_decl));
4314 if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
4315 pedwarn ("ISO C forbids qualified function types");
4317 /* GNU C interprets a `volatile void' return type to indicate
4318 that the function does not return. */
4319 if ((type_quals & TYPE_QUAL_VOLATILE)
4320 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
4321 warning ("`noreturn' function returns non-void value");
4323 if (extern_ref)
4324 DECL_EXTERNAL (decl) = 1;
4325 /* Record absence of global scope for `static' or `auto'. */
4326 TREE_PUBLIC (decl)
4327 = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
4329 if (defaulted_int)
4330 C_FUNCTION_IMPLICIT_INT (decl) = 1;
4332 /* Record presence of `inline', if it is reasonable. */
4333 if (MAIN_NAME_P (declarator))
4335 if (inlinep)
4336 warning ("cannot inline function `main'");
4338 else if (inlinep)
4340 /* Assume that otherwise the function can be inlined. */
4341 DECL_DECLARED_INLINE_P (decl) = 1;
4343 /* Do not mark bare declarations as DECL_INLINE. Doing so
4344 in the presence of multiple declarations can result in
4345 the abstract origin pointing between the declarations,
4346 which will confuse dwarf2out. */
4347 if (initialized)
4349 DECL_INLINE (decl) = 1;
4350 if (specbits & (1 << (int) RID_EXTERN))
4351 current_extern_inline = 1;
4354 /* If -finline-functions, assume it can be inlined. This does
4355 two things: let the function be deferred until it is actually
4356 needed, and let dwarf2 know that the function is inlinable. */
4357 else if (flag_inline_trees == 2 && initialized)
4359 if (!DECL_INLINE (decl))
4360 DID_INLINE_FUNC (decl) = 1;
4361 DECL_INLINE (decl) = 1;
4362 DECL_DECLARED_INLINE_P (decl) = 0;
4365 else
4367 /* It's a variable. */
4368 /* An uninitialized decl with `extern' is a reference. */
4369 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
4371 /* Move type qualifiers down to element of an array. */
4372 if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
4374 int saved_align = TYPE_ALIGN(type);
4375 type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
4376 type_quals),
4377 TYPE_DOMAIN (type));
4378 TYPE_ALIGN (type) = saved_align;
4379 #if 0 /* Leave the variable const or volatile as well. */
4380 type_quals = TYPE_UNQUALIFIED;
4381 #endif
4383 else if (type_quals)
4384 type = c_build_qualified_type (type, type_quals);
4386 /* It is invalid to create an `extern' declaration for a
4387 variable if there is a global declaration that is
4388 `static'. */
4389 if (extern_ref && current_binding_level != global_binding_level)
4391 tree global_decl;
4393 global_decl = identifier_global_value (declarator);
4394 if (global_decl
4395 && TREE_CODE (global_decl) == VAR_DECL
4396 && !TREE_PUBLIC (global_decl))
4397 error ("variable previously declared `static' redeclared "
4398 "`extern'");
4401 decl = build_decl (VAR_DECL, declarator, type);
4402 if (size_varies)
4403 C_DECL_VARIABLE_SIZE (decl) = 1;
4405 if (inlinep)
4406 pedwarn_with_decl (decl, "variable `%s' declared `inline'");
4408 DECL_EXTERNAL (decl) = extern_ref;
4410 /* At top level, the presence of a `static' or `register' storage
4411 class specifier, or the absence of all storage class specifiers
4412 makes this declaration a definition (perhaps tentative). Also,
4413 the absence of both `static' and `register' makes it public. */
4414 if (current_binding_level == global_binding_level)
4416 TREE_PUBLIC (decl) = !(specbits & ((1 << (int) RID_STATIC)
4417 | (1 << (int) RID_REGISTER)));
4418 TREE_STATIC (decl) = !extern_ref;
4420 /* Not at top level, only `static' makes a static definition. */
4421 else
4423 TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
4424 TREE_PUBLIC (decl) = extern_ref;
4427 if (specbits & 1 << (int) RID_THREAD)
4429 if (targetm.have_tls)
4430 DECL_THREAD_LOCAL (decl) = 1;
4431 else
4432 /* A mere warning is sure to result in improper semantics
4433 at runtime. Don't bother to allow this to compile. */
4434 error ("thread-local storage not supported for this target");
4438 /* Record `register' declaration for warnings on &
4439 and in case doing stupid register allocation. */
4441 if (specbits & (1 << (int) RID_REGISTER))
4442 DECL_REGISTER (decl) = 1;
4444 /* Record constancy and volatility. */
4445 c_apply_type_quals_to_decl (type_quals, decl);
4447 /* If a type has volatile components, it should be stored in memory.
4448 Otherwise, the fact that those components are volatile
4449 will be ignored, and would even crash the compiler. */
4450 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
4451 c_mark_addressable (decl);
4453 decl_attributes (&decl, returned_attrs, 0);
4455 return decl;
4459 /* Decode the parameter-list info for a function type or function definition.
4460 The argument is the value returned by `get_parm_info' (or made in parse.y
4461 if there is an identifier list instead of a parameter decl list).
4462 These two functions are separate because when a function returns
4463 or receives functions then each is called multiple times but the order
4464 of calls is different. The last call to `grokparms' is always the one
4465 that contains the formal parameter names of a function definition.
4467 Store in `last_function_parms' a chain of the decls of parms.
4468 Also store in `last_function_parm_tags' a chain of the struct, union,
4469 and enum tags declared among the parms.
4471 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4473 FUNCDEF_FLAG is nonzero for a function definition, 0 for
4474 a mere declaration. A nonempty identifier-list gets an error message
4475 when FUNCDEF_FLAG is zero. */
4477 static tree
4478 grokparms (tree parms_info, int funcdef_flag)
4480 tree first_parm = TREE_CHAIN (parms_info);
4482 last_function_parms = TREE_PURPOSE (parms_info);
4483 last_function_parm_tags = TREE_VALUE (parms_info);
4485 if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
4486 && !in_system_header)
4487 warning ("function declaration isn't a prototype");
4489 if (first_parm != 0
4490 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
4492 if (! funcdef_flag)
4493 pedwarn ("parameter names (without types) in function declaration");
4495 last_function_parms = first_parm;
4496 return 0;
4498 else
4500 tree parm;
4501 tree typelt;
4502 /* We no longer test FUNCDEF_FLAG.
4503 If the arg types are incomplete in a declaration,
4504 they must include undefined tags.
4505 These tags can never be defined in the scope of the declaration,
4506 so the types can never be completed,
4507 and no call can be compiled successfully. */
4508 #if 0
4509 /* In a fcn definition, arg types must be complete. */
4510 if (funcdef_flag)
4511 #endif
4512 for (parm = last_function_parms, typelt = first_parm;
4513 parm;
4514 parm = TREE_CHAIN (parm))
4515 /* Skip over any enumeration constants declared here. */
4516 if (TREE_CODE (parm) == PARM_DECL)
4518 /* Barf if the parameter itself has an incomplete type. */
4519 tree type = TREE_VALUE (typelt);
4520 if (type == error_mark_node)
4521 continue;
4522 if (!COMPLETE_TYPE_P (type))
4524 if (funcdef_flag && DECL_NAME (parm) != 0)
4525 error ("parameter `%s' has incomplete type",
4526 IDENTIFIER_POINTER (DECL_NAME (parm)));
4527 else
4528 warning ("parameter has incomplete type");
4529 if (funcdef_flag)
4531 TREE_VALUE (typelt) = error_mark_node;
4532 TREE_TYPE (parm) = error_mark_node;
4535 #if 0
4536 /* This has been replaced by parm_tags_warning, which
4537 uses a more accurate criterion for what to warn
4538 about. */
4539 else
4541 /* Now warn if is a pointer to an incomplete type. */
4542 while (TREE_CODE (type) == POINTER_TYPE
4543 || TREE_CODE (type) == REFERENCE_TYPE)
4544 type = TREE_TYPE (type);
4545 type = TYPE_MAIN_VARIANT (type);
4546 if (!COMPLETE_TYPE_P (type))
4548 if (DECL_NAME (parm) != 0)
4549 warning ("parameter `%s' points to incomplete type",
4550 IDENTIFIER_POINTER (DECL_NAME (parm)));
4551 else
4552 warning ("parameter points to incomplete type");
4555 #endif
4556 typelt = TREE_CHAIN (typelt);
4559 return first_parm;
4563 /* Return a tree_list node with info on a parameter list just parsed.
4564 The TREE_PURPOSE is a chain of decls of those parms.
4565 The TREE_VALUE is a list of structure, union and enum tags defined.
4566 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
4567 This tree_list node is later fed to `grokparms'.
4569 VOID_AT_END nonzero means append `void' to the end of the type-list.
4570 Zero means the parmlist ended with an ellipsis so don't append `void'. */
4572 tree
4573 get_parm_info (int void_at_end)
4575 tree decl, t;
4576 tree types = 0;
4577 int erred = 0;
4578 tree tags = gettags ();
4579 tree parms = getdecls ();
4580 tree new_parms = 0;
4581 tree order = current_binding_level->parm_order;
4583 /* Just `void' (and no ellipsis) is special. There are really no parms.
4584 But if the `void' is qualified (by `const' or `volatile') or has a
4585 storage class specifier (`register'), then the behavior is undefined;
4586 by not counting it as the special case of `void' we will cause an
4587 error later. Typedefs for `void' are OK (see DR#157). */
4588 if (void_at_end && parms != 0
4589 && TREE_CHAIN (parms) == 0
4590 && VOID_TYPE_P (TREE_TYPE (parms))
4591 && ! TREE_THIS_VOLATILE (parms)
4592 && ! TREE_READONLY (parms)
4593 && ! DECL_REGISTER (parms)
4594 && DECL_NAME (parms) == 0)
4596 parms = NULL_TREE;
4597 storedecls (NULL_TREE);
4598 return tree_cons (NULL_TREE, NULL_TREE,
4599 tree_cons (NULL_TREE, void_type_node, NULL_TREE));
4602 /* Extract enumerator values and other non-parms declared with the parms.
4603 Likewise any forward parm decls that didn't have real parm decls. */
4604 for (decl = parms; decl;)
4606 tree next = TREE_CHAIN (decl);
4608 if (TREE_CODE (decl) != PARM_DECL)
4610 TREE_CHAIN (decl) = new_parms;
4611 new_parms = decl;
4613 else if (TREE_ASM_WRITTEN (decl))
4615 error_with_decl (decl,
4616 "parameter `%s' has just a forward declaration");
4617 TREE_CHAIN (decl) = new_parms;
4618 new_parms = decl;
4620 decl = next;
4623 /* Put the parm decls back in the order they were in in the parm list. */
4624 for (t = order; t; t = TREE_CHAIN (t))
4626 if (TREE_CHAIN (t))
4627 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
4628 else
4629 TREE_CHAIN (TREE_VALUE (t)) = 0;
4632 new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
4633 new_parms);
4635 /* Store the parmlist in the binding level since the old one
4636 is no longer a valid list. (We have changed the chain pointers.) */
4637 storedecls (new_parms);
4639 for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
4640 /* There may also be declarations for enumerators if an enumeration
4641 type is declared among the parms. Ignore them here. */
4642 if (TREE_CODE (decl) == PARM_DECL)
4644 /* Since there is a prototype,
4645 args are passed in their declared types. */
4646 tree type = TREE_TYPE (decl);
4647 DECL_ARG_TYPE (decl) = type;
4648 if (PROMOTE_PROTOTYPES
4649 && INTEGRAL_TYPE_P (type)
4650 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
4651 DECL_ARG_TYPE (decl) = integer_type_node;
4653 types = tree_cons (NULL_TREE, TREE_TYPE (decl), types);
4654 if (VOID_TYPE_P (TREE_VALUE (types)) && ! erred
4655 && DECL_NAME (decl) == 0)
4657 error ("`void' in parameter list must be the entire list");
4658 erred = 1;
4662 if (void_at_end)
4663 return tree_cons (new_parms, tags,
4664 nreverse (tree_cons (NULL_TREE, void_type_node, types)));
4666 return tree_cons (new_parms, tags, nreverse (types));
4669 /* At end of parameter list, warn about any struct, union or enum tags
4670 defined within. Do so because these types cannot ever become complete. */
4672 void
4673 parmlist_tags_warning (void)
4675 tree elt;
4676 static int already;
4678 for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
4680 enum tree_code code = TREE_CODE (TREE_VALUE (elt));
4681 /* An anonymous union parm type is meaningful as a GNU extension.
4682 So don't warn for that. */
4683 if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic)
4684 continue;
4685 if (TREE_PURPOSE (elt) != 0)
4687 if (code == RECORD_TYPE)
4688 warning ("`struct %s' declared inside parameter list",
4689 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4690 else if (code == UNION_TYPE)
4691 warning ("`union %s' declared inside parameter list",
4692 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4693 else
4694 warning ("`enum %s' declared inside parameter list",
4695 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
4697 else
4699 /* For translation these need to be separate warnings */
4700 if (code == RECORD_TYPE)
4701 warning ("anonymous struct declared inside parameter list");
4702 else if (code == UNION_TYPE)
4703 warning ("anonymous union declared inside parameter list");
4704 else
4705 warning ("anonymous enum declared inside parameter list");
4707 if (! already)
4709 warning ("its scope is only this definition or declaration, which is probably not what you want");
4710 already = 1;
4715 /* Get the struct, enum or union (CODE says which) with tag NAME.
4716 Define the tag as a forward-reference if it is not defined. */
4718 tree
4719 xref_tag (enum tree_code code, tree name)
4721 /* If a cross reference is requested, look up the type
4722 already defined for this tag and return it. */
4724 tree ref = lookup_tag (code, name, 0);
4725 /* If this is the right type of tag, return what we found.
4726 (This reference will be shadowed by shadow_tag later if appropriate.)
4727 If this is the wrong type of tag, do not return it. If it was the
4728 wrong type in the same binding level, we will have had an error
4729 message already; if in a different binding level and declaring
4730 a name, pending_xref_error will give an error message; but if in a
4731 different binding level and not declaring a name, this tag should
4732 shadow the previous declaration of a different type of tag, and
4733 this would not work properly if we return the reference found.
4734 (For example, with "struct foo" in an outer scope, "union foo;"
4735 must shadow that tag with a new one of union type.) */
4736 if (ref && TREE_CODE (ref) == code)
4737 return ref;
4739 /* If no such tag is yet defined, create a forward-reference node
4740 and record it as the "definition".
4741 When a real declaration of this type is found,
4742 the forward-reference will be altered into a real type. */
4744 ref = make_node (code);
4745 if (code == ENUMERAL_TYPE)
4747 /* Give the type a default layout like unsigned int
4748 to avoid crashing if it does not get defined. */
4749 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
4750 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
4751 TYPE_USER_ALIGN (ref) = 0;
4752 TREE_UNSIGNED (ref) = 1;
4753 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
4754 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
4755 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
4758 pushtag (name, ref);
4760 return ref;
4763 /* Make sure that the tag NAME is defined *in the current binding level*
4764 at least as a forward reference.
4765 CODE says which kind of tag NAME ought to be. */
4767 tree
4768 start_struct (enum tree_code code, tree name)
4770 /* If there is already a tag defined at this binding level
4771 (as a forward reference), just return it. */
4773 tree ref = 0;
4775 if (name != 0)
4776 ref = lookup_tag (code, name, 1);
4777 if (ref && TREE_CODE (ref) == code)
4779 if (TYPE_FIELDS (ref))
4781 if (code == UNION_TYPE)
4782 error ("redefinition of `union %s'", IDENTIFIER_POINTER (name));
4783 else
4784 error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name));
4787 else
4789 /* Otherwise create a forward-reference just so the tag is in scope. */
4791 ref = make_node (code);
4792 pushtag (name, ref);
4795 C_TYPE_BEING_DEFINED (ref) = 1;
4796 TYPE_PACKED (ref) = flag_pack_struct;
4797 return ref;
4800 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
4801 of a structure component, returning a FIELD_DECL node.
4802 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
4804 This is done during the parsing of the struct declaration.
4805 The FIELD_DECL nodes are chained together and the lot of them
4806 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
4808 tree
4809 grokfield (tree declarator, tree declspecs, tree width)
4811 tree value;
4813 if (declarator == NULL_TREE && width == NULL_TREE)
4815 /* This is an unnamed decl.
4817 If we have something of the form "union { list } ;" then this
4818 is the anonymous union extension. Similarly for struct.
4820 If this is something of the form "struct foo;", then
4821 If MS extensions are enabled, this is handled as an
4822 anonymous struct.
4823 Otherwise this is a forward declaration of a structure tag.
4825 If this is something of the form "foo;" and foo is a TYPE_DECL, then
4826 If MS extensions are enabled and foo names a structure, then
4827 again this is an anonymous struct.
4828 Otherwise this is an error.
4830 Oh what a horrid tangled web we weave. I wonder if MS consciously
4831 took this from Plan 9 or if it was an accident of implementation
4832 that took root before someone noticed the bug... */
4834 tree type = TREE_VALUE (declspecs);
4836 if (flag_ms_extensions && TREE_CODE (type) == TYPE_DECL)
4837 type = TREE_TYPE (type);
4838 if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE)
4840 if (flag_ms_extensions)
4841 ; /* ok */
4842 else if (flag_iso)
4843 goto warn_unnamed_field;
4844 else if (TYPE_NAME (type) == NULL)
4845 ; /* ok */
4846 else
4847 goto warn_unnamed_field;
4849 else
4851 warn_unnamed_field:
4852 warning ("declaration does not declare anything");
4853 return NULL_TREE;
4857 value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
4859 finish_decl (value, NULL_TREE, NULL_TREE);
4860 DECL_INITIAL (value) = width;
4862 if (c_dialect_objc ())
4863 objc_check_decl (value);
4864 return value;
4867 /* Generate an error for any duplicate field names in FIELDLIST. Munge
4868 the list such that this does not present a problem later. */
4870 static void
4871 detect_field_duplicates (tree fieldlist)
4873 tree x, y;
4874 int timeout = 10;
4876 /* First, see if there are more than "a few" fields.
4877 This is trivially true if there are zero or one fields. */
4878 if (!fieldlist)
4879 return;
4880 x = TREE_CHAIN (fieldlist);
4881 if (!x)
4882 return;
4883 do {
4884 timeout--;
4885 x = TREE_CHAIN (x);
4886 } while (timeout > 0 && x);
4888 /* If there were "few" fields, avoid the overhead of allocating
4889 a hash table. Instead just do the nested traversal thing. */
4890 if (timeout > 0)
4892 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x))
4893 if (DECL_NAME (x))
4895 for (y = fieldlist; y != x; y = TREE_CHAIN (y))
4896 if (DECL_NAME (y) == DECL_NAME (x))
4898 error_with_decl (x, "duplicate member `%s'");
4899 DECL_NAME (x) = NULL_TREE;
4903 else
4905 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
4906 void **slot;
4908 for (x = fieldlist; x ; x = TREE_CHAIN (x))
4909 if ((y = DECL_NAME (x)) != 0)
4911 slot = htab_find_slot (htab, y, INSERT);
4912 if (*slot)
4914 error_with_decl (x, "duplicate member `%s'");
4915 DECL_NAME (x) = NULL_TREE;
4917 *slot = y;
4920 htab_delete (htab);
4924 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
4925 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
4926 ATTRIBUTES are attributes to be applied to the structure. */
4928 tree
4929 finish_struct (tree t, tree fieldlist, tree attributes)
4931 tree x;
4932 int toplevel = global_binding_level == current_binding_level;
4933 int saw_named_field;
4935 /* If this type was previously laid out as a forward reference,
4936 make sure we lay it out again. */
4938 TYPE_SIZE (t) = 0;
4940 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
4942 /* Nameless union parm types are useful as GCC extension. */
4943 if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
4944 /* Otherwise, warn about any struct or union def. in parmlist. */
4945 if (in_parm_level_p ())
4947 if (pedantic)
4948 pedwarn ("%s defined inside parms",
4949 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure"));
4950 else
4951 warning ("%s defined inside parms",
4952 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure"));
4955 if (pedantic)
4957 for (x = fieldlist; x; x = TREE_CHAIN (x))
4958 if (DECL_NAME (x) != 0)
4959 break;
4961 if (x == 0)
4962 pedwarn ("%s has no %s",
4963 TREE_CODE (t) == UNION_TYPE ? _("union") : _("struct"),
4964 fieldlist ? _("named members") : _("members"));
4967 /* Install struct as DECL_CONTEXT of each field decl.
4968 Also process specified field sizes,m which is found in the DECL_INITIAL.
4969 Store 0 there, except for ": 0" fields (so we can find them
4970 and delete them, below). */
4972 saw_named_field = 0;
4973 for (x = fieldlist; x; x = TREE_CHAIN (x))
4975 DECL_CONTEXT (x) = t;
4976 DECL_PACKED (x) |= TYPE_PACKED (t);
4978 /* If any field is const, the structure type is pseudo-const. */
4979 if (TREE_READONLY (x))
4980 C_TYPE_FIELDS_READONLY (t) = 1;
4981 else
4983 /* A field that is pseudo-const makes the structure likewise. */
4984 tree t1 = TREE_TYPE (x);
4985 while (TREE_CODE (t1) == ARRAY_TYPE)
4986 t1 = TREE_TYPE (t1);
4987 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
4988 && C_TYPE_FIELDS_READONLY (t1))
4989 C_TYPE_FIELDS_READONLY (t) = 1;
4992 /* Any field that is volatile means variables of this type must be
4993 treated in some ways as volatile. */
4994 if (TREE_THIS_VOLATILE (x))
4995 C_TYPE_FIELDS_VOLATILE (t) = 1;
4997 /* Any field of nominal variable size implies structure is too. */
4998 if (C_DECL_VARIABLE_SIZE (x))
4999 C_TYPE_VARIABLE_SIZE (t) = 1;
5001 /* Detect invalid nested redefinition. */
5002 if (TREE_TYPE (x) == t)
5003 error ("nested redefinition of `%s'",
5004 IDENTIFIER_POINTER (TYPE_NAME (t)));
5006 /* Detect invalid bit-field size. */
5007 if (DECL_INITIAL (x))
5008 STRIP_NOPS (DECL_INITIAL (x));
5009 if (DECL_INITIAL (x))
5011 if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST)
5012 constant_expression_warning (DECL_INITIAL (x));
5013 else
5015 error_with_decl (x,
5016 "bit-field `%s' width not an integer constant");
5017 DECL_INITIAL (x) = NULL;
5021 /* Detect invalid bit-field type. */
5022 if (DECL_INITIAL (x)
5023 && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
5024 && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE
5025 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
5027 error_with_decl (x, "bit-field `%s' has invalid type");
5028 DECL_INITIAL (x) = NULL;
5031 if (DECL_INITIAL (x) && pedantic
5032 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
5033 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
5034 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node
5035 /* Accept an enum that's equivalent to int or unsigned int. */
5036 && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5037 && (TYPE_PRECISION (TREE_TYPE (x))
5038 == TYPE_PRECISION (integer_type_node))))
5039 pedwarn_with_decl (x, "bit-field `%s' type invalid in ISO C");
5041 /* Detect and ignore out of range field width and process valid
5042 field widths. */
5043 if (DECL_INITIAL (x))
5045 int max_width
5046 = (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node
5047 ? CHAR_TYPE_SIZE : TYPE_PRECISION (TREE_TYPE (x)));
5049 if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
5050 error_with_decl (x, "negative width in bit-field `%s'");
5051 else if (0 < compare_tree_int (DECL_INITIAL (x), max_width))
5052 pedwarn_with_decl (x, "width of `%s' exceeds its type");
5053 else if (integer_zerop (DECL_INITIAL (x)) && DECL_NAME (x) != 0)
5054 error_with_decl (x, "zero width for bit-field `%s'");
5055 else
5057 /* The test above has assured us that TREE_INT_CST_HIGH is 0. */
5058 unsigned HOST_WIDE_INT width
5059 = tree_low_cst (DECL_INITIAL (x), 1);
5061 if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5062 && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
5063 TREE_UNSIGNED (TREE_TYPE (x)))
5064 || (width
5065 < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
5066 TREE_UNSIGNED (TREE_TYPE (x))))))
5067 warning_with_decl (x,
5068 "`%s' is narrower than values of its type");
5070 DECL_SIZE (x) = bitsize_int (width);
5071 DECL_BIT_FIELD (x) = 1;
5072 SET_DECL_C_BIT_FIELD (x);
5076 DECL_INITIAL (x) = 0;
5078 /* Detect flexible array member in an invalid context. */
5079 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5080 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
5081 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
5082 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
5084 if (TREE_CODE (t) == UNION_TYPE)
5085 error_with_decl (x, "flexible array member in union");
5086 else if (TREE_CHAIN (x) != NULL_TREE)
5087 error_with_decl (x, "flexible array member not at end of struct");
5088 else if (! saw_named_field)
5089 error_with_decl (x, "flexible array member in otherwise empty struct");
5092 if (pedantic && TREE_CODE (t) == RECORD_TYPE
5093 && flexible_array_type_p (TREE_TYPE (x)))
5094 pedwarn_with_decl (x, "invalid use of structure with flexible array member");
5096 if (DECL_NAME (x))
5097 saw_named_field = 1;
5100 detect_field_duplicates (fieldlist);
5102 /* Now we have the nearly final fieldlist. Record it,
5103 then lay out the structure or union (including the fields). */
5105 TYPE_FIELDS (t) = fieldlist;
5107 layout_type (t);
5109 /* Delete all zero-width bit-fields from the fieldlist */
5111 tree *fieldlistp = &fieldlist;
5112 while (*fieldlistp)
5113 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
5114 *fieldlistp = TREE_CHAIN (*fieldlistp);
5115 else
5116 fieldlistp = &TREE_CHAIN (*fieldlistp);
5119 /* Now we have the truly final field list.
5120 Store it in this type and in the variants. */
5122 TYPE_FIELDS (t) = fieldlist;
5124 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5126 TYPE_FIELDS (x) = TYPE_FIELDS (t);
5127 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
5128 TYPE_ALIGN (x) = TYPE_ALIGN (t);
5129 TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t);
5132 /* If this was supposed to be a transparent union, but we can't
5133 make it one, warn and turn off the flag. */
5134 if (TREE_CODE (t) == UNION_TYPE
5135 && TYPE_TRANSPARENT_UNION (t)
5136 && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))
5138 TYPE_TRANSPARENT_UNION (t) = 0;
5139 warning ("union cannot be made transparent");
5142 /* If this structure or union completes the type of any previous
5143 variable declaration, lay it out and output its rtl. */
5145 if (current_binding_level->incomplete_list != NULL_TREE)
5147 tree prev = NULL_TREE;
5149 for (x = current_binding_level->incomplete_list; x; x = TREE_CHAIN (x))
5151 tree decl = TREE_VALUE (x);
5153 if (TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TYPE_MAIN_VARIANT (t)
5154 && TREE_CODE (decl) != TYPE_DECL)
5156 layout_decl (decl, 0);
5157 /* This is a no-op in c-lang.c or something real in objc-act.c. */
5158 if (c_dialect_objc ())
5159 objc_check_decl (decl);
5160 rest_of_decl_compilation (decl, NULL, toplevel, 0);
5161 if (! toplevel)
5162 expand_decl (decl);
5163 /* Unlink X from the incomplete list. */
5164 if (prev)
5165 TREE_CHAIN (prev) = TREE_CHAIN (x);
5166 else
5167 current_binding_level->incomplete_list = TREE_CHAIN (x);
5169 else if (!COMPLETE_TYPE_P (TREE_TYPE (decl))
5170 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
5172 tree element = TREE_TYPE (decl);
5173 while (TREE_CODE (element) == ARRAY_TYPE)
5174 element = TREE_TYPE (element);
5175 if (element == t)
5177 layout_array_type (TREE_TYPE (decl));
5178 if (TREE_CODE (decl) != TYPE_DECL)
5180 layout_decl (decl, 0);
5181 if (c_dialect_objc ())
5182 objc_check_decl (decl);
5183 rest_of_decl_compilation (decl, NULL, toplevel, 0);
5184 if (! toplevel)
5185 expand_decl (decl);
5187 /* Unlink X from the incomplete list. */
5188 if (prev)
5189 TREE_CHAIN (prev) = TREE_CHAIN (x);
5190 else
5191 current_binding_level->incomplete_list = TREE_CHAIN (x);
5197 /* Finish debugging output for this type. */
5198 rest_of_type_compilation (t, toplevel);
5200 return t;
5203 /* Lay out the type T, and its element type, and so on. */
5205 static void
5206 layout_array_type (tree t)
5208 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5209 layout_array_type (TREE_TYPE (t));
5210 layout_type (t);
5213 /* Begin compiling the definition of an enumeration type.
5214 NAME is its name (or null if anonymous).
5215 Returns the type object, as yet incomplete.
5216 Also records info about it so that build_enumerator
5217 may be used to declare the individual values as they are read. */
5219 tree
5220 start_enum (tree name)
5222 tree enumtype = 0;
5224 /* If this is the real definition for a previous forward reference,
5225 fill in the contents in the same object that used to be the
5226 forward reference. */
5228 if (name != 0)
5229 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1);
5231 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
5233 enumtype = make_node (ENUMERAL_TYPE);
5234 pushtag (name, enumtype);
5237 C_TYPE_BEING_DEFINED (enumtype) = 1;
5239 if (TYPE_VALUES (enumtype) != 0)
5241 /* This enum is a named one that has been declared already. */
5242 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
5244 /* Completely replace its old definition.
5245 The old enumerators remain defined, however. */
5246 TYPE_VALUES (enumtype) = 0;
5249 enum_next_value = integer_zero_node;
5250 enum_overflow = 0;
5252 if (flag_short_enums)
5253 TYPE_PACKED (enumtype) = 1;
5255 return enumtype;
5258 /* After processing and defining all the values of an enumeration type,
5259 install their decls in the enumeration type and finish it off.
5260 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5261 and ATTRIBUTES are the specified attributes.
5262 Returns ENUMTYPE. */
5264 tree
5265 finish_enum (tree enumtype, tree values, tree attributes)
5267 tree pair, tem;
5268 tree minnode = 0, maxnode = 0, enum_value_type;
5269 int precision, unsign;
5270 int toplevel = (global_binding_level == current_binding_level);
5272 if (in_parm_level_p ())
5273 warning ("enum defined inside parms");
5275 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5277 /* Calculate the maximum value of any enumerator in this type. */
5279 if (values == error_mark_node)
5280 minnode = maxnode = integer_zero_node;
5281 else
5283 minnode = maxnode = TREE_VALUE (values);
5284 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
5286 tree value = TREE_VALUE (pair);
5287 if (tree_int_cst_lt (maxnode, value))
5288 maxnode = value;
5289 if (tree_int_cst_lt (value, minnode))
5290 minnode = value;
5294 /* Construct the final type of this enumeration. It is the same
5295 as one of the integral types - the narrowest one that fits, except
5296 that normally we only go as narrow as int - and signed iff any of
5297 the values are negative. */
5298 unsign = (tree_int_cst_sgn (minnode) >= 0);
5299 precision = MAX (min_precision (minnode, unsign),
5300 min_precision (maxnode, unsign));
5301 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
5303 tree narrowest = c_common_type_for_size (precision, unsign);
5304 if (narrowest == 0)
5306 warning ("enumeration values exceed range of largest integer");
5307 narrowest = long_long_integer_type_node;
5310 precision = TYPE_PRECISION (narrowest);
5312 else
5313 precision = TYPE_PRECISION (integer_type_node);
5315 if (precision == TYPE_PRECISION (integer_type_node))
5316 enum_value_type = c_common_type_for_size (precision, 0);
5317 else
5318 enum_value_type = enumtype;
5320 TYPE_MIN_VALUE (enumtype) = minnode;
5321 TYPE_MAX_VALUE (enumtype) = maxnode;
5322 TYPE_PRECISION (enumtype) = precision;
5323 TREE_UNSIGNED (enumtype) = unsign;
5324 TYPE_SIZE (enumtype) = 0;
5325 layout_type (enumtype);
5327 if (values != error_mark_node)
5329 /* Change the type of the enumerators to be the enum type. We
5330 need to do this irrespective of the size of the enum, for
5331 proper type checking. Replace the DECL_INITIALs of the
5332 enumerators, and the value slots of the list, with copies
5333 that have the enum type; they cannot be modified in place
5334 because they may be shared (e.g. integer_zero_node) Finally,
5335 change the purpose slots to point to the names of the decls. */
5336 for (pair = values; pair; pair = TREE_CHAIN (pair))
5338 tree enu = TREE_PURPOSE (pair);
5340 TREE_TYPE (enu) = enumtype;
5342 /* The ISO C Standard mandates enumerators to have type int,
5343 even though the underlying type of an enum type is
5344 unspecified. Here we convert any enumerators that fit in
5345 an int to type int, to avoid promotions to unsigned types
5346 when comparing integers with enumerators that fit in the
5347 int range. When -pedantic is given, build_enumerator()
5348 would have already taken care of those that don't fit. */
5349 if (int_fits_type_p (DECL_INITIAL (enu), enum_value_type))
5350 DECL_INITIAL (enu) = convert (enum_value_type, DECL_INITIAL (enu));
5351 else
5352 DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu));
5354 TREE_PURPOSE (pair) = DECL_NAME (enu);
5355 TREE_VALUE (pair) = DECL_INITIAL (enu);
5358 TYPE_VALUES (enumtype) = values;
5361 /* Fix up all variant types of this enum type. */
5362 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
5364 if (tem == enumtype)
5365 continue;
5366 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
5367 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
5368 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
5369 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
5370 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
5371 TYPE_MODE (tem) = TYPE_MODE (enumtype);
5372 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
5373 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
5374 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
5375 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
5378 /* Finish debugging output for this type. */
5379 rest_of_type_compilation (enumtype, toplevel);
5381 return enumtype;
5384 /* Build and install a CONST_DECL for one value of the
5385 current enumeration type (one that was begun with start_enum).
5386 Return a tree-list containing the CONST_DECL and its value.
5387 Assignment of sequential values by default is handled here. */
5389 tree
5390 build_enumerator (tree name, tree value)
5392 tree decl, type;
5394 /* Validate and default VALUE. */
5396 /* Remove no-op casts from the value. */
5397 if (value)
5398 STRIP_TYPE_NOPS (value);
5400 if (value != 0)
5402 if (TREE_CODE (value) == INTEGER_CST)
5404 value = default_conversion (value);
5405 constant_expression_warning (value);
5407 else
5409 error ("enumerator value for `%s' not integer constant",
5410 IDENTIFIER_POINTER (name));
5411 value = 0;
5415 /* Default based on previous value. */
5416 /* It should no longer be possible to have NON_LVALUE_EXPR
5417 in the default. */
5418 if (value == 0)
5420 value = enum_next_value;
5421 if (enum_overflow)
5422 error ("overflow in enumeration values");
5425 if (pedantic && ! int_fits_type_p (value, integer_type_node))
5427 pedwarn ("ISO C restricts enumerator values to range of `int'");
5428 value = convert (integer_type_node, value);
5431 /* Set basis for default for next value. */
5432 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
5433 enum_overflow = tree_int_cst_lt (enum_next_value, value);
5435 /* Now create a declaration for the enum value name. */
5437 type = TREE_TYPE (value);
5438 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
5439 TYPE_PRECISION (integer_type_node)),
5440 (TYPE_PRECISION (type)
5441 >= TYPE_PRECISION (integer_type_node)
5442 && TREE_UNSIGNED (type)));
5444 decl = build_decl (CONST_DECL, name, type);
5445 DECL_INITIAL (decl) = convert (type, value);
5446 pushdecl (decl);
5448 return tree_cons (decl, value, NULL_TREE);
5452 /* Create the FUNCTION_DECL for a function definition.
5453 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
5454 the declaration; they describe the function's name and the type it returns,
5455 but twisted together in a fashion that parallels the syntax of C.
5457 This function creates a binding context for the function body
5458 as well as setting up the FUNCTION_DECL in current_function_decl.
5460 Returns 1 on success. If the DECLARATOR is not suitable for a function
5461 (it defines a datum instead), we return 0, which tells
5462 yyparse to report a parse error. */
5465 start_function (tree declspecs, tree declarator, tree attributes)
5467 tree decl1, old_decl;
5468 tree restype;
5469 int old_immediate_size_expand = immediate_size_expand;
5471 current_function_returns_value = 0; /* Assume, until we see it does. */
5472 current_function_returns_null = 0;
5473 current_function_returns_abnormally = 0;
5474 warn_about_return_type = 0;
5475 current_extern_inline = 0;
5476 named_labels = 0;
5477 shadowed_labels = 0;
5479 /* Don't expand any sizes in the return type of the function. */
5480 immediate_size_expand = 0;
5482 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
5484 /* If the declarator is not suitable for a function definition,
5485 cause a syntax error. */
5486 if (decl1 == 0)
5488 immediate_size_expand = old_immediate_size_expand;
5489 return 0;
5492 decl_attributes (&decl1, attributes, 0);
5494 /* If #pragma weak was used, mark the decl weak now. */
5495 if (current_binding_level == global_binding_level)
5496 maybe_apply_pragma_weak (decl1);
5498 if (DECL_DECLARED_INLINE_P (decl1)
5499 && DECL_UNINLINABLE (decl1)
5500 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
5501 warning_with_decl (decl1,
5502 "inline function `%s' given attribute noinline");
5504 announce_function (decl1);
5506 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
5508 error ("return type is an incomplete type");
5509 /* Make it return void instead. */
5510 TREE_TYPE (decl1)
5511 = build_function_type (void_type_node,
5512 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
5515 if (warn_about_return_type)
5516 pedwarn_c99 ("return type defaults to `int'");
5518 /* Save the parm names or decls from this function's declarator
5519 where store_parm_decls will find them. */
5520 current_function_parms = last_function_parms;
5521 current_function_parm_tags = last_function_parm_tags;
5523 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5524 error_mark_node is replaced below (in poplevel) with the BLOCK. */
5525 DECL_INITIAL (decl1) = error_mark_node;
5527 /* If this definition isn't a prototype and we had a prototype declaration
5528 before, copy the arg type info from that prototype.
5529 But not if what we had before was a builtin function. */
5530 old_decl = lookup_name_current_level (DECL_NAME (decl1));
5531 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
5532 && !DECL_BUILT_IN (old_decl)
5533 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5534 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
5535 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
5537 TREE_TYPE (decl1) = TREE_TYPE (old_decl);
5538 current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
5541 /* Optionally warn of old-fashioned def with no previous prototype. */
5542 if (warn_strict_prototypes
5543 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
5544 && C_DECL_ISNT_PROTOTYPE (old_decl))
5545 warning ("function declaration isn't a prototype");
5546 /* Optionally warn of any global def with no previous prototype. */
5547 else if (warn_missing_prototypes
5548 && TREE_PUBLIC (decl1)
5549 && ! MAIN_NAME_P (DECL_NAME (decl1))
5550 && C_DECL_ISNT_PROTOTYPE (old_decl))
5551 warning_with_decl (decl1, "no previous prototype for `%s'");
5552 /* Optionally warn of any def with no previous prototype
5553 if the function has already been used. */
5554 else if (warn_missing_prototypes
5555 && old_decl != 0 && TREE_USED (old_decl)
5556 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
5557 warning_with_decl (decl1,
5558 "`%s' was used with no prototype before its definition");
5559 /* Optionally warn of any global def with no previous declaration. */
5560 else if (warn_missing_declarations
5561 && TREE_PUBLIC (decl1)
5562 && old_decl == 0
5563 && ! MAIN_NAME_P (DECL_NAME (decl1)))
5564 warning_with_decl (decl1, "no previous declaration for `%s'");
5565 /* Optionally warn of any def with no previous declaration
5566 if the function has already been used. */
5567 else if (warn_missing_declarations
5568 && old_decl != 0 && TREE_USED (old_decl)
5569 && C_DECL_IMPLICIT (old_decl))
5570 warning_with_decl (decl1,
5571 "`%s' was used with no declaration before its definition");
5573 /* This is a definition, not a reference.
5574 So normally clear DECL_EXTERNAL.
5575 However, `extern inline' acts like a declaration
5576 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5577 DECL_EXTERNAL (decl1) = current_extern_inline;
5579 /* This function exists in static storage.
5580 (This does not mean `static' in the C sense!) */
5581 TREE_STATIC (decl1) = 1;
5583 /* A nested function is not global. */
5584 if (current_function_decl != 0)
5585 TREE_PUBLIC (decl1) = 0;
5587 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5588 if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
5590 tree args;
5591 int argct = 0;
5593 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5594 != integer_type_node)
5595 pedwarn_with_decl (decl1, "return type of `%s' is not `int'");
5597 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
5598 args = TREE_CHAIN (args))
5600 tree type = args ? TREE_VALUE (args) : 0;
5602 if (type == void_type_node)
5603 break;
5605 ++argct;
5606 switch (argct)
5608 case 1:
5609 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
5610 pedwarn_with_decl (decl1,
5611 "first argument of `%s' should be `int'");
5612 break;
5614 case 2:
5615 if (TREE_CODE (type) != POINTER_TYPE
5616 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5617 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5618 != char_type_node))
5619 pedwarn_with_decl (decl1,
5620 "second argument of `%s' should be `char **'");
5621 break;
5623 case 3:
5624 if (TREE_CODE (type) != POINTER_TYPE
5625 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5626 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5627 != char_type_node))
5628 pedwarn_with_decl (decl1,
5629 "third argument of `%s' should probably be `char **'");
5630 break;
5634 /* It is intentional that this message does not mention the third
5635 argument because it's only mentioned in an appendix of the
5636 standard. */
5637 if (argct > 0 && (argct < 2 || argct > 3))
5638 pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments");
5640 if (! TREE_PUBLIC (decl1))
5641 pedwarn_with_decl (decl1, "`%s' is normally a non-static function");
5644 /* Record the decl so that the function name is defined.
5645 If we already have a decl for this name, and it is a FUNCTION_DECL,
5646 use the old decl. */
5648 current_function_decl = pushdecl (decl1);
5650 pushlevel (0);
5651 declare_parm_level (1);
5653 make_decl_rtl (current_function_decl, NULL);
5655 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
5656 /* Promote the value to int before returning it. */
5657 if (c_promoting_integer_type_p (restype))
5659 /* It retains unsignedness if not really getting wider. */
5660 if (TREE_UNSIGNED (restype)
5661 && (TYPE_PRECISION (restype)
5662 == TYPE_PRECISION (integer_type_node)))
5663 restype = unsigned_type_node;
5664 else
5665 restype = integer_type_node;
5667 DECL_RESULT (current_function_decl)
5668 = build_decl (RESULT_DECL, NULL_TREE, restype);
5670 /* If this fcn was already referenced via a block-scope `extern' decl
5671 (or an implicit decl), propagate certain information about the usage. */
5672 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
5673 TREE_ADDRESSABLE (current_function_decl) = 1;
5675 immediate_size_expand = old_immediate_size_expand;
5677 start_fname_decls ();
5679 return 1;
5682 /* Store the parameter declarations into the current function declaration.
5683 This is called after parsing the parameter declarations, before
5684 digesting the body of the function.
5686 For an old-style definition, modify the function's type
5687 to specify at least the number of arguments. */
5689 void
5690 store_parm_decls (void)
5692 tree fndecl = current_function_decl;
5693 tree parm;
5695 /* This is either a chain of PARM_DECLs (if a prototype was used)
5696 or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */
5697 tree specparms = current_function_parms;
5699 /* This is a list of types declared among parms in a prototype. */
5700 tree parmtags = current_function_parm_tags;
5702 /* This is a chain of PARM_DECLs from old-style parm declarations. */
5703 tree parmdecls = getdecls ();
5705 /* This is a chain of any other decls that came in among the parm
5706 declarations. If a parm is declared with enum {foo, bar} x;
5707 then CONST_DECLs for foo and bar are put here. */
5708 tree nonparms = 0;
5710 /* The function containing FNDECL, if any. */
5711 tree context = decl_function_context (fndecl);
5713 /* Nonzero if this definition is written with a prototype. */
5714 int prototype = 0;
5716 bool saved_warn_shadow = warn_shadow;
5718 /* Don't re-emit shadow warnings. */
5719 warn_shadow = false;
5721 if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
5723 /* This case is when the function was defined with an ANSI prototype.
5724 The parms already have decls, so we need not do anything here
5725 except record them as in effect
5726 and complain if any redundant old-style parm decls were written. */
5728 tree next;
5729 tree others = 0;
5731 prototype = 1;
5733 if (parmdecls != 0)
5735 tree decl, link;
5737 error_with_decl (fndecl,
5738 "parm types given both in parmlist and separately");
5739 /* Get rid of the erroneous decls; don't keep them on
5740 the list of parms, since they might not be PARM_DECLs. */
5741 for (decl = current_binding_level->names;
5742 decl; decl = TREE_CHAIN (decl))
5743 if (DECL_NAME (decl))
5744 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl)) = 0;
5745 for (link = current_binding_level->shadowed;
5746 link; link = TREE_CHAIN (link))
5747 IDENTIFIER_SYMBOL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
5748 current_binding_level->names = 0;
5749 current_binding_level->shadowed = 0;
5752 specparms = nreverse (specparms);
5753 for (parm = specparms; parm; parm = next)
5755 next = TREE_CHAIN (parm);
5756 if (TREE_CODE (parm) == PARM_DECL)
5758 if (DECL_NAME (parm) == 0)
5759 error_with_decl (parm, "parameter name omitted");
5760 else if (TREE_CODE (TREE_TYPE (parm)) != ERROR_MARK
5761 && VOID_TYPE_P (TREE_TYPE (parm)))
5763 error_with_decl (parm, "parameter `%s' declared void");
5764 /* Change the type to error_mark_node so this parameter
5765 will be ignored by assign_parms. */
5766 TREE_TYPE (parm) = error_mark_node;
5768 pushdecl (parm);
5770 else
5772 /* If we find an enum constant or a type tag,
5773 put it aside for the moment. */
5774 TREE_CHAIN (parm) = 0;
5775 others = chainon (others, parm);
5779 /* Get the decls in their original chain order
5780 and record in the function. */
5781 DECL_ARGUMENTS (fndecl) = getdecls ();
5783 #if 0
5784 /* If this function takes a variable number of arguments,
5785 add a phony parameter to the end of the parm list,
5786 to represent the position of the first unnamed argument. */
5787 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
5788 != void_type_node)
5790 tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
5791 /* Let's hope the address of the unnamed parm
5792 won't depend on its type. */
5793 TREE_TYPE (dummy) = integer_type_node;
5794 DECL_ARG_TYPE (dummy) = integer_type_node;
5795 DECL_ARGUMENTS (fndecl) = chainon (DECL_ARGUMENTS (fndecl), dummy);
5797 #endif
5799 /* Now pushdecl the enum constants. */
5800 for (parm = others; parm; parm = next)
5802 next = TREE_CHAIN (parm);
5803 if (DECL_NAME (parm) == 0)
5805 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
5807 else if (TREE_CODE (parm) != PARM_DECL)
5808 pushdecl (parm);
5811 storetags (chainon (parmtags, gettags ()));
5813 else
5815 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
5816 each with a parm name as the TREE_VALUE.
5818 PARMDECLS is a chain of declarations for parameters.
5819 Warning! It can also contain CONST_DECLs which are not parameters
5820 but are names of enumerators of any enum types
5821 declared among the parameters.
5823 First match each formal parameter name with its declaration.
5824 Associate decls with the names and store the decls
5825 into the TREE_PURPOSE slots. */
5827 /* We use DECL_WEAK as a flag to show which parameters have been
5828 seen already since it is not used on PARM_DECL or CONST_DECL. */
5829 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
5830 DECL_WEAK (parm) = 0;
5832 for (parm = specparms; parm; parm = TREE_CHAIN (parm))
5834 tree tail, found = NULL;
5836 if (TREE_VALUE (parm) == 0)
5838 error_with_decl (fndecl,
5839 "parameter name missing from parameter list");
5840 TREE_PURPOSE (parm) = 0;
5841 continue;
5844 /* See if any of the parmdecls specifies this parm by name.
5845 Ignore any enumerator decls. */
5846 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
5847 if (DECL_NAME (tail) == TREE_VALUE (parm)
5848 && TREE_CODE (tail) == PARM_DECL)
5850 found = tail;
5851 break;
5854 /* If declaration already marked, we have a duplicate name.
5855 Complain, and don't use this decl twice. */
5856 if (found && DECL_WEAK (found))
5858 error_with_decl (found, "multiple parameters named `%s'");
5859 found = 0;
5862 /* If the declaration says "void", complain and ignore it. */
5863 if (found && VOID_TYPE_P (TREE_TYPE (found)))
5865 error_with_decl (found, "parameter `%s' declared void");
5866 TREE_TYPE (found) = integer_type_node;
5867 DECL_ARG_TYPE (found) = integer_type_node;
5868 layout_decl (found, 0);
5871 /* If no declaration found, default to int. */
5872 if (!found)
5874 found = build_decl (PARM_DECL, TREE_VALUE (parm),
5875 integer_type_node);
5876 DECL_ARG_TYPE (found) = TREE_TYPE (found);
5877 DECL_SOURCE_LOCATION (found) = DECL_SOURCE_LOCATION (fndecl);
5878 if (flag_isoc99)
5879 pedwarn_with_decl (found, "type of `%s' defaults to `int'");
5880 else if (extra_warnings)
5881 warning_with_decl (found, "type of `%s' defaults to `int'");
5882 pushdecl (found);
5885 TREE_PURPOSE (parm) = found;
5887 /* Mark this decl as "already found". */
5888 DECL_WEAK (found) = 1;
5891 /* Put anything which is on the parmdecls chain and which is
5892 not a PARM_DECL onto the list NONPARMS. (The types of
5893 non-parm things which might appear on the list include
5894 enumerators and NULL-named TYPE_DECL nodes.) Complain about
5895 any actual PARM_DECLs not matched with any names. */
5897 nonparms = 0;
5898 for (parm = parmdecls; parm;)
5900 tree next = TREE_CHAIN (parm);
5901 TREE_CHAIN (parm) = 0;
5903 if (TREE_CODE (parm) != PARM_DECL)
5904 nonparms = chainon (nonparms, parm);
5905 else
5907 /* Complain about args with incomplete types. */
5908 if (!COMPLETE_TYPE_P (TREE_TYPE (parm)))
5910 error_with_decl (parm, "parameter `%s' has incomplete type");
5911 TREE_TYPE (parm) = error_mark_node;
5914 if (! DECL_WEAK (parm))
5916 error_with_decl (parm,
5917 "declaration for parameter `%s' but no such parameter");
5918 /* Pretend the parameter was not missing.
5919 This gets us to a standard state and minimizes
5920 further error messages. */
5921 specparms
5922 = chainon (specparms,
5923 tree_cons (parm, NULL_TREE, NULL_TREE));
5927 parm = next;
5930 /* Chain the declarations together in the order of the list of
5931 names. Store that chain in the function decl, replacing the
5932 list of names. */
5933 parm = specparms;
5934 DECL_ARGUMENTS (fndecl) = 0;
5936 tree last;
5937 for (last = 0; parm; parm = TREE_CHAIN (parm))
5938 if (TREE_PURPOSE (parm))
5940 if (last == 0)
5941 DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
5942 else
5943 TREE_CHAIN (last) = TREE_PURPOSE (parm);
5944 last = TREE_PURPOSE (parm);
5945 TREE_CHAIN (last) = 0;
5949 /* If there was a previous prototype,
5950 set the DECL_ARG_TYPE of each argument according to
5951 the type previously specified, and report any mismatches. */
5953 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
5955 tree type;
5956 for (parm = DECL_ARGUMENTS (fndecl),
5957 type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
5958 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
5959 != void_type_node));
5960 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
5962 if (parm == 0 || type == 0
5963 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
5965 error ("number of arguments doesn't match prototype");
5966 error ("%Hprototype declaration",
5967 &current_function_prototype_locus);
5968 break;
5970 /* Type for passing arg must be consistent with that
5971 declared for the arg. ISO C says we take the unqualified
5972 type for parameters declared with qualified type. */
5973 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
5974 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
5976 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
5977 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
5979 /* Adjust argument to match prototype. E.g. a previous
5980 `int foo(float);' prototype causes
5981 `int foo(x) float x; {...}' to be treated like
5982 `int foo(float x) {...}'. This is particularly
5983 useful for argument types like uid_t. */
5984 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
5986 if (PROMOTE_PROTOTYPES
5987 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
5988 && TYPE_PRECISION (TREE_TYPE (parm))
5989 < TYPE_PRECISION (integer_type_node))
5990 DECL_ARG_TYPE (parm) = integer_type_node;
5992 if (pedantic)
5994 pedwarn ("promoted argument `%s' doesn't match prototype",
5995 IDENTIFIER_POINTER (DECL_NAME (parm)));
5996 warning ("%Hprototype declaration",
5997 &current_function_prototype_locus);
6000 else
6002 error ("argument `%s' doesn't match prototype",
6003 IDENTIFIER_POINTER (DECL_NAME (parm)));
6004 error ("%Hprototype declaration",
6005 &current_function_prototype_locus);
6009 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6012 /* Otherwise, create a prototype that would match. */
6014 else
6016 tree actual = 0, last = 0, type;
6018 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6020 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6021 if (last)
6022 TREE_CHAIN (last) = type;
6023 else
6024 actual = type;
6025 last = type;
6027 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6028 if (last)
6029 TREE_CHAIN (last) = type;
6030 else
6031 actual = type;
6033 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6034 of the type of this function, but we need to avoid having this
6035 affect the types of other similarly-typed functions, so we must
6036 first force the generation of an identical (but separate) type
6037 node for the relevant function type. The new node we create
6038 will be a variant of the main variant of the original function
6039 type. */
6041 TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
6043 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6046 /* Now store the final chain of decls for the arguments
6047 as the decl-chain of the current lexical scope.
6048 Put the enumerators in as well, at the front so that
6049 DECL_ARGUMENTS is not modified. */
6051 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
6054 /* Make sure the binding level for the top of the function body
6055 gets a BLOCK if there are any in the function.
6056 Otherwise, the dbx output is wrong. */
6058 keep_next_if_subblocks = 1;
6060 /* ??? This might be an improvement,
6061 but needs to be thought about some more. */
6062 #if 0
6063 keep_next_level_flag = 1;
6064 #endif
6066 /* Write a record describing this function definition to the prototypes
6067 file (if requested). */
6069 gen_aux_info_record (fndecl, 1, 0, prototype);
6071 /* Initialize the RTL code for the function. */
6072 init_function_start (fndecl);
6074 /* Begin the statement tree for this function. */
6075 begin_stmt_tree (&DECL_SAVED_TREE (current_function_decl));
6077 /* If this is a nested function, save away the sizes of any
6078 variable-size types so that we can expand them when generating
6079 RTL. */
6080 if (context)
6082 tree t;
6084 DECL_LANG_SPECIFIC (fndecl)->pending_sizes
6085 = nreverse (get_pending_sizes ());
6086 for (t = DECL_LANG_SPECIFIC (fndecl)->pending_sizes;
6088 t = TREE_CHAIN (t))
6089 SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = context;
6092 /* This function is being processed in whole-function mode. */
6093 cfun->x_whole_function_mode_p = 1;
6095 /* Even though we're inside a function body, we still don't want to
6096 call expand_expr to calculate the size of a variable-sized array.
6097 We haven't necessarily assigned RTL to all variables yet, so it's
6098 not safe to try to expand expressions involving them. */
6099 immediate_size_expand = 0;
6100 cfun->x_dont_save_pending_sizes_p = 1;
6102 warn_shadow = saved_warn_shadow;
6105 /* Finish up a function declaration and compile that function
6106 all the way to assembler language output. The free the storage
6107 for the function definition.
6109 This is called after parsing the body of the function definition.
6111 NESTED is nonzero if the function being finished is nested in another.
6112 CAN_DEFER_P is nonzero if the function may be deferred. */
6114 void
6115 finish_function (int nested, int can_defer_p)
6117 tree fndecl = current_function_decl;
6119 /* When a function declaration is totally empty, e.g.
6120 void foo(void) { }
6121 (the argument list is irrelevant) the compstmt rule will not
6122 bother calling pushlevel/poplevel, which means we get here with
6123 the binding_level stack out of sync. Detect this situation by
6124 noticing that the current_binding_level is still as
6125 store_parm_decls left it, and do a dummy push/pop to get back to
6126 consistency. Note that the call to pushlevel does not actually
6127 push another binding level - see there for details. */
6128 if (current_binding_level->parm_flag && keep_next_if_subblocks)
6130 pushlevel (0);
6131 poplevel (1, 0, 1);
6134 #if 0
6135 /* This caused &foo to be of type ptr-to-const-function which then
6136 got a warning when stored in a ptr-to-function variable. */
6137 TREE_READONLY (fndecl) = 1;
6138 #endif
6140 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6142 /* Must mark the RESULT_DECL as being in this function. */
6144 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
6146 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
6148 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6149 != integer_type_node)
6151 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6152 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6153 if (! warn_main)
6154 pedwarn_with_decl (fndecl, "return type of `%s' is not `int'");
6156 else
6158 #ifdef DEFAULT_MAIN_RETURN
6159 /* Make it so that `main' always returns success by default. */
6160 DEFAULT_MAIN_RETURN;
6161 #else
6162 if (flag_isoc99)
6163 c_expand_return (integer_zero_node);
6164 #endif
6168 finish_fname_decls ();
6170 /* Tie off the statement tree for this function. */
6171 finish_stmt_tree (&DECL_SAVED_TREE (fndecl));
6173 /* Complain if there's just no return statement. */
6174 if (warn_return_type
6175 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
6176 && !current_function_returns_value && !current_function_returns_null
6177 /* Don't complain if we abort. */
6178 && !current_function_returns_abnormally
6179 /* Don't warn for main(). */
6180 && !MAIN_NAME_P (DECL_NAME (fndecl))
6181 /* Or if they didn't actually specify a return type. */
6182 && !C_FUNCTION_IMPLICIT_INT (fndecl)
6183 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6184 inline function, as we might never be compiled separately. */
6185 && DECL_INLINE (fndecl))
6186 warning ("no return statement in function returning non-void");
6188 /* Clear out memory we no longer need. */
6189 free_after_parsing (cfun);
6190 /* Since we never call rest_of_compilation, we never clear
6191 CFUN. Do so explicitly. */
6192 free_after_compilation (cfun);
6193 cfun = NULL;
6195 if (flag_unit_at_a_time && can_defer_p)
6197 cgraph_finalize_function (fndecl, DECL_SAVED_TREE (fndecl));
6198 current_function_decl = NULL;
6199 return;
6202 if (! nested)
6204 /* Function is parsed.
6205 Generate RTL for the body of this function or defer
6206 it for later expansion. */
6207 int uninlinable = 1;
6209 /* There's no reason to do any of the work here if we're only doing
6210 semantic analysis; this code just generates RTL. */
6211 if (flag_syntax_only)
6213 current_function_decl = NULL;
6214 DECL_SAVED_TREE (fndecl) = NULL_TREE;
6215 return;
6218 if (flag_inline_trees)
6220 /* First, cache whether the current function is inlinable. Some
6221 predicates depend on cfun and current_function_decl to
6222 function completely. */
6223 timevar_push (TV_INTEGRATION);
6224 uninlinable = ! tree_inlinable_function_p (fndecl, 0);
6226 if (can_defer_p
6227 /* We defer functions marked inline *even if* the function
6228 itself is not inlinable. This is because we don't yet
6229 know if the function will actually be used; we may be
6230 able to avoid emitting it entirely. */
6231 && (! uninlinable || DECL_DECLARED_INLINE_P (fndecl))
6232 /* Save function tree for inlining. Should return 0 if the
6233 language does not support function deferring or the
6234 function could not be deferred. */
6235 && defer_fn (fndecl))
6237 /* Let the back-end know that this function exists. */
6238 (*debug_hooks->deferred_inline_function) (fndecl);
6239 timevar_pop (TV_INTEGRATION);
6240 current_function_decl = NULL;
6241 return;
6244 /* Then, inline any functions called in it. */
6245 optimize_inline_calls (fndecl);
6246 timevar_pop (TV_INTEGRATION);
6249 c_expand_body (fndecl);
6251 /* Keep the function body if it's needed for inlining or dumping. */
6252 if (uninlinable && !dump_enabled_p (TDI_all))
6254 /* Allow the body of the function to be garbage collected. */
6255 DECL_SAVED_TREE (fndecl) = NULL_TREE;
6258 /* Let the error reporting routines know that we're outside a
6259 function. For a nested function, this value is used in
6260 c_pop_function_context and then reset via pop_function_context. */
6261 current_function_decl = NULL;
6265 /* Generate the RTL for a deferred function FNDECL. */
6267 void
6268 c_expand_deferred_function (tree fndecl)
6270 /* DECL_INLINE or DECL_RESULT might got cleared after the inline
6271 function was deferred, e.g. in duplicate_decls. */
6272 if (DECL_INLINE (fndecl) && DECL_RESULT (fndecl))
6274 if (flag_inline_trees)
6276 timevar_push (TV_INTEGRATION);
6277 optimize_inline_calls (fndecl);
6278 timevar_pop (TV_INTEGRATION);
6280 c_expand_body (fndecl);
6281 current_function_decl = NULL;
6285 /* Called to move the SAVE_EXPRs for parameter declarations in a
6286 nested function into the nested function. DATA is really the
6287 nested FUNCTION_DECL. */
6289 static tree
6290 set_save_expr_context (tree *tp,
6291 int *walk_subtrees,
6292 void *data)
6294 if (TREE_CODE (*tp) == SAVE_EXPR && !SAVE_EXPR_CONTEXT (*tp))
6295 SAVE_EXPR_CONTEXT (*tp) = (tree) data;
6296 /* Do not walk back into the SAVE_EXPR_CONTEXT; that will cause
6297 circularity. */
6298 else if (DECL_P (*tp))
6299 *walk_subtrees = 0;
6301 return NULL_TREE;
6304 /* Generate the RTL for the body of FNDECL. If NESTED_P is nonzero,
6305 then we are already in the process of generating RTL for another
6306 function. If can_defer_p is zero, we won't attempt to defer the
6307 generation of RTL. */
6309 static void
6310 c_expand_body_1 (tree fndecl, int nested_p)
6312 timevar_push (TV_EXPAND);
6314 if (nested_p)
6316 /* Make sure that we will evaluate variable-sized types involved
6317 in our function's type. */
6318 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes);
6319 /* Squirrel away our current state. */
6320 push_function_context ();
6323 /* Initialize the RTL code for the function. */
6324 current_function_decl = fndecl;
6325 input_location = DECL_SOURCE_LOCATION (fndecl);
6326 init_function_start (fndecl);
6328 /* This function is being processed in whole-function mode. */
6329 cfun->x_whole_function_mode_p = 1;
6331 /* Even though we're inside a function body, we still don't want to
6332 call expand_expr to calculate the size of a variable-sized array.
6333 We haven't necessarily assigned RTL to all variables yet, so it's
6334 not safe to try to expand expressions involving them. */
6335 immediate_size_expand = 0;
6336 cfun->x_dont_save_pending_sizes_p = 1;
6338 /* Set up parameters and prepare for return, for the function. */
6339 expand_function_start (fndecl, 0);
6341 /* If the function has a variably modified type, there may be
6342 SAVE_EXPRs in the parameter types. Their context must be set to
6343 refer to this function; they cannot be expanded in the containing
6344 function. */
6345 if (decl_function_context (fndecl)
6346 && variably_modified_type_p (TREE_TYPE (fndecl)))
6347 walk_tree (&TREE_TYPE (fndecl), set_save_expr_context, fndecl,
6348 NULL);
6350 /* If this function is `main', emit a call to `__main'
6351 to run global initializers, etc. */
6352 if (DECL_NAME (fndecl)
6353 && MAIN_NAME_P (DECL_NAME (fndecl))
6354 && DECL_CONTEXT (fndecl) == NULL_TREE)
6355 expand_main_function ();
6357 /* Generate the RTL for this function. */
6358 expand_stmt (DECL_SAVED_TREE (fndecl));
6360 /* We hard-wired immediate_size_expand to zero above.
6361 expand_function_end will decrement this variable. So, we set the
6362 variable to one here, so that after the decrement it will remain
6363 zero. */
6364 immediate_size_expand = 1;
6366 /* Allow language dialects to perform special processing. */
6367 if (lang_expand_function_end)
6368 (*lang_expand_function_end) ();
6370 /* Generate rtl for function exit. */
6371 expand_function_end ();
6373 /* If this is a nested function, protect the local variables in the stack
6374 above us from being collected while we're compiling this function. */
6375 if (nested_p)
6376 ggc_push_context ();
6378 /* Run the optimizers and output the assembler code for this function. */
6379 rest_of_compilation (fndecl);
6381 /* Undo the GC context switch. */
6382 if (nested_p)
6383 ggc_pop_context ();
6385 /* With just -Wextra, complain only if function returns both with
6386 and without a value. */
6387 if (extra_warnings
6388 && current_function_returns_value
6389 && current_function_returns_null)
6390 warning ("this function may return with or without a value");
6392 /* If requested, warn about function definitions where the function will
6393 return a value (usually of some struct or union type) which itself will
6394 take up a lot of stack space. */
6396 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
6398 tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
6400 if (ret_type && TYPE_SIZE_UNIT (ret_type)
6401 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST
6402 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type),
6403 larger_than_size))
6405 unsigned int size_as_int
6406 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type));
6408 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0)
6409 warning_with_decl (fndecl,
6410 "size of return value of `%s' is %u bytes",
6411 size_as_int);
6412 else
6413 warning_with_decl (fndecl,
6414 "size of return value of `%s' is larger than %d bytes",
6415 larger_than_size);
6419 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested_p
6420 && ! flag_inline_trees)
6422 /* Stop pointing to the local nodes about to be freed.
6423 But DECL_INITIAL must remain nonzero so we know this
6424 was an actual function definition.
6425 For a nested function, this is done in c_pop_function_context.
6426 If rest_of_compilation set this to 0, leave it 0. */
6427 if (DECL_INITIAL (fndecl) != 0)
6428 DECL_INITIAL (fndecl) = error_mark_node;
6430 DECL_ARGUMENTS (fndecl) = 0;
6433 if (DECL_STATIC_CONSTRUCTOR (fndecl))
6435 if (targetm.have_ctors_dtors)
6436 (* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0),
6437 DEFAULT_INIT_PRIORITY);
6438 else
6439 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
6442 if (DECL_STATIC_DESTRUCTOR (fndecl))
6444 if (targetm.have_ctors_dtors)
6445 (* targetm.asm_out.destructor) (XEXP (DECL_RTL (fndecl), 0),
6446 DEFAULT_INIT_PRIORITY);
6447 else
6448 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
6451 if (nested_p)
6452 /* Return to the enclosing function. */
6453 pop_function_context ();
6454 timevar_pop (TV_EXPAND);
6457 /* Like c_expand_body_1 but only for unnested functions. */
6459 void
6460 c_expand_body (tree fndecl)
6462 c_expand_body_1 (fndecl, 0);
6465 /* Check the declarations given in a for-loop for satisfying the C99
6466 constraints. */
6467 void
6468 check_for_loop_decls (void)
6470 tree t;
6472 if (!flag_isoc99)
6474 /* If we get here, declarations have been used in a for loop without
6475 the C99 for loop scope. This doesn't make much sense, so don't
6476 allow it. */
6477 error ("`for' loop initial declaration used outside C99 mode");
6478 return;
6480 /* C99 subclause 6.8.5 paragraph 3:
6482 [#3] The declaration part of a for statement shall only
6483 declare identifiers for objects having storage class auto or
6484 register.
6486 It isn't clear whether, in this sentence, "identifiers" binds to
6487 "shall only declare" or to "objects" - that is, whether all identifiers
6488 declared must be identifiers for objects, or whether the restriction
6489 only applies to those that are. (A question on this in comp.std.c
6490 in November 2000 received no answer.) We implement the strictest
6491 interpretation, to avoid creating an extension which later causes
6492 problems. */
6494 for (t = gettags (); t; t = TREE_CHAIN (t))
6496 if (TREE_PURPOSE (t) != 0)
6498 enum tree_code code = TREE_CODE (TREE_VALUE (t));
6500 if (code == RECORD_TYPE)
6501 error ("`struct %s' declared in `for' loop initial declaration",
6502 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
6503 else if (code == UNION_TYPE)
6504 error ("`union %s' declared in `for' loop initial declaration",
6505 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
6506 else
6507 error ("`enum %s' declared in `for' loop initial declaration",
6508 IDENTIFIER_POINTER (TREE_PURPOSE (t)));
6512 for (t = getdecls (); t; t = TREE_CHAIN (t))
6514 if (TREE_CODE (t) != VAR_DECL && DECL_NAME (t))
6515 error_with_decl (t, "declaration of non-variable `%s' in `for' loop initial declaration");
6516 else if (TREE_STATIC (t))
6517 error_with_decl (t, "declaration of static variable `%s' in `for' loop initial declaration");
6518 else if (DECL_EXTERNAL (t))
6519 error_with_decl (t, "declaration of `extern' variable `%s' in `for' loop initial declaration");
6523 /* Save and restore the variables in this file and elsewhere
6524 that keep track of the progress of compilation of the current function.
6525 Used for nested functions. */
6527 struct language_function GTY(())
6529 struct c_language_function base;
6530 tree named_labels;
6531 tree shadowed_labels;
6532 int returns_value;
6533 int returns_null;
6534 int returns_abnormally;
6535 int warn_about_return_type;
6536 int extern_inline;
6537 struct binding_level *binding_level;
6540 /* Save and reinitialize the variables
6541 used during compilation of a C function. */
6543 void
6544 c_push_function_context (struct function *f)
6546 struct language_function *p;
6547 p = ((struct language_function *)
6548 ggc_alloc (sizeof (struct language_function)));
6549 f->language = p;
6551 p->base.x_stmt_tree = c_stmt_tree;
6552 p->base.x_scope_stmt_stack = c_scope_stmt_stack;
6553 p->named_labels = named_labels;
6554 p->shadowed_labels = shadowed_labels;
6555 p->returns_value = current_function_returns_value;
6556 p->returns_null = current_function_returns_null;
6557 p->returns_abnormally = current_function_returns_abnormally;
6558 p->warn_about_return_type = warn_about_return_type;
6559 p->extern_inline = current_extern_inline;
6560 p->binding_level = current_binding_level;
6563 /* Restore the variables used during compilation of a C function. */
6565 void
6566 c_pop_function_context (struct function *f)
6568 struct language_function *p = f->language;
6569 tree link;
6571 /* Bring back all the labels that were shadowed. */
6572 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
6573 if (DECL_NAME (TREE_VALUE (link)) != 0)
6574 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
6575 = TREE_VALUE (link);
6577 if (DECL_SAVED_INSNS (current_function_decl) == 0
6578 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
6580 /* Stop pointing to the local nodes about to be freed. */
6581 /* But DECL_INITIAL must remain nonzero so we know this
6582 was an actual function definition. */
6583 DECL_INITIAL (current_function_decl) = error_mark_node;
6584 DECL_ARGUMENTS (current_function_decl) = 0;
6587 c_stmt_tree = p->base.x_stmt_tree;
6588 c_scope_stmt_stack = p->base.x_scope_stmt_stack;
6589 named_labels = p->named_labels;
6590 shadowed_labels = p->shadowed_labels;
6591 current_function_returns_value = p->returns_value;
6592 current_function_returns_null = p->returns_null;
6593 current_function_returns_abnormally = p->returns_abnormally;
6594 warn_about_return_type = p->warn_about_return_type;
6595 current_extern_inline = p->extern_inline;
6596 current_binding_level = p->binding_level;
6598 f->language = NULL;
6601 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
6603 void
6604 c_dup_lang_specific_decl (tree decl)
6606 struct lang_decl *ld;
6608 if (!DECL_LANG_SPECIFIC (decl))
6609 return;
6611 ld = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl));
6612 memcpy ((char *) ld, (char *) DECL_LANG_SPECIFIC (decl),
6613 sizeof (struct lang_decl));
6614 DECL_LANG_SPECIFIC (decl) = ld;
6617 /* The functions below are required for functionality of doing
6618 function at once processing in the C front end. Currently these
6619 functions are not called from anywhere in the C front end, but as
6620 these changes continue, that will change. */
6622 /* Returns nonzero if the current statement is a full expression,
6623 i.e. temporaries created during that statement should be destroyed
6624 at the end of the statement. */
6627 stmts_are_full_exprs_p (void)
6629 return 0;
6632 /* Returns the stmt_tree (if any) to which statements are currently
6633 being added. If there is no active statement-tree, NULL is
6634 returned. */
6636 stmt_tree
6637 current_stmt_tree (void)
6639 return &c_stmt_tree;
6642 /* Returns the stack of SCOPE_STMTs for the current function. */
6644 tree *
6645 current_scope_stmt_stack (void)
6647 return &c_scope_stmt_stack;
6650 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
6651 C. */
6654 anon_aggr_type_p (tree node ATTRIBUTE_UNUSED)
6656 return 0;
6659 /* Dummy function in place of callback used by C++. */
6661 void
6662 extract_interface_info (void)
6666 /* Return a new COMPOUND_STMT, after adding it to the current
6667 statement tree. */
6669 tree
6670 c_begin_compound_stmt (void)
6672 tree stmt;
6674 /* Create the COMPOUND_STMT. */
6675 stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE));
6677 return stmt;
6680 /* Expand T (a DECL_STMT) if it declares an entity not handled by the
6681 common code. */
6683 void
6684 c_expand_decl_stmt (tree t)
6686 tree decl = DECL_STMT_DECL (t);
6688 /* Expand nested functions. */
6689 if (TREE_CODE (decl) == FUNCTION_DECL
6690 && DECL_CONTEXT (decl) == current_function_decl
6691 && DECL_SAVED_TREE (decl))
6692 c_expand_body_1 (decl, 1);
6695 /* Return the global value of T as a symbol. */
6697 tree
6698 identifier_global_value (tree t)
6700 tree decl = IDENTIFIER_SYMBOL_VALUE (t);
6701 if (decl == 0 || DECL_CONTEXT (decl) == 0)
6702 return decl;
6704 /* Shadowed by something else; find the true global value. */
6705 for (decl = global_binding_level->names; decl; decl = TREE_CHAIN (decl))
6706 if (DECL_NAME (decl) == t)
6707 return decl;
6709 /* Only local values for this decl. */
6710 return 0;
6713 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
6714 otherwise the name is found in ridpointers from RID_INDEX. */
6716 void
6717 record_builtin_type (enum rid rid_index, const char *name, tree type)
6719 tree id;
6720 if (name == 0)
6721 id = ridpointers[(int) rid_index];
6722 else
6723 id = get_identifier (name);
6724 pushdecl (build_decl (TYPE_DECL, id, type));
6727 /* Build the void_list_node (void_type_node having been created). */
6728 tree
6729 build_void_list_node (void)
6731 tree t = build_tree_list (NULL_TREE, void_type_node);
6732 return t;
6735 /* Return something to represent absolute declarators containing a *.
6736 TARGET is the absolute declarator that the * contains.
6737 TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile
6738 to apply to the pointer type, represented as identifiers, possible mixed
6739 with attributes.
6741 We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST,
6742 if attributes are present) and whose type is the modifier list. */
6744 tree
6745 make_pointer_declarator (tree type_quals_attrs, tree target)
6747 tree quals, attrs;
6748 tree itarget = target;
6749 split_specs_attrs (type_quals_attrs, &quals, &attrs);
6750 if (attrs != NULL_TREE)
6751 itarget = tree_cons (attrs, target, NULL_TREE);
6752 return build1 (INDIRECT_REF, quals, itarget);
6755 #include "gt-c-decl.h"