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, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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"
56 #include "tree-iterator.h"
57 #include "diagnostic.h"
58 #include "tree-dump.h"
63 #include "langhooks-def.h"
64 #include "pointer-set.h"
68 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
70 { NORMAL, /* Ordinary declaration */
71 FUNCDEF, /* Function definition */
72 PARM, /* Declaration of parm before function body */
73 FIELD, /* Declaration inside struct or union */
74 TYPENAME}; /* Typename (inside cast or sizeof) */
76 /* States indicating how grokdeclarator() should handle declspecs marked
77 with __attribute__((deprecated)). An object declared as
78 __attribute__((deprecated)) suppresses warnings of uses of other
81 enum deprecated_states {
87 /* Nonzero if we have seen an invalid cross reference
88 to a struct, union, or enum, but not yet printed the message. */
89 tree pending_invalid_xref;
91 /* File and line to appear in the eventual error message. */
92 location_t pending_invalid_xref_location;
94 /* True means we've initialized exception handling. */
95 bool c_eh_initialized_p;
97 /* The file and line that the prototype came from if this is an
98 old-style definition; used for diagnostics in
99 store_parm_decls_oldstyle. */
101 static location_t current_function_prototype_locus;
103 /* Whether this prototype was built-in. */
105 static bool current_function_prototype_built_in;
107 /* The argument type information of this prototype. */
109 static tree current_function_prototype_arg_types;
111 /* The argument information structure for the function currently being
114 static struct c_arg_info *current_function_arg_info;
116 /* The obstack on which parser and related data structures, which are
117 not live beyond their top-level declaration or definition, are
119 struct obstack parser_obstack;
121 /* The current statement tree. */
123 static GTY(()) struct stmt_tree_s c_stmt_tree;
125 /* State saving variables. */
129 /* Linked list of TRANSLATION_UNIT_DECLS for the translation units
130 included in this invocation. Note that the current translation
131 unit is not included in this list. */
133 static GTY(()) tree all_translation_units;
135 /* A list of decls to be made automatically visible in each file scope. */
136 static GTY(()) tree visible_builtins;
138 /* Set to 0 at beginning of a function definition, set to 1 if
139 a return statement that specifies a return value is seen. */
141 int current_function_returns_value;
143 /* Set to 0 at beginning of a function definition, set to 1 if
144 a return statement with no argument is seen. */
146 int current_function_returns_null;
148 /* Set to 0 at beginning of a function definition, set to 1 if
149 a call to a noreturn function is seen. */
151 int current_function_returns_abnormally;
153 /* Set to nonzero by `grokdeclarator' for a function
154 whose return type is defaulted, if warnings for this are desired. */
156 static int warn_about_return_type;
158 /* Nonzero when the current toplevel function contains a declaration
159 of a nested function which is never defined. */
161 static bool undef_nested_function;
163 /* True means global_bindings_p should return false even if the scope stack
164 says we are in file scope. */
165 bool c_override_global_bindings_to_false;
168 /* Each c_binding structure describes one binding of an identifier to
169 a decl. All the decls in a scope - irrespective of namespace - are
170 chained together by the ->prev field, which (as the name implies)
171 runs in reverse order. All the decls in a given namespace bound to
172 a given identifier are chained by the ->shadowed field, which runs
173 from inner to outer scopes.
175 The ->decl field usually points to a DECL node, but there are two
176 exceptions. In the namespace of type tags, the bound entity is a
177 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
178 identifier is encountered, it is bound to error_mark_node to
179 suppress further errors about that identifier in the current
182 The ->type field stores the type of the declaration in this scope;
183 if NULL, the type is the type of the ->decl field. This is only of
184 relevance for objects with external or internal linkage which may
185 be redeclared in inner scopes, forming composite types that only
186 persist for the duration of those scopes. In the external scope,
187 this stores the composite of all the types declared for this
188 object, visible or not. The ->inner_comp field (used only at file
189 scope) stores whether an incomplete array type at file scope was
190 completed at an inner scope to an array size other than 1.
192 The depth field is copied from the scope structure that holds this
193 decl. It is used to preserve the proper ordering of the ->shadowed
194 field (see bind()) and also for a handful of special-case checks.
195 Finally, the invisible bit is true for a decl which should be
196 ignored for purposes of normal name lookup, and the nested bit is
197 true for a decl that's been bound a second time in an inner scope;
198 in all such cases, the binding in the outer scope will have its
199 invisible bit true. */
201 struct GTY((chain_next ("%h.prev"))) c_binding {
202 tree decl; /* the decl bound */
203 tree type; /* the type in this scope */
204 tree id; /* the identifier it's bound to */
205 struct c_binding *prev; /* the previous decl in this scope */
206 struct c_binding *shadowed; /* the innermost decl shadowed by this one */
207 unsigned int depth : 28; /* depth of this scope */
208 BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */
209 BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */
210 BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
212 location_t locus; /* location for nested bindings */
214 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
215 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
216 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
217 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
219 #define I_SYMBOL_BINDING(node) \
220 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding)
221 #define I_SYMBOL_DECL(node) \
222 (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
224 #define I_TAG_BINDING(node) \
225 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->tag_binding)
226 #define I_TAG_DECL(node) \
227 (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
229 #define I_LABEL_BINDING(node) \
230 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->label_binding)
231 #define I_LABEL_DECL(node) \
232 (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
234 /* Each C symbol points to three linked lists of c_binding structures.
235 These describe the values of the identifier in the three different
236 namespaces defined by the language. */
238 struct GTY(()) lang_identifier {
239 struct c_common_identifier common_id;
240 struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
241 struct c_binding *tag_binding; /* struct/union/enum tags */
242 struct c_binding *label_binding; /* labels */
245 /* Validate c-lang.c's assumptions. */
246 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
247 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
249 /* The resulting tree type. */
251 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
252 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))"))) lang_tree_node
254 union tree_node GTY ((tag ("0"),
255 desc ("tree_node_structure (&%h)")))
257 struct lang_identifier GTY ((tag ("1"))) identifier;
260 /* Each c_scope structure describes the complete contents of one
261 scope. Four scopes are distinguished specially: the innermost or
262 current scope, the innermost function scope, the file scope (always
263 the second to outermost) and the outermost or external scope.
265 Most declarations are recorded in the current scope.
267 All normal label declarations are recorded in the innermost
268 function scope, as are bindings of undeclared identifiers to
269 error_mark_node. (GCC permits nested functions as an extension,
270 hence the 'innermost' qualifier.) Explicitly declared labels
271 (using the __label__ extension) appear in the current scope.
273 Being in the file scope (current_scope == file_scope) causes
274 special behavior in several places below. Also, under some
275 conditions the Objective-C front end records declarations in the
276 file scope even though that isn't the current scope.
278 All declarations with external linkage are recorded in the external
279 scope, even if they aren't visible there; this models the fact that
280 such declarations are visible to the entire program, and (with a
281 bit of cleverness, see pushdecl) allows diagnosis of some violations
282 of C99 6.2.2p7 and 6.2.7p2:
284 If, within the same translation unit, the same identifier appears
285 with both internal and external linkage, the behavior is
288 All declarations that refer to the same object or function shall
289 have compatible type; otherwise, the behavior is undefined.
291 Initially only the built-in declarations, which describe compiler
292 intrinsic functions plus a subset of the standard library, are in
295 The order of the blocks list matters, and it is frequently appended
296 to. To avoid having to walk all the way to the end of the list on
297 each insertion, or reverse the list later, we maintain a pointer to
298 the last list entry. (FIXME: It should be feasible to use a reversed
301 The bindings list is strictly in reverse order of declarations;
302 pop_scope relies on this. */
305 struct GTY((chain_next ("%h.outer"))) c_scope {
306 /* The scope containing this one. */
307 struct c_scope *outer;
309 /* The next outermost function scope. */
310 struct c_scope *outer_function;
312 /* All bindings in this scope. */
313 struct c_binding *bindings;
315 /* For each scope (except the global one), a chain of BLOCK nodes
316 for all the scopes that were entered and exited one level down. */
320 /* The depth of this scope. Used to keep the ->shadowed chain of
321 bindings sorted innermost to outermost. */
322 unsigned int depth : 28;
324 /* True if we are currently filling this scope with parameter
326 BOOL_BITFIELD parm_flag : 1;
328 /* True if we saw [*] in this scope. Used to give an error messages
329 if these appears in a function definition. */
330 BOOL_BITFIELD had_vla_unspec : 1;
332 /* True if we already complained about forward parameter decls
333 in this scope. This prevents double warnings on
334 foo (int a; int b; ...) */
335 BOOL_BITFIELD warned_forward_parm_decls : 1;
337 /* True if this is the outermost block scope of a function body.
338 This scope contains the parameters, the local variables declared
339 in the outermost block, and all the labels (except those in
340 nested functions, or declared at block scope with __label__). */
341 BOOL_BITFIELD function_body : 1;
343 /* True means make a BLOCK for this scope no matter what. */
344 BOOL_BITFIELD keep : 1;
347 /* The scope currently in effect. */
349 static GTY(()) struct c_scope *current_scope;
351 /* The innermost function scope. Ordinary (not explicitly declared)
352 labels, bindings to error_mark_node, and the lazily-created
353 bindings of __func__ and its friends get this scope. */
355 static GTY(()) struct c_scope *current_function_scope;
357 /* The C file scope. This is reset for each input translation unit. */
359 static GTY(()) struct c_scope *file_scope;
361 /* The outermost scope. This is used for all declarations with
362 external linkage, and only these, hence the name. */
364 static GTY(()) struct c_scope *external_scope;
366 /* A chain of c_scope structures awaiting reuse. */
368 static GTY((deletable)) struct c_scope *scope_freelist;
370 /* A chain of c_binding structures awaiting reuse. */
372 static GTY((deletable)) struct c_binding *binding_freelist;
374 /* Append VAR to LIST in scope SCOPE. */
375 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
376 struct c_scope *s_ = (scope); \
378 if (s_->list##_last) \
379 BLOCK_CHAIN (s_->list##_last) = d_; \
382 s_->list##_last = d_; \
385 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
386 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
387 struct c_scope *t_ = (tscope); \
388 struct c_scope *f_ = (fscope); \
390 BLOCK_CHAIN (t_->to##_last) = f_->from; \
393 t_->to##_last = f_->from##_last; \
396 /* A c_inline_static structure stores details of a static identifier
397 referenced in a definition of a function that may be an inline
398 definition if no subsequent declaration of that function uses
399 "extern" or does not use "inline". */
401 struct GTY((chain_next ("%h.next"))) c_inline_static {
402 /* The location for a diagnostic. */
405 /* The function that may be an inline definition. */
408 /* The object or function referenced. */
411 /* What sort of reference this is. */
412 enum c_inline_static_type type;
414 /* The next such structure or NULL. */
415 struct c_inline_static *next;
418 /* List of static identifiers used or referenced in functions that may
419 be inline definitions. */
420 static GTY(()) struct c_inline_static *c_inline_statics;
422 /* True means unconditionally make a BLOCK for the next scope pushed. */
424 static bool keep_next_level_flag;
426 /* True means the next call to push_scope will be the outermost scope
427 of a function body, so do not push a new scope, merely cease
428 expecting parameter decls. */
430 static bool next_is_function_body;
432 /* Forward declarations. */
433 static tree lookup_name_in_scope (tree, struct c_scope *);
434 static tree c_make_fname_decl (tree, int);
435 static tree grokdeclarator (const struct c_declarator *,
436 struct c_declspecs *,
437 enum decl_context, bool, tree *, tree *, tree *,
438 bool *, enum deprecated_states);
439 static tree grokparms (struct c_arg_info *, bool);
440 static void layout_array_type (tree);
442 /* T is a statement. Add it to the statement-tree. This is the
443 C/ObjC version--C++ has a slightly different version of this
449 enum tree_code code = TREE_CODE (t);
451 if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
453 if (!EXPR_HAS_LOCATION (t))
454 SET_EXPR_LOCATION (t, input_location);
457 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
458 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
460 /* Add T to the statement-tree. Non-side-effect statements need to be
461 recorded during statement expressions. */
462 append_to_statement_list_force (t, &cur_stmt_list);
469 c_print_identifier (FILE *file, tree node, int indent)
471 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
472 print_node (file, "tag", I_TAG_DECL (node), indent + 4);
473 print_node (file, "label", I_LABEL_DECL (node), indent + 4);
474 if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN)
476 tree rid = ridpointers[C_RID_CODE (node)];
477 indent_to (file, indent + 4);
478 fprintf (file, "rid %p \"%s\"",
479 (void *) rid, IDENTIFIER_POINTER (rid));
483 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
484 which may be any of several kinds of DECL or TYPE or error_mark_node,
485 in the scope SCOPE. */
487 bind (tree name, tree decl, struct c_scope *scope, bool invisible,
488 bool nested, location_t locus)
490 struct c_binding *b, **here;
492 if (binding_freelist)
494 b = binding_freelist;
495 binding_freelist = b->prev;
498 b = GGC_NEW (struct c_binding);
503 b->depth = scope->depth;
504 b->invisible = invisible;
511 b->prev = scope->bindings;
517 switch (TREE_CODE (decl))
519 case LABEL_DECL: here = &I_LABEL_BINDING (name); break;
522 case RECORD_TYPE: here = &I_TAG_BINDING (name); break;
528 case ERROR_MARK: here = &I_SYMBOL_BINDING (name); break;
534 /* Locate the appropriate place in the chain of shadowed decls
535 to insert this binding. Normally, scope == current_scope and
536 this does nothing. */
537 while (*here && (*here)->depth > scope->depth)
538 here = &(*here)->shadowed;
544 /* Clear the binding structure B, stick it on the binding_freelist,
545 and return the former value of b->prev. This is used by pop_scope
546 and get_parm_info to iterate destructively over all the bindings
547 from a given scope. */
548 static struct c_binding *
549 free_binding_and_advance (struct c_binding *b)
551 struct c_binding *prev = b->prev;
553 memset (b, 0, sizeof (struct c_binding));
554 b->prev = binding_freelist;
555 binding_freelist = b;
561 /* Hook called at end of compilation to assume 1 elt
562 for a file-scope tentative array defn that wasn't complete before. */
565 c_finish_incomplete_decl (tree decl)
567 if (TREE_CODE (decl) == VAR_DECL)
569 tree type = TREE_TYPE (decl);
570 if (type != error_mark_node
571 && TREE_CODE (type) == ARRAY_TYPE
572 && !DECL_EXTERNAL (decl)
573 && TYPE_DOMAIN (type) == 0)
575 warning (0, "array %q+D assumed to have one element", decl);
577 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
579 layout_decl (decl, 0);
584 /* Record that inline function FUNC contains a reference (location
585 LOC) to static DECL (file-scope or function-local according to
589 record_inline_static (location_t loc, tree func, tree decl,
590 enum c_inline_static_type type)
592 struct c_inline_static *csi = GGC_NEW (struct c_inline_static);
594 csi->function = func;
595 csi->static_decl = decl;
597 csi->next = c_inline_statics;
598 c_inline_statics = csi;
601 /* Check for references to static declarations in inline functions at
602 the end of the translation unit and diagnose them if the functions
603 are still inline definitions. */
606 check_inline_statics (void)
608 struct c_inline_static *csi;
609 for (csi = c_inline_statics; csi; csi = csi->next)
611 if (DECL_EXTERNAL (csi->function))
615 pedwarn (csi->location, 0,
616 "%qD is static but used in inline function %qD "
617 "which is not static", csi->static_decl, csi->function);
620 pedwarn (csi->location, 0,
621 "%q+D is static but declared in inline function %qD "
622 "which is not static", csi->static_decl, csi->function);
628 c_inline_statics = NULL;
631 /* The Objective-C front-end often needs to determine the current scope. */
634 objc_get_current_scope (void)
636 return current_scope;
639 /* The following function is used only by Objective-C. It needs to live here
640 because it accesses the innards of c_scope. */
643 objc_mark_locals_volatile (void *enclosing_blk)
645 struct c_scope *scope;
648 for (scope = current_scope;
649 scope && scope != enclosing_blk;
650 scope = scope->outer)
652 for (b = scope->bindings; b; b = b->prev)
653 objc_volatilize_decl (b->decl);
655 /* Do not climb up past the current function. */
656 if (scope->function_body)
661 /* Nonzero if we are currently in file scope. */
664 global_bindings_p (void)
666 return (current_scope == file_scope && !c_override_global_bindings_to_false
672 keep_next_level (void)
674 keep_next_level_flag = true;
677 /* Identify this scope as currently being filled with parameters. */
680 declare_parm_level (void)
682 current_scope->parm_flag = true;
688 if (next_is_function_body)
690 /* This is the transition from the parameters to the top level
691 of the function body. These are the same scope
692 (C99 6.2.1p4,6) so we do not push another scope structure.
693 next_is_function_body is set only by store_parm_decls, which
694 in turn is called when and only when we are about to
695 encounter the opening curly brace for the function body.
697 The outermost block of a function always gets a BLOCK node,
698 because the debugging output routines expect that each
699 function has at least one BLOCK. */
700 current_scope->parm_flag = false;
701 current_scope->function_body = true;
702 current_scope->keep = true;
703 current_scope->outer_function = current_function_scope;
704 current_function_scope = current_scope;
706 keep_next_level_flag = false;
707 next_is_function_body = false;
711 struct c_scope *scope;
714 scope = scope_freelist;
715 scope_freelist = scope->outer;
718 scope = GGC_CNEW (struct c_scope);
720 scope->keep = keep_next_level_flag;
721 scope->outer = current_scope;
722 scope->depth = current_scope ? (current_scope->depth + 1) : 0;
724 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but
726 if (current_scope && scope->depth == 0)
729 sorry ("GCC supports only %u nested scopes", scope->depth);
732 current_scope = scope;
733 keep_next_level_flag = false;
737 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */
740 set_type_context (tree type, tree context)
742 for (type = TYPE_MAIN_VARIANT (type); type;
743 type = TYPE_NEXT_VARIANT (type))
744 TYPE_CONTEXT (type) = context;
747 /* Exit a scope. Restore the state of the identifier-decl mappings
748 that were in effect when this scope was entered. Return a BLOCK
749 node containing all the DECLs in this scope that are of interest
750 to debug info generation. */
755 struct c_scope *scope = current_scope;
756 tree block, context, p;
759 bool functionbody = scope->function_body;
760 bool keep = functionbody || scope->keep || scope->bindings;
762 c_end_vm_scope (scope->depth);
764 /* If appropriate, create a BLOCK to record the decls for the life
769 block = make_node (BLOCK);
770 BLOCK_SUBBLOCKS (block) = scope->blocks;
771 TREE_USED (block) = 1;
773 /* In each subblock, record that this is its superior. */
774 for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
775 BLOCK_SUPERCONTEXT (p) = block;
777 BLOCK_VARS (block) = 0;
780 /* The TYPE_CONTEXTs for all of the tagged types belonging to this
781 scope must be set so that they point to the appropriate
782 construct, i.e. either to the current FUNCTION_DECL node, or
783 else to the BLOCK node we just constructed.
785 Note that for tagged types whose scope is just the formal
786 parameter list for some function type specification, we can't
787 properly set their TYPE_CONTEXTs here, because we don't have a
788 pointer to the appropriate FUNCTION_TYPE node readily available
789 to us. For those cases, the TYPE_CONTEXTs of the relevant tagged
790 type nodes get set in `grokdeclarator' as soon as we have created
791 the FUNCTION_TYPE node which will represent the "scope" for these
792 "parameter list local" tagged types. */
793 if (scope->function_body)
794 context = current_function_decl;
795 else if (scope == file_scope)
797 tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
798 TREE_CHAIN (file_decl) = all_translation_units;
799 all_translation_units = file_decl;
805 /* Clear all bindings in this scope. */
806 for (b = scope->bindings; b; b = free_binding_and_advance (b))
809 switch (TREE_CODE (p))
812 /* Warnings for unused labels, errors for undefined labels. */
813 if (TREE_USED (p) && !DECL_INITIAL (p))
815 error ("label %q+D used but not defined", p);
816 DECL_INITIAL (p) = error_mark_node;
819 warn_for_unused_label (p);
821 /* Labels go in BLOCK_VARS. */
822 TREE_CHAIN (p) = BLOCK_VARS (block);
823 BLOCK_VARS (block) = p;
824 gcc_assert (I_LABEL_BINDING (b->id) == b);
825 I_LABEL_BINDING (b->id) = b->shadowed;
831 set_type_context (p, context);
833 /* Types may not have tag-names, in which case the type
834 appears in the bindings list with b->id NULL. */
837 gcc_assert (I_TAG_BINDING (b->id) == b);
838 I_TAG_BINDING (b->id) = b->shadowed;
843 /* Propagate TREE_ADDRESSABLE from nested functions to their
844 containing functions. */
845 if (!TREE_ASM_WRITTEN (p)
846 && DECL_INITIAL (p) != 0
847 && TREE_ADDRESSABLE (p)
848 && DECL_ABSTRACT_ORIGIN (p) != 0
849 && DECL_ABSTRACT_ORIGIN (p) != p)
850 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
851 if (!DECL_EXTERNAL (p)
853 && scope != file_scope
854 && scope != external_scope)
856 error ("nested function %q+D declared but never defined", p);
857 undef_nested_function = true;
859 else if (DECL_DECLARED_INLINE_P (p)
861 && !DECL_INITIAL (p))
863 /* C99 6.7.4p6: "a function with external linkage... declared
864 with an inline function specifier ... shall also be defined
865 in the same translation unit." */
866 if (!flag_gnu89_inline)
867 pedwarn (input_location, 0,
868 "inline function %q+D declared but never defined", p);
869 DECL_EXTERNAL (p) = 1;
875 /* Warnings for unused variables. */
877 && !TREE_NO_WARNING (p)
878 && !DECL_IN_SYSTEM_HEADER (p)
880 && !DECL_ARTIFICIAL (p)
881 && scope != file_scope
882 && scope != external_scope)
883 warning (OPT_Wunused_variable, "unused variable %q+D", p);
887 error ("type of array %q+D completed incompatibly with"
888 " implicit initialization", p);
895 /* All of these go in BLOCK_VARS, but only if this is the
896 binding in the home scope. */
899 TREE_CHAIN (p) = BLOCK_VARS (block);
900 BLOCK_VARS (block) = p;
902 else if (VAR_OR_FUNCTION_DECL_P (p))
904 /* For block local externs add a special
905 DECL_EXTERNAL decl for debug info generation. */
906 tree extp = copy_node (p);
908 DECL_EXTERNAL (extp) = 1;
909 TREE_STATIC (extp) = 0;
910 TREE_PUBLIC (extp) = 1;
911 DECL_INITIAL (extp) = NULL_TREE;
912 DECL_LANG_SPECIFIC (extp) = NULL;
913 DECL_CONTEXT (extp) = current_function_decl;
914 if (TREE_CODE (p) == FUNCTION_DECL)
916 DECL_RESULT (extp) = NULL_TREE;
917 DECL_SAVED_TREE (extp) = NULL_TREE;
918 DECL_STRUCT_FUNCTION (extp) = NULL;
920 if (b->locus != UNKNOWN_LOCATION)
921 DECL_SOURCE_LOCATION (extp) = b->locus;
922 TREE_CHAIN (extp) = BLOCK_VARS (block);
923 BLOCK_VARS (block) = extp;
925 /* If this is the file scope, and we are processing more
926 than one translation unit in this compilation, set
927 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
928 This makes same_translation_unit_p work, and causes
929 static declarations to be given disambiguating suffixes. */
930 if (scope == file_scope && num_in_fnames > 1)
932 DECL_CONTEXT (p) = context;
933 if (TREE_CODE (p) == TYPE_DECL)
934 set_type_context (TREE_TYPE (p), context);
938 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
939 already been put there by store_parm_decls. Unused-
940 parameter warnings are handled by function.c.
941 error_mark_node obviously does not go in BLOCK_VARS and
942 does not get unused-variable warnings. */
945 /* It is possible for a decl not to have a name. We get
946 here with b->id NULL in this case. */
949 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
950 I_SYMBOL_BINDING (b->id) = b->shadowed;
951 if (b->shadowed && b->shadowed->type)
952 TREE_TYPE (b->shadowed->decl) = b->shadowed->type;
962 /* Dispose of the block that we just made inside some higher level. */
963 if ((scope->function_body || scope == file_scope) && context)
965 DECL_INITIAL (context) = block;
966 BLOCK_SUPERCONTEXT (block) = context;
968 else if (scope->outer)
971 SCOPE_LIST_APPEND (scope->outer, blocks, block);
972 /* If we did not make a block for the scope just exited, any
973 blocks made for inner scopes must be carried forward so they
974 will later become subblocks of something else. */
975 else if (scope->blocks)
976 SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
979 /* Pop the current scope, and free the structure for reuse. */
980 current_scope = scope->outer;
981 if (scope->function_body)
982 current_function_scope = scope->outer_function;
984 memset (scope, 0, sizeof (struct c_scope));
985 scope->outer = scope_freelist;
986 scope_freelist = scope;
992 push_file_scope (void)
1000 file_scope = current_scope;
1002 start_fname_decls ();
1004 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
1005 bind (DECL_NAME (decl), decl, file_scope,
1006 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
1010 pop_file_scope (void)
1012 /* In case there were missing closebraces, get us back to the global
1014 while (current_scope != file_scope)
1017 /* __FUNCTION__ is defined at file scope (""). This
1018 call may not be necessary as my tests indicate it
1019 still works without it. */
1020 finish_fname_decls ();
1022 check_inline_statics ();
1024 /* This is the point to write out a PCH if we're doing that.
1025 In that case we do not want to do anything else. */
1028 c_common_write_pch ();
1032 /* Pop off the file scope and close this translation unit. */
1036 maybe_apply_pending_pragma_weaks ();
1037 cgraph_finalize_compilation_unit ();
1041 /* Push a definition or a declaration of struct, union or enum tag "name".
1042 "type" should be the type node.
1043 We assume that the tag "name" is not already defined.
1045 Note that the definition may really be just a forward reference.
1046 In that case, the TYPE_SIZE will be zero. */
1049 pushtag (tree name, tree type)
1051 /* Record the identifier as the type's name if it has none. */
1052 if (name && !TYPE_NAME (type))
1053 TYPE_NAME (type) = name;
1054 bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false,
1057 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1058 tagged type we just added to the current scope. This fake
1059 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1060 to output a representation of a tagged type, and it also gives
1061 us a convenient place to record the "scope start" address for the
1064 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
1066 /* An approximation for now, so we can tell this is a function-scope tag.
1067 This will be updated in pop_scope. */
1068 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1071 /* Subroutine of compare_decls. Allow harmless mismatches in return
1072 and argument types provided that the type modes match. This function
1073 return a unified type given a suitable match, and 0 otherwise. */
1076 match_builtin_function_types (tree newtype, tree oldtype)
1078 tree newrettype, oldrettype;
1079 tree newargs, oldargs;
1080 tree trytype, tryargs;
1082 /* Accept the return type of the new declaration if same modes. */
1083 oldrettype = TREE_TYPE (oldtype);
1084 newrettype = TREE_TYPE (newtype);
1086 if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype))
1089 oldargs = TYPE_ARG_TYPES (oldtype);
1090 newargs = TYPE_ARG_TYPES (newtype);
1093 while (oldargs || newargs)
1097 || !TREE_VALUE (oldargs)
1098 || !TREE_VALUE (newargs)
1099 || TYPE_MODE (TREE_VALUE (oldargs))
1100 != TYPE_MODE (TREE_VALUE (newargs)))
1103 oldargs = TREE_CHAIN (oldargs);
1104 newargs = TREE_CHAIN (newargs);
1107 trytype = build_function_type (newrettype, tryargs);
1108 return build_type_attribute_variant (trytype, TYPE_ATTRIBUTES (oldtype));
1111 /* Subroutine of diagnose_mismatched_decls. Check for function type
1112 mismatch involving an empty arglist vs a nonempty one and give clearer
1115 diagnose_arglist_conflict (tree newdecl, tree olddecl,
1116 tree newtype, tree oldtype)
1120 if (TREE_CODE (olddecl) != FUNCTION_DECL
1121 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
1122 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0)
1124 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
1127 t = TYPE_ARG_TYPES (oldtype);
1129 t = TYPE_ARG_TYPES (newtype);
1130 for (; t; t = TREE_CHAIN (t))
1132 tree type = TREE_VALUE (t);
1134 if (TREE_CHAIN (t) == 0
1135 && TYPE_MAIN_VARIANT (type) != void_type_node)
1137 inform (input_location, "a parameter list with an ellipsis can%'t match "
1138 "an empty parameter name list declaration");
1142 if (c_type_promotes_to (type) != type)
1144 inform (input_location, "an argument type that has a default promotion can%'t match "
1145 "an empty parameter name list declaration");
1151 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
1152 old-style function definition, NEWDECL is a prototype declaration.
1153 Diagnose inconsistencies in the argument list. Returns TRUE if
1154 the prototype is compatible, FALSE if not. */
1156 validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
1158 tree newargs, oldargs;
1161 #define END_OF_ARGLIST(t) ((t) == void_type_node)
1163 oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
1164 newargs = TYPE_ARG_TYPES (newtype);
1169 tree oldargtype = TREE_VALUE (oldargs);
1170 tree newargtype = TREE_VALUE (newargs);
1172 if (oldargtype == error_mark_node || newargtype == error_mark_node)
1175 oldargtype = TYPE_MAIN_VARIANT (oldargtype);
1176 newargtype = TYPE_MAIN_VARIANT (newargtype);
1178 if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
1181 /* Reaching the end of just one list means the two decls don't
1182 agree on the number of arguments. */
1183 if (END_OF_ARGLIST (oldargtype))
1185 error ("prototype for %q+D declares more arguments "
1186 "than previous old-style definition", newdecl);
1189 else if (END_OF_ARGLIST (newargtype))
1191 error ("prototype for %q+D declares fewer arguments "
1192 "than previous old-style definition", newdecl);
1196 /* Type for passing arg must be consistent with that declared
1198 else if (!comptypes (oldargtype, newargtype))
1200 error ("prototype for %q+D declares argument %d"
1201 " with incompatible type",
1206 oldargs = TREE_CHAIN (oldargs);
1207 newargs = TREE_CHAIN (newargs);
1211 /* If we get here, no errors were found, but do issue a warning
1212 for this poor-style construct. */
1213 warning (0, "prototype for %q+D follows non-prototype definition",
1216 #undef END_OF_ARGLIST
1219 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
1220 first in a pair of mismatched declarations, using the diagnostic
1223 locate_old_decl (tree decl)
1225 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1227 else if (DECL_INITIAL (decl))
1228 inform (input_location, "previous definition of %q+D was here", decl);
1229 else if (C_DECL_IMPLICIT (decl))
1230 inform (input_location, "previous implicit declaration of %q+D was here", decl);
1232 inform (input_location, "previous declaration of %q+D was here", decl);
1235 /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL.
1236 Returns true if the caller should proceed to merge the two, false
1237 if OLDDECL should simply be discarded. As a side effect, issues
1238 all necessary diagnostics for invalid or poor-style combinations.
1239 If it returns true, writes the types of NEWDECL and OLDDECL to
1240 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1241 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
1244 diagnose_mismatched_decls (tree newdecl, tree olddecl,
1245 tree *newtypep, tree *oldtypep)
1247 tree newtype, oldtype;
1248 bool pedwarned = false;
1249 bool warned = false;
1252 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \
1253 && DECL_EXTERNAL (DECL))
1255 /* If we have error_mark_node for either decl or type, just discard
1256 the previous decl - we're in an error cascade already. */
1257 if (olddecl == error_mark_node || newdecl == error_mark_node)
1259 *oldtypep = oldtype = TREE_TYPE (olddecl);
1260 *newtypep = newtype = TREE_TYPE (newdecl);
1261 if (oldtype == error_mark_node || newtype == error_mark_node)
1264 /* Two different categories of symbol altogether. This is an error
1265 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
1266 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1268 if (!(TREE_CODE (olddecl) == FUNCTION_DECL
1269 && DECL_BUILT_IN (olddecl)
1270 && !C_DECL_DECLARED_BUILTIN (olddecl)))
1272 error ("%q+D redeclared as different kind of symbol", newdecl);
1273 locate_old_decl (olddecl);
1275 else if (TREE_PUBLIC (newdecl))
1276 warning (0, "built-in function %q+D declared as non-function",
1279 warning (OPT_Wshadow, "declaration of %q+D shadows "
1280 "a built-in function", newdecl);
1284 /* Enumerators have no linkage, so may only be declared once in a
1286 if (TREE_CODE (olddecl) == CONST_DECL)
1288 error ("redeclaration of enumerator %q+D", newdecl);
1289 locate_old_decl (olddecl);
1293 if (!comptypes (oldtype, newtype))
1295 if (TREE_CODE (olddecl) == FUNCTION_DECL
1296 && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
1298 /* Accept harmless mismatch in function types.
1299 This is for the ffs and fprintf builtins. */
1300 tree trytype = match_builtin_function_types (newtype, oldtype);
1302 if (trytype && comptypes (newtype, trytype))
1303 *oldtypep = oldtype = trytype;
1306 /* If types don't match for a built-in, throw away the
1307 built-in. No point in calling locate_old_decl here, it
1308 won't print anything. */
1309 warning (0, "conflicting types for built-in function %q+D",
1314 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1315 && DECL_IS_BUILTIN (olddecl))
1317 /* A conflicting function declaration for a predeclared
1318 function that isn't actually built in. Objective C uses
1319 these. The new declaration silently overrides everything
1320 but the volatility (i.e. noreturn) indication. See also
1321 below. FIXME: Make Objective C use normal builtins. */
1322 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1325 /* Permit void foo (...) to match int foo (...) if the latter is
1326 the definition and implicit int was used. See
1327 c-torture/compile/920625-2.c. */
1328 else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
1329 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
1330 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
1331 && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
1333 pedwarned = pedwarn (input_location, 0,
1334 "conflicting types for %q+D", newdecl);
1335 /* Make sure we keep void as the return type. */
1336 TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
1337 C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
1339 /* Permit void foo (...) to match an earlier call to foo (...) with
1340 no declared type (thus, implicitly int). */
1341 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1342 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
1343 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
1344 && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
1346 pedwarned = pedwarn (input_location, 0,
1347 "conflicting types for %q+D", newdecl);
1348 /* Make sure we keep void as the return type. */
1349 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
1353 if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype))
1354 error ("conflicting type qualifiers for %q+D", newdecl);
1356 error ("conflicting types for %q+D", newdecl);
1357 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
1358 locate_old_decl (olddecl);
1363 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1364 but silently ignore the redeclaration if either is in a system
1365 header. (Conflicting redeclarations were handled above.) */
1366 if (TREE_CODE (newdecl) == TYPE_DECL)
1368 if (DECL_IN_SYSTEM_HEADER (newdecl)
1369 || DECL_IN_SYSTEM_HEADER (olddecl)
1370 || TREE_NO_WARNING (newdecl)
1371 || TREE_NO_WARNING (olddecl))
1372 return true; /* Allow OLDDECL to continue in use. */
1374 error ("redefinition of typedef %q+D", newdecl);
1375 locate_old_decl (olddecl);
1379 /* Function declarations can either be 'static' or 'extern' (no
1380 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1381 can never conflict with each other on account of linkage
1382 (6.2.2p4). Multiple definitions are not allowed (6.9p3,5) but
1383 gnu89 mode permits two definitions if one is 'extern inline' and
1384 one is not. The non- extern-inline definition supersedes the
1385 extern-inline definition. */
1387 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1389 /* If you declare a built-in function name as static, or
1390 define the built-in with an old-style definition (so we
1391 can't validate the argument list) the built-in definition is
1392 overridden, but optionally warn this was a bad choice of name. */
1393 if (DECL_BUILT_IN (olddecl)
1394 && !C_DECL_DECLARED_BUILTIN (olddecl)
1395 && (!TREE_PUBLIC (newdecl)
1396 || (DECL_INITIAL (newdecl)
1397 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
1399 warning (OPT_Wshadow, "declaration of %q+D shadows "
1400 "a built-in function", newdecl);
1401 /* Discard the old built-in function. */
1405 if (DECL_INITIAL (newdecl))
1407 if (DECL_INITIAL (olddecl))
1409 /* If both decls are in the same TU and the new declaration
1410 isn't overriding an extern inline reject the new decl.
1411 In c99, no overriding is allowed in the same translation
1413 if ((!DECL_EXTERN_INLINE (olddecl)
1414 || DECL_EXTERN_INLINE (newdecl)
1415 || (!flag_gnu89_inline
1416 && (!DECL_DECLARED_INLINE_P (olddecl)
1417 || !lookup_attribute ("gnu_inline",
1418 DECL_ATTRIBUTES (olddecl)))
1419 && (!DECL_DECLARED_INLINE_P (newdecl)
1420 || !lookup_attribute ("gnu_inline",
1421 DECL_ATTRIBUTES (newdecl))))
1423 && same_translation_unit_p (newdecl, olddecl))
1425 error ("redefinition of %q+D", newdecl);
1426 locate_old_decl (olddecl);
1431 /* If we have a prototype after an old-style function definition,
1432 the argument types must be checked specially. */
1433 else if (DECL_INITIAL (olddecl)
1434 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype)
1435 && TYPE_ACTUAL_ARG_TYPES (oldtype)
1436 && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
1438 locate_old_decl (olddecl);
1441 /* A non-static declaration (even an "extern") followed by a
1442 static declaration is undefined behavior per C99 6.2.2p3-5,7.
1443 The same is true for a static forward declaration at block
1444 scope followed by a non-static declaration/definition at file
1445 scope. Static followed by non-static at the same scope is
1446 not undefined behavior, and is the most convenient way to get
1447 some effects (see e.g. what unwind-dw2-fde-glibc.c does to
1448 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
1449 we do diagnose it if -Wtraditional. */
1450 if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
1452 /* Two exceptions to the rule. If olddecl is an extern
1453 inline, or a predeclared function that isn't actually
1454 built in, newdecl silently overrides olddecl. The latter
1455 occur only in Objective C; see also above. (FIXME: Make
1456 Objective C use normal builtins.) */
1457 if (!DECL_IS_BUILTIN (olddecl)
1458 && !DECL_EXTERN_INLINE (olddecl))
1460 error ("static declaration of %q+D follows "
1461 "non-static declaration", newdecl);
1462 locate_old_decl (olddecl);
1466 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
1468 if (DECL_CONTEXT (olddecl))
1470 error ("non-static declaration of %q+D follows "
1471 "static declaration", newdecl);
1472 locate_old_decl (olddecl);
1475 else if (warn_traditional)
1477 warned |= warning (OPT_Wtraditional,
1478 "non-static declaration of %q+D "
1479 "follows static declaration", newdecl);
1483 /* Make sure gnu_inline attribute is either not present, or
1484 present on all inline decls. */
1485 if (DECL_DECLARED_INLINE_P (olddecl)
1486 && DECL_DECLARED_INLINE_P (newdecl))
1488 bool newa = lookup_attribute ("gnu_inline",
1489 DECL_ATTRIBUTES (newdecl)) != NULL;
1490 bool olda = lookup_attribute ("gnu_inline",
1491 DECL_ATTRIBUTES (olddecl)) != NULL;
1494 error ("%<gnu_inline%> attribute present on %q+D",
1495 newa ? newdecl : olddecl);
1496 error ("%Jbut not here", newa ? olddecl : newdecl);
1500 else if (TREE_CODE (newdecl) == VAR_DECL)
1502 /* Only variables can be thread-local, and all declarations must
1503 agree on this property. */
1504 if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
1506 /* Nothing to check. Since OLDDECL is marked threadprivate
1507 and NEWDECL does not have a thread-local attribute, we
1508 will merge the threadprivate attribute into NEWDECL. */
1511 else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
1513 if (DECL_THREAD_LOCAL_P (newdecl))
1514 error ("thread-local declaration of %q+D follows "
1515 "non-thread-local declaration", newdecl);
1517 error ("non-thread-local declaration of %q+D follows "
1518 "thread-local declaration", newdecl);
1520 locate_old_decl (olddecl);
1524 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1525 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
1527 error ("redefinition of %q+D", newdecl);
1528 locate_old_decl (olddecl);
1532 /* Objects declared at file scope: if the first declaration had
1533 external linkage (even if it was an external reference) the
1534 second must have external linkage as well, or the behavior is
1535 undefined. If the first declaration had internal linkage, then
1536 the second must too, or else be an external reference (in which
1537 case the composite declaration still has internal linkage).
1538 As for function declarations, we warn about the static-then-
1539 extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */
1540 if (DECL_FILE_SCOPE_P (newdecl)
1541 && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
1543 if (DECL_EXTERNAL (newdecl))
1545 if (!DECL_FILE_SCOPE_P (olddecl))
1547 error ("extern declaration of %q+D follows "
1548 "declaration with no linkage", newdecl);
1549 locate_old_decl (olddecl);
1552 else if (warn_traditional)
1554 warned |= warning (OPT_Wtraditional,
1555 "non-static declaration of %q+D "
1556 "follows static declaration", newdecl);
1561 if (TREE_PUBLIC (newdecl))
1562 error ("non-static declaration of %q+D follows "
1563 "static declaration", newdecl);
1565 error ("static declaration of %q+D follows "
1566 "non-static declaration", newdecl);
1568 locate_old_decl (olddecl);
1572 /* Two objects with the same name declared at the same block
1573 scope must both be external references (6.7p3). */
1574 else if (!DECL_FILE_SCOPE_P (newdecl))
1576 if (DECL_EXTERNAL (newdecl))
1578 /* Extern with initializer at block scope, which will
1579 already have received an error. */
1581 else if (DECL_EXTERNAL (olddecl))
1583 error ("declaration of %q+D with no linkage follows "
1584 "extern declaration", newdecl);
1585 locate_old_decl (olddecl);
1589 error ("redeclaration of %q+D with no linkage", newdecl);
1590 locate_old_decl (olddecl);
1598 /* All decls must agree on a visibility. */
1599 if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
1600 && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
1601 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
1603 warned |= warning (0, "redeclaration of %q+D with different visibility "
1604 "(old visibility preserved)", newdecl);
1607 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1609 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1610 if (DECL_DECLARED_INLINE_P (newdecl)
1611 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1613 warned |= warning (OPT_Wattributes,
1614 "inline declaration of %qD follows "
1615 "declaration with attribute noinline", newdecl);
1617 else if (DECL_DECLARED_INLINE_P (olddecl)
1618 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1620 warned |= warning (OPT_Wattributes,
1621 "declaration of %q+D with attribute "
1622 "noinline follows inline declaration ", newdecl);
1625 else /* PARM_DECL, VAR_DECL */
1627 /* Redeclaration of a parameter is a constraint violation (this is
1628 not explicitly stated, but follows from C99 6.7p3 [no more than
1629 one declaration of the same identifier with no linkage in the
1630 same scope, except type tags] and 6.2.2p6 [parameters have no
1631 linkage]). We must check for a forward parameter declaration,
1632 indicated by TREE_ASM_WRITTEN on the old declaration - this is
1633 an extension, the mandatory diagnostic for which is handled by
1634 mark_forward_parm_decls. */
1636 if (TREE_CODE (newdecl) == PARM_DECL
1637 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
1639 error ("redefinition of parameter %q+D", newdecl);
1640 locate_old_decl (olddecl);
1645 /* Optional warning for completely redundant decls. */
1646 if (!warned && !pedwarned
1647 && warn_redundant_decls
1648 /* Don't warn about a function declaration followed by a
1650 && !(TREE_CODE (newdecl) == FUNCTION_DECL
1651 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
1652 /* Don't warn about redundant redeclarations of builtins. */
1653 && !(TREE_CODE (newdecl) == FUNCTION_DECL
1654 && !DECL_BUILT_IN (newdecl)
1655 && DECL_BUILT_IN (olddecl)
1656 && !C_DECL_DECLARED_BUILTIN (olddecl))
1657 /* Don't warn about an extern followed by a definition. */
1658 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
1659 /* Don't warn about forward parameter decls. */
1660 && !(TREE_CODE (newdecl) == PARM_DECL
1661 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
1662 /* Don't warn about a variable definition following a declaration. */
1663 && !(TREE_CODE (newdecl) == VAR_DECL
1664 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
1666 warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
1670 /* Report location of previous decl/defn. */
1671 if (warned || pedwarned)
1672 locate_old_decl (olddecl);
1674 #undef DECL_EXTERN_INLINE
1679 /* Subroutine of duplicate_decls. NEWDECL has been found to be
1680 consistent with OLDDECL, but carries new information. Merge the
1681 new information into OLDDECL. This function issues no
1685 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
1687 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1688 && DECL_INITIAL (newdecl) != 0);
1689 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
1690 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
1691 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
1692 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
1693 bool extern_changed = false;
1695 /* For real parm decl following a forward decl, rechain the old decl
1696 in its new location and clear TREE_ASM_WRITTEN (it's not a
1697 forward decl anymore). */
1698 if (TREE_CODE (newdecl) == PARM_DECL
1699 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
1701 struct c_binding *b, **here;
1703 for (here = ¤t_scope->bindings; *here; here = &(*here)->prev)
1704 if ((*here)->decl == olddecl)
1711 b->prev = current_scope->bindings;
1712 current_scope->bindings = b;
1714 TREE_ASM_WRITTEN (olddecl) = 0;
1717 DECL_ATTRIBUTES (newdecl)
1718 = targetm.merge_decl_attributes (olddecl, newdecl);
1720 /* Merge the data types specified in the two decls. */
1722 = TREE_TYPE (olddecl)
1723 = composite_type (newtype, oldtype);
1725 /* Lay the type out, unless already done. */
1726 if (!comptypes (oldtype, TREE_TYPE (newdecl)))
1728 if (TREE_TYPE (newdecl) != error_mark_node)
1729 layout_type (TREE_TYPE (newdecl));
1730 if (TREE_CODE (newdecl) != FUNCTION_DECL
1731 && TREE_CODE (newdecl) != TYPE_DECL
1732 && TREE_CODE (newdecl) != CONST_DECL)
1733 layout_decl (newdecl, 0);
1737 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1738 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1739 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
1740 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1741 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1743 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1744 DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
1748 /* Keep the old rtl since we can safely use it. */
1749 if (HAS_RTL_P (olddecl))
1750 COPY_DECL_RTL (olddecl, newdecl);
1752 /* Merge the type qualifiers. */
1753 if (TREE_READONLY (newdecl))
1754 TREE_READONLY (olddecl) = 1;
1756 if (TREE_THIS_VOLATILE (newdecl))
1757 TREE_THIS_VOLATILE (olddecl) = 1;
1759 /* Merge deprecatedness. */
1760 if (TREE_DEPRECATED (newdecl))
1761 TREE_DEPRECATED (olddecl) = 1;
1763 /* If a decl is in a system header and the other isn't, keep the one on the
1764 system header. Otherwise, keep source location of definition rather than
1765 declaration and of prototype rather than non-prototype unless that
1766 prototype is built-in. */
1767 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
1768 && DECL_IN_SYSTEM_HEADER (olddecl)
1769 && !DECL_IN_SYSTEM_HEADER (newdecl) )
1770 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1771 else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
1772 && DECL_IN_SYSTEM_HEADER (newdecl)
1773 && !DECL_IN_SYSTEM_HEADER (olddecl))
1774 DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
1775 else if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
1776 || (old_is_prototype && !new_is_prototype
1777 && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
1778 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1780 /* Merge the initialization information. */
1781 if (DECL_INITIAL (newdecl) == 0)
1782 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1784 /* Merge the threadprivate attribute. */
1785 if (TREE_CODE (olddecl) == VAR_DECL && C_DECL_THREADPRIVATE_P (olddecl))
1787 DECL_TLS_MODEL (newdecl) = DECL_TLS_MODEL (olddecl);
1788 C_DECL_THREADPRIVATE_P (newdecl) = 1;
1791 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS))
1793 /* Merge the section attribute.
1794 We want to issue an error if the sections conflict but that
1795 must be done later in decl_attributes since we are called
1796 before attributes are assigned. */
1797 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1798 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1800 /* Copy the assembler name.
1801 Currently, it can only be defined in the prototype. */
1802 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
1804 /* Use visibility of whichever declaration had it specified */
1805 if (DECL_VISIBILITY_SPECIFIED (olddecl))
1807 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
1808 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
1811 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1813 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1814 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1815 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1816 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1817 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1818 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1819 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1820 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
1821 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1822 DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1823 DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
1826 /* Merge the storage class information. */
1827 merge_weak (newdecl, olddecl);
1829 /* For functions, static overrides non-static. */
1830 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1832 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1833 /* This is since we don't automatically
1834 copy the attributes of NEWDECL into OLDDECL. */
1835 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1836 /* If this clears `static', clear it in the identifier too. */
1837 if (!TREE_PUBLIC (olddecl))
1838 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1842 /* In c99, 'extern' declaration before (or after) 'inline' means this
1843 function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
1845 if (TREE_CODE (newdecl) == FUNCTION_DECL
1846 && !flag_gnu89_inline
1847 && (DECL_DECLARED_INLINE_P (newdecl)
1848 || DECL_DECLARED_INLINE_P (olddecl))
1849 && (!DECL_DECLARED_INLINE_P (newdecl)
1850 || !DECL_DECLARED_INLINE_P (olddecl)
1851 || !DECL_EXTERNAL (olddecl))
1852 && DECL_EXTERNAL (newdecl)
1853 && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
1854 && !current_function_decl)
1855 DECL_EXTERNAL (newdecl) = 0;
1857 if (DECL_EXTERNAL (newdecl))
1859 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
1860 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1862 /* An extern decl does not override previous storage class. */
1863 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1864 if (!DECL_EXTERNAL (newdecl))
1866 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1867 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
1872 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1873 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1876 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1878 /* If we're redefining a function previously defined as extern
1879 inline, make sure we emit debug info for the inline before we
1880 throw it away, in case it was inlined into a function that
1881 hasn't been written out yet. */
1882 if (new_is_definition && DECL_INITIAL (olddecl))
1883 /* The new defn must not be inline. */
1884 DECL_UNINLINABLE (newdecl) = 1;
1887 /* If either decl says `inline', this fn is inline, unless
1888 its definition was passed already. */
1889 if (DECL_DECLARED_INLINE_P (newdecl)
1890 || DECL_DECLARED_INLINE_P (olddecl))
1891 DECL_DECLARED_INLINE_P (newdecl) = 1;
1893 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1894 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1896 DECL_DISREGARD_INLINE_LIMITS (newdecl)
1897 = DECL_DISREGARD_INLINE_LIMITS (olddecl)
1898 = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
1899 || DECL_DISREGARD_INLINE_LIMITS (olddecl));
1902 if (DECL_BUILT_IN (olddecl))
1904 /* If redeclaring a builtin function, it stays built in.
1905 But it gets tagged as having been declared. */
1906 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1907 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1908 C_DECL_DECLARED_BUILTIN (newdecl) = 1;
1909 if (new_is_prototype)
1910 C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
1912 C_DECL_BUILTIN_PROTOTYPE (newdecl)
1913 = C_DECL_BUILTIN_PROTOTYPE (olddecl);
1916 /* Preserve function specific target and optimization options */
1917 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
1918 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
1919 DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
1920 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
1922 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
1923 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
1924 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
1925 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
1927 /* Also preserve various other info from the definition. */
1928 if (!new_is_definition)
1931 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1932 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1933 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
1934 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1935 gimple_set_body (newdecl, gimple_body (olddecl));
1936 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
1937 for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t))
1938 DECL_CONTEXT (t) = newdecl;
1940 /* See if we've got a function to instantiate from. */
1941 if (DECL_SAVED_TREE (olddecl))
1942 DECL_ABSTRACT_ORIGIN (newdecl)
1943 = DECL_ABSTRACT_ORIGIN (olddecl);
1947 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl);
1949 /* Merge the USED information. */
1950 if (TREE_USED (olddecl))
1951 TREE_USED (newdecl) = 1;
1952 else if (TREE_USED (newdecl))
1953 TREE_USED (olddecl) = 1;
1955 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1956 But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
1958 unsigned olddecl_uid = DECL_UID (olddecl);
1959 tree olddecl_context = DECL_CONTEXT (olddecl);
1960 tree olddecl_arguments = NULL;
1961 if (TREE_CODE (olddecl) == FUNCTION_DECL)
1962 olddecl_arguments = DECL_ARGUMENTS (olddecl);
1964 memcpy ((char *) olddecl + sizeof (struct tree_common),
1965 (char *) newdecl + sizeof (struct tree_common),
1966 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
1967 switch (TREE_CODE (olddecl))
1970 gimple_set_body (olddecl, gimple_body (newdecl));
1980 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
1981 (char *) newdecl + sizeof (struct tree_decl_common),
1982 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
1987 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
1988 (char *) newdecl + sizeof (struct tree_decl_common),
1989 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
1991 DECL_UID (olddecl) = olddecl_uid;
1992 DECL_CONTEXT (olddecl) = olddecl_context;
1993 if (TREE_CODE (olddecl) == FUNCTION_DECL)
1994 DECL_ARGUMENTS (olddecl) = olddecl_arguments;
1997 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1998 so that encode_section_info has a chance to look at the new decl
1999 flags and attributes. */
2000 if (DECL_RTL_SET_P (olddecl)
2001 && (TREE_CODE (olddecl) == FUNCTION_DECL
2002 || (TREE_CODE (olddecl) == VAR_DECL
2003 && TREE_STATIC (olddecl))))
2004 make_decl_rtl (olddecl);
2006 /* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL,
2007 and the definition is coming from the old version, cgraph needs
2008 to be called again. */
2009 if (extern_changed && !new_is_definition
2010 && TREE_CODE (olddecl) == FUNCTION_DECL && DECL_INITIAL (olddecl))
2011 cgraph_mark_if_needed (olddecl);
2014 /* Handle when a new declaration NEWDECL has the same name as an old
2015 one OLDDECL in the same binding contour. Prints an error message
2018 If safely possible, alter OLDDECL to look like NEWDECL, and return
2019 true. Otherwise, return false. */
2022 duplicate_decls (tree newdecl, tree olddecl)
2024 tree newtype = NULL, oldtype = NULL;
2026 if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
2028 /* Avoid `unused variable' and other warnings for OLDDECL. */
2029 TREE_NO_WARNING (olddecl) = 1;
2033 merge_decls (newdecl, olddecl, newtype, oldtype);
2038 /* Check whether decl-node NEW_DECL shadows an existing declaration. */
2040 warn_if_shadowing (tree new_decl)
2042 struct c_binding *b;
2044 /* Shadow warnings wanted? */
2046 /* No shadow warnings for internally generated vars. */
2047 || DECL_IS_BUILTIN (new_decl)
2048 /* No shadow warnings for vars made for inlining. */
2049 || DECL_FROM_INLINE (new_decl))
2052 /* Is anything being shadowed? Invisible decls do not count. */
2053 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
2054 if (b->decl && b->decl != new_decl && !b->invisible)
2056 tree old_decl = b->decl;
2058 if (old_decl == error_mark_node)
2060 warning (OPT_Wshadow, "declaration of %q+D shadows previous "
2061 "non-variable", new_decl);
2064 else if (TREE_CODE (old_decl) == PARM_DECL)
2065 warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
2067 else if (DECL_FILE_SCOPE_P (old_decl))
2068 warning (OPT_Wshadow, "declaration of %q+D shadows a global "
2069 "declaration", new_decl);
2070 else if (TREE_CODE (old_decl) == FUNCTION_DECL
2071 && DECL_BUILT_IN (old_decl))
2073 warning (OPT_Wshadow, "declaration of %q+D shadows "
2074 "a built-in function", new_decl);
2078 warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
2081 warning (OPT_Wshadow, "%Jshadowed declaration is here", old_decl);
2087 /* Record a decl-node X as belonging to the current lexical scope.
2088 Check for errors (such as an incompatible declaration for the same
2089 name already seen in the same scope).
2091 Returns either X or an old decl for the same name.
2092 If an old decl is returned, it may have been smashed
2093 to agree with what X says. */
2098 tree name = DECL_NAME (x);
2099 struct c_scope *scope = current_scope;
2100 struct c_binding *b;
2101 bool nested = false;
2102 location_t locus = DECL_SOURCE_LOCATION (x);
2104 /* Must set DECL_CONTEXT for everything not at file scope or
2105 DECL_FILE_SCOPE_P won't work. Local externs don't count
2106 unless they have initializers (which generate code). */
2107 if (current_function_decl
2108 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
2109 || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
2110 DECL_CONTEXT (x) = current_function_decl;
2112 /* If this is of variably modified type, prevent jumping into its
2114 if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL)
2115 && variably_modified_type_p (TREE_TYPE (x), NULL_TREE))
2116 c_begin_vm_scope (scope->depth);
2118 /* Anonymous decls are just inserted in the scope. */
2121 bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
2126 /* First, see if there is another declaration with the same name in
2127 the current scope. If there is, duplicate_decls may do all the
2128 work for us. If duplicate_decls returns false, that indicates
2129 two incompatible decls in the same scope; we are to silently
2130 replace the old one (duplicate_decls has issued all appropriate
2131 diagnostics). In particular, we should not consider possible
2132 duplicates in the external scope, or shadowing. */
2133 b = I_SYMBOL_BINDING (name);
2134 if (b && B_IN_SCOPE (b, scope))
2136 struct c_binding *b_ext, *b_use;
2137 tree type = TREE_TYPE (x);
2138 tree visdecl = b->decl;
2139 tree vistype = TREE_TYPE (visdecl);
2140 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
2141 && COMPLETE_TYPE_P (TREE_TYPE (x)))
2142 b->inner_comp = false;
2145 /* If this is an external linkage declaration, we should check
2146 for compatibility with the type in the external scope before
2147 setting the type at this scope based on the visible
2148 information only. */
2149 if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
2151 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
2152 b_ext = b_ext->shadowed;
2157 TREE_TYPE (b_use->decl) = b_use->type;
2160 if (duplicate_decls (x, b_use->decl))
2164 /* Save the updated type in the external scope and
2165 restore the proper type for this scope. */
2167 if (comptypes (vistype, type))
2168 thistype = composite_type (vistype, type);
2170 thistype = TREE_TYPE (b_use->decl);
2171 b_use->type = TREE_TYPE (b_use->decl);
2172 if (TREE_CODE (b_use->decl) == FUNCTION_DECL
2173 && DECL_BUILT_IN (b_use->decl))
2175 = build_type_attribute_variant (thistype,
2178 TREE_TYPE (b_use->decl) = thistype;
2183 goto skip_external_and_shadow_checks;
2186 /* All declarations with external linkage, and all external
2187 references, go in the external scope, no matter what scope is
2188 current. However, the binding in that scope is ignored for
2189 purposes of normal name lookup. A separate binding structure is
2190 created in the requested scope; this governs the normal
2191 visibility of the symbol.
2193 The binding in the externals scope is used exclusively for
2194 detecting duplicate declarations of the same object, no matter
2195 what scope they are in; this is what we do here. (C99 6.2.7p2:
2196 All declarations that refer to the same object or function shall
2197 have compatible type; otherwise, the behavior is undefined.) */
2198 if (DECL_EXTERNAL (x) || scope == file_scope)
2200 tree type = TREE_TYPE (x);
2203 bool type_saved = false;
2204 if (b && !B_IN_EXTERNAL_SCOPE (b)
2205 && (TREE_CODE (b->decl) == FUNCTION_DECL
2206 || TREE_CODE (b->decl) == VAR_DECL)
2207 && DECL_FILE_SCOPE_P (b->decl))
2210 vistype = TREE_TYPE (visdecl);
2212 if (scope != file_scope
2213 && !DECL_IN_SYSTEM_HEADER (x))
2214 warning (OPT_Wnested_externs, "nested extern declaration of %qD", x);
2216 while (b && !B_IN_EXTERNAL_SCOPE (b))
2218 /* If this decl might be modified, save its type. This is
2219 done here rather than when the decl is first bound
2220 because the type may change after first binding, through
2221 being completed or through attributes being added. If we
2222 encounter multiple such decls, only the first should have
2223 its type saved; the others will already have had their
2224 proper types saved and the types will not have changed as
2225 their scopes will not have been re-entered. */
2226 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
2228 b->type = TREE_TYPE (b->decl);
2231 if (B_IN_FILE_SCOPE (b)
2232 && TREE_CODE (b->decl) == VAR_DECL
2233 && TREE_STATIC (b->decl)
2234 && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
2235 && !TYPE_DOMAIN (TREE_TYPE (b->decl))
2236 && TREE_CODE (type) == ARRAY_TYPE
2237 && TYPE_DOMAIN (type)
2238 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
2239 && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
2241 /* Array type completed in inner scope, which should be
2242 diagnosed if the completion does not have size 1 and
2243 it does not get completed in the file scope. */
2244 b->inner_comp = true;
2249 /* If a matching external declaration has been found, set its
2250 type to the composite of all the types of that declaration.
2251 After the consistency checks, it will be reset to the
2252 composite of the visible types only. */
2253 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2255 TREE_TYPE (b->decl) = b->type;
2257 /* The point of the same_translation_unit_p check here is,
2258 we want to detect a duplicate decl for a construct like
2259 foo() { extern bar(); } ... static bar(); but not if
2260 they are in different translation units. In any case,
2261 the static does not go in the externals scope. */
2263 && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2264 && duplicate_decls (x, b->decl))
2269 if (comptypes (vistype, type))
2270 thistype = composite_type (vistype, type);
2272 thistype = TREE_TYPE (b->decl);
2276 b->type = TREE_TYPE (b->decl);
2277 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
2279 = build_type_attribute_variant (thistype,
2280 TYPE_ATTRIBUTES (b->type));
2281 TREE_TYPE (b->decl) = thistype;
2282 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
2286 else if (TREE_PUBLIC (x))
2288 if (visdecl && !b && duplicate_decls (x, visdecl))
2290 /* An external declaration at block scope referring to a
2291 visible entity with internal linkage. The composite
2292 type will already be correct for this scope, so we
2293 just need to fall through to make the declaration in
2300 bind (name, x, external_scope, /*invisible=*/true,
2301 /*nested=*/false, locus);
2307 if (TREE_CODE (x) != PARM_DECL)
2308 warn_if_shadowing (x);
2310 skip_external_and_shadow_checks:
2311 if (TREE_CODE (x) == TYPE_DECL)
2312 set_underlying_type (x);
2314 bind (name, x, scope, /*invisible=*/false, nested, locus);
2316 /* If x's type is incomplete because it's based on a
2317 structure or union which has not yet been fully declared,
2318 attach it to that structure or union type, so we can go
2319 back and complete the variable declaration later, if the
2320 structure or union gets fully declared.
2322 If the input is erroneous, we can have error_mark in the type
2323 slot (e.g. "f(void a, ...)") - that doesn't count as an
2325 if (TREE_TYPE (x) != error_mark_node
2326 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
2328 tree element = TREE_TYPE (x);
2330 while (TREE_CODE (element) == ARRAY_TYPE)
2331 element = TREE_TYPE (element);
2332 element = TYPE_MAIN_VARIANT (element);
2334 if ((TREE_CODE (element) == RECORD_TYPE
2335 || TREE_CODE (element) == UNION_TYPE)
2336 && (TREE_CODE (x) != TYPE_DECL
2337 || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
2338 && !COMPLETE_TYPE_P (element))
2339 C_TYPE_INCOMPLETE_VARS (element)
2340 = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
2345 /* Record X as belonging to file scope.
2346 This is used only internally by the Objective-C front end,
2347 and is limited to its needs. duplicate_decls is not called;
2348 if there is any preexisting decl for this identifier, it is an ICE. */
2351 pushdecl_top_level (tree x)
2354 bool nested = false;
2355 gcc_assert (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == CONST_DECL);
2357 name = DECL_NAME (x);
2359 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
2361 if (TREE_PUBLIC (x))
2363 bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false,
2368 bind (name, x, file_scope, /*invisible=*/false, nested, UNKNOWN_LOCATION);
2374 implicit_decl_warning (tree id, tree olddecl)
2376 if (warn_implicit_function_declaration)
2381 warned = pedwarn (input_location, OPT_Wimplicit_function_declaration,
2382 "implicit declaration of function %qE", id);
2384 warned = warning (OPT_Wimplicit_function_declaration,
2385 G_("implicit declaration of function %qE"), id);
2386 if (olddecl && warned)
2387 locate_old_decl (olddecl);
2391 /* Generate an implicit declaration for identifier FUNCTIONID as a
2392 function of type int (). */
2395 implicitly_declare (tree functionid)
2397 struct c_binding *b;
2401 for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
2403 if (B_IN_SCOPE (b, external_scope))
2412 if (decl == error_mark_node)
2415 /* FIXME: Objective-C has weird not-really-builtin functions
2416 which are supposed to be visible automatically. They wind up
2417 in the external scope because they're pushed before the file
2418 scope gets created. Catch this here and rebind them into the
2420 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
2422 bind (functionid, decl, file_scope,
2423 /*invisible=*/false, /*nested=*/true,
2424 DECL_SOURCE_LOCATION (decl));
2429 tree newtype = default_function_type;
2431 TREE_TYPE (decl) = b->type;
2432 /* Implicit declaration of a function already declared
2433 (somehow) in a different scope, or as a built-in.
2434 If this is the first time this has happened, warn;
2435 then recycle the old declaration but with the new type. */
2436 if (!C_DECL_IMPLICIT (decl))
2438 implicit_decl_warning (functionid, decl);
2439 C_DECL_IMPLICIT (decl) = 1;
2441 if (DECL_BUILT_IN (decl))
2443 newtype = build_type_attribute_variant (newtype,
2445 (TREE_TYPE (decl)));
2446 if (!comptypes (newtype, TREE_TYPE (decl)))
2448 warning (0, "incompatible implicit declaration of built-in"
2449 " function %qD", decl);
2450 newtype = TREE_TYPE (decl);
2455 if (!comptypes (newtype, TREE_TYPE (decl)))
2457 error ("incompatible implicit declaration of function %qD",
2459 locate_old_decl (decl);
2462 b->type = TREE_TYPE (decl);
2463 TREE_TYPE (decl) = newtype;
2464 bind (functionid, decl, current_scope,
2465 /*invisible=*/false, /*nested=*/true,
2466 DECL_SOURCE_LOCATION (decl));
2471 /* Not seen before. */
2472 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2473 DECL_EXTERNAL (decl) = 1;
2474 TREE_PUBLIC (decl) = 1;
2475 C_DECL_IMPLICIT (decl) = 1;
2476 implicit_decl_warning (functionid, 0);
2477 asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
2479 set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
2481 /* C89 says implicit declarations are in the innermost block.
2482 So we record the decl in the standard fashion. */
2483 decl = pushdecl (decl);
2485 /* No need to call objc_check_decl here - it's a function type. */
2486 rest_of_decl_compilation (decl, 0, 0);
2488 /* Write a record describing this implicit function declaration
2489 to the prototypes file (if requested). */
2490 gen_aux_info_record (decl, 0, 1, 0);
2492 /* Possibly apply some default attributes to this implicit declaration. */
2493 decl_attributes (&decl, NULL_TREE, 0);
2498 /* Issue an error message for a reference to an undeclared variable
2499 ID, including a reference to a builtin outside of function-call
2500 context. Establish a binding of the identifier to error_mark_node
2501 in an appropriate scope, which will suppress further errors for the
2502 same identifier. The error message should be given location LOC. */
2504 undeclared_variable (tree id, location_t loc)
2506 static bool already = false;
2507 struct c_scope *scope;
2509 if (current_function_decl == 0)
2511 error ("%H%qE undeclared here (not in a function)", &loc, id);
2512 scope = current_scope;
2516 error ("%H%qE undeclared (first use in this function)", &loc, id);
2520 error ("%H(Each undeclared identifier is reported only once", &loc);
2521 error ("%Hfor each function it appears in.)", &loc);
2525 /* If we are parsing old-style parameter decls, current_function_decl
2526 will be nonnull but current_function_scope will be null. */
2527 scope = current_function_scope ? current_function_scope : current_scope;
2529 bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
2533 /* Subroutine of lookup_label, declare_label, define_label: construct a
2534 LABEL_DECL with all the proper frills. */
2537 make_label (tree name, location_t location)
2539 tree label = build_decl (LABEL_DECL, name, void_type_node);
2541 DECL_CONTEXT (label) = current_function_decl;
2542 DECL_MODE (label) = VOIDmode;
2543 DECL_SOURCE_LOCATION (label) = location;
2548 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
2549 Create one if none exists so far for the current function.
2550 This is called when a label is used in a goto expression or
2551 has its address taken. */
2554 lookup_label (tree name)
2558 if (current_function_decl == 0)
2560 error ("label %qE referenced outside of any function", name);
2564 /* Use a label already defined or ref'd with this name, but not if
2565 it is inherited from a containing function and wasn't declared
2567 label = I_LABEL_DECL (name);
2568 if (label && (DECL_CONTEXT (label) == current_function_decl
2569 || C_DECLARED_LABEL_FLAG (label)))
2571 /* If the label has only been declared, update its apparent
2572 location to point here, for better diagnostics if it
2573 turns out not to have been defined. */
2574 if (!TREE_USED (label))
2575 DECL_SOURCE_LOCATION (label) = input_location;
2579 /* No label binding for that identifier; make one. */
2580 label = make_label (name, input_location);
2582 /* Ordinary labels go in the current function scope. */
2583 bind (name, label, current_function_scope,
2584 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
2588 /* Make a label named NAME in the current function, shadowing silently
2589 any that may be inherited from containing functions or containing
2590 scopes. This is called for __label__ declarations. */
2593 declare_label (tree name)
2595 struct c_binding *b = I_LABEL_BINDING (name);
2598 /* Check to make sure that the label hasn't already been declared
2600 if (b && B_IN_CURRENT_SCOPE (b))
2602 error ("duplicate label declaration %qE", name);
2603 locate_old_decl (b->decl);
2605 /* Just use the previous declaration. */
2609 label = make_label (name, input_location);
2610 C_DECLARED_LABEL_FLAG (label) = 1;
2612 /* Declared labels go in the current scope. */
2613 bind (name, label, current_scope,
2614 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
2618 /* Define a label, specifying the location in the source file.
2619 Return the LABEL_DECL node for the label, if the definition is valid.
2620 Otherwise return 0. */
2623 define_label (location_t location, tree name)
2625 /* Find any preexisting label with this name. It is an error
2626 if that label has already been defined in this function, or
2627 if there is a containing function with a declared label with
2629 tree label = I_LABEL_DECL (name);
2630 struct c_label_list *nlist_se, *nlist_vm;
2633 && ((DECL_CONTEXT (label) == current_function_decl
2634 && DECL_INITIAL (label) != 0)
2635 || (DECL_CONTEXT (label) != current_function_decl
2636 && C_DECLARED_LABEL_FLAG (label))))
2638 error ("%Hduplicate label %qD", &location, label);
2639 locate_old_decl (label);
2642 else if (label && DECL_CONTEXT (label) == current_function_decl)
2644 /* The label has been used or declared already in this function,
2645 but not defined. Update its location to point to this
2647 if (C_DECL_UNDEFINABLE_STMT_EXPR (label))
2648 error ("%Jjump into statement expression", label);
2649 if (C_DECL_UNDEFINABLE_VM (label))
2650 error ("%Jjump into scope of identifier with variably modified type",
2652 DECL_SOURCE_LOCATION (label) = location;
2656 /* No label binding for that identifier; make one. */
2657 label = make_label (name, location);
2659 /* Ordinary labels go in the current function scope. */
2660 bind (name, label, current_function_scope,
2661 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
2664 if (!in_system_header && lookup_name (name))
2665 warning (OPT_Wtraditional, "%Htraditional C lacks a separate namespace "
2666 "for labels, identifier %qE conflicts", &location, name);
2668 nlist_se = XOBNEW (&parser_obstack, struct c_label_list);
2669 nlist_se->next = label_context_stack_se->labels_def;
2670 nlist_se->label = label;
2671 label_context_stack_se->labels_def = nlist_se;
2673 nlist_vm = XOBNEW (&parser_obstack, struct c_label_list);
2674 nlist_vm->next = label_context_stack_vm->labels_def;
2675 nlist_vm->label = label;
2676 label_context_stack_vm->labels_def = nlist_vm;
2678 /* Mark label as having been defined. */
2679 DECL_INITIAL (label) = error_mark_node;
2683 /* Given NAME, an IDENTIFIER_NODE,
2684 return the structure (or union or enum) definition for that name.
2685 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2686 CODE says which kind of type the caller wants;
2687 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2688 If the wrong kind of type is found, an error is reported. */
2691 lookup_tag (enum tree_code code, tree name, int thislevel_only)
2693 struct c_binding *b = I_TAG_BINDING (name);
2699 /* We only care about whether it's in this level if
2700 thislevel_only was set or it might be a type clash. */
2701 if (thislevel_only || TREE_CODE (b->decl) != code)
2703 /* For our purposes, a tag in the external scope is the same as
2704 a tag in the file scope. (Primarily relevant to Objective-C
2705 and its builtin structure tags, which get pushed before the
2706 file scope is created.) */
2707 if (B_IN_CURRENT_SCOPE (b)
2708 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
2712 if (thislevel_only && !thislevel)
2715 if (TREE_CODE (b->decl) != code)
2717 /* Definition isn't the kind we were looking for. */
2718 pending_invalid_xref = name;
2719 pending_invalid_xref_location = input_location;
2721 /* If in the same binding level as a declaration as a tag
2722 of a different type, this must not be allowed to
2723 shadow that tag, so give the error immediately.
2724 (For example, "struct foo; union foo;" is invalid.) */
2726 pending_xref_error ();
2731 /* Print an error message now
2732 for a recent invalid struct, union or enum cross reference.
2733 We don't print them immediately because they are not invalid
2734 when used in the `struct foo;' construct for shadowing. */
2737 pending_xref_error (void)
2739 if (pending_invalid_xref != 0)
2740 error ("%H%qE defined as wrong kind of tag",
2741 &pending_invalid_xref_location, pending_invalid_xref);
2742 pending_invalid_xref = 0;
2746 /* Look up NAME in the current scope and its superiors
2747 in the namespace of variables, functions and typedefs.
2748 Return a ..._DECL node of some kind representing its definition,
2749 or return 0 if it is undefined. */
2752 lookup_name (tree name)
2754 struct c_binding *b = I_SYMBOL_BINDING (name);
2755 if (b && !b->invisible)
2760 /* Similar to `lookup_name' but look only at the indicated scope. */
2763 lookup_name_in_scope (tree name, struct c_scope *scope)
2765 struct c_binding *b;
2767 for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
2768 if (B_IN_SCOPE (b, scope))
2773 /* Create the predefined scalar types of C,
2774 and some nodes representing standard constants (0, 1, (void *) 0).
2775 Initialize the global scope.
2776 Make definitions for built-in primitive functions. */
2779 c_init_decl_processing (void)
2781 location_t save_loc = input_location;
2783 /* Initialize reserved words for parser. */
2786 current_function_decl = 0;
2788 gcc_obstack_init (&parser_obstack);
2790 /* Make the externals scope. */
2792 external_scope = current_scope;
2794 /* Declarations from c_common_nodes_and_builtins must not be associated
2795 with this input file, lest we get differences between using and not
2796 using preprocessed headers. */
2797 input_location = BUILTINS_LOCATION;
2799 build_common_tree_nodes (flag_signed_char, false);
2801 c_common_nodes_and_builtins ();
2803 /* In C, comparisons and TRUTH_* expressions have type int. */
2804 truthvalue_type_node = integer_type_node;
2805 truthvalue_true_node = integer_one_node;
2806 truthvalue_false_node = integer_zero_node;
2808 /* Even in C99, which has a real boolean type. */
2809 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
2810 boolean_type_node));
2812 input_location = save_loc;
2814 pedantic_lvalues = true;
2816 make_fname_decl = c_make_fname_decl;
2817 start_fname_decls ();
2820 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2821 decl, NAME is the initialization string and TYPE_DEP indicates whether
2822 NAME depended on the type of the function. As we don't yet implement
2823 delayed emission of static data, we mark the decl as emitted
2824 so it is not placed in the output. Anything using it must therefore pull
2825 out the STRING_CST initializer directly. FIXME. */
2828 c_make_fname_decl (tree id, int type_dep)
2830 const char *name = fname_as_string (type_dep);
2831 tree decl, type, init;
2832 size_t length = strlen (name);
2834 type = build_array_type (char_type_node,
2835 build_index_type (size_int (length)));
2836 type = c_build_qualified_type (type, TYPE_QUAL_CONST);
2838 decl = build_decl (VAR_DECL, id, type);
2840 TREE_STATIC (decl) = 1;
2841 TREE_READONLY (decl) = 1;
2842 DECL_ARTIFICIAL (decl) = 1;
2844 init = build_string (length + 1, name);
2845 free (CONST_CAST (char *, name));
2846 TREE_TYPE (init) = type;
2847 DECL_INITIAL (decl) = init;
2849 TREE_USED (decl) = 1;
2851 if (current_function_decl
2852 /* For invalid programs like this:
2855 const char* p = __FUNCTION__;
2857 the __FUNCTION__ is believed to appear in K&R style function
2858 parameter declarator. In that case we still don't have
2860 && (!errorcount || current_function_scope))
2862 DECL_CONTEXT (decl) = current_function_decl;
2863 bind (id, decl, current_function_scope,
2864 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
2867 finish_decl (decl, init, NULL_TREE, NULL_TREE);
2873 c_builtin_function (tree decl)
2875 tree type = TREE_TYPE (decl);
2876 tree id = DECL_NAME (decl);
2878 const char *name = IDENTIFIER_POINTER (id);
2879 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
2881 /* Should never be called on a symbol with a preexisting meaning. */
2882 gcc_assert (!I_SYMBOL_BINDING (id));
2884 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
2887 /* Builtins in the implementation namespace are made visible without
2888 needing to be explicitly declared. See push_file_scope. */
2889 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
2891 TREE_CHAIN (decl) = visible_builtins;
2892 visible_builtins = decl;
2899 c_builtin_function_ext_scope (tree decl)
2901 tree type = TREE_TYPE (decl);
2902 tree id = DECL_NAME (decl);
2904 const char *name = IDENTIFIER_POINTER (id);
2905 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
2907 /* Should never be called on a symbol with a preexisting meaning. */
2908 gcc_assert (!I_SYMBOL_BINDING (id));
2910 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
2913 /* Builtins in the implementation namespace are made visible without
2914 needing to be explicitly declared. See push_file_scope. */
2915 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
2917 TREE_CHAIN (decl) = visible_builtins;
2918 visible_builtins = decl;
2924 /* Called when a declaration is seen that contains no names to declare.
2925 If its type is a reference to a structure, union or enum inherited
2926 from a containing scope, shadow that tag name for the current scope
2927 with a forward reference.
2928 If its type defines a new named structure or union
2929 or defines an enum, it is valid but we need not do anything here.
2930 Otherwise, it is an error. */
2933 shadow_tag (const struct c_declspecs *declspecs)
2935 shadow_tag_warned (declspecs, 0);
2938 /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
2941 shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
2943 bool found_tag = false;
2945 if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
2947 tree value = declspecs->type;
2948 enum tree_code code = TREE_CODE (value);
2950 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
2951 /* Used to test also that TYPE_SIZE (value) != 0.
2952 That caused warning for `struct foo;' at top level in the file. */
2954 tree name = TYPE_NAME (value);
2959 if (declspecs->restrict_p)
2961 error ("invalid use of %<restrict%>");
2967 if (warned != 1 && code != ENUMERAL_TYPE)
2968 /* Empty unnamed enum OK */
2970 pedwarn (input_location, 0,
2971 "unnamed struct/union that defines no instances");
2975 else if (!declspecs->tag_defined_p
2976 && declspecs->storage_class != csc_none)
2979 pedwarn (input_location, 0,
2980 "empty declaration with storage class specifier "
2981 "does not redeclare tag");
2983 pending_xref_error ();
2985 else if (!declspecs->tag_defined_p
2986 && (declspecs->const_p
2987 || declspecs->volatile_p
2988 || declspecs->restrict_p))
2991 pedwarn (input_location, 0,
2992 "empty declaration with type qualifier "
2993 "does not redeclare tag");
2995 pending_xref_error ();
2999 pending_invalid_xref = 0;
3000 t = lookup_tag (code, name, 1);
3004 t = make_node (code);
3011 if (warned != 1 && !in_system_header)
3013 pedwarn (input_location, 0,
3014 "useless type name in empty declaration");
3019 else if (warned != 1 && !in_system_header && declspecs->typedef_p)
3021 pedwarn (input_location, 0, "useless type name in empty declaration");
3025 pending_invalid_xref = 0;
3027 if (declspecs->inline_p)
3029 error ("%<inline%> in empty declaration");
3033 if (current_scope == file_scope && declspecs->storage_class == csc_auto)
3035 error ("%<auto%> in file-scope empty declaration");
3039 if (current_scope == file_scope && declspecs->storage_class == csc_register)
3041 error ("%<register%> in file-scope empty declaration");
3045 if (!warned && !in_system_header && declspecs->storage_class != csc_none)
3047 warning (0, "useless storage class specifier in empty declaration");
3051 if (!warned && !in_system_header && declspecs->thread_p)
3053 warning (0, "useless %<__thread%> in empty declaration");
3057 if (!warned && !in_system_header && (declspecs->const_p
3058 || declspecs->volatile_p
3059 || declspecs->restrict_p))
3061 warning (0, "useless type qualifier in empty declaration");
3068 pedwarn (input_location, 0, "empty declaration");
3073 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
3074 bits. SPECS represents declaration specifiers that the grammar
3075 only permits to contain type qualifiers and attributes. */
3078 quals_from_declspecs (const struct c_declspecs *specs)
3080 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
3081 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
3082 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0));
3083 gcc_assert (!specs->type
3084 && !specs->decl_attr
3085 && specs->typespec_word == cts_none
3086 && specs->storage_class == csc_none
3087 && !specs->typedef_p
3088 && !specs->explicit_signed_p
3089 && !specs->deprecated_p
3091 && !specs->long_long_p
3094 && !specs->unsigned_p
3095 && !specs->complex_p
3097 && !specs->thread_p);
3101 /* Construct an array declarator. EXPR is the expression inside [],
3102 or NULL_TREE. QUALS are the type qualifiers inside the [] (to be
3103 applied to the pointer to which a parameter array is converted).
3104 STATIC_P is true if "static" is inside the [], false otherwise.
3105 VLA_UNSPEC_P is true if the array is [*], a VLA of unspecified
3106 length which is nevertheless a complete type, false otherwise. The
3107 field for the contained declarator is left to be filled in by
3108 set_array_declarator_inner. */
3110 struct c_declarator *
3111 build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p,
3114 struct c_declarator *declarator = XOBNEW (&parser_obstack,
3115 struct c_declarator);
3116 declarator->kind = cdk_array;
3117 declarator->declarator = 0;
3118 declarator->u.array.dimen = expr;
3121 declarator->u.array.attrs = quals->attrs;
3122 declarator->u.array.quals = quals_from_declspecs (quals);
3126 declarator->u.array.attrs = NULL_TREE;
3127 declarator->u.array.quals = 0;
3129 declarator->u.array.static_p = static_p;
3130 declarator->u.array.vla_unspec_p = vla_unspec_p;
3133 if (static_p || quals != NULL)
3134 pedwarn (input_location, OPT_pedantic,
3135 "ISO C90 does not support %<static%> or type "
3136 "qualifiers in parameter array declarators");
3138 pedwarn (input_location, OPT_pedantic,
3139 "ISO C90 does not support %<[*]%> array declarators");
3143 if (!current_scope->parm_flag)
3146 error ("%<[*]%> not allowed in other than function prototype scope");
3147 declarator->u.array.vla_unspec_p = false;
3150 current_scope->had_vla_unspec = true;
3155 /* Set the contained declarator of an array declarator. DECL is the
3156 declarator, as constructed by build_array_declarator; INNER is what
3157 appears on the left of the []. */
3159 struct c_declarator *
3160 set_array_declarator_inner (struct c_declarator *decl,
3161 struct c_declarator *inner)
3163 decl->declarator = inner;
3167 /* INIT is a constructor that forms DECL's initializer. If the final
3168 element initializes a flexible array field, add the size of that
3169 initializer to DECL's size. */
3172 add_flexible_array_elts_to_size (tree decl, tree init)
3176 if (VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (init)))
3179 elt = VEC_last (constructor_elt, CONSTRUCTOR_ELTS (init))->value;
3180 type = TREE_TYPE (elt);
3181 if (TREE_CODE (type) == ARRAY_TYPE
3182 && TYPE_SIZE (type) == NULL_TREE
3183 && TYPE_DOMAIN (type) != NULL_TREE
3184 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
3186 complete_array_type (&type, elt, false);
3188 = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
3189 DECL_SIZE_UNIT (decl)
3190 = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type));
3194 /* Decode a "typename", such as "int **", returning a ..._TYPE node.
3195 Set *EXPR, if EXPR not NULL, to any expression to be evaluated
3196 before the type name, and set *EXPR_CONST_OPERANDS, if
3197 EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
3198 appear in a constant expression. */
3201 groktypename (struct c_type_name *type_name, tree *expr,
3202 bool *expr_const_operands)
3205 tree attrs = type_name->specs->attrs;
3207 type_name->specs->attrs = NULL_TREE;
3209 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
3210 false, NULL, &attrs, expr, expr_const_operands,
3213 /* Apply attributes. */
3214 decl_attributes (&type, attrs, 0);
3219 /* Decode a declarator in an ordinary declaration or data definition.
3220 This is called as soon as the type information and variable name
3221 have been parsed, before parsing the initializer if any.
3222 Here we create the ..._DECL node, fill in its type,
3223 and put it on the list of decls for the current context.
3224 The ..._DECL node is returned as the value.
3226 Exception: for arrays where the length is not specified,
3227 the type is left null, to be filled in by `finish_decl'.
3229 Function definitions do not come here; they go to start_function
3230 instead. However, external and forward declarations of functions
3231 do go through here. Structure field declarations are done by
3232 grokfield and not through here. */
3235 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
3236 bool initialized, tree attributes)
3240 tree expr = NULL_TREE;
3241 enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
3243 /* An object declared as __attribute__((deprecated)) suppresses
3244 warnings of uses of other deprecated items. */
3245 if (lookup_attribute ("deprecated", attributes))
3246 deprecated_state = DEPRECATED_SUPPRESS;
3248 decl = grokdeclarator (declarator, declspecs,
3249 NORMAL, initialized, NULL, &attributes, &expr, NULL,
3257 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
3258 warning (OPT_Wmain, "%q+D is usually a function", decl);
3261 /* Is it valid for this decl to have an initializer at all?
3262 If not, set INITIALIZED to zero, which will indirectly
3263 tell 'finish_decl' to ignore the initializer once it is parsed. */
3264 switch (TREE_CODE (decl))
3267 error ("typedef %qD is initialized (use __typeof__ instead)", decl);
3272 error ("function %qD is initialized like a variable", decl);
3277 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3278 error ("parameter %qD is initialized", decl);
3283 /* Don't allow initializations for incomplete types except for
3284 arrays which might be completed by the initialization. */
3286 /* This can happen if the array size is an undefined macro.
3287 We already gave a warning, so we don't need another one. */
3288 if (TREE_TYPE (decl) == error_mark_node)
3290 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
3292 /* A complete type is ok if size is fixed. */
3294 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3295 || C_DECL_VARIABLE_SIZE (decl))
3297 error ("variable-sized object may not be initialized");
3301 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3303 error ("variable %qD has initializer but incomplete type", decl);
3306 else if (C_DECL_VARIABLE_SIZE (decl))
3308 /* Although C99 is unclear about whether incomplete arrays
3309 of VLAs themselves count as VLAs, it does not make
3310 sense to permit them to be initialized given that
3311 ordinary VLAs may not be initialized. */
3312 error ("variable-sized object may not be initialized");
3319 if (current_scope == file_scope)
3320 TREE_STATIC (decl) = 1;
3322 /* Tell 'pushdecl' this is an initialized decl
3323 even though we don't yet have the initializer expression.
3324 Also tell 'finish_decl' it may store the real initializer. */
3325 DECL_INITIAL (decl) = error_mark_node;
3328 /* If this is a function declaration, write a record describing it to the
3329 prototypes file (if requested). */
3331 if (TREE_CODE (decl) == FUNCTION_DECL)
3332 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
3334 /* ANSI specifies that a tentative definition which is not merged with
3335 a non-tentative definition behaves exactly like a definition with an
3336 initializer equal to zero. (Section 3.7.2)
3338 -fno-common gives strict ANSI behavior, though this tends to break
3339 a large body of code that grew up without this rule.
3341 Thread-local variables are never common, since there's no entrenched
3342 body of code to break, and it allows more efficient variable references
3343 in the presence of dynamic linking. */
3345 if (TREE_CODE (decl) == VAR_DECL
3347 && TREE_PUBLIC (decl)
3348 && !DECL_THREAD_LOCAL_P (decl)
3350 DECL_COMMON (decl) = 1;
3352 /* Set attributes here so if duplicate decl, will have proper attributes. */
3353 decl_attributes (&decl, attributes, 0);
3355 /* Handle gnu_inline attribute. */
3356 if (declspecs->inline_p
3357 && !flag_gnu89_inline
3358 && TREE_CODE (decl) == FUNCTION_DECL
3359 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
3360 || current_function_decl))
3362 if (declspecs->storage_class == csc_auto && current_scope != file_scope)
3364 else if (declspecs->storage_class != csc_static)
3365 DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
3368 if (TREE_CODE (decl) == FUNCTION_DECL
3369 && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
3371 struct c_declarator *ce = declarator;
3373 if (ce->kind == cdk_pointer)
3374 ce = declarator->declarator;
3375 if (ce->kind == cdk_function)
3377 tree args = ce->u.arg_info->parms;
3378 for (; args; args = TREE_CHAIN (args))
3380 tree type = TREE_TYPE (args);
3381 if (type && INTEGRAL_TYPE_P (type)
3382 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
3383 DECL_ARG_TYPE (args) = integer_type_node;
3388 if (TREE_CODE (decl) == FUNCTION_DECL
3389 && DECL_DECLARED_INLINE_P (decl)
3390 && DECL_UNINLINABLE (decl)
3391 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
3392 warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
3395 /* C99 6.7.4p3: An inline definition of a function with external
3396 linkage shall not contain a definition of a modifiable object
3397 with static storage duration... */
3398 if (TREE_CODE (decl) == VAR_DECL
3399 && current_scope != file_scope
3400 && TREE_STATIC (decl)
3401 && !TREE_READONLY (decl)
3402 && DECL_DECLARED_INLINE_P (current_function_decl)
3403 && DECL_EXTERNAL (current_function_decl))
3404 record_inline_static (input_location, current_function_decl,
3405 decl, csi_modifiable);
3407 /* Add this decl to the current scope.
3408 TEM may equal DECL or it may be a previous decl of the same name. */
3409 tem = pushdecl (decl);
3411 if (initialized && DECL_EXTERNAL (tem))
3413 DECL_EXTERNAL (tem) = 0;
3414 TREE_STATIC (tem) = 1;
3420 /* Initialize EH if not initialized yet and exceptions are enabled. */
3423 c_maybe_initialize_eh (void)
3425 if (!flag_exceptions || c_eh_initialized_p)
3428 c_eh_initialized_p = true;
3429 eh_personality_libfunc
3430 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
3431 ? "__gcc_personality_sj0"
3432 : "__gcc_personality_v0");
3433 default_init_unwind_resume_libfunc ();
3434 using_eh_for_cleanups ();
3437 /* Finish processing of a declaration;
3438 install its initial value.
3439 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
3440 If the length of an array type is not known before,
3441 it must be determined now, from the initial value, or it is an error. */
3444 finish_decl (tree decl, tree init, tree origtype, tree asmspec_tree)
3447 int was_incomplete = (DECL_SIZE (decl) == 0);
3448 const char *asmspec = 0;
3450 /* If a name was specified, get the string. */
3451 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
3452 && DECL_FILE_SCOPE_P (decl))
3453 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
3455 asmspec = TREE_STRING_POINTER (asmspec_tree);
3457 /* If `start_decl' didn't like having an initialization, ignore it now. */
3458 if (init != 0 && DECL_INITIAL (decl) == 0)
3461 /* Don't crash if parm is initialized. */
3462 if (TREE_CODE (decl) == PARM_DECL)
3466 store_init_value (decl, init, origtype);
3468 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
3469 || TREE_CODE (decl) == FUNCTION_DECL
3470 || TREE_CODE (decl) == FIELD_DECL))
3471 objc_check_decl (decl);
3473 type = TREE_TYPE (decl);
3475 /* Deduce size of array from initialization, if not already known. */
3476 if (TREE_CODE (type) == ARRAY_TYPE
3477 && TYPE_DOMAIN (type) == 0
3478 && TREE_CODE (decl) != TYPE_DECL)
3481 = (TREE_STATIC (decl)
3482 /* Even if pedantic, an external linkage array
3483 may have incomplete type at first. */
3484 ? pedantic && !TREE_PUBLIC (decl)
3485 : !DECL_EXTERNAL (decl));
3487 = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
3490 /* Get the completed type made by complete_array_type. */
3491 type = TREE_TYPE (decl);
3496 error ("initializer fails to determine size of %q+D", decl);
3501 error ("array size missing in %q+D", decl);
3502 /* If a `static' var's size isn't known,
3503 make it extern as well as static, so it does not get
3505 If it is not `static', then do not mark extern;
3506 finish_incomplete_decl will give it a default size
3507 and it will get allocated. */
3508 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
3509 DECL_EXTERNAL (decl) = 1;
3513 error ("zero or negative size array %q+D", decl);
3517 /* For global variables, update the copy of the type that
3518 exists in the binding. */
3519 if (TREE_PUBLIC (decl))
3521 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
3522 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
3523 b_ext = b_ext->shadowed;
3527 b_ext->type = composite_type (b_ext->type, type);
3538 if (DECL_INITIAL (decl))
3539 TREE_TYPE (DECL_INITIAL (decl)) = type;
3541 layout_decl (decl, 0);
3544 if (TREE_CODE (decl) == VAR_DECL)
3546 if (init && TREE_CODE (init) == CONSTRUCTOR)
3547 add_flexible_array_elts_to_size (decl, init);
3549 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
3550 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
3551 layout_decl (decl, 0);
3553 if (DECL_SIZE (decl) == 0
3554 /* Don't give an error if we already gave one earlier. */
3555 && TREE_TYPE (decl) != error_mark_node
3556 && (TREE_STATIC (decl)
3557 /* A static variable with an incomplete type
3558 is an error if it is initialized.
3559 Also if it is not file scope.
3560 Otherwise, let it through, but if it is not `extern'
3561 then it may cause an error message later. */
3562 ? (DECL_INITIAL (decl) != 0
3563 || !DECL_FILE_SCOPE_P (decl))
3564 /* An automatic variable with an incomplete type
3566 : !DECL_EXTERNAL (decl)))
3568 error ("storage size of %q+D isn%'t known", decl);
3569 TREE_TYPE (decl) = error_mark_node;
3572 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
3573 && DECL_SIZE (decl) != 0)
3575 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3576 constant_expression_warning (DECL_SIZE (decl));
3579 error ("storage size of %q+D isn%'t constant", decl);
3580 TREE_TYPE (decl) = error_mark_node;
3584 if (TREE_USED (type))
3585 TREE_USED (decl) = 1;
3588 /* If this is a function and an assembler name is specified, reset DECL_RTL
3589 so we can give it its new name. Also, update built_in_decls if it
3590 was a normal built-in. */
3591 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
3593 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
3594 set_builtin_user_assembler_name (decl, asmspec);
3595 set_user_assembler_name (decl, asmspec);
3598 /* If #pragma weak was used, mark the decl weak now. */
3599 maybe_apply_pragma_weak (decl);
3601 /* Output the assembler code and/or RTL code for variables and functions,
3602 unless the type is an undefined structure or union.
3603 If not, it will get done when the type is completed. */
3605 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3607 /* Determine the ELF visibility. */
3608 if (TREE_PUBLIC (decl))
3609 c_determine_visibility (decl);
3611 /* This is a no-op in c-lang.c or something real in objc-act.c. */
3612 if (c_dialect_objc ())
3613 objc_check_decl (decl);
3617 /* If this is not a static variable, issue a warning.
3618 It doesn't make any sense to give an ASMSPEC for an
3619 ordinary, non-register local variable. Historically,
3620 GCC has accepted -- but ignored -- the ASMSPEC in
3622 if (!DECL_FILE_SCOPE_P (decl)
3623 && TREE_CODE (decl) == VAR_DECL
3624 && !C_DECL_REGISTER (decl)
3625 && !TREE_STATIC (decl))
3626 warning (0, "ignoring asm-specifier for non-static local "
3627 "variable %q+D", decl);
3629 set_user_assembler_name (decl, asmspec);
3632 if (DECL_FILE_SCOPE_P (decl))
3634 if (DECL_INITIAL (decl) == NULL_TREE
3635 || DECL_INITIAL (decl) == error_mark_node)
3636 /* Don't output anything
3637 when a tentative file-scope definition is seen.
3638 But at end of compilation, do output code for them. */
3639 DECL_DEFER_OUTPUT (decl) = 1;
3640 rest_of_decl_compilation (decl, true, 0);
3644 /* In conjunction with an ASMSPEC, the `register'
3645 keyword indicates that we should place the variable
3646 in a particular register. */
3647 if (asmspec && C_DECL_REGISTER (decl))
3649 DECL_HARD_REGISTER (decl) = 1;
3650 /* This cannot be done for a structure with volatile
3651 fields, on which DECL_REGISTER will have been
3653 if (!DECL_REGISTER (decl))
3654 error ("cannot put object with volatile field into register");
3657 if (TREE_CODE (decl) != FUNCTION_DECL)
3659 /* If we're building a variable sized type, and we might be
3660 reachable other than via the top of the current binding
3661 level, then create a new BIND_EXPR so that we deallocate
3662 the object at the right time. */
3663 /* Note that DECL_SIZE can be null due to errors. */
3664 if (DECL_SIZE (decl)
3665 && !TREE_CONSTANT (DECL_SIZE (decl))
3666 && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
3669 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
3670 TREE_SIDE_EFFECTS (bind) = 1;
3672 BIND_EXPR_BODY (bind) = push_stmt_list ();
3674 add_stmt (build_stmt (DECL_EXPR, decl));
3679 if (!DECL_FILE_SCOPE_P (decl))
3681 /* Recompute the RTL of a local array now
3682 if it used to be an incomplete type. */
3684 && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
3686 /* If we used it already as memory, it must stay in memory. */
3687 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
3688 /* If it's still incomplete now, no init will save it. */
3689 if (DECL_SIZE (decl) == 0)
3690 DECL_INITIAL (decl) = 0;
3695 if (TREE_CODE (decl) == TYPE_DECL)
3697 if (!DECL_FILE_SCOPE_P (decl)
3698 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
3699 add_stmt (build_stmt (DECL_EXPR, decl));
3701 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
3704 /* At the end of a declaration, throw away any variable type sizes
3705 of types defined inside that declaration. There is no use
3706 computing them in the following function definition. */
3707 if (current_scope == file_scope)
3708 get_pending_sizes ();
3710 /* Install a cleanup (aka destructor) if one was given. */
3711 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
3713 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
3716 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
3717 tree cleanup_decl = lookup_name (cleanup_id);
3721 /* Build "cleanup(&decl)" for the destructor. */
3722 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0);
3723 vec = VEC_alloc (tree, gc, 1);
3724 VEC_quick_push (tree, vec, cleanup);
3725 cleanup = build_function_call_vec (cleanup_decl, vec, NULL);
3726 VEC_free (tree, gc, vec);
3728 /* Don't warn about decl unused; the cleanup uses it. */
3729 TREE_USED (decl) = 1;
3730 TREE_USED (cleanup_decl) = 1;
3732 /* Initialize EH, if we've been told to do so. */
3733 c_maybe_initialize_eh ();
3735 push_cleanup (decl, cleanup, false);
3740 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */
3743 grokparm (const struct c_parm *parm)
3745 tree attrs = parm->attrs;
3746 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
3747 NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL);
3749 decl_attributes (&decl, attrs, 0);
3754 /* Given a parsed parameter declaration, decode it into a PARM_DECL
3755 and push that on the current scope. */
3758 push_parm_decl (const struct c_parm *parm)
3760 tree attrs = parm->attrs;
3763 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
3764 &attrs, NULL, NULL, DEPRECATED_NORMAL);
3765 decl_attributes (&decl, attrs, 0);
3767 decl = pushdecl (decl);
3769 finish_decl (decl, NULL_TREE, NULL_TREE, NULL_TREE);
3772 /* Mark all the parameter declarations to date as forward decls.
3773 Also diagnose use of this extension. */
3776 mark_forward_parm_decls (void)
3778 struct c_binding *b;
3780 if (pedantic && !current_scope->warned_forward_parm_decls)
3782 pedwarn (input_location, OPT_pedantic,
3783 "ISO C forbids forward parameter declarations");
3784 current_scope->warned_forward_parm_decls = true;
3787 for (b = current_scope->bindings; b; b = b->prev)
3788 if (TREE_CODE (b->decl) == PARM_DECL)
3789 TREE_ASM_WRITTEN (b->decl) = 1;
3792 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3793 literal, which may be an incomplete array type completed by the
3794 initializer; INIT is a CONSTRUCTOR that initializes the compound
3795 literal. NON_CONST is true if the initializers contain something
3796 that cannot occur in a constant expression. */
3799 build_compound_literal (tree type, tree init, bool non_const)
3801 /* We do not use start_decl here because we have a type, not a declarator;
3802 and do not use finish_decl because the decl should be stored inside
3803 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
3808 if (type == error_mark_node)
3809 return error_mark_node;
3811 decl = build_decl (VAR_DECL, NULL_TREE, type);
3812 DECL_EXTERNAL (decl) = 0;
3813 TREE_PUBLIC (decl) = 0;
3814 TREE_STATIC (decl) = (current_scope == file_scope);
3815 DECL_CONTEXT (decl) = current_function_decl;
3816 TREE_USED (decl) = 1;
3817 TREE_TYPE (decl) = type;
3818 TREE_READONLY (decl) = TYPE_READONLY (type);
3819 store_init_value (decl, init, NULL_TREE);
3821 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
3823 int failure = complete_array_type (&TREE_TYPE (decl),
3824 DECL_INITIAL (decl), true);
3825 gcc_assert (!failure);
3827 type = TREE_TYPE (decl);
3828 TREE_TYPE (DECL_INITIAL (decl)) = type;
3831 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
3832 return error_mark_node;
3834 stmt = build_stmt (DECL_EXPR, decl);
3835 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
3836 TREE_SIDE_EFFECTS (complit) = 1;
3838 layout_decl (decl, 0);
3840 if (TREE_STATIC (decl))
3842 /* This decl needs a name for the assembler output. */
3843 set_compound_literal_name (decl);
3844 DECL_DEFER_OUTPUT (decl) = 1;
3845 DECL_COMDAT (decl) = 1;
3846 DECL_ARTIFICIAL (decl) = 1;
3847 DECL_IGNORED_P (decl) = 1;
3849 rest_of_decl_compilation (decl, 1, 0);
3854 complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
3855 C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
3861 /* Determine whether TYPE is a structure with a flexible array member,
3862 or a union containing such a structure (possibly recursively). */
3865 flexible_array_type_p (tree type)
3868 switch (TREE_CODE (type))
3871 x = TYPE_FIELDS (type);
3874 while (TREE_CHAIN (x) != NULL_TREE)
3876 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
3877 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3878 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
3879 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
3883 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
3885 if (flexible_array_type_p (TREE_TYPE (x)))
3894 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3895 replacing with appropriate values if they are invalid. */
3897 check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
3900 unsigned int max_width;
3901 unsigned HOST_WIDE_INT w;
3902 const char *name = (orig_name
3903 ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
3904 : _("<anonymous>"));
3906 /* Detect and ignore out of range field width and process valid
3908 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))
3909 || TREE_CODE (*width) != INTEGER_CST)
3911 error ("bit-field %qs width not an integer constant", name);
3912 *width = integer_one_node;
3916 constant_expression_warning (*width);
3917 if (tree_int_cst_sgn (*width) < 0)
3919 error ("negative width in bit-field %qs", name);
3920 *width = integer_one_node;
3922 else if (integer_zerop (*width) && orig_name)
3924 error ("zero width for bit-field %qs", name);
3925 *width = integer_one_node;
3929 /* Detect invalid bit-field type. */
3930 if (TREE_CODE (*type) != INTEGER_TYPE
3931 && TREE_CODE (*type) != BOOLEAN_TYPE
3932 && TREE_CODE (*type) != ENUMERAL_TYPE)
3934 error ("bit-field %qs has invalid type", name);
3935 *type = unsigned_type_node;
3938 type_mv = TYPE_MAIN_VARIANT (*type);
3939 if (!in_system_header
3940 && type_mv != integer_type_node
3941 && type_mv != unsigned_type_node
3942 && type_mv != boolean_type_node)
3943 pedwarn (input_location, OPT_pedantic,
3944 "type of bit-field %qs is a GCC extension", name);
3946 max_width = TYPE_PRECISION (*type);
3948 if (0 < compare_tree_int (*width, max_width))
3950 error ("width of %qs exceeds its type", name);
3952 *width = build_int_cst (NULL_TREE, w);
3955 w = tree_low_cst (*width, 1);
3957 if (TREE_CODE (*type) == ENUMERAL_TYPE)
3959 struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
3961 || w < tree_int_cst_min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
3962 || w < tree_int_cst_min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
3963 warning (0, "%qs is narrower than values of its type", name);
3969 /* Print warning about variable length array if necessary. */
3972 warn_variable_length_array (tree name, tree size)
3974 int const_size = TREE_CONSTANT (size);
3976 if (!flag_isoc99 && pedantic && warn_vla != 0)
3981 pedwarn (input_location, OPT_Wvla,
3982 "ISO C90 forbids array %qE whose size "
3983 "can%'t be evaluated",
3986 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size "
3987 "can%'t be evaluated");
3992 pedwarn (input_location, OPT_Wvla,
3993 "ISO C90 forbids variable length array %qE",
3996 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array");
3999 else if (warn_vla > 0)
4005 "the size of array %qE can"
4006 "%'t be evaluated", name);
4009 "the size of array can %'t be evaluated");
4015 "variable length array %qE is used",
4019 "variable length array is used");
4024 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR to
4025 serve as the actual size-expression for a type or decl. This is
4026 like variable_size in stor-layout.c, but we make global_bindings_p
4027 return negative to avoid calls to that function from outside the
4028 front end resulting in errors at file scope, then call this version
4029 instead from front-end code. */
4032 c_variable_size (tree size)
4036 if (TREE_CONSTANT (size))
4039 size = save_expr (size);
4041 save = skip_simple_arithmetic (size);
4043 if (cfun && cfun->dont_save_pending_sizes_p)
4046 if (!global_bindings_p ())
4047 put_pending_size (save);
4052 /* Given declspecs and a declarator,
4053 determine the name and type of the object declared
4054 and construct a ..._DECL node for it.
4055 (In one case we can return a ..._TYPE node instead.
4056 For invalid input we sometimes return 0.)
4058 DECLSPECS is a c_declspecs structure for the declaration specifiers.
4060 DECL_CONTEXT says which syntactic context this declaration is in:
4061 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
4062 FUNCDEF for a function definition. Like NORMAL but a few different
4063 error messages in each case. Return value may be zero meaning
4064 this definition is too screwy to try to parse.
4065 PARM for a parameter declaration (either within a function prototype
4066 or before a function body). Make a PARM_DECL, or return void_type_node.
4067 TYPENAME if for a typename (in a cast or sizeof).
4068 Don't make a DECL node; just return the ..._TYPE node.
4069 FIELD for a struct or union field; make a FIELD_DECL.
4070 INITIALIZED is true if the decl has an initializer.
4071 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
4072 representing the width of the bit-field.
4073 DECL_ATTRS points to the list of attributes that should be added to this
4074 decl. Any nested attributes that belong on the decl itself will be
4076 If EXPR is not NULL, any expressions that need to be evaluated as
4077 part of evaluating variably modified types will be stored in *EXPR.
4078 If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
4079 set to indicate whether operands in *EXPR can be used in constant
4081 DEPRECATED_STATE is a deprecated_states value indicating whether
4082 deprecation warnings should be suppressed.
4084 In the TYPENAME case, DECLARATOR is really an absolute declarator.
4085 It may also be so in the PARM case, for a prototype where the
4086 argument type is specified but not the name.
4088 This function is where the complicated C meanings of `static'
4089 and `extern' are interpreted. */
4092 grokdeclarator (const struct c_declarator *declarator,
4093 struct c_declspecs *declspecs,
4094 enum decl_context decl_context, bool initialized, tree *width,
4095 tree *decl_attrs, tree *expr, bool *expr_const_operands,
4096 enum deprecated_states deprecated_state)
4098 tree type = declspecs->type;
4099 bool threadp = declspecs->thread_p;
4100 enum c_storage_class storage_class = declspecs->storage_class;
4104 int type_quals = TYPE_UNQUALIFIED;
4105 tree name = NULL_TREE;
4106 bool funcdef_flag = false;
4107 bool funcdef_syntax = false;
4108 int size_varies = 0;
4109 tree decl_attr = declspecs->decl_attr;
4110 int array_ptr_quals = TYPE_UNQUALIFIED;
4111 tree array_ptr_attrs = NULL_TREE;
4112 int array_parm_static = 0;
4113 bool array_parm_vla_unspec_p = false;
4114 tree returned_attrs = NULL_TREE;
4115 bool bitfield = width != NULL;
4117 struct c_arg_info *arg_info = 0;
4119 bool expr_const_operands_dummy;
4123 if (expr_const_operands == NULL)
4124 expr_const_operands = &expr_const_operands_dummy;
4126 *expr = declspecs->expr;
4127 *expr_const_operands = declspecs->expr_const_operands;
4129 if (decl_context == FUNCDEF)
4130 funcdef_flag = true, decl_context = NORMAL;
4132 /* Look inside a declarator for the name being declared
4133 and get it as an IDENTIFIER_NODE, for an error message. */
4135 const struct c_declarator *decl = declarator;
4143 funcdef_syntax = (decl->kind == cdk_function);
4144 decl = decl->declarator;
4148 decl = decl->declarator;
4162 gcc_assert (decl_context == PARM
4163 || decl_context == TYPENAME
4164 || (decl_context == FIELD
4165 && declarator->kind == cdk_id));
4166 gcc_assert (!initialized);
4170 /* A function definition's declarator must have the form of
4171 a function declarator. */
4173 if (funcdef_flag && !funcdef_syntax)
4176 /* If this looks like a function definition, make it one,
4177 even if it occurs where parms are expected.
4178 Then store_parm_decls will reject it and not use it as a parm. */
4179 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
4180 decl_context = PARM;
4182 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
4183 warn_deprecated_use (declspecs->type);
4185 if ((decl_context == NORMAL || decl_context == FIELD)
4186 && current_scope == file_scope
4187 && variably_modified_type_p (type, NULL_TREE))
4190 error ("variably modified %qE at file scope", name);
4192 error ("variably modified field at file scope");
4193 type = integer_type_node;
4196 size_varies = C_TYPE_VARIABLE_SIZE (type);
4198 /* Diagnose defaulting to "int". */
4200 if (declspecs->default_int_p && !in_system_header)
4202 /* Issue a warning if this is an ISO C 99 program or if
4203 -Wreturn-type and this is a function, or if -Wimplicit;
4204 prefer the former warning since it is more explicit. */
4205 if ((warn_implicit_int || warn_return_type || flag_isoc99)
4207 warn_about_return_type = 1;
4211 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
4212 "type defaults to %<int%> in declaration of %qE",
4215 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
4216 "type defaults to %<int%> in type name");
4220 /* Adjust the type if a bit-field is being declared,
4221 -funsigned-bitfields applied and the type is not explicitly
4223 if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
4224 && TREE_CODE (type) == INTEGER_TYPE)
4225 type = unsigned_type_for (type);
4227 /* Figure out the type qualifiers for the declaration. There are
4228 two ways a declaration can become qualified. One is something
4229 like `const int i' where the `const' is explicit. Another is
4230 something like `typedef const int CI; CI i' where the type of the
4231 declaration contains the `const'. A third possibility is that
4232 there is a type qualifier on the element type of a typedefed
4233 array type, in which case we should extract that qualifier so
4234 that c_apply_type_quals_to_decl receives the full list of
4235 qualifiers to work with (C90 is not entirely clear about whether
4236 duplicate qualifiers should be diagnosed in this case, but it
4237 seems most appropriate to do so). */
4238 element_type = strip_array_types (type);
4239 constp = declspecs->const_p + TYPE_READONLY (element_type);
4240 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
4241 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
4242 if (pedantic && !flag_isoc99)
4245 pedwarn (input_location, OPT_pedantic, "duplicate %<const%>");
4247 pedwarn (input_location, OPT_pedantic, "duplicate %<restrict%>");
4249 pedwarn (input_location, OPT_pedantic, "duplicate %<volatile%>");
4251 if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
4252 type = TYPE_MAIN_VARIANT (type);
4253 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4254 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4255 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
4257 /* Warn about storage classes that are invalid for certain
4258 kinds of declarations (parameters, typenames, etc.). */
4262 || storage_class == csc_auto
4263 || storage_class == csc_register
4264 || storage_class == csc_typedef))
4266 if (storage_class == csc_auto)
4267 pedwarn (input_location,
4268 (current_scope == file_scope) ? 0 : OPT_pedantic,
4269 "function definition declared %<auto%>");
4270 if (storage_class == csc_register)
4271 error ("function definition declared %<register%>");
4272 if (storage_class == csc_typedef)
4273 error ("function definition declared %<typedef%>");
4275 error ("function definition declared %<__thread%>");
4277 if (storage_class == csc_auto
4278 || storage_class == csc_register
4279 || storage_class == csc_typedef)
4280 storage_class = csc_none;
4282 else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
4284 if (decl_context == PARM && storage_class == csc_register)
4288 switch (decl_context)
4292 error ("storage class specified for structure field %qE",
4295 error ("storage class specified for structure field");
4299 error ("storage class specified for parameter %qE", name);
4301 error ("storage class specified for unnamed parameter");
4304 error ("storage class specified for typename");
4307 storage_class = csc_none;
4311 else if (storage_class == csc_extern
4315 /* 'extern' with initialization is invalid if not at file scope. */
4316 if (current_scope == file_scope)
4318 /* It is fine to have 'extern const' when compiling at C
4319 and C++ intersection. */
4320 if (!(warn_cxx_compat && constp))
4321 warning (0, "%qE initialized and declared %<extern%>", name);
4324 error ("%qE has both %<extern%> and initializer", name);
4326 else if (current_scope == file_scope)
4328 if (storage_class == csc_auto)
4329 error ("file-scope declaration of %qE specifies %<auto%>", name);
4330 if (pedantic && storage_class == csc_register)
4331 pedwarn (input_location, OPT_pedantic,
4332 "file-scope declaration of %qE specifies %<register%>", name);
4336 if (storage_class == csc_extern && funcdef_flag)
4337 error ("nested function %qE declared %<extern%>", name);
4338 else if (threadp && storage_class == csc_none)
4340 error ("function-scope %qE implicitly auto and declared "
4347 /* Now figure out the structure of the declarator proper.
4348 Descend through it, creating more complex types, until we reach
4349 the declared identifier (or NULL_TREE, in an absolute declarator).
4350 At each stage we maintain an unqualified version of the type
4351 together with any qualifiers that should be applied to it with
4352 c_build_qualified_type; this way, array types including
4353 multidimensional array types are first built up in unqualified
4354 form and then the qualified form is created with
4355 TYPE_MAIN_VARIANT pointing to the unqualified form. */
4357 while (declarator && declarator->kind != cdk_id)
4359 if (type == error_mark_node)
4361 declarator = declarator->declarator;
4365 /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
4366 a cdk_pointer (for *...),
4367 a cdk_function (for ...(...)),
4368 a cdk_attrs (for nested attributes),
4369 or a cdk_id (for the name being declared
4370 or the place in an absolute declarator
4371 where the name was omitted).
4372 For the last case, we have just exited the loop.
4374 At this point, TYPE is the type of elements of an array,
4375 or for a function to return, or for a pointer to point to.
4376 After this sequence of ifs, TYPE is the type of the
4377 array or function or pointer, and DECLARATOR has had its
4378 outermost layer removed. */
4380 if (array_ptr_quals != TYPE_UNQUALIFIED
4381 || array_ptr_attrs != NULL_TREE
4382 || array_parm_static)
4384 /* Only the innermost declarator (making a parameter be of
4385 array type which is converted to pointer type)
4386 may have static or type qualifiers. */
4387 error ("static or type qualifiers in non-parameter array declarator");
4388 array_ptr_quals = TYPE_UNQUALIFIED;
4389 array_ptr_attrs = NULL_TREE;
4390 array_parm_static = 0;
4393 switch (declarator->kind)
4397 /* A declarator with embedded attributes. */
4398 tree attrs = declarator->u.attrs;
4399 const struct c_declarator *inner_decl;
4401 declarator = declarator->declarator;
4402 inner_decl = declarator;
4403 while (inner_decl->kind == cdk_attrs)
4404 inner_decl = inner_decl->declarator;
4405 if (inner_decl->kind == cdk_id)
4406 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
4407 else if (inner_decl->kind == cdk_function)
4408 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
4409 else if (inner_decl->kind == cdk_array)
4410 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
4411 returned_attrs = decl_attributes (&type,
4412 chainon (returned_attrs, attrs),
4418 tree itype = NULL_TREE;
4419 tree size = declarator->u.array.dimen;
4420 /* The index is a signed object `sizetype' bits wide. */
4421 tree index_type = c_common_signed_type (sizetype);
4423 array_ptr_quals = declarator->u.array.quals;
4424 array_ptr_attrs = declarator->u.array.attrs;
4425 array_parm_static = declarator->u.array.static_p;
4426 array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
4428 declarator = declarator->declarator;
4430 /* Check for some types that there cannot be arrays of. */
4432 if (VOID_TYPE_P (type))
4435 error ("declaration of %qE as array of voids", name);
4437 error ("declaration of type name as array of voids");
4438 type = error_mark_node;
4441 if (TREE_CODE (type) == FUNCTION_TYPE)
4444 error ("declaration of %qE as array of functions", name);
4446 error ("declaration of type name as array of functions");
4447 type = error_mark_node;
4450 if (pedantic && !in_system_header && flexible_array_type_p (type))
4451 pedwarn (input_location, OPT_pedantic,
4452 "invalid use of structure with flexible array member");
4454 if (size == error_mark_node)
4455 type = error_mark_node;
4457 if (type == error_mark_node)
4460 /* If size was specified, set ITYPE to a range-type for
4461 that size. Otherwise, ITYPE remains null. finish_decl
4462 may figure it out from an initial value. */
4466 bool size_maybe_const = true;
4467 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
4468 && !TREE_OVERFLOW (size));
4469 bool this_size_varies = false;
4471 /* Strip NON_LVALUE_EXPRs since we aren't using as an
4473 STRIP_TYPE_NOPS (size);
4475 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
4478 error ("size of array %qE has non-integer type", name);
4480 error ("size of unnamed array has non-integer type");
4481 size = integer_one_node;
4484 size = c_fully_fold (size, false, &size_maybe_const);
4486 if (pedantic && size_maybe_const && integer_zerop (size))
4489 pedwarn (input_location, OPT_pedantic,
4490 "ISO C forbids zero-size array %qE", name);
4492 pedwarn (input_location, OPT_pedantic,
4493 "ISO C forbids zero-size array");
4496 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
4498 constant_expression_warning (size);
4499 if (tree_int_cst_sgn (size) < 0)
4502 error ("size of array %qE is negative", name);
4504 error ("size of unnamed array is negative");
4505 size = integer_one_node;
4507 /* Handle a size folded to an integer constant but
4508 not an integer constant expression. */
4509 if (!size_int_const)
4511 /* If this is a file scope declaration of an
4512 ordinary identifier, this is invalid code;
4513 diagnosing it here and not subsequently
4514 treating the type as variable-length avoids
4515 more confusing diagnostics later. */
4516 if ((decl_context == NORMAL || decl_context == FIELD)
4517 && current_scope == file_scope)
4518 pedwarn (input_location, 0,
4519 "variably modified %qE at file scope",
4522 this_size_varies = size_varies = 1;
4523 warn_variable_length_array (name, size);
4526 else if ((decl_context == NORMAL || decl_context == FIELD)
4527 && current_scope == file_scope)
4529 error ("variably modified %qE at file scope", name);
4530 size = integer_one_node;
4534 /* Make sure the array size remains visibly
4535 nonconstant even if it is (eg) a const variable
4536 with known value. */
4537 this_size_varies = size_varies = 1;
4538 warn_variable_length_array (name, size);
4541 if (integer_zerop (size) && !this_size_varies)
4543 /* A zero-length array cannot be represented with
4544 an unsigned index type, which is what we'll
4545 get with build_index_type. Create an
4546 open-ended range instead. */
4547 itype = build_range_type (sizetype, size, NULL_TREE);
4551 /* Arrange for the SAVE_EXPR on the inside of the
4552 MINUS_EXPR, which allows the -1 to get folded
4553 with the +1 that happens when building TYPE_SIZE. */
4555 size = c_variable_size (size);
4556 if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
4557 size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
4558 integer_zero_node, size);
4560 /* Compute the maximum valid index, that is, size
4561 - 1. Do the calculation in index_type, so that
4562 if it is a variable the computations will be
4563 done in the proper mode. */
4564 itype = fold_build2 (MINUS_EXPR, index_type,
4565 convert (index_type, size),
4566 convert (index_type,
4569 /* If that overflowed, the array is too big. ???
4570 While a size of INT_MAX+1 technically shouldn't
4571 cause an overflow (because we subtract 1), the
4572 overflow is recorded during the conversion to
4573 index_type, before the subtraction. Handling
4574 this case seems like an unnecessary
4576 if (TREE_CODE (itype) == INTEGER_CST
4577 && TREE_OVERFLOW (itype))
4580 error ("size of array %qE is too large", name);
4582 error ("size of unnamed array is too large");
4583 type = error_mark_node;
4587 itype = build_index_type (itype);
4589 if (this_size_varies)
4592 *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
4596 *expr_const_operands &= size_maybe_const;
4599 else if (decl_context == FIELD)
4601 bool flexible_array_member = false;
4602 if (array_parm_vla_unspec_p)
4603 /* Field names can in fact have function prototype
4604 scope so [*] is disallowed here through making
4605 the field variably modified, not through being
4606 something other than a declaration with function
4611 const struct c_declarator *t = declarator;
4612 while (t->kind == cdk_attrs)
4614 flexible_array_member = (t->kind == cdk_id);
4616 if (flexible_array_member
4617 && pedantic && !flag_isoc99 && !in_system_header)
4618 pedwarn (input_location, OPT_pedantic,
4619 "ISO C90 does not support flexible array members");
4621 /* ISO C99 Flexible array members are effectively
4622 identical to GCC's zero-length array extension. */
4623 if (flexible_array_member || array_parm_vla_unspec_p)
4624 itype = build_range_type (sizetype, size_zero_node,
4627 else if (decl_context == PARM)
4629 if (array_parm_vla_unspec_p)
4631 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
4635 else if (decl_context == TYPENAME)
4637 if (array_parm_vla_unspec_p)
4640 warning (0, "%<[*]%> not in a declaration");
4641 /* We use this to avoid messing up with incomplete
4642 array types of the same type, that would
4643 otherwise be modified below. */
4644 itype = build_range_type (sizetype, size_zero_node,
4650 /* Complain about arrays of incomplete types. */
4651 if (!COMPLETE_TYPE_P (type))
4653 error ("array type has incomplete element type");
4654 type = error_mark_node;
4657 /* When itype is NULL, a shared incomplete array type is
4658 returned for all array of a given type. Elsewhere we
4659 make sure we don't complete that type before copying
4660 it, but here we want to make sure we don't ever
4661 modify the shared type, so we gcc_assert (itype)
4663 type = build_array_type (type, itype);
4665 if (type != error_mark_node)
4669 /* It is ok to modify type here even if itype is
4670 NULL: if size_varies, we're in a
4671 multi-dimensional array and the inner type has
4672 variable size, so the enclosing shared array type
4674 if (size && TREE_CODE (size) == INTEGER_CST)
4676 = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
4677 C_TYPE_VARIABLE_SIZE (type) = 1;
4680 /* The GCC extension for zero-length arrays differs from
4681 ISO flexible array members in that sizeof yields
4683 if (size && integer_zerop (size))
4686 TYPE_SIZE (type) = bitsize_zero_node;
4687 TYPE_SIZE_UNIT (type) = size_zero_node;
4689 if (array_parm_vla_unspec_p)
4692 /* The type is complete. C99 6.7.5.2p4 */
4693 TYPE_SIZE (type) = bitsize_zero_node;
4694 TYPE_SIZE_UNIT (type) = size_zero_node;
4698 if (decl_context != PARM
4699 && (array_ptr_quals != TYPE_UNQUALIFIED
4700 || array_ptr_attrs != NULL_TREE
4701 || array_parm_static))
4703 error ("static or type qualifiers in non-parameter array declarator");
4704 array_ptr_quals = TYPE_UNQUALIFIED;
4705 array_ptr_attrs = NULL_TREE;
4706 array_parm_static = 0;
4712 /* Say it's a definition only for the declarator closest
4713 to the identifier, apart possibly from some
4715 bool really_funcdef = false;
4719 const struct c_declarator *t = declarator->declarator;
4720 while (t->kind == cdk_attrs)
4722 really_funcdef = (t->kind == cdk_id);
4725 /* Declaring a function type. Make sure we have a valid
4726 type for the function to return. */
4727 if (type == error_mark_node)
4732 /* Warn about some types functions can't return. */
4733 if (TREE_CODE (type) == FUNCTION_TYPE)
4736 error ("%qE declared as function returning a function",
4739 error ("type name declared as function "
4740 "returning a function");
4741 type = integer_type_node;
4743 if (TREE_CODE (type) == ARRAY_TYPE)
4746 error ("%qE declared as function returning an array", name);
4748 error ("type name declared as function returning an array");
4749 type = integer_type_node;
4752 /* Construct the function type and go to the next
4753 inner layer of declarator. */
4754 arg_info = declarator->u.arg_info;
4755 arg_types = grokparms (arg_info, really_funcdef);
4757 put_pending_sizes (arg_info->pending_sizes);
4759 /* Type qualifiers before the return type of the function
4760 qualify the return type, not the function type. */
4763 /* Type qualifiers on a function return type are
4764 normally permitted by the standard but have no
4765 effect, so give a warning at -Wreturn-type.
4766 Qualifiers on a void return type are banned on
4767 function definitions in ISO C; GCC used to used
4768 them for noreturn functions. */
4769 if (VOID_TYPE_P (type) && really_funcdef)
4770 pedwarn (input_location, 0,
4771 "function definition has qualified void return type");
4773 warning (OPT_Wignored_qualifiers,
4774 "type qualifiers ignored on function return type");
4776 type = c_build_qualified_type (type, type_quals);
4778 type_quals = TYPE_UNQUALIFIED;
4780 type = build_function_type (type, arg_types);
4781 declarator = declarator->declarator;
4783 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4784 the formal parameter list of this FUNCTION_TYPE to point to
4785 the FUNCTION_TYPE node itself. */
4789 for (link = arg_info->tags;
4791 link = TREE_CHAIN (link))
4792 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4798 /* Merge any constancy or volatility into the target type
4801 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4803 pedwarn (input_location, OPT_pedantic,
4804 "ISO C forbids qualified function types");
4806 type = c_build_qualified_type (type, type_quals);
4809 /* When the pointed-to type involves components of variable size,
4810 care must be taken to ensure that the size evaluation code is
4811 emitted early enough to dominate all the possible later uses
4812 and late enough for the variables on which it depends to have
4815 This is expected to happen automatically when the pointed-to
4816 type has a name/declaration of it's own, but special attention
4817 is required if the type is anonymous.
4819 We handle the NORMAL and FIELD contexts here by attaching an
4820 artificial TYPE_DECL to such pointed-to type. This forces the
4821 sizes evaluation at a safe point and ensures it is not deferred
4822 until e.g. within a deeper conditional context.
4824 We expect nothing to be needed here for PARM or TYPENAME.
4825 Pushing a TYPE_DECL at this point for TYPENAME would actually
4826 be incorrect, as we might be in the middle of an expression
4827 with side effects on the pointed-to type size "arguments" prior
4828 to the pointer declaration point and the fake TYPE_DECL in the
4829 enclosing context would force the size evaluation prior to the
4832 if (!TYPE_NAME (type)
4833 && (decl_context == NORMAL || decl_context == FIELD)
4834 && variably_modified_type_p (type, NULL_TREE))
4836 tree decl = build_decl (TYPE_DECL, NULL_TREE, type);
4837 DECL_ARTIFICIAL (decl) = 1;
4839 finish_decl (decl, NULL_TREE, NULL_TREE, NULL_TREE);
4840 TYPE_NAME (type) = decl;
4843 type = build_pointer_type (type);
4845 /* Process type qualifiers (such as const or volatile)
4846 that were given inside the `*'. */
4847 type_quals = declarator->u.pointer_quals;
4849 declarator = declarator->declarator;
4856 *decl_attrs = chainon (returned_attrs, *decl_attrs);
4858 /* Now TYPE has the actual type, apart from any qualifiers in
4861 /* Check the type and width of a bit-field. */
4863 check_bitfield_type_and_width (&type, width, name);
4865 /* Did array size calculations overflow? */
4867 if (TREE_CODE (type) == ARRAY_TYPE
4868 && COMPLETE_TYPE_P (type)
4869 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
4870 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
4873 error ("size of array %qE is too large", name);
4875 error ("size of unnamed array is too large");
4876 /* If we proceed with the array type as it is, we'll eventually
4877 crash in tree_low_cst(). */
4878 type = error_mark_node;
4881 /* If this is declaring a typedef name, return a TYPE_DECL. */
4883 if (storage_class == csc_typedef)
4886 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4888 pedwarn (input_location, OPT_pedantic,
4889 "ISO C forbids qualified function types");
4891 type = c_build_qualified_type (type, type_quals);
4892 decl = build_decl (TYPE_DECL, declarator->u.id, type);
4893 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
4894 if (declspecs->explicit_signed_p)
4895 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4896 if (declspecs->inline_p)
4897 pedwarn (input_location, 0,"typedef %q+D declared %<inline%>", decl);
4901 /* If this is a type name (such as, in a cast or sizeof),
4902 compute the type and return it now. */
4904 if (decl_context == TYPENAME)
4906 /* Note that the grammar rejects storage classes in typenames
4908 gcc_assert (storage_class == csc_none && !threadp
4909 && !declspecs->inline_p);
4910 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4912 pedwarn (input_location, OPT_pedantic,
4913 "ISO C forbids const or volatile function types");
4915 type = c_build_qualified_type (type, type_quals);
4919 if (pedantic && decl_context == FIELD
4920 && variably_modified_type_p (type, NULL_TREE))
4923 pedwarn (input_location, OPT_pedantic,
4924 "a member of a structure or union cannot have a variably modified type");
4927 /* Aside from typedefs and type names (handle above),
4928 `void' at top level (not within pointer)
4929 is allowed only in public variables.
4930 We don't complain about parms either, but that is because
4931 a better error message can be made later. */
4933 if (VOID_TYPE_P (type) && decl_context != PARM
4934 && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4935 && (storage_class == csc_extern
4936 || (current_scope == file_scope
4937 && !(storage_class == csc_static
4938 || storage_class == csc_register)))))
4940 error ("variable or field %qE declared void", name);
4941 type = integer_type_node;
4944 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4945 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4950 if (decl_context == PARM)
4954 /* A parameter declared as an array of T is really a pointer to T.
4955 One declared as a function is really a pointer to a function. */
4957 if (TREE_CODE (type) == ARRAY_TYPE)
4959 /* Transfer const-ness of array into that of type pointed to. */
4960 type = TREE_TYPE (type);
4962 type = c_build_qualified_type (type, type_quals);
4963 type = build_pointer_type (type);
4964 type_quals = array_ptr_quals;
4966 type = c_build_qualified_type (type, type_quals);
4968 /* We don't yet implement attributes in this context. */
4969 if (array_ptr_attrs != NULL_TREE)
4970 warning (OPT_Wattributes,
4971 "attributes in parameter array declarator ignored");
4975 else if (TREE_CODE (type) == FUNCTION_TYPE)
4978 pedwarn (input_location, OPT_pedantic,
4979 "ISO C forbids qualified function types");
4981 type = c_build_qualified_type (type, type_quals);
4982 type = build_pointer_type (type);
4983 type_quals = TYPE_UNQUALIFIED;
4985 else if (type_quals)
4986 type = c_build_qualified_type (type, type_quals);
4988 decl = build_decl (PARM_DECL, declarator->u.id, type);
4989 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
4991 C_DECL_VARIABLE_SIZE (decl) = 1;
4993 /* Compute the type actually passed in the parmlist,
4994 for the case where there is no prototype.
4995 (For example, shorts and chars are passed as ints.)
4996 When there is a prototype, this is overridden later. */
4998 if (type == error_mark_node)
4999 promoted_type = type;
5001 promoted_type = c_type_promotes_to (type);
5003 DECL_ARG_TYPE (decl) = promoted_type;
5004 if (declspecs->inline_p)
5005 pedwarn (input_location, 0, "parameter %q+D declared %<inline%>", decl);
5007 else if (decl_context == FIELD)
5009 /* Note that the grammar rejects storage classes in typenames
5011 gcc_assert (storage_class == csc_none && !threadp
5012 && !declspecs->inline_p);
5014 /* Structure field. It may not be a function. */
5016 if (TREE_CODE (type) == FUNCTION_TYPE)
5018 error ("field %qE declared as a function", name);
5019 type = build_pointer_type (type);
5021 else if (TREE_CODE (type) != ERROR_MARK
5022 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
5024 error ("field %qE has incomplete type", name);
5025 type = error_mark_node;
5027 type = c_build_qualified_type (type, type_quals);
5028 decl = build_decl (FIELD_DECL, declarator->u.id, type);
5029 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
5030 DECL_NONADDRESSABLE_P (decl) = bitfield;
5031 if (bitfield && !declarator->u.id)
5032 TREE_NO_WARNING (decl) = 1;
5035 C_DECL_VARIABLE_SIZE (decl) = 1;
5037 else if (TREE_CODE (type) == FUNCTION_TYPE)
5039 if (storage_class == csc_register || threadp)
5041 error ("invalid storage class for function %qE", name);
5043 else if (current_scope != file_scope)
5045 /* Function declaration not at file scope. Storage
5046 classes other than `extern' are not allowed, C99
5047 6.7.1p5, and `extern' makes no difference. However,
5048 GCC allows 'auto', perhaps with 'inline', to support
5049 nested functions. */
5050 if (storage_class == csc_auto)
5051 pedwarn (input_location, OPT_pedantic,
5052 "invalid storage class for function %qE", name);
5053 else if (storage_class == csc_static)
5055 error ("invalid storage class for function %qE", name);
5057 storage_class = declspecs->storage_class = csc_none;
5063 decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
5064 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
5065 decl = build_decl_attribute_variant (decl, decl_attr);
5067 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
5068 pedwarn (input_location, OPT_pedantic,
5069 "ISO C forbids qualified function types");
5071 /* GNU C interprets a volatile-qualified function type to indicate
5072 that the function does not return. */
5073 if ((type_quals & TYPE_QUAL_VOLATILE)
5074 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
5075 warning (0, "%<noreturn%> function returns non-void value");
5077 /* Every function declaration is an external reference
5078 (DECL_EXTERNAL) except for those which are not at file
5079 scope and are explicitly declared "auto". This is
5080 forbidden by standard C (C99 6.7.1p5) and is interpreted by
5081 GCC to signify a forward declaration of a nested function. */
5082 if (storage_class == csc_auto && current_scope != file_scope)
5083 DECL_EXTERNAL (decl) = 0;
5084 /* In C99, a function which is declared 'inline' with 'extern'
5085 is not an external reference (which is confusing). It
5086 means that the later definition of the function must be output
5087 in this file, C99 6.7.4p6. In GNU C89, a function declared
5088 'extern inline' is an external reference. */
5089 else if (declspecs->inline_p && storage_class != csc_static)
5090 DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
5091 == flag_gnu89_inline);
5093 DECL_EXTERNAL (decl) = !initialized;
5095 /* Record absence of global scope for `static' or `auto'. */
5097 = !(storage_class == csc_static || storage_class == csc_auto);
5099 /* For a function definition, record the argument information
5100 block where store_parm_decls will look for it. */
5102 current_function_arg_info = arg_info;
5104 if (declspecs->default_int_p)
5105 C_FUNCTION_IMPLICIT_INT (decl) = 1;
5107 /* Record presence of `inline', if it is reasonable. */
5108 if (flag_hosted && MAIN_NAME_P (declarator->u.id))
5110 if (declspecs->inline_p)
5111 pedwarn (input_location, 0, "cannot inline function %<main%>");
5113 else if (declspecs->inline_p)
5114 /* Record that the function is declared `inline'. */
5115 DECL_DECLARED_INLINE_P (decl) = 1;
5119 /* It's a variable. */
5120 /* An uninitialized decl with `extern' is a reference. */
5121 int extern_ref = !initialized && storage_class == csc_extern;
5123 type = c_build_qualified_type (type, type_quals);
5125 /* C99 6.2.2p7: It is invalid (compile-time undefined
5126 behavior) to create an 'extern' declaration for a
5127 variable if there is a global declaration that is
5128 'static' and the global declaration is not visible.
5129 (If the static declaration _is_ currently visible,
5130 the 'extern' declaration is taken to refer to that decl.) */
5131 if (extern_ref && current_scope != file_scope)
5133 tree global_decl = identifier_global_value (declarator->u.id);
5134 tree visible_decl = lookup_name (declarator->u.id);
5137 && global_decl != visible_decl
5138 && TREE_CODE (global_decl) == VAR_DECL
5139 && !TREE_PUBLIC (global_decl))
5140 error ("variable previously declared %<static%> redeclared "
5144 decl = build_decl (VAR_DECL, declarator->u.id, type);
5145 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
5147 C_DECL_VARIABLE_SIZE (decl) = 1;
5149 if (declspecs->inline_p)
5150 pedwarn (input_location, 0, "variable %q+D declared %<inline%>", decl);
5152 /* At file scope, an initialized extern declaration may follow
5153 a static declaration. In that case, DECL_EXTERNAL will be
5154 reset later in start_decl. */
5155 DECL_EXTERNAL (decl) = (storage_class == csc_extern);
5157 /* At file scope, the presence of a `static' or `register' storage
5158 class specifier, or the absence of all storage class specifiers
5159 makes this declaration a definition (perhaps tentative). Also,
5160 the absence of `static' makes it public. */
5161 if (current_scope == file_scope)
5163 TREE_PUBLIC (decl) = storage_class != csc_static;
5164 TREE_STATIC (decl) = !extern_ref;
5166 /* Not at file scope, only `static' makes a static definition. */
5169 TREE_STATIC (decl) = (storage_class == csc_static);
5170 TREE_PUBLIC (decl) = extern_ref;
5174 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
5177 if ((storage_class == csc_extern
5178 || (storage_class == csc_none
5179 && TREE_CODE (type) == FUNCTION_TYPE
5181 && variably_modified_type_p (type, NULL_TREE))
5184 if (TREE_CODE (type) == FUNCTION_TYPE)
5185 error ("non-nested function with variably modified type");
5187 error ("object with variably modified type must have no linkage");
5190 /* Record `register' declaration for warnings on &
5191 and in case doing stupid register allocation. */
5193 if (storage_class == csc_register)
5195 C_DECL_REGISTER (decl) = 1;
5196 DECL_REGISTER (decl) = 1;
5199 /* Record constancy and volatility. */
5200 c_apply_type_quals_to_decl (type_quals, decl);
5202 /* If a type has volatile components, it should be stored in memory.
5203 Otherwise, the fact that those components are volatile
5204 will be ignored, and would even crash the compiler.
5205 Of course, this only makes sense on VAR,PARM, and RESULT decl's. */
5206 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
5207 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
5208 || TREE_CODE (decl) == RESULT_DECL))
5210 /* It is not an error for a structure with volatile fields to
5211 be declared register, but reset DECL_REGISTER since it
5212 cannot actually go in a register. */
5213 int was_reg = C_DECL_REGISTER (decl);
5214 C_DECL_REGISTER (decl) = 0;
5215 DECL_REGISTER (decl) = 0;
5216 c_mark_addressable (decl);
5217 C_DECL_REGISTER (decl) = was_reg;
5220 /* This is the earliest point at which we might know the assembler
5221 name of a variable. Thus, if it's known before this, die horribly. */
5222 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
5228 /* Decode the parameter-list info for a function type or function definition.
5229 The argument is the value returned by `get_parm_info' (or made in c-parse.c
5230 if there is an identifier list instead of a parameter decl list).
5231 These two functions are separate because when a function returns
5232 or receives functions then each is called multiple times but the order
5233 of calls is different. The last call to `grokparms' is always the one
5234 that contains the formal parameter names of a function definition.
5236 Return a list of arg types to use in the FUNCTION_TYPE for this function.
5238 FUNCDEF_FLAG is true for a function definition, false for
5239 a mere declaration. A nonempty identifier-list gets an error message
5240 when FUNCDEF_FLAG is false. */
5243 grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
5245 tree arg_types = arg_info->types;
5247 if (funcdef_flag && arg_info->had_vla_unspec)
5249 /* A function definition isn't function prototype scope C99 6.2.1p4. */
5251 error ("%<[*]%> not allowed in other than function prototype scope");
5254 if (arg_types == 0 && !funcdef_flag && !in_system_header)
5255 warning (OPT_Wstrict_prototypes,
5256 "function declaration isn%'t a prototype");
5258 if (arg_types == error_mark_node)
5259 return 0; /* don't set TYPE_ARG_TYPES in this case */
5261 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
5264 pedwarn (input_location, 0, "parameter names (without types) in function declaration");
5266 arg_info->parms = arg_info->types;
5267 arg_info->types = 0;
5272 tree parm, type, typelt;
5273 unsigned int parmno;
5275 /* If there is a parameter of incomplete type in a definition,
5276 this is an error. In a declaration this is valid, and a
5277 struct or union type may be completed later, before any calls
5278 or definition of the function. In the case where the tag was
5279 first declared within the parameter list, a warning has
5280 already been given. If a parameter has void type, then
5281 however the function cannot be defined or called, so
5284 for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
5286 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
5288 type = TREE_VALUE (typelt);
5289 if (type == error_mark_node)
5292 if (!COMPLETE_TYPE_P (type))
5296 if (DECL_NAME (parm))
5297 error ("parameter %u (%q+D) has incomplete type",
5300 error ("%Jparameter %u has incomplete type",
5303 TREE_VALUE (typelt) = error_mark_node;
5304 TREE_TYPE (parm) = error_mark_node;
5306 else if (VOID_TYPE_P (type))
5308 if (DECL_NAME (parm))
5309 warning (0, "parameter %u (%q+D) has void type",
5312 warning (0, "%Jparameter %u has void type",
5317 if (DECL_NAME (parm) && TREE_USED (parm))
5318 warn_if_shadowing (parm);
5324 /* Take apart the current scope and return a c_arg_info structure with
5325 info on a parameter list just parsed.
5327 This structure is later fed to 'grokparms' and 'store_parm_decls'.
5329 ELLIPSIS being true means the argument list ended in '...' so don't
5330 append a sentinel (void_list_node) to the end of the type-list. */
5333 get_parm_info (bool ellipsis)
5335 struct c_binding *b = current_scope->bindings;
5336 struct c_arg_info *arg_info = XOBNEW (&parser_obstack,
5343 static bool explained_incomplete_types = false;
5344 bool gave_void_only_once_err = false;
5346 arg_info->parms = 0;
5348 arg_info->types = 0;
5349 arg_info->others = 0;
5350 arg_info->pending_sizes = 0;
5351 arg_info->had_vla_unspec = current_scope->had_vla_unspec;
5353 /* The bindings in this scope must not get put into a block.
5354 We will take care of deleting the binding nodes. */
5355 current_scope->bindings = 0;
5357 /* This function is only called if there was *something* on the
5361 /* A parameter list consisting solely of 'void' indicates that the
5362 function takes no arguments. But if the 'void' is qualified
5363 (by 'const' or 'volatile'), or has a storage class specifier
5364 ('register'), then the behavior is undefined; issue an error.
5365 Typedefs for 'void' are OK (see DR#157). */
5366 if (b->prev == 0 /* one binding */
5367 && TREE_CODE (b->decl) == PARM_DECL /* which is a parameter */
5368 && !DECL_NAME (b->decl) /* anonymous */
5369 && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
5371 if (TREE_THIS_VOLATILE (b->decl)
5372 || TREE_READONLY (b->decl)
5373 || C_DECL_REGISTER (b->decl))
5374 error ("%<void%> as only parameter may not be qualified");
5376 /* There cannot be an ellipsis. */
5378 error ("%<void%> must be the only parameter");
5380 arg_info->types = void_list_node;
5385 types = void_list_node;
5387 /* Break up the bindings list into parms, tags, types, and others;
5388 apply sanity checks; purge the name-to-decl bindings. */
5391 tree decl = b->decl;
5392 tree type = TREE_TYPE (decl);
5393 const char *keyword;
5395 switch (TREE_CODE (decl))
5400 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
5401 I_SYMBOL_BINDING (b->id) = b->shadowed;
5404 /* Check for forward decls that never got their actual decl. */
5405 if (TREE_ASM_WRITTEN (decl))
5406 error ("parameter %q+D has just a forward declaration", decl);
5407 /* Check for (..., void, ...) and issue an error. */
5408 else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
5410 if (!gave_void_only_once_err)
5412 error ("%<void%> must be the only parameter");
5413 gave_void_only_once_err = true;
5418 /* Valid parameter, add it to the list. */
5419 TREE_CHAIN (decl) = parms;
5422 /* Since there is a prototype, args are passed in their
5423 declared types. The back end may override this later. */
5424 DECL_ARG_TYPE (decl) = type;
5425 types = tree_cons (0, type, types);
5429 case ENUMERAL_TYPE: keyword = "enum"; goto tag;
5430 case UNION_TYPE: keyword = "union"; goto tag;
5431 case RECORD_TYPE: keyword = "struct"; goto tag;
5433 /* Types may not have tag-names, in which case the type
5434 appears in the bindings list with b->id NULL. */
5437 gcc_assert (I_TAG_BINDING (b->id) == b);
5438 I_TAG_BINDING (b->id) = b->shadowed;
5441 /* Warn about any struct, union or enum tags defined in a
5442 parameter list. The scope of such types is limited to
5443 the parameter list, which is rarely if ever desirable
5444 (it's impossible to call such a function with type-
5445 correct arguments). An anonymous union parm type is
5446 meaningful as a GNU extension, so don't warn for that. */
5447 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
5450 /* The %s will be one of 'struct', 'union', or 'enum'. */
5451 warning (0, "%<%s %E%> declared inside parameter list",
5454 /* The %s will be one of 'struct', 'union', or 'enum'. */
5455 warning (0, "anonymous %s declared inside parameter list",
5458 if (!explained_incomplete_types)
5460 warning (0, "its scope is only this definition or declaration,"
5461 " which is probably not what you want");
5462 explained_incomplete_types = true;
5466 tags = tree_cons (b->id, decl, tags);
5472 /* CONST_DECLs appear here when we have an embedded enum,
5473 and TYPE_DECLs appear here when we have an embedded struct
5474 or union. No warnings for this - we already warned about the
5475 type itself. FUNCTION_DECLs appear when there is an implicit
5476 function declaration in the parameter list. */
5478 TREE_CHAIN (decl) = others;
5483 /* error_mark_node appears here when we have an undeclared
5484 variable. Just throw it away. */
5487 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
5488 I_SYMBOL_BINDING (b->id) = b->shadowed;
5492 /* Other things that might be encountered. */
5499 b = free_binding_and_advance (b);
5502 arg_info->parms = parms;
5503 arg_info->tags = tags;
5504 arg_info->types = types;
5505 arg_info->others = others;
5506 arg_info->pending_sizes = get_pending_sizes ();
5510 /* Get the struct, enum or union (CODE says which) with tag NAME.
5511 Define the tag as a forward-reference if it is not defined.
5512 Return a c_typespec structure for the type specifier. */
5515 parser_xref_tag (enum tree_code code, tree name)
5517 struct c_typespec ret;
5520 ret.expr = NULL_TREE;
5521 ret.expr_const_operands = true;
5523 /* If a cross reference is requested, look up the type
5524 already defined for this tag and return it. */
5526 ref = lookup_tag (code, name, 0);
5527 /* If this is the right type of tag, return what we found.
5528 (This reference will be shadowed by shadow_tag later if appropriate.)
5529 If this is the wrong type of tag, do not return it. If it was the
5530 wrong type in the same scope, we will have had an error
5531 message already; if in a different scope and declaring
5532 a name, pending_xref_error will give an error message; but if in a
5533 different scope and not declaring a name, this tag should
5534 shadow the previous declaration of a different type of tag, and
5535 this would not work properly if we return the reference found.
5536 (For example, with "struct foo" in an outer scope, "union foo;"
5537 must shadow that tag with a new one of union type.) */
5538 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
5539 if (ref && TREE_CODE (ref) == code)
5545 /* If no such tag is yet defined, create a forward-reference node
5546 and record it as the "definition".
5547 When a real declaration of this type is found,
5548 the forward-reference will be altered into a real type. */
5550 ref = make_node (code);
5551 if (code == ENUMERAL_TYPE)
5553 /* Give the type a default layout like unsigned int
5554 to avoid crashing if it does not get defined. */
5555 SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
5556 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5557 TYPE_USER_ALIGN (ref) = 0;
5558 TYPE_UNSIGNED (ref) = 1;
5559 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5560 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5561 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5564 pushtag (name, ref);
5570 /* Get the struct, enum or union (CODE says which) with tag NAME.
5571 Define the tag as a forward-reference if it is not defined.
5572 Return a tree for the type. */
5575 xref_tag (enum tree_code code, tree name)
5577 return parser_xref_tag (code, name).spec;
5580 /* Make sure that the tag NAME is defined *in the current scope*
5581 at least as a forward reference.
5582 CODE says which kind of tag NAME ought to be. */
5585 start_struct (enum tree_code code, tree name)
5587 /* If there is already a tag defined at this scope
5588 (as a forward reference), just return it. */
5593 ref = lookup_tag (code, name, 1);
5594 if (ref && TREE_CODE (ref) == code)
5596 if (TYPE_SIZE (ref))
5598 if (code == UNION_TYPE)
5599 error ("redefinition of %<union %E%>", name);
5601 error ("redefinition of %<struct %E%>", name);
5602 /* Don't create structures using a name already in use. */
5605 else if (C_TYPE_BEING_DEFINED (ref))
5607 if (code == UNION_TYPE)
5608 error ("nested redefinition of %<union %E%>", name);
5610 error ("nested redefinition of %<struct %E%>", name);
5611 /* Don't create structures that contain themselves. */
5616 /* Otherwise create a forward-reference just so the tag is in scope. */
5618 if (ref == NULL_TREE || TREE_CODE (ref) != code)
5620 ref = make_node (code);
5621 pushtag (name, ref);
5624 C_TYPE_BEING_DEFINED (ref) = 1;
5625 TYPE_PACKED (ref) = flag_pack_struct;
5629 /* Process the specs, declarator and width (NULL if omitted)
5630 of a structure component, returning a FIELD_DECL node.
5631 WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
5632 DECL_ATTRS is as for grokdeclarator.
5634 LOC is the location of the structure component.
5636 This is done during the parsing of the struct declaration.
5637 The FIELD_DECL nodes are chained together and the lot of them
5638 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5641 grokfield (location_t loc,
5642 struct c_declarator *declarator, struct c_declspecs *declspecs,
5643 tree width, tree *decl_attrs)
5647 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
5648 && width == NULL_TREE)
5650 /* This is an unnamed decl.
5652 If we have something of the form "union { list } ;" then this
5653 is the anonymous union extension. Similarly for struct.
5655 If this is something of the form "struct foo;", then
5656 If MS extensions are enabled, this is handled as an
5658 Otherwise this is a forward declaration of a structure tag.
5660 If this is something of the form "foo;" and foo is a TYPE_DECL, then
5661 If MS extensions are enabled and foo names a structure, then
5662 again this is an anonymous struct.
5663 Otherwise this is an error.
5665 Oh what a horrid tangled web we weave. I wonder if MS consciously
5666 took this from Plan 9 or if it was an accident of implementation
5667 that took root before someone noticed the bug... */
5669 tree type = declspecs->type;
5670 bool type_ok = (TREE_CODE (type) == RECORD_TYPE
5671 || TREE_CODE (type) == UNION_TYPE);
5675 && (flag_ms_extensions || !declspecs->typedef_p))
5677 if (flag_ms_extensions)
5681 else if (TYPE_NAME (type) == NULL)
5688 pedwarn (loc, 0, "declaration does not declare anything");
5691 pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions");
5694 value = grokdeclarator (declarator, declspecs, FIELD, false,
5695 width ? &width : NULL, decl_attrs, NULL, NULL,
5698 finish_decl (value, NULL_TREE, NULL_TREE, NULL_TREE);
5699 DECL_INITIAL (value) = width;
5704 /* Generate an error for any duplicate field names in FIELDLIST. Munge
5705 the list such that this does not present a problem later. */
5708 detect_field_duplicates (tree fieldlist)
5713 /* First, see if there are more than "a few" fields.
5714 This is trivially true if there are zero or one fields. */
5717 x = TREE_CHAIN (fieldlist);
5723 } while (timeout > 0 && x);
5725 /* If there were "few" fields, avoid the overhead of allocating
5726 a hash table. Instead just do the nested traversal thing. */
5729 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x))
5732 for (y = fieldlist; y != x; y = TREE_CHAIN (y))
5733 if (DECL_NAME (y) == DECL_NAME (x))
5735 error ("duplicate member %q+D", x);
5736 DECL_NAME (x) = NULL_TREE;
5742 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
5745 for (x = fieldlist; x ; x = TREE_CHAIN (x))
5746 if ((y = DECL_NAME (x)) != 0)
5748 slot = htab_find_slot (htab, y, INSERT);
5751 error ("duplicate member %q+D", x);
5752 DECL_NAME (x) = NULL_TREE;
5761 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5762 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5763 ATTRIBUTES are attributes to be applied to the structure. */
5766 finish_struct (tree t, tree fieldlist, tree attributes)
5769 bool toplevel = file_scope == current_scope;
5770 int saw_named_field;
5772 /* If this type was previously laid out as a forward reference,
5773 make sure we lay it out again. */
5777 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5781 for (x = fieldlist; x; x = TREE_CHAIN (x))
5782 if (DECL_NAME (x) != 0)
5787 if (TREE_CODE (t) == UNION_TYPE)
5790 pedwarn (input_location, OPT_pedantic, "union has no named members");
5792 pedwarn (input_location, OPT_pedantic, "union has no members");
5797 pedwarn (input_location, OPT_pedantic, "struct has no named members");
5799 pedwarn (input_location, OPT_pedantic, "struct has no members");
5804 /* Install struct as DECL_CONTEXT of each field decl.
5805 Also process specified field sizes, found in the DECL_INITIAL,
5806 storing 0 there after the type has been changed to precision equal
5807 to its width, rather than the precision of the specified standard
5808 type. (Correct layout requires the original type to have been preserved
5811 saw_named_field = 0;
5812 for (x = fieldlist; x; x = TREE_CHAIN (x))
5814 if (TREE_TYPE (x) == error_mark_node)
5817 DECL_CONTEXT (x) = t;
5819 /* If any field is const, the structure type is pseudo-const. */
5820 if (TREE_READONLY (x))
5821 C_TYPE_FIELDS_READONLY (t) = 1;
5824 /* A field that is pseudo-const makes the structure likewise. */
5825 tree t1 = TREE_TYPE (x);
5826 while (TREE_CODE (t1) == ARRAY_TYPE)
5827 t1 = TREE_TYPE (t1);
5828 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5829 && C_TYPE_FIELDS_READONLY (t1))
5830 C_TYPE_FIELDS_READONLY (t) = 1;
5833 /* Any field that is volatile means variables of this type must be
5834 treated in some ways as volatile. */
5835 if (TREE_THIS_VOLATILE (x))
5836 C_TYPE_FIELDS_VOLATILE (t) = 1;
5838 /* Any field of nominal variable size implies structure is too. */
5839 if (C_DECL_VARIABLE_SIZE (x))
5840 C_TYPE_VARIABLE_SIZE (t) = 1;
5842 if (DECL_INITIAL (x))
5844 unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
5845 DECL_SIZE (x) = bitsize_int (width);
5846 DECL_BIT_FIELD (x) = 1;
5847 SET_DECL_C_BIT_FIELD (x);
5851 && (DECL_BIT_FIELD (x)
5852 || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
5853 DECL_PACKED (x) = 1;
5855 /* Detect flexible array member in an invalid context. */
5856 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5857 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
5858 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
5859 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
5861 if (TREE_CODE (t) == UNION_TYPE)
5863 error ("%Jflexible array member in union", x);
5864 TREE_TYPE (x) = error_mark_node;
5866 else if (TREE_CHAIN (x) != NULL_TREE)
5868 error ("%Jflexible array member not at end of struct", x);
5869 TREE_TYPE (x) = error_mark_node;
5871 else if (!saw_named_field)
5873 error ("%Jflexible array member in otherwise empty struct", x);
5874 TREE_TYPE (x) = error_mark_node;
5878 if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
5879 && flexible_array_type_p (TREE_TYPE (x)))
5880 pedwarn (input_location, OPT_pedantic,
5881 "%Jinvalid use of structure with flexible array member", x);
5884 saw_named_field = 1;
5887 detect_field_duplicates (fieldlist);
5889 /* Now we have the nearly final fieldlist. Record it,
5890 then lay out the structure or union (including the fields). */
5892 TYPE_FIELDS (t) = fieldlist;
5896 /* Give bit-fields their proper types. */
5898 tree *fieldlistp = &fieldlist;
5900 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
5901 && TREE_TYPE (*fieldlistp) != error_mark_node)
5903 unsigned HOST_WIDE_INT width
5904 = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
5905 tree type = TREE_TYPE (*fieldlistp);
5906 if (width != TYPE_PRECISION (type))
5908 TREE_TYPE (*fieldlistp)
5909 = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type));
5910 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
5912 DECL_INITIAL (*fieldlistp) = 0;
5915 fieldlistp = &TREE_CHAIN (*fieldlistp);
5918 /* Now we have the truly final field list.
5919 Store it in this type and in the variants. */
5921 TYPE_FIELDS (t) = fieldlist;
5923 /* If there are lots of fields, sort so we can look through them fast.
5924 We arbitrarily consider 16 or more elts to be "a lot". */
5929 for (x = fieldlist; x; x = TREE_CHAIN (x))
5931 if (len > 15 || DECL_NAME (x) == NULL)
5939 struct lang_type *space;
5940 struct sorted_fields_type *space2;
5942 len += list_length (x);
5944 /* Use the same allocation policy here that make_node uses, to
5945 ensure that this lives as long as the rest of the struct decl.
5946 All decls in an inline function need to be saved. */
5948 space = GGC_CNEW (struct lang_type);
5949 space2 = GGC_NEWVAR (struct sorted_fields_type,
5950 sizeof (struct sorted_fields_type) + len * sizeof (tree));
5954 field_array = &space2->elts[0];
5955 for (x = fieldlist; x; x = TREE_CHAIN (x))
5957 field_array[len++] = x;
5959 /* If there is anonymous struct or union, break out of the loop. */
5960 if (DECL_NAME (x) == NULL)
5963 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
5966 TYPE_LANG_SPECIFIC (t) = space;
5967 TYPE_LANG_SPECIFIC (t)->s->len = len;
5968 field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
5969 qsort (field_array, len, sizeof (tree), field_decl_cmp);
5974 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5976 TYPE_FIELDS (x) = TYPE_FIELDS (t);
5977 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
5978 C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
5979 C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
5980 C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
5983 /* If this was supposed to be a transparent union, but we can't
5984 make it one, warn and turn off the flag. */
5985 if (TREE_CODE (t) == UNION_TYPE
5986 && TYPE_TRANSPARENT_UNION (t)
5987 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
5989 TYPE_TRANSPARENT_UNION (t) = 0;
5990 warning (0, "union cannot be made transparent");
5993 /* If this structure or union completes the type of any previous
5994 variable declaration, lay it out and output its rtl. */
5995 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
5999 tree decl = TREE_VALUE (x);
6000 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
6001 layout_array_type (TREE_TYPE (decl));
6002 if (TREE_CODE (decl) != TYPE_DECL)
6004 layout_decl (decl, 0);
6005 if (c_dialect_objc ())
6006 objc_check_decl (decl);
6007 rest_of_decl_compilation (decl, toplevel, 0);
6012 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
6014 /* Finish debugging output for this type. */
6015 rest_of_type_compilation (t, toplevel);
6017 /* If we're inside a function proper, i.e. not file-scope and not still
6018 parsing parameters, then arrange for the size of a variable sized type
6020 if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE))
6021 add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t)));
6026 /* Lay out the type T, and its element type, and so on. */
6029 layout_array_type (tree t)
6031 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6032 layout_array_type (TREE_TYPE (t));
6036 /* Begin compiling the definition of an enumeration type.
6037 NAME is its name (or null if anonymous).
6038 Returns the type object, as yet incomplete.
6039 Also records info about it so that build_enumerator
6040 may be used to declare the individual values as they are read. */
6043 start_enum (struct c_enum_contents *the_enum, tree name)
6047 /* If this is the real definition for a previous forward reference,
6048 fill in the contents in the same object that used to be the
6049 forward reference. */
6052 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1);
6054 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
6056 enumtype = make_node (ENUMERAL_TYPE);
6057 pushtag (name, enumtype);
6060 if (C_TYPE_BEING_DEFINED (enumtype))
6061 error ("nested redefinition of %<enum %E%>", name);
6063 C_TYPE_BEING_DEFINED (enumtype) = 1;
6065 if (TYPE_VALUES (enumtype) != 0)
6067 /* This enum is a named one that has been declared already. */
6068 error ("redeclaration of %<enum %E%>", name);
6070 /* Completely replace its old definition.
6071 The old enumerators remain defined, however. */
6072 TYPE_VALUES (enumtype) = 0;
6075 the_enum->enum_next_value = integer_zero_node;
6076 the_enum->enum_overflow = 0;
6078 if (flag_short_enums)
6079 TYPE_PACKED (enumtype) = 1;
6084 /* After processing and defining all the values of an enumeration type,
6085 install their decls in the enumeration type and finish it off.
6086 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
6087 and ATTRIBUTES are the specified attributes.
6088 Returns ENUMTYPE. */
6091 finish_enum (tree enumtype, tree values, tree attributes)
6094 tree minnode = 0, maxnode = 0;
6095 int precision, unsign;
6096 bool toplevel = (file_scope == current_scope);
6097 struct lang_type *lt;
6099 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
6101 /* Calculate the maximum value of any enumerator in this type. */
6103 if (values == error_mark_node)
6104 minnode = maxnode = integer_zero_node;
6107 minnode = maxnode = TREE_VALUE (values);
6108 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
6110 tree value = TREE_VALUE (pair);
6111 if (tree_int_cst_lt (maxnode, value))
6113 if (tree_int_cst_lt (value, minnode))
6118 /* Construct the final type of this enumeration. It is the same
6119 as one of the integral types - the narrowest one that fits, except
6120 that normally we only go as narrow as int - and signed iff any of
6121 the values are negative. */
6122 unsign = (tree_int_cst_sgn (minnode) >= 0);
6123 precision = MAX (tree_int_cst_min_precision (minnode, unsign),
6124 tree_int_cst_min_precision (maxnode, unsign));
6126 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
6128 tem = c_common_type_for_size (precision, unsign);
6131 warning (0, "enumeration values exceed range of largest integer");
6132 tem = long_long_integer_type_node;
6136 tem = unsign ? unsigned_type_node : integer_type_node;
6138 TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
6139 TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
6140 TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
6141 TYPE_SIZE (enumtype) = 0;
6143 /* If the precision of the type was specific with an attribute and it
6144 was too small, give an error. Otherwise, use it. */
6145 if (TYPE_PRECISION (enumtype))
6147 if (precision > TYPE_PRECISION (enumtype))
6148 error ("specified mode too small for enumeral values");
6151 TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
6153 layout_type (enumtype);
6155 if (values != error_mark_node)
6157 /* Change the type of the enumerators to be the enum type. We
6158 need to do this irrespective of the size of the enum, for
6159 proper type checking. Replace the DECL_INITIALs of the
6160 enumerators, and the value slots of the list, with copies
6161 that have the enum type; they cannot be modified in place
6162 because they may be shared (e.g. integer_zero_node) Finally,
6163 change the purpose slots to point to the names of the decls. */
6164 for (pair = values; pair; pair = TREE_CHAIN (pair))
6166 tree enu = TREE_PURPOSE (pair);
6167 tree ini = DECL_INITIAL (enu);
6169 TREE_TYPE (enu) = enumtype;
6171 /* The ISO C Standard mandates enumerators to have type int,
6172 even though the underlying type of an enum type is
6173 unspecified. However, GCC allows enumerators of any
6174 integer type as an extensions. build_enumerator()
6175 converts any enumerators that fit in an int to type int,
6176 to avoid promotions to unsigned types when comparing
6177 integers with enumerators that fit in the int range.
6178 When -pedantic is given, build_enumerator() would have
6179 already warned about those that don't fit. Here we
6180 convert the rest to the enumerator type. */
6181 if (TREE_TYPE (ini) != integer_type_node)
6182 ini = convert (enumtype, ini);
6184 DECL_INITIAL (enu) = ini;
6185 TREE_PURPOSE (pair) = DECL_NAME (enu);
6186 TREE_VALUE (pair) = ini;
6189 TYPE_VALUES (enumtype) = values;
6192 /* Record the min/max values so that we can warn about bit-field
6193 enumerations that are too small for the values. */
6194 lt = GGC_CNEW (struct lang_type);
6195 lt->enum_min = minnode;
6196 lt->enum_max = maxnode;
6197 TYPE_LANG_SPECIFIC (enumtype) = lt;
6199 /* Fix up all variant types of this enum type. */
6200 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
6202 if (tem == enumtype)
6204 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
6205 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
6206 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
6207 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
6208 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
6209 SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
6210 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
6211 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
6212 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
6213 TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
6214 TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
6217 /* Finish debugging output for this type. */
6218 rest_of_type_compilation (enumtype, toplevel);
6223 /* Build and install a CONST_DECL for one value of the
6224 current enumeration type (one that was begun with start_enum).
6225 Return a tree-list containing the CONST_DECL and its value.
6226 Assignment of sequential values by default is handled here. */
6229 build_enumerator (struct c_enum_contents *the_enum, tree name, tree value,
6230 location_t value_loc)
6234 /* Validate and default VALUE. */
6238 /* Don't issue more errors for error_mark_node (i.e. an
6239 undeclared identifier) - just ignore the value expression. */
6240 if (value == error_mark_node)
6242 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
6244 error ("enumerator value for %qE is not an integer constant", name);
6249 if (TREE_CODE (value) != INTEGER_CST)
6251 value = c_fully_fold (value, false, NULL);
6252 if (TREE_CODE (value) == INTEGER_CST)
6253 pedwarn (value_loc, OPT_pedantic,
6254 "enumerator value for %qE is not an integer "
6255 "constant expression", name);
6257 if (TREE_CODE (value) != INTEGER_CST)
6259 error ("enumerator value for %qE is not an integer constant",
6265 value = default_conversion (value);
6266 constant_expression_warning (value);
6271 /* Default based on previous value. */
6272 /* It should no longer be possible to have NON_LVALUE_EXPR
6276 value = the_enum->enum_next_value;
6277 if (the_enum->enum_overflow)
6278 error ("overflow in enumeration values");
6280 /* Even though the underlying type of an enum is unspecified, the
6281 type of enumeration constants is explicitly defined as int
6282 (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as
6284 else if (!int_fits_type_p (value, integer_type_node))
6285 pedwarn (value_loc, OPT_pedantic,
6286 "ISO C restricts enumerator values to range of %<int%>");
6288 /* The ISO C Standard mandates enumerators to have type int, even
6289 though the underlying type of an enum type is unspecified.
6290 However, GCC allows enumerators of any integer type as an
6291 extensions. Here we convert any enumerators that fit in an int
6292 to type int, to avoid promotions to unsigned types when comparing
6293 integers with enumerators that fit in the int range. When
6294 -pedantic is given, we would have already warned about those that
6295 don't fit. We have to do this here rather than in finish_enum
6296 because this value may be used to define more enumerators. */
6297 if (int_fits_type_p (value, integer_type_node))
6298 value = convert (integer_type_node, value);
6300 /* Set basis for default for next value. */
6301 the_enum->enum_next_value
6303 (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location,
6304 PLUS_EXPR, value, integer_one_node, 0);
6305 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
6307 /* Now create a declaration for the enum value name. */
6309 type = TREE_TYPE (value);
6310 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
6311 TYPE_PRECISION (integer_type_node)),
6312 (TYPE_PRECISION (type)
6313 >= TYPE_PRECISION (integer_type_node)
6314 && TYPE_UNSIGNED (type)));
6316 decl = build_decl (CONST_DECL, name, type);
6317 DECL_INITIAL (decl) = convert (type, value);
6320 return tree_cons (decl, value, NULL_TREE);
6324 /* Create the FUNCTION_DECL for a function definition.
6325 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
6326 the declaration; they describe the function's name and the type it returns,
6327 but twisted together in a fashion that parallels the syntax of C.
6329 This function creates a binding context for the function body
6330 as well as setting up the FUNCTION_DECL in current_function_decl.
6332 Returns 1 on success. If the DECLARATOR is not suitable for a function
6333 (it defines a datum instead), we return 0, which tells
6334 yyparse to report a parse error. */
6337 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
6340 tree decl1, old_decl;
6341 tree restype, resdecl;
6342 struct c_label_context_se *nstack_se;
6343 struct c_label_context_vm *nstack_vm;
6345 current_function_returns_value = 0; /* Assume, until we see it does. */
6346 current_function_returns_null = 0;
6347 current_function_returns_abnormally = 0;
6348 warn_about_return_type = 0;
6349 c_switch_stack = NULL;
6351 nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
6352 nstack_se->labels_def = NULL;
6353 nstack_se->labels_used = NULL;
6354 nstack_se->next = label_context_stack_se;
6355 label_context_stack_se = nstack_se;
6357 nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm);
6358 nstack_vm->labels_def = NULL;
6359 nstack_vm->labels_used = NULL;
6360 nstack_vm->scope = 0;
6361 nstack_vm->next = label_context_stack_vm;
6362 label_context_stack_vm = nstack_vm;
6364 /* Indicate no valid break/continue context by setting these variables
6365 to some non-null, non-label value. We'll notice and emit the proper
6366 error message in c_finish_bc_stmt. */
6367 c_break_label = c_cont_label = size_zero_node;
6369 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
6370 &attributes, NULL, NULL, DEPRECATED_NORMAL);
6372 /* If the declarator is not suitable for a function definition,
6373 cause a syntax error. */
6376 label_context_stack_se = label_context_stack_se->next;
6377 label_context_stack_vm = label_context_stack_vm->next;
6381 decl_attributes (&decl1, attributes, 0);
6383 if (DECL_DECLARED_INLINE_P (decl1)
6384 && DECL_UNINLINABLE (decl1)
6385 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
6386 warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
6389 /* Handle gnu_inline attribute. */
6390 if (declspecs->inline_p
6391 && !flag_gnu89_inline
6392 && TREE_CODE (decl1) == FUNCTION_DECL
6393 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
6394 || current_function_decl))
6396 if (declspecs->storage_class != csc_static)
6397 DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
6400 announce_function (decl1);
6402 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
6404 error ("return type is an incomplete type");
6405 /* Make it return void instead. */
6407 = build_function_type (void_type_node,
6408 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
6411 if (warn_about_return_type)
6412 pedwarn_c99 (input_location, flag_isoc99 ? 0
6413 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int),
6414 "return type defaults to %<int%>");
6416 /* Make the init_value nonzero so pushdecl knows this is not tentative.
6417 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
6418 DECL_INITIAL (decl1) = error_mark_node;
6420 /* If this definition isn't a prototype and we had a prototype declaration
6421 before, copy the arg type info from that prototype. */
6422 old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
6423 if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
6425 current_function_prototype_locus = UNKNOWN_LOCATION;
6426 current_function_prototype_built_in = false;
6427 current_function_prototype_arg_types = NULL_TREE;
6428 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
6430 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
6431 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
6432 TREE_TYPE (TREE_TYPE (old_decl))))
6434 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
6436 current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
6437 current_function_prototype_built_in
6438 = C_DECL_BUILTIN_PROTOTYPE (old_decl);
6439 current_function_prototype_arg_types
6440 = TYPE_ARG_TYPES (TREE_TYPE (decl1));
6442 if (TREE_PUBLIC (decl1))
6444 /* If there is an external prototype declaration of this
6445 function, record its location but do not copy information
6446 to this decl. This may be an invisible declaration
6447 (built-in or in a scope which has finished) or simply
6448 have more refined argument types than any declaration
6450 struct c_binding *b;
6451 for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
6452 if (B_IN_SCOPE (b, external_scope))
6456 tree ext_decl, ext_type;
6458 ext_type = b->type ? b->type : TREE_TYPE (ext_decl);
6459 if (TREE_CODE (ext_type) == FUNCTION_TYPE
6460 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
6461 TREE_TYPE (ext_type)))
6463 current_function_prototype_locus
6464 = DECL_SOURCE_LOCATION (ext_decl);
6465 current_function_prototype_built_in
6466 = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
6467 current_function_prototype_arg_types
6468 = TYPE_ARG_TYPES (ext_type);
6474 /* Optionally warn of old-fashioned def with no previous prototype. */
6475 if (warn_strict_prototypes
6476 && old_decl != error_mark_node
6477 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
6478 && C_DECL_ISNT_PROTOTYPE (old_decl))
6479 warning (OPT_Wstrict_prototypes,
6480 "function declaration isn%'t a prototype");
6481 /* Optionally warn of any global def with no previous prototype. */
6482 else if (warn_missing_prototypes
6483 && old_decl != error_mark_node
6484 && TREE_PUBLIC (decl1)
6485 && !MAIN_NAME_P (DECL_NAME (decl1))
6486 && C_DECL_ISNT_PROTOTYPE (old_decl))
6487 warning (OPT_Wmissing_prototypes, "no previous prototype for %q+D", decl1);
6488 /* Optionally warn of any def with no previous prototype
6489 if the function has already been used. */
6490 else if (warn_missing_prototypes
6492 && old_decl != error_mark_node
6493 && TREE_USED (old_decl)
6494 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
6495 warning (OPT_Wmissing_prototypes,
6496 "%q+D was used with no prototype before its definition", decl1);
6497 /* Optionally warn of any global def with no previous declaration. */
6498 else if (warn_missing_declarations
6499 && TREE_PUBLIC (decl1)
6501 && !MAIN_NAME_P (DECL_NAME (decl1)))
6502 warning (OPT_Wmissing_declarations, "no previous declaration for %q+D",
6504 /* Optionally warn of any def with no previous declaration
6505 if the function has already been used. */
6506 else if (warn_missing_declarations
6508 && old_decl != error_mark_node
6509 && TREE_USED (old_decl)
6510 && C_DECL_IMPLICIT (old_decl))
6511 warning (OPT_Wmissing_declarations,
6512 "%q+D was used with no declaration before its definition", decl1);
6514 /* This function exists in static storage.
6515 (This does not mean `static' in the C sense!) */
6516 TREE_STATIC (decl1) = 1;
6518 /* A nested function is not global. */
6519 if (current_function_decl != 0)
6520 TREE_PUBLIC (decl1) = 0;
6522 /* This is the earliest point at which we might know the assembler
6523 name of the function. Thus, if it's set before this, die horribly. */
6524 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
6526 /* If #pragma weak was used, mark the decl weak now. */
6527 if (current_scope == file_scope)
6528 maybe_apply_pragma_weak (decl1);
6530 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
6531 if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
6533 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6534 != integer_type_node)
6535 pedwarn (input_location, OPT_Wmain, "return type of %q+D is not %<int%>", decl1);
6537 check_main_parameter_types (decl1);
6539 if (!TREE_PUBLIC (decl1))
6540 pedwarn (input_location, OPT_Wmain, "%q+D is normally a non-static function", decl1);
6543 /* Record the decl so that the function name is defined.
6544 If we already have a decl for this name, and it is a FUNCTION_DECL,
6545 use the old decl. */
6547 current_function_decl = pushdecl (decl1);
6550 declare_parm_level ();
6552 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
6553 resdecl = build_decl (RESULT_DECL, NULL_TREE, restype);
6554 DECL_ARTIFICIAL (resdecl) = 1;
6555 DECL_IGNORED_P (resdecl) = 1;
6556 DECL_RESULT (current_function_decl) = resdecl;
6558 start_fname_decls ();
6563 /* Subroutine of store_parm_decls which handles new-style function
6564 definitions (prototype format). The parms already have decls, so we
6565 need only record them as in effect and complain if any redundant
6566 old-style parm decls were written. */
6568 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
6572 if (current_scope->bindings)
6574 error ("%Jold-style parameter declarations in prototyped "
6575 "function definition", fndecl);
6577 /* Get rid of the old-style declarations. */
6581 /* Don't issue this warning for nested functions, and don't issue this
6582 warning if we got here because ARG_INFO_TYPES was error_mark_node
6583 (this happens when a function definition has just an ellipsis in
6584 its parameter list). */
6585 else if (!in_system_header && !current_function_scope
6586 && arg_info->types != error_mark_node)
6587 warning (OPT_Wtraditional,
6588 "%Jtraditional C rejects ISO C style function definitions",
6591 /* Now make all the parameter declarations visible in the function body.
6592 We can bypass most of the grunt work of pushdecl. */
6593 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl))
6595 DECL_CONTEXT (decl) = current_function_decl;
6596 if (DECL_NAME (decl))
6598 bind (DECL_NAME (decl), decl, current_scope,
6599 /*invisible=*/false, /*nested=*/false,
6601 if (!TREE_USED (decl))
6602 warn_if_shadowing (decl);
6605 error ("%Jparameter name omitted", decl);
6608 /* Record the parameter list in the function declaration. */
6609 DECL_ARGUMENTS (fndecl) = arg_info->parms;
6611 /* Now make all the ancillary declarations visible, likewise. */
6612 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl))
6614 DECL_CONTEXT (decl) = current_function_decl;
6615 if (DECL_NAME (decl))
6616 bind (DECL_NAME (decl), decl, current_scope,
6617 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
6620 /* And all the tag declarations. */
6621 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl))
6622 if (TREE_PURPOSE (decl))
6623 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
6624 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
6627 /* Subroutine of store_parm_decls which handles old-style function
6628 definitions (separate parameter list and declarations). */
6631 store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
6633 struct c_binding *b;
6634 tree parm, decl, last;
6635 tree parmids = arg_info->parms;
6636 struct pointer_set_t *seen_args = pointer_set_create ();
6638 if (!in_system_header)
6639 warning (OPT_Wold_style_definition, "%Jold-style function definition",
6642 /* Match each formal parameter name with its declaration. Save each
6643 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
6644 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
6646 if (TREE_VALUE (parm) == 0)
6648 error ("%Jparameter name missing from parameter list", fndecl);
6649 TREE_PURPOSE (parm) = 0;
6653 b = I_SYMBOL_BINDING (TREE_VALUE (parm));
6654 if (b && B_IN_CURRENT_SCOPE (b))
6657 /* If we got something other than a PARM_DECL it is an error. */
6658 if (TREE_CODE (decl) != PARM_DECL)
6659 error ("%q+D declared as a non-parameter", decl);
6660 /* If the declaration is already marked, we have a duplicate
6661 name. Complain and ignore the duplicate. */
6662 else if (pointer_set_contains (seen_args, decl))
6664 error ("multiple parameters named %q+D", decl);
6665 TREE_PURPOSE (parm) = 0;
6668 /* If the declaration says "void", complain and turn it into
6670 else if (VOID_TYPE_P (TREE_TYPE (decl)))
6672 error ("parameter %q+D declared with void type", decl);
6673 TREE_TYPE (decl) = integer_type_node;
6674 DECL_ARG_TYPE (decl) = integer_type_node;
6675 layout_decl (decl, 0);
6677 warn_if_shadowing (decl);
6679 /* If no declaration found, default to int. */
6682 decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node);
6683 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
6684 DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl);
6686 warn_if_shadowing (decl);
6689 pedwarn (input_location, 0, "type of %q+D defaults to %<int%>", decl);
6691 warning (OPT_Wmissing_parameter_type, "type of %q+D defaults to %<int%>", decl);
6694 TREE_PURPOSE (parm) = decl;
6695 pointer_set_insert (seen_args, decl);
6698 /* Now examine the parms chain for incomplete declarations
6699 and declarations with no corresponding names. */
6701 for (b = current_scope->bindings; b; b = b->prev)
6704 if (TREE_CODE (parm) != PARM_DECL)
6707 if (TREE_TYPE (parm) != error_mark_node
6708 && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
6710 error ("parameter %q+D has incomplete type", parm);
6711 TREE_TYPE (parm) = error_mark_node;
6714 if (!pointer_set_contains (seen_args, parm))
6716 error ("declaration for parameter %q+D but no such parameter", parm);
6718 /* Pretend the parameter was not missing.
6719 This gets us to a standard state and minimizes
6720 further error messages. */
6721 parmids = chainon (parmids, tree_cons (parm, 0, 0));
6725 /* Chain the declarations together in the order of the list of
6726 names. Store that chain in the function decl, replacing the
6727 list of names. Update the current scope to match. */
6728 DECL_ARGUMENTS (fndecl) = 0;
6730 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
6731 if (TREE_PURPOSE (parm))
6733 if (parm && TREE_PURPOSE (parm))
6735 last = TREE_PURPOSE (parm);
6736 DECL_ARGUMENTS (fndecl) = last;
6738 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
6739 if (TREE_PURPOSE (parm))
6741 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6742 last = TREE_PURPOSE (parm);
6744 TREE_CHAIN (last) = 0;
6747 pointer_set_destroy (seen_args);
6749 /* If there was a previous prototype,
6750 set the DECL_ARG_TYPE of each argument according to
6751 the type previously specified, and report any mismatches. */
6753 if (current_function_prototype_arg_types)
6756 for (parm = DECL_ARGUMENTS (fndecl),
6757 type = current_function_prototype_arg_types;
6758 parm || (type && TREE_VALUE (type) != error_mark_node
6759 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node));
6760 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6762 if (parm == 0 || type == 0
6763 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6765 if (current_function_prototype_built_in)
6766 warning (0, "number of arguments doesn%'t match "
6767 "built-in prototype");
6770 error ("number of arguments doesn%'t match prototype");
6771 error ("%Hprototype declaration",
6772 ¤t_function_prototype_locus);
6776 /* Type for passing arg must be consistent with that
6777 declared for the arg. ISO C says we take the unqualified
6778 type for parameters declared with qualified type. */
6779 if (TREE_TYPE (parm) != error_mark_node
6780 && TREE_TYPE (type) != error_mark_node
6781 && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
6782 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
6784 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6785 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6787 /* Adjust argument to match prototype. E.g. a previous
6788 `int foo(float);' prototype causes
6789 `int foo(x) float x; {...}' to be treated like
6790 `int foo(float x) {...}'. This is particularly
6791 useful for argument types like uid_t. */
6792 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6794 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
6795 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
6796 && TYPE_PRECISION (TREE_TYPE (parm))
6797 < TYPE_PRECISION (integer_type_node))
6798 DECL_ARG_TYPE (parm) = integer_type_node;
6800 /* ??? Is it possible to get here with a
6801 built-in prototype or will it always have
6802 been diagnosed as conflicting with an
6803 old-style definition and discarded? */
6804 if (current_function_prototype_built_in)
6805 warning (OPT_pedantic, "promoted argument %qD "
6806 "doesn%'t match built-in prototype", parm);
6809 pedwarn (input_location, OPT_pedantic, "promoted argument %qD "
6810 "doesn%'t match prototype", parm);
6811 pedwarn (current_function_prototype_locus, OPT_pedantic,
6812 "prototype declaration");
6817 if (current_function_prototype_built_in)
6818 warning (0, "argument %qD doesn%'t match "
6819 "built-in prototype", parm);
6822 error ("argument %qD doesn%'t match prototype", parm);
6823 error ("%Hprototype declaration",
6824 ¤t_function_prototype_locus);
6829 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6832 /* Otherwise, create a prototype that would match. */
6836 tree actual = 0, last = 0, type;
6838 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6840 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6842 TREE_CHAIN (last) = type;
6847 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6849 TREE_CHAIN (last) = type;
6853 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6854 of the type of this function, but we need to avoid having this
6855 affect the types of other similarly-typed functions, so we must
6856 first force the generation of an identical (but separate) type
6857 node for the relevant function type. The new node we create
6858 will be a variant of the main variant of the original function
6861 TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
6863 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6867 /* Store parameter declarations passed in ARG_INFO into the current
6868 function declaration. */
6871 store_parm_decls_from (struct c_arg_info *arg_info)
6873 current_function_arg_info = arg_info;
6874 store_parm_decls ();
6877 /* Store the parameter declarations into the current function declaration.
6878 This is called after parsing the parameter declarations, before
6879 digesting the body of the function.
6881 For an old-style definition, construct a prototype out of the old-style
6882 parameter declarations and inject it into the function's type. */
6885 store_parm_decls (void)
6887 tree fndecl = current_function_decl;
6890 /* The argument information block for FNDECL. */
6891 struct c_arg_info *arg_info = current_function_arg_info;
6892 current_function_arg_info = 0;
6894 /* True if this definition is written with a prototype. Note:
6895 despite C99 6.7.5.3p14, we can *not* treat an empty argument
6896 list in a function definition as equivalent to (void) -- an
6897 empty argument list specifies the function has no parameters,
6898 but only (void) sets up a prototype for future calls. */
6899 proto = arg_info->types != 0;
6902 store_parm_decls_newstyle (fndecl, arg_info);
6904 store_parm_decls_oldstyle (fndecl, arg_info);
6906 /* The next call to push_scope will be a function body. */
6908 next_is_function_body = true;
6910 /* Write a record describing this function definition to the prototypes
6911 file (if requested). */
6913 gen_aux_info_record (fndecl, 1, 0, proto);
6915 /* Initialize the RTL code for the function. */
6916 allocate_struct_function (fndecl, false);
6918 /* Begin the statement tree for this function. */
6919 DECL_SAVED_TREE (fndecl) = push_stmt_list ();
6921 /* ??? Insert the contents of the pending sizes list into the function
6922 to be evaluated. The only reason left to have this is
6923 void foo(int n, int array[n++])
6924 because we throw away the array type in favor of a pointer type, and
6925 thus won't naturally see the SAVE_EXPR containing the increment. All
6926 other pending sizes would be handled by gimplify_parameters. */
6929 for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t))
6930 add_stmt (TREE_VALUE (t));
6933 /* Even though we're inside a function body, we still don't want to
6934 call expand_expr to calculate the size of a variable-sized array.
6935 We haven't necessarily assigned RTL to all variables yet, so it's
6936 not safe to try to expand expressions involving them. */
6937 cfun->dont_save_pending_sizes_p = 1;
6940 /* Emit diagnostics that require gimple input for detection. Operate on
6941 FNDECL and all its nested functions. */
6944 c_gimple_diagnostics_recursively (tree fndecl)
6946 struct cgraph_node *cgn;
6947 gimple_seq body = gimple_body (fndecl);
6949 /* Handle attribute((warn_unused_result)). Relies on gimple input. */
6950 c_warn_unused_result (body);
6952 /* Notice when OpenMP structured block constraints are violated. */
6954 diagnose_omp_structured_block_errors (fndecl);
6956 /* Finalize all nested functions now. */
6957 cgn = cgraph_node (fndecl);
6958 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
6959 c_gimple_diagnostics_recursively (cgn->decl);
6962 /* Finish up a function declaration and compile that function
6963 all the way to assembler language output. The free the storage
6964 for the function definition.
6966 This is called after parsing the body of the function definition. */
6969 finish_function (void)
6971 tree fndecl = current_function_decl;
6973 label_context_stack_se = label_context_stack_se->next;
6974 label_context_stack_vm = label_context_stack_vm->next;
6976 if (TREE_CODE (fndecl) == FUNCTION_DECL
6977 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
6979 tree args = DECL_ARGUMENTS (fndecl);
6980 for (; args; args = TREE_CHAIN (args))
6982 tree type = TREE_TYPE (args);
6983 if (INTEGRAL_TYPE_P (type)
6984 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
6985 DECL_ARG_TYPE (args) = integer_type_node;
6989 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
6990 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6992 /* Must mark the RESULT_DECL as being in this function. */
6994 if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
6995 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
6997 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted
6998 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6999 == integer_type_node && flag_isoc99)
7001 tree stmt = c_finish_return (integer_zero_node, NULL_TREE);
7002 /* Hack. We don't want the middle-end to warn that this return
7003 is unreachable, so we mark its location as special. Using
7004 UNKNOWN_LOCATION has the problem that it gets clobbered in
7005 annotate_one_with_locus. A cleaner solution might be to
7006 ensure ! should_carry_locus_p (stmt), but that needs a flag.
7008 SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION);
7011 /* Tie off the statement tree for this function. */
7012 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
7014 finish_fname_decls ();
7016 /* Complain if there's just no return statement. */
7017 if (warn_return_type
7018 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
7019 && !current_function_returns_value && !current_function_returns_null
7020 /* Don't complain if we are no-return. */
7021 && !current_function_returns_abnormally
7022 /* Don't warn for main(). */
7023 && !MAIN_NAME_P (DECL_NAME (fndecl))
7024 /* Or if they didn't actually specify a return type. */
7025 && !C_FUNCTION_IMPLICIT_INT (fndecl)
7026 /* Normally, with -Wreturn-type, flow will complain, but we might
7027 optimize out static functions. */
7028 && !TREE_PUBLIC (fndecl))
7030 warning (OPT_Wreturn_type,
7031 "no return statement in function returning non-void");
7032 TREE_NO_WARNING (fndecl) = 1;
7035 /* Store the end of the function, so that we get good line number
7036 info for the epilogue. */
7037 cfun->function_end_locus = input_location;
7039 /* Finalize the ELF visibility for the function. */
7040 c_determine_visibility (fndecl);
7042 /* For GNU C extern inline functions disregard inline limits. */
7043 if (DECL_EXTERNAL (fndecl)
7044 && DECL_DECLARED_INLINE_P (fndecl))
7045 DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
7047 /* Genericize before inlining. Delay genericizing nested functions
7048 until their parent function is genericized. Since finalizing
7049 requires GENERIC, delay that as well. */
7051 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
7052 && !undef_nested_function)
7054 if (!decl_function_context (fndecl))
7056 c_genericize (fndecl);
7057 c_gimple_diagnostics_recursively (fndecl);
7059 /* ??? Objc emits functions after finalizing the compilation unit.
7060 This should be cleaned up later and this conditional removed. */
7061 if (cgraph_global_info_ready)
7063 cgraph_add_new_function (fndecl, false);
7067 cgraph_finalize_function (fndecl, false);
7071 /* Register this function with cgraph just far enough to get it
7072 added to our parent's nested function list. Handy, since the
7073 C front end doesn't have such a list. */
7074 (void) cgraph_node (fndecl);
7078 if (!decl_function_context (fndecl))
7079 undef_nested_function = false;
7081 /* We're leaving the context of this function, so zap cfun.
7082 It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
7083 tree_rest_of_compilation. */
7085 current_function_decl = NULL;
7088 /* Check the declarations given in a for-loop for satisfying the C99
7089 constraints. If exactly one such decl is found, return it. */
7092 check_for_loop_decls (void)
7094 struct c_binding *b;
7095 tree one_decl = NULL_TREE;
7100 static bool hint = true;
7101 /* If we get here, declarations have been used in a for loop without
7102 the C99 for loop scope. This doesn't make much sense, so don't
7104 error ("%<for%> loop initial declarations are only allowed in C99 mode");
7107 inform (input_location,
7108 "use option -std=c99 or -std=gnu99 to compile your code");
7113 /* C99 subclause 6.8.5 paragraph 3:
7115 [#3] The declaration part of a for statement shall only
7116 declare identifiers for objects having storage class auto or
7119 It isn't clear whether, in this sentence, "identifiers" binds to
7120 "shall only declare" or to "objects" - that is, whether all identifiers
7121 declared must be identifiers for objects, or whether the restriction
7122 only applies to those that are. (A question on this in comp.std.c
7123 in November 2000 received no answer.) We implement the strictest
7124 interpretation, to avoid creating an extension which later causes
7127 for (b = current_scope->bindings; b; b = b->prev)
7130 tree decl = b->decl;
7135 switch (TREE_CODE (decl))
7138 if (TREE_STATIC (decl))
7139 error ("declaration of static variable %q+D in %<for%> loop "
7140 "initial declaration", decl);
7141 else if (DECL_EXTERNAL (decl))
7142 error ("declaration of %<extern%> variable %q+D in %<for%> loop "
7143 "initial declaration", decl);
7147 error ("%<struct %E%> declared in %<for%> loop initial declaration",
7151 error ("%<union %E%> declared in %<for%> loop initial declaration",
7155 error ("%<enum %E%> declared in %<for%> loop initial declaration",
7159 error ("declaration of non-variable %q+D in %<for%> loop "
7160 "initial declaration", decl);
7167 return n_decls == 1 ? one_decl : NULL_TREE;
7170 /* Save and reinitialize the variables
7171 used during compilation of a C function. */
7174 c_push_function_context (void)
7176 struct language_function *p;
7177 p = GGC_NEW (struct language_function);
7180 p->base.x_stmt_tree = c_stmt_tree;
7181 p->x_break_label = c_break_label;
7182 p->x_cont_label = c_cont_label;
7183 p->x_switch_stack = c_switch_stack;
7184 p->arg_info = current_function_arg_info;
7185 p->returns_value = current_function_returns_value;
7186 p->returns_null = current_function_returns_null;
7187 p->returns_abnormally = current_function_returns_abnormally;
7188 p->warn_about_return_type = warn_about_return_type;
7190 push_function_context ();
7193 /* Restore the variables used during compilation of a C function. */
7196 c_pop_function_context (void)
7198 struct language_function *p;
7200 pop_function_context ();
7202 cfun->language = NULL;
7204 if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
7205 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
7207 /* Stop pointing to the local nodes about to be freed. */
7208 /* But DECL_INITIAL must remain nonzero so we know this
7209 was an actual function definition. */
7210 DECL_INITIAL (current_function_decl) = error_mark_node;
7211 DECL_ARGUMENTS (current_function_decl) = 0;
7214 c_stmt_tree = p->base.x_stmt_tree;
7215 c_break_label = p->x_break_label;
7216 c_cont_label = p->x_cont_label;
7217 c_switch_stack = p->x_switch_stack;
7218 current_function_arg_info = p->arg_info;
7219 current_function_returns_value = p->returns_value;
7220 current_function_returns_null = p->returns_null;
7221 current_function_returns_abnormally = p->returns_abnormally;
7222 warn_about_return_type = p->warn_about_return_type;
7225 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
7228 c_dup_lang_specific_decl (tree decl)
7230 struct lang_decl *ld;
7232 if (!DECL_LANG_SPECIFIC (decl))
7235 ld = GGC_NEW (struct lang_decl);
7236 memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl));
7237 DECL_LANG_SPECIFIC (decl) = ld;
7240 /* The functions below are required for functionality of doing
7241 function at once processing in the C front end. Currently these
7242 functions are not called from anywhere in the C front end, but as
7243 these changes continue, that will change. */
7245 /* Returns the stmt_tree (if any) to which statements are currently
7246 being added. If there is no active statement-tree, NULL is
7250 current_stmt_tree (void)
7252 return &c_stmt_tree;
7255 /* Return the global value of T as a symbol. */
7258 identifier_global_value (tree t)
7260 struct c_binding *b;
7262 for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
7263 if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
7269 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
7270 otherwise the name is found in ridpointers from RID_INDEX. */
7273 record_builtin_type (enum rid rid_index, const char *name, tree type)
7277 id = ridpointers[(int) rid_index];
7279 id = get_identifier (name);
7280 decl = build_decl (TYPE_DECL, id, type);
7282 if (debug_hooks->type_decl)
7283 debug_hooks->type_decl (decl, false);
7286 /* Build the void_list_node (void_type_node having been created). */
7288 build_void_list_node (void)
7290 tree t = build_tree_list (NULL_TREE, void_type_node);
7294 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR. */
7297 build_c_parm (struct c_declspecs *specs, tree attrs,
7298 struct c_declarator *declarator)
7300 struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
7303 ret->declarator = declarator;
7307 /* Return a declarator with nested attributes. TARGET is the inner
7308 declarator to which these attributes apply. ATTRS are the
7311 struct c_declarator *
7312 build_attrs_declarator (tree attrs, struct c_declarator *target)
7314 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
7315 ret->kind = cdk_attrs;
7316 ret->declarator = target;
7317 ret->u.attrs = attrs;
7321 /* Return a declarator for a function with arguments specified by ARGS
7322 and return type specified by TARGET. */
7324 struct c_declarator *
7325 build_function_declarator (struct c_arg_info *args,
7326 struct c_declarator *target)
7328 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
7329 ret->kind = cdk_function;
7330 ret->declarator = target;
7331 ret->u.arg_info = args;
7335 /* Return a declarator for the identifier IDENT (which may be
7336 NULL_TREE for an abstract declarator). */
7338 struct c_declarator *
7339 build_id_declarator (tree ident)
7341 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
7343 ret->declarator = 0;
7345 /* Default value - may get reset to a more precise location. */
7346 ret->id_loc = input_location;
7350 /* Return something to represent absolute declarators containing a *.
7351 TARGET is the absolute declarator that the * contains.
7352 TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
7353 to apply to the pointer type. */
7355 struct c_declarator *
7356 make_pointer_declarator (struct c_declspecs *type_quals_attrs,
7357 struct c_declarator *target)
7361 struct c_declarator *itarget = target;
7362 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
7363 if (type_quals_attrs)
7365 attrs = type_quals_attrs->attrs;
7366 quals = quals_from_declspecs (type_quals_attrs);
7367 if (attrs != NULL_TREE)
7368 itarget = build_attrs_declarator (attrs, target);
7370 ret->kind = cdk_pointer;
7371 ret->declarator = itarget;
7372 ret->u.pointer_quals = quals;
7376 /* Return a pointer to a structure for an empty list of declaration
7379 struct c_declspecs *
7380 build_null_declspecs (void)
7382 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
7387 ret->typespec_word = cts_none;
7388 ret->storage_class = csc_none;
7389 ret->expr_const_operands = true;
7390 ret->declspecs_seen_p = false;
7391 ret->type_seen_p = false;
7392 ret->non_sc_seen_p = false;
7393 ret->typedef_p = false;
7394 ret->tag_defined_p = false;
7395 ret->explicit_signed_p = false;
7396 ret->deprecated_p = false;
7397 ret->default_int_p = false;
7398 ret->long_p = false;
7399 ret->long_long_p = false;
7400 ret->short_p = false;
7401 ret->signed_p = false;
7402 ret->unsigned_p = false;
7403 ret->complex_p = false;
7404 ret->inline_p = false;
7405 ret->thread_p = false;
7406 ret->const_p = false;
7407 ret->volatile_p = false;
7408 ret->restrict_p = false;
7409 ret->saturating_p = false;
7413 /* Add the type qualifier QUAL to the declaration specifiers SPECS,
7416 struct c_declspecs *
7417 declspecs_add_qual (struct c_declspecs *specs, tree qual)
7421 specs->non_sc_seen_p = true;
7422 specs->declspecs_seen_p = true;
7423 gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
7424 && C_IS_RESERVED_WORD (qual));
7425 i = C_RID_CODE (qual);
7429 dupe = specs->const_p;
7430 specs->const_p = true;
7433 dupe = specs->volatile_p;
7434 specs->volatile_p = true;
7437 dupe = specs->restrict_p;
7438 specs->restrict_p = true;
7443 if (dupe && !flag_isoc99)
7444 pedwarn (input_location, OPT_pedantic, "duplicate %qE", qual);
7448 /* Add the type specifier TYPE to the declaration specifiers SPECS,
7451 struct c_declspecs *
7452 declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec)
7454 tree type = spec.spec;
7455 specs->non_sc_seen_p = true;
7456 specs->declspecs_seen_p = true;
7457 specs->type_seen_p = true;
7458 if (TREE_DEPRECATED (type))
7459 specs->deprecated_p = true;
7461 /* Handle type specifier keywords. */
7462 if (TREE_CODE (type) == IDENTIFIER_NODE
7463 && C_IS_RESERVED_WORD (type)
7464 && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
7466 enum rid i = C_RID_CODE (type);
7469 error ("two or more data types in declaration specifiers");
7472 if ((int) i <= (int) RID_LAST_MODIFIER)
7474 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */
7479 if (specs->long_long_p)
7481 error ("%<long long long%> is too long for GCC");
7486 if (specs->typespec_word == cts_double)
7488 error ("both %<long long%> and %<double%> in "
7489 "declaration specifiers");
7492 pedwarn_c90 (input_location, OPT_Wlong_long,
7493 "ISO C90 does not support %<long long%>");
7494 specs->long_long_p = 1;
7498 error ("both %<long%> and %<short%> in "
7499 "declaration specifiers");
7500 else if (specs->typespec_word == cts_void)
7501 error ("both %<long%> and %<void%> in "
7502 "declaration specifiers");
7503 else if (specs->typespec_word == cts_bool)
7504 error ("both %<long%> and %<_Bool%> in "
7505 "declaration specifiers");
7506 else if (specs->typespec_word == cts_char)
7507 error ("both %<long%> and %<char%> in "
7508 "declaration specifiers");
7509 else if (specs->typespec_word == cts_float)
7510 error ("both %<long%> and %<float%> in "
7511 "declaration specifiers");
7512 else if (specs->typespec_word == cts_dfloat32)
7513 error ("both %<long%> and %<_Decimal32%> in "
7514 "declaration specifiers");
7515 else if (specs->typespec_word == cts_dfloat64)
7516 error ("both %<long%> and %<_Decimal64%> in "
7517 "declaration specifiers");
7518 else if (specs->typespec_word == cts_dfloat128)
7519 error ("both %<long%> and %<_Decimal128%> in "
7520 "declaration specifiers");
7522 specs->long_p = true;
7525 dupe = specs->short_p;
7527 error ("both %<long%> and %<short%> in "
7528 "declaration specifiers");
7529 else if (specs->typespec_word == cts_void)
7530 error ("both %<short%> and %<void%> in "
7531 "declaration specifiers");
7532 else if (specs->typespec_word == cts_bool)
7533 error ("both %<short%> and %<_Bool%> in "
7534 "declaration specifiers");
7535 else if (specs->typespec_word == cts_char)
7536 error ("both %<short%> and %<char%> in "
7537 "declaration specifiers");
7538 else if (specs->typespec_word == cts_float)
7539 error ("both %<short%> and %<float%> in "
7540 "declaration specifiers");
7541 else if (specs->typespec_word == cts_double)
7542 error ("both %<short%> and %<double%> in "
7543 "declaration specifiers");
7544 else if (specs->typespec_word == cts_dfloat32)
7545 error ("both %<short%> and %<_Decimal32%> in "
7546 "declaration specifiers");
7547 else if (specs->typespec_word == cts_dfloat64)
7548 error ("both %<short%> and %<_Decimal64%> in "
7549 "declaration specifiers");
7550 else if (specs->typespec_word == cts_dfloat128)
7551 error ("both %<short%> and %<_Decimal128%> in "
7552 "declaration specifiers");
7554 specs->short_p = true;
7557 dupe = specs->signed_p;
7558 if (specs->unsigned_p)
7559 error ("both %<signed%> and %<unsigned%> in "
7560 "declaration specifiers");
7561 else if (specs->typespec_word == cts_void)
7562 error ("both %<signed%> and %<void%> in "
7563 "declaration specifiers");
7564 else if (specs->typespec_word == cts_bool)
7565 error ("both %<signed%> and %<_Bool%> in "
7566 "declaration specifiers");
7567 else if (specs->typespec_word == cts_float)
7568 error ("both %<signed%> and %<float%> in "
7569 "declaration specifiers");
7570 else if (specs->typespec_word == cts_double)
7571 error ("both %<signed%> and %<double%> in "
7572 "declaration specifiers");
7573 else if (specs->typespec_word == cts_dfloat32)
7574 error ("both %<signed%> and %<_Decimal32%> in "
7575 "declaration specifiers");
7576 else if (specs->typespec_word == cts_dfloat64)
7577 error ("both %<signed%> and %<_Decimal64%> in "
7578 "declaration specifiers");
7579 else if (specs->typespec_word == cts_dfloat128)
7580 error ("both %<signed%> and %<_Decimal128%> in "
7581 "declaration specifiers");
7583 specs->signed_p = true;
7586 dupe = specs->unsigned_p;
7587 if (specs->signed_p)
7588 error ("both %<signed%> and %<unsigned%> in "
7589 "declaration specifiers");
7590 else if (specs->typespec_word == cts_void)
7591 error ("both %<unsigned%> and %<void%> in "
7592 "declaration specifiers");
7593 else if (specs->typespec_word == cts_bool)
7594 error ("both %<unsigned%> and %<_Bool%> in "
7595 "declaration specifiers");
7596 else if (specs->typespec_word == cts_float)
7597 error ("both %<unsigned%> and %<float%> in "
7598 "declaration specifiers");
7599 else if (specs->typespec_word == cts_double)
7600 error ("both %<unsigned%> and %<double%> in "
7601 "declaration specifiers");
7602 else if (specs->typespec_word == cts_dfloat32)
7603 error ("both %<unsigned%> and %<_Decimal32%> in "
7604 "declaration specifiers");
7605 else if (specs->typespec_word == cts_dfloat64)
7606 error ("both %<unsigned%> and %<_Decimal64%> in "
7607 "declaration specifiers");
7608 else if (specs->typespec_word == cts_dfloat128)
7609 error ("both %<unsigned%> and %<_Decimal128%> in "
7610 "declaration specifiers");
7612 specs->unsigned_p = true;
7615 dupe = specs->complex_p;
7616 if (!flag_isoc99 && !in_system_header)
7617 pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types");
7618 if (specs->typespec_word == cts_void)
7619 error ("both %<complex%> and %<void%> in "
7620 "declaration specifiers");
7621 else if (specs->typespec_word == cts_bool)
7622 error ("both %<complex%> and %<_Bool%> in "
7623 "declaration specifiers");
7624 else if (specs->typespec_word == cts_dfloat32)
7625 error ("both %<complex%> and %<_Decimal32%> in "
7626 "declaration specifiers");
7627 else if (specs->typespec_word == cts_dfloat64)
7628 error ("both %<complex%> and %<_Decimal64%> in "
7629 "declaration specifiers");
7630 else if (specs->typespec_word == cts_dfloat128)
7631 error ("both %<complex%> and %<_Decimal128%> in "
7632 "declaration specifiers");
7633 else if (specs->typespec_word == cts_fract)
7634 error ("both %<complex%> and %<_Fract%> in "
7635 "declaration specifiers");
7636 else if (specs->typespec_word == cts_accum)
7637 error ("both %<complex%> and %<_Accum%> in "
7638 "declaration specifiers");
7639 else if (specs->saturating_p)
7640 error ("both %<complex%> and %<_Sat%> in "
7641 "declaration specifiers");
7643 specs->complex_p = true;
7646 dupe = specs->saturating_p;
7647 pedwarn (input_location, OPT_pedantic, "ISO C does not support saturating types");
7648 if (specs->typespec_word == cts_void)
7649 error ("both %<_Sat%> and %<void%> in "
7650 "declaration specifiers");
7651 else if (specs->typespec_word == cts_bool)
7652 error ("both %<_Sat%> and %<_Bool%> in "
7653 "declaration specifiers");
7654 else if (specs->typespec_word == cts_char)
7655 error ("both %<_Sat%> and %<char%> in "
7656 "declaration specifiers");
7657 else if (specs->typespec_word == cts_int)
7658 error ("both %<_Sat%> and %<int%> in "
7659 "declaration specifiers");
7660 else if (specs->typespec_word == cts_float)
7661 error ("both %<_Sat%> and %<float%> in "
7662 "declaration specifiers");
7663 else if (specs->typespec_word == cts_double)
7664 error ("both %<_Sat%> and %<double%> in "
7665 "declaration specifiers");
7666 else if (specs->typespec_word == cts_dfloat32)
7667 error ("both %<_Sat%> and %<_Decimal32%> in "
7668 "declaration specifiers");
7669 else if (specs->typespec_word == cts_dfloat64)
7670 error ("both %<_Sat%> and %<_Decimal64%> in "
7671 "declaration specifiers");
7672 else if (specs->typespec_word == cts_dfloat128)
7673 error ("both %<_Sat%> and %<_Decimal128%> in "
7674 "declaration specifiers");
7675 else if (specs->complex_p)
7676 error ("both %<_Sat%> and %<complex%> in "
7677 "declaration specifiers");
7679 specs->saturating_p = true;
7686 error ("duplicate %qE", type);
7692 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32",
7693 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */
7694 if (specs->typespec_word != cts_none)
7696 error ("two or more data types in declaration specifiers");
7703 error ("both %<long%> and %<void%> in "
7704 "declaration specifiers");
7705 else if (specs->short_p)
7706 error ("both %<short%> and %<void%> in "
7707 "declaration specifiers");
7708 else if (specs->signed_p)
7709 error ("both %<signed%> and %<void%> in "
7710 "declaration specifiers");
7711 else if (specs->unsigned_p)
7712 error ("both %<unsigned%> and %<void%> in "
7713 "declaration specifiers");
7714 else if (specs->complex_p)
7715 error ("both %<complex%> and %<void%> in "
7716 "declaration specifiers");
7717 else if (specs->saturating_p)
7718 error ("both %<_Sat%> and %<void%> in "
7719 "declaration specifiers");
7721 specs->typespec_word = cts_void;
7725 error ("both %<long%> and %<_Bool%> in "
7726 "declaration specifiers");
7727 else if (specs->short_p)
7728 error ("both %<short%> and %<_Bool%> in "
7729 "declaration specifiers");
7730 else if (specs->signed_p)
7731 error ("both %<signed%> and %<_Bool%> in "
7732 "declaration specifiers");
7733 else if (specs->unsigned_p)
7734 error ("both %<unsigned%> and %<_Bool%> in "
7735 "declaration specifiers");
7736 else if (specs->complex_p)
7737 error ("both %<complex%> and %<_Bool%> in "
7738 "declaration specifiers");
7739 else if (specs->saturating_p)
7740 error ("both %<_Sat%> and %<_Bool%> in "
7741 "declaration specifiers");
7743 specs->typespec_word = cts_bool;
7747 error ("both %<long%> and %<char%> in "
7748 "declaration specifiers");
7749 else if (specs->short_p)
7750 error ("both %<short%> and %<char%> in "
7751 "declaration specifiers");
7752 else if (specs->saturating_p)
7753 error ("both %<_Sat%> and %<char%> in "
7754 "declaration specifiers");
7756 specs->typespec_word = cts_char;
7759 if (specs->saturating_p)
7760 error ("both %<_Sat%> and %<int%> in "
7761 "declaration specifiers");
7763 specs->typespec_word = cts_int;
7767 error ("both %<long%> and %<float%> in "
7768 "declaration specifiers");
7769 else if (specs->short_p)
7770 error ("both %<short%> and %<float%> in "
7771 "declaration specifiers");
7772 else if (specs->signed_p)
7773 error ("both %<signed%> and %<float%> in "
7774 "declaration specifiers");
7775 else if (specs->unsigned_p)
7776 error ("both %<unsigned%> and %<float%> in "
7777 "declaration specifiers");
7778 else if (specs->saturating_p)
7779 error ("both %<_Sat%> and %<float%> in "
7780 "declaration specifiers");
7782 specs->typespec_word = cts_float;
7785 if (specs->long_long_p)
7786 error ("both %<long long%> and %<double%> in "
7787 "declaration specifiers");
7788 else if (specs->short_p)
7789 error ("both %<short%> and %<double%> in "
7790 "declaration specifiers");
7791 else if (specs->signed_p)
7792 error ("both %<signed%> and %<double%> in "
7793 "declaration specifiers");
7794 else if (specs->unsigned_p)
7795 error ("both %<unsigned%> and %<double%> in "
7796 "declaration specifiers");
7797 else if (specs->saturating_p)
7798 error ("both %<_Sat%> and %<double%> in "
7799 "declaration specifiers");
7801 specs->typespec_word = cts_double;
7808 if (i == RID_DFLOAT32)
7810 else if (i == RID_DFLOAT64)
7813 str = "_Decimal128";
7814 if (specs->long_long_p)
7815 error ("both %<long long%> and %<%s%> in "
7816 "declaration specifiers", str);
7818 error ("both %<long%> and %<%s%> in "
7819 "declaration specifiers", str);
7820 else if (specs->short_p)
7821 error ("both %<short%> and %<%s%> in "
7822 "declaration specifiers", str);
7823 else if (specs->signed_p)
7824 error ("both %<signed%> and %<%s%> in "
7825 "declaration specifiers", str);
7826 else if (specs->unsigned_p)
7827 error ("both %<unsigned%> and %<%s%> in "
7828 "declaration specifiers", str);
7829 else if (specs->complex_p)
7830 error ("both %<complex%> and %<%s%> in "
7831 "declaration specifiers", str);
7832 else if (specs->saturating_p)
7833 error ("both %<_Sat%> and %<%s%> in "
7834 "declaration specifiers", str);
7835 else if (i == RID_DFLOAT32)
7836 specs->typespec_word = cts_dfloat32;
7837 else if (i == RID_DFLOAT64)
7838 specs->typespec_word = cts_dfloat64;
7840 specs->typespec_word = cts_dfloat128;
7842 if (!targetm.decimal_float_supported_p ())
7843 error ("decimal floating point not supported for this target");
7844 pedwarn (input_location, OPT_pedantic,
7845 "ISO C does not support decimal floating point");
7855 if (specs->complex_p)
7856 error ("both %<complex%> and %<%s%> in "
7857 "declaration specifiers", str);
7858 else if (i == RID_FRACT)
7859 specs->typespec_word = cts_fract;
7861 specs->typespec_word = cts_accum;
7863 if (!targetm.fixed_point_supported_p ())
7864 error ("fixed-point types not supported for this target");
7865 pedwarn (input_location, OPT_pedantic,
7866 "ISO C does not support fixed-point types");
7869 /* ObjC reserved word "id", handled below. */
7875 /* Now we have a typedef (a TYPE_DECL node), an identifier (some
7876 form of ObjC type, cases such as "int" and "long" being handled
7877 above), a TYPE (struct, union, enum and typeof specifiers) or an
7878 ERROR_MARK. In none of these cases may there have previously
7879 been any type specifiers. */
7880 if (specs->type || specs->typespec_word != cts_none
7881 || specs->long_p || specs->short_p || specs->signed_p
7882 || specs->unsigned_p || specs->complex_p)
7883 error ("two or more data types in declaration specifiers");
7884 else if (TREE_CODE (type) == TYPE_DECL)
7886 if (TREE_TYPE (type) == error_mark_node)
7887 ; /* Allow the type to default to int to avoid cascading errors. */
7890 specs->type = TREE_TYPE (type);
7891 specs->decl_attr = DECL_ATTRIBUTES (type);
7892 specs->typedef_p = true;
7893 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
7896 else if (TREE_CODE (type) == IDENTIFIER_NODE)
7898 tree t = lookup_name (type);
7899 if (!t || TREE_CODE (t) != TYPE_DECL)
7900 error ("%qE fails to be a typedef or built in type", type);
7901 else if (TREE_TYPE (t) == error_mark_node)
7904 specs->type = TREE_TYPE (t);
7906 else if (TREE_CODE (type) != ERROR_MARK)
7908 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref)
7909 specs->tag_defined_p = true;
7910 if (spec.kind == ctsk_typeof)
7912 specs->typedef_p = true;
7916 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
7917 specs->expr, spec.expr);
7919 specs->expr = spec.expr;
7920 specs->expr_const_operands &= spec.expr_const_operands;
7929 /* Add the storage class specifier or function specifier SCSPEC to the
7930 declaration specifiers SPECS, returning SPECS. */
7932 struct c_declspecs *
7933 declspecs_add_scspec (struct c_declspecs *specs, tree scspec)
7936 enum c_storage_class n = csc_none;
7938 specs->declspecs_seen_p = true;
7939 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
7940 && C_IS_RESERVED_WORD (scspec));
7941 i = C_RID_CODE (scspec);
7942 if (specs->non_sc_seen_p)
7943 warning (OPT_Wold_style_declaration,
7944 "%qE is not at beginning of declaration", scspec);
7948 /* C99 permits duplicate inline. Although of doubtful utility,
7949 it seems simplest to permit it in gnu89 mode as well, as
7950 there is also little utility in maintaining this as a
7951 difference between gnu89 and C99 inline. */
7953 specs->inline_p = true;
7956 dupe = specs->thread_p;
7957 if (specs->storage_class == csc_auto)
7958 error ("%<__thread%> used with %<auto%>");
7959 else if (specs->storage_class == csc_register)
7960 error ("%<__thread%> used with %<register%>");
7961 else if (specs->storage_class == csc_typedef)
7962 error ("%<__thread%> used with %<typedef%>");
7964 specs->thread_p = true;
7971 /* Diagnose "__thread extern". */
7972 if (specs->thread_p)
7973 error ("%<__thread%> before %<extern%>");
7980 /* Diagnose "__thread static". */
7981 if (specs->thread_p)
7982 error ("%<__thread%> before %<static%>");
7990 if (n != csc_none && n == specs->storage_class)
7993 error ("duplicate %qE", scspec);
7996 if (specs->storage_class != csc_none && n != specs->storage_class)
7998 error ("multiple storage classes in declaration specifiers");
8002 specs->storage_class = n;
8003 if (n != csc_extern && n != csc_static && specs->thread_p)
8005 error ("%<__thread%> used with %qE", scspec);
8006 specs->thread_p = false;
8013 /* Add the attributes ATTRS to the declaration specifiers SPECS,
8016 struct c_declspecs *
8017 declspecs_add_attrs (struct c_declspecs *specs, tree attrs)
8019 specs->attrs = chainon (attrs, specs->attrs);
8020 specs->declspecs_seen_p = true;
8024 /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
8025 specifiers with any other type specifier to determine the resulting
8026 type. This is where ISO C checks on complex types are made, since
8027 "_Complex long" is a prefix of the valid ISO C type "_Complex long
8030 struct c_declspecs *
8031 finish_declspecs (struct c_declspecs *specs)
8033 /* If a type was specified as a whole, we have no modifiers and are
8035 if (specs->type != NULL_TREE)
8037 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
8038 && !specs->signed_p && !specs->unsigned_p
8039 && !specs->complex_p);
8043 /* If none of "void", "_Bool", "char", "int", "float" or "double"
8044 has been specified, treat it as "int" unless "_Complex" is
8045 present and there are no other specifiers. If we just have
8046 "_Complex", it is equivalent to "_Complex double", but e.g.
8047 "_Complex short" is equivalent to "_Complex short int". */
8048 if (specs->typespec_word == cts_none)
8050 if (specs->saturating_p)
8052 error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
8053 if (!targetm.fixed_point_supported_p ())
8054 error ("fixed-point types not supported for this target");
8055 specs->typespec_word = cts_fract;
8057 else if (specs->long_p || specs->short_p
8058 || specs->signed_p || specs->unsigned_p)
8060 specs->typespec_word = cts_int;
8062 else if (specs->complex_p)
8064 specs->typespec_word = cts_double;
8065 pedwarn (input_location, OPT_pedantic,
8066 "ISO C does not support plain %<complex%> meaning "
8067 "%<double complex%>");
8071 specs->typespec_word = cts_int;
8072 specs->default_int_p = true;
8073 /* We don't diagnose this here because grokdeclarator will
8074 give more specific diagnostics according to whether it is
8075 a function definition. */
8079 /* If "signed" was specified, record this to distinguish "int" and
8080 "signed int" in the case of a bit-field with
8081 -funsigned-bitfields. */
8082 specs->explicit_signed_p = specs->signed_p;
8084 /* Now compute the actual type. */
8085 switch (specs->typespec_word)
8088 gcc_assert (!specs->long_p && !specs->short_p
8089 && !specs->signed_p && !specs->unsigned_p
8090 && !specs->complex_p);
8091 specs->type = void_type_node;
8094 gcc_assert (!specs->long_p && !specs->short_p
8095 && !specs->signed_p && !specs->unsigned_p
8096 && !specs->complex_p);
8097 specs->type = boolean_type_node;
8100 gcc_assert (!specs->long_p && !specs->short_p);
8101 gcc_assert (!(specs->signed_p && specs->unsigned_p));
8102 if (specs->signed_p)
8103 specs->type = signed_char_type_node;
8104 else if (specs->unsigned_p)
8105 specs->type = unsigned_char_type_node;
8107 specs->type = char_type_node;
8108 if (specs->complex_p)
8110 pedwarn (input_location, OPT_pedantic,
8111 "ISO C does not support complex integer types");
8112 specs->type = build_complex_type (specs->type);
8116 gcc_assert (!(specs->long_p && specs->short_p));
8117 gcc_assert (!(specs->signed_p && specs->unsigned_p));
8118 if (specs->long_long_p)
8119 specs->type = (specs->unsigned_p
8120 ? long_long_unsigned_type_node
8121 : long_long_integer_type_node);
8122 else if (specs->long_p)
8123 specs->type = (specs->unsigned_p
8124 ? long_unsigned_type_node
8125 : long_integer_type_node);
8126 else if (specs->short_p)
8127 specs->type = (specs->unsigned_p
8128 ? short_unsigned_type_node
8129 : short_integer_type_node);
8131 specs->type = (specs->unsigned_p
8132 ? unsigned_type_node
8133 : integer_type_node);
8134 if (specs->complex_p)
8136 pedwarn (input_location, OPT_pedantic,
8137 "ISO C does not support complex integer types");
8138 specs->type = build_complex_type (specs->type);
8142 gcc_assert (!specs->long_p && !specs->short_p
8143 && !specs->signed_p && !specs->unsigned_p);
8144 specs->type = (specs->complex_p
8145 ? complex_float_type_node
8149 gcc_assert (!specs->long_long_p && !specs->short_p
8150 && !specs->signed_p && !specs->unsigned_p);
8153 specs->type = (specs->complex_p
8154 ? complex_long_double_type_node
8155 : long_double_type_node);
8159 specs->type = (specs->complex_p
8160 ? complex_double_type_node
8161 : double_type_node);
8167 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
8168 && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
8169 if (specs->typespec_word == cts_dfloat32)
8170 specs->type = dfloat32_type_node;
8171 else if (specs->typespec_word == cts_dfloat64)
8172 specs->type = dfloat64_type_node;
8174 specs->type = dfloat128_type_node;
8177 gcc_assert (!specs->complex_p);
8178 if (!targetm.fixed_point_supported_p ())
8179 specs->type = integer_type_node;
8180 else if (specs->saturating_p)
8182 if (specs->long_long_p)
8183 specs->type = specs->unsigned_p
8184 ? sat_unsigned_long_long_fract_type_node
8185 : sat_long_long_fract_type_node;
8186 else if (specs->long_p)
8187 specs->type = specs->unsigned_p
8188 ? sat_unsigned_long_fract_type_node
8189 : sat_long_fract_type_node;
8190 else if (specs->short_p)
8191 specs->type = specs->unsigned_p
8192 ? sat_unsigned_short_fract_type_node
8193 : sat_short_fract_type_node;
8195 specs->type = specs->unsigned_p
8196 ? sat_unsigned_fract_type_node
8197 : sat_fract_type_node;
8201 if (specs->long_long_p)
8202 specs->type = specs->unsigned_p
8203 ? unsigned_long_long_fract_type_node
8204 : long_long_fract_type_node;
8205 else if (specs->long_p)
8206 specs->type = specs->unsigned_p
8207 ? unsigned_long_fract_type_node
8208 : long_fract_type_node;
8209 else if (specs->short_p)
8210 specs->type = specs->unsigned_p
8211 ? unsigned_short_fract_type_node
8212 : short_fract_type_node;
8214 specs->type = specs->unsigned_p
8215 ? unsigned_fract_type_node
8220 gcc_assert (!specs->complex_p);
8221 if (!targetm.fixed_point_supported_p ())
8222 specs->type = integer_type_node;
8223 else if (specs->saturating_p)
8225 if (specs->long_long_p)
8226 specs->type = specs->unsigned_p
8227 ? sat_unsigned_long_long_accum_type_node
8228 : sat_long_long_accum_type_node;
8229 else if (specs->long_p)
8230 specs->type = specs->unsigned_p
8231 ? sat_unsigned_long_accum_type_node
8232 : sat_long_accum_type_node;
8233 else if (specs->short_p)
8234 specs->type = specs->unsigned_p
8235 ? sat_unsigned_short_accum_type_node
8236 : sat_short_accum_type_node;
8238 specs->type = specs->unsigned_p
8239 ? sat_unsigned_accum_type_node
8240 : sat_accum_type_node;
8244 if (specs->long_long_p)
8245 specs->type = specs->unsigned_p
8246 ? unsigned_long_long_accum_type_node
8247 : long_long_accum_type_node;
8248 else if (specs->long_p)
8249 specs->type = specs->unsigned_p
8250 ? unsigned_long_accum_type_node
8251 : long_accum_type_node;
8252 else if (specs->short_p)
8253 specs->type = specs->unsigned_p
8254 ? unsigned_short_accum_type_node
8255 : short_accum_type_node;
8257 specs->type = specs->unsigned_p
8258 ? unsigned_accum_type_node
8269 /* A subroutine of c_write_global_declarations. Perform final processing
8270 on one file scope's declarations (or the external scope's declarations),
8274 c_write_global_declarations_1 (tree globals)
8279 /* Process the decls in the order they were written. */
8280 for (decl = globals; decl; decl = TREE_CHAIN (decl))
8282 /* Check for used but undefined static functions using the C
8283 standard's definition of "used", and set TREE_NO_WARNING so
8284 that check_global_declarations doesn't repeat the check. */
8285 if (TREE_CODE (decl) == FUNCTION_DECL
8286 && DECL_INITIAL (decl) == 0
8287 && DECL_EXTERNAL (decl)
8288 && !TREE_PUBLIC (decl)
8289 && C_DECL_USED (decl))
8291 pedwarn (input_location, 0, "%q+F used but never defined", decl);
8292 TREE_NO_WARNING (decl) = 1;
8295 wrapup_global_declaration_1 (decl);
8301 for (decl = globals; decl; decl = TREE_CHAIN (decl))
8302 reconsider |= wrapup_global_declaration_2 (decl);
8306 for (decl = globals; decl; decl = TREE_CHAIN (decl))
8307 check_global_declaration_1 (decl);
8310 /* A subroutine of c_write_global_declarations Emit debug information for each
8311 of the declarations in GLOBALS. */
8314 c_write_global_declarations_2 (tree globals)
8318 for (decl = globals; decl ; decl = TREE_CHAIN (decl))
8319 debug_hooks->global_decl (decl);
8322 /* Preserve the external declarations scope across a garbage collect. */
8323 static GTY(()) tree ext_block;
8326 c_write_global_declarations (void)
8330 /* We don't want to do this if generating a PCH. */
8334 /* Don't waste time on further processing if -fsyntax-only or we've
8335 encountered errors. */
8336 if (flag_syntax_only || errorcount || sorrycount)
8339 /* Close the external scope. */
8340 ext_block = pop_scope ();
8342 gcc_assert (!current_scope);
8346 tree tmp = BLOCK_VARS (ext_block);
8348 FILE * stream = dump_begin (TDI_tu, &flags);
8351 dump_node (tmp, flags & ~TDF_SLIM, stream);
8352 dump_end (TDI_tu, stream);
8356 /* Process all file scopes in this compilation, and the external_scope,
8357 through wrapup_global_declarations and check_global_declarations. */
8358 for (t = all_translation_units; t; t = TREE_CHAIN (t))
8359 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
8360 c_write_global_declarations_1 (BLOCK_VARS (ext_block));
8362 /* We're done parsing; proceed to optimize and emit assembly.
8363 FIXME: shouldn't be the front end's responsibility to call this. */
8366 /* After cgraph has had a chance to emit everything that's going to
8367 be emitted, output debug information for globals. */
8368 if (errorcount == 0 && sorrycount == 0)
8370 timevar_push (TV_SYMOUT);
8371 for (t = all_translation_units; t; t = TREE_CHAIN (t))
8372 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
8373 c_write_global_declarations_2 (BLOCK_VARS (ext_block));
8374 timevar_pop (TV_SYMOUT);
8380 #include "gt-c-decl.h"