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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
31 #include "coretypes.h"
35 #include "tree-inline.h"
56 #include "langhooks-def.h"
58 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
60 { NORMAL
, /* Ordinary declaration */
61 FUNCDEF
, /* Function definition */
62 PARM
, /* Declaration of parm before function body */
63 FIELD
, /* Declaration inside struct or union */
64 TYPENAME
}; /* Typename (inside cast or sizeof) */
67 /* Nonzero if we have seen an invalid cross reference
68 to a struct, union, or enum, but not yet printed the message. */
70 tree pending_invalid_xref
;
71 /* File and line to appear in the eventual error message. */
72 location_t pending_invalid_xref_location
;
74 /* While defining an enum type, this is 1 plus the last enumerator
75 constant value. Note that will do not have to save this or `enum_overflow'
76 around nested function definition since such a definition could only
77 occur in an enum value expression and we don't use these variables in
80 static tree enum_next_value
;
82 /* Nonzero means that there was overflow computing enum_next_value. */
84 static int enum_overflow
;
86 /* These #defines are for clarity in working with the information block
87 returned by get_parm_info. */
88 #define ARG_INFO_PARMS(args) TREE_PURPOSE(args)
89 #define ARG_INFO_TAGS(args) TREE_VALUE(args)
90 #define ARG_INFO_TYPES(args) TREE_CHAIN(args)
91 #define ARG_INFO_OTHERS(args) TREE_TYPE(args)
93 /* The file and line that the prototype came from if this is an
94 old-style definition; used for diagnostics in
95 store_parm_decls_oldstyle. */
97 static location_t current_function_prototype_locus
;
99 /* The current statement tree. */
101 static GTY(()) struct stmt_tree_s c_stmt_tree
;
103 /* The current scope statement stack. */
105 static GTY(()) tree c_scope_stmt_stack
;
107 /* State saving variables. */
108 int c_in_iteration_stmt
;
111 /* A DECL for the current file-scope context. */
113 static GTY(()) tree current_file_decl
;
115 /* A list of decls to be made automatically visible in each file scope. */
116 static GTY(()) tree visible_builtins
;
118 /* Set to 0 at beginning of a function definition, set to 1 if
119 a return statement that specifies a return value is seen. */
121 int current_function_returns_value
;
123 /* Set to 0 at beginning of a function definition, set to 1 if
124 a return statement with no argument is seen. */
126 int current_function_returns_null
;
128 /* Set to 0 at beginning of a function definition, set to 1 if
129 a call to a noreturn function is seen. */
131 int current_function_returns_abnormally
;
133 /* Set to nonzero by `grokdeclarator' for a function
134 whose return type is defaulted, if warnings for this are desired. */
136 static int warn_about_return_type
;
138 /* Nonzero when starting a function declared `extern inline'. */
140 static int current_extern_inline
;
142 /* True means global_bindings_p should return false even if the scope stack
143 says we are in file scope. */
144 bool c_override_global_bindings_to_false
;
147 /* Each c_binding structure describes one binding of an identifier to
148 a decl. All the decls in a scope - irrespective of namespace - are
149 chained together by the ->prev field, which (as the name implies)
150 runs in reverse order. All the decls in a given namespace bound to
151 a given identifier are chained by the ->shadowed field, which runs
152 from inner to outer scopes. Finally, the ->contour field points
153 back to the relevant scope structure; this is mainly used to make
154 decls in the externals scope invisible (see below).
156 The ->decl field usually points to a DECL node, but there are two
157 exceptions. In the namespace of type tags, the bound entity is a
158 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
159 identifier is encountered, it is bound to error_mark_node to
160 suppress further errors about that identifier in the current
163 struct c_binding
GTY((chain_next ("%h.prev")))
165 tree decl
; /* the decl bound */
166 tree id
; /* the identifier it's bound to */
167 struct c_binding
*prev
; /* the previous decl in this scope */
168 struct c_binding
*shadowed
; /* the innermost decl shadowed by this one */
169 struct c_scope
*contour
; /* the scope in which this decl is bound */
172 #define I_SYMBOL_BINDING(node) \
173 (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->symbol_binding)
174 #define I_SYMBOL_DECL(node) \
175 (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
177 #define I_TAG_BINDING(node) \
178 (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->tag_binding)
179 #define I_TAG_DECL(node) \
180 (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
182 #define I_LABEL_BINDING(node) \
183 (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->label_binding)
184 #define I_LABEL_DECL(node) \
185 (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
187 /* Each C symbol points to three linked lists of c_binding structures.
188 These describe the values of the identifier in the three different
189 namespaces defined by the language. */
191 struct lang_identifier
GTY(())
193 struct c_common_identifier common_id
;
194 struct c_binding
*symbol_binding
; /* vars, funcs, constants, typedefs */
195 struct c_binding
*tag_binding
; /* struct/union/enum tags */
196 struct c_binding
*label_binding
; /* labels */
199 /* Validate c-lang.c's assumptions. */
200 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
201 [(sizeof(struct lang_identifier
) == C_SIZEOF_STRUCT_LANG_IDENTIFIER
) ? 1 : -1];
203 /* The resulting tree type. */
206 GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
207 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)")))
209 union tree_node
GTY ((tag ("0"),
210 desc ("tree_node_structure (&%h)")))
212 struct lang_identifier
GTY ((tag ("1"))) identifier
;
215 /* Each c_scope structure describes the complete contents of one
216 scope. Four scopes are distinguished specially: the innermost or
217 current scope, the innermost function scope, the file scope (always
218 the second to outermost) and the outermost or external scope.
220 Most declarations are recorded in the current scope.
222 All normal label declarations are recorded in the innermost
223 function scope, as are bindings of undeclared identifiers to
224 error_mark_node. (GCC permits nested functions as an extension,
225 hence the 'innermost' qualifier.) Explicitly declared labels
226 (using the __label__ extension) appear in the current scope.
228 Being in the file scope (current_scope == file_scope) causes
229 special behavior in several places below. Also, under some
230 conditions the Objective-C front end records declarations in the
231 file scope even though that isn't the current scope.
233 All declarations with external linkage are recorded in the external
234 scope, even if they aren't visible there; this models the fact that
235 such declarations are visible to the entire program, and (with a
236 bit of cleverness, see pushdecl) allows diagnosis of some violations
237 of C99 6.2.2p7 and 6.2.7p2:
239 If, within the same translation unit, the same identifier appears
240 with both internal and external linkage, the behavior is
243 All declarations that refer to the same object or function shall
244 have compatible type; otherwise, the behavior is undefined.
246 Initially only the built-in declarations, which describe compiler
247 intrinsic functions plus a subset of the standard library, are in
250 The order of the blocks list matters, and it is frequently appended
251 to. To avoid having to walk all the way to the end of the list on
252 each insertion, or reverse the list later, we maintain a pointer to
253 the last list entry. (FIXME: It should be feasible to use a reversed
256 The bindings list is strictly in reverse order of declarations;
257 pop_scope relies on this. */
260 struct c_scope
GTY((chain_next ("%h.outer")))
262 /* The scope containing this one. */
263 struct c_scope
*outer
;
265 /* The next outermost function scope. */
266 struct c_scope
*outer_function
;
268 /* All bindings in this scope. */
269 struct c_binding
*bindings
;
271 /* For each scope (except the global one), a chain of BLOCK nodes
272 for all the scopes that were entered and exited one level down. */
276 /* The depth of this scope. Used to keep the ->shadowed chain of
277 bindings sorted innermost to outermost. */
278 unsigned int depth
: 28;
280 /* True if we are currently filling this scope with parameter
282 BOOL_BITFIELD parm_flag
: 1;
284 /* True if we already complained about forward parameter decls
285 in this scope. This prevents double warnings on
286 foo (int a; int b; ...) */
287 BOOL_BITFIELD warned_forward_parm_decls
: 1;
289 /* True if this is the outermost block scope of a function body.
290 This scope contains the parameters, the local variables declared
291 in the outermost block, and all the labels (except those in
292 nested functions, or declared at block scope with __label__). */
293 BOOL_BITFIELD function_body
: 1;
295 /* True means make a BLOCK for this scope no matter what. */
296 BOOL_BITFIELD keep
: 1;
299 /* The scope currently in effect. */
301 static GTY(()) struct c_scope
*current_scope
;
303 /* The innermost function scope. Ordinary (not explicitly declared)
304 labels, bindings to error_mark_node, and the lazily-created
305 bindings of __func__ and its friends get this scope. */
307 static GTY(()) struct c_scope
*current_function_scope
;
309 /* The C file scope. This is reset for each input translation unit. */
311 static GTY(()) struct c_scope
*file_scope
;
313 /* The outermost scope. This is used for all declarations with
314 external linkage, and only these, hence the name. */
316 static GTY(()) struct c_scope
*external_scope
;
318 /* A chain of c_scope structures awaiting reuse. */
320 static GTY((deletable
)) struct c_scope
*scope_freelist
;
322 /* A chain of c_binding structures awaiting reuse. */
324 static GTY((deletable
)) struct c_binding
*binding_freelist
;
326 /* Append VAR to LIST in scope SCOPE. */
327 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
328 struct c_scope *s_ = (scope); \
330 if (s_->list##_last) \
331 TREE_CHAIN (s_->list##_last) = d_; \
334 s_->list##_last = d_; \
337 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
338 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
339 struct c_scope *t_ = (tscope); \
340 struct c_scope *f_ = (fscope); \
342 TREE_CHAIN (t_->to##_last) = f_->from; \
345 t_->to##_last = f_->from##_last; \
348 /* True means unconditionally make a BLOCK for the next scope pushed. */
350 static bool keep_next_level_flag
;
352 /* True means the next call to push_scope will be the outermost scope
353 of a function body, so do not push a new scope, merely cease
354 expecting parameter decls. */
356 static bool next_is_function_body
;
358 /* Functions called automatically at the beginning and end of execution. */
360 tree static_ctors
, static_dtors
;
362 /* Forward declarations. */
363 static tree
lookup_name_in_scope (tree
, struct c_scope
*);
364 static tree
c_make_fname_decl (tree
, int);
365 static tree
grokdeclarator (tree
, tree
, enum decl_context
, int, tree
*);
366 static tree
grokparms (tree
, int);
367 static void layout_array_type (tree
);
369 /* States indicating how grokdeclarator() should handle declspecs marked
370 with __attribute__((deprecated)). An object declared as
371 __attribute__((deprecated)) suppresses warnings of uses of other
374 enum deprecated_states
{
379 static enum deprecated_states deprecated_state
= DEPRECATED_NORMAL
;
382 c_print_identifier (FILE *file
, tree node
, int indent
)
384 print_node (file
, "symbol", I_SYMBOL_DECL (node
), indent
+ 4);
385 print_node (file
, "tag", I_TAG_DECL (node
), indent
+ 4);
386 print_node (file
, "label", I_LABEL_DECL (node
), indent
+ 4);
387 if (C_IS_RESERVED_WORD (node
))
389 tree rid
= ridpointers
[C_RID_CODE (node
)];
390 indent_to (file
, indent
+ 4);
391 fprintf (file
, "rid " HOST_PTR_PRINTF
" \"%s\"",
392 (void *) rid
, IDENTIFIER_POINTER (rid
));
396 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
397 which may be any of several kinds of DECL or TYPE or error_mark_node,
398 in the scope SCOPE. */
400 bind (tree name
, tree decl
, struct c_scope
*scope
)
402 struct c_binding
*b
, **here
;
404 if (binding_freelist
)
406 b
= binding_freelist
;
407 binding_freelist
= b
->prev
;
410 b
= ggc_alloc (sizeof (struct c_binding
));
417 b
->prev
= scope
->bindings
;
423 switch (TREE_CODE (decl
))
425 case LABEL_DECL
: here
= &I_LABEL_BINDING (name
); break;
428 case RECORD_TYPE
: here
= &I_TAG_BINDING (name
); break;
434 case ERROR_MARK
: here
= &I_SYMBOL_BINDING (name
); break;
440 /* Locate the appropriate place in the chain of shadowed decls
441 to insert this binding. Normally, scope == current_scope and
442 this does nothing. */
443 while (*here
&& (*here
)->contour
->depth
> scope
->depth
)
444 here
= &(*here
)->shadowed
;
450 /* Clear the binding structure B, stick it on the binding_freelist,
451 and return the former value of b->prev. This is used by pop_scope
452 and get_parm_info to iterate destructively over all the bindings
453 from a given scope. */
454 static struct c_binding
*
455 free_binding_and_advance (struct c_binding
*b
)
457 struct c_binding
*prev
= b
->prev
;
463 b
->prev
= binding_freelist
;
464 binding_freelist
= b
;
470 /* Hook called at end of compilation to assume 1 elt
471 for a file-scope tentative array defn that wasn't complete before. */
474 c_finish_incomplete_decl (tree decl
)
476 if (TREE_CODE (decl
) == VAR_DECL
)
478 tree type
= TREE_TYPE (decl
);
479 if (type
!= error_mark_node
480 && TREE_CODE (type
) == ARRAY_TYPE
481 && ! DECL_EXTERNAL (decl
)
482 && TYPE_DOMAIN (type
) == 0)
484 warning ("%Jarray '%D' assumed to have one element", decl
, decl
);
486 complete_array_type (type
, NULL_TREE
, 1);
488 layout_decl (decl
, 0);
493 /* The Objective-C front-end often needs to determine the current scope. */
496 get_current_scope (void)
498 return current_scope
;
501 /* The following function is used only by Objective-C. It needs to live here
502 because it accesses the innards of c_scope. */
505 objc_mark_locals_volatile (void *enclosing_blk
)
507 struct c_scope
*scope
;
510 for (scope
= current_scope
;
511 scope
&& scope
!= enclosing_blk
;
512 scope
= scope
->outer
)
514 for (b
= scope
->bindings
; b
; b
= b
->prev
)
516 if (TREE_CODE (b
->decl
) == VAR_DECL
517 || TREE_CODE (b
->decl
) == PARM_DECL
)
519 C_DECL_REGISTER (b
->decl
) = 0;
520 DECL_REGISTER (b
->decl
) = 0;
521 TREE_THIS_VOLATILE (b
->decl
) = 1;
525 /* Do not climb up past the current function. */
526 if (scope
->function_body
)
531 /* Nonzero if we are currently in file scope. */
534 global_bindings_p (void)
536 return current_scope
== file_scope
&& !c_override_global_bindings_to_false
;
540 keep_next_level (void)
542 keep_next_level_flag
= true;
545 /* Identify this scope as currently being filled with parameters. */
548 declare_parm_level (void)
550 current_scope
->parm_flag
= true;
556 if (next_is_function_body
)
558 /* This is the transition from the parameters to the top level
559 of the function body. These are the same scope
560 (C99 6.2.1p4,6) so we do not push another scope structure.
561 next_is_function_body is set only by store_parm_decls, which
562 in turn is called when and only when we are about to
563 encounter the opening curly brace for the function body.
565 The outermost block of a function always gets a BLOCK node,
566 because the debugging output routines expect that each
567 function has at least one BLOCK. */
568 current_scope
->parm_flag
= false;
569 current_scope
->function_body
= true;
570 current_scope
->keep
= true;
571 current_scope
->outer_function
= current_function_scope
;
572 current_function_scope
= current_scope
;
574 keep_next_level_flag
= false;
575 next_is_function_body
= false;
579 struct c_scope
*scope
;
582 scope
= scope_freelist
;
583 scope_freelist
= scope
->outer
;
586 scope
= ggc_alloc_cleared (sizeof (struct c_scope
));
588 scope
->keep
= keep_next_level_flag
;
589 scope
->outer
= current_scope
;
590 scope
->depth
= current_scope
? (current_scope
->depth
+ 1) : 0;
592 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but
594 if (current_scope
&& scope
->depth
== 0)
597 sorry ("GCC supports only %u nested scopes\n", scope
->depth
);
600 current_scope
= scope
;
601 keep_next_level_flag
= false;
605 /* Exit a scope. Restore the state of the identifier-decl mappings
606 that were in effect when this scope was entered. Return a BLOCK
607 node containing all the DECLs in this scope that are of interest
608 to debug info generation. */
613 struct c_scope
*scope
= current_scope
;
614 tree block
, context
, p
;
617 bool functionbody
= scope
->function_body
;
618 bool keep
= functionbody
|| scope
->keep
|| scope
->bindings
;
620 /* If appropriate, create a BLOCK to record the decls for the life
625 block
= make_node (BLOCK
);
626 BLOCK_SUBBLOCKS (block
) = scope
->blocks
;
627 TREE_USED (block
) = 1;
629 /* In each subblock, record that this is its superior. */
630 for (p
= scope
->blocks
; p
; p
= TREE_CHAIN (p
))
631 BLOCK_SUPERCONTEXT (p
) = block
;
633 BLOCK_VARS (block
) = 0;
636 /* The TYPE_CONTEXTs for all of the tagged types belonging to this
637 scope must be set so that they point to the appropriate
638 construct, i.e. either to the current FUNCTION_DECL node, or
639 else to the BLOCK node we just constructed.
641 Note that for tagged types whose scope is just the formal
642 parameter list for some function type specification, we can't
643 properly set their TYPE_CONTEXTs here, because we don't have a
644 pointer to the appropriate FUNCTION_TYPE node readily available
645 to us. For those cases, the TYPE_CONTEXTs of the relevant tagged
646 type nodes get set in `grokdeclarator' as soon as we have created
647 the FUNCTION_TYPE node which will represent the "scope" for these
648 "parameter list local" tagged types. */
649 if (scope
->function_body
)
650 context
= current_function_decl
;
651 else if (scope
== file_scope
)
652 context
= current_file_decl
;
656 /* Clear all bindings in this scope. */
657 for (b
= scope
->bindings
; b
; b
= free_binding_and_advance (b
))
660 switch (TREE_CODE (p
))
663 /* Warnings for unused labels, errors for undefined labels. */
664 if (TREE_USED (p
) && !DECL_INITIAL (p
))
666 error ("%Jlabel `%D' used but not defined", p
, p
);
667 DECL_INITIAL (p
) = error_mark_node
;
669 else if (!TREE_USED (p
) && warn_unused_label
)
671 if (DECL_INITIAL (p
))
672 warning ("%Jlabel `%D' defined but not used", p
, p
);
674 warning ("%Jlabel `%D' declared but not defined", p
, p
);
676 /* Labels go in BLOCK_VARS. */
677 TREE_CHAIN (p
) = BLOCK_VARS (block
);
678 BLOCK_VARS (block
) = p
;
680 #ifdef ENABLE_CHECKING
681 if (I_LABEL_BINDING (b
->id
) != b
) abort ();
683 I_LABEL_BINDING (b
->id
) = b
->shadowed
;
689 TYPE_CONTEXT (p
) = context
;
691 /* Types may not have tag-names, in which case the type
692 appears in the bindings list with b->id NULL. */
695 #ifdef ENABLE_CHECKING
696 if (I_TAG_BINDING (b
->id
) != b
) abort ();
698 I_TAG_BINDING (b
->id
) = b
->shadowed
;
703 /* Propagate TREE_ADDRESSABLE from nested functions to their
704 containing functions. */
705 if (! TREE_ASM_WRITTEN (p
)
706 && DECL_INITIAL (p
) != 0
707 && TREE_ADDRESSABLE (p
)
708 && DECL_ABSTRACT_ORIGIN (p
) != 0
709 && DECL_ABSTRACT_ORIGIN (p
) != p
)
710 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p
)) = 1;
714 /* Warnings for unused variables. Keep this in sync with
715 stmt.c:warn_about_unused_variables, which we cannot use
716 since it expects a different data structure. */
717 if (warn_unused_variable
719 && !DECL_IN_SYSTEM_HEADER (p
)
721 && !DECL_ARTIFICIAL (p
)
722 && (scope
!= file_scope
723 || (TREE_STATIC (p
) && !TREE_PUBLIC (p
)
724 && !TREE_THIS_VOLATILE (p
)))
725 && scope
!= external_scope
)
726 warning ("%Junused variable `%D'", p
, p
);
732 /* All of these go in BLOCK_VARS, but only if this is the
733 binding in the home scope. */
734 if (!C_DECL_IN_EXTERNAL_SCOPE (p
) || scope
== external_scope
)
736 TREE_CHAIN (p
) = BLOCK_VARS (block
);
737 BLOCK_VARS (block
) = p
;
741 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
742 already been put there by store_parm_decls. Unused-
743 parameter warnings are handled by function.c.
744 error_mark_node obviously does not go in BLOCK_VARS and
745 does not get unused-variable warnings. */
748 /* It is possible for a decl not to have a name. We get
749 here with b->id NULL in this case. */
752 #ifdef ENABLE_CHECKING
753 if (I_SYMBOL_BINDING (b
->id
) != b
) abort ();
755 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
765 /* Dispose of the block that we just made inside some higher level. */
766 if ((scope
->function_body
|| scope
== file_scope
) && context
)
768 DECL_INITIAL (context
) = block
;
769 BLOCK_SUPERCONTEXT (block
) = context
;
771 else if (scope
->outer
)
774 SCOPE_LIST_APPEND (scope
->outer
, blocks
, block
);
775 /* If we did not make a block for the scope just exited, any
776 blocks made for inner scopes must be carried forward so they
777 will later become subblocks of something else. */
778 else if (scope
->blocks
)
779 SCOPE_LIST_CONCAT (scope
->outer
, blocks
, scope
, blocks
);
782 /* Pop the current scope, and free the structure for reuse. */
783 current_scope
= scope
->outer
;
784 if (scope
->function_body
)
785 current_function_scope
= scope
->outer_function
;
787 memset (scope
, 0, sizeof (struct c_scope
));
788 scope
->outer
= scope_freelist
;
789 scope_freelist
= scope
;
795 push_file_scope (void)
798 tree file_decl
= build_decl (TRANSLATION_UNIT_DECL
, 0, 0);
799 TREE_CHAIN (file_decl
) = current_file_decl
;
800 current_file_decl
= file_decl
;
803 file_scope
= current_scope
;
805 start_fname_decls ();
807 for (decl
= visible_builtins
; decl
; decl
= TREE_CHAIN (decl
))
808 bind (DECL_NAME (decl
), decl
, file_scope
);
812 pop_file_scope (void)
814 /* In case there were missing closebraces, get us back to the global
816 while (current_scope
!= file_scope
)
819 /* __FUNCTION__ is defined at file scope (""). This
820 call may not be necessary as my tests indicate it
821 still works without it. */
822 finish_fname_decls ();
824 /* Kludge: don't actually pop the file scope if generating a
825 precompiled header, so that macros and local symbols are still
826 visible to the PCH generator. */
830 /* And pop off the file scope. */
834 cpp_undef_all (parse_in
);
837 /* Insert BLOCK at the end of the list of subblocks of the current
838 scope. This is used when a BIND_EXPR is expanded, to handle the
839 BLOCK node inside the BIND_EXPR. */
842 insert_block (tree block
)
844 TREE_USED (block
) = 1;
845 SCOPE_LIST_APPEND (current_scope
, blocks
, block
);
848 /* Push a definition or a declaration of struct, union or enum tag "name".
849 "type" should be the type node.
850 We assume that the tag "name" is not already defined.
852 Note that the definition may really be just a forward reference.
853 In that case, the TYPE_SIZE will be zero. */
856 pushtag (tree name
, tree type
)
858 /* Record the identifier as the type's name if it has none. */
859 if (name
&& !TYPE_NAME (type
))
860 TYPE_NAME (type
) = name
;
861 bind (name
, type
, current_scope
);
863 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
864 tagged type we just added to the current scope. This fake
865 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
866 to output a representation of a tagged type, and it also gives
867 us a convenient place to record the "scope start" address for the
870 TYPE_STUB_DECL (type
) = pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, type
));
872 /* An approximation for now, so we can tell this is a function-scope tag.
873 This will be updated in pop_scope. */
874 TYPE_CONTEXT (type
) = DECL_CONTEXT (TYPE_STUB_DECL (type
));
877 /* Subroutine of compare_decls. Allow harmless mismatches in return
878 and argument types provided that the type modes match. This function
879 return a unified type given a suitable match, and 0 otherwise. */
882 match_builtin_function_types (tree newtype
, tree oldtype
)
884 tree newrettype
, oldrettype
;
885 tree newargs
, oldargs
;
886 tree trytype
, tryargs
;
888 /* Accept the return type of the new declaration if same modes. */
889 oldrettype
= TREE_TYPE (oldtype
);
890 newrettype
= TREE_TYPE (newtype
);
892 if (TYPE_MODE (oldrettype
) != TYPE_MODE (newrettype
))
895 oldargs
= TYPE_ARG_TYPES (oldtype
);
896 newargs
= TYPE_ARG_TYPES (newtype
);
899 while (oldargs
|| newargs
)
903 || ! TREE_VALUE (oldargs
)
904 || ! TREE_VALUE (newargs
)
905 || TYPE_MODE (TREE_VALUE (oldargs
))
906 != TYPE_MODE (TREE_VALUE (newargs
)))
909 oldargs
= TREE_CHAIN (oldargs
);
910 newargs
= TREE_CHAIN (newargs
);
913 trytype
= build_function_type (newrettype
, tryargs
);
914 return build_type_attribute_variant (trytype
, TYPE_ATTRIBUTES (oldtype
));
917 /* Subroutine of diagnose_mismatched_decls. Check for function type
918 mismatch involving an empty arglist vs a nonempty one and give clearer
921 diagnose_arglist_conflict (tree newdecl
, tree olddecl
,
922 tree newtype
, tree oldtype
)
926 if (TREE_CODE (olddecl
) != FUNCTION_DECL
927 || !comptypes (TREE_TYPE (oldtype
), TREE_TYPE (newtype
), COMPARE_STRICT
)
928 || !((TYPE_ARG_TYPES (oldtype
) == 0 && DECL_INITIAL (olddecl
) == 0)
930 (TYPE_ARG_TYPES (newtype
) == 0 && DECL_INITIAL (newdecl
) == 0)))
933 t
= TYPE_ARG_TYPES (oldtype
);
935 t
= TYPE_ARG_TYPES (newtype
);
936 for (; t
; t
= TREE_CHAIN (t
))
938 tree type
= TREE_VALUE (t
);
940 if (TREE_CHAIN (t
) == 0
941 && TYPE_MAIN_VARIANT (type
) != void_type_node
)
943 inform ("a parameter list with an ellipsis can't match "
944 "an empty parameter name list declaration");
948 if (c_type_promotes_to (type
) != type
)
950 inform ("an argument type that has a default promotion can't match "
951 "an empty parameter name list declaration");
957 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
958 old-style function definition, NEWDECL is a prototype declaration.
959 Diagnose inconsistencies in the argument list. Returns TRUE if
960 the prototype is compatible, FALSE if not. */
962 validate_proto_after_old_defn (tree newdecl
, tree newtype
, tree oldtype
)
964 tree newargs
, oldargs
;
967 /* ??? Elsewhere TYPE_MAIN_VARIANT is not used in this context. */
968 #define END_OF_ARGLIST(t) (TYPE_MAIN_VARIANT (t) == void_type_node)
970 oldargs
= TYPE_ACTUAL_ARG_TYPES (oldtype
);
971 newargs
= TYPE_ARG_TYPES (newtype
);
976 tree oldargtype
= TREE_VALUE (oldargs
);
977 tree newargtype
= TREE_VALUE (newargs
);
979 if (END_OF_ARGLIST (oldargtype
) && END_OF_ARGLIST (newargtype
))
982 /* Reaching the end of just one list means the two decls don't
983 agree on the number of arguments. */
984 if (END_OF_ARGLIST (oldargtype
))
986 error ("%Jprototype for '%D' declares more arguments "
987 "than previous old-style definition", newdecl
, newdecl
);
990 else if (END_OF_ARGLIST (newargtype
))
992 error ("%Jprototype for '%D' declares fewer arguments "
993 "than previous old-style definition", newdecl
, newdecl
);
997 /* Type for passing arg must be consistent with that declared
999 else if (! comptypes (oldargtype
, newargtype
, COMPARE_STRICT
))
1001 error ("%Jprototype for '%D' declares arg %d with incompatible type",
1002 newdecl
, newdecl
, i
);
1006 oldargs
= TREE_CHAIN (oldargs
);
1007 newargs
= TREE_CHAIN (newargs
);
1011 /* If we get here, no errors were found, but do issue a warning
1012 for this poor-style construct. */
1013 warning ("%Jprototype for '%D' follows non-prototype definition",
1016 #undef END_OF_ARGLIST
1019 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
1020 first in a pair of mismatched declarations, using the diagnostic
1023 locate_old_decl (tree decl
, void (*diag
)(const char *, ...))
1025 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
1027 else if (DECL_INITIAL (decl
))
1028 diag (N_("%Jprevious definition of '%D' was here"), decl
, decl
);
1029 else if (C_DECL_IMPLICIT (decl
))
1030 diag (N_("%Jprevious implicit declaration of '%D' was here"), decl
, decl
);
1032 diag (N_("%Jprevious declaration of '%D' was here"), decl
, decl
);
1035 /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL.
1036 Returns true if the caller should proceed to merge the two, false
1037 if OLDDECL should simply be discarded. As a side effect, issues
1038 all necessary diagnostics for invalid or poor-style combinations.
1039 If it returns true, writes the types of NEWDECL and OLDDECL to
1040 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1041 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
1044 diagnose_mismatched_decls (tree newdecl
, tree olddecl
,
1045 tree
*newtypep
, tree
*oldtypep
)
1047 tree newtype
, oldtype
;
1048 bool pedwarned
= false;
1049 bool warned
= false;
1051 /* If we have error_mark_node for either decl or type, just discard
1052 the previous decl - we're in an error cascade already. */
1053 if (olddecl
== error_mark_node
|| newdecl
== error_mark_node
)
1055 *oldtypep
= oldtype
= TREE_TYPE (olddecl
);
1056 *newtypep
= newtype
= TREE_TYPE (newdecl
);
1057 if (oldtype
== error_mark_node
|| newtype
== error_mark_node
)
1060 /* Two different categories of symbol altogether. This is an error
1061 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
1062 if (TREE_CODE (olddecl
) != TREE_CODE (newdecl
))
1064 if (!(TREE_CODE (olddecl
) == FUNCTION_DECL
1065 && DECL_BUILT_IN (olddecl
)
1066 && !C_DECL_DECLARED_BUILTIN (olddecl
)))
1068 error ("%J'%D' redeclared as different kind of symbol",
1070 locate_old_decl (olddecl
, error
);
1072 else if (TREE_PUBLIC (newdecl
))
1073 warning ("%Jbuilt-in function '%D' declared as non-function",
1075 else if (warn_shadow
)
1076 warning ("%Jdeclaration of '%D' shadows a built-in function",
1081 if (!comptypes (oldtype
, newtype
, COMPARE_STRICT
))
1083 if (TREE_CODE (olddecl
) == FUNCTION_DECL
1084 && DECL_BUILT_IN (olddecl
) && !C_DECL_DECLARED_BUILTIN (olddecl
))
1086 /* Accept harmless mismatch in function types.
1087 This is for the ffs and fprintf builtins. */
1088 tree trytype
= match_builtin_function_types (newtype
, oldtype
);
1090 if (trytype
&& comptypes (newtype
, trytype
, COMPARE_STRICT
))
1091 *oldtypep
= oldtype
= trytype
;
1094 /* If types don't match for a built-in, throw away the
1095 built-in. No point in calling locate_old_decl here, it
1096 won't print anything. */
1097 warning ("%Jconflicting types for built-in function '%D'",
1102 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
1103 && DECL_SOURCE_LINE (olddecl
) == 0)
1105 /* A conflicting function declaration for a predeclared
1106 function that isn't actually built in. Objective C uses
1107 these. The new declaration silently overrides everything
1108 but the volatility (i.e. noreturn) indication. See also
1109 below. FIXME: Make Objective C use normal builtins. */
1110 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1113 /* Permit void foo (...) to match int foo (...) if the latter is
1114 the definition and implicit int was used. See
1115 c-torture/compile/920625-2.c. */
1116 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
&& DECL_INITIAL (newdecl
)
1117 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype
)) == void_type_node
1118 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype
)) == integer_type_node
1119 && C_FUNCTION_IMPLICIT_INT (newdecl
))
1121 pedwarn ("%Jconflicting types for '%D'", newdecl
, newdecl
);
1122 /* Make sure we keep void as the return type. */
1123 TREE_TYPE (newdecl
) = *newtypep
= newtype
= oldtype
;
1124 C_FUNCTION_IMPLICIT_INT (newdecl
) = 0;
1129 error ("%Jconflicting types for '%D'", newdecl
, newdecl
);
1130 diagnose_arglist_conflict (newdecl
, olddecl
, newtype
, oldtype
);
1131 locate_old_decl (olddecl
, error
);
1136 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1137 but silently ignore the redeclaration if either is in a system
1138 header. (Conflicting redeclarations were handled above.) */
1139 if (TREE_CODE (newdecl
) == TYPE_DECL
)
1141 if (DECL_IN_SYSTEM_HEADER (newdecl
) || DECL_IN_SYSTEM_HEADER (olddecl
))
1142 return true; /* Allow OLDDECL to continue in use. */
1144 error ("%Jredefinition of typedef '%D'", newdecl
, newdecl
);
1145 locate_old_decl (olddecl
, error
);
1149 /* Function declarations can either be 'static' or 'extern' (no
1150 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1151 can never conflict with each other on account of linkage (6.2.2p4).
1152 Multiple definitions are not allowed (6.9p3,5) but GCC permits
1153 two definitions if one is 'extern inline' and one is not. The non-
1154 extern-inline definition supersedes the extern-inline definition. */
1155 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1157 /* If you declare a built-in function name as static, or
1158 define the built-in with an old-style definition (so we
1159 can't validate the argument list) the built-in definition is
1160 overridden, but optionally warn this was a bad choice of name. */
1161 if (DECL_BUILT_IN (olddecl
)
1162 && !C_DECL_DECLARED_BUILTIN (olddecl
)
1163 && (!TREE_PUBLIC (newdecl
)
1164 || (DECL_INITIAL (newdecl
)
1165 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl
)))))
1168 warning ("%Jdeclaration of '%D' shadows a built-in function",
1170 /* Discard the old built-in function. */
1174 if (DECL_INITIAL (newdecl
))
1176 if (DECL_INITIAL (olddecl
)
1177 && !(DECL_DECLARED_INLINE_P (olddecl
)
1178 && DECL_EXTERNAL (olddecl
)
1179 && !(DECL_DECLARED_INLINE_P (newdecl
)
1180 && DECL_EXTERNAL (newdecl
))))
1182 error ("%Jredefinition of '%D'", newdecl
, newdecl
);
1183 locate_old_decl (olddecl
, error
);
1187 /* If we have a prototype after an old-style function definition,
1188 the argument types must be checked specially. */
1189 else if (DECL_INITIAL (olddecl
)
1190 && !TYPE_ARG_TYPES (oldtype
) && TYPE_ARG_TYPES (newtype
)
1191 && TYPE_ACTUAL_ARG_TYPES (oldtype
)
1192 && !validate_proto_after_old_defn (newdecl
, newtype
, oldtype
))
1194 locate_old_decl (olddecl
, error
);
1197 /* Mismatched non-static and static is considered poor style.
1198 We only diagnose static then non-static if -Wtraditional,
1199 because it is the most convenient way to get some effects
1200 (see e.g. what unwind-dw2-fde-glibc.c does to the definition
1201 of _Unwind_Find_FDE in unwind-dw2-fde.c). Revisit? */
1202 if (TREE_PUBLIC (olddecl
) && !TREE_PUBLIC (newdecl
))
1204 /* A static function declaration for a predeclared function
1205 that isn't actually built in, silently overrides the
1206 default. Objective C uses these. See also above.
1207 FIXME: Make Objective C use normal builtins. */
1208 if (TREE_CODE (olddecl
) == FUNCTION_DECL
1209 && DECL_SOURCE_LINE (olddecl
) == 0)
1213 warning ("%Jstatic declaration of '%D' follows "
1214 "non-static declaration", newdecl
, newdecl
);
1218 else if (TREE_PUBLIC (newdecl
) && !TREE_PUBLIC (olddecl
)
1219 && warn_traditional
)
1221 warning ("%Jnon-static declaration of '%D' follows "
1222 "static declaration", newdecl
, newdecl
);
1226 else if (TREE_CODE (newdecl
) == VAR_DECL
)
1228 /* Only variables can be thread-local, and all declarations must
1229 agree on this property. */
1230 if (DECL_THREAD_LOCAL (newdecl
) != DECL_THREAD_LOCAL (olddecl
))
1232 if (DECL_THREAD_LOCAL (newdecl
))
1233 error ("%Jthread-local declaration of '%D' follows "
1234 "non-thread-local declaration", newdecl
, newdecl
);
1236 error ("%Jnon-thread-local declaration of '%D' follows "
1237 "thread-local declaration", newdecl
, newdecl
);
1239 locate_old_decl (olddecl
, error
);
1243 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1244 if (DECL_INITIAL (newdecl
) && DECL_INITIAL (olddecl
))
1246 error ("%Jredefinition of '%D'", newdecl
, newdecl
);
1247 locate_old_decl (olddecl
, error
);
1251 /* Objects declared at file scope: if at least one is 'extern',
1252 it's fine (6.2.2p4); otherwise the linkage must agree (6.2.2p7). */
1253 if (DECL_FILE_SCOPE_P (newdecl
))
1255 if (!DECL_EXTERNAL (newdecl
)
1256 && !DECL_EXTERNAL (olddecl
)
1257 && TREE_PUBLIC (newdecl
) != TREE_PUBLIC (olddecl
))
1259 if (TREE_PUBLIC (newdecl
))
1260 error ("%Jnon-static declaration of '%D' follows "
1261 "static declaration", newdecl
, newdecl
);
1263 error ("%Jstatic declaration of '%D' follows "
1264 "non-static declaration", newdecl
, newdecl
);
1266 locate_old_decl (olddecl
, error
);
1270 /* Two objects with the same name declared at the same block
1271 scope must both be external references (6.7p3). */
1272 else if (DECL_CONTEXT (newdecl
) == DECL_CONTEXT (olddecl
)
1273 && (!DECL_EXTERNAL (newdecl
) || !DECL_EXTERNAL (olddecl
)))
1275 if (DECL_EXTERNAL (newdecl
))
1276 error ("%Jextern declaration of '%D' follows "
1277 "declaration with no linkage", newdecl
, newdecl
);
1278 else if (DECL_EXTERNAL (olddecl
))
1279 error ("%Jdeclaration of '%D' with no linkage follows "
1280 "extern declaration", newdecl
, newdecl
);
1282 error ("%Jredeclaration of '%D' with no linkage",
1285 locate_old_decl (olddecl
, error
);
1291 /* All decls must agree on a non-default visibility. */
1292 if (DECL_VISIBILITY (newdecl
) != VISIBILITY_DEFAULT
1293 && DECL_VISIBILITY (olddecl
) != VISIBILITY_DEFAULT
1294 && DECL_VISIBILITY (newdecl
) != DECL_VISIBILITY (olddecl
))
1296 warning ("%Jredeclaration of '%D' with different visibility "
1297 "(old visibility preserved)", newdecl
, newdecl
);
1301 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1303 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1304 if (DECL_DECLARED_INLINE_P (newdecl
)
1305 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
1307 warning ("%Jinline declaration of '%D' follows "
1308 "declaration with attribute noinline", newdecl
, newdecl
);
1311 else if (DECL_DECLARED_INLINE_P (olddecl
)
1312 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
)))
1314 warning ("%Jdeclaration of '%D' with attribute noinline follows "
1315 "inline declaration ", newdecl
, newdecl
);
1319 /* Inline declaration after use or definition.
1320 ??? Should we still warn about this now we have unit-at-a-time
1321 mode and can get it right? */
1322 if (DECL_DECLARED_INLINE_P (newdecl
) && !DECL_DECLARED_INLINE_P (olddecl
))
1324 if (TREE_USED (olddecl
))
1326 warning ("%J'%D' declared inline after being called",
1330 else if (DECL_INITIAL (olddecl
))
1332 warning ("%J'%D' declared inline after its definition",
1338 else /* PARM_DECL, VAR_DECL */
1340 /* Redeclaration of a parameter is a constraint violation (this is
1341 not explicitly stated, but follows from C99 6.7p3 [no more than
1342 one declaration of the same identifier with no linkage in the
1343 same scope, except type tags] and 6.2.2p6 [parameters have no
1344 linkage]). We must check for a forward parameter declaration,
1345 indicated by TREE_ASM_WRITTEN on the old declaration - this is
1346 an extension, the mandatory diagnostic for which is handled by
1347 mark_forward_parm_decls. */
1349 if (TREE_CODE (newdecl
) == PARM_DECL
1350 && (!TREE_ASM_WRITTEN (olddecl
) || TREE_ASM_WRITTEN (newdecl
)))
1352 error ("%Jredefinition of parameter '%D'", newdecl
, newdecl
);
1353 locate_old_decl (olddecl
, error
);
1357 /* These bits are only type qualifiers when applied to objects. */
1358 if (TREE_THIS_VOLATILE (newdecl
) != TREE_THIS_VOLATILE (olddecl
))
1360 if (TREE_THIS_VOLATILE (newdecl
))
1361 pedwarn ("%Jvolatile declaration of '%D' follows "
1362 "non-volatile declaration", newdecl
, newdecl
);
1364 pedwarn ("%Jnon-volatile declaration of '%D' follows "
1365 "volatile declaration", newdecl
, newdecl
);
1368 if (TREE_READONLY (newdecl
) != TREE_READONLY (olddecl
))
1370 if (TREE_READONLY (newdecl
))
1371 pedwarn ("%Jconst declaration of '%D' follows "
1372 "non-const declaration", newdecl
, newdecl
);
1374 pedwarn ("%Jnon-const declaration of '%D' follows "
1375 "const declaration", newdecl
, newdecl
);
1380 /* Optional warning for completely redundant decls. */
1381 if (!warned
&& !pedwarned
1382 && warn_redundant_decls
1383 /* Don't warn about a function declaration followed by a
1385 && !(TREE_CODE (newdecl
) == FUNCTION_DECL
1386 && DECL_INITIAL (newdecl
) && !DECL_INITIAL (olddecl
))
1387 /* Don't warn about an extern followed by a definition. */
1388 && !(DECL_EXTERNAL (olddecl
) && !DECL_EXTERNAL (newdecl
))
1389 /* Don't warn about forward parameter decls. */
1390 && !(TREE_CODE (newdecl
) == PARM_DECL
1391 && TREE_ASM_WRITTEN (olddecl
) && !TREE_ASM_WRITTEN (newdecl
)))
1393 warning ("%Jredundant redeclaration of '%D'", newdecl
, newdecl
);
1397 /* Report location of previous decl/defn in a consistent manner. */
1398 if (warned
|| pedwarned
)
1399 locate_old_decl (olddecl
, pedwarned
? pedwarn
: warning
);
1404 /* Subroutine of duplicate_decls. NEWDECL has been found to be
1405 consistent with OLDDECL, but carries new information. Merge the
1406 new information into OLDDECL. This function issues no
1410 merge_decls (tree newdecl
, tree olddecl
, tree newtype
, tree oldtype
)
1412 int new_is_definition
= (TREE_CODE (newdecl
) == FUNCTION_DECL
1413 && DECL_INITIAL (newdecl
) != 0);
1415 /* For real parm decl following a forward decl, rechain the old decl
1416 in its new location and clear TREE_ASM_WRITTEN (it's not a
1417 forward decl anymore). */
1418 if (TREE_CODE (newdecl
) == PARM_DECL
1419 && TREE_ASM_WRITTEN (olddecl
) && ! TREE_ASM_WRITTEN (newdecl
))
1421 struct c_binding
*b
, **here
;
1423 for (here
= ¤t_scope
->bindings
; *here
; here
= &(*here
)->prev
)
1424 if ((*here
)->decl
== olddecl
)
1431 b
->prev
= current_scope
->bindings
;
1432 current_scope
->bindings
= b
;
1434 TREE_ASM_WRITTEN (olddecl
) = 0;
1437 DECL_ATTRIBUTES (newdecl
)
1438 = targetm
.merge_decl_attributes (olddecl
, newdecl
);
1440 /* Merge the data types specified in the two decls. */
1442 = TREE_TYPE (olddecl
)
1443 = common_type (newtype
, oldtype
);
1445 /* Lay the type out, unless already done. */
1446 if (oldtype
!= TREE_TYPE (newdecl
))
1448 if (TREE_TYPE (newdecl
) != error_mark_node
)
1449 layout_type (TREE_TYPE (newdecl
));
1450 if (TREE_CODE (newdecl
) != FUNCTION_DECL
1451 && TREE_CODE (newdecl
) != TYPE_DECL
1452 && TREE_CODE (newdecl
) != CONST_DECL
)
1453 layout_decl (newdecl
, 0);
1457 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1458 DECL_SIZE (newdecl
) = DECL_SIZE (olddecl
);
1459 DECL_SIZE_UNIT (newdecl
) = DECL_SIZE_UNIT (olddecl
);
1460 DECL_MODE (newdecl
) = DECL_MODE (olddecl
);
1461 if (TREE_CODE (olddecl
) != FUNCTION_DECL
)
1462 if (DECL_ALIGN (olddecl
) > DECL_ALIGN (newdecl
))
1464 DECL_ALIGN (newdecl
) = DECL_ALIGN (olddecl
);
1465 DECL_USER_ALIGN (newdecl
) |= DECL_ALIGN (olddecl
);
1469 /* Keep the old rtl since we can safely use it. */
1470 COPY_DECL_RTL (olddecl
, newdecl
);
1472 /* Merge the type qualifiers. */
1473 if (TREE_READONLY (newdecl
))
1474 TREE_READONLY (olddecl
) = 1;
1476 if (TREE_THIS_VOLATILE (newdecl
))
1478 TREE_THIS_VOLATILE (olddecl
) = 1;
1479 if (TREE_CODE (newdecl
) == VAR_DECL
)
1480 make_var_volatile (newdecl
);
1483 /* Keep source location of definition rather than declaration. */
1484 if (DECL_INITIAL (newdecl
) == 0 && DECL_INITIAL (olddecl
) != 0)
1485 DECL_SOURCE_LOCATION (newdecl
) = DECL_SOURCE_LOCATION (olddecl
);
1487 /* Merge the unused-warning information. */
1488 if (DECL_IN_SYSTEM_HEADER (olddecl
))
1489 DECL_IN_SYSTEM_HEADER (newdecl
) = 1;
1490 else if (DECL_IN_SYSTEM_HEADER (newdecl
))
1491 DECL_IN_SYSTEM_HEADER (olddecl
) = 1;
1493 /* Merge the initialization information. */
1494 if (DECL_INITIAL (newdecl
) == 0)
1495 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1497 /* Merge the section attribute.
1498 We want to issue an error if the sections conflict but that must be
1499 done later in decl_attributes since we are called before attributes
1501 if (DECL_SECTION_NAME (newdecl
) == NULL_TREE
)
1502 DECL_SECTION_NAME (newdecl
) = DECL_SECTION_NAME (olddecl
);
1504 /* Copy the assembler name.
1505 Currently, it can only be defined in the prototype. */
1506 COPY_DECL_ASSEMBLER_NAME (olddecl
, newdecl
);
1508 /* If either declaration has a nondefault visibility, use it. */
1509 if (DECL_VISIBILITY (olddecl
) != VISIBILITY_DEFAULT
)
1510 DECL_VISIBILITY (newdecl
) = DECL_VISIBILITY (olddecl
);
1512 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1514 DECL_STATIC_CONSTRUCTOR(newdecl
) |= DECL_STATIC_CONSTRUCTOR(olddecl
);
1515 DECL_STATIC_DESTRUCTOR (newdecl
) |= DECL_STATIC_DESTRUCTOR (olddecl
);
1516 DECL_NO_LIMIT_STACK (newdecl
) |= DECL_NO_LIMIT_STACK (olddecl
);
1517 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl
)
1518 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl
);
1519 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1520 TREE_READONLY (newdecl
) |= TREE_READONLY (olddecl
);
1521 DECL_IS_MALLOC (newdecl
) |= DECL_IS_MALLOC (olddecl
);
1522 DECL_IS_PURE (newdecl
) |= DECL_IS_PURE (olddecl
);
1525 /* Merge the storage class information. */
1526 merge_weak (newdecl
, olddecl
);
1528 /* For functions, static overrides non-static. */
1529 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1531 TREE_PUBLIC (newdecl
) &= TREE_PUBLIC (olddecl
);
1532 /* This is since we don't automatically
1533 copy the attributes of NEWDECL into OLDDECL. */
1534 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1535 /* If this clears `static', clear it in the identifier too. */
1536 if (! TREE_PUBLIC (olddecl
))
1537 TREE_PUBLIC (DECL_NAME (olddecl
)) = 0;
1539 if (DECL_EXTERNAL (newdecl
))
1541 TREE_STATIC (newdecl
) = TREE_STATIC (olddecl
);
1542 DECL_EXTERNAL (newdecl
) = DECL_EXTERNAL (olddecl
);
1544 /* An extern decl does not override previous storage class. */
1545 TREE_PUBLIC (newdecl
) = TREE_PUBLIC (olddecl
);
1546 if (! DECL_EXTERNAL (newdecl
))
1548 DECL_CONTEXT (newdecl
) = DECL_CONTEXT (olddecl
);
1549 DECL_COMMON (newdecl
) = DECL_COMMON (olddecl
);
1554 TREE_STATIC (olddecl
) = TREE_STATIC (newdecl
);
1555 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1558 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1560 /* If we're redefining a function previously defined as extern
1561 inline, make sure we emit debug info for the inline before we
1562 throw it away, in case it was inlined into a function that hasn't
1563 been written out yet. */
1564 if (new_is_definition
&& DECL_INITIAL (olddecl
))
1566 if (TREE_USED (olddecl
)
1567 /* In unit-at-a-time mode we never inline re-defined extern
1568 inline functions. */
1569 && !flag_unit_at_a_time
1570 && cgraph_function_possibly_inlined_p (olddecl
))
1571 (*debug_hooks
->outlining_inline_function
) (olddecl
);
1573 /* The new defn must not be inline. */
1574 DECL_INLINE (newdecl
) = 0;
1575 DECL_UNINLINABLE (newdecl
) = 1;
1579 /* If either decl says `inline', this fn is inline,
1580 unless its definition was passed already. */
1581 if (DECL_DECLARED_INLINE_P (newdecl
)
1582 || DECL_DECLARED_INLINE_P (olddecl
))
1583 DECL_DECLARED_INLINE_P (newdecl
) = 1;
1585 DECL_UNINLINABLE (newdecl
) = DECL_UNINLINABLE (olddecl
)
1586 = (DECL_UNINLINABLE (newdecl
) || DECL_UNINLINABLE (olddecl
));
1589 if (DECL_BUILT_IN (olddecl
))
1591 /* If redeclaring a builtin function, it stays built in.
1592 But it gets tagged as having been declared. */
1593 DECL_BUILT_IN_CLASS (newdecl
) = DECL_BUILT_IN_CLASS (olddecl
);
1594 DECL_FUNCTION_CODE (newdecl
) = DECL_FUNCTION_CODE (olddecl
);
1595 C_DECL_DECLARED_BUILTIN (newdecl
) = 1;
1598 /* Also preserve various other info from the definition. */
1599 if (! new_is_definition
)
1601 DECL_RESULT (newdecl
) = DECL_RESULT (olddecl
);
1602 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1603 DECL_STRUCT_FUNCTION (newdecl
) = DECL_STRUCT_FUNCTION (olddecl
);
1604 DECL_SAVED_TREE (newdecl
) = DECL_SAVED_TREE (olddecl
);
1605 DECL_ARGUMENTS (newdecl
) = DECL_ARGUMENTS (olddecl
);
1607 /* Set DECL_INLINE on the declaration if we've got a body
1608 from which to instantiate. */
1609 if (DECL_INLINE (olddecl
) && ! DECL_UNINLINABLE (newdecl
))
1611 DECL_INLINE (newdecl
) = 1;
1612 DECL_ABSTRACT_ORIGIN (newdecl
)
1613 = DECL_ABSTRACT_ORIGIN (olddecl
);
1618 /* If a previous declaration said inline, mark the
1619 definition as inlinable. */
1620 if (DECL_DECLARED_INLINE_P (newdecl
)
1621 && ! DECL_UNINLINABLE (newdecl
))
1622 DECL_INLINE (newdecl
) = 1;
1626 /* This bit must not get wiped out. */
1627 C_DECL_IN_EXTERNAL_SCOPE (newdecl
) |= C_DECL_IN_EXTERNAL_SCOPE (olddecl
);
1629 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1630 But preserve OLDDECL's DECL_UID. */
1632 unsigned olddecl_uid
= DECL_UID (olddecl
);
1634 memcpy ((char *) olddecl
+ sizeof (struct tree_common
),
1635 (char *) newdecl
+ sizeof (struct tree_common
),
1636 sizeof (struct tree_decl
) - sizeof (struct tree_common
));
1637 DECL_UID (olddecl
) = olddecl_uid
;
1640 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1641 so that encode_section_info has a chance to look at the new decl
1642 flags and attributes. */
1643 if (DECL_RTL_SET_P (olddecl
)
1644 && (TREE_CODE (olddecl
) == FUNCTION_DECL
1645 || (TREE_CODE (olddecl
) == VAR_DECL
1646 && TREE_STATIC (olddecl
))))
1647 make_decl_rtl (olddecl
, NULL
);
1650 /* Handle when a new declaration NEWDECL has the same name as an old
1651 one OLDDECL in the same binding contour. Prints an error message
1654 If safely possible, alter OLDDECL to look like NEWDECL, and return
1655 true. Otherwise, return false. */
1658 duplicate_decls (tree newdecl
, tree olddecl
)
1660 tree newtype
, oldtype
;
1662 if (!diagnose_mismatched_decls (newdecl
, olddecl
, &newtype
, &oldtype
))
1665 merge_decls (newdecl
, olddecl
, newtype
, oldtype
);
1670 /* Check whether decl-node NEW shadows an existing declaration. */
1672 warn_if_shadowing (tree
new)
1674 struct c_binding
*b
;
1676 /* Shadow warnings wanted? */
1678 /* No shadow warnings for internally generated vars. */
1679 || DECL_SOURCE_LINE (new) == 0
1680 /* No shadow warnings for vars made for inlining. */
1681 || DECL_FROM_INLINE (new)
1682 /* Don't warn about the parm names in function declarator
1683 within a function declarator. It would be nice to avoid
1684 warning in any function declarator in a declaration, as
1685 opposed to a definition, but there is no way to tell
1686 it's not a definition at this point. */
1687 || (TREE_CODE (new) == PARM_DECL
&& current_scope
->outer
->parm_flag
))
1690 /* Is anything being shadowed? Do not be confused by a second binding
1691 to the same decl in the externals scope. */
1692 for (b
= I_SYMBOL_BINDING (DECL_NAME (new)); b
; b
= b
->shadowed
)
1693 if (b
->decl
&& b
->decl
!= new && b
->contour
!= external_scope
)
1697 if (TREE_CODE (old
) == PARM_DECL
)
1698 warning ("%Jdeclaration of '%D' shadows a parameter", new, new);
1699 else if (DECL_FILE_SCOPE_P (old
))
1700 warning ("%Jdeclaration of '%D' shadows a global declaration",
1702 else if (TREE_CODE (old
) == FUNCTION_DECL
&& DECL_BUILT_IN (old
))
1703 warning ("%Jdeclaration of '%D' shadows a built-in function",
1706 warning ("%Jdeclaration of '%D' shadows a previous local", new, new);
1708 if (TREE_CODE (old
) != FUNCTION_DECL
|| !DECL_BUILT_IN (old
))
1709 warning ("%Jshadowed declaration is here", old
);
1716 /* Subroutine of pushdecl.
1718 X is a TYPE_DECL for a typedef statement. Create a brand new
1719 ..._TYPE node (which will be just a variant of the existing
1720 ..._TYPE node with identical properties) and then install X
1721 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
1723 The whole point here is to end up with a situation where each
1724 and every ..._TYPE node the compiler creates will be uniquely
1725 associated with AT MOST one node representing a typedef name.
1726 This way, even though the compiler substitutes corresponding
1727 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
1728 early on, later parts of the compiler can always do the reverse
1729 translation and get back the corresponding typedef name. For
1732 typedef struct S MY_TYPE;
1735 Later parts of the compiler might only know that `object' was of
1736 type `struct S' if it were not for code just below. With this
1737 code however, later parts of the compiler see something like:
1739 struct S' == struct S
1740 typedef struct S' MY_TYPE;
1743 And they can then deduce (from the node for type struct S') that
1744 the original object declaration was:
1748 Being able to do this is important for proper support of protoize,
1749 and also for generating precise symbolic debugging information
1750 which takes full account of the programmer's (typedef) vocabulary.
1752 Obviously, we don't want to generate a duplicate ..._TYPE node if
1753 the TYPE_DECL node that we are now processing really represents a
1754 standard built-in type.
1756 Since all standard types are effectively declared at line zero
1757 in the source file, we can easily check to see if we are working
1758 on a standard type by checking the current value of lineno. */
1761 clone_underlying_type (tree x
)
1763 if (DECL_SOURCE_LINE (x
) == 0)
1765 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
1766 TYPE_NAME (TREE_TYPE (x
)) = x
;
1768 else if (TREE_TYPE (x
) != error_mark_node
1769 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
1771 tree tt
= TREE_TYPE (x
);
1772 DECL_ORIGINAL_TYPE (x
) = tt
;
1773 tt
= build_type_copy (tt
);
1775 TREE_USED (tt
) = TREE_USED (x
);
1780 /* Record a decl-node X as belonging to the current lexical scope.
1781 Check for errors (such as an incompatible declaration for the same
1782 name already seen in the same scope).
1784 Returns either X or an old decl for the same name.
1785 If an old decl is returned, it may have been smashed
1786 to agree with what X says. */
1791 tree name
= DECL_NAME (x
);
1792 struct c_scope
*scope
= current_scope
;
1793 struct c_binding
*b
;
1795 /* Functions need the lang_decl data. */
1796 if (TREE_CODE (x
) == FUNCTION_DECL
&& ! DECL_LANG_SPECIFIC (x
))
1797 DECL_LANG_SPECIFIC (x
) = ggc_alloc_cleared (sizeof (struct lang_decl
));
1799 /* A local extern declaration for a function doesn't constitute nesting.
1800 A local auto declaration does, since it's a forward decl
1801 for a nested function coming later. */
1802 if (current_function_decl
== NULL
1803 || ((TREE_CODE (x
) == FUNCTION_DECL
|| TREE_CODE (x
) == VAR_DECL
)
1804 && DECL_INITIAL (x
) == 0 && DECL_EXTERNAL (x
)))
1805 DECL_CONTEXT (x
) = current_file_decl
;
1807 DECL_CONTEXT (x
) = current_function_decl
;
1809 /* Anonymous decls are just inserted in the scope. */
1812 bind (name
, x
, scope
);
1816 /* First, see if there is another declaration with the same name in
1817 the current scope. If there is, duplicate_decls may do all the
1818 work for us. If duplicate_decls returns false, that indicates
1819 two incompatible decls in the same scope; we are to silently
1820 replace the old one (duplicate_decls has issued all appropriate
1821 diagnostics). In particular, we should not consider possible
1822 duplicates in the external scope, or shadowing. */
1823 b
= I_SYMBOL_BINDING (name
);
1824 if (b
&& b
->contour
== scope
)
1826 if (duplicate_decls (x
, b
->decl
))
1829 goto skip_external_and_shadow_checks
;
1832 /* All declarations with external linkage, and all external
1833 references, go in the external scope, no matter what scope is
1834 current. However, the binding in that scope is ignored for
1835 purposes of normal name lookup. A separate binding structure is
1836 created in the requested scope; this governs the normal
1837 visibility of the symbol.
1839 The binding in the externals scope is used exclusively for
1840 detecting duplicate declarations of the same object, no matter
1841 what scope they are in; this is what we do here. (C99 6.2.7p2:
1842 All declarations that refer to the same object or function shall
1843 have compatible type; otherwise, the behavior is undefined.) */
1844 if (DECL_EXTERNAL (x
) || scope
== file_scope
)
1846 if (warn_nested_externs
1847 && scope
!= file_scope
1848 && !DECL_IN_SYSTEM_HEADER (x
))
1849 warning ("nested extern declaration of `%s'",
1850 IDENTIFIER_POINTER (name
));
1852 while (b
&& b
->contour
!= external_scope
)
1855 /* The point of the same_translation_unit_p check here is,
1856 we want to detect a duplicate decl for a construct like
1857 foo() { extern bar(); } ... static bar(); but not if
1858 they are in different translation units. In any case,
1859 the static does not go in the externals scope. */
1861 && (DECL_EXTERNAL (x
) || TREE_PUBLIC (x
)
1862 || same_translation_unit_p (x
, b
->decl
))
1863 && duplicate_decls (x
, b
->decl
))
1865 bind (name
, b
->decl
, scope
);
1868 else if (DECL_EXTERNAL (x
) || TREE_PUBLIC (x
))
1870 C_DECL_IN_EXTERNAL_SCOPE (x
) = 1;
1871 bind (name
, x
, external_scope
);
1875 warn_if_shadowing (x
);
1877 skip_external_and_shadow_checks
:
1878 if (TREE_CODE (x
) == TYPE_DECL
)
1879 clone_underlying_type (x
);
1881 bind (name
, x
, scope
);
1883 /* If x's type is incomplete because it's based on a
1884 structure or union which has not yet been fully declared,
1885 attach it to that structure or union type, so we can go
1886 back and complete the variable declaration later, if the
1887 structure or union gets fully declared.
1889 If the input is erroneous, we can have error_mark in the type
1890 slot (e.g. "f(void a, ...)") - that doesn't count as an
1892 if (TREE_TYPE (x
) != error_mark_node
1893 && !COMPLETE_TYPE_P (TREE_TYPE (x
)))
1895 tree element
= TREE_TYPE (x
);
1897 while (TREE_CODE (element
) == ARRAY_TYPE
)
1898 element
= TREE_TYPE (element
);
1899 element
= TYPE_MAIN_VARIANT (element
);
1901 if ((TREE_CODE (element
) == RECORD_TYPE
1902 || TREE_CODE (element
) == UNION_TYPE
)
1903 && (TREE_CODE (x
) != TYPE_DECL
1904 || TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
)
1905 && !COMPLETE_TYPE_P (element
))
1906 C_TYPE_INCOMPLETE_VARS (element
)
1907 = tree_cons (NULL_TREE
, x
, C_TYPE_INCOMPLETE_VARS (element
));
1912 /* Record X as belonging to file scope.
1913 This is used only internally by the Objective-C front end,
1914 and is limited to its needs. duplicate_decls is not called;
1915 if there is any preexisting decl for this identifier, it is an ICE. */
1918 pushdecl_top_level (tree x
)
1922 if (TREE_CODE (x
) != VAR_DECL
)
1925 name
= DECL_NAME (x
);
1927 if (I_SYMBOL_BINDING (name
))
1930 DECL_CONTEXT (x
) = current_file_decl
;
1931 if (DECL_EXTERNAL (x
) || TREE_PUBLIC (x
))
1933 C_DECL_IN_EXTERNAL_SCOPE (x
) = 1;
1934 bind (name
, x
, external_scope
);
1937 bind (name
, x
, file_scope
);
1943 implicit_decl_warning (tree id
, tree olddecl
)
1945 void (*diag
) (const char *, ...);
1946 switch (mesg_implicit_function_declaration
)
1949 case 1: diag
= warning
; break;
1950 case 2: diag
= error
; break;
1954 diag (N_("implicit declaration of function '%E'"), id
);
1956 locate_old_decl (olddecl
, diag
);
1959 /* Generate an implicit declaration for identifier FUNCTIONID as a
1960 function of type int (). */
1963 implicitly_declare (tree functionid
)
1965 tree decl
= lookup_name_in_scope (functionid
, external_scope
);
1969 /* FIXME: Objective-C has weird not-really-builtin functions
1970 which are supposed to be visible automatically. They wind up
1971 in the external scope because they're pushed before the file
1972 scope gets created. Catch this here and rebind them into the
1974 if (!DECL_BUILT_IN (decl
) && DECL_SOURCE_LINE (decl
) == 0)
1976 bind (functionid
, decl
, file_scope
);
1981 /* Implicit declaration of a function already declared
1982 (somehow) in a different scope, or as a built-in.
1983 If this is the first time this has happened, warn;
1984 then recycle the old declaration. */
1985 if (!C_DECL_IMPLICIT (decl
))
1987 implicit_decl_warning (functionid
, decl
);
1988 C_DECL_IMPLICIT (decl
) = 1;
1990 bind (functionid
, decl
, current_scope
);
1995 /* Not seen before. */
1996 decl
= build_decl (FUNCTION_DECL
, functionid
, default_function_type
);
1997 DECL_EXTERNAL (decl
) = 1;
1998 TREE_PUBLIC (decl
) = 1;
1999 C_DECL_IMPLICIT (decl
) = 1;
2000 implicit_decl_warning (functionid
, 0);
2002 /* C89 says implicit declarations are in the innermost block.
2003 So we record the decl in the standard fashion. */
2004 decl
= pushdecl (decl
);
2006 /* No need to call objc_check_decl here - it's a function type. */
2007 rest_of_decl_compilation (decl
, NULL
, 0, 0);
2009 /* Write a record describing this implicit function declaration
2010 to the prototypes file (if requested). */
2011 gen_aux_info_record (decl
, 0, 1, 0);
2013 /* Possibly apply some default attributes to this implicit declaration. */
2014 decl_attributes (&decl
, NULL_TREE
, 0);
2019 /* Issue an error message for a reference to an undeclared variable
2020 ID, including a reference to a builtin outside of function-call
2021 context. Establish a binding of the identifier to error_mark_node
2022 in an appropriate scope, which will suppress further errors for the
2025 undeclared_variable (tree id
)
2027 static bool already
= false;
2028 struct c_scope
*scope
;
2030 if (current_function_decl
== 0)
2032 error ("'%E' undeclared here (not in a function)", id
);
2033 scope
= current_scope
;
2037 error ("'%E' undeclared (first use in this function)", id
);
2041 error ("(Each undeclared identifier is reported only once");
2042 error ("for each function it appears in.)");
2046 /* If we are parsing old-style parameter decls, current_function_decl
2047 will be nonnull but current_function_scope will be null. */
2048 scope
= current_function_scope
? current_function_scope
: current_scope
;
2050 bind (id
, error_mark_node
, scope
);
2053 /* Subroutine of lookup_label, declare_label, define_label: construct a
2054 LABEL_DECL with all the proper frills. */
2057 make_label (tree name
, location_t location
)
2059 tree label
= build_decl (LABEL_DECL
, name
, void_type_node
);
2061 DECL_CONTEXT (label
) = current_function_decl
;
2062 DECL_MODE (label
) = VOIDmode
;
2063 DECL_SOURCE_LOCATION (label
) = location
;
2068 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
2069 Create one if none exists so far for the current function.
2070 This is called when a label is used in a goto expression or
2071 has its address taken. */
2074 lookup_label (tree name
)
2078 if (current_function_decl
== 0)
2080 error ("label %s referenced outside of any function",
2081 IDENTIFIER_POINTER (name
));
2085 /* Use a label already defined or ref'd with this name, but not if
2086 it is inherited from a containing function and wasn't declared
2088 label
= I_LABEL_DECL (name
);
2089 if (label
&& (DECL_CONTEXT (label
) == current_function_decl
2090 || C_DECLARED_LABEL_FLAG (label
)))
2092 /* If the label has only been declared, update its apparent
2093 location to point here, for better diagnostics if it
2094 turns out not to have been defined. */
2095 if (!TREE_USED (label
))
2096 DECL_SOURCE_LOCATION (label
) = input_location
;
2100 /* No label binding for that identifier; make one. */
2101 label
= make_label (name
, input_location
);
2103 /* Ordinary labels go in the current function scope. */
2104 bind (name
, label
, current_function_scope
);
2108 /* Make a label named NAME in the current function, shadowing silently
2109 any that may be inherited from containing functions or containing
2110 scopes. This is called for __label__ declarations. */
2112 /* Note that valid use, if the label being shadowed comes from another
2113 scope in the same function, requires calling declare_nonlocal_label
2114 right away. (Is this still true? -zw 2003-07-17) */
2117 declare_label (tree name
)
2119 struct c_binding
*b
= I_LABEL_BINDING (name
);
2122 /* Check to make sure that the label hasn't already been declared
2124 if (b
&& b
->contour
== current_scope
)
2126 error ("duplicate label declaration `%s'", IDENTIFIER_POINTER (name
));
2127 locate_old_decl (b
->decl
, error
);
2129 /* Just use the previous declaration. */
2133 label
= make_label (name
, input_location
);
2134 C_DECLARED_LABEL_FLAG (label
) = 1;
2136 /* Declared labels go in the current scope. */
2137 bind (name
, label
, current_scope
);
2141 /* Define a label, specifying the location in the source file.
2142 Return the LABEL_DECL node for the label, if the definition is valid.
2143 Otherwise return 0. */
2146 define_label (location_t location
, tree name
)
2148 /* Find any preexisting label with this name. It is an error
2149 if that label has already been defined in this function, or
2150 if there is a containing function with a declared label with
2152 tree label
= I_LABEL_DECL (name
);
2155 && ((DECL_CONTEXT (label
) == current_function_decl
2156 && DECL_INITIAL (label
) != 0)
2157 || (DECL_CONTEXT (label
) != current_function_decl
2158 && C_DECLARED_LABEL_FLAG (label
))))
2160 error ("%Hduplicate label `%D'", &location
, label
);
2161 locate_old_decl (label
, error
);
2164 else if (label
&& DECL_CONTEXT (label
) == current_function_decl
)
2166 /* The label has been used or declared already in this function,
2167 but not defined. Update its location to point to this
2169 DECL_SOURCE_LOCATION (label
) = location
;
2173 /* No label binding for that identifier; make one. */
2174 label
= make_label (name
, location
);
2176 /* Ordinary labels go in the current function scope. */
2177 bind (name
, label
, current_function_scope
);
2180 if (warn_traditional
&& !in_system_header
&& lookup_name (name
))
2181 warning ("%Htraditional C lacks a separate namespace for labels, "
2182 "identifier `%s' conflicts", &location
,
2183 IDENTIFIER_POINTER (name
));
2185 /* Mark label as having been defined. */
2186 DECL_INITIAL (label
) = error_mark_node
;
2190 /* Given NAME, an IDENTIFIER_NODE,
2191 return the structure (or union or enum) definition for that name.
2192 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2193 CODE says which kind of type the caller wants;
2194 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2195 If the wrong kind of type is found, an error is reported. */
2198 lookup_tag (enum tree_code code
, tree name
, int thislevel_only
)
2200 struct c_binding
*b
= I_TAG_BINDING (name
);
2206 /* We only care about whether it's in this level if
2207 thislevel_only was set or it might be a type clash. */
2208 if (thislevel_only
|| TREE_CODE (b
->decl
) != code
)
2210 /* For our purposes, a tag in the external scope is the same as
2211 a tag in the file scope. (Primarily relevant to Objective-C
2212 and its builtin structure tags, which get pushed before the
2213 file scope is created.) */
2214 if (b
->contour
== current_scope
2215 || (current_scope
== file_scope
&& b
->contour
== external_scope
))
2219 if (thislevel_only
&& !thislevel
)
2222 if (TREE_CODE (b
->decl
) != code
)
2224 /* Definition isn't the kind we were looking for. */
2225 pending_invalid_xref
= name
;
2226 pending_invalid_xref_location
= input_location
;
2228 /* If in the same binding level as a declaration as a tag
2229 of a different type, this must not be allowed to
2230 shadow that tag, so give the error immediately.
2231 (For example, "struct foo; union foo;" is invalid.) */
2233 pending_xref_error ();
2238 /* Print an error message now
2239 for a recent invalid struct, union or enum cross reference.
2240 We don't print them immediately because they are not invalid
2241 when used in the `struct foo;' construct for shadowing. */
2244 pending_xref_error (void)
2246 if (pending_invalid_xref
!= 0)
2247 error ("%H`%s' defined as wrong kind of tag",
2248 &pending_invalid_xref_location
,
2249 IDENTIFIER_POINTER (pending_invalid_xref
));
2250 pending_invalid_xref
= 0;
2254 /* Look up NAME in the current scope and its superiors
2255 in the namespace of variables, functions and typedefs.
2256 Return a ..._DECL node of some kind representing its definition,
2257 or return 0 if it is undefined. */
2260 lookup_name (tree name
)
2262 struct c_binding
*b
= I_SYMBOL_BINDING (name
);
2263 if (b
&& (b
->contour
!= external_scope
|| TREE_CODE (b
->decl
) == TYPE_DECL
))
2268 /* Similar to `lookup_name' but look only at the indicated scope. */
2271 lookup_name_in_scope (tree name
, struct c_scope
*scope
)
2273 struct c_binding
*b
;
2275 for (b
= I_SYMBOL_BINDING (name
); b
; b
= b
->shadowed
)
2276 if (b
->contour
== scope
)
2281 /* Create the predefined scalar types of C,
2282 and some nodes representing standard constants (0, 1, (void *) 0).
2283 Initialize the global scope.
2284 Make definitions for built-in primitive functions. */
2287 c_init_decl_processing (void)
2290 tree ptr_ftype_void
, ptr_ftype_ptr
;
2291 location_t save_loc
= input_location
;
2293 /* Adds some ggc roots, and reserved words for c-parse.in. */
2296 current_function_decl
= 0;
2298 /* Make the externals scope. */
2300 external_scope
= current_scope
;
2302 /* Declarations from c_common_nodes_and_builtins must not be associated
2303 with this input file, lest we get differences between using and not
2304 using preprocessed headers. */
2305 input_location
.file
= "<internal>";
2306 input_location
.line
= 0;
2308 build_common_tree_nodes (flag_signed_char
);
2310 c_common_nodes_and_builtins ();
2312 /* In C, comparisons and TRUTH_* expressions have type int. */
2313 truthvalue_type_node
= integer_type_node
;
2314 truthvalue_true_node
= integer_one_node
;
2315 truthvalue_false_node
= integer_zero_node
;
2317 /* Even in C99, which has a real boolean type. */
2318 pushdecl (build_decl (TYPE_DECL
, get_identifier ("_Bool"),
2319 boolean_type_node
));
2321 endlink
= void_list_node
;
2322 ptr_ftype_void
= build_function_type (ptr_type_node
, endlink
);
2324 = build_function_type (ptr_type_node
,
2325 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
2327 input_location
= save_loc
;
2329 pedantic_lvalues
= true;
2331 make_fname_decl
= c_make_fname_decl
;
2332 start_fname_decls ();
2335 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2336 decl, NAME is the initialization string and TYPE_DEP indicates whether
2337 NAME depended on the type of the function. As we don't yet implement
2338 delayed emission of static data, we mark the decl as emitted
2339 so it is not placed in the output. Anything using it must therefore pull
2340 out the STRING_CST initializer directly. FIXME. */
2343 c_make_fname_decl (tree id
, int type_dep
)
2345 const char *name
= fname_as_string (type_dep
);
2346 tree decl
, type
, init
;
2347 size_t length
= strlen (name
);
2349 type
= build_array_type
2350 (build_qualified_type (char_type_node
, TYPE_QUAL_CONST
),
2351 build_index_type (size_int (length
)));
2353 decl
= build_decl (VAR_DECL
, id
, type
);
2355 TREE_STATIC (decl
) = 1;
2356 TREE_READONLY (decl
) = 1;
2357 DECL_ARTIFICIAL (decl
) = 1;
2359 init
= build_string (length
+ 1, name
);
2360 TREE_TYPE (init
) = type
;
2361 DECL_INITIAL (decl
) = init
;
2363 TREE_USED (decl
) = 1;
2365 if (current_function_decl
)
2367 DECL_CONTEXT (decl
) = current_function_decl
;
2368 bind (id
, decl
, current_function_scope
);
2371 finish_decl (decl
, init
, NULL_TREE
);
2376 /* Return a definition for a builtin function named NAME and whose data type
2377 is TYPE. TYPE should be a function type with argument types.
2378 FUNCTION_CODE tells later passes how to compile calls to this function.
2379 See tree.h for its possible values.
2381 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
2382 the name to be called if we can't opencode the function. If
2383 ATTRS is nonzero, use that for the function's attribute list. */
2386 builtin_function (const char *name
, tree type
, int function_code
,
2387 enum built_in_class
class, const char *library_name
,
2390 tree id
= get_identifier (name
);
2391 tree decl
= build_decl (FUNCTION_DECL
, id
, type
);
2392 TREE_PUBLIC (decl
) = 1;
2393 DECL_EXTERNAL (decl
) = 1;
2394 DECL_LANG_SPECIFIC (decl
) = ggc_alloc_cleared (sizeof (struct lang_decl
));
2395 DECL_BUILT_IN_CLASS (decl
) = class;
2396 DECL_FUNCTION_CODE (decl
) = function_code
;
2398 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (library_name
));
2399 make_decl_rtl (decl
, NULL
);
2401 /* Should never be called on a symbol with a preexisting meaning. */
2402 if (I_SYMBOL_BINDING (id
))
2405 C_DECL_IN_EXTERNAL_SCOPE (decl
) = 1;
2406 bind (id
, decl
, external_scope
);
2408 /* Builtins in the implementation namespace are made visible without
2409 needing to be explicitly declared. See push_file_scope. */
2410 if (name
[0] == '_' && (name
[1] == '_' || ISUPPER (name
[1])))
2412 TREE_CHAIN (decl
) = visible_builtins
;
2413 visible_builtins
= decl
;
2416 /* Possibly apply some default attributes to this built-in function. */
2418 decl_attributes (&decl
, attrs
, ATTR_FLAG_BUILT_IN
);
2420 decl_attributes (&decl
, NULL_TREE
, 0);
2425 /* Called when a declaration is seen that contains no names to declare.
2426 If its type is a reference to a structure, union or enum inherited
2427 from a containing scope, shadow that tag name for the current scope
2428 with a forward reference.
2429 If its type defines a new named structure or union
2430 or defines an enum, it is valid but we need not do anything here.
2431 Otherwise, it is an error. */
2434 shadow_tag (tree declspecs
)
2436 shadow_tag_warned (declspecs
, 0);
2440 shadow_tag_warned (tree declspecs
, int warned
)
2443 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
2450 pending_invalid_xref
= 0;
2452 /* Remove the attributes from declspecs, since they will confuse the
2454 split_specs_attrs (declspecs
, &specs
, &attrs
);
2456 for (link
= specs
; link
; link
= TREE_CHAIN (link
))
2458 tree value
= TREE_VALUE (link
);
2459 enum tree_code code
= TREE_CODE (value
);
2461 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ENUMERAL_TYPE
)
2462 /* Used to test also that TYPE_SIZE (value) != 0.
2463 That caused warning for `struct foo;' at top level in the file. */
2465 tree name
= TYPE_NAME (value
);
2472 if (warned
!= 1 && code
!= ENUMERAL_TYPE
)
2473 /* Empty unnamed enum OK */
2475 pedwarn ("unnamed struct/union that defines no instances");
2481 t
= lookup_tag (code
, name
, 1);
2485 t
= make_node (code
);
2492 if (!warned
&& ! in_system_header
)
2494 warning ("useless keyword or type name in empty declaration");
2501 error ("two types specified in one empty declaration");
2506 pedwarn ("empty declaration");
2510 /* Construct an array declarator. EXPR is the expression inside [], or
2511 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
2512 to the pointer to which a parameter array is converted). STATIC_P is
2513 nonzero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P
2514 is nonzero is the array is [*], a VLA of unspecified length which is
2515 nevertheless a complete type (not currently implemented by GCC),
2516 zero otherwise. The declarator is constructed as an ARRAY_REF
2517 (to be decoded by grokdeclarator), whose operand 0 is what's on the
2518 left of the [] (filled by in set_array_declarator_type) and operand 1
2519 is the expression inside; whose TREE_TYPE is the type qualifiers and
2520 which has TREE_STATIC set if "static" is used. */
2523 build_array_declarator (tree expr
, tree quals
, int static_p
, int vla_unspec_p
)
2526 decl
= build_nt (ARRAY_REF
, NULL_TREE
, expr
);
2527 TREE_TYPE (decl
) = quals
;
2528 TREE_STATIC (decl
) = (static_p
? 1 : 0);
2529 if (pedantic
&& !flag_isoc99
)
2531 if (static_p
|| quals
!= NULL_TREE
)
2532 pedwarn ("ISO C90 does not support `static' or type qualifiers in parameter array declarators");
2534 pedwarn ("ISO C90 does not support `[*]' array declarators");
2537 warning ("GCC does not yet properly implement `[*]' array declarators");
2541 /* Set the type of an array declarator. DECL is the declarator, as
2542 constructed by build_array_declarator; TYPE is what appears on the left
2543 of the [] and goes in operand 0. ABSTRACT_P is nonzero if it is an
2544 abstract declarator, zero otherwise; this is used to reject static and
2545 type qualifiers in abstract declarators, where they are not in the
2549 set_array_declarator_type (tree decl
, tree type
, int abstract_p
)
2551 TREE_OPERAND (decl
, 0) = type
;
2552 if (abstract_p
&& (TREE_TYPE (decl
) != NULL_TREE
|| TREE_STATIC (decl
)))
2553 error ("static or type qualifiers in abstract declarator");
2557 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
2560 groktypename (tree typename
)
2564 if (TREE_CODE (typename
) != TREE_LIST
)
2567 split_specs_attrs (TREE_PURPOSE (typename
), &specs
, &attrs
);
2569 typename
= grokdeclarator (TREE_VALUE (typename
), specs
, TYPENAME
, 0,
2572 /* Apply attributes. */
2573 decl_attributes (&typename
, attrs
, 0);
2578 /* Return a PARM_DECL node for a given pair of specs and declarator. */
2581 groktypename_in_parm_context (tree typename
)
2583 if (TREE_CODE (typename
) != TREE_LIST
)
2585 return grokdeclarator (TREE_VALUE (typename
),
2586 TREE_PURPOSE (typename
),
2590 /* Decode a declarator in an ordinary declaration or data definition.
2591 This is called as soon as the type information and variable name
2592 have been parsed, before parsing the initializer if any.
2593 Here we create the ..._DECL node, fill in its type,
2594 and put it on the list of decls for the current context.
2595 The ..._DECL node is returned as the value.
2597 Exception: for arrays where the length is not specified,
2598 the type is left null, to be filled in by `finish_decl'.
2600 Function definitions do not come here; they go to start_function
2601 instead. However, external and forward declarations of functions
2602 do go through here. Structure field declarations are done by
2603 grokfield and not through here. */
2606 start_decl (tree declarator
, tree declspecs
, int initialized
, tree attributes
)
2611 /* An object declared as __attribute__((deprecated)) suppresses
2612 warnings of uses of other deprecated items. */
2613 if (lookup_attribute ("deprecated", attributes
))
2614 deprecated_state
= DEPRECATED_SUPPRESS
;
2616 decl
= grokdeclarator (declarator
, declspecs
,
2617 NORMAL
, initialized
, NULL
);
2619 deprecated_state
= DEPRECATED_NORMAL
;
2621 if (warn_main
> 0 && TREE_CODE (decl
) != FUNCTION_DECL
2622 && MAIN_NAME_P (DECL_NAME (decl
)))
2623 warning ("%J'%D' is usually a function", decl
, decl
);
2626 /* Is it valid for this decl to have an initializer at all?
2627 If not, set INITIALIZED to zero, which will indirectly
2628 tell 'finish_decl' to ignore the initializer once it is parsed. */
2629 switch (TREE_CODE (decl
))
2632 error ("typedef '%D' is initialized (use __typeof__ instead)", decl
);
2637 error ("function '%D' is initialized like a variable", decl
);
2642 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
2643 error ("parameter '%D' is initialized", decl
);
2648 /* Don't allow initializations for incomplete types except for
2649 arrays which might be completed by the initialization. */
2651 /* This can happen if the array size is an undefined macro.
2652 We already gave a warning, so we don't need another one. */
2653 if (TREE_TYPE (decl
) == error_mark_node
)
2655 else if (COMPLETE_TYPE_P (TREE_TYPE (decl
)))
2657 /* A complete type is ok if size is fixed. */
2659 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl
))) != INTEGER_CST
2660 || C_DECL_VARIABLE_SIZE (decl
))
2662 error ("variable-sized object may not be initialized");
2666 else if (TREE_CODE (TREE_TYPE (decl
)) != ARRAY_TYPE
)
2668 error ("variable '%D' has initializer but incomplete type", decl
);
2671 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
2673 error ("elements of array '%D' have incomplete type", decl
);
2680 DECL_EXTERNAL (decl
) = 0;
2681 if (current_scope
== file_scope
)
2682 TREE_STATIC (decl
) = 1;
2684 /* Tell 'pushdecl' this is an initialized decl
2685 even though we don't yet have the initializer expression.
2686 Also tell 'finish_decl' it may store the real initializer. */
2687 DECL_INITIAL (decl
) = error_mark_node
;
2690 /* If this is a function declaration, write a record describing it to the
2691 prototypes file (if requested). */
2693 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2694 gen_aux_info_record (decl
, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl
)) != 0);
2696 /* ANSI specifies that a tentative definition which is not merged with
2697 a non-tentative definition behaves exactly like a definition with an
2698 initializer equal to zero. (Section 3.7.2)
2700 -fno-common gives strict ANSI behavior, though this tends to break
2701 a large body of code that grew up without this rule.
2703 Thread-local variables are never common, since there's no entrenched
2704 body of code to break, and it allows more efficient variable references
2705 in the presence of dynamic linking. */
2707 if (TREE_CODE (decl
) == VAR_DECL
2709 && TREE_PUBLIC (decl
)
2710 && !DECL_THREAD_LOCAL (decl
)
2712 DECL_COMMON (decl
) = 1;
2714 /* Set attributes here so if duplicate decl, will have proper attributes. */
2715 decl_attributes (&decl
, attributes
, 0);
2717 if (TREE_CODE (decl
) == FUNCTION_DECL
2718 && targetm
.calls
.promote_prototypes (TREE_TYPE (decl
)))
2720 tree ce
= declarator
;
2722 if (TREE_CODE (ce
) == INDIRECT_REF
)
2723 ce
= TREE_OPERAND (declarator
, 0);
2724 if (TREE_CODE (ce
) == CALL_EXPR
)
2726 tree args
= TREE_PURPOSE (TREE_OPERAND (ce
, 1));
2727 for (; args
; args
= TREE_CHAIN (args
))
2729 tree type
= TREE_TYPE (args
);
2730 if (INTEGRAL_TYPE_P (type
)
2731 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
2732 DECL_ARG_TYPE (args
) = integer_type_node
;
2737 if (TREE_CODE (decl
) == FUNCTION_DECL
2738 && DECL_DECLARED_INLINE_P (decl
)
2739 && DECL_UNINLINABLE (decl
)
2740 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl
)))
2741 warning ("%Jinline function '%D' given attribute noinline", decl
, decl
);
2743 /* Add this decl to the current scope.
2744 TEM may equal DECL or it may be a previous decl of the same name. */
2745 tem
= pushdecl (decl
);
2750 /* Finish processing of a declaration;
2751 install its initial value.
2752 If the length of an array type is not known before,
2753 it must be determined now, from the initial value, or it is an error. */
2756 finish_decl (tree decl
, tree init
, tree asmspec_tree
)
2758 tree type
= TREE_TYPE (decl
);
2759 int was_incomplete
= (DECL_SIZE (decl
) == 0);
2760 const char *asmspec
= 0;
2762 /* If a name was specified, get the string. */
2763 if (current_scope
== file_scope
)
2764 asmspec_tree
= maybe_apply_renaming_pragma (decl
, asmspec_tree
);
2766 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
2768 /* If `start_decl' didn't like having an initialization, ignore it now. */
2769 if (init
!= 0 && DECL_INITIAL (decl
) == 0)
2772 /* Don't crash if parm is initialized. */
2773 if (TREE_CODE (decl
) == PARM_DECL
)
2777 store_init_value (decl
, init
);
2779 if (c_dialect_objc () && (TREE_CODE (decl
) == VAR_DECL
2780 || TREE_CODE (decl
) == FUNCTION_DECL
2781 || TREE_CODE (decl
) == FIELD_DECL
))
2782 objc_check_decl (decl
);
2784 /* Deduce size of array from initialization, if not already known. */
2785 if (TREE_CODE (type
) == ARRAY_TYPE
2786 && TYPE_DOMAIN (type
) == 0
2787 && TREE_CODE (decl
) != TYPE_DECL
)
2790 = (TREE_STATIC (decl
)
2791 /* Even if pedantic, an external linkage array
2792 may have incomplete type at first. */
2793 ? pedantic
&& !TREE_PUBLIC (decl
)
2794 : !DECL_EXTERNAL (decl
));
2796 = complete_array_type (type
, DECL_INITIAL (decl
), do_default
);
2798 /* Get the completed type made by complete_array_type. */
2799 type
= TREE_TYPE (decl
);
2802 error ("%Jinitializer fails to determine size of '%D'", decl
, decl
);
2804 else if (failure
== 2)
2807 error ("%Jarray size missing in '%D'", decl
, decl
);
2808 /* If a `static' var's size isn't known,
2809 make it extern as well as static, so it does not get
2811 If it is not `static', then do not mark extern;
2812 finish_incomplete_decl will give it a default size
2813 and it will get allocated. */
2814 else if (!pedantic
&& TREE_STATIC (decl
) && ! TREE_PUBLIC (decl
))
2815 DECL_EXTERNAL (decl
) = 1;
2818 /* TYPE_MAX_VALUE is always one less than the number of elements
2819 in the array, because we start counting at zero. Therefore,
2820 warn only if the value is less than zero. */
2821 else if (pedantic
&& TYPE_DOMAIN (type
) != 0
2822 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))) < 0)
2823 error ("%Jzero or negative size array '%D'", decl
, decl
);
2825 layout_decl (decl
, 0);
2828 if (TREE_CODE (decl
) == VAR_DECL
)
2830 if (DECL_SIZE (decl
) == 0 && TREE_TYPE (decl
) != error_mark_node
2831 && COMPLETE_TYPE_P (TREE_TYPE (decl
)))
2832 layout_decl (decl
, 0);
2834 if (DECL_SIZE (decl
) == 0
2835 /* Don't give an error if we already gave one earlier. */
2836 && TREE_TYPE (decl
) != error_mark_node
2837 && (TREE_STATIC (decl
)
2839 /* A static variable with an incomplete type
2840 is an error if it is initialized.
2841 Also if it is not file scope.
2842 Otherwise, let it through, but if it is not `extern'
2843 then it may cause an error message later. */
2844 (DECL_INITIAL (decl
) != 0
2845 || !DECL_FILE_SCOPE_P (decl
))
2847 /* An automatic variable with an incomplete type
2849 !DECL_EXTERNAL (decl
)))
2851 error ("%Jstorage size of '%D' isn't known", decl
, decl
);
2852 TREE_TYPE (decl
) = error_mark_node
;
2855 if ((DECL_EXTERNAL (decl
) || TREE_STATIC (decl
))
2856 && DECL_SIZE (decl
) != 0)
2858 if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
2859 constant_expression_warning (DECL_SIZE (decl
));
2861 error ("%Jstorage size of '%D' isn't constant", decl
, decl
);
2864 if (TREE_USED (type
))
2865 TREE_USED (decl
) = 1;
2868 /* If this is a function and an assembler name is specified, reset DECL_RTL
2869 so we can give it its new name. Also, update built_in_decls if it
2870 was a normal built-in. */
2871 if (TREE_CODE (decl
) == FUNCTION_DECL
&& asmspec
)
2873 /* ASMSPEC is given, and not the name of a register. Mark the
2874 name with a star so assemble_name won't munge it. */
2875 char *starred
= alloca (strlen (asmspec
) + 2);
2877 strcpy (starred
+ 1, asmspec
);
2879 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
)
2881 tree builtin
= built_in_decls
[DECL_FUNCTION_CODE (decl
)];
2882 SET_DECL_RTL (builtin
, NULL_RTX
);
2883 SET_DECL_ASSEMBLER_NAME (builtin
, get_identifier (starred
));
2884 #ifdef TARGET_MEM_FUNCTIONS
2885 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_MEMCPY
)
2886 init_block_move_fn (starred
);
2887 else if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_MEMSET
)
2888 init_block_clear_fn (starred
);
2890 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_BCOPY
)
2891 init_block_move_fn (starred
);
2892 else if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_BZERO
)
2893 init_block_clear_fn (starred
);
2896 SET_DECL_RTL (decl
, NULL_RTX
);
2897 change_decl_assembler_name (decl
, get_identifier (starred
));
2900 /* If #pragma weak was used, mark the decl weak now. */
2901 if (current_scope
== file_scope
)
2902 maybe_apply_pragma_weak (decl
);
2904 /* Output the assembler code and/or RTL code for variables and functions,
2905 unless the type is an undefined structure or union.
2906 If not, it will get done when the type is completed. */
2908 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
)
2910 /* This is a no-op in c-lang.c or something real in objc-act.c. */
2911 if (c_dialect_objc ())
2912 objc_check_decl (decl
);
2914 if (DECL_FILE_SCOPE_P (decl
))
2916 if (DECL_INITIAL (decl
) == NULL_TREE
2917 || DECL_INITIAL (decl
) == error_mark_node
)
2918 /* Don't output anything
2919 when a tentative file-scope definition is seen.
2920 But at end of compilation, do output code for them. */
2921 DECL_DEFER_OUTPUT (decl
) = 1;
2922 rest_of_decl_compilation (decl
, asmspec
, true, 0);
2926 /* This is a local variable. If there is an ASMSPEC, the
2927 user has requested that we handle it specially. */
2930 /* In conjunction with an ASMSPEC, the `register'
2931 keyword indicates that we should place the variable
2932 in a particular register. */
2933 if (C_DECL_REGISTER (decl
))
2935 DECL_C_HARD_REGISTER (decl
) = 1;
2936 /* This cannot be done for a structure with volatile
2937 fields, on which DECL_REGISTER will have been
2939 if (!DECL_REGISTER (decl
))
2940 error ("cannot put object with volatile field into register");
2943 /* If this is not a static variable, issue a warning.
2944 It doesn't make any sense to give an ASMSPEC for an
2945 ordinary, non-register local variable. Historically,
2946 GCC has accepted -- but ignored -- the ASMSPEC in
2948 if (TREE_CODE (decl
) == VAR_DECL
2949 && !C_DECL_REGISTER (decl
)
2950 && !TREE_STATIC (decl
))
2951 warning ("%Jignoring asm-specifier for non-static local "
2952 "variable '%D'", decl
, decl
);
2954 change_decl_assembler_name (decl
, get_identifier (asmspec
));
2957 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2958 add_decl_stmt (decl
);
2961 if (!DECL_FILE_SCOPE_P (decl
))
2963 /* Recompute the RTL of a local array now
2964 if it used to be an incomplete type. */
2966 && ! TREE_STATIC (decl
) && ! DECL_EXTERNAL (decl
))
2968 /* If we used it already as memory, it must stay in memory. */
2969 TREE_ADDRESSABLE (decl
) = TREE_USED (decl
);
2970 /* If it's still incomplete now, no init will save it. */
2971 if (DECL_SIZE (decl
) == 0)
2972 DECL_INITIAL (decl
) = 0;
2977 /* If this was marked 'used', be sure it will be output. */
2978 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl
)))
2979 mark_referenced (DECL_ASSEMBLER_NAME (decl
));
2981 if (TREE_CODE (decl
) == TYPE_DECL
)
2982 rest_of_decl_compilation (decl
, NULL
, DECL_FILE_SCOPE_P (decl
), 0);
2984 /* At the end of a declaration, throw away any variable type sizes
2985 of types defined inside that declaration. There is no use
2986 computing them in the following function definition. */
2987 if (current_scope
== file_scope
)
2988 get_pending_sizes ();
2990 /* Install a cleanup (aka destructor) if one was given. */
2991 if (TREE_CODE (decl
) == VAR_DECL
&& !TREE_STATIC (decl
))
2993 tree attr
= lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl
));
2996 static bool eh_initialized_p
;
2998 tree cleanup_id
= TREE_VALUE (TREE_VALUE (attr
));
2999 tree cleanup_decl
= lookup_name (cleanup_id
);
3002 /* Build "cleanup(&decl)" for the destructor. */
3003 cleanup
= build_unary_op (ADDR_EXPR
, decl
, 0);
3004 cleanup
= build_tree_list (NULL_TREE
, cleanup
);
3005 cleanup
= build_function_call (cleanup_decl
, cleanup
);
3007 /* Don't warn about decl unused; the cleanup uses it. */
3008 TREE_USED (decl
) = 1;
3010 /* Initialize EH, if we've been told to do so. */
3011 if (flag_exceptions
&& !eh_initialized_p
)
3013 eh_initialized_p
= true;
3014 eh_personality_libfunc
3015 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
3016 ? "__gcc_personality_sj0"
3017 : "__gcc_personality_v0");
3018 using_eh_for_cleanups ();
3021 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
3026 /* Given a parsed parameter declaration, decode it into a PARM_DECL
3027 and push that on the current scope. */
3030 push_parm_decl (tree parm
)
3034 /* Don't attempt to expand sizes while parsing this decl.
3035 (We can get here with i_s_e 1 somehow from Objective-C.) */
3036 int save_immediate_size_expand
= immediate_size_expand
;
3037 immediate_size_expand
= 0;
3039 decl
= grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm
)),
3040 TREE_PURPOSE (TREE_PURPOSE (parm
)),
3042 decl_attributes (&decl
, TREE_VALUE (parm
), 0);
3044 decl
= pushdecl (decl
);
3046 finish_decl (decl
, NULL_TREE
, NULL_TREE
);
3048 immediate_size_expand
= save_immediate_size_expand
;
3051 /* Mark all the parameter declarations to date as forward decls.
3052 Also diagnose use of this extension. */
3055 mark_forward_parm_decls (void)
3057 struct c_binding
*b
;
3059 if (pedantic
&& !current_scope
->warned_forward_parm_decls
)
3061 pedwarn ("ISO C forbids forward parameter declarations");
3062 current_scope
->warned_forward_parm_decls
= true;
3065 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
3066 if (TREE_CODE (b
->decl
) == PARM_DECL
)
3067 TREE_ASM_WRITTEN (b
->decl
) = 1;
3070 static GTY(()) int compound_literal_number
;
3072 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3073 literal, which may be an incomplete array type completed by the
3074 initializer; INIT is a CONSTRUCTOR that initializes the compound
3078 build_compound_literal (tree type
, tree init
)
3080 /* We do not use start_decl here because we have a type, not a declarator;
3081 and do not use finish_decl because the decl should be stored inside
3082 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
3083 tree decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
3086 DECL_EXTERNAL (decl
) = 0;
3087 TREE_PUBLIC (decl
) = 0;
3088 TREE_STATIC (decl
) = (current_scope
== file_scope
);
3089 DECL_CONTEXT (decl
) = current_function_decl
;
3090 TREE_USED (decl
) = 1;
3091 TREE_TYPE (decl
) = type
;
3092 TREE_READONLY (decl
) = TYPE_READONLY (type
);
3093 store_init_value (decl
, init
);
3095 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
3097 int failure
= complete_array_type (type
, DECL_INITIAL (decl
), 1);
3102 type
= TREE_TYPE (decl
);
3103 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
3104 return error_mark_node
;
3106 stmt
= build_stmt (DECL_STMT
, decl
);
3107 complit
= build1 (COMPOUND_LITERAL_EXPR
, TREE_TYPE (decl
), stmt
);
3108 TREE_SIDE_EFFECTS (complit
) = 1;
3110 layout_decl (decl
, 0);
3112 if (TREE_STATIC (decl
))
3114 /* This decl needs a name for the assembler output. We also need
3115 a unique suffix to be added to the name. */
3118 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
3119 compound_literal_number
);
3120 compound_literal_number
++;
3121 DECL_NAME (decl
) = get_identifier (name
);
3122 DECL_DEFER_OUTPUT (decl
) = 1;
3123 DECL_COMDAT (decl
) = 1;
3124 DECL_ARTIFICIAL (decl
) = 1;
3126 rest_of_decl_compilation (decl
, NULL
, 1, 0);
3132 /* Make TYPE a complete type based on INITIAL_VALUE.
3133 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3134 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3137 complete_array_type (tree type
, tree initial_value
, int do_default
)
3139 tree maxindex
= NULL_TREE
;
3144 /* Note MAXINDEX is really the maximum index,
3145 one less than the size. */
3146 if (TREE_CODE (initial_value
) == STRING_CST
)
3149 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
3150 maxindex
= build_int_2 ((TREE_STRING_LENGTH (initial_value
)
3153 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
3155 tree elts
= CONSTRUCTOR_ELTS (initial_value
);
3156 maxindex
= build_int_2 (-1, -1);
3157 for (; elts
; elts
= TREE_CHAIN (elts
))
3159 if (TREE_PURPOSE (elts
))
3160 maxindex
= TREE_PURPOSE (elts
);
3162 maxindex
= fold (build (PLUS_EXPR
, integer_type_node
,
3163 maxindex
, integer_one_node
));
3165 maxindex
= copy_node (maxindex
);
3169 /* Make an error message unless that happened already. */
3170 if (initial_value
!= error_mark_node
)
3173 /* Prevent further error messages. */
3174 maxindex
= build_int_2 (0, 0);
3181 maxindex
= build_int_2 (0, 0);
3187 TYPE_DOMAIN (type
) = build_index_type (maxindex
);
3188 if (!TREE_TYPE (maxindex
))
3189 TREE_TYPE (maxindex
) = TYPE_DOMAIN (type
);
3192 /* Lay out the type now that we can get the real answer. */
3199 /* Determine whether TYPE is a structure with a flexible array member,
3200 or a union containing such a structure (possibly recursively). */
3203 flexible_array_type_p (tree type
)
3206 switch (TREE_CODE (type
))
3209 x
= TYPE_FIELDS (type
);
3212 while (TREE_CHAIN (x
) != NULL_TREE
)
3214 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
3215 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
3216 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
3217 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
3221 for (x
= TYPE_FIELDS (type
); x
!= NULL_TREE
; x
= TREE_CHAIN (x
))
3223 if (flexible_array_type_p (TREE_TYPE (x
)))
3232 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3233 replacing with appropriate values if they are invalid. */
3235 check_bitfield_type_and_width (tree
*type
, tree
*width
, const char *orig_name
)
3238 unsigned int max_width
;
3239 unsigned HOST_WIDE_INT w
;
3240 const char *name
= orig_name
? orig_name
: _("<anonymous>");
3243 STRIP_NOPS (*width
);
3245 /* Detect and ignore out of range field width and process valid
3247 if (TREE_CODE (*width
) != INTEGER_CST
)
3249 error ("bit-field `%s' width not an integer constant", name
);
3250 *width
= integer_one_node
;
3254 constant_expression_warning (*width
);
3255 if (tree_int_cst_sgn (*width
) < 0)
3257 error ("negative width in bit-field `%s'", name
);
3258 *width
= integer_one_node
;
3260 else if (integer_zerop (*width
) && orig_name
)
3262 error ("zero width for bit-field `%s'", name
);
3263 *width
= integer_one_node
;
3267 /* Detect invalid bit-field type. */
3268 if (TREE_CODE (*type
) != INTEGER_TYPE
3269 && TREE_CODE (*type
) != BOOLEAN_TYPE
3270 && TREE_CODE (*type
) != ENUMERAL_TYPE
)
3272 error ("bit-field `%s' has invalid type", name
);
3273 *type
= unsigned_type_node
;
3276 type_mv
= TYPE_MAIN_VARIANT (*type
);
3278 && type_mv
!= integer_type_node
3279 && type_mv
!= unsigned_type_node
3280 && type_mv
!= boolean_type_node
)
3281 pedwarn ("type of bit-field `%s' is a GCC extension", name
);
3283 if (type_mv
== boolean_type_node
)
3284 max_width
= CHAR_TYPE_SIZE
;
3286 max_width
= TYPE_PRECISION (*type
);
3288 if (0 < compare_tree_int (*width
, max_width
))
3290 error ("width of `%s' exceeds its type", name
);
3292 *width
= build_int_2 (w
, 0);
3295 w
= tree_low_cst (*width
, 1);
3297 if (TREE_CODE (*type
) == ENUMERAL_TYPE
3298 && (w
< min_precision (TYPE_MIN_VALUE (*type
), TYPE_UNSIGNED (*type
))
3299 || w
< min_precision (TYPE_MAX_VALUE (*type
),
3300 TYPE_UNSIGNED (*type
))))
3301 warning ("`%s' is narrower than values of its type", name
);
3304 /* Given declspecs and a declarator,
3305 determine the name and type of the object declared
3306 and construct a ..._DECL node for it.
3307 (In one case we can return a ..._TYPE node instead.
3308 For invalid input we sometimes return 0.)
3310 DECLSPECS is a chain of tree_list nodes whose value fields
3311 are the storage classes and type specifiers.
3313 DECL_CONTEXT says which syntactic context this declaration is in:
3314 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3315 FUNCDEF for a function definition. Like NORMAL but a few different
3316 error messages in each case. Return value may be zero meaning
3317 this definition is too screwy to try to parse.
3318 PARM for a parameter declaration (either within a function prototype
3319 or before a function body). Make a PARM_DECL, or return void_type_node.
3320 TYPENAME if for a typename (in a cast or sizeof).
3321 Don't make a DECL node; just return the ..._TYPE node.
3322 FIELD for a struct or union field; make a FIELD_DECL.
3323 INITIALIZED is 1 if the decl has an initializer.
3324 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
3325 representing the width of the bit-field.
3327 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3328 It may also be so in the PARM case, for a prototype where the
3329 argument type is specified but not the name.
3331 This function is where the complicated C meanings of `static'
3332 and `extern' are interpreted. */
3335 grokdeclarator (tree declarator
, tree declspecs
,
3336 enum decl_context decl_context
, int initialized
, tree
*width
)
3340 tree type
= NULL_TREE
;
3345 int type_quals
= TYPE_UNQUALIFIED
;
3347 int explicit_int
= 0;
3348 int explicit_char
= 0;
3349 int defaulted_int
= 0;
3350 tree typedef_decl
= 0;
3351 const char *name
, *orig_name
;
3352 tree typedef_type
= 0;
3353 int funcdef_flag
= 0;
3354 enum tree_code innermost_code
= ERROR_MARK
;
3355 int size_varies
= 0;
3356 tree decl_attr
= NULL_TREE
;
3357 tree array_ptr_quals
= NULL_TREE
;
3358 int array_parm_static
= 0;
3359 tree returned_attrs
= NULL_TREE
;
3360 bool bitfield
= width
!= NULL
;
3362 tree arg_info
= NULL_TREE
;
3364 if (decl_context
== FUNCDEF
)
3365 funcdef_flag
= 1, decl_context
= NORMAL
;
3367 /* Look inside a declarator for the name being declared
3368 and get it as a string, for an error message. */
3370 tree decl
= declarator
;
3374 switch (TREE_CODE (decl
))
3379 innermost_code
= TREE_CODE (decl
);
3380 decl
= TREE_OPERAND (decl
, 0);
3384 decl
= TREE_VALUE (decl
);
3387 case IDENTIFIER_NODE
:
3388 name
= IDENTIFIER_POINTER (decl
);
3400 /* A function definition's declarator must have the form of
3401 a function declarator. */
3403 if (funcdef_flag
&& innermost_code
!= CALL_EXPR
)
3406 /* If this looks like a function definition, make it one,
3407 even if it occurs where parms are expected.
3408 Then store_parm_decls will reject it and not use it as a parm. */
3409 if (decl_context
== NORMAL
&& !funcdef_flag
&& current_scope
->parm_flag
)
3410 decl_context
= PARM
;
3412 /* Look through the decl specs and record which ones appear.
3413 Some typespecs are defined as built-in typenames.
3414 Others, the ones that are modifiers of other types,
3415 are represented by bits in SPECBITS: set the bits for
3416 the modifiers that appear. Storage class keywords are also in SPECBITS.
3418 If there is a typedef name or a type, store the type in TYPE.
3419 This includes builtin typedefs such as `int'.
3421 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3422 and did not come from a user typedef.
3424 Set LONGLONG if `long' is mentioned twice. */
3426 for (spec
= declspecs
; spec
; spec
= TREE_CHAIN (spec
))
3428 tree id
= TREE_VALUE (spec
);
3430 /* If the entire declaration is itself tagged as deprecated then
3431 suppress reports of deprecated items. */
3432 if (id
&& TREE_DEPRECATED (id
))
3434 if (deprecated_state
!= DEPRECATED_SUPPRESS
)
3435 warn_deprecated_use (id
);
3438 if (id
== ridpointers
[(int) RID_INT
])
3440 if (id
== ridpointers
[(int) RID_CHAR
])
3443 if (TREE_CODE (id
) == IDENTIFIER_NODE
&& C_IS_RESERVED_WORD (id
))
3445 enum rid i
= C_RID_CODE (id
);
3446 if ((int) i
<= (int) RID_LAST_MODIFIER
)
3448 if (i
== RID_LONG
&& (specbits
& (1 << (int) RID_LONG
)))
3451 error ("`long long long' is too long for GCC");
3454 if (pedantic
&& !flag_isoc99
&& ! in_system_header
3456 pedwarn ("ISO C90 does not support `long long'");
3460 else if (specbits
& (1 << (int) i
))
3462 if (i
== RID_CONST
|| i
== RID_VOLATILE
|| i
== RID_RESTRICT
)
3464 if (pedantic
&& !flag_isoc99
)
3465 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id
));
3468 error ("duplicate `%s'", IDENTIFIER_POINTER (id
));
3471 /* Diagnose "__thread extern". Recall that this list
3472 is in the reverse order seen in the text. */
3474 && (specbits
& (1 << (int) RID_EXTERN
3475 | 1 << (int) RID_STATIC
)))
3477 if (specbits
& 1 << (int) RID_EXTERN
)
3478 error ("`__thread' before `extern'");
3480 error ("`__thread' before `static'");
3483 specbits
|= 1 << (int) i
;
3488 error ("two or more data types in declaration of `%s'", name
);
3489 /* Actual typedefs come to us as TYPE_DECL nodes. */
3490 else if (TREE_CODE (id
) == TYPE_DECL
)
3492 if (TREE_TYPE (id
) == error_mark_node
)
3493 ; /* Allow the type to default to int to avoid cascading errors. */
3496 type
= TREE_TYPE (id
);
3497 decl_attr
= DECL_ATTRIBUTES (id
);
3501 /* Built-in types come as identifiers. */
3502 else if (TREE_CODE (id
) == IDENTIFIER_NODE
)
3504 tree t
= lookup_name (id
);
3505 if (!t
|| TREE_CODE (t
) != TYPE_DECL
)
3506 error ("`%s' fails to be a typedef or built in type",
3507 IDENTIFIER_POINTER (id
));
3508 else if (TREE_TYPE (t
) == error_mark_node
)
3512 type
= TREE_TYPE (t
);
3516 else if (TREE_CODE (id
) != ERROR_MARK
)
3523 typedef_type
= type
;
3525 size_varies
= C_TYPE_VARIABLE_SIZE (type
);
3527 /* No type at all: default to `int', and set DEFAULTED_INT
3528 because it was not a user-defined typedef. */
3532 if ((! (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3533 | (1 << (int) RID_SIGNED
)
3534 | (1 << (int) RID_UNSIGNED
)
3535 | (1 << (int) RID_COMPLEX
))))
3536 /* Don't warn about typedef foo = bar. */
3537 && ! (specbits
& (1 << (int) RID_TYPEDEF
) && initialized
)
3538 && ! in_system_header
)
3540 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
3541 and this is a function, or if -Wimplicit; prefer the former
3542 warning since it is more explicit. */
3543 if ((warn_implicit_int
|| warn_return_type
|| flag_isoc99
)
3545 warn_about_return_type
= 1;
3546 else if (warn_implicit_int
|| flag_isoc99
)
3547 pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
3552 type
= integer_type_node
;
3555 /* Now process the modifiers that were specified
3556 and check for invalid combinations. */
3558 /* Long double is a special combination. */
3560 if ((specbits
& 1 << (int) RID_LONG
) && ! longlong
3561 && TYPE_MAIN_VARIANT (type
) == double_type_node
)
3563 specbits
&= ~(1 << (int) RID_LONG
);
3564 type
= long_double_type_node
;
3567 /* Check all other uses of type modifiers. */
3569 if (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3570 | (1 << (int) RID_UNSIGNED
) | (1 << (int) RID_SIGNED
)))
3574 if ((specbits
& 1 << (int) RID_LONG
)
3575 && (specbits
& 1 << (int) RID_SHORT
))
3576 error ("both long and short specified for `%s'", name
);
3577 else if (((specbits
& 1 << (int) RID_LONG
)
3578 || (specbits
& 1 << (int) RID_SHORT
))
3580 error ("long or short specified with char for `%s'", name
);
3581 else if (((specbits
& 1 << (int) RID_LONG
)
3582 || (specbits
& 1 << (int) RID_SHORT
))
3583 && TREE_CODE (type
) == REAL_TYPE
)
3585 static int already
= 0;
3587 error ("long or short specified with floating type for `%s'", name
);
3588 if (! already
&& ! pedantic
)
3590 error ("the only valid combination is `long double'");
3594 else if ((specbits
& 1 << (int) RID_SIGNED
)
3595 && (specbits
& 1 << (int) RID_UNSIGNED
))
3596 error ("both signed and unsigned specified for `%s'", name
);
3597 else if (TREE_CODE (type
) != INTEGER_TYPE
)
3598 error ("long, short, signed or unsigned invalid for `%s'", name
);
3602 if (!explicit_int
&& !defaulted_int
&& !explicit_char
)
3604 error ("long, short, signed or unsigned used invalidly for `%s'",
3610 /* Discard the type modifiers if they are invalid. */
3613 specbits
&= ~((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3614 | (1 << (int) RID_UNSIGNED
) | (1 << (int) RID_SIGNED
));
3619 if ((specbits
& (1 << (int) RID_COMPLEX
))
3620 && TREE_CODE (type
) != INTEGER_TYPE
&& TREE_CODE (type
) != REAL_TYPE
)
3622 error ("complex invalid for `%s'", name
);
3623 specbits
&= ~(1 << (int) RID_COMPLEX
);
3626 /* Decide whether an integer type is signed or not.
3627 Optionally treat bit-fields as signed by default. */
3628 if (specbits
& 1 << (int) RID_UNSIGNED
3629 || (bitfield
&& ! flag_signed_bitfields
3630 && (explicit_int
|| defaulted_int
|| explicit_char
3631 /* A typedef for plain `int' without `signed'
3632 can be controlled just like plain `int'. */
3633 || ! (typedef_decl
!= 0
3634 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
3635 && TREE_CODE (type
) != ENUMERAL_TYPE
3636 && !(specbits
& 1 << (int) RID_SIGNED
)))
3639 type
= long_long_unsigned_type_node
;
3640 else if (specbits
& 1 << (int) RID_LONG
)
3641 type
= long_unsigned_type_node
;
3642 else if (specbits
& 1 << (int) RID_SHORT
)
3643 type
= short_unsigned_type_node
;
3644 else if (type
== char_type_node
)
3645 type
= unsigned_char_type_node
;
3646 else if (typedef_decl
)
3647 type
= c_common_unsigned_type (type
);
3649 type
= unsigned_type_node
;
3651 else if ((specbits
& 1 << (int) RID_SIGNED
)
3652 && type
== char_type_node
)
3653 type
= signed_char_type_node
;
3655 type
= long_long_integer_type_node
;
3656 else if (specbits
& 1 << (int) RID_LONG
)
3657 type
= long_integer_type_node
;
3658 else if (specbits
& 1 << (int) RID_SHORT
)
3659 type
= short_integer_type_node
;
3661 if (specbits
& 1 << (int) RID_COMPLEX
)
3663 if (pedantic
&& !flag_isoc99
)
3664 pedwarn ("ISO C90 does not support complex types");
3665 /* If we just have "complex", it is equivalent to
3666 "complex double", but if any modifiers at all are specified it is
3667 the complex form of TYPE. E.g, "complex short" is
3668 "complex short int". */
3670 if (defaulted_int
&& ! longlong
3671 && ! (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3672 | (1 << (int) RID_SIGNED
)
3673 | (1 << (int) RID_UNSIGNED
))))
3676 pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
3677 type
= complex_double_type_node
;
3679 else if (type
== integer_type_node
)
3682 pedwarn ("ISO C does not support complex integer types");
3683 type
= complex_integer_type_node
;
3685 else if (type
== float_type_node
)
3686 type
= complex_float_type_node
;
3687 else if (type
== double_type_node
)
3688 type
= complex_double_type_node
;
3689 else if (type
== long_double_type_node
)
3690 type
= complex_long_double_type_node
;
3694 pedwarn ("ISO C does not support complex integer types");
3695 type
= build_complex_type (type
);
3699 /* Check the type and width of a bit-field. */
3701 check_bitfield_type_and_width (&type
, width
, orig_name
);
3703 /* Figure out the type qualifiers for the declaration. There are
3704 two ways a declaration can become qualified. One is something
3705 like `const int i' where the `const' is explicit. Another is
3706 something like `typedef const int CI; CI i' where the type of the
3707 declaration contains the `const'. A third possibility is that
3708 there is a type qualifier on the element type of a typedefed
3709 array type, in which case we should extract that qualifier so
3710 that c_apply_type_quals_to_decls receives the full list of
3711 qualifiers to work with (C90 is not entirely clear about whether
3712 duplicate qualifiers should be diagnosed in this case, but it
3713 seems most appropriate to do so). */
3714 element_type
= strip_array_types (type
);
3715 constp
= !! (specbits
& 1 << (int) RID_CONST
) + TYPE_READONLY (element_type
);
3717 = !! (specbits
& 1 << (int) RID_RESTRICT
) + TYPE_RESTRICT (element_type
);
3719 = !! (specbits
& 1 << (int) RID_VOLATILE
) + TYPE_VOLATILE (element_type
);
3720 inlinep
= !! (specbits
& (1 << (int) RID_INLINE
));
3721 if (pedantic
&& !flag_isoc99
)
3724 pedwarn ("duplicate `const'");
3726 pedwarn ("duplicate `restrict'");
3728 pedwarn ("duplicate `volatile'");
3730 if (! flag_gen_aux_info
&& (TYPE_QUALS (type
)))
3731 type
= TYPE_MAIN_VARIANT (type
);
3732 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
3733 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
3734 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
3736 /* Warn if two storage classes are given. Default to `auto'. */
3741 if (specbits
& 1 << (int) RID_AUTO
) nclasses
++;
3742 if (specbits
& 1 << (int) RID_STATIC
) nclasses
++;
3743 if (specbits
& 1 << (int) RID_EXTERN
) nclasses
++;
3744 if (specbits
& 1 << (int) RID_REGISTER
) nclasses
++;
3745 if (specbits
& 1 << (int) RID_TYPEDEF
) nclasses
++;
3747 /* "static __thread" and "extern __thread" are allowed. */
3748 if ((specbits
& (1 << (int) RID_THREAD
3749 | 1 << (int) RID_STATIC
3750 | 1 << (int) RID_EXTERN
)) == (1 << (int) RID_THREAD
))
3753 /* Warn about storage classes that are invalid for certain
3754 kinds of declarations (parameters, typenames, etc.). */
3757 error ("multiple storage classes in declaration of `%s'", name
);
3758 else if (funcdef_flag
3760 & ((1 << (int) RID_REGISTER
)
3761 | (1 << (int) RID_AUTO
)
3762 | (1 << (int) RID_TYPEDEF
)
3763 | (1 << (int) RID_THREAD
))))
3765 if (specbits
& 1 << (int) RID_AUTO
3766 && (pedantic
|| current_scope
== file_scope
))
3767 pedwarn ("function definition declared `auto'");
3768 if (specbits
& 1 << (int) RID_REGISTER
)
3769 error ("function definition declared `register'");
3770 if (specbits
& 1 << (int) RID_TYPEDEF
)
3771 error ("function definition declared `typedef'");
3772 if (specbits
& 1 << (int) RID_THREAD
)
3773 error ("function definition declared `__thread'");
3774 specbits
&= ~((1 << (int) RID_TYPEDEF
) | (1 << (int) RID_REGISTER
)
3775 | (1 << (int) RID_AUTO
) | (1 << (int) RID_THREAD
));
3777 else if (decl_context
!= NORMAL
&& nclasses
> 0)
3779 if (decl_context
== PARM
&& specbits
& 1 << (int) RID_REGISTER
)
3783 switch (decl_context
)
3786 error ("storage class specified for structure field `%s'",
3790 error ("storage class specified for parameter `%s'", name
);
3793 error ("storage class specified for typename");
3796 specbits
&= ~((1 << (int) RID_TYPEDEF
) | (1 << (int) RID_REGISTER
)
3797 | (1 << (int) RID_AUTO
) | (1 << (int) RID_STATIC
)
3798 | (1 << (int) RID_EXTERN
) | (1 << (int) RID_THREAD
));
3801 else if (specbits
& 1 << (int) RID_EXTERN
&& initialized
&& ! funcdef_flag
)
3803 /* `extern' with initialization is invalid if not at file scope. */
3804 if (current_scope
== file_scope
)
3805 warning ("`%s' initialized and declared `extern'", name
);
3807 error ("`%s' has both `extern' and initializer", name
);
3809 else if (current_scope
== file_scope
)
3811 if (specbits
& 1 << (int) RID_AUTO
)
3812 error ("file-scope declaration of `%s' specifies `auto'", name
);
3816 if (specbits
& 1 << (int) RID_EXTERN
&& funcdef_flag
)
3817 error ("nested function `%s' declared `extern'", name
);
3818 else if ((specbits
& (1 << (int) RID_THREAD
3819 | 1 << (int) RID_EXTERN
3820 | 1 << (int) RID_STATIC
))
3821 == (1 << (int) RID_THREAD
))
3823 error ("function-scope `%s' implicitly auto and declared `__thread'",
3825 specbits
&= ~(1 << (int) RID_THREAD
);
3830 /* Now figure out the structure of the declarator proper.
3831 Descend through it, creating more complex types, until we reach
3832 the declared identifier (or NULL_TREE, in an absolute declarator). */
3834 while (declarator
&& TREE_CODE (declarator
) != IDENTIFIER_NODE
)
3836 if (type
== error_mark_node
)
3838 declarator
= TREE_OPERAND (declarator
, 0);
3842 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
3843 an INDIRECT_REF (for *...),
3844 a CALL_EXPR (for ...(...)),
3845 a TREE_LIST (for nested attributes),
3846 an identifier (for the name being declared)
3847 or a null pointer (for the place in an absolute declarator
3848 where the name was omitted).
3849 For the last two cases, we have just exited the loop.
3851 At this point, TYPE is the type of elements of an array,
3852 or for a function to return, or for a pointer to point to.
3853 After this sequence of ifs, TYPE is the type of the
3854 array or function or pointer, and DECLARATOR has had its
3855 outermost layer removed. */
3857 if (array_ptr_quals
!= NULL_TREE
|| array_parm_static
)
3859 /* Only the innermost declarator (making a parameter be of
3860 array type which is converted to pointer type)
3861 may have static or type qualifiers. */
3862 error ("static or type qualifiers in non-parameter array declarator");
3863 array_ptr_quals
= NULL_TREE
;
3864 array_parm_static
= 0;
3867 if (TREE_CODE (declarator
) == TREE_LIST
)
3869 /* We encode a declarator with embedded attributes using
3871 tree attrs
= TREE_PURPOSE (declarator
);
3874 declarator
= TREE_VALUE (declarator
);
3875 inner_decl
= declarator
;
3876 while (inner_decl
!= NULL_TREE
3877 && TREE_CODE (inner_decl
) == TREE_LIST
)
3878 inner_decl
= TREE_VALUE (inner_decl
);
3879 if (inner_decl
== NULL_TREE
3880 || TREE_CODE (inner_decl
) == IDENTIFIER_NODE
)
3881 attr_flags
|= (int) ATTR_FLAG_DECL_NEXT
;
3882 else if (TREE_CODE (inner_decl
) == CALL_EXPR
)
3883 attr_flags
|= (int) ATTR_FLAG_FUNCTION_NEXT
;
3884 else if (TREE_CODE (inner_decl
) == ARRAY_REF
)
3885 attr_flags
|= (int) ATTR_FLAG_ARRAY_NEXT
;
3886 returned_attrs
= decl_attributes (&type
,
3887 chainon (returned_attrs
, attrs
),
3890 else if (TREE_CODE (declarator
) == ARRAY_REF
)
3892 tree itype
= NULL_TREE
;
3893 tree size
= TREE_OPERAND (declarator
, 1);
3894 /* The index is a signed object `sizetype' bits wide. */
3895 tree index_type
= c_common_signed_type (sizetype
);
3897 array_ptr_quals
= TREE_TYPE (declarator
);
3898 array_parm_static
= TREE_STATIC (declarator
);
3900 declarator
= TREE_OPERAND (declarator
, 0);
3902 /* Check for some types that there cannot be arrays of. */
3904 if (VOID_TYPE_P (type
))
3906 error ("declaration of `%s' as array of voids", name
);
3907 type
= error_mark_node
;
3910 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3912 error ("declaration of `%s' as array of functions", name
);
3913 type
= error_mark_node
;
3916 if (pedantic
&& flexible_array_type_p (type
))
3917 pedwarn ("invalid use of structure with flexible array member");
3919 if (size
== error_mark_node
)
3920 type
= error_mark_node
;
3922 if (type
== error_mark_node
)
3925 /* If size was specified, set ITYPE to a range-type for that size.
3926 Otherwise, ITYPE remains null. finish_decl may figure it out
3927 from an initial value. */
3931 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3932 STRIP_TYPE_NOPS (size
);
3934 if (! INTEGRAL_TYPE_P (TREE_TYPE (size
)))
3936 error ("size of array `%s' has non-integer type", name
);
3937 size
= integer_one_node
;
3940 if (pedantic
&& integer_zerop (size
))
3941 pedwarn ("ISO C forbids zero-size array `%s'", name
);
3943 if (TREE_CODE (size
) == INTEGER_CST
)
3945 constant_expression_warning (size
);
3946 if (tree_int_cst_sgn (size
) < 0)
3948 error ("size of array `%s' is negative", name
);
3949 size
= integer_one_node
;
3954 /* Make sure the array size remains visibly nonconstant
3955 even if it is (eg) a const variable with known value. */
3958 if (!flag_isoc99
&& pedantic
)
3960 if (TREE_CONSTANT (size
))
3961 pedwarn ("ISO C90 forbids array `%s' whose size can't be evaluated",
3964 pedwarn ("ISO C90 forbids variable-size array `%s'",
3969 if (integer_zerop (size
))
3971 /* A zero-length array cannot be represented with an
3972 unsigned index type, which is what we'll get with
3973 build_index_type. Create an open-ended range instead. */
3974 itype
= build_range_type (sizetype
, size
, NULL_TREE
);
3978 /* Compute the maximum valid index, that is, size - 1.
3979 Do the calculation in index_type, so that if it is
3980 a variable the computations will be done in the
3982 itype
= fold (build (MINUS_EXPR
, index_type
,
3983 convert (index_type
, size
),
3984 convert (index_type
, size_one_node
)));
3986 /* If that overflowed, the array is too big.
3987 ??? While a size of INT_MAX+1 technically shouldn't
3988 cause an overflow (because we subtract 1), the overflow
3989 is recorded during the conversion to index_type, before
3990 the subtraction. Handling this case seems like an
3991 unnecessary complication. */
3992 if (TREE_OVERFLOW (itype
))
3994 error ("size of array `%s' is too large", name
);
3995 type
= error_mark_node
;
4001 /* We must be able to distinguish the
4002 SAVE_EXPR_CONTEXT for the variably-sized type
4003 so that we can set it correctly in
4004 set_save_expr_context. The convention is
4005 that all SAVE_EXPRs that need to be reset
4006 have NULL_TREE for their SAVE_EXPR_CONTEXT. */
4007 tree cfd
= current_function_decl
;
4008 if (decl_context
== PARM
)
4009 current_function_decl
= NULL_TREE
;
4010 itype
= variable_size (itype
);
4011 if (decl_context
== PARM
)
4012 current_function_decl
= cfd
;
4014 itype
= build_index_type (itype
);
4017 else if (decl_context
== FIELD
)
4019 if (pedantic
&& !flag_isoc99
&& !in_system_header
)
4020 pedwarn ("ISO C90 does not support flexible array members");
4022 /* ISO C99 Flexible array members are effectively identical
4023 to GCC's zero-length array extension. */
4024 itype
= build_range_type (sizetype
, size_zero_node
, NULL_TREE
);
4027 /* If pedantic, complain about arrays of incomplete types. */
4029 if (pedantic
&& !COMPLETE_TYPE_P (type
))
4030 pedwarn ("array type has incomplete element type");
4032 /* Build the array type itself, then merge any constancy or
4033 volatility into the target type. We must do it in this order
4034 to ensure that the TYPE_MAIN_VARIANT field of the array type
4035 is set correctly. */
4037 type
= build_array_type (type
, itype
);
4039 type
= c_build_qualified_type (type
, type_quals
);
4042 C_TYPE_VARIABLE_SIZE (type
) = 1;
4044 /* The GCC extension for zero-length arrays differs from
4045 ISO flexible array members in that sizeof yields zero. */
4046 if (size
&& integer_zerop (size
))
4049 TYPE_SIZE (type
) = bitsize_zero_node
;
4050 TYPE_SIZE_UNIT (type
) = size_zero_node
;
4052 if (decl_context
!= PARM
4053 && (array_ptr_quals
!= NULL_TREE
|| array_parm_static
))
4055 error ("static or type qualifiers in non-parameter array declarator");
4056 array_ptr_quals
= NULL_TREE
;
4057 array_parm_static
= 0;
4060 else if (TREE_CODE (declarator
) == CALL_EXPR
)
4062 /* Say it's a definition only for the CALL_EXPR closest to
4064 bool really_funcdef
= (funcdef_flag
4065 && (TREE_CODE (TREE_OPERAND (declarator
, 0))
4066 == IDENTIFIER_NODE
));
4069 /* Declaring a function type.
4070 Make sure we have a valid type for the function to return. */
4071 if (type
== error_mark_node
)
4076 /* Warn about some types functions can't return. */
4078 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4080 error ("`%s' declared as function returning a function", name
);
4081 type
= integer_type_node
;
4083 if (TREE_CODE (type
) == ARRAY_TYPE
)
4085 error ("`%s' declared as function returning an array", name
);
4086 type
= integer_type_node
;
4089 /* Construct the function type and go to the next
4090 inner layer of declarator. */
4091 arg_info
= TREE_OPERAND (declarator
, 1);
4092 arg_types
= grokparms (arg_info
, really_funcdef
);
4094 /* Type qualifiers before the return type of the function
4095 qualify the return type, not the function type. */
4098 /* Type qualifiers on a function return type are normally
4099 permitted by the standard but have no effect, so give a
4100 warning at -Wextra. Qualifiers on a void return type have
4101 meaning as a GNU extension, and are banned on function
4102 definitions in ISO C. FIXME: strictly we shouldn't
4103 pedwarn for qualified void return types except on function
4104 definitions, but not doing so could lead to the undesirable
4105 state of a "volatile void" function return type not being
4106 warned about, and a use of the function being compiled
4107 with GNU semantics, with no diagnostics under -pedantic. */
4108 if (VOID_TYPE_P (type
) && pedantic
&& !in_system_header
)
4109 pedwarn ("ISO C forbids qualified void function return type");
4110 else if (extra_warnings
4111 && !(VOID_TYPE_P (type
)
4112 && type_quals
== TYPE_QUAL_VOLATILE
))
4113 warning ("type qualifiers ignored on function return type");
4115 type
= c_build_qualified_type (type
, type_quals
);
4117 type_quals
= TYPE_UNQUALIFIED
;
4119 type
= build_function_type (type
, arg_types
);
4120 declarator
= TREE_OPERAND (declarator
, 0);
4122 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4123 the formal parameter list of this FUNCTION_TYPE to point to
4124 the FUNCTION_TYPE node itself. */
4129 for (link
= ARG_INFO_TAGS (arg_info
);
4131 link
= TREE_CHAIN (link
))
4132 TYPE_CONTEXT (TREE_VALUE (link
)) = type
;
4135 else if (TREE_CODE (declarator
) == INDIRECT_REF
)
4137 /* Merge any constancy or volatility into the target type
4140 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4142 pedwarn ("ISO C forbids qualified function types");
4144 type
= c_build_qualified_type (type
, type_quals
);
4145 type_quals
= TYPE_UNQUALIFIED
;
4148 type
= build_pointer_type (type
);
4150 /* Process a list of type modifier keywords
4151 (such as const or volatile) that were given inside the `*'. */
4153 if (TREE_TYPE (declarator
))
4161 for (typemodlist
= TREE_TYPE (declarator
); typemodlist
;
4162 typemodlist
= TREE_CHAIN (typemodlist
))
4164 tree qualifier
= TREE_VALUE (typemodlist
);
4166 if (C_IS_RESERVED_WORD (qualifier
))
4168 if (C_RID_CODE (qualifier
) == RID_CONST
)
4170 else if (C_RID_CODE (qualifier
) == RID_VOLATILE
)
4172 else if (C_RID_CODE (qualifier
) == RID_RESTRICT
)
4182 error ("invalid type modifier within pointer declarator");
4183 if (pedantic
&& !flag_isoc99
)
4186 pedwarn ("duplicate `const'");
4188 pedwarn ("duplicate `volatile'");
4190 pedwarn ("duplicate `restrict'");
4193 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4194 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4195 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4198 declarator
= TREE_OPERAND (declarator
, 0);
4205 /* Now TYPE has the actual type. */
4207 /* Did array size calculations overflow? */
4209 if (TREE_CODE (type
) == ARRAY_TYPE
4210 && COMPLETE_TYPE_P (type
)
4211 && TREE_OVERFLOW (TYPE_SIZE (type
)))
4213 error ("size of array `%s' is too large", name
);
4214 /* If we proceed with the array type as it is, we'll eventually
4215 crash in tree_low_cst(). */
4216 type
= error_mark_node
;
4219 /* If this is declaring a typedef name, return a TYPE_DECL. */
4221 if (specbits
& (1 << (int) RID_TYPEDEF
))
4224 /* Note that the grammar rejects storage classes
4225 in typenames, fields or parameters */
4226 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4228 pedwarn ("ISO C forbids qualified function types");
4230 type
= c_build_qualified_type (type
, type_quals
);
4231 decl
= build_decl (TYPE_DECL
, declarator
, type
);
4232 if ((specbits
& (1 << (int) RID_SIGNED
))
4233 || (typedef_decl
&& C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
4234 C_TYPEDEF_EXPLICITLY_SIGNED (decl
) = 1;
4235 decl_attributes (&decl
, returned_attrs
, 0);
4239 /* Detect the case of an array type of unspecified size
4240 which came, as such, direct from a typedef name.
4241 We must copy the type, so that each identifier gets
4242 a distinct type, so that each identifier's size can be
4243 controlled separately by its own initializer. */
4245 if (type
!= 0 && typedef_type
!= 0
4246 && TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
) == 0
4247 && TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (typedef_type
))
4249 type
= build_array_type (TREE_TYPE (type
), 0);
4251 C_TYPE_VARIABLE_SIZE (type
) = 1;
4254 /* If this is a type name (such as, in a cast or sizeof),
4255 compute the type and return it now. */
4257 if (decl_context
== TYPENAME
)
4259 /* Note that the grammar rejects storage classes
4260 in typenames, fields or parameters */
4261 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4263 pedwarn ("ISO C forbids const or volatile function types");
4265 type
= c_build_qualified_type (type
, type_quals
);
4266 decl_attributes (&type
, returned_attrs
, 0);
4270 /* Aside from typedefs and type names (handle above),
4271 `void' at top level (not within pointer)
4272 is allowed only in public variables.
4273 We don't complain about parms either, but that is because
4274 a better error message can be made later. */
4276 if (VOID_TYPE_P (type
) && decl_context
!= PARM
4277 && ! ((decl_context
!= FIELD
&& TREE_CODE (type
) != FUNCTION_TYPE
)
4278 && ((specbits
& (1 << (int) RID_EXTERN
))
4279 || (current_scope
== file_scope
4281 & ((1 << (int) RID_STATIC
) | (1 << (int) RID_REGISTER
)))))))
4283 error ("variable or field `%s' declared void", name
);
4284 type
= integer_type_node
;
4287 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4288 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4293 if (decl_context
== PARM
)
4295 tree type_as_written
;
4298 /* A parameter declared as an array of T is really a pointer to T.
4299 One declared as a function is really a pointer to a function. */
4301 if (TREE_CODE (type
) == ARRAY_TYPE
)
4303 /* Transfer const-ness of array into that of type pointed to. */
4304 type
= TREE_TYPE (type
);
4306 type
= c_build_qualified_type (type
, type_quals
);
4307 type
= build_pointer_type (type
);
4308 type_quals
= TYPE_UNQUALIFIED
;
4309 if (array_ptr_quals
)
4311 tree new_ptr_quals
, new_ptr_attrs
;
4313 split_specs_attrs (array_ptr_quals
, &new_ptr_quals
, &new_ptr_attrs
);
4314 /* We don't yet implement attributes in this context. */
4315 if (new_ptr_attrs
!= NULL_TREE
)
4316 warning ("attributes in parameter array declarator ignored");
4321 for (; new_ptr_quals
; new_ptr_quals
= TREE_CHAIN (new_ptr_quals
))
4323 tree qualifier
= TREE_VALUE (new_ptr_quals
);
4325 if (C_IS_RESERVED_WORD (qualifier
))
4327 if (C_RID_CODE (qualifier
) == RID_CONST
)
4329 else if (C_RID_CODE (qualifier
) == RID_VOLATILE
)
4331 else if (C_RID_CODE (qualifier
) == RID_RESTRICT
)
4341 error ("invalid type modifier within array declarator");
4343 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4344 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4345 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4349 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
4351 if (pedantic
&& type_quals
)
4352 pedwarn ("ISO C forbids qualified function types");
4354 type
= c_build_qualified_type (type
, type_quals
);
4355 type
= build_pointer_type (type
);
4356 type_quals
= TYPE_UNQUALIFIED
;
4358 else if (type_quals
)
4359 type
= c_build_qualified_type (type
, type_quals
);
4361 type_as_written
= type
;
4363 decl
= build_decl (PARM_DECL
, declarator
, type
);
4365 C_DECL_VARIABLE_SIZE (decl
) = 1;
4367 /* Compute the type actually passed in the parmlist,
4368 for the case where there is no prototype.
4369 (For example, shorts and chars are passed as ints.)
4370 When there is a prototype, this is overridden later. */
4372 if (type
== error_mark_node
)
4373 promoted_type
= type
;
4375 promoted_type
= c_type_promotes_to (type
);
4377 DECL_ARG_TYPE (decl
) = promoted_type
;
4378 DECL_ARG_TYPE_AS_WRITTEN (decl
) = type_as_written
;
4380 else if (decl_context
== FIELD
)
4382 /* Structure field. It may not be a function. */
4384 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4386 error ("field `%s' declared as a function", name
);
4387 type
= build_pointer_type (type
);
4389 else if (TREE_CODE (type
) != ERROR_MARK
4390 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type
))
4392 error ("field `%s' has incomplete type", name
);
4393 type
= error_mark_node
;
4395 /* Move type qualifiers down to element of an array. */
4396 if (TREE_CODE (type
) == ARRAY_TYPE
&& type_quals
)
4397 type
= build_array_type (c_build_qualified_type (TREE_TYPE (type
),
4399 TYPE_DOMAIN (type
));
4400 decl
= build_decl (FIELD_DECL
, declarator
, type
);
4401 DECL_NONADDRESSABLE_P (decl
) = bitfield
;
4404 C_DECL_VARIABLE_SIZE (decl
) = 1;
4406 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
4408 /* Every function declaration is "external"
4409 except for those which are inside a function body
4410 in which `auto' is used.
4411 That is a case not specified by ANSI C,
4412 and we use it for forward declarations for nested functions. */
4413 int extern_ref
= (!(specbits
& (1 << (int) RID_AUTO
))
4414 || current_scope
== file_scope
);
4416 if (specbits
& (1 << (int) RID_AUTO
)
4417 && (pedantic
|| current_scope
== file_scope
))
4418 pedwarn ("invalid storage class for function `%s'", name
);
4419 if (specbits
& (1 << (int) RID_REGISTER
))
4420 error ("invalid storage class for function `%s'", name
);
4421 if (specbits
& (1 << (int) RID_THREAD
))
4422 error ("invalid storage class for function `%s'", name
);
4423 /* Function declaration not at file scope.
4424 Storage classes other than `extern' are not allowed
4425 and `extern' makes no difference. */
4426 if (current_scope
!= file_scope
4427 && (specbits
& ((1 << (int) RID_STATIC
) | (1 << (int) RID_INLINE
)))
4429 pedwarn ("invalid storage class for function `%s'", name
);
4431 decl
= build_decl (FUNCTION_DECL
, declarator
, type
);
4432 decl
= build_decl_attribute_variant (decl
, decl_attr
);
4434 DECL_LANG_SPECIFIC (decl
)
4435 = ggc_alloc_cleared (sizeof (struct lang_decl
));
4437 if (pedantic
&& type_quals
&& ! DECL_IN_SYSTEM_HEADER (decl
))
4438 pedwarn ("ISO C forbids qualified function types");
4440 /* GNU C interprets a `volatile void' return type to indicate
4441 that the function does not return. */
4442 if ((type_quals
& TYPE_QUAL_VOLATILE
)
4443 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
4444 warning ("`noreturn' function returns non-void value");
4447 DECL_EXTERNAL (decl
) = 1;
4448 /* Record absence of global scope for `static' or `auto'. */
4450 = !(specbits
& ((1 << (int) RID_STATIC
) | (1 << (int) RID_AUTO
)));
4452 /* For a function definition, record the argument information
4453 block in DECL_ARGUMENTS where store_parm_decls will look
4456 DECL_ARGUMENTS (decl
) = arg_info
;
4459 C_FUNCTION_IMPLICIT_INT (decl
) = 1;
4461 /* Record presence of `inline', if it is reasonable. */
4462 if (MAIN_NAME_P (declarator
))
4465 warning ("cannot inline function `main'");
4469 /* Record that the function is declared `inline'. */
4470 DECL_DECLARED_INLINE_P (decl
) = 1;
4472 /* Do not mark bare declarations as DECL_INLINE. Doing so
4473 in the presence of multiple declarations can result in
4474 the abstract origin pointing between the declarations,
4475 which will confuse dwarf2out. */
4478 DECL_INLINE (decl
) = 1;
4479 if (specbits
& (1 << (int) RID_EXTERN
))
4480 current_extern_inline
= 1;
4483 /* If -finline-functions, assume it can be inlined. This does
4484 two things: let the function be deferred until it is actually
4485 needed, and let dwarf2 know that the function is inlinable. */
4486 else if (flag_inline_trees
== 2 && initialized
)
4487 DECL_INLINE (decl
) = 1;
4491 /* It's a variable. */
4492 /* An uninitialized decl with `extern' is a reference. */
4493 int extern_ref
= !initialized
&& (specbits
& (1 << (int) RID_EXTERN
));
4495 /* Move type qualifiers down to element of an array. */
4496 if (TREE_CODE (type
) == ARRAY_TYPE
&& type_quals
)
4498 int saved_align
= TYPE_ALIGN(type
);
4499 type
= build_array_type (c_build_qualified_type (TREE_TYPE (type
),
4501 TYPE_DOMAIN (type
));
4502 TYPE_ALIGN (type
) = saved_align
;
4504 else if (type_quals
)
4505 type
= c_build_qualified_type (type
, type_quals
);
4507 /* C99 6.2.2p7: It is invalid (compile-time undefined
4508 behavior) to create an 'extern' declaration for a
4509 variable if there is a global declaration that is
4510 'static' and the global declaration is not visible.
4511 (If the static declaration _is_ currently visible,
4512 the 'extern' declaration is taken to refer to that decl.) */
4513 if (extern_ref
&& current_scope
!= file_scope
)
4515 tree global_decl
= identifier_global_value (declarator
);
4516 tree visible_decl
= lookup_name (declarator
);
4519 && global_decl
!= visible_decl
4520 && TREE_CODE (global_decl
) == VAR_DECL
4521 && !TREE_PUBLIC (global_decl
))
4522 error ("variable previously declared 'static' redeclared "
4526 decl
= build_decl (VAR_DECL
, declarator
, type
);
4528 C_DECL_VARIABLE_SIZE (decl
) = 1;
4531 pedwarn ("%Jvariable '%D' declared `inline'", decl
, decl
);
4533 DECL_EXTERNAL (decl
) = extern_ref
;
4535 /* At file scope, the presence of a `static' or `register' storage
4536 class specifier, or the absence of all storage class specifiers
4537 makes this declaration a definition (perhaps tentative). Also,
4538 the absence of both `static' and `register' makes it public. */
4539 if (current_scope
== file_scope
)
4541 TREE_PUBLIC (decl
) = !(specbits
& ((1 << (int) RID_STATIC
)
4542 | (1 << (int) RID_REGISTER
)));
4543 TREE_STATIC (decl
) = !extern_ref
;
4545 /* Not at file scope, only `static' makes a static definition. */
4548 TREE_STATIC (decl
) = (specbits
& (1 << (int) RID_STATIC
)) != 0;
4549 TREE_PUBLIC (decl
) = extern_ref
;
4552 if (specbits
& 1 << (int) RID_THREAD
)
4554 if (targetm
.have_tls
)
4555 DECL_THREAD_LOCAL (decl
) = 1;
4557 /* A mere warning is sure to result in improper semantics
4558 at runtime. Don't bother to allow this to compile. */
4559 error ("thread-local storage not supported for this target");
4563 /* Record `register' declaration for warnings on &
4564 and in case doing stupid register allocation. */
4566 if (specbits
& (1 << (int) RID_REGISTER
))
4568 C_DECL_REGISTER (decl
) = 1;
4569 DECL_REGISTER (decl
) = 1;
4572 /* Record constancy and volatility. */
4573 c_apply_type_quals_to_decl (type_quals
, decl
);
4575 /* If a type has volatile components, it should be stored in memory.
4576 Otherwise, the fact that those components are volatile
4577 will be ignored, and would even crash the compiler. */
4578 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl
)))
4580 /* It is not an error for a structure with volatile fields to
4581 be declared register, but reset DECL_REGISTER since it
4582 cannot actually go in a register. */
4583 int was_reg
= C_DECL_REGISTER (decl
);
4584 C_DECL_REGISTER (decl
) = 0;
4585 DECL_REGISTER (decl
) = 0;
4586 c_mark_addressable (decl
);
4587 C_DECL_REGISTER (decl
) = was_reg
;
4590 #ifdef ENABLE_CHECKING
4591 /* This is the earliest point at which we might know the assembler
4592 name of a variable. Thus, if it's known before this, die horribly. */
4593 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
4597 decl_attributes (&decl
, returned_attrs
, 0);
4603 /* Decode the parameter-list info for a function type or function definition.
4604 The argument is the value returned by `get_parm_info' (or made in parse.y
4605 if there is an identifier list instead of a parameter decl list).
4606 These two functions are separate because when a function returns
4607 or receives functions then each is called multiple times but the order
4608 of calls is different. The last call to `grokparms' is always the one
4609 that contains the formal parameter names of a function definition.
4611 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4613 FUNCDEF_FLAG is nonzero for a function definition, 0 for
4614 a mere declaration. A nonempty identifier-list gets an error message
4615 when FUNCDEF_FLAG is zero. */
4618 grokparms (tree arg_info
, int funcdef_flag
)
4620 tree arg_types
= ARG_INFO_TYPES (arg_info
);
4622 if (warn_strict_prototypes
&& arg_types
== 0 && !funcdef_flag
4623 && !in_system_header
)
4624 warning ("function declaration isn't a prototype");
4626 if (arg_types
== error_mark_node
)
4627 return 0; /* don't set TYPE_ARG_TYPES in this case */
4629 else if (arg_types
&& TREE_CODE (TREE_VALUE (arg_types
)) == IDENTIFIER_NODE
)
4632 pedwarn ("parameter names (without types) in function declaration");
4634 ARG_INFO_PARMS (arg_info
) = ARG_INFO_TYPES (arg_info
);
4635 ARG_INFO_TYPES (arg_info
) = 0;
4640 tree parm
, type
, typelt
;
4641 unsigned int parmno
;
4643 /* If the arg types are incomplete in a declaration, they must
4644 include undefined tags. These tags can never be defined in
4645 the scope of the declaration, so the types can never be
4646 completed, and no call can be compiled successfully. */
4648 for (parm
= ARG_INFO_PARMS (arg_info
), typelt
= arg_types
, parmno
= 1;
4650 parm
= TREE_CHAIN (parm
), typelt
= TREE_CHAIN (typelt
), parmno
++)
4652 type
= TREE_VALUE (typelt
);
4653 if (type
== error_mark_node
)
4656 if (!COMPLETE_TYPE_P (type
))
4660 if (DECL_NAME (parm
))
4661 error ("%Jparameter %u ('%D') has incomplete type",
4662 parm
, parmno
, parm
);
4664 error ("%Jparameter %u has incomplete type",
4667 TREE_VALUE (typelt
) = error_mark_node
;
4668 TREE_TYPE (parm
) = error_mark_node
;
4672 if (DECL_NAME (parm
))
4673 warning ("%Jparameter %u ('%D') has incomplete type",
4674 parm
, parmno
, parm
);
4676 warning ("%Jparameter %u has incomplete type",
4685 /* Take apart the current scope and return a tree_list node with info
4686 on a parameter list just parsed. This tree_list node should be
4687 examined using the ARG_INFO_* macros, defined above:
4689 ARG_INFO_PARMS: a list of parameter decls.
4690 ARG_INFO_TAGS: a list of structure, union and enum tags defined.
4691 ARG_INFO_TYPES: a list of argument types to go in the FUNCTION_TYPE.
4692 ARG_INFO_OTHERS: a list of non-parameter decls (notably enumeration
4693 constants) defined with the parameters.
4695 This tree_list node is later fed to 'grokparms' and 'store_parm_decls'.
4697 ELLIPSIS being true means the argument list ended in '...' so don't
4698 append a sentinel (void_list_node) to the end of the type-list. */
4701 get_parm_info (bool ellipsis
)
4703 struct c_binding
*b
= current_scope
->bindings
;
4704 tree arg_info
= make_node (TREE_LIST
);
4710 static bool explained_incomplete_types
= false;
4711 bool gave_void_only_once_err
= false;
4713 /* The bindings in this scope must not get put into a block.
4714 We will take care of deleting the binding nodes. */
4715 current_scope
->bindings
= 0;
4717 /* This function is only called if there was *something* on the
4719 #ifdef ENABLE_CHECKING
4724 /* A parameter list consisting solely of 'void' indicates that the
4725 function takes no arguments. But if the 'void' is qualified
4726 (by 'const' or 'volatile'), or has a storage class specifier
4727 ('register'), then the behavior is undefined; issue an error.
4728 Typedefs for 'void' are OK (see DR#157). */
4729 if (b
->prev
== 0 /* one binding */
4730 && TREE_CODE (b
->decl
) == PARM_DECL
/* which is a parameter */
4731 && !DECL_NAME (b
->decl
) /* anonymous */
4732 && VOID_TYPE_P (TREE_TYPE (b
->decl
))) /* of void type */
4734 if (TREE_THIS_VOLATILE (b
->decl
)
4735 || TREE_READONLY (b
->decl
)
4736 || C_DECL_REGISTER (b
->decl
))
4737 error ("'void' as only parameter may not be qualified");
4739 /* There cannot be an ellipsis. */
4741 error ("'void' must be the only parameter");
4743 ARG_INFO_TYPES (arg_info
) = void_list_node
;
4748 types
= void_list_node
;
4750 /* Break up the bindings list into parms, tags, types, and others;
4751 apply sanity checks; purge the name-to-decl bindings. */
4754 tree decl
= b
->decl
;
4755 tree type
= TREE_TYPE (decl
);
4756 const char *keyword
;
4758 switch (TREE_CODE (decl
))
4763 #ifdef ENABLE_CHECKING
4764 if (I_SYMBOL_BINDING (b
->id
) != b
) abort ();
4766 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
4769 /* Check for forward decls that never got their actual decl. */
4770 if (TREE_ASM_WRITTEN (decl
))
4771 error ("%Jparameter '%D' has just a forward declaration",
4773 /* Check for (..., void, ...) and issue an error. */
4774 else if (VOID_TYPE_P (type
) && !DECL_NAME (decl
))
4776 if (!gave_void_only_once_err
)
4778 error ("'void' must be the only parameter");
4779 gave_void_only_once_err
= true;
4784 /* Valid parameter, add it to the list. */
4785 TREE_CHAIN (decl
) = parms
;
4788 /* Since there is a prototype, args are passed in their
4789 declared types. The back end may override this later. */
4790 DECL_ARG_TYPE (decl
) = type
;
4791 types
= tree_cons (0, type
, types
);
4795 case ENUMERAL_TYPE
: keyword
= "struct"; goto tag
;
4796 case UNION_TYPE
: keyword
= "union"; goto tag
;
4797 case RECORD_TYPE
: keyword
= "enum"; goto tag
;
4799 /* Types may not have tag-names, in which case the type
4800 appears in the bindings list with b->id NULL. */
4803 #ifdef ENABLE_CHECKING
4804 if (I_TAG_BINDING (b
->id
) != b
) abort ();
4806 I_TAG_BINDING (b
->id
) = b
->shadowed
;
4809 /* Warn about any struct, union or enum tags defined in a
4810 parameter list. The scope of such types is limited to
4811 the parameter list, which is rarely if ever desirable
4812 (it's impossible to call such a function with type-
4813 correct arguments). An anonymous union parm type is
4814 meaningful as a GNU extension, so don't warn for that. */
4815 if (TREE_CODE (decl
) != UNION_TYPE
|| b
->id
!= 0)
4818 /* The %s will be one of 'struct', 'union', or 'enum'. */
4819 warning ("'%s %E' declared inside parameter list",
4822 /* The %s will be one of 'struct', 'union', or 'enum'. */
4823 warning ("anonymous %s declared inside parameter list",
4826 if (! explained_incomplete_types
)
4828 warning ("its scope is only this definition or declaration,"
4829 " which is probably not what you want");
4830 explained_incomplete_types
= true;
4834 tags
= tree_cons (b
->id
, decl
, tags
);
4839 /* CONST_DECLs appear here when we have an embedded enum,
4840 and TYPE_DECLs appear here when we have an embedded struct
4841 or union. No warnings for this - we already warned about the
4843 TREE_CHAIN (decl
) = others
;
4848 /* error_mark_node appears here when we have an undeclared
4849 variable. Just throw it away. */
4852 #ifdef ENABLE_CHECKING
4853 if (I_SYMBOL_BINDING (b
->id
) != b
) abort ();
4855 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
4859 /* Other things that might be encountered. */
4867 b
= free_binding_and_advance (b
);
4870 ARG_INFO_PARMS (arg_info
) = parms
;
4871 ARG_INFO_TAGS (arg_info
) = tags
;
4872 ARG_INFO_TYPES (arg_info
) = types
;
4873 ARG_INFO_OTHERS (arg_info
) = others
;
4877 /* Get the struct, enum or union (CODE says which) with tag NAME.
4878 Define the tag as a forward-reference if it is not defined. */
4881 xref_tag (enum tree_code code
, tree name
)
4883 /* If a cross reference is requested, look up the type
4884 already defined for this tag and return it. */
4886 tree ref
= lookup_tag (code
, name
, 0);
4887 /* If this is the right type of tag, return what we found.
4888 (This reference will be shadowed by shadow_tag later if appropriate.)
4889 If this is the wrong type of tag, do not return it. If it was the
4890 wrong type in the same scope, we will have had an error
4891 message already; if in a different scope and declaring
4892 a name, pending_xref_error will give an error message; but if in a
4893 different scope and not declaring a name, this tag should
4894 shadow the previous declaration of a different type of tag, and
4895 this would not work properly if we return the reference found.
4896 (For example, with "struct foo" in an outer scope, "union foo;"
4897 must shadow that tag with a new one of union type.) */
4898 if (ref
&& TREE_CODE (ref
) == code
)
4901 /* If no such tag is yet defined, create a forward-reference node
4902 and record it as the "definition".
4903 When a real declaration of this type is found,
4904 the forward-reference will be altered into a real type. */
4906 ref
= make_node (code
);
4907 if (code
== ENUMERAL_TYPE
)
4909 /* Give the type a default layout like unsigned int
4910 to avoid crashing if it does not get defined. */
4911 TYPE_MODE (ref
) = TYPE_MODE (unsigned_type_node
);
4912 TYPE_ALIGN (ref
) = TYPE_ALIGN (unsigned_type_node
);
4913 TYPE_USER_ALIGN (ref
) = 0;
4914 TYPE_UNSIGNED (ref
) = 1;
4915 TYPE_PRECISION (ref
) = TYPE_PRECISION (unsigned_type_node
);
4916 TYPE_MIN_VALUE (ref
) = TYPE_MIN_VALUE (unsigned_type_node
);
4917 TYPE_MAX_VALUE (ref
) = TYPE_MAX_VALUE (unsigned_type_node
);
4920 pushtag (name
, ref
);
4925 /* Make sure that the tag NAME is defined *in the current scope*
4926 at least as a forward reference.
4927 CODE says which kind of tag NAME ought to be. */
4930 start_struct (enum tree_code code
, tree name
)
4932 /* If there is already a tag defined at this scope
4933 (as a forward reference), just return it. */
4938 ref
= lookup_tag (code
, name
, 1);
4939 if (ref
&& TREE_CODE (ref
) == code
)
4941 if (TYPE_FIELDS (ref
))
4943 if (code
== UNION_TYPE
)
4944 error ("redefinition of `union %s'", IDENTIFIER_POINTER (name
));
4946 error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name
));
4951 /* Otherwise create a forward-reference just so the tag is in scope. */
4953 ref
= make_node (code
);
4954 pushtag (name
, ref
);
4957 C_TYPE_BEING_DEFINED (ref
) = 1;
4958 TYPE_PACKED (ref
) = flag_pack_struct
;
4962 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
4963 of a structure component, returning a FIELD_DECL node.
4964 WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
4966 This is done during the parsing of the struct declaration.
4967 The FIELD_DECL nodes are chained together and the lot of them
4968 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
4971 grokfield (tree declarator
, tree declspecs
, tree width
)
4975 if (declarator
== NULL_TREE
&& width
== NULL_TREE
)
4977 /* This is an unnamed decl.
4979 If we have something of the form "union { list } ;" then this
4980 is the anonymous union extension. Similarly for struct.
4982 If this is something of the form "struct foo;", then
4983 If MS extensions are enabled, this is handled as an
4985 Otherwise this is a forward declaration of a structure tag.
4987 If this is something of the form "foo;" and foo is a TYPE_DECL, then
4988 If MS extensions are enabled and foo names a structure, then
4989 again this is an anonymous struct.
4990 Otherwise this is an error.
4992 Oh what a horrid tangled web we weave. I wonder if MS consciously
4993 took this from Plan 9 or if it was an accident of implementation
4994 that took root before someone noticed the bug... */
4996 tree type
= TREE_VALUE (declspecs
);
4998 if (flag_ms_extensions
&& TREE_CODE (type
) == TYPE_DECL
)
4999 type
= TREE_TYPE (type
);
5000 if (TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
)
5002 if (flag_ms_extensions
)
5005 goto warn_unnamed_field
;
5006 else if (TYPE_NAME (type
) == NULL
)
5009 goto warn_unnamed_field
;
5014 warning ("declaration does not declare anything");
5019 value
= grokdeclarator (declarator
, declspecs
, FIELD
, 0,
5020 width
? &width
: NULL
);
5022 finish_decl (value
, NULL_TREE
, NULL_TREE
);
5023 DECL_INITIAL (value
) = width
;
5028 /* Generate an error for any duplicate field names in FIELDLIST. Munge
5029 the list such that this does not present a problem later. */
5032 detect_field_duplicates (tree fieldlist
)
5037 /* First, see if there are more than "a few" fields.
5038 This is trivially true if there are zero or one fields. */
5041 x
= TREE_CHAIN (fieldlist
);
5047 } while (timeout
> 0 && x
);
5049 /* If there were "few" fields, avoid the overhead of allocating
5050 a hash table. Instead just do the nested traversal thing. */
5053 for (x
= TREE_CHAIN (fieldlist
); x
; x
= TREE_CHAIN (x
))
5056 for (y
= fieldlist
; y
!= x
; y
= TREE_CHAIN (y
))
5057 if (DECL_NAME (y
) == DECL_NAME (x
))
5059 error ("%Jduplicate member '%D'", x
, x
);
5060 DECL_NAME (x
) = NULL_TREE
;
5066 htab_t htab
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
5069 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5070 if ((y
= DECL_NAME (x
)) != 0)
5072 slot
= htab_find_slot (htab
, y
, INSERT
);
5075 error ("%Jduplicate member '%D'", x
, x
);
5076 DECL_NAME (x
) = NULL_TREE
;
5085 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5086 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5087 ATTRIBUTES are attributes to be applied to the structure. */
5090 finish_struct (tree t
, tree fieldlist
, tree attributes
)
5093 bool toplevel
= file_scope
== current_scope
;
5094 int saw_named_field
;
5096 /* If this type was previously laid out as a forward reference,
5097 make sure we lay it out again. */
5101 decl_attributes (&t
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
5105 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5106 if (DECL_NAME (x
) != 0)
5110 pedwarn ("%s has no %s",
5111 TREE_CODE (t
) == UNION_TYPE
? _("union") : _("struct"),
5112 fieldlist
? _("named members") : _("members"));
5115 /* Install struct as DECL_CONTEXT of each field decl.
5116 Also process specified field sizes,m which is found in the DECL_INITIAL.
5117 Store 0 there, except for ": 0" fields (so we can find them
5118 and delete them, below). */
5120 saw_named_field
= 0;
5121 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5123 DECL_CONTEXT (x
) = t
;
5124 DECL_PACKED (x
) |= TYPE_PACKED (t
);
5126 /* If any field is const, the structure type is pseudo-const. */
5127 if (TREE_READONLY (x
))
5128 C_TYPE_FIELDS_READONLY (t
) = 1;
5131 /* A field that is pseudo-const makes the structure likewise. */
5132 tree t1
= TREE_TYPE (x
);
5133 while (TREE_CODE (t1
) == ARRAY_TYPE
)
5134 t1
= TREE_TYPE (t1
);
5135 if ((TREE_CODE (t1
) == RECORD_TYPE
|| TREE_CODE (t1
) == UNION_TYPE
)
5136 && C_TYPE_FIELDS_READONLY (t1
))
5137 C_TYPE_FIELDS_READONLY (t
) = 1;
5140 /* Any field that is volatile means variables of this type must be
5141 treated in some ways as volatile. */
5142 if (TREE_THIS_VOLATILE (x
))
5143 C_TYPE_FIELDS_VOLATILE (t
) = 1;
5145 /* Any field of nominal variable size implies structure is too. */
5146 if (C_DECL_VARIABLE_SIZE (x
))
5147 C_TYPE_VARIABLE_SIZE (t
) = 1;
5149 /* Detect invalid nested redefinition. */
5150 if (TREE_TYPE (x
) == t
)
5151 error ("nested redefinition of `%s'",
5152 IDENTIFIER_POINTER (TYPE_NAME (t
)));
5154 if (DECL_INITIAL (x
))
5156 unsigned HOST_WIDE_INT width
= tree_low_cst (DECL_INITIAL (x
), 1);
5157 DECL_SIZE (x
) = bitsize_int (width
);
5158 DECL_BIT_FIELD (x
) = 1;
5159 SET_DECL_C_BIT_FIELD (x
);
5162 DECL_INITIAL (x
) = 0;
5164 /* Detect flexible array member in an invalid context. */
5165 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
5166 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
5167 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
5168 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
5170 if (TREE_CODE (t
) == UNION_TYPE
)
5172 error ("%Jflexible array member in union", x
);
5173 TREE_TYPE (x
) = error_mark_node
;
5175 else if (TREE_CHAIN (x
) != NULL_TREE
)
5177 error ("%Jflexible array member not at end of struct", x
);
5178 TREE_TYPE (x
) = error_mark_node
;
5180 else if (! saw_named_field
)
5182 error ("%Jflexible array member in otherwise empty struct", x
);
5183 TREE_TYPE (x
) = error_mark_node
;
5187 if (pedantic
&& TREE_CODE (t
) == RECORD_TYPE
5188 && flexible_array_type_p (TREE_TYPE (x
)))
5189 pedwarn ("%Jinvalid use of structure with flexible array member", x
);
5192 saw_named_field
= 1;
5195 detect_field_duplicates (fieldlist
);
5197 /* Now we have the nearly final fieldlist. Record it,
5198 then lay out the structure or union (including the fields). */
5200 TYPE_FIELDS (t
) = fieldlist
;
5204 /* Delete all zero-width bit-fields from the fieldlist. */
5206 tree
*fieldlistp
= &fieldlist
;
5208 if (TREE_CODE (*fieldlistp
) == FIELD_DECL
&& DECL_INITIAL (*fieldlistp
))
5209 *fieldlistp
= TREE_CHAIN (*fieldlistp
);
5211 fieldlistp
= &TREE_CHAIN (*fieldlistp
);
5214 /* Now we have the truly final field list.
5215 Store it in this type and in the variants. */
5217 TYPE_FIELDS (t
) = fieldlist
;
5219 /* If there are lots of fields, sort so we can look through them fast.
5220 We arbitrarily consider 16 or more elts to be "a lot". */
5225 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5227 if (len
> 15 || DECL_NAME (x
) == NULL
)
5235 struct lang_type
*space
;
5236 struct sorted_fields_type
*space2
;
5238 len
+= list_length (x
);
5240 /* Use the same allocation policy here that make_node uses, to
5241 ensure that this lives as long as the rest of the struct decl.
5242 All decls in an inline function need to be saved. */
5244 space
= ggc_alloc (sizeof (struct lang_type
));
5245 space2
= ggc_alloc (sizeof (struct sorted_fields_type
) + len
* sizeof (tree
));
5249 field_array
= &space2
->elts
[0];
5250 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5252 field_array
[len
++] = x
;
5254 /* If there is anonymous struct or union, break out of the loop. */
5255 if (DECL_NAME (x
) == NULL
)
5258 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
5261 TYPE_LANG_SPECIFIC (t
) = space
;
5262 TYPE_LANG_SPECIFIC (t
)->s
->len
= len
;
5263 field_array
= TYPE_LANG_SPECIFIC (t
)->s
->elts
;
5264 qsort (field_array
, len
, sizeof (tree
), field_decl_cmp
);
5269 for (x
= TYPE_MAIN_VARIANT (t
); x
; x
= TYPE_NEXT_VARIANT (x
))
5271 TYPE_FIELDS (x
) = TYPE_FIELDS (t
);
5272 TYPE_LANG_SPECIFIC (x
) = TYPE_LANG_SPECIFIC (t
);
5273 TYPE_ALIGN (x
) = TYPE_ALIGN (t
);
5274 TYPE_USER_ALIGN (x
) = TYPE_USER_ALIGN (t
);
5277 /* If this was supposed to be a transparent union, but we can't
5278 make it one, warn and turn off the flag. */
5279 if (TREE_CODE (t
) == UNION_TYPE
5280 && TYPE_TRANSPARENT_UNION (t
)
5281 && TYPE_MODE (t
) != DECL_MODE (TYPE_FIELDS (t
)))
5283 TYPE_TRANSPARENT_UNION (t
) = 0;
5284 warning ("union cannot be made transparent");
5287 /* If this structure or union completes the type of any previous
5288 variable declaration, lay it out and output its rtl. */
5289 for (x
= C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
));
5293 tree decl
= TREE_VALUE (x
);
5294 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
5295 layout_array_type (TREE_TYPE (decl
));
5296 if (TREE_CODE (decl
) != TYPE_DECL
)
5298 layout_decl (decl
, 0);
5299 if (c_dialect_objc ())
5300 objc_check_decl (decl
);
5301 rest_of_decl_compilation (decl
, NULL
, toplevel
, 0);
5306 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
)) = 0;
5308 /* Finish debugging output for this type. */
5309 rest_of_type_compilation (t
, toplevel
);
5314 /* Lay out the type T, and its element type, and so on. */
5317 layout_array_type (tree t
)
5319 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5320 layout_array_type (TREE_TYPE (t
));
5324 /* Begin compiling the definition of an enumeration type.
5325 NAME is its name (or null if anonymous).
5326 Returns the type object, as yet incomplete.
5327 Also records info about it so that build_enumerator
5328 may be used to declare the individual values as they are read. */
5331 start_enum (tree name
)
5335 /* If this is the real definition for a previous forward reference,
5336 fill in the contents in the same object that used to be the
5337 forward reference. */
5340 enumtype
= lookup_tag (ENUMERAL_TYPE
, name
, 1);
5342 if (enumtype
== 0 || TREE_CODE (enumtype
) != ENUMERAL_TYPE
)
5344 enumtype
= make_node (ENUMERAL_TYPE
);
5345 pushtag (name
, enumtype
);
5348 C_TYPE_BEING_DEFINED (enumtype
) = 1;
5350 if (TYPE_VALUES (enumtype
) != 0)
5352 /* This enum is a named one that has been declared already. */
5353 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name
));
5355 /* Completely replace its old definition.
5356 The old enumerators remain defined, however. */
5357 TYPE_VALUES (enumtype
) = 0;
5360 enum_next_value
= integer_zero_node
;
5363 if (flag_short_enums
)
5364 TYPE_PACKED (enumtype
) = 1;
5369 /* After processing and defining all the values of an enumeration type,
5370 install their decls in the enumeration type and finish it off.
5371 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5372 and ATTRIBUTES are the specified attributes.
5373 Returns ENUMTYPE. */
5376 finish_enum (tree enumtype
, tree values
, tree attributes
)
5379 tree minnode
= 0, maxnode
= 0, enum_value_type
;
5380 int precision
, unsign
;
5381 bool toplevel
= (file_scope
== current_scope
);
5383 decl_attributes (&enumtype
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
5385 /* Calculate the maximum value of any enumerator in this type. */
5387 if (values
== error_mark_node
)
5388 minnode
= maxnode
= integer_zero_node
;
5391 minnode
= maxnode
= TREE_VALUE (values
);
5392 for (pair
= TREE_CHAIN (values
); pair
; pair
= TREE_CHAIN (pair
))
5394 tree value
= TREE_VALUE (pair
);
5395 if (tree_int_cst_lt (maxnode
, value
))
5397 if (tree_int_cst_lt (value
, minnode
))
5402 /* Construct the final type of this enumeration. It is the same
5403 as one of the integral types - the narrowest one that fits, except
5404 that normally we only go as narrow as int - and signed iff any of
5405 the values are negative. */
5406 unsign
= (tree_int_cst_sgn (minnode
) >= 0);
5407 precision
= MAX (min_precision (minnode
, unsign
),
5408 min_precision (maxnode
, unsign
));
5409 if (TYPE_PACKED (enumtype
) || precision
> TYPE_PRECISION (integer_type_node
))
5411 tree narrowest
= c_common_type_for_size (precision
, unsign
);
5414 warning ("enumeration values exceed range of largest integer");
5415 narrowest
= long_long_integer_type_node
;
5418 precision
= TYPE_PRECISION (narrowest
);
5421 precision
= TYPE_PRECISION (integer_type_node
);
5423 if (precision
== TYPE_PRECISION (integer_type_node
))
5424 enum_value_type
= c_common_type_for_size (precision
, 0);
5426 enum_value_type
= enumtype
;
5428 TYPE_MIN_VALUE (enumtype
) = minnode
;
5429 TYPE_MAX_VALUE (enumtype
) = maxnode
;
5430 TYPE_PRECISION (enumtype
) = precision
;
5431 TYPE_UNSIGNED (enumtype
) = unsign
;
5432 TYPE_SIZE (enumtype
) = 0;
5433 layout_type (enumtype
);
5435 if (values
!= error_mark_node
)
5437 /* Change the type of the enumerators to be the enum type. We
5438 need to do this irrespective of the size of the enum, for
5439 proper type checking. Replace the DECL_INITIALs of the
5440 enumerators, and the value slots of the list, with copies
5441 that have the enum type; they cannot be modified in place
5442 because they may be shared (e.g. integer_zero_node) Finally,
5443 change the purpose slots to point to the names of the decls. */
5444 for (pair
= values
; pair
; pair
= TREE_CHAIN (pair
))
5446 tree enu
= TREE_PURPOSE (pair
);
5448 TREE_TYPE (enu
) = enumtype
;
5450 /* The ISO C Standard mandates enumerators to have type int,
5451 even though the underlying type of an enum type is
5452 unspecified. Here we convert any enumerators that fit in
5453 an int to type int, to avoid promotions to unsigned types
5454 when comparing integers with enumerators that fit in the
5455 int range. When -pedantic is given, build_enumerator()
5456 would have already taken care of those that don't fit. */
5457 if (int_fits_type_p (DECL_INITIAL (enu
), enum_value_type
))
5458 DECL_INITIAL (enu
) = convert (enum_value_type
, DECL_INITIAL (enu
));
5460 DECL_INITIAL (enu
) = convert (enumtype
, DECL_INITIAL (enu
));
5462 TREE_PURPOSE (pair
) = DECL_NAME (enu
);
5463 TREE_VALUE (pair
) = DECL_INITIAL (enu
);
5466 TYPE_VALUES (enumtype
) = values
;
5469 /* Fix up all variant types of this enum type. */
5470 for (tem
= TYPE_MAIN_VARIANT (enumtype
); tem
; tem
= TYPE_NEXT_VARIANT (tem
))
5472 if (tem
== enumtype
)
5474 TYPE_VALUES (tem
) = TYPE_VALUES (enumtype
);
5475 TYPE_MIN_VALUE (tem
) = TYPE_MIN_VALUE (enumtype
);
5476 TYPE_MAX_VALUE (tem
) = TYPE_MAX_VALUE (enumtype
);
5477 TYPE_SIZE (tem
) = TYPE_SIZE (enumtype
);
5478 TYPE_SIZE_UNIT (tem
) = TYPE_SIZE_UNIT (enumtype
);
5479 TYPE_MODE (tem
) = TYPE_MODE (enumtype
);
5480 TYPE_PRECISION (tem
) = TYPE_PRECISION (enumtype
);
5481 TYPE_ALIGN (tem
) = TYPE_ALIGN (enumtype
);
5482 TYPE_USER_ALIGN (tem
) = TYPE_USER_ALIGN (enumtype
);
5483 TYPE_UNSIGNED (tem
) = TYPE_UNSIGNED (enumtype
);
5486 /* Finish debugging output for this type. */
5487 rest_of_type_compilation (enumtype
, toplevel
);
5492 /* Build and install a CONST_DECL for one value of the
5493 current enumeration type (one that was begun with start_enum).
5494 Return a tree-list containing the CONST_DECL and its value.
5495 Assignment of sequential values by default is handled here. */
5498 build_enumerator (tree name
, tree value
)
5502 /* Validate and default VALUE. */
5504 /* Remove no-op casts from the value. */
5506 STRIP_TYPE_NOPS (value
);
5510 /* Don't issue more errors for error_mark_node (i.e. an
5511 undeclared identifier) - just ignore the value expression. */
5512 if (value
== error_mark_node
)
5514 else if (TREE_CODE (value
) != INTEGER_CST
)
5516 error ("enumerator value for '%E' is not an integer constant", name
);
5521 value
= default_conversion (value
);
5522 constant_expression_warning (value
);
5526 /* Default based on previous value. */
5527 /* It should no longer be possible to have NON_LVALUE_EXPR
5531 value
= enum_next_value
;
5533 error ("overflow in enumeration values");
5536 if (pedantic
&& ! int_fits_type_p (value
, integer_type_node
))
5538 pedwarn ("ISO C restricts enumerator values to range of `int'");
5539 /* XXX This causes -pedantic to change the meaning of the program.
5540 Remove? -zw 2004-03-15 */
5541 value
= convert (integer_type_node
, value
);
5544 /* Set basis for default for next value. */
5545 enum_next_value
= build_binary_op (PLUS_EXPR
, value
, integer_one_node
, 0);
5546 enum_overflow
= tree_int_cst_lt (enum_next_value
, value
);
5548 /* Now create a declaration for the enum value name. */
5550 type
= TREE_TYPE (value
);
5551 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
5552 TYPE_PRECISION (integer_type_node
)),
5553 (TYPE_PRECISION (type
)
5554 >= TYPE_PRECISION (integer_type_node
)
5555 && TYPE_UNSIGNED (type
)));
5557 decl
= build_decl (CONST_DECL
, name
, type
);
5558 DECL_INITIAL (decl
) = convert (type
, value
);
5561 return tree_cons (decl
, value
, NULL_TREE
);
5565 /* Create the FUNCTION_DECL for a function definition.
5566 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
5567 the declaration; they describe the function's name and the type it returns,
5568 but twisted together in a fashion that parallels the syntax of C.
5570 This function creates a binding context for the function body
5571 as well as setting up the FUNCTION_DECL in current_function_decl.
5573 Returns 1 on success. If the DECLARATOR is not suitable for a function
5574 (it defines a datum instead), we return 0, which tells
5575 yyparse to report a parse error. */
5578 start_function (tree declspecs
, tree declarator
, tree attributes
)
5580 tree decl1
, old_decl
;
5582 int old_immediate_size_expand
= immediate_size_expand
;
5584 current_function_returns_value
= 0; /* Assume, until we see it does. */
5585 current_function_returns_null
= 0;
5586 current_function_returns_abnormally
= 0;
5587 warn_about_return_type
= 0;
5588 current_extern_inline
= 0;
5589 c_in_iteration_stmt
= 0;
5592 /* Don't expand any sizes in the return type of the function. */
5593 immediate_size_expand
= 0;
5595 decl1
= grokdeclarator (declarator
, declspecs
, FUNCDEF
, 1, NULL
);
5597 /* If the declarator is not suitable for a function definition,
5598 cause a syntax error. */
5601 immediate_size_expand
= old_immediate_size_expand
;
5605 decl_attributes (&decl1
, attributes
, 0);
5607 if (DECL_DECLARED_INLINE_P (decl1
)
5608 && DECL_UNINLINABLE (decl1
)
5609 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1
)))
5610 warning ("%Jinline function '%D' given attribute noinline", decl1
, decl1
);
5612 announce_function (decl1
);
5614 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1
))))
5616 error ("return type is an incomplete type");
5617 /* Make it return void instead. */
5619 = build_function_type (void_type_node
,
5620 TYPE_ARG_TYPES (TREE_TYPE (decl1
)));
5623 if (warn_about_return_type
)
5624 pedwarn_c99 ("return type defaults to `int'");
5626 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5627 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
5628 DECL_INITIAL (decl1
) = error_mark_node
;
5630 /* If this definition isn't a prototype and we had a prototype declaration
5631 before, copy the arg type info from that prototype.
5632 But not if what we had before was a builtin function. */
5633 old_decl
= lookup_name_in_scope (DECL_NAME (decl1
), current_scope
);
5634 if (old_decl
!= 0 && TREE_CODE (TREE_TYPE (old_decl
)) == FUNCTION_TYPE
5635 && !DECL_BUILT_IN (old_decl
)
5636 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
5637 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl
))))
5638 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0)
5640 TREE_TYPE (decl1
) = TREE_TYPE (old_decl
);
5641 current_function_prototype_locus
= DECL_SOURCE_LOCATION (old_decl
);
5644 /* Optionally warn of old-fashioned def with no previous prototype. */
5645 if (warn_strict_prototypes
5646 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0
5647 && C_DECL_ISNT_PROTOTYPE (old_decl
))
5648 warning ("function declaration isn't a prototype");
5649 /* Optionally warn of any global def with no previous prototype. */
5650 else if (warn_missing_prototypes
5651 && TREE_PUBLIC (decl1
)
5652 && ! MAIN_NAME_P (DECL_NAME (decl1
))
5653 && C_DECL_ISNT_PROTOTYPE (old_decl
))
5654 warning ("%Jno previous prototype for '%D'", decl1
, decl1
);
5655 /* Optionally warn of any def with no previous prototype
5656 if the function has already been used. */
5657 else if (warn_missing_prototypes
5658 && old_decl
!= 0 && TREE_USED (old_decl
)
5659 && TYPE_ARG_TYPES (TREE_TYPE (old_decl
)) == 0)
5660 warning ("%J'%D' was used with no prototype before its definition",
5662 /* Optionally warn of any global def with no previous declaration. */
5663 else if (warn_missing_declarations
5664 && TREE_PUBLIC (decl1
)
5666 && ! MAIN_NAME_P (DECL_NAME (decl1
)))
5667 warning ("%Jno previous declaration for '%D'", decl1
, decl1
);
5668 /* Optionally warn of any def with no previous declaration
5669 if the function has already been used. */
5670 else if (warn_missing_declarations
5671 && old_decl
!= 0 && TREE_USED (old_decl
)
5672 && C_DECL_IMPLICIT (old_decl
))
5673 warning ("%J`%D' was used with no declaration before its definition",
5676 /* This is a definition, not a reference.
5677 So normally clear DECL_EXTERNAL.
5678 However, `extern inline' acts like a declaration
5679 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5680 DECL_EXTERNAL (decl1
) = current_extern_inline
;
5682 /* This function exists in static storage.
5683 (This does not mean `static' in the C sense!) */
5684 TREE_STATIC (decl1
) = 1;
5686 /* A nested function is not global. */
5687 if (current_function_decl
!= 0)
5688 TREE_PUBLIC (decl1
) = 0;
5690 #ifdef ENABLE_CHECKING
5691 /* This is the earliest point at which we might know the assembler
5692 name of the function. Thus, if it's set before this, die horribly. */
5693 if (DECL_ASSEMBLER_NAME_SET_P (decl1
))
5697 /* If #pragma weak was used, mark the decl weak now. */
5698 if (current_scope
== file_scope
)
5699 maybe_apply_pragma_weak (decl1
);
5701 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5702 if (warn_main
> 0 && MAIN_NAME_P (DECL_NAME (decl1
)))
5707 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
5708 != integer_type_node
)
5709 pedwarn ("%Jreturn type of '%D' is not `int'", decl1
, decl1
);
5711 for (args
= TYPE_ARG_TYPES (TREE_TYPE (decl1
)); args
;
5712 args
= TREE_CHAIN (args
))
5714 tree type
= args
? TREE_VALUE (args
) : 0;
5716 if (type
== void_type_node
)
5723 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
5724 pedwarn ("%Jfirst argument of '%D' should be `int'",
5729 if (TREE_CODE (type
) != POINTER_TYPE
5730 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
5731 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
5733 pedwarn ("%Jsecond argument of '%D' should be 'char **'",
5738 if (TREE_CODE (type
) != POINTER_TYPE
5739 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
5740 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
5742 pedwarn ("%Jthird argument of '%D' should probably be "
5743 "'char **'", decl1
, decl1
);
5748 /* It is intentional that this message does not mention the third
5749 argument because it's only mentioned in an appendix of the
5751 if (argct
> 0 && (argct
< 2 || argct
> 3))
5752 pedwarn ("%J'%D' takes only zero or two arguments", decl1
, decl1
);
5754 if (! TREE_PUBLIC (decl1
))
5755 pedwarn ("%J'%D' is normally a non-static function", decl1
, decl1
);
5758 /* Record the decl so that the function name is defined.
5759 If we already have a decl for this name, and it is a FUNCTION_DECL,
5760 use the old decl. */
5762 current_function_decl
= pushdecl (decl1
);
5765 declare_parm_level ();
5767 make_decl_rtl (current_function_decl
, NULL
);
5769 restype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
5770 /* Promote the value to int before returning it. */
5771 if (c_promoting_integer_type_p (restype
))
5773 /* It retains unsignedness if not really getting wider. */
5774 if (TYPE_UNSIGNED (restype
)
5775 && (TYPE_PRECISION (restype
)
5776 == TYPE_PRECISION (integer_type_node
)))
5777 restype
= unsigned_type_node
;
5779 restype
= integer_type_node
;
5781 DECL_RESULT (current_function_decl
)
5782 = build_decl (RESULT_DECL
, NULL_TREE
, restype
);
5784 /* If this fcn was already referenced via a block-scope `extern' decl
5785 (or an implicit decl), propagate certain information about the usage. */
5786 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl
)))
5787 TREE_ADDRESSABLE (current_function_decl
) = 1;
5789 immediate_size_expand
= old_immediate_size_expand
;
5791 start_fname_decls ();
5796 /* Subroutine of store_parm_decls which handles new-style function
5797 definitions (prototype format). The parms already have decls, so we
5798 need only record them as in effect and complain if any redundant
5799 old-style parm decls were written. */
5801 store_parm_decls_newstyle (tree fndecl
, tree arg_info
)
5804 tree parms
= ARG_INFO_PARMS (arg_info
);
5805 tree tags
= ARG_INFO_TAGS (arg_info
);
5806 tree others
= ARG_INFO_OTHERS (arg_info
);
5808 if (current_scope
->bindings
)
5810 error ("%Jold-style parameter declarations in prototyped "
5811 "function definition", fndecl
);
5813 /* Get rid of the old-style declarations. */
5817 /* Don't issue this warning for nested functions, and don't issue this
5818 warning if we got here because ARG_INFO_TYPES was error_mark_node
5819 (this happens when a function definition has just an ellipsis in
5820 its parameter list). */
5821 else if (warn_traditional
&& !in_system_header
5822 && DECL_CONTEXT (fndecl
) == current_file_decl
5823 && ARG_INFO_TYPES (arg_info
) != error_mark_node
)
5824 warning ("%Jtraditional C rejects ISO C style function definitions",
5827 /* Now make all the parameter declarations visible in the function body.
5828 We can bypass most of the grunt work of pushdecl. */
5829 for (decl
= parms
; decl
; decl
= TREE_CHAIN (decl
))
5831 DECL_CONTEXT (decl
) = current_function_decl
;
5832 if (DECL_NAME (decl
))
5833 bind (DECL_NAME (decl
), decl
, current_scope
);
5835 error ("%Jparameter name omitted", decl
);
5838 /* Record the parameter list in the function declaration. */
5839 DECL_ARGUMENTS (fndecl
) = parms
;
5841 /* Now make all the ancillary declarations visible, likewise. */
5842 for (decl
= others
; decl
; decl
= TREE_CHAIN (decl
))
5844 DECL_CONTEXT (decl
) = current_function_decl
;
5845 if (DECL_NAME (decl
))
5846 bind (DECL_NAME (decl
), decl
, current_scope
);
5849 /* And all the tag declarations. */
5850 for (decl
= tags
; decl
; decl
= TREE_CHAIN (decl
))
5851 if (TREE_PURPOSE (decl
))
5852 bind (TREE_PURPOSE (decl
), TREE_VALUE (decl
), current_scope
);
5855 /* Subroutine of store_parm_decls which handles old-style function
5856 definitions (separate parameter list and declarations). */
5859 store_parm_decls_oldstyle (tree fndecl
, tree arg_info
)
5861 struct c_binding
*b
;
5862 tree parm
, decl
, last
;
5863 tree parmids
= ARG_INFO_PARMS (arg_info
);
5865 /* We use DECL_WEAK as a flag to show which parameters have been
5866 seen already, since it is not used on PARM_DECL. */
5867 #ifdef ENABLE_CHECKING
5868 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
5869 if (TREE_CODE (b
->decl
) == PARM_DECL
&& DECL_WEAK (b
->decl
))
5873 if (warn_old_style_definition
&& !in_system_header
)
5874 warning ("%Jold-style function definition", fndecl
);
5876 /* Match each formal parameter name with its declaration. Save each
5877 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
5878 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
5880 if (TREE_VALUE (parm
) == 0)
5882 error ("%Jparameter name missing from parameter list", fndecl
);
5883 TREE_PURPOSE (parm
) = 0;
5887 b
= I_SYMBOL_BINDING (TREE_VALUE (parm
));
5888 if (b
&& b
->contour
== current_scope
)
5891 /* If we got something other than a PARM_DECL it is an error. */
5892 if (TREE_CODE (decl
) != PARM_DECL
)
5893 error ("%J'%D' declared as a non-parameter", decl
, decl
);
5894 /* If the declaration is already marked, we have a duplicate
5895 name. Complain and ignore the duplicate. */
5896 else if (DECL_WEAK (decl
))
5898 error ("%Jmultiple parameters named '%D'", decl
, decl
);
5899 TREE_PURPOSE (parm
) = 0;
5902 /* If the declaration says "void", complain and turn it into
5904 else if (VOID_TYPE_P (TREE_TYPE (decl
)))
5906 error ("%Jparameter '%D' declared with void type", decl
, decl
);
5907 TREE_TYPE (decl
) = integer_type_node
;
5908 DECL_ARG_TYPE (decl
) = integer_type_node
;
5909 layout_decl (decl
, 0);
5912 /* If no declaration found, default to int. */
5915 decl
= build_decl (PARM_DECL
, TREE_VALUE (parm
), integer_type_node
);
5916 DECL_ARG_TYPE (decl
) = TREE_TYPE (decl
);
5917 DECL_SOURCE_LOCATION (decl
) = DECL_SOURCE_LOCATION (fndecl
);
5921 pedwarn ("%Jtype of '%D' defaults to 'int'", decl
, decl
);
5922 else if (extra_warnings
)
5923 warning ("%Jtype of '%D' defaults to 'int'", decl
, decl
);
5926 TREE_PURPOSE (parm
) = decl
;
5927 DECL_WEAK (decl
) = 1;
5930 /* Now examine the parms chain for incomplete declarations
5931 and declarations with no corresponding names. */
5933 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
5936 if (TREE_CODE (parm
) != PARM_DECL
)
5939 if (!COMPLETE_TYPE_P (TREE_TYPE (parm
)))
5941 error ("%Jparameter '%D' has incomplete type", parm
, parm
);
5942 TREE_TYPE (parm
) = error_mark_node
;
5945 if (! DECL_WEAK (parm
))
5947 error ("%Jdeclaration for parameter '%D' but no such parameter",
5950 /* Pretend the parameter was not missing.
5951 This gets us to a standard state and minimizes
5952 further error messages. */
5953 parmids
= chainon (parmids
, tree_cons (parm
, 0, 0));
5957 /* Chain the declarations together in the order of the list of
5958 names. Store that chain in the function decl, replacing the
5959 list of names. Update the current scope to match. */
5960 DECL_ARGUMENTS (fndecl
) = 0;
5962 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
5963 if (TREE_PURPOSE (parm
))
5965 if (parm
&& TREE_PURPOSE (parm
))
5967 last
= TREE_PURPOSE (parm
);
5968 DECL_ARGUMENTS (fndecl
) = last
;
5969 DECL_WEAK (last
) = 0;
5971 for (parm
= TREE_CHAIN (parm
); parm
; parm
= TREE_CHAIN (parm
))
5972 if (TREE_PURPOSE (parm
))
5974 TREE_CHAIN (last
) = TREE_PURPOSE (parm
);
5975 last
= TREE_PURPOSE (parm
);
5976 DECL_WEAK (last
) = 0;
5978 TREE_CHAIN (last
) = 0;
5981 /* If there was a previous prototype,
5982 set the DECL_ARG_TYPE of each argument according to
5983 the type previously specified, and report any mismatches. */
5985 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
5988 for (parm
= DECL_ARGUMENTS (fndecl
),
5989 type
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
5990 parm
|| (type
&& (TYPE_MAIN_VARIANT (TREE_VALUE (type
))
5991 != void_type_node
));
5992 parm
= TREE_CHAIN (parm
), type
= TREE_CHAIN (type
))
5994 if (parm
== 0 || type
== 0
5995 || TYPE_MAIN_VARIANT (TREE_VALUE (type
)) == void_type_node
)
5997 error ("number of arguments doesn't match prototype");
5998 error ("%Hprototype declaration",
5999 ¤t_function_prototype_locus
);
6002 /* Type for passing arg must be consistent with that
6003 declared for the arg. ISO C says we take the unqualified
6004 type for parameters declared with qualified type. */
6005 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm
)),
6006 TYPE_MAIN_VARIANT (TREE_VALUE (type
)),
6009 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm
))
6010 == TYPE_MAIN_VARIANT (TREE_VALUE (type
)))
6012 /* Adjust argument to match prototype. E.g. a previous
6013 `int foo(float);' prototype causes
6014 `int foo(x) float x; {...}' to be treated like
6015 `int foo(float x) {...}'. This is particularly
6016 useful for argument types like uid_t. */
6017 DECL_ARG_TYPE (parm
) = TREE_TYPE (parm
);
6019 if (targetm
.calls
.promote_prototypes (TREE_TYPE (current_function_decl
))
6020 && INTEGRAL_TYPE_P (TREE_TYPE (parm
))
6021 && TYPE_PRECISION (TREE_TYPE (parm
))
6022 < TYPE_PRECISION (integer_type_node
))
6023 DECL_ARG_TYPE (parm
) = integer_type_node
;
6027 pedwarn ("promoted argument '%D' "
6028 "doesn't match prototype", parm
);
6029 pedwarn ("%Hprototype declaration",
6030 ¤t_function_prototype_locus
);
6035 error ("argument '%D' doesn't match prototype", parm
);
6036 error ("%Hprototype declaration",
6037 ¤t_function_prototype_locus
);
6041 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = 0;
6044 /* Otherwise, create a prototype that would match. */
6048 tree actual
= 0, last
= 0, type
;
6050 for (parm
= DECL_ARGUMENTS (fndecl
); parm
; parm
= TREE_CHAIN (parm
))
6052 type
= tree_cons (NULL_TREE
, DECL_ARG_TYPE (parm
), NULL_TREE
);
6054 TREE_CHAIN (last
) = type
;
6059 type
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
6061 TREE_CHAIN (last
) = type
;
6065 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6066 of the type of this function, but we need to avoid having this
6067 affect the types of other similarly-typed functions, so we must
6068 first force the generation of an identical (but separate) type
6069 node for the relevant function type. The new node we create
6070 will be a variant of the main variant of the original function
6073 TREE_TYPE (fndecl
) = build_type_copy (TREE_TYPE (fndecl
));
6075 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = actual
;
6079 /* Store the parameter declarations into the current function declaration.
6080 This is called after parsing the parameter declarations, before
6081 digesting the body of the function.
6083 For an old-style definition, construct a prototype out of the old-style
6084 parameter declarations and inject it into the function's type. */
6087 store_parm_decls (void)
6089 tree fndecl
= current_function_decl
;
6091 /* The function containing FNDECL, if any. */
6092 tree context
= decl_function_context (fndecl
);
6094 /* The argument information block for FNDECL. */
6095 tree arg_info
= DECL_ARGUMENTS (fndecl
);
6097 /* True if this definition is written with a prototype. Note:
6098 despite C99 6.7.5.3p14, we can *not* treat an empty argument
6099 list in a function definition as equivalent to (void) -- an
6100 empty argument list specifies the function has no parameters,
6101 but only (void) sets up a prototype for future calls. */
6102 bool proto
= ARG_INFO_TYPES (arg_info
) != 0;
6105 store_parm_decls_newstyle (fndecl
, arg_info
);
6107 store_parm_decls_oldstyle (fndecl
, arg_info
);
6109 /* The next call to push_scope will be a function body. */
6111 next_is_function_body
= true;
6113 /* Write a record describing this function definition to the prototypes
6114 file (if requested). */
6116 gen_aux_info_record (fndecl
, 1, 0, proto
);
6118 /* Initialize the RTL code for the function. */
6119 allocate_struct_function (fndecl
);
6121 /* Begin the statement tree for this function. */
6122 begin_stmt_tree (&DECL_SAVED_TREE (fndecl
));
6124 /* If this is a nested function, save away the sizes of any
6125 variable-size types so that we can expand them when generating
6131 DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
6132 = nreverse (get_pending_sizes ());
6133 for (t
= DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
;
6136 SAVE_EXPR_CONTEXT (TREE_VALUE (t
)) = context
;
6139 /* This function is being processed in whole-function mode. */
6140 cfun
->x_whole_function_mode_p
= 1;
6142 /* Even though we're inside a function body, we still don't want to
6143 call expand_expr to calculate the size of a variable-sized array.
6144 We haven't necessarily assigned RTL to all variables yet, so it's
6145 not safe to try to expand expressions involving them. */
6146 immediate_size_expand
= 0;
6147 cfun
->x_dont_save_pending_sizes_p
= 1;
6150 /* Finish up a function declaration and compile that function
6151 all the way to assembler language output. The free the storage
6152 for the function definition.
6154 This is called after parsing the body of the function definition. */
6157 finish_function (void)
6159 tree fndecl
= current_function_decl
;
6161 /* When a function declaration is totally empty, e.g.
6163 (the argument list is irrelevant) the compstmt rule will not
6164 bother calling push_scope/pop_scope, which means we get here with
6165 the scope stack out of sync. Detect this situation by noticing
6166 that current_scope is still as store_parm_decls left it, and do
6167 a dummy push/pop to get back to consistency.
6168 Note that the call to push_scope does not actually push another
6169 scope - see there for details. */
6171 if (current_scope
->parm_flag
&& next_is_function_body
)
6177 if (TREE_CODE (fndecl
) == FUNCTION_DECL
6178 && targetm
.calls
.promote_prototypes (TREE_TYPE (fndecl
)))
6180 tree args
= DECL_ARGUMENTS (fndecl
);
6181 for (; args
; args
= TREE_CHAIN (args
))
6183 tree type
= TREE_TYPE (args
);
6184 if (INTEGRAL_TYPE_P (type
)
6185 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
6186 DECL_ARG_TYPE (args
) = integer_type_node
;
6190 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
6191 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
6193 /* Must mark the RESULT_DECL as being in this function. */
6195 if (DECL_RESULT (fndecl
) && DECL_RESULT (fndecl
) != error_mark_node
)
6196 DECL_CONTEXT (DECL_RESULT (fndecl
)) = fndecl
;
6198 if (MAIN_NAME_P (DECL_NAME (fndecl
)) && flag_hosted
)
6200 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl
)))
6201 != integer_type_node
)
6203 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6204 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6206 pedwarn ("%Jreturn type of '%D' is not `int'", fndecl
, fndecl
);
6210 #ifdef DEFAULT_MAIN_RETURN
6211 /* Make it so that `main' always returns success by default. */
6212 DEFAULT_MAIN_RETURN
;
6215 c_expand_return (integer_zero_node
);
6220 finish_fname_decls ();
6222 /* Tie off the statement tree for this function. */
6223 finish_stmt_tree (&DECL_SAVED_TREE (fndecl
));
6225 /* Complain if there's just no return statement. */
6226 if (warn_return_type
6227 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl
))) != VOID_TYPE
6228 && !current_function_returns_value
&& !current_function_returns_null
6229 /* Don't complain if we abort. */
6230 && !current_function_returns_abnormally
6231 /* Don't warn for main(). */
6232 && !MAIN_NAME_P (DECL_NAME (fndecl
))
6233 /* Or if they didn't actually specify a return type. */
6234 && !C_FUNCTION_IMPLICIT_INT (fndecl
)
6235 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6236 inline function, as we might never be compiled separately. */
6237 && DECL_INLINE (fndecl
))
6238 warning ("no return statement in function returning non-void");
6240 /* With just -Wextra, complain only if function returns both with
6241 and without a value. */
6243 && current_function_returns_value
6244 && current_function_returns_null
)
6245 warning ("this function may return with or without a value");
6247 /* We're leaving the context of this function, so zap cfun.
6248 It's still in DECL_STRUCT_FUNCTION , and we'll restore it in
6249 tree_rest_of_compilation. */
6252 /* ??? Objc emits functions after finalizing the compilation unit.
6253 This should be cleaned up later and this conditional removed. */
6254 if (!cgraph_global_info_ready
)
6255 cgraph_finalize_function (fndecl
, false);
6257 c_expand_body (fndecl
);
6258 current_function_decl
= NULL
;
6261 /* Generate the RTL for the body of FNDECL. If NESTED_P is nonzero,
6262 then we are already in the process of generating RTL for another
6266 c_expand_body_1 (tree fndecl
, int nested_p
)
6270 /* Make sure that we will evaluate variable-sized types involved
6271 in our function's type. */
6272 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
);
6274 /* Squirrel away our current state. */
6275 push_function_context ();
6278 tree_rest_of_compilation (fndecl
, nested_p
);
6281 /* Return to the enclosing function. */
6282 pop_function_context ();
6284 if (DECL_STATIC_CONSTRUCTOR (fndecl
))
6286 if (targetm
.have_ctors_dtors
)
6287 targetm
.asm_out
.constructor (XEXP (DECL_RTL (fndecl
), 0),
6288 DEFAULT_INIT_PRIORITY
);
6290 static_ctors
= tree_cons (NULL_TREE
, fndecl
, static_ctors
);
6293 if (DECL_STATIC_DESTRUCTOR (fndecl
))
6295 if (targetm
.have_ctors_dtors
)
6296 targetm
.asm_out
.destructor (XEXP (DECL_RTL (fndecl
), 0),
6297 DEFAULT_INIT_PRIORITY
);
6299 static_dtors
= tree_cons (NULL_TREE
, fndecl
, static_dtors
);
6303 /* Like c_expand_body_1 but only for unnested functions. */
6306 c_expand_body (tree fndecl
)
6309 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
6310 c_expand_body_1 (fndecl
, 0);
6313 /* Check the declarations given in a for-loop for satisfying the C99
6316 check_for_loop_decls (void)
6318 struct c_binding
*b
;
6322 /* If we get here, declarations have been used in a for loop without
6323 the C99 for loop scope. This doesn't make much sense, so don't
6325 error ("'for' loop initial declaration used outside C99 mode");
6328 /* C99 subclause 6.8.5 paragraph 3:
6330 [#3] The declaration part of a for statement shall only
6331 declare identifiers for objects having storage class auto or
6334 It isn't clear whether, in this sentence, "identifiers" binds to
6335 "shall only declare" or to "objects" - that is, whether all identifiers
6336 declared must be identifiers for objects, or whether the restriction
6337 only applies to those that are. (A question on this in comp.std.c
6338 in November 2000 received no answer.) We implement the strictest
6339 interpretation, to avoid creating an extension which later causes
6342 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
6345 tree decl
= b
->decl
;
6350 switch (TREE_CODE (decl
))
6353 if (TREE_STATIC (decl
))
6354 error ("%Jdeclaration of static variable '%D' in 'for' loop "
6355 "initial declaration", decl
, decl
);
6356 else if (DECL_EXTERNAL (decl
))
6357 error ("%Jdeclaration of 'extern' variable '%D' in 'for' loop "
6358 "initial declaration", decl
, decl
);
6362 error ("'struct %E' declared in 'for' loop initial declaration", id
);
6365 error ("'union %E' declared in 'for' loop initial declaration", id
);
6368 error ("'enum %E' declared in 'for' loop initial declaration", id
);
6371 error ("%Jdeclaration of non-variable '%D' in 'for' loop "
6372 "initial declaration", decl
, decl
);
6377 /* Save and reinitialize the variables
6378 used during compilation of a C function. */
6381 c_push_function_context (struct function
*f
)
6383 struct language_function
*p
;
6384 p
= ggc_alloc (sizeof (struct language_function
));
6387 p
->base
.x_stmt_tree
= c_stmt_tree
;
6388 p
->base
.x_scope_stmt_stack
= c_scope_stmt_stack
;
6389 p
->x_in_iteration_stmt
= c_in_iteration_stmt
;
6390 p
->x_in_case_stmt
= c_in_case_stmt
;
6391 p
->returns_value
= current_function_returns_value
;
6392 p
->returns_null
= current_function_returns_null
;
6393 p
->returns_abnormally
= current_function_returns_abnormally
;
6394 p
->warn_about_return_type
= warn_about_return_type
;
6395 p
->extern_inline
= current_extern_inline
;
6398 /* Restore the variables used during compilation of a C function. */
6401 c_pop_function_context (struct function
*f
)
6403 struct language_function
*p
= f
->language
;
6405 if (DECL_STRUCT_FUNCTION (current_function_decl
) == 0
6406 && DECL_SAVED_TREE (current_function_decl
) == NULL_TREE
)
6408 /* Stop pointing to the local nodes about to be freed. */
6409 /* But DECL_INITIAL must remain nonzero so we know this
6410 was an actual function definition. */
6411 DECL_INITIAL (current_function_decl
) = error_mark_node
;
6412 DECL_ARGUMENTS (current_function_decl
) = 0;
6415 c_stmt_tree
= p
->base
.x_stmt_tree
;
6416 c_scope_stmt_stack
= p
->base
.x_scope_stmt_stack
;
6417 c_in_iteration_stmt
= p
->x_in_iteration_stmt
;
6418 c_in_case_stmt
= p
->x_in_case_stmt
;
6419 current_function_returns_value
= p
->returns_value
;
6420 current_function_returns_null
= p
->returns_null
;
6421 current_function_returns_abnormally
= p
->returns_abnormally
;
6422 warn_about_return_type
= p
->warn_about_return_type
;
6423 current_extern_inline
= p
->extern_inline
;
6428 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
6431 c_dup_lang_specific_decl (tree decl
)
6433 struct lang_decl
*ld
;
6435 if (!DECL_LANG_SPECIFIC (decl
))
6438 ld
= ggc_alloc (sizeof (struct lang_decl
));
6439 memcpy (ld
, DECL_LANG_SPECIFIC (decl
), sizeof (struct lang_decl
));
6440 DECL_LANG_SPECIFIC (decl
) = ld
;
6443 /* The functions below are required for functionality of doing
6444 function at once processing in the C front end. Currently these
6445 functions are not called from anywhere in the C front end, but as
6446 these changes continue, that will change. */
6448 /* Returns nonzero if the current statement is a full expression,
6449 i.e. temporaries created during that statement should be destroyed
6450 at the end of the statement. */
6453 stmts_are_full_exprs_p (void)
6458 /* Returns the stmt_tree (if any) to which statements are currently
6459 being added. If there is no active statement-tree, NULL is
6463 current_stmt_tree (void)
6465 return &c_stmt_tree
;
6468 /* Returns the stack of SCOPE_STMTs for the current function. */
6471 current_scope_stmt_stack (void)
6473 return &c_scope_stmt_stack
;
6476 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
6480 anon_aggr_type_p (tree node ATTRIBUTE_UNUSED
)
6485 /* Dummy function in place of callback used by C++. */
6488 extract_interface_info (void)
6492 /* Return a new COMPOUND_STMT, after adding it to the current
6496 c_begin_compound_stmt (void)
6500 /* Create the COMPOUND_STMT. */
6501 stmt
= add_stmt (build_stmt (COMPOUND_STMT
, NULL_TREE
));
6506 /* Expand T (a DECL_STMT) if it declares an entity not handled by the
6510 c_expand_decl_stmt (tree t
)
6512 tree decl
= DECL_STMT_DECL (t
);
6514 /* Expand nested functions. */
6515 if (TREE_CODE (decl
) == FUNCTION_DECL
6516 && DECL_CONTEXT (decl
) == current_function_decl
6517 && DECL_SAVED_TREE (decl
))
6518 c_expand_body_1 (decl
, 1);
6521 /* Return the global value of T as a symbol. */
6524 identifier_global_value (tree t
)
6526 struct c_binding
*b
;
6528 for (b
= I_SYMBOL_BINDING (t
); b
; b
= b
->shadowed
)
6529 if (b
->contour
== file_scope
|| b
->contour
== external_scope
)
6535 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
6536 otherwise the name is found in ridpointers from RID_INDEX. */
6539 record_builtin_type (enum rid rid_index
, const char *name
, tree type
)
6543 id
= ridpointers
[(int) rid_index
];
6545 id
= get_identifier (name
);
6546 pushdecl (build_decl (TYPE_DECL
, id
, type
));
6549 /* Build the void_list_node (void_type_node having been created). */
6551 build_void_list_node (void)
6553 tree t
= build_tree_list (NULL_TREE
, void_type_node
);
6557 /* Return something to represent absolute declarators containing a *.
6558 TARGET is the absolute declarator that the * contains.
6559 TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile
6560 to apply to the pointer type, represented as identifiers, possible mixed
6563 We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST,
6564 if attributes are present) and whose type is the modifier list. */
6567 make_pointer_declarator (tree type_quals_attrs
, tree target
)
6570 tree itarget
= target
;
6571 split_specs_attrs (type_quals_attrs
, &quals
, &attrs
);
6572 if (attrs
!= NULL_TREE
)
6573 itarget
= tree_cons (attrs
, target
, NULL_TREE
);
6574 return build1 (INDIRECT_REF
, quals
, itarget
);
6577 /* A wrapper around lhd_set_decl_assembler_name that gives static
6578 variables their C names if they are at file scope and only one
6579 translation unit is being compiled, for backwards compatibility
6580 with certain bizarre assembler hacks (like crtstuff.c). */
6583 c_static_assembler_name (tree decl
)
6585 if (num_in_fnames
== 1
6586 && !TREE_PUBLIC (decl
) && DECL_CONTEXT (decl
)
6587 && TREE_CODE (DECL_CONTEXT (decl
)) == TRANSLATION_UNIT_DECL
)
6588 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
6590 lhd_set_decl_assembler_name (decl
);
6593 /* Perform final processing on file-scope data. */
6595 c_write_global_declarations_1 (tree globals
)
6597 size_t len
= list_length (globals
);
6598 tree
*vec
= xmalloc (sizeof (tree
) * len
);
6602 /* Process the decls in the order they were written. */
6603 for (i
= 0, decl
= globals
; i
< len
; i
++, decl
= TREE_CHAIN (decl
))
6606 wrapup_global_declarations (vec
, len
);
6607 check_global_declarations (vec
, len
);
6613 c_write_global_declarations (void)
6617 /* We don't want to do this if generating a PCH. */
6621 /* Process all file scopes in this compilation. */
6622 for (t
= current_file_decl
; t
; t
= TREE_CHAIN (t
))
6623 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t
)));
6625 /* Now do the same for the externals scope. */
6628 c_write_global_declarations_1 (BLOCK_VARS (t
));
6631 #include "gt-c-decl.h"