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 /* True if we are currently parsing the fields of a struct or
132 static bool in_struct
;
134 /* A list of types defined in the current struct or union. */
136 static VEC(tree
,heap
) *struct_types
;
138 /* Linked list of TRANSLATION_UNIT_DECLS for the translation units
139 included in this invocation. Note that the current translation
140 unit is not included in this list. */
142 static GTY(()) tree all_translation_units
;
144 /* A list of decls to be made automatically visible in each file scope. */
145 static GTY(()) tree visible_builtins
;
147 /* Set to 0 at beginning of a function definition, set to 1 if
148 a return statement that specifies a return value is seen. */
150 int current_function_returns_value
;
152 /* Set to 0 at beginning of a function definition, set to 1 if
153 a return statement with no argument is seen. */
155 int current_function_returns_null
;
157 /* Set to 0 at beginning of a function definition, set to 1 if
158 a call to a noreturn function is seen. */
160 int current_function_returns_abnormally
;
162 /* Set to nonzero by `grokdeclarator' for a function
163 whose return type is defaulted, if warnings for this are desired. */
165 static int warn_about_return_type
;
167 /* Nonzero when the current toplevel function contains a declaration
168 of a nested function which is never defined. */
170 static bool undef_nested_function
;
172 /* True means global_bindings_p should return false even if the scope stack
173 says we are in file scope. */
174 bool c_override_global_bindings_to_false
;
177 /* Each c_binding structure describes one binding of an identifier to
178 a decl. All the decls in a scope - irrespective of namespace - are
179 chained together by the ->prev field, which (as the name implies)
180 runs in reverse order. All the decls in a given namespace bound to
181 a given identifier are chained by the ->shadowed field, which runs
182 from inner to outer scopes.
184 The ->decl field usually points to a DECL node, but there are two
185 exceptions. In the namespace of type tags, the bound entity is a
186 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
187 identifier is encountered, it is bound to error_mark_node to
188 suppress further errors about that identifier in the current
191 The ->type field stores the type of the declaration in this scope;
192 if NULL, the type is the type of the ->decl field. This is only of
193 relevance for objects with external or internal linkage which may
194 be redeclared in inner scopes, forming composite types that only
195 persist for the duration of those scopes. In the external scope,
196 this stores the composite of all the types declared for this
197 object, visible or not. The ->inner_comp field (used only at file
198 scope) stores whether an incomplete array type at file scope was
199 completed at an inner scope to an array size other than 1.
201 The depth field is copied from the scope structure that holds this
202 decl. It is used to preserve the proper ordering of the ->shadowed
203 field (see bind()) and also for a handful of special-case checks.
204 Finally, the invisible bit is true for a decl which should be
205 ignored for purposes of normal name lookup, and the nested bit is
206 true for a decl that's been bound a second time in an inner scope;
207 in all such cases, the binding in the outer scope will have its
208 invisible bit true. */
210 struct GTY((chain_next ("%h.prev"))) c_binding
{
211 tree decl
; /* the decl bound */
212 tree type
; /* the type in this scope */
213 tree id
; /* the identifier it's bound to */
214 struct c_binding
*prev
; /* the previous decl in this scope */
215 struct c_binding
*shadowed
; /* the innermost decl shadowed by this one */
216 unsigned int depth
: 28; /* depth of this scope */
217 BOOL_BITFIELD invisible
: 1; /* normal lookup should ignore this binding */
218 BOOL_BITFIELD nested
: 1; /* do not set DECL_CONTEXT when popping */
219 BOOL_BITFIELD inner_comp
: 1; /* incomplete array completed in inner scope */
221 location_t locus
; /* location for nested bindings */
223 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
224 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
225 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
226 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
228 #define I_SYMBOL_BINDING(node) \
229 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding)
230 #define I_SYMBOL_DECL(node) \
231 (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
233 #define I_TAG_BINDING(node) \
234 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->tag_binding)
235 #define I_TAG_DECL(node) \
236 (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
238 #define I_LABEL_BINDING(node) \
239 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->label_binding)
240 #define I_LABEL_DECL(node) \
241 (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
243 /* Each C symbol points to three linked lists of c_binding structures.
244 These describe the values of the identifier in the three different
245 namespaces defined by the language. */
247 struct GTY(()) lang_identifier
{
248 struct c_common_identifier common_id
;
249 struct c_binding
*symbol_binding
; /* vars, funcs, constants, typedefs */
250 struct c_binding
*tag_binding
; /* struct/union/enum tags */
251 struct c_binding
*label_binding
; /* labels */
254 /* Validate c-lang.c's assumptions. */
255 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
256 [(sizeof(struct lang_identifier
) == C_SIZEOF_STRUCT_LANG_IDENTIFIER
) ? 1 : -1];
258 /* The resulting tree type. */
260 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
261 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
263 union tree_node
GTY ((tag ("0"),
264 desc ("tree_node_structure (&%h)")))
266 struct lang_identifier
GTY ((tag ("1"))) identifier
;
269 /* Each c_scope structure describes the complete contents of one
270 scope. Four scopes are distinguished specially: the innermost or
271 current scope, the innermost function scope, the file scope (always
272 the second to outermost) and the outermost or external scope.
274 Most declarations are recorded in the current scope.
276 All normal label declarations are recorded in the innermost
277 function scope, as are bindings of undeclared identifiers to
278 error_mark_node. (GCC permits nested functions as an extension,
279 hence the 'innermost' qualifier.) Explicitly declared labels
280 (using the __label__ extension) appear in the current scope.
282 Being in the file scope (current_scope == file_scope) causes
283 special behavior in several places below. Also, under some
284 conditions the Objective-C front end records declarations in the
285 file scope even though that isn't the current scope.
287 All declarations with external linkage are recorded in the external
288 scope, even if they aren't visible there; this models the fact that
289 such declarations are visible to the entire program, and (with a
290 bit of cleverness, see pushdecl) allows diagnosis of some violations
291 of C99 6.2.2p7 and 6.2.7p2:
293 If, within the same translation unit, the same identifier appears
294 with both internal and external linkage, the behavior is
297 All declarations that refer to the same object or function shall
298 have compatible type; otherwise, the behavior is undefined.
300 Initially only the built-in declarations, which describe compiler
301 intrinsic functions plus a subset of the standard library, are in
304 The order of the blocks list matters, and it is frequently appended
305 to. To avoid having to walk all the way to the end of the list on
306 each insertion, or reverse the list later, we maintain a pointer to
307 the last list entry. (FIXME: It should be feasible to use a reversed
310 The bindings list is strictly in reverse order of declarations;
311 pop_scope relies on this. */
314 struct GTY((chain_next ("%h.outer"))) c_scope
{
315 /* The scope containing this one. */
316 struct c_scope
*outer
;
318 /* The next outermost function scope. */
319 struct c_scope
*outer_function
;
321 /* All bindings in this scope. */
322 struct c_binding
*bindings
;
324 /* For each scope (except the global one), a chain of BLOCK nodes
325 for all the scopes that were entered and exited one level down. */
329 /* The depth of this scope. Used to keep the ->shadowed chain of
330 bindings sorted innermost to outermost. */
331 unsigned int depth
: 28;
333 /* True if we are currently filling this scope with parameter
335 BOOL_BITFIELD parm_flag
: 1;
337 /* True if we saw [*] in this scope. Used to give an error messages
338 if these appears in a function definition. */
339 BOOL_BITFIELD had_vla_unspec
: 1;
341 /* True if we already complained about forward parameter decls
342 in this scope. This prevents double warnings on
343 foo (int a; int b; ...) */
344 BOOL_BITFIELD warned_forward_parm_decls
: 1;
346 /* True if this is the outermost block scope of a function body.
347 This scope contains the parameters, the local variables declared
348 in the outermost block, and all the labels (except those in
349 nested functions, or declared at block scope with __label__). */
350 BOOL_BITFIELD function_body
: 1;
352 /* True means make a BLOCK for this scope no matter what. */
353 BOOL_BITFIELD keep
: 1;
355 /* True means that an unsuffixed float constant is _Decimal64. */
356 BOOL_BITFIELD float_const_decimal64
: 1;
359 /* The scope currently in effect. */
361 static GTY(()) struct c_scope
*current_scope
;
363 /* The innermost function scope. Ordinary (not explicitly declared)
364 labels, bindings to error_mark_node, and the lazily-created
365 bindings of __func__ and its friends get this scope. */
367 static GTY(()) struct c_scope
*current_function_scope
;
369 /* The C file scope. This is reset for each input translation unit. */
371 static GTY(()) struct c_scope
*file_scope
;
373 /* The outermost scope. This is used for all declarations with
374 external linkage, and only these, hence the name. */
376 static GTY(()) struct c_scope
*external_scope
;
378 /* A chain of c_scope structures awaiting reuse. */
380 static GTY((deletable
)) struct c_scope
*scope_freelist
;
382 /* A chain of c_binding structures awaiting reuse. */
384 static GTY((deletable
)) struct c_binding
*binding_freelist
;
386 /* Append VAR to LIST in scope SCOPE. */
387 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
388 struct c_scope *s_ = (scope); \
390 if (s_->list##_last) \
391 BLOCK_CHAIN (s_->list##_last) = d_; \
394 s_->list##_last = d_; \
397 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
398 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
399 struct c_scope *t_ = (tscope); \
400 struct c_scope *f_ = (fscope); \
402 BLOCK_CHAIN (t_->to##_last) = f_->from; \
405 t_->to##_last = f_->from##_last; \
408 /* A c_inline_static structure stores details of a static identifier
409 referenced in a definition of a function that may be an inline
410 definition if no subsequent declaration of that function uses
411 "extern" or does not use "inline". */
413 struct GTY((chain_next ("%h.next"))) c_inline_static
{
414 /* The location for a diagnostic. */
417 /* The function that may be an inline definition. */
420 /* The object or function referenced. */
423 /* What sort of reference this is. */
424 enum c_inline_static_type type
;
426 /* The next such structure or NULL. */
427 struct c_inline_static
*next
;
430 /* List of static identifiers used or referenced in functions that may
431 be inline definitions. */
432 static GTY(()) struct c_inline_static
*c_inline_statics
;
434 /* True means unconditionally make a BLOCK for the next scope pushed. */
436 static bool keep_next_level_flag
;
438 /* True means the next call to push_scope will be the outermost scope
439 of a function body, so do not push a new scope, merely cease
440 expecting parameter decls. */
442 static bool next_is_function_body
;
444 /* Forward declarations. */
445 static tree
lookup_name_in_scope (tree
, struct c_scope
*);
446 static tree
c_make_fname_decl (tree
, int);
447 static tree
grokdeclarator (const struct c_declarator
*,
448 struct c_declspecs
*,
449 enum decl_context
, bool, tree
*, tree
*, tree
*,
450 bool *, enum deprecated_states
);
451 static tree
grokparms (struct c_arg_info
*, bool);
452 static void layout_array_type (tree
);
454 /* T is a statement. Add it to the statement-tree. This is the
455 C/ObjC version--C++ has a slightly different version of this
461 enum tree_code code
= TREE_CODE (t
);
463 if (CAN_HAVE_LOCATION_P (t
) && code
!= LABEL_EXPR
)
465 if (!EXPR_HAS_LOCATION (t
))
466 SET_EXPR_LOCATION (t
, input_location
);
469 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
470 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
472 /* Add T to the statement-tree. Non-side-effect statements need to be
473 recorded during statement expressions. */
474 append_to_statement_list_force (t
, &cur_stmt_list
);
481 c_print_identifier (FILE *file
, tree node
, int indent
)
483 print_node (file
, "symbol", I_SYMBOL_DECL (node
), indent
+ 4);
484 print_node (file
, "tag", I_TAG_DECL (node
), indent
+ 4);
485 print_node (file
, "label", I_LABEL_DECL (node
), indent
+ 4);
486 if (C_IS_RESERVED_WORD (node
) && C_RID_CODE (node
) != RID_CXX_COMPAT_WARN
)
488 tree rid
= ridpointers
[C_RID_CODE (node
)];
489 indent_to (file
, indent
+ 4);
490 fprintf (file
, "rid %p \"%s\"",
491 (void *) rid
, IDENTIFIER_POINTER (rid
));
495 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
496 which may be any of several kinds of DECL or TYPE or error_mark_node,
497 in the scope SCOPE. */
499 bind (tree name
, tree decl
, struct c_scope
*scope
, bool invisible
,
500 bool nested
, location_t locus
)
502 struct c_binding
*b
, **here
;
504 if (binding_freelist
)
506 b
= binding_freelist
;
507 binding_freelist
= b
->prev
;
510 b
= GGC_NEW (struct c_binding
);
515 b
->depth
= scope
->depth
;
516 b
->invisible
= invisible
;
523 b
->prev
= scope
->bindings
;
529 switch (TREE_CODE (decl
))
531 case LABEL_DECL
: here
= &I_LABEL_BINDING (name
); break;
534 case RECORD_TYPE
: here
= &I_TAG_BINDING (name
); break;
540 case ERROR_MARK
: here
= &I_SYMBOL_BINDING (name
); break;
546 /* Locate the appropriate place in the chain of shadowed decls
547 to insert this binding. Normally, scope == current_scope and
548 this does nothing. */
549 while (*here
&& (*here
)->depth
> scope
->depth
)
550 here
= &(*here
)->shadowed
;
556 /* Clear the binding structure B, stick it on the binding_freelist,
557 and return the former value of b->prev. This is used by pop_scope
558 and get_parm_info to iterate destructively over all the bindings
559 from a given scope. */
560 static struct c_binding
*
561 free_binding_and_advance (struct c_binding
*b
)
563 struct c_binding
*prev
= b
->prev
;
565 memset (b
, 0, sizeof (struct c_binding
));
566 b
->prev
= binding_freelist
;
567 binding_freelist
= b
;
573 /* Hook called at end of compilation to assume 1 elt
574 for a file-scope tentative array defn that wasn't complete before. */
577 c_finish_incomplete_decl (tree decl
)
579 if (TREE_CODE (decl
) == VAR_DECL
)
581 tree type
= TREE_TYPE (decl
);
582 if (type
!= error_mark_node
583 && TREE_CODE (type
) == ARRAY_TYPE
584 && !DECL_EXTERNAL (decl
)
585 && TYPE_DOMAIN (type
) == 0)
587 warning (0, "array %q+D assumed to have one element", decl
);
589 complete_array_type (&TREE_TYPE (decl
), NULL_TREE
, true);
591 layout_decl (decl
, 0);
596 /* Record that inline function FUNC contains a reference (location
597 LOC) to static DECL (file-scope or function-local according to
601 record_inline_static (location_t loc
, tree func
, tree decl
,
602 enum c_inline_static_type type
)
604 struct c_inline_static
*csi
= GGC_NEW (struct c_inline_static
);
606 csi
->function
= func
;
607 csi
->static_decl
= decl
;
609 csi
->next
= c_inline_statics
;
610 c_inline_statics
= csi
;
613 /* Check for references to static declarations in inline functions at
614 the end of the translation unit and diagnose them if the functions
615 are still inline definitions. */
618 check_inline_statics (void)
620 struct c_inline_static
*csi
;
621 for (csi
= c_inline_statics
; csi
; csi
= csi
->next
)
623 if (DECL_EXTERNAL (csi
->function
))
627 pedwarn (csi
->location
, 0,
628 "%qD is static but used in inline function %qD "
629 "which is not static", csi
->static_decl
, csi
->function
);
632 pedwarn (csi
->location
, 0,
633 "%q+D is static but declared in inline function %qD "
634 "which is not static", csi
->static_decl
, csi
->function
);
640 c_inline_statics
= NULL
;
643 /* The Objective-C front-end often needs to determine the current scope. */
646 objc_get_current_scope (void)
648 return current_scope
;
651 /* The following function is used only by Objective-C. It needs to live here
652 because it accesses the innards of c_scope. */
655 objc_mark_locals_volatile (void *enclosing_blk
)
657 struct c_scope
*scope
;
660 for (scope
= current_scope
;
661 scope
&& scope
!= enclosing_blk
;
662 scope
= scope
->outer
)
664 for (b
= scope
->bindings
; b
; b
= b
->prev
)
665 objc_volatilize_decl (b
->decl
);
667 /* Do not climb up past the current function. */
668 if (scope
->function_body
)
673 /* Nonzero if we are currently in file scope. */
676 global_bindings_p (void)
678 return (current_scope
== file_scope
&& !c_override_global_bindings_to_false
684 keep_next_level (void)
686 keep_next_level_flag
= true;
689 /* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON. */
692 set_float_const_decimal64 (void)
694 current_scope
->float_const_decimal64
= true;
697 /* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma. */
700 clear_float_const_decimal64 (void)
702 current_scope
->float_const_decimal64
= false;
705 /* Return nonzero if an unsuffixed float constant is _Decimal64. */
708 float_const_decimal64_p (void)
710 return current_scope
->float_const_decimal64
;
713 /* Identify this scope as currently being filled with parameters. */
716 declare_parm_level (void)
718 current_scope
->parm_flag
= true;
724 if (next_is_function_body
)
726 /* This is the transition from the parameters to the top level
727 of the function body. These are the same scope
728 (C99 6.2.1p4,6) so we do not push another scope structure.
729 next_is_function_body is set only by store_parm_decls, which
730 in turn is called when and only when we are about to
731 encounter the opening curly brace for the function body.
733 The outermost block of a function always gets a BLOCK node,
734 because the debugging output routines expect that each
735 function has at least one BLOCK. */
736 current_scope
->parm_flag
= false;
737 current_scope
->function_body
= true;
738 current_scope
->keep
= true;
739 current_scope
->outer_function
= current_function_scope
;
740 current_function_scope
= current_scope
;
742 keep_next_level_flag
= false;
743 next_is_function_body
= false;
745 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */
746 if (current_scope
->outer
)
747 current_scope
->float_const_decimal64
748 = current_scope
->outer
->float_const_decimal64
;
750 current_scope
->float_const_decimal64
= false;
754 struct c_scope
*scope
;
757 scope
= scope_freelist
;
758 scope_freelist
= scope
->outer
;
761 scope
= GGC_CNEW (struct c_scope
);
763 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */
765 scope
->float_const_decimal64
= current_scope
->float_const_decimal64
;
767 scope
->float_const_decimal64
= false;
769 scope
->keep
= keep_next_level_flag
;
770 scope
->outer
= current_scope
;
771 scope
->depth
= current_scope
? (current_scope
->depth
+ 1) : 0;
773 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but
775 if (current_scope
&& scope
->depth
== 0)
778 sorry ("GCC supports only %u nested scopes", scope
->depth
);
781 current_scope
= scope
;
782 keep_next_level_flag
= false;
786 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */
789 set_type_context (tree type
, tree context
)
791 for (type
= TYPE_MAIN_VARIANT (type
); type
;
792 type
= TYPE_NEXT_VARIANT (type
))
793 TYPE_CONTEXT (type
) = context
;
796 /* Exit a scope. Restore the state of the identifier-decl mappings
797 that were in effect when this scope was entered. Return a BLOCK
798 node containing all the DECLs in this scope that are of interest
799 to debug info generation. */
804 struct c_scope
*scope
= current_scope
;
805 tree block
, context
, p
;
808 bool functionbody
= scope
->function_body
;
809 bool keep
= functionbody
|| scope
->keep
|| scope
->bindings
;
811 c_end_vm_scope (scope
->depth
);
813 /* If appropriate, create a BLOCK to record the decls for the life
818 block
= make_node (BLOCK
);
819 BLOCK_SUBBLOCKS (block
) = scope
->blocks
;
820 TREE_USED (block
) = 1;
822 /* In each subblock, record that this is its superior. */
823 for (p
= scope
->blocks
; p
; p
= BLOCK_CHAIN (p
))
824 BLOCK_SUPERCONTEXT (p
) = block
;
826 BLOCK_VARS (block
) = 0;
829 /* The TYPE_CONTEXTs for all of the tagged types belonging to this
830 scope must be set so that they point to the appropriate
831 construct, i.e. either to the current FUNCTION_DECL node, or
832 else to the BLOCK node we just constructed.
834 Note that for tagged types whose scope is just the formal
835 parameter list for some function type specification, we can't
836 properly set their TYPE_CONTEXTs here, because we don't have a
837 pointer to the appropriate FUNCTION_TYPE node readily available
838 to us. For those cases, the TYPE_CONTEXTs of the relevant tagged
839 type nodes get set in `grokdeclarator' as soon as we have created
840 the FUNCTION_TYPE node which will represent the "scope" for these
841 "parameter list local" tagged types. */
842 if (scope
->function_body
)
843 context
= current_function_decl
;
844 else if (scope
== file_scope
)
846 tree file_decl
= build_decl (TRANSLATION_UNIT_DECL
, 0, 0);
847 TREE_CHAIN (file_decl
) = all_translation_units
;
848 all_translation_units
= file_decl
;
854 /* Clear all bindings in this scope. */
855 for (b
= scope
->bindings
; b
; b
= free_binding_and_advance (b
))
858 switch (TREE_CODE (p
))
861 /* Warnings for unused labels, errors for undefined labels. */
862 if (TREE_USED (p
) && !DECL_INITIAL (p
))
864 error ("label %q+D used but not defined", p
);
865 DECL_INITIAL (p
) = error_mark_node
;
868 warn_for_unused_label (p
);
870 /* Labels go in BLOCK_VARS. */
871 TREE_CHAIN (p
) = BLOCK_VARS (block
);
872 BLOCK_VARS (block
) = p
;
873 gcc_assert (I_LABEL_BINDING (b
->id
) == b
);
874 I_LABEL_BINDING (b
->id
) = b
->shadowed
;
880 set_type_context (p
, context
);
882 /* Types may not have tag-names, in which case the type
883 appears in the bindings list with b->id NULL. */
886 gcc_assert (I_TAG_BINDING (b
->id
) == b
);
887 I_TAG_BINDING (b
->id
) = b
->shadowed
;
892 /* Propagate TREE_ADDRESSABLE from nested functions to their
893 containing functions. */
894 if (!TREE_ASM_WRITTEN (p
)
895 && DECL_INITIAL (p
) != 0
896 && TREE_ADDRESSABLE (p
)
897 && DECL_ABSTRACT_ORIGIN (p
) != 0
898 && DECL_ABSTRACT_ORIGIN (p
) != p
)
899 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p
)) = 1;
900 if (!DECL_EXTERNAL (p
)
902 && scope
!= file_scope
903 && scope
!= external_scope
)
905 error ("nested function %q+D declared but never defined", p
);
906 undef_nested_function
= true;
908 else if (DECL_DECLARED_INLINE_P (p
)
910 && !DECL_INITIAL (p
))
912 /* C99 6.7.4p6: "a function with external linkage... declared
913 with an inline function specifier ... shall also be defined
914 in the same translation unit." */
915 if (!flag_gnu89_inline
)
916 pedwarn (input_location
, 0,
917 "inline function %q+D declared but never defined", p
);
918 DECL_EXTERNAL (p
) = 1;
924 /* Warnings for unused variables. */
926 && !TREE_NO_WARNING (p
)
927 && !DECL_IN_SYSTEM_HEADER (p
)
929 && !DECL_ARTIFICIAL (p
)
930 && scope
!= file_scope
931 && scope
!= external_scope
)
932 warning (OPT_Wunused_variable
, "unused variable %q+D", p
);
936 error ("type of array %q+D completed incompatibly with"
937 " implicit initialization", p
);
944 /* All of these go in BLOCK_VARS, but only if this is the
945 binding in the home scope. */
948 TREE_CHAIN (p
) = BLOCK_VARS (block
);
949 BLOCK_VARS (block
) = p
;
951 else if (VAR_OR_FUNCTION_DECL_P (p
))
953 /* For block local externs add a special
954 DECL_EXTERNAL decl for debug info generation. */
955 tree extp
= copy_node (p
);
957 DECL_EXTERNAL (extp
) = 1;
958 TREE_STATIC (extp
) = 0;
959 TREE_PUBLIC (extp
) = 1;
960 DECL_INITIAL (extp
) = NULL_TREE
;
961 DECL_LANG_SPECIFIC (extp
) = NULL
;
962 DECL_CONTEXT (extp
) = current_function_decl
;
963 if (TREE_CODE (p
) == FUNCTION_DECL
)
965 DECL_RESULT (extp
) = NULL_TREE
;
966 DECL_SAVED_TREE (extp
) = NULL_TREE
;
967 DECL_STRUCT_FUNCTION (extp
) = NULL
;
969 if (b
->locus
!= UNKNOWN_LOCATION
)
970 DECL_SOURCE_LOCATION (extp
) = b
->locus
;
971 TREE_CHAIN (extp
) = BLOCK_VARS (block
);
972 BLOCK_VARS (block
) = extp
;
974 /* If this is the file scope, and we are processing more
975 than one translation unit in this compilation, set
976 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
977 This makes same_translation_unit_p work, and causes
978 static declarations to be given disambiguating suffixes. */
979 if (scope
== file_scope
&& num_in_fnames
> 1)
981 DECL_CONTEXT (p
) = context
;
982 if (TREE_CODE (p
) == TYPE_DECL
)
983 set_type_context (TREE_TYPE (p
), context
);
987 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
988 already been put there by store_parm_decls. Unused-
989 parameter warnings are handled by function.c.
990 error_mark_node obviously does not go in BLOCK_VARS and
991 does not get unused-variable warnings. */
994 /* It is possible for a decl not to have a name. We get
995 here with b->id NULL in this case. */
998 gcc_assert (I_SYMBOL_BINDING (b
->id
) == b
);
999 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
1000 if (b
->shadowed
&& b
->shadowed
->type
)
1001 TREE_TYPE (b
->shadowed
->decl
) = b
->shadowed
->type
;
1011 /* Dispose of the block that we just made inside some higher level. */
1012 if ((scope
->function_body
|| scope
== file_scope
) && context
)
1014 DECL_INITIAL (context
) = block
;
1015 BLOCK_SUPERCONTEXT (block
) = context
;
1017 else if (scope
->outer
)
1020 SCOPE_LIST_APPEND (scope
->outer
, blocks
, block
);
1021 /* If we did not make a block for the scope just exited, any
1022 blocks made for inner scopes must be carried forward so they
1023 will later become subblocks of something else. */
1024 else if (scope
->blocks
)
1025 SCOPE_LIST_CONCAT (scope
->outer
, blocks
, scope
, blocks
);
1028 /* Pop the current scope, and free the structure for reuse. */
1029 current_scope
= scope
->outer
;
1030 if (scope
->function_body
)
1031 current_function_scope
= scope
->outer_function
;
1033 memset (scope
, 0, sizeof (struct c_scope
));
1034 scope
->outer
= scope_freelist
;
1035 scope_freelist
= scope
;
1041 push_file_scope (void)
1049 file_scope
= current_scope
;
1051 start_fname_decls ();
1053 for (decl
= visible_builtins
; decl
; decl
= TREE_CHAIN (decl
))
1054 bind (DECL_NAME (decl
), decl
, file_scope
,
1055 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl
));
1059 pop_file_scope (void)
1061 /* In case there were missing closebraces, get us back to the global
1063 while (current_scope
!= file_scope
)
1066 /* __FUNCTION__ is defined at file scope (""). This
1067 call may not be necessary as my tests indicate it
1068 still works without it. */
1069 finish_fname_decls ();
1071 check_inline_statics ();
1073 /* This is the point to write out a PCH if we're doing that.
1074 In that case we do not want to do anything else. */
1077 c_common_write_pch ();
1081 /* Pop off the file scope and close this translation unit. */
1085 maybe_apply_pending_pragma_weaks ();
1086 cgraph_finalize_compilation_unit ();
1090 /* Push a definition or a declaration of struct, union or enum tag "name".
1091 "type" should be the type node.
1092 We assume that the tag "name" is not already defined.
1094 Note that the definition may really be just a forward reference.
1095 In that case, the TYPE_SIZE will be zero. */
1098 pushtag (tree name
, tree type
, location_t loc
)
1100 /* Record the identifier as the type's name if it has none. */
1101 if (name
&& !TYPE_NAME (type
))
1102 TYPE_NAME (type
) = name
;
1103 bind (name
, type
, current_scope
, /*invisible=*/false, /*nested=*/false, loc
);
1105 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1106 tagged type we just added to the current scope. This fake
1107 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1108 to output a representation of a tagged type, and it also gives
1109 us a convenient place to record the "scope start" address for the
1112 TYPE_STUB_DECL (type
) = pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, type
));
1114 /* An approximation for now, so we can tell this is a function-scope tag.
1115 This will be updated in pop_scope. */
1116 TYPE_CONTEXT (type
) = DECL_CONTEXT (TYPE_STUB_DECL (type
));
1119 /* Subroutine of compare_decls. Allow harmless mismatches in return
1120 and argument types provided that the type modes match. This function
1121 return a unified type given a suitable match, and 0 otherwise. */
1124 match_builtin_function_types (tree newtype
, tree oldtype
)
1126 tree newrettype
, oldrettype
;
1127 tree newargs
, oldargs
;
1128 tree trytype
, tryargs
;
1130 /* Accept the return type of the new declaration if same modes. */
1131 oldrettype
= TREE_TYPE (oldtype
);
1132 newrettype
= TREE_TYPE (newtype
);
1134 if (TYPE_MODE (oldrettype
) != TYPE_MODE (newrettype
))
1137 oldargs
= TYPE_ARG_TYPES (oldtype
);
1138 newargs
= TYPE_ARG_TYPES (newtype
);
1141 while (oldargs
|| newargs
)
1145 || !TREE_VALUE (oldargs
)
1146 || !TREE_VALUE (newargs
)
1147 || TYPE_MODE (TREE_VALUE (oldargs
))
1148 != TYPE_MODE (TREE_VALUE (newargs
)))
1151 oldargs
= TREE_CHAIN (oldargs
);
1152 newargs
= TREE_CHAIN (newargs
);
1155 trytype
= build_function_type (newrettype
, tryargs
);
1156 return build_type_attribute_variant (trytype
, TYPE_ATTRIBUTES (oldtype
));
1159 /* Subroutine of diagnose_mismatched_decls. Check for function type
1160 mismatch involving an empty arglist vs a nonempty one and give clearer
1163 diagnose_arglist_conflict (tree newdecl
, tree olddecl
,
1164 tree newtype
, tree oldtype
)
1168 if (TREE_CODE (olddecl
) != FUNCTION_DECL
1169 || !comptypes (TREE_TYPE (oldtype
), TREE_TYPE (newtype
))
1170 || !((TYPE_ARG_TYPES (oldtype
) == 0 && DECL_INITIAL (olddecl
) == 0)
1172 (TYPE_ARG_TYPES (newtype
) == 0 && DECL_INITIAL (newdecl
) == 0)))
1175 t
= TYPE_ARG_TYPES (oldtype
);
1177 t
= TYPE_ARG_TYPES (newtype
);
1178 for (; t
; t
= TREE_CHAIN (t
))
1180 tree type
= TREE_VALUE (t
);
1182 if (TREE_CHAIN (t
) == 0
1183 && TYPE_MAIN_VARIANT (type
) != void_type_node
)
1185 inform (input_location
, "a parameter list with an ellipsis can%'t match "
1186 "an empty parameter name list declaration");
1190 if (c_type_promotes_to (type
) != type
)
1192 inform (input_location
, "an argument type that has a default promotion can%'t match "
1193 "an empty parameter name list declaration");
1199 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
1200 old-style function definition, NEWDECL is a prototype declaration.
1201 Diagnose inconsistencies in the argument list. Returns TRUE if
1202 the prototype is compatible, FALSE if not. */
1204 validate_proto_after_old_defn (tree newdecl
, tree newtype
, tree oldtype
)
1206 tree newargs
, oldargs
;
1209 #define END_OF_ARGLIST(t) ((t) == void_type_node)
1211 oldargs
= TYPE_ACTUAL_ARG_TYPES (oldtype
);
1212 newargs
= TYPE_ARG_TYPES (newtype
);
1217 tree oldargtype
= TREE_VALUE (oldargs
);
1218 tree newargtype
= TREE_VALUE (newargs
);
1220 if (oldargtype
== error_mark_node
|| newargtype
== error_mark_node
)
1223 oldargtype
= TYPE_MAIN_VARIANT (oldargtype
);
1224 newargtype
= TYPE_MAIN_VARIANT (newargtype
);
1226 if (END_OF_ARGLIST (oldargtype
) && END_OF_ARGLIST (newargtype
))
1229 /* Reaching the end of just one list means the two decls don't
1230 agree on the number of arguments. */
1231 if (END_OF_ARGLIST (oldargtype
))
1233 error ("prototype for %q+D declares more arguments "
1234 "than previous old-style definition", newdecl
);
1237 else if (END_OF_ARGLIST (newargtype
))
1239 error ("prototype for %q+D declares fewer arguments "
1240 "than previous old-style definition", newdecl
);
1244 /* Type for passing arg must be consistent with that declared
1246 else if (!comptypes (oldargtype
, newargtype
))
1248 error ("prototype for %q+D declares argument %d"
1249 " with incompatible type",
1254 oldargs
= TREE_CHAIN (oldargs
);
1255 newargs
= TREE_CHAIN (newargs
);
1259 /* If we get here, no errors were found, but do issue a warning
1260 for this poor-style construct. */
1261 warning (0, "prototype for %q+D follows non-prototype definition",
1264 #undef END_OF_ARGLIST
1267 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
1268 first in a pair of mismatched declarations, using the diagnostic
1271 locate_old_decl (tree decl
)
1273 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1275 else if (DECL_INITIAL (decl
))
1276 inform (input_location
, "previous definition of %q+D was here", decl
);
1277 else if (C_DECL_IMPLICIT (decl
))
1278 inform (input_location
, "previous implicit declaration of %q+D was here", decl
);
1280 inform (input_location
, "previous declaration of %q+D was here", decl
);
1283 /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL.
1284 Returns true if the caller should proceed to merge the two, false
1285 if OLDDECL should simply be discarded. As a side effect, issues
1286 all necessary diagnostics for invalid or poor-style combinations.
1287 If it returns true, writes the types of NEWDECL and OLDDECL to
1288 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1289 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
1292 diagnose_mismatched_decls (tree newdecl
, tree olddecl
,
1293 tree
*newtypep
, tree
*oldtypep
)
1295 tree newtype
, oldtype
;
1296 bool pedwarned
= false;
1297 bool warned
= false;
1300 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \
1301 && DECL_EXTERNAL (DECL))
1303 /* If we have error_mark_node for either decl or type, just discard
1304 the previous decl - we're in an error cascade already. */
1305 if (olddecl
== error_mark_node
|| newdecl
== error_mark_node
)
1307 *oldtypep
= oldtype
= TREE_TYPE (olddecl
);
1308 *newtypep
= newtype
= TREE_TYPE (newdecl
);
1309 if (oldtype
== error_mark_node
|| newtype
== error_mark_node
)
1312 /* Two different categories of symbol altogether. This is an error
1313 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
1314 if (TREE_CODE (olddecl
) != TREE_CODE (newdecl
))
1316 if (!(TREE_CODE (olddecl
) == FUNCTION_DECL
1317 && DECL_BUILT_IN (olddecl
)
1318 && !C_DECL_DECLARED_BUILTIN (olddecl
)))
1320 error ("%q+D redeclared as different kind of symbol", newdecl
);
1321 locate_old_decl (olddecl
);
1323 else if (TREE_PUBLIC (newdecl
))
1324 warning (0, "built-in function %q+D declared as non-function",
1327 warning (OPT_Wshadow
, "declaration of %q+D shadows "
1328 "a built-in function", newdecl
);
1332 /* Enumerators have no linkage, so may only be declared once in a
1334 if (TREE_CODE (olddecl
) == CONST_DECL
)
1336 error ("redeclaration of enumerator %q+D", newdecl
);
1337 locate_old_decl (olddecl
);
1341 if (!comptypes (oldtype
, newtype
))
1343 if (TREE_CODE (olddecl
) == FUNCTION_DECL
1344 && DECL_BUILT_IN (olddecl
) && !C_DECL_DECLARED_BUILTIN (olddecl
))
1346 /* Accept harmless mismatch in function types.
1347 This is for the ffs and fprintf builtins. */
1348 tree trytype
= match_builtin_function_types (newtype
, oldtype
);
1350 if (trytype
&& comptypes (newtype
, trytype
))
1351 *oldtypep
= oldtype
= trytype
;
1354 /* If types don't match for a built-in, throw away the
1355 built-in. No point in calling locate_old_decl here, it
1356 won't print anything. */
1357 warning (0, "conflicting types for built-in function %q+D",
1362 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
1363 && DECL_IS_BUILTIN (olddecl
))
1365 /* A conflicting function declaration for a predeclared
1366 function that isn't actually built in. Objective C uses
1367 these. The new declaration silently overrides everything
1368 but the volatility (i.e. noreturn) indication. See also
1369 below. FIXME: Make Objective C use normal builtins. */
1370 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1373 /* Permit void foo (...) to match int foo (...) if the latter is
1374 the definition and implicit int was used. See
1375 c-torture/compile/920625-2.c. */
1376 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
&& DECL_INITIAL (newdecl
)
1377 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype
)) == void_type_node
1378 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype
)) == integer_type_node
1379 && C_FUNCTION_IMPLICIT_INT (newdecl
) && !DECL_INITIAL (olddecl
))
1381 pedwarned
= pedwarn (input_location
, 0,
1382 "conflicting types for %q+D", newdecl
);
1383 /* Make sure we keep void as the return type. */
1384 TREE_TYPE (newdecl
) = *newtypep
= newtype
= oldtype
;
1385 C_FUNCTION_IMPLICIT_INT (newdecl
) = 0;
1387 /* Permit void foo (...) to match an earlier call to foo (...) with
1388 no declared type (thus, implicitly int). */
1389 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
1390 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype
)) == void_type_node
1391 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype
)) == integer_type_node
1392 && C_DECL_IMPLICIT (olddecl
) && !DECL_INITIAL (olddecl
))
1394 pedwarned
= pedwarn (input_location
, 0,
1395 "conflicting types for %q+D", newdecl
);
1396 /* Make sure we keep void as the return type. */
1397 TREE_TYPE (olddecl
) = *oldtypep
= oldtype
= newtype
;
1401 if (TYPE_QUALS (newtype
) != TYPE_QUALS (oldtype
))
1402 error ("conflicting type qualifiers for %q+D", newdecl
);
1404 error ("conflicting types for %q+D", newdecl
);
1405 diagnose_arglist_conflict (newdecl
, olddecl
, newtype
, oldtype
);
1406 locate_old_decl (olddecl
);
1411 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1412 but silently ignore the redeclaration if either is in a system
1413 header. (Conflicting redeclarations were handled above.) */
1414 if (TREE_CODE (newdecl
) == TYPE_DECL
)
1416 if (DECL_IN_SYSTEM_HEADER (newdecl
)
1417 || DECL_IN_SYSTEM_HEADER (olddecl
)
1418 || TREE_NO_WARNING (newdecl
)
1419 || TREE_NO_WARNING (olddecl
))
1420 return true; /* Allow OLDDECL to continue in use. */
1422 error ("redefinition of typedef %q+D", newdecl
);
1423 locate_old_decl (olddecl
);
1427 /* Function declarations can either be 'static' or 'extern' (no
1428 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1429 can never conflict with each other on account of linkage
1430 (6.2.2p4). Multiple definitions are not allowed (6.9p3,5) but
1431 gnu89 mode permits two definitions if one is 'extern inline' and
1432 one is not. The non- extern-inline definition supersedes the
1433 extern-inline definition. */
1435 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1437 /* If you declare a built-in function name as static, or
1438 define the built-in with an old-style definition (so we
1439 can't validate the argument list) the built-in definition is
1440 overridden, but optionally warn this was a bad choice of name. */
1441 if (DECL_BUILT_IN (olddecl
)
1442 && !C_DECL_DECLARED_BUILTIN (olddecl
)
1443 && (!TREE_PUBLIC (newdecl
)
1444 || (DECL_INITIAL (newdecl
)
1445 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl
)))))
1447 warning (OPT_Wshadow
, "declaration of %q+D shadows "
1448 "a built-in function", newdecl
);
1449 /* Discard the old built-in function. */
1453 if (DECL_INITIAL (newdecl
))
1455 if (DECL_INITIAL (olddecl
))
1457 /* If both decls are in the same TU and the new declaration
1458 isn't overriding an extern inline reject the new decl.
1459 In c99, no overriding is allowed in the same translation
1461 if ((!DECL_EXTERN_INLINE (olddecl
)
1462 || DECL_EXTERN_INLINE (newdecl
)
1463 || (!flag_gnu89_inline
1464 && (!DECL_DECLARED_INLINE_P (olddecl
)
1465 || !lookup_attribute ("gnu_inline",
1466 DECL_ATTRIBUTES (olddecl
)))
1467 && (!DECL_DECLARED_INLINE_P (newdecl
)
1468 || !lookup_attribute ("gnu_inline",
1469 DECL_ATTRIBUTES (newdecl
))))
1471 && same_translation_unit_p (newdecl
, olddecl
))
1473 error ("redefinition of %q+D", newdecl
);
1474 locate_old_decl (olddecl
);
1479 /* If we have a prototype after an old-style function definition,
1480 the argument types must be checked specially. */
1481 else if (DECL_INITIAL (olddecl
)
1482 && !TYPE_ARG_TYPES (oldtype
) && TYPE_ARG_TYPES (newtype
)
1483 && TYPE_ACTUAL_ARG_TYPES (oldtype
)
1484 && !validate_proto_after_old_defn (newdecl
, newtype
, oldtype
))
1486 locate_old_decl (olddecl
);
1489 /* A non-static declaration (even an "extern") followed by a
1490 static declaration is undefined behavior per C99 6.2.2p3-5,7.
1491 The same is true for a static forward declaration at block
1492 scope followed by a non-static declaration/definition at file
1493 scope. Static followed by non-static at the same scope is
1494 not undefined behavior, and is the most convenient way to get
1495 some effects (see e.g. what unwind-dw2-fde-glibc.c does to
1496 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
1497 we do diagnose it if -Wtraditional. */
1498 if (TREE_PUBLIC (olddecl
) && !TREE_PUBLIC (newdecl
))
1500 /* Two exceptions to the rule. If olddecl is an extern
1501 inline, or a predeclared function that isn't actually
1502 built in, newdecl silently overrides olddecl. The latter
1503 occur only in Objective C; see also above. (FIXME: Make
1504 Objective C use normal builtins.) */
1505 if (!DECL_IS_BUILTIN (olddecl
)
1506 && !DECL_EXTERN_INLINE (olddecl
))
1508 error ("static declaration of %q+D follows "
1509 "non-static declaration", newdecl
);
1510 locate_old_decl (olddecl
);
1514 else if (TREE_PUBLIC (newdecl
) && !TREE_PUBLIC (olddecl
))
1516 if (DECL_CONTEXT (olddecl
))
1518 error ("non-static declaration of %q+D follows "
1519 "static declaration", newdecl
);
1520 locate_old_decl (olddecl
);
1523 else if (warn_traditional
)
1525 warned
|= warning (OPT_Wtraditional
,
1526 "non-static declaration of %q+D "
1527 "follows static declaration", newdecl
);
1531 /* Make sure gnu_inline attribute is either not present, or
1532 present on all inline decls. */
1533 if (DECL_DECLARED_INLINE_P (olddecl
)
1534 && DECL_DECLARED_INLINE_P (newdecl
))
1536 bool newa
= lookup_attribute ("gnu_inline",
1537 DECL_ATTRIBUTES (newdecl
)) != NULL
;
1538 bool olda
= lookup_attribute ("gnu_inline",
1539 DECL_ATTRIBUTES (olddecl
)) != NULL
;
1542 error ("%<gnu_inline%> attribute present on %q+D",
1543 newa
? newdecl
: olddecl
);
1544 error ("%Jbut not here", newa
? olddecl
: newdecl
);
1548 else if (TREE_CODE (newdecl
) == VAR_DECL
)
1550 /* Only variables can be thread-local, and all declarations must
1551 agree on this property. */
1552 if (C_DECL_THREADPRIVATE_P (olddecl
) && !DECL_THREAD_LOCAL_P (newdecl
))
1554 /* Nothing to check. Since OLDDECL is marked threadprivate
1555 and NEWDECL does not have a thread-local attribute, we
1556 will merge the threadprivate attribute into NEWDECL. */
1559 else if (DECL_THREAD_LOCAL_P (newdecl
) != DECL_THREAD_LOCAL_P (olddecl
))
1561 if (DECL_THREAD_LOCAL_P (newdecl
))
1562 error ("thread-local declaration of %q+D follows "
1563 "non-thread-local declaration", newdecl
);
1565 error ("non-thread-local declaration of %q+D follows "
1566 "thread-local declaration", newdecl
);
1568 locate_old_decl (olddecl
);
1572 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1573 if (DECL_INITIAL (newdecl
) && DECL_INITIAL (olddecl
))
1575 error ("redefinition of %q+D", newdecl
);
1576 locate_old_decl (olddecl
);
1580 /* Objects declared at file scope: if the first declaration had
1581 external linkage (even if it was an external reference) the
1582 second must have external linkage as well, or the behavior is
1583 undefined. If the first declaration had internal linkage, then
1584 the second must too, or else be an external reference (in which
1585 case the composite declaration still has internal linkage).
1586 As for function declarations, we warn about the static-then-
1587 extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */
1588 if (DECL_FILE_SCOPE_P (newdecl
)
1589 && TREE_PUBLIC (newdecl
) != TREE_PUBLIC (olddecl
))
1591 if (DECL_EXTERNAL (newdecl
))
1593 if (!DECL_FILE_SCOPE_P (olddecl
))
1595 error ("extern declaration of %q+D follows "
1596 "declaration with no linkage", newdecl
);
1597 locate_old_decl (olddecl
);
1600 else if (warn_traditional
)
1602 warned
|= warning (OPT_Wtraditional
,
1603 "non-static declaration of %q+D "
1604 "follows static declaration", newdecl
);
1609 if (TREE_PUBLIC (newdecl
))
1610 error ("non-static declaration of %q+D follows "
1611 "static declaration", newdecl
);
1613 error ("static declaration of %q+D follows "
1614 "non-static declaration", newdecl
);
1616 locate_old_decl (olddecl
);
1620 /* Two objects with the same name declared at the same block
1621 scope must both be external references (6.7p3). */
1622 else if (!DECL_FILE_SCOPE_P (newdecl
))
1624 if (DECL_EXTERNAL (newdecl
))
1626 /* Extern with initializer at block scope, which will
1627 already have received an error. */
1629 else if (DECL_EXTERNAL (olddecl
))
1631 error ("declaration of %q+D with no linkage follows "
1632 "extern declaration", newdecl
);
1633 locate_old_decl (olddecl
);
1637 error ("redeclaration of %q+D with no linkage", newdecl
);
1638 locate_old_decl (olddecl
);
1646 /* All decls must agree on a visibility. */
1647 if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl
), TS_DECL_WITH_VIS
)
1648 && DECL_VISIBILITY_SPECIFIED (newdecl
) && DECL_VISIBILITY_SPECIFIED (olddecl
)
1649 && DECL_VISIBILITY (newdecl
) != DECL_VISIBILITY (olddecl
))
1651 warned
|= warning (0, "redeclaration of %q+D with different visibility "
1652 "(old visibility preserved)", newdecl
);
1655 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1657 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1658 if (DECL_DECLARED_INLINE_P (newdecl
)
1659 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
1661 warned
|= warning (OPT_Wattributes
,
1662 "inline declaration of %qD follows "
1663 "declaration with attribute noinline", newdecl
);
1665 else if (DECL_DECLARED_INLINE_P (olddecl
)
1666 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
)))
1668 warned
|= warning (OPT_Wattributes
,
1669 "declaration of %q+D with attribute "
1670 "noinline follows inline declaration ", newdecl
);
1673 else /* PARM_DECL, VAR_DECL */
1675 /* Redeclaration of a parameter is a constraint violation (this is
1676 not explicitly stated, but follows from C99 6.7p3 [no more than
1677 one declaration of the same identifier with no linkage in the
1678 same scope, except type tags] and 6.2.2p6 [parameters have no
1679 linkage]). We must check for a forward parameter declaration,
1680 indicated by TREE_ASM_WRITTEN on the old declaration - this is
1681 an extension, the mandatory diagnostic for which is handled by
1682 mark_forward_parm_decls. */
1684 if (TREE_CODE (newdecl
) == PARM_DECL
1685 && (!TREE_ASM_WRITTEN (olddecl
) || TREE_ASM_WRITTEN (newdecl
)))
1687 error ("redefinition of parameter %q+D", newdecl
);
1688 locate_old_decl (olddecl
);
1693 /* Optional warning for completely redundant decls. */
1694 if (!warned
&& !pedwarned
1695 && warn_redundant_decls
1696 /* Don't warn about a function declaration followed by a
1698 && !(TREE_CODE (newdecl
) == FUNCTION_DECL
1699 && DECL_INITIAL (newdecl
) && !DECL_INITIAL (olddecl
))
1700 /* Don't warn about redundant redeclarations of builtins. */
1701 && !(TREE_CODE (newdecl
) == FUNCTION_DECL
1702 && !DECL_BUILT_IN (newdecl
)
1703 && DECL_BUILT_IN (olddecl
)
1704 && !C_DECL_DECLARED_BUILTIN (olddecl
))
1705 /* Don't warn about an extern followed by a definition. */
1706 && !(DECL_EXTERNAL (olddecl
) && !DECL_EXTERNAL (newdecl
))
1707 /* Don't warn about forward parameter decls. */
1708 && !(TREE_CODE (newdecl
) == PARM_DECL
1709 && TREE_ASM_WRITTEN (olddecl
) && !TREE_ASM_WRITTEN (newdecl
))
1710 /* Don't warn about a variable definition following a declaration. */
1711 && !(TREE_CODE (newdecl
) == VAR_DECL
1712 && DECL_INITIAL (newdecl
) && !DECL_INITIAL (olddecl
)))
1714 warned
= warning (OPT_Wredundant_decls
, "redundant redeclaration of %q+D",
1718 /* Report location of previous decl/defn. */
1719 if (warned
|| pedwarned
)
1720 locate_old_decl (olddecl
);
1722 #undef DECL_EXTERN_INLINE
1727 /* Subroutine of duplicate_decls. NEWDECL has been found to be
1728 consistent with OLDDECL, but carries new information. Merge the
1729 new information into OLDDECL. This function issues no
1733 merge_decls (tree newdecl
, tree olddecl
, tree newtype
, tree oldtype
)
1735 bool new_is_definition
= (TREE_CODE (newdecl
) == FUNCTION_DECL
1736 && DECL_INITIAL (newdecl
) != 0);
1737 bool new_is_prototype
= (TREE_CODE (newdecl
) == FUNCTION_DECL
1738 && TYPE_ARG_TYPES (TREE_TYPE (newdecl
)) != 0);
1739 bool old_is_prototype
= (TREE_CODE (olddecl
) == FUNCTION_DECL
1740 && TYPE_ARG_TYPES (TREE_TYPE (olddecl
)) != 0);
1741 bool extern_changed
= false;
1743 /* For real parm decl following a forward decl, rechain the old decl
1744 in its new location and clear TREE_ASM_WRITTEN (it's not a
1745 forward decl anymore). */
1746 if (TREE_CODE (newdecl
) == PARM_DECL
1747 && TREE_ASM_WRITTEN (olddecl
) && !TREE_ASM_WRITTEN (newdecl
))
1749 struct c_binding
*b
, **here
;
1751 for (here
= ¤t_scope
->bindings
; *here
; here
= &(*here
)->prev
)
1752 if ((*here
)->decl
== olddecl
)
1759 b
->prev
= current_scope
->bindings
;
1760 current_scope
->bindings
= b
;
1762 TREE_ASM_WRITTEN (olddecl
) = 0;
1765 DECL_ATTRIBUTES (newdecl
)
1766 = targetm
.merge_decl_attributes (olddecl
, newdecl
);
1768 /* Merge the data types specified in the two decls. */
1770 = TREE_TYPE (olddecl
)
1771 = composite_type (newtype
, oldtype
);
1773 /* Lay the type out, unless already done. */
1774 if (!comptypes (oldtype
, TREE_TYPE (newdecl
)))
1776 if (TREE_TYPE (newdecl
) != error_mark_node
)
1777 layout_type (TREE_TYPE (newdecl
));
1778 if (TREE_CODE (newdecl
) != FUNCTION_DECL
1779 && TREE_CODE (newdecl
) != TYPE_DECL
1780 && TREE_CODE (newdecl
) != CONST_DECL
)
1781 layout_decl (newdecl
, 0);
1785 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1786 DECL_SIZE (newdecl
) = DECL_SIZE (olddecl
);
1787 DECL_SIZE_UNIT (newdecl
) = DECL_SIZE_UNIT (olddecl
);
1788 DECL_MODE (newdecl
) = DECL_MODE (olddecl
);
1789 if (DECL_ALIGN (olddecl
) > DECL_ALIGN (newdecl
))
1791 DECL_ALIGN (newdecl
) = DECL_ALIGN (olddecl
);
1792 DECL_USER_ALIGN (newdecl
) |= DECL_USER_ALIGN (olddecl
);
1796 /* Keep the old rtl since we can safely use it. */
1797 if (HAS_RTL_P (olddecl
))
1798 COPY_DECL_RTL (olddecl
, newdecl
);
1800 /* Merge the type qualifiers. */
1801 if (TREE_READONLY (newdecl
))
1802 TREE_READONLY (olddecl
) = 1;
1804 if (TREE_THIS_VOLATILE (newdecl
))
1805 TREE_THIS_VOLATILE (olddecl
) = 1;
1807 /* Merge deprecatedness. */
1808 if (TREE_DEPRECATED (newdecl
))
1809 TREE_DEPRECATED (olddecl
) = 1;
1811 /* If a decl is in a system header and the other isn't, keep the one on the
1812 system header. Otherwise, keep source location of definition rather than
1813 declaration and of prototype rather than non-prototype unless that
1814 prototype is built-in. */
1815 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl
), TS_DECL_WITH_VIS
)
1816 && DECL_IN_SYSTEM_HEADER (olddecl
)
1817 && !DECL_IN_SYSTEM_HEADER (newdecl
) )
1818 DECL_SOURCE_LOCATION (newdecl
) = DECL_SOURCE_LOCATION (olddecl
);
1819 else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl
), TS_DECL_WITH_VIS
)
1820 && DECL_IN_SYSTEM_HEADER (newdecl
)
1821 && !DECL_IN_SYSTEM_HEADER (olddecl
))
1822 DECL_SOURCE_LOCATION (olddecl
) = DECL_SOURCE_LOCATION (newdecl
);
1823 else if ((DECL_INITIAL (newdecl
) == 0 && DECL_INITIAL (olddecl
) != 0)
1824 || (old_is_prototype
&& !new_is_prototype
1825 && !C_DECL_BUILTIN_PROTOTYPE (olddecl
)))
1826 DECL_SOURCE_LOCATION (newdecl
) = DECL_SOURCE_LOCATION (olddecl
);
1828 /* Merge the initialization information. */
1829 if (DECL_INITIAL (newdecl
) == 0)
1830 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1832 /* Merge the threadprivate attribute. */
1833 if (TREE_CODE (olddecl
) == VAR_DECL
&& C_DECL_THREADPRIVATE_P (olddecl
))
1835 DECL_TLS_MODEL (newdecl
) = DECL_TLS_MODEL (olddecl
);
1836 C_DECL_THREADPRIVATE_P (newdecl
) = 1;
1839 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl
), TS_DECL_WITH_VIS
))
1841 /* Merge the section attribute.
1842 We want to issue an error if the sections conflict but that
1843 must be done later in decl_attributes since we are called
1844 before attributes are assigned. */
1845 if (DECL_SECTION_NAME (newdecl
) == NULL_TREE
)
1846 DECL_SECTION_NAME (newdecl
) = DECL_SECTION_NAME (olddecl
);
1848 /* Copy the assembler name.
1849 Currently, it can only be defined in the prototype. */
1850 COPY_DECL_ASSEMBLER_NAME (olddecl
, newdecl
);
1852 /* Use visibility of whichever declaration had it specified */
1853 if (DECL_VISIBILITY_SPECIFIED (olddecl
))
1855 DECL_VISIBILITY (newdecl
) = DECL_VISIBILITY (olddecl
);
1856 DECL_VISIBILITY_SPECIFIED (newdecl
) = 1;
1859 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1861 DECL_STATIC_CONSTRUCTOR(newdecl
) |= DECL_STATIC_CONSTRUCTOR(olddecl
);
1862 DECL_STATIC_DESTRUCTOR (newdecl
) |= DECL_STATIC_DESTRUCTOR (olddecl
);
1863 DECL_NO_LIMIT_STACK (newdecl
) |= DECL_NO_LIMIT_STACK (olddecl
);
1864 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl
)
1865 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl
);
1866 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1867 DECL_IS_MALLOC (newdecl
) |= DECL_IS_MALLOC (olddecl
);
1868 DECL_IS_OPERATOR_NEW (newdecl
) |= DECL_IS_OPERATOR_NEW (olddecl
);
1869 TREE_READONLY (newdecl
) |= TREE_READONLY (olddecl
);
1870 DECL_PURE_P (newdecl
) |= DECL_PURE_P (olddecl
);
1871 DECL_IS_NOVOPS (newdecl
) |= DECL_IS_NOVOPS (olddecl
);
1874 /* Merge the storage class information. */
1875 merge_weak (newdecl
, olddecl
);
1877 /* For functions, static overrides non-static. */
1878 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1880 TREE_PUBLIC (newdecl
) &= TREE_PUBLIC (olddecl
);
1881 /* This is since we don't automatically
1882 copy the attributes of NEWDECL into OLDDECL. */
1883 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1884 /* If this clears `static', clear it in the identifier too. */
1885 if (!TREE_PUBLIC (olddecl
))
1886 TREE_PUBLIC (DECL_NAME (olddecl
)) = 0;
1890 /* In c99, 'extern' declaration before (or after) 'inline' means this
1891 function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
1893 if (TREE_CODE (newdecl
) == FUNCTION_DECL
1894 && !flag_gnu89_inline
1895 && (DECL_DECLARED_INLINE_P (newdecl
)
1896 || DECL_DECLARED_INLINE_P (olddecl
))
1897 && (!DECL_DECLARED_INLINE_P (newdecl
)
1898 || !DECL_DECLARED_INLINE_P (olddecl
)
1899 || !DECL_EXTERNAL (olddecl
))
1900 && DECL_EXTERNAL (newdecl
)
1901 && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl
))
1902 && !current_function_decl
)
1903 DECL_EXTERNAL (newdecl
) = 0;
1905 if (DECL_EXTERNAL (newdecl
))
1907 TREE_STATIC (newdecl
) = TREE_STATIC (olddecl
);
1908 DECL_EXTERNAL (newdecl
) = DECL_EXTERNAL (olddecl
);
1910 /* An extern decl does not override previous storage class. */
1911 TREE_PUBLIC (newdecl
) = TREE_PUBLIC (olddecl
);
1912 if (!DECL_EXTERNAL (newdecl
))
1914 DECL_CONTEXT (newdecl
) = DECL_CONTEXT (olddecl
);
1915 DECL_COMMON (newdecl
) = DECL_COMMON (olddecl
);
1920 TREE_STATIC (olddecl
) = TREE_STATIC (newdecl
);
1921 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1924 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1926 /* If we're redefining a function previously defined as extern
1927 inline, make sure we emit debug info for the inline before we
1928 throw it away, in case it was inlined into a function that
1929 hasn't been written out yet. */
1930 if (new_is_definition
&& DECL_INITIAL (olddecl
))
1931 /* The new defn must not be inline. */
1932 DECL_UNINLINABLE (newdecl
) = 1;
1935 /* If either decl says `inline', this fn is inline, unless
1936 its definition was passed already. */
1937 if (DECL_DECLARED_INLINE_P (newdecl
)
1938 || DECL_DECLARED_INLINE_P (olddecl
))
1939 DECL_DECLARED_INLINE_P (newdecl
) = 1;
1941 DECL_UNINLINABLE (newdecl
) = DECL_UNINLINABLE (olddecl
)
1942 = (DECL_UNINLINABLE (newdecl
) || DECL_UNINLINABLE (olddecl
));
1944 DECL_DISREGARD_INLINE_LIMITS (newdecl
)
1945 = DECL_DISREGARD_INLINE_LIMITS (olddecl
)
1946 = (DECL_DISREGARD_INLINE_LIMITS (newdecl
)
1947 || DECL_DISREGARD_INLINE_LIMITS (olddecl
));
1950 if (DECL_BUILT_IN (olddecl
))
1952 /* If redeclaring a builtin function, it stays built in.
1953 But it gets tagged as having been declared. */
1954 DECL_BUILT_IN_CLASS (newdecl
) = DECL_BUILT_IN_CLASS (olddecl
);
1955 DECL_FUNCTION_CODE (newdecl
) = DECL_FUNCTION_CODE (olddecl
);
1956 C_DECL_DECLARED_BUILTIN (newdecl
) = 1;
1957 if (new_is_prototype
)
1958 C_DECL_BUILTIN_PROTOTYPE (newdecl
) = 0;
1960 C_DECL_BUILTIN_PROTOTYPE (newdecl
)
1961 = C_DECL_BUILTIN_PROTOTYPE (olddecl
);
1964 /* Preserve function specific target and optimization options */
1965 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl
)
1966 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl
))
1967 DECL_FUNCTION_SPECIFIC_TARGET (newdecl
)
1968 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl
);
1970 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl
)
1971 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl
))
1972 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl
)
1973 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl
);
1975 /* Also preserve various other info from the definition. */
1976 if (!new_is_definition
)
1979 DECL_RESULT (newdecl
) = DECL_RESULT (olddecl
);
1980 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1981 DECL_STRUCT_FUNCTION (newdecl
) = DECL_STRUCT_FUNCTION (olddecl
);
1982 DECL_SAVED_TREE (newdecl
) = DECL_SAVED_TREE (olddecl
);
1983 gimple_set_body (newdecl
, gimple_body (olddecl
));
1984 DECL_ARGUMENTS (newdecl
) = copy_list (DECL_ARGUMENTS (olddecl
));
1985 for (t
= DECL_ARGUMENTS (newdecl
); t
; t
= TREE_CHAIN (t
))
1986 DECL_CONTEXT (t
) = newdecl
;
1988 /* See if we've got a function to instantiate from. */
1989 if (DECL_SAVED_TREE (olddecl
))
1990 DECL_ABSTRACT_ORIGIN (newdecl
)
1991 = DECL_ABSTRACT_ORIGIN (olddecl
);
1995 extern_changed
= DECL_EXTERNAL (olddecl
) && !DECL_EXTERNAL (newdecl
);
1997 /* Merge the USED information. */
1998 if (TREE_USED (olddecl
))
1999 TREE_USED (newdecl
) = 1;
2000 else if (TREE_USED (newdecl
))
2001 TREE_USED (olddecl
) = 1;
2003 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
2004 But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
2006 unsigned olddecl_uid
= DECL_UID (olddecl
);
2007 tree olddecl_context
= DECL_CONTEXT (olddecl
);
2008 tree olddecl_arguments
= NULL
;
2009 if (TREE_CODE (olddecl
) == FUNCTION_DECL
)
2010 olddecl_arguments
= DECL_ARGUMENTS (olddecl
);
2012 memcpy ((char *) olddecl
+ sizeof (struct tree_common
),
2013 (char *) newdecl
+ sizeof (struct tree_common
),
2014 sizeof (struct tree_decl_common
) - sizeof (struct tree_common
));
2015 switch (TREE_CODE (olddecl
))
2018 gimple_set_body (olddecl
, gimple_body (newdecl
));
2028 memcpy ((char *) olddecl
+ sizeof (struct tree_decl_common
),
2029 (char *) newdecl
+ sizeof (struct tree_decl_common
),
2030 tree_code_size (TREE_CODE (olddecl
)) - sizeof (struct tree_decl_common
));
2035 memcpy ((char *) olddecl
+ sizeof (struct tree_decl_common
),
2036 (char *) newdecl
+ sizeof (struct tree_decl_common
),
2037 sizeof (struct tree_decl_non_common
) - sizeof (struct tree_decl_common
));
2039 DECL_UID (olddecl
) = olddecl_uid
;
2040 DECL_CONTEXT (olddecl
) = olddecl_context
;
2041 if (TREE_CODE (olddecl
) == FUNCTION_DECL
)
2042 DECL_ARGUMENTS (olddecl
) = olddecl_arguments
;
2045 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
2046 so that encode_section_info has a chance to look at the new decl
2047 flags and attributes. */
2048 if (DECL_RTL_SET_P (olddecl
)
2049 && (TREE_CODE (olddecl
) == FUNCTION_DECL
2050 || (TREE_CODE (olddecl
) == VAR_DECL
2051 && TREE_STATIC (olddecl
))))
2052 make_decl_rtl (olddecl
);
2054 /* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL,
2055 and the definition is coming from the old version, cgraph needs
2056 to be called again. */
2057 if (extern_changed
&& !new_is_definition
2058 && TREE_CODE (olddecl
) == FUNCTION_DECL
&& DECL_INITIAL (olddecl
))
2059 cgraph_mark_if_needed (olddecl
);
2062 /* Handle when a new declaration NEWDECL has the same name as an old
2063 one OLDDECL in the same binding contour. Prints an error message
2066 If safely possible, alter OLDDECL to look like NEWDECL, and return
2067 true. Otherwise, return false. */
2070 duplicate_decls (tree newdecl
, tree olddecl
)
2072 tree newtype
= NULL
, oldtype
= NULL
;
2074 if (!diagnose_mismatched_decls (newdecl
, olddecl
, &newtype
, &oldtype
))
2076 /* Avoid `unused variable' and other warnings for OLDDECL. */
2077 TREE_NO_WARNING (olddecl
) = 1;
2081 merge_decls (newdecl
, olddecl
, newtype
, oldtype
);
2086 /* Check whether decl-node NEW_DECL shadows an existing declaration. */
2088 warn_if_shadowing (tree new_decl
)
2090 struct c_binding
*b
;
2092 /* Shadow warnings wanted? */
2094 /* No shadow warnings for internally generated vars. */
2095 || DECL_IS_BUILTIN (new_decl
)
2096 /* No shadow warnings for vars made for inlining. */
2097 || DECL_FROM_INLINE (new_decl
))
2100 /* Is anything being shadowed? Invisible decls do not count. */
2101 for (b
= I_SYMBOL_BINDING (DECL_NAME (new_decl
)); b
; b
= b
->shadowed
)
2102 if (b
->decl
&& b
->decl
!= new_decl
&& !b
->invisible
)
2104 tree old_decl
= b
->decl
;
2106 if (old_decl
== error_mark_node
)
2108 warning (OPT_Wshadow
, "declaration of %q+D shadows previous "
2109 "non-variable", new_decl
);
2112 else if (TREE_CODE (old_decl
) == PARM_DECL
)
2113 warning (OPT_Wshadow
, "declaration of %q+D shadows a parameter",
2115 else if (DECL_FILE_SCOPE_P (old_decl
))
2116 warning (OPT_Wshadow
, "declaration of %q+D shadows a global "
2117 "declaration", new_decl
);
2118 else if (TREE_CODE (old_decl
) == FUNCTION_DECL
2119 && DECL_BUILT_IN (old_decl
))
2121 warning (OPT_Wshadow
, "declaration of %q+D shadows "
2122 "a built-in function", new_decl
);
2126 warning (OPT_Wshadow
, "declaration of %q+D shadows a previous local",
2129 warning (OPT_Wshadow
, "%Jshadowed declaration is here", old_decl
);
2135 /* Record a decl-node X as belonging to the current lexical scope.
2136 Check for errors (such as an incompatible declaration for the same
2137 name already seen in the same scope).
2139 Returns either X or an old decl for the same name.
2140 If an old decl is returned, it may have been smashed
2141 to agree with what X says. */
2146 tree name
= DECL_NAME (x
);
2147 struct c_scope
*scope
= current_scope
;
2148 struct c_binding
*b
;
2149 bool nested
= false;
2150 location_t locus
= DECL_SOURCE_LOCATION (x
);
2152 /* Must set DECL_CONTEXT for everything not at file scope or
2153 DECL_FILE_SCOPE_P won't work. Local externs don't count
2154 unless they have initializers (which generate code). */
2155 if (current_function_decl
2156 && ((TREE_CODE (x
) != FUNCTION_DECL
&& TREE_CODE (x
) != VAR_DECL
)
2157 || DECL_INITIAL (x
) || !DECL_EXTERNAL (x
)))
2158 DECL_CONTEXT (x
) = current_function_decl
;
2160 /* If this is of variably modified type, prevent jumping into its
2162 if ((TREE_CODE (x
) == VAR_DECL
|| TREE_CODE (x
) == TYPE_DECL
)
2163 && variably_modified_type_p (TREE_TYPE (x
), NULL_TREE
))
2164 c_begin_vm_scope (scope
->depth
);
2166 /* Anonymous decls are just inserted in the scope. */
2169 bind (name
, x
, scope
, /*invisible=*/false, /*nested=*/false,
2174 /* First, see if there is another declaration with the same name in
2175 the current scope. If there is, duplicate_decls may do all the
2176 work for us. If duplicate_decls returns false, that indicates
2177 two incompatible decls in the same scope; we are to silently
2178 replace the old one (duplicate_decls has issued all appropriate
2179 diagnostics). In particular, we should not consider possible
2180 duplicates in the external scope, or shadowing. */
2181 b
= I_SYMBOL_BINDING (name
);
2182 if (b
&& B_IN_SCOPE (b
, scope
))
2184 struct c_binding
*b_ext
, *b_use
;
2185 tree type
= TREE_TYPE (x
);
2186 tree visdecl
= b
->decl
;
2187 tree vistype
= TREE_TYPE (visdecl
);
2188 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
2189 && COMPLETE_TYPE_P (TREE_TYPE (x
)))
2190 b
->inner_comp
= false;
2193 /* If this is an external linkage declaration, we should check
2194 for compatibility with the type in the external scope before
2195 setting the type at this scope based on the visible
2196 information only. */
2197 if (TREE_PUBLIC (x
) && TREE_PUBLIC (visdecl
))
2199 while (b_ext
&& !B_IN_EXTERNAL_SCOPE (b_ext
))
2200 b_ext
= b_ext
->shadowed
;
2205 TREE_TYPE (b_use
->decl
) = b_use
->type
;
2208 if (duplicate_decls (x
, b_use
->decl
))
2212 /* Save the updated type in the external scope and
2213 restore the proper type for this scope. */
2215 if (comptypes (vistype
, type
))
2216 thistype
= composite_type (vistype
, type
);
2218 thistype
= TREE_TYPE (b_use
->decl
);
2219 b_use
->type
= TREE_TYPE (b_use
->decl
);
2220 if (TREE_CODE (b_use
->decl
) == FUNCTION_DECL
2221 && DECL_BUILT_IN (b_use
->decl
))
2223 = build_type_attribute_variant (thistype
,
2226 TREE_TYPE (b_use
->decl
) = thistype
;
2231 goto skip_external_and_shadow_checks
;
2234 /* All declarations with external linkage, and all external
2235 references, go in the external scope, no matter what scope is
2236 current. However, the binding in that scope is ignored for
2237 purposes of normal name lookup. A separate binding structure is
2238 created in the requested scope; this governs the normal
2239 visibility of the symbol.
2241 The binding in the externals scope is used exclusively for
2242 detecting duplicate declarations of the same object, no matter
2243 what scope they are in; this is what we do here. (C99 6.2.7p2:
2244 All declarations that refer to the same object or function shall
2245 have compatible type; otherwise, the behavior is undefined.) */
2246 if (DECL_EXTERNAL (x
) || scope
== file_scope
)
2248 tree type
= TREE_TYPE (x
);
2251 bool type_saved
= false;
2252 if (b
&& !B_IN_EXTERNAL_SCOPE (b
)
2253 && (TREE_CODE (b
->decl
) == FUNCTION_DECL
2254 || TREE_CODE (b
->decl
) == VAR_DECL
)
2255 && DECL_FILE_SCOPE_P (b
->decl
))
2258 vistype
= TREE_TYPE (visdecl
);
2260 if (scope
!= file_scope
2261 && !DECL_IN_SYSTEM_HEADER (x
))
2262 warning (OPT_Wnested_externs
, "nested extern declaration of %qD", x
);
2264 while (b
&& !B_IN_EXTERNAL_SCOPE (b
))
2266 /* If this decl might be modified, save its type. This is
2267 done here rather than when the decl is first bound
2268 because the type may change after first binding, through
2269 being completed or through attributes being added. If we
2270 encounter multiple such decls, only the first should have
2271 its type saved; the others will already have had their
2272 proper types saved and the types will not have changed as
2273 their scopes will not have been re-entered. */
2274 if (DECL_P (b
->decl
) && DECL_FILE_SCOPE_P (b
->decl
) && !type_saved
)
2276 b
->type
= TREE_TYPE (b
->decl
);
2279 if (B_IN_FILE_SCOPE (b
)
2280 && TREE_CODE (b
->decl
) == VAR_DECL
2281 && TREE_STATIC (b
->decl
)
2282 && TREE_CODE (TREE_TYPE (b
->decl
)) == ARRAY_TYPE
2283 && !TYPE_DOMAIN (TREE_TYPE (b
->decl
))
2284 && TREE_CODE (type
) == ARRAY_TYPE
2285 && TYPE_DOMAIN (type
)
2286 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
2287 && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
2289 /* Array type completed in inner scope, which should be
2290 diagnosed if the completion does not have size 1 and
2291 it does not get completed in the file scope. */
2292 b
->inner_comp
= true;
2297 /* If a matching external declaration has been found, set its
2298 type to the composite of all the types of that declaration.
2299 After the consistency checks, it will be reset to the
2300 composite of the visible types only. */
2301 if (b
&& (TREE_PUBLIC (x
) || same_translation_unit_p (x
, b
->decl
))
2303 TREE_TYPE (b
->decl
) = b
->type
;
2305 /* The point of the same_translation_unit_p check here is,
2306 we want to detect a duplicate decl for a construct like
2307 foo() { extern bar(); } ... static bar(); but not if
2308 they are in different translation units. In any case,
2309 the static does not go in the externals scope. */
2311 && (TREE_PUBLIC (x
) || same_translation_unit_p (x
, b
->decl
))
2312 && duplicate_decls (x
, b
->decl
))
2317 if (comptypes (vistype
, type
))
2318 thistype
= composite_type (vistype
, type
);
2320 thistype
= TREE_TYPE (b
->decl
);
2324 b
->type
= TREE_TYPE (b
->decl
);
2325 if (TREE_CODE (b
->decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (b
->decl
))
2327 = build_type_attribute_variant (thistype
,
2328 TYPE_ATTRIBUTES (b
->type
));
2329 TREE_TYPE (b
->decl
) = thistype
;
2330 bind (name
, b
->decl
, scope
, /*invisible=*/false, /*nested=*/true,
2334 else if (TREE_PUBLIC (x
))
2336 if (visdecl
&& !b
&& duplicate_decls (x
, visdecl
))
2338 /* An external declaration at block scope referring to a
2339 visible entity with internal linkage. The composite
2340 type will already be correct for this scope, so we
2341 just need to fall through to make the declaration in
2348 bind (name
, x
, external_scope
, /*invisible=*/true,
2349 /*nested=*/false, locus
);
2355 if (TREE_CODE (x
) != PARM_DECL
)
2356 warn_if_shadowing (x
);
2358 skip_external_and_shadow_checks
:
2359 if (TREE_CODE (x
) == TYPE_DECL
)
2360 set_underlying_type (x
);
2362 bind (name
, x
, scope
, /*invisible=*/false, nested
, locus
);
2364 /* If x's type is incomplete because it's based on a
2365 structure or union which has not yet been fully declared,
2366 attach it to that structure or union type, so we can go
2367 back and complete the variable declaration later, if the
2368 structure or union gets fully declared.
2370 If the input is erroneous, we can have error_mark in the type
2371 slot (e.g. "f(void a, ...)") - that doesn't count as an
2373 if (TREE_TYPE (x
) != error_mark_node
2374 && !COMPLETE_TYPE_P (TREE_TYPE (x
)))
2376 tree element
= TREE_TYPE (x
);
2378 while (TREE_CODE (element
) == ARRAY_TYPE
)
2379 element
= TREE_TYPE (element
);
2380 element
= TYPE_MAIN_VARIANT (element
);
2382 if ((TREE_CODE (element
) == RECORD_TYPE
2383 || TREE_CODE (element
) == UNION_TYPE
)
2384 && (TREE_CODE (x
) != TYPE_DECL
2385 || TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
)
2386 && !COMPLETE_TYPE_P (element
))
2387 C_TYPE_INCOMPLETE_VARS (element
)
2388 = tree_cons (NULL_TREE
, x
, C_TYPE_INCOMPLETE_VARS (element
));
2393 /* Record X as belonging to file scope.
2394 This is used only internally by the Objective-C front end,
2395 and is limited to its needs. duplicate_decls is not called;
2396 if there is any preexisting decl for this identifier, it is an ICE. */
2399 pushdecl_top_level (tree x
)
2402 bool nested
= false;
2403 gcc_assert (TREE_CODE (x
) == VAR_DECL
|| TREE_CODE (x
) == CONST_DECL
);
2405 name
= DECL_NAME (x
);
2407 gcc_assert (TREE_CODE (x
) == CONST_DECL
|| !I_SYMBOL_BINDING (name
));
2409 if (TREE_PUBLIC (x
))
2411 bind (name
, x
, external_scope
, /*invisible=*/true, /*nested=*/false,
2416 bind (name
, x
, file_scope
, /*invisible=*/false, nested
, UNKNOWN_LOCATION
);
2422 implicit_decl_warning (tree id
, tree olddecl
)
2424 if (warn_implicit_function_declaration
)
2429 warned
= pedwarn (input_location
, OPT_Wimplicit_function_declaration
,
2430 "implicit declaration of function %qE", id
);
2432 warned
= warning (OPT_Wimplicit_function_declaration
,
2433 G_("implicit declaration of function %qE"), id
);
2434 if (olddecl
&& warned
)
2435 locate_old_decl (olddecl
);
2439 /* Generate an implicit declaration for identifier FUNCTIONID as a
2440 function of type int (). */
2443 implicitly_declare (tree functionid
)
2445 struct c_binding
*b
;
2449 for (b
= I_SYMBOL_BINDING (functionid
); b
; b
= b
->shadowed
)
2451 if (B_IN_SCOPE (b
, external_scope
))
2460 if (decl
== error_mark_node
)
2463 /* FIXME: Objective-C has weird not-really-builtin functions
2464 which are supposed to be visible automatically. They wind up
2465 in the external scope because they're pushed before the file
2466 scope gets created. Catch this here and rebind them into the
2468 if (!DECL_BUILT_IN (decl
) && DECL_IS_BUILTIN (decl
))
2470 bind (functionid
, decl
, file_scope
,
2471 /*invisible=*/false, /*nested=*/true,
2472 DECL_SOURCE_LOCATION (decl
));
2477 tree newtype
= default_function_type
;
2479 TREE_TYPE (decl
) = b
->type
;
2480 /* Implicit declaration of a function already declared
2481 (somehow) in a different scope, or as a built-in.
2482 If this is the first time this has happened, warn;
2483 then recycle the old declaration but with the new type. */
2484 if (!C_DECL_IMPLICIT (decl
))
2486 implicit_decl_warning (functionid
, decl
);
2487 C_DECL_IMPLICIT (decl
) = 1;
2489 if (DECL_BUILT_IN (decl
))
2491 newtype
= build_type_attribute_variant (newtype
,
2493 (TREE_TYPE (decl
)));
2494 if (!comptypes (newtype
, TREE_TYPE (decl
)))
2496 warning (0, "incompatible implicit declaration of built-in"
2497 " function %qD", decl
);
2498 newtype
= TREE_TYPE (decl
);
2503 if (!comptypes (newtype
, TREE_TYPE (decl
)))
2505 error ("incompatible implicit declaration of function %qD",
2507 locate_old_decl (decl
);
2510 b
->type
= TREE_TYPE (decl
);
2511 TREE_TYPE (decl
) = newtype
;
2512 bind (functionid
, decl
, current_scope
,
2513 /*invisible=*/false, /*nested=*/true,
2514 DECL_SOURCE_LOCATION (decl
));
2519 /* Not seen before. */
2520 decl
= build_decl (FUNCTION_DECL
, functionid
, default_function_type
);
2521 DECL_EXTERNAL (decl
) = 1;
2522 TREE_PUBLIC (decl
) = 1;
2523 C_DECL_IMPLICIT (decl
) = 1;
2524 implicit_decl_warning (functionid
, 0);
2525 asmspec_tree
= maybe_apply_renaming_pragma (decl
, /*asmname=*/NULL
);
2527 set_user_assembler_name (decl
, TREE_STRING_POINTER (asmspec_tree
));
2529 /* C89 says implicit declarations are in the innermost block.
2530 So we record the decl in the standard fashion. */
2531 decl
= pushdecl (decl
);
2533 /* No need to call objc_check_decl here - it's a function type. */
2534 rest_of_decl_compilation (decl
, 0, 0);
2536 /* Write a record describing this implicit function declaration
2537 to the prototypes file (if requested). */
2538 gen_aux_info_record (decl
, 0, 1, 0);
2540 /* Possibly apply some default attributes to this implicit declaration. */
2541 decl_attributes (&decl
, NULL_TREE
, 0);
2546 /* Issue an error message for a reference to an undeclared variable
2547 ID, including a reference to a builtin outside of function-call
2548 context. Establish a binding of the identifier to error_mark_node
2549 in an appropriate scope, which will suppress further errors for the
2550 same identifier. The error message should be given location LOC. */
2552 undeclared_variable (tree id
, location_t loc
)
2554 static bool already
= false;
2555 struct c_scope
*scope
;
2557 if (current_function_decl
== 0)
2559 error ("%H%qE undeclared here (not in a function)", &loc
, id
);
2560 scope
= current_scope
;
2564 error ("%H%qE undeclared (first use in this function)", &loc
, id
);
2568 error ("%H(Each undeclared identifier is reported only once", &loc
);
2569 error ("%Hfor each function it appears in.)", &loc
);
2573 /* If we are parsing old-style parameter decls, current_function_decl
2574 will be nonnull but current_function_scope will be null. */
2575 scope
= current_function_scope
? current_function_scope
: current_scope
;
2577 bind (id
, error_mark_node
, scope
, /*invisible=*/false, /*nested=*/false,
2581 /* Subroutine of lookup_label, declare_label, define_label: construct a
2582 LABEL_DECL with all the proper frills. */
2585 make_label (tree name
, location_t location
)
2587 tree label
= build_decl (LABEL_DECL
, name
, void_type_node
);
2589 DECL_CONTEXT (label
) = current_function_decl
;
2590 DECL_MODE (label
) = VOIDmode
;
2591 DECL_SOURCE_LOCATION (label
) = location
;
2596 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
2597 Create one if none exists so far for the current function.
2598 This is called when a label is used in a goto expression or
2599 has its address taken. */
2602 lookup_label (tree name
)
2606 if (current_function_decl
== 0)
2608 error ("label %qE referenced outside of any function", name
);
2612 /* Use a label already defined or ref'd with this name, but not if
2613 it is inherited from a containing function and wasn't declared
2615 label
= I_LABEL_DECL (name
);
2616 if (label
&& (DECL_CONTEXT (label
) == current_function_decl
2617 || C_DECLARED_LABEL_FLAG (label
)))
2619 /* If the label has only been declared, update its apparent
2620 location to point here, for better diagnostics if it
2621 turns out not to have been defined. */
2622 if (!TREE_USED (label
))
2623 DECL_SOURCE_LOCATION (label
) = input_location
;
2627 /* No label binding for that identifier; make one. */
2628 label
= make_label (name
, input_location
);
2630 /* Ordinary labels go in the current function scope. */
2631 bind (name
, label
, current_function_scope
,
2632 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION
);
2636 /* Make a label named NAME in the current function, shadowing silently
2637 any that may be inherited from containing functions or containing
2638 scopes. This is called for __label__ declarations. */
2641 declare_label (tree name
)
2643 struct c_binding
*b
= I_LABEL_BINDING (name
);
2646 /* Check to make sure that the label hasn't already been declared
2648 if (b
&& B_IN_CURRENT_SCOPE (b
))
2650 error ("duplicate label declaration %qE", name
);
2651 locate_old_decl (b
->decl
);
2653 /* Just use the previous declaration. */
2657 label
= make_label (name
, input_location
);
2658 C_DECLARED_LABEL_FLAG (label
) = 1;
2660 /* Declared labels go in the current scope. */
2661 bind (name
, label
, current_scope
,
2662 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION
);
2666 /* Define a label, specifying the location in the source file.
2667 Return the LABEL_DECL node for the label, if the definition is valid.
2668 Otherwise return 0. */
2671 define_label (location_t location
, tree name
)
2673 /* Find any preexisting label with this name. It is an error
2674 if that label has already been defined in this function, or
2675 if there is a containing function with a declared label with
2677 tree label
= I_LABEL_DECL (name
);
2678 struct c_label_list
*nlist_se
, *nlist_vm
;
2681 && ((DECL_CONTEXT (label
) == current_function_decl
2682 && DECL_INITIAL (label
) != 0)
2683 || (DECL_CONTEXT (label
) != current_function_decl
2684 && C_DECLARED_LABEL_FLAG (label
))))
2686 error ("%Hduplicate label %qD", &location
, label
);
2687 locate_old_decl (label
);
2690 else if (label
&& DECL_CONTEXT (label
) == current_function_decl
)
2692 /* The label has been used or declared already in this function,
2693 but not defined. Update its location to point to this
2695 if (C_DECL_UNDEFINABLE_STMT_EXPR (label
))
2696 error ("%Jjump into statement expression", label
);
2697 if (C_DECL_UNDEFINABLE_VM (label
))
2698 error ("%Jjump into scope of identifier with variably modified type",
2700 DECL_SOURCE_LOCATION (label
) = location
;
2704 /* No label binding for that identifier; make one. */
2705 label
= make_label (name
, location
);
2707 /* Ordinary labels go in the current function scope. */
2708 bind (name
, label
, current_function_scope
,
2709 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION
);
2712 if (!in_system_header
&& lookup_name (name
))
2713 warning (OPT_Wtraditional
, "%Htraditional C lacks a separate namespace "
2714 "for labels, identifier %qE conflicts", &location
, name
);
2716 nlist_se
= XOBNEW (&parser_obstack
, struct c_label_list
);
2717 nlist_se
->next
= label_context_stack_se
->labels_def
;
2718 nlist_se
->label
= label
;
2719 label_context_stack_se
->labels_def
= nlist_se
;
2721 nlist_vm
= XOBNEW (&parser_obstack
, struct c_label_list
);
2722 nlist_vm
->next
= label_context_stack_vm
->labels_def
;
2723 nlist_vm
->label
= label
;
2724 label_context_stack_vm
->labels_def
= nlist_vm
;
2726 /* Mark label as having been defined. */
2727 DECL_INITIAL (label
) = error_mark_node
;
2731 /* Given NAME, an IDENTIFIER_NODE,
2732 return the structure (or union or enum) definition for that name.
2733 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2734 CODE says which kind of type the caller wants;
2735 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2736 If PLOC is not NULL and this returns non-null, it sets *PLOC to the
2737 location where the tag was defined.
2738 If the wrong kind of type is found, an error is reported. */
2741 lookup_tag (enum tree_code code
, tree name
, int thislevel_only
,
2744 struct c_binding
*b
= I_TAG_BINDING (name
);
2750 /* We only care about whether it's in this level if
2751 thislevel_only was set or it might be a type clash. */
2752 if (thislevel_only
|| TREE_CODE (b
->decl
) != code
)
2754 /* For our purposes, a tag in the external scope is the same as
2755 a tag in the file scope. (Primarily relevant to Objective-C
2756 and its builtin structure tags, which get pushed before the
2757 file scope is created.) */
2758 if (B_IN_CURRENT_SCOPE (b
)
2759 || (current_scope
== file_scope
&& B_IN_EXTERNAL_SCOPE (b
)))
2763 if (thislevel_only
&& !thislevel
)
2766 if (TREE_CODE (b
->decl
) != code
)
2768 /* Definition isn't the kind we were looking for. */
2769 pending_invalid_xref
= name
;
2770 pending_invalid_xref_location
= input_location
;
2772 /* If in the same binding level as a declaration as a tag
2773 of a different type, this must not be allowed to
2774 shadow that tag, so give the error immediately.
2775 (For example, "struct foo; union foo;" is invalid.) */
2777 pending_xref_error ();
2786 /* Print an error message now
2787 for a recent invalid struct, union or enum cross reference.
2788 We don't print them immediately because they are not invalid
2789 when used in the `struct foo;' construct for shadowing. */
2792 pending_xref_error (void)
2794 if (pending_invalid_xref
!= 0)
2795 error ("%H%qE defined as wrong kind of tag",
2796 &pending_invalid_xref_location
, pending_invalid_xref
);
2797 pending_invalid_xref
= 0;
2801 /* Look up NAME in the current scope and its superiors
2802 in the namespace of variables, functions and typedefs.
2803 Return a ..._DECL node of some kind representing its definition,
2804 or return 0 if it is undefined. */
2807 lookup_name (tree name
)
2809 struct c_binding
*b
= I_SYMBOL_BINDING (name
);
2810 if (b
&& !b
->invisible
)
2815 /* Similar to `lookup_name' but look only at the indicated scope. */
2818 lookup_name_in_scope (tree name
, struct c_scope
*scope
)
2820 struct c_binding
*b
;
2822 for (b
= I_SYMBOL_BINDING (name
); b
; b
= b
->shadowed
)
2823 if (B_IN_SCOPE (b
, scope
))
2828 /* Create the predefined scalar types of C,
2829 and some nodes representing standard constants (0, 1, (void *) 0).
2830 Initialize the global scope.
2831 Make definitions for built-in primitive functions. */
2834 c_init_decl_processing (void)
2836 location_t save_loc
= input_location
;
2838 /* Initialize reserved words for parser. */
2841 current_function_decl
= 0;
2843 gcc_obstack_init (&parser_obstack
);
2845 /* Make the externals scope. */
2847 external_scope
= current_scope
;
2849 /* Declarations from c_common_nodes_and_builtins must not be associated
2850 with this input file, lest we get differences between using and not
2851 using preprocessed headers. */
2852 input_location
= BUILTINS_LOCATION
;
2854 build_common_tree_nodes (flag_signed_char
, false);
2856 c_common_nodes_and_builtins ();
2858 /* In C, comparisons and TRUTH_* expressions have type int. */
2859 truthvalue_type_node
= integer_type_node
;
2860 truthvalue_true_node
= integer_one_node
;
2861 truthvalue_false_node
= integer_zero_node
;
2863 /* Even in C99, which has a real boolean type. */
2864 pushdecl (build_decl (TYPE_DECL
, get_identifier ("_Bool"),
2865 boolean_type_node
));
2867 input_location
= save_loc
;
2869 pedantic_lvalues
= true;
2871 make_fname_decl
= c_make_fname_decl
;
2872 start_fname_decls ();
2875 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2876 decl, NAME is the initialization string and TYPE_DEP indicates whether
2877 NAME depended on the type of the function. As we don't yet implement
2878 delayed emission of static data, we mark the decl as emitted
2879 so it is not placed in the output. Anything using it must therefore pull
2880 out the STRING_CST initializer directly. FIXME. */
2883 c_make_fname_decl (tree id
, int type_dep
)
2885 const char *name
= fname_as_string (type_dep
);
2886 tree decl
, type
, init
;
2887 size_t length
= strlen (name
);
2889 type
= build_array_type (char_type_node
,
2890 build_index_type (size_int (length
)));
2891 type
= c_build_qualified_type (type
, TYPE_QUAL_CONST
);
2893 decl
= build_decl (VAR_DECL
, id
, type
);
2895 TREE_STATIC (decl
) = 1;
2896 TREE_READONLY (decl
) = 1;
2897 DECL_ARTIFICIAL (decl
) = 1;
2899 init
= build_string (length
+ 1, name
);
2900 free (CONST_CAST (char *, name
));
2901 TREE_TYPE (init
) = type
;
2902 DECL_INITIAL (decl
) = init
;
2904 TREE_USED (decl
) = 1;
2906 if (current_function_decl
2907 /* For invalid programs like this:
2910 const char* p = __FUNCTION__;
2912 the __FUNCTION__ is believed to appear in K&R style function
2913 parameter declarator. In that case we still don't have
2915 && (!errorcount
|| current_function_scope
))
2917 DECL_CONTEXT (decl
) = current_function_decl
;
2918 bind (id
, decl
, current_function_scope
,
2919 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION
);
2922 finish_decl (decl
, init
, NULL_TREE
, NULL_TREE
);
2928 c_builtin_function (tree decl
)
2930 tree type
= TREE_TYPE (decl
);
2931 tree id
= DECL_NAME (decl
);
2933 const char *name
= IDENTIFIER_POINTER (id
);
2934 C_DECL_BUILTIN_PROTOTYPE (decl
) = (TYPE_ARG_TYPES (type
) != 0);
2936 /* Should never be called on a symbol with a preexisting meaning. */
2937 gcc_assert (!I_SYMBOL_BINDING (id
));
2939 bind (id
, decl
, external_scope
, /*invisible=*/true, /*nested=*/false,
2942 /* Builtins in the implementation namespace are made visible without
2943 needing to be explicitly declared. See push_file_scope. */
2944 if (name
[0] == '_' && (name
[1] == '_' || ISUPPER (name
[1])))
2946 TREE_CHAIN (decl
) = visible_builtins
;
2947 visible_builtins
= decl
;
2954 c_builtin_function_ext_scope (tree decl
)
2956 tree type
= TREE_TYPE (decl
);
2957 tree id
= DECL_NAME (decl
);
2959 const char *name
= IDENTIFIER_POINTER (id
);
2960 C_DECL_BUILTIN_PROTOTYPE (decl
) = (TYPE_ARG_TYPES (type
) != 0);
2962 /* Should never be called on a symbol with a preexisting meaning. */
2963 gcc_assert (!I_SYMBOL_BINDING (id
));
2965 bind (id
, decl
, external_scope
, /*invisible=*/false, /*nested=*/false,
2968 /* Builtins in the implementation namespace are made visible without
2969 needing to be explicitly declared. See push_file_scope. */
2970 if (name
[0] == '_' && (name
[1] == '_' || ISUPPER (name
[1])))
2972 TREE_CHAIN (decl
) = visible_builtins
;
2973 visible_builtins
= decl
;
2979 /* Called when a declaration is seen that contains no names to declare.
2980 If its type is a reference to a structure, union or enum inherited
2981 from a containing scope, shadow that tag name for the current scope
2982 with a forward reference.
2983 If its type defines a new named structure or union
2984 or defines an enum, it is valid but we need not do anything here.
2985 Otherwise, it is an error. */
2988 shadow_tag (const struct c_declspecs
*declspecs
)
2990 shadow_tag_warned (declspecs
, 0);
2993 /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
2996 shadow_tag_warned (const struct c_declspecs
*declspecs
, int warned
)
2998 bool found_tag
= false;
3000 if (declspecs
->type
&& !declspecs
->default_int_p
&& !declspecs
->typedef_p
)
3002 tree value
= declspecs
->type
;
3003 enum tree_code code
= TREE_CODE (value
);
3005 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ENUMERAL_TYPE
)
3006 /* Used to test also that TYPE_SIZE (value) != 0.
3007 That caused warning for `struct foo;' at top level in the file. */
3009 tree name
= TYPE_NAME (value
);
3014 if (declspecs
->restrict_p
)
3016 error ("invalid use of %<restrict%>");
3022 if (warned
!= 1 && code
!= ENUMERAL_TYPE
)
3023 /* Empty unnamed enum OK */
3025 pedwarn (input_location
, 0,
3026 "unnamed struct/union that defines no instances");
3030 else if (!declspecs
->tag_defined_p
3031 && declspecs
->storage_class
!= csc_none
)
3034 pedwarn (input_location
, 0,
3035 "empty declaration with storage class specifier "
3036 "does not redeclare tag");
3038 pending_xref_error ();
3040 else if (!declspecs
->tag_defined_p
3041 && (declspecs
->const_p
3042 || declspecs
->volatile_p
3043 || declspecs
->restrict_p
))
3046 pedwarn (input_location
, 0,
3047 "empty declaration with type qualifier "
3048 "does not redeclare tag");
3050 pending_xref_error ();
3054 pending_invalid_xref
= 0;
3055 t
= lookup_tag (code
, name
, 1, NULL
);
3059 t
= make_node (code
);
3060 pushtag (name
, t
, input_location
);
3066 if (warned
!= 1 && !in_system_header
)
3068 pedwarn (input_location
, 0,
3069 "useless type name in empty declaration");
3074 else if (warned
!= 1 && !in_system_header
&& declspecs
->typedef_p
)
3076 pedwarn (input_location
, 0, "useless type name in empty declaration");
3080 pending_invalid_xref
= 0;
3082 if (declspecs
->inline_p
)
3084 error ("%<inline%> in empty declaration");
3088 if (current_scope
== file_scope
&& declspecs
->storage_class
== csc_auto
)
3090 error ("%<auto%> in file-scope empty declaration");
3094 if (current_scope
== file_scope
&& declspecs
->storage_class
== csc_register
)
3096 error ("%<register%> in file-scope empty declaration");
3100 if (!warned
&& !in_system_header
&& declspecs
->storage_class
!= csc_none
)
3102 warning (0, "useless storage class specifier in empty declaration");
3106 if (!warned
&& !in_system_header
&& declspecs
->thread_p
)
3108 warning (0, "useless %<__thread%> in empty declaration");
3112 if (!warned
&& !in_system_header
&& (declspecs
->const_p
3113 || declspecs
->volatile_p
3114 || declspecs
->restrict_p
))
3116 warning (0, "useless type qualifier in empty declaration");
3123 pedwarn (input_location
, 0, "empty declaration");
3128 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
3129 bits. SPECS represents declaration specifiers that the grammar
3130 only permits to contain type qualifiers and attributes. */
3133 quals_from_declspecs (const struct c_declspecs
*specs
)
3135 int quals
= ((specs
->const_p
? TYPE_QUAL_CONST
: 0)
3136 | (specs
->volatile_p
? TYPE_QUAL_VOLATILE
: 0)
3137 | (specs
->restrict_p
? TYPE_QUAL_RESTRICT
: 0));
3138 gcc_assert (!specs
->type
3139 && !specs
->decl_attr
3140 && specs
->typespec_word
== cts_none
3141 && specs
->storage_class
== csc_none
3142 && !specs
->typedef_p
3143 && !specs
->explicit_signed_p
3144 && !specs
->deprecated_p
3146 && !specs
->long_long_p
3149 && !specs
->unsigned_p
3150 && !specs
->complex_p
3152 && !specs
->thread_p
);
3156 /* Construct an array declarator. EXPR is the expression inside [],
3157 or NULL_TREE. QUALS are the type qualifiers inside the [] (to be
3158 applied to the pointer to which a parameter array is converted).
3159 STATIC_P is true if "static" is inside the [], false otherwise.
3160 VLA_UNSPEC_P is true if the array is [*], a VLA of unspecified
3161 length which is nevertheless a complete type, false otherwise. The
3162 field for the contained declarator is left to be filled in by
3163 set_array_declarator_inner. */
3165 struct c_declarator
*
3166 build_array_declarator (tree expr
, struct c_declspecs
*quals
, bool static_p
,
3169 struct c_declarator
*declarator
= XOBNEW (&parser_obstack
,
3170 struct c_declarator
);
3171 declarator
->kind
= cdk_array
;
3172 declarator
->declarator
= 0;
3173 declarator
->u
.array
.dimen
= expr
;
3176 declarator
->u
.array
.attrs
= quals
->attrs
;
3177 declarator
->u
.array
.quals
= quals_from_declspecs (quals
);
3181 declarator
->u
.array
.attrs
= NULL_TREE
;
3182 declarator
->u
.array
.quals
= 0;
3184 declarator
->u
.array
.static_p
= static_p
;
3185 declarator
->u
.array
.vla_unspec_p
= vla_unspec_p
;
3188 if (static_p
|| quals
!= NULL
)
3189 pedwarn (input_location
, OPT_pedantic
,
3190 "ISO C90 does not support %<static%> or type "
3191 "qualifiers in parameter array declarators");
3193 pedwarn (input_location
, OPT_pedantic
,
3194 "ISO C90 does not support %<[*]%> array declarators");
3198 if (!current_scope
->parm_flag
)
3201 error ("%<[*]%> not allowed in other than function prototype scope");
3202 declarator
->u
.array
.vla_unspec_p
= false;
3205 current_scope
->had_vla_unspec
= true;
3210 /* Set the contained declarator of an array declarator. DECL is the
3211 declarator, as constructed by build_array_declarator; INNER is what
3212 appears on the left of the []. */
3214 struct c_declarator
*
3215 set_array_declarator_inner (struct c_declarator
*decl
,
3216 struct c_declarator
*inner
)
3218 decl
->declarator
= inner
;
3222 /* INIT is a constructor that forms DECL's initializer. If the final
3223 element initializes a flexible array field, add the size of that
3224 initializer to DECL's size. */
3227 add_flexible_array_elts_to_size (tree decl
, tree init
)
3231 if (VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (init
)))
3234 elt
= VEC_last (constructor_elt
, CONSTRUCTOR_ELTS (init
))->value
;
3235 type
= TREE_TYPE (elt
);
3236 if (TREE_CODE (type
) == ARRAY_TYPE
3237 && TYPE_SIZE (type
) == NULL_TREE
3238 && TYPE_DOMAIN (type
) != NULL_TREE
3239 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
)
3241 complete_array_type (&type
, elt
, false);
3243 = size_binop (PLUS_EXPR
, DECL_SIZE (decl
), TYPE_SIZE (type
));
3244 DECL_SIZE_UNIT (decl
)
3245 = size_binop (PLUS_EXPR
, DECL_SIZE_UNIT (decl
), TYPE_SIZE_UNIT (type
));
3249 /* Decode a "typename", such as "int **", returning a ..._TYPE node.
3250 Set *EXPR, if EXPR not NULL, to any expression to be evaluated
3251 before the type name, and set *EXPR_CONST_OPERANDS, if
3252 EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
3253 appear in a constant expression. */
3256 groktypename (struct c_type_name
*type_name
, tree
*expr
,
3257 bool *expr_const_operands
)
3260 tree attrs
= type_name
->specs
->attrs
;
3262 type_name
->specs
->attrs
= NULL_TREE
;
3264 type
= grokdeclarator (type_name
->declarator
, type_name
->specs
, TYPENAME
,
3265 false, NULL
, &attrs
, expr
, expr_const_operands
,
3268 /* Apply attributes. */
3269 decl_attributes (&type
, attrs
, 0);
3274 /* Decode a declarator in an ordinary declaration or data definition.
3275 This is called as soon as the type information and variable name
3276 have been parsed, before parsing the initializer if any.
3277 Here we create the ..._DECL node, fill in its type,
3278 and put it on the list of decls for the current context.
3279 The ..._DECL node is returned as the value.
3281 Exception: for arrays where the length is not specified,
3282 the type is left null, to be filled in by `finish_decl'.
3284 Function definitions do not come here; they go to start_function
3285 instead. However, external and forward declarations of functions
3286 do go through here. Structure field declarations are done by
3287 grokfield and not through here. */
3290 start_decl (struct c_declarator
*declarator
, struct c_declspecs
*declspecs
,
3291 bool initialized
, tree attributes
)
3295 tree expr
= NULL_TREE
;
3296 enum deprecated_states deprecated_state
= DEPRECATED_NORMAL
;
3298 /* An object declared as __attribute__((deprecated)) suppresses
3299 warnings of uses of other deprecated items. */
3300 if (lookup_attribute ("deprecated", attributes
))
3301 deprecated_state
= DEPRECATED_SUPPRESS
;
3303 decl
= grokdeclarator (declarator
, declspecs
,
3304 NORMAL
, initialized
, NULL
, &attributes
, &expr
, NULL
,
3312 if (TREE_CODE (decl
) != FUNCTION_DECL
&& MAIN_NAME_P (DECL_NAME (decl
)))
3313 warning (OPT_Wmain
, "%q+D is usually a function", decl
);
3316 /* Is it valid for this decl to have an initializer at all?
3317 If not, set INITIALIZED to zero, which will indirectly
3318 tell 'finish_decl' to ignore the initializer once it is parsed. */
3319 switch (TREE_CODE (decl
))
3322 error ("typedef %qD is initialized (use __typeof__ instead)", decl
);
3327 error ("function %qD is initialized like a variable", decl
);
3332 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3333 error ("parameter %qD is initialized", decl
);
3338 /* Don't allow initializations for incomplete types except for
3339 arrays which might be completed by the initialization. */
3341 /* This can happen if the array size is an undefined macro.
3342 We already gave a warning, so we don't need another one. */
3343 if (TREE_TYPE (decl
) == error_mark_node
)
3345 else if (COMPLETE_TYPE_P (TREE_TYPE (decl
)))
3347 /* A complete type is ok if size is fixed. */
3349 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl
))) != INTEGER_CST
3350 || C_DECL_VARIABLE_SIZE (decl
))
3352 error ("variable-sized object may not be initialized");
3356 else if (TREE_CODE (TREE_TYPE (decl
)) != ARRAY_TYPE
)
3358 error ("variable %qD has initializer but incomplete type", decl
);
3361 else if (C_DECL_VARIABLE_SIZE (decl
))
3363 /* Although C99 is unclear about whether incomplete arrays
3364 of VLAs themselves count as VLAs, it does not make
3365 sense to permit them to be initialized given that
3366 ordinary VLAs may not be initialized. */
3367 error ("variable-sized object may not be initialized");
3374 if (current_scope
== file_scope
)
3375 TREE_STATIC (decl
) = 1;
3377 /* Tell 'pushdecl' this is an initialized decl
3378 even though we don't yet have the initializer expression.
3379 Also tell 'finish_decl' it may store the real initializer. */
3380 DECL_INITIAL (decl
) = error_mark_node
;
3383 /* If this is a function declaration, write a record describing it to the
3384 prototypes file (if requested). */
3386 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3387 gen_aux_info_record (decl
, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl
)) != 0);
3389 /* ANSI specifies that a tentative definition which is not merged with
3390 a non-tentative definition behaves exactly like a definition with an
3391 initializer equal to zero. (Section 3.7.2)
3393 -fno-common gives strict ANSI behavior, though this tends to break
3394 a large body of code that grew up without this rule.
3396 Thread-local variables are never common, since there's no entrenched
3397 body of code to break, and it allows more efficient variable references
3398 in the presence of dynamic linking. */
3400 if (TREE_CODE (decl
) == VAR_DECL
3402 && TREE_PUBLIC (decl
)
3403 && !DECL_THREAD_LOCAL_P (decl
)
3405 DECL_COMMON (decl
) = 1;
3407 /* Set attributes here so if duplicate decl, will have proper attributes. */
3408 decl_attributes (&decl
, attributes
, 0);
3410 /* Handle gnu_inline attribute. */
3411 if (declspecs
->inline_p
3412 && !flag_gnu89_inline
3413 && TREE_CODE (decl
) == FUNCTION_DECL
3414 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl
))
3415 || current_function_decl
))
3417 if (declspecs
->storage_class
== csc_auto
&& current_scope
!= file_scope
)
3419 else if (declspecs
->storage_class
!= csc_static
)
3420 DECL_EXTERNAL (decl
) = !DECL_EXTERNAL (decl
);
3423 if (TREE_CODE (decl
) == FUNCTION_DECL
3424 && targetm
.calls
.promote_prototypes (TREE_TYPE (decl
)))
3426 struct c_declarator
*ce
= declarator
;
3428 if (ce
->kind
== cdk_pointer
)
3429 ce
= declarator
->declarator
;
3430 if (ce
->kind
== cdk_function
)
3432 tree args
= ce
->u
.arg_info
->parms
;
3433 for (; args
; args
= TREE_CHAIN (args
))
3435 tree type
= TREE_TYPE (args
);
3436 if (type
&& INTEGRAL_TYPE_P (type
)
3437 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
3438 DECL_ARG_TYPE (args
) = integer_type_node
;
3443 if (TREE_CODE (decl
) == FUNCTION_DECL
3444 && DECL_DECLARED_INLINE_P (decl
)
3445 && DECL_UNINLINABLE (decl
)
3446 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl
)))
3447 warning (OPT_Wattributes
, "inline function %q+D given attribute noinline",
3450 /* C99 6.7.4p3: An inline definition of a function with external
3451 linkage shall not contain a definition of a modifiable object
3452 with static storage duration... */
3453 if (TREE_CODE (decl
) == VAR_DECL
3454 && current_scope
!= file_scope
3455 && TREE_STATIC (decl
)
3456 && !TREE_READONLY (decl
)
3457 && DECL_DECLARED_INLINE_P (current_function_decl
)
3458 && DECL_EXTERNAL (current_function_decl
))
3459 record_inline_static (input_location
, current_function_decl
,
3460 decl
, csi_modifiable
);
3462 /* Add this decl to the current scope.
3463 TEM may equal DECL or it may be a previous decl of the same name. */
3464 tem
= pushdecl (decl
);
3466 if (initialized
&& DECL_EXTERNAL (tem
))
3468 DECL_EXTERNAL (tem
) = 0;
3469 TREE_STATIC (tem
) = 1;
3475 /* Initialize EH if not initialized yet and exceptions are enabled. */
3478 c_maybe_initialize_eh (void)
3480 if (!flag_exceptions
|| c_eh_initialized_p
)
3483 c_eh_initialized_p
= true;
3484 eh_personality_libfunc
3485 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
3486 ? "__gcc_personality_sj0"
3487 : "__gcc_personality_v0");
3488 default_init_unwind_resume_libfunc ();
3489 using_eh_for_cleanups ();
3492 /* Finish processing of a declaration;
3493 install its initial value.
3494 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
3495 If the length of an array type is not known before,
3496 it must be determined now, from the initial value, or it is an error. */
3499 finish_decl (tree decl
, tree init
, tree origtype
, tree asmspec_tree
)
3502 int was_incomplete
= (DECL_SIZE (decl
) == 0);
3503 const char *asmspec
= 0;
3505 /* If a name was specified, get the string. */
3506 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
3507 && DECL_FILE_SCOPE_P (decl
))
3508 asmspec_tree
= maybe_apply_renaming_pragma (decl
, asmspec_tree
);
3510 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
3512 /* If `start_decl' didn't like having an initialization, ignore it now. */
3513 if (init
!= 0 && DECL_INITIAL (decl
) == 0)
3516 /* Don't crash if parm is initialized. */
3517 if (TREE_CODE (decl
) == PARM_DECL
)
3521 store_init_value (decl
, init
, origtype
);
3523 if (c_dialect_objc () && (TREE_CODE (decl
) == VAR_DECL
3524 || TREE_CODE (decl
) == FUNCTION_DECL
3525 || TREE_CODE (decl
) == FIELD_DECL
))
3526 objc_check_decl (decl
);
3528 type
= TREE_TYPE (decl
);
3530 /* Deduce size of array from initialization, if not already known. */
3531 if (TREE_CODE (type
) == ARRAY_TYPE
3532 && TYPE_DOMAIN (type
) == 0
3533 && TREE_CODE (decl
) != TYPE_DECL
)
3536 = (TREE_STATIC (decl
)
3537 /* Even if pedantic, an external linkage array
3538 may have incomplete type at first. */
3539 ? pedantic
&& !TREE_PUBLIC (decl
)
3540 : !DECL_EXTERNAL (decl
));
3542 = complete_array_type (&TREE_TYPE (decl
), DECL_INITIAL (decl
),
3545 /* Get the completed type made by complete_array_type. */
3546 type
= TREE_TYPE (decl
);
3551 error ("initializer fails to determine size of %q+D", decl
);
3556 error ("array size missing in %q+D", decl
);
3557 /* If a `static' var's size isn't known,
3558 make it extern as well as static, so it does not get
3560 If it is not `static', then do not mark extern;
3561 finish_incomplete_decl will give it a default size
3562 and it will get allocated. */
3563 else if (!pedantic
&& TREE_STATIC (decl
) && !TREE_PUBLIC (decl
))
3564 DECL_EXTERNAL (decl
) = 1;
3568 error ("zero or negative size array %q+D", decl
);
3572 /* For global variables, update the copy of the type that
3573 exists in the binding. */
3574 if (TREE_PUBLIC (decl
))
3576 struct c_binding
*b_ext
= I_SYMBOL_BINDING (DECL_NAME (decl
));
3577 while (b_ext
&& !B_IN_EXTERNAL_SCOPE (b_ext
))
3578 b_ext
= b_ext
->shadowed
;
3582 b_ext
->type
= composite_type (b_ext
->type
, type
);
3593 if (DECL_INITIAL (decl
))
3594 TREE_TYPE (DECL_INITIAL (decl
)) = type
;
3596 layout_decl (decl
, 0);
3599 if (TREE_CODE (decl
) == VAR_DECL
)
3601 if (init
&& TREE_CODE (init
) == CONSTRUCTOR
)
3602 add_flexible_array_elts_to_size (decl
, init
);
3604 if (DECL_SIZE (decl
) == 0 && TREE_TYPE (decl
) != error_mark_node
3605 && COMPLETE_TYPE_P (TREE_TYPE (decl
)))
3606 layout_decl (decl
, 0);
3608 if (DECL_SIZE (decl
) == 0
3609 /* Don't give an error if we already gave one earlier. */
3610 && TREE_TYPE (decl
) != error_mark_node
3611 && (TREE_STATIC (decl
)
3612 /* A static variable with an incomplete type
3613 is an error if it is initialized.
3614 Also if it is not file scope.
3615 Otherwise, let it through, but if it is not `extern'
3616 then it may cause an error message later. */
3617 ? (DECL_INITIAL (decl
) != 0
3618 || !DECL_FILE_SCOPE_P (decl
))
3619 /* An automatic variable with an incomplete type
3621 : !DECL_EXTERNAL (decl
)))
3623 error ("storage size of %q+D isn%'t known", decl
);
3624 TREE_TYPE (decl
) = error_mark_node
;
3627 if ((DECL_EXTERNAL (decl
) || TREE_STATIC (decl
))
3628 && DECL_SIZE (decl
) != 0)
3630 if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
3631 constant_expression_warning (DECL_SIZE (decl
));
3634 error ("storage size of %q+D isn%'t constant", decl
);
3635 TREE_TYPE (decl
) = error_mark_node
;
3639 if (TREE_USED (type
))
3640 TREE_USED (decl
) = 1;
3643 /* If this is a function and an assembler name is specified, reset DECL_RTL
3644 so we can give it its new name. Also, update built_in_decls if it
3645 was a normal built-in. */
3646 if (TREE_CODE (decl
) == FUNCTION_DECL
&& asmspec
)
3648 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
)
3649 set_builtin_user_assembler_name (decl
, asmspec
);
3650 set_user_assembler_name (decl
, asmspec
);
3653 /* If #pragma weak was used, mark the decl weak now. */
3654 maybe_apply_pragma_weak (decl
);
3656 /* Output the assembler code and/or RTL code for variables and functions,
3657 unless the type is an undefined structure or union.
3658 If not, it will get done when the type is completed. */
3660 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
)
3662 /* Determine the ELF visibility. */
3663 if (TREE_PUBLIC (decl
))
3664 c_determine_visibility (decl
);
3666 /* This is a no-op in c-lang.c or something real in objc-act.c. */
3667 if (c_dialect_objc ())
3668 objc_check_decl (decl
);
3672 /* If this is not a static variable, issue a warning.
3673 It doesn't make any sense to give an ASMSPEC for an
3674 ordinary, non-register local variable. Historically,
3675 GCC has accepted -- but ignored -- the ASMSPEC in
3677 if (!DECL_FILE_SCOPE_P (decl
)
3678 && TREE_CODE (decl
) == VAR_DECL
3679 && !C_DECL_REGISTER (decl
)
3680 && !TREE_STATIC (decl
))
3681 warning (0, "ignoring asm-specifier for non-static local "
3682 "variable %q+D", decl
);
3684 set_user_assembler_name (decl
, asmspec
);
3687 if (DECL_FILE_SCOPE_P (decl
))
3689 if (DECL_INITIAL (decl
) == NULL_TREE
3690 || DECL_INITIAL (decl
) == error_mark_node
)
3691 /* Don't output anything
3692 when a tentative file-scope definition is seen.
3693 But at end of compilation, do output code for them. */
3694 DECL_DEFER_OUTPUT (decl
) = 1;
3695 rest_of_decl_compilation (decl
, true, 0);
3699 /* In conjunction with an ASMSPEC, the `register'
3700 keyword indicates that we should place the variable
3701 in a particular register. */
3702 if (asmspec
&& C_DECL_REGISTER (decl
))
3704 DECL_HARD_REGISTER (decl
) = 1;
3705 /* This cannot be done for a structure with volatile
3706 fields, on which DECL_REGISTER will have been
3708 if (!DECL_REGISTER (decl
))
3709 error ("cannot put object with volatile field into register");
3712 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3714 /* If we're building a variable sized type, and we might be
3715 reachable other than via the top of the current binding
3716 level, then create a new BIND_EXPR so that we deallocate
3717 the object at the right time. */
3718 /* Note that DECL_SIZE can be null due to errors. */
3719 if (DECL_SIZE (decl
)
3720 && !TREE_CONSTANT (DECL_SIZE (decl
))
3721 && STATEMENT_LIST_HAS_LABEL (cur_stmt_list
))
3724 bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
3725 TREE_SIDE_EFFECTS (bind
) = 1;
3727 BIND_EXPR_BODY (bind
) = push_stmt_list ();
3729 add_stmt (build_stmt (DECL_EXPR
, decl
));
3734 if (!DECL_FILE_SCOPE_P (decl
))
3736 /* Recompute the RTL of a local array now
3737 if it used to be an incomplete type. */
3739 && !TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
))
3741 /* If we used it already as memory, it must stay in memory. */
3742 TREE_ADDRESSABLE (decl
) = TREE_USED (decl
);
3743 /* If it's still incomplete now, no init will save it. */
3744 if (DECL_SIZE (decl
) == 0)
3745 DECL_INITIAL (decl
) = 0;
3750 if (TREE_CODE (decl
) == TYPE_DECL
)
3752 if (!DECL_FILE_SCOPE_P (decl
)
3753 && variably_modified_type_p (TREE_TYPE (decl
), NULL_TREE
))
3754 add_stmt (build_stmt (DECL_EXPR
, decl
));
3756 rest_of_decl_compilation (decl
, DECL_FILE_SCOPE_P (decl
), 0);
3759 /* At the end of a declaration, throw away any variable type sizes
3760 of types defined inside that declaration. There is no use
3761 computing them in the following function definition. */
3762 if (current_scope
== file_scope
)
3763 get_pending_sizes ();
3765 /* Install a cleanup (aka destructor) if one was given. */
3766 if (TREE_CODE (decl
) == VAR_DECL
&& !TREE_STATIC (decl
))
3768 tree attr
= lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl
));
3771 tree cleanup_id
= TREE_VALUE (TREE_VALUE (attr
));
3772 tree cleanup_decl
= lookup_name (cleanup_id
);
3776 /* Build "cleanup(&decl)" for the destructor. */
3777 cleanup
= build_unary_op (input_location
, ADDR_EXPR
, decl
, 0);
3778 vec
= VEC_alloc (tree
, gc
, 1);
3779 VEC_quick_push (tree
, vec
, cleanup
);
3780 cleanup
= build_function_call_vec (cleanup_decl
, vec
, NULL
);
3781 VEC_free (tree
, gc
, vec
);
3783 /* Don't warn about decl unused; the cleanup uses it. */
3784 TREE_USED (decl
) = 1;
3785 TREE_USED (cleanup_decl
) = 1;
3787 /* Initialize EH, if we've been told to do so. */
3788 c_maybe_initialize_eh ();
3790 push_cleanup (decl
, cleanup
, false);
3795 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */
3798 grokparm (const struct c_parm
*parm
)
3800 tree attrs
= parm
->attrs
;
3801 tree decl
= grokdeclarator (parm
->declarator
, parm
->specs
, PARM
, false,
3802 NULL
, &attrs
, NULL
, NULL
, DEPRECATED_NORMAL
);
3804 decl_attributes (&decl
, attrs
, 0);
3809 /* Given a parsed parameter declaration, decode it into a PARM_DECL
3810 and push that on the current scope. */
3813 push_parm_decl (const struct c_parm
*parm
)
3815 tree attrs
= parm
->attrs
;
3818 decl
= grokdeclarator (parm
->declarator
, parm
->specs
, PARM
, false, NULL
,
3819 &attrs
, NULL
, NULL
, DEPRECATED_NORMAL
);
3820 decl_attributes (&decl
, attrs
, 0);
3822 decl
= pushdecl (decl
);
3824 finish_decl (decl
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
3827 /* Mark all the parameter declarations to date as forward decls.
3828 Also diagnose use of this extension. */
3831 mark_forward_parm_decls (void)
3833 struct c_binding
*b
;
3835 if (pedantic
&& !current_scope
->warned_forward_parm_decls
)
3837 pedwarn (input_location
, OPT_pedantic
,
3838 "ISO C forbids forward parameter declarations");
3839 current_scope
->warned_forward_parm_decls
= true;
3842 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
3843 if (TREE_CODE (b
->decl
) == PARM_DECL
)
3844 TREE_ASM_WRITTEN (b
->decl
) = 1;
3847 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3848 literal, which may be an incomplete array type completed by the
3849 initializer; INIT is a CONSTRUCTOR that initializes the compound
3850 literal. NON_CONST is true if the initializers contain something
3851 that cannot occur in a constant expression. */
3854 build_compound_literal (tree type
, tree init
, bool non_const
)
3856 /* We do not use start_decl here because we have a type, not a declarator;
3857 and do not use finish_decl because the decl should be stored inside
3858 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
3863 if (type
== error_mark_node
)
3864 return error_mark_node
;
3866 decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
3867 DECL_EXTERNAL (decl
) = 0;
3868 TREE_PUBLIC (decl
) = 0;
3869 TREE_STATIC (decl
) = (current_scope
== file_scope
);
3870 DECL_CONTEXT (decl
) = current_function_decl
;
3871 TREE_USED (decl
) = 1;
3872 TREE_TYPE (decl
) = type
;
3873 TREE_READONLY (decl
) = TYPE_READONLY (type
);
3874 store_init_value (decl
, init
, NULL_TREE
);
3876 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
3878 int failure
= complete_array_type (&TREE_TYPE (decl
),
3879 DECL_INITIAL (decl
), true);
3880 gcc_assert (!failure
);
3882 type
= TREE_TYPE (decl
);
3883 TREE_TYPE (DECL_INITIAL (decl
)) = type
;
3886 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
3887 return error_mark_node
;
3889 stmt
= build_stmt (DECL_EXPR
, decl
);
3890 complit
= build1 (COMPOUND_LITERAL_EXPR
, type
, stmt
);
3891 TREE_SIDE_EFFECTS (complit
) = 1;
3893 layout_decl (decl
, 0);
3895 if (TREE_STATIC (decl
))
3897 /* This decl needs a name for the assembler output. */
3898 set_compound_literal_name (decl
);
3899 DECL_DEFER_OUTPUT (decl
) = 1;
3900 DECL_COMDAT (decl
) = 1;
3901 DECL_ARTIFICIAL (decl
) = 1;
3902 DECL_IGNORED_P (decl
) = 1;
3904 rest_of_decl_compilation (decl
, 1, 0);
3909 complit
= build2 (C_MAYBE_CONST_EXPR
, type
, NULL
, complit
);
3910 C_MAYBE_CONST_EXPR_NON_CONST (complit
) = 1;
3916 /* Check the type of a compound literal. Here we just check that it
3917 is valid for C++. */
3920 check_compound_literal_type (struct c_type_name
*type_name
, location_t loc
)
3922 if (warn_cxx_compat
&& type_name
->specs
->tag_defined_p
)
3923 warning_at (loc
, OPT_Wc___compat
,
3924 "defining a type in a compound literal is invalid in C++");
3927 /* Determine whether TYPE is a structure with a flexible array member,
3928 or a union containing such a structure (possibly recursively). */
3931 flexible_array_type_p (tree type
)
3934 switch (TREE_CODE (type
))
3937 x
= TYPE_FIELDS (type
);
3940 while (TREE_CHAIN (x
) != NULL_TREE
)
3942 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
3943 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
3944 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
3945 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
3949 for (x
= TYPE_FIELDS (type
); x
!= NULL_TREE
; x
= TREE_CHAIN (x
))
3951 if (flexible_array_type_p (TREE_TYPE (x
)))
3960 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3961 replacing with appropriate values if they are invalid. */
3963 check_bitfield_type_and_width (tree
*type
, tree
*width
, tree orig_name
)
3966 unsigned int max_width
;
3967 unsigned HOST_WIDE_INT w
;
3968 const char *name
= (orig_name
3969 ? identifier_to_locale (IDENTIFIER_POINTER (orig_name
))
3970 : _("<anonymous>"));
3972 /* Detect and ignore out of range field width and process valid
3974 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width
))
3975 || TREE_CODE (*width
) != INTEGER_CST
)
3977 error ("bit-field %qs width not an integer constant", name
);
3978 *width
= integer_one_node
;
3982 constant_expression_warning (*width
);
3983 if (tree_int_cst_sgn (*width
) < 0)
3985 error ("negative width in bit-field %qs", name
);
3986 *width
= integer_one_node
;
3988 else if (integer_zerop (*width
) && orig_name
)
3990 error ("zero width for bit-field %qs", name
);
3991 *width
= integer_one_node
;
3995 /* Detect invalid bit-field type. */
3996 if (TREE_CODE (*type
) != INTEGER_TYPE
3997 && TREE_CODE (*type
) != BOOLEAN_TYPE
3998 && TREE_CODE (*type
) != ENUMERAL_TYPE
)
4000 error ("bit-field %qs has invalid type", name
);
4001 *type
= unsigned_type_node
;
4004 type_mv
= TYPE_MAIN_VARIANT (*type
);
4005 if (!in_system_header
4006 && type_mv
!= integer_type_node
4007 && type_mv
!= unsigned_type_node
4008 && type_mv
!= boolean_type_node
)
4009 pedwarn (input_location
, OPT_pedantic
,
4010 "type of bit-field %qs is a GCC extension", name
);
4012 max_width
= TYPE_PRECISION (*type
);
4014 if (0 < compare_tree_int (*width
, max_width
))
4016 error ("width of %qs exceeds its type", name
);
4018 *width
= build_int_cst (NULL_TREE
, w
);
4021 w
= tree_low_cst (*width
, 1);
4023 if (TREE_CODE (*type
) == ENUMERAL_TYPE
)
4025 struct lang_type
*lt
= TYPE_LANG_SPECIFIC (*type
);
4027 || w
< tree_int_cst_min_precision (lt
->enum_min
, TYPE_UNSIGNED (*type
))
4028 || w
< tree_int_cst_min_precision (lt
->enum_max
, TYPE_UNSIGNED (*type
)))
4029 warning (0, "%qs is narrower than values of its type", name
);
4035 /* Print warning about variable length array if necessary. */
4038 warn_variable_length_array (tree name
, tree size
)
4040 int const_size
= TREE_CONSTANT (size
);
4042 if (!flag_isoc99
&& pedantic
&& warn_vla
!= 0)
4047 pedwarn (input_location
, OPT_Wvla
,
4048 "ISO C90 forbids array %qE whose size "
4049 "can%'t be evaluated",
4052 pedwarn (input_location
, OPT_Wvla
, "ISO C90 forbids array whose size "
4053 "can%'t be evaluated");
4058 pedwarn (input_location
, OPT_Wvla
,
4059 "ISO C90 forbids variable length array %qE",
4062 pedwarn (input_location
, OPT_Wvla
, "ISO C90 forbids variable length array");
4065 else if (warn_vla
> 0)
4071 "the size of array %qE can"
4072 "%'t be evaluated", name
);
4075 "the size of array can %'t be evaluated");
4081 "variable length array %qE is used",
4085 "variable length array is used");
4090 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR to
4091 serve as the actual size-expression for a type or decl. This is
4092 like variable_size in stor-layout.c, but we make global_bindings_p
4093 return negative to avoid calls to that function from outside the
4094 front end resulting in errors at file scope, then call this version
4095 instead from front-end code. */
4098 c_variable_size (tree size
)
4102 if (TREE_CONSTANT (size
))
4105 size
= save_expr (size
);
4107 save
= skip_simple_arithmetic (size
);
4109 if (cfun
&& cfun
->dont_save_pending_sizes_p
)
4112 if (!global_bindings_p ())
4113 put_pending_size (save
);
4118 /* Given declspecs and a declarator,
4119 determine the name and type of the object declared
4120 and construct a ..._DECL node for it.
4121 (In one case we can return a ..._TYPE node instead.
4122 For invalid input we sometimes return 0.)
4124 DECLSPECS is a c_declspecs structure for the declaration specifiers.
4126 DECL_CONTEXT says which syntactic context this declaration is in:
4127 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
4128 FUNCDEF for a function definition. Like NORMAL but a few different
4129 error messages in each case. Return value may be zero meaning
4130 this definition is too screwy to try to parse.
4131 PARM for a parameter declaration (either within a function prototype
4132 or before a function body). Make a PARM_DECL, or return void_type_node.
4133 TYPENAME if for a typename (in a cast or sizeof).
4134 Don't make a DECL node; just return the ..._TYPE node.
4135 FIELD for a struct or union field; make a FIELD_DECL.
4136 INITIALIZED is true if the decl has an initializer.
4137 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
4138 representing the width of the bit-field.
4139 DECL_ATTRS points to the list of attributes that should be added to this
4140 decl. Any nested attributes that belong on the decl itself will be
4142 If EXPR is not NULL, any expressions that need to be evaluated as
4143 part of evaluating variably modified types will be stored in *EXPR.
4144 If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
4145 set to indicate whether operands in *EXPR can be used in constant
4147 DEPRECATED_STATE is a deprecated_states value indicating whether
4148 deprecation warnings should be suppressed.
4150 In the TYPENAME case, DECLARATOR is really an absolute declarator.
4151 It may also be so in the PARM case, for a prototype where the
4152 argument type is specified but not the name.
4154 This function is where the complicated C meanings of `static'
4155 and `extern' are interpreted. */
4158 grokdeclarator (const struct c_declarator
*declarator
,
4159 struct c_declspecs
*declspecs
,
4160 enum decl_context decl_context
, bool initialized
, tree
*width
,
4161 tree
*decl_attrs
, tree
*expr
, bool *expr_const_operands
,
4162 enum deprecated_states deprecated_state
)
4164 tree type
= declspecs
->type
;
4165 bool threadp
= declspecs
->thread_p
;
4166 enum c_storage_class storage_class
= declspecs
->storage_class
;
4170 int type_quals
= TYPE_UNQUALIFIED
;
4171 tree name
= NULL_TREE
;
4172 bool funcdef_flag
= false;
4173 bool funcdef_syntax
= false;
4174 int size_varies
= 0;
4175 tree decl_attr
= declspecs
->decl_attr
;
4176 int array_ptr_quals
= TYPE_UNQUALIFIED
;
4177 tree array_ptr_attrs
= NULL_TREE
;
4178 int array_parm_static
= 0;
4179 bool array_parm_vla_unspec_p
= false;
4180 tree returned_attrs
= NULL_TREE
;
4181 bool bitfield
= width
!= NULL
;
4183 struct c_arg_info
*arg_info
= 0;
4185 bool expr_const_operands_dummy
;
4189 if (expr_const_operands
== NULL
)
4190 expr_const_operands
= &expr_const_operands_dummy
;
4192 *expr
= declspecs
->expr
;
4193 *expr_const_operands
= declspecs
->expr_const_operands
;
4195 if (decl_context
== FUNCDEF
)
4196 funcdef_flag
= true, decl_context
= NORMAL
;
4198 /* Look inside a declarator for the name being declared
4199 and get it as an IDENTIFIER_NODE, for an error message. */
4201 const struct c_declarator
*decl
= declarator
;
4209 funcdef_syntax
= (decl
->kind
== cdk_function
);
4210 decl
= decl
->declarator
;
4214 decl
= decl
->declarator
;
4228 gcc_assert (decl_context
== PARM
4229 || decl_context
== TYPENAME
4230 || (decl_context
== FIELD
4231 && declarator
->kind
== cdk_id
));
4232 gcc_assert (!initialized
);
4236 /* A function definition's declarator must have the form of
4237 a function declarator. */
4239 if (funcdef_flag
&& !funcdef_syntax
)
4242 /* If this looks like a function definition, make it one,
4243 even if it occurs where parms are expected.
4244 Then store_parm_decls will reject it and not use it as a parm. */
4245 if (decl_context
== NORMAL
&& !funcdef_flag
&& current_scope
->parm_flag
)
4246 decl_context
= PARM
;
4248 if (declspecs
->deprecated_p
&& deprecated_state
!= DEPRECATED_SUPPRESS
)
4249 warn_deprecated_use (declspecs
->type
, declspecs
->decl_attr
);
4251 if ((decl_context
== NORMAL
|| decl_context
== FIELD
)
4252 && current_scope
== file_scope
4253 && variably_modified_type_p (type
, NULL_TREE
))
4256 error ("variably modified %qE at file scope", name
);
4258 error ("variably modified field at file scope");
4259 type
= integer_type_node
;
4262 size_varies
= C_TYPE_VARIABLE_SIZE (type
);
4264 /* Diagnose defaulting to "int". */
4266 if (declspecs
->default_int_p
&& !in_system_header
)
4268 /* Issue a warning if this is an ISO C 99 program or if
4269 -Wreturn-type and this is a function, or if -Wimplicit;
4270 prefer the former warning since it is more explicit. */
4271 if ((warn_implicit_int
|| warn_return_type
|| flag_isoc99
)
4273 warn_about_return_type
= 1;
4277 pedwarn_c99 (input_location
, flag_isoc99
? 0 : OPT_Wimplicit_int
,
4278 "type defaults to %<int%> in declaration of %qE",
4281 pedwarn_c99 (input_location
, flag_isoc99
? 0 : OPT_Wimplicit_int
,
4282 "type defaults to %<int%> in type name");
4286 /* Adjust the type if a bit-field is being declared,
4287 -funsigned-bitfields applied and the type is not explicitly
4289 if (bitfield
&& !flag_signed_bitfields
&& !declspecs
->explicit_signed_p
4290 && TREE_CODE (type
) == INTEGER_TYPE
)
4291 type
= unsigned_type_for (type
);
4293 /* Figure out the type qualifiers for the declaration. There are
4294 two ways a declaration can become qualified. One is something
4295 like `const int i' where the `const' is explicit. Another is
4296 something like `typedef const int CI; CI i' where the type of the
4297 declaration contains the `const'. A third possibility is that
4298 there is a type qualifier on the element type of a typedefed
4299 array type, in which case we should extract that qualifier so
4300 that c_apply_type_quals_to_decl receives the full list of
4301 qualifiers to work with (C90 is not entirely clear about whether
4302 duplicate qualifiers should be diagnosed in this case, but it
4303 seems most appropriate to do so). */
4304 element_type
= strip_array_types (type
);
4305 constp
= declspecs
->const_p
+ TYPE_READONLY (element_type
);
4306 restrictp
= declspecs
->restrict_p
+ TYPE_RESTRICT (element_type
);
4307 volatilep
= declspecs
->volatile_p
+ TYPE_VOLATILE (element_type
);
4308 if (pedantic
&& !flag_isoc99
)
4311 pedwarn (input_location
, OPT_pedantic
, "duplicate %<const%>");
4313 pedwarn (input_location
, OPT_pedantic
, "duplicate %<restrict%>");
4315 pedwarn (input_location
, OPT_pedantic
, "duplicate %<volatile%>");
4317 if (!flag_gen_aux_info
&& (TYPE_QUALS (element_type
)))
4318 type
= TYPE_MAIN_VARIANT (type
);
4319 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4320 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4321 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4323 /* Warn about storage classes that are invalid for certain
4324 kinds of declarations (parameters, typenames, etc.). */
4328 || storage_class
== csc_auto
4329 || storage_class
== csc_register
4330 || storage_class
== csc_typedef
))
4332 if (storage_class
== csc_auto
)
4333 pedwarn (input_location
,
4334 (current_scope
== file_scope
) ? 0 : OPT_pedantic
,
4335 "function definition declared %<auto%>");
4336 if (storage_class
== csc_register
)
4337 error ("function definition declared %<register%>");
4338 if (storage_class
== csc_typedef
)
4339 error ("function definition declared %<typedef%>");
4341 error ("function definition declared %<__thread%>");
4343 if (storage_class
== csc_auto
4344 || storage_class
== csc_register
4345 || storage_class
== csc_typedef
)
4346 storage_class
= csc_none
;
4348 else if (decl_context
!= NORMAL
&& (storage_class
!= csc_none
|| threadp
))
4350 if (decl_context
== PARM
&& storage_class
== csc_register
)
4354 switch (decl_context
)
4358 error ("storage class specified for structure field %qE",
4361 error ("storage class specified for structure field");
4365 error ("storage class specified for parameter %qE", name
);
4367 error ("storage class specified for unnamed parameter");
4370 error ("storage class specified for typename");
4373 storage_class
= csc_none
;
4377 else if (storage_class
== csc_extern
4381 /* 'extern' with initialization is invalid if not at file scope. */
4382 if (current_scope
== file_scope
)
4384 /* It is fine to have 'extern const' when compiling at C
4385 and C++ intersection. */
4386 if (!(warn_cxx_compat
&& constp
))
4387 warning (0, "%qE initialized and declared %<extern%>", name
);
4390 error ("%qE has both %<extern%> and initializer", name
);
4392 else if (current_scope
== file_scope
)
4394 if (storage_class
== csc_auto
)
4395 error ("file-scope declaration of %qE specifies %<auto%>", name
);
4396 if (pedantic
&& storage_class
== csc_register
)
4397 pedwarn (input_location
, OPT_pedantic
,
4398 "file-scope declaration of %qE specifies %<register%>", name
);
4402 if (storage_class
== csc_extern
&& funcdef_flag
)
4403 error ("nested function %qE declared %<extern%>", name
);
4404 else if (threadp
&& storage_class
== csc_none
)
4406 error ("function-scope %qE implicitly auto and declared "
4413 /* Now figure out the structure of the declarator proper.
4414 Descend through it, creating more complex types, until we reach
4415 the declared identifier (or NULL_TREE, in an absolute declarator).
4416 At each stage we maintain an unqualified version of the type
4417 together with any qualifiers that should be applied to it with
4418 c_build_qualified_type; this way, array types including
4419 multidimensional array types are first built up in unqualified
4420 form and then the qualified form is created with
4421 TYPE_MAIN_VARIANT pointing to the unqualified form. */
4423 while (declarator
&& declarator
->kind
!= cdk_id
)
4425 if (type
== error_mark_node
)
4427 declarator
= declarator
->declarator
;
4431 /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
4432 a cdk_pointer (for *...),
4433 a cdk_function (for ...(...)),
4434 a cdk_attrs (for nested attributes),
4435 or a cdk_id (for the name being declared
4436 or the place in an absolute declarator
4437 where the name was omitted).
4438 For the last case, we have just exited the loop.
4440 At this point, TYPE is the type of elements of an array,
4441 or for a function to return, or for a pointer to point to.
4442 After this sequence of ifs, TYPE is the type of the
4443 array or function or pointer, and DECLARATOR has had its
4444 outermost layer removed. */
4446 if (array_ptr_quals
!= TYPE_UNQUALIFIED
4447 || array_ptr_attrs
!= NULL_TREE
4448 || array_parm_static
)
4450 /* Only the innermost declarator (making a parameter be of
4451 array type which is converted to pointer type)
4452 may have static or type qualifiers. */
4453 error ("static or type qualifiers in non-parameter array declarator");
4454 array_ptr_quals
= TYPE_UNQUALIFIED
;
4455 array_ptr_attrs
= NULL_TREE
;
4456 array_parm_static
= 0;
4459 switch (declarator
->kind
)
4463 /* A declarator with embedded attributes. */
4464 tree attrs
= declarator
->u
.attrs
;
4465 const struct c_declarator
*inner_decl
;
4467 declarator
= declarator
->declarator
;
4468 inner_decl
= declarator
;
4469 while (inner_decl
->kind
== cdk_attrs
)
4470 inner_decl
= inner_decl
->declarator
;
4471 if (inner_decl
->kind
== cdk_id
)
4472 attr_flags
|= (int) ATTR_FLAG_DECL_NEXT
;
4473 else if (inner_decl
->kind
== cdk_function
)
4474 attr_flags
|= (int) ATTR_FLAG_FUNCTION_NEXT
;
4475 else if (inner_decl
->kind
== cdk_array
)
4476 attr_flags
|= (int) ATTR_FLAG_ARRAY_NEXT
;
4477 returned_attrs
= decl_attributes (&type
,
4478 chainon (returned_attrs
, attrs
),
4484 tree itype
= NULL_TREE
;
4485 tree size
= declarator
->u
.array
.dimen
;
4486 /* The index is a signed object `sizetype' bits wide. */
4487 tree index_type
= c_common_signed_type (sizetype
);
4489 array_ptr_quals
= declarator
->u
.array
.quals
;
4490 array_ptr_attrs
= declarator
->u
.array
.attrs
;
4491 array_parm_static
= declarator
->u
.array
.static_p
;
4492 array_parm_vla_unspec_p
= declarator
->u
.array
.vla_unspec_p
;
4494 declarator
= declarator
->declarator
;
4496 /* Check for some types that there cannot be arrays of. */
4498 if (VOID_TYPE_P (type
))
4501 error ("declaration of %qE as array of voids", name
);
4503 error ("declaration of type name as array of voids");
4504 type
= error_mark_node
;
4507 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4510 error ("declaration of %qE as array of functions", name
);
4512 error ("declaration of type name as array of functions");
4513 type
= error_mark_node
;
4516 if (pedantic
&& !in_system_header
&& flexible_array_type_p (type
))
4517 pedwarn (input_location
, OPT_pedantic
,
4518 "invalid use of structure with flexible array member");
4520 if (size
== error_mark_node
)
4521 type
= error_mark_node
;
4523 if (type
== error_mark_node
)
4526 /* If size was specified, set ITYPE to a range-type for
4527 that size. Otherwise, ITYPE remains null. finish_decl
4528 may figure it out from an initial value. */
4532 bool size_maybe_const
= true;
4533 bool size_int_const
= (TREE_CODE (size
) == INTEGER_CST
4534 && !TREE_OVERFLOW (size
));
4535 bool this_size_varies
= false;
4537 /* Strip NON_LVALUE_EXPRs since we aren't using as an
4539 STRIP_TYPE_NOPS (size
);
4541 if (!INTEGRAL_TYPE_P (TREE_TYPE (size
)))
4544 error ("size of array %qE has non-integer type", name
);
4546 error ("size of unnamed array has non-integer type");
4547 size
= integer_one_node
;
4550 size
= c_fully_fold (size
, false, &size_maybe_const
);
4552 if (pedantic
&& size_maybe_const
&& integer_zerop (size
))
4555 pedwarn (input_location
, OPT_pedantic
,
4556 "ISO C forbids zero-size array %qE", name
);
4558 pedwarn (input_location
, OPT_pedantic
,
4559 "ISO C forbids zero-size array");
4562 if (TREE_CODE (size
) == INTEGER_CST
&& size_maybe_const
)
4564 constant_expression_warning (size
);
4565 if (tree_int_cst_sgn (size
) < 0)
4568 error ("size of array %qE is negative", name
);
4570 error ("size of unnamed array is negative");
4571 size
= integer_one_node
;
4573 /* Handle a size folded to an integer constant but
4574 not an integer constant expression. */
4575 if (!size_int_const
)
4577 /* If this is a file scope declaration of an
4578 ordinary identifier, this is invalid code;
4579 diagnosing it here and not subsequently
4580 treating the type as variable-length avoids
4581 more confusing diagnostics later. */
4582 if ((decl_context
== NORMAL
|| decl_context
== FIELD
)
4583 && current_scope
== file_scope
)
4584 pedwarn (input_location
, 0,
4585 "variably modified %qE at file scope",
4588 this_size_varies
= size_varies
= 1;
4589 warn_variable_length_array (name
, size
);
4592 else if ((decl_context
== NORMAL
|| decl_context
== FIELD
)
4593 && current_scope
== file_scope
)
4595 error ("variably modified %qE at file scope", name
);
4596 size
= integer_one_node
;
4600 /* Make sure the array size remains visibly
4601 nonconstant even if it is (eg) a const variable
4602 with known value. */
4603 this_size_varies
= size_varies
= 1;
4604 warn_variable_length_array (name
, size
);
4607 if (integer_zerop (size
) && !this_size_varies
)
4609 /* A zero-length array cannot be represented with
4610 an unsigned index type, which is what we'll
4611 get with build_index_type. Create an
4612 open-ended range instead. */
4613 itype
= build_range_type (sizetype
, size
, NULL_TREE
);
4617 /* Arrange for the SAVE_EXPR on the inside of the
4618 MINUS_EXPR, which allows the -1 to get folded
4619 with the +1 that happens when building TYPE_SIZE. */
4621 size
= c_variable_size (size
);
4622 if (this_size_varies
&& TREE_CODE (size
) == INTEGER_CST
)
4623 size
= build2 (COMPOUND_EXPR
, TREE_TYPE (size
),
4624 integer_zero_node
, size
);
4626 /* Compute the maximum valid index, that is, size
4627 - 1. Do the calculation in index_type, so that
4628 if it is a variable the computations will be
4629 done in the proper mode. */
4630 itype
= fold_build2 (MINUS_EXPR
, index_type
,
4631 convert (index_type
, size
),
4632 convert (index_type
,
4635 /* If that overflowed, the array is too big. ???
4636 While a size of INT_MAX+1 technically shouldn't
4637 cause an overflow (because we subtract 1), the
4638 overflow is recorded during the conversion to
4639 index_type, before the subtraction. Handling
4640 this case seems like an unnecessary
4642 if (TREE_CODE (itype
) == INTEGER_CST
4643 && TREE_OVERFLOW (itype
))
4646 error ("size of array %qE is too large", name
);
4648 error ("size of unnamed array is too large");
4649 type
= error_mark_node
;
4653 itype
= build_index_type (itype
);
4655 if (this_size_varies
)
4658 *expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (size
),
4662 *expr_const_operands
&= size_maybe_const
;
4665 else if (decl_context
== FIELD
)
4667 bool flexible_array_member
= false;
4668 if (array_parm_vla_unspec_p
)
4669 /* Field names can in fact have function prototype
4670 scope so [*] is disallowed here through making
4671 the field variably modified, not through being
4672 something other than a declaration with function
4677 const struct c_declarator
*t
= declarator
;
4678 while (t
->kind
== cdk_attrs
)
4680 flexible_array_member
= (t
->kind
== cdk_id
);
4682 if (flexible_array_member
4683 && pedantic
&& !flag_isoc99
&& !in_system_header
)
4684 pedwarn (input_location
, OPT_pedantic
,
4685 "ISO C90 does not support flexible array members");
4687 /* ISO C99 Flexible array members are effectively
4688 identical to GCC's zero-length array extension. */
4689 if (flexible_array_member
|| array_parm_vla_unspec_p
)
4690 itype
= build_range_type (sizetype
, size_zero_node
,
4693 else if (decl_context
== PARM
)
4695 if (array_parm_vla_unspec_p
)
4697 itype
= build_range_type (sizetype
, size_zero_node
, NULL_TREE
);
4701 else if (decl_context
== TYPENAME
)
4703 if (array_parm_vla_unspec_p
)
4706 warning (0, "%<[*]%> not in a declaration");
4707 /* We use this to avoid messing up with incomplete
4708 array types of the same type, that would
4709 otherwise be modified below. */
4710 itype
= build_range_type (sizetype
, size_zero_node
,
4716 /* Complain about arrays of incomplete types. */
4717 if (!COMPLETE_TYPE_P (type
))
4719 error ("array type has incomplete element type");
4720 type
= error_mark_node
;
4723 /* When itype is NULL, a shared incomplete array type is
4724 returned for all array of a given type. Elsewhere we
4725 make sure we don't complete that type before copying
4726 it, but here we want to make sure we don't ever
4727 modify the shared type, so we gcc_assert (itype)
4729 type
= build_array_type (type
, itype
);
4731 if (type
!= error_mark_node
)
4735 /* It is ok to modify type here even if itype is
4736 NULL: if size_varies, we're in a
4737 multi-dimensional array and the inner type has
4738 variable size, so the enclosing shared array type
4740 if (size
&& TREE_CODE (size
) == INTEGER_CST
)
4742 = build_distinct_type_copy (TYPE_MAIN_VARIANT (type
));
4743 C_TYPE_VARIABLE_SIZE (type
) = 1;
4746 /* The GCC extension for zero-length arrays differs from
4747 ISO flexible array members in that sizeof yields
4749 if (size
&& integer_zerop (size
))
4752 TYPE_SIZE (type
) = bitsize_zero_node
;
4753 TYPE_SIZE_UNIT (type
) = size_zero_node
;
4755 if (array_parm_vla_unspec_p
)
4758 /* The type is complete. C99 6.7.5.2p4 */
4759 TYPE_SIZE (type
) = bitsize_zero_node
;
4760 TYPE_SIZE_UNIT (type
) = size_zero_node
;
4764 if (decl_context
!= PARM
4765 && (array_ptr_quals
!= TYPE_UNQUALIFIED
4766 || array_ptr_attrs
!= NULL_TREE
4767 || array_parm_static
))
4769 error ("static or type qualifiers in non-parameter array declarator");
4770 array_ptr_quals
= TYPE_UNQUALIFIED
;
4771 array_ptr_attrs
= NULL_TREE
;
4772 array_parm_static
= 0;
4778 /* Say it's a definition only for the declarator closest
4779 to the identifier, apart possibly from some
4781 bool really_funcdef
= false;
4785 const struct c_declarator
*t
= declarator
->declarator
;
4786 while (t
->kind
== cdk_attrs
)
4788 really_funcdef
= (t
->kind
== cdk_id
);
4791 /* Declaring a function type. Make sure we have a valid
4792 type for the function to return. */
4793 if (type
== error_mark_node
)
4798 /* Warn about some types functions can't return. */
4799 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4802 error ("%qE declared as function returning a function",
4805 error ("type name declared as function "
4806 "returning a function");
4807 type
= integer_type_node
;
4809 if (TREE_CODE (type
) == ARRAY_TYPE
)
4812 error ("%qE declared as function returning an array", name
);
4814 error ("type name declared as function returning an array");
4815 type
= integer_type_node
;
4818 /* Construct the function type and go to the next
4819 inner layer of declarator. */
4820 arg_info
= declarator
->u
.arg_info
;
4821 arg_types
= grokparms (arg_info
, really_funcdef
);
4823 put_pending_sizes (arg_info
->pending_sizes
);
4825 /* Type qualifiers before the return type of the function
4826 qualify the return type, not the function type. */
4829 /* Type qualifiers on a function return type are
4830 normally permitted by the standard but have no
4831 effect, so give a warning at -Wreturn-type.
4832 Qualifiers on a void return type are banned on
4833 function definitions in ISO C; GCC used to used
4834 them for noreturn functions. */
4835 if (VOID_TYPE_P (type
) && really_funcdef
)
4836 pedwarn (input_location
, 0,
4837 "function definition has qualified void return type");
4839 warning (OPT_Wignored_qualifiers
,
4840 "type qualifiers ignored on function return type");
4842 type
= c_build_qualified_type (type
, type_quals
);
4844 type_quals
= TYPE_UNQUALIFIED
;
4846 type
= build_function_type (type
, arg_types
);
4847 declarator
= declarator
->declarator
;
4849 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4850 the formal parameter list of this FUNCTION_TYPE to point to
4851 the FUNCTION_TYPE node itself. */
4855 for (link
= arg_info
->tags
;
4857 link
= TREE_CHAIN (link
))
4858 TYPE_CONTEXT (TREE_VALUE (link
)) = type
;
4864 /* Merge any constancy or volatility into the target type
4867 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4869 pedwarn (input_location
, OPT_pedantic
,
4870 "ISO C forbids qualified function types");
4872 type
= c_build_qualified_type (type
, type_quals
);
4875 /* When the pointed-to type involves components of variable size,
4876 care must be taken to ensure that the size evaluation code is
4877 emitted early enough to dominate all the possible later uses
4878 and late enough for the variables on which it depends to have
4881 This is expected to happen automatically when the pointed-to
4882 type has a name/declaration of it's own, but special attention
4883 is required if the type is anonymous.
4885 We handle the NORMAL and FIELD contexts here by attaching an
4886 artificial TYPE_DECL to such pointed-to type. This forces the
4887 sizes evaluation at a safe point and ensures it is not deferred
4888 until e.g. within a deeper conditional context.
4890 We expect nothing to be needed here for PARM or TYPENAME.
4891 Pushing a TYPE_DECL at this point for TYPENAME would actually
4892 be incorrect, as we might be in the middle of an expression
4893 with side effects on the pointed-to type size "arguments" prior
4894 to the pointer declaration point and the fake TYPE_DECL in the
4895 enclosing context would force the size evaluation prior to the
4898 if (!TYPE_NAME (type
)
4899 && (decl_context
== NORMAL
|| decl_context
== FIELD
)
4900 && variably_modified_type_p (type
, NULL_TREE
))
4902 tree decl
= build_decl (TYPE_DECL
, NULL_TREE
, type
);
4903 DECL_ARTIFICIAL (decl
) = 1;
4905 finish_decl (decl
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
4906 TYPE_NAME (type
) = decl
;
4909 type
= build_pointer_type (type
);
4911 /* Process type qualifiers (such as const or volatile)
4912 that were given inside the `*'. */
4913 type_quals
= declarator
->u
.pointer_quals
;
4915 declarator
= declarator
->declarator
;
4922 *decl_attrs
= chainon (returned_attrs
, *decl_attrs
);
4924 /* Now TYPE has the actual type, apart from any qualifiers in
4927 /* Check the type and width of a bit-field. */
4929 check_bitfield_type_and_width (&type
, width
, name
);
4931 /* Did array size calculations overflow? */
4933 if (TREE_CODE (type
) == ARRAY_TYPE
4934 && COMPLETE_TYPE_P (type
)
4935 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
4936 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type
)))
4939 error ("size of array %qE is too large", name
);
4941 error ("size of unnamed array is too large");
4942 /* If we proceed with the array type as it is, we'll eventually
4943 crash in tree_low_cst(). */
4944 type
= error_mark_node
;
4947 /* If this is declaring a typedef name, return a TYPE_DECL. */
4949 if (storage_class
== csc_typedef
)
4952 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4954 pedwarn (input_location
, OPT_pedantic
,
4955 "ISO C forbids qualified function types");
4957 type
= c_build_qualified_type (type
, type_quals
);
4958 decl
= build_decl (TYPE_DECL
, declarator
->u
.id
, type
);
4959 DECL_SOURCE_LOCATION (decl
) = declarator
->id_loc
;
4960 if (declspecs
->explicit_signed_p
)
4961 C_TYPEDEF_EXPLICITLY_SIGNED (decl
) = 1;
4962 if (declspecs
->inline_p
)
4963 pedwarn (input_location
, 0,"typedef %q+D declared %<inline%>", decl
);
4967 /* If this is a type name (such as, in a cast or sizeof),
4968 compute the type and return it now. */
4970 if (decl_context
== TYPENAME
)
4972 /* Note that the grammar rejects storage classes in typenames
4974 gcc_assert (storage_class
== csc_none
&& !threadp
4975 && !declspecs
->inline_p
);
4976 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4978 pedwarn (input_location
, OPT_pedantic
,
4979 "ISO C forbids const or volatile function types");
4981 type
= c_build_qualified_type (type
, type_quals
);
4985 if (pedantic
&& decl_context
== FIELD
4986 && variably_modified_type_p (type
, NULL_TREE
))
4989 pedwarn (input_location
, OPT_pedantic
,
4990 "a member of a structure or union cannot have a variably modified type");
4993 /* Aside from typedefs and type names (handle above),
4994 `void' at top level (not within pointer)
4995 is allowed only in public variables.
4996 We don't complain about parms either, but that is because
4997 a better error message can be made later. */
4999 if (VOID_TYPE_P (type
) && decl_context
!= PARM
5000 && !((decl_context
!= FIELD
&& TREE_CODE (type
) != FUNCTION_TYPE
)
5001 && (storage_class
== csc_extern
5002 || (current_scope
== file_scope
5003 && !(storage_class
== csc_static
5004 || storage_class
== csc_register
)))))
5006 error ("variable or field %qE declared void", name
);
5007 type
= integer_type_node
;
5010 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
5011 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
5016 if (decl_context
== PARM
)
5020 /* A parameter declared as an array of T is really a pointer to T.
5021 One declared as a function is really a pointer to a function. */
5023 if (TREE_CODE (type
) == ARRAY_TYPE
)
5025 /* Transfer const-ness of array into that of type pointed to. */
5026 type
= TREE_TYPE (type
);
5028 type
= c_build_qualified_type (type
, type_quals
);
5029 type
= build_pointer_type (type
);
5030 type_quals
= array_ptr_quals
;
5032 type
= c_build_qualified_type (type
, type_quals
);
5034 /* We don't yet implement attributes in this context. */
5035 if (array_ptr_attrs
!= NULL_TREE
)
5036 warning (OPT_Wattributes
,
5037 "attributes in parameter array declarator ignored");
5041 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
5044 pedwarn (input_location
, OPT_pedantic
,
5045 "ISO C forbids qualified function types");
5047 type
= c_build_qualified_type (type
, type_quals
);
5048 type
= build_pointer_type (type
);
5049 type_quals
= TYPE_UNQUALIFIED
;
5051 else if (type_quals
)
5052 type
= c_build_qualified_type (type
, type_quals
);
5054 decl
= build_decl (PARM_DECL
, declarator
->u
.id
, type
);
5055 DECL_SOURCE_LOCATION (decl
) = declarator
->id_loc
;
5057 C_DECL_VARIABLE_SIZE (decl
) = 1;
5059 /* Compute the type actually passed in the parmlist,
5060 for the case where there is no prototype.
5061 (For example, shorts and chars are passed as ints.)
5062 When there is a prototype, this is overridden later. */
5064 if (type
== error_mark_node
)
5065 promoted_type
= type
;
5067 promoted_type
= c_type_promotes_to (type
);
5069 DECL_ARG_TYPE (decl
) = promoted_type
;
5070 if (declspecs
->inline_p
)
5071 pedwarn (input_location
, 0, "parameter %q+D declared %<inline%>", decl
);
5073 else if (decl_context
== FIELD
)
5075 /* Note that the grammar rejects storage classes in typenames
5077 gcc_assert (storage_class
== csc_none
&& !threadp
5078 && !declspecs
->inline_p
);
5080 /* Structure field. It may not be a function. */
5082 if (TREE_CODE (type
) == FUNCTION_TYPE
)
5084 error ("field %qE declared as a function", name
);
5085 type
= build_pointer_type (type
);
5087 else if (TREE_CODE (type
) != ERROR_MARK
5088 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type
))
5091 error ("field %qE has incomplete type", name
);
5093 error ("unnamed field has incomplete type");
5094 type
= error_mark_node
;
5096 type
= c_build_qualified_type (type
, type_quals
);
5097 decl
= build_decl (FIELD_DECL
, declarator
->u
.id
, type
);
5098 DECL_SOURCE_LOCATION (decl
) = declarator
->id_loc
;
5099 DECL_NONADDRESSABLE_P (decl
) = bitfield
;
5100 if (bitfield
&& !declarator
->u
.id
)
5101 TREE_NO_WARNING (decl
) = 1;
5104 C_DECL_VARIABLE_SIZE (decl
) = 1;
5106 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
5108 if (storage_class
== csc_register
|| threadp
)
5110 error ("invalid storage class for function %qE", name
);
5112 else if (current_scope
!= file_scope
)
5114 /* Function declaration not at file scope. Storage
5115 classes other than `extern' are not allowed, C99
5116 6.7.1p5, and `extern' makes no difference. However,
5117 GCC allows 'auto', perhaps with 'inline', to support
5118 nested functions. */
5119 if (storage_class
== csc_auto
)
5120 pedwarn (input_location
, OPT_pedantic
,
5121 "invalid storage class for function %qE", name
);
5122 else if (storage_class
== csc_static
)
5124 error ("invalid storage class for function %qE", name
);
5126 storage_class
= declspecs
->storage_class
= csc_none
;
5132 decl
= build_decl (FUNCTION_DECL
, declarator
->u
.id
, type
);
5133 DECL_SOURCE_LOCATION (decl
) = declarator
->id_loc
;
5134 decl
= build_decl_attribute_variant (decl
, decl_attr
);
5136 if (pedantic
&& type_quals
&& !DECL_IN_SYSTEM_HEADER (decl
))
5137 pedwarn (input_location
, OPT_pedantic
,
5138 "ISO C forbids qualified function types");
5140 /* GNU C interprets a volatile-qualified function type to indicate
5141 that the function does not return. */
5142 if ((type_quals
& TYPE_QUAL_VOLATILE
)
5143 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
5144 warning (0, "%<noreturn%> function returns non-void value");
5146 /* Every function declaration is an external reference
5147 (DECL_EXTERNAL) except for those which are not at file
5148 scope and are explicitly declared "auto". This is
5149 forbidden by standard C (C99 6.7.1p5) and is interpreted by
5150 GCC to signify a forward declaration of a nested function. */
5151 if (storage_class
== csc_auto
&& current_scope
!= file_scope
)
5152 DECL_EXTERNAL (decl
) = 0;
5153 /* In C99, a function which is declared 'inline' with 'extern'
5154 is not an external reference (which is confusing). It
5155 means that the later definition of the function must be output
5156 in this file, C99 6.7.4p6. In GNU C89, a function declared
5157 'extern inline' is an external reference. */
5158 else if (declspecs
->inline_p
&& storage_class
!= csc_static
)
5159 DECL_EXTERNAL (decl
) = ((storage_class
== csc_extern
)
5160 == flag_gnu89_inline
);
5162 DECL_EXTERNAL (decl
) = !initialized
;
5164 /* Record absence of global scope for `static' or `auto'. */
5166 = !(storage_class
== csc_static
|| storage_class
== csc_auto
);
5168 /* For a function definition, record the argument information
5169 block where store_parm_decls will look for it. */
5171 current_function_arg_info
= arg_info
;
5173 if (declspecs
->default_int_p
)
5174 C_FUNCTION_IMPLICIT_INT (decl
) = 1;
5176 /* Record presence of `inline', if it is reasonable. */
5177 if (flag_hosted
&& MAIN_NAME_P (declarator
->u
.id
))
5179 if (declspecs
->inline_p
)
5180 pedwarn (input_location
, 0, "cannot inline function %<main%>");
5182 else if (declspecs
->inline_p
)
5183 /* Record that the function is declared `inline'. */
5184 DECL_DECLARED_INLINE_P (decl
) = 1;
5188 /* It's a variable. */
5189 /* An uninitialized decl with `extern' is a reference. */
5190 int extern_ref
= !initialized
&& storage_class
== csc_extern
;
5192 type
= c_build_qualified_type (type
, type_quals
);
5194 /* C99 6.2.2p7: It is invalid (compile-time undefined
5195 behavior) to create an 'extern' declaration for a
5196 variable if there is a global declaration that is
5197 'static' and the global declaration is not visible.
5198 (If the static declaration _is_ currently visible,
5199 the 'extern' declaration is taken to refer to that decl.) */
5200 if (extern_ref
&& current_scope
!= file_scope
)
5202 tree global_decl
= identifier_global_value (declarator
->u
.id
);
5203 tree visible_decl
= lookup_name (declarator
->u
.id
);
5206 && global_decl
!= visible_decl
5207 && TREE_CODE (global_decl
) == VAR_DECL
5208 && !TREE_PUBLIC (global_decl
))
5209 error ("variable previously declared %<static%> redeclared "
5213 decl
= build_decl (VAR_DECL
, declarator
->u
.id
, type
);
5214 DECL_SOURCE_LOCATION (decl
) = declarator
->id_loc
;
5216 C_DECL_VARIABLE_SIZE (decl
) = 1;
5218 if (declspecs
->inline_p
)
5219 pedwarn (input_location
, 0, "variable %q+D declared %<inline%>", decl
);
5221 /* At file scope, an initialized extern declaration may follow
5222 a static declaration. In that case, DECL_EXTERNAL will be
5223 reset later in start_decl. */
5224 DECL_EXTERNAL (decl
) = (storage_class
== csc_extern
);
5226 /* At file scope, the presence of a `static' or `register' storage
5227 class specifier, or the absence of all storage class specifiers
5228 makes this declaration a definition (perhaps tentative). Also,
5229 the absence of `static' makes it public. */
5230 if (current_scope
== file_scope
)
5232 TREE_PUBLIC (decl
) = storage_class
!= csc_static
;
5233 TREE_STATIC (decl
) = !extern_ref
;
5235 /* Not at file scope, only `static' makes a static definition. */
5238 TREE_STATIC (decl
) = (storage_class
== csc_static
);
5239 TREE_PUBLIC (decl
) = extern_ref
;
5243 DECL_TLS_MODEL (decl
) = decl_default_tls_model (decl
);
5246 if ((storage_class
== csc_extern
5247 || (storage_class
== csc_none
5248 && TREE_CODE (type
) == FUNCTION_TYPE
5250 && variably_modified_type_p (type
, NULL_TREE
))
5253 if (TREE_CODE (type
) == FUNCTION_TYPE
)
5254 error ("non-nested function with variably modified type");
5256 error ("object with variably modified type must have no linkage");
5259 /* Record `register' declaration for warnings on &
5260 and in case doing stupid register allocation. */
5262 if (storage_class
== csc_register
)
5264 C_DECL_REGISTER (decl
) = 1;
5265 DECL_REGISTER (decl
) = 1;
5268 /* Record constancy and volatility. */
5269 c_apply_type_quals_to_decl (type_quals
, decl
);
5271 /* If a type has volatile components, it should be stored in memory.
5272 Otherwise, the fact that those components are volatile
5273 will be ignored, and would even crash the compiler.
5274 Of course, this only makes sense on VAR,PARM, and RESULT decl's. */
5275 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl
))
5276 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
5277 || TREE_CODE (decl
) == RESULT_DECL
))
5279 /* It is not an error for a structure with volatile fields to
5280 be declared register, but reset DECL_REGISTER since it
5281 cannot actually go in a register. */
5282 int was_reg
= C_DECL_REGISTER (decl
);
5283 C_DECL_REGISTER (decl
) = 0;
5284 DECL_REGISTER (decl
) = 0;
5285 c_mark_addressable (decl
);
5286 C_DECL_REGISTER (decl
) = was_reg
;
5289 /* This is the earliest point at which we might know the assembler
5290 name of a variable. Thus, if it's known before this, die horribly. */
5291 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl
));
5297 /* Decode the parameter-list info for a function type or function definition.
5298 The argument is the value returned by `get_parm_info' (or made in c-parse.c
5299 if there is an identifier list instead of a parameter decl list).
5300 These two functions are separate because when a function returns
5301 or receives functions then each is called multiple times but the order
5302 of calls is different. The last call to `grokparms' is always the one
5303 that contains the formal parameter names of a function definition.
5305 Return a list of arg types to use in the FUNCTION_TYPE for this function.
5307 FUNCDEF_FLAG is true for a function definition, false for
5308 a mere declaration. A nonempty identifier-list gets an error message
5309 when FUNCDEF_FLAG is false. */
5312 grokparms (struct c_arg_info
*arg_info
, bool funcdef_flag
)
5314 tree arg_types
= arg_info
->types
;
5316 if (funcdef_flag
&& arg_info
->had_vla_unspec
)
5318 /* A function definition isn't function prototype scope C99 6.2.1p4. */
5320 error ("%<[*]%> not allowed in other than function prototype scope");
5323 if (arg_types
== 0 && !funcdef_flag
&& !in_system_header
)
5324 warning (OPT_Wstrict_prototypes
,
5325 "function declaration isn%'t a prototype");
5327 if (arg_types
== error_mark_node
)
5328 return 0; /* don't set TYPE_ARG_TYPES in this case */
5330 else if (arg_types
&& TREE_CODE (TREE_VALUE (arg_types
)) == IDENTIFIER_NODE
)
5333 pedwarn (input_location
, 0, "parameter names (without types) in function declaration");
5335 arg_info
->parms
= arg_info
->types
;
5336 arg_info
->types
= 0;
5341 tree parm
, type
, typelt
;
5342 unsigned int parmno
;
5344 /* If there is a parameter of incomplete type in a definition,
5345 this is an error. In a declaration this is valid, and a
5346 struct or union type may be completed later, before any calls
5347 or definition of the function. In the case where the tag was
5348 first declared within the parameter list, a warning has
5349 already been given. If a parameter has void type, then
5350 however the function cannot be defined or called, so
5353 for (parm
= arg_info
->parms
, typelt
= arg_types
, parmno
= 1;
5355 parm
= TREE_CHAIN (parm
), typelt
= TREE_CHAIN (typelt
), parmno
++)
5357 type
= TREE_VALUE (typelt
);
5358 if (type
== error_mark_node
)
5361 if (!COMPLETE_TYPE_P (type
))
5365 if (DECL_NAME (parm
))
5366 error ("parameter %u (%q+D) has incomplete type",
5369 error ("%Jparameter %u has incomplete type",
5372 TREE_VALUE (typelt
) = error_mark_node
;
5373 TREE_TYPE (parm
) = error_mark_node
;
5375 else if (VOID_TYPE_P (type
))
5377 if (DECL_NAME (parm
))
5378 warning (0, "parameter %u (%q+D) has void type",
5381 warning (0, "%Jparameter %u has void type",
5386 if (DECL_NAME (parm
) && TREE_USED (parm
))
5387 warn_if_shadowing (parm
);
5393 /* Take apart the current scope and return a c_arg_info structure with
5394 info on a parameter list just parsed.
5396 This structure is later fed to 'grokparms' and 'store_parm_decls'.
5398 ELLIPSIS being true means the argument list ended in '...' so don't
5399 append a sentinel (void_list_node) to the end of the type-list. */
5402 get_parm_info (bool ellipsis
)
5404 struct c_binding
*b
= current_scope
->bindings
;
5405 struct c_arg_info
*arg_info
= XOBNEW (&parser_obstack
,
5412 static bool explained_incomplete_types
= false;
5413 bool gave_void_only_once_err
= false;
5415 arg_info
->parms
= 0;
5417 arg_info
->types
= 0;
5418 arg_info
->others
= 0;
5419 arg_info
->pending_sizes
= 0;
5420 arg_info
->had_vla_unspec
= current_scope
->had_vla_unspec
;
5422 /* The bindings in this scope must not get put into a block.
5423 We will take care of deleting the binding nodes. */
5424 current_scope
->bindings
= 0;
5426 /* This function is only called if there was *something* on the
5430 /* A parameter list consisting solely of 'void' indicates that the
5431 function takes no arguments. But if the 'void' is qualified
5432 (by 'const' or 'volatile'), or has a storage class specifier
5433 ('register'), then the behavior is undefined; issue an error.
5434 Typedefs for 'void' are OK (see DR#157). */
5435 if (b
->prev
== 0 /* one binding */
5436 && TREE_CODE (b
->decl
) == PARM_DECL
/* which is a parameter */
5437 && !DECL_NAME (b
->decl
) /* anonymous */
5438 && VOID_TYPE_P (TREE_TYPE (b
->decl
))) /* of void type */
5440 if (TREE_THIS_VOLATILE (b
->decl
)
5441 || TREE_READONLY (b
->decl
)
5442 || C_DECL_REGISTER (b
->decl
))
5443 error ("%<void%> as only parameter may not be qualified");
5445 /* There cannot be an ellipsis. */
5447 error ("%<void%> must be the only parameter");
5449 arg_info
->types
= void_list_node
;
5454 types
= void_list_node
;
5456 /* Break up the bindings list into parms, tags, types, and others;
5457 apply sanity checks; purge the name-to-decl bindings. */
5460 tree decl
= b
->decl
;
5461 tree type
= TREE_TYPE (decl
);
5462 const char *keyword
;
5464 switch (TREE_CODE (decl
))
5469 gcc_assert (I_SYMBOL_BINDING (b
->id
) == b
);
5470 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
5473 /* Check for forward decls that never got their actual decl. */
5474 if (TREE_ASM_WRITTEN (decl
))
5475 error ("parameter %q+D has just a forward declaration", decl
);
5476 /* Check for (..., void, ...) and issue an error. */
5477 else if (VOID_TYPE_P (type
) && !DECL_NAME (decl
))
5479 if (!gave_void_only_once_err
)
5481 error ("%<void%> must be the only parameter");
5482 gave_void_only_once_err
= true;
5487 /* Valid parameter, add it to the list. */
5488 TREE_CHAIN (decl
) = parms
;
5491 /* Since there is a prototype, args are passed in their
5492 declared types. The back end may override this later. */
5493 DECL_ARG_TYPE (decl
) = type
;
5494 types
= tree_cons (0, type
, types
);
5498 case ENUMERAL_TYPE
: keyword
= "enum"; goto tag
;
5499 case UNION_TYPE
: keyword
= "union"; goto tag
;
5500 case RECORD_TYPE
: keyword
= "struct"; goto tag
;
5502 /* Types may not have tag-names, in which case the type
5503 appears in the bindings list with b->id NULL. */
5506 gcc_assert (I_TAG_BINDING (b
->id
) == b
);
5507 I_TAG_BINDING (b
->id
) = b
->shadowed
;
5510 /* Warn about any struct, union or enum tags defined in a
5511 parameter list. The scope of such types is limited to
5512 the parameter list, which is rarely if ever desirable
5513 (it's impossible to call such a function with type-
5514 correct arguments). An anonymous union parm type is
5515 meaningful as a GNU extension, so don't warn for that. */
5516 if (TREE_CODE (decl
) != UNION_TYPE
|| b
->id
!= 0)
5519 /* The %s will be one of 'struct', 'union', or 'enum'. */
5520 warning (0, "%<%s %E%> declared inside parameter list",
5523 /* The %s will be one of 'struct', 'union', or 'enum'. */
5524 warning (0, "anonymous %s declared inside parameter list",
5527 if (!explained_incomplete_types
)
5529 warning (0, "its scope is only this definition or declaration,"
5530 " which is probably not what you want");
5531 explained_incomplete_types
= true;
5535 tags
= tree_cons (b
->id
, decl
, tags
);
5541 /* CONST_DECLs appear here when we have an embedded enum,
5542 and TYPE_DECLs appear here when we have an embedded struct
5543 or union. No warnings for this - we already warned about the
5544 type itself. FUNCTION_DECLs appear when there is an implicit
5545 function declaration in the parameter list. */
5547 TREE_CHAIN (decl
) = others
;
5552 /* error_mark_node appears here when we have an undeclared
5553 variable. Just throw it away. */
5556 gcc_assert (I_SYMBOL_BINDING (b
->id
) == b
);
5557 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
5561 /* Other things that might be encountered. */
5568 b
= free_binding_and_advance (b
);
5571 arg_info
->parms
= parms
;
5572 arg_info
->tags
= tags
;
5573 arg_info
->types
= types
;
5574 arg_info
->others
= others
;
5575 arg_info
->pending_sizes
= get_pending_sizes ();
5579 /* Get the struct, enum or union (CODE says which) with tag NAME.
5580 Define the tag as a forward-reference if it is not defined.
5581 Return a c_typespec structure for the type specifier. */
5584 parser_xref_tag (enum tree_code code
, tree name
, location_t loc
)
5586 struct c_typespec ret
;
5590 ret
.expr
= NULL_TREE
;
5591 ret
.expr_const_operands
= true;
5593 /* If a cross reference is requested, look up the type
5594 already defined for this tag and return it. */
5596 ref
= lookup_tag (code
, name
, 0, &refloc
);
5597 /* If this is the right type of tag, return what we found.
5598 (This reference will be shadowed by shadow_tag later if appropriate.)
5599 If this is the wrong type of tag, do not return it. If it was the
5600 wrong type in the same scope, we will have had an error
5601 message already; if in a different scope and declaring
5602 a name, pending_xref_error will give an error message; but if in a
5603 different scope and not declaring a name, this tag should
5604 shadow the previous declaration of a different type of tag, and
5605 this would not work properly if we return the reference found.
5606 (For example, with "struct foo" in an outer scope, "union foo;"
5607 must shadow that tag with a new one of union type.) */
5608 ret
.kind
= (ref
? ctsk_tagref
: ctsk_tagfirstref
);
5609 if (ref
&& TREE_CODE (ref
) == code
)
5611 if (C_TYPE_DEFINED_IN_STRUCT (ref
)
5612 && loc
!= UNKNOWN_LOCATION
5618 warning_at (loc
, OPT_Wc___compat
,
5619 ("enum type defined in struct or union "
5620 "is not visible in C++"));
5621 inform (refloc
, "enum type defined here");
5624 warning_at (loc
, OPT_Wc___compat
,
5625 ("struct defined in struct or union "
5626 "is not visible in C++"));
5627 inform (refloc
, "struct defined here");
5630 warning_at (loc
, OPT_Wc___compat
,
5631 ("union defined in struct or union "
5632 "is not visible in C++"));
5633 inform (refloc
, "union defined here");
5644 /* If no such tag is yet defined, create a forward-reference node
5645 and record it as the "definition".
5646 When a real declaration of this type is found,
5647 the forward-reference will be altered into a real type. */
5649 ref
= make_node (code
);
5650 if (code
== ENUMERAL_TYPE
)
5652 /* Give the type a default layout like unsigned int
5653 to avoid crashing if it does not get defined. */
5654 SET_TYPE_MODE (ref
, TYPE_MODE (unsigned_type_node
));
5655 TYPE_ALIGN (ref
) = TYPE_ALIGN (unsigned_type_node
);
5656 TYPE_USER_ALIGN (ref
) = 0;
5657 TYPE_UNSIGNED (ref
) = 1;
5658 TYPE_PRECISION (ref
) = TYPE_PRECISION (unsigned_type_node
);
5659 TYPE_MIN_VALUE (ref
) = TYPE_MIN_VALUE (unsigned_type_node
);
5660 TYPE_MAX_VALUE (ref
) = TYPE_MAX_VALUE (unsigned_type_node
);
5663 pushtag (name
, ref
, loc
);
5669 /* Get the struct, enum or union (CODE says which) with tag NAME.
5670 Define the tag as a forward-reference if it is not defined.
5671 Return a tree for the type. */
5674 xref_tag (enum tree_code code
, tree name
)
5676 return parser_xref_tag (code
, name
, UNKNOWN_LOCATION
).spec
;
5679 /* Make sure that the tag NAME is defined *in the current scope*
5680 at least as a forward reference.
5681 CODE says which kind of tag NAME ought to be.
5683 This stores the current value of the file static IN_STRUCT in
5684 *ENCLOSING_IN_STRUCT, and sets IN_STRUCT to true. Similarly, this
5685 sets STRUCT_TYPES in *ENCLOSING_STRUCT_TYPES, and sets STRUCT_TYPES
5686 to an empty vector. The old values are restored in
5690 start_struct (enum tree_code code
, tree name
, bool *enclosing_in_struct
,
5691 VEC(tree
,heap
) **enclosing_struct_types
, location_t loc
)
5693 /* If there is already a tag defined at this scope
5694 (as a forward reference), just return it. */
5696 tree ref
= NULL_TREE
;
5697 location_t refloc
= UNKNOWN_LOCATION
;
5699 if (name
!= NULL_TREE
)
5700 ref
= lookup_tag (code
, name
, 1, &refloc
);
5701 if (ref
&& TREE_CODE (ref
) == code
)
5703 if (TYPE_SIZE (ref
))
5705 if (code
== UNION_TYPE
)
5706 error_at (loc
, "redefinition of %<union %E%>", name
);
5708 error_at (loc
, "redefinition of %<struct %E%>", name
);
5709 if (refloc
!= UNKNOWN_LOCATION
)
5710 inform (refloc
, "originally defined here");
5711 /* Don't create structures using a name already in use. */
5714 else if (C_TYPE_BEING_DEFINED (ref
))
5716 if (code
== UNION_TYPE
)
5717 error_at (loc
, "nested redefinition of %<union %E%>", name
);
5719 error_at (loc
, "nested redefinition of %<struct %E%>", name
);
5720 /* Don't bother to report "originally defined here" for a
5721 nested redefinition; the original definition should be
5723 /* Don't create structures that contain themselves. */
5728 /* Otherwise create a forward-reference just so the tag is in scope. */
5730 if (ref
== NULL_TREE
|| TREE_CODE (ref
) != code
)
5732 ref
= make_node (code
);
5733 pushtag (name
, ref
, loc
);
5736 C_TYPE_BEING_DEFINED (ref
) = 1;
5737 TYPE_PACKED (ref
) = flag_pack_struct
;
5739 *enclosing_in_struct
= in_struct
;
5740 *enclosing_struct_types
= struct_types
;
5742 struct_types
= VEC_alloc(tree
, heap
, 0);
5744 /* FIXME: This will issue a warning for a use of a type defined
5745 within a statement expr used within sizeof, et. al. This is not
5746 terribly serious as C++ doesn't permit statement exprs within
5748 if (warn_cxx_compat
&& (in_sizeof
|| in_typeof
|| in_alignof
))
5749 warning_at (loc
, OPT_Wc___compat
,
5750 "defining type in %qs expression is invalid in C++",
5753 : (in_typeof
? "typeof" : "alignof")));
5758 /* Process the specs, declarator and width (NULL if omitted)
5759 of a structure component, returning a FIELD_DECL node.
5760 WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
5761 DECL_ATTRS is as for grokdeclarator.
5763 LOC is the location of the structure component.
5765 This is done during the parsing of the struct declaration.
5766 The FIELD_DECL nodes are chained together and the lot of them
5767 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5770 grokfield (location_t loc
,
5771 struct c_declarator
*declarator
, struct c_declspecs
*declspecs
,
5772 tree width
, tree
*decl_attrs
)
5776 if (declarator
->kind
== cdk_id
&& declarator
->u
.id
== NULL_TREE
5777 && width
== NULL_TREE
)
5779 /* This is an unnamed decl.
5781 If we have something of the form "union { list } ;" then this
5782 is the anonymous union extension. Similarly for struct.
5784 If this is something of the form "struct foo;", then
5785 If MS extensions are enabled, this is handled as an
5787 Otherwise this is a forward declaration of a structure tag.
5789 If this is something of the form "foo;" and foo is a TYPE_DECL, then
5790 If MS extensions are enabled and foo names a structure, then
5791 again this is an anonymous struct.
5792 Otherwise this is an error.
5794 Oh what a horrid tangled web we weave. I wonder if MS consciously
5795 took this from Plan 9 or if it was an accident of implementation
5796 that took root before someone noticed the bug... */
5798 tree type
= declspecs
->type
;
5799 bool type_ok
= (TREE_CODE (type
) == RECORD_TYPE
5800 || TREE_CODE (type
) == UNION_TYPE
);
5804 && (flag_ms_extensions
|| !declspecs
->typedef_p
))
5806 if (flag_ms_extensions
)
5810 else if (TYPE_NAME (type
) == NULL
)
5817 pedwarn (loc
, 0, "declaration does not declare anything");
5820 pedwarn (loc
, OPT_pedantic
, "ISO C doesn%'t support unnamed structs/unions");
5823 value
= grokdeclarator (declarator
, declspecs
, FIELD
, false,
5824 width
? &width
: NULL
, decl_attrs
, NULL
, NULL
,
5827 finish_decl (value
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
5828 DECL_INITIAL (value
) = width
;
5833 /* Generate an error for any duplicate field names in FIELDLIST. Munge
5834 the list such that this does not present a problem later. */
5837 detect_field_duplicates (tree fieldlist
)
5842 /* First, see if there are more than "a few" fields.
5843 This is trivially true if there are zero or one fields. */
5846 x
= TREE_CHAIN (fieldlist
);
5852 } while (timeout
> 0 && x
);
5854 /* If there were "few" fields, avoid the overhead of allocating
5855 a hash table. Instead just do the nested traversal thing. */
5858 for (x
= TREE_CHAIN (fieldlist
); x
; x
= TREE_CHAIN (x
))
5861 for (y
= fieldlist
; y
!= x
; y
= TREE_CHAIN (y
))
5862 if (DECL_NAME (y
) == DECL_NAME (x
))
5864 error ("duplicate member %q+D", x
);
5865 DECL_NAME (x
) = NULL_TREE
;
5871 htab_t htab
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
5874 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5875 if ((y
= DECL_NAME (x
)) != 0)
5877 slot
= htab_find_slot (htab
, y
, INSERT
);
5880 error ("duplicate member %q+D", x
);
5881 DECL_NAME (x
) = NULL_TREE
;
5890 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5891 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5892 ATTRIBUTES are attributes to be applied to the structure.
5894 ENCLOSING_IN_STRUCT is the value of IN_STRUCT, and
5895 ENCLOSING_STRUCT_TYPES is the value of STRUCT_TYPES, when the
5896 struct was started. This sets the C_TYPE_DEFINED_IN_STRUCT flag
5897 for any type defined in the current struct. */
5900 finish_struct (tree t
, tree fieldlist
, tree attributes
,
5901 bool enclosing_in_struct
,
5902 VEC(tree
,heap
) *enclosing_struct_types
)
5905 bool toplevel
= file_scope
== current_scope
;
5906 int saw_named_field
;
5909 /* If this type was previously laid out as a forward reference,
5910 make sure we lay it out again. */
5914 decl_attributes (&t
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
5918 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5919 if (DECL_NAME (x
) != 0)
5924 if (TREE_CODE (t
) == UNION_TYPE
)
5927 pedwarn (input_location
, OPT_pedantic
, "union has no named members");
5929 pedwarn (input_location
, OPT_pedantic
, "union has no members");
5934 pedwarn (input_location
, OPT_pedantic
, "struct has no named members");
5936 pedwarn (input_location
, OPT_pedantic
, "struct has no members");
5941 /* Install struct as DECL_CONTEXT of each field decl.
5942 Also process specified field sizes, found in the DECL_INITIAL,
5943 storing 0 there after the type has been changed to precision equal
5944 to its width, rather than the precision of the specified standard
5945 type. (Correct layout requires the original type to have been preserved
5948 saw_named_field
= 0;
5949 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5951 if (TREE_TYPE (x
) == error_mark_node
)
5954 DECL_CONTEXT (x
) = t
;
5956 /* If any field is const, the structure type is pseudo-const. */
5957 if (TREE_READONLY (x
))
5958 C_TYPE_FIELDS_READONLY (t
) = 1;
5961 /* A field that is pseudo-const makes the structure likewise. */
5962 tree t1
= TREE_TYPE (x
);
5963 while (TREE_CODE (t1
) == ARRAY_TYPE
)
5964 t1
= TREE_TYPE (t1
);
5965 if ((TREE_CODE (t1
) == RECORD_TYPE
|| TREE_CODE (t1
) == UNION_TYPE
)
5966 && C_TYPE_FIELDS_READONLY (t1
))
5967 C_TYPE_FIELDS_READONLY (t
) = 1;
5970 /* Any field that is volatile means variables of this type must be
5971 treated in some ways as volatile. */
5972 if (TREE_THIS_VOLATILE (x
))
5973 C_TYPE_FIELDS_VOLATILE (t
) = 1;
5975 /* Any field of nominal variable size implies structure is too. */
5976 if (C_DECL_VARIABLE_SIZE (x
))
5977 C_TYPE_VARIABLE_SIZE (t
) = 1;
5979 if (DECL_INITIAL (x
))
5981 unsigned HOST_WIDE_INT width
= tree_low_cst (DECL_INITIAL (x
), 1);
5982 DECL_SIZE (x
) = bitsize_int (width
);
5983 DECL_BIT_FIELD (x
) = 1;
5984 SET_DECL_C_BIT_FIELD (x
);
5988 && (DECL_BIT_FIELD (x
)
5989 || TYPE_ALIGN (TREE_TYPE (x
)) > BITS_PER_UNIT
))
5990 DECL_PACKED (x
) = 1;
5992 /* Detect flexible array member in an invalid context. */
5993 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
5994 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
5995 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
5996 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
5998 if (TREE_CODE (t
) == UNION_TYPE
)
6000 error ("%Jflexible array member in union", x
);
6001 TREE_TYPE (x
) = error_mark_node
;
6003 else if (TREE_CHAIN (x
) != NULL_TREE
)
6005 error ("%Jflexible array member not at end of struct", x
);
6006 TREE_TYPE (x
) = error_mark_node
;
6008 else if (!saw_named_field
)
6010 error ("%Jflexible array member in otherwise empty struct", x
);
6011 TREE_TYPE (x
) = error_mark_node
;
6015 if (pedantic
&& !in_system_header
&& TREE_CODE (t
) == RECORD_TYPE
6016 && flexible_array_type_p (TREE_TYPE (x
)))
6017 pedwarn (input_location
, OPT_pedantic
,
6018 "%Jinvalid use of structure with flexible array member", x
);
6021 saw_named_field
= 1;
6024 detect_field_duplicates (fieldlist
);
6026 /* Now we have the nearly final fieldlist. Record it,
6027 then lay out the structure or union (including the fields). */
6029 TYPE_FIELDS (t
) = fieldlist
;
6033 /* Give bit-fields their proper types. */
6035 tree
*fieldlistp
= &fieldlist
;
6037 if (TREE_CODE (*fieldlistp
) == FIELD_DECL
&& DECL_INITIAL (*fieldlistp
)
6038 && TREE_TYPE (*fieldlistp
) != error_mark_node
)
6040 unsigned HOST_WIDE_INT width
6041 = tree_low_cst (DECL_INITIAL (*fieldlistp
), 1);
6042 tree type
= TREE_TYPE (*fieldlistp
);
6043 if (width
!= TYPE_PRECISION (type
))
6045 TREE_TYPE (*fieldlistp
)
6046 = c_build_bitfield_integer_type (width
, TYPE_UNSIGNED (type
));
6047 DECL_MODE (*fieldlistp
) = TYPE_MODE (TREE_TYPE (*fieldlistp
));
6049 DECL_INITIAL (*fieldlistp
) = 0;
6052 fieldlistp
= &TREE_CHAIN (*fieldlistp
);
6055 /* Now we have the truly final field list.
6056 Store it in this type and in the variants. */
6058 TYPE_FIELDS (t
) = fieldlist
;
6060 /* If there are lots of fields, sort so we can look through them fast.
6061 We arbitrarily consider 16 or more elts to be "a lot". */
6066 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
6068 if (len
> 15 || DECL_NAME (x
) == NULL
)
6076 struct lang_type
*space
;
6077 struct sorted_fields_type
*space2
;
6079 len
+= list_length (x
);
6081 /* Use the same allocation policy here that make_node uses, to
6082 ensure that this lives as long as the rest of the struct decl.
6083 All decls in an inline function need to be saved. */
6085 space
= GGC_CNEW (struct lang_type
);
6086 space2
= GGC_NEWVAR (struct sorted_fields_type
,
6087 sizeof (struct sorted_fields_type
) + len
* sizeof (tree
));
6091 field_array
= &space2
->elts
[0];
6092 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
6094 field_array
[len
++] = x
;
6096 /* If there is anonymous struct or union, break out of the loop. */
6097 if (DECL_NAME (x
) == NULL
)
6100 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
6103 TYPE_LANG_SPECIFIC (t
) = space
;
6104 TYPE_LANG_SPECIFIC (t
)->s
->len
= len
;
6105 field_array
= TYPE_LANG_SPECIFIC (t
)->s
->elts
;
6106 qsort (field_array
, len
, sizeof (tree
), field_decl_cmp
);
6111 for (x
= TYPE_MAIN_VARIANT (t
); x
; x
= TYPE_NEXT_VARIANT (x
))
6113 TYPE_FIELDS (x
) = TYPE_FIELDS (t
);
6114 TYPE_LANG_SPECIFIC (x
) = TYPE_LANG_SPECIFIC (t
);
6115 C_TYPE_FIELDS_READONLY (x
) = C_TYPE_FIELDS_READONLY (t
);
6116 C_TYPE_FIELDS_VOLATILE (x
) = C_TYPE_FIELDS_VOLATILE (t
);
6117 C_TYPE_VARIABLE_SIZE (x
) = C_TYPE_VARIABLE_SIZE (t
);
6120 /* If this was supposed to be a transparent union, but we can't
6121 make it one, warn and turn off the flag. */
6122 if (TREE_CODE (t
) == UNION_TYPE
6123 && TYPE_TRANSPARENT_UNION (t
)
6124 && (!TYPE_FIELDS (t
) || TYPE_MODE (t
) != DECL_MODE (TYPE_FIELDS (t
))))
6126 TYPE_TRANSPARENT_UNION (t
) = 0;
6127 warning (0, "union cannot be made transparent");
6130 /* If this structure or union completes the type of any previous
6131 variable declaration, lay it out and output its rtl. */
6132 for (x
= C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
));
6136 tree decl
= TREE_VALUE (x
);
6137 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
6138 layout_array_type (TREE_TYPE (decl
));
6139 if (TREE_CODE (decl
) != TYPE_DECL
)
6141 layout_decl (decl
, 0);
6142 if (c_dialect_objc ())
6143 objc_check_decl (decl
);
6144 rest_of_decl_compilation (decl
, toplevel
, 0);
6149 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
)) = 0;
6151 /* Finish debugging output for this type. */
6152 rest_of_type_compilation (t
, toplevel
);
6154 /* If we're inside a function proper, i.e. not file-scope and not still
6155 parsing parameters, then arrange for the size of a variable sized type
6157 if (cur_stmt_list
&& variably_modified_type_p (t
, NULL_TREE
))
6158 add_stmt (build_stmt (DECL_EXPR
, build_decl (TYPE_DECL
, NULL
, t
)));
6160 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
6161 the current struct. We do this now at the end of the struct
6162 because the flag is used to issue visibility warnings when using
6163 -Wc++-compat, and we only want to issue those warnings if the
6164 type is referenced outside of the struct declaration. */
6165 for (ix
= 0; VEC_iterate (tree
, struct_types
, ix
, x
); ++ix
)
6166 C_TYPE_DEFINED_IN_STRUCT (x
) = 1;
6168 VEC_free (tree
, heap
, struct_types
);
6170 in_struct
= enclosing_in_struct
;
6171 struct_types
= enclosing_struct_types
;
6173 /* If this struct is defined inside a struct, add it to
6175 if (in_struct
&& !in_sizeof
&& !in_typeof
&& !in_alignof
)
6176 VEC_safe_push (tree
, heap
, struct_types
, t
);
6181 /* Lay out the type T, and its element type, and so on. */
6184 layout_array_type (tree t
)
6186 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6187 layout_array_type (TREE_TYPE (t
));
6191 /* Begin compiling the definition of an enumeration type.
6192 NAME is its name (or null if anonymous).
6193 Returns the type object, as yet incomplete.
6194 Also records info about it so that build_enumerator
6195 may be used to declare the individual values as they are read. */
6198 start_enum (struct c_enum_contents
*the_enum
, tree name
, location_t loc
)
6200 tree enumtype
= NULL_TREE
;
6201 location_t enumloc
= UNKNOWN_LOCATION
;
6203 /* If this is the real definition for a previous forward reference,
6204 fill in the contents in the same object that used to be the
6205 forward reference. */
6207 if (name
!= NULL_TREE
)
6208 enumtype
= lookup_tag (ENUMERAL_TYPE
, name
, 1, &enumloc
);
6210 if (enumtype
== 0 || TREE_CODE (enumtype
) != ENUMERAL_TYPE
)
6212 enumtype
= make_node (ENUMERAL_TYPE
);
6213 pushtag (name
, enumtype
, loc
);
6216 if (C_TYPE_BEING_DEFINED (enumtype
))
6217 error_at (loc
, "nested redefinition of %<enum %E%>", name
);
6219 C_TYPE_BEING_DEFINED (enumtype
) = 1;
6221 if (TYPE_VALUES (enumtype
) != 0)
6223 /* This enum is a named one that has been declared already. */
6224 error_at (loc
, "redeclaration of %<enum %E%>", name
);
6225 if (enumloc
!= UNKNOWN_LOCATION
)
6226 inform (enumloc
, "originally defined here");
6228 /* Completely replace its old definition.
6229 The old enumerators remain defined, however. */
6230 TYPE_VALUES (enumtype
) = 0;
6233 the_enum
->enum_next_value
= integer_zero_node
;
6234 the_enum
->enum_overflow
= 0;
6236 if (flag_short_enums
)
6237 TYPE_PACKED (enumtype
) = 1;
6239 /* FIXME: This will issue a warning for a use of a type defined
6240 within sizeof in a statement expr. This is not terribly serious
6241 as C++ doesn't permit statement exprs within sizeof anyhow. */
6242 if (warn_cxx_compat
&& (in_sizeof
|| in_typeof
|| in_alignof
))
6243 warning_at (loc
, OPT_Wc___compat
,
6244 "defining type in %qs expression is invalid in C++",
6247 : (in_typeof
? "typeof" : "alignof")));
6252 /* After processing and defining all the values of an enumeration type,
6253 install their decls in the enumeration type and finish it off.
6254 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
6255 and ATTRIBUTES are the specified attributes.
6256 Returns ENUMTYPE. */
6259 finish_enum (tree enumtype
, tree values
, tree attributes
)
6262 tree minnode
= 0, maxnode
= 0;
6263 int precision
, unsign
;
6264 bool toplevel
= (file_scope
== current_scope
);
6265 struct lang_type
*lt
;
6267 decl_attributes (&enumtype
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
6269 /* Calculate the maximum value of any enumerator in this type. */
6271 if (values
== error_mark_node
)
6272 minnode
= maxnode
= integer_zero_node
;
6275 minnode
= maxnode
= TREE_VALUE (values
);
6276 for (pair
= TREE_CHAIN (values
); pair
; pair
= TREE_CHAIN (pair
))
6278 tree value
= TREE_VALUE (pair
);
6279 if (tree_int_cst_lt (maxnode
, value
))
6281 if (tree_int_cst_lt (value
, minnode
))
6286 /* Construct the final type of this enumeration. It is the same
6287 as one of the integral types - the narrowest one that fits, except
6288 that normally we only go as narrow as int - and signed iff any of
6289 the values are negative. */
6290 unsign
= (tree_int_cst_sgn (minnode
) >= 0);
6291 precision
= MAX (tree_int_cst_min_precision (minnode
, unsign
),
6292 tree_int_cst_min_precision (maxnode
, unsign
));
6294 if (TYPE_PACKED (enumtype
) || precision
> TYPE_PRECISION (integer_type_node
))
6296 tem
= c_common_type_for_size (precision
, unsign
);
6299 warning (0, "enumeration values exceed range of largest integer");
6300 tem
= long_long_integer_type_node
;
6304 tem
= unsign
? unsigned_type_node
: integer_type_node
;
6306 TYPE_MIN_VALUE (enumtype
) = TYPE_MIN_VALUE (tem
);
6307 TYPE_MAX_VALUE (enumtype
) = TYPE_MAX_VALUE (tem
);
6308 TYPE_UNSIGNED (enumtype
) = TYPE_UNSIGNED (tem
);
6309 TYPE_SIZE (enumtype
) = 0;
6311 /* If the precision of the type was specific with an attribute and it
6312 was too small, give an error. Otherwise, use it. */
6313 if (TYPE_PRECISION (enumtype
))
6315 if (precision
> TYPE_PRECISION (enumtype
))
6316 error ("specified mode too small for enumeral values");
6319 TYPE_PRECISION (enumtype
) = TYPE_PRECISION (tem
);
6321 layout_type (enumtype
);
6323 if (values
!= error_mark_node
)
6325 /* Change the type of the enumerators to be the enum type. We
6326 need to do this irrespective of the size of the enum, for
6327 proper type checking. Replace the DECL_INITIALs of the
6328 enumerators, and the value slots of the list, with copies
6329 that have the enum type; they cannot be modified in place
6330 because they may be shared (e.g. integer_zero_node) Finally,
6331 change the purpose slots to point to the names of the decls. */
6332 for (pair
= values
; pair
; pair
= TREE_CHAIN (pair
))
6334 tree enu
= TREE_PURPOSE (pair
);
6335 tree ini
= DECL_INITIAL (enu
);
6337 TREE_TYPE (enu
) = enumtype
;
6339 /* The ISO C Standard mandates enumerators to have type int,
6340 even though the underlying type of an enum type is
6341 unspecified. However, GCC allows enumerators of any
6342 integer type as an extensions. build_enumerator()
6343 converts any enumerators that fit in an int to type int,
6344 to avoid promotions to unsigned types when comparing
6345 integers with enumerators that fit in the int range.
6346 When -pedantic is given, build_enumerator() would have
6347 already warned about those that don't fit. Here we
6348 convert the rest to the enumerator type. */
6349 if (TREE_TYPE (ini
) != integer_type_node
)
6350 ini
= convert (enumtype
, ini
);
6352 DECL_INITIAL (enu
) = ini
;
6353 TREE_PURPOSE (pair
) = DECL_NAME (enu
);
6354 TREE_VALUE (pair
) = ini
;
6357 TYPE_VALUES (enumtype
) = values
;
6360 /* Record the min/max values so that we can warn about bit-field
6361 enumerations that are too small for the values. */
6362 lt
= GGC_CNEW (struct lang_type
);
6363 lt
->enum_min
= minnode
;
6364 lt
->enum_max
= maxnode
;
6365 TYPE_LANG_SPECIFIC (enumtype
) = lt
;
6367 /* Fix up all variant types of this enum type. */
6368 for (tem
= TYPE_MAIN_VARIANT (enumtype
); tem
; tem
= TYPE_NEXT_VARIANT (tem
))
6370 if (tem
== enumtype
)
6372 TYPE_VALUES (tem
) = TYPE_VALUES (enumtype
);
6373 TYPE_MIN_VALUE (tem
) = TYPE_MIN_VALUE (enumtype
);
6374 TYPE_MAX_VALUE (tem
) = TYPE_MAX_VALUE (enumtype
);
6375 TYPE_SIZE (tem
) = TYPE_SIZE (enumtype
);
6376 TYPE_SIZE_UNIT (tem
) = TYPE_SIZE_UNIT (enumtype
);
6377 SET_TYPE_MODE (tem
, TYPE_MODE (enumtype
));
6378 TYPE_PRECISION (tem
) = TYPE_PRECISION (enumtype
);
6379 TYPE_ALIGN (tem
) = TYPE_ALIGN (enumtype
);
6380 TYPE_USER_ALIGN (tem
) = TYPE_USER_ALIGN (enumtype
);
6381 TYPE_UNSIGNED (tem
) = TYPE_UNSIGNED (enumtype
);
6382 TYPE_LANG_SPECIFIC (tem
) = TYPE_LANG_SPECIFIC (enumtype
);
6385 /* Finish debugging output for this type. */
6386 rest_of_type_compilation (enumtype
, toplevel
);
6388 /* If this enum is defined inside a struct, add it to
6390 if (in_struct
&& !in_sizeof
&& !in_typeof
&& !in_alignof
)
6391 VEC_safe_push (tree
, heap
, struct_types
, enumtype
);
6396 /* Build and install a CONST_DECL for one value of the
6397 current enumeration type (one that was begun with start_enum).
6398 Return a tree-list containing the CONST_DECL and its value.
6399 Assignment of sequential values by default is handled here. */
6402 build_enumerator (struct c_enum_contents
*the_enum
, tree name
, tree value
,
6403 location_t value_loc
)
6407 /* Validate and default VALUE. */
6411 /* Don't issue more errors for error_mark_node (i.e. an
6412 undeclared identifier) - just ignore the value expression. */
6413 if (value
== error_mark_node
)
6415 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
6417 error ("enumerator value for %qE is not an integer constant", name
);
6422 if (TREE_CODE (value
) != INTEGER_CST
)
6424 value
= c_fully_fold (value
, false, NULL
);
6425 if (TREE_CODE (value
) == INTEGER_CST
)
6426 pedwarn (value_loc
, OPT_pedantic
,
6427 "enumerator value for %qE is not an integer "
6428 "constant expression", name
);
6430 if (TREE_CODE (value
) != INTEGER_CST
)
6432 error ("enumerator value for %qE is not an integer constant",
6438 value
= default_conversion (value
);
6439 constant_expression_warning (value
);
6444 /* Default based on previous value. */
6445 /* It should no longer be possible to have NON_LVALUE_EXPR
6449 value
= the_enum
->enum_next_value
;
6450 if (the_enum
->enum_overflow
)
6451 error ("overflow in enumeration values");
6453 /* Even though the underlying type of an enum is unspecified, the
6454 type of enumeration constants is explicitly defined as int
6455 (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as
6457 else if (!int_fits_type_p (value
, integer_type_node
))
6458 pedwarn (value_loc
, OPT_pedantic
,
6459 "ISO C restricts enumerator values to range of %<int%>");
6461 /* The ISO C Standard mandates enumerators to have type int, even
6462 though the underlying type of an enum type is unspecified.
6463 However, GCC allows enumerators of any integer type as an
6464 extensions. Here we convert any enumerators that fit in an int
6465 to type int, to avoid promotions to unsigned types when comparing
6466 integers with enumerators that fit in the int range. When
6467 -pedantic is given, we would have already warned about those that
6468 don't fit. We have to do this here rather than in finish_enum
6469 because this value may be used to define more enumerators. */
6470 if (int_fits_type_p (value
, integer_type_node
))
6471 value
= convert (integer_type_node
, value
);
6473 /* Set basis for default for next value. */
6474 the_enum
->enum_next_value
6476 (EXPR_HAS_LOCATION (value
) ? EXPR_LOCATION (value
) : input_location
,
6477 PLUS_EXPR
, value
, integer_one_node
, 0);
6478 the_enum
->enum_overflow
= tree_int_cst_lt (the_enum
->enum_next_value
, value
);
6480 /* Now create a declaration for the enum value name. */
6482 type
= TREE_TYPE (value
);
6483 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
6484 TYPE_PRECISION (integer_type_node
)),
6485 (TYPE_PRECISION (type
)
6486 >= TYPE_PRECISION (integer_type_node
)
6487 && TYPE_UNSIGNED (type
)));
6489 decl
= build_decl (CONST_DECL
, name
, type
);
6490 DECL_INITIAL (decl
) = convert (type
, value
);
6493 return tree_cons (decl
, value
, NULL_TREE
);
6497 /* Create the FUNCTION_DECL for a function definition.
6498 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
6499 the declaration; they describe the function's name and the type it returns,
6500 but twisted together in a fashion that parallels the syntax of C.
6502 This function creates a binding context for the function body
6503 as well as setting up the FUNCTION_DECL in current_function_decl.
6505 Returns 1 on success. If the DECLARATOR is not suitable for a function
6506 (it defines a datum instead), we return 0, which tells
6507 yyparse to report a parse error. */
6510 start_function (struct c_declspecs
*declspecs
, struct c_declarator
*declarator
,
6513 tree decl1
, old_decl
;
6514 tree restype
, resdecl
;
6515 struct c_label_context_se
*nstack_se
;
6516 struct c_label_context_vm
*nstack_vm
;
6518 current_function_returns_value
= 0; /* Assume, until we see it does. */
6519 current_function_returns_null
= 0;
6520 current_function_returns_abnormally
= 0;
6521 warn_about_return_type
= 0;
6522 c_switch_stack
= NULL
;
6524 nstack_se
= XOBNEW (&parser_obstack
, struct c_label_context_se
);
6525 nstack_se
->labels_def
= NULL
;
6526 nstack_se
->labels_used
= NULL
;
6527 nstack_se
->next
= label_context_stack_se
;
6528 label_context_stack_se
= nstack_se
;
6530 nstack_vm
= XOBNEW (&parser_obstack
, struct c_label_context_vm
);
6531 nstack_vm
->labels_def
= NULL
;
6532 nstack_vm
->labels_used
= NULL
;
6533 nstack_vm
->scope
= 0;
6534 nstack_vm
->next
= label_context_stack_vm
;
6535 label_context_stack_vm
= nstack_vm
;
6537 /* Indicate no valid break/continue context by setting these variables
6538 to some non-null, non-label value. We'll notice and emit the proper
6539 error message in c_finish_bc_stmt. */
6540 c_break_label
= c_cont_label
= size_zero_node
;
6542 decl1
= grokdeclarator (declarator
, declspecs
, FUNCDEF
, true, NULL
,
6543 &attributes
, NULL
, NULL
, DEPRECATED_NORMAL
);
6545 /* If the declarator is not suitable for a function definition,
6546 cause a syntax error. */
6549 label_context_stack_se
= label_context_stack_se
->next
;
6550 label_context_stack_vm
= label_context_stack_vm
->next
;
6554 decl_attributes (&decl1
, attributes
, 0);
6556 if (DECL_DECLARED_INLINE_P (decl1
)
6557 && DECL_UNINLINABLE (decl1
)
6558 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1
)))
6559 warning (OPT_Wattributes
, "inline function %q+D given attribute noinline",
6562 /* Handle gnu_inline attribute. */
6563 if (declspecs
->inline_p
6564 && !flag_gnu89_inline
6565 && TREE_CODE (decl1
) == FUNCTION_DECL
6566 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1
))
6567 || current_function_decl
))
6569 if (declspecs
->storage_class
!= csc_static
)
6570 DECL_EXTERNAL (decl1
) = !DECL_EXTERNAL (decl1
);
6573 announce_function (decl1
);
6575 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1
))))
6577 error ("return type is an incomplete type");
6578 /* Make it return void instead. */
6580 = build_function_type (void_type_node
,
6581 TYPE_ARG_TYPES (TREE_TYPE (decl1
)));
6584 if (warn_about_return_type
)
6585 pedwarn_c99 (input_location
, flag_isoc99
? 0
6586 : (warn_return_type
? OPT_Wreturn_type
: OPT_Wimplicit_int
),
6587 "return type defaults to %<int%>");
6589 /* Make the init_value nonzero so pushdecl knows this is not tentative.
6590 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
6591 DECL_INITIAL (decl1
) = error_mark_node
;
6593 /* If this definition isn't a prototype and we had a prototype declaration
6594 before, copy the arg type info from that prototype. */
6595 old_decl
= lookup_name_in_scope (DECL_NAME (decl1
), current_scope
);
6596 if (old_decl
&& TREE_CODE (old_decl
) != FUNCTION_DECL
)
6598 current_function_prototype_locus
= UNKNOWN_LOCATION
;
6599 current_function_prototype_built_in
= false;
6600 current_function_prototype_arg_types
= NULL_TREE
;
6601 if (TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0)
6603 if (old_decl
!= 0 && TREE_CODE (TREE_TYPE (old_decl
)) == FUNCTION_TYPE
6604 && comptypes (TREE_TYPE (TREE_TYPE (decl1
)),
6605 TREE_TYPE (TREE_TYPE (old_decl
))))
6607 TREE_TYPE (decl1
) = composite_type (TREE_TYPE (old_decl
),
6609 current_function_prototype_locus
= DECL_SOURCE_LOCATION (old_decl
);
6610 current_function_prototype_built_in
6611 = C_DECL_BUILTIN_PROTOTYPE (old_decl
);
6612 current_function_prototype_arg_types
6613 = TYPE_ARG_TYPES (TREE_TYPE (decl1
));
6615 if (TREE_PUBLIC (decl1
))
6617 /* If there is an external prototype declaration of this
6618 function, record its location but do not copy information
6619 to this decl. This may be an invisible declaration
6620 (built-in or in a scope which has finished) or simply
6621 have more refined argument types than any declaration
6623 struct c_binding
*b
;
6624 for (b
= I_SYMBOL_BINDING (DECL_NAME (decl1
)); b
; b
= b
->shadowed
)
6625 if (B_IN_SCOPE (b
, external_scope
))
6629 tree ext_decl
, ext_type
;
6631 ext_type
= b
->type
? b
->type
: TREE_TYPE (ext_decl
);
6632 if (TREE_CODE (ext_type
) == FUNCTION_TYPE
6633 && comptypes (TREE_TYPE (TREE_TYPE (decl1
)),
6634 TREE_TYPE (ext_type
)))
6636 current_function_prototype_locus
6637 = DECL_SOURCE_LOCATION (ext_decl
);
6638 current_function_prototype_built_in
6639 = C_DECL_BUILTIN_PROTOTYPE (ext_decl
);
6640 current_function_prototype_arg_types
6641 = TYPE_ARG_TYPES (ext_type
);
6647 /* Optionally warn of old-fashioned def with no previous prototype. */
6648 if (warn_strict_prototypes
6649 && old_decl
!= error_mark_node
6650 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0
6651 && C_DECL_ISNT_PROTOTYPE (old_decl
))
6652 warning (OPT_Wstrict_prototypes
,
6653 "function declaration isn%'t a prototype");
6654 /* Optionally warn of any global def with no previous prototype. */
6655 else if (warn_missing_prototypes
6656 && old_decl
!= error_mark_node
6657 && TREE_PUBLIC (decl1
)
6658 && !MAIN_NAME_P (DECL_NAME (decl1
))
6659 && C_DECL_ISNT_PROTOTYPE (old_decl
))
6660 warning (OPT_Wmissing_prototypes
, "no previous prototype for %q+D", decl1
);
6661 /* Optionally warn of any def with no previous prototype
6662 if the function has already been used. */
6663 else if (warn_missing_prototypes
6665 && old_decl
!= error_mark_node
6666 && TREE_USED (old_decl
)
6667 && TYPE_ARG_TYPES (TREE_TYPE (old_decl
)) == 0)
6668 warning (OPT_Wmissing_prototypes
,
6669 "%q+D was used with no prototype before its definition", decl1
);
6670 /* Optionally warn of any global def with no previous declaration. */
6671 else if (warn_missing_declarations
6672 && TREE_PUBLIC (decl1
)
6674 && !MAIN_NAME_P (DECL_NAME (decl1
)))
6675 warning (OPT_Wmissing_declarations
, "no previous declaration for %q+D",
6677 /* Optionally warn of any def with no previous declaration
6678 if the function has already been used. */
6679 else if (warn_missing_declarations
6681 && old_decl
!= error_mark_node
6682 && TREE_USED (old_decl
)
6683 && C_DECL_IMPLICIT (old_decl
))
6684 warning (OPT_Wmissing_declarations
,
6685 "%q+D was used with no declaration before its definition", decl1
);
6687 /* This function exists in static storage.
6688 (This does not mean `static' in the C sense!) */
6689 TREE_STATIC (decl1
) = 1;
6691 /* A nested function is not global. */
6692 if (current_function_decl
!= 0)
6693 TREE_PUBLIC (decl1
) = 0;
6695 /* This is the earliest point at which we might know the assembler
6696 name of the function. Thus, if it's set before this, die horribly. */
6697 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1
));
6699 /* If #pragma weak was used, mark the decl weak now. */
6700 if (current_scope
== file_scope
)
6701 maybe_apply_pragma_weak (decl1
);
6703 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
6704 if (warn_main
&& MAIN_NAME_P (DECL_NAME (decl1
)))
6706 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
6707 != integer_type_node
)
6708 pedwarn (input_location
, OPT_Wmain
, "return type of %q+D is not %<int%>", decl1
);
6710 check_main_parameter_types (decl1
);
6712 if (!TREE_PUBLIC (decl1
))
6713 pedwarn (input_location
, OPT_Wmain
, "%q+D is normally a non-static function", decl1
);
6716 /* Record the decl so that the function name is defined.
6717 If we already have a decl for this name, and it is a FUNCTION_DECL,
6718 use the old decl. */
6720 current_function_decl
= pushdecl (decl1
);
6723 declare_parm_level ();
6725 restype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
6726 resdecl
= build_decl (RESULT_DECL
, NULL_TREE
, restype
);
6727 DECL_ARTIFICIAL (resdecl
) = 1;
6728 DECL_IGNORED_P (resdecl
) = 1;
6729 DECL_RESULT (current_function_decl
) = resdecl
;
6731 start_fname_decls ();
6736 /* Subroutine of store_parm_decls which handles new-style function
6737 definitions (prototype format). The parms already have decls, so we
6738 need only record them as in effect and complain if any redundant
6739 old-style parm decls were written. */
6741 store_parm_decls_newstyle (tree fndecl
, const struct c_arg_info
*arg_info
)
6745 if (current_scope
->bindings
)
6747 error ("%Jold-style parameter declarations in prototyped "
6748 "function definition", fndecl
);
6750 /* Get rid of the old-style declarations. */
6754 /* Don't issue this warning for nested functions, and don't issue this
6755 warning if we got here because ARG_INFO_TYPES was error_mark_node
6756 (this happens when a function definition has just an ellipsis in
6757 its parameter list). */
6758 else if (!in_system_header
&& !current_function_scope
6759 && arg_info
->types
!= error_mark_node
)
6760 warning (OPT_Wtraditional
,
6761 "%Jtraditional C rejects ISO C style function definitions",
6764 /* Now make all the parameter declarations visible in the function body.
6765 We can bypass most of the grunt work of pushdecl. */
6766 for (decl
= arg_info
->parms
; decl
; decl
= TREE_CHAIN (decl
))
6768 DECL_CONTEXT (decl
) = current_function_decl
;
6769 if (DECL_NAME (decl
))
6771 bind (DECL_NAME (decl
), decl
, current_scope
,
6772 /*invisible=*/false, /*nested=*/false,
6774 if (!TREE_USED (decl
))
6775 warn_if_shadowing (decl
);
6778 error ("%Jparameter name omitted", decl
);
6781 /* Record the parameter list in the function declaration. */
6782 DECL_ARGUMENTS (fndecl
) = arg_info
->parms
;
6784 /* Now make all the ancillary declarations visible, likewise. */
6785 for (decl
= arg_info
->others
; decl
; decl
= TREE_CHAIN (decl
))
6787 DECL_CONTEXT (decl
) = current_function_decl
;
6788 if (DECL_NAME (decl
))
6789 bind (DECL_NAME (decl
), decl
, current_scope
,
6790 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION
);
6793 /* And all the tag declarations. */
6794 for (decl
= arg_info
->tags
; decl
; decl
= TREE_CHAIN (decl
))
6795 if (TREE_PURPOSE (decl
))
6796 bind (TREE_PURPOSE (decl
), TREE_VALUE (decl
), current_scope
,
6797 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION
);
6800 /* Subroutine of store_parm_decls which handles old-style function
6801 definitions (separate parameter list and declarations). */
6804 store_parm_decls_oldstyle (tree fndecl
, const struct c_arg_info
*arg_info
)
6806 struct c_binding
*b
;
6807 tree parm
, decl
, last
;
6808 tree parmids
= arg_info
->parms
;
6809 struct pointer_set_t
*seen_args
= pointer_set_create ();
6811 if (!in_system_header
)
6812 warning (OPT_Wold_style_definition
, "%Jold-style function definition",
6815 /* Match each formal parameter name with its declaration. Save each
6816 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
6817 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
6819 if (TREE_VALUE (parm
) == 0)
6821 error ("%Jparameter name missing from parameter list", fndecl
);
6822 TREE_PURPOSE (parm
) = 0;
6826 b
= I_SYMBOL_BINDING (TREE_VALUE (parm
));
6827 if (b
&& B_IN_CURRENT_SCOPE (b
))
6830 /* If we got something other than a PARM_DECL it is an error. */
6831 if (TREE_CODE (decl
) != PARM_DECL
)
6832 error ("%q+D declared as a non-parameter", decl
);
6833 /* If the declaration is already marked, we have a duplicate
6834 name. Complain and ignore the duplicate. */
6835 else if (pointer_set_contains (seen_args
, decl
))
6837 error ("multiple parameters named %q+D", decl
);
6838 TREE_PURPOSE (parm
) = 0;
6841 /* If the declaration says "void", complain and turn it into
6843 else if (VOID_TYPE_P (TREE_TYPE (decl
)))
6845 error ("parameter %q+D declared with void type", decl
);
6846 TREE_TYPE (decl
) = integer_type_node
;
6847 DECL_ARG_TYPE (decl
) = integer_type_node
;
6848 layout_decl (decl
, 0);
6850 warn_if_shadowing (decl
);
6852 /* If no declaration found, default to int. */
6855 decl
= build_decl (PARM_DECL
, TREE_VALUE (parm
), integer_type_node
);
6856 DECL_ARG_TYPE (decl
) = TREE_TYPE (decl
);
6857 DECL_SOURCE_LOCATION (decl
) = DECL_SOURCE_LOCATION (fndecl
);
6859 warn_if_shadowing (decl
);
6862 pedwarn (input_location
, 0, "type of %q+D defaults to %<int%>", decl
);
6864 warning (OPT_Wmissing_parameter_type
, "type of %q+D defaults to %<int%>", decl
);
6867 TREE_PURPOSE (parm
) = decl
;
6868 pointer_set_insert (seen_args
, decl
);
6871 /* Now examine the parms chain for incomplete declarations
6872 and declarations with no corresponding names. */
6874 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
6877 if (TREE_CODE (parm
) != PARM_DECL
)
6880 if (TREE_TYPE (parm
) != error_mark_node
6881 && !COMPLETE_TYPE_P (TREE_TYPE (parm
)))
6883 error ("parameter %q+D has incomplete type", parm
);
6884 TREE_TYPE (parm
) = error_mark_node
;
6887 if (!pointer_set_contains (seen_args
, parm
))
6889 error ("declaration for parameter %q+D but no such parameter", parm
);
6891 /* Pretend the parameter was not missing.
6892 This gets us to a standard state and minimizes
6893 further error messages. */
6894 parmids
= chainon (parmids
, tree_cons (parm
, 0, 0));
6898 /* Chain the declarations together in the order of the list of
6899 names. Store that chain in the function decl, replacing the
6900 list of names. Update the current scope to match. */
6901 DECL_ARGUMENTS (fndecl
) = 0;
6903 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
6904 if (TREE_PURPOSE (parm
))
6906 if (parm
&& TREE_PURPOSE (parm
))
6908 last
= TREE_PURPOSE (parm
);
6909 DECL_ARGUMENTS (fndecl
) = last
;
6911 for (parm
= TREE_CHAIN (parm
); parm
; parm
= TREE_CHAIN (parm
))
6912 if (TREE_PURPOSE (parm
))
6914 TREE_CHAIN (last
) = TREE_PURPOSE (parm
);
6915 last
= TREE_PURPOSE (parm
);
6917 TREE_CHAIN (last
) = 0;
6920 pointer_set_destroy (seen_args
);
6922 /* If there was a previous prototype,
6923 set the DECL_ARG_TYPE of each argument according to
6924 the type previously specified, and report any mismatches. */
6926 if (current_function_prototype_arg_types
)
6929 for (parm
= DECL_ARGUMENTS (fndecl
),
6930 type
= current_function_prototype_arg_types
;
6931 parm
|| (type
&& TREE_VALUE (type
) != error_mark_node
6932 && (TYPE_MAIN_VARIANT (TREE_VALUE (type
)) != void_type_node
));
6933 parm
= TREE_CHAIN (parm
), type
= TREE_CHAIN (type
))
6935 if (parm
== 0 || type
== 0
6936 || TYPE_MAIN_VARIANT (TREE_VALUE (type
)) == void_type_node
)
6938 if (current_function_prototype_built_in
)
6939 warning (0, "number of arguments doesn%'t match "
6940 "built-in prototype");
6943 error ("number of arguments doesn%'t match prototype");
6944 error ("%Hprototype declaration",
6945 ¤t_function_prototype_locus
);
6949 /* Type for passing arg must be consistent with that
6950 declared for the arg. ISO C says we take the unqualified
6951 type for parameters declared with qualified type. */
6952 if (TREE_TYPE (parm
) != error_mark_node
6953 && TREE_TYPE (type
) != error_mark_node
6954 && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm
)),
6955 TYPE_MAIN_VARIANT (TREE_VALUE (type
))))
6957 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm
))
6958 == TYPE_MAIN_VARIANT (TREE_VALUE (type
)))
6960 /* Adjust argument to match prototype. E.g. a previous
6961 `int foo(float);' prototype causes
6962 `int foo(x) float x; {...}' to be treated like
6963 `int foo(float x) {...}'. This is particularly
6964 useful for argument types like uid_t. */
6965 DECL_ARG_TYPE (parm
) = TREE_TYPE (parm
);
6967 if (targetm
.calls
.promote_prototypes (TREE_TYPE (current_function_decl
))
6968 && INTEGRAL_TYPE_P (TREE_TYPE (parm
))
6969 && TYPE_PRECISION (TREE_TYPE (parm
))
6970 < TYPE_PRECISION (integer_type_node
))
6971 DECL_ARG_TYPE (parm
) = integer_type_node
;
6973 /* ??? Is it possible to get here with a
6974 built-in prototype or will it always have
6975 been diagnosed as conflicting with an
6976 old-style definition and discarded? */
6977 if (current_function_prototype_built_in
)
6978 warning (OPT_pedantic
, "promoted argument %qD "
6979 "doesn%'t match built-in prototype", parm
);
6982 pedwarn (input_location
, OPT_pedantic
, "promoted argument %qD "
6983 "doesn%'t match prototype", parm
);
6984 pedwarn (current_function_prototype_locus
, OPT_pedantic
,
6985 "prototype declaration");
6990 if (current_function_prototype_built_in
)
6991 warning (0, "argument %qD doesn%'t match "
6992 "built-in prototype", parm
);
6995 error ("argument %qD doesn%'t match prototype", parm
);
6996 error ("%Hprototype declaration",
6997 ¤t_function_prototype_locus
);
7002 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = 0;
7005 /* Otherwise, create a prototype that would match. */
7009 tree actual
= 0, last
= 0, type
;
7011 for (parm
= DECL_ARGUMENTS (fndecl
); parm
; parm
= TREE_CHAIN (parm
))
7013 type
= tree_cons (NULL_TREE
, DECL_ARG_TYPE (parm
), NULL_TREE
);
7015 TREE_CHAIN (last
) = type
;
7020 type
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
7022 TREE_CHAIN (last
) = type
;
7026 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
7027 of the type of this function, but we need to avoid having this
7028 affect the types of other similarly-typed functions, so we must
7029 first force the generation of an identical (but separate) type
7030 node for the relevant function type. The new node we create
7031 will be a variant of the main variant of the original function
7034 TREE_TYPE (fndecl
) = build_variant_type_copy (TREE_TYPE (fndecl
));
7036 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = actual
;
7040 /* Store parameter declarations passed in ARG_INFO into the current
7041 function declaration. */
7044 store_parm_decls_from (struct c_arg_info
*arg_info
)
7046 current_function_arg_info
= arg_info
;
7047 store_parm_decls ();
7050 /* Store the parameter declarations into the current function declaration.
7051 This is called after parsing the parameter declarations, before
7052 digesting the body of the function.
7054 For an old-style definition, construct a prototype out of the old-style
7055 parameter declarations and inject it into the function's type. */
7058 store_parm_decls (void)
7060 tree fndecl
= current_function_decl
;
7063 /* The argument information block for FNDECL. */
7064 struct c_arg_info
*arg_info
= current_function_arg_info
;
7065 current_function_arg_info
= 0;
7067 /* True if this definition is written with a prototype. Note:
7068 despite C99 6.7.5.3p14, we can *not* treat an empty argument
7069 list in a function definition as equivalent to (void) -- an
7070 empty argument list specifies the function has no parameters,
7071 but only (void) sets up a prototype for future calls. */
7072 proto
= arg_info
->types
!= 0;
7075 store_parm_decls_newstyle (fndecl
, arg_info
);
7077 store_parm_decls_oldstyle (fndecl
, arg_info
);
7079 /* The next call to push_scope will be a function body. */
7081 next_is_function_body
= true;
7083 /* Write a record describing this function definition to the prototypes
7084 file (if requested). */
7086 gen_aux_info_record (fndecl
, 1, 0, proto
);
7088 /* Initialize the RTL code for the function. */
7089 allocate_struct_function (fndecl
, false);
7091 /* Begin the statement tree for this function. */
7092 DECL_SAVED_TREE (fndecl
) = push_stmt_list ();
7094 /* ??? Insert the contents of the pending sizes list into the function
7095 to be evaluated. The only reason left to have this is
7096 void foo(int n, int array[n++])
7097 because we throw away the array type in favor of a pointer type, and
7098 thus won't naturally see the SAVE_EXPR containing the increment. All
7099 other pending sizes would be handled by gimplify_parameters. */
7102 for (t
= nreverse (get_pending_sizes ()); t
; t
= TREE_CHAIN (t
))
7103 add_stmt (TREE_VALUE (t
));
7106 /* Even though we're inside a function body, we still don't want to
7107 call expand_expr to calculate the size of a variable-sized array.
7108 We haven't necessarily assigned RTL to all variables yet, so it's
7109 not safe to try to expand expressions involving them. */
7110 cfun
->dont_save_pending_sizes_p
= 1;
7113 /* Emit diagnostics that require gimple input for detection. Operate on
7114 FNDECL and all its nested functions. */
7117 c_gimple_diagnostics_recursively (tree fndecl
)
7119 struct cgraph_node
*cgn
;
7120 gimple_seq body
= gimple_body (fndecl
);
7122 /* Handle attribute((warn_unused_result)). Relies on gimple input. */
7123 c_warn_unused_result (body
);
7125 /* Notice when OpenMP structured block constraints are violated. */
7127 diagnose_omp_structured_block_errors (fndecl
);
7129 /* Finalize all nested functions now. */
7130 cgn
= cgraph_node (fndecl
);
7131 for (cgn
= cgn
->nested
; cgn
; cgn
= cgn
->next_nested
)
7132 c_gimple_diagnostics_recursively (cgn
->decl
);
7135 /* Finish up a function declaration and compile that function
7136 all the way to assembler language output. The free the storage
7137 for the function definition.
7139 This is called after parsing the body of the function definition. */
7142 finish_function (void)
7144 tree fndecl
= current_function_decl
;
7146 label_context_stack_se
= label_context_stack_se
->next
;
7147 label_context_stack_vm
= label_context_stack_vm
->next
;
7149 if (TREE_CODE (fndecl
) == FUNCTION_DECL
7150 && targetm
.calls
.promote_prototypes (TREE_TYPE (fndecl
)))
7152 tree args
= DECL_ARGUMENTS (fndecl
);
7153 for (; args
; args
= TREE_CHAIN (args
))
7155 tree type
= TREE_TYPE (args
);
7156 if (INTEGRAL_TYPE_P (type
)
7157 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
7158 DECL_ARG_TYPE (args
) = integer_type_node
;
7162 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
7163 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
7165 /* Must mark the RESULT_DECL as being in this function. */
7167 if (DECL_RESULT (fndecl
) && DECL_RESULT (fndecl
) != error_mark_node
)
7168 DECL_CONTEXT (DECL_RESULT (fndecl
)) = fndecl
;
7170 if (MAIN_NAME_P (DECL_NAME (fndecl
)) && flag_hosted
7171 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl
)))
7172 == integer_type_node
&& flag_isoc99
)
7174 tree stmt
= c_finish_return (integer_zero_node
, NULL_TREE
);
7175 /* Hack. We don't want the middle-end to warn that this return
7176 is unreachable, so we mark its location as special. Using
7177 UNKNOWN_LOCATION has the problem that it gets clobbered in
7178 annotate_one_with_locus. A cleaner solution might be to
7179 ensure ! should_carry_locus_p (stmt), but that needs a flag.
7181 SET_EXPR_LOCATION (stmt
, BUILTINS_LOCATION
);
7184 /* Tie off the statement tree for this function. */
7185 DECL_SAVED_TREE (fndecl
) = pop_stmt_list (DECL_SAVED_TREE (fndecl
));
7187 finish_fname_decls ();
7189 /* Complain if there's just no return statement. */
7190 if (warn_return_type
7191 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl
))) != VOID_TYPE
7192 && !current_function_returns_value
&& !current_function_returns_null
7193 /* Don't complain if we are no-return. */
7194 && !current_function_returns_abnormally
7195 /* Don't warn for main(). */
7196 && !MAIN_NAME_P (DECL_NAME (fndecl
))
7197 /* Or if they didn't actually specify a return type. */
7198 && !C_FUNCTION_IMPLICIT_INT (fndecl
)
7199 /* Normally, with -Wreturn-type, flow will complain, but we might
7200 optimize out static functions. */
7201 && !TREE_PUBLIC (fndecl
))
7203 warning (OPT_Wreturn_type
,
7204 "no return statement in function returning non-void");
7205 TREE_NO_WARNING (fndecl
) = 1;
7208 /* Store the end of the function, so that we get good line number
7209 info for the epilogue. */
7210 cfun
->function_end_locus
= input_location
;
7212 /* Finalize the ELF visibility for the function. */
7213 c_determine_visibility (fndecl
);
7215 /* For GNU C extern inline functions disregard inline limits. */
7216 if (DECL_EXTERNAL (fndecl
)
7217 && DECL_DECLARED_INLINE_P (fndecl
))
7218 DECL_DISREGARD_INLINE_LIMITS (fndecl
) = 1;
7220 /* Genericize before inlining. Delay genericizing nested functions
7221 until their parent function is genericized. Since finalizing
7222 requires GENERIC, delay that as well. */
7224 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
7225 && !undef_nested_function
)
7227 if (!decl_function_context (fndecl
))
7229 c_genericize (fndecl
);
7230 c_gimple_diagnostics_recursively (fndecl
);
7232 /* ??? Objc emits functions after finalizing the compilation unit.
7233 This should be cleaned up later and this conditional removed. */
7234 if (cgraph_global_info_ready
)
7236 cgraph_add_new_function (fndecl
, false);
7240 cgraph_finalize_function (fndecl
, false);
7244 /* Register this function with cgraph just far enough to get it
7245 added to our parent's nested function list. Handy, since the
7246 C front end doesn't have such a list. */
7247 (void) cgraph_node (fndecl
);
7251 if (!decl_function_context (fndecl
))
7252 undef_nested_function
= false;
7254 /* We're leaving the context of this function, so zap cfun.
7255 It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
7256 tree_rest_of_compilation. */
7258 current_function_decl
= NULL
;
7261 /* Check the declarations given in a for-loop for satisfying the C99
7262 constraints. If exactly one such decl is found, return it. */
7265 check_for_loop_decls (void)
7267 struct c_binding
*b
;
7268 tree one_decl
= NULL_TREE
;
7273 static bool hint
= true;
7274 /* If we get here, declarations have been used in a for loop without
7275 the C99 for loop scope. This doesn't make much sense, so don't
7277 error ("%<for%> loop initial declarations are only allowed in C99 mode");
7280 inform (input_location
,
7281 "use option -std=c99 or -std=gnu99 to compile your code");
7286 /* C99 subclause 6.8.5 paragraph 3:
7288 [#3] The declaration part of a for statement shall only
7289 declare identifiers for objects having storage class auto or
7292 It isn't clear whether, in this sentence, "identifiers" binds to
7293 "shall only declare" or to "objects" - that is, whether all identifiers
7294 declared must be identifiers for objects, or whether the restriction
7295 only applies to those that are. (A question on this in comp.std.c
7296 in November 2000 received no answer.) We implement the strictest
7297 interpretation, to avoid creating an extension which later causes
7300 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
7303 tree decl
= b
->decl
;
7308 switch (TREE_CODE (decl
))
7311 if (TREE_STATIC (decl
))
7312 error ("declaration of static variable %q+D in %<for%> loop "
7313 "initial declaration", decl
);
7314 else if (DECL_EXTERNAL (decl
))
7315 error ("declaration of %<extern%> variable %q+D in %<for%> loop "
7316 "initial declaration", decl
);
7320 error ("%<struct %E%> declared in %<for%> loop initial declaration",
7324 error ("%<union %E%> declared in %<for%> loop initial declaration",
7328 error ("%<enum %E%> declared in %<for%> loop initial declaration",
7332 error ("declaration of non-variable %q+D in %<for%> loop "
7333 "initial declaration", decl
);
7340 return n_decls
== 1 ? one_decl
: NULL_TREE
;
7343 /* Save and reinitialize the variables
7344 used during compilation of a C function. */
7347 c_push_function_context (void)
7349 struct language_function
*p
;
7350 p
= GGC_NEW (struct language_function
);
7353 p
->base
.x_stmt_tree
= c_stmt_tree
;
7354 p
->x_break_label
= c_break_label
;
7355 p
->x_cont_label
= c_cont_label
;
7356 p
->x_switch_stack
= c_switch_stack
;
7357 p
->arg_info
= current_function_arg_info
;
7358 p
->returns_value
= current_function_returns_value
;
7359 p
->returns_null
= current_function_returns_null
;
7360 p
->returns_abnormally
= current_function_returns_abnormally
;
7361 p
->warn_about_return_type
= warn_about_return_type
;
7363 push_function_context ();
7366 /* Restore the variables used during compilation of a C function. */
7369 c_pop_function_context (void)
7371 struct language_function
*p
;
7373 pop_function_context ();
7375 cfun
->language
= NULL
;
7377 if (DECL_STRUCT_FUNCTION (current_function_decl
) == 0
7378 && DECL_SAVED_TREE (current_function_decl
) == NULL_TREE
)
7380 /* Stop pointing to the local nodes about to be freed. */
7381 /* But DECL_INITIAL must remain nonzero so we know this
7382 was an actual function definition. */
7383 DECL_INITIAL (current_function_decl
) = error_mark_node
;
7384 DECL_ARGUMENTS (current_function_decl
) = 0;
7387 c_stmt_tree
= p
->base
.x_stmt_tree
;
7388 c_break_label
= p
->x_break_label
;
7389 c_cont_label
= p
->x_cont_label
;
7390 c_switch_stack
= p
->x_switch_stack
;
7391 current_function_arg_info
= p
->arg_info
;
7392 current_function_returns_value
= p
->returns_value
;
7393 current_function_returns_null
= p
->returns_null
;
7394 current_function_returns_abnormally
= p
->returns_abnormally
;
7395 warn_about_return_type
= p
->warn_about_return_type
;
7398 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
7401 c_dup_lang_specific_decl (tree decl
)
7403 struct lang_decl
*ld
;
7405 if (!DECL_LANG_SPECIFIC (decl
))
7408 ld
= GGC_NEW (struct lang_decl
);
7409 memcpy (ld
, DECL_LANG_SPECIFIC (decl
), sizeof (struct lang_decl
));
7410 DECL_LANG_SPECIFIC (decl
) = ld
;
7413 /* The functions below are required for functionality of doing
7414 function at once processing in the C front end. Currently these
7415 functions are not called from anywhere in the C front end, but as
7416 these changes continue, that will change. */
7418 /* Returns the stmt_tree (if any) to which statements are currently
7419 being added. If there is no active statement-tree, NULL is
7423 current_stmt_tree (void)
7425 return &c_stmt_tree
;
7428 /* Return the global value of T as a symbol. */
7431 identifier_global_value (tree t
)
7433 struct c_binding
*b
;
7435 for (b
= I_SYMBOL_BINDING (t
); b
; b
= b
->shadowed
)
7436 if (B_IN_FILE_SCOPE (b
) || B_IN_EXTERNAL_SCOPE (b
))
7442 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
7443 otherwise the name is found in ridpointers from RID_INDEX. */
7446 record_builtin_type (enum rid rid_index
, const char *name
, tree type
)
7450 id
= ridpointers
[(int) rid_index
];
7452 id
= get_identifier (name
);
7453 decl
= build_decl (TYPE_DECL
, id
, type
);
7455 if (debug_hooks
->type_decl
)
7456 debug_hooks
->type_decl (decl
, false);
7459 /* Build the void_list_node (void_type_node having been created). */
7461 build_void_list_node (void)
7463 tree t
= build_tree_list (NULL_TREE
, void_type_node
);
7467 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR. */
7470 build_c_parm (struct c_declspecs
*specs
, tree attrs
,
7471 struct c_declarator
*declarator
)
7473 struct c_parm
*ret
= XOBNEW (&parser_obstack
, struct c_parm
);
7476 ret
->declarator
= declarator
;
7480 /* Return a declarator with nested attributes. TARGET is the inner
7481 declarator to which these attributes apply. ATTRS are the
7484 struct c_declarator
*
7485 build_attrs_declarator (tree attrs
, struct c_declarator
*target
)
7487 struct c_declarator
*ret
= XOBNEW (&parser_obstack
, struct c_declarator
);
7488 ret
->kind
= cdk_attrs
;
7489 ret
->declarator
= target
;
7490 ret
->u
.attrs
= attrs
;
7494 /* Return a declarator for a function with arguments specified by ARGS
7495 and return type specified by TARGET. */
7497 struct c_declarator
*
7498 build_function_declarator (struct c_arg_info
*args
,
7499 struct c_declarator
*target
)
7501 struct c_declarator
*ret
= XOBNEW (&parser_obstack
, struct c_declarator
);
7502 ret
->kind
= cdk_function
;
7503 ret
->declarator
= target
;
7504 ret
->u
.arg_info
= args
;
7508 /* Return a declarator for the identifier IDENT (which may be
7509 NULL_TREE for an abstract declarator). */
7511 struct c_declarator
*
7512 build_id_declarator (tree ident
)
7514 struct c_declarator
*ret
= XOBNEW (&parser_obstack
, struct c_declarator
);
7516 ret
->declarator
= 0;
7518 /* Default value - may get reset to a more precise location. */
7519 ret
->id_loc
= input_location
;
7523 /* Return something to represent absolute declarators containing a *.
7524 TARGET is the absolute declarator that the * contains.
7525 TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
7526 to apply to the pointer type. */
7528 struct c_declarator
*
7529 make_pointer_declarator (struct c_declspecs
*type_quals_attrs
,
7530 struct c_declarator
*target
)
7534 struct c_declarator
*itarget
= target
;
7535 struct c_declarator
*ret
= XOBNEW (&parser_obstack
, struct c_declarator
);
7536 if (type_quals_attrs
)
7538 attrs
= type_quals_attrs
->attrs
;
7539 quals
= quals_from_declspecs (type_quals_attrs
);
7540 if (attrs
!= NULL_TREE
)
7541 itarget
= build_attrs_declarator (attrs
, target
);
7543 ret
->kind
= cdk_pointer
;
7544 ret
->declarator
= itarget
;
7545 ret
->u
.pointer_quals
= quals
;
7549 /* Return a pointer to a structure for an empty list of declaration
7552 struct c_declspecs
*
7553 build_null_declspecs (void)
7555 struct c_declspecs
*ret
= XOBNEW (&parser_obstack
, struct c_declspecs
);
7560 ret
->typespec_word
= cts_none
;
7561 ret
->storage_class
= csc_none
;
7562 ret
->expr_const_operands
= true;
7563 ret
->declspecs_seen_p
= false;
7564 ret
->type_seen_p
= false;
7565 ret
->non_sc_seen_p
= false;
7566 ret
->typedef_p
= false;
7567 ret
->tag_defined_p
= false;
7568 ret
->explicit_signed_p
= false;
7569 ret
->deprecated_p
= false;
7570 ret
->default_int_p
= false;
7571 ret
->long_p
= false;
7572 ret
->long_long_p
= false;
7573 ret
->short_p
= false;
7574 ret
->signed_p
= false;
7575 ret
->unsigned_p
= false;
7576 ret
->complex_p
= false;
7577 ret
->inline_p
= false;
7578 ret
->thread_p
= false;
7579 ret
->const_p
= false;
7580 ret
->volatile_p
= false;
7581 ret
->restrict_p
= false;
7582 ret
->saturating_p
= false;
7586 /* Add the type qualifier QUAL to the declaration specifiers SPECS,
7589 struct c_declspecs
*
7590 declspecs_add_qual (struct c_declspecs
*specs
, tree qual
)
7594 specs
->non_sc_seen_p
= true;
7595 specs
->declspecs_seen_p
= true;
7596 gcc_assert (TREE_CODE (qual
) == IDENTIFIER_NODE
7597 && C_IS_RESERVED_WORD (qual
));
7598 i
= C_RID_CODE (qual
);
7602 dupe
= specs
->const_p
;
7603 specs
->const_p
= true;
7606 dupe
= specs
->volatile_p
;
7607 specs
->volatile_p
= true;
7610 dupe
= specs
->restrict_p
;
7611 specs
->restrict_p
= true;
7616 if (dupe
&& !flag_isoc99
)
7617 pedwarn (input_location
, OPT_pedantic
, "duplicate %qE", qual
);
7621 /* Add the type specifier TYPE to the declaration specifiers SPECS,
7624 struct c_declspecs
*
7625 declspecs_add_type (struct c_declspecs
*specs
, struct c_typespec spec
)
7627 tree type
= spec
.spec
;
7628 specs
->non_sc_seen_p
= true;
7629 specs
->declspecs_seen_p
= true;
7630 specs
->type_seen_p
= true;
7631 if (TREE_DEPRECATED (type
))
7632 specs
->deprecated_p
= true;
7634 /* Handle type specifier keywords. */
7635 if (TREE_CODE (type
) == IDENTIFIER_NODE
7636 && C_IS_RESERVED_WORD (type
)
7637 && C_RID_CODE (type
) != RID_CXX_COMPAT_WARN
)
7639 enum rid i
= C_RID_CODE (type
);
7642 error ("two or more data types in declaration specifiers");
7645 if ((int) i
<= (int) RID_LAST_MODIFIER
)
7647 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */
7652 if (specs
->long_long_p
)
7654 error ("%<long long long%> is too long for GCC");
7659 if (specs
->typespec_word
== cts_double
)
7661 error ("both %<long long%> and %<double%> in "
7662 "declaration specifiers");
7665 pedwarn_c90 (input_location
, OPT_Wlong_long
,
7666 "ISO C90 does not support %<long long%>");
7667 specs
->long_long_p
= 1;
7671 error ("both %<long%> and %<short%> in "
7672 "declaration specifiers");
7673 else if (specs
->typespec_word
== cts_void
)
7674 error ("both %<long%> and %<void%> in "
7675 "declaration specifiers");
7676 else if (specs
->typespec_word
== cts_bool
)
7677 error ("both %<long%> and %<_Bool%> in "
7678 "declaration specifiers");
7679 else if (specs
->typespec_word
== cts_char
)
7680 error ("both %<long%> and %<char%> in "
7681 "declaration specifiers");
7682 else if (specs
->typespec_word
== cts_float
)
7683 error ("both %<long%> and %<float%> in "
7684 "declaration specifiers");
7685 else if (specs
->typespec_word
== cts_dfloat32
)
7686 error ("both %<long%> and %<_Decimal32%> in "
7687 "declaration specifiers");
7688 else if (specs
->typespec_word
== cts_dfloat64
)
7689 error ("both %<long%> and %<_Decimal64%> in "
7690 "declaration specifiers");
7691 else if (specs
->typespec_word
== cts_dfloat128
)
7692 error ("both %<long%> and %<_Decimal128%> in "
7693 "declaration specifiers");
7695 specs
->long_p
= true;
7698 dupe
= specs
->short_p
;
7700 error ("both %<long%> and %<short%> in "
7701 "declaration specifiers");
7702 else if (specs
->typespec_word
== cts_void
)
7703 error ("both %<short%> and %<void%> in "
7704 "declaration specifiers");
7705 else if (specs
->typespec_word
== cts_bool
)
7706 error ("both %<short%> and %<_Bool%> in "
7707 "declaration specifiers");
7708 else if (specs
->typespec_word
== cts_char
)
7709 error ("both %<short%> and %<char%> in "
7710 "declaration specifiers");
7711 else if (specs
->typespec_word
== cts_float
)
7712 error ("both %<short%> and %<float%> in "
7713 "declaration specifiers");
7714 else if (specs
->typespec_word
== cts_double
)
7715 error ("both %<short%> and %<double%> in "
7716 "declaration specifiers");
7717 else if (specs
->typespec_word
== cts_dfloat32
)
7718 error ("both %<short%> and %<_Decimal32%> in "
7719 "declaration specifiers");
7720 else if (specs
->typespec_word
== cts_dfloat64
)
7721 error ("both %<short%> and %<_Decimal64%> in "
7722 "declaration specifiers");
7723 else if (specs
->typespec_word
== cts_dfloat128
)
7724 error ("both %<short%> and %<_Decimal128%> in "
7725 "declaration specifiers");
7727 specs
->short_p
= true;
7730 dupe
= specs
->signed_p
;
7731 if (specs
->unsigned_p
)
7732 error ("both %<signed%> and %<unsigned%> in "
7733 "declaration specifiers");
7734 else if (specs
->typespec_word
== cts_void
)
7735 error ("both %<signed%> and %<void%> in "
7736 "declaration specifiers");
7737 else if (specs
->typespec_word
== cts_bool
)
7738 error ("both %<signed%> and %<_Bool%> in "
7739 "declaration specifiers");
7740 else if (specs
->typespec_word
== cts_float
)
7741 error ("both %<signed%> and %<float%> in "
7742 "declaration specifiers");
7743 else if (specs
->typespec_word
== cts_double
)
7744 error ("both %<signed%> and %<double%> in "
7745 "declaration specifiers");
7746 else if (specs
->typespec_word
== cts_dfloat32
)
7747 error ("both %<signed%> and %<_Decimal32%> in "
7748 "declaration specifiers");
7749 else if (specs
->typespec_word
== cts_dfloat64
)
7750 error ("both %<signed%> and %<_Decimal64%> in "
7751 "declaration specifiers");
7752 else if (specs
->typespec_word
== cts_dfloat128
)
7753 error ("both %<signed%> and %<_Decimal128%> in "
7754 "declaration specifiers");
7756 specs
->signed_p
= true;
7759 dupe
= specs
->unsigned_p
;
7760 if (specs
->signed_p
)
7761 error ("both %<signed%> and %<unsigned%> in "
7762 "declaration specifiers");
7763 else if (specs
->typespec_word
== cts_void
)
7764 error ("both %<unsigned%> and %<void%> in "
7765 "declaration specifiers");
7766 else if (specs
->typespec_word
== cts_bool
)
7767 error ("both %<unsigned%> and %<_Bool%> in "
7768 "declaration specifiers");
7769 else if (specs
->typespec_word
== cts_float
)
7770 error ("both %<unsigned%> and %<float%> in "
7771 "declaration specifiers");
7772 else if (specs
->typespec_word
== cts_double
)
7773 error ("both %<unsigned%> and %<double%> in "
7774 "declaration specifiers");
7775 else if (specs
->typespec_word
== cts_dfloat32
)
7776 error ("both %<unsigned%> and %<_Decimal32%> in "
7777 "declaration specifiers");
7778 else if (specs
->typespec_word
== cts_dfloat64
)
7779 error ("both %<unsigned%> and %<_Decimal64%> in "
7780 "declaration specifiers");
7781 else if (specs
->typespec_word
== cts_dfloat128
)
7782 error ("both %<unsigned%> and %<_Decimal128%> in "
7783 "declaration specifiers");
7785 specs
->unsigned_p
= true;
7788 dupe
= specs
->complex_p
;
7789 if (!flag_isoc99
&& !in_system_header
)
7790 pedwarn (input_location
, OPT_pedantic
, "ISO C90 does not support complex types");
7791 if (specs
->typespec_word
== cts_void
)
7792 error ("both %<complex%> and %<void%> in "
7793 "declaration specifiers");
7794 else if (specs
->typespec_word
== cts_bool
)
7795 error ("both %<complex%> and %<_Bool%> in "
7796 "declaration specifiers");
7797 else if (specs
->typespec_word
== cts_dfloat32
)
7798 error ("both %<complex%> and %<_Decimal32%> in "
7799 "declaration specifiers");
7800 else if (specs
->typespec_word
== cts_dfloat64
)
7801 error ("both %<complex%> and %<_Decimal64%> in "
7802 "declaration specifiers");
7803 else if (specs
->typespec_word
== cts_dfloat128
)
7804 error ("both %<complex%> and %<_Decimal128%> in "
7805 "declaration specifiers");
7806 else if (specs
->typespec_word
== cts_fract
)
7807 error ("both %<complex%> and %<_Fract%> in "
7808 "declaration specifiers");
7809 else if (specs
->typespec_word
== cts_accum
)
7810 error ("both %<complex%> and %<_Accum%> in "
7811 "declaration specifiers");
7812 else if (specs
->saturating_p
)
7813 error ("both %<complex%> and %<_Sat%> in "
7814 "declaration specifiers");
7816 specs
->complex_p
= true;
7819 dupe
= specs
->saturating_p
;
7820 pedwarn (input_location
, OPT_pedantic
, "ISO C does not support saturating types");
7821 if (specs
->typespec_word
== cts_void
)
7822 error ("both %<_Sat%> and %<void%> in "
7823 "declaration specifiers");
7824 else if (specs
->typespec_word
== cts_bool
)
7825 error ("both %<_Sat%> and %<_Bool%> in "
7826 "declaration specifiers");
7827 else if (specs
->typespec_word
== cts_char
)
7828 error ("both %<_Sat%> and %<char%> in "
7829 "declaration specifiers");
7830 else if (specs
->typespec_word
== cts_int
)
7831 error ("both %<_Sat%> and %<int%> in "
7832 "declaration specifiers");
7833 else if (specs
->typespec_word
== cts_float
)
7834 error ("both %<_Sat%> and %<float%> in "
7835 "declaration specifiers");
7836 else if (specs
->typespec_word
== cts_double
)
7837 error ("both %<_Sat%> and %<double%> in "
7838 "declaration specifiers");
7839 else if (specs
->typespec_word
== cts_dfloat32
)
7840 error ("both %<_Sat%> and %<_Decimal32%> in "
7841 "declaration specifiers");
7842 else if (specs
->typespec_word
== cts_dfloat64
)
7843 error ("both %<_Sat%> and %<_Decimal64%> in "
7844 "declaration specifiers");
7845 else if (specs
->typespec_word
== cts_dfloat128
)
7846 error ("both %<_Sat%> and %<_Decimal128%> in "
7847 "declaration specifiers");
7848 else if (specs
->complex_p
)
7849 error ("both %<_Sat%> and %<complex%> in "
7850 "declaration specifiers");
7852 specs
->saturating_p
= true;
7859 error ("duplicate %qE", type
);
7865 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32",
7866 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */
7867 if (specs
->typespec_word
!= cts_none
)
7869 error ("two or more data types in declaration specifiers");
7876 error ("both %<long%> and %<void%> in "
7877 "declaration specifiers");
7878 else if (specs
->short_p
)
7879 error ("both %<short%> and %<void%> in "
7880 "declaration specifiers");
7881 else if (specs
->signed_p
)
7882 error ("both %<signed%> and %<void%> in "
7883 "declaration specifiers");
7884 else if (specs
->unsigned_p
)
7885 error ("both %<unsigned%> and %<void%> in "
7886 "declaration specifiers");
7887 else if (specs
->complex_p
)
7888 error ("both %<complex%> and %<void%> in "
7889 "declaration specifiers");
7890 else if (specs
->saturating_p
)
7891 error ("both %<_Sat%> and %<void%> in "
7892 "declaration specifiers");
7894 specs
->typespec_word
= cts_void
;
7898 error ("both %<long%> and %<_Bool%> in "
7899 "declaration specifiers");
7900 else if (specs
->short_p
)
7901 error ("both %<short%> and %<_Bool%> in "
7902 "declaration specifiers");
7903 else if (specs
->signed_p
)
7904 error ("both %<signed%> and %<_Bool%> in "
7905 "declaration specifiers");
7906 else if (specs
->unsigned_p
)
7907 error ("both %<unsigned%> and %<_Bool%> in "
7908 "declaration specifiers");
7909 else if (specs
->complex_p
)
7910 error ("both %<complex%> and %<_Bool%> in "
7911 "declaration specifiers");
7912 else if (specs
->saturating_p
)
7913 error ("both %<_Sat%> and %<_Bool%> in "
7914 "declaration specifiers");
7916 specs
->typespec_word
= cts_bool
;
7920 error ("both %<long%> and %<char%> in "
7921 "declaration specifiers");
7922 else if (specs
->short_p
)
7923 error ("both %<short%> and %<char%> in "
7924 "declaration specifiers");
7925 else if (specs
->saturating_p
)
7926 error ("both %<_Sat%> and %<char%> in "
7927 "declaration specifiers");
7929 specs
->typespec_word
= cts_char
;
7932 if (specs
->saturating_p
)
7933 error ("both %<_Sat%> and %<int%> in "
7934 "declaration specifiers");
7936 specs
->typespec_word
= cts_int
;
7940 error ("both %<long%> and %<float%> in "
7941 "declaration specifiers");
7942 else if (specs
->short_p
)
7943 error ("both %<short%> and %<float%> in "
7944 "declaration specifiers");
7945 else if (specs
->signed_p
)
7946 error ("both %<signed%> and %<float%> in "
7947 "declaration specifiers");
7948 else if (specs
->unsigned_p
)
7949 error ("both %<unsigned%> and %<float%> in "
7950 "declaration specifiers");
7951 else if (specs
->saturating_p
)
7952 error ("both %<_Sat%> and %<float%> in "
7953 "declaration specifiers");
7955 specs
->typespec_word
= cts_float
;
7958 if (specs
->long_long_p
)
7959 error ("both %<long long%> and %<double%> in "
7960 "declaration specifiers");
7961 else if (specs
->short_p
)
7962 error ("both %<short%> and %<double%> in "
7963 "declaration specifiers");
7964 else if (specs
->signed_p
)
7965 error ("both %<signed%> and %<double%> in "
7966 "declaration specifiers");
7967 else if (specs
->unsigned_p
)
7968 error ("both %<unsigned%> and %<double%> in "
7969 "declaration specifiers");
7970 else if (specs
->saturating_p
)
7971 error ("both %<_Sat%> and %<double%> in "
7972 "declaration specifiers");
7974 specs
->typespec_word
= cts_double
;
7981 if (i
== RID_DFLOAT32
)
7983 else if (i
== RID_DFLOAT64
)
7986 str
= "_Decimal128";
7987 if (specs
->long_long_p
)
7988 error ("both %<long long%> and %<%s%> in "
7989 "declaration specifiers", str
);
7991 error ("both %<long%> and %<%s%> in "
7992 "declaration specifiers", str
);
7993 else if (specs
->short_p
)
7994 error ("both %<short%> and %<%s%> in "
7995 "declaration specifiers", str
);
7996 else if (specs
->signed_p
)
7997 error ("both %<signed%> and %<%s%> in "
7998 "declaration specifiers", str
);
7999 else if (specs
->unsigned_p
)
8000 error ("both %<unsigned%> and %<%s%> in "
8001 "declaration specifiers", str
);
8002 else if (specs
->complex_p
)
8003 error ("both %<complex%> and %<%s%> in "
8004 "declaration specifiers", str
);
8005 else if (specs
->saturating_p
)
8006 error ("both %<_Sat%> and %<%s%> in "
8007 "declaration specifiers", str
);
8008 else if (i
== RID_DFLOAT32
)
8009 specs
->typespec_word
= cts_dfloat32
;
8010 else if (i
== RID_DFLOAT64
)
8011 specs
->typespec_word
= cts_dfloat64
;
8013 specs
->typespec_word
= cts_dfloat128
;
8015 if (!targetm
.decimal_float_supported_p ())
8016 error ("decimal floating point not supported for this target");
8017 pedwarn (input_location
, OPT_pedantic
,
8018 "ISO C does not support decimal floating point");
8028 if (specs
->complex_p
)
8029 error ("both %<complex%> and %<%s%> in "
8030 "declaration specifiers", str
);
8031 else if (i
== RID_FRACT
)
8032 specs
->typespec_word
= cts_fract
;
8034 specs
->typespec_word
= cts_accum
;
8036 if (!targetm
.fixed_point_supported_p ())
8037 error ("fixed-point types not supported for this target");
8038 pedwarn (input_location
, OPT_pedantic
,
8039 "ISO C does not support fixed-point types");
8042 /* ObjC reserved word "id", handled below. */
8048 /* Now we have a typedef (a TYPE_DECL node), an identifier (some
8049 form of ObjC type, cases such as "int" and "long" being handled
8050 above), a TYPE (struct, union, enum and typeof specifiers) or an
8051 ERROR_MARK. In none of these cases may there have previously
8052 been any type specifiers. */
8053 if (specs
->type
|| specs
->typespec_word
!= cts_none
8054 || specs
->long_p
|| specs
->short_p
|| specs
->signed_p
8055 || specs
->unsigned_p
|| specs
->complex_p
)
8056 error ("two or more data types in declaration specifiers");
8057 else if (TREE_CODE (type
) == TYPE_DECL
)
8059 if (TREE_TYPE (type
) == error_mark_node
)
8060 ; /* Allow the type to default to int to avoid cascading errors. */
8063 specs
->type
= TREE_TYPE (type
);
8064 specs
->decl_attr
= DECL_ATTRIBUTES (type
);
8065 specs
->typedef_p
= true;
8066 specs
->explicit_signed_p
= C_TYPEDEF_EXPLICITLY_SIGNED (type
);
8069 else if (TREE_CODE (type
) == IDENTIFIER_NODE
)
8071 tree t
= lookup_name (type
);
8072 if (!t
|| TREE_CODE (t
) != TYPE_DECL
)
8073 error ("%qE fails to be a typedef or built in type", type
);
8074 else if (TREE_TYPE (t
) == error_mark_node
)
8077 specs
->type
= TREE_TYPE (t
);
8079 else if (TREE_CODE (type
) != ERROR_MARK
)
8081 if (spec
.kind
== ctsk_tagdef
|| spec
.kind
== ctsk_tagfirstref
)
8082 specs
->tag_defined_p
= true;
8083 if (spec
.kind
== ctsk_typeof
)
8085 specs
->typedef_p
= true;
8089 specs
->expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (spec
.expr
),
8090 specs
->expr
, spec
.expr
);
8092 specs
->expr
= spec
.expr
;
8093 specs
->expr_const_operands
&= spec
.expr_const_operands
;
8102 /* Add the storage class specifier or function specifier SCSPEC to the
8103 declaration specifiers SPECS, returning SPECS. */
8105 struct c_declspecs
*
8106 declspecs_add_scspec (struct c_declspecs
*specs
, tree scspec
)
8109 enum c_storage_class n
= csc_none
;
8111 specs
->declspecs_seen_p
= true;
8112 gcc_assert (TREE_CODE (scspec
) == IDENTIFIER_NODE
8113 && C_IS_RESERVED_WORD (scspec
));
8114 i
= C_RID_CODE (scspec
);
8115 if (specs
->non_sc_seen_p
)
8116 warning (OPT_Wold_style_declaration
,
8117 "%qE is not at beginning of declaration", scspec
);
8121 /* C99 permits duplicate inline. Although of doubtful utility,
8122 it seems simplest to permit it in gnu89 mode as well, as
8123 there is also little utility in maintaining this as a
8124 difference between gnu89 and C99 inline. */
8126 specs
->inline_p
= true;
8129 dupe
= specs
->thread_p
;
8130 if (specs
->storage_class
== csc_auto
)
8131 error ("%<__thread%> used with %<auto%>");
8132 else if (specs
->storage_class
== csc_register
)
8133 error ("%<__thread%> used with %<register%>");
8134 else if (specs
->storage_class
== csc_typedef
)
8135 error ("%<__thread%> used with %<typedef%>");
8137 specs
->thread_p
= true;
8144 /* Diagnose "__thread extern". */
8145 if (specs
->thread_p
)
8146 error ("%<__thread%> before %<extern%>");
8153 /* Diagnose "__thread static". */
8154 if (specs
->thread_p
)
8155 error ("%<__thread%> before %<static%>");
8163 if (n
!= csc_none
&& n
== specs
->storage_class
)
8166 error ("duplicate %qE", scspec
);
8169 if (specs
->storage_class
!= csc_none
&& n
!= specs
->storage_class
)
8171 error ("multiple storage classes in declaration specifiers");
8175 specs
->storage_class
= n
;
8176 if (n
!= csc_extern
&& n
!= csc_static
&& specs
->thread_p
)
8178 error ("%<__thread%> used with %qE", scspec
);
8179 specs
->thread_p
= false;
8186 /* Add the attributes ATTRS to the declaration specifiers SPECS,
8189 struct c_declspecs
*
8190 declspecs_add_attrs (struct c_declspecs
*specs
, tree attrs
)
8192 specs
->attrs
= chainon (attrs
, specs
->attrs
);
8193 specs
->declspecs_seen_p
= true;
8197 /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
8198 specifiers with any other type specifier to determine the resulting
8199 type. This is where ISO C checks on complex types are made, since
8200 "_Complex long" is a prefix of the valid ISO C type "_Complex long
8203 struct c_declspecs
*
8204 finish_declspecs (struct c_declspecs
*specs
)
8206 /* If a type was specified as a whole, we have no modifiers and are
8208 if (specs
->type
!= NULL_TREE
)
8210 gcc_assert (!specs
->long_p
&& !specs
->long_long_p
&& !specs
->short_p
8211 && !specs
->signed_p
&& !specs
->unsigned_p
8212 && !specs
->complex_p
);
8216 /* If none of "void", "_Bool", "char", "int", "float" or "double"
8217 has been specified, treat it as "int" unless "_Complex" is
8218 present and there are no other specifiers. If we just have
8219 "_Complex", it is equivalent to "_Complex double", but e.g.
8220 "_Complex short" is equivalent to "_Complex short int". */
8221 if (specs
->typespec_word
== cts_none
)
8223 if (specs
->saturating_p
)
8225 error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
8226 if (!targetm
.fixed_point_supported_p ())
8227 error ("fixed-point types not supported for this target");
8228 specs
->typespec_word
= cts_fract
;
8230 else if (specs
->long_p
|| specs
->short_p
8231 || specs
->signed_p
|| specs
->unsigned_p
)
8233 specs
->typespec_word
= cts_int
;
8235 else if (specs
->complex_p
)
8237 specs
->typespec_word
= cts_double
;
8238 pedwarn (input_location
, OPT_pedantic
,
8239 "ISO C does not support plain %<complex%> meaning "
8240 "%<double complex%>");
8244 specs
->typespec_word
= cts_int
;
8245 specs
->default_int_p
= true;
8246 /* We don't diagnose this here because grokdeclarator will
8247 give more specific diagnostics according to whether it is
8248 a function definition. */
8252 /* If "signed" was specified, record this to distinguish "int" and
8253 "signed int" in the case of a bit-field with
8254 -funsigned-bitfields. */
8255 specs
->explicit_signed_p
= specs
->signed_p
;
8257 /* Now compute the actual type. */
8258 switch (specs
->typespec_word
)
8261 gcc_assert (!specs
->long_p
&& !specs
->short_p
8262 && !specs
->signed_p
&& !specs
->unsigned_p
8263 && !specs
->complex_p
);
8264 specs
->type
= void_type_node
;
8267 gcc_assert (!specs
->long_p
&& !specs
->short_p
8268 && !specs
->signed_p
&& !specs
->unsigned_p
8269 && !specs
->complex_p
);
8270 specs
->type
= boolean_type_node
;
8273 gcc_assert (!specs
->long_p
&& !specs
->short_p
);
8274 gcc_assert (!(specs
->signed_p
&& specs
->unsigned_p
));
8275 if (specs
->signed_p
)
8276 specs
->type
= signed_char_type_node
;
8277 else if (specs
->unsigned_p
)
8278 specs
->type
= unsigned_char_type_node
;
8280 specs
->type
= char_type_node
;
8281 if (specs
->complex_p
)
8283 pedwarn (input_location
, OPT_pedantic
,
8284 "ISO C does not support complex integer types");
8285 specs
->type
= build_complex_type (specs
->type
);
8289 gcc_assert (!(specs
->long_p
&& specs
->short_p
));
8290 gcc_assert (!(specs
->signed_p
&& specs
->unsigned_p
));
8291 if (specs
->long_long_p
)
8292 specs
->type
= (specs
->unsigned_p
8293 ? long_long_unsigned_type_node
8294 : long_long_integer_type_node
);
8295 else if (specs
->long_p
)
8296 specs
->type
= (specs
->unsigned_p
8297 ? long_unsigned_type_node
8298 : long_integer_type_node
);
8299 else if (specs
->short_p
)
8300 specs
->type
= (specs
->unsigned_p
8301 ? short_unsigned_type_node
8302 : short_integer_type_node
);
8304 specs
->type
= (specs
->unsigned_p
8305 ? unsigned_type_node
8306 : integer_type_node
);
8307 if (specs
->complex_p
)
8309 pedwarn (input_location
, OPT_pedantic
,
8310 "ISO C does not support complex integer types");
8311 specs
->type
= build_complex_type (specs
->type
);
8315 gcc_assert (!specs
->long_p
&& !specs
->short_p
8316 && !specs
->signed_p
&& !specs
->unsigned_p
);
8317 specs
->type
= (specs
->complex_p
8318 ? complex_float_type_node
8322 gcc_assert (!specs
->long_long_p
&& !specs
->short_p
8323 && !specs
->signed_p
&& !specs
->unsigned_p
);
8326 specs
->type
= (specs
->complex_p
8327 ? complex_long_double_type_node
8328 : long_double_type_node
);
8332 specs
->type
= (specs
->complex_p
8333 ? complex_double_type_node
8334 : double_type_node
);
8340 gcc_assert (!specs
->long_p
&& !specs
->long_long_p
&& !specs
->short_p
8341 && !specs
->signed_p
&& !specs
->unsigned_p
&& !specs
->complex_p
);
8342 if (specs
->typespec_word
== cts_dfloat32
)
8343 specs
->type
= dfloat32_type_node
;
8344 else if (specs
->typespec_word
== cts_dfloat64
)
8345 specs
->type
= dfloat64_type_node
;
8347 specs
->type
= dfloat128_type_node
;
8350 gcc_assert (!specs
->complex_p
);
8351 if (!targetm
.fixed_point_supported_p ())
8352 specs
->type
= integer_type_node
;
8353 else if (specs
->saturating_p
)
8355 if (specs
->long_long_p
)
8356 specs
->type
= specs
->unsigned_p
8357 ? sat_unsigned_long_long_fract_type_node
8358 : sat_long_long_fract_type_node
;
8359 else if (specs
->long_p
)
8360 specs
->type
= specs
->unsigned_p
8361 ? sat_unsigned_long_fract_type_node
8362 : sat_long_fract_type_node
;
8363 else if (specs
->short_p
)
8364 specs
->type
= specs
->unsigned_p
8365 ? sat_unsigned_short_fract_type_node
8366 : sat_short_fract_type_node
;
8368 specs
->type
= specs
->unsigned_p
8369 ? sat_unsigned_fract_type_node
8370 : sat_fract_type_node
;
8374 if (specs
->long_long_p
)
8375 specs
->type
= specs
->unsigned_p
8376 ? unsigned_long_long_fract_type_node
8377 : long_long_fract_type_node
;
8378 else if (specs
->long_p
)
8379 specs
->type
= specs
->unsigned_p
8380 ? unsigned_long_fract_type_node
8381 : long_fract_type_node
;
8382 else if (specs
->short_p
)
8383 specs
->type
= specs
->unsigned_p
8384 ? unsigned_short_fract_type_node
8385 : short_fract_type_node
;
8387 specs
->type
= specs
->unsigned_p
8388 ? unsigned_fract_type_node
8393 gcc_assert (!specs
->complex_p
);
8394 if (!targetm
.fixed_point_supported_p ())
8395 specs
->type
= integer_type_node
;
8396 else if (specs
->saturating_p
)
8398 if (specs
->long_long_p
)
8399 specs
->type
= specs
->unsigned_p
8400 ? sat_unsigned_long_long_accum_type_node
8401 : sat_long_long_accum_type_node
;
8402 else if (specs
->long_p
)
8403 specs
->type
= specs
->unsigned_p
8404 ? sat_unsigned_long_accum_type_node
8405 : sat_long_accum_type_node
;
8406 else if (specs
->short_p
)
8407 specs
->type
= specs
->unsigned_p
8408 ? sat_unsigned_short_accum_type_node
8409 : sat_short_accum_type_node
;
8411 specs
->type
= specs
->unsigned_p
8412 ? sat_unsigned_accum_type_node
8413 : sat_accum_type_node
;
8417 if (specs
->long_long_p
)
8418 specs
->type
= specs
->unsigned_p
8419 ? unsigned_long_long_accum_type_node
8420 : long_long_accum_type_node
;
8421 else if (specs
->long_p
)
8422 specs
->type
= specs
->unsigned_p
8423 ? unsigned_long_accum_type_node
8424 : long_accum_type_node
;
8425 else if (specs
->short_p
)
8426 specs
->type
= specs
->unsigned_p
8427 ? unsigned_short_accum_type_node
8428 : short_accum_type_node
;
8430 specs
->type
= specs
->unsigned_p
8431 ? unsigned_accum_type_node
8442 /* A subroutine of c_write_global_declarations. Perform final processing
8443 on one file scope's declarations (or the external scope's declarations),
8447 c_write_global_declarations_1 (tree globals
)
8452 /* Process the decls in the order they were written. */
8453 for (decl
= globals
; decl
; decl
= TREE_CHAIN (decl
))
8455 /* Check for used but undefined static functions using the C
8456 standard's definition of "used", and set TREE_NO_WARNING so
8457 that check_global_declarations doesn't repeat the check. */
8458 if (TREE_CODE (decl
) == FUNCTION_DECL
8459 && DECL_INITIAL (decl
) == 0
8460 && DECL_EXTERNAL (decl
)
8461 && !TREE_PUBLIC (decl
)
8462 && C_DECL_USED (decl
))
8464 pedwarn (input_location
, 0, "%q+F used but never defined", decl
);
8465 TREE_NO_WARNING (decl
) = 1;
8468 wrapup_global_declaration_1 (decl
);
8474 for (decl
= globals
; decl
; decl
= TREE_CHAIN (decl
))
8475 reconsider
|= wrapup_global_declaration_2 (decl
);
8479 for (decl
= globals
; decl
; decl
= TREE_CHAIN (decl
))
8480 check_global_declaration_1 (decl
);
8483 /* A subroutine of c_write_global_declarations Emit debug information for each
8484 of the declarations in GLOBALS. */
8487 c_write_global_declarations_2 (tree globals
)
8491 for (decl
= globals
; decl
; decl
= TREE_CHAIN (decl
))
8492 debug_hooks
->global_decl (decl
);
8495 /* Preserve the external declarations scope across a garbage collect. */
8496 static GTY(()) tree ext_block
;
8499 c_write_global_declarations (void)
8503 /* We don't want to do this if generating a PCH. */
8507 /* Don't waste time on further processing if -fsyntax-only or we've
8508 encountered errors. */
8509 if (flag_syntax_only
|| errorcount
|| sorrycount
)
8512 /* Close the external scope. */
8513 ext_block
= pop_scope ();
8515 gcc_assert (!current_scope
);
8519 tree tmp
= BLOCK_VARS (ext_block
);
8521 FILE * stream
= dump_begin (TDI_tu
, &flags
);
8524 dump_node (tmp
, flags
& ~TDF_SLIM
, stream
);
8525 dump_end (TDI_tu
, stream
);
8529 /* Process all file scopes in this compilation, and the external_scope,
8530 through wrapup_global_declarations and check_global_declarations. */
8531 for (t
= all_translation_units
; t
; t
= TREE_CHAIN (t
))
8532 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t
)));
8533 c_write_global_declarations_1 (BLOCK_VARS (ext_block
));
8535 /* We're done parsing; proceed to optimize and emit assembly.
8536 FIXME: shouldn't be the front end's responsibility to call this. */
8539 /* After cgraph has had a chance to emit everything that's going to
8540 be emitted, output debug information for globals. */
8541 if (errorcount
== 0 && sorrycount
== 0)
8543 timevar_push (TV_SYMOUT
);
8544 for (t
= all_translation_units
; t
; t
= TREE_CHAIN (t
))
8545 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t
)));
8546 c_write_global_declarations_2 (BLOCK_VARS (ext_block
));
8547 timevar_pop (TV_SYMOUT
);
8553 #include "gt-c-decl.h"