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 /* Parsing a function declarator leaves a list of parameter names
87 or a chain of parameter decls here. */
89 static tree last_function_parms
;
91 /* ... and a chain of structure and enum types declared in the
94 static tree last_function_parm_tags
;
96 /* ... and a chain of all non-parameter declarations (such as
97 CONST_DECLs from enumerations) here. */
99 static tree last_function_parm_others
;
101 /* After parsing the declarator that starts a function definition,
102 `start_function' puts the list of parameter names or chain of decls here
103 for `store_parm_decls' to find. */
105 static tree current_function_parms
;
107 /* Similar, for last_function_parm_tags. */
109 static tree current_function_parm_tags
;
111 /* And for last_function_parm_others. */
113 static tree current_function_parm_others
;
115 /* Similar, for the file and line that the prototype came from if this is
116 an old-style definition. */
118 static location_t current_function_prototype_locus
;
120 /* The current statement tree. */
122 static GTY(()) struct stmt_tree_s c_stmt_tree
;
124 /* The current scope statement stack. */
126 static GTY(()) tree c_scope_stmt_stack
;
128 /* State saving variables. */
129 int c_in_iteration_stmt
;
132 /* A list of external DECLs that appeared at block scope when there was
133 some other global meaning for that identifier. */
134 static GTY(()) tree truly_local_externals
;
136 /* All the builtins; this is a subset of the entries of global_scope. */
138 static GTY(()) tree first_builtin_decl
;
139 static GTY(()) tree last_builtin_decl
;
141 /* A DECL for the current file-scope context. */
143 static GTY(()) tree current_file_decl
;
145 /* Set to 0 at beginning of a function definition, set to 1 if
146 a return statement that specifies a return value is seen. */
148 int current_function_returns_value
;
150 /* Set to 0 at beginning of a function definition, set to 1 if
151 a return statement with no argument is seen. */
153 int current_function_returns_null
;
155 /* Set to 0 at beginning of a function definition, set to 1 if
156 a call to a noreturn function is seen. */
158 int current_function_returns_abnormally
;
160 /* Set to nonzero by `grokdeclarator' for a function
161 whose return type is defaulted, if warnings for this are desired. */
163 static int warn_about_return_type
;
165 /* Nonzero when starting a function declared `extern inline'. */
167 static int current_extern_inline
;
169 /* Each c_scope structure describes the complete contents of one scope.
170 Three scopes are distinguished specially: the innermost or current
171 scope, the innermost function scope, and the outermost or file scope.
173 Most declarations are recorded in the current scope.
175 All normal label declarations are recorded in the innermost
176 function scope, as are bindings of undeclared identifiers to
177 error_mark_node. (GCC permits nested functions as an extension,
178 hence the 'innermost' qualifier.) Explicitly declared labels
179 (using the __label__ extension) appear in the current scope.
181 Being in the global scope (current_scope == global_scope) causes
182 special behavior in several places below. Also, under some
183 conditions the Objective-C front end records declarations in the
184 global scope even though that isn't the current scope.
186 The order of the names, parms, and blocks lists matters, and they
187 are frequently appended to. To avoid having to walk all the way to
188 the end of the list on each insertion, or reverse the lists later,
189 we maintain a pointer to the last list entry for each of the lists.
191 The order of the tags, shadowed, and shadowed_tags
192 lists does not matter, so we just prepend to these lists. */
194 struct c_scope
GTY(())
196 /* The scope containing this one. */
197 struct c_scope
*outer
;
199 /* The next outermost function scope. */
200 struct c_scope
*outer_function
;
202 /* All variables, constants, functions, labels, and typedef names. */
206 /* All parameter declarations. Used only in the outermost scope of
211 /* All structure, union, and enum type tags. */
214 /* For each scope, a list of shadowed outer-scope definitions
215 to be restored when this scope is popped.
216 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
217 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
220 /* For each scope, a list of shadowed outer-scope tag definitions
221 to be restored when this scope is popped.
222 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
223 whose TREE_VALUE is its old definition (a kind of ..._TYPE node). */
226 /* For each scope (except the global one), a chain of BLOCK nodes
227 for all the scopes that were entered and exited one level down. */
231 /* True if we are currently filling this scope with parameter
235 /* True if we already complained about forward parameter decls
236 in this scope. This prevents double warnings on
237 foo (int a; int b; ...) */
238 bool warned_forward_parm_decls
: 1;
240 /* True if this is the outermost block scope of a function body.
241 This scope contains the parameters, the local variables declared
242 in the outermost block, and all the labels (except those in
243 nested functions, or declared at block scope with __label__). */
244 bool function_body
: 1;
246 /* True means make a BLOCK for this scope no matter what. */
250 /* The scope currently in effect. */
252 static GTY(()) struct c_scope
*current_scope
;
254 /* A chain of c_scope structures awaiting reuse. */
256 static GTY((deletable (""))) struct c_scope
*scope_freelist
;
258 /* The innermost function scope. Ordinary (not explicitly declared)
259 labels, bindings to error_mark_node, and the lazily-created
260 bindings of __func__ and its friends get this scope. */
262 static GTY(()) struct c_scope
*current_function_scope
;
264 /* The outermost scope, corresponding to the C "file scope". This is
265 created when the compiler is started and exists through the entire run. */
267 static GTY(()) struct c_scope
*global_scope
;
269 /* Append VAR to LIST in scope SCOPE. */
270 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
271 struct c_scope *s_ = (scope); \
273 if (s_->list##_last) \
274 TREE_CHAIN (s_->list##_last) = d_; \
277 s_->list##_last = d_; \
280 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
281 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
282 struct c_scope *t_ = (tscope); \
283 struct c_scope *f_ = (fscope); \
285 TREE_CHAIN (t_->to##_last) = f_->from; \
288 t_->to##_last = f_->from##_last; \
291 /* True means unconditionally make a BLOCK for the next scope pushed. */
293 static bool keep_next_level_flag
;
295 /* True means the next call to pushlevel will be the outermost scope
296 of a function body, so do not push a new scope, merely cease
297 expecting parameter decls. */
299 static bool next_is_function_body
;
301 /* Functions called automatically at the beginning and end of execution. */
303 tree static_ctors
, static_dtors
;
305 /* Forward declarations. */
307 static struct c_scope
*make_scope (void);
308 static void pop_scope (void);
309 static tree
make_label (tree
, location_t
);
310 static void bind_label (tree
, tree
, struct c_scope
*);
311 static void implicit_decl_warning (tree
);
312 static tree
lookup_tag (enum tree_code
, tree
, int);
313 static tree
lookup_name_current_level (tree
);
314 static tree
grokdeclarator (tree
, tree
, enum decl_context
, int, tree
*);
315 static tree
grokparms (tree
, int);
316 static void layout_array_type (tree
);
317 static void store_parm_decls_newstyle (void);
318 static void store_parm_decls_oldstyle (void);
319 static tree
c_make_fname_decl (tree
, int);
320 static void c_expand_body_1 (tree
, int);
321 static tree
any_external_decl (tree
);
322 static void record_external_decl (tree
);
323 static void warn_if_shadowing (tree
, tree
);
324 static void check_bitfield_type_and_width (tree
*, tree
*, const char *);
325 static void clone_underlying_type (tree
);
326 static bool flexible_array_type_p (tree
);
327 static hashval_t
link_hash_hash (const void *);
328 static int link_hash_eq (const void *, const void *);
330 /* States indicating how grokdeclarator() should handle declspecs marked
331 with __attribute__((deprecated)). An object declared as
332 __attribute__((deprecated)) suppresses warnings of uses of other
335 enum deprecated_states
{
340 static enum deprecated_states deprecated_state
= DEPRECATED_NORMAL
;
343 c_print_identifier (FILE *file
, tree node
, int indent
)
345 print_node (file
, "symbol", IDENTIFIER_SYMBOL_VALUE (node
), indent
+ 4);
346 print_node (file
, "tag", IDENTIFIER_TAG_VALUE (node
), indent
+ 4);
347 print_node (file
, "label", IDENTIFIER_LABEL_VALUE (node
), indent
+ 4);
348 if (C_IS_RESERVED_WORD (node
))
350 tree rid
= ridpointers
[C_RID_CODE (node
)];
351 indent_to (file
, indent
+ 4);
352 fprintf (file
, "rid " HOST_PTR_PRINTF
" \"%s\"",
353 (void *) rid
, IDENTIFIER_POINTER (rid
));
357 /* Hook called at end of compilation to assume 1 elt
358 for a file-scope tentative array defn that wasn't complete before. */
361 c_finish_incomplete_decl (tree decl
)
363 if (TREE_CODE (decl
) == VAR_DECL
)
365 tree type
= TREE_TYPE (decl
);
366 if (type
!= error_mark_node
367 && TREE_CODE (type
) == ARRAY_TYPE
368 && ! DECL_EXTERNAL (decl
)
369 && TYPE_DOMAIN (type
) == 0)
371 warning ("%Jarray '%D' assumed to have one element", decl
, decl
);
373 complete_array_type (type
, NULL_TREE
, 1);
375 layout_decl (decl
, 0);
380 /* Reuse or create a struct for this scope. */
382 static struct c_scope
*
385 struct c_scope
*result
;
388 result
= scope_freelist
;
389 scope_freelist
= result
->outer
;
392 result
= ggc_alloc_cleared (sizeof (struct c_scope
));
397 /* Remove the topmost scope from the stack and add it to the
398 free list, updating current_function_scope if necessary. */
403 struct c_scope
*scope
= current_scope
;
405 current_scope
= scope
->outer
;
406 if (scope
->function_body
)
407 current_function_scope
= scope
->outer_function
;
409 memset (scope
, 0, sizeof (struct c_scope
));
410 scope
->outer
= scope_freelist
;
411 scope_freelist
= scope
;
414 /* The Objective-C front-end often needs to determine the current scope. */
417 get_current_scope (void)
419 return current_scope
;
422 /* The following function is used only by Objective-C. It needs to live here
423 because it accesses the innards of c_scope. */
426 objc_mark_locals_volatile (void *enclosing_blk
)
428 struct c_scope
*scope
;
430 for (scope
= current_scope
;
431 scope
&& scope
!= enclosing_blk
;
432 scope
= scope
->outer
)
436 for (decl
= scope
->names
; decl
; decl
= TREE_CHAIN (decl
))
438 DECL_REGISTER (decl
) = 0;
439 TREE_THIS_VOLATILE (decl
) = 1;
441 /* Do not climb up past the current function. */
442 if (scope
->function_body
)
447 /* Nonzero if we are currently in the global scope. */
450 global_bindings_p (void)
452 return current_scope
== global_scope
;
456 keep_next_level (void)
458 keep_next_level_flag
= true;
461 /* Identify this scope as currently being filled with parameters. */
464 declare_parm_level (void)
466 current_scope
->parm_flag
= true;
469 /* Nonzero if currently making parm declarations. */
472 in_parm_level_p (void)
474 return current_scope
->parm_flag
;
477 /* Enter a new scope. The dummy parameter is for signature
478 compatibility with lang_hooks.decls.pushlevel. */
481 pushlevel (int dummy ATTRIBUTE_UNUSED
)
483 if (next_is_function_body
)
485 /* This is the transition from the parameters to the top level
486 of the function body. These are the same scope
487 (C99 6.2.1p4,6) so we do not push another scope structure.
488 next_is_function_body is set only by store_parm_decls, which
489 in turn is called when and only when we are about to
490 encounter the opening curly brace for the function body.
492 The outermost block of a function always gets a BLOCK node,
493 because the debugging output routines expect that each
494 function has at least one BLOCK. */
495 current_scope
->parm_flag
= false;
496 current_scope
->function_body
= true;
497 current_scope
->keep
= true;
498 current_scope
->outer_function
= current_function_scope
;
499 current_function_scope
= current_scope
;
501 keep_next_level_flag
= false;
502 next_is_function_body
= false;
506 struct c_scope
*scope
= make_scope ();
508 scope
->keep
= keep_next_level_flag
;
509 scope
->outer
= current_scope
;
510 current_scope
= scope
;
511 keep_next_level_flag
= false;
515 /* Exit a scope. Restore the state of the identifier-decl mappings
516 that were in effect when this scope was entered.
518 If KEEP is KEEP_YES (1), this scope had explicit declarations, so
519 create a BLOCK node to record its declarations and subblocks for
520 debugging output. If KEEP is KEEP_MAYBE, do so only if the names
521 or tags lists are nonempty.
523 The second parameter is ignored; it is present only for
524 signature compatibility with lang_hooks.decls.poplevel.
526 If FUNCTIONBODY is nonzero, this level is the body of a function,
527 even if current_scope->function_body is not set. This is used
528 by language-independent code that generates synthetic functions,
529 and cannot set current_scope->function_body.
531 FIXME: Eliminate the need for all arguments. */
534 poplevel (int keep
, int dummy ATTRIBUTE_UNUSED
, int functionbody
)
536 struct c_scope
*scope
= current_scope
;
541 /* The following line does not use |= due to a bug in HP's C compiler. */
542 scope
->function_body
= scope
->function_body
| functionbody
;
544 if (keep
== KEEP_MAYBE
)
545 keep
= (scope
->names
|| scope
->tags
);
548 keep
|= scope
->function_body
;
550 /* If appropriate, create a BLOCK to record the decls for the life
555 block
= make_node (BLOCK
);
556 BLOCK_VARS (block
) = scope
->names
;
557 BLOCK_SUBBLOCKS (block
) = scope
->blocks
;
558 TREE_USED (block
) = 1;
561 /* In each subblock, record that this is its superior. */
562 for (p
= scope
->blocks
; p
; p
= TREE_CHAIN (p
))
563 BLOCK_SUPERCONTEXT (p
) = block
;
565 /* Clear out the variable bindings in this scope.
567 Propagate TREE_ADDRESSABLE from nested functions to their
568 containing functions.
570 Issue warnings for unused variables and labels, and errors for
571 undefined labels, if there are any. */
573 for (p
= scope
->names
; p
; p
= TREE_CHAIN (p
))
575 switch (TREE_CODE (p
))
578 if (TREE_USED (p
) && !DECL_INITIAL (p
))
580 error ("%Jlabel `%D' used but not defined", p
, p
);
581 DECL_INITIAL (p
) = error_mark_node
;
583 else if (!TREE_USED (p
) && warn_unused_label
)
585 if (DECL_INITIAL (p
))
586 warning ("%Jlabel `%D' defined but not used", p
, p
);
588 warning ("%Jlabel `%D' declared but not defined", p
, p
);
591 IDENTIFIER_LABEL_VALUE (DECL_NAME (p
)) = 0;
595 if (! TREE_ASM_WRITTEN (p
)
596 && DECL_INITIAL (p
) != 0
597 && TREE_ADDRESSABLE (p
)
598 && DECL_ABSTRACT_ORIGIN (p
) != 0
599 && DECL_ABSTRACT_ORIGIN (p
) != p
)
600 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p
)) = 1;
604 /* Keep this in sync with stmt.c:warn_about_unused_variables.
605 No warnings when the global scope is popped because the
606 global scope isn't popped for the last translation unit,
607 so the warnings are done in c_write_global_declaration. */
608 if (warn_unused_variable
&& scope
!= global_scope
610 && !DECL_IN_SYSTEM_HEADER (p
)
612 && !DECL_ARTIFICIAL (p
))
613 warning ("%Junused variable `%D'", p
, p
);
620 if (DECL_EXTERNAL (p
) && scope
!= global_scope
)
621 /* External decls stay in the symbol-value slot but are
623 C_DECL_INVISIBLE (p
) = 1;
625 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (p
)) = 0;
631 /* Clear out the parameter bindings in this scope, if any.
632 Unused-parameter warnings are handled by function.c. */
633 for (p
= scope
->parms
; p
; p
= TREE_CHAIN (p
))
635 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (p
)) = 0;
637 /* Clear out the tag-meanings declared in this scope.
639 Set the TYPE_CONTEXTs for all of the tagged types belonging to
640 this scope so that they point to the appropriate construct, i.e.
641 either to the current FUNCTION_DECL node, or else to the BLOCK
642 node we just constructed.
644 Note that for tagged types whose scope is just the formal
645 parameter list for some function type specification, we can't
646 properly set their TYPE_CONTEXTs here, because we don't have a
647 pointer to the appropriate FUNCTION_TYPE node readily available
648 to us. For those cases, the TYPE_CONTEXTs of the relevant tagged
649 type nodes get set in `grokdeclarator' as soon as we have created
650 the FUNCTION_TYPE node which will represent the "scope" for these
651 "parameter list local" tagged types. */
653 decl
= scope
->function_body
? current_function_decl
: block
;
654 for (p
= scope
->tags
; p
; p
= TREE_CHAIN (p
))
656 if (TREE_PURPOSE (p
))
657 IDENTIFIER_TAG_VALUE (TREE_PURPOSE (p
)) = 0;
659 TYPE_CONTEXT (TREE_VALUE (p
)) = decl
;
662 /* Restore all name- and label-meanings from outer scopes that were
663 shadowed by this scope. */
664 for (p
= scope
->shadowed
; p
; p
= TREE_CHAIN (p
))
665 if (TREE_VALUE (p
) && TREE_CODE (TREE_VALUE (p
)) == LABEL_DECL
)
666 IDENTIFIER_LABEL_VALUE (TREE_PURPOSE (p
)) = TREE_VALUE (p
);
668 IDENTIFIER_SYMBOL_VALUE (TREE_PURPOSE (p
)) = TREE_VALUE (p
);
670 /* Restore all tag-meanings from outer scopes that were shadowed by
672 for (p
= scope
->shadowed_tags
; p
; p
= TREE_CHAIN (p
))
673 IDENTIFIER_TAG_VALUE (TREE_PURPOSE (p
)) = TREE_VALUE (p
);
675 /* Dispose of the block that we just made inside some higher level. */
676 if (scope
->function_body
&& current_function_decl
)
677 DECL_INITIAL (current_function_decl
) = block
;
678 else if (scope
->outer
)
681 SCOPE_LIST_APPEND (scope
->outer
, blocks
, block
);
682 /* If we did not make a block for the scope just exited, any
683 blocks made for inner scopes must be carried forward so they
684 will later become subblocks of something else. */
685 else if (scope
->blocks
)
686 SCOPE_LIST_CONCAT (scope
->outer
, blocks
, scope
, blocks
);
689 /* Pop the current scope, and free the structure for reuse. */
695 /* Insert BLOCK at the end of the list of subblocks of the current
696 scope. This is used when a BIND_EXPR is expanded, to handle the
697 BLOCK node inside the BIND_EXPR. */
700 insert_block (tree block
)
702 TREE_USED (block
) = 1;
703 SCOPE_LIST_APPEND (current_scope
, blocks
, block
);
706 /* Set the BLOCK node for the innermost scope (the one we are
707 currently in). The RTL expansion machinery requires us to provide
708 this hook, but it is not useful in function-at-a-time mode. */
711 set_block (tree block ATTRIBUTE_UNUSED
)
715 /* Push a definition or a declaration of struct, union or enum tag "name".
716 "type" should be the type node.
717 We assume that the tag "name" is not already defined.
719 Note that the definition may really be just a forward reference.
720 In that case, the TYPE_SIZE will be zero. */
723 pushtag (tree name
, tree type
)
725 struct c_scope
*b
= current_scope
;
727 /* Record the identifier as the type's name if it has none. */
730 if (TYPE_NAME (type
) == 0)
731 TYPE_NAME (type
) = name
;
733 if (IDENTIFIER_TAG_VALUE (name
))
734 b
->shadowed_tags
= tree_cons (name
, IDENTIFIER_TAG_VALUE (name
),
736 IDENTIFIER_TAG_VALUE (name
) = type
;
739 b
->tags
= tree_cons (name
, type
, b
->tags
);
741 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
742 tagged type we just added to the current scope. This fake
743 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
744 to output a representation of a tagged type, and it also gives
745 us a convenient place to record the "scope start" address for the
748 TYPE_STUB_DECL (type
) = pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, type
));
750 /* An approximation for now, so we can tell this is a function-scope tag.
751 This will be updated in poplevel. */
752 TYPE_CONTEXT (type
) = DECL_CONTEXT (TYPE_STUB_DECL (type
));
755 /* Subroutine of compare_decls. Allow harmless mismatches in return
756 and argument types provided that the type modes match. This function
757 return a unified type given a suitable match, and 0 otherwise. */
760 match_builtin_function_types (tree newtype
, tree oldtype
)
762 tree newrettype
, oldrettype
;
763 tree newargs
, oldargs
;
764 tree trytype
, tryargs
;
766 /* Accept the return type of the new declaration if same modes. */
767 oldrettype
= TREE_TYPE (oldtype
);
768 newrettype
= TREE_TYPE (newtype
);
770 if (TYPE_MODE (oldrettype
) != TYPE_MODE (newrettype
))
773 oldargs
= TYPE_ARG_TYPES (oldtype
);
774 newargs
= TYPE_ARG_TYPES (newtype
);
777 while (oldargs
|| newargs
)
781 || ! TREE_VALUE (oldargs
)
782 || ! TREE_VALUE (newargs
)
783 || TYPE_MODE (TREE_VALUE (oldargs
))
784 != TYPE_MODE (TREE_VALUE (newargs
)))
787 oldargs
= TREE_CHAIN (oldargs
);
788 newargs
= TREE_CHAIN (newargs
);
791 trytype
= build_function_type (newrettype
, tryargs
);
792 return build_type_attribute_variant (trytype
, TYPE_ATTRIBUTES (oldtype
));
795 /* Subroutine of diagnose_mismathed_decls. Check for function type
796 mismatch involving an empty arglist vs a nonempty one and give clearer
799 diagnose_arglist_conflict (tree newdecl
, tree olddecl
,
800 tree newtype
, tree oldtype
)
804 if (TREE_CODE (olddecl
) != FUNCTION_DECL
805 || !comptypes (TREE_TYPE (oldtype
), TREE_TYPE (newtype
), COMPARE_STRICT
)
806 || !((TYPE_ARG_TYPES (oldtype
) == 0 && DECL_INITIAL (olddecl
) == 0)
808 (TYPE_ARG_TYPES (newtype
) == 0 && DECL_INITIAL (newdecl
) == 0)))
811 t
= TYPE_ARG_TYPES (oldtype
);
813 t
= TYPE_ARG_TYPES (newtype
);
814 for (; t
; t
= TREE_CHAIN (t
))
816 tree type
= TREE_VALUE (t
);
818 if (TREE_CHAIN (t
) == 0
819 && TYPE_MAIN_VARIANT (type
) != void_type_node
)
821 inform ("a parameter list with an ellipsis can't match "
822 "an empty parameter name list declaration");
826 if (c_type_promotes_to (type
) != type
)
828 inform ("an argument type that has a default promotion can't match "
829 "an empty parameter name list declaration");
835 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
836 old-style function definition, NEWDECL is a prototype declaration.
837 Diagnose inconsistencies in the argument list. Returns TRUE if
838 the prototype is compatible, FALSE if not. */
840 validate_proto_after_old_defn (tree newdecl
, tree newtype
, tree oldtype
)
842 tree newargs
, oldargs
;
845 /* ??? Elsewhere TYPE_MAIN_VARIANT is not used in this context. */
846 #define END_OF_ARGLIST(t) (TYPE_MAIN_VARIANT (t) == void_type_node)
848 oldargs
= TYPE_ACTUAL_ARG_TYPES (oldtype
);
849 newargs
= TYPE_ARG_TYPES (newtype
);
854 tree oldargtype
= TREE_VALUE (oldargs
);
855 tree newargtype
= TREE_VALUE (newargs
);
857 if (END_OF_ARGLIST (oldargtype
) && END_OF_ARGLIST (newargtype
))
860 /* Reaching the end of just one list means the two decls don't
861 agree on the number of arguments. */
862 if (END_OF_ARGLIST (oldargtype
))
864 error ("%Jprototype for '%D' declares more arguments "
865 "than previous old-style definition", newdecl
, newdecl
);
868 else if (END_OF_ARGLIST (newargtype
))
870 error ("%Jprototype for '%D' declares fewer arguments "
871 "than previous old-style definition", newdecl
, newdecl
);
875 /* Type for passing arg must be consistent with that declared
877 else if (! comptypes (oldargtype
, newargtype
, COMPARE_STRICT
))
879 error ("%Jprototype for '%D' declares arg %d with incompatible type",
880 newdecl
, newdecl
, i
);
884 oldargs
= TREE_CHAIN (oldargs
);
885 newargs
= TREE_CHAIN (newargs
);
889 /* If we get here, no errors were found, but do issue a warning
890 for this poor-style construct. */
891 warning ("%Jprototype for '%D' follows non-prototype definition",
894 #undef END_OF_ARGLIST
897 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
898 first in a pair of mismatched declarations, using the diagnostic
901 locate_old_decl (tree decl
, void (*diag
)(const char *, ...))
903 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
905 else if (DECL_INITIAL (decl
))
906 diag (N_("%Jprevious definition of '%D' was here"), decl
, decl
);
907 else if (C_DECL_IMPLICIT (decl
))
908 diag (N_("%Jprevious implicit declaration of '%D' was here"), decl
, decl
);
910 diag (N_("%Jprevious declaration of '%D' was here"), decl
, decl
);
913 /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL.
914 Returns true if the caller should proceed to merge the two, false
915 if OLDDECL should simply be discarded. As a side effect, issues
916 all necessary diagnostics for invalid or poor-style combinations.
917 If it returns true, writes the types of NEWDECL and OLDDECL to
918 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
919 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
922 diagnose_mismatched_decls (tree newdecl
, tree olddecl
,
923 tree
*newtypep
, tree
*oldtypep
)
925 tree newtype
, oldtype
;
926 bool pedwarned
= false;
929 /* If we have error_mark_node for either decl or type, just discard
930 the previous decl - we're in an error cascade already. */
931 if (olddecl
== error_mark_node
|| newdecl
== error_mark_node
)
933 *oldtypep
= oldtype
= TREE_TYPE (olddecl
);
934 *newtypep
= newtype
= TREE_TYPE (newdecl
);
935 if (oldtype
== error_mark_node
|| newtype
== error_mark_node
)
938 /* Two different categories of symbol altogether. This is an error
939 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
940 if (TREE_CODE (olddecl
) != TREE_CODE (newdecl
))
942 if (TREE_CODE (olddecl
) != FUNCTION_DECL
|| !DECL_BUILT_IN (olddecl
))
944 error ("%J'%D' redeclared as different kind of symbol",
946 locate_old_decl (olddecl
, error
);
948 else if (TREE_PUBLIC (newdecl
))
949 warning ("%Jbuilt-in function '%D' declared as non-function",
951 else if (warn_shadow
)
952 warning ("%Jshadowing built-in function '%D'",
957 if (!comptypes (oldtype
, newtype
, COMPARE_STRICT
))
959 if (TREE_CODE (olddecl
) == FUNCTION_DECL
&& DECL_BUILT_IN (olddecl
))
961 /* Accept harmless mismatch in function types.
962 This is for the ffs and fprintf builtins. */
963 tree trytype
= match_builtin_function_types (newtype
, oldtype
);
965 if (trytype
&& comptypes (newtype
, trytype
, COMPARE_STRICT
))
966 *oldtypep
= oldtype
= trytype
;
969 /* If types don't match for a built-in, throw away the
970 built-in. No point in calling locate_old_decl here, it
971 won't print anything. */
972 warning ("%Jconflicting types for built-in function '%D'",
977 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
978 && DECL_SOURCE_LINE (olddecl
) == 0)
980 /* A conflicting function declaration for a predeclared
981 function that isn't actually built in. Objective C uses
982 these. The new declaration silently overrides everything
983 but the volatility (i.e. noreturn) indication. See also
984 below. FIXME: Make Objective C use normal builtins. */
985 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
988 /* Permit void foo (...) to match int foo (...) if the latter is
989 the definition and implicit int was used. See
990 c-torture/compile/920625-2.c. */
991 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
&& DECL_INITIAL (newdecl
)
992 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype
)) == void_type_node
993 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype
)) == integer_type_node
994 && C_FUNCTION_IMPLICIT_INT (newdecl
))
996 pedwarn ("%Jconflicting types for '%D'", newdecl
, newdecl
);
997 /* Make sure we keep void as the return type. */
998 TREE_TYPE (newdecl
) = *newtypep
= newtype
= oldtype
;
999 C_FUNCTION_IMPLICIT_INT (newdecl
) = 0;
1004 error ("%Jconflicting types for '%D'", newdecl
, newdecl
);
1005 diagnose_arglist_conflict (newdecl
, olddecl
, newtype
, oldtype
);
1006 locate_old_decl (olddecl
, error
);
1011 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1012 but silently ignore the redeclaration if either is in a system
1013 header. (Conflicting redeclarations were handled above.) */
1014 if (TREE_CODE (newdecl
) == TYPE_DECL
)
1016 if (DECL_IN_SYSTEM_HEADER (newdecl
) || DECL_IN_SYSTEM_HEADER (olddecl
))
1017 return true; /* allow OLDDECL to continue in use */
1019 error ("%Jredefinition of typedef '%D'", newdecl
, newdecl
);
1020 locate_old_decl (olddecl
, error
);
1024 /* Function declarations can either be 'static' or 'extern' (no
1025 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1026 can never conflict with each other on account of linkage (6.2.2p4).
1027 Multiple definitions are not allowed (6.9p3,5) but GCC permits
1028 two definitions if one is 'extern inline' and one is not. The non-
1029 extern-inline definition supersedes the extern-inline definition. */
1030 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1032 if (DECL_BUILT_IN (olddecl
) && !TREE_PUBLIC (newdecl
))
1034 /* If you declare a built-in function name as static, the
1035 built-in definition is overridden,
1036 but optionally warn this was a bad choice of name. */
1038 warning ("%Jshadowing built-in function '%D'", newdecl
, newdecl
);
1039 /* Discard the old built-in function. */
1043 if (DECL_INITIAL (newdecl
))
1045 if (DECL_INITIAL (olddecl
)
1046 && !(DECL_DECLARED_INLINE_P (olddecl
)
1047 && DECL_EXTERNAL (olddecl
)
1048 && !(DECL_DECLARED_INLINE_P (newdecl
)
1049 && DECL_EXTERNAL (newdecl
))))
1051 error ("%Jredefinition of '%D'", newdecl
, newdecl
);
1052 locate_old_decl (olddecl
, error
);
1056 /* If we have a prototype after an old-style function definition,
1057 the argument types must be checked specially. */
1058 else if (DECL_INITIAL (olddecl
)
1059 && !TYPE_ARG_TYPES (oldtype
) && TYPE_ARG_TYPES (newtype
)
1060 && TYPE_ACTUAL_ARG_TYPES (oldtype
)
1061 && !validate_proto_after_old_defn (newdecl
, newtype
, oldtype
))
1063 locate_old_decl (olddecl
, error
);
1066 /* Mismatched non-static and static is considered poor style.
1067 We only diagnose static then non-static if -Wtraditional,
1068 because it is the most convenient way to get some effects
1069 (see e.g. what unwind-dw2-fde-glibc.c does to the definition
1070 of _Unwind_Find_FDE in unwind-dw2-fde.c). Revisit? */
1071 if (TREE_PUBLIC (olddecl
) && !TREE_PUBLIC (newdecl
))
1073 /* A static function declaration for a predeclared function
1074 that isn't actually built in, silently overrides the
1075 default. Objective C uses these. See also above.
1076 FIXME: Make Objective C use normal builtins. */
1077 if (TREE_CODE (olddecl
) == FUNCTION_DECL
1078 && DECL_SOURCE_LINE (olddecl
) == 0)
1082 warning ("%Jstatic declaration of '%D' follows "
1083 "non-static declaration", newdecl
, newdecl
);
1087 else if (TREE_PUBLIC (newdecl
) && !TREE_PUBLIC (olddecl
)
1088 && warn_traditional
)
1090 warning ("%Jnon-static declaration of '%D' follows "
1091 "static declaration", newdecl
, newdecl
);
1095 else if (TREE_CODE (newdecl
) == VAR_DECL
)
1097 /* Only variables can be thread-local, and all declarations must
1098 agree on this property. */
1099 if (DECL_THREAD_LOCAL (newdecl
) != DECL_THREAD_LOCAL (olddecl
))
1101 if (DECL_THREAD_LOCAL (newdecl
))
1102 error ("%Jthread-local declaration of '%D' follows "
1103 "non-thread-local declaration", newdecl
, newdecl
);
1105 error ("%Jnon-thread-local declaration of '%D' follows "
1106 "thread-local declaration", newdecl
, newdecl
);
1108 locate_old_decl (olddecl
, error
);
1112 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1113 if (DECL_INITIAL (newdecl
) && DECL_INITIAL (olddecl
))
1115 error ("%Jredefinition of '%D'", newdecl
, newdecl
);
1116 locate_old_decl (olddecl
, error
);
1120 /* Objects declared at file scope: if at least one is 'extern',
1121 it's fine (6.2.2p4); otherwise the linkage must agree (6.2.2p7). */
1122 if (DECL_FILE_SCOPE_P (newdecl
))
1124 if (!DECL_EXTERNAL (newdecl
)
1125 && !DECL_EXTERNAL (olddecl
)
1126 && TREE_PUBLIC (newdecl
) != TREE_PUBLIC (olddecl
))
1128 if (TREE_PUBLIC (newdecl
))
1129 error ("%Jnon-static declaration of '%D' follows "
1130 "static declaration", newdecl
, newdecl
);
1132 error ("%Jstatic declaration of '%D' follows "
1133 "non-static declaration", newdecl
, newdecl
);
1135 locate_old_decl (olddecl
, error
);
1139 /* Two objects with the same name declared at the same block
1140 scope must both be external references (6.7p3). */
1141 else if (DECL_CONTEXT (newdecl
) == DECL_CONTEXT (olddecl
)
1142 && (!DECL_EXTERNAL (newdecl
) || !DECL_EXTERNAL (olddecl
)))
1144 if (DECL_EXTERNAL (newdecl
))
1145 error ("%Jextern declaration of '%D' follows "
1146 "declaration with no linkage", newdecl
, newdecl
);
1147 else if (DECL_EXTERNAL (olddecl
))
1148 error ("%Jdeclaration of '%D' with no linkage follows "
1149 "extern declaration", newdecl
, newdecl
);
1151 error ("%Jredeclaration of '%D' with no linkage",
1154 locate_old_decl (olddecl
, error
);
1160 /* All decls must agree on a non-default visibility. */
1161 if (DECL_VISIBILITY (newdecl
) != VISIBILITY_DEFAULT
1162 && DECL_VISIBILITY (olddecl
) != VISIBILITY_DEFAULT
1163 && DECL_VISIBILITY (newdecl
) != DECL_VISIBILITY (olddecl
))
1165 warning ("%Jredeclaration of '%D' with different visibility "
1166 "(old visibility preserved)", newdecl
, newdecl
);
1170 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1172 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1173 if (DECL_DECLARED_INLINE_P (newdecl
)
1174 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
1176 warning ("%Jinline declaration of '%D' follows "
1177 "declaration with attribute noinline", newdecl
, newdecl
);
1180 else if (DECL_DECLARED_INLINE_P (olddecl
)
1181 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
)))
1183 warning ("%Jdeclaration of '%D' with attribute noinline follows "
1184 "inline declaration ", newdecl
, newdecl
);
1188 /* Inline declaration after use or definition.
1189 ??? Should we still warn about this now we have unit-at-a-time
1190 mode and can get it right? */
1191 if (DECL_DECLARED_INLINE_P (newdecl
) && !DECL_DECLARED_INLINE_P (olddecl
))
1193 if (TREE_USED (olddecl
))
1195 warning ("%J'%D' declared inline after being called",
1199 else if (DECL_INITIAL (olddecl
))
1201 warning ("%J'%D' declared inline after its definition",
1209 /* These bits are only type qualifiers when applied to objects. */
1210 if (TREE_THIS_VOLATILE (newdecl
) != TREE_THIS_VOLATILE (olddecl
))
1212 if (TREE_THIS_VOLATILE (newdecl
))
1213 pedwarn ("%Jvolatile declaration of '%D' follows "
1214 "non-volatile declaration", newdecl
, newdecl
);
1216 pedwarn ("%Jnon-volatile declaration of '%D' follows "
1217 "volatile declaration", newdecl
, newdecl
);
1220 if (TREE_READONLY (newdecl
) != TREE_READONLY (olddecl
))
1222 if (TREE_READONLY (newdecl
))
1223 pedwarn ("%Jconst declaration of '%D' follows "
1224 "non-const declaration", newdecl
, newdecl
);
1226 pedwarn ("%Jnon-const declaration of '%D' follows "
1227 "const declaration", newdecl
, newdecl
);
1232 /* Optional warning for completely redundant decls. */
1233 if (!warned
&& !pedwarned
1234 && warn_redundant_decls
1235 /* Don't warn about a function declaration followed by a
1237 && !(TREE_CODE (newdecl
) == FUNCTION_DECL
1238 && DECL_INITIAL (newdecl
) && !DECL_INITIAL (olddecl
))
1239 /* Don't warn about an extern followed by a definition. */
1240 && !(DECL_EXTERNAL (olddecl
) && !DECL_EXTERNAL (newdecl
)))
1242 warning ("%Jredundant redeclaration of '%D'", newdecl
, newdecl
);
1246 /* Report location of previous decl/defn in a consistent manner. */
1247 if (warned
|| pedwarned
)
1248 locate_old_decl (olddecl
, pedwarned
? pedwarn
: warning
);
1253 /* Subroutine of duplicate_decls. NEWDECL has been found to be
1254 consistent with OLDDECL, but carries new information. Merge the
1255 new information into OLDDECL. If DIFFERENT_BINDING_LEVEL or
1256 DIFFERENT_TU is true, avoid completely merging the decls, as this
1257 will break assumptions elsewhere. This function issues no
1261 merge_decls (tree newdecl
, tree olddecl
, tree newtype
, tree oldtype
,
1262 bool different_binding_level
, bool different_tu
)
1264 int new_is_definition
= (TREE_CODE (newdecl
) == FUNCTION_DECL
1265 && DECL_INITIAL (newdecl
) != 0);
1267 /* When copying info to olddecl, we store into write_olddecl
1268 instead. This allows us to avoid modifying olddecl when
1269 different_binding_level is true. */
1270 tree write_olddecl
= different_binding_level
? newdecl
: olddecl
;
1272 /* For real parm decl following a forward decl, return 1 so old decl
1273 will be reused. Only allow this to happen once. */
1274 if (TREE_CODE (newdecl
) == PARM_DECL
1275 && TREE_ASM_WRITTEN (olddecl
) && ! TREE_ASM_WRITTEN (newdecl
))
1277 TREE_ASM_WRITTEN (olddecl
) = 0;
1281 DECL_ATTRIBUTES (newdecl
)
1282 = (*targetm
.merge_decl_attributes
) (olddecl
, newdecl
);
1284 /* Merge the data types specified in the two decls. */
1285 if (TREE_CODE (newdecl
) != FUNCTION_DECL
|| !DECL_BUILT_IN (olddecl
))
1287 if (different_binding_level
)
1289 if (TYPE_ARG_TYPES (oldtype
) != 0
1290 && TYPE_ARG_TYPES (newtype
) == 0)
1291 TREE_TYPE (newdecl
) = common_type (newtype
, oldtype
);
1294 = build_type_attribute_variant
1296 merge_attributes (TYPE_ATTRIBUTES (newtype
),
1297 TYPE_ATTRIBUTES (oldtype
)));
1301 = TREE_TYPE (olddecl
)
1302 = common_type (newtype
, oldtype
);
1305 /* Lay the type out, unless already done. */
1306 if (oldtype
!= TREE_TYPE (newdecl
))
1308 if (TREE_TYPE (newdecl
) != error_mark_node
)
1309 layout_type (TREE_TYPE (newdecl
));
1310 if (TREE_CODE (newdecl
) != FUNCTION_DECL
1311 && TREE_CODE (newdecl
) != TYPE_DECL
1312 && TREE_CODE (newdecl
) != CONST_DECL
)
1313 layout_decl (newdecl
, 0);
1317 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1318 DECL_SIZE (newdecl
) = DECL_SIZE (olddecl
);
1319 DECL_SIZE_UNIT (newdecl
) = DECL_SIZE_UNIT (olddecl
);
1320 DECL_MODE (newdecl
) = DECL_MODE (olddecl
);
1321 if (TREE_CODE (olddecl
) != FUNCTION_DECL
)
1322 if (DECL_ALIGN (olddecl
) > DECL_ALIGN (newdecl
))
1324 DECL_ALIGN (newdecl
) = DECL_ALIGN (olddecl
);
1325 DECL_USER_ALIGN (newdecl
) |= DECL_ALIGN (olddecl
);
1329 /* Keep the old rtl since we can safely use it. */
1330 COPY_DECL_RTL (olddecl
, newdecl
);
1332 /* Merge the type qualifiers. */
1333 if (TREE_READONLY (newdecl
))
1334 TREE_READONLY (write_olddecl
) = 1;
1336 if (TREE_THIS_VOLATILE (newdecl
))
1338 TREE_THIS_VOLATILE (write_olddecl
) = 1;
1339 if (TREE_CODE (newdecl
) == VAR_DECL
)
1340 make_var_volatile (newdecl
);
1343 /* Keep source location of definition rather than declaration. */
1344 /* When called with different_binding_level set, keep the old
1345 information so that meaningful diagnostics can be given. */
1346 if (DECL_INITIAL (newdecl
) == 0 && DECL_INITIAL (olddecl
) != 0
1347 && ! different_binding_level
)
1348 DECL_SOURCE_LOCATION (newdecl
) = DECL_SOURCE_LOCATION (olddecl
);
1350 /* Merge the unused-warning information. */
1351 if (DECL_IN_SYSTEM_HEADER (olddecl
))
1352 DECL_IN_SYSTEM_HEADER (newdecl
) = 1;
1353 else if (DECL_IN_SYSTEM_HEADER (newdecl
))
1354 DECL_IN_SYSTEM_HEADER (write_olddecl
) = 1;
1356 /* Merge the initialization information. */
1357 /* When called with different_binding_level set, don't copy over
1358 DECL_INITIAL, so that we don't accidentally change function
1359 declarations into function definitions. */
1360 if (DECL_INITIAL (newdecl
) == 0 && ! different_binding_level
)
1361 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1363 /* Merge the section attribute.
1364 We want to issue an error if the sections conflict but that must be
1365 done later in decl_attributes since we are called before attributes
1367 if (DECL_SECTION_NAME (newdecl
) == NULL_TREE
)
1368 DECL_SECTION_NAME (newdecl
) = DECL_SECTION_NAME (olddecl
);
1370 /* Copy the assembler name.
1371 Currently, it can only be defined in the prototype. */
1372 COPY_DECL_ASSEMBLER_NAME (olddecl
, newdecl
);
1374 /* If either declaration has a nondefault visibility, use it. */
1375 if (DECL_VISIBILITY (olddecl
) != VISIBILITY_DEFAULT
)
1376 DECL_VISIBILITY (newdecl
) = DECL_VISIBILITY (olddecl
);
1378 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1380 DECL_STATIC_CONSTRUCTOR(newdecl
) |= DECL_STATIC_CONSTRUCTOR(olddecl
);
1381 DECL_STATIC_DESTRUCTOR (newdecl
) |= DECL_STATIC_DESTRUCTOR (olddecl
);
1382 DECL_NO_LIMIT_STACK (newdecl
) |= DECL_NO_LIMIT_STACK (olddecl
);
1383 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl
)
1384 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl
);
1385 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1386 TREE_READONLY (newdecl
) |= TREE_READONLY (olddecl
);
1387 DECL_IS_MALLOC (newdecl
) |= DECL_IS_MALLOC (olddecl
);
1388 DECL_IS_PURE (newdecl
) |= DECL_IS_PURE (olddecl
);
1391 /* Merge the storage class information. */
1392 merge_weak (newdecl
, olddecl
);
1394 /* For functions, static overrides non-static. */
1395 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1397 TREE_PUBLIC (newdecl
) &= TREE_PUBLIC (olddecl
);
1398 /* This is since we don't automatically
1399 copy the attributes of NEWDECL into OLDDECL. */
1400 /* No need to worry about different_binding_level here because
1401 then TREE_PUBLIC (newdecl) was true. */
1402 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1403 /* If this clears `static', clear it in the identifier too. */
1404 if (! TREE_PUBLIC (olddecl
))
1405 TREE_PUBLIC (DECL_NAME (olddecl
)) = 0;
1407 if (DECL_EXTERNAL (newdecl
))
1409 if (! different_binding_level
|| different_tu
)
1411 /* Don't mess with these flags on local externs; they remain
1412 external even if there's a declaration at file scope which
1414 TREE_STATIC (newdecl
) = TREE_STATIC (olddecl
);
1415 DECL_EXTERNAL (newdecl
) = DECL_EXTERNAL (olddecl
);
1417 /* An extern decl does not override previous storage class. */
1418 TREE_PUBLIC (newdecl
) = TREE_PUBLIC (olddecl
);
1419 if (! DECL_EXTERNAL (newdecl
))
1421 DECL_CONTEXT (newdecl
) = DECL_CONTEXT (olddecl
);
1422 DECL_COMMON (newdecl
) = DECL_COMMON (olddecl
);
1423 /* If we have two non-EXTERNAL file-scope decls that are
1424 the same, only one of them should be written out. */
1426 TREE_ASM_WRITTEN (newdecl
) = 1;
1431 TREE_STATIC (olddecl
) = TREE_STATIC (newdecl
);
1432 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1435 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1437 /* If we're redefining a function previously defined as extern
1438 inline, make sure we emit debug info for the inline before we
1439 throw it away, in case it was inlined into a function that hasn't
1440 been written out yet. */
1441 if (new_is_definition
&& DECL_INITIAL (olddecl
))
1443 if (TREE_USED (olddecl
)
1444 /* In unit-at-a-time mode we never inline re-defined extern
1445 inline functions. */
1446 && !flag_unit_at_a_time
1447 && cgraph_function_possibly_inlined_p (olddecl
))
1448 (*debug_hooks
->outlining_inline_function
) (olddecl
);
1450 /* The new defn must not be inline. */
1451 DECL_INLINE (newdecl
) = 0;
1452 DECL_UNINLINABLE (newdecl
) = 1;
1456 /* If either decl says `inline', this fn is inline,
1457 unless its definition was passed already. */
1458 if (DECL_DECLARED_INLINE_P (newdecl
)
1459 || DECL_DECLARED_INLINE_P (olddecl
))
1460 DECL_DECLARED_INLINE_P (newdecl
) = 1;
1462 DECL_UNINLINABLE (newdecl
) = DECL_UNINLINABLE (olddecl
)
1463 = (DECL_UNINLINABLE (newdecl
) || DECL_UNINLINABLE (olddecl
));
1466 if (DECL_BUILT_IN (olddecl
))
1468 /* Get rid of any built-in function if we have a function
1470 if (new_is_definition
)
1472 if (! different_binding_level
)
1474 TREE_TYPE (olddecl
) = TREE_TYPE (newdecl
);
1475 DECL_BUILT_IN_CLASS (olddecl
) = NOT_BUILT_IN
;
1480 /* If redeclaring a builtin function, and not a definition,
1481 it stays built in. */
1482 DECL_BUILT_IN_CLASS (newdecl
) = DECL_BUILT_IN_CLASS (olddecl
);
1483 DECL_FUNCTION_CODE (newdecl
) = DECL_FUNCTION_CODE (olddecl
);
1487 /* Also preserve various other info from the definition. */
1488 if (! new_is_definition
)
1490 DECL_RESULT (newdecl
) = DECL_RESULT (olddecl
);
1491 /* When called with different_binding_level set, don't copy over
1492 DECL_INITIAL, so that we don't accidentally change function
1493 declarations into function definitions. */
1494 if (! different_binding_level
)
1495 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1496 DECL_SAVED_INSNS (newdecl
) = DECL_SAVED_INSNS (olddecl
);
1497 DECL_SAVED_TREE (newdecl
) = DECL_SAVED_TREE (olddecl
);
1498 DECL_ESTIMATED_INSNS (newdecl
) = DECL_ESTIMATED_INSNS (olddecl
);
1499 DECL_ARGUMENTS (newdecl
) = DECL_ARGUMENTS (olddecl
);
1501 /* Set DECL_INLINE on the declaration if we've got a body
1502 from which to instantiate. */
1503 if (DECL_INLINE (olddecl
) && ! DECL_UNINLINABLE (newdecl
))
1505 DECL_INLINE (newdecl
) = 1;
1506 DECL_ABSTRACT_ORIGIN (newdecl
)
1507 = (different_binding_level
1508 ? DECL_ORIGIN (olddecl
)
1509 : DECL_ABSTRACT_ORIGIN (olddecl
));
1514 /* If a previous declaration said inline, mark the
1515 definition as inlinable. */
1516 if (DECL_DECLARED_INLINE_P (newdecl
)
1517 && ! DECL_UNINLINABLE (newdecl
))
1518 DECL_INLINE (newdecl
) = 1;
1521 if (different_binding_level
)
1524 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1525 But preserve OLDDECL's DECL_UID. */
1527 unsigned olddecl_uid
= DECL_UID (olddecl
);
1529 memcpy ((char *) olddecl
+ sizeof (struct tree_common
),
1530 (char *) newdecl
+ sizeof (struct tree_common
),
1531 sizeof (struct tree_decl
) - sizeof (struct tree_common
));
1532 DECL_UID (olddecl
) = olddecl_uid
;
1535 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1536 so that encode_section_info has a chance to look at the new decl
1537 flags and attributes. */
1538 if (DECL_RTL_SET_P (olddecl
)
1539 && (TREE_CODE (olddecl
) == FUNCTION_DECL
1540 || (TREE_CODE (olddecl
) == VAR_DECL
1541 && TREE_STATIC (olddecl
))))
1542 make_decl_rtl (olddecl
, NULL
);
1545 /* Handle when a new declaration NEWDECL has the same name as an old
1546 one OLDDECL in the same binding contour. Prints an error message
1549 If safely possible, alter OLDDECL to look like NEWDECL, and return
1550 true. Otherwise, return false.
1552 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external
1553 declaration, and OLDDECL is in an outer scope and should thus not
1557 duplicate_decls (tree newdecl
, tree olddecl
,
1558 bool different_binding_level
, bool different_tu
)
1560 tree newtype
, oldtype
;
1562 if (!diagnose_mismatched_decls (newdecl
, olddecl
, &newtype
, &oldtype
))
1565 merge_decls (newdecl
, olddecl
, newtype
, oldtype
,
1566 different_binding_level
, different_tu
);
1567 return !different_binding_level
;
1571 /* Return any external DECL associated with ID, whether or not it is
1572 currently in scope. */
1575 any_external_decl (tree id
)
1577 tree decl
= IDENTIFIER_SYMBOL_VALUE (id
);
1580 if (decl
== 0 || TREE_CODE (decl
) == ERROR_MARK
)
1582 else if (TREE_CODE (decl
) != TYPE_DECL
&& DECL_EXTERNAL (decl
))
1585 t
= purpose_member (id
, truly_local_externals
);
1587 return TREE_VALUE (t
);
1592 /* Record an external decl DECL. This only does something if a
1593 shadowing decl already exists. */
1595 record_external_decl (tree decl
)
1597 tree name
= DECL_NAME (decl
);
1598 if (!IDENTIFIER_SYMBOL_VALUE (name
))
1601 truly_local_externals
= tree_cons (name
, decl
, truly_local_externals
);
1604 /* Check whether decl-node X shadows an existing declaration.
1605 OLD is the old IDENTIFIER_SYMBOL_VALUE of the DECL_NAME of X,
1606 which might be a NULL_TREE. */
1608 warn_if_shadowing (tree x
, tree old
)
1612 /* Nothing to shadow? */
1614 /* Shadow warnings not wanted? */
1616 /* No shadow warnings for internally generated vars. */
1617 || DECL_SOURCE_LINE (x
) == 0
1618 /* No shadow warnings for vars made for inlining. */
1619 || DECL_FROM_INLINE (x
)
1620 /* Don't warn about the parm names in function declarator
1621 within a function declarator.
1622 It would be nice to avoid warning in any function
1623 declarator in a declaration, as opposed to a definition,
1624 but there is no way to tell it's not a definition. */
1625 || (TREE_CODE (x
) == PARM_DECL
&& current_scope
->outer
->parm_flag
))
1628 name
= IDENTIFIER_POINTER (DECL_NAME (x
));
1629 if (TREE_CODE (old
) == PARM_DECL
)
1630 shadow_warning (SW_PARAM
, name
, old
);
1631 else if (DECL_FILE_SCOPE_P (old
))
1632 shadow_warning (SW_GLOBAL
, name
, old
);
1634 shadow_warning (SW_LOCAL
, name
, old
);
1638 /* Subroutine of pushdecl.
1640 X is a TYPE_DECL for a typedef statement. Create a brand new
1641 ..._TYPE node (which will be just a variant of the existing
1642 ..._TYPE node with identical properties) and then install X
1643 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
1645 The whole point here is to end up with a situation where each
1646 and every ..._TYPE node the compiler creates will be uniquely
1647 associated with AT MOST one node representing a typedef name.
1648 This way, even though the compiler substitutes corresponding
1649 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
1650 early on, later parts of the compiler can always do the reverse
1651 translation and get back the corresponding typedef name. For
1654 typedef struct S MY_TYPE;
1657 Later parts of the compiler might only know that `object' was of
1658 type `struct S' if it were not for code just below. With this
1659 code however, later parts of the compiler see something like:
1661 struct S' == struct S
1662 typedef struct S' MY_TYPE;
1665 And they can then deduce (from the node for type struct S') that
1666 the original object declaration was:
1670 Being able to do this is important for proper support of protoize,
1671 and also for generating precise symbolic debugging information
1672 which takes full account of the programmer's (typedef) vocabulary.
1674 Obviously, we don't want to generate a duplicate ..._TYPE node if
1675 the TYPE_DECL node that we are now processing really represents a
1676 standard built-in type.
1678 Since all standard types are effectively declared at line zero
1679 in the source file, we can easily check to see if we are working
1680 on a standard type by checking the current value of lineno. */
1683 clone_underlying_type (tree x
)
1685 if (DECL_SOURCE_LINE (x
) == 0)
1687 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
1688 TYPE_NAME (TREE_TYPE (x
)) = x
;
1690 else if (TREE_TYPE (x
) != error_mark_node
1691 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
1693 tree tt
= TREE_TYPE (x
);
1694 DECL_ORIGINAL_TYPE (x
) = tt
;
1695 tt
= build_type_copy (tt
);
1697 TREE_USED (tt
) = TREE_USED (x
);
1702 /* Record a decl-node X as belonging to the current lexical scope.
1703 Check for errors (such as an incompatible declaration for the same
1704 name already seen in the same scope).
1706 Returns either X or an old decl for the same name.
1707 If an old decl is returned, it may have been smashed
1708 to agree with what X says. */
1713 tree name
= DECL_NAME (x
);
1714 struct c_scope
*scope
= current_scope
;
1716 #ifdef ENABLE_CHECKING
1717 if (error_mark_node
== 0)
1718 /* Called too early. */
1722 /* Functions need the lang_decl data. */
1723 if (TREE_CODE (x
) == FUNCTION_DECL
&& ! DECL_LANG_SPECIFIC (x
))
1724 DECL_LANG_SPECIFIC (x
) = ggc_alloc_cleared (sizeof (struct lang_decl
));
1726 /* A local extern declaration for a function doesn't constitute nesting.
1727 A local auto declaration does, since it's a forward decl
1728 for a nested function coming later. */
1729 if (current_function_decl
== NULL
1730 || ((TREE_CODE (x
) == FUNCTION_DECL
|| TREE_CODE (x
) == VAR_DECL
)
1731 && DECL_INITIAL (x
) == 0 && DECL_EXTERNAL (x
)))
1732 DECL_CONTEXT (x
) = current_file_decl
;
1734 DECL_CONTEXT (x
) = current_function_decl
;
1740 if (warn_nested_externs
1741 && scope
!= global_scope
1742 && DECL_EXTERNAL (x
)
1743 && !DECL_IN_SYSTEM_HEADER (x
))
1744 warning ("nested extern declaration of `%s'",
1745 IDENTIFIER_POINTER (name
));
1747 old
= lookup_name_current_level (name
);
1748 if (old
&& duplicate_decls (x
, old
, 0, false))
1750 /* For PARM_DECLs, old may be a forward declaration.
1751 If so, we want to remove it from its old location
1752 (in the variables chain) and rechain it in the
1753 location given by the new declaration. */
1754 if (TREE_CODE (x
) == PARM_DECL
)
1757 for (p
= &scope
->names
; *p
; p
= &TREE_CHAIN (*p
))
1760 *p
= TREE_CHAIN (old
);
1761 SCOPE_LIST_APPEND (scope
, parms
, old
);
1767 if (DECL_EXTERNAL (x
) || scope
== global_scope
)
1769 /* Find and check against a previous, not-in-scope, external
1770 decl for this identifier. (C99 6.2.7p2: All declarations
1771 that refer to the same object or function shall have
1772 compatible type; otherwise, the behavior is undefined.) */
1773 tree ext
= any_external_decl (name
);
1776 if (duplicate_decls (x
, ext
, scope
!= global_scope
,
1778 x
= copy_node (ext
);
1781 record_external_decl (x
);
1784 if (TREE_CODE (x
) == TYPE_DECL
)
1785 clone_underlying_type (x
);
1787 /* If storing a local value, there may already be one
1788 (inherited). If so, record it for restoration when this
1789 scope ends. Take care not to do this if we are replacing an
1790 older decl in the same scope (i.e. duplicate_decls returned
1792 if (scope
!= global_scope
1793 && IDENTIFIER_SYMBOL_VALUE (name
)
1794 && IDENTIFIER_SYMBOL_VALUE (name
) != old
)
1796 warn_if_shadowing (x
, IDENTIFIER_SYMBOL_VALUE (name
));
1797 scope
->shadowed
= tree_cons (name
, IDENTIFIER_SYMBOL_VALUE (name
),
1801 /* Install the new declaration in the requested scope. */
1802 IDENTIFIER_SYMBOL_VALUE (name
) = x
;
1803 C_DECL_INVISIBLE (x
) = 0;
1805 /* If x's type is incomplete because it's based on a
1806 structure or union which has not yet been fully declared,
1807 attach it to that structure or union type, so we can go
1808 back and complete the variable declaration later, if the
1809 structure or union gets fully declared.
1811 If the input is erroneous, we can have error_mark in the type
1812 slot (e.g. "f(void a, ...)") - that doesn't count as an
1814 if (TREE_TYPE (x
) != error_mark_node
1815 && !COMPLETE_TYPE_P (TREE_TYPE (x
)))
1817 tree element
= TREE_TYPE (x
);
1819 while (TREE_CODE (element
) == ARRAY_TYPE
)
1820 element
= TREE_TYPE (element
);
1821 element
= TYPE_MAIN_VARIANT (element
);
1823 if ((TREE_CODE (element
) == RECORD_TYPE
1824 || TREE_CODE (element
) == UNION_TYPE
)
1825 && (TREE_CODE (x
) != TYPE_DECL
1826 || TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
)
1827 && !COMPLETE_TYPE_P (element
))
1828 C_TYPE_INCOMPLETE_VARS (element
)
1829 = tree_cons (NULL_TREE
, x
, C_TYPE_INCOMPLETE_VARS (element
));
1833 if (TREE_CODE (x
) == PARM_DECL
)
1834 SCOPE_LIST_APPEND (scope
, parms
, x
);
1836 SCOPE_LIST_APPEND (scope
, names
, x
);
1841 /* Record X as belonging to the global scope (C99 "file scope").
1842 This is used only internally by the Objective-C front end,
1843 and is limited to its needs. duplicate_decls is not called;
1844 if there is any preexisting decl for this identifier, it is an ICE. */
1847 pushdecl_top_level (tree x
)
1851 if (TREE_CODE (x
) != VAR_DECL
)
1854 name
= DECL_NAME (x
);
1856 if (IDENTIFIER_SYMBOL_VALUE (name
))
1859 DECL_CONTEXT (x
) = current_file_decl
;
1860 IDENTIFIER_SYMBOL_VALUE (name
) = x
;
1862 SCOPE_LIST_APPEND (global_scope
, names
, x
);
1866 /* Generate an implicit declaration for identifier FUNCTIONID as a
1867 function of type int (). */
1870 implicitly_declare (tree functionid
)
1872 tree decl
= any_external_decl (functionid
);
1876 /* Implicit declaration of a function already declared
1877 (somehow) in a different scope, or as a built-in.
1878 If this is the first time this has happened, warn;
1879 then recycle the old declaration. */
1880 if (!C_DECL_IMPLICIT (decl
))
1882 implicit_decl_warning (DECL_NAME (decl
));
1883 if (! DECL_FILE_SCOPE_P (decl
))
1884 warning ("%Jprevious declaration of '%D'", decl
, decl
);
1885 C_DECL_IMPLICIT (decl
) = 1;
1887 /* If this function is global, then it must already be in the
1888 global scope, so there's no need to push it again. */
1889 if (current_scope
== global_scope
)
1891 /* If this is a local declaration, make a copy; we can't have
1892 the same DECL listed in two different scopes. */
1893 return pushdecl (copy_node (decl
));
1896 /* Not seen before. */
1897 decl
= build_decl (FUNCTION_DECL
, functionid
, default_function_type
);
1898 DECL_EXTERNAL (decl
) = 1;
1899 TREE_PUBLIC (decl
) = 1;
1900 C_DECL_IMPLICIT (decl
) = 1;
1901 implicit_decl_warning (functionid
);
1903 /* C89 says implicit declarations are in the innermost block.
1904 So we record the decl in the standard fashion. */
1905 decl
= pushdecl (decl
);
1907 /* No need to call objc_check_decl here - it's a function type. */
1908 rest_of_decl_compilation (decl
, NULL
, 0, 0);
1910 /* Write a record describing this implicit function declaration
1911 to the prototypes file (if requested). */
1912 gen_aux_info_record (decl
, 0, 1, 0);
1914 /* Possibly apply some default attributes to this implicit declaration. */
1915 decl_attributes (&decl
, NULL_TREE
, 0);
1921 implicit_decl_warning (tree id
)
1923 const char *name
= IDENTIFIER_POINTER (id
);
1924 if (mesg_implicit_function_declaration
== 2)
1925 error ("implicit declaration of function `%s'", name
);
1926 else if (mesg_implicit_function_declaration
== 1)
1927 warning ("implicit declaration of function `%s'", name
);
1930 /* Issue an error message for a reference to an undeclared variable
1931 ID, including a reference to a builtin outside of function-call
1932 context. Establish a binding of the identifier to error_mark_node
1933 in an appropriate scope, which will suppress further errors for the
1936 undeclared_variable (tree id
)
1938 static bool already
= false;
1939 struct c_scope
*scope
;
1941 if (current_function_decl
== 0)
1943 error ("`%s' undeclared here (not in a function)",
1944 IDENTIFIER_POINTER (id
));
1945 scope
= current_scope
;
1949 error ("`%s' undeclared (first use in this function)",
1950 IDENTIFIER_POINTER (id
));
1954 error ("(Each undeclared identifier is reported only once");
1955 error ("for each function it appears in.)");
1959 scope
= current_function_scope
;
1962 scope
->shadowed
= tree_cons (id
, IDENTIFIER_SYMBOL_VALUE (id
),
1964 IDENTIFIER_SYMBOL_VALUE (id
) = error_mark_node
;
1967 /* Subroutine of lookup_label, declare_label, define_label: construct a
1968 LABEL_DECL with all the proper frills. */
1971 make_label (tree name
, location_t location
)
1973 tree label
= build_decl (LABEL_DECL
, name
, void_type_node
);
1975 DECL_CONTEXT (label
) = current_function_decl
;
1976 DECL_MODE (label
) = VOIDmode
;
1977 DECL_SOURCE_LOCATION (label
) = location
;
1982 /* Another subroutine of lookup_label, declare_label, define_label:
1983 set up the binding of name to LABEL_DECL in the given SCOPE. */
1986 bind_label (tree name
, tree label
, struct c_scope
*scope
)
1988 if (IDENTIFIER_LABEL_VALUE (name
))
1989 scope
->shadowed
= tree_cons (name
, IDENTIFIER_LABEL_VALUE (name
),
1991 IDENTIFIER_LABEL_VALUE (name
) = label
;
1993 SCOPE_LIST_APPEND (scope
, names
, label
);
1996 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
1997 Create one if none exists so far for the current function.
1998 This is called when a label is used in a goto expression or
1999 has its address taken. */
2002 lookup_label (tree name
)
2006 if (current_function_decl
== 0)
2008 error ("label %s referenced outside of any function",
2009 IDENTIFIER_POINTER (name
));
2013 /* Use a label already defined or ref'd with this name, but not if
2014 it is inherited from a containing function and wasn't declared
2016 label
= IDENTIFIER_LABEL_VALUE (name
);
2017 if (label
&& (DECL_CONTEXT (label
) == current_function_decl
2018 || C_DECLARED_LABEL_FLAG (label
)))
2020 /* If the label has only been declared, update its apparent
2021 location to point here, for better diagnostics if it
2022 turns out not to have been defined. */
2023 if (!TREE_USED (label
))
2024 DECL_SOURCE_LOCATION (label
) = input_location
;
2028 /* No label binding for that identifier; make one. */
2029 label
= make_label (name
, input_location
);
2031 /* Ordinary labels go in the current function scope. */
2032 bind_label (name
, label
, current_function_scope
);
2036 /* Make a label named NAME in the current function, shadowing silently
2037 any that may be inherited from containing functions or containing
2038 scopes. This is called for __label__ declarations. */
2040 /* Note that valid use, if the label being shadowed comes from another
2041 scope in the same function, requires calling declare_nonlocal_label
2042 right away. (Is this still true? -zw 2003-07-17) */
2045 declare_label (tree name
)
2047 tree label
= IDENTIFIER_LABEL_VALUE (name
);
2050 /* Check to make sure that the label hasn't already been declared
2052 for (dup
= current_scope
->names
; dup
; dup
= TREE_CHAIN (dup
))
2055 error ("duplicate label declaration `%s'", IDENTIFIER_POINTER (name
));
2056 error ("%Jthis is a previous declaration", dup
);
2058 /* Just use the previous declaration. */
2062 label
= make_label (name
, input_location
);
2063 C_DECLARED_LABEL_FLAG (label
) = 1;
2065 /* Declared labels go in the current scope. */
2066 bind_label (name
, label
, current_scope
);
2070 /* Define a label, specifying the location in the source file.
2071 Return the LABEL_DECL node for the label, if the definition is valid.
2072 Otherwise return 0. */
2075 define_label (location_t location
, tree name
)
2079 /* Find any preexisting label with this name. It is an error
2080 if that label has already been defined in this function, or
2081 if there is a containing function with a declared label with
2083 label
= IDENTIFIER_LABEL_VALUE (name
);
2086 && ((DECL_CONTEXT (label
) == current_function_decl
2087 && DECL_INITIAL (label
) != 0)
2088 || (DECL_CONTEXT (label
) != current_function_decl
2089 && C_DECLARED_LABEL_FLAG (label
))))
2091 error ("%Hduplicate label `%D'", &location
, label
);
2092 if (DECL_INITIAL (label
))
2093 error ("%J`%D' previously defined here", label
, label
);
2095 error ("%J`%D' previously declared here", label
, label
);
2098 else if (label
&& DECL_CONTEXT (label
) == current_function_decl
)
2100 /* The label has been used or declared already in this function,
2101 but not defined. Update its location to point to this
2103 DECL_SOURCE_LOCATION (label
) = location
;
2107 /* No label binding for that identifier; make one. */
2108 label
= make_label (name
, location
);
2110 /* Ordinary labels go in the current function scope. */
2111 bind_label (name
, label
, current_function_scope
);
2114 if (warn_traditional
&& !in_system_header
&& lookup_name (name
))
2115 warning ("%Htraditional C lacks a separate namespace for labels, "
2116 "identifier `%s' conflicts", &location
,
2117 IDENTIFIER_POINTER (name
));
2119 /* Mark label as having been defined. */
2120 DECL_INITIAL (label
) = error_mark_node
;
2124 /* Return the list of declarations of the current scope. */
2129 return current_scope
->names
;
2133 /* Given NAME, an IDENTIFIER_NODE,
2134 return the structure (or union or enum) definition for that name.
2135 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2136 CODE says which kind of type the caller wants;
2137 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2138 If the wrong kind of type is found, an error is reported. */
2141 lookup_tag (enum tree_code code
, tree name
, int thislevel_only
)
2143 tree tag
= IDENTIFIER_TAG_VALUE (name
);
2149 /* We only care about whether it's in this level if
2150 thislevel_only was set or it might be a type clash. */
2151 if (thislevel_only
|| TREE_CODE (tag
) != code
)
2153 if (current_scope
== global_scope
2154 || purpose_member (name
, current_scope
->tags
))
2158 if (thislevel_only
&& !thislevel
)
2161 if (TREE_CODE (tag
) != code
)
2163 /* Definition isn't the kind we were looking for. */
2164 pending_invalid_xref
= name
;
2165 pending_invalid_xref_location
= input_location
;
2167 /* If in the same binding level as a declaration as a tag
2168 of a different type, this must not be allowed to
2169 shadow that tag, so give the error immediately.
2170 (For example, "struct foo; union foo;" is invalid.) */
2172 pending_xref_error ();
2177 /* Print an error message now
2178 for a recent invalid struct, union or enum cross reference.
2179 We don't print them immediately because they are not invalid
2180 when used in the `struct foo;' construct for shadowing. */
2183 pending_xref_error (void)
2185 if (pending_invalid_xref
!= 0)
2186 error ("%H`%s' defined as wrong kind of tag",
2187 &pending_invalid_xref_location
,
2188 IDENTIFIER_POINTER (pending_invalid_xref
));
2189 pending_invalid_xref
= 0;
2193 /* Look up NAME in the current scope and its superiors
2194 in the namespace of variables, functions and typedefs.
2195 Return a ..._DECL node of some kind representing its definition,
2196 or return 0 if it is undefined. */
2199 lookup_name (tree name
)
2201 tree decl
= IDENTIFIER_SYMBOL_VALUE (name
);
2202 if (decl
== 0 || decl
== error_mark_node
)
2204 if (C_DECL_INVISIBLE (decl
))
2209 /* Similar to `lookup_name' but look only at the current scope. */
2212 lookup_name_current_level (tree name
)
2214 tree decl
= IDENTIFIER_SYMBOL_VALUE (name
);
2216 if (decl
== 0 || decl
== error_mark_node
|| C_DECL_INVISIBLE (decl
))
2219 if (current_scope
== global_scope
)
2222 /* Scan the current scope for a decl with name NAME.
2223 For PARM_DECLs, we have to look at both ->parms and ->names, since
2224 forward parameter declarations wind up on the ->names list. */
2225 if (TREE_CODE (decl
) == PARM_DECL
2226 && chain_member (decl
, current_scope
->parms
))
2228 if (chain_member (decl
, current_scope
->names
))
2234 /* Create the predefined scalar types of C,
2235 and some nodes representing standard constants (0, 1, (void *) 0).
2236 Initialize the global scope.
2237 Make definitions for built-in primitive functions. */
2240 c_init_decl_processing (void)
2243 tree ptr_ftype_void
, ptr_ftype_ptr
;
2244 location_t save_loc
= input_location
;
2246 /* Adds some ggc roots, and reserved words for c-parse.in. */
2249 current_function_decl
= 0;
2251 /* Make the c_scope structure for global names. */
2253 global_scope
= current_scope
;
2255 /* Declarations from c_common_nodes_and_builtins must not be associated
2256 with this input file, lest we get differences between using and not
2257 using preprocessed headers. */
2258 input_location
.file
= "<internal>";
2259 input_location
.line
= 0;
2261 /* Make the DECL for the toplevel file scope. */
2262 current_file_decl
= build_decl (TRANSLATION_UNIT_DECL
, NULL
, NULL
);
2264 build_common_tree_nodes (flag_signed_char
);
2266 c_common_nodes_and_builtins ();
2268 /* In C, comparisons and TRUTH_* expressions have type int. */
2269 truthvalue_type_node
= integer_type_node
;
2270 truthvalue_true_node
= integer_one_node
;
2271 truthvalue_false_node
= integer_zero_node
;
2273 /* Even in C99, which has a real boolean type. */
2274 pushdecl (build_decl (TYPE_DECL
, get_identifier ("_Bool"),
2275 boolean_type_node
));
2277 endlink
= void_list_node
;
2278 ptr_ftype_void
= build_function_type (ptr_type_node
, endlink
);
2280 = build_function_type (ptr_type_node
,
2281 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
2283 input_location
= save_loc
;
2285 pedantic_lvalues
= pedantic
;
2287 make_fname_decl
= c_make_fname_decl
;
2288 start_fname_decls ();
2290 first_builtin_decl
= global_scope
->names
;
2291 last_builtin_decl
= global_scope
->names_last
;
2294 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2295 decl, NAME is the initialization string and TYPE_DEP indicates whether
2296 NAME depended on the type of the function. As we don't yet implement
2297 delayed emission of static data, we mark the decl as emitted
2298 so it is not placed in the output. Anything using it must therefore pull
2299 out the STRING_CST initializer directly. FIXME. */
2302 c_make_fname_decl (tree id
, int type_dep
)
2304 const char *name
= fname_as_string (type_dep
);
2305 tree decl
, type
, init
;
2306 size_t length
= strlen (name
);
2308 type
= build_array_type
2309 (build_qualified_type (char_type_node
, TYPE_QUAL_CONST
),
2310 build_index_type (size_int (length
)));
2312 decl
= build_decl (VAR_DECL
, id
, type
);
2314 TREE_STATIC (decl
) = 1;
2315 TREE_READONLY (decl
) = 1;
2316 DECL_ARTIFICIAL (decl
) = 1;
2318 init
= build_string (length
+ 1, name
);
2319 TREE_TYPE (init
) = type
;
2320 DECL_INITIAL (decl
) = init
;
2322 TREE_USED (decl
) = 1;
2324 if (current_function_decl
)
2326 DECL_CONTEXT (decl
) = current_function_decl
;
2327 IDENTIFIER_SYMBOL_VALUE (id
) = decl
;
2328 SCOPE_LIST_APPEND (current_function_scope
, names
, decl
);
2331 finish_decl (decl
, init
, NULL_TREE
);
2336 /* Return a definition for a builtin function named NAME and whose data type
2337 is TYPE. TYPE should be a function type with argument types.
2338 FUNCTION_CODE tells later passes how to compile calls to this function.
2339 See tree.h for its possible values.
2341 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
2342 the name to be called if we can't opencode the function. If
2343 ATTRS is nonzero, use that for the function's attribute list. */
2346 builtin_function (const char *name
, tree type
, int function_code
,
2347 enum built_in_class
class, const char *library_name
,
2350 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
), type
);
2351 DECL_EXTERNAL (decl
) = 1;
2352 TREE_PUBLIC (decl
) = 1;
2354 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (library_name
));
2355 make_decl_rtl (decl
, NULL
);
2357 DECL_BUILT_IN_CLASS (decl
) = class;
2358 DECL_FUNCTION_CODE (decl
) = function_code
;
2360 /* Warn if a function in the namespace for users
2361 is used without an occasion to consider it declared. */
2362 if (name
[0] != '_' || name
[1] != '_')
2363 C_DECL_INVISIBLE (decl
) = 1;
2365 /* Possibly apply some default attributes to this built-in function. */
2367 decl_attributes (&decl
, attrs
, ATTR_FLAG_BUILT_IN
);
2369 decl_attributes (&decl
, NULL_TREE
, 0);
2374 /* Called when a declaration is seen that contains no names to declare.
2375 If its type is a reference to a structure, union or enum inherited
2376 from a containing scope, shadow that tag name for the current scope
2377 with a forward reference.
2378 If its type defines a new named structure or union
2379 or defines an enum, it is valid but we need not do anything here.
2380 Otherwise, it is an error. */
2383 shadow_tag (tree declspecs
)
2385 shadow_tag_warned (declspecs
, 0);
2389 shadow_tag_warned (tree declspecs
, int warned
)
2392 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
2399 pending_invalid_xref
= 0;
2401 /* Remove the attributes from declspecs, since they will confuse the
2403 split_specs_attrs (declspecs
, &specs
, &attrs
);
2405 for (link
= specs
; link
; link
= TREE_CHAIN (link
))
2407 tree value
= TREE_VALUE (link
);
2408 enum tree_code code
= TREE_CODE (value
);
2410 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ENUMERAL_TYPE
)
2411 /* Used to test also that TYPE_SIZE (value) != 0.
2412 That caused warning for `struct foo;' at top level in the file. */
2414 tree name
= TYPE_NAME (value
);
2421 if (warned
!= 1 && code
!= ENUMERAL_TYPE
)
2422 /* Empty unnamed enum OK */
2424 pedwarn ("unnamed struct/union that defines no instances");
2430 t
= lookup_tag (code
, name
, 1);
2434 t
= make_node (code
);
2441 if (!warned
&& ! in_system_header
)
2443 warning ("useless keyword or type name in empty declaration");
2450 error ("two types specified in one empty declaration");
2455 pedwarn ("empty declaration");
2459 /* Construct an array declarator. EXPR is the expression inside [], or
2460 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
2461 to the pointer to which a parameter array is converted). STATIC_P is
2462 nonzero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P
2463 is nonzero is the array is [*], a VLA of unspecified length which is
2464 nevertheless a complete type (not currently implemented by GCC),
2465 zero otherwise. The declarator is constructed as an ARRAY_REF
2466 (to be decoded by grokdeclarator), whose operand 0 is what's on the
2467 left of the [] (filled by in set_array_declarator_type) and operand 1
2468 is the expression inside; whose TREE_TYPE is the type qualifiers and
2469 which has TREE_STATIC set if "static" is used. */
2472 build_array_declarator (tree expr
, tree quals
, int static_p
, int vla_unspec_p
)
2475 decl
= build_nt (ARRAY_REF
, NULL_TREE
, expr
);
2476 TREE_TYPE (decl
) = quals
;
2477 TREE_STATIC (decl
) = (static_p
? 1 : 0);
2478 if (pedantic
&& !flag_isoc99
)
2480 if (static_p
|| quals
!= NULL_TREE
)
2481 pedwarn ("ISO C90 does not support `static' or type qualifiers in parameter array declarators");
2483 pedwarn ("ISO C90 does not support `[*]' array declarators");
2486 warning ("GCC does not yet properly implement `[*]' array declarators");
2490 /* Set the type of an array declarator. DECL is the declarator, as
2491 constructed by build_array_declarator; TYPE is what appears on the left
2492 of the [] and goes in operand 0. ABSTRACT_P is nonzero if it is an
2493 abstract declarator, zero otherwise; this is used to reject static and
2494 type qualifiers in abstract declarators, where they are not in the
2498 set_array_declarator_type (tree decl
, tree type
, int abstract_p
)
2500 TREE_OPERAND (decl
, 0) = type
;
2501 if (abstract_p
&& (TREE_TYPE (decl
) != NULL_TREE
|| TREE_STATIC (decl
)))
2502 error ("static or type qualifiers in abstract declarator");
2506 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
2509 groktypename (tree typename
)
2513 if (TREE_CODE (typename
) != TREE_LIST
)
2516 split_specs_attrs (TREE_PURPOSE (typename
), &specs
, &attrs
);
2518 typename
= grokdeclarator (TREE_VALUE (typename
), specs
, TYPENAME
, 0,
2521 /* Apply attributes. */
2522 decl_attributes (&typename
, attrs
, 0);
2527 /* Return a PARM_DECL node for a given pair of specs and declarator. */
2530 groktypename_in_parm_context (tree typename
)
2532 if (TREE_CODE (typename
) != TREE_LIST
)
2534 return grokdeclarator (TREE_VALUE (typename
),
2535 TREE_PURPOSE (typename
),
2539 /* Decode a declarator in an ordinary declaration or data definition.
2540 This is called as soon as the type information and variable name
2541 have been parsed, before parsing the initializer if any.
2542 Here we create the ..._DECL node, fill in its type,
2543 and put it on the list of decls for the current context.
2544 The ..._DECL node is returned as the value.
2546 Exception: for arrays where the length is not specified,
2547 the type is left null, to be filled in by `finish_decl'.
2549 Function definitions do not come here; they go to start_function
2550 instead. However, external and forward declarations of functions
2551 do go through here. Structure field declarations are done by
2552 grokfield and not through here. */
2555 start_decl (tree declarator
, tree declspecs
, int initialized
, tree attributes
)
2560 /* An object declared as __attribute__((deprecated)) suppresses
2561 warnings of uses of other deprecated items. */
2562 if (lookup_attribute ("deprecated", attributes
))
2563 deprecated_state
= DEPRECATED_SUPPRESS
;
2565 decl
= grokdeclarator (declarator
, declspecs
,
2566 NORMAL
, initialized
, NULL
);
2568 deprecated_state
= DEPRECATED_NORMAL
;
2570 if (warn_main
> 0 && TREE_CODE (decl
) != FUNCTION_DECL
2571 && MAIN_NAME_P (DECL_NAME (decl
)))
2572 warning ("%J'%D' is usually a function", decl
, decl
);
2575 /* Is it valid for this decl to have an initializer at all?
2576 If not, set INITIALIZED to zero, which will indirectly
2577 tell `finish_decl' to ignore the initializer once it is parsed. */
2578 switch (TREE_CODE (decl
))
2581 error ("typedef `%s' is initialized (use __typeof__ instead)",
2582 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2587 error ("function `%s' is initialized like a variable",
2588 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2593 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
2594 error ("parameter `%s' is initialized",
2595 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2600 /* Don't allow initializations for incomplete types
2601 except for arrays which might be completed by the initialization. */
2603 /* This can happen if the array size is an undefined macro. We already
2604 gave a warning, so we don't need another one. */
2605 if (TREE_TYPE (decl
) == error_mark_node
)
2607 else if (COMPLETE_TYPE_P (TREE_TYPE (decl
)))
2609 /* A complete type is ok if size is fixed. */
2611 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl
))) != INTEGER_CST
2612 || C_DECL_VARIABLE_SIZE (decl
))
2614 error ("variable-sized object may not be initialized");
2618 else if (TREE_CODE (TREE_TYPE (decl
)) != ARRAY_TYPE
)
2620 error ("variable `%s' has initializer but incomplete type",
2621 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2624 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
2626 error ("elements of array `%s' have incomplete type",
2627 IDENTIFIER_POINTER (DECL_NAME (decl
)));
2634 DECL_EXTERNAL (decl
) = 0;
2635 if (current_scope
== global_scope
)
2636 TREE_STATIC (decl
) = 1;
2638 /* Tell `pushdecl' this is an initialized decl
2639 even though we don't yet have the initializer expression.
2640 Also tell `finish_decl' it may store the real initializer. */
2641 DECL_INITIAL (decl
) = error_mark_node
;
2644 /* If this is a function declaration, write a record describing it to the
2645 prototypes file (if requested). */
2647 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2648 gen_aux_info_record (decl
, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl
)) != 0);
2650 /* ANSI specifies that a tentative definition which is not merged with
2651 a non-tentative definition behaves exactly like a definition with an
2652 initializer equal to zero. (Section 3.7.2)
2654 -fno-common gives strict ANSI behavior, though this tends to break
2655 a large body of code that grew up without this rule.
2657 Thread-local variables are never common, since there's no entrenched
2658 body of code to break, and it allows more efficient variable references
2659 in the presence of dynamic linking. */
2661 if (TREE_CODE (decl
) == VAR_DECL
2663 && TREE_PUBLIC (decl
)
2664 && !DECL_THREAD_LOCAL (decl
)
2666 DECL_COMMON (decl
) = 1;
2668 /* Set attributes here so if duplicate decl, will have proper attributes. */
2669 decl_attributes (&decl
, attributes
, 0);
2671 if (TREE_CODE (decl
) == FUNCTION_DECL
2672 && targetm
.calls
.promote_prototypes (TREE_TYPE (decl
)))
2674 tree ce
= declarator
;
2676 if (TREE_CODE (ce
) == INDIRECT_REF
)
2677 ce
= TREE_OPERAND (declarator
, 0);
2678 if (TREE_CODE (ce
) == CALL_EXPR
)
2680 tree args
= TREE_PURPOSE (TREE_OPERAND (ce
, 1));
2681 for (; args
; args
= TREE_CHAIN (args
))
2683 tree type
= TREE_TYPE (args
);
2684 if (INTEGRAL_TYPE_P (type
)
2685 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
2686 DECL_ARG_TYPE (args
) = integer_type_node
;
2691 if (TREE_CODE (decl
) == FUNCTION_DECL
2692 && DECL_DECLARED_INLINE_P (decl
)
2693 && DECL_UNINLINABLE (decl
)
2694 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl
)))
2695 warning ("%Jinline function '%D' given attribute noinline", decl
, decl
);
2697 /* Add this decl to the current scope.
2698 TEM may equal DECL or it may be a previous decl of the same name. */
2699 tem
= pushdecl (decl
);
2701 /* For a local variable, define the RTL now. */
2702 if (current_scope
!= global_scope
2703 /* But not if this is a duplicate decl
2704 and we preserved the rtl from the previous one
2705 (which may or may not happen). */
2706 && !DECL_RTL_SET_P (tem
)
2707 && DECL_FILE_SCOPE_P (tem
))
2709 if (TREE_TYPE (tem
) != error_mark_node
2710 && (COMPLETE_TYPE_P (TREE_TYPE (tem
))
2711 || (TREE_CODE (TREE_TYPE (tem
)) == ARRAY_TYPE
2712 && DECL_INITIAL (tem
) != 0)))
2719 /* Finish processing of a declaration;
2720 install its initial value.
2721 If the length of an array type is not known before,
2722 it must be determined now, from the initial value, or it is an error. */
2725 finish_decl (tree decl
, tree init
, tree asmspec_tree
)
2727 tree type
= TREE_TYPE (decl
);
2728 int was_incomplete
= (DECL_SIZE (decl
) == 0);
2729 const char *asmspec
= 0;
2731 /* If a name was specified, get the string. */
2732 if (current_scope
== global_scope
)
2733 asmspec_tree
= maybe_apply_renaming_pragma (decl
, asmspec_tree
);
2735 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
2737 /* If `start_decl' didn't like having an initialization, ignore it now. */
2738 if (init
!= 0 && DECL_INITIAL (decl
) == 0)
2741 /* Don't crash if parm is initialized. */
2742 if (TREE_CODE (decl
) == PARM_DECL
)
2746 store_init_value (decl
, init
);
2748 if (c_dialect_objc () && (TREE_CODE (decl
) == VAR_DECL
2749 || TREE_CODE (decl
) == FUNCTION_DECL
2750 || TREE_CODE (decl
) == FIELD_DECL
))
2751 objc_check_decl (decl
);
2753 /* Deduce size of array from initialization, if not already known. */
2754 if (TREE_CODE (type
) == ARRAY_TYPE
2755 && TYPE_DOMAIN (type
) == 0
2756 && TREE_CODE (decl
) != TYPE_DECL
)
2759 = (TREE_STATIC (decl
)
2760 /* Even if pedantic, an external linkage array
2761 may have incomplete type at first. */
2762 ? pedantic
&& !TREE_PUBLIC (decl
)
2763 : !DECL_EXTERNAL (decl
));
2765 = complete_array_type (type
, DECL_INITIAL (decl
), do_default
);
2767 /* Get the completed type made by complete_array_type. */
2768 type
= TREE_TYPE (decl
);
2771 error ("%Jinitializer fails to determine size of '%D'", decl
, decl
);
2773 else if (failure
== 2)
2776 error ("%Jarray size missing in '%D'", decl
, decl
);
2777 /* If a `static' var's size isn't known,
2778 make it extern as well as static, so it does not get
2780 If it is not `static', then do not mark extern;
2781 finish_incomplete_decl will give it a default size
2782 and it will get allocated. */
2783 else if (!pedantic
&& TREE_STATIC (decl
) && ! TREE_PUBLIC (decl
))
2784 DECL_EXTERNAL (decl
) = 1;
2787 /* TYPE_MAX_VALUE is always one less than the number of elements
2788 in the array, because we start counting at zero. Therefore,
2789 warn only if the value is less than zero. */
2790 else if (pedantic
&& TYPE_DOMAIN (type
) != 0
2791 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))) < 0)
2792 error ("%Jzero or negative size array '%D'", decl
, decl
);
2794 layout_decl (decl
, 0);
2797 if (TREE_CODE (decl
) == VAR_DECL
)
2799 if (DECL_SIZE (decl
) == 0 && TREE_TYPE (decl
) != error_mark_node
2800 && COMPLETE_TYPE_P (TREE_TYPE (decl
)))
2801 layout_decl (decl
, 0);
2803 if (DECL_SIZE (decl
) == 0
2804 /* Don't give an error if we already gave one earlier. */
2805 && TREE_TYPE (decl
) != error_mark_node
2806 && (TREE_STATIC (decl
)
2808 /* A static variable with an incomplete type
2809 is an error if it is initialized.
2810 Also if it is not file scope.
2811 Otherwise, let it through, but if it is not `extern'
2812 then it may cause an error message later. */
2813 (DECL_INITIAL (decl
) != 0
2814 || !DECL_FILE_SCOPE_P (decl
))
2816 /* An automatic variable with an incomplete type
2818 !DECL_EXTERNAL (decl
)))
2820 error ("%Jstorage size of '%D' isn't known", decl
, decl
);
2821 TREE_TYPE (decl
) = error_mark_node
;
2824 if ((DECL_EXTERNAL (decl
) || TREE_STATIC (decl
))
2825 && DECL_SIZE (decl
) != 0)
2827 if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
2828 constant_expression_warning (DECL_SIZE (decl
));
2830 error ("%Jstorage size of '%D' isn't constant", decl
, decl
);
2833 if (TREE_USED (type
))
2834 TREE_USED (decl
) = 1;
2837 /* If this is a function and an assembler name is specified, reset DECL_RTL
2838 so we can give it its new name. Also, update built_in_decls if it
2839 was a normal built-in. */
2840 if (TREE_CODE (decl
) == FUNCTION_DECL
&& asmspec
)
2842 /* ASMSPEC is given, and not the name of a register. Mark the
2843 name with a star so assemble_name won't munge it. */
2844 char *starred
= alloca (strlen (asmspec
) + 2);
2846 strcpy (starred
+ 1, asmspec
);
2848 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
)
2850 tree builtin
= built_in_decls
[DECL_FUNCTION_CODE (decl
)];
2851 SET_DECL_RTL (builtin
, NULL_RTX
);
2852 SET_DECL_ASSEMBLER_NAME (builtin
, get_identifier (starred
));
2853 #ifdef TARGET_MEM_FUNCTIONS
2854 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_MEMCPY
)
2855 init_block_move_fn (starred
);
2856 else if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_MEMSET
)
2857 init_block_clear_fn (starred
);
2859 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_BCOPY
)
2860 init_block_move_fn (starred
);
2861 else if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_BZERO
)
2862 init_block_clear_fn (starred
);
2865 SET_DECL_RTL (decl
, NULL_RTX
);
2866 change_decl_assembler_name (decl
, get_identifier (starred
));
2869 /* If #pragma weak was used, mark the decl weak now. */
2870 if (current_scope
== global_scope
)
2871 maybe_apply_pragma_weak (decl
);
2873 /* Output the assembler code and/or RTL code for variables and functions,
2874 unless the type is an undefined structure or union.
2875 If not, it will get done when the type is completed. */
2877 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
)
2879 /* This is a no-op in c-lang.c or something real in objc-act.c. */
2880 if (c_dialect_objc ())
2881 objc_check_decl (decl
);
2883 if (DECL_FILE_SCOPE_P (decl
))
2885 if (DECL_INITIAL (decl
) == NULL_TREE
2886 || DECL_INITIAL (decl
) == error_mark_node
)
2887 /* Don't output anything
2888 when a tentative file-scope definition is seen.
2889 But at end of compilation, do output code for them. */
2890 DECL_DEFER_OUTPUT (decl
) = 1;
2891 rest_of_decl_compilation (decl
, asmspec
, true, 0);
2895 /* This is a local variable. If there is an ASMSPEC, the
2896 user has requested that we handle it specially. */
2899 /* In conjunction with an ASMSPEC, the `register'
2900 keyword indicates that we should place the variable
2901 in a particular register. */
2902 if (DECL_REGISTER (decl
))
2903 DECL_C_HARD_REGISTER (decl
) = 1;
2905 /* If this is not a static variable, issue a warning.
2906 It doesn't make any sense to give an ASMSPEC for an
2907 ordinary, non-register local variable. Historically,
2908 GCC has accepted -- but ignored -- the ASMSPEC in
2910 if (TREE_CODE (decl
) == VAR_DECL
2911 && !DECL_REGISTER (decl
)
2912 && !TREE_STATIC (decl
))
2913 warning ("%Jignoring asm-specifier for non-static local "
2914 "variable '%D'", decl
, decl
);
2916 change_decl_assembler_name (decl
, get_identifier (asmspec
));
2919 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2920 add_decl_stmt (decl
);
2923 if (!DECL_FILE_SCOPE_P (decl
))
2925 /* Recompute the RTL of a local array now
2926 if it used to be an incomplete type. */
2928 && ! TREE_STATIC (decl
) && ! DECL_EXTERNAL (decl
))
2930 /* If we used it already as memory, it must stay in memory. */
2931 TREE_ADDRESSABLE (decl
) = TREE_USED (decl
);
2932 /* If it's still incomplete now, no init will save it. */
2933 if (DECL_SIZE (decl
) == 0)
2934 DECL_INITIAL (decl
) = 0;
2939 /* If this was marked 'used', be sure it will be output. */
2940 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl
)))
2941 mark_referenced (DECL_ASSEMBLER_NAME (decl
));
2943 if (TREE_CODE (decl
) == TYPE_DECL
)
2944 rest_of_decl_compilation (decl
, NULL
, DECL_FILE_SCOPE_P (decl
), 0);
2946 /* At the end of a declaration, throw away any variable type sizes
2947 of types defined inside that declaration. There is no use
2948 computing them in the following function definition. */
2949 if (current_scope
== global_scope
)
2950 get_pending_sizes ();
2952 /* Install a cleanup (aka destructor) if one was given. */
2953 if (TREE_CODE (decl
) == VAR_DECL
&& !TREE_STATIC (decl
))
2955 tree attr
= lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl
));
2958 static bool eh_initialized_p
;
2960 tree cleanup_id
= TREE_VALUE (TREE_VALUE (attr
));
2961 tree cleanup_decl
= lookup_name (cleanup_id
);
2964 /* Build "cleanup(&decl)" for the destructor. */
2965 cleanup
= build_unary_op (ADDR_EXPR
, decl
, 0);
2966 cleanup
= build_tree_list (NULL_TREE
, cleanup
);
2967 cleanup
= build_function_call (cleanup_decl
, cleanup
);
2969 /* Don't warn about decl unused; the cleanup uses it. */
2970 TREE_USED (decl
) = 1;
2972 /* Initialize EH, if we've been told to do so. */
2973 if (flag_exceptions
&& !eh_initialized_p
)
2975 eh_initialized_p
= true;
2976 eh_personality_libfunc
2977 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
2978 ? "__gcc_personality_sj0"
2979 : "__gcc_personality_v0");
2980 using_eh_for_cleanups ();
2983 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
2988 /* Given a parsed parameter declaration, decode it into a PARM_DECL
2989 and push that on the current scope. */
2992 push_parm_decl (tree parm
)
2996 /* Don't attempt to expand sizes while parsing this decl.
2997 (We can get here with i_s_e 1 somehow from Objective-C.) */
2998 int save_immediate_size_expand
= immediate_size_expand
;
2999 immediate_size_expand
= 0;
3001 decl
= grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm
)),
3002 TREE_PURPOSE (TREE_PURPOSE (parm
)),
3004 decl_attributes (&decl
, TREE_VALUE (parm
), 0);
3006 decl
= pushdecl (decl
);
3008 finish_decl (decl
, NULL_TREE
, NULL_TREE
);
3010 immediate_size_expand
= save_immediate_size_expand
;
3013 /* Mark all the parameter declarations to date as forward decls,
3014 shift them to the variables list, and reset the parameters list.
3015 Also diagnose use of this extension. */
3018 mark_forward_parm_decls (void)
3022 if (pedantic
&& !current_scope
->warned_forward_parm_decls
)
3024 pedwarn ("ISO C forbids forward parameter declarations");
3025 current_scope
->warned_forward_parm_decls
= true;
3028 for (parm
= current_scope
->parms
; parm
; parm
= TREE_CHAIN (parm
))
3029 TREE_ASM_WRITTEN (parm
) = 1;
3031 SCOPE_LIST_CONCAT (current_scope
, names
, current_scope
, parms
);
3032 current_scope
->parms
= 0;
3033 current_scope
->parms_last
= 0;
3036 static GTY(()) int compound_literal_number
;
3038 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3039 literal, which may be an incomplete array type completed by the
3040 initializer; INIT is a CONSTRUCTOR that initializes the compound
3044 build_compound_literal (tree type
, tree init
)
3046 /* We do not use start_decl here because we have a type, not a declarator;
3047 and do not use finish_decl because the decl should be stored inside
3048 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
3049 tree decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
3052 DECL_EXTERNAL (decl
) = 0;
3053 TREE_PUBLIC (decl
) = 0;
3054 TREE_STATIC (decl
) = (current_scope
== global_scope
);
3055 DECL_CONTEXT (decl
) = current_function_decl
;
3056 TREE_USED (decl
) = 1;
3057 TREE_TYPE (decl
) = type
;
3058 TREE_READONLY (decl
) = TREE_READONLY (type
);
3059 store_init_value (decl
, init
);
3061 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
3063 int failure
= complete_array_type (type
, DECL_INITIAL (decl
), 1);
3068 type
= TREE_TYPE (decl
);
3069 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
3070 return error_mark_node
;
3072 stmt
= build_stmt (DECL_STMT
, decl
);
3073 complit
= build1 (COMPOUND_LITERAL_EXPR
, TREE_TYPE (decl
), stmt
);
3074 TREE_SIDE_EFFECTS (complit
) = 1;
3076 layout_decl (decl
, 0);
3078 if (TREE_STATIC (decl
))
3080 /* This decl needs a name for the assembler output. We also need
3081 a unique suffix to be added to the name. */
3084 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
3085 compound_literal_number
);
3086 compound_literal_number
++;
3087 DECL_NAME (decl
) = get_identifier (name
);
3088 DECL_DEFER_OUTPUT (decl
) = 1;
3089 DECL_COMDAT (decl
) = 1;
3090 DECL_ARTIFICIAL (decl
) = 1;
3092 rest_of_decl_compilation (decl
, NULL
, 1, 0);
3098 /* Make TYPE a complete type based on INITIAL_VALUE.
3099 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3100 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3103 complete_array_type (tree type
, tree initial_value
, int do_default
)
3105 tree maxindex
= NULL_TREE
;
3110 /* Note MAXINDEX is really the maximum index,
3111 one less than the size. */
3112 if (TREE_CODE (initial_value
) == STRING_CST
)
3115 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
3116 maxindex
= build_int_2 ((TREE_STRING_LENGTH (initial_value
)
3119 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
3121 tree elts
= CONSTRUCTOR_ELTS (initial_value
);
3122 maxindex
= build_int_2 (-1, -1);
3123 for (; elts
; elts
= TREE_CHAIN (elts
))
3125 if (TREE_PURPOSE (elts
))
3126 maxindex
= TREE_PURPOSE (elts
);
3128 maxindex
= fold (build (PLUS_EXPR
, integer_type_node
,
3129 maxindex
, integer_one_node
));
3131 maxindex
= copy_node (maxindex
);
3135 /* Make an error message unless that happened already. */
3136 if (initial_value
!= error_mark_node
)
3139 /* Prevent further error messages. */
3140 maxindex
= build_int_2 (0, 0);
3147 maxindex
= build_int_2 (0, 0);
3153 TYPE_DOMAIN (type
) = build_index_type (maxindex
);
3154 if (!TREE_TYPE (maxindex
))
3155 TREE_TYPE (maxindex
) = TYPE_DOMAIN (type
);
3158 /* Lay out the type now that we can get the real answer. */
3165 /* Determine whether TYPE is a structure with a flexible array member,
3166 or a union containing such a structure (possibly recursively). */
3169 flexible_array_type_p (tree type
)
3172 switch (TREE_CODE (type
))
3175 x
= TYPE_FIELDS (type
);
3178 while (TREE_CHAIN (x
) != NULL_TREE
)
3180 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
3181 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
3182 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
3183 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
3187 for (x
= TYPE_FIELDS (type
); x
!= NULL_TREE
; x
= TREE_CHAIN (x
))
3189 if (flexible_array_type_p (TREE_TYPE (x
)))
3198 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3199 replacing with appropriate values if they are invalid. */
3201 check_bitfield_type_and_width (tree
*type
, tree
*width
, const char *orig_name
)
3204 unsigned int max_width
;
3205 unsigned HOST_WIDE_INT w
;
3206 const char *name
= orig_name
? orig_name
: _("<anonymous>");
3209 STRIP_NOPS (*width
);
3211 /* Detect and ignore out of range field width and process valid
3213 if (TREE_CODE (*width
) != INTEGER_CST
)
3215 error ("bit-field `%s' width not an integer constant", name
);
3216 *width
= integer_one_node
;
3220 constant_expression_warning (*width
);
3221 if (tree_int_cst_sgn (*width
) < 0)
3223 error ("negative width in bit-field `%s'", name
);
3224 *width
= integer_one_node
;
3226 else if (integer_zerop (*width
) && orig_name
)
3228 error ("zero width for bit-field `%s'", name
);
3229 *width
= integer_one_node
;
3233 /* Detect invalid bit-field type. */
3234 if (TREE_CODE (*type
) != INTEGER_TYPE
3235 && TREE_CODE (*type
) != BOOLEAN_TYPE
3236 && TREE_CODE (*type
) != ENUMERAL_TYPE
)
3238 error ("bit-field `%s' has invalid type", name
);
3239 *type
= unsigned_type_node
;
3242 type_mv
= TYPE_MAIN_VARIANT (*type
);
3244 && type_mv
!= integer_type_node
3245 && type_mv
!= unsigned_type_node
3246 && type_mv
!= boolean_type_node
)
3247 pedwarn ("type of bit-field `%s' is a GCC extension", name
);
3249 if (type_mv
== boolean_type_node
)
3250 max_width
= CHAR_TYPE_SIZE
;
3252 max_width
= TYPE_PRECISION (*type
);
3254 if (0 < compare_tree_int (*width
, max_width
))
3256 error ("width of `%s' exceeds its type", name
);
3258 *width
= build_int_2 (w
, 0);
3261 w
= tree_low_cst (*width
, 1);
3263 if (TREE_CODE (*type
) == ENUMERAL_TYPE
3264 && (w
< min_precision (TYPE_MIN_VALUE (*type
), TREE_UNSIGNED (*type
))
3265 || w
< min_precision (TYPE_MAX_VALUE (*type
), TREE_UNSIGNED (*type
))))
3266 warning ("`%s' is narrower than values of its type", name
);
3269 /* Given declspecs and a declarator,
3270 determine the name and type of the object declared
3271 and construct a ..._DECL node for it.
3272 (In one case we can return a ..._TYPE node instead.
3273 For invalid input we sometimes return 0.)
3275 DECLSPECS is a chain of tree_list nodes whose value fields
3276 are the storage classes and type specifiers.
3278 DECL_CONTEXT says which syntactic context this declaration is in:
3279 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3280 FUNCDEF for a function definition. Like NORMAL but a few different
3281 error messages in each case. Return value may be zero meaning
3282 this definition is too screwy to try to parse.
3283 PARM for a parameter declaration (either within a function prototype
3284 or before a function body). Make a PARM_DECL, or return void_type_node.
3285 TYPENAME if for a typename (in a cast or sizeof).
3286 Don't make a DECL node; just return the ..._TYPE node.
3287 FIELD for a struct or union field; make a FIELD_DECL.
3288 INITIALIZED is 1 if the decl has an initializer.
3289 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
3290 representing the width of the bit-field.
3292 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3293 It may also be so in the PARM case, for a prototype where the
3294 argument type is specified but not the name.
3296 This function is where the complicated C meanings of `static'
3297 and `extern' are interpreted. */
3300 grokdeclarator (tree declarator
, tree declspecs
,
3301 enum decl_context decl_context
, int initialized
, tree
*width
)
3305 tree type
= NULL_TREE
;
3310 int type_quals
= TYPE_UNQUALIFIED
;
3312 int explicit_int
= 0;
3313 int explicit_char
= 0;
3314 int defaulted_int
= 0;
3315 tree typedef_decl
= 0;
3316 const char *name
, *orig_name
;
3317 tree typedef_type
= 0;
3318 int funcdef_flag
= 0;
3319 enum tree_code innermost_code
= ERROR_MARK
;
3320 int size_varies
= 0;
3321 tree decl_attr
= NULL_TREE
;
3322 tree array_ptr_quals
= NULL_TREE
;
3323 int array_parm_static
= 0;
3324 tree returned_attrs
= NULL_TREE
;
3325 bool bitfield
= width
!= NULL
;
3328 if (decl_context
== FUNCDEF
)
3329 funcdef_flag
= 1, decl_context
= NORMAL
;
3331 /* Look inside a declarator for the name being declared
3332 and get it as a string, for an error message. */
3334 tree decl
= declarator
;
3338 switch (TREE_CODE (decl
))
3343 innermost_code
= TREE_CODE (decl
);
3344 decl
= TREE_OPERAND (decl
, 0);
3348 decl
= TREE_VALUE (decl
);
3351 case IDENTIFIER_NODE
:
3352 name
= IDENTIFIER_POINTER (decl
);
3364 /* A function definition's declarator must have the form of
3365 a function declarator. */
3367 if (funcdef_flag
&& innermost_code
!= CALL_EXPR
)
3370 /* If this looks like a function definition, make it one,
3371 even if it occurs where parms are expected.
3372 Then store_parm_decls will reject it and not use it as a parm. */
3373 if (decl_context
== NORMAL
&& !funcdef_flag
3374 && current_scope
->parm_flag
)
3375 decl_context
= PARM
;
3377 /* Look through the decl specs and record which ones appear.
3378 Some typespecs are defined as built-in typenames.
3379 Others, the ones that are modifiers of other types,
3380 are represented by bits in SPECBITS: set the bits for
3381 the modifiers that appear. Storage class keywords are also in SPECBITS.
3383 If there is a typedef name or a type, store the type in TYPE.
3384 This includes builtin typedefs such as `int'.
3386 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3387 and did not come from a user typedef.
3389 Set LONGLONG if `long' is mentioned twice. */
3391 for (spec
= declspecs
; spec
; spec
= TREE_CHAIN (spec
))
3393 tree id
= TREE_VALUE (spec
);
3395 /* If the entire declaration is itself tagged as deprecated then
3396 suppress reports of deprecated items. */
3397 if (id
&& TREE_DEPRECATED (id
))
3399 if (deprecated_state
!= DEPRECATED_SUPPRESS
)
3400 warn_deprecated_use (id
);
3403 if (id
== ridpointers
[(int) RID_INT
])
3405 if (id
== ridpointers
[(int) RID_CHAR
])
3408 if (TREE_CODE (id
) == IDENTIFIER_NODE
&& C_IS_RESERVED_WORD (id
))
3410 enum rid i
= C_RID_CODE (id
);
3411 if ((int) i
<= (int) RID_LAST_MODIFIER
)
3413 if (i
== RID_LONG
&& (specbits
& (1 << (int) RID_LONG
)))
3416 error ("`long long long' is too long for GCC");
3419 if (pedantic
&& !flag_isoc99
&& ! in_system_header
3421 pedwarn ("ISO C90 does not support `long long'");
3425 else if (specbits
& (1 << (int) i
))
3427 if (i
== RID_CONST
|| i
== RID_VOLATILE
|| i
== RID_RESTRICT
)
3430 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id
));
3433 error ("duplicate `%s'", IDENTIFIER_POINTER (id
));
3436 /* Diagnose "__thread extern". Recall that this list
3437 is in the reverse order seen in the text. */
3439 && (specbits
& (1 << (int) RID_EXTERN
3440 | 1 << (int) RID_STATIC
)))
3442 if (specbits
& 1 << (int) RID_EXTERN
)
3443 error ("`__thread' before `extern'");
3445 error ("`__thread' before `static'");
3448 specbits
|= 1 << (int) i
;
3453 error ("two or more data types in declaration of `%s'", name
);
3454 /* Actual typedefs come to us as TYPE_DECL nodes. */
3455 else if (TREE_CODE (id
) == TYPE_DECL
)
3457 if (TREE_TYPE (id
) == error_mark_node
)
3458 ; /* Allow the type to default to int to avoid cascading errors. */
3461 type
= TREE_TYPE (id
);
3462 decl_attr
= DECL_ATTRIBUTES (id
);
3466 /* Built-in types come as identifiers. */
3467 else if (TREE_CODE (id
) == IDENTIFIER_NODE
)
3469 tree t
= lookup_name (id
);
3470 if (TREE_TYPE (t
) == error_mark_node
)
3472 else if (!t
|| TREE_CODE (t
) != TYPE_DECL
)
3473 error ("`%s' fails to be a typedef or built in type",
3474 IDENTIFIER_POINTER (id
));
3477 type
= TREE_TYPE (t
);
3481 else if (TREE_CODE (id
) != ERROR_MARK
)
3488 typedef_type
= type
;
3490 size_varies
= C_TYPE_VARIABLE_SIZE (type
);
3492 /* No type at all: default to `int', and set DEFAULTED_INT
3493 because it was not a user-defined typedef. */
3497 if ((! (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3498 | (1 << (int) RID_SIGNED
)
3499 | (1 << (int) RID_UNSIGNED
)
3500 | (1 << (int) RID_COMPLEX
))))
3501 /* Don't warn about typedef foo = bar. */
3502 && ! (specbits
& (1 << (int) RID_TYPEDEF
) && initialized
)
3503 && ! in_system_header
)
3505 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
3506 and this is a function, or if -Wimplicit; prefer the former
3507 warning since it is more explicit. */
3508 if ((warn_implicit_int
|| warn_return_type
|| flag_isoc99
)
3510 warn_about_return_type
= 1;
3511 else if (warn_implicit_int
|| flag_isoc99
)
3512 pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
3517 type
= integer_type_node
;
3520 /* Now process the modifiers that were specified
3521 and check for invalid combinations. */
3523 /* Long double is a special combination. */
3525 if ((specbits
& 1 << (int) RID_LONG
) && ! longlong
3526 && TYPE_MAIN_VARIANT (type
) == double_type_node
)
3528 specbits
&= ~(1 << (int) RID_LONG
);
3529 type
= long_double_type_node
;
3532 /* Check all other uses of type modifiers. */
3534 if (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3535 | (1 << (int) RID_UNSIGNED
) | (1 << (int) RID_SIGNED
)))
3539 if ((specbits
& 1 << (int) RID_LONG
)
3540 && (specbits
& 1 << (int) RID_SHORT
))
3541 error ("both long and short specified for `%s'", name
);
3542 else if (((specbits
& 1 << (int) RID_LONG
)
3543 || (specbits
& 1 << (int) RID_SHORT
))
3545 error ("long or short specified with char for `%s'", name
);
3546 else if (((specbits
& 1 << (int) RID_LONG
)
3547 || (specbits
& 1 << (int) RID_SHORT
))
3548 && TREE_CODE (type
) == REAL_TYPE
)
3550 static int already
= 0;
3552 error ("long or short specified with floating type for `%s'", name
);
3553 if (! already
&& ! pedantic
)
3555 error ("the only valid combination is `long double'");
3559 else if ((specbits
& 1 << (int) RID_SIGNED
)
3560 && (specbits
& 1 << (int) RID_UNSIGNED
))
3561 error ("both signed and unsigned specified for `%s'", name
);
3562 else if (TREE_CODE (type
) != INTEGER_TYPE
)
3563 error ("long, short, signed or unsigned invalid for `%s'", name
);
3567 if (!explicit_int
&& !defaulted_int
&& !explicit_char
)
3569 error ("long, short, signed or unsigned used invalidly for `%s'",
3575 /* Discard the type modifiers if they are invalid. */
3578 specbits
&= ~((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3579 | (1 << (int) RID_UNSIGNED
) | (1 << (int) RID_SIGNED
));
3584 if ((specbits
& (1 << (int) RID_COMPLEX
))
3585 && TREE_CODE (type
) != INTEGER_TYPE
&& TREE_CODE (type
) != REAL_TYPE
)
3587 error ("complex invalid for `%s'", name
);
3588 specbits
&= ~(1 << (int) RID_COMPLEX
);
3591 /* Decide whether an integer type is signed or not.
3592 Optionally treat bit-fields as signed by default. */
3593 if (specbits
& 1 << (int) RID_UNSIGNED
3594 || (bitfield
&& ! flag_signed_bitfields
3595 && (explicit_int
|| defaulted_int
|| explicit_char
3596 /* A typedef for plain `int' without `signed'
3597 can be controlled just like plain `int'. */
3598 || ! (typedef_decl
!= 0
3599 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
3600 && TREE_CODE (type
) != ENUMERAL_TYPE
3601 && !(specbits
& 1 << (int) RID_SIGNED
)))
3604 type
= long_long_unsigned_type_node
;
3605 else if (specbits
& 1 << (int) RID_LONG
)
3606 type
= long_unsigned_type_node
;
3607 else if (specbits
& 1 << (int) RID_SHORT
)
3608 type
= short_unsigned_type_node
;
3609 else if (type
== char_type_node
)
3610 type
= unsigned_char_type_node
;
3611 else if (typedef_decl
)
3612 type
= c_common_unsigned_type (type
);
3614 type
= unsigned_type_node
;
3616 else if ((specbits
& 1 << (int) RID_SIGNED
)
3617 && type
== char_type_node
)
3618 type
= signed_char_type_node
;
3620 type
= long_long_integer_type_node
;
3621 else if (specbits
& 1 << (int) RID_LONG
)
3622 type
= long_integer_type_node
;
3623 else if (specbits
& 1 << (int) RID_SHORT
)
3624 type
= short_integer_type_node
;
3626 if (specbits
& 1 << (int) RID_COMPLEX
)
3628 if (pedantic
&& !flag_isoc99
)
3629 pedwarn ("ISO C90 does not support complex types");
3630 /* If we just have "complex", it is equivalent to
3631 "complex double", but if any modifiers at all are specified it is
3632 the complex form of TYPE. E.g, "complex short" is
3633 "complex short int". */
3635 if (defaulted_int
&& ! longlong
3636 && ! (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3637 | (1 << (int) RID_SIGNED
)
3638 | (1 << (int) RID_UNSIGNED
))))
3641 pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
3642 type
= complex_double_type_node
;
3644 else if (type
== integer_type_node
)
3647 pedwarn ("ISO C does not support complex integer types");
3648 type
= complex_integer_type_node
;
3650 else if (type
== float_type_node
)
3651 type
= complex_float_type_node
;
3652 else if (type
== double_type_node
)
3653 type
= complex_double_type_node
;
3654 else if (type
== long_double_type_node
)
3655 type
= complex_long_double_type_node
;
3659 pedwarn ("ISO C does not support complex integer types");
3660 type
= build_complex_type (type
);
3664 /* Check the type and width of a bit-field. */
3666 check_bitfield_type_and_width (&type
, width
, orig_name
);
3668 /* Figure out the type qualifiers for the declaration. There are
3669 two ways a declaration can become qualified. One is something
3670 like `const int i' where the `const' is explicit. Another is
3671 something like `typedef const int CI; CI i' where the type of the
3672 declaration contains the `const'. A third possibility is that
3673 there is a type qualifier on the element type of a typedefed
3674 array type, in which case we should extract that qualifier so
3675 that c_apply_type_quals_to_decls receives the full list of
3676 qualifiers to work with (C90 is not entirely clear about whether
3677 duplicate qualifiers should be diagnosed in this case, but it
3678 seems most appropriate to do so). */
3679 element_type
= strip_array_types (type
);
3680 constp
= !! (specbits
& 1 << (int) RID_CONST
) + TYPE_READONLY (element_type
);
3682 = !! (specbits
& 1 << (int) RID_RESTRICT
) + TYPE_RESTRICT (element_type
);
3684 = !! (specbits
& 1 << (int) RID_VOLATILE
) + TYPE_VOLATILE (element_type
);
3685 inlinep
= !! (specbits
& (1 << (int) RID_INLINE
));
3686 if (constp
> 1 && ! flag_isoc99
)
3687 pedwarn ("duplicate `const'");
3688 if (restrictp
> 1 && ! flag_isoc99
)
3689 pedwarn ("duplicate `restrict'");
3690 if (volatilep
> 1 && ! flag_isoc99
)
3691 pedwarn ("duplicate `volatile'");
3692 if (! flag_gen_aux_info
&& (TYPE_QUALS (type
)))
3693 type
= TYPE_MAIN_VARIANT (type
);
3694 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
3695 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
3696 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
3698 /* Warn if two storage classes are given. Default to `auto'. */
3703 if (specbits
& 1 << (int) RID_AUTO
) nclasses
++;
3704 if (specbits
& 1 << (int) RID_STATIC
) nclasses
++;
3705 if (specbits
& 1 << (int) RID_EXTERN
) nclasses
++;
3706 if (specbits
& 1 << (int) RID_REGISTER
) nclasses
++;
3707 if (specbits
& 1 << (int) RID_TYPEDEF
) nclasses
++;
3709 /* "static __thread" and "extern __thread" are allowed. */
3710 if ((specbits
& (1 << (int) RID_THREAD
3711 | 1 << (int) RID_STATIC
3712 | 1 << (int) RID_EXTERN
)) == (1 << (int) RID_THREAD
))
3715 /* Warn about storage classes that are invalid for certain
3716 kinds of declarations (parameters, typenames, etc.). */
3719 error ("multiple storage classes in declaration of `%s'", name
);
3720 else if (funcdef_flag
3722 & ((1 << (int) RID_REGISTER
)
3723 | (1 << (int) RID_AUTO
)
3724 | (1 << (int) RID_TYPEDEF
)
3725 | (1 << (int) RID_THREAD
))))
3727 if (specbits
& 1 << (int) RID_AUTO
3728 && (pedantic
|| current_scope
== global_scope
))
3729 pedwarn ("function definition declared `auto'");
3730 if (specbits
& 1 << (int) RID_REGISTER
)
3731 error ("function definition declared `register'");
3732 if (specbits
& 1 << (int) RID_TYPEDEF
)
3733 error ("function definition declared `typedef'");
3734 if (specbits
& 1 << (int) RID_THREAD
)
3735 error ("function definition declared `__thread'");
3736 specbits
&= ~((1 << (int) RID_TYPEDEF
) | (1 << (int) RID_REGISTER
)
3737 | (1 << (int) RID_AUTO
) | (1 << (int) RID_THREAD
));
3739 else if (decl_context
!= NORMAL
&& nclasses
> 0)
3741 if (decl_context
== PARM
&& specbits
& 1 << (int) RID_REGISTER
)
3745 switch (decl_context
)
3748 error ("storage class specified for structure field `%s'",
3752 error ("storage class specified for parameter `%s'", name
);
3755 error ("storage class specified for typename");
3758 specbits
&= ~((1 << (int) RID_TYPEDEF
) | (1 << (int) RID_REGISTER
)
3759 | (1 << (int) RID_AUTO
) | (1 << (int) RID_STATIC
)
3760 | (1 << (int) RID_EXTERN
) | (1 << (int) RID_THREAD
));
3763 else if (specbits
& 1 << (int) RID_EXTERN
&& initialized
&& ! funcdef_flag
)
3765 /* `extern' with initialization is invalid if not at file scope. */
3766 if (current_scope
== global_scope
)
3767 warning ("`%s' initialized and declared `extern'", name
);
3769 error ("`%s' has both `extern' and initializer", name
);
3771 else if (current_scope
== global_scope
)
3773 if (specbits
& 1 << (int) RID_AUTO
)
3774 error ("file-scope declaration of `%s' specifies `auto'", name
);
3778 if (specbits
& 1 << (int) RID_EXTERN
&& funcdef_flag
)
3779 error ("nested function `%s' declared `extern'", name
);
3780 else if ((specbits
& (1 << (int) RID_THREAD
3781 | 1 << (int) RID_EXTERN
3782 | 1 << (int) RID_STATIC
))
3783 == (1 << (int) RID_THREAD
))
3785 error ("function-scope `%s' implicitly auto and declared `__thread'",
3787 specbits
&= ~(1 << (int) RID_THREAD
);
3792 /* Now figure out the structure of the declarator proper.
3793 Descend through it, creating more complex types, until we reach
3794 the declared identifier (or NULL_TREE, in an absolute declarator). */
3796 while (declarator
&& TREE_CODE (declarator
) != IDENTIFIER_NODE
)
3798 if (type
== error_mark_node
)
3800 declarator
= TREE_OPERAND (declarator
, 0);
3804 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
3805 an INDIRECT_REF (for *...),
3806 a CALL_EXPR (for ...(...)),
3807 a TREE_LIST (for nested attributes),
3808 an identifier (for the name being declared)
3809 or a null pointer (for the place in an absolute declarator
3810 where the name was omitted).
3811 For the last two cases, we have just exited the loop.
3813 At this point, TYPE is the type of elements of an array,
3814 or for a function to return, or for a pointer to point to.
3815 After this sequence of ifs, TYPE is the type of the
3816 array or function or pointer, and DECLARATOR has had its
3817 outermost layer removed. */
3819 if (array_ptr_quals
!= NULL_TREE
|| array_parm_static
)
3821 /* Only the innermost declarator (making a parameter be of
3822 array type which is converted to pointer type)
3823 may have static or type qualifiers. */
3824 error ("static or type qualifiers in non-parameter array declarator");
3825 array_ptr_quals
= NULL_TREE
;
3826 array_parm_static
= 0;
3829 if (TREE_CODE (declarator
) == TREE_LIST
)
3831 /* We encode a declarator with embedded attributes using
3833 tree attrs
= TREE_PURPOSE (declarator
);
3836 declarator
= TREE_VALUE (declarator
);
3837 inner_decl
= declarator
;
3838 while (inner_decl
!= NULL_TREE
3839 && TREE_CODE (inner_decl
) == TREE_LIST
)
3840 inner_decl
= TREE_VALUE (inner_decl
);
3841 if (inner_decl
== NULL_TREE
3842 || TREE_CODE (inner_decl
) == IDENTIFIER_NODE
)
3843 attr_flags
|= (int) ATTR_FLAG_DECL_NEXT
;
3844 else if (TREE_CODE (inner_decl
) == CALL_EXPR
)
3845 attr_flags
|= (int) ATTR_FLAG_FUNCTION_NEXT
;
3846 else if (TREE_CODE (inner_decl
) == ARRAY_REF
)
3847 attr_flags
|= (int) ATTR_FLAG_ARRAY_NEXT
;
3848 returned_attrs
= decl_attributes (&type
,
3849 chainon (returned_attrs
, attrs
),
3852 else if (TREE_CODE (declarator
) == ARRAY_REF
)
3854 tree itype
= NULL_TREE
;
3855 tree size
= TREE_OPERAND (declarator
, 1);
3856 /* The index is a signed object `sizetype' bits wide. */
3857 tree index_type
= c_common_signed_type (sizetype
);
3859 array_ptr_quals
= TREE_TYPE (declarator
);
3860 array_parm_static
= TREE_STATIC (declarator
);
3862 declarator
= TREE_OPERAND (declarator
, 0);
3864 /* Check for some types that there cannot be arrays of. */
3866 if (VOID_TYPE_P (type
))
3868 error ("declaration of `%s' as array of voids", name
);
3869 type
= error_mark_node
;
3872 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3874 error ("declaration of `%s' as array of functions", name
);
3875 type
= error_mark_node
;
3878 if (pedantic
&& flexible_array_type_p (type
))
3879 pedwarn ("invalid use of structure with flexible array member");
3881 if (size
== error_mark_node
)
3882 type
= error_mark_node
;
3884 if (type
== error_mark_node
)
3887 /* If size was specified, set ITYPE to a range-type for that size.
3888 Otherwise, ITYPE remains null. finish_decl may figure it out
3889 from an initial value. */
3893 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3894 STRIP_TYPE_NOPS (size
);
3896 if (! INTEGRAL_TYPE_P (TREE_TYPE (size
)))
3898 error ("size of array `%s' has non-integer type", name
);
3899 size
= integer_one_node
;
3902 if (pedantic
&& integer_zerop (size
))
3903 pedwarn ("ISO C forbids zero-size array `%s'", name
);
3905 if (TREE_CODE (size
) == INTEGER_CST
)
3907 constant_expression_warning (size
);
3908 if (tree_int_cst_sgn (size
) < 0)
3910 error ("size of array `%s' is negative", name
);
3911 size
= integer_one_node
;
3916 /* Make sure the array size remains visibly nonconstant
3917 even if it is (eg) a const variable with known value. */
3920 if (!flag_isoc99
&& pedantic
)
3922 if (TREE_CONSTANT (size
))
3923 pedwarn ("ISO C90 forbids array `%s' whose size can't be evaluated",
3926 pedwarn ("ISO C90 forbids variable-size array `%s'",
3931 if (integer_zerop (size
))
3933 /* A zero-length array cannot be represented with an
3934 unsigned index type, which is what we'll get with
3935 build_index_type. Create an open-ended range instead. */
3936 itype
= build_range_type (sizetype
, size
, NULL_TREE
);
3940 /* Compute the maximum valid index, that is, size - 1.
3941 Do the calculation in index_type, so that if it is
3942 a variable the computations will be done in the
3944 itype
= fold (build (MINUS_EXPR
, index_type
,
3945 convert (index_type
, size
),
3946 convert (index_type
, size_one_node
)));
3948 /* If that overflowed, the array is too big.
3949 ??? While a size of INT_MAX+1 technically shouldn't
3950 cause an overflow (because we subtract 1), the overflow
3951 is recorded during the conversion to index_type, before
3952 the subtraction. Handling this case seems like an
3953 unnecessary complication. */
3954 if (TREE_OVERFLOW (itype
))
3956 error ("size of array `%s' is too large", name
);
3957 type
= error_mark_node
;
3963 /* We must be able to distinguish the
3964 SAVE_EXPR_CONTEXT for the variably-sized type
3965 so that we can set it correctly in
3966 set_save_expr_context. The convention is
3967 that all SAVE_EXPRs that need to be reset
3968 have NULL_TREE for their SAVE_EXPR_CONTEXT. */
3969 tree cfd
= current_function_decl
;
3970 if (decl_context
== PARM
)
3971 current_function_decl
= NULL_TREE
;
3972 itype
= variable_size (itype
);
3973 if (decl_context
== PARM
)
3974 current_function_decl
= cfd
;
3976 itype
= build_index_type (itype
);
3979 else if (decl_context
== FIELD
)
3981 if (pedantic
&& !flag_isoc99
&& !in_system_header
)
3982 pedwarn ("ISO C90 does not support flexible array members");
3984 /* ISO C99 Flexible array members are effectively identical
3985 to GCC's zero-length array extension. */
3986 itype
= build_range_type (sizetype
, size_zero_node
, NULL_TREE
);
3989 /* If pedantic, complain about arrays of incomplete types. */
3991 if (pedantic
&& !COMPLETE_TYPE_P (type
))
3992 pedwarn ("array type has incomplete element type");
3994 /* Build the array type itself, then merge any constancy or
3995 volatility into the target type. We must do it in this order
3996 to ensure that the TYPE_MAIN_VARIANT field of the array type
3997 is set correctly. */
3999 type
= build_array_type (type
, itype
);
4001 type
= c_build_qualified_type (type
, type_quals
);
4004 C_TYPE_VARIABLE_SIZE (type
) = 1;
4006 /* The GCC extension for zero-length arrays differs from
4007 ISO flexible array members in that sizeof yields zero. */
4008 if (size
&& integer_zerop (size
))
4011 TYPE_SIZE (type
) = bitsize_zero_node
;
4012 TYPE_SIZE_UNIT (type
) = size_zero_node
;
4014 if (decl_context
!= PARM
4015 && (array_ptr_quals
!= NULL_TREE
|| array_parm_static
))
4017 error ("static or type qualifiers in non-parameter array declarator");
4018 array_ptr_quals
= NULL_TREE
;
4019 array_parm_static
= 0;
4022 else if (TREE_CODE (declarator
) == CALL_EXPR
)
4026 /* Declaring a function type.
4027 Make sure we have a valid type for the function to return. */
4028 if (type
== error_mark_node
)
4033 /* Warn about some types functions can't return. */
4035 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4037 error ("`%s' declared as function returning a function", name
);
4038 type
= integer_type_node
;
4040 if (TREE_CODE (type
) == ARRAY_TYPE
)
4042 error ("`%s' declared as function returning an array", name
);
4043 type
= integer_type_node
;
4046 /* Construct the function type and go to the next
4047 inner layer of declarator. */
4049 arg_types
= grokparms (TREE_OPERAND (declarator
, 1),
4051 /* Say it's a definition
4052 only for the CALL_EXPR
4053 closest to the identifier. */
4054 && TREE_CODE (TREE_OPERAND (declarator
, 0)) == IDENTIFIER_NODE
);
4055 /* Type qualifiers before the return type of the function
4056 qualify the return type, not the function type. */
4059 /* Type qualifiers on a function return type are normally
4060 permitted by the standard but have no effect, so give a
4061 warning at -Wextra. Qualifiers on a void return type have
4062 meaning as a GNU extension, and are banned on function
4063 definitions in ISO C. FIXME: strictly we shouldn't
4064 pedwarn for qualified void return types except on function
4065 definitions, but not doing so could lead to the undesirable
4066 state of a "volatile void" function return type not being
4067 warned about, and a use of the function being compiled
4068 with GNU semantics, with no diagnostics under -pedantic. */
4069 if (VOID_TYPE_P (type
) && pedantic
&& !in_system_header
)
4070 pedwarn ("ISO C forbids qualified void function return type");
4071 else if (extra_warnings
4072 && !(VOID_TYPE_P (type
)
4073 && type_quals
== TYPE_QUAL_VOLATILE
))
4074 warning ("type qualifiers ignored on function return type");
4076 type
= c_build_qualified_type (type
, type_quals
);
4078 type_quals
= TYPE_UNQUALIFIED
;
4080 type
= build_function_type (type
, arg_types
);
4081 declarator
= TREE_OPERAND (declarator
, 0);
4083 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4084 the formal parameter list of this FUNCTION_TYPE to point to
4085 the FUNCTION_TYPE node itself. */
4090 for (link
= last_function_parm_tags
;
4092 link
= TREE_CHAIN (link
))
4093 TYPE_CONTEXT (TREE_VALUE (link
)) = type
;
4096 else if (TREE_CODE (declarator
) == INDIRECT_REF
)
4098 /* Merge any constancy or volatility into the target type
4101 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4103 pedwarn ("ISO C forbids qualified function types");
4105 type
= c_build_qualified_type (type
, type_quals
);
4106 type_quals
= TYPE_UNQUALIFIED
;
4109 type
= build_pointer_type (type
);
4111 /* Process a list of type modifier keywords
4112 (such as const or volatile) that were given inside the `*'. */
4114 if (TREE_TYPE (declarator
))
4122 for (typemodlist
= TREE_TYPE (declarator
); typemodlist
;
4123 typemodlist
= TREE_CHAIN (typemodlist
))
4125 tree qualifier
= TREE_VALUE (typemodlist
);
4127 if (C_IS_RESERVED_WORD (qualifier
))
4129 if (C_RID_CODE (qualifier
) == RID_CONST
)
4131 else if (C_RID_CODE (qualifier
) == RID_VOLATILE
)
4133 else if (C_RID_CODE (qualifier
) == RID_RESTRICT
)
4143 error ("invalid type modifier within pointer declarator");
4144 if (constp
> 1 && ! flag_isoc99
)
4145 pedwarn ("duplicate `const'");
4146 if (volatilep
> 1 && ! flag_isoc99
)
4147 pedwarn ("duplicate `volatile'");
4148 if (restrictp
> 1 && ! flag_isoc99
)
4149 pedwarn ("duplicate `restrict'");
4151 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4152 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4153 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4156 declarator
= TREE_OPERAND (declarator
, 0);
4163 /* Now TYPE has the actual type. */
4165 /* Did array size calculations overflow? */
4167 if (TREE_CODE (type
) == ARRAY_TYPE
4168 && COMPLETE_TYPE_P (type
)
4169 && TREE_OVERFLOW (TYPE_SIZE (type
)))
4171 error ("size of array `%s' is too large", name
);
4172 /* If we proceed with the array type as it is, we'll eventually
4173 crash in tree_low_cst(). */
4174 type
= error_mark_node
;
4177 /* If this is declaring a typedef name, return a TYPE_DECL. */
4179 if (specbits
& (1 << (int) RID_TYPEDEF
))
4182 /* Note that the grammar rejects storage classes
4183 in typenames, fields or parameters */
4184 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4186 pedwarn ("ISO C forbids qualified function types");
4188 type
= c_build_qualified_type (type
, type_quals
);
4189 decl
= build_decl (TYPE_DECL
, declarator
, type
);
4190 if ((specbits
& (1 << (int) RID_SIGNED
))
4191 || (typedef_decl
&& C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
4192 C_TYPEDEF_EXPLICITLY_SIGNED (decl
) = 1;
4193 decl_attributes (&decl
, returned_attrs
, 0);
4197 /* Detect the case of an array type of unspecified size
4198 which came, as such, direct from a typedef name.
4199 We must copy the type, so that each identifier gets
4200 a distinct type, so that each identifier's size can be
4201 controlled separately by its own initializer. */
4203 if (type
!= 0 && typedef_type
!= 0
4204 && TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
) == 0
4205 && TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (typedef_type
))
4207 type
= build_array_type (TREE_TYPE (type
), 0);
4209 C_TYPE_VARIABLE_SIZE (type
) = 1;
4212 /* If this is a type name (such as, in a cast or sizeof),
4213 compute the type and return it now. */
4215 if (decl_context
== TYPENAME
)
4217 /* Note that the grammar rejects storage classes
4218 in typenames, fields or parameters */
4219 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4221 pedwarn ("ISO C forbids const or volatile function types");
4223 type
= c_build_qualified_type (type
, type_quals
);
4224 decl_attributes (&type
, returned_attrs
, 0);
4228 /* Aside from typedefs and type names (handle above),
4229 `void' at top level (not within pointer)
4230 is allowed only in public variables.
4231 We don't complain about parms either, but that is because
4232 a better error message can be made later. */
4234 if (VOID_TYPE_P (type
) && decl_context
!= PARM
4235 && ! ((decl_context
!= FIELD
&& TREE_CODE (type
) != FUNCTION_TYPE
)
4236 && ((specbits
& (1 << (int) RID_EXTERN
))
4237 || (current_scope
== global_scope
4239 & ((1 << (int) RID_STATIC
) | (1 << (int) RID_REGISTER
)))))))
4241 error ("variable or field `%s' declared void", name
);
4242 type
= integer_type_node
;
4245 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4246 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4251 if (decl_context
== PARM
)
4253 tree type_as_written
;
4256 /* A parameter declared as an array of T is really a pointer to T.
4257 One declared as a function is really a pointer to a function. */
4259 if (TREE_CODE (type
) == ARRAY_TYPE
)
4261 /* Transfer const-ness of array into that of type pointed to. */
4262 type
= TREE_TYPE (type
);
4264 type
= c_build_qualified_type (type
, type_quals
);
4265 type
= build_pointer_type (type
);
4266 type_quals
= TYPE_UNQUALIFIED
;
4267 if (array_ptr_quals
)
4269 tree new_ptr_quals
, new_ptr_attrs
;
4271 split_specs_attrs (array_ptr_quals
, &new_ptr_quals
, &new_ptr_attrs
);
4272 /* We don't yet implement attributes in this context. */
4273 if (new_ptr_attrs
!= NULL_TREE
)
4274 warning ("attributes in parameter array declarator ignored");
4279 for (; new_ptr_quals
; new_ptr_quals
= TREE_CHAIN (new_ptr_quals
))
4281 tree qualifier
= TREE_VALUE (new_ptr_quals
);
4283 if (C_IS_RESERVED_WORD (qualifier
))
4285 if (C_RID_CODE (qualifier
) == RID_CONST
)
4287 else if (C_RID_CODE (qualifier
) == RID_VOLATILE
)
4289 else if (C_RID_CODE (qualifier
) == RID_RESTRICT
)
4299 error ("invalid type modifier within array declarator");
4301 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4302 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4303 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4307 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
4309 if (pedantic
&& type_quals
)
4310 pedwarn ("ISO C forbids qualified function types");
4312 type
= c_build_qualified_type (type
, type_quals
);
4313 type
= build_pointer_type (type
);
4314 type_quals
= TYPE_UNQUALIFIED
;
4316 else if (type_quals
)
4317 type
= c_build_qualified_type (type
, type_quals
);
4319 type_as_written
= type
;
4321 decl
= build_decl (PARM_DECL
, declarator
, type
);
4323 C_DECL_VARIABLE_SIZE (decl
) = 1;
4325 /* Compute the type actually passed in the parmlist,
4326 for the case where there is no prototype.
4327 (For example, shorts and chars are passed as ints.)
4328 When there is a prototype, this is overridden later. */
4330 if (type
== error_mark_node
)
4331 promoted_type
= type
;
4333 promoted_type
= c_type_promotes_to (type
);
4335 DECL_ARG_TYPE (decl
) = promoted_type
;
4336 DECL_ARG_TYPE_AS_WRITTEN (decl
) = type_as_written
;
4338 else if (decl_context
== FIELD
)
4340 /* Structure field. It may not be a function. */
4342 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4344 error ("field `%s' declared as a function", name
);
4345 type
= build_pointer_type (type
);
4347 else if (TREE_CODE (type
) != ERROR_MARK
4348 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type
))
4350 error ("field `%s' has incomplete type", name
);
4351 type
= error_mark_node
;
4353 /* Move type qualifiers down to element of an array. */
4354 if (TREE_CODE (type
) == ARRAY_TYPE
&& type_quals
)
4355 type
= build_array_type (c_build_qualified_type (TREE_TYPE (type
),
4357 TYPE_DOMAIN (type
));
4358 decl
= build_decl (FIELD_DECL
, declarator
, type
);
4359 DECL_NONADDRESSABLE_P (decl
) = bitfield
;
4362 C_DECL_VARIABLE_SIZE (decl
) = 1;
4364 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
4366 /* Every function declaration is "external"
4367 except for those which are inside a function body
4368 in which `auto' is used.
4369 That is a case not specified by ANSI C,
4370 and we use it for forward declarations for nested functions. */
4371 int extern_ref
= (!(specbits
& (1 << (int) RID_AUTO
))
4372 || current_scope
== global_scope
);
4374 if (specbits
& (1 << (int) RID_AUTO
)
4375 && (pedantic
|| current_scope
== global_scope
))
4376 pedwarn ("invalid storage class for function `%s'", name
);
4377 if (specbits
& (1 << (int) RID_REGISTER
))
4378 error ("invalid storage class for function `%s'", name
);
4379 if (specbits
& (1 << (int) RID_THREAD
))
4380 error ("invalid storage class for function `%s'", name
);
4381 /* Function declaration not at file scope.
4382 Storage classes other than `extern' are not allowed
4383 and `extern' makes no difference. */
4384 if (current_scope
!= global_scope
4385 && (specbits
& ((1 << (int) RID_STATIC
) | (1 << (int) RID_INLINE
)))
4387 pedwarn ("invalid storage class for function `%s'", name
);
4389 decl
= build_decl (FUNCTION_DECL
, declarator
, type
);
4390 decl
= build_decl_attribute_variant (decl
, decl_attr
);
4392 DECL_LANG_SPECIFIC (decl
)
4393 = ggc_alloc_cleared (sizeof (struct lang_decl
));
4395 if (pedantic
&& type_quals
&& ! DECL_IN_SYSTEM_HEADER (decl
))
4396 pedwarn ("ISO C forbids qualified function types");
4398 /* GNU C interprets a `volatile void' return type to indicate
4399 that the function does not return. */
4400 if ((type_quals
& TYPE_QUAL_VOLATILE
)
4401 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
4402 warning ("`noreturn' function returns non-void value");
4405 DECL_EXTERNAL (decl
) = 1;
4406 /* Record absence of global scope for `static' or `auto'. */
4408 = !(specbits
& ((1 << (int) RID_STATIC
) | (1 << (int) RID_AUTO
)));
4411 C_FUNCTION_IMPLICIT_INT (decl
) = 1;
4413 /* Record presence of `inline', if it is reasonable. */
4414 if (MAIN_NAME_P (declarator
))
4417 warning ("cannot inline function `main'");
4421 /* Record that the function is declared `inline'. */
4422 DECL_DECLARED_INLINE_P (decl
) = 1;
4424 /* Do not mark bare declarations as DECL_INLINE. Doing so
4425 in the presence of multiple declarations can result in
4426 the abstract origin pointing between the declarations,
4427 which will confuse dwarf2out. */
4430 DECL_INLINE (decl
) = 1;
4431 if (specbits
& (1 << (int) RID_EXTERN
))
4432 current_extern_inline
= 1;
4435 /* If -finline-functions, assume it can be inlined. This does
4436 two things: let the function be deferred until it is actually
4437 needed, and let dwarf2 know that the function is inlinable. */
4438 else if (flag_inline_trees
== 2 && initialized
)
4439 DECL_INLINE (decl
) = 1;
4443 /* It's a variable. */
4444 /* An uninitialized decl with `extern' is a reference. */
4445 int extern_ref
= !initialized
&& (specbits
& (1 << (int) RID_EXTERN
));
4447 /* Move type qualifiers down to element of an array. */
4448 if (TREE_CODE (type
) == ARRAY_TYPE
&& type_quals
)
4450 int saved_align
= TYPE_ALIGN(type
);
4451 type
= build_array_type (c_build_qualified_type (TREE_TYPE (type
),
4453 TYPE_DOMAIN (type
));
4454 TYPE_ALIGN (type
) = saved_align
;
4456 else if (type_quals
)
4457 type
= c_build_qualified_type (type
, type_quals
);
4459 /* It is invalid to create an `extern' declaration for a
4460 variable if there is a global declaration that is
4462 if (extern_ref
&& current_scope
!= global_scope
)
4466 global_decl
= identifier_global_value (declarator
);
4468 && TREE_CODE (global_decl
) == VAR_DECL
4469 && !TREE_PUBLIC (global_decl
))
4470 error ("variable previously declared `static' redeclared "
4474 decl
= build_decl (VAR_DECL
, declarator
, type
);
4476 C_DECL_VARIABLE_SIZE (decl
) = 1;
4479 pedwarn ("%Jvariable '%D' declared `inline'", decl
, decl
);
4481 DECL_EXTERNAL (decl
) = extern_ref
;
4483 /* At file scope, the presence of a `static' or `register' storage
4484 class specifier, or the absence of all storage class specifiers
4485 makes this declaration a definition (perhaps tentative). Also,
4486 the absence of both `static' and `register' makes it public. */
4487 if (current_scope
== global_scope
)
4489 TREE_PUBLIC (decl
) = !(specbits
& ((1 << (int) RID_STATIC
)
4490 | (1 << (int) RID_REGISTER
)));
4491 TREE_STATIC (decl
) = !extern_ref
;
4493 /* Not at file scope, only `static' makes a static definition. */
4496 TREE_STATIC (decl
) = (specbits
& (1 << (int) RID_STATIC
)) != 0;
4497 TREE_PUBLIC (decl
) = extern_ref
;
4500 if (specbits
& 1 << (int) RID_THREAD
)
4502 if (targetm
.have_tls
)
4503 DECL_THREAD_LOCAL (decl
) = 1;
4505 /* A mere warning is sure to result in improper semantics
4506 at runtime. Don't bother to allow this to compile. */
4507 error ("thread-local storage not supported for this target");
4511 /* Record `register' declaration for warnings on &
4512 and in case doing stupid register allocation. */
4514 if (specbits
& (1 << (int) RID_REGISTER
))
4515 DECL_REGISTER (decl
) = 1;
4517 /* Record constancy and volatility. */
4518 c_apply_type_quals_to_decl (type_quals
, decl
);
4520 /* If a type has volatile components, it should be stored in memory.
4521 Otherwise, the fact that those components are volatile
4522 will be ignored, and would even crash the compiler. */
4523 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl
)))
4524 c_mark_addressable (decl
);
4526 #ifdef ENABLE_CHECKING
4527 /* This is the earliest point at which we might know the assembler
4528 name of a variable. Thus, if it's known before this, die horribly. */
4529 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
4533 decl_attributes (&decl
, returned_attrs
, 0);
4539 /* Decode the parameter-list info for a function type or function definition.
4540 The argument is the value returned by `get_parm_info' (or made in parse.y
4541 if there is an identifier list instead of a parameter decl list).
4542 These two functions are separate because when a function returns
4543 or receives functions then each is called multiple times but the order
4544 of calls is different. The last call to `grokparms' is always the one
4545 that contains the formal parameter names of a function definition.
4547 Store in `last_function_parms' a chain of the decls of parms.
4548 Also store in `last_function_parm_tags' a chain of the struct, union,
4549 and enum tags declared among the parms.
4551 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4553 FUNCDEF_FLAG is nonzero for a function definition, 0 for
4554 a mere declaration. A nonempty identifier-list gets an error message
4555 when FUNCDEF_FLAG is zero. */
4558 grokparms (tree parms_info
, int funcdef_flag
)
4560 tree first_parm
= TREE_CHAIN (parms_info
);
4562 last_function_parms
= TREE_PURPOSE (parms_info
);
4563 last_function_parm_tags
= TREE_VALUE (parms_info
);
4564 last_function_parm_others
= TREE_TYPE (parms_info
);
4566 if (warn_strict_prototypes
&& first_parm
== 0 && !funcdef_flag
4567 && !in_system_header
)
4568 warning ("function declaration isn't a prototype");
4571 && TREE_CODE (TREE_VALUE (first_parm
)) == IDENTIFIER_NODE
)
4574 pedwarn ("parameter names (without types) in function declaration");
4576 last_function_parms
= first_parm
;
4583 /* If the arg types are incomplete in a declaration,
4584 they must include undefined tags.
4585 These tags can never be defined in the scope of the declaration,
4586 so the types can never be completed,
4587 and no call can be compiled successfully. */
4589 for (parm
= last_function_parms
, typelt
= first_parm
;
4591 parm
= TREE_CHAIN (parm
))
4592 /* Skip over any enumeration constants declared here. */
4593 if (TREE_CODE (parm
) == PARM_DECL
)
4595 /* Barf if the parameter itself has an incomplete type. */
4596 tree type
= TREE_VALUE (typelt
);
4597 if (type
== error_mark_node
)
4599 if (!COMPLETE_TYPE_P (type
))
4601 if (funcdef_flag
&& DECL_NAME (parm
) != 0)
4602 error ("parameter `%s' has incomplete type",
4603 IDENTIFIER_POINTER (DECL_NAME (parm
)));
4605 warning ("parameter has incomplete type");
4608 TREE_VALUE (typelt
) = error_mark_node
;
4609 TREE_TYPE (parm
) = error_mark_node
;
4612 typelt
= TREE_CHAIN (typelt
);
4619 /* Return a tree_list node with info on a parameter list just parsed.
4620 The TREE_PURPOSE is a list of decls of those parms.
4621 The TREE_VALUE is a list of structure, union and enum tags defined.
4622 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
4623 The TREE_TYPE is a list of non-parameter decls which appeared with the
4625 This tree_list node is later fed to `grokparms'.
4627 VOID_AT_END nonzero means append `void' to the end of the type-list.
4628 Zero means the parmlist ended with an ellipsis so don't append `void'. */
4631 get_parm_info (int void_at_end
)
4633 tree decl
, type
, list
;
4635 tree
*last_type
= &types
;
4636 tree tags
= current_scope
->tags
;
4637 tree parms
= current_scope
->parms
;
4638 tree others
= current_scope
->names
;
4639 static bool explained_incomplete_types
= false;
4640 bool gave_void_only_once_err
= false;
4642 /* Just "void" (and no ellipsis) is special. There are really no parms.
4643 But if the "void" is qualified (by "const" or "volatile"), or has a
4644 storage class specifier ("register"), then the behavior is undefined;
4645 issue an error. Typedefs for "void" are OK (see DR#157). */
4646 if (void_at_end
&& parms
!= 0
4647 && TREE_CHAIN (parms
) == 0
4648 && VOID_TYPE_P (TREE_TYPE (parms
))
4649 && !DECL_NAME (parms
))
4651 if (TREE_THIS_VOLATILE (parms
)
4652 || TREE_READONLY (parms
)
4653 || DECL_REGISTER (parms
))
4654 error ("\"void\" as only parameter may not be qualified");
4656 return tree_cons (0, 0, tree_cons (0, void_type_node
, 0));
4659 /* Sanity check all of the parameter declarations. */
4660 for (decl
= parms
; decl
; decl
= TREE_CHAIN (decl
))
4662 if (TREE_CODE (decl
) != PARM_DECL
)
4664 if (TREE_ASM_WRITTEN (decl
))
4667 /* Since there is a prototype, args are passed in their
4668 declared types. The back end may override this. */
4669 type
= TREE_TYPE (decl
);
4670 DECL_ARG_TYPE (decl
) = type
;
4672 /* Check for (..., void, ...) and issue an error. */
4673 if (VOID_TYPE_P (type
) && !DECL_NAME (decl
) && !gave_void_only_once_err
)
4675 error ("\"void\" must be the only parameter");
4676 gave_void_only_once_err
= true;
4679 type
= build_tree_list (0, type
);
4681 last_type
= &TREE_CHAIN (type
);
4684 /* Check the list of non-parameter decls for any forward parm decls
4685 that never got real decls. */
4686 for (decl
= others
; decl
; decl
= TREE_CHAIN (decl
))
4687 if (TREE_CODE (decl
) == PARM_DECL
)
4689 if (!TREE_ASM_WRITTEN (decl
))
4692 error ("%Jparameter \"%D\" has just a forward declaration",
4696 /* Warn about any struct, union or enum tags defined within this
4697 list. The scope of such types is limited to this declaration,
4698 which is rarely if ever desirable (it's impossible to call such
4699 a function with type-correct arguments). */
4700 for (decl
= tags
; decl
; decl
= TREE_CHAIN (decl
))
4702 enum tree_code code
= TREE_CODE (TREE_VALUE (decl
));
4703 const char *keyword
;
4704 /* An anonymous union parm type is meaningful as a GNU extension.
4705 So don't warn for that. */
4706 if (code
== UNION_TYPE
&& TREE_PURPOSE (decl
) == 0 && !pedantic
)
4709 /* The keyword should not be translated. */
4712 case RECORD_TYPE
: keyword
= "struct"; break;
4713 case UNION_TYPE
: keyword
= "union"; break;
4714 case ENUMERAL_TYPE
: keyword
= "enum"; break;
4718 if (TREE_PURPOSE (decl
))
4719 /* The first %s will be one of 'struct', 'union', or 'enum'. */
4720 warning ("\"%s %s\" declared inside parameter list",
4721 keyword
, IDENTIFIER_POINTER (TREE_PURPOSE (decl
)));
4723 /* The %s will be one of 'struct', 'union', or 'enum'. */
4724 warning ("anonymous %s declared inside parameter list", keyword
);
4726 if (! explained_incomplete_types
)
4728 warning ("its scope is only this definition or declaration,"
4729 " which is probably not what you want");
4730 explained_incomplete_types
= true;
4737 type
= build_tree_list (0, void_type_node
);
4741 list
= tree_cons (parms
, tags
, types
);
4742 TREE_TYPE (list
) = others
;
4746 /* Get the struct, enum or union (CODE says which) with tag NAME.
4747 Define the tag as a forward-reference if it is not defined. */
4750 xref_tag (enum tree_code code
, tree name
)
4752 /* If a cross reference is requested, look up the type
4753 already defined for this tag and return it. */
4755 tree ref
= lookup_tag (code
, name
, 0);
4756 /* If this is the right type of tag, return what we found.
4757 (This reference will be shadowed by shadow_tag later if appropriate.)
4758 If this is the wrong type of tag, do not return it. If it was the
4759 wrong type in the same scope, we will have had an error
4760 message already; if in a different scope and declaring
4761 a name, pending_xref_error will give an error message; but if in a
4762 different scope and not declaring a name, this tag should
4763 shadow the previous declaration of a different type of tag, and
4764 this would not work properly if we return the reference found.
4765 (For example, with "struct foo" in an outer scope, "union foo;"
4766 must shadow that tag with a new one of union type.) */
4767 if (ref
&& TREE_CODE (ref
) == code
)
4770 /* If no such tag is yet defined, create a forward-reference node
4771 and record it as the "definition".
4772 When a real declaration of this type is found,
4773 the forward-reference will be altered into a real type. */
4775 ref
= make_node (code
);
4776 if (code
== ENUMERAL_TYPE
)
4778 /* Give the type a default layout like unsigned int
4779 to avoid crashing if it does not get defined. */
4780 TYPE_MODE (ref
) = TYPE_MODE (unsigned_type_node
);
4781 TYPE_ALIGN (ref
) = TYPE_ALIGN (unsigned_type_node
);
4782 TYPE_USER_ALIGN (ref
) = 0;
4783 TREE_UNSIGNED (ref
) = 1;
4784 TYPE_PRECISION (ref
) = TYPE_PRECISION (unsigned_type_node
);
4785 TYPE_MIN_VALUE (ref
) = TYPE_MIN_VALUE (unsigned_type_node
);
4786 TYPE_MAX_VALUE (ref
) = TYPE_MAX_VALUE (unsigned_type_node
);
4789 pushtag (name
, ref
);
4794 /* Make sure that the tag NAME is defined *in the current scope*
4795 at least as a forward reference.
4796 CODE says which kind of tag NAME ought to be. */
4799 start_struct (enum tree_code code
, tree name
)
4801 /* If there is already a tag defined at this scope
4802 (as a forward reference), just return it. */
4807 ref
= lookup_tag (code
, name
, 1);
4808 if (ref
&& TREE_CODE (ref
) == code
)
4810 if (TYPE_FIELDS (ref
))
4812 if (code
== UNION_TYPE
)
4813 error ("redefinition of `union %s'", IDENTIFIER_POINTER (name
));
4815 error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name
));
4820 /* Otherwise create a forward-reference just so the tag is in scope. */
4822 ref
= make_node (code
);
4823 pushtag (name
, ref
);
4826 C_TYPE_BEING_DEFINED (ref
) = 1;
4827 TYPE_PACKED (ref
) = flag_pack_struct
;
4831 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
4832 of a structure component, returning a FIELD_DECL node.
4833 WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
4835 This is done during the parsing of the struct declaration.
4836 The FIELD_DECL nodes are chained together and the lot of them
4837 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
4840 grokfield (tree declarator
, tree declspecs
, tree width
)
4844 if (declarator
== NULL_TREE
&& width
== NULL_TREE
)
4846 /* This is an unnamed decl.
4848 If we have something of the form "union { list } ;" then this
4849 is the anonymous union extension. Similarly for struct.
4851 If this is something of the form "struct foo;", then
4852 If MS extensions are enabled, this is handled as an
4854 Otherwise this is a forward declaration of a structure tag.
4856 If this is something of the form "foo;" and foo is a TYPE_DECL, then
4857 If MS extensions are enabled and foo names a structure, then
4858 again this is an anonymous struct.
4859 Otherwise this is an error.
4861 Oh what a horrid tangled web we weave. I wonder if MS consciously
4862 took this from Plan 9 or if it was an accident of implementation
4863 that took root before someone noticed the bug... */
4865 tree type
= TREE_VALUE (declspecs
);
4867 if (flag_ms_extensions
&& TREE_CODE (type
) == TYPE_DECL
)
4868 type
= TREE_TYPE (type
);
4869 if (TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
)
4871 if (flag_ms_extensions
)
4874 goto warn_unnamed_field
;
4875 else if (TYPE_NAME (type
) == NULL
)
4878 goto warn_unnamed_field
;
4883 warning ("declaration does not declare anything");
4888 value
= grokdeclarator (declarator
, declspecs
, FIELD
, 0,
4889 width
? &width
: NULL
);
4891 finish_decl (value
, NULL_TREE
, NULL_TREE
);
4892 DECL_INITIAL (value
) = width
;
4897 /* Generate an error for any duplicate field names in FIELDLIST. Munge
4898 the list such that this does not present a problem later. */
4901 detect_field_duplicates (tree fieldlist
)
4906 /* First, see if there are more than "a few" fields.
4907 This is trivially true if there are zero or one fields. */
4910 x
= TREE_CHAIN (fieldlist
);
4916 } while (timeout
> 0 && x
);
4918 /* If there were "few" fields, avoid the overhead of allocating
4919 a hash table. Instead just do the nested traversal thing. */
4922 for (x
= TREE_CHAIN (fieldlist
); x
; x
= TREE_CHAIN (x
))
4925 for (y
= fieldlist
; y
!= x
; y
= TREE_CHAIN (y
))
4926 if (DECL_NAME (y
) == DECL_NAME (x
))
4928 error ("%Jduplicate member '%D'", x
, x
);
4929 DECL_NAME (x
) = NULL_TREE
;
4935 htab_t htab
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
4938 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
4939 if ((y
= DECL_NAME (x
)) != 0)
4941 slot
= htab_find_slot (htab
, y
, INSERT
);
4944 error ("%Jduplicate member '%D'", x
, x
);
4945 DECL_NAME (x
) = NULL_TREE
;
4954 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
4955 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
4956 ATTRIBUTES are attributes to be applied to the structure. */
4959 finish_struct (tree t
, tree fieldlist
, tree attributes
)
4962 int toplevel
= global_scope
== current_scope
;
4963 int saw_named_field
;
4965 /* If this type was previously laid out as a forward reference,
4966 make sure we lay it out again. */
4970 decl_attributes (&t
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
4972 /* Nameless union parm types are useful as GCC extension. */
4973 if (! (TREE_CODE (t
) == UNION_TYPE
&& TYPE_NAME (t
) == 0) && !pedantic
)
4974 /* Otherwise, warn about any struct or union def. in parmlist. */
4975 if (in_parm_level_p ())
4978 pedwarn ("%s defined inside parms",
4979 TREE_CODE (t
) == UNION_TYPE
? _("union") : _("structure"));
4981 warning ("%s defined inside parms",
4982 TREE_CODE (t
) == UNION_TYPE
? _("union") : _("structure"));
4987 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
4988 if (DECL_NAME (x
) != 0)
4992 pedwarn ("%s has no %s",
4993 TREE_CODE (t
) == UNION_TYPE
? _("union") : _("struct"),
4994 fieldlist
? _("named members") : _("members"));
4997 /* Install struct as DECL_CONTEXT of each field decl.
4998 Also process specified field sizes,m which is found in the DECL_INITIAL.
4999 Store 0 there, except for ": 0" fields (so we can find them
5000 and delete them, below). */
5002 saw_named_field
= 0;
5003 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5005 DECL_CONTEXT (x
) = t
;
5006 DECL_PACKED (x
) |= TYPE_PACKED (t
);
5008 /* If any field is const, the structure type is pseudo-const. */
5009 if (TREE_READONLY (x
))
5010 C_TYPE_FIELDS_READONLY (t
) = 1;
5013 /* A field that is pseudo-const makes the structure likewise. */
5014 tree t1
= TREE_TYPE (x
);
5015 while (TREE_CODE (t1
) == ARRAY_TYPE
)
5016 t1
= TREE_TYPE (t1
);
5017 if ((TREE_CODE (t1
) == RECORD_TYPE
|| TREE_CODE (t1
) == UNION_TYPE
)
5018 && C_TYPE_FIELDS_READONLY (t1
))
5019 C_TYPE_FIELDS_READONLY (t
) = 1;
5022 /* Any field that is volatile means variables of this type must be
5023 treated in some ways as volatile. */
5024 if (TREE_THIS_VOLATILE (x
))
5025 C_TYPE_FIELDS_VOLATILE (t
) = 1;
5027 /* Any field of nominal variable size implies structure is too. */
5028 if (C_DECL_VARIABLE_SIZE (x
))
5029 C_TYPE_VARIABLE_SIZE (t
) = 1;
5031 /* Detect invalid nested redefinition. */
5032 if (TREE_TYPE (x
) == t
)
5033 error ("nested redefinition of `%s'",
5034 IDENTIFIER_POINTER (TYPE_NAME (t
)));
5036 if (DECL_INITIAL (x
))
5038 unsigned HOST_WIDE_INT width
= tree_low_cst (DECL_INITIAL (x
), 1);
5039 DECL_SIZE (x
) = bitsize_int (width
);
5040 DECL_BIT_FIELD (x
) = 1;
5041 SET_DECL_C_BIT_FIELD (x
);
5044 DECL_INITIAL (x
) = 0;
5046 /* Detect flexible array member in an invalid context. */
5047 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
5048 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
5049 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
5050 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
5052 if (TREE_CODE (t
) == UNION_TYPE
)
5053 error ("%Jflexible array member in union", x
);
5054 else if (TREE_CHAIN (x
) != NULL_TREE
)
5055 error ("%Jflexible array member not at end of struct", x
);
5056 else if (! saw_named_field
)
5057 error ("%Jflexible array member in otherwise empty struct", x
);
5060 if (pedantic
&& TREE_CODE (t
) == RECORD_TYPE
5061 && flexible_array_type_p (TREE_TYPE (x
)))
5062 pedwarn ("%Jinvalid use of structure with flexible array member", x
);
5065 saw_named_field
= 1;
5068 detect_field_duplicates (fieldlist
);
5070 /* Now we have the nearly final fieldlist. Record it,
5071 then lay out the structure or union (including the fields). */
5073 TYPE_FIELDS (t
) = fieldlist
;
5077 /* Delete all zero-width bit-fields from the fieldlist. */
5079 tree
*fieldlistp
= &fieldlist
;
5081 if (TREE_CODE (*fieldlistp
) == FIELD_DECL
&& DECL_INITIAL (*fieldlistp
))
5082 *fieldlistp
= TREE_CHAIN (*fieldlistp
);
5084 fieldlistp
= &TREE_CHAIN (*fieldlistp
);
5087 /* Now we have the truly final field list.
5088 Store it in this type and in the variants. */
5090 TYPE_FIELDS (t
) = fieldlist
;
5092 /* If there are lots of fields, sort so we can look through them fast.
5093 We arbitrarily consider 16 or more elts to be "a lot". */
5098 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5100 if (len
> 15 || DECL_NAME (x
) == NULL
)
5108 struct lang_type
*space
;
5109 struct sorted_fields_type
*space2
;
5111 len
+= list_length (x
);
5113 /* Use the same allocation policy here that make_node uses, to
5114 ensure that this lives as long as the rest of the struct decl.
5115 All decls in an inline function need to be saved. */
5117 space
= ggc_alloc (sizeof (struct lang_type
));
5118 space2
= ggc_alloc (sizeof (struct sorted_fields_type
) + len
* sizeof (tree
));
5122 field_array
= &space2
->elts
[0];
5123 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5125 field_array
[len
++] = x
;
5127 /* If there is anonymous struct or union, break out of the loop. */
5128 if (DECL_NAME (x
) == NULL
)
5131 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
5134 TYPE_LANG_SPECIFIC (t
) = space
;
5135 TYPE_LANG_SPECIFIC (t
)->s
->len
= len
;
5136 field_array
= TYPE_LANG_SPECIFIC (t
)->s
->elts
;
5137 qsort (field_array
, len
, sizeof (tree
), field_decl_cmp
);
5142 for (x
= TYPE_MAIN_VARIANT (t
); x
; x
= TYPE_NEXT_VARIANT (x
))
5144 TYPE_FIELDS (x
) = TYPE_FIELDS (t
);
5145 TYPE_LANG_SPECIFIC (x
) = TYPE_LANG_SPECIFIC (t
);
5146 TYPE_ALIGN (x
) = TYPE_ALIGN (t
);
5147 TYPE_USER_ALIGN (x
) = TYPE_USER_ALIGN (t
);
5150 /* If this was supposed to be a transparent union, but we can't
5151 make it one, warn and turn off the flag. */
5152 if (TREE_CODE (t
) == UNION_TYPE
5153 && TYPE_TRANSPARENT_UNION (t
)
5154 && TYPE_MODE (t
) != DECL_MODE (TYPE_FIELDS (t
)))
5156 TYPE_TRANSPARENT_UNION (t
) = 0;
5157 warning ("union cannot be made transparent");
5160 /* If this structure or union completes the type of any previous
5161 variable declaration, lay it out and output its rtl. */
5162 for (x
= C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
));
5166 tree decl
= TREE_VALUE (x
);
5167 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
5168 layout_array_type (TREE_TYPE (decl
));
5169 if (TREE_CODE (decl
) != TYPE_DECL
)
5171 layout_decl (decl
, 0);
5172 if (c_dialect_objc ())
5173 objc_check_decl (decl
);
5174 rest_of_decl_compilation (decl
, NULL
, toplevel
, 0);
5179 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
)) = 0;
5181 /* Finish debugging output for this type. */
5182 rest_of_type_compilation (t
, toplevel
);
5187 /* Lay out the type T, and its element type, and so on. */
5190 layout_array_type (tree t
)
5192 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5193 layout_array_type (TREE_TYPE (t
));
5197 /* Begin compiling the definition of an enumeration type.
5198 NAME is its name (or null if anonymous).
5199 Returns the type object, as yet incomplete.
5200 Also records info about it so that build_enumerator
5201 may be used to declare the individual values as they are read. */
5204 start_enum (tree name
)
5208 /* If this is the real definition for a previous forward reference,
5209 fill in the contents in the same object that used to be the
5210 forward reference. */
5213 enumtype
= lookup_tag (ENUMERAL_TYPE
, name
, 1);
5215 if (enumtype
== 0 || TREE_CODE (enumtype
) != ENUMERAL_TYPE
)
5217 enumtype
= make_node (ENUMERAL_TYPE
);
5218 pushtag (name
, enumtype
);
5221 C_TYPE_BEING_DEFINED (enumtype
) = 1;
5223 if (TYPE_VALUES (enumtype
) != 0)
5225 /* This enum is a named one that has been declared already. */
5226 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name
));
5228 /* Completely replace its old definition.
5229 The old enumerators remain defined, however. */
5230 TYPE_VALUES (enumtype
) = 0;
5233 enum_next_value
= integer_zero_node
;
5236 if (flag_short_enums
)
5237 TYPE_PACKED (enumtype
) = 1;
5242 /* After processing and defining all the values of an enumeration type,
5243 install their decls in the enumeration type and finish it off.
5244 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5245 and ATTRIBUTES are the specified attributes.
5246 Returns ENUMTYPE. */
5249 finish_enum (tree enumtype
, tree values
, tree attributes
)
5252 tree minnode
= 0, maxnode
= 0, enum_value_type
;
5253 int precision
, unsign
;
5254 int toplevel
= (global_scope
== current_scope
);
5256 if (in_parm_level_p ())
5257 warning ("enum defined inside parms");
5259 decl_attributes (&enumtype
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
5261 /* Calculate the maximum value of any enumerator in this type. */
5263 if (values
== error_mark_node
)
5264 minnode
= maxnode
= integer_zero_node
;
5267 minnode
= maxnode
= TREE_VALUE (values
);
5268 for (pair
= TREE_CHAIN (values
); pair
; pair
= TREE_CHAIN (pair
))
5270 tree value
= TREE_VALUE (pair
);
5271 if (tree_int_cst_lt (maxnode
, value
))
5273 if (tree_int_cst_lt (value
, minnode
))
5278 /* Construct the final type of this enumeration. It is the same
5279 as one of the integral types - the narrowest one that fits, except
5280 that normally we only go as narrow as int - and signed iff any of
5281 the values are negative. */
5282 unsign
= (tree_int_cst_sgn (minnode
) >= 0);
5283 precision
= MAX (min_precision (minnode
, unsign
),
5284 min_precision (maxnode
, unsign
));
5285 if (TYPE_PACKED (enumtype
) || precision
> TYPE_PRECISION (integer_type_node
))
5287 tree narrowest
= c_common_type_for_size (precision
, unsign
);
5290 warning ("enumeration values exceed range of largest integer");
5291 narrowest
= long_long_integer_type_node
;
5294 precision
= TYPE_PRECISION (narrowest
);
5297 precision
= TYPE_PRECISION (integer_type_node
);
5299 if (precision
== TYPE_PRECISION (integer_type_node
))
5300 enum_value_type
= c_common_type_for_size (precision
, 0);
5302 enum_value_type
= enumtype
;
5304 TYPE_MIN_VALUE (enumtype
) = minnode
;
5305 TYPE_MAX_VALUE (enumtype
) = maxnode
;
5306 TYPE_PRECISION (enumtype
) = precision
;
5307 TREE_UNSIGNED (enumtype
) = unsign
;
5308 TYPE_SIZE (enumtype
) = 0;
5309 layout_type (enumtype
);
5311 if (values
!= error_mark_node
)
5313 /* Change the type of the enumerators to be the enum type. We
5314 need to do this irrespective of the size of the enum, for
5315 proper type checking. Replace the DECL_INITIALs of the
5316 enumerators, and the value slots of the list, with copies
5317 that have the enum type; they cannot be modified in place
5318 because they may be shared (e.g. integer_zero_node) Finally,
5319 change the purpose slots to point to the names of the decls. */
5320 for (pair
= values
; pair
; pair
= TREE_CHAIN (pair
))
5322 tree enu
= TREE_PURPOSE (pair
);
5324 TREE_TYPE (enu
) = enumtype
;
5326 /* The ISO C Standard mandates enumerators to have type int,
5327 even though the underlying type of an enum type is
5328 unspecified. Here we convert any enumerators that fit in
5329 an int to type int, to avoid promotions to unsigned types
5330 when comparing integers with enumerators that fit in the
5331 int range. When -pedantic is given, build_enumerator()
5332 would have already taken care of those that don't fit. */
5333 if (int_fits_type_p (DECL_INITIAL (enu
), enum_value_type
))
5334 DECL_INITIAL (enu
) = convert (enum_value_type
, DECL_INITIAL (enu
));
5336 DECL_INITIAL (enu
) = convert (enumtype
, DECL_INITIAL (enu
));
5338 TREE_PURPOSE (pair
) = DECL_NAME (enu
);
5339 TREE_VALUE (pair
) = DECL_INITIAL (enu
);
5342 TYPE_VALUES (enumtype
) = values
;
5345 /* Fix up all variant types of this enum type. */
5346 for (tem
= TYPE_MAIN_VARIANT (enumtype
); tem
; tem
= TYPE_NEXT_VARIANT (tem
))
5348 if (tem
== enumtype
)
5350 TYPE_VALUES (tem
) = TYPE_VALUES (enumtype
);
5351 TYPE_MIN_VALUE (tem
) = TYPE_MIN_VALUE (enumtype
);
5352 TYPE_MAX_VALUE (tem
) = TYPE_MAX_VALUE (enumtype
);
5353 TYPE_SIZE (tem
) = TYPE_SIZE (enumtype
);
5354 TYPE_SIZE_UNIT (tem
) = TYPE_SIZE_UNIT (enumtype
);
5355 TYPE_MODE (tem
) = TYPE_MODE (enumtype
);
5356 TYPE_PRECISION (tem
) = TYPE_PRECISION (enumtype
);
5357 TYPE_ALIGN (tem
) = TYPE_ALIGN (enumtype
);
5358 TYPE_USER_ALIGN (tem
) = TYPE_USER_ALIGN (enumtype
);
5359 TREE_UNSIGNED (tem
) = TREE_UNSIGNED (enumtype
);
5362 /* Finish debugging output for this type. */
5363 rest_of_type_compilation (enumtype
, toplevel
);
5368 /* Build and install a CONST_DECL for one value of the
5369 current enumeration type (one that was begun with start_enum).
5370 Return a tree-list containing the CONST_DECL and its value.
5371 Assignment of sequential values by default is handled here. */
5374 build_enumerator (tree name
, tree value
)
5378 /* Validate and default VALUE. */
5380 /* Remove no-op casts from the value. */
5382 STRIP_TYPE_NOPS (value
);
5386 if (TREE_CODE (value
) == INTEGER_CST
)
5388 value
= default_conversion (value
);
5389 constant_expression_warning (value
);
5393 error ("enumerator value for `%s' not integer constant",
5394 IDENTIFIER_POINTER (name
));
5399 /* Default based on previous value. */
5400 /* It should no longer be possible to have NON_LVALUE_EXPR
5404 value
= enum_next_value
;
5406 error ("overflow in enumeration values");
5409 if (pedantic
&& ! int_fits_type_p (value
, integer_type_node
))
5411 pedwarn ("ISO C restricts enumerator values to range of `int'");
5412 value
= convert (integer_type_node
, value
);
5415 /* Set basis for default for next value. */
5416 enum_next_value
= build_binary_op (PLUS_EXPR
, value
, integer_one_node
, 0);
5417 enum_overflow
= tree_int_cst_lt (enum_next_value
, value
);
5419 /* Now create a declaration for the enum value name. */
5421 type
= TREE_TYPE (value
);
5422 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
5423 TYPE_PRECISION (integer_type_node
)),
5424 (TYPE_PRECISION (type
)
5425 >= TYPE_PRECISION (integer_type_node
)
5426 && TREE_UNSIGNED (type
)));
5428 decl
= build_decl (CONST_DECL
, name
, type
);
5429 DECL_INITIAL (decl
) = convert (type
, value
);
5432 return tree_cons (decl
, value
, NULL_TREE
);
5436 /* Create the FUNCTION_DECL for a function definition.
5437 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
5438 the declaration; they describe the function's name and the type it returns,
5439 but twisted together in a fashion that parallels the syntax of C.
5441 This function creates a binding context for the function body
5442 as well as setting up the FUNCTION_DECL in current_function_decl.
5444 Returns 1 on success. If the DECLARATOR is not suitable for a function
5445 (it defines a datum instead), we return 0, which tells
5446 yyparse to report a parse error. */
5449 start_function (tree declspecs
, tree declarator
, tree attributes
)
5451 tree decl1
, old_decl
;
5453 int old_immediate_size_expand
= immediate_size_expand
;
5455 current_function_returns_value
= 0; /* Assume, until we see it does. */
5456 current_function_returns_null
= 0;
5457 current_function_returns_abnormally
= 0;
5458 warn_about_return_type
= 0;
5459 current_extern_inline
= 0;
5460 c_in_iteration_stmt
= 0;
5463 /* Don't expand any sizes in the return type of the function. */
5464 immediate_size_expand
= 0;
5466 decl1
= grokdeclarator (declarator
, declspecs
, FUNCDEF
, 1, NULL
);
5468 /* If the declarator is not suitable for a function definition,
5469 cause a syntax error. */
5472 immediate_size_expand
= old_immediate_size_expand
;
5476 decl_attributes (&decl1
, attributes
, 0);
5478 if (DECL_DECLARED_INLINE_P (decl1
)
5479 && DECL_UNINLINABLE (decl1
)
5480 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1
)))
5481 warning ("%Jinline function '%D' given attribute noinline", decl1
, decl1
);
5483 announce_function (decl1
);
5485 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1
))))
5487 error ("return type is an incomplete type");
5488 /* Make it return void instead. */
5490 = build_function_type (void_type_node
,
5491 TYPE_ARG_TYPES (TREE_TYPE (decl1
)));
5494 if (warn_about_return_type
)
5495 pedwarn_c99 ("return type defaults to `int'");
5497 /* Save the parm names or decls from this function's declarator
5498 where store_parm_decls will find them. */
5499 current_function_parms
= last_function_parms
;
5500 current_function_parm_tags
= last_function_parm_tags
;
5501 current_function_parm_others
= last_function_parm_others
;
5503 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5504 error_mark_node is replaced below (in poplevel) with the BLOCK. */
5505 DECL_INITIAL (decl1
) = error_mark_node
;
5507 /* If this definition isn't a prototype and we had a prototype declaration
5508 before, copy the arg type info from that prototype.
5509 But not if what we had before was a builtin function. */
5510 old_decl
= lookup_name_current_level (DECL_NAME (decl1
));
5511 if (old_decl
!= 0 && TREE_CODE (TREE_TYPE (old_decl
)) == FUNCTION_TYPE
5512 && !DECL_BUILT_IN (old_decl
)
5513 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
5514 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl
))))
5515 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0)
5517 TREE_TYPE (decl1
) = TREE_TYPE (old_decl
);
5518 current_function_prototype_locus
= DECL_SOURCE_LOCATION (old_decl
);
5521 /* Optionally warn of old-fashioned def with no previous prototype. */
5522 if (warn_strict_prototypes
5523 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0
5524 && C_DECL_ISNT_PROTOTYPE (old_decl
))
5525 warning ("function declaration isn't a prototype");
5526 /* Optionally warn of any global def with no previous prototype. */
5527 else if (warn_missing_prototypes
5528 && TREE_PUBLIC (decl1
)
5529 && ! MAIN_NAME_P (DECL_NAME (decl1
))
5530 && C_DECL_ISNT_PROTOTYPE (old_decl
))
5531 warning ("%Jno previous prototype for '%D'", decl1
, decl1
);
5532 /* Optionally warn of any def with no previous prototype
5533 if the function has already been used. */
5534 else if (warn_missing_prototypes
5535 && old_decl
!= 0 && TREE_USED (old_decl
)
5536 && TYPE_ARG_TYPES (TREE_TYPE (old_decl
)) == 0)
5537 warning ("%J'%D' was used with no prototype before its definition",
5539 /* Optionally warn of any global def with no previous declaration. */
5540 else if (warn_missing_declarations
5541 && TREE_PUBLIC (decl1
)
5543 && ! MAIN_NAME_P (DECL_NAME (decl1
)))
5544 warning ("%Jno previous declaration for '%D'", decl1
, decl1
);
5545 /* Optionally warn of any def with no previous declaration
5546 if the function has already been used. */
5547 else if (warn_missing_declarations
5548 && old_decl
!= 0 && TREE_USED (old_decl
)
5549 && C_DECL_IMPLICIT (old_decl
))
5550 warning ("%J`%D' was used with no declaration before its definition",
5553 /* This is a definition, not a reference.
5554 So normally clear DECL_EXTERNAL.
5555 However, `extern inline' acts like a declaration
5556 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5557 DECL_EXTERNAL (decl1
) = current_extern_inline
;
5559 /* This function exists in static storage.
5560 (This does not mean `static' in the C sense!) */
5561 TREE_STATIC (decl1
) = 1;
5563 /* A nested function is not global. */
5564 if (current_function_decl
!= 0)
5565 TREE_PUBLIC (decl1
) = 0;
5567 #ifdef ENABLE_CHECKING
5568 /* This is the earliest point at which we might know the assembler
5569 name of the function. Thus, if it's set before this, die horribly. */
5570 if (DECL_ASSEMBLER_NAME_SET_P (decl1
))
5574 /* If #pragma weak was used, mark the decl weak now. */
5575 if (current_scope
== global_scope
)
5576 maybe_apply_pragma_weak (decl1
);
5578 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5579 if (warn_main
> 0 && MAIN_NAME_P (DECL_NAME (decl1
)))
5584 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
5585 != integer_type_node
)
5586 pedwarn ("%Jreturn type of '%D' is not `int'", decl1
, decl1
);
5588 for (args
= TYPE_ARG_TYPES (TREE_TYPE (decl1
)); args
;
5589 args
= TREE_CHAIN (args
))
5591 tree type
= args
? TREE_VALUE (args
) : 0;
5593 if (type
== void_type_node
)
5600 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
5601 pedwarn ("%Jfirst argument of '%D' should be `int'",
5606 if (TREE_CODE (type
) != POINTER_TYPE
5607 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
5608 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
5610 pedwarn ("%Jsecond argument of '%D' should be 'char **'",
5615 if (TREE_CODE (type
) != POINTER_TYPE
5616 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
5617 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
5619 pedwarn ("%Jthird argument of '%D' should probably be "
5620 "'char **'", decl1
, decl1
);
5625 /* It is intentional that this message does not mention the third
5626 argument because it's only mentioned in an appendix of the
5628 if (argct
> 0 && (argct
< 2 || argct
> 3))
5629 pedwarn ("%J'%D' takes only zero or two arguments", decl1
, decl1
);
5631 if (! TREE_PUBLIC (decl1
))
5632 pedwarn ("%J'%D' is normally a non-static function", decl1
, decl1
);
5635 /* Record the decl so that the function name is defined.
5636 If we already have a decl for this name, and it is a FUNCTION_DECL,
5637 use the old decl. */
5639 current_function_decl
= pushdecl (decl1
);
5642 declare_parm_level ();
5644 make_decl_rtl (current_function_decl
, NULL
);
5646 restype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
5647 /* Promote the value to int before returning it. */
5648 if (c_promoting_integer_type_p (restype
))
5650 /* It retains unsignedness if not really getting wider. */
5651 if (TREE_UNSIGNED (restype
)
5652 && (TYPE_PRECISION (restype
)
5653 == TYPE_PRECISION (integer_type_node
)))
5654 restype
= unsigned_type_node
;
5656 restype
= integer_type_node
;
5658 DECL_RESULT (current_function_decl
)
5659 = build_decl (RESULT_DECL
, NULL_TREE
, restype
);
5661 /* If this fcn was already referenced via a block-scope `extern' decl
5662 (or an implicit decl), propagate certain information about the usage. */
5663 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl
)))
5664 TREE_ADDRESSABLE (current_function_decl
) = 1;
5666 immediate_size_expand
= old_immediate_size_expand
;
5668 start_fname_decls ();
5673 /* Subroutine of store_parm_decls which handles new-style function
5674 definitions (prototype format). The parms already have decls, so we
5675 need only record them as in effect and complain if any redundant
5676 old-style parm decls were written. */
5678 store_parm_decls_newstyle (void)
5681 tree fndecl
= current_function_decl
;
5682 tree parms
= current_function_parms
;
5683 tree tags
= current_function_parm_tags
;
5684 tree others
= current_function_parm_others
;
5686 if (current_scope
->parms
|| current_scope
->names
|| current_scope
->tags
)
5688 error ("%Jold-style parameter declarations in prototyped "
5689 "function definition", fndecl
);
5691 /* Get rid of the old-style declarations. */
5696 /* Now make all the parameter declarations visible in the function body.
5697 We can bypass most of the grunt work of pushdecl. */
5698 for (last
= 0, decl
= parms
; decl
; last
= decl
, decl
= TREE_CHAIN (decl
))
5700 DECL_CONTEXT (decl
) = current_function_decl
;
5701 if (DECL_NAME (decl
) == 0)
5702 error ("%Jparameter name omitted", decl
);
5705 if (IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl
)))
5706 current_scope
->shadowed
5707 = tree_cons (DECL_NAME (decl
),
5708 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl
)),
5709 current_scope
->shadowed
);
5710 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl
)) = decl
;
5713 current_scope
->parms
= parms
;
5714 current_scope
->parms_last
= last
;
5716 /* Record the parameter list in the function declaration. */
5717 DECL_ARGUMENTS (fndecl
) = parms
;
5719 /* Now make all the ancillary declarations visible, likewise. */
5720 for (last
= 0, decl
= others
; decl
; last
= decl
, decl
= TREE_CHAIN (decl
))
5722 DECL_CONTEXT (decl
) = current_function_decl
;
5723 if (DECL_NAME (decl
)
5724 && TYPE_MAIN_VARIANT (TREE_TYPE (decl
)) != void_type_node
)
5726 if (IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl
)))
5727 current_scope
->shadowed
5728 = tree_cons (DECL_NAME (decl
),
5729 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl
)),
5730 current_scope
->shadowed
);
5731 IDENTIFIER_SYMBOL_VALUE (DECL_NAME (decl
)) = decl
;
5734 current_scope
->names
= others
;
5735 current_scope
->names_last
= last
;
5737 /* And all the tag declarations. */
5738 for (decl
= tags
; decl
; decl
= TREE_CHAIN (decl
))
5739 if (TREE_PURPOSE (decl
))
5741 if (IDENTIFIER_TAG_VALUE (TREE_PURPOSE (decl
)))
5742 current_scope
->shadowed_tags
5743 = tree_cons (TREE_PURPOSE (decl
),
5744 IDENTIFIER_SYMBOL_VALUE (TREE_PURPOSE (decl
)),
5745 current_scope
->shadowed_tags
);
5746 IDENTIFIER_TAG_VALUE (TREE_PURPOSE (decl
)) = TREE_VALUE (decl
);
5748 current_scope
->tags
= tags
;
5751 /* Subroutine of store_parm_decls which handles old-style function
5752 definitions (separate parameter list and declarations). */
5755 store_parm_decls_oldstyle (void)
5757 tree parm
, decl
, last
;
5758 tree fndecl
= current_function_decl
;
5760 /* This is the identifier list from the function declarator. */
5761 tree parmids
= current_function_parms
;
5763 /* We use DECL_WEAK as a flag to show which parameters have been
5764 seen already, since it is not used on PARM_DECL. */
5765 #ifdef ENABLE_CHECKING
5766 for (parm
= current_scope
->parms
; parm
; parm
= TREE_CHAIN (parm
))
5767 if (DECL_WEAK (parm
))
5771 /* Match each formal parameter name with its declaration. Save each
5772 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
5773 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
5775 if (TREE_VALUE (parm
) == 0)
5777 error ("%Jparameter name missing from parameter list", fndecl
);
5778 TREE_PURPOSE (parm
) = 0;
5782 decl
= IDENTIFIER_SYMBOL_VALUE (TREE_VALUE (parm
));
5783 if (decl
&& DECL_CONTEXT (decl
) == fndecl
)
5785 /* If we got something other than a PARM_DECL it is an error. */
5786 if (TREE_CODE (decl
) != PARM_DECL
)
5787 error ("%J\"%D\" declared as a non-parameter", decl
, decl
);
5788 /* If the declaration is already marked, we have a duplicate
5789 name. Complain and ignore the duplicate. */
5790 else if (DECL_WEAK (decl
))
5792 error ("%Jmultiple parameters named \"%D\"", decl
, decl
);
5793 TREE_PURPOSE (parm
) = 0;
5796 /* If the declaration says "void", complain and turn it into
5798 else if (VOID_TYPE_P (TREE_TYPE (decl
)))
5800 error ("%Jparameter \"%D\" declared void", decl
, decl
);
5801 TREE_TYPE (decl
) = integer_type_node
;
5802 DECL_ARG_TYPE (decl
) = integer_type_node
;
5803 layout_decl (decl
, 0);
5806 /* If no declaration found, default to int. */
5809 decl
= build_decl (PARM_DECL
, TREE_VALUE (parm
), integer_type_node
);
5810 DECL_ARG_TYPE (decl
) = TREE_TYPE (decl
);
5811 DECL_SOURCE_LOCATION (decl
) = DECL_SOURCE_LOCATION (fndecl
);
5815 pedwarn ("%Jtype of \"%D\" defaults to \"int\"", decl
, decl
);
5816 else if (extra_warnings
)
5817 warning ("%Jtype of \"%D\" defaults to \"int\"", decl
, decl
);
5820 TREE_PURPOSE (parm
) = decl
;
5821 DECL_WEAK (decl
) = 1;
5824 /* Now examine the parms chain for incomplete declarations
5825 and declarations with no corresponding names. */
5827 for (parm
= current_scope
->parms
; parm
; parm
= TREE_CHAIN (parm
))
5829 if (!COMPLETE_TYPE_P (TREE_TYPE (parm
)))
5831 error ("%Jparameter \"%D\" has incomplete type", parm
, parm
);
5832 TREE_TYPE (parm
) = error_mark_node
;
5835 if (! DECL_WEAK (parm
))
5837 error ("%Jdeclaration for parameter \"%D\" but no such parameter",
5840 /* Pretend the parameter was not missing.
5841 This gets us to a standard state and minimizes
5842 further error messages. */
5843 parmids
= chainon (parmids
, tree_cons (parm
, 0, 0));
5847 /* Chain the declarations together in the order of the list of
5848 names. Store that chain in the function decl, replacing the
5849 list of names. Update the current scope to match. */
5850 DECL_ARGUMENTS (fndecl
) = 0;
5852 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
5853 if (TREE_PURPOSE (parm
))
5855 if (parm
&& TREE_PURPOSE (parm
))
5857 last
= TREE_PURPOSE (parm
);
5858 DECL_ARGUMENTS (fndecl
) = last
;
5859 current_scope
->parms
= last
;
5860 DECL_WEAK (last
) = 0;
5862 for (parm
= TREE_CHAIN (parm
); parm
; parm
= TREE_CHAIN (parm
))
5863 if (TREE_PURPOSE (parm
))
5865 TREE_CHAIN (last
) = TREE_PURPOSE (parm
);
5866 last
= TREE_PURPOSE (parm
);
5867 DECL_WEAK (last
) = 0;
5869 current_scope
->parms_last
= last
;
5870 TREE_CHAIN (last
) = 0;
5873 /* If there was a previous prototype,
5874 set the DECL_ARG_TYPE of each argument according to
5875 the type previously specified, and report any mismatches. */
5877 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
5880 for (parm
= DECL_ARGUMENTS (fndecl
),
5881 type
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
5882 parm
|| (type
&& (TYPE_MAIN_VARIANT (TREE_VALUE (type
))
5883 != void_type_node
));
5884 parm
= TREE_CHAIN (parm
), type
= TREE_CHAIN (type
))
5886 if (parm
== 0 || type
== 0
5887 || TYPE_MAIN_VARIANT (TREE_VALUE (type
)) == void_type_node
)
5889 error ("number of arguments doesn't match prototype");
5890 error ("%Hprototype declaration",
5891 ¤t_function_prototype_locus
);
5894 /* Type for passing arg must be consistent with that
5895 declared for the arg. ISO C says we take the unqualified
5896 type for parameters declared with qualified type. */
5897 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm
)),
5898 TYPE_MAIN_VARIANT (TREE_VALUE (type
)),
5901 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm
))
5902 == TYPE_MAIN_VARIANT (TREE_VALUE (type
)))
5904 /* Adjust argument to match prototype. E.g. a previous
5905 `int foo(float);' prototype causes
5906 `int foo(x) float x; {...}' to be treated like
5907 `int foo(float x) {...}'. This is particularly
5908 useful for argument types like uid_t. */
5909 DECL_ARG_TYPE (parm
) = TREE_TYPE (parm
);
5911 if (targetm
.calls
.promote_prototypes (TREE_TYPE (current_function_decl
))
5912 && INTEGRAL_TYPE_P (TREE_TYPE (parm
))
5913 && TYPE_PRECISION (TREE_TYPE (parm
))
5914 < TYPE_PRECISION (integer_type_node
))
5915 DECL_ARG_TYPE (parm
) = integer_type_node
;
5919 pedwarn ("promoted argument \"%D\" "
5920 "doesn't match prototype", parm
);
5921 pedwarn ("%Hprototype declaration",
5922 ¤t_function_prototype_locus
);
5927 error ("argument \"%D\" doesn't match prototype", parm
);
5928 error ("%Hprototype declaration",
5929 ¤t_function_prototype_locus
);
5933 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = 0;
5936 /* Otherwise, create a prototype that would match. */
5940 tree actual
= 0, last
= 0, type
;
5942 for (parm
= DECL_ARGUMENTS (fndecl
); parm
; parm
= TREE_CHAIN (parm
))
5944 type
= tree_cons (NULL_TREE
, DECL_ARG_TYPE (parm
), NULL_TREE
);
5946 TREE_CHAIN (last
) = type
;
5951 type
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
5953 TREE_CHAIN (last
) = type
;
5957 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
5958 of the type of this function, but we need to avoid having this
5959 affect the types of other similarly-typed functions, so we must
5960 first force the generation of an identical (but separate) type
5961 node for the relevant function type. The new node we create
5962 will be a variant of the main variant of the original function
5965 TREE_TYPE (fndecl
) = build_type_copy (TREE_TYPE (fndecl
));
5967 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = actual
;
5971 /* Store the parameter declarations into the current function declaration.
5972 This is called after parsing the parameter declarations, before
5973 digesting the body of the function.
5975 For an old-style definition, construct a prototype out of the old-style
5976 parameter declarations and inject it into the function's type. */
5979 store_parm_decls (void)
5981 tree fndecl
= current_function_decl
;
5983 /* The function containing FNDECL, if any. */
5984 tree context
= decl_function_context (fndecl
);
5986 /* True if this definition is written with a prototype. */
5987 bool prototype
= (current_function_parms
5988 && TREE_CODE (current_function_parms
) != TREE_LIST
);
5991 store_parm_decls_newstyle ();
5993 store_parm_decls_oldstyle ();
5995 /* The next call to pushlevel will be a function body. */
5997 next_is_function_body
= true;
5999 /* Write a record describing this function definition to the prototypes
6000 file (if requested). */
6002 gen_aux_info_record (fndecl
, 1, 0, prototype
);
6004 /* Initialize the RTL code for the function. */
6005 allocate_struct_function (fndecl
);
6007 /* Begin the statement tree for this function. */
6008 begin_stmt_tree (&DECL_SAVED_TREE (fndecl
));
6010 /* If this is a nested function, save away the sizes of any
6011 variable-size types so that we can expand them when generating
6017 DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
6018 = nreverse (get_pending_sizes ());
6019 for (t
= DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
;
6022 SAVE_EXPR_CONTEXT (TREE_VALUE (t
)) = context
;
6025 /* This function is being processed in whole-function mode. */
6026 cfun
->x_whole_function_mode_p
= 1;
6028 /* Even though we're inside a function body, we still don't want to
6029 call expand_expr to calculate the size of a variable-sized array.
6030 We haven't necessarily assigned RTL to all variables yet, so it's
6031 not safe to try to expand expressions involving them. */
6032 immediate_size_expand
= 0;
6033 cfun
->x_dont_save_pending_sizes_p
= 1;
6036 /* Finish up a function declaration and compile that function
6037 all the way to assembler language output. The free the storage
6038 for the function definition.
6040 This is called after parsing the body of the function definition. */
6043 finish_function (void)
6045 tree fndecl
= current_function_decl
;
6047 /* When a function declaration is totally empty, e.g.
6049 (the argument list is irrelevant) the compstmt rule will not
6050 bother calling pushlevel/poplevel, which means we get here with
6051 the scope stack out of sync. Detect this situation by noticing
6052 that current_scope is still as store_parm_decls left it, and do
6053 a dummy push/pop to get back to consistency.
6054 Note that the call to pushlevel does not actually push another
6055 scope - see there for details. */
6057 if (current_scope
->parm_flag
&& next_is_function_body
)
6063 if (TREE_CODE (fndecl
) == FUNCTION_DECL
6064 && targetm
.calls
.promote_prototypes (TREE_TYPE (fndecl
)))
6066 tree args
= DECL_ARGUMENTS (fndecl
);
6067 for (; args
; args
= TREE_CHAIN (args
))
6069 tree type
= TREE_TYPE (args
);
6070 if (INTEGRAL_TYPE_P (type
)
6071 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
6072 DECL_ARG_TYPE (args
) = integer_type_node
;
6076 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
6077 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
6079 /* Must mark the RESULT_DECL as being in this function. */
6081 if (DECL_RESULT (fndecl
) && DECL_RESULT (fndecl
) != error_mark_node
)
6082 DECL_CONTEXT (DECL_RESULT (fndecl
)) = fndecl
;
6084 if (MAIN_NAME_P (DECL_NAME (fndecl
)) && flag_hosted
)
6086 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl
)))
6087 != integer_type_node
)
6089 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6090 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6092 pedwarn ("%Jreturn type of '%D' is not `int'", fndecl
, fndecl
);
6096 #ifdef DEFAULT_MAIN_RETURN
6097 /* Make it so that `main' always returns success by default. */
6098 DEFAULT_MAIN_RETURN
;
6101 c_expand_return (integer_zero_node
);
6106 finish_fname_decls ();
6108 /* Tie off the statement tree for this function. */
6109 finish_stmt_tree (&DECL_SAVED_TREE (fndecl
));
6111 /* Complain if there's just no return statement. */
6112 if (warn_return_type
6113 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl
))) != VOID_TYPE
6114 && !current_function_returns_value
&& !current_function_returns_null
6115 /* Don't complain if we abort. */
6116 && !current_function_returns_abnormally
6117 /* Don't warn for main(). */
6118 && !MAIN_NAME_P (DECL_NAME (fndecl
))
6119 /* Or if they didn't actually specify a return type. */
6120 && !C_FUNCTION_IMPLICIT_INT (fndecl
)
6121 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6122 inline function, as we might never be compiled separately. */
6123 && DECL_INLINE (fndecl
))
6124 warning ("no return statement in function returning non-void");
6126 /* With just -Wextra, complain only if function returns both with
6127 and without a value. */
6129 && current_function_returns_value
6130 && current_function_returns_null
)
6131 warning ("this function may return with or without a value");
6133 /* We're leaving the context of this function, so zap cfun. It's still in
6134 DECL_SAVED_INSNS, and we'll restore it in tree_rest_of_compilation. */
6137 /* ??? Objc emits functions after finalizing the compilation unit.
6138 This should be cleaned up later and this conditional removed. */
6139 if (!cgraph_global_info_ready
)
6140 cgraph_finalize_function (fndecl
, false);
6142 c_expand_body (fndecl
);
6143 current_function_decl
= NULL
;
6146 /* Generate the RTL for a deferred function FNDECL. */
6149 c_expand_deferred_function (tree fndecl
)
6151 /* DECL_INLINE or DECL_RESULT might got cleared after the inline
6152 function was deferred, e.g. in duplicate_decls. */
6153 if (DECL_INLINE (fndecl
) && DECL_RESULT (fndecl
))
6155 if (flag_inline_trees
)
6157 timevar_push (TV_INTEGRATION
);
6158 optimize_inline_calls (fndecl
);
6159 timevar_pop (TV_INTEGRATION
);
6161 c_expand_body (fndecl
);
6162 current_function_decl
= NULL
;
6166 /* Generate the RTL for the body of FNDECL. If NESTED_P is nonzero,
6167 then we are already in the process of generating RTL for another
6171 c_expand_body_1 (tree fndecl
, int nested_p
)
6175 /* Make sure that we will evaluate variable-sized types involved
6176 in our function's type. */
6177 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
);
6179 /* Squirrel away our current state. */
6180 push_function_context ();
6183 tree_rest_of_compilation (fndecl
, nested_p
);
6186 /* Return to the enclosing function. */
6187 pop_function_context ();
6189 if (DECL_STATIC_CONSTRUCTOR (fndecl
))
6191 if (targetm
.have_ctors_dtors
)
6192 (* targetm
.asm_out
.constructor
) (XEXP (DECL_RTL (fndecl
), 0),
6193 DEFAULT_INIT_PRIORITY
);
6195 static_ctors
= tree_cons (NULL_TREE
, fndecl
, static_ctors
);
6198 if (DECL_STATIC_DESTRUCTOR (fndecl
))
6200 if (targetm
.have_ctors_dtors
)
6201 (* targetm
.asm_out
.destructor
) (XEXP (DECL_RTL (fndecl
), 0),
6202 DEFAULT_INIT_PRIORITY
);
6204 static_dtors
= tree_cons (NULL_TREE
, fndecl
, static_dtors
);
6208 /* Like c_expand_body_1 but only for unnested functions. */
6211 c_expand_body (tree fndecl
)
6214 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
6215 c_expand_body_1 (fndecl
, 0);
6218 /* Check the declarations given in a for-loop for satisfying the C99
6221 check_for_loop_decls (void)
6227 /* If we get here, declarations have been used in a for loop without
6228 the C99 for loop scope. This doesn't make much sense, so don't
6230 error ("'for' loop initial declaration used outside C99 mode");
6233 /* C99 subclause 6.8.5 paragraph 3:
6235 [#3] The declaration part of a for statement shall only
6236 declare identifiers for objects having storage class auto or
6239 It isn't clear whether, in this sentence, "identifiers" binds to
6240 "shall only declare" or to "objects" - that is, whether all identifiers
6241 declared must be identifiers for objects, or whether the restriction
6242 only applies to those that are. (A question on this in comp.std.c
6243 in November 2000 received no answer.) We implement the strictest
6244 interpretation, to avoid creating an extension which later causes
6247 for (t
= current_scope
->tags
; t
; t
= TREE_CHAIN (t
))
6249 if (TREE_PURPOSE (t
) != 0)
6251 enum tree_code code
= TREE_CODE (TREE_VALUE (t
));
6253 if (code
== RECORD_TYPE
)
6254 error ("'struct %s' declared in 'for' loop initial declaration",
6255 IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
6256 else if (code
== UNION_TYPE
)
6257 error ("'union %s' declared in 'for' loop initial declaration",
6258 IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
6260 error ("'enum %s' declared in 'for' loop initial declaration",
6261 IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
6265 for (t
= getdecls (); t
; t
= TREE_CHAIN (t
))
6267 if (TREE_CODE (t
) != VAR_DECL
&& DECL_NAME (t
))
6268 error ("%Jdeclaration of non-variable '%D' in 'for' loop "
6269 "initial declaration", t
, t
);
6270 else if (TREE_STATIC (t
))
6271 error ("%Jdeclaration of static variable '%D' in 'for' loop "
6272 "initial declaration", t
, t
);
6273 else if (DECL_EXTERNAL (t
))
6274 error ("%Jdeclaration of 'extern' variable '%D' in 'for' loop "
6275 "initial declaration", t
, t
);
6279 /* Save and reinitialize the variables
6280 used during compilation of a C function. */
6283 c_push_function_context (struct function
*f
)
6285 struct language_function
*p
;
6286 p
= ggc_alloc (sizeof (struct language_function
));
6289 p
->base
.x_stmt_tree
= c_stmt_tree
;
6290 p
->base
.x_scope_stmt_stack
= c_scope_stmt_stack
;
6291 p
->x_in_iteration_stmt
= c_in_iteration_stmt
;
6292 p
->x_in_case_stmt
= c_in_case_stmt
;
6293 p
->returns_value
= current_function_returns_value
;
6294 p
->returns_null
= current_function_returns_null
;
6295 p
->returns_abnormally
= current_function_returns_abnormally
;
6296 p
->warn_about_return_type
= warn_about_return_type
;
6297 p
->extern_inline
= current_extern_inline
;
6300 /* Restore the variables used during compilation of a C function. */
6303 c_pop_function_context (struct function
*f
)
6305 struct language_function
*p
= f
->language
;
6307 if (DECL_SAVED_INSNS (current_function_decl
) == 0
6308 && DECL_SAVED_TREE (current_function_decl
) == NULL_TREE
)
6310 /* Stop pointing to the local nodes about to be freed. */
6311 /* But DECL_INITIAL must remain nonzero so we know this
6312 was an actual function definition. */
6313 DECL_INITIAL (current_function_decl
) = error_mark_node
;
6314 DECL_ARGUMENTS (current_function_decl
) = 0;
6317 c_stmt_tree
= p
->base
.x_stmt_tree
;
6318 c_scope_stmt_stack
= p
->base
.x_scope_stmt_stack
;
6319 c_in_iteration_stmt
= p
->x_in_iteration_stmt
;
6320 c_in_case_stmt
= p
->x_in_case_stmt
;
6321 current_function_returns_value
= p
->returns_value
;
6322 current_function_returns_null
= p
->returns_null
;
6323 current_function_returns_abnormally
= p
->returns_abnormally
;
6324 warn_about_return_type
= p
->warn_about_return_type
;
6325 current_extern_inline
= p
->extern_inline
;
6330 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
6333 c_dup_lang_specific_decl (tree decl
)
6335 struct lang_decl
*ld
;
6337 if (!DECL_LANG_SPECIFIC (decl
))
6340 ld
= ggc_alloc (sizeof (struct lang_decl
));
6341 memcpy (ld
, DECL_LANG_SPECIFIC (decl
), sizeof (struct lang_decl
));
6342 DECL_LANG_SPECIFIC (decl
) = ld
;
6345 /* The functions below are required for functionality of doing
6346 function at once processing in the C front end. Currently these
6347 functions are not called from anywhere in the C front end, but as
6348 these changes continue, that will change. */
6350 /* Returns nonzero if the current statement is a full expression,
6351 i.e. temporaries created during that statement should be destroyed
6352 at the end of the statement. */
6355 stmts_are_full_exprs_p (void)
6360 /* Returns the stmt_tree (if any) to which statements are currently
6361 being added. If there is no active statement-tree, NULL is
6365 current_stmt_tree (void)
6367 return &c_stmt_tree
;
6370 /* Returns the stack of SCOPE_STMTs for the current function. */
6373 current_scope_stmt_stack (void)
6375 return &c_scope_stmt_stack
;
6378 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
6382 anon_aggr_type_p (tree node ATTRIBUTE_UNUSED
)
6387 /* Dummy function in place of callback used by C++. */
6390 extract_interface_info (void)
6394 /* Return a new COMPOUND_STMT, after adding it to the current
6398 c_begin_compound_stmt (void)
6402 /* Create the COMPOUND_STMT. */
6403 stmt
= add_stmt (build_stmt (COMPOUND_STMT
, NULL_TREE
));
6408 /* Expand T (a DECL_STMT) if it declares an entity not handled by the
6412 c_expand_decl_stmt (tree t
)
6414 tree decl
= DECL_STMT_DECL (t
);
6416 /* Expand nested functions. */
6417 if (TREE_CODE (decl
) == FUNCTION_DECL
6418 && DECL_CONTEXT (decl
) == current_function_decl
6419 && DECL_SAVED_TREE (decl
))
6420 c_expand_body_1 (decl
, 1);
6423 /* Return the global value of T as a symbol. */
6426 identifier_global_value (tree t
)
6428 tree decl
= IDENTIFIER_SYMBOL_VALUE (t
);
6429 if (decl
== 0 || DECL_FILE_SCOPE_P (decl
))
6432 /* Shadowed by something else; find the true global value. */
6433 for (decl
= global_scope
->names
; decl
; decl
= TREE_CHAIN (decl
))
6434 if (DECL_NAME (decl
) == t
)
6437 /* Only local values for this decl. */
6441 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
6442 otherwise the name is found in ridpointers from RID_INDEX. */
6445 record_builtin_type (enum rid rid_index
, const char *name
, tree type
)
6449 id
= ridpointers
[(int) rid_index
];
6451 id
= get_identifier (name
);
6452 pushdecl (build_decl (TYPE_DECL
, id
, type
));
6455 /* Build the void_list_node (void_type_node having been created). */
6457 build_void_list_node (void)
6459 tree t
= build_tree_list (NULL_TREE
, void_type_node
);
6463 /* Return something to represent absolute declarators containing a *.
6464 TARGET is the absolute declarator that the * contains.
6465 TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile
6466 to apply to the pointer type, represented as identifiers, possible mixed
6469 We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST,
6470 if attributes are present) and whose type is the modifier list. */
6473 make_pointer_declarator (tree type_quals_attrs
, tree target
)
6476 tree itarget
= target
;
6477 split_specs_attrs (type_quals_attrs
, &quals
, &attrs
);
6478 if (attrs
!= NULL_TREE
)
6479 itarget
= tree_cons (attrs
, target
, NULL_TREE
);
6480 return build1 (INDIRECT_REF
, quals
, itarget
);
6483 /* A wrapper around lhd_set_decl_assembler_name that gives static
6484 variables their C names if they are at file scope and only one
6485 translation unit is being compiled, for backwards compatibility
6486 with certain bizarre assembler hacks (like crtstuff.c). */
6489 c_static_assembler_name (tree decl
)
6491 if (num_in_fnames
== 1
6492 && !TREE_PUBLIC (decl
) && DECL_CONTEXT (decl
)
6493 && TREE_CODE (DECL_CONTEXT (decl
)) == TRANSLATION_UNIT_DECL
)
6494 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
6496 lhd_set_decl_assembler_name (decl
);
6499 /* Hash and equality functions for link_hash_table: key off
6500 DECL_ASSEMBLER_NAME. */
6503 link_hash_hash (const void *x_p
)
6506 return (hashval_t
) (long)DECL_ASSEMBLER_NAME (x
);
6510 link_hash_eq (const void *x1_p
, const void *x2_p
)
6512 tree x1
= (tree
)x1_p
;
6513 tree x2
= (tree
)x2_p
;
6514 return DECL_ASSEMBLER_NAME (x1
) == DECL_ASSEMBLER_NAME (x2
);
6517 /* Propagate information between definitions and uses between multiple
6518 translation units in TU_LIST based on linkage rules. */
6521 merge_translation_unit_decls (void)
6523 const tree tu_list
= current_file_decl
;
6526 htab_t link_hash_table
;
6529 /* Create the BLOCK that poplevel would have created, but don't
6530 actually call poplevel since that's expensive. */
6531 block
= make_node (BLOCK
);
6532 BLOCK_VARS (block
) = current_scope
->names
;
6533 TREE_USED (block
) = 1;
6534 DECL_INITIAL (current_file_decl
) = block
;
6536 /* If only one translation unit seen, no copying necessary. */
6537 if (TREE_CHAIN (tu_list
) == NULL_TREE
)
6540 link_hash_table
= htab_create (1021, link_hash_hash
, link_hash_eq
, NULL
);
6542 /* Enter any actual definitions into the hash table. */
6543 for (tu
= tu_list
; tu
; tu
= TREE_CHAIN (tu
))
6544 for (decl
= BLOCK_VARS (DECL_INITIAL (tu
)); decl
; decl
= TREE_CHAIN (decl
))
6545 if (TREE_PUBLIC (decl
) && ! DECL_EXTERNAL (decl
))
6548 slot
= htab_find_slot (link_hash_table
, decl
, INSERT
);
6550 /* If we've already got a definition, work out which one is
6551 the real one, put it into the hash table, and make the
6552 other one DECL_EXTERNAL. This is important to avoid
6553 putting out two definitions of the same symbol in the
6557 tree old_decl
= (tree
) *slot
;
6559 /* If this is weak or common or whatever, suppress it
6560 in favor of the other definition. */
6561 if (DECL_WEAK (decl
))
6562 DECL_EXTERNAL (decl
) = 1;
6563 else if (DECL_WEAK (old_decl
) && ! DECL_WEAK (decl
))
6564 DECL_EXTERNAL (old_decl
) = 1;
6565 else if (DECL_COMMON (decl
) || DECL_ONE_ONLY (decl
))
6566 DECL_EXTERNAL (decl
) = 1;
6567 else if (DECL_COMMON (old_decl
) || DECL_ONE_ONLY (old_decl
))
6568 DECL_EXTERNAL (old_decl
) = 1;
6570 if (DECL_EXTERNAL (decl
))
6572 DECL_INITIAL (decl
) = NULL_TREE
;
6573 DECL_COMMON (decl
) = 0;
6574 DECL_ONE_ONLY (decl
) = 0;
6575 DECL_WEAK (decl
) = 0;
6577 else if (DECL_EXTERNAL (old_decl
))
6579 DECL_INITIAL (old_decl
) = NULL_TREE
;
6580 DECL_COMMON (old_decl
) = 0;
6581 DECL_ONE_ONLY (old_decl
) = 0;
6582 DECL_WEAK (old_decl
) = 0;
6587 error ("%Jredefinition of global '%D'", decl
, decl
);
6588 error ("%J'%D' previously defined here", old_decl
, old_decl
);
6595 /* Now insert the desired information from all the definitions
6596 into any plain declarations. */
6597 for (tu
= tu_list
; tu
; tu
= TREE_CHAIN (tu
))
6598 for (decl
= BLOCK_VARS (DECL_INITIAL (tu
)); decl
; decl
= TREE_CHAIN (decl
))
6599 if (TREE_PUBLIC (decl
) && DECL_EXTERNAL (decl
))
6602 global_decl
= htab_find (link_hash_table
, decl
);
6607 /* Print any appropriate error messages, and partially merge
6609 (void) duplicate_decls (decl
, global_decl
, true, true);
6612 htab_delete (link_hash_table
);
6615 /* Perform final processing on file-scope data. */
6618 c_write_global_declarations(void)
6622 for (link
= current_file_decl
; link
; link
= TREE_CHAIN (link
))
6624 tree globals
= BLOCK_VARS (DECL_INITIAL (link
));
6625 int len
= list_length (globals
);
6626 tree
*vec
= xmalloc (sizeof (tree
) * len
);
6630 /* Process the decls in the order they were written. */
6632 for (i
= 0, decl
= globals
; i
< len
; i
++, decl
= TREE_CHAIN (decl
))
6635 wrapup_global_declarations (vec
, len
);
6637 check_global_declarations (vec
, len
);
6644 /* Reset the parser's state in preparation for a new file. */
6647 c_reset_state (void)
6650 tree file_scope_decl
;
6652 /* Pop the global scope. */
6653 if (current_scope
!= global_scope
)
6654 current_scope
= global_scope
;
6655 file_scope_decl
= current_file_decl
;
6656 DECL_INITIAL (file_scope_decl
) = poplevel (1, 0, 0);
6657 BLOCK_SUPERCONTEXT (DECL_INITIAL (file_scope_decl
)) = file_scope_decl
;
6658 truly_local_externals
= NULL_TREE
;
6660 /* Start a new global binding level. */
6662 global_scope
= current_scope
;
6663 current_file_decl
= build_decl (TRANSLATION_UNIT_DECL
, NULL
, NULL
);
6664 TREE_CHAIN (current_file_decl
) = file_scope_decl
;
6666 /* Reintroduce the builtin declarations. */
6667 for (link
= first_builtin_decl
;
6668 link
!= TREE_CHAIN (last_builtin_decl
);
6669 link
= TREE_CHAIN (link
))
6670 pushdecl (copy_node (link
));
6673 #include "gt-c-decl.h"