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, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
31 #include "coretypes.h"
36 #include "tree-inline.h"
53 #include "langhooks.h"
54 #include "tree-mudflap.h"
55 #include "tree-gimple.h"
56 #include "diagnostic.h"
57 #include "tree-dump.h"
62 #include "langhooks-def.h"
64 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
66 { NORMAL, /* Ordinary declaration */
67 FUNCDEF, /* Function definition */
68 PARM, /* Declaration of parm before function body */
69 FIELD, /* Declaration inside struct or union */
70 TYPENAME}; /* Typename (inside cast or sizeof) */
73 /* Nonzero if we have seen an invalid cross reference
74 to a struct, union, or enum, but not yet printed the message. */
75 tree pending_invalid_xref;
77 /* File and line to appear in the eventual error message. */
78 location_t pending_invalid_xref_location;
80 /* True means we've initialized exception handling. */
81 bool c_eh_initialized_p;
83 /* While defining an enum type, this is 1 plus the last enumerator
84 constant value. Note that will do not have to save this or `enum_overflow'
85 around nested function definition since such a definition could only
86 occur in an enum value expression and we don't use these variables in
89 static tree enum_next_value;
91 /* Nonzero means that there was overflow computing enum_next_value. */
93 static int enum_overflow;
95 /* The file and line that the prototype came from if this is an
96 old-style definition; used for diagnostics in
97 store_parm_decls_oldstyle. */
99 static location_t current_function_prototype_locus;
101 /* Whether this prototype was built-in. */
103 static bool current_function_prototype_built_in;
105 /* The argument type information of this prototype. */
107 static tree current_function_prototype_arg_types;
109 /* The argument information structure for the function currently being
112 static struct c_arg_info *current_function_arg_info;
114 /* The obstack on which parser and related data structures, which are
115 not live beyond their top-level declaration or definition, are
117 struct obstack parser_obstack;
119 /* The current statement tree. */
121 static GTY(()) struct stmt_tree_s c_stmt_tree;
123 /* State saving variables. */
127 /* Linked list of TRANSLATION_UNIT_DECLS for the translation units
128 included in this invocation. Note that the current translation
129 unit is not included in this list. */
131 static GTY(()) tree all_translation_units;
133 /* A list of decls to be made automatically visible in each file scope. */
134 static GTY(()) tree visible_builtins;
136 /* Set to 0 at beginning of a function definition, set to 1 if
137 a return statement that specifies a return value is seen. */
139 int current_function_returns_value;
141 /* Set to 0 at beginning of a function definition, set to 1 if
142 a return statement with no argument is seen. */
144 int current_function_returns_null;
146 /* Set to 0 at beginning of a function definition, set to 1 if
147 a call to a noreturn function is seen. */
149 int current_function_returns_abnormally;
151 /* Set to nonzero by `grokdeclarator' for a function
152 whose return type is defaulted, if warnings for this are desired. */
154 static int warn_about_return_type;
156 /* Nonzero when starting a function declared `extern inline'. */
158 static int current_extern_inline;
160 /* Nonzero when the current toplevel function contains a declaration
161 of a nested function which is never defined. */
163 static bool undef_nested_function;
165 /* True means global_bindings_p should return false even if the scope stack
166 says we are in file scope. */
167 bool c_override_global_bindings_to_false;
170 /* Each c_binding structure describes one binding of an identifier to
171 a decl. All the decls in a scope - irrespective of namespace - are
172 chained together by the ->prev field, which (as the name implies)
173 runs in reverse order. All the decls in a given namespace bound to
174 a given identifier are chained by the ->shadowed field, which runs
175 from inner to outer scopes.
177 The ->decl field usually points to a DECL node, but there are two
178 exceptions. In the namespace of type tags, the bound entity is a
179 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
180 identifier is encountered, it is bound to error_mark_node to
181 suppress further errors about that identifier in the current
184 The ->type field stores the type of the declaration in this scope;
185 if NULL, the type is the type of the ->decl field. This is only of
186 relevance for objects with external or internal linkage which may
187 be redeclared in inner scopes, forming composite types that only
188 persist for the duration of those scopes. In the external scope,
189 this stores the composite of all the types declared for this
190 object, visible or not. The ->inner_comp field (used only at file
191 scope) stores whether an incomplete array type at file scope was
192 completed at an inner scope to an array size other than 1.
194 The depth field is copied from the scope structure that holds this
195 decl. It is used to preserve the proper ordering of the ->shadowed
196 field (see bind()) and also for a handful of special-case checks.
197 Finally, the invisible bit is true for a decl which should be
198 ignored for purposes of normal name lookup, and the nested bit is
199 true for a decl that's been bound a second time in an inner scope;
200 in all such cases, the binding in the outer scope will have its
201 invisible bit true. */
203 struct c_binding GTY((chain_next ("%h.prev")))
205 tree decl; /* the decl bound */
206 tree type; /* the type in this scope */
207 tree id; /* the identifier it's bound to */
208 struct c_binding *prev; /* the previous decl in this scope */
209 struct c_binding *shadowed; /* the innermost decl shadowed by this one */
210 unsigned int depth : 28; /* depth of this scope */
211 BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */
212 BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */
213 BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
216 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
217 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
218 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
219 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
221 #define I_SYMBOL_BINDING(node) \
222 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding)
223 #define I_SYMBOL_DECL(node) \
224 (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
226 #define I_TAG_BINDING(node) \
227 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->tag_binding)
228 #define I_TAG_DECL(node) \
229 (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
231 #define I_LABEL_BINDING(node) \
232 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->label_binding)
233 #define I_LABEL_DECL(node) \
234 (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
236 /* Each C symbol points to three linked lists of c_binding structures.
237 These describe the values of the identifier in the three different
238 namespaces defined by the language. */
240 struct lang_identifier GTY(())
242 struct c_common_identifier common_id;
243 struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
244 struct c_binding *tag_binding; /* struct/union/enum tags */
245 struct c_binding *label_binding; /* labels */
248 /* Validate c-lang.c's assumptions. */
249 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
250 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
252 /* The resulting tree type. */
255 GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
256 chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : (union lang_tree_node *) TREE_CHAIN (&%h.generic)")))
258 union tree_node GTY ((tag ("0"),
259 desc ("tree_node_structure (&%h)")))
261 struct lang_identifier GTY ((tag ("1"))) identifier;
264 /* Each c_scope structure describes the complete contents of one
265 scope. Four scopes are distinguished specially: the innermost or
266 current scope, the innermost function scope, the file scope (always
267 the second to outermost) and the outermost or external scope.
269 Most declarations are recorded in the current scope.
271 All normal label declarations are recorded in the innermost
272 function scope, as are bindings of undeclared identifiers to
273 error_mark_node. (GCC permits nested functions as an extension,
274 hence the 'innermost' qualifier.) Explicitly declared labels
275 (using the __label__ extension) appear in the current scope.
277 Being in the file scope (current_scope == file_scope) causes
278 special behavior in several places below. Also, under some
279 conditions the Objective-C front end records declarations in the
280 file scope even though that isn't the current scope.
282 All declarations with external linkage are recorded in the external
283 scope, even if they aren't visible there; this models the fact that
284 such declarations are visible to the entire program, and (with a
285 bit of cleverness, see pushdecl) allows diagnosis of some violations
286 of C99 6.2.2p7 and 6.2.7p2:
288 If, within the same translation unit, the same identifier appears
289 with both internal and external linkage, the behavior is
292 All declarations that refer to the same object or function shall
293 have compatible type; otherwise, the behavior is undefined.
295 Initially only the built-in declarations, which describe compiler
296 intrinsic functions plus a subset of the standard library, are in
299 The order of the blocks list matters, and it is frequently appended
300 to. To avoid having to walk all the way to the end of the list on
301 each insertion, or reverse the list later, we maintain a pointer to
302 the last list entry. (FIXME: It should be feasible to use a reversed
305 The bindings list is strictly in reverse order of declarations;
306 pop_scope relies on this. */
309 struct c_scope GTY((chain_next ("%h.outer")))
311 /* The scope containing this one. */
312 struct c_scope *outer;
314 /* The next outermost function scope. */
315 struct c_scope *outer_function;
317 /* All bindings in this scope. */
318 struct c_binding *bindings;
320 /* For each scope (except the global one), a chain of BLOCK nodes
321 for all the scopes that were entered and exited one level down. */
325 /* The depth of this scope. Used to keep the ->shadowed chain of
326 bindings sorted innermost to outermost. */
327 unsigned int depth : 28;
329 /* True if we are currently filling this scope with parameter
331 BOOL_BITFIELD parm_flag : 1;
333 /* True if we already complained about forward parameter decls
334 in this scope. This prevents double warnings on
335 foo (int a; int b; ...) */
336 BOOL_BITFIELD warned_forward_parm_decls : 1;
338 /* True if this is the outermost block scope of a function body.
339 This scope contains the parameters, the local variables declared
340 in the outermost block, and all the labels (except those in
341 nested functions, or declared at block scope with __label__). */
342 BOOL_BITFIELD function_body : 1;
344 /* True means make a BLOCK for this scope no matter what. */
345 BOOL_BITFIELD keep : 1;
348 /* The scope currently in effect. */
350 static GTY(()) struct c_scope *current_scope;
352 /* The innermost function scope. Ordinary (not explicitly declared)
353 labels, bindings to error_mark_node, and the lazily-created
354 bindings of __func__ and its friends get this scope. */
356 static GTY(()) struct c_scope *current_function_scope;
358 /* The C file scope. This is reset for each input translation unit. */
360 static GTY(()) struct c_scope *file_scope;
362 /* The outermost scope. This is used for all declarations with
363 external linkage, and only these, hence the name. */
365 static GTY(()) struct c_scope *external_scope;
367 /* A chain of c_scope structures awaiting reuse. */
369 static GTY((deletable)) struct c_scope *scope_freelist;
371 /* A chain of c_binding structures awaiting reuse. */
373 static GTY((deletable)) struct c_binding *binding_freelist;
375 /* Append VAR to LIST in scope SCOPE. */
376 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
377 struct c_scope *s_ = (scope); \
379 if (s_->list##_last) \
380 TREE_CHAIN (s_->list##_last) = d_; \
383 s_->list##_last = d_; \
386 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
387 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
388 struct c_scope *t_ = (tscope); \
389 struct c_scope *f_ = (fscope); \
391 TREE_CHAIN (t_->to##_last) = f_->from; \
394 t_->to##_last = f_->from##_last; \
397 /* True means unconditionally make a BLOCK for the next scope pushed. */
399 static bool keep_next_level_flag;
401 /* True means the next call to push_scope will be the outermost scope
402 of a function body, so do not push a new scope, merely cease
403 expecting parameter decls. */
405 static bool next_is_function_body;
407 /* Functions called automatically at the beginning and end of execution. */
409 static GTY(()) tree static_ctors;
410 static GTY(()) tree static_dtors;
412 /* Forward declarations. */
413 static tree lookup_name_in_scope (tree, struct c_scope *);
414 static tree c_make_fname_decl (tree, int);
415 static tree grokdeclarator (const struct c_declarator *,
416 struct c_declspecs *,
417 enum decl_context, bool, tree *);
418 static tree grokparms (struct c_arg_info *, bool);
419 static void layout_array_type (tree);
421 /* T is a statement. Add it to the statement-tree. This is the
422 C/ObjC version--C++ has a slightly different version of this
428 enum tree_code code = TREE_CODE (t);
430 if (EXPR_P (t) && code != LABEL_EXPR)
432 if (!EXPR_HAS_LOCATION (t))
433 SET_EXPR_LOCATION (t, input_location);
436 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
437 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
439 /* Add T to the statement-tree. Non-side-effect statements need to be
440 recorded during statement expressions. */
441 append_to_statement_list_force (t, &cur_stmt_list);
446 /* States indicating how grokdeclarator() should handle declspecs marked
447 with __attribute__((deprecated)). An object declared as
448 __attribute__((deprecated)) suppresses warnings of uses of other
451 enum deprecated_states {
456 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
459 c_print_identifier (FILE *file, tree node, int indent)
461 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
462 print_node (file, "tag", I_TAG_DECL (node), indent + 4);
463 print_node (file, "label", I_LABEL_DECL (node), indent + 4);
464 if (C_IS_RESERVED_WORD (node))
466 tree rid = ridpointers[C_RID_CODE (node)];
467 indent_to (file, indent + 4);
468 fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
469 (void *) rid, IDENTIFIER_POINTER (rid));
473 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
474 which may be any of several kinds of DECL or TYPE or error_mark_node,
475 in the scope SCOPE. */
477 bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested)
479 struct c_binding *b, **here;
481 if (binding_freelist)
483 b = binding_freelist;
484 binding_freelist = b->prev;
487 b = GGC_NEW (struct c_binding);
492 b->depth = scope->depth;
493 b->invisible = invisible;
499 b->prev = scope->bindings;
505 switch (TREE_CODE (decl))
507 case LABEL_DECL: here = &I_LABEL_BINDING (name); break;
510 case RECORD_TYPE: here = &I_TAG_BINDING (name); break;
516 case ERROR_MARK: here = &I_SYMBOL_BINDING (name); break;
522 /* Locate the appropriate place in the chain of shadowed decls
523 to insert this binding. Normally, scope == current_scope and
524 this does nothing. */
525 while (*here && (*here)->depth > scope->depth)
526 here = &(*here)->shadowed;
532 /* Clear the binding structure B, stick it on the binding_freelist,
533 and return the former value of b->prev. This is used by pop_scope
534 and get_parm_info to iterate destructively over all the bindings
535 from a given scope. */
536 static struct c_binding *
537 free_binding_and_advance (struct c_binding *b)
539 struct c_binding *prev = b->prev;
541 memset (b, 0, sizeof (struct c_binding));
542 b->prev = binding_freelist;
543 binding_freelist = b;
549 /* Hook called at end of compilation to assume 1 elt
550 for a file-scope tentative array defn that wasn't complete before. */
553 c_finish_incomplete_decl (tree decl)
555 if (TREE_CODE (decl) == VAR_DECL)
557 tree type = TREE_TYPE (decl);
558 if (type != error_mark_node
559 && TREE_CODE (type) == ARRAY_TYPE
560 && !DECL_EXTERNAL (decl)
561 && TYPE_DOMAIN (type) == 0)
563 warning (0, "%Jarray %qD assumed to have one element", decl, decl);
565 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
567 layout_decl (decl, 0);
572 /* The Objective-C front-end often needs to determine the current scope. */
575 objc_get_current_scope (void)
577 return current_scope;
580 /* The following function is used only by Objective-C. It needs to live here
581 because it accesses the innards of c_scope. */
584 objc_mark_locals_volatile (void *enclosing_blk)
586 struct c_scope *scope;
589 for (scope = current_scope;
590 scope && scope != enclosing_blk;
591 scope = scope->outer)
593 for (b = scope->bindings; b; b = b->prev)
594 objc_volatilize_decl (b->decl);
596 /* Do not climb up past the current function. */
597 if (scope->function_body)
602 /* Nonzero if we are currently in file scope. */
605 global_bindings_p (void)
607 return current_scope == file_scope && !c_override_global_bindings_to_false;
611 keep_next_level (void)
613 keep_next_level_flag = true;
616 /* Identify this scope as currently being filled with parameters. */
619 declare_parm_level (void)
621 current_scope->parm_flag = true;
627 if (next_is_function_body)
629 /* This is the transition from the parameters to the top level
630 of the function body. These are the same scope
631 (C99 6.2.1p4,6) so we do not push another scope structure.
632 next_is_function_body is set only by store_parm_decls, which
633 in turn is called when and only when we are about to
634 encounter the opening curly brace for the function body.
636 The outermost block of a function always gets a BLOCK node,
637 because the debugging output routines expect that each
638 function has at least one BLOCK. */
639 current_scope->parm_flag = false;
640 current_scope->function_body = true;
641 current_scope->keep = true;
642 current_scope->outer_function = current_function_scope;
643 current_function_scope = current_scope;
645 keep_next_level_flag = false;
646 next_is_function_body = false;
650 struct c_scope *scope;
653 scope = scope_freelist;
654 scope_freelist = scope->outer;
657 scope = GGC_CNEW (struct c_scope);
659 scope->keep = keep_next_level_flag;
660 scope->outer = current_scope;
661 scope->depth = current_scope ? (current_scope->depth + 1) : 0;
663 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but
665 if (current_scope && scope->depth == 0)
668 sorry ("GCC supports only %u nested scopes", scope->depth);
671 current_scope = scope;
672 keep_next_level_flag = false;
676 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */
679 set_type_context (tree type, tree context)
681 for (type = TYPE_MAIN_VARIANT (type); type;
682 type = TYPE_NEXT_VARIANT (type))
683 TYPE_CONTEXT (type) = context;
686 /* Exit a scope. Restore the state of the identifier-decl mappings
687 that were in effect when this scope was entered. Return a BLOCK
688 node containing all the DECLs in this scope that are of interest
689 to debug info generation. */
694 struct c_scope *scope = current_scope;
695 tree block, context, p;
698 bool functionbody = scope->function_body;
699 bool keep = functionbody || scope->keep || scope->bindings;
701 c_end_vm_scope (scope->depth);
703 /* If appropriate, create a BLOCK to record the decls for the life
708 block = make_node (BLOCK);
709 BLOCK_SUBBLOCKS (block) = scope->blocks;
710 TREE_USED (block) = 1;
712 /* In each subblock, record that this is its superior. */
713 for (p = scope->blocks; p; p = TREE_CHAIN (p))
714 BLOCK_SUPERCONTEXT (p) = block;
716 BLOCK_VARS (block) = 0;
719 /* The TYPE_CONTEXTs for all of the tagged types belonging to this
720 scope must be set so that they point to the appropriate
721 construct, i.e. either to the current FUNCTION_DECL node, or
722 else to the BLOCK node we just constructed.
724 Note that for tagged types whose scope is just the formal
725 parameter list for some function type specification, we can't
726 properly set their TYPE_CONTEXTs here, because we don't have a
727 pointer to the appropriate FUNCTION_TYPE node readily available
728 to us. For those cases, the TYPE_CONTEXTs of the relevant tagged
729 type nodes get set in `grokdeclarator' as soon as we have created
730 the FUNCTION_TYPE node which will represent the "scope" for these
731 "parameter list local" tagged types. */
732 if (scope->function_body)
733 context = current_function_decl;
734 else if (scope == file_scope)
736 tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
737 TREE_CHAIN (file_decl) = all_translation_units;
738 all_translation_units = file_decl;
744 /* Clear all bindings in this scope. */
745 for (b = scope->bindings; b; b = free_binding_and_advance (b))
748 switch (TREE_CODE (p))
751 /* Warnings for unused labels, errors for undefined labels. */
752 if (TREE_USED (p) && !DECL_INITIAL (p))
754 error ("%Jlabel %qD used but not defined", p, p);
755 DECL_INITIAL (p) = error_mark_node;
757 else if (!TREE_USED (p) && warn_unused_label)
759 if (DECL_INITIAL (p))
760 warning (0, "%Jlabel %qD defined but not used", p, p);
762 warning (0, "%Jlabel %qD declared but not defined", p, p);
764 /* Labels go in BLOCK_VARS. */
765 TREE_CHAIN (p) = BLOCK_VARS (block);
766 BLOCK_VARS (block) = p;
767 gcc_assert (I_LABEL_BINDING (b->id) == b);
768 I_LABEL_BINDING (b->id) = b->shadowed;
774 set_type_context (p, context);
776 /* Types may not have tag-names, in which case the type
777 appears in the bindings list with b->id NULL. */
780 gcc_assert (I_TAG_BINDING (b->id) == b);
781 I_TAG_BINDING (b->id) = b->shadowed;
786 /* Propagate TREE_ADDRESSABLE from nested functions to their
787 containing functions. */
788 if (!TREE_ASM_WRITTEN (p)
789 && DECL_INITIAL (p) != 0
790 && TREE_ADDRESSABLE (p)
791 && DECL_ABSTRACT_ORIGIN (p) != 0
792 && DECL_ABSTRACT_ORIGIN (p) != p)
793 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
794 if (!DECL_EXTERNAL (p)
795 && DECL_INITIAL (p) == 0)
797 error ("%Jnested function %qD declared but never defined", p, p);
798 undef_nested_function = true;
803 /* Warnings for unused variables. */
805 && !DECL_IN_SYSTEM_HEADER (p)
807 && !DECL_ARTIFICIAL (p)
808 && scope != file_scope
809 && scope != external_scope)
810 warning (OPT_Wunused_variable, "%Junused variable %qD", p, p);
814 error ("%Jtype of array %qD completed incompatibly with"
815 " implicit initialization", p, p);
822 /* All of these go in BLOCK_VARS, but only if this is the
823 binding in the home scope. */
826 TREE_CHAIN (p) = BLOCK_VARS (block);
827 BLOCK_VARS (block) = p;
829 /* If this is the file scope, and we are processing more
830 than one translation unit in this compilation, set
831 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
832 This makes same_translation_unit_p work, and causes
833 static declarations to be given disambiguating suffixes. */
834 if (scope == file_scope && num_in_fnames > 1)
836 DECL_CONTEXT (p) = context;
837 if (TREE_CODE (p) == TYPE_DECL)
838 set_type_context (TREE_TYPE (p), context);
842 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
843 already been put there by store_parm_decls. Unused-
844 parameter warnings are handled by function.c.
845 error_mark_node obviously does not go in BLOCK_VARS and
846 does not get unused-variable warnings. */
849 /* It is possible for a decl not to have a name. We get
850 here with b->id NULL in this case. */
853 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
854 I_SYMBOL_BINDING (b->id) = b->shadowed;
855 if (b->shadowed && b->shadowed->type)
856 TREE_TYPE (b->shadowed->decl) = b->shadowed->type;
866 /* Dispose of the block that we just made inside some higher level. */
867 if ((scope->function_body || scope == file_scope) && context)
869 DECL_INITIAL (context) = block;
870 BLOCK_SUPERCONTEXT (block) = context;
872 else if (scope->outer)
875 SCOPE_LIST_APPEND (scope->outer, blocks, block);
876 /* If we did not make a block for the scope just exited, any
877 blocks made for inner scopes must be carried forward so they
878 will later become subblocks of something else. */
879 else if (scope->blocks)
880 SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
883 /* Pop the current scope, and free the structure for reuse. */
884 current_scope = scope->outer;
885 if (scope->function_body)
886 current_function_scope = scope->outer_function;
888 memset (scope, 0, sizeof (struct c_scope));
889 scope->outer = scope_freelist;
890 scope_freelist = scope;
896 push_file_scope (void)
904 file_scope = current_scope;
906 start_fname_decls ();
908 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
909 bind (DECL_NAME (decl), decl, file_scope,
910 /*invisible=*/false, /*nested=*/true);
914 pop_file_scope (void)
916 /* In case there were missing closebraces, get us back to the global
918 while (current_scope != file_scope)
921 /* __FUNCTION__ is defined at file scope (""). This
922 call may not be necessary as my tests indicate it
923 still works without it. */
924 finish_fname_decls ();
926 /* This is the point to write out a PCH if we're doing that.
927 In that case we do not want to do anything else. */
930 c_common_write_pch ();
934 /* Pop off the file scope and close this translation unit. */
938 maybe_apply_pending_pragma_weaks ();
939 cgraph_finalize_compilation_unit ();
942 /* Insert BLOCK at the end of the list of subblocks of the current
943 scope. This is used when a BIND_EXPR is expanded, to handle the
944 BLOCK node inside the BIND_EXPR. */
947 insert_block (tree block)
949 TREE_USED (block) = 1;
950 SCOPE_LIST_APPEND (current_scope, blocks, block);
953 /* Push a definition or a declaration of struct, union or enum tag "name".
954 "type" should be the type node.
955 We assume that the tag "name" is not already defined.
957 Note that the definition may really be just a forward reference.
958 In that case, the TYPE_SIZE will be zero. */
961 pushtag (tree name, tree type)
963 /* Record the identifier as the type's name if it has none. */
964 if (name && !TYPE_NAME (type))
965 TYPE_NAME (type) = name;
966 bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false);
968 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
969 tagged type we just added to the current scope. This fake
970 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
971 to output a representation of a tagged type, and it also gives
972 us a convenient place to record the "scope start" address for the
975 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
977 /* An approximation for now, so we can tell this is a function-scope tag.
978 This will be updated in pop_scope. */
979 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
982 /* Subroutine of compare_decls. Allow harmless mismatches in return
983 and argument types provided that the type modes match. This function
984 return a unified type given a suitable match, and 0 otherwise. */
987 match_builtin_function_types (tree newtype, tree oldtype)
989 tree newrettype, oldrettype;
990 tree newargs, oldargs;
991 tree trytype, tryargs;
993 /* Accept the return type of the new declaration if same modes. */
994 oldrettype = TREE_TYPE (oldtype);
995 newrettype = TREE_TYPE (newtype);
997 if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype))
1000 oldargs = TYPE_ARG_TYPES (oldtype);
1001 newargs = TYPE_ARG_TYPES (newtype);
1004 while (oldargs || newargs)
1008 || !TREE_VALUE (oldargs)
1009 || !TREE_VALUE (newargs)
1010 || TYPE_MODE (TREE_VALUE (oldargs))
1011 != TYPE_MODE (TREE_VALUE (newargs)))
1014 oldargs = TREE_CHAIN (oldargs);
1015 newargs = TREE_CHAIN (newargs);
1018 trytype = build_function_type (newrettype, tryargs);
1019 return build_type_attribute_variant (trytype, TYPE_ATTRIBUTES (oldtype));
1022 /* Subroutine of diagnose_mismatched_decls. Check for function type
1023 mismatch involving an empty arglist vs a nonempty one and give clearer
1026 diagnose_arglist_conflict (tree newdecl, tree olddecl,
1027 tree newtype, tree oldtype)
1031 if (TREE_CODE (olddecl) != FUNCTION_DECL
1032 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
1033 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0)
1035 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
1038 t = TYPE_ARG_TYPES (oldtype);
1040 t = TYPE_ARG_TYPES (newtype);
1041 for (; t; t = TREE_CHAIN (t))
1043 tree type = TREE_VALUE (t);
1045 if (TREE_CHAIN (t) == 0
1046 && TYPE_MAIN_VARIANT (type) != void_type_node)
1048 inform ("a parameter list with an ellipsis can%'t match "
1049 "an empty parameter name list declaration");
1053 if (c_type_promotes_to (type) != type)
1055 inform ("an argument type that has a default promotion can%'t match "
1056 "an empty parameter name list declaration");
1062 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
1063 old-style function definition, NEWDECL is a prototype declaration.
1064 Diagnose inconsistencies in the argument list. Returns TRUE if
1065 the prototype is compatible, FALSE if not. */
1067 validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
1069 tree newargs, oldargs;
1072 #define END_OF_ARGLIST(t) ((t) == void_type_node)
1074 oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
1075 newargs = TYPE_ARG_TYPES (newtype);
1080 tree oldargtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
1081 tree newargtype = TYPE_MAIN_VARIANT (TREE_VALUE (newargs));
1083 if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
1086 /* Reaching the end of just one list means the two decls don't
1087 agree on the number of arguments. */
1088 if (END_OF_ARGLIST (oldargtype))
1090 error ("%Jprototype for %qD declares more arguments "
1091 "than previous old-style definition", newdecl, newdecl);
1094 else if (END_OF_ARGLIST (newargtype))
1096 error ("%Jprototype for %qD declares fewer arguments "
1097 "than previous old-style definition", newdecl, newdecl);
1101 /* Type for passing arg must be consistent with that declared
1103 else if (!comptypes (oldargtype, newargtype))
1105 error ("%Jprototype for %qD declares argument %d"
1106 " with incompatible type",
1107 newdecl, newdecl, i);
1111 oldargs = TREE_CHAIN (oldargs);
1112 newargs = TREE_CHAIN (newargs);
1116 /* If we get here, no errors were found, but do issue a warning
1117 for this poor-style construct. */
1118 warning (0, "%Jprototype for %qD follows non-prototype definition",
1121 #undef END_OF_ARGLIST
1124 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
1125 first in a pair of mismatched declarations, using the diagnostic
1128 locate_old_decl (tree decl, void (*diag)(const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2))
1130 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1132 else if (DECL_INITIAL (decl))
1133 diag (G_("%Jprevious definition of %qD was here"), decl, decl);
1134 else if (C_DECL_IMPLICIT (decl))
1135 diag (G_("%Jprevious implicit declaration of %qD was here"), decl, decl);
1137 diag (G_("%Jprevious declaration of %qD was here"), decl, decl);
1140 /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL.
1141 Returns true if the caller should proceed to merge the two, false
1142 if OLDDECL should simply be discarded. As a side effect, issues
1143 all necessary diagnostics for invalid or poor-style combinations.
1144 If it returns true, writes the types of NEWDECL and OLDDECL to
1145 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1146 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
1149 diagnose_mismatched_decls (tree newdecl, tree olddecl,
1150 tree *newtypep, tree *oldtypep)
1152 tree newtype, oldtype;
1153 bool pedwarned = false;
1154 bool warned = false;
1157 /* If we have error_mark_node for either decl or type, just discard
1158 the previous decl - we're in an error cascade already. */
1159 if (olddecl == error_mark_node || newdecl == error_mark_node)
1161 *oldtypep = oldtype = TREE_TYPE (olddecl);
1162 *newtypep = newtype = TREE_TYPE (newdecl);
1163 if (oldtype == error_mark_node || newtype == error_mark_node)
1166 /* Two different categories of symbol altogether. This is an error
1167 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
1168 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1170 if (!(TREE_CODE (olddecl) == FUNCTION_DECL
1171 && DECL_BUILT_IN (olddecl)
1172 && !C_DECL_DECLARED_BUILTIN (olddecl)))
1174 error ("%J%qD redeclared as different kind of symbol",
1176 locate_old_decl (olddecl, error);
1178 else if (TREE_PUBLIC (newdecl))
1179 warning (0, "%Jbuilt-in function %qD declared as non-function",
1182 warning (OPT_Wshadow, "%Jdeclaration of %qD shadows "
1183 "a built-in function", newdecl, newdecl);
1187 /* Enumerators have no linkage, so may only be declared once in a
1189 if (TREE_CODE (olddecl) == CONST_DECL)
1191 error ("%Jredeclaration of enumerator %qD", newdecl, newdecl);
1192 locate_old_decl (olddecl, error);
1196 if (!comptypes (oldtype, newtype))
1198 if (TREE_CODE (olddecl) == FUNCTION_DECL
1199 && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
1201 /* Accept harmless mismatch in function types.
1202 This is for the ffs and fprintf builtins. */
1203 tree trytype = match_builtin_function_types (newtype, oldtype);
1205 if (trytype && comptypes (newtype, trytype))
1206 *oldtypep = oldtype = trytype;
1209 /* If types don't match for a built-in, throw away the
1210 built-in. No point in calling locate_old_decl here, it
1211 won't print anything. */
1212 warning (0, "%Jconflicting types for built-in function %qD",
1217 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1218 && DECL_IS_BUILTIN (olddecl))
1220 /* A conflicting function declaration for a predeclared
1221 function that isn't actually built in. Objective C uses
1222 these. The new declaration silently overrides everything
1223 but the volatility (i.e. noreturn) indication. See also
1224 below. FIXME: Make Objective C use normal builtins. */
1225 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1228 /* Permit void foo (...) to match int foo (...) if the latter is
1229 the definition and implicit int was used. See
1230 c-torture/compile/920625-2.c. */
1231 else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
1232 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
1233 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
1234 && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
1236 pedwarn ("%Jconflicting types for %qD", newdecl, newdecl);
1237 /* Make sure we keep void as the return type. */
1238 TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
1239 C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
1242 /* Permit void foo (...) to match an earlier call to foo (...) with
1243 no declared type (thus, implicitly int). */
1244 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1245 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
1246 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
1247 && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
1249 pedwarn ("%Jconflicting types for %qD", newdecl, newdecl);
1250 /* Make sure we keep void as the return type. */
1251 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
1256 if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype))
1257 error ("%J conflicting type qualifiers for %qD", newdecl, newdecl);
1259 error ("%Jconflicting types for %qD", newdecl, newdecl);
1260 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
1261 locate_old_decl (olddecl, error);
1266 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1267 but silently ignore the redeclaration if either is in a system
1268 header. (Conflicting redeclarations were handled above.) */
1269 if (TREE_CODE (newdecl) == TYPE_DECL)
1271 if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl))
1272 return true; /* Allow OLDDECL to continue in use. */
1274 error ("%Jredefinition of typedef %qD", newdecl, newdecl);
1275 locate_old_decl (olddecl, error);
1279 /* Function declarations can either be 'static' or 'extern' (no
1280 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1281 can never conflict with each other on account of linkage (6.2.2p4).
1282 Multiple definitions are not allowed (6.9p3,5) but GCC permits
1283 two definitions if one is 'extern inline' and one is not. The non-
1284 extern-inline definition supersedes the extern-inline definition. */
1285 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1287 /* If you declare a built-in function name as static, or
1288 define the built-in with an old-style definition (so we
1289 can't validate the argument list) the built-in definition is
1290 overridden, but optionally warn this was a bad choice of name. */
1291 if (DECL_BUILT_IN (olddecl)
1292 && !C_DECL_DECLARED_BUILTIN (olddecl)
1293 && (!TREE_PUBLIC (newdecl)
1294 || (DECL_INITIAL (newdecl)
1295 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
1297 warning (OPT_Wshadow, "%Jdeclaration of %qD shadows "
1298 "a built-in function", newdecl, newdecl);
1299 /* Discard the old built-in function. */
1303 if (DECL_INITIAL (newdecl))
1305 if (DECL_INITIAL (olddecl))
1307 /* If both decls have extern inline and are in the same TU,
1308 reject the new decl. */
1309 if (DECL_DECLARED_INLINE_P (olddecl)
1310 && DECL_EXTERNAL (olddecl)
1311 && DECL_DECLARED_INLINE_P (newdecl)
1312 && DECL_EXTERNAL (newdecl)
1313 && same_translation_unit_p (newdecl, olddecl))
1315 error ("%Jredefinition of %qD", newdecl, newdecl);
1316 locate_old_decl (olddecl, error);
1319 /* If both decls have not extern inline, reject the new decl. */
1320 if (!DECL_DECLARED_INLINE_P (olddecl)
1321 && !DECL_EXTERNAL (olddecl)
1322 && !DECL_DECLARED_INLINE_P (newdecl)
1323 && !DECL_EXTERNAL (newdecl))
1325 error ("%Jredefinition of %qD", newdecl, newdecl);
1326 locate_old_decl (olddecl, error);
1329 /* If the new decl is declared as extern inline, error if they are
1330 in the same TU, otherwise retain the old decl. */
1331 if (!DECL_DECLARED_INLINE_P (olddecl)
1332 && !DECL_EXTERNAL (olddecl)
1333 && DECL_DECLARED_INLINE_P (newdecl)
1334 && DECL_EXTERNAL (newdecl))
1336 if (same_translation_unit_p (newdecl, olddecl))
1338 error ("%Jredefinition of %qD", newdecl, newdecl);
1339 locate_old_decl (olddecl, error);
1347 /* If we have a prototype after an old-style function definition,
1348 the argument types must be checked specially. */
1349 else if (DECL_INITIAL (olddecl)
1350 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype)
1351 && TYPE_ACTUAL_ARG_TYPES (oldtype)
1352 && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
1354 locate_old_decl (olddecl, error);
1357 /* A non-static declaration (even an "extern") followed by a
1358 static declaration is undefined behavior per C99 6.2.2p3-5,7.
1359 The same is true for a static forward declaration at block
1360 scope followed by a non-static declaration/definition at file
1361 scope. Static followed by non-static at the same scope is
1362 not undefined behavior, and is the most convenient way to get
1363 some effects (see e.g. what unwind-dw2-fde-glibc.c does to
1364 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
1365 we do diagnose it if -Wtraditional. */
1366 if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
1368 /* Two exceptions to the rule. If olddecl is an extern
1369 inline, or a predeclared function that isn't actually
1370 built in, newdecl silently overrides olddecl. The latter
1371 occur only in Objective C; see also above. (FIXME: Make
1372 Objective C use normal builtins.) */
1373 if (!DECL_IS_BUILTIN (olddecl)
1374 && !(DECL_EXTERNAL (olddecl)
1375 && DECL_DECLARED_INLINE_P (olddecl)))
1377 error ("%Jstatic declaration of %qD follows "
1378 "non-static declaration", newdecl, newdecl);
1379 locate_old_decl (olddecl, error);
1383 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
1385 if (DECL_CONTEXT (olddecl))
1387 error ("%Jnon-static declaration of %qD follows "
1388 "static declaration", newdecl, newdecl);
1389 locate_old_decl (olddecl, error);
1392 else if (warn_traditional)
1394 warning (OPT_Wtraditional, "%Jnon-static declaration of %qD "
1395 "follows static declaration", newdecl, newdecl);
1400 else if (TREE_CODE (newdecl) == VAR_DECL)
1402 /* Only variables can be thread-local, and all declarations must
1403 agree on this property. */
1404 if (DECL_THREAD_LOCAL (newdecl) != DECL_THREAD_LOCAL (olddecl))
1406 if (DECL_THREAD_LOCAL (newdecl))
1407 error ("%Jthread-local declaration of %qD follows "
1408 "non-thread-local declaration", newdecl, newdecl);
1410 error ("%Jnon-thread-local declaration of %qD follows "
1411 "thread-local declaration", newdecl, newdecl);
1413 locate_old_decl (olddecl, error);
1417 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1418 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
1420 error ("%Jredefinition of %qD", newdecl, newdecl);
1421 locate_old_decl (olddecl, error);
1425 /* Objects declared at file scope: if the first declaration had
1426 external linkage (even if it was an external reference) the
1427 second must have external linkage as well, or the behavior is
1428 undefined. If the first declaration had internal linkage, then
1429 the second must too, or else be an external reference (in which
1430 case the composite declaration still has internal linkage).
1431 As for function declarations, we warn about the static-then-
1432 extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */
1433 if (DECL_FILE_SCOPE_P (newdecl)
1434 && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
1436 if (DECL_EXTERNAL (newdecl))
1438 if (!DECL_FILE_SCOPE_P (olddecl))
1440 error ("%Jextern declaration of %qD follows "
1441 "declaration with no linkage", newdecl, newdecl);
1442 locate_old_decl (olddecl, error);
1445 else if (warn_traditional)
1447 warning (OPT_Wtraditional, "%Jnon-static declaration of %qD "
1448 "follows static declaration", newdecl, newdecl);
1454 if (TREE_PUBLIC (newdecl))
1455 error ("%Jnon-static declaration of %qD follows "
1456 "static declaration", newdecl, newdecl);
1458 error ("%Jstatic declaration of %qD follows "
1459 "non-static declaration", newdecl, newdecl);
1461 locate_old_decl (olddecl, error);
1465 /* Two objects with the same name declared at the same block
1466 scope must both be external references (6.7p3). */
1467 else if (!DECL_FILE_SCOPE_P (newdecl))
1469 if (DECL_EXTERNAL (newdecl))
1471 /* Extern with initializer at block scope, which will
1472 already have received an error. */
1474 else if (DECL_EXTERNAL (olddecl))
1476 error ("%Jdeclaration of %qD with no linkage follows "
1477 "extern declaration", newdecl, newdecl);
1478 locate_old_decl (olddecl, error);
1482 error ("%Jredeclaration of %qD with no linkage",
1484 locate_old_decl (olddecl, error);
1492 /* All decls must agree on a visibility. */
1493 if (DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
1494 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
1496 warning (0, "%Jredeclaration of %qD with different visibility "
1497 "(old visibility preserved)", newdecl, newdecl);
1501 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1503 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1504 if (DECL_DECLARED_INLINE_P (newdecl)
1505 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1507 warning (OPT_Wattributes, "%Jinline declaration of %qD follows "
1508 "declaration with attribute noinline", newdecl, newdecl);
1511 else if (DECL_DECLARED_INLINE_P (olddecl)
1512 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1514 warning (OPT_Wattributes, "%Jdeclaration of %qD with attribute "
1515 "noinline follows inline declaration ", newdecl, newdecl);
1519 /* Inline declaration after use or definition.
1520 ??? Should we still warn about this now we have unit-at-a-time
1521 mode and can get it right?
1522 Definitely don't complain if the decls are in different translation
1524 if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
1525 && same_translation_unit_p (olddecl, newdecl))
1527 if (TREE_USED (olddecl))
1529 warning (0, "%J%qD declared inline after being called",
1533 else if (DECL_INITIAL (olddecl))
1535 warning (0, "%J%qD declared inline after its definition",
1541 else /* PARM_DECL, VAR_DECL */
1543 /* Redeclaration of a parameter is a constraint violation (this is
1544 not explicitly stated, but follows from C99 6.7p3 [no more than
1545 one declaration of the same identifier with no linkage in the
1546 same scope, except type tags] and 6.2.2p6 [parameters have no
1547 linkage]). We must check for a forward parameter declaration,
1548 indicated by TREE_ASM_WRITTEN on the old declaration - this is
1549 an extension, the mandatory diagnostic for which is handled by
1550 mark_forward_parm_decls. */
1552 if (TREE_CODE (newdecl) == PARM_DECL
1553 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
1555 error ("%Jredefinition of parameter %qD", newdecl, newdecl);
1556 locate_old_decl (olddecl, error);
1561 /* Optional warning for completely redundant decls. */
1562 if (!warned && !pedwarned
1563 && warn_redundant_decls
1564 /* Don't warn about a function declaration followed by a
1566 && !(TREE_CODE (newdecl) == FUNCTION_DECL
1567 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
1568 /* Don't warn about redundant redeclarations of builtins. */
1569 && !(TREE_CODE (newdecl) == FUNCTION_DECL
1570 && !DECL_BUILT_IN (newdecl)
1571 && DECL_BUILT_IN (olddecl)
1572 && !C_DECL_DECLARED_BUILTIN (olddecl))
1573 /* Don't warn about an extern followed by a definition. */
1574 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
1575 /* Don't warn about forward parameter decls. */
1576 && !(TREE_CODE (newdecl) == PARM_DECL
1577 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)))
1579 warning (OPT_Wredundant_decls, "%Jredundant redeclaration of %qD",
1584 /* Report location of previous decl/defn in a consistent manner. */
1585 if (warned || pedwarned)
1586 locate_old_decl (olddecl, pedwarned ? pedwarn : warning0);
1591 /* Subroutine of duplicate_decls. NEWDECL has been found to be
1592 consistent with OLDDECL, but carries new information. Merge the
1593 new information into OLDDECL. This function issues no
1597 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
1599 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1600 && DECL_INITIAL (newdecl) != 0);
1601 int new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
1602 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
1603 int old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
1604 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
1606 /* For real parm decl following a forward decl, rechain the old decl
1607 in its new location and clear TREE_ASM_WRITTEN (it's not a
1608 forward decl anymore). */
1609 if (TREE_CODE (newdecl) == PARM_DECL
1610 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
1612 struct c_binding *b, **here;
1614 for (here = ¤t_scope->bindings; *here; here = &(*here)->prev)
1615 if ((*here)->decl == olddecl)
1622 b->prev = current_scope->bindings;
1623 current_scope->bindings = b;
1625 TREE_ASM_WRITTEN (olddecl) = 0;
1628 DECL_ATTRIBUTES (newdecl)
1629 = targetm.merge_decl_attributes (olddecl, newdecl);
1631 /* Merge the data types specified in the two decls. */
1633 = TREE_TYPE (olddecl)
1634 = composite_type (newtype, oldtype);
1636 /* Lay the type out, unless already done. */
1637 if (!comptypes (oldtype, TREE_TYPE (newdecl)))
1639 if (TREE_TYPE (newdecl) != error_mark_node)
1640 layout_type (TREE_TYPE (newdecl));
1641 if (TREE_CODE (newdecl) != FUNCTION_DECL
1642 && TREE_CODE (newdecl) != TYPE_DECL
1643 && TREE_CODE (newdecl) != CONST_DECL)
1644 layout_decl (newdecl, 0);
1648 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1649 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1650 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
1651 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1652 if (TREE_CODE (olddecl) != FUNCTION_DECL)
1653 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1655 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1656 DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl);
1660 /* Keep the old rtl since we can safely use it. */
1661 COPY_DECL_RTL (olddecl, newdecl);
1663 /* Merge the type qualifiers. */
1664 if (TREE_READONLY (newdecl))
1665 TREE_READONLY (olddecl) = 1;
1667 if (TREE_THIS_VOLATILE (newdecl))
1669 TREE_THIS_VOLATILE (olddecl) = 1;
1670 if (TREE_CODE (newdecl) == VAR_DECL)
1671 make_var_volatile (newdecl);
1674 /* Merge deprecatedness. */
1675 if (TREE_DEPRECATED (newdecl))
1676 TREE_DEPRECATED (olddecl) = 1;
1678 /* Keep source location of definition rather than declaration and of
1679 prototype rather than non-prototype unless that prototype is
1681 if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
1682 || (old_is_prototype && !new_is_prototype
1683 && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
1684 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1686 /* Merge the unused-warning information. */
1687 if (DECL_IN_SYSTEM_HEADER (olddecl))
1688 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1689 else if (DECL_IN_SYSTEM_HEADER (newdecl))
1690 DECL_IN_SYSTEM_HEADER (olddecl) = 1;
1692 /* Merge the initialization information. */
1693 if (DECL_INITIAL (newdecl) == 0)
1694 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1696 /* Merge the section attribute.
1697 We want to issue an error if the sections conflict but that must be
1698 done later in decl_attributes since we are called before attributes
1700 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1701 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1703 /* Copy the assembler name.
1704 Currently, it can only be defined in the prototype. */
1705 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
1707 /* Use visibility of whichever declaration had it specified */
1708 if (DECL_VISIBILITY_SPECIFIED (olddecl))
1710 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
1711 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
1714 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1716 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1717 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1718 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1719 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1720 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1721 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1722 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1723 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1724 DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
1725 DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
1728 /* Merge the storage class information. */
1729 merge_weak (newdecl, olddecl);
1731 /* For functions, static overrides non-static. */
1732 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1734 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1735 /* This is since we don't automatically
1736 copy the attributes of NEWDECL into OLDDECL. */
1737 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1738 /* If this clears `static', clear it in the identifier too. */
1739 if (!TREE_PUBLIC (olddecl))
1740 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1742 if (DECL_EXTERNAL (newdecl))
1744 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
1745 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1747 /* An extern decl does not override previous storage class. */
1748 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1749 if (!DECL_EXTERNAL (newdecl))
1751 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1752 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
1757 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1758 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1761 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1763 /* If we're redefining a function previously defined as extern
1764 inline, make sure we emit debug info for the inline before we
1765 throw it away, in case it was inlined into a function that hasn't
1766 been written out yet. */
1767 if (new_is_definition && DECL_INITIAL (olddecl))
1769 if (TREE_USED (olddecl)
1770 /* In unit-at-a-time mode we never inline re-defined extern
1771 inline functions. */
1772 && !flag_unit_at_a_time
1773 && cgraph_function_possibly_inlined_p (olddecl))
1774 (*debug_hooks->outlining_inline_function) (olddecl);
1776 /* The new defn must not be inline. */
1777 DECL_INLINE (newdecl) = 0;
1778 DECL_UNINLINABLE (newdecl) = 1;
1782 /* If either decl says `inline', this fn is inline,
1783 unless its definition was passed already. */
1784 if (DECL_DECLARED_INLINE_P (newdecl)
1785 || DECL_DECLARED_INLINE_P (olddecl))
1786 DECL_DECLARED_INLINE_P (newdecl) = 1;
1788 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1789 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1792 if (DECL_BUILT_IN (olddecl))
1794 /* If redeclaring a builtin function, it stays built in.
1795 But it gets tagged as having been declared. */
1796 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1797 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1798 C_DECL_DECLARED_BUILTIN (newdecl) = 1;
1799 if (new_is_prototype)
1800 C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
1802 C_DECL_BUILTIN_PROTOTYPE (newdecl)
1803 = C_DECL_BUILTIN_PROTOTYPE (olddecl);
1806 /* Also preserve various other info from the definition. */
1807 if (!new_is_definition)
1809 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1810 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1811 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
1812 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1813 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
1815 /* Set DECL_INLINE on the declaration if we've got a body
1816 from which to instantiate. */
1817 if (DECL_INLINE (olddecl) && !DECL_UNINLINABLE (newdecl))
1819 DECL_INLINE (newdecl) = 1;
1820 DECL_ABSTRACT_ORIGIN (newdecl)
1821 = DECL_ABSTRACT_ORIGIN (olddecl);
1826 /* If a previous declaration said inline, mark the
1827 definition as inlinable. */
1828 if (DECL_DECLARED_INLINE_P (newdecl)
1829 && !DECL_UNINLINABLE (newdecl))
1830 DECL_INLINE (newdecl) = 1;
1834 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1835 But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
1837 unsigned olddecl_uid = DECL_UID (olddecl);
1838 tree olddecl_context = DECL_CONTEXT (olddecl);
1840 memcpy ((char *) olddecl + sizeof (struct tree_common),
1841 (char *) newdecl + sizeof (struct tree_common),
1842 sizeof (struct tree_decl) - sizeof (struct tree_common));
1843 DECL_UID (olddecl) = olddecl_uid;
1844 DECL_CONTEXT (olddecl) = olddecl_context;
1847 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1848 so that encode_section_info has a chance to look at the new decl
1849 flags and attributes. */
1850 if (DECL_RTL_SET_P (olddecl)
1851 && (TREE_CODE (olddecl) == FUNCTION_DECL
1852 || (TREE_CODE (olddecl) == VAR_DECL
1853 && TREE_STATIC (olddecl))))
1854 make_decl_rtl (olddecl);
1857 /* Handle when a new declaration NEWDECL has the same name as an old
1858 one OLDDECL in the same binding contour. Prints an error message
1861 If safely possible, alter OLDDECL to look like NEWDECL, and return
1862 true. Otherwise, return false. */
1865 duplicate_decls (tree newdecl, tree olddecl)
1867 tree newtype = NULL, oldtype = NULL;
1869 if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
1872 merge_decls (newdecl, olddecl, newtype, oldtype);
1877 /* Check whether decl-node NEW_DECL shadows an existing declaration. */
1879 warn_if_shadowing (tree new_decl)
1881 struct c_binding *b;
1883 /* Shadow warnings wanted? */
1885 /* No shadow warnings for internally generated vars. */
1886 || DECL_IS_BUILTIN (new_decl)
1887 /* No shadow warnings for vars made for inlining. */
1888 || DECL_FROM_INLINE (new_decl)
1889 /* Don't warn about the parm names in function declarator
1890 within a function declarator. It would be nice to avoid
1891 warning in any function declarator in a declaration, as
1892 opposed to a definition, but there is no way to tell
1893 it's not a definition at this point. */
1894 || (TREE_CODE (new_decl) == PARM_DECL && current_scope->outer->parm_flag))
1897 /* Is anything being shadowed? Invisible decls do not count. */
1898 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
1899 if (b->decl && b->decl != new_decl && !b->invisible)
1901 tree old_decl = b->decl;
1903 if (old_decl == error_mark_node)
1905 warning (0, "%Jdeclaration of %qD shadows previous non-variable",
1906 new_decl, new_decl);
1909 else if (TREE_CODE (old_decl) == PARM_DECL)
1910 warning (0, "%Jdeclaration of %qD shadows a parameter",
1911 new_decl, new_decl);
1912 else if (DECL_FILE_SCOPE_P (old_decl))
1913 warning (0, "%Jdeclaration of %qD shadows a global declaration",
1914 new_decl, new_decl);
1915 else if (TREE_CODE (old_decl) == FUNCTION_DECL
1916 && DECL_BUILT_IN (old_decl))
1918 warning (0, "%Jdeclaration of %qD shadows a built-in function",
1919 new_decl, new_decl);
1923 warning (0, "%Jdeclaration of %qD shadows a previous local",
1924 new_decl, new_decl);
1926 warning (0, "%Jshadowed declaration is here", old_decl);
1933 /* Subroutine of pushdecl.
1935 X is a TYPE_DECL for a typedef statement. Create a brand new
1936 ..._TYPE node (which will be just a variant of the existing
1937 ..._TYPE node with identical properties) and then install X
1938 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
1940 The whole point here is to end up with a situation where each
1941 and every ..._TYPE node the compiler creates will be uniquely
1942 associated with AT MOST one node representing a typedef name.
1943 This way, even though the compiler substitutes corresponding
1944 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
1945 early on, later parts of the compiler can always do the reverse
1946 translation and get back the corresponding typedef name. For
1949 typedef struct S MY_TYPE;
1952 Later parts of the compiler might only know that `object' was of
1953 type `struct S' if it were not for code just below. With this
1954 code however, later parts of the compiler see something like:
1956 struct S' == struct S
1957 typedef struct S' MY_TYPE;
1960 And they can then deduce (from the node for type struct S') that
1961 the original object declaration was:
1965 Being able to do this is important for proper support of protoize,
1966 and also for generating precise symbolic debugging information
1967 which takes full account of the programmer's (typedef) vocabulary.
1969 Obviously, we don't want to generate a duplicate ..._TYPE node if
1970 the TYPE_DECL node that we are now processing really represents a
1971 standard built-in type.
1973 Since all standard types are effectively declared at line zero
1974 in the source file, we can easily check to see if we are working
1975 on a standard type by checking the current value of lineno. */
1978 clone_underlying_type (tree x)
1980 if (DECL_IS_BUILTIN (x))
1982 if (TYPE_NAME (TREE_TYPE (x)) == 0)
1983 TYPE_NAME (TREE_TYPE (x)) = x;
1985 else if (TREE_TYPE (x) != error_mark_node
1986 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
1988 tree tt = TREE_TYPE (x);
1989 DECL_ORIGINAL_TYPE (x) = tt;
1990 tt = build_variant_type_copy (tt);
1992 TREE_USED (tt) = TREE_USED (x);
1997 /* Record a decl-node X as belonging to the current lexical scope.
1998 Check for errors (such as an incompatible declaration for the same
1999 name already seen in the same scope).
2001 Returns either X or an old decl for the same name.
2002 If an old decl is returned, it may have been smashed
2003 to agree with what X says. */
2008 tree name = DECL_NAME (x);
2009 struct c_scope *scope = current_scope;
2010 struct c_binding *b;
2011 bool nested = false;
2013 /* Functions need the lang_decl data. */
2014 if (TREE_CODE (x) == FUNCTION_DECL && !DECL_LANG_SPECIFIC (x))
2015 DECL_LANG_SPECIFIC (x) = GGC_CNEW (struct lang_decl);
2017 /* Must set DECL_CONTEXT for everything not at file scope or
2018 DECL_FILE_SCOPE_P won't work. Local externs don't count
2019 unless they have initializers (which generate code). */
2020 if (current_function_decl
2021 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
2022 || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
2023 DECL_CONTEXT (x) = current_function_decl;
2025 /* If this is of variably modified type, prevent jumping into its
2027 if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL)
2028 && variably_modified_type_p (TREE_TYPE (x), NULL_TREE))
2029 c_begin_vm_scope (scope->depth);
2031 /* Anonymous decls are just inserted in the scope. */
2034 bind (name, x, scope, /*invisible=*/false, /*nested=*/false);
2038 /* First, see if there is another declaration with the same name in
2039 the current scope. If there is, duplicate_decls may do all the
2040 work for us. If duplicate_decls returns false, that indicates
2041 two incompatible decls in the same scope; we are to silently
2042 replace the old one (duplicate_decls has issued all appropriate
2043 diagnostics). In particular, we should not consider possible
2044 duplicates in the external scope, or shadowing. */
2045 b = I_SYMBOL_BINDING (name);
2046 if (b && B_IN_SCOPE (b, scope))
2048 struct c_binding *b_ext, *b_use;
2049 tree type = TREE_TYPE (x);
2050 tree visdecl = b->decl;
2051 tree vistype = TREE_TYPE (visdecl);
2052 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
2053 && COMPLETE_TYPE_P (TREE_TYPE (x)))
2054 b->inner_comp = false;
2057 /* If this is an external linkage declaration, we should check
2058 for compatibility with the type in the external scope before
2059 setting the type at this scope based on the visible
2060 information only. */
2061 if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
2063 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
2064 b_ext = b_ext->shadowed;
2069 TREE_TYPE (b_use->decl) = b_use->type;
2072 if (duplicate_decls (x, b_use->decl))
2076 /* Save the updated type in the external scope and
2077 restore the proper type for this scope. */
2079 if (comptypes (vistype, type))
2080 thistype = composite_type (vistype, type);
2082 thistype = TREE_TYPE (b_use->decl);
2083 b_use->type = TREE_TYPE (b_use->decl);
2084 if (TREE_CODE (b_use->decl) == FUNCTION_DECL
2085 && DECL_BUILT_IN (b_use->decl))
2087 = build_type_attribute_variant (thistype,
2090 TREE_TYPE (b_use->decl) = thistype;
2095 goto skip_external_and_shadow_checks;
2098 /* All declarations with external linkage, and all external
2099 references, go in the external scope, no matter what scope is
2100 current. However, the binding in that scope is ignored for
2101 purposes of normal name lookup. A separate binding structure is
2102 created in the requested scope; this governs the normal
2103 visibility of the symbol.
2105 The binding in the externals scope is used exclusively for
2106 detecting duplicate declarations of the same object, no matter
2107 what scope they are in; this is what we do here. (C99 6.2.7p2:
2108 All declarations that refer to the same object or function shall
2109 have compatible type; otherwise, the behavior is undefined.) */
2110 if (DECL_EXTERNAL (x) || scope == file_scope)
2112 tree type = TREE_TYPE (x);
2115 bool type_saved = false;
2116 if (b && !B_IN_EXTERNAL_SCOPE (b)
2117 && (TREE_CODE (b->decl) == FUNCTION_DECL
2118 || TREE_CODE (b->decl) == VAR_DECL)
2119 && DECL_FILE_SCOPE_P (b->decl))
2122 vistype = TREE_TYPE (visdecl);
2124 if (scope != file_scope
2125 && !DECL_IN_SYSTEM_HEADER (x))
2126 warning (OPT_Wnested_externs, "nested extern declaration of %qD", x);
2128 while (b && !B_IN_EXTERNAL_SCOPE (b))
2130 /* If this decl might be modified, save its type. This is
2131 done here rather than when the decl is first bound
2132 because the type may change after first binding, through
2133 being completed or through attributes being added. If we
2134 encounter multiple such decls, only the first should have
2135 its type saved; the others will already have had their
2136 proper types saved and the types will not have changed as
2137 their scopes will not have been re-entered. */
2138 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
2140 b->type = TREE_TYPE (b->decl);
2143 if (B_IN_FILE_SCOPE (b)
2144 && TREE_CODE (b->decl) == VAR_DECL
2145 && TREE_STATIC (b->decl)
2146 && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
2147 && !TYPE_DOMAIN (TREE_TYPE (b->decl))
2148 && TREE_CODE (type) == ARRAY_TYPE
2149 && TYPE_DOMAIN (type)
2150 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
2151 && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
2153 /* Array type completed in inner scope, which should be
2154 diagnosed if the completion does not have size 1 and
2155 it does not get completed in the file scope. */
2156 b->inner_comp = true;
2161 /* If a matching external declaration has been found, set its
2162 type to the composite of all the types of that declaration.
2163 After the consistency checks, it will be reset to the
2164 composite of the visible types only. */
2165 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2167 TREE_TYPE (b->decl) = b->type;
2169 /* The point of the same_translation_unit_p check here is,
2170 we want to detect a duplicate decl for a construct like
2171 foo() { extern bar(); } ... static bar(); but not if
2172 they are in different translation units. In any case,
2173 the static does not go in the externals scope. */
2175 && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2176 && duplicate_decls (x, b->decl))
2181 if (comptypes (vistype, type))
2182 thistype = composite_type (vistype, type);
2184 thistype = TREE_TYPE (b->decl);
2188 b->type = TREE_TYPE (b->decl);
2189 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
2191 = build_type_attribute_variant (thistype,
2192 TYPE_ATTRIBUTES (b->type));
2193 TREE_TYPE (b->decl) = thistype;
2194 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true);
2197 else if (TREE_PUBLIC (x))
2199 if (visdecl && !b && duplicate_decls (x, visdecl))
2201 /* An external declaration at block scope referring to a
2202 visible entity with internal linkage. The composite
2203 type will already be correct for this scope, so we
2204 just need to fall through to make the declaration in
2211 bind (name, x, external_scope, /*invisible=*/true,
2218 warn_if_shadowing (x);
2220 skip_external_and_shadow_checks:
2221 if (TREE_CODE (x) == TYPE_DECL)
2222 clone_underlying_type (x);
2224 bind (name, x, scope, /*invisible=*/false, nested);
2226 /* If x's type is incomplete because it's based on a
2227 structure or union which has not yet been fully declared,
2228 attach it to that structure or union type, so we can go
2229 back and complete the variable declaration later, if the
2230 structure or union gets fully declared.
2232 If the input is erroneous, we can have error_mark in the type
2233 slot (e.g. "f(void a, ...)") - that doesn't count as an
2235 if (TREE_TYPE (x) != error_mark_node
2236 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
2238 tree element = TREE_TYPE (x);
2240 while (TREE_CODE (element) == ARRAY_TYPE)
2241 element = TREE_TYPE (element);
2242 element = TYPE_MAIN_VARIANT (element);
2244 if ((TREE_CODE (element) == RECORD_TYPE
2245 || TREE_CODE (element) == UNION_TYPE)
2246 && (TREE_CODE (x) != TYPE_DECL
2247 || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
2248 && !COMPLETE_TYPE_P (element))
2249 C_TYPE_INCOMPLETE_VARS (element)
2250 = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
2255 /* Record X as belonging to file scope.
2256 This is used only internally by the Objective-C front end,
2257 and is limited to its needs. duplicate_decls is not called;
2258 if there is any preexisting decl for this identifier, it is an ICE. */
2261 pushdecl_top_level (tree x)
2264 bool nested = false;
2265 gcc_assert (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == CONST_DECL);
2267 name = DECL_NAME (x);
2269 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
2271 if (TREE_PUBLIC (x))
2273 bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false);
2277 bind (name, x, file_scope, /*invisible=*/false, nested);
2283 implicit_decl_warning (tree id, tree olddecl)
2285 void (*diag) (const char *, ...) ATTRIBUTE_GCC_CDIAG(1,2);
2286 switch (mesg_implicit_function_declaration)
2289 case 1: diag = warning0; break;
2290 case 2: diag = error; break;
2291 default: gcc_unreachable ();
2294 diag (G_("implicit declaration of function %qE"), id);
2296 locate_old_decl (olddecl, diag);
2299 /* Generate an implicit declaration for identifier FUNCTIONID as a
2300 function of type int (). */
2303 implicitly_declare (tree functionid)
2305 struct c_binding *b;
2309 for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
2311 if (B_IN_SCOPE (b, external_scope))
2320 if (decl == error_mark_node)
2323 /* FIXME: Objective-C has weird not-really-builtin functions
2324 which are supposed to be visible automatically. They wind up
2325 in the external scope because they're pushed before the file
2326 scope gets created. Catch this here and rebind them into the
2328 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
2330 bind (functionid, decl, file_scope,
2331 /*invisible=*/false, /*nested=*/true);
2336 tree newtype = default_function_type;
2338 TREE_TYPE (decl) = b->type;
2339 /* Implicit declaration of a function already declared
2340 (somehow) in a different scope, or as a built-in.
2341 If this is the first time this has happened, warn;
2342 then recycle the old declaration but with the new type. */
2343 if (!C_DECL_IMPLICIT (decl))
2345 implicit_decl_warning (functionid, decl);
2346 C_DECL_IMPLICIT (decl) = 1;
2348 if (DECL_BUILT_IN (decl))
2350 newtype = build_type_attribute_variant (newtype,
2352 (TREE_TYPE (decl)));
2353 if (!comptypes (newtype, TREE_TYPE (decl)))
2355 warning (0, "incompatible implicit declaration of built-in"
2356 " function %qD", decl);
2357 newtype = TREE_TYPE (decl);
2362 if (!comptypes (newtype, TREE_TYPE (decl)))
2364 error ("incompatible implicit declaration of function %qD",
2366 locate_old_decl (decl, error);
2369 b->type = TREE_TYPE (decl);
2370 TREE_TYPE (decl) = newtype;
2371 bind (functionid, decl, current_scope,
2372 /*invisible=*/false, /*nested=*/true);
2377 /* Not seen before. */
2378 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2379 DECL_EXTERNAL (decl) = 1;
2380 TREE_PUBLIC (decl) = 1;
2381 C_DECL_IMPLICIT (decl) = 1;
2382 implicit_decl_warning (functionid, 0);
2383 asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
2385 set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
2387 /* C89 says implicit declarations are in the innermost block.
2388 So we record the decl in the standard fashion. */
2389 decl = pushdecl (decl);
2391 /* No need to call objc_check_decl here - it's a function type. */
2392 rest_of_decl_compilation (decl, 0, 0);
2394 /* Write a record describing this implicit function declaration
2395 to the prototypes file (if requested). */
2396 gen_aux_info_record (decl, 0, 1, 0);
2398 /* Possibly apply some default attributes to this implicit declaration. */
2399 decl_attributes (&decl, NULL_TREE, 0);
2404 /* Issue an error message for a reference to an undeclared variable
2405 ID, including a reference to a builtin outside of function-call
2406 context. Establish a binding of the identifier to error_mark_node
2407 in an appropriate scope, which will suppress further errors for the
2408 same identifier. The error message should be given location LOC. */
2410 undeclared_variable (tree id, location_t loc)
2412 static bool already = false;
2413 struct c_scope *scope;
2415 if (current_function_decl == 0)
2417 error ("%H%qE undeclared here (not in a function)", &loc, id);
2418 scope = current_scope;
2422 error ("%H%qE undeclared (first use in this function)", &loc, id);
2426 error ("%H(Each undeclared identifier is reported only once", &loc);
2427 error ("%Hfor each function it appears in.)", &loc);
2431 /* If we are parsing old-style parameter decls, current_function_decl
2432 will be nonnull but current_function_scope will be null. */
2433 scope = current_function_scope ? current_function_scope : current_scope;
2435 bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false);
2438 /* Subroutine of lookup_label, declare_label, define_label: construct a
2439 LABEL_DECL with all the proper frills. */
2442 make_label (tree name, location_t location)
2444 tree label = build_decl (LABEL_DECL, name, void_type_node);
2446 DECL_CONTEXT (label) = current_function_decl;
2447 DECL_MODE (label) = VOIDmode;
2448 DECL_SOURCE_LOCATION (label) = location;
2453 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
2454 Create one if none exists so far for the current function.
2455 This is called when a label is used in a goto expression or
2456 has its address taken. */
2459 lookup_label (tree name)
2463 if (current_function_decl == 0)
2465 error ("label %qE referenced outside of any function", name);
2469 /* Use a label already defined or ref'd with this name, but not if
2470 it is inherited from a containing function and wasn't declared
2472 label = I_LABEL_DECL (name);
2473 if (label && (DECL_CONTEXT (label) == current_function_decl
2474 || C_DECLARED_LABEL_FLAG (label)))
2476 /* If the label has only been declared, update its apparent
2477 location to point here, for better diagnostics if it
2478 turns out not to have been defined. */
2479 if (!TREE_USED (label))
2480 DECL_SOURCE_LOCATION (label) = input_location;
2484 /* No label binding for that identifier; make one. */
2485 label = make_label (name, input_location);
2487 /* Ordinary labels go in the current function scope. */
2488 bind (name, label, current_function_scope,
2489 /*invisible=*/false, /*nested=*/false);
2493 /* Make a label named NAME in the current function, shadowing silently
2494 any that may be inherited from containing functions or containing
2495 scopes. This is called for __label__ declarations. */
2498 declare_label (tree name)
2500 struct c_binding *b = I_LABEL_BINDING (name);
2503 /* Check to make sure that the label hasn't already been declared
2505 if (b && B_IN_CURRENT_SCOPE (b))
2507 error ("duplicate label declaration %qE", name);
2508 locate_old_decl (b->decl, error);
2510 /* Just use the previous declaration. */
2514 label = make_label (name, input_location);
2515 C_DECLARED_LABEL_FLAG (label) = 1;
2517 /* Declared labels go in the current scope. */
2518 bind (name, label, current_scope,
2519 /*invisible=*/false, /*nested=*/false);
2523 /* Define a label, specifying the location in the source file.
2524 Return the LABEL_DECL node for the label, if the definition is valid.
2525 Otherwise return 0. */
2528 define_label (location_t location, tree name)
2530 /* Find any preexisting label with this name. It is an error
2531 if that label has already been defined in this function, or
2532 if there is a containing function with a declared label with
2534 tree label = I_LABEL_DECL (name);
2535 struct c_label_list *nlist_se, *nlist_vm;
2538 && ((DECL_CONTEXT (label) == current_function_decl
2539 && DECL_INITIAL (label) != 0)
2540 || (DECL_CONTEXT (label) != current_function_decl
2541 && C_DECLARED_LABEL_FLAG (label))))
2543 error ("%Hduplicate label %qD", &location, label);
2544 locate_old_decl (label, error);
2547 else if (label && DECL_CONTEXT (label) == current_function_decl)
2549 /* The label has been used or declared already in this function,
2550 but not defined. Update its location to point to this
2552 if (C_DECL_UNDEFINABLE_STMT_EXPR (label))
2553 error ("%Jjump into statement expression", label);
2554 if (C_DECL_UNDEFINABLE_VM (label))
2555 error ("%Jjump into scope of identifier with variably modified type",
2557 DECL_SOURCE_LOCATION (label) = location;
2561 /* No label binding for that identifier; make one. */
2562 label = make_label (name, location);
2564 /* Ordinary labels go in the current function scope. */
2565 bind (name, label, current_function_scope,
2566 /*invisible=*/false, /*nested=*/false);
2569 if (!in_system_header && lookup_name (name))
2570 warning (OPT_Wtraditional, "%Htraditional C lacks a separate namespace "
2571 "for labels, identifier %qE conflicts", &location, name);
2573 nlist_se = XOBNEW (&parser_obstack, struct c_label_list);
2574 nlist_se->next = label_context_stack_se->labels_def;
2575 nlist_se->label = label;
2576 label_context_stack_se->labels_def = nlist_se;
2578 nlist_vm = XOBNEW (&parser_obstack, struct c_label_list);
2579 nlist_vm->next = label_context_stack_vm->labels_def;
2580 nlist_vm->label = label;
2581 label_context_stack_vm->labels_def = nlist_vm;
2583 /* Mark label as having been defined. */
2584 DECL_INITIAL (label) = error_mark_node;
2588 /* Given NAME, an IDENTIFIER_NODE,
2589 return the structure (or union or enum) definition for that name.
2590 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2591 CODE says which kind of type the caller wants;
2592 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2593 If the wrong kind of type is found, an error is reported. */
2596 lookup_tag (enum tree_code code, tree name, int thislevel_only)
2598 struct c_binding *b = I_TAG_BINDING (name);
2604 /* We only care about whether it's in this level if
2605 thislevel_only was set or it might be a type clash. */
2606 if (thislevel_only || TREE_CODE (b->decl) != code)
2608 /* For our purposes, a tag in the external scope is the same as
2609 a tag in the file scope. (Primarily relevant to Objective-C
2610 and its builtin structure tags, which get pushed before the
2611 file scope is created.) */
2612 if (B_IN_CURRENT_SCOPE (b)
2613 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
2617 if (thislevel_only && !thislevel)
2620 if (TREE_CODE (b->decl) != code)
2622 /* Definition isn't the kind we were looking for. */
2623 pending_invalid_xref = name;
2624 pending_invalid_xref_location = input_location;
2626 /* If in the same binding level as a declaration as a tag
2627 of a different type, this must not be allowed to
2628 shadow that tag, so give the error immediately.
2629 (For example, "struct foo; union foo;" is invalid.) */
2631 pending_xref_error ();
2636 /* Print an error message now
2637 for a recent invalid struct, union or enum cross reference.
2638 We don't print them immediately because they are not invalid
2639 when used in the `struct foo;' construct for shadowing. */
2642 pending_xref_error (void)
2644 if (pending_invalid_xref != 0)
2645 error ("%H%qE defined as wrong kind of tag",
2646 &pending_invalid_xref_location, pending_invalid_xref);
2647 pending_invalid_xref = 0;
2651 /* Look up NAME in the current scope and its superiors
2652 in the namespace of variables, functions and typedefs.
2653 Return a ..._DECL node of some kind representing its definition,
2654 or return 0 if it is undefined. */
2657 lookup_name (tree name)
2659 struct c_binding *b = I_SYMBOL_BINDING (name);
2660 if (b && !b->invisible)
2665 /* Similar to `lookup_name' but look only at the indicated scope. */
2668 lookup_name_in_scope (tree name, struct c_scope *scope)
2670 struct c_binding *b;
2672 for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
2673 if (B_IN_SCOPE (b, scope))
2678 /* Create the predefined scalar types of C,
2679 and some nodes representing standard constants (0, 1, (void *) 0).
2680 Initialize the global scope.
2681 Make definitions for built-in primitive functions. */
2684 c_init_decl_processing (void)
2686 location_t save_loc = input_location;
2688 /* Initialize reserved words for parser. */
2691 current_function_decl = 0;
2693 gcc_obstack_init (&parser_obstack);
2695 /* Make the externals scope. */
2697 external_scope = current_scope;
2699 /* Declarations from c_common_nodes_and_builtins must not be associated
2700 with this input file, lest we get differences between using and not
2701 using preprocessed headers. */
2702 #ifdef USE_MAPPED_LOCATION
2703 input_location = BUILTINS_LOCATION;
2705 input_location.file = "<built-in>";
2706 input_location.line = 0;
2709 build_common_tree_nodes (flag_signed_char, false);
2711 c_common_nodes_and_builtins ();
2713 /* In C, comparisons and TRUTH_* expressions have type int. */
2714 truthvalue_type_node = integer_type_node;
2715 truthvalue_true_node = integer_one_node;
2716 truthvalue_false_node = integer_zero_node;
2718 /* Even in C99, which has a real boolean type. */
2719 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
2720 boolean_type_node));
2722 input_location = save_loc;
2724 pedantic_lvalues = true;
2726 make_fname_decl = c_make_fname_decl;
2727 start_fname_decls ();
2730 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2731 decl, NAME is the initialization string and TYPE_DEP indicates whether
2732 NAME depended on the type of the function. As we don't yet implement
2733 delayed emission of static data, we mark the decl as emitted
2734 so it is not placed in the output. Anything using it must therefore pull
2735 out the STRING_CST initializer directly. FIXME. */
2738 c_make_fname_decl (tree id, int type_dep)
2740 const char *name = fname_as_string (type_dep);
2741 tree decl, type, init;
2742 size_t length = strlen (name);
2744 type = build_array_type (char_type_node,
2745 build_index_type (size_int (length)));
2746 type = c_build_qualified_type (type, TYPE_QUAL_CONST);
2748 decl = build_decl (VAR_DECL, id, type);
2750 TREE_STATIC (decl) = 1;
2751 TREE_READONLY (decl) = 1;
2752 DECL_ARTIFICIAL (decl) = 1;
2754 init = build_string (length + 1, name);
2755 free ((char *) name);
2756 TREE_TYPE (init) = type;
2757 DECL_INITIAL (decl) = init;
2759 TREE_USED (decl) = 1;
2761 if (current_function_decl)
2763 DECL_CONTEXT (decl) = current_function_decl;
2764 bind (id, decl, current_function_scope,
2765 /*invisible=*/false, /*nested=*/false);
2768 finish_decl (decl, init, NULL_TREE);
2773 /* Return a definition for a builtin function named NAME and whose data type
2774 is TYPE. TYPE should be a function type with argument types.
2775 FUNCTION_CODE tells later passes how to compile calls to this function.
2776 See tree.h for its possible values.
2778 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
2779 the name to be called if we can't opencode the function. If
2780 ATTRS is nonzero, use that for the function's attribute list. */
2783 builtin_function (const char *name, tree type, int function_code,
2784 enum built_in_class cl, const char *library_name,
2787 tree id = get_identifier (name);
2788 tree decl = build_decl (FUNCTION_DECL, id, type);
2789 TREE_PUBLIC (decl) = 1;
2790 DECL_EXTERNAL (decl) = 1;
2791 DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
2792 DECL_BUILT_IN_CLASS (decl) = cl;
2793 DECL_FUNCTION_CODE (decl) = function_code;
2794 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
2796 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
2798 /* Should never be called on a symbol with a preexisting meaning. */
2799 gcc_assert (!I_SYMBOL_BINDING (id));
2801 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false);
2803 /* Builtins in the implementation namespace are made visible without
2804 needing to be explicitly declared. See push_file_scope. */
2805 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
2807 TREE_CHAIN (decl) = visible_builtins;
2808 visible_builtins = decl;
2811 /* Possibly apply some default attributes to this built-in function. */
2813 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
2815 decl_attributes (&decl, NULL_TREE, 0);
2820 /* Called when a declaration is seen that contains no names to declare.
2821 If its type is a reference to a structure, union or enum inherited
2822 from a containing scope, shadow that tag name for the current scope
2823 with a forward reference.
2824 If its type defines a new named structure or union
2825 or defines an enum, it is valid but we need not do anything here.
2826 Otherwise, it is an error. */
2829 shadow_tag (const struct c_declspecs *declspecs)
2831 shadow_tag_warned (declspecs, 0);
2834 /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
2837 shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
2839 bool found_tag = false;
2841 if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
2843 tree value = declspecs->type;
2844 enum tree_code code = TREE_CODE (value);
2846 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
2847 /* Used to test also that TYPE_SIZE (value) != 0.
2848 That caused warning for `struct foo;' at top level in the file. */
2850 tree name = TYPE_NAME (value);
2857 if (warned != 1 && code != ENUMERAL_TYPE)
2858 /* Empty unnamed enum OK */
2860 pedwarn ("unnamed struct/union that defines no instances");
2864 else if (!declspecs->tag_defined_p
2865 && declspecs->storage_class != csc_none)
2868 pedwarn ("empty declaration with storage class specifier "
2869 "does not redeclare tag");
2871 pending_xref_error ();
2873 else if (!declspecs->tag_defined_p
2874 && (declspecs->const_p
2875 || declspecs->volatile_p
2876 || declspecs->restrict_p))
2879 pedwarn ("empty declaration with type qualifier "
2880 "does not redeclare tag");
2882 pending_xref_error ();
2886 pending_invalid_xref = 0;
2887 t = lookup_tag (code, name, 1);
2891 t = make_node (code);
2898 if (warned != 1 && !in_system_header)
2900 pedwarn ("useless type name in empty declaration");
2905 else if (warned != 1 && !in_system_header && declspecs->typedef_p)
2907 pedwarn ("useless type name in empty declaration");
2911 pending_invalid_xref = 0;
2913 if (declspecs->inline_p)
2915 error ("%<inline%> in empty declaration");
2919 if (current_scope == file_scope && declspecs->storage_class == csc_auto)
2921 error ("%<auto%> in file-scope empty declaration");
2925 if (current_scope == file_scope && declspecs->storage_class == csc_register)
2927 error ("%<register%> in file-scope empty declaration");
2931 if (!warned && !in_system_header && declspecs->storage_class != csc_none)
2933 warning (0, "useless storage class specifier in empty declaration");
2937 if (!warned && !in_system_header && declspecs->thread_p)
2939 warning (0, "useless %<__thread%> in empty declaration");
2943 if (!warned && !in_system_header && (declspecs->const_p
2944 || declspecs->volatile_p
2945 || declspecs->restrict_p))
2947 warning (0, "useless type qualifier in empty declaration");
2954 pedwarn ("empty declaration");
2959 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
2960 bits. SPECS represents declaration specifiers that the grammar
2961 only permits to contain type qualifiers and attributes. */
2964 quals_from_declspecs (const struct c_declspecs *specs)
2966 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
2967 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
2968 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0));
2969 gcc_assert (!specs->type
2970 && !specs->decl_attr
2971 && specs->typespec_word == cts_none
2972 && specs->storage_class == csc_none
2973 && !specs->typedef_p
2974 && !specs->explicit_signed_p
2975 && !specs->deprecated_p
2977 && !specs->long_long_p
2980 && !specs->unsigned_p
2981 && !specs->complex_p
2983 && !specs->thread_p);
2987 /* Construct an array declarator. EXPR is the expression inside [], or
2988 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
2989 to the pointer to which a parameter array is converted). STATIC_P is
2990 true if "static" is inside the [], false otherwise. VLA_UNSPEC_P
2991 is true if the array is [*], a VLA of unspecified length which is
2992 nevertheless a complete type (not currently implemented by GCC),
2993 false otherwise. The field for the contained declarator is left to be
2994 filled in by set_array_declarator_inner. */
2996 struct c_declarator *
2997 build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p,
3000 struct c_declarator *declarator = XOBNEW (&parser_obstack,
3001 struct c_declarator);
3002 declarator->kind = cdk_array;
3003 declarator->declarator = 0;
3004 declarator->u.array.dimen = expr;
3007 declarator->u.array.attrs = quals->attrs;
3008 declarator->u.array.quals = quals_from_declspecs (quals);
3012 declarator->u.array.attrs = NULL_TREE;
3013 declarator->u.array.quals = 0;
3015 declarator->u.array.static_p = static_p;
3016 declarator->u.array.vla_unspec_p = vla_unspec_p;
3017 if (pedantic && !flag_isoc99)
3019 if (static_p || quals != NULL)
3020 pedwarn ("ISO C90 does not support %<static%> or type "
3021 "qualifiers in parameter array declarators");
3023 pedwarn ("ISO C90 does not support %<[*]%> array declarators");
3026 warning (0, "GCC does not yet properly implement %<[*]%> array declarators");
3030 /* Set the contained declarator of an array declarator. DECL is the
3031 declarator, as constructed by build_array_declarator; INNER is what
3032 appears on the left of the []. ABSTRACT_P is true if it is an
3033 abstract declarator, false otherwise; this is used to reject static
3034 and type qualifiers in abstract declarators, where they are not in
3035 the C99 grammar (subject to possible change in DR#289). */
3037 struct c_declarator *
3038 set_array_declarator_inner (struct c_declarator *decl,
3039 struct c_declarator *inner, bool abstract_p)
3041 decl->declarator = inner;
3042 if (abstract_p && (decl->u.array.quals != TYPE_UNQUALIFIED
3043 || decl->u.array.attrs != NULL_TREE
3044 || decl->u.array.static_p))
3045 error ("static or type qualifiers in abstract declarator");
3049 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
3052 groktypename (struct c_type_name *type_name)
3055 tree attrs = type_name->specs->attrs;
3057 type_name->specs->attrs = NULL_TREE;
3059 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
3062 /* Apply attributes. */
3063 decl_attributes (&type, attrs, 0);
3068 /* Decode a declarator in an ordinary declaration or data definition.
3069 This is called as soon as the type information and variable name
3070 have been parsed, before parsing the initializer if any.
3071 Here we create the ..._DECL node, fill in its type,
3072 and put it on the list of decls for the current context.
3073 The ..._DECL node is returned as the value.
3075 Exception: for arrays where the length is not specified,
3076 the type is left null, to be filled in by `finish_decl'.
3078 Function definitions do not come here; they go to start_function
3079 instead. However, external and forward declarations of functions
3080 do go through here. Structure field declarations are done by
3081 grokfield and not through here. */
3084 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
3085 bool initialized, tree attributes)
3090 /* An object declared as __attribute__((deprecated)) suppresses
3091 warnings of uses of other deprecated items. */
3092 if (lookup_attribute ("deprecated", attributes))
3093 deprecated_state = DEPRECATED_SUPPRESS;
3095 decl = grokdeclarator (declarator, declspecs,
3096 NORMAL, initialized, NULL);
3100 deprecated_state = DEPRECATED_NORMAL;
3102 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
3103 && MAIN_NAME_P (DECL_NAME (decl)))
3104 warning (OPT_Wmain, "%J%qD is usually a function", decl, decl);
3107 /* Is it valid for this decl to have an initializer at all?
3108 If not, set INITIALIZED to zero, which will indirectly
3109 tell 'finish_decl' to ignore the initializer once it is parsed. */
3110 switch (TREE_CODE (decl))
3113 error ("typedef %qD is initialized (use __typeof__ instead)", decl);
3118 error ("function %qD is initialized like a variable", decl);
3123 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3124 error ("parameter %qD is initialized", decl);
3129 /* Don't allow initializations for incomplete types except for
3130 arrays which might be completed by the initialization. */
3132 /* This can happen if the array size is an undefined macro.
3133 We already gave a warning, so we don't need another one. */
3134 if (TREE_TYPE (decl) == error_mark_node)
3136 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
3138 /* A complete type is ok if size is fixed. */
3140 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3141 || C_DECL_VARIABLE_SIZE (decl))
3143 error ("variable-sized object may not be initialized");
3147 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3149 error ("variable %qD has initializer but incomplete type", decl);
3152 else if (C_DECL_VARIABLE_SIZE (decl))
3154 /* Although C99 is unclear about whether incomplete arrays
3155 of VLAs themselves count as VLAs, it does not make
3156 sense to permit them to be initialized given that
3157 ordinary VLAs may not be initialized. */
3158 error ("variable-sized object may not be initialized");
3165 if (current_scope == file_scope)
3166 TREE_STATIC (decl) = 1;
3168 /* Tell 'pushdecl' this is an initialized decl
3169 even though we don't yet have the initializer expression.
3170 Also tell 'finish_decl' it may store the real initializer. */
3171 DECL_INITIAL (decl) = error_mark_node;
3174 /* If this is a function declaration, write a record describing it to the
3175 prototypes file (if requested). */
3177 if (TREE_CODE (decl) == FUNCTION_DECL)
3178 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
3180 /* ANSI specifies that a tentative definition which is not merged with
3181 a non-tentative definition behaves exactly like a definition with an
3182 initializer equal to zero. (Section 3.7.2)
3184 -fno-common gives strict ANSI behavior, though this tends to break
3185 a large body of code that grew up without this rule.
3187 Thread-local variables are never common, since there's no entrenched
3188 body of code to break, and it allows more efficient variable references
3189 in the presence of dynamic linking. */
3191 if (TREE_CODE (decl) == VAR_DECL
3193 && TREE_PUBLIC (decl)
3194 && !DECL_THREAD_LOCAL (decl)
3196 DECL_COMMON (decl) = 1;
3198 /* Set attributes here so if duplicate decl, will have proper attributes. */
3199 decl_attributes (&decl, attributes, 0);
3201 if (TREE_CODE (decl) == FUNCTION_DECL
3202 && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
3204 struct c_declarator *ce = declarator;
3206 if (ce->kind == cdk_pointer)
3207 ce = declarator->declarator;
3208 if (ce->kind == cdk_function)
3210 tree args = ce->u.arg_info->parms;
3211 for (; args; args = TREE_CHAIN (args))
3213 tree type = TREE_TYPE (args);
3214 if (type && INTEGRAL_TYPE_P (type)
3215 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
3216 DECL_ARG_TYPE (args) = integer_type_node;
3221 if (TREE_CODE (decl) == FUNCTION_DECL
3222 && DECL_DECLARED_INLINE_P (decl)
3223 && DECL_UNINLINABLE (decl)
3224 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
3225 warning (OPT_Wattributes, "%Jinline function %qD given attribute noinline",
3228 /* Add this decl to the current scope.
3229 TEM may equal DECL or it may be a previous decl of the same name. */
3230 tem = pushdecl (decl);
3232 if (initialized && DECL_EXTERNAL (tem))
3234 DECL_EXTERNAL (tem) = 0;
3235 TREE_STATIC (tem) = 1;
3241 /* Finish processing of a declaration;
3242 install its initial value.
3243 If the length of an array type is not known before,
3244 it must be determined now, from the initial value, or it is an error. */
3247 finish_decl (tree decl, tree init, tree asmspec_tree)
3249 tree type = TREE_TYPE (decl);
3250 int was_incomplete = (DECL_SIZE (decl) == 0);
3251 const char *asmspec = 0;
3253 /* If a name was specified, get the string. */
3254 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
3255 && DECL_FILE_SCOPE_P (decl))
3256 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
3258 asmspec = TREE_STRING_POINTER (asmspec_tree);
3260 /* If `start_decl' didn't like having an initialization, ignore it now. */
3261 if (init != 0 && DECL_INITIAL (decl) == 0)
3264 /* Don't crash if parm is initialized. */
3265 if (TREE_CODE (decl) == PARM_DECL)
3269 store_init_value (decl, init);
3271 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
3272 || TREE_CODE (decl) == FUNCTION_DECL
3273 || TREE_CODE (decl) == FIELD_DECL))
3274 objc_check_decl (decl);
3276 /* Deduce size of array from initialization, if not already known. */
3277 if (TREE_CODE (type) == ARRAY_TYPE
3278 && TYPE_DOMAIN (type) == 0
3279 && TREE_CODE (decl) != TYPE_DECL)
3282 = (TREE_STATIC (decl)
3283 /* Even if pedantic, an external linkage array
3284 may have incomplete type at first. */
3285 ? pedantic && !TREE_PUBLIC (decl)
3286 : !DECL_EXTERNAL (decl));
3288 = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
3291 /* Get the completed type made by complete_array_type. */
3292 type = TREE_TYPE (decl);
3297 error ("%Jinitializer fails to determine size of %qD", decl, decl);
3302 error ("%Jarray size missing in %qD", decl, decl);
3303 /* If a `static' var's size isn't known,
3304 make it extern as well as static, so it does not get
3306 If it is not `static', then do not mark extern;
3307 finish_incomplete_decl will give it a default size
3308 and it will get allocated. */
3309 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
3310 DECL_EXTERNAL (decl) = 1;
3314 error ("%Jzero or negative size array %qD", decl, decl);
3318 /* For global variables, update the copy of the type that
3319 exists in the binding. */
3320 if (TREE_PUBLIC (decl))
3322 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
3323 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
3324 b_ext = b_ext->shadowed;
3328 b_ext->type = composite_type (b_ext->type, type);
3339 if (DECL_INITIAL (decl))
3340 TREE_TYPE (DECL_INITIAL (decl)) = type;
3342 layout_decl (decl, 0);
3345 if (TREE_CODE (decl) == VAR_DECL)
3347 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
3348 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
3349 layout_decl (decl, 0);
3351 if (DECL_SIZE (decl) == 0
3352 /* Don't give an error if we already gave one earlier. */
3353 && TREE_TYPE (decl) != error_mark_node
3354 && (TREE_STATIC (decl)
3355 /* A static variable with an incomplete type
3356 is an error if it is initialized.
3357 Also if it is not file scope.
3358 Otherwise, let it through, but if it is not `extern'
3359 then it may cause an error message later. */
3360 ? (DECL_INITIAL (decl) != 0
3361 || !DECL_FILE_SCOPE_P (decl))
3362 /* An automatic variable with an incomplete type
3364 : !DECL_EXTERNAL (decl)))
3366 error ("%Jstorage size of %qD isn%'t known", decl, decl);
3367 TREE_TYPE (decl) = error_mark_node;
3370 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
3371 && DECL_SIZE (decl) != 0)
3373 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3374 constant_expression_warning (DECL_SIZE (decl));
3376 error ("%Jstorage size of %qD isn%'t constant", decl, decl);
3379 if (TREE_USED (type))
3380 TREE_USED (decl) = 1;
3383 /* If this is a function and an assembler name is specified, reset DECL_RTL
3384 so we can give it its new name. Also, update built_in_decls if it
3385 was a normal built-in. */
3386 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
3388 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
3389 set_builtin_user_assembler_name (decl, asmspec);
3390 set_user_assembler_name (decl, asmspec);
3393 /* If #pragma weak was used, mark the decl weak now. */
3394 maybe_apply_pragma_weak (decl);
3396 /* If this is a variable definition, determine its ELF visibility. */
3397 if (TREE_CODE (decl) == VAR_DECL
3398 && TREE_STATIC (decl)
3399 && !DECL_EXTERNAL (decl))
3400 c_determine_visibility (decl);
3402 /* Output the assembler code and/or RTL code for variables and functions,
3403 unless the type is an undefined structure or union.
3404 If not, it will get done when the type is completed. */
3406 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3408 /* This is a no-op in c-lang.c or something real in objc-act.c. */
3409 if (c_dialect_objc ())
3410 objc_check_decl (decl);
3414 /* If this is not a static variable, issue a warning.
3415 It doesn't make any sense to give an ASMSPEC for an
3416 ordinary, non-register local variable. Historically,
3417 GCC has accepted -- but ignored -- the ASMSPEC in
3419 if (!DECL_FILE_SCOPE_P (decl)
3420 && TREE_CODE (decl) == VAR_DECL
3421 && !C_DECL_REGISTER (decl)
3422 && !TREE_STATIC (decl))
3423 warning (0, "%Jignoring asm-specifier for non-static local "
3424 "variable %qD", decl, decl);
3425 else if (C_DECL_REGISTER (decl))
3426 change_decl_assembler_name (decl, get_identifier (asmspec));
3428 set_user_assembler_name (decl, asmspec);
3431 if (DECL_FILE_SCOPE_P (decl))
3433 if (DECL_INITIAL (decl) == NULL_TREE
3434 || DECL_INITIAL (decl) == error_mark_node)
3435 /* Don't output anything
3436 when a tentative file-scope definition is seen.
3437 But at end of compilation, do output code for them. */
3438 DECL_DEFER_OUTPUT (decl) = 1;
3439 rest_of_decl_compilation (decl, true, 0);
3443 /* In conjunction with an ASMSPEC, the `register'
3444 keyword indicates that we should place the variable
3445 in a particular register. */
3446 if (asmspec && C_DECL_REGISTER (decl))
3448 DECL_HARD_REGISTER (decl) = 1;
3449 /* This cannot be done for a structure with volatile
3450 fields, on which DECL_REGISTER will have been
3452 if (!DECL_REGISTER (decl))
3453 error ("cannot put object with volatile field into register");
3456 if (TREE_CODE (decl) != FUNCTION_DECL)
3458 /* If we're building a variable sized type, and we might be
3459 reachable other than via the top of the current binding
3460 level, then create a new BIND_EXPR so that we deallocate
3461 the object at the right time. */
3462 /* Note that DECL_SIZE can be null due to errors. */
3463 if (DECL_SIZE (decl)
3464 && !TREE_CONSTANT (DECL_SIZE (decl))
3465 && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
3468 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
3469 TREE_SIDE_EFFECTS (bind) = 1;
3471 BIND_EXPR_BODY (bind) = push_stmt_list ();
3473 add_stmt (build_stmt (DECL_EXPR, decl));
3478 if (!DECL_FILE_SCOPE_P (decl))
3480 /* Recompute the RTL of a local array now
3481 if it used to be an incomplete type. */
3483 && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
3485 /* If we used it already as memory, it must stay in memory. */
3486 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
3487 /* If it's still incomplete now, no init will save it. */
3488 if (DECL_SIZE (decl) == 0)
3489 DECL_INITIAL (decl) = 0;
3494 /* If this was marked 'used', be sure it will be output. */
3495 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
3496 mark_decl_referenced (decl);
3498 if (TREE_CODE (decl) == TYPE_DECL)
3500 if (!DECL_FILE_SCOPE_P (decl)
3501 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
3502 add_stmt (build_stmt (DECL_EXPR, decl));
3504 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
3507 /* At the end of a declaration, throw away any variable type sizes
3508 of types defined inside that declaration. There is no use
3509 computing them in the following function definition. */
3510 if (current_scope == file_scope)
3511 get_pending_sizes ();
3513 /* Install a cleanup (aka destructor) if one was given. */
3514 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
3516 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
3519 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
3520 tree cleanup_decl = lookup_name (cleanup_id);
3523 /* Build "cleanup(&decl)" for the destructor. */
3524 cleanup = build_unary_op (ADDR_EXPR, decl, 0);
3525 cleanup = build_tree_list (NULL_TREE, cleanup);
3526 cleanup = build_function_call (cleanup_decl, cleanup);
3528 /* Don't warn about decl unused; the cleanup uses it. */
3529 TREE_USED (decl) = 1;
3530 TREE_USED (cleanup_decl) = 1;
3532 /* Initialize EH, if we've been told to do so. */
3533 if (flag_exceptions && !c_eh_initialized_p)
3535 c_eh_initialized_p = true;
3536 eh_personality_libfunc
3537 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
3538 ? "__gcc_personality_sj0"
3539 : "__gcc_personality_v0");
3540 using_eh_for_cleanups ();
3543 push_cleanup (decl, cleanup, false);
3548 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */
3551 grokparm (const struct c_parm *parm)
3553 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
3556 decl_attributes (&decl, parm->attrs, 0);
3561 /* Given a parsed parameter declaration, decode it into a PARM_DECL
3562 and push that on the current scope. */
3565 push_parm_decl (const struct c_parm *parm)
3569 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL);
3570 decl_attributes (&decl, parm->attrs, 0);
3572 decl = pushdecl (decl);
3574 finish_decl (decl, NULL_TREE, NULL_TREE);
3577 /* Mark all the parameter declarations to date as forward decls.
3578 Also diagnose use of this extension. */
3581 mark_forward_parm_decls (void)
3583 struct c_binding *b;
3585 if (pedantic && !current_scope->warned_forward_parm_decls)
3587 pedwarn ("ISO C forbids forward parameter declarations");
3588 current_scope->warned_forward_parm_decls = true;
3591 for (b = current_scope->bindings; b; b = b->prev)
3592 if (TREE_CODE (b->decl) == PARM_DECL)
3593 TREE_ASM_WRITTEN (b->decl) = 1;
3596 static GTY(()) int compound_literal_number;
3598 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3599 literal, which may be an incomplete array type completed by the
3600 initializer; INIT is a CONSTRUCTOR that initializes the compound
3604 build_compound_literal (tree type, tree init)
3606 /* We do not use start_decl here because we have a type, not a declarator;
3607 and do not use finish_decl because the decl should be stored inside
3608 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
3613 if (type == error_mark_node)
3614 return error_mark_node;
3616 decl = build_decl (VAR_DECL, NULL_TREE, type);
3617 DECL_EXTERNAL (decl) = 0;
3618 TREE_PUBLIC (decl) = 0;
3619 TREE_STATIC (decl) = (current_scope == file_scope);
3620 DECL_CONTEXT (decl) = current_function_decl;
3621 TREE_USED (decl) = 1;
3622 TREE_TYPE (decl) = type;
3623 TREE_READONLY (decl) = TYPE_READONLY (type);
3624 store_init_value (decl, init);
3626 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
3628 int failure = complete_array_type (&TREE_TYPE (decl),
3629 DECL_INITIAL (decl), true);
3630 gcc_assert (!failure);
3632 type = TREE_TYPE (decl);
3633 TREE_TYPE (DECL_INITIAL (decl)) = type;
3636 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
3637 return error_mark_node;
3639 stmt = build_stmt (DECL_EXPR, decl);
3640 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
3641 TREE_SIDE_EFFECTS (complit) = 1;
3643 layout_decl (decl, 0);
3645 if (TREE_STATIC (decl))
3647 /* This decl needs a name for the assembler output. We also need
3648 a unique suffix to be added to the name. */
3651 ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
3652 compound_literal_number);
3653 compound_literal_number++;
3654 DECL_NAME (decl) = get_identifier (name);
3655 DECL_DEFER_OUTPUT (decl) = 1;
3656 DECL_COMDAT (decl) = 1;
3657 DECL_ARTIFICIAL (decl) = 1;
3658 DECL_IGNORED_P (decl) = 1;
3660 rest_of_decl_compilation (decl, 1, 0);
3666 /* Determine whether TYPE is a structure with a flexible array member,
3667 or a union containing such a structure (possibly recursively). */
3670 flexible_array_type_p (tree type)
3673 switch (TREE_CODE (type))
3676 x = TYPE_FIELDS (type);
3679 while (TREE_CHAIN (x) != NULL_TREE)
3681 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
3682 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3683 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
3684 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
3688 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
3690 if (flexible_array_type_p (TREE_TYPE (x)))
3699 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3700 replacing with appropriate values if they are invalid. */
3702 check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
3705 unsigned int max_width;
3706 unsigned HOST_WIDE_INT w;
3707 const char *name = orig_name ? orig_name: _("<anonymous>");
3709 /* Detect and ignore out of range field width and process valid
3711 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))
3712 || TREE_CODE (*width) != INTEGER_CST)
3714 error ("bit-field %qs width not an integer constant", name);
3715 *width = integer_one_node;
3719 constant_expression_warning (*width);
3720 if (tree_int_cst_sgn (*width) < 0)
3722 error ("negative width in bit-field %qs", name);
3723 *width = integer_one_node;
3725 else if (integer_zerop (*width) && orig_name)
3727 error ("zero width for bit-field %qs", name);
3728 *width = integer_one_node;
3732 /* Detect invalid bit-field type. */
3733 if (TREE_CODE (*type) != INTEGER_TYPE
3734 && TREE_CODE (*type) != BOOLEAN_TYPE
3735 && TREE_CODE (*type) != ENUMERAL_TYPE)
3737 error ("bit-field %qs has invalid type", name);
3738 *type = unsigned_type_node;
3741 type_mv = TYPE_MAIN_VARIANT (*type);
3743 && type_mv != integer_type_node
3744 && type_mv != unsigned_type_node
3745 && type_mv != boolean_type_node)
3746 pedwarn ("type of bit-field %qs is a GCC extension", name);
3748 if (type_mv == boolean_type_node)
3749 max_width = CHAR_TYPE_SIZE;
3751 max_width = TYPE_PRECISION (*type);
3753 if (0 < compare_tree_int (*width, max_width))
3755 error ("width of %qs exceeds its type", name);
3757 *width = build_int_cst (NULL_TREE, w);
3760 w = tree_low_cst (*width, 1);
3762 if (TREE_CODE (*type) == ENUMERAL_TYPE)
3764 struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
3766 || w < min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
3767 || w < min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
3768 warning (0, "%qs is narrower than values of its type", name);
3772 /* Given declspecs and a declarator,
3773 determine the name and type of the object declared
3774 and construct a ..._DECL node for it.
3775 (In one case we can return a ..._TYPE node instead.
3776 For invalid input we sometimes return 0.)
3778 DECLSPECS is a c_declspecs structure for the declaration specifiers.
3780 DECL_CONTEXT says which syntactic context this declaration is in:
3781 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3782 FUNCDEF for a function definition. Like NORMAL but a few different
3783 error messages in each case. Return value may be zero meaning
3784 this definition is too screwy to try to parse.
3785 PARM for a parameter declaration (either within a function prototype
3786 or before a function body). Make a PARM_DECL, or return void_type_node.
3787 TYPENAME if for a typename (in a cast or sizeof).
3788 Don't make a DECL node; just return the ..._TYPE node.
3789 FIELD for a struct or union field; make a FIELD_DECL.
3790 INITIALIZED is true if the decl has an initializer.
3791 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
3792 representing the width of the bit-field.
3794 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3795 It may also be so in the PARM case, for a prototype where the
3796 argument type is specified but not the name.
3798 This function is where the complicated C meanings of `static'
3799 and `extern' are interpreted. */
3802 grokdeclarator (const struct c_declarator *declarator,
3803 struct c_declspecs *declspecs,
3804 enum decl_context decl_context, bool initialized, tree *width)
3806 tree type = declspecs->type;
3807 bool threadp = declspecs->thread_p;
3808 enum c_storage_class storage_class = declspecs->storage_class;
3812 int type_quals = TYPE_UNQUALIFIED;
3813 const char *name, *orig_name;
3814 tree typedef_type = 0;
3815 int funcdef_flag = 0;
3816 bool funcdef_syntax = false;
3817 int size_varies = 0;
3818 tree decl_attr = declspecs->decl_attr;
3819 int array_ptr_quals = TYPE_UNQUALIFIED;
3820 tree array_ptr_attrs = NULL_TREE;
3821 int array_parm_static = 0;
3822 tree returned_attrs = NULL_TREE;
3823 bool bitfield = width != NULL;
3825 struct c_arg_info *arg_info = 0;
3827 if (decl_context == FUNCDEF)
3828 funcdef_flag = 1, decl_context = NORMAL;
3830 /* Look inside a declarator for the name being declared
3831 and get it as a string, for an error message. */
3833 const struct c_declarator *decl = declarator;
3842 funcdef_syntax = (decl->kind == cdk_function);
3843 decl = decl->declarator;
3847 decl = decl->declarator;
3852 name = IDENTIFIER_POINTER (decl->u.id);
3864 /* A function definition's declarator must have the form of
3865 a function declarator. */
3867 if (funcdef_flag && !funcdef_syntax)
3870 /* If this looks like a function definition, make it one,
3871 even if it occurs where parms are expected.
3872 Then store_parm_decls will reject it and not use it as a parm. */
3873 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
3874 decl_context = PARM;
3876 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
3877 warn_deprecated_use (declspecs->type);
3879 typedef_type = type;
3880 size_varies = C_TYPE_VARIABLE_SIZE (type);
3882 /* Diagnose defaulting to "int". */
3884 if (declspecs->default_int_p && !in_system_header)
3886 /* Issue a warning if this is an ISO C 99 program or if
3887 -Wreturn-type and this is a function, or if -Wimplicit;
3888 prefer the former warning since it is more explicit. */
3889 if ((warn_implicit_int || warn_return_type || flag_isoc99)
3891 warn_about_return_type = 1;
3892 else if (warn_implicit_int || flag_isoc99)
3893 pedwarn_c99 ("type defaults to %<int%> in declaration of %qs", name);
3896 /* Adjust the type if a bit-field is being declared,
3897 -funsigned-bitfields applied and the type is not explicitly
3899 if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
3900 && TREE_CODE (type) == INTEGER_TYPE)
3901 type = c_common_unsigned_type (type);
3903 /* Figure out the type qualifiers for the declaration. There are
3904 two ways a declaration can become qualified. One is something
3905 like `const int i' where the `const' is explicit. Another is
3906 something like `typedef const int CI; CI i' where the type of the
3907 declaration contains the `const'. A third possibility is that
3908 there is a type qualifier on the element type of a typedefed
3909 array type, in which case we should extract that qualifier so
3910 that c_apply_type_quals_to_decls receives the full list of
3911 qualifiers to work with (C90 is not entirely clear about whether
3912 duplicate qualifiers should be diagnosed in this case, but it
3913 seems most appropriate to do so). */
3914 element_type = strip_array_types (type);
3915 constp = declspecs->const_p + TYPE_READONLY (element_type);
3916 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
3917 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
3918 if (pedantic && !flag_isoc99)
3921 pedwarn ("duplicate %<const%>");
3923 pedwarn ("duplicate %<restrict%>");
3925 pedwarn ("duplicate %<volatile%>");
3927 if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
3928 type = TYPE_MAIN_VARIANT (type);
3929 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
3930 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
3931 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
3933 /* Warn about storage classes that are invalid for certain
3934 kinds of declarations (parameters, typenames, etc.). */
3938 || storage_class == csc_auto
3939 || storage_class == csc_register
3940 || storage_class == csc_typedef))
3942 if (storage_class == csc_auto
3943 && (pedantic || current_scope == file_scope))
3944 pedwarn ("function definition declared %<auto%>");
3945 if (storage_class == csc_register)
3946 error ("function definition declared %<register%>");
3947 if (storage_class == csc_typedef)
3948 error ("function definition declared %<typedef%>");
3950 error ("function definition declared %<__thread%>");
3952 if (storage_class == csc_auto
3953 || storage_class == csc_register
3954 || storage_class == csc_typedef)
3955 storage_class = csc_none;
3957 else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
3959 if (decl_context == PARM && storage_class == csc_register)
3963 switch (decl_context)
3966 error ("storage class specified for structure field %qs",
3970 error ("storage class specified for parameter %qs", name);
3973 error ("storage class specified for typename");
3976 storage_class = csc_none;
3980 else if (storage_class == csc_extern
3984 /* 'extern' with initialization is invalid if not at file scope. */
3985 if (current_scope == file_scope)
3986 warning (0, "%qs initialized and declared %<extern%>", name);
3988 error ("%qs has both %<extern%> and initializer", name);
3990 else if (current_scope == file_scope)
3992 if (storage_class == csc_auto)
3993 error ("file-scope declaration of %qs specifies %<auto%>", name);
3994 if (pedantic && storage_class == csc_register)
3995 pedwarn ("file-scope declaration of %qs specifies %<register%>", name);
3999 if (storage_class == csc_extern && funcdef_flag)
4000 error ("nested function %qs declared %<extern%>", name);
4001 else if (threadp && storage_class == csc_none)
4003 error ("function-scope %qs implicitly auto and declared "
4010 /* Now figure out the structure of the declarator proper.
4011 Descend through it, creating more complex types, until we reach
4012 the declared identifier (or NULL_TREE, in an absolute declarator).
4013 At each stage we maintain an unqualified version of the type
4014 together with any qualifiers that should be applied to it with
4015 c_build_qualified_type; this way, array types including
4016 multidimensional array types are first built up in unqualified
4017 form and then the qualified form is created with
4018 TYPE_MAIN_VARIANT pointing to the unqualified form. */
4020 while (declarator && declarator->kind != cdk_id)
4022 if (type == error_mark_node)
4024 declarator = declarator->declarator;
4028 /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
4029 a cdk_pointer (for *...),
4030 a cdk_function (for ...(...)),
4031 a cdk_attrs (for nested attributes),
4032 or a cdk_id (for the name being declared
4033 or the place in an absolute declarator
4034 where the name was omitted).
4035 For the last case, we have just exited the loop.
4037 At this point, TYPE is the type of elements of an array,
4038 or for a function to return, or for a pointer to point to.
4039 After this sequence of ifs, TYPE is the type of the
4040 array or function or pointer, and DECLARATOR has had its
4041 outermost layer removed. */
4043 if (array_ptr_quals != TYPE_UNQUALIFIED
4044 || array_ptr_attrs != NULL_TREE
4045 || array_parm_static)
4047 /* Only the innermost declarator (making a parameter be of
4048 array type which is converted to pointer type)
4049 may have static or type qualifiers. */
4050 error ("static or type qualifiers in non-parameter array declarator");
4051 array_ptr_quals = TYPE_UNQUALIFIED;
4052 array_ptr_attrs = NULL_TREE;
4053 array_parm_static = 0;
4056 switch (declarator->kind)
4060 /* A declarator with embedded attributes. */
4061 tree attrs = declarator->u.attrs;
4062 const struct c_declarator *inner_decl;
4064 declarator = declarator->declarator;
4065 inner_decl = declarator;
4066 while (inner_decl->kind == cdk_attrs)
4067 inner_decl = inner_decl->declarator;
4068 if (inner_decl->kind == cdk_id)
4069 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
4070 else if (inner_decl->kind == cdk_function)
4071 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
4072 else if (inner_decl->kind == cdk_array)
4073 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
4074 returned_attrs = decl_attributes (&type,
4075 chainon (returned_attrs, attrs),
4081 tree itype = NULL_TREE;
4082 tree size = declarator->u.array.dimen;
4083 /* The index is a signed object `sizetype' bits wide. */
4084 tree index_type = c_common_signed_type (sizetype);
4086 array_ptr_quals = declarator->u.array.quals;
4087 array_ptr_attrs = declarator->u.array.attrs;
4088 array_parm_static = declarator->u.array.static_p;
4090 declarator = declarator->declarator;
4092 /* Check for some types that there cannot be arrays of. */
4094 if (VOID_TYPE_P (type))
4096 error ("declaration of %qs as array of voids", name);
4097 type = error_mark_node;
4100 if (TREE_CODE (type) == FUNCTION_TYPE)
4102 error ("declaration of %qs as array of functions", name);
4103 type = error_mark_node;
4106 if (pedantic && !in_system_header && flexible_array_type_p (type))
4107 pedwarn ("invalid use of structure with flexible array member");
4109 if (size == error_mark_node)
4110 type = error_mark_node;
4112 if (type == error_mark_node)
4115 /* If size was specified, set ITYPE to a range-type for
4116 that size. Otherwise, ITYPE remains null. finish_decl
4117 may figure it out from an initial value. */
4121 /* Strip NON_LVALUE_EXPRs since we aren't using as an
4123 STRIP_TYPE_NOPS (size);
4125 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
4127 error ("size of array %qs has non-integer type", name);
4128 size = integer_one_node;
4131 if (pedantic && integer_zerop (size))
4132 pedwarn ("ISO C forbids zero-size array %qs", name);
4134 if (TREE_CODE (size) == INTEGER_CST)
4136 constant_expression_warning (size);
4137 if (tree_int_cst_sgn (size) < 0)
4139 error ("size of array %qs is negative", name);
4140 size = integer_one_node;
4145 /* Make sure the array size remains visibly
4146 nonconstant even if it is (eg) a const variable
4147 with known value. */
4150 if (!flag_isoc99 && pedantic)
4152 if (TREE_CONSTANT (size))
4153 pedwarn ("ISO C90 forbids array %qs whose size "
4154 "can%'t be evaluated",
4157 pedwarn ("ISO C90 forbids variable-size array %qs",
4162 if (integer_zerop (size))
4164 /* A zero-length array cannot be represented with
4165 an unsigned index type, which is what we'll
4166 get with build_index_type. Create an
4167 open-ended range instead. */
4168 itype = build_range_type (sizetype, size, NULL_TREE);
4172 /* Arrange for the SAVE_EXPR on the inside of the
4173 MINUS_EXPR, which allows the -1 to get folded
4174 with the +1 that happens when building TYPE_SIZE. */
4176 size = variable_size (size);
4178 /* Compute the maximum valid index, that is, size
4179 - 1. Do the calculation in index_type, so that
4180 if it is a variable the computations will be
4181 done in the proper mode. */
4182 itype = fold_build2 (MINUS_EXPR, index_type,
4183 convert (index_type, size),
4184 convert (index_type,
4187 /* If that overflowed, the array is too big. ???
4188 While a size of INT_MAX+1 technically shouldn't
4189 cause an overflow (because we subtract 1), the
4190 overflow is recorded during the conversion to
4191 index_type, before the subtraction. Handling
4192 this case seems like an unnecessary
4194 if (TREE_CODE (itype) == INTEGER_CST
4195 && TREE_OVERFLOW (itype))
4197 error ("size of array %qs is too large", name);
4198 type = error_mark_node;
4202 itype = build_index_type (itype);
4205 else if (decl_context == FIELD)
4207 if (pedantic && !flag_isoc99 && !in_system_header)
4208 pedwarn ("ISO C90 does not support flexible array members");
4210 /* ISO C99 Flexible array members are effectively
4211 identical to GCC's zero-length array extension. */
4212 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
4215 /* Complain about arrays of incomplete types. */
4216 if (!COMPLETE_TYPE_P (type))
4218 error ("array type has incomplete element type");
4219 type = error_mark_node;
4222 type = build_array_type (type, itype);
4225 C_TYPE_VARIABLE_SIZE (type) = 1;
4227 /* The GCC extension for zero-length arrays differs from
4228 ISO flexible array members in that sizeof yields
4230 if (size && integer_zerop (size))
4232 TYPE_SIZE (type) = bitsize_zero_node;
4233 TYPE_SIZE_UNIT (type) = size_zero_node;
4236 if (decl_context != PARM
4237 && (array_ptr_quals != TYPE_UNQUALIFIED
4238 || array_ptr_attrs != NULL_TREE
4239 || array_parm_static))
4241 error ("static or type qualifiers in non-parameter array declarator");
4242 array_ptr_quals = TYPE_UNQUALIFIED;
4243 array_ptr_attrs = NULL_TREE;
4244 array_parm_static = 0;
4250 /* Say it's a definition only for the declarator closest
4251 to the identifier, apart possibly from some
4253 bool really_funcdef = false;
4257 const struct c_declarator *t = declarator->declarator;
4258 while (t->kind == cdk_attrs)
4260 really_funcdef = (t->kind == cdk_id);
4263 /* Declaring a function type. Make sure we have a valid
4264 type for the function to return. */
4265 if (type == error_mark_node)
4270 /* Warn about some types functions can't return. */
4271 if (TREE_CODE (type) == FUNCTION_TYPE)
4273 error ("%qs declared as function returning a function", name);
4274 type = integer_type_node;
4276 if (TREE_CODE (type) == ARRAY_TYPE)
4278 error ("%qs declared as function returning an array", name);
4279 type = integer_type_node;
4282 /* Construct the function type and go to the next
4283 inner layer of declarator. */
4284 arg_info = declarator->u.arg_info;
4285 arg_types = grokparms (arg_info, really_funcdef);
4287 /* Type qualifiers before the return type of the function
4288 qualify the return type, not the function type. */
4291 /* Type qualifiers on a function return type are
4292 normally permitted by the standard but have no
4293 effect, so give a warning at -Wreturn-type.
4294 Qualifiers on a void return type are banned on
4295 function definitions in ISO C; GCC used to used
4296 them for noreturn functions. */
4297 if (VOID_TYPE_P (type) && really_funcdef)
4298 pedwarn ("function definition has qualified void return type");
4300 warning (OPT_Wreturn_type,
4301 "type qualifiers ignored on function return type");
4303 type = c_build_qualified_type (type, type_quals);
4305 type_quals = TYPE_UNQUALIFIED;
4307 type = build_function_type (type, arg_types);
4308 declarator = declarator->declarator;
4310 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4311 the formal parameter list of this FUNCTION_TYPE to point to
4312 the FUNCTION_TYPE node itself. */
4316 for (link = arg_info->tags;
4318 link = TREE_CHAIN (link))
4319 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4325 /* Merge any constancy or volatility into the target type
4328 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4330 pedwarn ("ISO C forbids qualified function types");
4332 type = c_build_qualified_type (type, type_quals);
4335 type = build_pointer_type (type);
4337 /* Process type qualifiers (such as const or volatile)
4338 that were given inside the `*'. */
4339 type_quals = declarator->u.pointer_quals;
4341 declarator = declarator->declarator;
4349 /* Now TYPE has the actual type, apart from any qualifiers in
4352 /* Check the type and width of a bit-field. */
4354 check_bitfield_type_and_width (&type, width, orig_name);
4356 /* Did array size calculations overflow? */
4358 if (TREE_CODE (type) == ARRAY_TYPE
4359 && COMPLETE_TYPE_P (type)
4360 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4361 && TREE_OVERFLOW (TYPE_SIZE (type)))
4363 error ("size of array %qs is too large", name);
4364 /* If we proceed with the array type as it is, we'll eventually
4365 crash in tree_low_cst(). */
4366 type = error_mark_node;
4369 /* If this is declaring a typedef name, return a TYPE_DECL. */
4371 if (storage_class == csc_typedef)
4374 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4376 pedwarn ("ISO C forbids qualified function types");
4378 type = c_build_qualified_type (type, type_quals);
4379 decl = build_decl (TYPE_DECL, declarator->u.id, type);
4380 if (declspecs->explicit_signed_p)
4381 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4382 decl_attributes (&decl, returned_attrs, 0);
4383 if (declspecs->inline_p)
4384 pedwarn ("%Jtypedef %qD declared %<inline%>", decl, decl);
4388 /* Detect the case of an array type of unspecified size
4389 which came, as such, direct from a typedef name.
4390 We must copy the type, so that each identifier gets
4391 a distinct type, so that each identifier's size can be
4392 controlled separately by its own initializer. */
4394 if (type != 0 && typedef_type != 0
4395 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
4396 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
4398 type = build_array_type (TREE_TYPE (type), 0);
4400 C_TYPE_VARIABLE_SIZE (type) = 1;
4403 /* If this is a type name (such as, in a cast or sizeof),
4404 compute the type and return it now. */
4406 if (decl_context == TYPENAME)
4408 /* Note that the grammar rejects storage classes in typenames
4410 gcc_assert (storage_class == csc_none && !threadp
4411 && !declspecs->inline_p);
4412 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4414 pedwarn ("ISO C forbids const or volatile function types");
4416 type = c_build_qualified_type (type, type_quals);
4417 decl_attributes (&type, returned_attrs, 0);
4421 /* Aside from typedefs and type names (handle above),
4422 `void' at top level (not within pointer)
4423 is allowed only in public variables.
4424 We don't complain about parms either, but that is because
4425 a better error message can be made later. */
4427 if (VOID_TYPE_P (type) && decl_context != PARM
4428 && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4429 && (storage_class == csc_extern
4430 || (current_scope == file_scope
4431 && !(storage_class == csc_static
4432 || storage_class == csc_register)))))
4434 error ("variable or field %qs declared void", name);
4435 type = integer_type_node;
4438 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4439 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4444 if (decl_context == PARM)
4446 tree type_as_written;
4449 /* A parameter declared as an array of T is really a pointer to T.
4450 One declared as a function is really a pointer to a function. */
4452 if (TREE_CODE (type) == ARRAY_TYPE)
4454 /* Transfer const-ness of array into that of type pointed to. */
4455 type = TREE_TYPE (type);
4457 type = c_build_qualified_type (type, type_quals);
4458 type = build_pointer_type (type);
4459 type_quals = array_ptr_quals;
4461 /* We don't yet implement attributes in this context. */
4462 if (array_ptr_attrs != NULL_TREE)
4463 warning (OPT_Wattributes,
4464 "attributes in parameter array declarator ignored");
4468 else if (TREE_CODE (type) == FUNCTION_TYPE)
4470 if (pedantic && type_quals)
4471 pedwarn ("ISO C forbids qualified function types");
4473 type = c_build_qualified_type (type, type_quals);
4474 type = build_pointer_type (type);
4475 type_quals = TYPE_UNQUALIFIED;
4477 else if (type_quals)
4478 type = c_build_qualified_type (type, type_quals);
4480 type_as_written = type;
4482 decl = build_decl (PARM_DECL, declarator->u.id, type);
4484 C_DECL_VARIABLE_SIZE (decl) = 1;
4486 /* Compute the type actually passed in the parmlist,
4487 for the case where there is no prototype.
4488 (For example, shorts and chars are passed as ints.)
4489 When there is a prototype, this is overridden later. */
4491 if (type == error_mark_node)
4492 promoted_type = type;
4494 promoted_type = c_type_promotes_to (type);
4496 DECL_ARG_TYPE (decl) = promoted_type;
4497 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
4498 if (declspecs->inline_p)
4499 pedwarn ("%Jparameter %qD declared %<inline%>", decl, decl);
4501 else if (decl_context == FIELD)
4503 /* Note that the grammar rejects storage classes in typenames
4505 gcc_assert (storage_class == csc_none && !threadp
4506 && !declspecs->inline_p);
4508 /* Structure field. It may not be a function. */
4510 if (TREE_CODE (type) == FUNCTION_TYPE)
4512 error ("field %qs declared as a function", name);
4513 type = build_pointer_type (type);
4515 else if (TREE_CODE (type) != ERROR_MARK
4516 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
4518 error ("field %qs has incomplete type", name);
4519 type = error_mark_node;
4521 type = c_build_qualified_type (type, type_quals);
4522 decl = build_decl (FIELD_DECL, declarator->u.id, type);
4523 DECL_NONADDRESSABLE_P (decl) = bitfield;
4526 C_DECL_VARIABLE_SIZE (decl) = 1;
4528 else if (TREE_CODE (type) == FUNCTION_TYPE)
4530 if (storage_class == csc_register || threadp)
4532 error ("invalid storage class for function %qs", name);
4534 else if (current_scope != file_scope)
4536 /* Function declaration not at file scope. Storage
4537 classes other than `extern' are not allowed, C99
4538 6.7.1p5, and `extern' makes no difference. However,
4539 GCC allows 'auto', perhaps with 'inline', to support
4540 nested functions. */
4541 if (storage_class == csc_auto)
4544 pedwarn ("invalid storage class for function %qs", name);
4546 else if (storage_class == csc_static)
4548 error ("invalid storage class for function %qs", name);
4550 storage_class = declspecs->storage_class = csc_none;
4556 decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
4557 decl = build_decl_attribute_variant (decl, decl_attr);
4559 DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
4561 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
4562 pedwarn ("ISO C forbids qualified function types");
4564 /* GNU C interprets a volatile-qualified function type to indicate
4565 that the function does not return. */
4566 if ((type_quals & TYPE_QUAL_VOLATILE)
4567 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
4568 warning (0, "%<noreturn%> function returns non-void value");
4570 /* Every function declaration is an external reference
4571 (DECL_EXTERNAL) except for those which are not at file
4572 scope and are explicitly declared "auto". This is
4573 forbidden by standard C (C99 6.7.1p5) and is interpreted by
4574 GCC to signify a forward declaration of a nested function. */
4575 if (storage_class == csc_auto && current_scope != file_scope)
4576 DECL_EXTERNAL (decl) = 0;
4578 DECL_EXTERNAL (decl) = 1;
4580 /* Record absence of global scope for `static' or `auto'. */
4582 = !(storage_class == csc_static || storage_class == csc_auto);
4584 /* For a function definition, record the argument information
4585 block where store_parm_decls will look for it. */
4587 current_function_arg_info = arg_info;
4589 if (declspecs->default_int_p)
4590 C_FUNCTION_IMPLICIT_INT (decl) = 1;
4592 /* Record presence of `inline', if it is reasonable. */
4593 if (flag_hosted && MAIN_NAME_P (declarator->u.id))
4595 if (declspecs->inline_p)
4596 pedwarn ("cannot inline function %<main%>");
4598 else if (declspecs->inline_p)
4600 /* Record that the function is declared `inline'. */
4601 DECL_DECLARED_INLINE_P (decl) = 1;
4603 /* Do not mark bare declarations as DECL_INLINE. Doing so
4604 in the presence of multiple declarations can result in
4605 the abstract origin pointing between the declarations,
4606 which will confuse dwarf2out. */
4609 DECL_INLINE (decl) = 1;
4610 if (storage_class == csc_extern)
4611 current_extern_inline = 1;
4614 /* If -finline-functions, assume it can be inlined. This does
4615 two things: let the function be deferred until it is actually
4616 needed, and let dwarf2 know that the function is inlinable. */
4617 else if (flag_inline_trees == 2 && initialized)
4618 DECL_INLINE (decl) = 1;
4622 /* It's a variable. */
4623 /* An uninitialized decl with `extern' is a reference. */
4624 int extern_ref = !initialized && storage_class == csc_extern;
4626 type = c_build_qualified_type (type, type_quals);
4628 /* C99 6.2.2p7: It is invalid (compile-time undefined
4629 behavior) to create an 'extern' declaration for a
4630 variable if there is a global declaration that is
4631 'static' and the global declaration is not visible.
4632 (If the static declaration _is_ currently visible,
4633 the 'extern' declaration is taken to refer to that decl.) */
4634 if (extern_ref && current_scope != file_scope)
4636 tree global_decl = identifier_global_value (declarator->u.id);
4637 tree visible_decl = lookup_name (declarator->u.id);
4640 && global_decl != visible_decl
4641 && TREE_CODE (global_decl) == VAR_DECL
4642 && !TREE_PUBLIC (global_decl))
4643 error ("variable previously declared %<static%> redeclared "
4647 decl = build_decl (VAR_DECL, declarator->u.id, type);
4648 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
4650 C_DECL_VARIABLE_SIZE (decl) = 1;
4652 if (declspecs->inline_p)
4653 pedwarn ("%Jvariable %qD declared %<inline%>", decl, decl);
4655 /* At file scope, an initialized extern declaration may follow
4656 a static declaration. In that case, DECL_EXTERNAL will be
4657 reset later in start_decl. */
4658 DECL_EXTERNAL (decl) = (storage_class == csc_extern);
4660 /* At file scope, the presence of a `static' or `register' storage
4661 class specifier, or the absence of all storage class specifiers
4662 makes this declaration a definition (perhaps tentative). Also,
4663 the absence of both `static' and `register' makes it public. */
4664 if (current_scope == file_scope)
4666 TREE_PUBLIC (decl) = !(storage_class == csc_static
4667 || storage_class == csc_register);
4668 TREE_STATIC (decl) = !extern_ref;
4670 /* Not at file scope, only `static' makes a static definition. */
4673 TREE_STATIC (decl) = (storage_class == csc_static);
4674 TREE_PUBLIC (decl) = extern_ref;
4679 if (targetm.have_tls)
4680 DECL_THREAD_LOCAL (decl) = 1;
4682 /* A mere warning is sure to result in improper semantics
4683 at runtime. Don't bother to allow this to compile. */
4684 error ("thread-local storage not supported for this target");
4688 /* Record `register' declaration for warnings on &
4689 and in case doing stupid register allocation. */
4691 if (storage_class == csc_register)
4693 C_DECL_REGISTER (decl) = 1;
4694 DECL_REGISTER (decl) = 1;
4697 /* Record constancy and volatility. */
4698 c_apply_type_quals_to_decl (type_quals, decl);
4700 /* If a type has volatile components, it should be stored in memory.
4701 Otherwise, the fact that those components are volatile
4702 will be ignored, and would even crash the compiler. */
4703 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
4705 /* It is not an error for a structure with volatile fields to
4706 be declared register, but reset DECL_REGISTER since it
4707 cannot actually go in a register. */
4708 int was_reg = C_DECL_REGISTER (decl);
4709 C_DECL_REGISTER (decl) = 0;
4710 DECL_REGISTER (decl) = 0;
4711 c_mark_addressable (decl);
4712 C_DECL_REGISTER (decl) = was_reg;
4715 /* This is the earliest point at which we might know the assembler
4716 name of a variable. Thus, if it's known before this, die horribly. */
4717 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
4719 decl_attributes (&decl, returned_attrs, 0);
4725 /* Decode the parameter-list info for a function type or function definition.
4726 The argument is the value returned by `get_parm_info' (or made in parse.y
4727 if there is an identifier list instead of a parameter decl list).
4728 These two functions are separate because when a function returns
4729 or receives functions then each is called multiple times but the order
4730 of calls is different. The last call to `grokparms' is always the one
4731 that contains the formal parameter names of a function definition.
4733 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4735 FUNCDEF_FLAG is true for a function definition, false for
4736 a mere declaration. A nonempty identifier-list gets an error message
4737 when FUNCDEF_FLAG is false. */
4740 grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
4742 tree arg_types = arg_info->types;
4744 if (arg_types == 0 && !funcdef_flag && !in_system_header)
4745 warning (OPT_Wstrict_prototypes,
4746 "function declaration isn%'t a prototype");
4748 if (arg_types == error_mark_node)
4749 return 0; /* don't set TYPE_ARG_TYPES in this case */
4751 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
4754 pedwarn ("parameter names (without types) in function declaration");
4756 arg_info->parms = arg_info->types;
4757 arg_info->types = 0;
4762 tree parm, type, typelt;
4763 unsigned int parmno;
4765 /* If there is a parameter of incomplete type in a definition,
4766 this is an error. In a declaration this is valid, and a
4767 struct or union type may be completed later, before any calls
4768 or definition of the function. In the case where the tag was
4769 first declared within the parameter list, a warning has
4770 already been given. If a parameter has void type, then
4771 however the function cannot be defined or called, so
4774 for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
4776 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
4778 type = TREE_VALUE (typelt);
4779 if (type == error_mark_node)
4782 if (!COMPLETE_TYPE_P (type))
4786 if (DECL_NAME (parm))
4787 error ("%Jparameter %u (%qD) has incomplete type",
4788 parm, parmno, parm);
4790 error ("%Jparameter %u has incomplete type",
4793 TREE_VALUE (typelt) = error_mark_node;
4794 TREE_TYPE (parm) = error_mark_node;
4796 else if (VOID_TYPE_P (type))
4798 if (DECL_NAME (parm))
4799 warning (0, "%Jparameter %u (%qD) has void type",
4800 parm, parmno, parm);
4802 warning (0, "%Jparameter %u has void type",
4811 /* Take apart the current scope and return a c_arg_info structure with
4812 info on a parameter list just parsed.
4814 This structure is later fed to 'grokparms' and 'store_parm_decls'.
4816 ELLIPSIS being true means the argument list ended in '...' so don't
4817 append a sentinel (void_list_node) to the end of the type-list. */
4820 get_parm_info (bool ellipsis)
4822 struct c_binding *b = current_scope->bindings;
4823 struct c_arg_info *arg_info = XOBNEW (&parser_obstack,
4830 static bool explained_incomplete_types = false;
4831 bool gave_void_only_once_err = false;
4833 arg_info->parms = 0;
4835 arg_info->types = 0;
4836 arg_info->others = 0;
4838 /* The bindings in this scope must not get put into a block.
4839 We will take care of deleting the binding nodes. */
4840 current_scope->bindings = 0;
4842 /* This function is only called if there was *something* on the
4846 /* A parameter list consisting solely of 'void' indicates that the
4847 function takes no arguments. But if the 'void' is qualified
4848 (by 'const' or 'volatile'), or has a storage class specifier
4849 ('register'), then the behavior is undefined; issue an error.
4850 Typedefs for 'void' are OK (see DR#157). */
4851 if (b->prev == 0 /* one binding */
4852 && TREE_CODE (b->decl) == PARM_DECL /* which is a parameter */
4853 && !DECL_NAME (b->decl) /* anonymous */
4854 && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
4856 if (TREE_THIS_VOLATILE (b->decl)
4857 || TREE_READONLY (b->decl)
4858 || C_DECL_REGISTER (b->decl))
4859 error ("%<void%> as only parameter may not be qualified");
4861 /* There cannot be an ellipsis. */
4863 error ("%<void%> must be the only parameter");
4865 arg_info->types = void_list_node;
4870 types = void_list_node;
4872 /* Break up the bindings list into parms, tags, types, and others;
4873 apply sanity checks; purge the name-to-decl bindings. */
4876 tree decl = b->decl;
4877 tree type = TREE_TYPE (decl);
4878 const char *keyword;
4880 switch (TREE_CODE (decl))
4885 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
4886 I_SYMBOL_BINDING (b->id) = b->shadowed;
4889 /* Check for forward decls that never got their actual decl. */
4890 if (TREE_ASM_WRITTEN (decl))
4891 error ("%Jparameter %qD has just a forward declaration",
4893 /* Check for (..., void, ...) and issue an error. */
4894 else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
4896 if (!gave_void_only_once_err)
4898 error ("%<void%> must be the only parameter");
4899 gave_void_only_once_err = true;
4904 /* Valid parameter, add it to the list. */
4905 TREE_CHAIN (decl) = parms;
4908 /* Since there is a prototype, args are passed in their
4909 declared types. The back end may override this later. */
4910 DECL_ARG_TYPE (decl) = type;
4911 types = tree_cons (0, type, types);
4915 case ENUMERAL_TYPE: keyword = "enum"; goto tag;
4916 case UNION_TYPE: keyword = "union"; goto tag;
4917 case RECORD_TYPE: keyword = "struct"; goto tag;
4919 /* Types may not have tag-names, in which case the type
4920 appears in the bindings list with b->id NULL. */
4923 gcc_assert (I_TAG_BINDING (b->id) == b);
4924 I_TAG_BINDING (b->id) = b->shadowed;
4927 /* Warn about any struct, union or enum tags defined in a
4928 parameter list. The scope of such types is limited to
4929 the parameter list, which is rarely if ever desirable
4930 (it's impossible to call such a function with type-
4931 correct arguments). An anonymous union parm type is
4932 meaningful as a GNU extension, so don't warn for that. */
4933 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
4936 /* The %s will be one of 'struct', 'union', or 'enum'. */
4937 warning (0, "%<%s %E%> declared inside parameter list",
4940 /* The %s will be one of 'struct', 'union', or 'enum'. */
4941 warning (0, "anonymous %s declared inside parameter list",
4944 if (!explained_incomplete_types)
4946 warning (0, "its scope is only this definition or declaration,"
4947 " which is probably not what you want");
4948 explained_incomplete_types = true;
4952 tags = tree_cons (b->id, decl, tags);
4958 /* CONST_DECLs appear here when we have an embedded enum,
4959 and TYPE_DECLs appear here when we have an embedded struct
4960 or union. No warnings for this - we already warned about the
4961 type itself. FUNCTION_DECLs appear when there is an implicit
4962 function declaration in the parameter list. */
4964 TREE_CHAIN (decl) = others;
4969 /* error_mark_node appears here when we have an undeclared
4970 variable. Just throw it away. */
4973 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
4974 I_SYMBOL_BINDING (b->id) = b->shadowed;
4978 /* Other things that might be encountered. */
4985 b = free_binding_and_advance (b);
4988 arg_info->parms = parms;
4989 arg_info->tags = tags;
4990 arg_info->types = types;
4991 arg_info->others = others;
4995 /* Get the struct, enum or union (CODE says which) with tag NAME.
4996 Define the tag as a forward-reference if it is not defined.
4997 Return a c_typespec structure for the type specifier. */
5000 parser_xref_tag (enum tree_code code, tree name)
5002 struct c_typespec ret;
5003 /* If a cross reference is requested, look up the type
5004 already defined for this tag and return it. */
5006 tree ref = lookup_tag (code, name, 0);
5007 /* If this is the right type of tag, return what we found.
5008 (This reference will be shadowed by shadow_tag later if appropriate.)
5009 If this is the wrong type of tag, do not return it. If it was the
5010 wrong type in the same scope, we will have had an error
5011 message already; if in a different scope and declaring
5012 a name, pending_xref_error will give an error message; but if in a
5013 different scope and not declaring a name, this tag should
5014 shadow the previous declaration of a different type of tag, and
5015 this would not work properly if we return the reference found.
5016 (For example, with "struct foo" in an outer scope, "union foo;"
5017 must shadow that tag with a new one of union type.) */
5018 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
5019 if (ref && TREE_CODE (ref) == code)
5025 /* If no such tag is yet defined, create a forward-reference node
5026 and record it as the "definition".
5027 When a real declaration of this type is found,
5028 the forward-reference will be altered into a real type. */
5030 ref = make_node (code);
5031 if (code == ENUMERAL_TYPE)
5033 /* Give the type a default layout like unsigned int
5034 to avoid crashing if it does not get defined. */
5035 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
5036 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5037 TYPE_USER_ALIGN (ref) = 0;
5038 TYPE_UNSIGNED (ref) = 1;
5039 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5040 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5041 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5044 pushtag (name, ref);
5050 /* Get the struct, enum or union (CODE says which) with tag NAME.
5051 Define the tag as a forward-reference if it is not defined.
5052 Return a tree for the type. */
5055 xref_tag (enum tree_code code, tree name)
5057 return parser_xref_tag (code, name).spec;
5060 /* Make sure that the tag NAME is defined *in the current scope*
5061 at least as a forward reference.
5062 CODE says which kind of tag NAME ought to be. */
5065 start_struct (enum tree_code code, tree name)
5067 /* If there is already a tag defined at this scope
5068 (as a forward reference), just return it. */
5073 ref = lookup_tag (code, name, 1);
5074 if (ref && TREE_CODE (ref) == code)
5076 if (TYPE_SIZE (ref))
5078 if (code == UNION_TYPE)
5079 error ("redefinition of %<union %E%>", name);
5081 error ("redefinition of %<struct %E%>", name);
5083 else if (C_TYPE_BEING_DEFINED (ref))
5085 if (code == UNION_TYPE)
5086 error ("nested redefinition of %<union %E%>", name);
5088 error ("nested redefinition of %<struct %E%>", name);
5093 /* Otherwise create a forward-reference just so the tag is in scope. */
5095 ref = make_node (code);
5096 pushtag (name, ref);
5099 C_TYPE_BEING_DEFINED (ref) = 1;
5100 TYPE_PACKED (ref) = flag_pack_struct;
5104 /* Process the specs, declarator and width (NULL if omitted)
5105 of a structure component, returning a FIELD_DECL node.
5106 WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
5108 This is done during the parsing of the struct declaration.
5109 The FIELD_DECL nodes are chained together and the lot of them
5110 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5113 grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs,
5118 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
5119 && width == NULL_TREE)
5121 /* This is an unnamed decl.
5123 If we have something of the form "union { list } ;" then this
5124 is the anonymous union extension. Similarly for struct.
5126 If this is something of the form "struct foo;", then
5127 If MS extensions are enabled, this is handled as an
5129 Otherwise this is a forward declaration of a structure tag.
5131 If this is something of the form "foo;" and foo is a TYPE_DECL, then
5132 If MS extensions are enabled and foo names a structure, then
5133 again this is an anonymous struct.
5134 Otherwise this is an error.
5136 Oh what a horrid tangled web we weave. I wonder if MS consciously
5137 took this from Plan 9 or if it was an accident of implementation
5138 that took root before someone noticed the bug... */
5140 tree type = declspecs->type;
5141 bool type_ok = (TREE_CODE (type) == RECORD_TYPE
5142 || TREE_CODE (type) == UNION_TYPE);
5146 && (flag_ms_extensions || !declspecs->typedef_p))
5148 if (flag_ms_extensions)
5152 else if (TYPE_NAME (type) == NULL)
5159 pedwarn ("declaration does not declare anything");
5163 pedwarn ("ISO C doesn%'t support unnamed structs/unions");
5166 value = grokdeclarator (declarator, declspecs, FIELD, false,
5167 width ? &width : NULL);
5169 finish_decl (value, NULL_TREE, NULL_TREE);
5170 DECL_INITIAL (value) = width;
5175 /* Generate an error for any duplicate field names in FIELDLIST. Munge
5176 the list such that this does not present a problem later. */
5179 detect_field_duplicates (tree fieldlist)
5184 /* First, see if there are more than "a few" fields.
5185 This is trivially true if there are zero or one fields. */
5188 x = TREE_CHAIN (fieldlist);
5194 } while (timeout > 0 && x);
5196 /* If there were "few" fields, avoid the overhead of allocating
5197 a hash table. Instead just do the nested traversal thing. */
5200 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x))
5203 for (y = fieldlist; y != x; y = TREE_CHAIN (y))
5204 if (DECL_NAME (y) == DECL_NAME (x))
5206 error ("%Jduplicate member %qD", x, x);
5207 DECL_NAME (x) = NULL_TREE;
5213 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
5216 for (x = fieldlist; x ; x = TREE_CHAIN (x))
5217 if ((y = DECL_NAME (x)) != 0)
5219 slot = htab_find_slot (htab, y, INSERT);
5222 error ("%Jduplicate member %qD", x, x);
5223 DECL_NAME (x) = NULL_TREE;
5232 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5233 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5234 ATTRIBUTES are attributes to be applied to the structure. */
5237 finish_struct (tree t, tree fieldlist, tree attributes)
5240 bool toplevel = file_scope == current_scope;
5241 int saw_named_field;
5243 /* If this type was previously laid out as a forward reference,
5244 make sure we lay it out again. */
5248 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5252 for (x = fieldlist; x; x = TREE_CHAIN (x))
5253 if (DECL_NAME (x) != 0)
5258 if (TREE_CODE (t) == UNION_TYPE)
5261 pedwarn ("union has no named members");
5263 pedwarn ("union has no members");
5268 pedwarn ("struct has no named members");
5270 pedwarn ("struct has no members");
5275 /* Install struct as DECL_CONTEXT of each field decl.
5276 Also process specified field sizes, found in the DECL_INITIAL,
5277 storing 0 there after the type has been changed to precision equal
5278 to its width, rather than the precision of the specified standard
5279 type. (Correct layout requires the original type to have been preserved
5282 saw_named_field = 0;
5283 for (x = fieldlist; x; x = TREE_CHAIN (x))
5285 DECL_CONTEXT (x) = t;
5286 DECL_PACKED (x) |= TYPE_PACKED (t);
5288 /* If any field is const, the structure type is pseudo-const. */
5289 if (TREE_READONLY (x))
5290 C_TYPE_FIELDS_READONLY (t) = 1;
5293 /* A field that is pseudo-const makes the structure likewise. */
5294 tree t1 = TREE_TYPE (x);
5295 while (TREE_CODE (t1) == ARRAY_TYPE)
5296 t1 = TREE_TYPE (t1);
5297 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5298 && C_TYPE_FIELDS_READONLY (t1))
5299 C_TYPE_FIELDS_READONLY (t) = 1;
5302 /* Any field that is volatile means variables of this type must be
5303 treated in some ways as volatile. */
5304 if (TREE_THIS_VOLATILE (x))
5305 C_TYPE_FIELDS_VOLATILE (t) = 1;
5307 /* Any field of nominal variable size implies structure is too. */
5308 if (C_DECL_VARIABLE_SIZE (x))
5309 C_TYPE_VARIABLE_SIZE (t) = 1;
5311 if (DECL_INITIAL (x))
5313 unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
5314 DECL_SIZE (x) = bitsize_int (width);
5315 DECL_BIT_FIELD (x) = 1;
5316 SET_DECL_C_BIT_FIELD (x);
5319 /* Detect flexible array member in an invalid context. */
5320 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5321 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
5322 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
5323 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
5325 if (TREE_CODE (t) == UNION_TYPE)
5327 error ("%Jflexible array member in union", x);
5328 TREE_TYPE (x) = error_mark_node;
5330 else if (TREE_CHAIN (x) != NULL_TREE)
5332 error ("%Jflexible array member not at end of struct", x);
5333 TREE_TYPE (x) = error_mark_node;
5335 else if (!saw_named_field)
5337 error ("%Jflexible array member in otherwise empty struct", x);
5338 TREE_TYPE (x) = error_mark_node;
5342 if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
5343 && flexible_array_type_p (TREE_TYPE (x)))
5344 pedwarn ("%Jinvalid use of structure with flexible array member", x);
5347 saw_named_field = 1;
5350 detect_field_duplicates (fieldlist);
5352 /* Now we have the nearly final fieldlist. Record it,
5353 then lay out the structure or union (including the fields). */
5355 TYPE_FIELDS (t) = fieldlist;
5359 /* Give bit-fields their proper types. */
5361 tree *fieldlistp = &fieldlist;
5363 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
5364 && TREE_TYPE (*fieldlistp) != error_mark_node)
5366 unsigned HOST_WIDE_INT width
5367 = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
5368 tree type = TREE_TYPE (*fieldlistp);
5369 if (width != TYPE_PRECISION (type))
5371 TREE_TYPE (*fieldlistp)
5372 = build_nonstandard_integer_type (width, TYPE_UNSIGNED (type));
5373 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
5375 DECL_INITIAL (*fieldlistp) = 0;
5378 fieldlistp = &TREE_CHAIN (*fieldlistp);
5381 /* Now we have the truly final field list.
5382 Store it in this type and in the variants. */
5384 TYPE_FIELDS (t) = fieldlist;
5386 /* If there are lots of fields, sort so we can look through them fast.
5387 We arbitrarily consider 16 or more elts to be "a lot". */
5392 for (x = fieldlist; x; x = TREE_CHAIN (x))
5394 if (len > 15 || DECL_NAME (x) == NULL)
5402 struct lang_type *space;
5403 struct sorted_fields_type *space2;
5405 len += list_length (x);
5407 /* Use the same allocation policy here that make_node uses, to
5408 ensure that this lives as long as the rest of the struct decl.
5409 All decls in an inline function need to be saved. */
5411 space = GGC_CNEW (struct lang_type);
5412 space2 = GGC_NEWVAR (struct sorted_fields_type,
5413 sizeof (struct sorted_fields_type) + len * sizeof (tree));
5417 field_array = &space2->elts[0];
5418 for (x = fieldlist; x; x = TREE_CHAIN (x))
5420 field_array[len++] = x;
5422 /* If there is anonymous struct or union, break out of the loop. */
5423 if (DECL_NAME (x) == NULL)
5426 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
5429 TYPE_LANG_SPECIFIC (t) = space;
5430 TYPE_LANG_SPECIFIC (t)->s->len = len;
5431 field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
5432 qsort (field_array, len, sizeof (tree), field_decl_cmp);
5437 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5439 TYPE_FIELDS (x) = TYPE_FIELDS (t);
5440 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
5441 TYPE_ALIGN (x) = TYPE_ALIGN (t);
5442 TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t);
5445 /* If this was supposed to be a transparent union, but we can't
5446 make it one, warn and turn off the flag. */
5447 if (TREE_CODE (t) == UNION_TYPE
5448 && TYPE_TRANSPARENT_UNION (t)
5449 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
5451 TYPE_TRANSPARENT_UNION (t) = 0;
5452 warning (0, "union cannot be made transparent");
5455 /* If this structure or union completes the type of any previous
5456 variable declaration, lay it out and output its rtl. */
5457 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
5461 tree decl = TREE_VALUE (x);
5462 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
5463 layout_array_type (TREE_TYPE (decl));
5464 if (TREE_CODE (decl) != TYPE_DECL)
5466 layout_decl (decl, 0);
5467 if (c_dialect_objc ())
5468 objc_check_decl (decl);
5469 rest_of_decl_compilation (decl, toplevel, 0);
5474 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
5476 /* Finish debugging output for this type. */
5477 rest_of_type_compilation (t, toplevel);
5479 /* If we're inside a function proper, i.e. not file-scope and not still
5480 parsing parameters, then arrange for the size of a variable sized type
5482 if (cur_stmt_list && variably_modified_type_p (t, NULL))
5483 add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t)));
5488 /* Lay out the type T, and its element type, and so on. */
5491 layout_array_type (tree t)
5493 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5494 layout_array_type (TREE_TYPE (t));
5498 /* Begin compiling the definition of an enumeration type.
5499 NAME is its name (or null if anonymous).
5500 Returns the type object, as yet incomplete.
5501 Also records info about it so that build_enumerator
5502 may be used to declare the individual values as they are read. */
5505 start_enum (tree name)
5509 /* If this is the real definition for a previous forward reference,
5510 fill in the contents in the same object that used to be the
5511 forward reference. */
5514 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1);
5516 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
5518 enumtype = make_node (ENUMERAL_TYPE);
5519 pushtag (name, enumtype);
5522 if (C_TYPE_BEING_DEFINED (enumtype))
5523 error ("nested redefinition of %<enum %E%>", name);
5525 C_TYPE_BEING_DEFINED (enumtype) = 1;
5527 if (TYPE_VALUES (enumtype) != 0)
5529 /* This enum is a named one that has been declared already. */
5530 error ("redeclaration of %<enum %E%>", name);
5532 /* Completely replace its old definition.
5533 The old enumerators remain defined, however. */
5534 TYPE_VALUES (enumtype) = 0;
5537 enum_next_value = integer_zero_node;
5540 if (flag_short_enums)
5541 TYPE_PACKED (enumtype) = 1;
5546 /* After processing and defining all the values of an enumeration type,
5547 install their decls in the enumeration type and finish it off.
5548 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5549 and ATTRIBUTES are the specified attributes.
5550 Returns ENUMTYPE. */
5553 finish_enum (tree enumtype, tree values, tree attributes)
5556 tree minnode = 0, maxnode = 0;
5557 int precision, unsign;
5558 bool toplevel = (file_scope == current_scope);
5559 struct lang_type *lt;
5561 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5563 /* Calculate the maximum value of any enumerator in this type. */
5565 if (values == error_mark_node)
5566 minnode = maxnode = integer_zero_node;
5569 minnode = maxnode = TREE_VALUE (values);
5570 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
5572 tree value = TREE_VALUE (pair);
5573 if (tree_int_cst_lt (maxnode, value))
5575 if (tree_int_cst_lt (value, minnode))
5580 /* Construct the final type of this enumeration. It is the same
5581 as one of the integral types - the narrowest one that fits, except
5582 that normally we only go as narrow as int - and signed iff any of
5583 the values are negative. */
5584 unsign = (tree_int_cst_sgn (minnode) >= 0);
5585 precision = MAX (min_precision (minnode, unsign),
5586 min_precision (maxnode, unsign));
5588 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
5590 tem = c_common_type_for_size (precision, unsign);
5593 warning (0, "enumeration values exceed range of largest integer");
5594 tem = long_long_integer_type_node;
5598 tem = unsign ? unsigned_type_node : integer_type_node;
5600 TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
5601 TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
5602 TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
5603 TYPE_SIZE (enumtype) = 0;
5605 /* If the precision of the type was specific with an attribute and it
5606 was too small, give an error. Otherwise, use it. */
5607 if (TYPE_PRECISION (enumtype))
5609 if (precision > TYPE_PRECISION (enumtype))
5610 error ("specified mode too small for enumeral values");
5613 TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
5615 layout_type (enumtype);
5617 if (values != error_mark_node)
5619 /* Change the type of the enumerators to be the enum type. We
5620 need to do this irrespective of the size of the enum, for
5621 proper type checking. Replace the DECL_INITIALs of the
5622 enumerators, and the value slots of the list, with copies
5623 that have the enum type; they cannot be modified in place
5624 because they may be shared (e.g. integer_zero_node) Finally,
5625 change the purpose slots to point to the names of the decls. */
5626 for (pair = values; pair; pair = TREE_CHAIN (pair))
5628 tree enu = TREE_PURPOSE (pair);
5629 tree ini = DECL_INITIAL (enu);
5631 TREE_TYPE (enu) = enumtype;
5633 /* The ISO C Standard mandates enumerators to have type int,
5634 even though the underlying type of an enum type is
5635 unspecified. Here we convert any enumerators that fit in
5636 an int to type int, to avoid promotions to unsigned types
5637 when comparing integers with enumerators that fit in the
5638 int range. When -pedantic is given, build_enumerator()
5639 would have already taken care of those that don't fit. */
5640 if (int_fits_type_p (ini, integer_type_node))
5641 tem = integer_type_node;
5644 ini = convert (tem, ini);
5646 DECL_INITIAL (enu) = ini;
5647 TREE_PURPOSE (pair) = DECL_NAME (enu);
5648 TREE_VALUE (pair) = ini;
5651 TYPE_VALUES (enumtype) = values;
5654 /* Record the min/max values so that we can warn about bit-field
5655 enumerations that are too small for the values. */
5656 lt = GGC_CNEW (struct lang_type);
5657 lt->enum_min = minnode;
5658 lt->enum_max = maxnode;
5659 TYPE_LANG_SPECIFIC (enumtype) = lt;
5661 /* Fix up all variant types of this enum type. */
5662 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
5664 if (tem == enumtype)
5666 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
5667 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
5668 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
5669 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
5670 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
5671 TYPE_MODE (tem) = TYPE_MODE (enumtype);
5672 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
5673 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
5674 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
5675 TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
5676 TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
5679 /* Finish debugging output for this type. */
5680 rest_of_type_compilation (enumtype, toplevel);
5685 /* Build and install a CONST_DECL for one value of the
5686 current enumeration type (one that was begun with start_enum).
5687 Return a tree-list containing the CONST_DECL and its value.
5688 Assignment of sequential values by default is handled here. */
5691 build_enumerator (tree name, tree value)
5695 /* Validate and default VALUE. */
5699 /* Don't issue more errors for error_mark_node (i.e. an
5700 undeclared identifier) - just ignore the value expression. */
5701 if (value == error_mark_node)
5703 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
5704 || TREE_CODE (value) != INTEGER_CST)
5706 error ("enumerator value for %qE is not an integer constant", name);
5711 value = default_conversion (value);
5712 constant_expression_warning (value);
5716 /* Default based on previous value. */
5717 /* It should no longer be possible to have NON_LVALUE_EXPR
5721 value = enum_next_value;
5723 error ("overflow in enumeration values");
5726 if (pedantic && !int_fits_type_p (value, integer_type_node))
5728 pedwarn ("ISO C restricts enumerator values to range of %<int%>");
5729 /* XXX This causes -pedantic to change the meaning of the program.
5730 Remove? -zw 2004-03-15 */
5731 value = convert (integer_type_node, value);
5734 /* Set basis for default for next value. */
5735 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
5736 enum_overflow = tree_int_cst_lt (enum_next_value, value);
5738 /* Now create a declaration for the enum value name. */
5740 type = TREE_TYPE (value);
5741 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
5742 TYPE_PRECISION (integer_type_node)),
5743 (TYPE_PRECISION (type)
5744 >= TYPE_PRECISION (integer_type_node)
5745 && TYPE_UNSIGNED (type)));
5747 decl = build_decl (CONST_DECL, name, type);
5748 DECL_INITIAL (decl) = convert (type, value);
5751 return tree_cons (decl, value, NULL_TREE);
5755 /* Create the FUNCTION_DECL for a function definition.
5756 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
5757 the declaration; they describe the function's name and the type it returns,
5758 but twisted together in a fashion that parallels the syntax of C.
5760 This function creates a binding context for the function body
5761 as well as setting up the FUNCTION_DECL in current_function_decl.
5763 Returns 1 on success. If the DECLARATOR is not suitable for a function
5764 (it defines a datum instead), we return 0, which tells
5765 yyparse to report a parse error. */
5768 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
5771 tree decl1, old_decl;
5772 tree restype, resdecl;
5773 struct c_label_context_se *nstack_se;
5774 struct c_label_context_vm *nstack_vm;
5776 current_function_returns_value = 0; /* Assume, until we see it does. */
5777 current_function_returns_null = 0;
5778 current_function_returns_abnormally = 0;
5779 warn_about_return_type = 0;
5780 current_extern_inline = 0;
5781 c_switch_stack = NULL;
5783 nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
5784 nstack_se->labels_def = NULL;
5785 nstack_se->labels_used = NULL;
5786 nstack_se->next = label_context_stack_se;
5787 label_context_stack_se = nstack_se;
5789 nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm);
5790 nstack_vm->labels_def = NULL;
5791 nstack_vm->labels_used = NULL;
5792 nstack_vm->scope = 0;
5793 nstack_vm->next = label_context_stack_vm;
5794 label_context_stack_vm = nstack_vm;
5796 /* Indicate no valid break/continue context by setting these variables
5797 to some non-null, non-label value. We'll notice and emit the proper
5798 error message in c_finish_bc_stmt. */
5799 c_break_label = c_cont_label = size_zero_node;
5801 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL);
5803 /* If the declarator is not suitable for a function definition,
5804 cause a syntax error. */
5807 label_context_stack_se = label_context_stack_se->next;
5808 label_context_stack_vm = label_context_stack_vm->next;
5812 decl_attributes (&decl1, attributes, 0);
5814 if (DECL_DECLARED_INLINE_P (decl1)
5815 && DECL_UNINLINABLE (decl1)
5816 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
5817 warning (OPT_Wattributes, "%Jinline function %qD given attribute noinline",
5820 announce_function (decl1);
5822 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
5824 error ("return type is an incomplete type");
5825 /* Make it return void instead. */
5827 = build_function_type (void_type_node,
5828 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
5831 if (warn_about_return_type)
5832 pedwarn_c99 ("return type defaults to %<int%>");
5834 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5835 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
5836 DECL_INITIAL (decl1) = error_mark_node;
5838 /* If this definition isn't a prototype and we had a prototype declaration
5839 before, copy the arg type info from that prototype. */
5840 old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
5841 current_function_prototype_locus = UNKNOWN_LOCATION;
5842 current_function_prototype_built_in = false;
5843 current_function_prototype_arg_types = NULL_TREE;
5844 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
5846 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
5847 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
5848 TREE_TYPE (TREE_TYPE (old_decl))))
5850 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
5852 current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
5853 current_function_prototype_built_in
5854 = C_DECL_BUILTIN_PROTOTYPE (old_decl);
5855 current_function_prototype_arg_types
5856 = TYPE_ARG_TYPES (TREE_TYPE (decl1));
5858 if (TREE_PUBLIC (decl1))
5860 /* If there is an external prototype declaration of this
5861 function, record its location but do not copy information
5862 to this decl. This may be an invisible declaration
5863 (built-in or in a scope which has finished) or simply
5864 have more refined argument types than any declaration
5866 struct c_binding *b;
5867 for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
5868 if (B_IN_SCOPE (b, external_scope))
5872 tree ext_decl, ext_type;
5874 ext_type = b->type ? b->type : TREE_TYPE (ext_decl);
5875 if (TREE_CODE (ext_type) == FUNCTION_TYPE
5876 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
5877 TREE_TYPE (ext_type)))
5879 current_function_prototype_locus
5880 = DECL_SOURCE_LOCATION (ext_decl);
5881 current_function_prototype_built_in
5882 = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
5883 current_function_prototype_arg_types
5884 = TYPE_ARG_TYPES (ext_type);
5890 /* Optionally warn of old-fashioned def with no previous prototype. */
5891 if (warn_strict_prototypes
5892 && old_decl != error_mark_node
5893 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
5894 && C_DECL_ISNT_PROTOTYPE (old_decl))
5895 warning (OPT_Wstrict_prototypes,
5896 "function declaration isn%'t a prototype");
5897 /* Optionally warn of any global def with no previous prototype. */
5898 else if (warn_missing_prototypes
5899 && old_decl != error_mark_node
5900 && TREE_PUBLIC (decl1)
5901 && !MAIN_NAME_P (DECL_NAME (decl1))
5902 && C_DECL_ISNT_PROTOTYPE (old_decl))
5903 warning (OPT_Wmissing_prototypes, "%Jno previous prototype for %qD",
5905 /* Optionally warn of any def with no previous prototype
5906 if the function has already been used. */
5907 else if (warn_missing_prototypes
5909 && old_decl != error_mark_node
5910 && TREE_USED (old_decl)
5911 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
5912 warning (OPT_Wmissing_prototypes,
5913 "%J%qD was used with no prototype before its definition",
5915 /* Optionally warn of any global def with no previous declaration. */
5916 else if (warn_missing_declarations
5917 && TREE_PUBLIC (decl1)
5919 && !MAIN_NAME_P (DECL_NAME (decl1)))
5920 warning (OPT_Wmissing_declarations, "%Jno previous declaration for %qD",
5922 /* Optionally warn of any def with no previous declaration
5923 if the function has already been used. */
5924 else if (warn_missing_declarations
5926 && old_decl != error_mark_node
5927 && TREE_USED (old_decl)
5928 && C_DECL_IMPLICIT (old_decl))
5929 warning (OPT_Wmissing_declarations,
5930 "%J%qD was used with no declaration before its definition",
5933 /* This is a definition, not a reference.
5934 So normally clear DECL_EXTERNAL.
5935 However, `extern inline' acts like a declaration
5936 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5937 DECL_EXTERNAL (decl1) = current_extern_inline;
5939 /* This function exists in static storage.
5940 (This does not mean `static' in the C sense!) */
5941 TREE_STATIC (decl1) = 1;
5943 /* A nested function is not global. */
5944 if (current_function_decl != 0)
5945 TREE_PUBLIC (decl1) = 0;
5947 /* This is the earliest point at which we might know the assembler
5948 name of the function. Thus, if it's set before this, die horribly. */
5949 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
5951 /* If #pragma weak was used, mark the decl weak now. */
5952 if (current_scope == file_scope)
5953 maybe_apply_pragma_weak (decl1);
5955 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5956 if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
5961 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
5962 != integer_type_node)
5963 pedwarn ("%Jreturn type of %qD is not %<int%>", decl1, decl1);
5965 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
5966 args = TREE_CHAIN (args))
5968 tree type = args ? TREE_VALUE (args) : 0;
5970 if (type == void_type_node)
5977 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
5978 pedwarn ("%Jfirst argument of %qD should be %<int%>",
5983 if (TREE_CODE (type) != POINTER_TYPE
5984 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5985 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5987 pedwarn ("%Jsecond argument of %qD should be %<char **%>",
5992 if (TREE_CODE (type) != POINTER_TYPE
5993 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
5994 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
5996 pedwarn ("%Jthird argument of %qD should probably be "
5997 "%<char **%>", decl1, decl1);
6002 /* It is intentional that this message does not mention the third
6003 argument because it's only mentioned in an appendix of the
6005 if (argct > 0 && (argct < 2 || argct > 3))
6006 pedwarn ("%J%qD takes only zero or two arguments", decl1, decl1);
6008 if (!TREE_PUBLIC (decl1))
6009 pedwarn ("%J%qD is normally a non-static function", decl1, decl1);
6012 /* Record the decl so that the function name is defined.
6013 If we already have a decl for this name, and it is a FUNCTION_DECL,
6014 use the old decl. */
6016 current_function_decl = pushdecl (decl1);
6019 declare_parm_level ();
6021 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
6022 /* Promote the value to int before returning it. */
6023 if (c_promoting_integer_type_p (restype))
6025 /* It retains unsignedness if not really getting wider. */
6026 if (TYPE_UNSIGNED (restype)
6027 && (TYPE_PRECISION (restype)
6028 == TYPE_PRECISION (integer_type_node)))
6029 restype = unsigned_type_node;
6031 restype = integer_type_node;
6034 resdecl = build_decl (RESULT_DECL, NULL_TREE, restype);
6035 DECL_ARTIFICIAL (resdecl) = 1;
6036 DECL_IGNORED_P (resdecl) = 1;
6037 DECL_RESULT (current_function_decl) = resdecl;
6039 start_fname_decls ();
6044 /* Subroutine of store_parm_decls which handles new-style function
6045 definitions (prototype format). The parms already have decls, so we
6046 need only record them as in effect and complain if any redundant
6047 old-style parm decls were written. */
6049 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
6053 if (current_scope->bindings)
6055 error ("%Jold-style parameter declarations in prototyped "
6056 "function definition", fndecl);
6058 /* Get rid of the old-style declarations. */
6062 /* Don't issue this warning for nested functions, and don't issue this
6063 warning if we got here because ARG_INFO_TYPES was error_mark_node
6064 (this happens when a function definition has just an ellipsis in
6065 its parameter list). */
6066 else if (!in_system_header && !current_function_scope
6067 && arg_info->types != error_mark_node)
6068 warning (OPT_Wtraditional,
6069 "%Jtraditional C rejects ISO C style function definitions",
6072 /* Now make all the parameter declarations visible in the function body.
6073 We can bypass most of the grunt work of pushdecl. */
6074 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl))
6076 DECL_CONTEXT (decl) = current_function_decl;
6077 if (DECL_NAME (decl))
6078 bind (DECL_NAME (decl), decl, current_scope,
6079 /*invisible=*/false, /*nested=*/false);
6081 error ("%Jparameter name omitted", decl);
6084 /* Record the parameter list in the function declaration. */
6085 DECL_ARGUMENTS (fndecl) = arg_info->parms;
6087 /* Now make all the ancillary declarations visible, likewise. */
6088 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl))
6090 DECL_CONTEXT (decl) = current_function_decl;
6091 if (DECL_NAME (decl))
6092 bind (DECL_NAME (decl), decl, current_scope,
6093 /*invisible=*/false, /*nested=*/false);
6096 /* And all the tag declarations. */
6097 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl))
6098 if (TREE_PURPOSE (decl))
6099 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
6100 /*invisible=*/false, /*nested=*/false);
6103 /* Subroutine of store_parm_decls which handles old-style function
6104 definitions (separate parameter list and declarations). */
6107 store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
6109 struct c_binding *b;
6110 tree parm, decl, last;
6111 tree parmids = arg_info->parms;
6113 /* We use DECL_WEAK as a flag to show which parameters have been
6114 seen already, since it is not used on PARM_DECL. */
6115 #ifdef ENABLE_CHECKING
6116 for (b = current_scope->bindings; b; b = b->prev)
6117 gcc_assert (TREE_CODE (b->decl) != PARM_DECL || !DECL_WEAK (b->decl));
6120 if (!in_system_header)
6121 warning (OPT_Wold_style_definition, "%Jold-style function definition",
6124 /* Match each formal parameter name with its declaration. Save each
6125 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
6126 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
6128 if (TREE_VALUE (parm) == 0)
6130 error ("%Jparameter name missing from parameter list", fndecl);
6131 TREE_PURPOSE (parm) = 0;
6135 b = I_SYMBOL_BINDING (TREE_VALUE (parm));
6136 if (b && B_IN_CURRENT_SCOPE (b))
6139 /* If we got something other than a PARM_DECL it is an error. */
6140 if (TREE_CODE (decl) != PARM_DECL)
6141 error ("%J%qD declared as a non-parameter", decl, decl);
6142 /* If the declaration is already marked, we have a duplicate
6143 name. Complain and ignore the duplicate. */
6144 else if (DECL_WEAK (decl))
6146 error ("%Jmultiple parameters named %qD", decl, decl);
6147 TREE_PURPOSE (parm) = 0;
6150 /* If the declaration says "void", complain and turn it into
6152 else if (VOID_TYPE_P (TREE_TYPE (decl)))
6154 error ("%Jparameter %qD declared with void type", decl, decl);
6155 TREE_TYPE (decl) = integer_type_node;
6156 DECL_ARG_TYPE (decl) = integer_type_node;
6157 layout_decl (decl, 0);
6160 /* If no declaration found, default to int. */
6163 decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node);
6164 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
6165 DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl);
6169 pedwarn ("%Jtype of %qD defaults to %<int%>", decl, decl);
6170 else if (extra_warnings)
6171 warning (OPT_Wextra, "%Jtype of %qD defaults to %<int%>",
6175 TREE_PURPOSE (parm) = decl;
6176 DECL_WEAK (decl) = 1;
6179 /* Now examine the parms chain for incomplete declarations
6180 and declarations with no corresponding names. */
6182 for (b = current_scope->bindings; b; b = b->prev)
6185 if (TREE_CODE (parm) != PARM_DECL)
6188 if (TREE_TYPE (parm) != error_mark_node
6189 && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
6191 error ("%Jparameter %qD has incomplete type", parm, parm);
6192 TREE_TYPE (parm) = error_mark_node;
6195 if (!DECL_WEAK (parm))
6197 error ("%Jdeclaration for parameter %qD but no such parameter",
6200 /* Pretend the parameter was not missing.
6201 This gets us to a standard state and minimizes
6202 further error messages. */
6203 parmids = chainon (parmids, tree_cons (parm, 0, 0));
6207 /* Chain the declarations together in the order of the list of
6208 names. Store that chain in the function decl, replacing the
6209 list of names. Update the current scope to match. */
6210 DECL_ARGUMENTS (fndecl) = 0;
6212 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
6213 if (TREE_PURPOSE (parm))
6215 if (parm && TREE_PURPOSE (parm))
6217 last = TREE_PURPOSE (parm);
6218 DECL_ARGUMENTS (fndecl) = last;
6219 DECL_WEAK (last) = 0;
6221 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
6222 if (TREE_PURPOSE (parm))
6224 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6225 last = TREE_PURPOSE (parm);
6226 DECL_WEAK (last) = 0;
6228 TREE_CHAIN (last) = 0;
6231 /* If there was a previous prototype,
6232 set the DECL_ARG_TYPE of each argument according to
6233 the type previously specified, and report any mismatches. */
6235 if (current_function_prototype_arg_types)
6238 for (parm = DECL_ARGUMENTS (fndecl),
6239 type = current_function_prototype_arg_types;
6240 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
6241 != void_type_node));
6242 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6244 if (parm == 0 || type == 0
6245 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6247 if (current_function_prototype_built_in)
6248 warning (0, "number of arguments doesn%'t match "
6249 "built-in prototype");
6252 error ("number of arguments doesn%'t match prototype");
6253 error ("%Hprototype declaration",
6254 ¤t_function_prototype_locus);
6258 /* Type for passing arg must be consistent with that
6259 declared for the arg. ISO C says we take the unqualified
6260 type for parameters declared with qualified type. */
6261 if (!comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
6262 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
6264 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6265 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6267 /* Adjust argument to match prototype. E.g. a previous
6268 `int foo(float);' prototype causes
6269 `int foo(x) float x; {...}' to be treated like
6270 `int foo(float x) {...}'. This is particularly
6271 useful for argument types like uid_t. */
6272 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6274 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
6275 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
6276 && TYPE_PRECISION (TREE_TYPE (parm))
6277 < TYPE_PRECISION (integer_type_node))
6278 DECL_ARG_TYPE (parm) = integer_type_node;
6282 /* ??? Is it possible to get here with a
6283 built-in prototype or will it always have
6284 been diagnosed as conflicting with an
6285 old-style definition and discarded? */
6286 if (current_function_prototype_built_in)
6287 warning (0, "promoted argument %qD "
6288 "doesn%'t match built-in prototype", parm);
6291 pedwarn ("promoted argument %qD "
6292 "doesn%'t match prototype", parm);
6293 pedwarn ("%Hprototype declaration",
6294 ¤t_function_prototype_locus);
6300 if (current_function_prototype_built_in)
6301 warning (0, "argument %qD doesn%'t match "
6302 "built-in prototype", parm);
6305 error ("argument %qD doesn%'t match prototype", parm);
6306 error ("%Hprototype declaration",
6307 ¤t_function_prototype_locus);
6312 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6315 /* Otherwise, create a prototype that would match. */
6319 tree actual = 0, last = 0, type;
6321 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6323 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6325 TREE_CHAIN (last) = type;
6330 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6332 TREE_CHAIN (last) = type;
6336 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6337 of the type of this function, but we need to avoid having this
6338 affect the types of other similarly-typed functions, so we must
6339 first force the generation of an identical (but separate) type
6340 node for the relevant function type. The new node we create
6341 will be a variant of the main variant of the original function
6344 TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
6346 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6350 /* Store parameter declarations passed in ARG_INFO into the current
6351 function declaration. */
6354 store_parm_decls_from (struct c_arg_info *arg_info)
6356 current_function_arg_info = arg_info;
6357 store_parm_decls ();
6360 /* Store the parameter declarations into the current function declaration.
6361 This is called after parsing the parameter declarations, before
6362 digesting the body of the function.
6364 For an old-style definition, construct a prototype out of the old-style
6365 parameter declarations and inject it into the function's type. */
6368 store_parm_decls (void)
6370 tree fndecl = current_function_decl;
6373 /* The argument information block for FNDECL. */
6374 struct c_arg_info *arg_info = current_function_arg_info;
6375 current_function_arg_info = 0;
6377 /* True if this definition is written with a prototype. Note:
6378 despite C99 6.7.5.3p14, we can *not* treat an empty argument
6379 list in a function definition as equivalent to (void) -- an
6380 empty argument list specifies the function has no parameters,
6381 but only (void) sets up a prototype for future calls. */
6382 proto = arg_info->types != 0;
6385 store_parm_decls_newstyle (fndecl, arg_info);
6387 store_parm_decls_oldstyle (fndecl, arg_info);
6389 /* The next call to push_scope will be a function body. */
6391 next_is_function_body = true;
6393 /* Write a record describing this function definition to the prototypes
6394 file (if requested). */
6396 gen_aux_info_record (fndecl, 1, 0, proto);
6398 /* Initialize the RTL code for the function. */
6399 allocate_struct_function (fndecl);
6401 /* Begin the statement tree for this function. */
6402 DECL_SAVED_TREE (fndecl) = push_stmt_list ();
6404 /* ??? Insert the contents of the pending sizes list into the function
6405 to be evaluated. The only reason left to have this is
6406 void foo(int n, int array[n++])
6407 because we throw away the array type in favor of a pointer type, and
6408 thus won't naturally see the SAVE_EXPR containing the increment. All
6409 other pending sizes would be handled by gimplify_parameters. */
6412 for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t))
6413 add_stmt (TREE_VALUE (t));
6416 /* Even though we're inside a function body, we still don't want to
6417 call expand_expr to calculate the size of a variable-sized array.
6418 We haven't necessarily assigned RTL to all variables yet, so it's
6419 not safe to try to expand expressions involving them. */
6420 cfun->x_dont_save_pending_sizes_p = 1;
6423 /* Handle attribute((warn_unused_result)) on FNDECL and all its nested
6427 c_warn_unused_result_recursively (tree fndecl)
6429 struct cgraph_node *cgn;
6431 /* Handle attribute((warn_unused_result)). Relies on gimple input. */
6432 c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
6434 /* Finalize all nested functions now. */
6435 cgn = cgraph_node (fndecl);
6436 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
6437 c_warn_unused_result_recursively (cgn->decl);
6440 /* Finish up a function declaration and compile that function
6441 all the way to assembler language output. The free the storage
6442 for the function definition.
6444 This is called after parsing the body of the function definition. */
6447 finish_function (void)
6449 tree fndecl = current_function_decl;
6451 label_context_stack_se = label_context_stack_se->next;
6452 label_context_stack_vm = label_context_stack_vm->next;
6454 if (TREE_CODE (fndecl) == FUNCTION_DECL
6455 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
6457 tree args = DECL_ARGUMENTS (fndecl);
6458 for (; args; args = TREE_CHAIN (args))
6460 tree type = TREE_TYPE (args);
6461 if (INTEGRAL_TYPE_P (type)
6462 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
6463 DECL_ARG_TYPE (args) = integer_type_node;
6467 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
6468 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6470 /* Must mark the RESULT_DECL as being in this function. */
6472 if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
6473 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
6475 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
6477 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6478 != integer_type_node)
6480 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6481 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6483 pedwarn ("%Jreturn type of %qD is not %<int%>", fndecl, fndecl);
6489 tree stmt = c_finish_return (integer_zero_node);
6490 #ifdef USE_MAPPED_LOCATION
6491 /* Hack. We don't want the middle-end to warn that this return
6492 is unreachable, so we mark its location as special. Using
6493 UNKNOWN_LOCATION has the problem that it gets clobbered in
6494 annotate_one_with_locus. A cleaner solution might be to
6495 ensure ! should_carry_locus_p (stmt), but that needs a flag.
6497 SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION);
6499 /* Hack. We don't want the middle-end to warn that this
6500 return is unreachable, so put the statement on the
6502 annotate_with_file_line (stmt, input_filename, 0);
6508 /* Tie off the statement tree for this function. */
6509 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
6511 finish_fname_decls ();
6513 /* Complain if there's just no return statement. */
6514 if (warn_return_type
6515 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
6516 && !current_function_returns_value && !current_function_returns_null
6517 /* Don't complain if we are no-return. */
6518 && !current_function_returns_abnormally
6519 /* Don't warn for main(). */
6520 && !MAIN_NAME_P (DECL_NAME (fndecl))
6521 /* Or if they didn't actually specify a return type. */
6522 && !C_FUNCTION_IMPLICIT_INT (fndecl)
6523 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6524 inline function, as we might never be compiled separately. */
6525 && DECL_INLINE (fndecl))
6527 warning (OPT_Wreturn_type,
6528 "no return statement in function returning non-void");
6529 TREE_NO_WARNING (fndecl) = 1;
6532 /* With just -Wextra, complain only if function returns both with
6533 and without a value. */
6535 && current_function_returns_value
6536 && current_function_returns_null)
6537 warning (OPT_Wextra, "this function may return with or without a value");
6539 /* Store the end of the function, so that we get good line number
6540 info for the epilogue. */
6541 cfun->function_end_locus = input_location;
6543 /* If we don't have ctors/dtors sections, and this is a static
6544 constructor or destructor, it must be recorded now. */
6545 if (DECL_STATIC_CONSTRUCTOR (fndecl)
6546 && !targetm.have_ctors_dtors)
6547 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
6548 if (DECL_STATIC_DESTRUCTOR (fndecl)
6549 && !targetm.have_ctors_dtors)
6550 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
6552 /* Finalize the ELF visibility for the function. */
6553 c_determine_visibility (fndecl);
6555 /* Genericize before inlining. Delay genericizing nested functions
6556 until their parent function is genericized. Since finalizing
6557 requires GENERIC, delay that as well. */
6559 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
6560 && !undef_nested_function)
6562 if (!decl_function_context (fndecl))
6564 c_genericize (fndecl);
6565 c_warn_unused_result_recursively (fndecl);
6567 /* ??? Objc emits functions after finalizing the compilation unit.
6568 This should be cleaned up later and this conditional removed. */
6569 if (cgraph_global_info_ready)
6571 c_expand_body (fndecl);
6575 cgraph_finalize_function (fndecl, false);
6579 /* Register this function with cgraph just far enough to get it
6580 added to our parent's nested function list. Handy, since the
6581 C front end doesn't have such a list. */
6582 (void) cgraph_node (fndecl);
6586 if (!decl_function_context (fndecl))
6587 undef_nested_function = false;
6589 /* We're leaving the context of this function, so zap cfun.
6590 It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
6591 tree_rest_of_compilation. */
6593 current_function_decl = NULL;
6596 /* Generate the RTL for the body of FNDECL. */
6599 c_expand_body (tree fndecl)
6602 if (!DECL_INITIAL (fndecl)
6603 || DECL_INITIAL (fndecl) == error_mark_node)
6606 tree_rest_of_compilation (fndecl);
6608 if (DECL_STATIC_CONSTRUCTOR (fndecl)
6609 && targetm.have_ctors_dtors)
6610 targetm.asm_out.constructor (XEXP (DECL_RTL (fndecl), 0),
6611 DEFAULT_INIT_PRIORITY);
6612 if (DECL_STATIC_DESTRUCTOR (fndecl)
6613 && targetm.have_ctors_dtors)
6614 targetm.asm_out.destructor (XEXP (DECL_RTL (fndecl), 0),
6615 DEFAULT_INIT_PRIORITY);
6618 /* Check the declarations given in a for-loop for satisfying the C99
6621 check_for_loop_decls (void)
6623 struct c_binding *b;
6627 /* If we get here, declarations have been used in a for loop without
6628 the C99 for loop scope. This doesn't make much sense, so don't
6630 error ("%<for%> loop initial declaration used outside C99 mode");
6633 /* C99 subclause 6.8.5 paragraph 3:
6635 [#3] The declaration part of a for statement shall only
6636 declare identifiers for objects having storage class auto or
6639 It isn't clear whether, in this sentence, "identifiers" binds to
6640 "shall only declare" or to "objects" - that is, whether all identifiers
6641 declared must be identifiers for objects, or whether the restriction
6642 only applies to those that are. (A question on this in comp.std.c
6643 in November 2000 received no answer.) We implement the strictest
6644 interpretation, to avoid creating an extension which later causes
6647 for (b = current_scope->bindings; b; b = b->prev)
6650 tree decl = b->decl;
6655 switch (TREE_CODE (decl))
6658 if (TREE_STATIC (decl))
6659 error ("%Jdeclaration of static variable %qD in %<for%> loop "
6660 "initial declaration", decl, decl);
6661 else if (DECL_EXTERNAL (decl))
6662 error ("%Jdeclaration of %<extern%> variable %qD in %<for%> loop "
6663 "initial declaration", decl, decl);
6667 error ("%<struct %E%> declared in %<for%> loop initial declaration",
6671 error ("%<union %E%> declared in %<for%> loop initial declaration",
6675 error ("%<enum %E%> declared in %<for%> loop initial declaration",
6679 error ("%Jdeclaration of non-variable %qD in %<for%> loop "
6680 "initial declaration", decl, decl);
6685 /* Save and reinitialize the variables
6686 used during compilation of a C function. */
6689 c_push_function_context (struct function *f)
6691 struct language_function *p;
6692 p = GGC_NEW (struct language_function);
6695 p->base.x_stmt_tree = c_stmt_tree;
6696 p->x_break_label = c_break_label;
6697 p->x_cont_label = c_cont_label;
6698 p->x_switch_stack = c_switch_stack;
6699 p->arg_info = current_function_arg_info;
6700 p->returns_value = current_function_returns_value;
6701 p->returns_null = current_function_returns_null;
6702 p->returns_abnormally = current_function_returns_abnormally;
6703 p->warn_about_return_type = warn_about_return_type;
6704 p->extern_inline = current_extern_inline;
6707 /* Restore the variables used during compilation of a C function. */
6710 c_pop_function_context (struct function *f)
6712 struct language_function *p = f->language;
6714 if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
6715 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
6717 /* Stop pointing to the local nodes about to be freed. */
6718 /* But DECL_INITIAL must remain nonzero so we know this
6719 was an actual function definition. */
6720 DECL_INITIAL (current_function_decl) = error_mark_node;
6721 DECL_ARGUMENTS (current_function_decl) = 0;
6724 c_stmt_tree = p->base.x_stmt_tree;
6725 c_break_label = p->x_break_label;
6726 c_cont_label = p->x_cont_label;
6727 c_switch_stack = p->x_switch_stack;
6728 current_function_arg_info = p->arg_info;
6729 current_function_returns_value = p->returns_value;
6730 current_function_returns_null = p->returns_null;
6731 current_function_returns_abnormally = p->returns_abnormally;
6732 warn_about_return_type = p->warn_about_return_type;
6733 current_extern_inline = p->extern_inline;
6738 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
6741 c_dup_lang_specific_decl (tree decl)
6743 struct lang_decl *ld;
6745 if (!DECL_LANG_SPECIFIC (decl))
6748 ld = GGC_NEW (struct lang_decl);
6749 memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl));
6750 DECL_LANG_SPECIFIC (decl) = ld;
6753 /* The functions below are required for functionality of doing
6754 function at once processing in the C front end. Currently these
6755 functions are not called from anywhere in the C front end, but as
6756 these changes continue, that will change. */
6758 /* Returns the stmt_tree (if any) to which statements are currently
6759 being added. If there is no active statement-tree, NULL is
6763 current_stmt_tree (void)
6765 return &c_stmt_tree;
6768 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
6772 anon_aggr_type_p (tree ARG_UNUSED (node))
6777 /* Return the global value of T as a symbol. */
6780 identifier_global_value (tree t)
6782 struct c_binding *b;
6784 for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
6785 if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
6791 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
6792 otherwise the name is found in ridpointers from RID_INDEX. */
6795 record_builtin_type (enum rid rid_index, const char *name, tree type)
6799 id = ridpointers[(int) rid_index];
6801 id = get_identifier (name);
6802 decl = build_decl (TYPE_DECL, id, type);
6804 if (debug_hooks->type_decl)
6805 debug_hooks->type_decl (decl, false);
6808 /* Build the void_list_node (void_type_node having been created). */
6810 build_void_list_node (void)
6812 tree t = build_tree_list (NULL_TREE, void_type_node);
6816 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR. */
6819 build_c_parm (struct c_declspecs *specs, tree attrs,
6820 struct c_declarator *declarator)
6822 struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
6825 ret->declarator = declarator;
6829 /* Return a declarator with nested attributes. TARGET is the inner
6830 declarator to which these attributes apply. ATTRS are the
6833 struct c_declarator *
6834 build_attrs_declarator (tree attrs, struct c_declarator *target)
6836 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
6837 ret->kind = cdk_attrs;
6838 ret->declarator = target;
6839 ret->u.attrs = attrs;
6843 /* Return a declarator for a function with arguments specified by ARGS
6844 and return type specified by TARGET. */
6846 struct c_declarator *
6847 build_function_declarator (struct c_arg_info *args,
6848 struct c_declarator *target)
6850 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
6851 ret->kind = cdk_function;
6852 ret->declarator = target;
6853 ret->u.arg_info = args;
6857 /* Return a declarator for the identifier IDENT (which may be
6858 NULL_TREE for an abstract declarator). */
6860 struct c_declarator *
6861 build_id_declarator (tree ident)
6863 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
6865 ret->declarator = 0;
6867 /* Default value - may get reset to a more precise location. */
6868 ret->id_loc = input_location;
6872 /* Return something to represent absolute declarators containing a *.
6873 TARGET is the absolute declarator that the * contains.
6874 TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
6875 to apply to the pointer type. */
6877 struct c_declarator *
6878 make_pointer_declarator (struct c_declspecs *type_quals_attrs,
6879 struct c_declarator *target)
6883 struct c_declarator *itarget = target;
6884 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
6885 if (type_quals_attrs)
6887 attrs = type_quals_attrs->attrs;
6888 quals = quals_from_declspecs (type_quals_attrs);
6889 if (attrs != NULL_TREE)
6890 itarget = build_attrs_declarator (attrs, target);
6892 ret->kind = cdk_pointer;
6893 ret->declarator = itarget;
6894 ret->u.pointer_quals = quals;
6898 /* Return a pointer to a structure for an empty list of declaration
6901 struct c_declspecs *
6902 build_null_declspecs (void)
6904 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
6908 ret->typespec_word = cts_none;
6909 ret->storage_class = csc_none;
6910 ret->declspecs_seen_p = false;
6911 ret->type_seen_p = false;
6912 ret->non_sc_seen_p = false;
6913 ret->typedef_p = false;
6914 ret->tag_defined_p = false;
6915 ret->explicit_signed_p = false;
6916 ret->deprecated_p = false;
6917 ret->default_int_p = false;
6918 ret->long_p = false;
6919 ret->long_long_p = false;
6920 ret->short_p = false;
6921 ret->signed_p = false;
6922 ret->unsigned_p = false;
6923 ret->complex_p = false;
6924 ret->inline_p = false;
6925 ret->thread_p = false;
6926 ret->const_p = false;
6927 ret->volatile_p = false;
6928 ret->restrict_p = false;
6932 /* Add the type qualifier QUAL to the declaration specifiers SPECS,
6935 struct c_declspecs *
6936 declspecs_add_qual (struct c_declspecs *specs, tree qual)
6940 specs->non_sc_seen_p = true;
6941 specs->declspecs_seen_p = true;
6942 gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
6943 && C_IS_RESERVED_WORD (qual));
6944 i = C_RID_CODE (qual);
6948 dupe = specs->const_p;
6949 specs->const_p = true;
6952 dupe = specs->volatile_p;
6953 specs->volatile_p = true;
6956 dupe = specs->restrict_p;
6957 specs->restrict_p = true;
6962 if (dupe && pedantic && !flag_isoc99)
6963 pedwarn ("duplicate %qE", qual);
6967 /* Add the type specifier TYPE to the declaration specifiers SPECS,
6970 struct c_declspecs *
6971 declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec)
6973 tree type = spec.spec;
6974 specs->non_sc_seen_p = true;
6975 specs->declspecs_seen_p = true;
6976 specs->type_seen_p = true;
6977 if (TREE_DEPRECATED (type))
6978 specs->deprecated_p = true;
6980 /* Handle type specifier keywords. */
6981 if (TREE_CODE (type) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (type))
6983 enum rid i = C_RID_CODE (type);
6986 error ("two or more data types in declaration specifiers");
6989 if ((int) i <= (int) RID_LAST_MODIFIER)
6991 /* "long", "short", "signed", "unsigned" or "_Complex". */
6996 if (specs->long_long_p)
6998 error ("%<long long long%> is too long for GCC");
7003 if (specs->typespec_word == cts_double)
7005 error ("both %<long long%> and %<double%> in "
7006 "declaration specifiers");
7009 if (pedantic && !flag_isoc99 && !in_system_header
7011 pedwarn ("ISO C90 does not support %<long long%>");
7012 specs->long_long_p = 1;
7016 error ("both %<long%> and %<short%> in "
7017 "declaration specifiers");
7018 else if (specs->typespec_word == cts_void)
7019 error ("both %<long%> and %<void%> in "
7020 "declaration specifiers");
7021 else if (specs->typespec_word == cts_bool)
7022 error ("both %<long%> and %<_Bool%> in "
7023 "declaration specifiers");
7024 else if (specs->typespec_word == cts_char)
7025 error ("both %<long%> and %<char%> in "
7026 "declaration specifiers");
7027 else if (specs->typespec_word == cts_float)
7028 error ("both %<long%> and %<float%> in "
7029 "declaration specifiers");
7031 specs->long_p = true;
7034 dupe = specs->short_p;
7036 error ("both %<long%> and %<short%> in "
7037 "declaration specifiers");
7038 else if (specs->typespec_word == cts_void)
7039 error ("both %<short%> and %<void%> in "
7040 "declaration specifiers");
7041 else if (specs->typespec_word == cts_bool)
7042 error ("both %<short%> and %<_Bool%> in "
7043 "declaration specifiers");
7044 else if (specs->typespec_word == cts_char)
7045 error ("both %<short%> and %<char%> in "
7046 "declaration specifiers");
7047 else if (specs->typespec_word == cts_float)
7048 error ("both %<short%> and %<float%> in "
7049 "declaration specifiers");
7050 else if (specs->typespec_word == cts_double)
7051 error ("both %<short%> and %<double%> in "
7052 "declaration specifiers");
7054 specs->short_p = true;
7057 dupe = specs->signed_p;
7058 if (specs->unsigned_p)
7059 error ("both %<signed%> and %<unsigned%> in "
7060 "declaration specifiers");
7061 else if (specs->typespec_word == cts_void)
7062 error ("both %<signed%> and %<void%> in "
7063 "declaration specifiers");
7064 else if (specs->typespec_word == cts_bool)
7065 error ("both %<signed%> and %<_Bool%> in "
7066 "declaration specifiers");
7067 else if (specs->typespec_word == cts_float)
7068 error ("both %<signed%> and %<float%> in "
7069 "declaration specifiers");
7070 else if (specs->typespec_word == cts_double)
7071 error ("both %<signed%> and %<double%> in "
7072 "declaration specifiers");
7074 specs->signed_p = true;
7077 dupe = specs->unsigned_p;
7078 if (specs->signed_p)
7079 error ("both %<signed%> and %<unsigned%> in "
7080 "declaration specifiers");
7081 else if (specs->typespec_word == cts_void)
7082 error ("both %<unsigned%> and %<void%> in "
7083 "declaration specifiers");
7084 else if (specs->typespec_word == cts_bool)
7085 error ("both %<unsigned%> and %<_Bool%> in "
7086 "declaration specifiers");
7087 else if (specs->typespec_word == cts_float)
7088 error ("both %<unsigned%> and %<float%> in "
7089 "declaration specifiers");
7090 else if (specs->typespec_word == cts_double)
7091 error ("both %<unsigned%> and %<double%> in "
7092 "declaration specifiers");
7094 specs->unsigned_p = true;
7097 dupe = specs->complex_p;
7098 if (pedantic && !flag_isoc99 && !in_system_header)
7099 pedwarn ("ISO C90 does not support complex types");
7100 if (specs->typespec_word == cts_void)
7101 error ("both %<complex%> and %<void%> in "
7102 "declaration specifiers");
7103 else if (specs->typespec_word == cts_bool)
7104 error ("both %<complex%> and %<_Bool%> in "
7105 "declaration specifiers");
7107 specs->complex_p = true;
7114 error ("duplicate %qE", type);
7120 /* "void", "_Bool", "char", "int", "float" or "double". */
7121 if (specs->typespec_word != cts_none)
7123 error ("two or more data types in declaration specifiers");
7130 error ("both %<long%> and %<void%> in "
7131 "declaration specifiers");
7132 else if (specs->short_p)
7133 error ("both %<short%> and %<void%> in "
7134 "declaration specifiers");
7135 else if (specs->signed_p)
7136 error ("both %<signed%> and %<void%> in "
7137 "declaration specifiers");
7138 else if (specs->unsigned_p)
7139 error ("both %<unsigned%> and %<void%> in "
7140 "declaration specifiers");
7141 else if (specs->complex_p)
7142 error ("both %<complex%> and %<void%> in "
7143 "declaration specifiers");
7145 specs->typespec_word = cts_void;
7149 error ("both %<long%> and %<_Bool%> in "
7150 "declaration specifiers");
7151 else if (specs->short_p)
7152 error ("both %<short%> and %<_Bool%> in "
7153 "declaration specifiers");
7154 else if (specs->signed_p)
7155 error ("both %<signed%> and %<_Bool%> in "
7156 "declaration specifiers");
7157 else if (specs->unsigned_p)
7158 error ("both %<unsigned%> and %<_Bool%> in "
7159 "declaration specifiers");
7160 else if (specs->complex_p)
7161 error ("both %<complex%> and %<_Bool%> in "
7162 "declaration specifiers");
7164 specs->typespec_word = cts_bool;
7168 error ("both %<long%> and %<char%> in "
7169 "declaration specifiers");
7170 else if (specs->short_p)
7171 error ("both %<short%> and %<char%> in "
7172 "declaration specifiers");
7174 specs->typespec_word = cts_char;
7177 specs->typespec_word = cts_int;
7181 error ("both %<long%> and %<float%> in "
7182 "declaration specifiers");
7183 else if (specs->short_p)
7184 error ("both %<short%> and %<float%> in "
7185 "declaration specifiers");
7186 else if (specs->signed_p)
7187 error ("both %<signed%> and %<float%> in "
7188 "declaration specifiers");
7189 else if (specs->unsigned_p)
7190 error ("both %<unsigned%> and %<float%> in "
7191 "declaration specifiers");
7193 specs->typespec_word = cts_float;
7196 if (specs->long_long_p)
7197 error ("both %<long long%> and %<double%> in "
7198 "declaration specifiers");
7199 else if (specs->short_p)
7200 error ("both %<short%> and %<double%> in "
7201 "declaration specifiers");
7202 else if (specs->signed_p)
7203 error ("both %<signed%> and %<double%> in "
7204 "declaration specifiers");
7205 else if (specs->unsigned_p)
7206 error ("both %<unsigned%> and %<double%> in "
7207 "declaration specifiers");
7209 specs->typespec_word = cts_double;
7212 /* ObjC reserved word "id", handled below. */
7218 /* Now we have a typedef (a TYPE_DECL node), an identifier (some
7219 form of ObjC type, cases such as "int" and "long" being handled
7220 above), a TYPE (struct, union, enum and typeof specifiers) or an
7221 ERROR_MARK. In none of these cases may there have previously
7222 been any type specifiers. */
7223 if (specs->type || specs->typespec_word != cts_none
7224 || specs->long_p || specs->short_p || specs->signed_p
7225 || specs->unsigned_p || specs->complex_p)
7226 error ("two or more data types in declaration specifiers");
7227 else if (TREE_CODE (type) == TYPE_DECL)
7229 if (TREE_TYPE (type) == error_mark_node)
7230 ; /* Allow the type to default to int to avoid cascading errors. */
7233 specs->type = TREE_TYPE (type);
7234 specs->decl_attr = DECL_ATTRIBUTES (type);
7235 specs->typedef_p = true;
7236 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
7239 else if (TREE_CODE (type) == IDENTIFIER_NODE)
7241 tree t = lookup_name (type);
7242 if (!t || TREE_CODE (t) != TYPE_DECL)
7243 error ("%qE fails to be a typedef or built in type", type);
7244 else if (TREE_TYPE (t) == error_mark_node)
7247 specs->type = TREE_TYPE (t);
7249 else if (TREE_CODE (type) != ERROR_MARK)
7251 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref)
7252 specs->tag_defined_p = true;
7253 if (spec.kind == ctsk_typeof)
7254 specs->typedef_p = true;
7261 /* Add the storage class specifier or function specifier SCSPEC to the
7262 declaration specifiers SPECS, returning SPECS. */
7264 struct c_declspecs *
7265 declspecs_add_scspec (struct c_declspecs *specs, tree scspec)
7268 enum c_storage_class n = csc_none;
7270 specs->declspecs_seen_p = true;
7271 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
7272 && C_IS_RESERVED_WORD (scspec));
7273 i = C_RID_CODE (scspec);
7274 if (extra_warnings && specs->non_sc_seen_p)
7275 warning (OPT_Wextra, "%qE is not at beginning of declaration", scspec);
7279 /* C99 permits duplicate inline. Although of doubtful utility,
7280 it seems simplest to permit it in gnu89 mode as well, as
7281 there is also little utility in maintaining this as a
7282 difference between gnu89 and C99 inline. */
7284 specs->inline_p = true;
7287 dupe = specs->thread_p;
7288 if (specs->storage_class == csc_auto)
7289 error ("%<__thread%> used with %<auto%>");
7290 else if (specs->storage_class == csc_register)
7291 error ("%<__thread%> used with %<register%>");
7292 else if (specs->storage_class == csc_typedef)
7293 error ("%<__thread%> used with %<typedef%>");
7295 specs->thread_p = true;
7302 /* Diagnose "__thread extern". */
7303 if (specs->thread_p)
7304 error ("%<__thread%> before %<extern%>");
7311 /* Diagnose "__thread static". */
7312 if (specs->thread_p)
7313 error ("%<__thread%> before %<static%>");
7321 if (n != csc_none && n == specs->storage_class)
7324 error ("duplicate %qE", scspec);
7327 if (specs->storage_class != csc_none && n != specs->storage_class)
7329 error ("multiple storage classes in declaration specifiers");
7333 specs->storage_class = n;
7334 if (n != csc_extern && n != csc_static && specs->thread_p)
7336 error ("%<__thread%> used with %qE", scspec);
7337 specs->thread_p = false;
7344 /* Add the attributes ATTRS to the declaration specifiers SPECS,
7347 struct c_declspecs *
7348 declspecs_add_attrs (struct c_declspecs *specs, tree attrs)
7350 specs->attrs = chainon (attrs, specs->attrs);
7351 specs->declspecs_seen_p = true;
7355 /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
7356 specifiers with any other type specifier to determine the resulting
7357 type. This is where ISO C checks on complex types are made, since
7358 "_Complex long" is a prefix of the valid ISO C type "_Complex long
7361 struct c_declspecs *
7362 finish_declspecs (struct c_declspecs *specs)
7364 /* If a type was specified as a whole, we have no modifiers and are
7366 if (specs->type != NULL_TREE)
7368 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
7369 && !specs->signed_p && !specs->unsigned_p
7370 && !specs->complex_p);
7374 /* If none of "void", "_Bool", "char", "int", "float" or "double"
7375 has been specified, treat it as "int" unless "_Complex" is
7376 present and there are no other specifiers. If we just have
7377 "_Complex", it is equivalent to "_Complex double", but e.g.
7378 "_Complex short" is equivalent to "_Complex short int". */
7379 if (specs->typespec_word == cts_none)
7381 if (specs->long_p || specs->short_p
7382 || specs->signed_p || specs->unsigned_p)
7384 specs->typespec_word = cts_int;
7386 else if (specs->complex_p)
7388 specs->typespec_word = cts_double;
7390 pedwarn ("ISO C does not support plain %<complex%> meaning "
7391 "%<double complex%>");
7395 specs->typespec_word = cts_int;
7396 specs->default_int_p = true;
7397 /* We don't diagnose this here because grokdeclarator will
7398 give more specific diagnostics according to whether it is
7399 a function definition. */
7403 /* If "signed" was specified, record this to distinguish "int" and
7404 "signed int" in the case of a bit-field with
7405 -funsigned-bitfields. */
7406 specs->explicit_signed_p = specs->signed_p;
7408 /* Now compute the actual type. */
7409 switch (specs->typespec_word)
7412 gcc_assert (!specs->long_p && !specs->short_p
7413 && !specs->signed_p && !specs->unsigned_p
7414 && !specs->complex_p);
7415 specs->type = void_type_node;
7418 gcc_assert (!specs->long_p && !specs->short_p
7419 && !specs->signed_p && !specs->unsigned_p
7420 && !specs->complex_p);
7421 specs->type = boolean_type_node;
7424 gcc_assert (!specs->long_p && !specs->short_p);
7425 gcc_assert (!(specs->signed_p && specs->unsigned_p));
7426 if (specs->signed_p)
7427 specs->type = signed_char_type_node;
7428 else if (specs->unsigned_p)
7429 specs->type = unsigned_char_type_node;
7431 specs->type = char_type_node;
7432 if (specs->complex_p)
7435 pedwarn ("ISO C does not support complex integer types");
7436 specs->type = build_complex_type (specs->type);
7440 gcc_assert (!(specs->long_p && specs->short_p));
7441 gcc_assert (!(specs->signed_p && specs->unsigned_p));
7442 if (specs->long_long_p)
7443 specs->type = (specs->unsigned_p
7444 ? long_long_unsigned_type_node
7445 : long_long_integer_type_node);
7446 else if (specs->long_p)
7447 specs->type = (specs->unsigned_p
7448 ? long_unsigned_type_node
7449 : long_integer_type_node);
7450 else if (specs->short_p)
7451 specs->type = (specs->unsigned_p
7452 ? short_unsigned_type_node
7453 : short_integer_type_node);
7455 specs->type = (specs->unsigned_p
7456 ? unsigned_type_node
7457 : integer_type_node);
7458 if (specs->complex_p)
7461 pedwarn ("ISO C does not support complex integer types");
7462 specs->type = build_complex_type (specs->type);
7466 gcc_assert (!specs->long_p && !specs->short_p
7467 && !specs->signed_p && !specs->unsigned_p);
7468 specs->type = (specs->complex_p
7469 ? complex_float_type_node
7473 gcc_assert (!specs->long_long_p && !specs->short_p
7474 && !specs->signed_p && !specs->unsigned_p);
7477 specs->type = (specs->complex_p
7478 ? complex_long_double_type_node
7479 : long_double_type_node);
7483 specs->type = (specs->complex_p
7484 ? complex_double_type_node
7485 : double_type_node);
7495 /* Synthesize a function which calls all the global ctors or global
7496 dtors in this file. This is only used for targets which do not
7497 support .ctors/.dtors sections. FIXME: Migrate into cgraph. */
7499 build_cdtor (int method_type, tree cdtors)
7506 for (; cdtors; cdtors = TREE_CHAIN (cdtors))
7507 append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
7510 cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
7513 /* Perform final processing on one file scope's declarations (or the
7514 external scope's declarations), GLOBALS. */
7516 c_write_global_declarations_1 (tree globals)
7518 size_t len = list_length (globals);
7519 tree *vec = XNEWVEC (tree, len);
7523 /* Process the decls in the order they were written. */
7524 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
7527 /* Check for used but undefined static functions using the C
7528 standard's definition of "used", and set TREE_NO_WARNING so
7529 that check_global_declarations doesn't repeat the check. */
7530 if (TREE_CODE (decl) == FUNCTION_DECL
7531 && DECL_INITIAL (decl) == 0
7532 && DECL_EXTERNAL (decl)
7533 && !TREE_PUBLIC (decl)
7534 && C_DECL_USED (decl))
7536 pedwarn ("%J%qF used but never defined", decl, decl);
7537 TREE_NO_WARNING (decl) = 1;
7541 wrapup_global_declarations (vec, len);
7542 check_global_declarations (vec, len);
7548 c_write_global_declarations (void)
7552 /* We don't want to do this if generating a PCH. */
7556 /* Don't waste time on further processing if -fsyntax-only or we've
7557 encountered errors. */
7558 if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in))
7561 /* Close the external scope. */
7562 ext_block = pop_scope ();
7564 gcc_assert (!current_scope);
7566 /* Process all file scopes in this compilation, and the external_scope,
7567 through wrapup_global_declarations and check_global_declarations. */
7568 for (t = all_translation_units; t; t = TREE_CHAIN (t))
7569 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
7570 c_write_global_declarations_1 (BLOCK_VARS (ext_block));
7572 /* Generate functions to call static constructors and destructors
7573 for targets that do not support .ctors/.dtors sections. These
7574 functions have magic names which are detected by collect2. */
7575 build_cdtor ('I', static_ctors); static_ctors = 0;
7576 build_cdtor ('D', static_dtors); static_dtors = 0;
7578 /* We're done parsing; proceed to optimize and emit assembly.
7579 FIXME: shouldn't be the front end's responsibility to call this. */
7583 #include "gt-c-decl.h"