1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
31 #include "coretypes.h"
35 #include "tree-inline.h"
56 #include "langhooks-def.h"
58 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
60 { NORMAL
, /* Ordinary declaration */
61 FUNCDEF
, /* Function definition */
62 PARM
, /* Declaration of parm before function body */
63 FIELD
, /* Declaration inside struct or union */
64 TYPENAME
}; /* Typename (inside cast or sizeof) */
67 /* Nonzero if we have seen an invalid cross reference
68 to a struct, union, or enum, but not yet printed the message. */
70 tree pending_invalid_xref
;
71 /* File and line to appear in the eventual error message. */
72 location_t pending_invalid_xref_location
;
74 /* While defining an enum type, this is 1 plus the last enumerator
75 constant value. Note that will do not have to save this or `enum_overflow'
76 around nested function definition since such a definition could only
77 occur in an enum value expression and we don't use these variables in
80 static tree enum_next_value
;
82 /* Nonzero means that there was overflow computing enum_next_value. */
84 static int enum_overflow
;
86 /* These #defines are for clarity in working with the information block
87 returned by get_parm_info. */
88 #define ARG_INFO_PARMS(args) TREE_PURPOSE(args)
89 #define ARG_INFO_TAGS(args) TREE_VALUE(args)
90 #define ARG_INFO_TYPES(args) TREE_CHAIN(args)
91 #define ARG_INFO_OTHERS(args) TREE_TYPE(args)
93 /* The file and line that the prototype came from if this is an
94 old-style definition; used for diagnostics in
95 store_parm_decls_oldstyle. */
97 static location_t current_function_prototype_locus
;
99 /* The current statement tree. */
101 static GTY(()) struct stmt_tree_s c_stmt_tree
;
103 /* The current scope statement stack. */
105 static GTY(()) tree c_scope_stmt_stack
;
107 /* State saving variables. */
108 int c_in_iteration_stmt
;
111 /* A DECL for the current file-scope context. */
113 static GTY(()) tree current_file_decl
;
115 /* A list of decls to be made automatically visible in each file scope. */
116 static GTY(()) tree visible_builtins
;
118 /* Set to 0 at beginning of a function definition, set to 1 if
119 a return statement that specifies a return value is seen. */
121 int current_function_returns_value
;
123 /* Set to 0 at beginning of a function definition, set to 1 if
124 a return statement with no argument is seen. */
126 int current_function_returns_null
;
128 /* Set to 0 at beginning of a function definition, set to 1 if
129 a call to a noreturn function is seen. */
131 int current_function_returns_abnormally
;
133 /* Set to nonzero by `grokdeclarator' for a function
134 whose return type is defaulted, if warnings for this are desired. */
136 static int warn_about_return_type
;
138 /* Nonzero when starting a function declared `extern inline'. */
140 static int current_extern_inline
;
142 /* True means global_bindings_p should return false even if the scope stack
143 says we are in file scope. */
144 bool c_override_global_bindings_to_false
;
147 /* Each c_binding structure describes one binding of an identifier to
148 a decl. All the decls in a scope - irrespective of namespace - are
149 chained together by the ->prev field, which (as the name implies)
150 runs in reverse order. All the decls in a given namespace bound to
151 a given identifier are chained by the ->shadowed field, which runs
152 from inner to outer scopes. Finally, the ->contour field points
153 back to the relevant scope structure; this is mainly used to make
154 decls in the externals scope invisible (see below).
156 The ->decl field usually points to a DECL node, but there are two
157 exceptions. In the namespace of type tags, the bound entity is a
158 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
159 identifier is encountered, it is bound to error_mark_node to
160 suppress further errors about that identifier in the current
163 struct c_binding
GTY(())
165 tree decl
; /* the decl bound */
166 tree id
; /* the identifier it's bound to */
167 struct c_binding
*prev
; /* the previous decl in this scope */
168 struct c_binding
*shadowed
; /* the innermost decl shadowed by this one */
169 struct c_scope
*contour
; /* the scope in which this decl is bound */
172 #define I_SYMBOL_BINDING(node) \
173 (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->symbol_binding)
174 #define I_SYMBOL_DECL(node) \
175 (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
177 #define I_TAG_BINDING(node) \
178 (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->tag_binding)
179 #define I_TAG_DECL(node) \
180 (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
182 #define I_LABEL_BINDING(node) \
183 (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->label_binding)
184 #define I_LABEL_DECL(node) \
185 (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
187 /* Each c_scope structure describes the complete contents of one
188 scope. Four scopes are distinguished specially: the innermost or
189 current scope, the innermost function scope, the file scope (always
190 the second to outermost) and the outermost or external scope.
192 Most declarations are recorded in the current scope.
194 All normal label declarations are recorded in the innermost
195 function scope, as are bindings of undeclared identifiers to
196 error_mark_node. (GCC permits nested functions as an extension,
197 hence the 'innermost' qualifier.) Explicitly declared labels
198 (using the __label__ extension) appear in the current scope.
200 Being in the file scope (current_scope == file_scope) causes
201 special behavior in several places below. Also, under some
202 conditions the Objective-C front end records declarations in the
203 file scope even though that isn't the current scope.
205 All declarations with external linkage are recorded in the external
206 scope, even if they aren't visible there; this models the fact that
207 such declarations are visible to the entire program, and (with a
208 bit of cleverness, see pushdecl) allows diagnosis of some violations
209 of C99 6.2.2p7 and 6.2.7p2:
211 If, within the same translation unit, the same identifier appears
212 with both internal and external linkage, the behavior is
215 All declarations that refer to the same object or function shall
216 have compatible type; otherwise, the behavior is undefined.
218 Initially only the built-in declarations, which describe compiler
219 intrinsic functions plus a subset of the standard library, are in
222 The order of the blocks list matters, and it is frequently appended
223 to. To avoid having to walk all the way to the end of the list on
224 each insertion, or reverse the list later, we maintain a pointer to
225 the last list entry. (FIXME: It should be feasible to use a reversed
228 The bindings list is strictly in reverse order of declarations;
229 pop_scope relies on this. */
232 struct c_scope
GTY(())
234 /* The scope containing this one. */
235 struct c_scope
*outer
;
237 /* The next outermost function scope. */
238 struct c_scope
*outer_function
;
240 /* All bindings in this scope. */
241 struct c_binding
*bindings
;
243 /* For each scope (except the global one), a chain of BLOCK nodes
244 for all the scopes that were entered and exited one level down. */
248 /* The depth of this scope. Used to keep the ->shadowed chain of
249 bindings sorted innermost to outermost. */
250 unsigned int depth
: 28;
252 /* True if we are currently filling this scope with parameter
254 BOOL_BITFIELD parm_flag
: 1;
256 /* True if we already complained about forward parameter decls
257 in this scope. This prevents double warnings on
258 foo (int a; int b; ...) */
259 BOOL_BITFIELD warned_forward_parm_decls
: 1;
261 /* True if this is the outermost block scope of a function body.
262 This scope contains the parameters, the local variables declared
263 in the outermost block, and all the labels (except those in
264 nested functions, or declared at block scope with __label__). */
265 BOOL_BITFIELD function_body
: 1;
267 /* True means make a BLOCK for this scope no matter what. */
268 BOOL_BITFIELD keep
: 1;
271 /* The scope currently in effect. */
273 static GTY(()) struct c_scope
*current_scope
;
275 /* The innermost function scope. Ordinary (not explicitly declared)
276 labels, bindings to error_mark_node, and the lazily-created
277 bindings of __func__ and its friends get this scope. */
279 static GTY(()) struct c_scope
*current_function_scope
;
281 /* The C file scope. This is reset for each input translation unit. */
283 static GTY(()) struct c_scope
*file_scope
;
285 /* The outermost scope. This is used for all declarations with
286 external linkage, and only these, hence the name. */
288 static GTY(()) struct c_scope
*external_scope
;
290 /* A chain of c_scope structures awaiting reuse. */
292 static GTY((deletable (""))) struct c_scope
*scope_freelist
;
294 /* A chain of c_binding structures awaiting reuse. */
296 static GTY((deletable (""))) struct c_binding
*binding_freelist
;
298 /* Append VAR to LIST in scope SCOPE. */
299 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
300 struct c_scope *s_ = (scope); \
302 if (s_->list##_last) \
303 TREE_CHAIN (s_->list##_last) = d_; \
306 s_->list##_last = d_; \
309 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
310 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
311 struct c_scope *t_ = (tscope); \
312 struct c_scope *f_ = (fscope); \
314 TREE_CHAIN (t_->to##_last) = f_->from; \
317 t_->to##_last = f_->from##_last; \
320 /* True means unconditionally make a BLOCK for the next scope pushed. */
322 static bool keep_next_level_flag
;
324 /* True means the next call to push_scope will be the outermost scope
325 of a function body, so do not push a new scope, merely cease
326 expecting parameter decls. */
328 static bool next_is_function_body
;
330 /* Functions called automatically at the beginning and end of execution. */
332 tree static_ctors
, static_dtors
;
334 /* Forward declarations. */
335 static tree
lookup_name_in_scope (tree
, struct c_scope
*);
336 static tree
c_make_fname_decl (tree
, int);
337 static tree
grokdeclarator (tree
, tree
, enum decl_context
, int, tree
*);
338 static tree
grokparms (tree
, int);
339 static void layout_array_type (tree
);
341 /* States indicating how grokdeclarator() should handle declspecs marked
342 with __attribute__((deprecated)). An object declared as
343 __attribute__((deprecated)) suppresses warnings of uses of other
346 enum deprecated_states
{
351 static enum deprecated_states deprecated_state
= DEPRECATED_NORMAL
;
354 c_print_identifier (FILE *file
, tree node
, int indent
)
356 print_node (file
, "symbol", I_SYMBOL_DECL (node
), indent
+ 4);
357 print_node (file
, "tag", I_TAG_DECL (node
), indent
+ 4);
358 print_node (file
, "label", I_LABEL_DECL (node
), indent
+ 4);
359 if (C_IS_RESERVED_WORD (node
))
361 tree rid
= ridpointers
[C_RID_CODE (node
)];
362 indent_to (file
, indent
+ 4);
363 fprintf (file
, "rid " HOST_PTR_PRINTF
" \"%s\"",
364 (void *) rid
, IDENTIFIER_POINTER (rid
));
368 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
369 which may be any of several kinds of DECL or TYPE or error_mark_node,
370 in the scope SCOPE. */
372 bind (tree name
, tree decl
, struct c_scope
*scope
)
374 struct c_binding
*b
, **here
;
376 if (binding_freelist
)
378 b
= binding_freelist
;
379 binding_freelist
= b
->prev
;
382 b
= ggc_alloc (sizeof (struct c_binding
));
389 b
->prev
= scope
->bindings
;
395 switch (TREE_CODE (decl
))
397 case LABEL_DECL
: here
= &I_LABEL_BINDING (name
); break;
400 case RECORD_TYPE
: here
= &I_TAG_BINDING (name
); break;
406 case ERROR_MARK
: here
= &I_SYMBOL_BINDING (name
); break;
412 /* Locate the appropriate place in the chain of shadowed decls
413 to insert this binding. Normally, scope == current_scope and
414 this does nothing. */
415 while (*here
&& (*here
)->contour
->depth
> scope
->depth
)
416 here
= &(*here
)->shadowed
;
422 /* Clear the binding structure B, stick it on the binding_freelist,
423 and return the former value of b->prev. This is used by pop_scope
424 and get_parm_info to iterate destructively over all the bindings
425 from a given scope. */
426 static struct c_binding
*
427 free_binding_and_advance (struct c_binding
*b
)
429 struct c_binding
*prev
= b
->prev
;
435 b
->prev
= binding_freelist
;
436 binding_freelist
= b
;
442 /* Hook called at end of compilation to assume 1 elt
443 for a file-scope tentative array defn that wasn't complete before. */
446 c_finish_incomplete_decl (tree decl
)
448 if (TREE_CODE (decl
) == VAR_DECL
)
450 tree type
= TREE_TYPE (decl
);
451 if (type
!= error_mark_node
452 && TREE_CODE (type
) == ARRAY_TYPE
453 && ! DECL_EXTERNAL (decl
)
454 && TYPE_DOMAIN (type
) == 0)
456 warning ("%Jarray '%D' assumed to have one element", decl
, decl
);
458 complete_array_type (type
, NULL_TREE
, 1);
460 layout_decl (decl
, 0);
465 /* The Objective-C front-end often needs to determine the current scope. */
468 get_current_scope (void)
470 return current_scope
;
473 /* The following function is used only by Objective-C. It needs to live here
474 because it accesses the innards of c_scope. */
477 objc_mark_locals_volatile (void *enclosing_blk
)
479 struct c_scope
*scope
;
482 for (scope
= current_scope
;
483 scope
&& scope
!= enclosing_blk
;
484 scope
= scope
->outer
)
486 for (b
= scope
->bindings
; b
; b
= b
->prev
)
488 if (TREE_CODE (b
->decl
) == VAR_DECL
489 || TREE_CODE (b
->decl
) == PARM_DECL
)
491 C_DECL_REGISTER (b
->decl
) = 0;
492 DECL_REGISTER (b
->decl
) = 0;
493 TREE_THIS_VOLATILE (b
->decl
) = 1;
497 /* Do not climb up past the current function. */
498 if (scope
->function_body
)
503 /* Nonzero if we are currently in file scope. */
506 global_bindings_p (void)
508 return current_scope
== file_scope
&& !c_override_global_bindings_to_false
;
512 keep_next_level (void)
514 keep_next_level_flag
= true;
517 /* Identify this scope as currently being filled with parameters. */
520 declare_parm_level (void)
522 current_scope
->parm_flag
= true;
528 if (next_is_function_body
)
530 /* This is the transition from the parameters to the top level
531 of the function body. These are the same scope
532 (C99 6.2.1p4,6) so we do not push another scope structure.
533 next_is_function_body is set only by store_parm_decls, which
534 in turn is called when and only when we are about to
535 encounter the opening curly brace for the function body.
537 The outermost block of a function always gets a BLOCK node,
538 because the debugging output routines expect that each
539 function has at least one BLOCK. */
540 current_scope
->parm_flag
= false;
541 current_scope
->function_body
= true;
542 current_scope
->keep
= true;
543 current_scope
->outer_function
= current_function_scope
;
544 current_function_scope
= current_scope
;
546 keep_next_level_flag
= false;
547 next_is_function_body
= false;
551 struct c_scope
*scope
;
554 scope
= scope_freelist
;
555 scope_freelist
= scope
->outer
;
558 scope
= ggc_alloc_cleared (sizeof (struct c_scope
));
560 scope
->keep
= keep_next_level_flag
;
561 scope
->outer
= current_scope
;
562 scope
->depth
= current_scope
? (current_scope
->depth
+ 1) : 0;
564 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but
566 if (current_scope
&& scope
->depth
== 0)
569 sorry ("GCC supports only %u nested scopes\n", scope
->depth
);
572 current_scope
= scope
;
573 keep_next_level_flag
= false;
577 /* Exit a scope. Restore the state of the identifier-decl mappings
578 that were in effect when this scope was entered. Return a BLOCK
579 node containing all the DECLs in this scope that are of interest
580 to debug info generation. */
585 struct c_scope
*scope
= current_scope
;
586 tree block
, context
, p
;
589 bool functionbody
= scope
->function_body
;
590 bool keep
= functionbody
|| scope
->keep
|| scope
->bindings
;
592 /* If appropriate, create a BLOCK to record the decls for the life
597 block
= make_node (BLOCK
);
598 BLOCK_SUBBLOCKS (block
) = scope
->blocks
;
599 TREE_USED (block
) = 1;
601 /* In each subblock, record that this is its superior. */
602 for (p
= scope
->blocks
; p
; p
= TREE_CHAIN (p
))
603 BLOCK_SUPERCONTEXT (p
) = block
;
605 BLOCK_VARS (block
) = 0;
608 /* The TYPE_CONTEXTs for all of the tagged types belonging to this
609 scope must be set so that they point to the appropriate
610 construct, i.e. either to the current FUNCTION_DECL node, or
611 else to the BLOCK node we just constructed.
613 Note that for tagged types whose scope is just the formal
614 parameter list for some function type specification, we can't
615 properly set their TYPE_CONTEXTs here, because we don't have a
616 pointer to the appropriate FUNCTION_TYPE node readily available
617 to us. For those cases, the TYPE_CONTEXTs of the relevant tagged
618 type nodes get set in `grokdeclarator' as soon as we have created
619 the FUNCTION_TYPE node which will represent the "scope" for these
620 "parameter list local" tagged types. */
621 if (scope
->function_body
)
622 context
= current_function_decl
;
623 else if (scope
== file_scope
)
624 context
= current_file_decl
;
628 /* Clear all bindings in this scope. */
629 for (b
= scope
->bindings
; b
; b
= free_binding_and_advance (b
))
632 switch (TREE_CODE (p
))
635 /* Warnings for unused labels, errors for undefined labels. */
636 if (TREE_USED (p
) && !DECL_INITIAL (p
))
638 error ("%Jlabel `%D' used but not defined", p
, p
);
639 DECL_INITIAL (p
) = error_mark_node
;
641 else if (!TREE_USED (p
) && warn_unused_label
)
643 if (DECL_INITIAL (p
))
644 warning ("%Jlabel `%D' defined but not used", p
, p
);
646 warning ("%Jlabel `%D' declared but not defined", p
, p
);
648 /* Labels go in BLOCK_VARS. */
649 TREE_CHAIN (p
) = BLOCK_VARS (block
);
650 BLOCK_VARS (block
) = p
;
652 #ifdef ENABLE_CHECKING
653 if (I_LABEL_BINDING (b
->id
) != b
) abort ();
655 I_LABEL_BINDING (b
->id
) = b
->shadowed
;
661 TYPE_CONTEXT (p
) = context
;
663 /* Types may not have tag-names, in which case the type
664 appears in the bindings list with b->id NULL. */
667 #ifdef ENABLE_CHECKING
668 if (I_TAG_BINDING (b
->id
) != b
) abort ();
670 I_TAG_BINDING (b
->id
) = b
->shadowed
;
675 /* Propagate TREE_ADDRESSABLE from nested functions to their
676 containing functions. */
677 if (! TREE_ASM_WRITTEN (p
)
678 && DECL_INITIAL (p
) != 0
679 && TREE_ADDRESSABLE (p
)
680 && DECL_ABSTRACT_ORIGIN (p
) != 0
681 && DECL_ABSTRACT_ORIGIN (p
) != p
)
682 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p
)) = 1;
686 /* Warnings for unused variables. Keep this in sync with
687 stmt.c:warn_about_unused_variables, which we cannot use
688 since it expects a different data structure. */
689 if (warn_unused_variable
691 && !DECL_IN_SYSTEM_HEADER (p
)
693 && !DECL_ARTIFICIAL (p
)
694 && (scope
!= file_scope
695 || (TREE_STATIC (p
) && !TREE_PUBLIC (p
)
696 && !TREE_THIS_VOLATILE (p
)))
697 && scope
!= external_scope
)
698 warning ("%Junused variable `%D'", p
, p
);
704 /* All of these go in BLOCK_VARS, but only if this is the
705 binding in the home scope. */
706 if (!C_DECL_IN_EXTERNAL_SCOPE (p
) || scope
== external_scope
)
708 TREE_CHAIN (p
) = BLOCK_VARS (block
);
709 BLOCK_VARS (block
) = p
;
713 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
714 already been put there by store_parm_decls. Unused-
715 parameter warnings are handled by function.c.
716 error_mark_node obviously does not go in BLOCK_VARS and
717 does not get unused-variable warnings. */
720 /* It is possible for a decl not to have a name. We get
721 here with b->id NULL in this case. */
724 #ifdef ENABLE_CHECKING
725 if (I_SYMBOL_BINDING (b
->id
) != b
) abort ();
727 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
737 /* Dispose of the block that we just made inside some higher level. */
738 if ((scope
->function_body
|| scope
== file_scope
) && context
)
740 DECL_INITIAL (context
) = block
;
741 BLOCK_SUPERCONTEXT (block
) = context
;
743 else if (scope
->outer
)
746 SCOPE_LIST_APPEND (scope
->outer
, blocks
, block
);
747 /* If we did not make a block for the scope just exited, any
748 blocks made for inner scopes must be carried forward so they
749 will later become subblocks of something else. */
750 else if (scope
->blocks
)
751 SCOPE_LIST_CONCAT (scope
->outer
, blocks
, scope
, blocks
);
754 /* Pop the current scope, and free the structure for reuse. */
755 current_scope
= scope
->outer
;
756 if (scope
->function_body
)
757 current_function_scope
= scope
->outer_function
;
759 memset (scope
, 0, sizeof (struct c_scope
));
760 scope
->outer
= scope_freelist
;
761 scope_freelist
= scope
;
767 push_file_scope (void)
770 tree file_decl
= build_decl (TRANSLATION_UNIT_DECL
, 0, 0);
771 TREE_CHAIN (file_decl
) = current_file_decl
;
772 current_file_decl
= file_decl
;
775 file_scope
= current_scope
;
777 start_fname_decls ();
779 for (decl
= visible_builtins
; decl
; decl
= TREE_CHAIN (decl
))
780 bind (DECL_NAME (decl
), decl
, file_scope
);
784 pop_file_scope (void)
786 /* In case there were missing closebraces, get us back to the global
788 while (current_scope
!= file_scope
)
791 /* __FUNCTION__ is defined at file scope (""). This
792 call may not be necessary as my tests indicate it
793 still works without it. */
794 finish_fname_decls ();
796 /* Kludge: don't actually pop the file scope if generating a
797 precompiled header, so that macros and local symbols are still
798 visible to the PCH generator. */
802 /* And pop off the file scope. */
806 cpp_undef_all (parse_in
);
809 /* Insert BLOCK at the end of the list of subblocks of the current
810 scope. This is used when a BIND_EXPR is expanded, to handle the
811 BLOCK node inside the BIND_EXPR. */
814 insert_block (tree block
)
816 TREE_USED (block
) = 1;
817 SCOPE_LIST_APPEND (current_scope
, blocks
, block
);
820 /* Push a definition or a declaration of struct, union or enum tag "name".
821 "type" should be the type node.
822 We assume that the tag "name" is not already defined.
824 Note that the definition may really be just a forward reference.
825 In that case, the TYPE_SIZE will be zero. */
828 pushtag (tree name
, tree type
)
830 /* Record the identifier as the type's name if it has none. */
831 if (name
&& !TYPE_NAME (type
))
832 TYPE_NAME (type
) = name
;
833 bind (name
, type
, current_scope
);
835 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
836 tagged type we just added to the current scope. This fake
837 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
838 to output a representation of a tagged type, and it also gives
839 us a convenient place to record the "scope start" address for the
842 TYPE_STUB_DECL (type
) = pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, type
));
844 /* An approximation for now, so we can tell this is a function-scope tag.
845 This will be updated in pop_scope. */
846 TYPE_CONTEXT (type
) = DECL_CONTEXT (TYPE_STUB_DECL (type
));
849 /* Subroutine of compare_decls. Allow harmless mismatches in return
850 and argument types provided that the type modes match. This function
851 return a unified type given a suitable match, and 0 otherwise. */
854 match_builtin_function_types (tree newtype
, tree oldtype
)
856 tree newrettype
, oldrettype
;
857 tree newargs
, oldargs
;
858 tree trytype
, tryargs
;
860 /* Accept the return type of the new declaration if same modes. */
861 oldrettype
= TREE_TYPE (oldtype
);
862 newrettype
= TREE_TYPE (newtype
);
864 if (TYPE_MODE (oldrettype
) != TYPE_MODE (newrettype
))
867 oldargs
= TYPE_ARG_TYPES (oldtype
);
868 newargs
= TYPE_ARG_TYPES (newtype
);
871 while (oldargs
|| newargs
)
875 || ! TREE_VALUE (oldargs
)
876 || ! TREE_VALUE (newargs
)
877 || TYPE_MODE (TREE_VALUE (oldargs
))
878 != TYPE_MODE (TREE_VALUE (newargs
)))
881 oldargs
= TREE_CHAIN (oldargs
);
882 newargs
= TREE_CHAIN (newargs
);
885 trytype
= build_function_type (newrettype
, tryargs
);
886 return build_type_attribute_variant (trytype
, TYPE_ATTRIBUTES (oldtype
));
889 /* Subroutine of diagnose_mismatched_decls. Check for function type
890 mismatch involving an empty arglist vs a nonempty one and give clearer
893 diagnose_arglist_conflict (tree newdecl
, tree olddecl
,
894 tree newtype
, tree oldtype
)
898 if (TREE_CODE (olddecl
) != FUNCTION_DECL
899 || !comptypes (TREE_TYPE (oldtype
), TREE_TYPE (newtype
), COMPARE_STRICT
)
900 || !((TYPE_ARG_TYPES (oldtype
) == 0 && DECL_INITIAL (olddecl
) == 0)
902 (TYPE_ARG_TYPES (newtype
) == 0 && DECL_INITIAL (newdecl
) == 0)))
905 t
= TYPE_ARG_TYPES (oldtype
);
907 t
= TYPE_ARG_TYPES (newtype
);
908 for (; t
; t
= TREE_CHAIN (t
))
910 tree type
= TREE_VALUE (t
);
912 if (TREE_CHAIN (t
) == 0
913 && TYPE_MAIN_VARIANT (type
) != void_type_node
)
915 inform ("a parameter list with an ellipsis can't match "
916 "an empty parameter name list declaration");
920 if (c_type_promotes_to (type
) != type
)
922 inform ("an argument type that has a default promotion can't match "
923 "an empty parameter name list declaration");
929 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
930 old-style function definition, NEWDECL is a prototype declaration.
931 Diagnose inconsistencies in the argument list. Returns TRUE if
932 the prototype is compatible, FALSE if not. */
934 validate_proto_after_old_defn (tree newdecl
, tree newtype
, tree oldtype
)
936 tree newargs
, oldargs
;
939 /* ??? Elsewhere TYPE_MAIN_VARIANT is not used in this context. */
940 #define END_OF_ARGLIST(t) (TYPE_MAIN_VARIANT (t) == void_type_node)
942 oldargs
= TYPE_ACTUAL_ARG_TYPES (oldtype
);
943 newargs
= TYPE_ARG_TYPES (newtype
);
948 tree oldargtype
= TREE_VALUE (oldargs
);
949 tree newargtype
= TREE_VALUE (newargs
);
951 if (END_OF_ARGLIST (oldargtype
) && END_OF_ARGLIST (newargtype
))
954 /* Reaching the end of just one list means the two decls don't
955 agree on the number of arguments. */
956 if (END_OF_ARGLIST (oldargtype
))
958 error ("%Jprototype for '%D' declares more arguments "
959 "than previous old-style definition", newdecl
, newdecl
);
962 else if (END_OF_ARGLIST (newargtype
))
964 error ("%Jprototype for '%D' declares fewer arguments "
965 "than previous old-style definition", newdecl
, newdecl
);
969 /* Type for passing arg must be consistent with that declared
971 else if (! comptypes (oldargtype
, newargtype
, COMPARE_STRICT
))
973 error ("%Jprototype for '%D' declares arg %d with incompatible type",
974 newdecl
, newdecl
, i
);
978 oldargs
= TREE_CHAIN (oldargs
);
979 newargs
= TREE_CHAIN (newargs
);
983 /* If we get here, no errors were found, but do issue a warning
984 for this poor-style construct. */
985 warning ("%Jprototype for '%D' follows non-prototype definition",
988 #undef END_OF_ARGLIST
991 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
992 first in a pair of mismatched declarations, using the diagnostic
995 locate_old_decl (tree decl
, void (*diag
)(const char *, ...))
997 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
999 else if (DECL_INITIAL (decl
))
1000 diag (N_("%Jprevious definition of '%D' was here"), decl
, decl
);
1001 else if (C_DECL_IMPLICIT (decl
))
1002 diag (N_("%Jprevious implicit declaration of '%D' was here"), decl
, decl
);
1004 diag (N_("%Jprevious declaration of '%D' was here"), decl
, decl
);
1007 /* Subroutine of duplicate_decls. Compare NEWDECL to OLDDECL.
1008 Returns true if the caller should proceed to merge the two, false
1009 if OLDDECL should simply be discarded. As a side effect, issues
1010 all necessary diagnostics for invalid or poor-style combinations.
1011 If it returns true, writes the types of NEWDECL and OLDDECL to
1012 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1013 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
1016 diagnose_mismatched_decls (tree newdecl
, tree olddecl
,
1017 tree
*newtypep
, tree
*oldtypep
)
1019 tree newtype
, oldtype
;
1020 bool pedwarned
= false;
1021 bool warned
= false;
1023 /* If we have error_mark_node for either decl or type, just discard
1024 the previous decl - we're in an error cascade already. */
1025 if (olddecl
== error_mark_node
|| newdecl
== error_mark_node
)
1027 *oldtypep
= oldtype
= TREE_TYPE (olddecl
);
1028 *newtypep
= newtype
= TREE_TYPE (newdecl
);
1029 if (oldtype
== error_mark_node
|| newtype
== error_mark_node
)
1032 /* Two different categories of symbol altogether. This is an error
1033 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
1034 if (TREE_CODE (olddecl
) != TREE_CODE (newdecl
))
1036 if (!(TREE_CODE (olddecl
) == FUNCTION_DECL
1037 && DECL_BUILT_IN (olddecl
)
1038 && !C_DECL_DECLARED_BUILTIN (olddecl
)))
1040 error ("%J'%D' redeclared as different kind of symbol",
1042 locate_old_decl (olddecl
, error
);
1044 else if (TREE_PUBLIC (newdecl
))
1045 warning ("%Jbuilt-in function '%D' declared as non-function",
1047 else if (warn_shadow
)
1048 warning ("%Jdeclaration of '%D' shadows a built-in function",
1053 if (!comptypes (oldtype
, newtype
, COMPARE_STRICT
))
1055 if (TREE_CODE (olddecl
) == FUNCTION_DECL
1056 && DECL_BUILT_IN (olddecl
) && !C_DECL_DECLARED_BUILTIN (olddecl
))
1058 /* Accept harmless mismatch in function types.
1059 This is for the ffs and fprintf builtins. */
1060 tree trytype
= match_builtin_function_types (newtype
, oldtype
);
1062 if (trytype
&& comptypes (newtype
, trytype
, COMPARE_STRICT
))
1063 *oldtypep
= oldtype
= trytype
;
1066 /* If types don't match for a built-in, throw away the
1067 built-in. No point in calling locate_old_decl here, it
1068 won't print anything. */
1069 warning ("%Jconflicting types for built-in function '%D'",
1074 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
1075 && DECL_SOURCE_LINE (olddecl
) == 0)
1077 /* A conflicting function declaration for a predeclared
1078 function that isn't actually built in. Objective C uses
1079 these. The new declaration silently overrides everything
1080 but the volatility (i.e. noreturn) indication. See also
1081 below. FIXME: Make Objective C use normal builtins. */
1082 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1085 /* Permit void foo (...) to match int foo (...) if the latter is
1086 the definition and implicit int was used. See
1087 c-torture/compile/920625-2.c. */
1088 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
&& DECL_INITIAL (newdecl
)
1089 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype
)) == void_type_node
1090 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype
)) == integer_type_node
1091 && C_FUNCTION_IMPLICIT_INT (newdecl
))
1093 pedwarn ("%Jconflicting types for '%D'", newdecl
, newdecl
);
1094 /* Make sure we keep void as the return type. */
1095 TREE_TYPE (newdecl
) = *newtypep
= newtype
= oldtype
;
1096 C_FUNCTION_IMPLICIT_INT (newdecl
) = 0;
1101 error ("%Jconflicting types for '%D'", newdecl
, newdecl
);
1102 diagnose_arglist_conflict (newdecl
, olddecl
, newtype
, oldtype
);
1103 locate_old_decl (olddecl
, error
);
1108 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1109 but silently ignore the redeclaration if either is in a system
1110 header. (Conflicting redeclarations were handled above.) */
1111 if (TREE_CODE (newdecl
) == TYPE_DECL
)
1113 if (DECL_IN_SYSTEM_HEADER (newdecl
) || DECL_IN_SYSTEM_HEADER (olddecl
))
1114 return true; /* Allow OLDDECL to continue in use. */
1116 error ("%Jredefinition of typedef '%D'", newdecl
, newdecl
);
1117 locate_old_decl (olddecl
, error
);
1121 /* Function declarations can either be 'static' or 'extern' (no
1122 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1123 can never conflict with each other on account of linkage (6.2.2p4).
1124 Multiple definitions are not allowed (6.9p3,5) but GCC permits
1125 two definitions if one is 'extern inline' and one is not. The non-
1126 extern-inline definition supersedes the extern-inline definition. */
1127 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1129 /* If you declare a built-in function name as static, or
1130 define the built-in with an old-style definition (so we
1131 can't validate the argument list) the built-in definition is
1132 overridden, but optionally warn this was a bad choice of name. */
1133 if (DECL_BUILT_IN (olddecl
)
1134 && !C_DECL_DECLARED_BUILTIN (olddecl
)
1135 && (!TREE_PUBLIC (newdecl
)
1136 || (DECL_INITIAL (newdecl
)
1137 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl
)))))
1140 warning ("%Jdeclaration of '%D' shadows a built-in function",
1142 /* Discard the old built-in function. */
1146 if (DECL_INITIAL (newdecl
))
1148 if (DECL_INITIAL (olddecl
)
1149 && !(DECL_DECLARED_INLINE_P (olddecl
)
1150 && DECL_EXTERNAL (olddecl
)
1151 && !(DECL_DECLARED_INLINE_P (newdecl
)
1152 && DECL_EXTERNAL (newdecl
))))
1154 error ("%Jredefinition of '%D'", newdecl
, newdecl
);
1155 locate_old_decl (olddecl
, error
);
1159 /* If we have a prototype after an old-style function definition,
1160 the argument types must be checked specially. */
1161 else if (DECL_INITIAL (olddecl
)
1162 && !TYPE_ARG_TYPES (oldtype
) && TYPE_ARG_TYPES (newtype
)
1163 && TYPE_ACTUAL_ARG_TYPES (oldtype
)
1164 && !validate_proto_after_old_defn (newdecl
, newtype
, oldtype
))
1166 locate_old_decl (olddecl
, error
);
1169 /* Mismatched non-static and static is considered poor style.
1170 We only diagnose static then non-static if -Wtraditional,
1171 because it is the most convenient way to get some effects
1172 (see e.g. what unwind-dw2-fde-glibc.c does to the definition
1173 of _Unwind_Find_FDE in unwind-dw2-fde.c). Revisit? */
1174 if (TREE_PUBLIC (olddecl
) && !TREE_PUBLIC (newdecl
))
1176 /* A static function declaration for a predeclared function
1177 that isn't actually built in, silently overrides the
1178 default. Objective C uses these. See also above.
1179 FIXME: Make Objective C use normal builtins. */
1180 if (TREE_CODE (olddecl
) == FUNCTION_DECL
1181 && DECL_SOURCE_LINE (olddecl
) == 0)
1185 warning ("%Jstatic declaration of '%D' follows "
1186 "non-static declaration", newdecl
, newdecl
);
1190 else if (TREE_PUBLIC (newdecl
) && !TREE_PUBLIC (olddecl
)
1191 && warn_traditional
)
1193 warning ("%Jnon-static declaration of '%D' follows "
1194 "static declaration", newdecl
, newdecl
);
1198 else if (TREE_CODE (newdecl
) == VAR_DECL
)
1200 /* Only variables can be thread-local, and all declarations must
1201 agree on this property. */
1202 if (DECL_THREAD_LOCAL (newdecl
) != DECL_THREAD_LOCAL (olddecl
))
1204 if (DECL_THREAD_LOCAL (newdecl
))
1205 error ("%Jthread-local declaration of '%D' follows "
1206 "non-thread-local declaration", newdecl
, newdecl
);
1208 error ("%Jnon-thread-local declaration of '%D' follows "
1209 "thread-local declaration", newdecl
, newdecl
);
1211 locate_old_decl (olddecl
, error
);
1215 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1216 if (DECL_INITIAL (newdecl
) && DECL_INITIAL (olddecl
))
1218 error ("%Jredefinition of '%D'", newdecl
, newdecl
);
1219 locate_old_decl (olddecl
, error
);
1223 /* Objects declared at file scope: if at least one is 'extern',
1224 it's fine (6.2.2p4); otherwise the linkage must agree (6.2.2p7). */
1225 if (DECL_FILE_SCOPE_P (newdecl
))
1227 if (!DECL_EXTERNAL (newdecl
)
1228 && !DECL_EXTERNAL (olddecl
)
1229 && TREE_PUBLIC (newdecl
) != TREE_PUBLIC (olddecl
))
1231 if (TREE_PUBLIC (newdecl
))
1232 error ("%Jnon-static declaration of '%D' follows "
1233 "static declaration", newdecl
, newdecl
);
1235 error ("%Jstatic declaration of '%D' follows "
1236 "non-static declaration", newdecl
, newdecl
);
1238 locate_old_decl (olddecl
, error
);
1242 /* Two objects with the same name declared at the same block
1243 scope must both be external references (6.7p3). */
1244 else if (DECL_CONTEXT (newdecl
) == DECL_CONTEXT (olddecl
)
1245 && (!DECL_EXTERNAL (newdecl
) || !DECL_EXTERNAL (olddecl
)))
1247 if (DECL_EXTERNAL (newdecl
))
1248 error ("%Jextern declaration of '%D' follows "
1249 "declaration with no linkage", newdecl
, newdecl
);
1250 else if (DECL_EXTERNAL (olddecl
))
1251 error ("%Jdeclaration of '%D' with no linkage follows "
1252 "extern declaration", newdecl
, newdecl
);
1254 error ("%Jredeclaration of '%D' with no linkage",
1257 locate_old_decl (olddecl
, error
);
1263 /* All decls must agree on a non-default visibility. */
1264 if (DECL_VISIBILITY (newdecl
) != VISIBILITY_DEFAULT
1265 && DECL_VISIBILITY (olddecl
) != VISIBILITY_DEFAULT
1266 && DECL_VISIBILITY (newdecl
) != DECL_VISIBILITY (olddecl
))
1268 warning ("%Jredeclaration of '%D' with different visibility "
1269 "(old visibility preserved)", newdecl
, newdecl
);
1273 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1275 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1276 if (DECL_DECLARED_INLINE_P (newdecl
)
1277 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl
)))
1279 warning ("%Jinline declaration of '%D' follows "
1280 "declaration with attribute noinline", newdecl
, newdecl
);
1283 else if (DECL_DECLARED_INLINE_P (olddecl
)
1284 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl
)))
1286 warning ("%Jdeclaration of '%D' with attribute noinline follows "
1287 "inline declaration ", newdecl
, newdecl
);
1291 /* Inline declaration after use or definition.
1292 ??? Should we still warn about this now we have unit-at-a-time
1293 mode and can get it right? */
1294 if (DECL_DECLARED_INLINE_P (newdecl
) && !DECL_DECLARED_INLINE_P (olddecl
))
1296 if (TREE_USED (olddecl
))
1298 warning ("%J'%D' declared inline after being called",
1302 else if (DECL_INITIAL (olddecl
))
1304 warning ("%J'%D' declared inline after its definition",
1310 else /* PARM_DECL, VAR_DECL */
1312 /* Redeclaration of a parameter is a constraint violation (this is
1313 not explicitly stated, but follows from C99 6.7p3 [no more than
1314 one declaration of the same identifier with no linkage in the
1315 same scope, except type tags] and 6.2.2p6 [parameters have no
1316 linkage]). We must check for a forward parameter declaration,
1317 indicated by TREE_ASM_WRITTEN on the old declaration - this is
1318 an extension, the mandatory diagnostic for which is handled by
1319 mark_forward_parm_decls. */
1321 if (TREE_CODE (newdecl
) == PARM_DECL
1322 && (!TREE_ASM_WRITTEN (olddecl
) || TREE_ASM_WRITTEN (newdecl
)))
1324 error ("%Jredefinition of parameter '%D'", newdecl
, newdecl
);
1325 locate_old_decl (olddecl
, error
);
1329 /* These bits are only type qualifiers when applied to objects. */
1330 if (TREE_THIS_VOLATILE (newdecl
) != TREE_THIS_VOLATILE (olddecl
))
1332 if (TREE_THIS_VOLATILE (newdecl
))
1333 pedwarn ("%Jvolatile declaration of '%D' follows "
1334 "non-volatile declaration", newdecl
, newdecl
);
1336 pedwarn ("%Jnon-volatile declaration of '%D' follows "
1337 "volatile declaration", newdecl
, newdecl
);
1340 if (TREE_READONLY (newdecl
) != TREE_READONLY (olddecl
))
1342 if (TREE_READONLY (newdecl
))
1343 pedwarn ("%Jconst declaration of '%D' follows "
1344 "non-const declaration", newdecl
, newdecl
);
1346 pedwarn ("%Jnon-const declaration of '%D' follows "
1347 "const declaration", newdecl
, newdecl
);
1352 /* Optional warning for completely redundant decls. */
1353 if (!warned
&& !pedwarned
1354 && warn_redundant_decls
1355 /* Don't warn about a function declaration followed by a
1357 && !(TREE_CODE (newdecl
) == FUNCTION_DECL
1358 && DECL_INITIAL (newdecl
) && !DECL_INITIAL (olddecl
))
1359 /* Don't warn about an extern followed by a definition. */
1360 && !(DECL_EXTERNAL (olddecl
) && !DECL_EXTERNAL (newdecl
))
1361 /* Don't warn about forward parameter decls. */
1362 && !(TREE_CODE (newdecl
) == PARM_DECL
1363 && TREE_ASM_WRITTEN (olddecl
) && !TREE_ASM_WRITTEN (newdecl
)))
1365 warning ("%Jredundant redeclaration of '%D'", newdecl
, newdecl
);
1369 /* Report location of previous decl/defn in a consistent manner. */
1370 if (warned
|| pedwarned
)
1371 locate_old_decl (olddecl
, pedwarned
? pedwarn
: warning
);
1376 /* Subroutine of duplicate_decls. NEWDECL has been found to be
1377 consistent with OLDDECL, but carries new information. Merge the
1378 new information into OLDDECL. This function issues no
1382 merge_decls (tree newdecl
, tree olddecl
, tree newtype
, tree oldtype
)
1384 int new_is_definition
= (TREE_CODE (newdecl
) == FUNCTION_DECL
1385 && DECL_INITIAL (newdecl
) != 0);
1387 /* For real parm decl following a forward decl, rechain the old decl
1388 in its new location and clear TREE_ASM_WRITTEN (it's not a
1389 forward decl anymore). */
1390 if (TREE_CODE (newdecl
) == PARM_DECL
1391 && TREE_ASM_WRITTEN (olddecl
) && ! TREE_ASM_WRITTEN (newdecl
))
1393 struct c_binding
*b
, **here
;
1395 for (here
= ¤t_scope
->bindings
; *here
; here
= &(*here
)->prev
)
1396 if ((*here
)->decl
== olddecl
)
1403 b
->prev
= current_scope
->bindings
;
1404 current_scope
->bindings
= b
;
1406 TREE_ASM_WRITTEN (olddecl
) = 0;
1409 DECL_ATTRIBUTES (newdecl
)
1410 = targetm
.merge_decl_attributes (olddecl
, newdecl
);
1412 /* Merge the data types specified in the two decls. */
1414 = TREE_TYPE (olddecl
)
1415 = common_type (newtype
, oldtype
);
1417 /* Lay the type out, unless already done. */
1418 if (oldtype
!= TREE_TYPE (newdecl
))
1420 if (TREE_TYPE (newdecl
) != error_mark_node
)
1421 layout_type (TREE_TYPE (newdecl
));
1422 if (TREE_CODE (newdecl
) != FUNCTION_DECL
1423 && TREE_CODE (newdecl
) != TYPE_DECL
1424 && TREE_CODE (newdecl
) != CONST_DECL
)
1425 layout_decl (newdecl
, 0);
1429 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1430 DECL_SIZE (newdecl
) = DECL_SIZE (olddecl
);
1431 DECL_SIZE_UNIT (newdecl
) = DECL_SIZE_UNIT (olddecl
);
1432 DECL_MODE (newdecl
) = DECL_MODE (olddecl
);
1433 if (TREE_CODE (olddecl
) != FUNCTION_DECL
)
1434 if (DECL_ALIGN (olddecl
) > DECL_ALIGN (newdecl
))
1436 DECL_ALIGN (newdecl
) = DECL_ALIGN (olddecl
);
1437 DECL_USER_ALIGN (newdecl
) |= DECL_ALIGN (olddecl
);
1441 /* Keep the old rtl since we can safely use it. */
1442 COPY_DECL_RTL (olddecl
, newdecl
);
1444 /* Merge the type qualifiers. */
1445 if (TREE_READONLY (newdecl
))
1446 TREE_READONLY (olddecl
) = 1;
1448 if (TREE_THIS_VOLATILE (newdecl
))
1450 TREE_THIS_VOLATILE (olddecl
) = 1;
1451 if (TREE_CODE (newdecl
) == VAR_DECL
)
1452 make_var_volatile (newdecl
);
1455 /* Keep source location of definition rather than declaration. */
1456 if (DECL_INITIAL (newdecl
) == 0 && DECL_INITIAL (olddecl
) != 0)
1457 DECL_SOURCE_LOCATION (newdecl
) = DECL_SOURCE_LOCATION (olddecl
);
1459 /* Merge the unused-warning information. */
1460 if (DECL_IN_SYSTEM_HEADER (olddecl
))
1461 DECL_IN_SYSTEM_HEADER (newdecl
) = 1;
1462 else if (DECL_IN_SYSTEM_HEADER (newdecl
))
1463 DECL_IN_SYSTEM_HEADER (olddecl
) = 1;
1465 /* Merge the initialization information. */
1466 if (DECL_INITIAL (newdecl
) == 0)
1467 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1469 /* Merge the section attribute.
1470 We want to issue an error if the sections conflict but that must be
1471 done later in decl_attributes since we are called before attributes
1473 if (DECL_SECTION_NAME (newdecl
) == NULL_TREE
)
1474 DECL_SECTION_NAME (newdecl
) = DECL_SECTION_NAME (olddecl
);
1476 /* Copy the assembler name.
1477 Currently, it can only be defined in the prototype. */
1478 COPY_DECL_ASSEMBLER_NAME (olddecl
, newdecl
);
1480 /* If either declaration has a nondefault visibility, use it. */
1481 if (DECL_VISIBILITY (olddecl
) != VISIBILITY_DEFAULT
)
1482 DECL_VISIBILITY (newdecl
) = DECL_VISIBILITY (olddecl
);
1484 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1486 DECL_STATIC_CONSTRUCTOR(newdecl
) |= DECL_STATIC_CONSTRUCTOR(olddecl
);
1487 DECL_STATIC_DESTRUCTOR (newdecl
) |= DECL_STATIC_DESTRUCTOR (olddecl
);
1488 DECL_NO_LIMIT_STACK (newdecl
) |= DECL_NO_LIMIT_STACK (olddecl
);
1489 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl
)
1490 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl
);
1491 TREE_THIS_VOLATILE (newdecl
) |= TREE_THIS_VOLATILE (olddecl
);
1492 TREE_READONLY (newdecl
) |= TREE_READONLY (olddecl
);
1493 DECL_IS_MALLOC (newdecl
) |= DECL_IS_MALLOC (olddecl
);
1494 DECL_IS_PURE (newdecl
) |= DECL_IS_PURE (olddecl
);
1497 /* Merge the storage class information. */
1498 merge_weak (newdecl
, olddecl
);
1500 /* For functions, static overrides non-static. */
1501 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1503 TREE_PUBLIC (newdecl
) &= TREE_PUBLIC (olddecl
);
1504 /* This is since we don't automatically
1505 copy the attributes of NEWDECL into OLDDECL. */
1506 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1507 /* If this clears `static', clear it in the identifier too. */
1508 if (! TREE_PUBLIC (olddecl
))
1509 TREE_PUBLIC (DECL_NAME (olddecl
)) = 0;
1511 if (DECL_EXTERNAL (newdecl
))
1513 TREE_STATIC (newdecl
) = TREE_STATIC (olddecl
);
1514 DECL_EXTERNAL (newdecl
) = DECL_EXTERNAL (olddecl
);
1516 /* An extern decl does not override previous storage class. */
1517 TREE_PUBLIC (newdecl
) = TREE_PUBLIC (olddecl
);
1518 if (! DECL_EXTERNAL (newdecl
))
1520 DECL_CONTEXT (newdecl
) = DECL_CONTEXT (olddecl
);
1521 DECL_COMMON (newdecl
) = DECL_COMMON (olddecl
);
1526 TREE_STATIC (olddecl
) = TREE_STATIC (newdecl
);
1527 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
1530 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
1532 /* If we're redefining a function previously defined as extern
1533 inline, make sure we emit debug info for the inline before we
1534 throw it away, in case it was inlined into a function that hasn't
1535 been written out yet. */
1536 if (new_is_definition
&& DECL_INITIAL (olddecl
))
1538 if (TREE_USED (olddecl
)
1539 /* In unit-at-a-time mode we never inline re-defined extern
1540 inline functions. */
1541 && !flag_unit_at_a_time
1542 && cgraph_function_possibly_inlined_p (olddecl
))
1543 (*debug_hooks
->outlining_inline_function
) (olddecl
);
1545 /* The new defn must not be inline. */
1546 DECL_INLINE (newdecl
) = 0;
1547 DECL_UNINLINABLE (newdecl
) = 1;
1551 /* If either decl says `inline', this fn is inline,
1552 unless its definition was passed already. */
1553 if (DECL_DECLARED_INLINE_P (newdecl
)
1554 || DECL_DECLARED_INLINE_P (olddecl
))
1555 DECL_DECLARED_INLINE_P (newdecl
) = 1;
1557 DECL_UNINLINABLE (newdecl
) = DECL_UNINLINABLE (olddecl
)
1558 = (DECL_UNINLINABLE (newdecl
) || DECL_UNINLINABLE (olddecl
));
1561 if (DECL_BUILT_IN (olddecl
))
1563 /* If redeclaring a builtin function, it stays built in.
1564 But it gets tagged as having been declared. */
1565 DECL_BUILT_IN_CLASS (newdecl
) = DECL_BUILT_IN_CLASS (olddecl
);
1566 DECL_FUNCTION_CODE (newdecl
) = DECL_FUNCTION_CODE (olddecl
);
1567 C_DECL_DECLARED_BUILTIN (newdecl
) = 1;
1570 /* Also preserve various other info from the definition. */
1571 if (! new_is_definition
)
1573 DECL_RESULT (newdecl
) = DECL_RESULT (olddecl
);
1574 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
1575 DECL_STRUCT_FUNCTION (newdecl
) = DECL_STRUCT_FUNCTION (olddecl
);
1576 DECL_SAVED_TREE (newdecl
) = DECL_SAVED_TREE (olddecl
);
1577 DECL_ARGUMENTS (newdecl
) = DECL_ARGUMENTS (olddecl
);
1579 /* Set DECL_INLINE on the declaration if we've got a body
1580 from which to instantiate. */
1581 if (DECL_INLINE (olddecl
) && ! DECL_UNINLINABLE (newdecl
))
1583 DECL_INLINE (newdecl
) = 1;
1584 DECL_ABSTRACT_ORIGIN (newdecl
)
1585 = DECL_ABSTRACT_ORIGIN (olddecl
);
1590 /* If a previous declaration said inline, mark the
1591 definition as inlinable. */
1592 if (DECL_DECLARED_INLINE_P (newdecl
)
1593 && ! DECL_UNINLINABLE (newdecl
))
1594 DECL_INLINE (newdecl
) = 1;
1598 /* This bit must not get wiped out. */
1599 C_DECL_IN_EXTERNAL_SCOPE (newdecl
) |= C_DECL_IN_EXTERNAL_SCOPE (olddecl
);
1601 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1602 But preserve OLDDECL's DECL_UID. */
1604 unsigned olddecl_uid
= DECL_UID (olddecl
);
1606 memcpy ((char *) olddecl
+ sizeof (struct tree_common
),
1607 (char *) newdecl
+ sizeof (struct tree_common
),
1608 sizeof (struct tree_decl
) - sizeof (struct tree_common
));
1609 DECL_UID (olddecl
) = olddecl_uid
;
1612 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1613 so that encode_section_info has a chance to look at the new decl
1614 flags and attributes. */
1615 if (DECL_RTL_SET_P (olddecl
)
1616 && (TREE_CODE (olddecl
) == FUNCTION_DECL
1617 || (TREE_CODE (olddecl
) == VAR_DECL
1618 && TREE_STATIC (olddecl
))))
1619 make_decl_rtl (olddecl
, NULL
);
1622 /* Handle when a new declaration NEWDECL has the same name as an old
1623 one OLDDECL in the same binding contour. Prints an error message
1626 If safely possible, alter OLDDECL to look like NEWDECL, and return
1627 true. Otherwise, return false. */
1630 duplicate_decls (tree newdecl
, tree olddecl
)
1632 tree newtype
, oldtype
;
1634 if (!diagnose_mismatched_decls (newdecl
, olddecl
, &newtype
, &oldtype
))
1637 merge_decls (newdecl
, olddecl
, newtype
, oldtype
);
1642 /* Check whether decl-node NEW shadows an existing declaration. */
1644 warn_if_shadowing (tree
new)
1646 struct c_binding
*b
;
1648 /* Shadow warnings wanted? */
1650 /* No shadow warnings for internally generated vars. */
1651 || DECL_SOURCE_LINE (new) == 0
1652 /* No shadow warnings for vars made for inlining. */
1653 || DECL_FROM_INLINE (new)
1654 /* Don't warn about the parm names in function declarator
1655 within a function declarator. It would be nice to avoid
1656 warning in any function declarator in a declaration, as
1657 opposed to a definition, but there is no way to tell
1658 it's not a definition at this point. */
1659 || (TREE_CODE (new) == PARM_DECL
&& current_scope
->outer
->parm_flag
))
1662 /* Is anything being shadowed? Do not be confused by a second binding
1663 to the same decl in the externals scope. */
1664 for (b
= I_SYMBOL_BINDING (DECL_NAME (new)); b
; b
= b
->shadowed
)
1665 if (b
->decl
&& b
->decl
!= new && b
->contour
!= external_scope
)
1669 if (TREE_CODE (old
) == PARM_DECL
)
1670 warning ("%Jdeclaration of '%D' shadows a parameter", new, new);
1671 else if (DECL_FILE_SCOPE_P (old
))
1672 warning ("%Jdeclaration of '%D' shadows a global declaration",
1674 else if (TREE_CODE (old
) == FUNCTION_DECL
&& DECL_BUILT_IN (old
))
1675 warning ("%Jdeclaration of '%D' shadows a built-in function",
1678 warning ("%Jdeclaration of '%D' shadows a previous local", new, new);
1680 if (TREE_CODE (old
) != FUNCTION_DECL
|| !DECL_BUILT_IN (old
))
1681 warning ("%Jshadowed declaration is here", old
);
1688 /* Subroutine of pushdecl.
1690 X is a TYPE_DECL for a typedef statement. Create a brand new
1691 ..._TYPE node (which will be just a variant of the existing
1692 ..._TYPE node with identical properties) and then install X
1693 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
1695 The whole point here is to end up with a situation where each
1696 and every ..._TYPE node the compiler creates will be uniquely
1697 associated with AT MOST one node representing a typedef name.
1698 This way, even though the compiler substitutes corresponding
1699 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
1700 early on, later parts of the compiler can always do the reverse
1701 translation and get back the corresponding typedef name. For
1704 typedef struct S MY_TYPE;
1707 Later parts of the compiler might only know that `object' was of
1708 type `struct S' if it were not for code just below. With this
1709 code however, later parts of the compiler see something like:
1711 struct S' == struct S
1712 typedef struct S' MY_TYPE;
1715 And they can then deduce (from the node for type struct S') that
1716 the original object declaration was:
1720 Being able to do this is important for proper support of protoize,
1721 and also for generating precise symbolic debugging information
1722 which takes full account of the programmer's (typedef) vocabulary.
1724 Obviously, we don't want to generate a duplicate ..._TYPE node if
1725 the TYPE_DECL node that we are now processing really represents a
1726 standard built-in type.
1728 Since all standard types are effectively declared at line zero
1729 in the source file, we can easily check to see if we are working
1730 on a standard type by checking the current value of lineno. */
1733 clone_underlying_type (tree x
)
1735 if (DECL_SOURCE_LINE (x
) == 0)
1737 if (TYPE_NAME (TREE_TYPE (x
)) == 0)
1738 TYPE_NAME (TREE_TYPE (x
)) = x
;
1740 else if (TREE_TYPE (x
) != error_mark_node
1741 && DECL_ORIGINAL_TYPE (x
) == NULL_TREE
)
1743 tree tt
= TREE_TYPE (x
);
1744 DECL_ORIGINAL_TYPE (x
) = tt
;
1745 tt
= build_type_copy (tt
);
1747 TREE_USED (tt
) = TREE_USED (x
);
1752 /* Record a decl-node X as belonging to the current lexical scope.
1753 Check for errors (such as an incompatible declaration for the same
1754 name already seen in the same scope).
1756 Returns either X or an old decl for the same name.
1757 If an old decl is returned, it may have been smashed
1758 to agree with what X says. */
1763 tree name
= DECL_NAME (x
);
1764 struct c_scope
*scope
= current_scope
;
1765 struct c_binding
*b
;
1767 /* Functions need the lang_decl data. */
1768 if (TREE_CODE (x
) == FUNCTION_DECL
&& ! DECL_LANG_SPECIFIC (x
))
1769 DECL_LANG_SPECIFIC (x
) = ggc_alloc_cleared (sizeof (struct lang_decl
));
1771 /* A local extern declaration for a function doesn't constitute nesting.
1772 A local auto declaration does, since it's a forward decl
1773 for a nested function coming later. */
1774 if (current_function_decl
== NULL
1775 || ((TREE_CODE (x
) == FUNCTION_DECL
|| TREE_CODE (x
) == VAR_DECL
)
1776 && DECL_INITIAL (x
) == 0 && DECL_EXTERNAL (x
)))
1777 DECL_CONTEXT (x
) = current_file_decl
;
1779 DECL_CONTEXT (x
) = current_function_decl
;
1781 /* Anonymous decls are just inserted in the scope. */
1784 bind (name
, x
, scope
);
1788 /* First, see if there is another declaration with the same name in
1789 the current scope. If there is, duplicate_decls may do all the
1790 work for us. If duplicate_decls returns false, that indicates
1791 two incompatible decls in the same scope; we are to silently
1792 replace the old one (duplicate_decls has issued all appropriate
1793 diagnostics). In particular, we should not consider possible
1794 duplicates in the external scope, or shadowing. */
1795 b
= I_SYMBOL_BINDING (name
);
1796 if (b
&& b
->contour
== scope
)
1798 if (duplicate_decls (x
, b
->decl
))
1801 goto skip_external_and_shadow_checks
;
1804 /* All declarations with external linkage, and all external
1805 references, go in the external scope, no matter what scope is
1806 current. However, the binding in that scope is ignored for
1807 purposes of normal name lookup. A separate binding structure is
1808 created in the requested scope; this governs the normal
1809 visibility of the symbol.
1811 The binding in the externals scope is used exclusively for
1812 detecting duplicate declarations of the same object, no matter
1813 what scope they are in; this is what we do here. (C99 6.2.7p2:
1814 All declarations that refer to the same object or function shall
1815 have compatible type; otherwise, the behavior is undefined.) */
1816 if (DECL_EXTERNAL (x
) || scope
== file_scope
)
1818 if (warn_nested_externs
1819 && scope
!= file_scope
1820 && !DECL_IN_SYSTEM_HEADER (x
))
1821 warning ("nested extern declaration of `%s'",
1822 IDENTIFIER_POINTER (name
));
1824 while (b
&& b
->contour
!= external_scope
)
1827 /* The point of the same_translation_unit_p check here is,
1828 we want to detect a duplicate decl for a construct like
1829 foo() { extern bar(); } ... static bar(); but not if
1830 they are in different translation units. In any case,
1831 the static does not go in the externals scope. */
1833 && (DECL_EXTERNAL (x
) || TREE_PUBLIC (x
)
1834 || same_translation_unit_p (x
, b
->decl
))
1835 && duplicate_decls (x
, b
->decl
))
1837 bind (name
, b
->decl
, scope
);
1840 else if (DECL_EXTERNAL (x
) || TREE_PUBLIC (x
))
1842 C_DECL_IN_EXTERNAL_SCOPE (x
) = 1;
1843 bind (name
, x
, external_scope
);
1847 warn_if_shadowing (x
);
1849 skip_external_and_shadow_checks
:
1850 if (TREE_CODE (x
) == TYPE_DECL
)
1851 clone_underlying_type (x
);
1853 bind (name
, x
, scope
);
1855 /* If x's type is incomplete because it's based on a
1856 structure or union which has not yet been fully declared,
1857 attach it to that structure or union type, so we can go
1858 back and complete the variable declaration later, if the
1859 structure or union gets fully declared.
1861 If the input is erroneous, we can have error_mark in the type
1862 slot (e.g. "f(void a, ...)") - that doesn't count as an
1864 if (TREE_TYPE (x
) != error_mark_node
1865 && !COMPLETE_TYPE_P (TREE_TYPE (x
)))
1867 tree element
= TREE_TYPE (x
);
1869 while (TREE_CODE (element
) == ARRAY_TYPE
)
1870 element
= TREE_TYPE (element
);
1871 element
= TYPE_MAIN_VARIANT (element
);
1873 if ((TREE_CODE (element
) == RECORD_TYPE
1874 || TREE_CODE (element
) == UNION_TYPE
)
1875 && (TREE_CODE (x
) != TYPE_DECL
1876 || TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
)
1877 && !COMPLETE_TYPE_P (element
))
1878 C_TYPE_INCOMPLETE_VARS (element
)
1879 = tree_cons (NULL_TREE
, x
, C_TYPE_INCOMPLETE_VARS (element
));
1884 /* Record X as belonging to file scope.
1885 This is used only internally by the Objective-C front end,
1886 and is limited to its needs. duplicate_decls is not called;
1887 if there is any preexisting decl for this identifier, it is an ICE. */
1890 pushdecl_top_level (tree x
)
1894 if (TREE_CODE (x
) != VAR_DECL
)
1897 name
= DECL_NAME (x
);
1899 if (I_SYMBOL_BINDING (name
))
1902 DECL_CONTEXT (x
) = current_file_decl
;
1903 if (DECL_EXTERNAL (x
) || TREE_PUBLIC (x
))
1905 C_DECL_IN_EXTERNAL_SCOPE (x
) = 1;
1906 bind (name
, x
, external_scope
);
1909 bind (name
, x
, file_scope
);
1915 implicit_decl_warning (tree id
, tree olddecl
)
1917 void (*diag
) (const char *, ...);
1918 switch (mesg_implicit_function_declaration
)
1921 case 1: diag
= warning
; break;
1922 case 2: diag
= error
; break;
1926 diag (N_("implicit declaration of function '%E'"), id
);
1928 locate_old_decl (olddecl
, diag
);
1931 /* Generate an implicit declaration for identifier FUNCTIONID as a
1932 function of type int (). */
1935 implicitly_declare (tree functionid
)
1937 tree decl
= lookup_name_in_scope (functionid
, external_scope
);
1941 /* FIXME: Objective-C has weird not-really-builtin functions
1942 which are supposed to be visible automatically. They wind up
1943 in the external scope because they're pushed before the file
1944 scope gets created. Catch this here and rebind them into the
1946 if (!DECL_BUILT_IN (decl
) && DECL_SOURCE_LINE (decl
) == 0)
1948 bind (functionid
, decl
, file_scope
);
1953 /* Implicit declaration of a function already declared
1954 (somehow) in a different scope, or as a built-in.
1955 If this is the first time this has happened, warn;
1956 then recycle the old declaration. */
1957 if (!C_DECL_IMPLICIT (decl
))
1959 implicit_decl_warning (functionid
, decl
);
1960 C_DECL_IMPLICIT (decl
) = 1;
1962 bind (functionid
, decl
, current_scope
);
1967 /* Not seen before. */
1968 decl
= build_decl (FUNCTION_DECL
, functionid
, default_function_type
);
1969 DECL_EXTERNAL (decl
) = 1;
1970 TREE_PUBLIC (decl
) = 1;
1971 C_DECL_IMPLICIT (decl
) = 1;
1972 implicit_decl_warning (functionid
, 0);
1974 /* C89 says implicit declarations are in the innermost block.
1975 So we record the decl in the standard fashion. */
1976 decl
= pushdecl (decl
);
1978 /* No need to call objc_check_decl here - it's a function type. */
1979 rest_of_decl_compilation (decl
, NULL
, 0, 0);
1981 /* Write a record describing this implicit function declaration
1982 to the prototypes file (if requested). */
1983 gen_aux_info_record (decl
, 0, 1, 0);
1985 /* Possibly apply some default attributes to this implicit declaration. */
1986 decl_attributes (&decl
, NULL_TREE
, 0);
1991 /* Issue an error message for a reference to an undeclared variable
1992 ID, including a reference to a builtin outside of function-call
1993 context. Establish a binding of the identifier to error_mark_node
1994 in an appropriate scope, which will suppress further errors for the
1997 undeclared_variable (tree id
)
1999 static bool already
= false;
2000 struct c_scope
*scope
;
2002 if (current_function_decl
== 0)
2004 error ("'%E' undeclared here (not in a function)", id
);
2005 scope
= current_scope
;
2009 error ("'%E' undeclared (first use in this function)", id
);
2013 error ("(Each undeclared identifier is reported only once");
2014 error ("for each function it appears in.)");
2018 /* If we are parsing old-style parameter decls, current_function_decl
2019 will be nonnull but current_function_scope will be null. */
2020 scope
= current_function_scope
? current_function_scope
: current_scope
;
2022 bind (id
, error_mark_node
, scope
);
2025 /* Subroutine of lookup_label, declare_label, define_label: construct a
2026 LABEL_DECL with all the proper frills. */
2029 make_label (tree name
, location_t location
)
2031 tree label
= build_decl (LABEL_DECL
, name
, void_type_node
);
2033 DECL_CONTEXT (label
) = current_function_decl
;
2034 DECL_MODE (label
) = VOIDmode
;
2035 DECL_SOURCE_LOCATION (label
) = location
;
2040 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
2041 Create one if none exists so far for the current function.
2042 This is called when a label is used in a goto expression or
2043 has its address taken. */
2046 lookup_label (tree name
)
2050 if (current_function_decl
== 0)
2052 error ("label %s referenced outside of any function",
2053 IDENTIFIER_POINTER (name
));
2057 /* Use a label already defined or ref'd with this name, but not if
2058 it is inherited from a containing function and wasn't declared
2060 label
= I_LABEL_DECL (name
);
2061 if (label
&& (DECL_CONTEXT (label
) == current_function_decl
2062 || C_DECLARED_LABEL_FLAG (label
)))
2064 /* If the label has only been declared, update its apparent
2065 location to point here, for better diagnostics if it
2066 turns out not to have been defined. */
2067 if (!TREE_USED (label
))
2068 DECL_SOURCE_LOCATION (label
) = input_location
;
2072 /* No label binding for that identifier; make one. */
2073 label
= make_label (name
, input_location
);
2075 /* Ordinary labels go in the current function scope. */
2076 bind (name
, label
, current_function_scope
);
2080 /* Make a label named NAME in the current function, shadowing silently
2081 any that may be inherited from containing functions or containing
2082 scopes. This is called for __label__ declarations. */
2084 /* Note that valid use, if the label being shadowed comes from another
2085 scope in the same function, requires calling declare_nonlocal_label
2086 right away. (Is this still true? -zw 2003-07-17) */
2089 declare_label (tree name
)
2091 struct c_binding
*b
= I_LABEL_BINDING (name
);
2094 /* Check to make sure that the label hasn't already been declared
2096 if (b
&& b
->contour
== current_scope
)
2098 error ("duplicate label declaration `%s'", IDENTIFIER_POINTER (name
));
2099 locate_old_decl (b
->decl
, error
);
2101 /* Just use the previous declaration. */
2105 label
= make_label (name
, input_location
);
2106 C_DECLARED_LABEL_FLAG (label
) = 1;
2108 /* Declared labels go in the current scope. */
2109 bind (name
, label
, current_scope
);
2113 /* Define a label, specifying the location in the source file.
2114 Return the LABEL_DECL node for the label, if the definition is valid.
2115 Otherwise return 0. */
2118 define_label (location_t location
, tree name
)
2120 /* Find any preexisting label with this name. It is an error
2121 if that label has already been defined in this function, or
2122 if there is a containing function with a declared label with
2124 tree label
= I_LABEL_DECL (name
);
2127 && ((DECL_CONTEXT (label
) == current_function_decl
2128 && DECL_INITIAL (label
) != 0)
2129 || (DECL_CONTEXT (label
) != current_function_decl
2130 && C_DECLARED_LABEL_FLAG (label
))))
2132 error ("%Hduplicate label `%D'", &location
, label
);
2133 locate_old_decl (label
, error
);
2136 else if (label
&& DECL_CONTEXT (label
) == current_function_decl
)
2138 /* The label has been used or declared already in this function,
2139 but not defined. Update its location to point to this
2141 DECL_SOURCE_LOCATION (label
) = location
;
2145 /* No label binding for that identifier; make one. */
2146 label
= make_label (name
, location
);
2148 /* Ordinary labels go in the current function scope. */
2149 bind (name
, label
, current_function_scope
);
2152 if (warn_traditional
&& !in_system_header
&& lookup_name (name
))
2153 warning ("%Htraditional C lacks a separate namespace for labels, "
2154 "identifier `%s' conflicts", &location
,
2155 IDENTIFIER_POINTER (name
));
2157 /* Mark label as having been defined. */
2158 DECL_INITIAL (label
) = error_mark_node
;
2162 /* Given NAME, an IDENTIFIER_NODE,
2163 return the structure (or union or enum) definition for that name.
2164 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2165 CODE says which kind of type the caller wants;
2166 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2167 If the wrong kind of type is found, an error is reported. */
2170 lookup_tag (enum tree_code code
, tree name
, int thislevel_only
)
2172 struct c_binding
*b
= I_TAG_BINDING (name
);
2178 /* We only care about whether it's in this level if
2179 thislevel_only was set or it might be a type clash. */
2180 if (thislevel_only
|| TREE_CODE (b
->decl
) != code
)
2182 /* For our purposes, a tag in the external scope is the same as
2183 a tag in the file scope. (Primarily relevant to Objective-C
2184 and its builtin structure tags, which get pushed before the
2185 file scope is created.) */
2186 if (b
->contour
== current_scope
2187 || (current_scope
== file_scope
&& b
->contour
== external_scope
))
2191 if (thislevel_only
&& !thislevel
)
2194 if (TREE_CODE (b
->decl
) != code
)
2196 /* Definition isn't the kind we were looking for. */
2197 pending_invalid_xref
= name
;
2198 pending_invalid_xref_location
= input_location
;
2200 /* If in the same binding level as a declaration as a tag
2201 of a different type, this must not be allowed to
2202 shadow that tag, so give the error immediately.
2203 (For example, "struct foo; union foo;" is invalid.) */
2205 pending_xref_error ();
2210 /* Print an error message now
2211 for a recent invalid struct, union or enum cross reference.
2212 We don't print them immediately because they are not invalid
2213 when used in the `struct foo;' construct for shadowing. */
2216 pending_xref_error (void)
2218 if (pending_invalid_xref
!= 0)
2219 error ("%H`%s' defined as wrong kind of tag",
2220 &pending_invalid_xref_location
,
2221 IDENTIFIER_POINTER (pending_invalid_xref
));
2222 pending_invalid_xref
= 0;
2226 /* Look up NAME in the current scope and its superiors
2227 in the namespace of variables, functions and typedefs.
2228 Return a ..._DECL node of some kind representing its definition,
2229 or return 0 if it is undefined. */
2232 lookup_name (tree name
)
2234 struct c_binding
*b
= I_SYMBOL_BINDING (name
);
2235 if (b
&& (b
->contour
!= external_scope
|| TREE_CODE (b
->decl
) == TYPE_DECL
))
2240 /* Similar to `lookup_name' but look only at the indicated scope. */
2243 lookup_name_in_scope (tree name
, struct c_scope
*scope
)
2245 struct c_binding
*b
;
2247 for (b
= I_SYMBOL_BINDING (name
); b
; b
= b
->shadowed
)
2248 if (b
->contour
== scope
)
2253 /* Create the predefined scalar types of C,
2254 and some nodes representing standard constants (0, 1, (void *) 0).
2255 Initialize the global scope.
2256 Make definitions for built-in primitive functions. */
2259 c_init_decl_processing (void)
2262 tree ptr_ftype_void
, ptr_ftype_ptr
;
2263 location_t save_loc
= input_location
;
2265 /* Adds some ggc roots, and reserved words for c-parse.in. */
2268 current_function_decl
= 0;
2270 /* Make the externals scope. */
2272 external_scope
= current_scope
;
2274 /* Declarations from c_common_nodes_and_builtins must not be associated
2275 with this input file, lest we get differences between using and not
2276 using preprocessed headers. */
2277 input_location
.file
= "<internal>";
2278 input_location
.line
= 0;
2280 build_common_tree_nodes (flag_signed_char
);
2282 c_common_nodes_and_builtins ();
2284 /* In C, comparisons and TRUTH_* expressions have type int. */
2285 truthvalue_type_node
= integer_type_node
;
2286 truthvalue_true_node
= integer_one_node
;
2287 truthvalue_false_node
= integer_zero_node
;
2289 /* Even in C99, which has a real boolean type. */
2290 pushdecl (build_decl (TYPE_DECL
, get_identifier ("_Bool"),
2291 boolean_type_node
));
2293 endlink
= void_list_node
;
2294 ptr_ftype_void
= build_function_type (ptr_type_node
, endlink
);
2296 = build_function_type (ptr_type_node
,
2297 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
2299 input_location
= save_loc
;
2301 pedantic_lvalues
= true;
2303 make_fname_decl
= c_make_fname_decl
;
2304 start_fname_decls ();
2307 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
2308 decl, NAME is the initialization string and TYPE_DEP indicates whether
2309 NAME depended on the type of the function. As we don't yet implement
2310 delayed emission of static data, we mark the decl as emitted
2311 so it is not placed in the output. Anything using it must therefore pull
2312 out the STRING_CST initializer directly. FIXME. */
2315 c_make_fname_decl (tree id
, int type_dep
)
2317 const char *name
= fname_as_string (type_dep
);
2318 tree decl
, type
, init
;
2319 size_t length
= strlen (name
);
2321 type
= build_array_type
2322 (build_qualified_type (char_type_node
, TYPE_QUAL_CONST
),
2323 build_index_type (size_int (length
)));
2325 decl
= build_decl (VAR_DECL
, id
, type
);
2327 TREE_STATIC (decl
) = 1;
2328 TREE_READONLY (decl
) = 1;
2329 DECL_ARTIFICIAL (decl
) = 1;
2331 init
= build_string (length
+ 1, name
);
2332 TREE_TYPE (init
) = type
;
2333 DECL_INITIAL (decl
) = init
;
2335 TREE_USED (decl
) = 1;
2337 if (current_function_decl
)
2339 DECL_CONTEXT (decl
) = current_function_decl
;
2340 bind (id
, decl
, current_function_scope
);
2343 finish_decl (decl
, init
, NULL_TREE
);
2348 /* Return a definition for a builtin function named NAME and whose data type
2349 is TYPE. TYPE should be a function type with argument types.
2350 FUNCTION_CODE tells later passes how to compile calls to this function.
2351 See tree.h for its possible values.
2353 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
2354 the name to be called if we can't opencode the function. If
2355 ATTRS is nonzero, use that for the function's attribute list. */
2358 builtin_function (const char *name
, tree type
, int function_code
,
2359 enum built_in_class
class, const char *library_name
,
2362 tree id
= get_identifier (name
);
2363 tree decl
= build_decl (FUNCTION_DECL
, id
, type
);
2364 TREE_PUBLIC (decl
) = 1;
2365 DECL_EXTERNAL (decl
) = 1;
2366 DECL_LANG_SPECIFIC (decl
) = ggc_alloc_cleared (sizeof (struct lang_decl
));
2367 DECL_BUILT_IN_CLASS (decl
) = class;
2368 DECL_FUNCTION_CODE (decl
) = function_code
;
2370 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (library_name
));
2371 make_decl_rtl (decl
, NULL
);
2373 /* Should never be called on a symbol with a preexisting meaning. */
2374 if (I_SYMBOL_BINDING (id
))
2377 C_DECL_IN_EXTERNAL_SCOPE (decl
) = 1;
2378 bind (id
, decl
, external_scope
);
2380 /* Builtins in the implementation namespace are made visible without
2381 needing to be explicitly declared. See push_file_scope. */
2382 if (name
[0] == '_' && (name
[1] == '_' || ISUPPER (name
[1])))
2384 TREE_CHAIN (decl
) = visible_builtins
;
2385 visible_builtins
= decl
;
2388 /* Possibly apply some default attributes to this built-in function. */
2390 decl_attributes (&decl
, attrs
, ATTR_FLAG_BUILT_IN
);
2392 decl_attributes (&decl
, NULL_TREE
, 0);
2397 /* Called when a declaration is seen that contains no names to declare.
2398 If its type is a reference to a structure, union or enum inherited
2399 from a containing scope, shadow that tag name for the current scope
2400 with a forward reference.
2401 If its type defines a new named structure or union
2402 or defines an enum, it is valid but we need not do anything here.
2403 Otherwise, it is an error. */
2406 shadow_tag (tree declspecs
)
2408 shadow_tag_warned (declspecs
, 0);
2412 shadow_tag_warned (tree declspecs
, int warned
)
2415 /* 1 => we have done a pedwarn. 2 => we have done a warning, but
2422 pending_invalid_xref
= 0;
2424 /* Remove the attributes from declspecs, since they will confuse the
2426 split_specs_attrs (declspecs
, &specs
, &attrs
);
2428 for (link
= specs
; link
; link
= TREE_CHAIN (link
))
2430 tree value
= TREE_VALUE (link
);
2431 enum tree_code code
= TREE_CODE (value
);
2433 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ENUMERAL_TYPE
)
2434 /* Used to test also that TYPE_SIZE (value) != 0.
2435 That caused warning for `struct foo;' at top level in the file. */
2437 tree name
= TYPE_NAME (value
);
2444 if (warned
!= 1 && code
!= ENUMERAL_TYPE
)
2445 /* Empty unnamed enum OK */
2447 pedwarn ("unnamed struct/union that defines no instances");
2453 t
= lookup_tag (code
, name
, 1);
2457 t
= make_node (code
);
2464 if (!warned
&& ! in_system_header
)
2466 warning ("useless keyword or type name in empty declaration");
2473 error ("two types specified in one empty declaration");
2478 pedwarn ("empty declaration");
2482 /* Construct an array declarator. EXPR is the expression inside [], or
2483 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied
2484 to the pointer to which a parameter array is converted). STATIC_P is
2485 nonzero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P
2486 is nonzero is the array is [*], a VLA of unspecified length which is
2487 nevertheless a complete type (not currently implemented by GCC),
2488 zero otherwise. The declarator is constructed as an ARRAY_REF
2489 (to be decoded by grokdeclarator), whose operand 0 is what's on the
2490 left of the [] (filled by in set_array_declarator_type) and operand 1
2491 is the expression inside; whose TREE_TYPE is the type qualifiers and
2492 which has TREE_STATIC set if "static" is used. */
2495 build_array_declarator (tree expr
, tree quals
, int static_p
, int vla_unspec_p
)
2498 decl
= build_nt (ARRAY_REF
, NULL_TREE
, expr
);
2499 TREE_TYPE (decl
) = quals
;
2500 TREE_STATIC (decl
) = (static_p
? 1 : 0);
2501 if (pedantic
&& !flag_isoc99
)
2503 if (static_p
|| quals
!= NULL_TREE
)
2504 pedwarn ("ISO C90 does not support `static' or type qualifiers in parameter array declarators");
2506 pedwarn ("ISO C90 does not support `[*]' array declarators");
2509 warning ("GCC does not yet properly implement `[*]' array declarators");
2513 /* Set the type of an array declarator. DECL is the declarator, as
2514 constructed by build_array_declarator; TYPE is what appears on the left
2515 of the [] and goes in operand 0. ABSTRACT_P is nonzero if it is an
2516 abstract declarator, zero otherwise; this is used to reject static and
2517 type qualifiers in abstract declarators, where they are not in the
2521 set_array_declarator_type (tree decl
, tree type
, int abstract_p
)
2523 TREE_OPERAND (decl
, 0) = type
;
2524 if (abstract_p
&& (TREE_TYPE (decl
) != NULL_TREE
|| TREE_STATIC (decl
)))
2525 error ("static or type qualifiers in abstract declarator");
2529 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
2532 groktypename (tree typename
)
2536 if (TREE_CODE (typename
) != TREE_LIST
)
2539 split_specs_attrs (TREE_PURPOSE (typename
), &specs
, &attrs
);
2541 typename
= grokdeclarator (TREE_VALUE (typename
), specs
, TYPENAME
, 0,
2544 /* Apply attributes. */
2545 decl_attributes (&typename
, attrs
, 0);
2550 /* Return a PARM_DECL node for a given pair of specs and declarator. */
2553 groktypename_in_parm_context (tree typename
)
2555 if (TREE_CODE (typename
) != TREE_LIST
)
2557 return grokdeclarator (TREE_VALUE (typename
),
2558 TREE_PURPOSE (typename
),
2562 /* Decode a declarator in an ordinary declaration or data definition.
2563 This is called as soon as the type information and variable name
2564 have been parsed, before parsing the initializer if any.
2565 Here we create the ..._DECL node, fill in its type,
2566 and put it on the list of decls for the current context.
2567 The ..._DECL node is returned as the value.
2569 Exception: for arrays where the length is not specified,
2570 the type is left null, to be filled in by `finish_decl'.
2572 Function definitions do not come here; they go to start_function
2573 instead. However, external and forward declarations of functions
2574 do go through here. Structure field declarations are done by
2575 grokfield and not through here. */
2578 start_decl (tree declarator
, tree declspecs
, int initialized
, tree attributes
)
2583 /* An object declared as __attribute__((deprecated)) suppresses
2584 warnings of uses of other deprecated items. */
2585 if (lookup_attribute ("deprecated", attributes
))
2586 deprecated_state
= DEPRECATED_SUPPRESS
;
2588 decl
= grokdeclarator (declarator
, declspecs
,
2589 NORMAL
, initialized
, NULL
);
2591 deprecated_state
= DEPRECATED_NORMAL
;
2593 if (warn_main
> 0 && TREE_CODE (decl
) != FUNCTION_DECL
2594 && MAIN_NAME_P (DECL_NAME (decl
)))
2595 warning ("%J'%D' is usually a function", decl
, decl
);
2598 /* Is it valid for this decl to have an initializer at all?
2599 If not, set INITIALIZED to zero, which will indirectly
2600 tell 'finish_decl' to ignore the initializer once it is parsed. */
2601 switch (TREE_CODE (decl
))
2604 error ("typedef '%D' is initialized (use __typeof__ instead)", decl
);
2609 error ("function '%D' is initialized like a variable", decl
);
2614 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
2615 error ("parameter '%D' is initialized", decl
);
2620 /* Don't allow initializations for incomplete types except for
2621 arrays which might be completed by the initialization. */
2623 /* This can happen if the array size is an undefined macro.
2624 We already gave a warning, so we don't need another one. */
2625 if (TREE_TYPE (decl
) == error_mark_node
)
2627 else if (COMPLETE_TYPE_P (TREE_TYPE (decl
)))
2629 /* A complete type is ok if size is fixed. */
2631 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl
))) != INTEGER_CST
2632 || C_DECL_VARIABLE_SIZE (decl
))
2634 error ("variable-sized object may not be initialized");
2638 else if (TREE_CODE (TREE_TYPE (decl
)) != ARRAY_TYPE
)
2640 error ("variable '%D' has initializer but incomplete type", decl
);
2643 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
2645 error ("elements of array '%D' have incomplete type", decl
);
2652 DECL_EXTERNAL (decl
) = 0;
2653 if (current_scope
== file_scope
)
2654 TREE_STATIC (decl
) = 1;
2656 /* Tell 'pushdecl' this is an initialized decl
2657 even though we don't yet have the initializer expression.
2658 Also tell 'finish_decl' it may store the real initializer. */
2659 DECL_INITIAL (decl
) = error_mark_node
;
2662 /* If this is a function declaration, write a record describing it to the
2663 prototypes file (if requested). */
2665 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2666 gen_aux_info_record (decl
, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl
)) != 0);
2668 /* ANSI specifies that a tentative definition which is not merged with
2669 a non-tentative definition behaves exactly like a definition with an
2670 initializer equal to zero. (Section 3.7.2)
2672 -fno-common gives strict ANSI behavior, though this tends to break
2673 a large body of code that grew up without this rule.
2675 Thread-local variables are never common, since there's no entrenched
2676 body of code to break, and it allows more efficient variable references
2677 in the presence of dynamic linking. */
2679 if (TREE_CODE (decl
) == VAR_DECL
2681 && TREE_PUBLIC (decl
)
2682 && !DECL_THREAD_LOCAL (decl
)
2684 DECL_COMMON (decl
) = 1;
2686 /* Set attributes here so if duplicate decl, will have proper attributes. */
2687 decl_attributes (&decl
, attributes
, 0);
2689 if (TREE_CODE (decl
) == FUNCTION_DECL
2690 && targetm
.calls
.promote_prototypes (TREE_TYPE (decl
)))
2692 tree ce
= declarator
;
2694 if (TREE_CODE (ce
) == INDIRECT_REF
)
2695 ce
= TREE_OPERAND (declarator
, 0);
2696 if (TREE_CODE (ce
) == CALL_EXPR
)
2698 tree args
= TREE_PURPOSE (TREE_OPERAND (ce
, 1));
2699 for (; args
; args
= TREE_CHAIN (args
))
2701 tree type
= TREE_TYPE (args
);
2702 if (INTEGRAL_TYPE_P (type
)
2703 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
2704 DECL_ARG_TYPE (args
) = integer_type_node
;
2709 if (TREE_CODE (decl
) == FUNCTION_DECL
2710 && DECL_DECLARED_INLINE_P (decl
)
2711 && DECL_UNINLINABLE (decl
)
2712 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl
)))
2713 warning ("%Jinline function '%D' given attribute noinline", decl
, decl
);
2715 /* Add this decl to the current scope.
2716 TEM may equal DECL or it may be a previous decl of the same name. */
2717 tem
= pushdecl (decl
);
2722 /* Finish processing of a declaration;
2723 install its initial value.
2724 If the length of an array type is not known before,
2725 it must be determined now, from the initial value, or it is an error. */
2728 finish_decl (tree decl
, tree init
, tree asmspec_tree
)
2730 tree type
= TREE_TYPE (decl
);
2731 int was_incomplete
= (DECL_SIZE (decl
) == 0);
2732 const char *asmspec
= 0;
2734 /* If a name was specified, get the string. */
2735 if (current_scope
== file_scope
)
2736 asmspec_tree
= maybe_apply_renaming_pragma (decl
, asmspec_tree
);
2738 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
2740 /* If `start_decl' didn't like having an initialization, ignore it now. */
2741 if (init
!= 0 && DECL_INITIAL (decl
) == 0)
2744 /* Don't crash if parm is initialized. */
2745 if (TREE_CODE (decl
) == PARM_DECL
)
2749 store_init_value (decl
, init
);
2751 if (c_dialect_objc () && (TREE_CODE (decl
) == VAR_DECL
2752 || TREE_CODE (decl
) == FUNCTION_DECL
2753 || TREE_CODE (decl
) == FIELD_DECL
))
2754 objc_check_decl (decl
);
2756 /* Deduce size of array from initialization, if not already known. */
2757 if (TREE_CODE (type
) == ARRAY_TYPE
2758 && TYPE_DOMAIN (type
) == 0
2759 && TREE_CODE (decl
) != TYPE_DECL
)
2762 = (TREE_STATIC (decl
)
2763 /* Even if pedantic, an external linkage array
2764 may have incomplete type at first. */
2765 ? pedantic
&& !TREE_PUBLIC (decl
)
2766 : !DECL_EXTERNAL (decl
));
2768 = complete_array_type (type
, DECL_INITIAL (decl
), do_default
);
2770 /* Get the completed type made by complete_array_type. */
2771 type
= TREE_TYPE (decl
);
2774 error ("%Jinitializer fails to determine size of '%D'", decl
, decl
);
2776 else if (failure
== 2)
2779 error ("%Jarray size missing in '%D'", decl
, decl
);
2780 /* If a `static' var's size isn't known,
2781 make it extern as well as static, so it does not get
2783 If it is not `static', then do not mark extern;
2784 finish_incomplete_decl will give it a default size
2785 and it will get allocated. */
2786 else if (!pedantic
&& TREE_STATIC (decl
) && ! TREE_PUBLIC (decl
))
2787 DECL_EXTERNAL (decl
) = 1;
2790 /* TYPE_MAX_VALUE is always one less than the number of elements
2791 in the array, because we start counting at zero. Therefore,
2792 warn only if the value is less than zero. */
2793 else if (pedantic
&& TYPE_DOMAIN (type
) != 0
2794 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))) < 0)
2795 error ("%Jzero or negative size array '%D'", decl
, decl
);
2797 layout_decl (decl
, 0);
2800 if (TREE_CODE (decl
) == VAR_DECL
)
2802 if (DECL_SIZE (decl
) == 0 && TREE_TYPE (decl
) != error_mark_node
2803 && COMPLETE_TYPE_P (TREE_TYPE (decl
)))
2804 layout_decl (decl
, 0);
2806 if (DECL_SIZE (decl
) == 0
2807 /* Don't give an error if we already gave one earlier. */
2808 && TREE_TYPE (decl
) != error_mark_node
2809 && (TREE_STATIC (decl
)
2811 /* A static variable with an incomplete type
2812 is an error if it is initialized.
2813 Also if it is not file scope.
2814 Otherwise, let it through, but if it is not `extern'
2815 then it may cause an error message later. */
2816 (DECL_INITIAL (decl
) != 0
2817 || !DECL_FILE_SCOPE_P (decl
))
2819 /* An automatic variable with an incomplete type
2821 !DECL_EXTERNAL (decl
)))
2823 error ("%Jstorage size of '%D' isn't known", decl
, decl
);
2824 TREE_TYPE (decl
) = error_mark_node
;
2827 if ((DECL_EXTERNAL (decl
) || TREE_STATIC (decl
))
2828 && DECL_SIZE (decl
) != 0)
2830 if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
2831 constant_expression_warning (DECL_SIZE (decl
));
2833 error ("%Jstorage size of '%D' isn't constant", decl
, decl
);
2836 if (TREE_USED (type
))
2837 TREE_USED (decl
) = 1;
2840 /* If this is a function and an assembler name is specified, reset DECL_RTL
2841 so we can give it its new name. Also, update built_in_decls if it
2842 was a normal built-in. */
2843 if (TREE_CODE (decl
) == FUNCTION_DECL
&& asmspec
)
2845 /* ASMSPEC is given, and not the name of a register. Mark the
2846 name with a star so assemble_name won't munge it. */
2847 char *starred
= alloca (strlen (asmspec
) + 2);
2849 strcpy (starred
+ 1, asmspec
);
2851 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
)
2853 tree builtin
= built_in_decls
[DECL_FUNCTION_CODE (decl
)];
2854 SET_DECL_RTL (builtin
, NULL_RTX
);
2855 SET_DECL_ASSEMBLER_NAME (builtin
, get_identifier (starred
));
2856 #ifdef TARGET_MEM_FUNCTIONS
2857 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_MEMCPY
)
2858 init_block_move_fn (starred
);
2859 else if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_MEMSET
)
2860 init_block_clear_fn (starred
);
2862 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_BCOPY
)
2863 init_block_move_fn (starred
);
2864 else if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_BZERO
)
2865 init_block_clear_fn (starred
);
2868 SET_DECL_RTL (decl
, NULL_RTX
);
2869 change_decl_assembler_name (decl
, get_identifier (starred
));
2872 /* If #pragma weak was used, mark the decl weak now. */
2873 if (current_scope
== file_scope
)
2874 maybe_apply_pragma_weak (decl
);
2876 /* Output the assembler code and/or RTL code for variables and functions,
2877 unless the type is an undefined structure or union.
2878 If not, it will get done when the type is completed. */
2880 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
)
2882 /* This is a no-op in c-lang.c or something real in objc-act.c. */
2883 if (c_dialect_objc ())
2884 objc_check_decl (decl
);
2886 if (DECL_FILE_SCOPE_P (decl
))
2888 if (DECL_INITIAL (decl
) == NULL_TREE
2889 || DECL_INITIAL (decl
) == error_mark_node
)
2890 /* Don't output anything
2891 when a tentative file-scope definition is seen.
2892 But at end of compilation, do output code for them. */
2893 DECL_DEFER_OUTPUT (decl
) = 1;
2894 rest_of_decl_compilation (decl
, asmspec
, true, 0);
2898 /* This is a local variable. If there is an ASMSPEC, the
2899 user has requested that we handle it specially. */
2902 /* In conjunction with an ASMSPEC, the `register'
2903 keyword indicates that we should place the variable
2904 in a particular register. */
2905 if (C_DECL_REGISTER (decl
))
2907 DECL_C_HARD_REGISTER (decl
) = 1;
2908 /* This cannot be done for a structure with volatile
2909 fields, on which DECL_REGISTER will have been
2911 if (!DECL_REGISTER (decl
))
2912 error ("cannot put object with volatile field into register");
2915 /* If this is not a static variable, issue a warning.
2916 It doesn't make any sense to give an ASMSPEC for an
2917 ordinary, non-register local variable. Historically,
2918 GCC has accepted -- but ignored -- the ASMSPEC in
2920 if (TREE_CODE (decl
) == VAR_DECL
2921 && !C_DECL_REGISTER (decl
)
2922 && !TREE_STATIC (decl
))
2923 warning ("%Jignoring asm-specifier for non-static local "
2924 "variable '%D'", decl
, decl
);
2926 change_decl_assembler_name (decl
, get_identifier (asmspec
));
2929 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2930 add_decl_stmt (decl
);
2933 if (!DECL_FILE_SCOPE_P (decl
))
2935 /* Recompute the RTL of a local array now
2936 if it used to be an incomplete type. */
2938 && ! TREE_STATIC (decl
) && ! DECL_EXTERNAL (decl
))
2940 /* If we used it already as memory, it must stay in memory. */
2941 TREE_ADDRESSABLE (decl
) = TREE_USED (decl
);
2942 /* If it's still incomplete now, no init will save it. */
2943 if (DECL_SIZE (decl
) == 0)
2944 DECL_INITIAL (decl
) = 0;
2949 /* If this was marked 'used', be sure it will be output. */
2950 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl
)))
2951 mark_referenced (DECL_ASSEMBLER_NAME (decl
));
2953 if (TREE_CODE (decl
) == TYPE_DECL
)
2954 rest_of_decl_compilation (decl
, NULL
, DECL_FILE_SCOPE_P (decl
), 0);
2956 /* At the end of a declaration, throw away any variable type sizes
2957 of types defined inside that declaration. There is no use
2958 computing them in the following function definition. */
2959 if (current_scope
== file_scope
)
2960 get_pending_sizes ();
2962 /* Install a cleanup (aka destructor) if one was given. */
2963 if (TREE_CODE (decl
) == VAR_DECL
&& !TREE_STATIC (decl
))
2965 tree attr
= lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl
));
2968 static bool eh_initialized_p
;
2970 tree cleanup_id
= TREE_VALUE (TREE_VALUE (attr
));
2971 tree cleanup_decl
= lookup_name (cleanup_id
);
2974 /* Build "cleanup(&decl)" for the destructor. */
2975 cleanup
= build_unary_op (ADDR_EXPR
, decl
, 0);
2976 cleanup
= build_tree_list (NULL_TREE
, cleanup
);
2977 cleanup
= build_function_call (cleanup_decl
, cleanup
);
2979 /* Don't warn about decl unused; the cleanup uses it. */
2980 TREE_USED (decl
) = 1;
2982 /* Initialize EH, if we've been told to do so. */
2983 if (flag_exceptions
&& !eh_initialized_p
)
2985 eh_initialized_p
= true;
2986 eh_personality_libfunc
2987 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
2988 ? "__gcc_personality_sj0"
2989 : "__gcc_personality_v0");
2990 using_eh_for_cleanups ();
2993 add_stmt (build_stmt (CLEANUP_STMT
, decl
, cleanup
));
2998 /* Given a parsed parameter declaration, decode it into a PARM_DECL
2999 and push that on the current scope. */
3002 push_parm_decl (tree parm
)
3006 /* Don't attempt to expand sizes while parsing this decl.
3007 (We can get here with i_s_e 1 somehow from Objective-C.) */
3008 int save_immediate_size_expand
= immediate_size_expand
;
3009 immediate_size_expand
= 0;
3011 decl
= grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm
)),
3012 TREE_PURPOSE (TREE_PURPOSE (parm
)),
3014 decl_attributes (&decl
, TREE_VALUE (parm
), 0);
3016 decl
= pushdecl (decl
);
3018 finish_decl (decl
, NULL_TREE
, NULL_TREE
);
3020 immediate_size_expand
= save_immediate_size_expand
;
3023 /* Mark all the parameter declarations to date as forward decls.
3024 Also diagnose use of this extension. */
3027 mark_forward_parm_decls (void)
3029 struct c_binding
*b
;
3031 if (pedantic
&& !current_scope
->warned_forward_parm_decls
)
3033 pedwarn ("ISO C forbids forward parameter declarations");
3034 current_scope
->warned_forward_parm_decls
= true;
3037 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
3038 if (TREE_CODE (b
->decl
) == PARM_DECL
)
3039 TREE_ASM_WRITTEN (b
->decl
) = 1;
3042 static GTY(()) int compound_literal_number
;
3044 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3045 literal, which may be an incomplete array type completed by the
3046 initializer; INIT is a CONSTRUCTOR that initializes the compound
3050 build_compound_literal (tree type
, tree init
)
3052 /* We do not use start_decl here because we have a type, not a declarator;
3053 and do not use finish_decl because the decl should be stored inside
3054 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
3055 tree decl
= build_decl (VAR_DECL
, NULL_TREE
, type
);
3058 DECL_EXTERNAL (decl
) = 0;
3059 TREE_PUBLIC (decl
) = 0;
3060 TREE_STATIC (decl
) = (current_scope
== file_scope
);
3061 DECL_CONTEXT (decl
) = current_function_decl
;
3062 TREE_USED (decl
) = 1;
3063 TREE_TYPE (decl
) = type
;
3064 TREE_READONLY (decl
) = TREE_READONLY (type
);
3065 store_init_value (decl
, init
);
3067 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
3069 int failure
= complete_array_type (type
, DECL_INITIAL (decl
), 1);
3074 type
= TREE_TYPE (decl
);
3075 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
3076 return error_mark_node
;
3078 stmt
= build_stmt (DECL_STMT
, decl
);
3079 complit
= build1 (COMPOUND_LITERAL_EXPR
, TREE_TYPE (decl
), stmt
);
3080 TREE_SIDE_EFFECTS (complit
) = 1;
3082 layout_decl (decl
, 0);
3084 if (TREE_STATIC (decl
))
3086 /* This decl needs a name for the assembler output. We also need
3087 a unique suffix to be added to the name. */
3090 ASM_FORMAT_PRIVATE_NAME (name
, "__compound_literal",
3091 compound_literal_number
);
3092 compound_literal_number
++;
3093 DECL_NAME (decl
) = get_identifier (name
);
3094 DECL_DEFER_OUTPUT (decl
) = 1;
3095 DECL_COMDAT (decl
) = 1;
3096 DECL_ARTIFICIAL (decl
) = 1;
3098 rest_of_decl_compilation (decl
, NULL
, 1, 0);
3104 /* Make TYPE a complete type based on INITIAL_VALUE.
3105 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
3106 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
3109 complete_array_type (tree type
, tree initial_value
, int do_default
)
3111 tree maxindex
= NULL_TREE
;
3116 /* Note MAXINDEX is really the maximum index,
3117 one less than the size. */
3118 if (TREE_CODE (initial_value
) == STRING_CST
)
3121 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
3122 maxindex
= build_int_2 ((TREE_STRING_LENGTH (initial_value
)
3125 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
3127 tree elts
= CONSTRUCTOR_ELTS (initial_value
);
3128 maxindex
= build_int_2 (-1, -1);
3129 for (; elts
; elts
= TREE_CHAIN (elts
))
3131 if (TREE_PURPOSE (elts
))
3132 maxindex
= TREE_PURPOSE (elts
);
3134 maxindex
= fold (build (PLUS_EXPR
, integer_type_node
,
3135 maxindex
, integer_one_node
));
3137 maxindex
= copy_node (maxindex
);
3141 /* Make an error message unless that happened already. */
3142 if (initial_value
!= error_mark_node
)
3145 /* Prevent further error messages. */
3146 maxindex
= build_int_2 (0, 0);
3153 maxindex
= build_int_2 (0, 0);
3159 TYPE_DOMAIN (type
) = build_index_type (maxindex
);
3160 if (!TREE_TYPE (maxindex
))
3161 TREE_TYPE (maxindex
) = TYPE_DOMAIN (type
);
3164 /* Lay out the type now that we can get the real answer. */
3171 /* Determine whether TYPE is a structure with a flexible array member,
3172 or a union containing such a structure (possibly recursively). */
3175 flexible_array_type_p (tree type
)
3178 switch (TREE_CODE (type
))
3181 x
= TYPE_FIELDS (type
);
3184 while (TREE_CHAIN (x
) != NULL_TREE
)
3186 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
3187 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
3188 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
3189 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
3193 for (x
= TYPE_FIELDS (type
); x
!= NULL_TREE
; x
= TREE_CHAIN (x
))
3195 if (flexible_array_type_p (TREE_TYPE (x
)))
3204 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3205 replacing with appropriate values if they are invalid. */
3207 check_bitfield_type_and_width (tree
*type
, tree
*width
, const char *orig_name
)
3210 unsigned int max_width
;
3211 unsigned HOST_WIDE_INT w
;
3212 const char *name
= orig_name
? orig_name
: _("<anonymous>");
3215 STRIP_NOPS (*width
);
3217 /* Detect and ignore out of range field width and process valid
3219 if (TREE_CODE (*width
) != INTEGER_CST
)
3221 error ("bit-field `%s' width not an integer constant", name
);
3222 *width
= integer_one_node
;
3226 constant_expression_warning (*width
);
3227 if (tree_int_cst_sgn (*width
) < 0)
3229 error ("negative width in bit-field `%s'", name
);
3230 *width
= integer_one_node
;
3232 else if (integer_zerop (*width
) && orig_name
)
3234 error ("zero width for bit-field `%s'", name
);
3235 *width
= integer_one_node
;
3239 /* Detect invalid bit-field type. */
3240 if (TREE_CODE (*type
) != INTEGER_TYPE
3241 && TREE_CODE (*type
) != BOOLEAN_TYPE
3242 && TREE_CODE (*type
) != ENUMERAL_TYPE
)
3244 error ("bit-field `%s' has invalid type", name
);
3245 *type
= unsigned_type_node
;
3248 type_mv
= TYPE_MAIN_VARIANT (*type
);
3250 && type_mv
!= integer_type_node
3251 && type_mv
!= unsigned_type_node
3252 && type_mv
!= boolean_type_node
)
3253 pedwarn ("type of bit-field `%s' is a GCC extension", name
);
3255 if (type_mv
== boolean_type_node
)
3256 max_width
= CHAR_TYPE_SIZE
;
3258 max_width
= TYPE_PRECISION (*type
);
3260 if (0 < compare_tree_int (*width
, max_width
))
3262 error ("width of `%s' exceeds its type", name
);
3264 *width
= build_int_2 (w
, 0);
3267 w
= tree_low_cst (*width
, 1);
3269 if (TREE_CODE (*type
) == ENUMERAL_TYPE
3270 && (w
< min_precision (TYPE_MIN_VALUE (*type
), TREE_UNSIGNED (*type
))
3271 || w
< min_precision (TYPE_MAX_VALUE (*type
), TREE_UNSIGNED (*type
))))
3272 warning ("`%s' is narrower than values of its type", name
);
3275 /* Given declspecs and a declarator,
3276 determine the name and type of the object declared
3277 and construct a ..._DECL node for it.
3278 (In one case we can return a ..._TYPE node instead.
3279 For invalid input we sometimes return 0.)
3281 DECLSPECS is a chain of tree_list nodes whose value fields
3282 are the storage classes and type specifiers.
3284 DECL_CONTEXT says which syntactic context this declaration is in:
3285 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
3286 FUNCDEF for a function definition. Like NORMAL but a few different
3287 error messages in each case. Return value may be zero meaning
3288 this definition is too screwy to try to parse.
3289 PARM for a parameter declaration (either within a function prototype
3290 or before a function body). Make a PARM_DECL, or return void_type_node.
3291 TYPENAME if for a typename (in a cast or sizeof).
3292 Don't make a DECL node; just return the ..._TYPE node.
3293 FIELD for a struct or union field; make a FIELD_DECL.
3294 INITIALIZED is 1 if the decl has an initializer.
3295 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
3296 representing the width of the bit-field.
3298 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3299 It may also be so in the PARM case, for a prototype where the
3300 argument type is specified but not the name.
3302 This function is where the complicated C meanings of `static'
3303 and `extern' are interpreted. */
3306 grokdeclarator (tree declarator
, tree declspecs
,
3307 enum decl_context decl_context
, int initialized
, tree
*width
)
3311 tree type
= NULL_TREE
;
3316 int type_quals
= TYPE_UNQUALIFIED
;
3318 int explicit_int
= 0;
3319 int explicit_char
= 0;
3320 int defaulted_int
= 0;
3321 tree typedef_decl
= 0;
3322 const char *name
, *orig_name
;
3323 tree typedef_type
= 0;
3324 int funcdef_flag
= 0;
3325 enum tree_code innermost_code
= ERROR_MARK
;
3326 int size_varies
= 0;
3327 tree decl_attr
= NULL_TREE
;
3328 tree array_ptr_quals
= NULL_TREE
;
3329 int array_parm_static
= 0;
3330 tree returned_attrs
= NULL_TREE
;
3331 bool bitfield
= width
!= NULL
;
3333 tree arg_info
= NULL_TREE
;
3335 if (decl_context
== FUNCDEF
)
3336 funcdef_flag
= 1, decl_context
= NORMAL
;
3338 /* Look inside a declarator for the name being declared
3339 and get it as a string, for an error message. */
3341 tree decl
= declarator
;
3345 switch (TREE_CODE (decl
))
3350 innermost_code
= TREE_CODE (decl
);
3351 decl
= TREE_OPERAND (decl
, 0);
3355 decl
= TREE_VALUE (decl
);
3358 case IDENTIFIER_NODE
:
3359 name
= IDENTIFIER_POINTER (decl
);
3371 /* A function definition's declarator must have the form of
3372 a function declarator. */
3374 if (funcdef_flag
&& innermost_code
!= CALL_EXPR
)
3377 /* If this looks like a function definition, make it one,
3378 even if it occurs where parms are expected.
3379 Then store_parm_decls will reject it and not use it as a parm. */
3380 if (decl_context
== NORMAL
&& !funcdef_flag
&& current_scope
->parm_flag
)
3381 decl_context
= PARM
;
3383 /* Look through the decl specs and record which ones appear.
3384 Some typespecs are defined as built-in typenames.
3385 Others, the ones that are modifiers of other types,
3386 are represented by bits in SPECBITS: set the bits for
3387 the modifiers that appear. Storage class keywords are also in SPECBITS.
3389 If there is a typedef name or a type, store the type in TYPE.
3390 This includes builtin typedefs such as `int'.
3392 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
3393 and did not come from a user typedef.
3395 Set LONGLONG if `long' is mentioned twice. */
3397 for (spec
= declspecs
; spec
; spec
= TREE_CHAIN (spec
))
3399 tree id
= TREE_VALUE (spec
);
3401 /* If the entire declaration is itself tagged as deprecated then
3402 suppress reports of deprecated items. */
3403 if (id
&& TREE_DEPRECATED (id
))
3405 if (deprecated_state
!= DEPRECATED_SUPPRESS
)
3406 warn_deprecated_use (id
);
3409 if (id
== ridpointers
[(int) RID_INT
])
3411 if (id
== ridpointers
[(int) RID_CHAR
])
3414 if (TREE_CODE (id
) == IDENTIFIER_NODE
&& C_IS_RESERVED_WORD (id
))
3416 enum rid i
= C_RID_CODE (id
);
3417 if ((int) i
<= (int) RID_LAST_MODIFIER
)
3419 if (i
== RID_LONG
&& (specbits
& (1 << (int) RID_LONG
)))
3422 error ("`long long long' is too long for GCC");
3425 if (pedantic
&& !flag_isoc99
&& ! in_system_header
3427 pedwarn ("ISO C90 does not support `long long'");
3431 else if (specbits
& (1 << (int) i
))
3433 if (i
== RID_CONST
|| i
== RID_VOLATILE
|| i
== RID_RESTRICT
)
3435 if (pedantic
&& !flag_isoc99
)
3436 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id
));
3439 error ("duplicate `%s'", IDENTIFIER_POINTER (id
));
3442 /* Diagnose "__thread extern". Recall that this list
3443 is in the reverse order seen in the text. */
3445 && (specbits
& (1 << (int) RID_EXTERN
3446 | 1 << (int) RID_STATIC
)))
3448 if (specbits
& 1 << (int) RID_EXTERN
)
3449 error ("`__thread' before `extern'");
3451 error ("`__thread' before `static'");
3454 specbits
|= 1 << (int) i
;
3459 error ("two or more data types in declaration of `%s'", name
);
3460 /* Actual typedefs come to us as TYPE_DECL nodes. */
3461 else if (TREE_CODE (id
) == TYPE_DECL
)
3463 if (TREE_TYPE (id
) == error_mark_node
)
3464 ; /* Allow the type to default to int to avoid cascading errors. */
3467 type
= TREE_TYPE (id
);
3468 decl_attr
= DECL_ATTRIBUTES (id
);
3472 /* Built-in types come as identifiers. */
3473 else if (TREE_CODE (id
) == IDENTIFIER_NODE
)
3475 tree t
= lookup_name (id
);
3476 if (!t
|| TREE_CODE (t
) != TYPE_DECL
)
3477 error ("`%s' fails to be a typedef or built in type",
3478 IDENTIFIER_POINTER (id
));
3479 else if (TREE_TYPE (t
) == error_mark_node
)
3483 type
= TREE_TYPE (t
);
3487 else if (TREE_CODE (id
) != ERROR_MARK
)
3494 typedef_type
= type
;
3496 size_varies
= C_TYPE_VARIABLE_SIZE (type
);
3498 /* No type at all: default to `int', and set DEFAULTED_INT
3499 because it was not a user-defined typedef. */
3503 if ((! (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3504 | (1 << (int) RID_SIGNED
)
3505 | (1 << (int) RID_UNSIGNED
)
3506 | (1 << (int) RID_COMPLEX
))))
3507 /* Don't warn about typedef foo = bar. */
3508 && ! (specbits
& (1 << (int) RID_TYPEDEF
) && initialized
)
3509 && ! in_system_header
)
3511 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type
3512 and this is a function, or if -Wimplicit; prefer the former
3513 warning since it is more explicit. */
3514 if ((warn_implicit_int
|| warn_return_type
|| flag_isoc99
)
3516 warn_about_return_type
= 1;
3517 else if (warn_implicit_int
|| flag_isoc99
)
3518 pedwarn_c99 ("type defaults to `int' in declaration of `%s'",
3523 type
= integer_type_node
;
3526 /* Now process the modifiers that were specified
3527 and check for invalid combinations. */
3529 /* Long double is a special combination. */
3531 if ((specbits
& 1 << (int) RID_LONG
) && ! longlong
3532 && TYPE_MAIN_VARIANT (type
) == double_type_node
)
3534 specbits
&= ~(1 << (int) RID_LONG
);
3535 type
= long_double_type_node
;
3538 /* Check all other uses of type modifiers. */
3540 if (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3541 | (1 << (int) RID_UNSIGNED
) | (1 << (int) RID_SIGNED
)))
3545 if ((specbits
& 1 << (int) RID_LONG
)
3546 && (specbits
& 1 << (int) RID_SHORT
))
3547 error ("both long and short specified for `%s'", name
);
3548 else if (((specbits
& 1 << (int) RID_LONG
)
3549 || (specbits
& 1 << (int) RID_SHORT
))
3551 error ("long or short specified with char for `%s'", name
);
3552 else if (((specbits
& 1 << (int) RID_LONG
)
3553 || (specbits
& 1 << (int) RID_SHORT
))
3554 && TREE_CODE (type
) == REAL_TYPE
)
3556 static int already
= 0;
3558 error ("long or short specified with floating type for `%s'", name
);
3559 if (! already
&& ! pedantic
)
3561 error ("the only valid combination is `long double'");
3565 else if ((specbits
& 1 << (int) RID_SIGNED
)
3566 && (specbits
& 1 << (int) RID_UNSIGNED
))
3567 error ("both signed and unsigned specified for `%s'", name
);
3568 else if (TREE_CODE (type
) != INTEGER_TYPE
)
3569 error ("long, short, signed or unsigned invalid for `%s'", name
);
3573 if (!explicit_int
&& !defaulted_int
&& !explicit_char
)
3575 error ("long, short, signed or unsigned used invalidly for `%s'",
3581 /* Discard the type modifiers if they are invalid. */
3584 specbits
&= ~((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3585 | (1 << (int) RID_UNSIGNED
) | (1 << (int) RID_SIGNED
));
3590 if ((specbits
& (1 << (int) RID_COMPLEX
))
3591 && TREE_CODE (type
) != INTEGER_TYPE
&& TREE_CODE (type
) != REAL_TYPE
)
3593 error ("complex invalid for `%s'", name
);
3594 specbits
&= ~(1 << (int) RID_COMPLEX
);
3597 /* Decide whether an integer type is signed or not.
3598 Optionally treat bit-fields as signed by default. */
3599 if (specbits
& 1 << (int) RID_UNSIGNED
3600 || (bitfield
&& ! flag_signed_bitfields
3601 && (explicit_int
|| defaulted_int
|| explicit_char
3602 /* A typedef for plain `int' without `signed'
3603 can be controlled just like plain `int'. */
3604 || ! (typedef_decl
!= 0
3605 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
3606 && TREE_CODE (type
) != ENUMERAL_TYPE
3607 && !(specbits
& 1 << (int) RID_SIGNED
)))
3610 type
= long_long_unsigned_type_node
;
3611 else if (specbits
& 1 << (int) RID_LONG
)
3612 type
= long_unsigned_type_node
;
3613 else if (specbits
& 1 << (int) RID_SHORT
)
3614 type
= short_unsigned_type_node
;
3615 else if (type
== char_type_node
)
3616 type
= unsigned_char_type_node
;
3617 else if (typedef_decl
)
3618 type
= c_common_unsigned_type (type
);
3620 type
= unsigned_type_node
;
3622 else if ((specbits
& 1 << (int) RID_SIGNED
)
3623 && type
== char_type_node
)
3624 type
= signed_char_type_node
;
3626 type
= long_long_integer_type_node
;
3627 else if (specbits
& 1 << (int) RID_LONG
)
3628 type
= long_integer_type_node
;
3629 else if (specbits
& 1 << (int) RID_SHORT
)
3630 type
= short_integer_type_node
;
3632 if (specbits
& 1 << (int) RID_COMPLEX
)
3634 if (pedantic
&& !flag_isoc99
)
3635 pedwarn ("ISO C90 does not support complex types");
3636 /* If we just have "complex", it is equivalent to
3637 "complex double", but if any modifiers at all are specified it is
3638 the complex form of TYPE. E.g, "complex short" is
3639 "complex short int". */
3641 if (defaulted_int
&& ! longlong
3642 && ! (specbits
& ((1 << (int) RID_LONG
) | (1 << (int) RID_SHORT
)
3643 | (1 << (int) RID_SIGNED
)
3644 | (1 << (int) RID_UNSIGNED
))))
3647 pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
3648 type
= complex_double_type_node
;
3650 else if (type
== integer_type_node
)
3653 pedwarn ("ISO C does not support complex integer types");
3654 type
= complex_integer_type_node
;
3656 else if (type
== float_type_node
)
3657 type
= complex_float_type_node
;
3658 else if (type
== double_type_node
)
3659 type
= complex_double_type_node
;
3660 else if (type
== long_double_type_node
)
3661 type
= complex_long_double_type_node
;
3665 pedwarn ("ISO C does not support complex integer types");
3666 type
= build_complex_type (type
);
3670 /* Check the type and width of a bit-field. */
3672 check_bitfield_type_and_width (&type
, width
, orig_name
);
3674 /* Figure out the type qualifiers for the declaration. There are
3675 two ways a declaration can become qualified. One is something
3676 like `const int i' where the `const' is explicit. Another is
3677 something like `typedef const int CI; CI i' where the type of the
3678 declaration contains the `const'. A third possibility is that
3679 there is a type qualifier on the element type of a typedefed
3680 array type, in which case we should extract that qualifier so
3681 that c_apply_type_quals_to_decls receives the full list of
3682 qualifiers to work with (C90 is not entirely clear about whether
3683 duplicate qualifiers should be diagnosed in this case, but it
3684 seems most appropriate to do so). */
3685 element_type
= strip_array_types (type
);
3686 constp
= !! (specbits
& 1 << (int) RID_CONST
) + TYPE_READONLY (element_type
);
3688 = !! (specbits
& 1 << (int) RID_RESTRICT
) + TYPE_RESTRICT (element_type
);
3690 = !! (specbits
& 1 << (int) RID_VOLATILE
) + TYPE_VOLATILE (element_type
);
3691 inlinep
= !! (specbits
& (1 << (int) RID_INLINE
));
3692 if (pedantic
&& !flag_isoc99
)
3695 pedwarn ("duplicate `const'");
3697 pedwarn ("duplicate `restrict'");
3699 pedwarn ("duplicate `volatile'");
3701 if (! flag_gen_aux_info
&& (TYPE_QUALS (type
)))
3702 type
= TYPE_MAIN_VARIANT (type
);
3703 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
3704 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
3705 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
3707 /* Warn if two storage classes are given. Default to `auto'. */
3712 if (specbits
& 1 << (int) RID_AUTO
) nclasses
++;
3713 if (specbits
& 1 << (int) RID_STATIC
) nclasses
++;
3714 if (specbits
& 1 << (int) RID_EXTERN
) nclasses
++;
3715 if (specbits
& 1 << (int) RID_REGISTER
) nclasses
++;
3716 if (specbits
& 1 << (int) RID_TYPEDEF
) nclasses
++;
3718 /* "static __thread" and "extern __thread" are allowed. */
3719 if ((specbits
& (1 << (int) RID_THREAD
3720 | 1 << (int) RID_STATIC
3721 | 1 << (int) RID_EXTERN
)) == (1 << (int) RID_THREAD
))
3724 /* Warn about storage classes that are invalid for certain
3725 kinds of declarations (parameters, typenames, etc.). */
3728 error ("multiple storage classes in declaration of `%s'", name
);
3729 else if (funcdef_flag
3731 & ((1 << (int) RID_REGISTER
)
3732 | (1 << (int) RID_AUTO
)
3733 | (1 << (int) RID_TYPEDEF
)
3734 | (1 << (int) RID_THREAD
))))
3736 if (specbits
& 1 << (int) RID_AUTO
3737 && (pedantic
|| current_scope
== file_scope
))
3738 pedwarn ("function definition declared `auto'");
3739 if (specbits
& 1 << (int) RID_REGISTER
)
3740 error ("function definition declared `register'");
3741 if (specbits
& 1 << (int) RID_TYPEDEF
)
3742 error ("function definition declared `typedef'");
3743 if (specbits
& 1 << (int) RID_THREAD
)
3744 error ("function definition declared `__thread'");
3745 specbits
&= ~((1 << (int) RID_TYPEDEF
) | (1 << (int) RID_REGISTER
)
3746 | (1 << (int) RID_AUTO
) | (1 << (int) RID_THREAD
));
3748 else if (decl_context
!= NORMAL
&& nclasses
> 0)
3750 if (decl_context
== PARM
&& specbits
& 1 << (int) RID_REGISTER
)
3754 switch (decl_context
)
3757 error ("storage class specified for structure field `%s'",
3761 error ("storage class specified for parameter `%s'", name
);
3764 error ("storage class specified for typename");
3767 specbits
&= ~((1 << (int) RID_TYPEDEF
) | (1 << (int) RID_REGISTER
)
3768 | (1 << (int) RID_AUTO
) | (1 << (int) RID_STATIC
)
3769 | (1 << (int) RID_EXTERN
) | (1 << (int) RID_THREAD
));
3772 else if (specbits
& 1 << (int) RID_EXTERN
&& initialized
&& ! funcdef_flag
)
3774 /* `extern' with initialization is invalid if not at file scope. */
3775 if (current_scope
== file_scope
)
3776 warning ("`%s' initialized and declared `extern'", name
);
3778 error ("`%s' has both `extern' and initializer", name
);
3780 else if (current_scope
== file_scope
)
3782 if (specbits
& 1 << (int) RID_AUTO
)
3783 error ("file-scope declaration of `%s' specifies `auto'", name
);
3787 if (specbits
& 1 << (int) RID_EXTERN
&& funcdef_flag
)
3788 error ("nested function `%s' declared `extern'", name
);
3789 else if ((specbits
& (1 << (int) RID_THREAD
3790 | 1 << (int) RID_EXTERN
3791 | 1 << (int) RID_STATIC
))
3792 == (1 << (int) RID_THREAD
))
3794 error ("function-scope `%s' implicitly auto and declared `__thread'",
3796 specbits
&= ~(1 << (int) RID_THREAD
);
3801 /* Now figure out the structure of the declarator proper.
3802 Descend through it, creating more complex types, until we reach
3803 the declared identifier (or NULL_TREE, in an absolute declarator). */
3805 while (declarator
&& TREE_CODE (declarator
) != IDENTIFIER_NODE
)
3807 if (type
== error_mark_node
)
3809 declarator
= TREE_OPERAND (declarator
, 0);
3813 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
3814 an INDIRECT_REF (for *...),
3815 a CALL_EXPR (for ...(...)),
3816 a TREE_LIST (for nested attributes),
3817 an identifier (for the name being declared)
3818 or a null pointer (for the place in an absolute declarator
3819 where the name was omitted).
3820 For the last two cases, we have just exited the loop.
3822 At this point, TYPE is the type of elements of an array,
3823 or for a function to return, or for a pointer to point to.
3824 After this sequence of ifs, TYPE is the type of the
3825 array or function or pointer, and DECLARATOR has had its
3826 outermost layer removed. */
3828 if (array_ptr_quals
!= NULL_TREE
|| array_parm_static
)
3830 /* Only the innermost declarator (making a parameter be of
3831 array type which is converted to pointer type)
3832 may have static or type qualifiers. */
3833 error ("static or type qualifiers in non-parameter array declarator");
3834 array_ptr_quals
= NULL_TREE
;
3835 array_parm_static
= 0;
3838 if (TREE_CODE (declarator
) == TREE_LIST
)
3840 /* We encode a declarator with embedded attributes using
3842 tree attrs
= TREE_PURPOSE (declarator
);
3845 declarator
= TREE_VALUE (declarator
);
3846 inner_decl
= declarator
;
3847 while (inner_decl
!= NULL_TREE
3848 && TREE_CODE (inner_decl
) == TREE_LIST
)
3849 inner_decl
= TREE_VALUE (inner_decl
);
3850 if (inner_decl
== NULL_TREE
3851 || TREE_CODE (inner_decl
) == IDENTIFIER_NODE
)
3852 attr_flags
|= (int) ATTR_FLAG_DECL_NEXT
;
3853 else if (TREE_CODE (inner_decl
) == CALL_EXPR
)
3854 attr_flags
|= (int) ATTR_FLAG_FUNCTION_NEXT
;
3855 else if (TREE_CODE (inner_decl
) == ARRAY_REF
)
3856 attr_flags
|= (int) ATTR_FLAG_ARRAY_NEXT
;
3857 returned_attrs
= decl_attributes (&type
,
3858 chainon (returned_attrs
, attrs
),
3861 else if (TREE_CODE (declarator
) == ARRAY_REF
)
3863 tree itype
= NULL_TREE
;
3864 tree size
= TREE_OPERAND (declarator
, 1);
3865 /* The index is a signed object `sizetype' bits wide. */
3866 tree index_type
= c_common_signed_type (sizetype
);
3868 array_ptr_quals
= TREE_TYPE (declarator
);
3869 array_parm_static
= TREE_STATIC (declarator
);
3871 declarator
= TREE_OPERAND (declarator
, 0);
3873 /* Check for some types that there cannot be arrays of. */
3875 if (VOID_TYPE_P (type
))
3877 error ("declaration of `%s' as array of voids", name
);
3878 type
= error_mark_node
;
3881 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3883 error ("declaration of `%s' as array of functions", name
);
3884 type
= error_mark_node
;
3887 if (pedantic
&& flexible_array_type_p (type
))
3888 pedwarn ("invalid use of structure with flexible array member");
3890 if (size
== error_mark_node
)
3891 type
= error_mark_node
;
3893 if (type
== error_mark_node
)
3896 /* If size was specified, set ITYPE to a range-type for that size.
3897 Otherwise, ITYPE remains null. finish_decl may figure it out
3898 from an initial value. */
3902 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
3903 STRIP_TYPE_NOPS (size
);
3905 if (! INTEGRAL_TYPE_P (TREE_TYPE (size
)))
3907 error ("size of array `%s' has non-integer type", name
);
3908 size
= integer_one_node
;
3911 if (pedantic
&& integer_zerop (size
))
3912 pedwarn ("ISO C forbids zero-size array `%s'", name
);
3914 if (TREE_CODE (size
) == INTEGER_CST
)
3916 constant_expression_warning (size
);
3917 if (tree_int_cst_sgn (size
) < 0)
3919 error ("size of array `%s' is negative", name
);
3920 size
= integer_one_node
;
3925 /* Make sure the array size remains visibly nonconstant
3926 even if it is (eg) a const variable with known value. */
3929 if (!flag_isoc99
&& pedantic
)
3931 if (TREE_CONSTANT (size
))
3932 pedwarn ("ISO C90 forbids array `%s' whose size can't be evaluated",
3935 pedwarn ("ISO C90 forbids variable-size array `%s'",
3940 if (integer_zerop (size
))
3942 /* A zero-length array cannot be represented with an
3943 unsigned index type, which is what we'll get with
3944 build_index_type. Create an open-ended range instead. */
3945 itype
= build_range_type (sizetype
, size
, NULL_TREE
);
3949 /* Compute the maximum valid index, that is, size - 1.
3950 Do the calculation in index_type, so that if it is
3951 a variable the computations will be done in the
3953 itype
= fold (build (MINUS_EXPR
, index_type
,
3954 convert (index_type
, size
),
3955 convert (index_type
, size_one_node
)));
3957 /* If that overflowed, the array is too big.
3958 ??? While a size of INT_MAX+1 technically shouldn't
3959 cause an overflow (because we subtract 1), the overflow
3960 is recorded during the conversion to index_type, before
3961 the subtraction. Handling this case seems like an
3962 unnecessary complication. */
3963 if (TREE_OVERFLOW (itype
))
3965 error ("size of array `%s' is too large", name
);
3966 type
= error_mark_node
;
3972 /* We must be able to distinguish the
3973 SAVE_EXPR_CONTEXT for the variably-sized type
3974 so that we can set it correctly in
3975 set_save_expr_context. The convention is
3976 that all SAVE_EXPRs that need to be reset
3977 have NULL_TREE for their SAVE_EXPR_CONTEXT. */
3978 tree cfd
= current_function_decl
;
3979 if (decl_context
== PARM
)
3980 current_function_decl
= NULL_TREE
;
3981 itype
= variable_size (itype
);
3982 if (decl_context
== PARM
)
3983 current_function_decl
= cfd
;
3985 itype
= build_index_type (itype
);
3988 else if (decl_context
== FIELD
)
3990 if (pedantic
&& !flag_isoc99
&& !in_system_header
)
3991 pedwarn ("ISO C90 does not support flexible array members");
3993 /* ISO C99 Flexible array members are effectively identical
3994 to GCC's zero-length array extension. */
3995 itype
= build_range_type (sizetype
, size_zero_node
, NULL_TREE
);
3998 /* If pedantic, complain about arrays of incomplete types. */
4000 if (pedantic
&& !COMPLETE_TYPE_P (type
))
4001 pedwarn ("array type has incomplete element type");
4003 /* Build the array type itself, then merge any constancy or
4004 volatility into the target type. We must do it in this order
4005 to ensure that the TYPE_MAIN_VARIANT field of the array type
4006 is set correctly. */
4008 type
= build_array_type (type
, itype
);
4010 type
= c_build_qualified_type (type
, type_quals
);
4013 C_TYPE_VARIABLE_SIZE (type
) = 1;
4015 /* The GCC extension for zero-length arrays differs from
4016 ISO flexible array members in that sizeof yields zero. */
4017 if (size
&& integer_zerop (size
))
4020 TYPE_SIZE (type
) = bitsize_zero_node
;
4021 TYPE_SIZE_UNIT (type
) = size_zero_node
;
4023 if (decl_context
!= PARM
4024 && (array_ptr_quals
!= NULL_TREE
|| array_parm_static
))
4026 error ("static or type qualifiers in non-parameter array declarator");
4027 array_ptr_quals
= NULL_TREE
;
4028 array_parm_static
= 0;
4031 else if (TREE_CODE (declarator
) == CALL_EXPR
)
4033 /* Say it's a definition only for the CALL_EXPR closest to
4035 bool really_funcdef
= (funcdef_flag
4036 && (TREE_CODE (TREE_OPERAND (declarator
, 0))
4037 == IDENTIFIER_NODE
));
4040 /* Declaring a function type.
4041 Make sure we have a valid type for the function to return. */
4042 if (type
== error_mark_node
)
4047 /* Warn about some types functions can't return. */
4049 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4051 error ("`%s' declared as function returning a function", name
);
4052 type
= integer_type_node
;
4054 if (TREE_CODE (type
) == ARRAY_TYPE
)
4056 error ("`%s' declared as function returning an array", name
);
4057 type
= integer_type_node
;
4060 /* Construct the function type and go to the next
4061 inner layer of declarator. */
4062 arg_info
= TREE_OPERAND (declarator
, 1);
4063 arg_types
= grokparms (arg_info
, really_funcdef
);
4065 /* Type qualifiers before the return type of the function
4066 qualify the return type, not the function type. */
4069 /* Type qualifiers on a function return type are normally
4070 permitted by the standard but have no effect, so give a
4071 warning at -Wextra. Qualifiers on a void return type have
4072 meaning as a GNU extension, and are banned on function
4073 definitions in ISO C. FIXME: strictly we shouldn't
4074 pedwarn for qualified void return types except on function
4075 definitions, but not doing so could lead to the undesirable
4076 state of a "volatile void" function return type not being
4077 warned about, and a use of the function being compiled
4078 with GNU semantics, with no diagnostics under -pedantic. */
4079 if (VOID_TYPE_P (type
) && pedantic
&& !in_system_header
)
4080 pedwarn ("ISO C forbids qualified void function return type");
4081 else if (extra_warnings
4082 && !(VOID_TYPE_P (type
)
4083 && type_quals
== TYPE_QUAL_VOLATILE
))
4084 warning ("type qualifiers ignored on function return type");
4086 type
= c_build_qualified_type (type
, type_quals
);
4088 type_quals
= TYPE_UNQUALIFIED
;
4090 type
= build_function_type (type
, arg_types
);
4091 declarator
= TREE_OPERAND (declarator
, 0);
4093 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4094 the formal parameter list of this FUNCTION_TYPE to point to
4095 the FUNCTION_TYPE node itself. */
4100 for (link
= ARG_INFO_TAGS (arg_info
);
4102 link
= TREE_CHAIN (link
))
4103 TYPE_CONTEXT (TREE_VALUE (link
)) = type
;
4106 else if (TREE_CODE (declarator
) == INDIRECT_REF
)
4108 /* Merge any constancy or volatility into the target type
4111 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4113 pedwarn ("ISO C forbids qualified function types");
4115 type
= c_build_qualified_type (type
, type_quals
);
4116 type_quals
= TYPE_UNQUALIFIED
;
4119 type
= build_pointer_type (type
);
4121 /* Process a list of type modifier keywords
4122 (such as const or volatile) that were given inside the `*'. */
4124 if (TREE_TYPE (declarator
))
4132 for (typemodlist
= TREE_TYPE (declarator
); typemodlist
;
4133 typemodlist
= TREE_CHAIN (typemodlist
))
4135 tree qualifier
= TREE_VALUE (typemodlist
);
4137 if (C_IS_RESERVED_WORD (qualifier
))
4139 if (C_RID_CODE (qualifier
) == RID_CONST
)
4141 else if (C_RID_CODE (qualifier
) == RID_VOLATILE
)
4143 else if (C_RID_CODE (qualifier
) == RID_RESTRICT
)
4153 error ("invalid type modifier within pointer declarator");
4154 if (pedantic
&& !flag_isoc99
)
4157 pedwarn ("duplicate `const'");
4159 pedwarn ("duplicate `volatile'");
4161 pedwarn ("duplicate `restrict'");
4164 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4165 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4166 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4169 declarator
= TREE_OPERAND (declarator
, 0);
4176 /* Now TYPE has the actual type. */
4178 /* Did array size calculations overflow? */
4180 if (TREE_CODE (type
) == ARRAY_TYPE
4181 && COMPLETE_TYPE_P (type
)
4182 && TREE_OVERFLOW (TYPE_SIZE (type
)))
4184 error ("size of array `%s' is too large", name
);
4185 /* If we proceed with the array type as it is, we'll eventually
4186 crash in tree_low_cst(). */
4187 type
= error_mark_node
;
4190 /* If this is declaring a typedef name, return a TYPE_DECL. */
4192 if (specbits
& (1 << (int) RID_TYPEDEF
))
4195 /* Note that the grammar rejects storage classes
4196 in typenames, fields or parameters */
4197 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4199 pedwarn ("ISO C forbids qualified function types");
4201 type
= c_build_qualified_type (type
, type_quals
);
4202 decl
= build_decl (TYPE_DECL
, declarator
, type
);
4203 if ((specbits
& (1 << (int) RID_SIGNED
))
4204 || (typedef_decl
&& C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
4205 C_TYPEDEF_EXPLICITLY_SIGNED (decl
) = 1;
4206 decl_attributes (&decl
, returned_attrs
, 0);
4210 /* Detect the case of an array type of unspecified size
4211 which came, as such, direct from a typedef name.
4212 We must copy the type, so that each identifier gets
4213 a distinct type, so that each identifier's size can be
4214 controlled separately by its own initializer. */
4216 if (type
!= 0 && typedef_type
!= 0
4217 && TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
) == 0
4218 && TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (typedef_type
))
4220 type
= build_array_type (TREE_TYPE (type
), 0);
4222 C_TYPE_VARIABLE_SIZE (type
) = 1;
4225 /* If this is a type name (such as, in a cast or sizeof),
4226 compute the type and return it now. */
4228 if (decl_context
== TYPENAME
)
4230 /* Note that the grammar rejects storage classes
4231 in typenames, fields or parameters */
4232 if (pedantic
&& TREE_CODE (type
) == FUNCTION_TYPE
4234 pedwarn ("ISO C forbids const or volatile function types");
4236 type
= c_build_qualified_type (type
, type_quals
);
4237 decl_attributes (&type
, returned_attrs
, 0);
4241 /* Aside from typedefs and type names (handle above),
4242 `void' at top level (not within pointer)
4243 is allowed only in public variables.
4244 We don't complain about parms either, but that is because
4245 a better error message can be made later. */
4247 if (VOID_TYPE_P (type
) && decl_context
!= PARM
4248 && ! ((decl_context
!= FIELD
&& TREE_CODE (type
) != FUNCTION_TYPE
)
4249 && ((specbits
& (1 << (int) RID_EXTERN
))
4250 || (current_scope
== file_scope
4252 & ((1 << (int) RID_STATIC
) | (1 << (int) RID_REGISTER
)))))))
4254 error ("variable or field `%s' declared void", name
);
4255 type
= integer_type_node
;
4258 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4259 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4264 if (decl_context
== PARM
)
4266 tree type_as_written
;
4269 /* A parameter declared as an array of T is really a pointer to T.
4270 One declared as a function is really a pointer to a function. */
4272 if (TREE_CODE (type
) == ARRAY_TYPE
)
4274 /* Transfer const-ness of array into that of type pointed to. */
4275 type
= TREE_TYPE (type
);
4277 type
= c_build_qualified_type (type
, type_quals
);
4278 type
= build_pointer_type (type
);
4279 type_quals
= TYPE_UNQUALIFIED
;
4280 if (array_ptr_quals
)
4282 tree new_ptr_quals
, new_ptr_attrs
;
4284 split_specs_attrs (array_ptr_quals
, &new_ptr_quals
, &new_ptr_attrs
);
4285 /* We don't yet implement attributes in this context. */
4286 if (new_ptr_attrs
!= NULL_TREE
)
4287 warning ("attributes in parameter array declarator ignored");
4292 for (; new_ptr_quals
; new_ptr_quals
= TREE_CHAIN (new_ptr_quals
))
4294 tree qualifier
= TREE_VALUE (new_ptr_quals
);
4296 if (C_IS_RESERVED_WORD (qualifier
))
4298 if (C_RID_CODE (qualifier
) == RID_CONST
)
4300 else if (C_RID_CODE (qualifier
) == RID_VOLATILE
)
4302 else if (C_RID_CODE (qualifier
) == RID_RESTRICT
)
4312 error ("invalid type modifier within array declarator");
4314 type_quals
= ((constp
? TYPE_QUAL_CONST
: 0)
4315 | (restrictp
? TYPE_QUAL_RESTRICT
: 0)
4316 | (volatilep
? TYPE_QUAL_VOLATILE
: 0));
4320 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
4322 if (pedantic
&& type_quals
)
4323 pedwarn ("ISO C forbids qualified function types");
4325 type
= c_build_qualified_type (type
, type_quals
);
4326 type
= build_pointer_type (type
);
4327 type_quals
= TYPE_UNQUALIFIED
;
4329 else if (type_quals
)
4330 type
= c_build_qualified_type (type
, type_quals
);
4332 type_as_written
= type
;
4334 decl
= build_decl (PARM_DECL
, declarator
, type
);
4336 C_DECL_VARIABLE_SIZE (decl
) = 1;
4338 /* Compute the type actually passed in the parmlist,
4339 for the case where there is no prototype.
4340 (For example, shorts and chars are passed as ints.)
4341 When there is a prototype, this is overridden later. */
4343 if (type
== error_mark_node
)
4344 promoted_type
= type
;
4346 promoted_type
= c_type_promotes_to (type
);
4348 DECL_ARG_TYPE (decl
) = promoted_type
;
4349 DECL_ARG_TYPE_AS_WRITTEN (decl
) = type_as_written
;
4351 else if (decl_context
== FIELD
)
4353 /* Structure field. It may not be a function. */
4355 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4357 error ("field `%s' declared as a function", name
);
4358 type
= build_pointer_type (type
);
4360 else if (TREE_CODE (type
) != ERROR_MARK
4361 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type
))
4363 error ("field `%s' has incomplete type", name
);
4364 type
= error_mark_node
;
4366 /* Move type qualifiers down to element of an array. */
4367 if (TREE_CODE (type
) == ARRAY_TYPE
&& type_quals
)
4368 type
= build_array_type (c_build_qualified_type (TREE_TYPE (type
),
4370 TYPE_DOMAIN (type
));
4371 decl
= build_decl (FIELD_DECL
, declarator
, type
);
4372 DECL_NONADDRESSABLE_P (decl
) = bitfield
;
4375 C_DECL_VARIABLE_SIZE (decl
) = 1;
4377 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
4379 /* Every function declaration is "external"
4380 except for those which are inside a function body
4381 in which `auto' is used.
4382 That is a case not specified by ANSI C,
4383 and we use it for forward declarations for nested functions. */
4384 int extern_ref
= (!(specbits
& (1 << (int) RID_AUTO
))
4385 || current_scope
== file_scope
);
4387 if (specbits
& (1 << (int) RID_AUTO
)
4388 && (pedantic
|| current_scope
== file_scope
))
4389 pedwarn ("invalid storage class for function `%s'", name
);
4390 if (specbits
& (1 << (int) RID_REGISTER
))
4391 error ("invalid storage class for function `%s'", name
);
4392 if (specbits
& (1 << (int) RID_THREAD
))
4393 error ("invalid storage class for function `%s'", name
);
4394 /* Function declaration not at file scope.
4395 Storage classes other than `extern' are not allowed
4396 and `extern' makes no difference. */
4397 if (current_scope
!= file_scope
4398 && (specbits
& ((1 << (int) RID_STATIC
) | (1 << (int) RID_INLINE
)))
4400 pedwarn ("invalid storage class for function `%s'", name
);
4402 decl
= build_decl (FUNCTION_DECL
, declarator
, type
);
4403 decl
= build_decl_attribute_variant (decl
, decl_attr
);
4405 DECL_LANG_SPECIFIC (decl
)
4406 = ggc_alloc_cleared (sizeof (struct lang_decl
));
4408 if (pedantic
&& type_quals
&& ! DECL_IN_SYSTEM_HEADER (decl
))
4409 pedwarn ("ISO C forbids qualified function types");
4411 /* GNU C interprets a `volatile void' return type to indicate
4412 that the function does not return. */
4413 if ((type_quals
& TYPE_QUAL_VOLATILE
)
4414 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
4415 warning ("`noreturn' function returns non-void value");
4418 DECL_EXTERNAL (decl
) = 1;
4419 /* Record absence of global scope for `static' or `auto'. */
4421 = !(specbits
& ((1 << (int) RID_STATIC
) | (1 << (int) RID_AUTO
)));
4423 /* For a function definition, record the argument information
4424 block in DECL_ARGUMENTS where store_parm_decls will look
4427 DECL_ARGUMENTS (decl
) = arg_info
;
4430 C_FUNCTION_IMPLICIT_INT (decl
) = 1;
4432 /* Record presence of `inline', if it is reasonable. */
4433 if (MAIN_NAME_P (declarator
))
4436 warning ("cannot inline function `main'");
4440 /* Record that the function is declared `inline'. */
4441 DECL_DECLARED_INLINE_P (decl
) = 1;
4443 /* Do not mark bare declarations as DECL_INLINE. Doing so
4444 in the presence of multiple declarations can result in
4445 the abstract origin pointing between the declarations,
4446 which will confuse dwarf2out. */
4449 DECL_INLINE (decl
) = 1;
4450 if (specbits
& (1 << (int) RID_EXTERN
))
4451 current_extern_inline
= 1;
4454 /* If -finline-functions, assume it can be inlined. This does
4455 two things: let the function be deferred until it is actually
4456 needed, and let dwarf2 know that the function is inlinable. */
4457 else if (flag_inline_trees
== 2 && initialized
)
4458 DECL_INLINE (decl
) = 1;
4462 /* It's a variable. */
4463 /* An uninitialized decl with `extern' is a reference. */
4464 int extern_ref
= !initialized
&& (specbits
& (1 << (int) RID_EXTERN
));
4466 /* Move type qualifiers down to element of an array. */
4467 if (TREE_CODE (type
) == ARRAY_TYPE
&& type_quals
)
4469 int saved_align
= TYPE_ALIGN(type
);
4470 type
= build_array_type (c_build_qualified_type (TREE_TYPE (type
),
4472 TYPE_DOMAIN (type
));
4473 TYPE_ALIGN (type
) = saved_align
;
4475 else if (type_quals
)
4476 type
= c_build_qualified_type (type
, type_quals
);
4478 /* C99 6.2.2p7: It is invalid (compile-time undefined
4479 behavior) to create an 'extern' declaration for a
4480 variable if there is a global declaration that is
4481 'static' and the global declaration is not visible.
4482 (If the static declaration _is_ currently visible,
4483 the 'extern' declaration is taken to refer to that decl.) */
4484 if (extern_ref
&& current_scope
!= file_scope
)
4486 tree global_decl
= identifier_global_value (declarator
);
4487 tree visible_decl
= lookup_name (declarator
);
4490 && global_decl
!= visible_decl
4491 && TREE_CODE (global_decl
) == VAR_DECL
4492 && !TREE_PUBLIC (global_decl
))
4493 error ("variable previously declared 'static' redeclared "
4497 decl
= build_decl (VAR_DECL
, declarator
, type
);
4499 C_DECL_VARIABLE_SIZE (decl
) = 1;
4502 pedwarn ("%Jvariable '%D' declared `inline'", decl
, decl
);
4504 DECL_EXTERNAL (decl
) = extern_ref
;
4506 /* At file scope, the presence of a `static' or `register' storage
4507 class specifier, or the absence of all storage class specifiers
4508 makes this declaration a definition (perhaps tentative). Also,
4509 the absence of both `static' and `register' makes it public. */
4510 if (current_scope
== file_scope
)
4512 TREE_PUBLIC (decl
) = !(specbits
& ((1 << (int) RID_STATIC
)
4513 | (1 << (int) RID_REGISTER
)));
4514 TREE_STATIC (decl
) = !extern_ref
;
4516 /* Not at file scope, only `static' makes a static definition. */
4519 TREE_STATIC (decl
) = (specbits
& (1 << (int) RID_STATIC
)) != 0;
4520 TREE_PUBLIC (decl
) = extern_ref
;
4523 if (specbits
& 1 << (int) RID_THREAD
)
4525 if (targetm
.have_tls
)
4526 DECL_THREAD_LOCAL (decl
) = 1;
4528 /* A mere warning is sure to result in improper semantics
4529 at runtime. Don't bother to allow this to compile. */
4530 error ("thread-local storage not supported for this target");
4534 /* Record `register' declaration for warnings on &
4535 and in case doing stupid register allocation. */
4537 if (specbits
& (1 << (int) RID_REGISTER
))
4539 C_DECL_REGISTER (decl
) = 1;
4540 DECL_REGISTER (decl
) = 1;
4543 /* Record constancy and volatility. */
4544 c_apply_type_quals_to_decl (type_quals
, decl
);
4546 /* If a type has volatile components, it should be stored in memory.
4547 Otherwise, the fact that those components are volatile
4548 will be ignored, and would even crash the compiler. */
4549 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl
)))
4551 /* It is not an error for a structure with volatile fields to
4552 be declared register, but reset DECL_REGISTER since it
4553 cannot actually go in a register. */
4554 int was_reg
= C_DECL_REGISTER (decl
);
4555 C_DECL_REGISTER (decl
) = 0;
4556 DECL_REGISTER (decl
) = 0;
4557 c_mark_addressable (decl
);
4558 C_DECL_REGISTER (decl
) = was_reg
;
4561 #ifdef ENABLE_CHECKING
4562 /* This is the earliest point at which we might know the assembler
4563 name of a variable. Thus, if it's known before this, die horribly. */
4564 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
4568 decl_attributes (&decl
, returned_attrs
, 0);
4574 /* Decode the parameter-list info for a function type or function definition.
4575 The argument is the value returned by `get_parm_info' (or made in parse.y
4576 if there is an identifier list instead of a parameter decl list).
4577 These two functions are separate because when a function returns
4578 or receives functions then each is called multiple times but the order
4579 of calls is different. The last call to `grokparms' is always the one
4580 that contains the formal parameter names of a function definition.
4582 Return a list of arg types to use in the FUNCTION_TYPE for this function.
4584 FUNCDEF_FLAG is nonzero for a function definition, 0 for
4585 a mere declaration. A nonempty identifier-list gets an error message
4586 when FUNCDEF_FLAG is zero. */
4589 grokparms (tree arg_info
, int funcdef_flag
)
4591 tree arg_types
= ARG_INFO_TYPES (arg_info
);
4593 if (warn_strict_prototypes
&& arg_types
== 0 && !funcdef_flag
4594 && !in_system_header
)
4595 warning ("function declaration isn't a prototype");
4597 if (arg_types
== error_mark_node
)
4598 return 0; /* don't set TYPE_ARG_TYPES in this case */
4600 else if (arg_types
&& TREE_CODE (TREE_VALUE (arg_types
)) == IDENTIFIER_NODE
)
4603 pedwarn ("parameter names (without types) in function declaration");
4605 ARG_INFO_PARMS (arg_info
) = ARG_INFO_TYPES (arg_info
);
4606 ARG_INFO_TYPES (arg_info
) = 0;
4611 tree parm
, type
, typelt
;
4612 unsigned int parmno
;
4614 /* If the arg types are incomplete in a declaration, they must
4615 include undefined tags. These tags can never be defined in
4616 the scope of the declaration, so the types can never be
4617 completed, and no call can be compiled successfully. */
4619 for (parm
= ARG_INFO_PARMS (arg_info
), typelt
= arg_types
, parmno
= 1;
4621 parm
= TREE_CHAIN (parm
), typelt
= TREE_CHAIN (typelt
), parmno
++)
4623 type
= TREE_VALUE (typelt
);
4624 if (type
== error_mark_node
)
4627 if (!COMPLETE_TYPE_P (type
))
4631 if (DECL_NAME (parm
))
4632 error ("%Jparameter %u ('%D') has incomplete type",
4633 parm
, parmno
, parm
);
4635 error ("%Jparameter %u has incomplete type",
4638 TREE_VALUE (typelt
) = error_mark_node
;
4639 TREE_TYPE (parm
) = error_mark_node
;
4643 if (DECL_NAME (parm
))
4644 warning ("%Jparameter %u ('%D') has incomplete type",
4645 parm
, parmno
, parm
);
4647 warning ("%Jparameter %u has incomplete type",
4656 /* Take apart the current scope and return a tree_list node with info
4657 on a parameter list just parsed. This tree_list node should be
4658 examined using the ARG_INFO_* macros, defined above:
4660 ARG_INFO_PARMS: a list of parameter decls.
4661 ARG_INFO_TAGS: a list of structure, union and enum tags defined.
4662 ARG_INFO_TYPES: a list of argument types to go in the FUNCTION_TYPE.
4663 ARG_INFO_OTHERS: a list of non-parameter decls (notably enumeration
4664 constants) defined with the parameters.
4666 This tree_list node is later fed to 'grokparms' and 'store_parm_decls'.
4668 ELLIPSIS being true means the argument list ended in '...' so don't
4669 append a sentinel (void_list_node) to the end of the type-list. */
4672 get_parm_info (bool ellipsis
)
4674 struct c_binding
*b
= current_scope
->bindings
;
4675 tree arg_info
= make_node (TREE_LIST
);
4681 static bool explained_incomplete_types
= false;
4682 bool gave_void_only_once_err
= false;
4684 /* The bindings in this scope must not get put into a block.
4685 We will take care of deleting the binding nodes. */
4686 current_scope
->bindings
= 0;
4688 /* This function is only called if there was *something* on the
4690 #ifdef ENABLE_CHECKING
4695 /* A parameter list consisting solely of 'void' indicates that the
4696 function takes no arguments. But if the 'void' is qualified
4697 (by 'const' or 'volatile'), or has a storage class specifier
4698 ('register'), then the behavior is undefined; issue an error.
4699 Typedefs for 'void' are OK (see DR#157). */
4700 if (b
->prev
== 0 /* one binding */
4701 && TREE_CODE (b
->decl
) == PARM_DECL
/* which is a parameter */
4702 && !DECL_NAME (b
->decl
) /* anonymous */
4703 && VOID_TYPE_P (TREE_TYPE (b
->decl
))) /* of void type */
4705 if (TREE_THIS_VOLATILE (b
->decl
)
4706 || TREE_READONLY (b
->decl
)
4707 || C_DECL_REGISTER (b
->decl
))
4708 error ("'void' as only parameter may not be qualified");
4710 /* There cannot be an ellipsis. */
4712 error ("'void' must be the only parameter");
4714 ARG_INFO_TYPES (arg_info
) = void_list_node
;
4719 types
= void_list_node
;
4721 /* Break up the bindings list into parms, tags, types, and others;
4722 apply sanity checks; purge the name-to-decl bindings. */
4725 tree decl
= b
->decl
;
4726 tree type
= TREE_TYPE (decl
);
4727 const char *keyword
;
4729 switch (TREE_CODE (decl
))
4734 #ifdef ENABLE_CHECKING
4735 if (I_SYMBOL_BINDING (b
->id
) != b
) abort ();
4737 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
4740 /* Check for forward decls that never got their actual decl. */
4741 if (TREE_ASM_WRITTEN (decl
))
4742 error ("%Jparameter '%D' has just a forward declaration",
4744 /* Check for (..., void, ...) and issue an error. */
4745 else if (VOID_TYPE_P (type
) && !DECL_NAME (decl
))
4747 if (!gave_void_only_once_err
)
4749 error ("'void' must be the only parameter");
4750 gave_void_only_once_err
= true;
4755 /* Valid parameter, add it to the list. */
4756 TREE_CHAIN (decl
) = parms
;
4759 /* Since there is a prototype, args are passed in their
4760 declared types. The back end may override this later. */
4761 DECL_ARG_TYPE (decl
) = type
;
4762 types
= tree_cons (0, type
, types
);
4766 case ENUMERAL_TYPE
: keyword
= "struct"; goto tag
;
4767 case UNION_TYPE
: keyword
= "union"; goto tag
;
4768 case RECORD_TYPE
: keyword
= "enum"; goto tag
;
4770 /* Types may not have tag-names, in which case the type
4771 appears in the bindings list with b->id NULL. */
4774 #ifdef ENABLE_CHECKING
4775 if (I_TAG_BINDING (b
->id
) != b
) abort ();
4777 I_TAG_BINDING (b
->id
) = b
->shadowed
;
4780 /* Warn about any struct, union or enum tags defined in a
4781 parameter list. The scope of such types is limited to
4782 the parameter list, which is rarely if ever desirable
4783 (it's impossible to call such a function with type-
4784 correct arguments). An anonymous union parm type is
4785 meaningful as a GNU extension, so don't warn for that. */
4786 if (TREE_CODE (decl
) != UNION_TYPE
|| b
->id
!= 0)
4789 /* The %s will be one of 'struct', 'union', or 'enum'. */
4790 warning ("'%s %E' declared inside parameter list",
4793 /* The %s will be one of 'struct', 'union', or 'enum'. */
4794 warning ("anonymous %s declared inside parameter list",
4797 if (! explained_incomplete_types
)
4799 warning ("its scope is only this definition or declaration,"
4800 " which is probably not what you want");
4801 explained_incomplete_types
= true;
4805 tags
= tree_cons (b
->id
, decl
, tags
);
4810 /* CONST_DECLs appear here when we have an embedded enum,
4811 and TYPE_DECLs appear here when we have an embedded struct
4812 or union. No warnings for this - we already warned about the
4816 #ifdef ENABLE_CHECKING
4817 if (I_SYMBOL_BINDING (b
->id
) != b
) abort ();
4819 I_SYMBOL_BINDING (b
->id
) = b
->shadowed
;
4822 TREE_CHAIN (decl
) = others
;
4826 /* Other things that might be encountered. */
4835 b
= free_binding_and_advance (b
);
4838 ARG_INFO_PARMS (arg_info
) = parms
;
4839 ARG_INFO_TAGS (arg_info
) = tags
;
4840 ARG_INFO_TYPES (arg_info
) = types
;
4841 ARG_INFO_OTHERS (arg_info
) = others
;
4845 /* Get the struct, enum or union (CODE says which) with tag NAME.
4846 Define the tag as a forward-reference if it is not defined. */
4849 xref_tag (enum tree_code code
, tree name
)
4851 /* If a cross reference is requested, look up the type
4852 already defined for this tag and return it. */
4854 tree ref
= lookup_tag (code
, name
, 0);
4855 /* If this is the right type of tag, return what we found.
4856 (This reference will be shadowed by shadow_tag later if appropriate.)
4857 If this is the wrong type of tag, do not return it. If it was the
4858 wrong type in the same scope, we will have had an error
4859 message already; if in a different scope and declaring
4860 a name, pending_xref_error will give an error message; but if in a
4861 different scope and not declaring a name, this tag should
4862 shadow the previous declaration of a different type of tag, and
4863 this would not work properly if we return the reference found.
4864 (For example, with "struct foo" in an outer scope, "union foo;"
4865 must shadow that tag with a new one of union type.) */
4866 if (ref
&& TREE_CODE (ref
) == code
)
4869 /* If no such tag is yet defined, create a forward-reference node
4870 and record it as the "definition".
4871 When a real declaration of this type is found,
4872 the forward-reference will be altered into a real type. */
4874 ref
= make_node (code
);
4875 if (code
== ENUMERAL_TYPE
)
4877 /* Give the type a default layout like unsigned int
4878 to avoid crashing if it does not get defined. */
4879 TYPE_MODE (ref
) = TYPE_MODE (unsigned_type_node
);
4880 TYPE_ALIGN (ref
) = TYPE_ALIGN (unsigned_type_node
);
4881 TYPE_USER_ALIGN (ref
) = 0;
4882 TREE_UNSIGNED (ref
) = 1;
4883 TYPE_PRECISION (ref
) = TYPE_PRECISION (unsigned_type_node
);
4884 TYPE_MIN_VALUE (ref
) = TYPE_MIN_VALUE (unsigned_type_node
);
4885 TYPE_MAX_VALUE (ref
) = TYPE_MAX_VALUE (unsigned_type_node
);
4888 pushtag (name
, ref
);
4893 /* Make sure that the tag NAME is defined *in the current scope*
4894 at least as a forward reference.
4895 CODE says which kind of tag NAME ought to be. */
4898 start_struct (enum tree_code code
, tree name
)
4900 /* If there is already a tag defined at this scope
4901 (as a forward reference), just return it. */
4906 ref
= lookup_tag (code
, name
, 1);
4907 if (ref
&& TREE_CODE (ref
) == code
)
4909 if (TYPE_FIELDS (ref
))
4911 if (code
== UNION_TYPE
)
4912 error ("redefinition of `union %s'", IDENTIFIER_POINTER (name
));
4914 error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name
));
4919 /* Otherwise create a forward-reference just so the tag is in scope. */
4921 ref
= make_node (code
);
4922 pushtag (name
, ref
);
4925 C_TYPE_BEING_DEFINED (ref
) = 1;
4926 TYPE_PACKED (ref
) = flag_pack_struct
;
4930 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
4931 of a structure component, returning a FIELD_DECL node.
4932 WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
4934 This is done during the parsing of the struct declaration.
4935 The FIELD_DECL nodes are chained together and the lot of them
4936 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
4939 grokfield (tree declarator
, tree declspecs
, tree width
)
4943 if (declarator
== NULL_TREE
&& width
== NULL_TREE
)
4945 /* This is an unnamed decl.
4947 If we have something of the form "union { list } ;" then this
4948 is the anonymous union extension. Similarly for struct.
4950 If this is something of the form "struct foo;", then
4951 If MS extensions are enabled, this is handled as an
4953 Otherwise this is a forward declaration of a structure tag.
4955 If this is something of the form "foo;" and foo is a TYPE_DECL, then
4956 If MS extensions are enabled and foo names a structure, then
4957 again this is an anonymous struct.
4958 Otherwise this is an error.
4960 Oh what a horrid tangled web we weave. I wonder if MS consciously
4961 took this from Plan 9 or if it was an accident of implementation
4962 that took root before someone noticed the bug... */
4964 tree type
= TREE_VALUE (declspecs
);
4966 if (flag_ms_extensions
&& TREE_CODE (type
) == TYPE_DECL
)
4967 type
= TREE_TYPE (type
);
4968 if (TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
)
4970 if (flag_ms_extensions
)
4973 goto warn_unnamed_field
;
4974 else if (TYPE_NAME (type
) == NULL
)
4977 goto warn_unnamed_field
;
4982 warning ("declaration does not declare anything");
4987 value
= grokdeclarator (declarator
, declspecs
, FIELD
, 0,
4988 width
? &width
: NULL
);
4990 finish_decl (value
, NULL_TREE
, NULL_TREE
);
4991 DECL_INITIAL (value
) = width
;
4996 /* Generate an error for any duplicate field names in FIELDLIST. Munge
4997 the list such that this does not present a problem later. */
5000 detect_field_duplicates (tree fieldlist
)
5005 /* First, see if there are more than "a few" fields.
5006 This is trivially true if there are zero or one fields. */
5009 x
= TREE_CHAIN (fieldlist
);
5015 } while (timeout
> 0 && x
);
5017 /* If there were "few" fields, avoid the overhead of allocating
5018 a hash table. Instead just do the nested traversal thing. */
5021 for (x
= TREE_CHAIN (fieldlist
); x
; x
= TREE_CHAIN (x
))
5024 for (y
= fieldlist
; y
!= x
; y
= TREE_CHAIN (y
))
5025 if (DECL_NAME (y
) == DECL_NAME (x
))
5027 error ("%Jduplicate member '%D'", x
, x
);
5028 DECL_NAME (x
) = NULL_TREE
;
5034 htab_t htab
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
5037 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5038 if ((y
= DECL_NAME (x
)) != 0)
5040 slot
= htab_find_slot (htab
, y
, INSERT
);
5043 error ("%Jduplicate member '%D'", x
, x
);
5044 DECL_NAME (x
) = NULL_TREE
;
5053 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5054 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5055 ATTRIBUTES are attributes to be applied to the structure. */
5058 finish_struct (tree t
, tree fieldlist
, tree attributes
)
5061 bool toplevel
= file_scope
== current_scope
;
5062 int saw_named_field
;
5064 /* If this type was previously laid out as a forward reference,
5065 make sure we lay it out again. */
5069 decl_attributes (&t
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
5073 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5074 if (DECL_NAME (x
) != 0)
5078 pedwarn ("%s has no %s",
5079 TREE_CODE (t
) == UNION_TYPE
? _("union") : _("struct"),
5080 fieldlist
? _("named members") : _("members"));
5083 /* Install struct as DECL_CONTEXT of each field decl.
5084 Also process specified field sizes,m which is found in the DECL_INITIAL.
5085 Store 0 there, except for ": 0" fields (so we can find them
5086 and delete them, below). */
5088 saw_named_field
= 0;
5089 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5091 DECL_CONTEXT (x
) = t
;
5092 DECL_PACKED (x
) |= TYPE_PACKED (t
);
5094 /* If any field is const, the structure type is pseudo-const. */
5095 if (TREE_READONLY (x
))
5096 C_TYPE_FIELDS_READONLY (t
) = 1;
5099 /* A field that is pseudo-const makes the structure likewise. */
5100 tree t1
= TREE_TYPE (x
);
5101 while (TREE_CODE (t1
) == ARRAY_TYPE
)
5102 t1
= TREE_TYPE (t1
);
5103 if ((TREE_CODE (t1
) == RECORD_TYPE
|| TREE_CODE (t1
) == UNION_TYPE
)
5104 && C_TYPE_FIELDS_READONLY (t1
))
5105 C_TYPE_FIELDS_READONLY (t
) = 1;
5108 /* Any field that is volatile means variables of this type must be
5109 treated in some ways as volatile. */
5110 if (TREE_THIS_VOLATILE (x
))
5111 C_TYPE_FIELDS_VOLATILE (t
) = 1;
5113 /* Any field of nominal variable size implies structure is too. */
5114 if (C_DECL_VARIABLE_SIZE (x
))
5115 C_TYPE_VARIABLE_SIZE (t
) = 1;
5117 /* Detect invalid nested redefinition. */
5118 if (TREE_TYPE (x
) == t
)
5119 error ("nested redefinition of `%s'",
5120 IDENTIFIER_POINTER (TYPE_NAME (t
)));
5122 if (DECL_INITIAL (x
))
5124 unsigned HOST_WIDE_INT width
= tree_low_cst (DECL_INITIAL (x
), 1);
5125 DECL_SIZE (x
) = bitsize_int (width
);
5126 DECL_BIT_FIELD (x
) = 1;
5127 SET_DECL_C_BIT_FIELD (x
);
5130 DECL_INITIAL (x
) = 0;
5132 /* Detect flexible array member in an invalid context. */
5133 if (TREE_CODE (TREE_TYPE (x
)) == ARRAY_TYPE
5134 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
5135 && TYPE_DOMAIN (TREE_TYPE (x
)) != NULL_TREE
5136 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x
))) == NULL_TREE
)
5138 if (TREE_CODE (t
) == UNION_TYPE
)
5140 error ("%Jflexible array member in union", x
);
5141 TREE_TYPE (x
) = error_mark_node
;
5143 else if (TREE_CHAIN (x
) != NULL_TREE
)
5145 error ("%Jflexible array member not at end of struct", x
);
5146 TREE_TYPE (x
) = error_mark_node
;
5148 else if (! saw_named_field
)
5150 error ("%Jflexible array member in otherwise empty struct", x
);
5151 TREE_TYPE (x
) = error_mark_node
;
5155 if (pedantic
&& TREE_CODE (t
) == RECORD_TYPE
5156 && flexible_array_type_p (TREE_TYPE (x
)))
5157 pedwarn ("%Jinvalid use of structure with flexible array member", x
);
5160 saw_named_field
= 1;
5163 detect_field_duplicates (fieldlist
);
5165 /* Now we have the nearly final fieldlist. Record it,
5166 then lay out the structure or union (including the fields). */
5168 TYPE_FIELDS (t
) = fieldlist
;
5172 /* Delete all zero-width bit-fields from the fieldlist. */
5174 tree
*fieldlistp
= &fieldlist
;
5176 if (TREE_CODE (*fieldlistp
) == FIELD_DECL
&& DECL_INITIAL (*fieldlistp
))
5177 *fieldlistp
= TREE_CHAIN (*fieldlistp
);
5179 fieldlistp
= &TREE_CHAIN (*fieldlistp
);
5182 /* Now we have the truly final field list.
5183 Store it in this type and in the variants. */
5185 TYPE_FIELDS (t
) = fieldlist
;
5187 /* If there are lots of fields, sort so we can look through them fast.
5188 We arbitrarily consider 16 or more elts to be "a lot". */
5193 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5195 if (len
> 15 || DECL_NAME (x
) == NULL
)
5203 struct lang_type
*space
;
5204 struct sorted_fields_type
*space2
;
5206 len
+= list_length (x
);
5208 /* Use the same allocation policy here that make_node uses, to
5209 ensure that this lives as long as the rest of the struct decl.
5210 All decls in an inline function need to be saved. */
5212 space
= ggc_alloc (sizeof (struct lang_type
));
5213 space2
= ggc_alloc (sizeof (struct sorted_fields_type
) + len
* sizeof (tree
));
5217 field_array
= &space2
->elts
[0];
5218 for (x
= fieldlist
; x
; x
= TREE_CHAIN (x
))
5220 field_array
[len
++] = x
;
5222 /* If there is anonymous struct or union, break out of the loop. */
5223 if (DECL_NAME (x
) == NULL
)
5226 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
5229 TYPE_LANG_SPECIFIC (t
) = space
;
5230 TYPE_LANG_SPECIFIC (t
)->s
->len
= len
;
5231 field_array
= TYPE_LANG_SPECIFIC (t
)->s
->elts
;
5232 qsort (field_array
, len
, sizeof (tree
), field_decl_cmp
);
5237 for (x
= TYPE_MAIN_VARIANT (t
); x
; x
= TYPE_NEXT_VARIANT (x
))
5239 TYPE_FIELDS (x
) = TYPE_FIELDS (t
);
5240 TYPE_LANG_SPECIFIC (x
) = TYPE_LANG_SPECIFIC (t
);
5241 TYPE_ALIGN (x
) = TYPE_ALIGN (t
);
5242 TYPE_USER_ALIGN (x
) = TYPE_USER_ALIGN (t
);
5245 /* If this was supposed to be a transparent union, but we can't
5246 make it one, warn and turn off the flag. */
5247 if (TREE_CODE (t
) == UNION_TYPE
5248 && TYPE_TRANSPARENT_UNION (t
)
5249 && TYPE_MODE (t
) != DECL_MODE (TYPE_FIELDS (t
)))
5251 TYPE_TRANSPARENT_UNION (t
) = 0;
5252 warning ("union cannot be made transparent");
5255 /* If this structure or union completes the type of any previous
5256 variable declaration, lay it out and output its rtl. */
5257 for (x
= C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
));
5261 tree decl
= TREE_VALUE (x
);
5262 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
5263 layout_array_type (TREE_TYPE (decl
));
5264 if (TREE_CODE (decl
) != TYPE_DECL
)
5266 layout_decl (decl
, 0);
5267 if (c_dialect_objc ())
5268 objc_check_decl (decl
);
5269 rest_of_decl_compilation (decl
, NULL
, toplevel
, 0);
5274 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t
)) = 0;
5276 /* Finish debugging output for this type. */
5277 rest_of_type_compilation (t
, toplevel
);
5282 /* Lay out the type T, and its element type, and so on. */
5285 layout_array_type (tree t
)
5287 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5288 layout_array_type (TREE_TYPE (t
));
5292 /* Begin compiling the definition of an enumeration type.
5293 NAME is its name (or null if anonymous).
5294 Returns the type object, as yet incomplete.
5295 Also records info about it so that build_enumerator
5296 may be used to declare the individual values as they are read. */
5299 start_enum (tree name
)
5303 /* If this is the real definition for a previous forward reference,
5304 fill in the contents in the same object that used to be the
5305 forward reference. */
5308 enumtype
= lookup_tag (ENUMERAL_TYPE
, name
, 1);
5310 if (enumtype
== 0 || TREE_CODE (enumtype
) != ENUMERAL_TYPE
)
5312 enumtype
= make_node (ENUMERAL_TYPE
);
5313 pushtag (name
, enumtype
);
5316 C_TYPE_BEING_DEFINED (enumtype
) = 1;
5318 if (TYPE_VALUES (enumtype
) != 0)
5320 /* This enum is a named one that has been declared already. */
5321 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name
));
5323 /* Completely replace its old definition.
5324 The old enumerators remain defined, however. */
5325 TYPE_VALUES (enumtype
) = 0;
5328 enum_next_value
= integer_zero_node
;
5331 if (flag_short_enums
)
5332 TYPE_PACKED (enumtype
) = 1;
5337 /* After processing and defining all the values of an enumeration type,
5338 install their decls in the enumeration type and finish it off.
5339 ENUMTYPE is the type object, VALUES a list of decl-value pairs,
5340 and ATTRIBUTES are the specified attributes.
5341 Returns ENUMTYPE. */
5344 finish_enum (tree enumtype
, tree values
, tree attributes
)
5347 tree minnode
= 0, maxnode
= 0, enum_value_type
;
5348 int precision
, unsign
;
5349 bool toplevel
= (file_scope
== current_scope
);
5351 decl_attributes (&enumtype
, attributes
, (int) ATTR_FLAG_TYPE_IN_PLACE
);
5353 /* Calculate the maximum value of any enumerator in this type. */
5355 if (values
== error_mark_node
)
5356 minnode
= maxnode
= integer_zero_node
;
5359 minnode
= maxnode
= TREE_VALUE (values
);
5360 for (pair
= TREE_CHAIN (values
); pair
; pair
= TREE_CHAIN (pair
))
5362 tree value
= TREE_VALUE (pair
);
5363 if (tree_int_cst_lt (maxnode
, value
))
5365 if (tree_int_cst_lt (value
, minnode
))
5370 /* Construct the final type of this enumeration. It is the same
5371 as one of the integral types - the narrowest one that fits, except
5372 that normally we only go as narrow as int - and signed iff any of
5373 the values are negative. */
5374 unsign
= (tree_int_cst_sgn (minnode
) >= 0);
5375 precision
= MAX (min_precision (minnode
, unsign
),
5376 min_precision (maxnode
, unsign
));
5377 if (TYPE_PACKED (enumtype
) || precision
> TYPE_PRECISION (integer_type_node
))
5379 tree narrowest
= c_common_type_for_size (precision
, unsign
);
5382 warning ("enumeration values exceed range of largest integer");
5383 narrowest
= long_long_integer_type_node
;
5386 precision
= TYPE_PRECISION (narrowest
);
5389 precision
= TYPE_PRECISION (integer_type_node
);
5391 if (precision
== TYPE_PRECISION (integer_type_node
))
5392 enum_value_type
= c_common_type_for_size (precision
, 0);
5394 enum_value_type
= enumtype
;
5396 TYPE_MIN_VALUE (enumtype
) = minnode
;
5397 TYPE_MAX_VALUE (enumtype
) = maxnode
;
5398 TYPE_PRECISION (enumtype
) = precision
;
5399 TREE_UNSIGNED (enumtype
) = unsign
;
5400 TYPE_SIZE (enumtype
) = 0;
5401 layout_type (enumtype
);
5403 if (values
!= error_mark_node
)
5405 /* Change the type of the enumerators to be the enum type. We
5406 need to do this irrespective of the size of the enum, for
5407 proper type checking. Replace the DECL_INITIALs of the
5408 enumerators, and the value slots of the list, with copies
5409 that have the enum type; they cannot be modified in place
5410 because they may be shared (e.g. integer_zero_node) Finally,
5411 change the purpose slots to point to the names of the decls. */
5412 for (pair
= values
; pair
; pair
= TREE_CHAIN (pair
))
5414 tree enu
= TREE_PURPOSE (pair
);
5416 TREE_TYPE (enu
) = enumtype
;
5418 /* The ISO C Standard mandates enumerators to have type int,
5419 even though the underlying type of an enum type is
5420 unspecified. Here we convert any enumerators that fit in
5421 an int to type int, to avoid promotions to unsigned types
5422 when comparing integers with enumerators that fit in the
5423 int range. When -pedantic is given, build_enumerator()
5424 would have already taken care of those that don't fit. */
5425 if (int_fits_type_p (DECL_INITIAL (enu
), enum_value_type
))
5426 DECL_INITIAL (enu
) = convert (enum_value_type
, DECL_INITIAL (enu
));
5428 DECL_INITIAL (enu
) = convert (enumtype
, DECL_INITIAL (enu
));
5430 TREE_PURPOSE (pair
) = DECL_NAME (enu
);
5431 TREE_VALUE (pair
) = DECL_INITIAL (enu
);
5434 TYPE_VALUES (enumtype
) = values
;
5437 /* Fix up all variant types of this enum type. */
5438 for (tem
= TYPE_MAIN_VARIANT (enumtype
); tem
; tem
= TYPE_NEXT_VARIANT (tem
))
5440 if (tem
== enumtype
)
5442 TYPE_VALUES (tem
) = TYPE_VALUES (enumtype
);
5443 TYPE_MIN_VALUE (tem
) = TYPE_MIN_VALUE (enumtype
);
5444 TYPE_MAX_VALUE (tem
) = TYPE_MAX_VALUE (enumtype
);
5445 TYPE_SIZE (tem
) = TYPE_SIZE (enumtype
);
5446 TYPE_SIZE_UNIT (tem
) = TYPE_SIZE_UNIT (enumtype
);
5447 TYPE_MODE (tem
) = TYPE_MODE (enumtype
);
5448 TYPE_PRECISION (tem
) = TYPE_PRECISION (enumtype
);
5449 TYPE_ALIGN (tem
) = TYPE_ALIGN (enumtype
);
5450 TYPE_USER_ALIGN (tem
) = TYPE_USER_ALIGN (enumtype
);
5451 TREE_UNSIGNED (tem
) = TREE_UNSIGNED (enumtype
);
5454 /* Finish debugging output for this type. */
5455 rest_of_type_compilation (enumtype
, toplevel
);
5460 /* Build and install a CONST_DECL for one value of the
5461 current enumeration type (one that was begun with start_enum).
5462 Return a tree-list containing the CONST_DECL and its value.
5463 Assignment of sequential values by default is handled here. */
5466 build_enumerator (tree name
, tree value
)
5470 /* Validate and default VALUE. */
5472 /* Remove no-op casts from the value. */
5474 STRIP_TYPE_NOPS (value
);
5478 /* Don't issue more errors for error_mark_node (i.e. an
5479 undeclared identifier) - just ignore the value expression. */
5480 if (value
== error_mark_node
)
5482 else if (TREE_CODE (value
) != INTEGER_CST
)
5484 error ("enumerator value for '%E' is not an integer constant", name
);
5489 value
= default_conversion (value
);
5490 constant_expression_warning (value
);
5494 /* Default based on previous value. */
5495 /* It should no longer be possible to have NON_LVALUE_EXPR
5499 value
= enum_next_value
;
5501 error ("overflow in enumeration values");
5504 if (pedantic
&& ! int_fits_type_p (value
, integer_type_node
))
5506 pedwarn ("ISO C restricts enumerator values to range of `int'");
5507 /* XXX This causes -pedantic to change the meaning of the program.
5508 Remove? -zw 2004-03-15 */
5509 value
= convert (integer_type_node
, value
);
5512 /* Set basis for default for next value. */
5513 enum_next_value
= build_binary_op (PLUS_EXPR
, value
, integer_one_node
, 0);
5514 enum_overflow
= tree_int_cst_lt (enum_next_value
, value
);
5516 /* Now create a declaration for the enum value name. */
5518 type
= TREE_TYPE (value
);
5519 type
= c_common_type_for_size (MAX (TYPE_PRECISION (type
),
5520 TYPE_PRECISION (integer_type_node
)),
5521 (TYPE_PRECISION (type
)
5522 >= TYPE_PRECISION (integer_type_node
)
5523 && TREE_UNSIGNED (type
)));
5525 decl
= build_decl (CONST_DECL
, name
, type
);
5526 DECL_INITIAL (decl
) = convert (type
, value
);
5529 return tree_cons (decl
, value
, NULL_TREE
);
5533 /* Create the FUNCTION_DECL for a function definition.
5534 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
5535 the declaration; they describe the function's name and the type it returns,
5536 but twisted together in a fashion that parallels the syntax of C.
5538 This function creates a binding context for the function body
5539 as well as setting up the FUNCTION_DECL in current_function_decl.
5541 Returns 1 on success. If the DECLARATOR is not suitable for a function
5542 (it defines a datum instead), we return 0, which tells
5543 yyparse to report a parse error. */
5546 start_function (tree declspecs
, tree declarator
, tree attributes
)
5548 tree decl1
, old_decl
;
5550 int old_immediate_size_expand
= immediate_size_expand
;
5552 current_function_returns_value
= 0; /* Assume, until we see it does. */
5553 current_function_returns_null
= 0;
5554 current_function_returns_abnormally
= 0;
5555 warn_about_return_type
= 0;
5556 current_extern_inline
= 0;
5557 c_in_iteration_stmt
= 0;
5560 /* Don't expand any sizes in the return type of the function. */
5561 immediate_size_expand
= 0;
5563 decl1
= grokdeclarator (declarator
, declspecs
, FUNCDEF
, 1, NULL
);
5565 /* If the declarator is not suitable for a function definition,
5566 cause a syntax error. */
5569 immediate_size_expand
= old_immediate_size_expand
;
5573 decl_attributes (&decl1
, attributes
, 0);
5575 if (DECL_DECLARED_INLINE_P (decl1
)
5576 && DECL_UNINLINABLE (decl1
)
5577 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1
)))
5578 warning ("%Jinline function '%D' given attribute noinline", decl1
, decl1
);
5580 announce_function (decl1
);
5582 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1
))))
5584 error ("return type is an incomplete type");
5585 /* Make it return void instead. */
5587 = build_function_type (void_type_node
,
5588 TYPE_ARG_TYPES (TREE_TYPE (decl1
)));
5591 if (warn_about_return_type
)
5592 pedwarn_c99 ("return type defaults to `int'");
5594 /* Make the init_value nonzero so pushdecl knows this is not tentative.
5595 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
5596 DECL_INITIAL (decl1
) = error_mark_node
;
5598 /* If this definition isn't a prototype and we had a prototype declaration
5599 before, copy the arg type info from that prototype.
5600 But not if what we had before was a builtin function. */
5601 old_decl
= lookup_name_in_scope (DECL_NAME (decl1
), current_scope
);
5602 if (old_decl
!= 0 && TREE_CODE (TREE_TYPE (old_decl
)) == FUNCTION_TYPE
5603 && !DECL_BUILT_IN (old_decl
)
5604 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
5605 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl
))))
5606 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0)
5608 TREE_TYPE (decl1
) = TREE_TYPE (old_decl
);
5609 current_function_prototype_locus
= DECL_SOURCE_LOCATION (old_decl
);
5612 /* Optionally warn of old-fashioned def with no previous prototype. */
5613 if (warn_strict_prototypes
5614 && TYPE_ARG_TYPES (TREE_TYPE (decl1
)) == 0
5615 && C_DECL_ISNT_PROTOTYPE (old_decl
))
5616 warning ("function declaration isn't a prototype");
5617 /* Optionally warn of any global def with no previous prototype. */
5618 else if (warn_missing_prototypes
5619 && TREE_PUBLIC (decl1
)
5620 && ! MAIN_NAME_P (DECL_NAME (decl1
))
5621 && C_DECL_ISNT_PROTOTYPE (old_decl
))
5622 warning ("%Jno previous prototype for '%D'", decl1
, decl1
);
5623 /* Optionally warn of any def with no previous prototype
5624 if the function has already been used. */
5625 else if (warn_missing_prototypes
5626 && old_decl
!= 0 && TREE_USED (old_decl
)
5627 && TYPE_ARG_TYPES (TREE_TYPE (old_decl
)) == 0)
5628 warning ("%J'%D' was used with no prototype before its definition",
5630 /* Optionally warn of any global def with no previous declaration. */
5631 else if (warn_missing_declarations
5632 && TREE_PUBLIC (decl1
)
5634 && ! MAIN_NAME_P (DECL_NAME (decl1
)))
5635 warning ("%Jno previous declaration for '%D'", decl1
, decl1
);
5636 /* Optionally warn of any def with no previous declaration
5637 if the function has already been used. */
5638 else if (warn_missing_declarations
5639 && old_decl
!= 0 && TREE_USED (old_decl
)
5640 && C_DECL_IMPLICIT (old_decl
))
5641 warning ("%J`%D' was used with no declaration before its definition",
5644 /* This is a definition, not a reference.
5645 So normally clear DECL_EXTERNAL.
5646 However, `extern inline' acts like a declaration
5647 except for defining how to inline. So set DECL_EXTERNAL in that case. */
5648 DECL_EXTERNAL (decl1
) = current_extern_inline
;
5650 /* This function exists in static storage.
5651 (This does not mean `static' in the C sense!) */
5652 TREE_STATIC (decl1
) = 1;
5654 /* A nested function is not global. */
5655 if (current_function_decl
!= 0)
5656 TREE_PUBLIC (decl1
) = 0;
5658 #ifdef ENABLE_CHECKING
5659 /* This is the earliest point at which we might know the assembler
5660 name of the function. Thus, if it's set before this, die horribly. */
5661 if (DECL_ASSEMBLER_NAME_SET_P (decl1
))
5665 /* If #pragma weak was used, mark the decl weak now. */
5666 if (current_scope
== file_scope
)
5667 maybe_apply_pragma_weak (decl1
);
5669 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
5670 if (warn_main
> 0 && MAIN_NAME_P (DECL_NAME (decl1
)))
5675 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1
)))
5676 != integer_type_node
)
5677 pedwarn ("%Jreturn type of '%D' is not `int'", decl1
, decl1
);
5679 for (args
= TYPE_ARG_TYPES (TREE_TYPE (decl1
)); args
;
5680 args
= TREE_CHAIN (args
))
5682 tree type
= args
? TREE_VALUE (args
) : 0;
5684 if (type
== void_type_node
)
5691 if (TYPE_MAIN_VARIANT (type
) != integer_type_node
)
5692 pedwarn ("%Jfirst argument of '%D' should be `int'",
5697 if (TREE_CODE (type
) != POINTER_TYPE
5698 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
5699 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
5701 pedwarn ("%Jsecond argument of '%D' should be 'char **'",
5706 if (TREE_CODE (type
) != POINTER_TYPE
5707 || TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
5708 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type
)))
5710 pedwarn ("%Jthird argument of '%D' should probably be "
5711 "'char **'", decl1
, decl1
);
5716 /* It is intentional that this message does not mention the third
5717 argument because it's only mentioned in an appendix of the
5719 if (argct
> 0 && (argct
< 2 || argct
> 3))
5720 pedwarn ("%J'%D' takes only zero or two arguments", decl1
, decl1
);
5722 if (! TREE_PUBLIC (decl1
))
5723 pedwarn ("%J'%D' is normally a non-static function", decl1
, decl1
);
5726 /* Record the decl so that the function name is defined.
5727 If we already have a decl for this name, and it is a FUNCTION_DECL,
5728 use the old decl. */
5730 current_function_decl
= pushdecl (decl1
);
5733 declare_parm_level ();
5735 make_decl_rtl (current_function_decl
, NULL
);
5737 restype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
5738 /* Promote the value to int before returning it. */
5739 if (c_promoting_integer_type_p (restype
))
5741 /* It retains unsignedness if not really getting wider. */
5742 if (TREE_UNSIGNED (restype
)
5743 && (TYPE_PRECISION (restype
)
5744 == TYPE_PRECISION (integer_type_node
)))
5745 restype
= unsigned_type_node
;
5747 restype
= integer_type_node
;
5749 DECL_RESULT (current_function_decl
)
5750 = build_decl (RESULT_DECL
, NULL_TREE
, restype
);
5752 /* If this fcn was already referenced via a block-scope `extern' decl
5753 (or an implicit decl), propagate certain information about the usage. */
5754 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl
)))
5755 TREE_ADDRESSABLE (current_function_decl
) = 1;
5757 immediate_size_expand
= old_immediate_size_expand
;
5759 start_fname_decls ();
5764 /* Subroutine of store_parm_decls which handles new-style function
5765 definitions (prototype format). The parms already have decls, so we
5766 need only record them as in effect and complain if any redundant
5767 old-style parm decls were written. */
5769 store_parm_decls_newstyle (tree fndecl
, tree arg_info
)
5772 tree parms
= ARG_INFO_PARMS (arg_info
);
5773 tree tags
= ARG_INFO_TAGS (arg_info
);
5774 tree others
= ARG_INFO_OTHERS (arg_info
);
5776 if (current_scope
->bindings
)
5778 error ("%Jold-style parameter declarations in prototyped "
5779 "function definition", fndecl
);
5781 /* Get rid of the old-style declarations. */
5785 /* Don't issue this warning for nested functions, and don't issue this
5786 warning if we got here because ARG_INFO_TYPES was error_mark_node
5787 (this happens when a function definition has just an ellipsis in
5788 its parameter list). */
5789 else if (warn_traditional
&& !in_system_header
5790 && DECL_CONTEXT (fndecl
) == current_file_decl
5791 && ARG_INFO_TYPES (arg_info
) != error_mark_node
)
5792 warning ("%Jtraditional C rejects ISO C style function definitions",
5795 /* Now make all the parameter declarations visible in the function body.
5796 We can bypass most of the grunt work of pushdecl. */
5797 for (decl
= parms
; decl
; decl
= TREE_CHAIN (decl
))
5799 DECL_CONTEXT (decl
) = current_function_decl
;
5800 if (DECL_NAME (decl
))
5801 bind (DECL_NAME (decl
), decl
, current_scope
);
5803 error ("%Jparameter name omitted", decl
);
5806 /* Record the parameter list in the function declaration. */
5807 DECL_ARGUMENTS (fndecl
) = parms
;
5809 /* Now make all the ancillary declarations visible, likewise. */
5810 for (decl
= others
; decl
; decl
= TREE_CHAIN (decl
))
5812 DECL_CONTEXT (decl
) = current_function_decl
;
5813 if (DECL_NAME (decl
))
5814 bind (DECL_NAME (decl
), decl
, current_scope
);
5817 /* And all the tag declarations. */
5818 for (decl
= tags
; decl
; decl
= TREE_CHAIN (decl
))
5819 if (TREE_PURPOSE (decl
))
5820 bind (TREE_PURPOSE (decl
), TREE_VALUE (decl
), current_scope
);
5823 /* Subroutine of store_parm_decls which handles old-style function
5824 definitions (separate parameter list and declarations). */
5827 store_parm_decls_oldstyle (tree fndecl
, tree arg_info
)
5829 struct c_binding
*b
;
5830 tree parm
, decl
, last
;
5831 tree parmids
= ARG_INFO_PARMS (arg_info
);
5833 /* We use DECL_WEAK as a flag to show which parameters have been
5834 seen already, since it is not used on PARM_DECL. */
5835 #ifdef ENABLE_CHECKING
5836 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
5837 if (TREE_CODE (b
->decl
) == PARM_DECL
&& DECL_WEAK (b
->decl
))
5841 if (warn_old_style_definition
&& !in_system_header
)
5842 warning ("%Jold-style function definition", fndecl
);
5844 /* Match each formal parameter name with its declaration. Save each
5845 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
5846 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
5848 if (TREE_VALUE (parm
) == 0)
5850 error ("%Jparameter name missing from parameter list", fndecl
);
5851 TREE_PURPOSE (parm
) = 0;
5855 b
= I_SYMBOL_BINDING (TREE_VALUE (parm
));
5856 if (b
&& b
->contour
== current_scope
)
5859 /* If we got something other than a PARM_DECL it is an error. */
5860 if (TREE_CODE (decl
) != PARM_DECL
)
5861 error ("%J'%D' declared as a non-parameter", decl
, decl
);
5862 /* If the declaration is already marked, we have a duplicate
5863 name. Complain and ignore the duplicate. */
5864 else if (DECL_WEAK (decl
))
5866 error ("%Jmultiple parameters named '%D'", decl
, decl
);
5867 TREE_PURPOSE (parm
) = 0;
5870 /* If the declaration says "void", complain and turn it into
5872 else if (VOID_TYPE_P (TREE_TYPE (decl
)))
5874 error ("%Jparameter '%D' declared with void type", decl
, decl
);
5875 TREE_TYPE (decl
) = integer_type_node
;
5876 DECL_ARG_TYPE (decl
) = integer_type_node
;
5877 layout_decl (decl
, 0);
5880 /* If no declaration found, default to int. */
5883 decl
= build_decl (PARM_DECL
, TREE_VALUE (parm
), integer_type_node
);
5884 DECL_ARG_TYPE (decl
) = TREE_TYPE (decl
);
5885 DECL_SOURCE_LOCATION (decl
) = DECL_SOURCE_LOCATION (fndecl
);
5889 pedwarn ("%Jtype of '%D' defaults to 'int'", decl
, decl
);
5890 else if (extra_warnings
)
5891 warning ("%Jtype of '%D' defaults to 'int'", decl
, decl
);
5894 TREE_PURPOSE (parm
) = decl
;
5895 DECL_WEAK (decl
) = 1;
5898 /* Now examine the parms chain for incomplete declarations
5899 and declarations with no corresponding names. */
5901 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
5904 if (TREE_CODE (parm
) != PARM_DECL
)
5907 if (!COMPLETE_TYPE_P (TREE_TYPE (parm
)))
5909 error ("%Jparameter '%D' has incomplete type", parm
, parm
);
5910 TREE_TYPE (parm
) = error_mark_node
;
5913 if (! DECL_WEAK (parm
))
5915 error ("%Jdeclaration for parameter '%D' but no such parameter",
5918 /* Pretend the parameter was not missing.
5919 This gets us to a standard state and minimizes
5920 further error messages. */
5921 parmids
= chainon (parmids
, tree_cons (parm
, 0, 0));
5925 /* Chain the declarations together in the order of the list of
5926 names. Store that chain in the function decl, replacing the
5927 list of names. Update the current scope to match. */
5928 DECL_ARGUMENTS (fndecl
) = 0;
5930 for (parm
= parmids
; parm
; parm
= TREE_CHAIN (parm
))
5931 if (TREE_PURPOSE (parm
))
5933 if (parm
&& TREE_PURPOSE (parm
))
5935 last
= TREE_PURPOSE (parm
);
5936 DECL_ARGUMENTS (fndecl
) = last
;
5937 DECL_WEAK (last
) = 0;
5939 for (parm
= TREE_CHAIN (parm
); parm
; parm
= TREE_CHAIN (parm
))
5940 if (TREE_PURPOSE (parm
))
5942 TREE_CHAIN (last
) = TREE_PURPOSE (parm
);
5943 last
= TREE_PURPOSE (parm
);
5944 DECL_WEAK (last
) = 0;
5946 TREE_CHAIN (last
) = 0;
5949 /* If there was a previous prototype,
5950 set the DECL_ARG_TYPE of each argument according to
5951 the type previously specified, and report any mismatches. */
5953 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
5956 for (parm
= DECL_ARGUMENTS (fndecl
),
5957 type
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
5958 parm
|| (type
&& (TYPE_MAIN_VARIANT (TREE_VALUE (type
))
5959 != void_type_node
));
5960 parm
= TREE_CHAIN (parm
), type
= TREE_CHAIN (type
))
5962 if (parm
== 0 || type
== 0
5963 || TYPE_MAIN_VARIANT (TREE_VALUE (type
)) == void_type_node
)
5965 error ("number of arguments doesn't match prototype");
5966 error ("%Hprototype declaration",
5967 ¤t_function_prototype_locus
);
5970 /* Type for passing arg must be consistent with that
5971 declared for the arg. ISO C says we take the unqualified
5972 type for parameters declared with qualified type. */
5973 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm
)),
5974 TYPE_MAIN_VARIANT (TREE_VALUE (type
)),
5977 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm
))
5978 == TYPE_MAIN_VARIANT (TREE_VALUE (type
)))
5980 /* Adjust argument to match prototype. E.g. a previous
5981 `int foo(float);' prototype causes
5982 `int foo(x) float x; {...}' to be treated like
5983 `int foo(float x) {...}'. This is particularly
5984 useful for argument types like uid_t. */
5985 DECL_ARG_TYPE (parm
) = TREE_TYPE (parm
);
5987 if (targetm
.calls
.promote_prototypes (TREE_TYPE (current_function_decl
))
5988 && INTEGRAL_TYPE_P (TREE_TYPE (parm
))
5989 && TYPE_PRECISION (TREE_TYPE (parm
))
5990 < TYPE_PRECISION (integer_type_node
))
5991 DECL_ARG_TYPE (parm
) = integer_type_node
;
5995 pedwarn ("promoted argument '%D' "
5996 "doesn't match prototype", parm
);
5997 pedwarn ("%Hprototype declaration",
5998 ¤t_function_prototype_locus
);
6003 error ("argument '%D' doesn't match prototype", parm
);
6004 error ("%Hprototype declaration",
6005 ¤t_function_prototype_locus
);
6009 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = 0;
6012 /* Otherwise, create a prototype that would match. */
6016 tree actual
= 0, last
= 0, type
;
6018 for (parm
= DECL_ARGUMENTS (fndecl
); parm
; parm
= TREE_CHAIN (parm
))
6020 type
= tree_cons (NULL_TREE
, DECL_ARG_TYPE (parm
), NULL_TREE
);
6022 TREE_CHAIN (last
) = type
;
6027 type
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
6029 TREE_CHAIN (last
) = type
;
6033 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6034 of the type of this function, but we need to avoid having this
6035 affect the types of other similarly-typed functions, so we must
6036 first force the generation of an identical (but separate) type
6037 node for the relevant function type. The new node we create
6038 will be a variant of the main variant of the original function
6041 TREE_TYPE (fndecl
) = build_type_copy (TREE_TYPE (fndecl
));
6043 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl
)) = actual
;
6047 /* Store the parameter declarations into the current function declaration.
6048 This is called after parsing the parameter declarations, before
6049 digesting the body of the function.
6051 For an old-style definition, construct a prototype out of the old-style
6052 parameter declarations and inject it into the function's type. */
6055 store_parm_decls (void)
6057 tree fndecl
= current_function_decl
;
6059 /* The function containing FNDECL, if any. */
6060 tree context
= decl_function_context (fndecl
);
6062 /* The argument information block for FNDECL. */
6063 tree arg_info
= DECL_ARGUMENTS (fndecl
);
6065 /* True if this definition is written with a prototype. Note:
6066 despite C99 6.7.5.3p14, we can *not* treat an empty argument
6067 list in a function definition as equivalent to (void) -- an
6068 empty argument list specifies the function has no parameters,
6069 but only (void) sets up a prototype for future calls. */
6070 bool proto
= ARG_INFO_TYPES (arg_info
) != 0;
6073 store_parm_decls_newstyle (fndecl
, arg_info
);
6075 store_parm_decls_oldstyle (fndecl
, arg_info
);
6077 /* The next call to push_scope will be a function body. */
6079 next_is_function_body
= true;
6081 /* Write a record describing this function definition to the prototypes
6082 file (if requested). */
6084 gen_aux_info_record (fndecl
, 1, 0, proto
);
6086 /* Initialize the RTL code for the function. */
6087 allocate_struct_function (fndecl
);
6089 /* Begin the statement tree for this function. */
6090 begin_stmt_tree (&DECL_SAVED_TREE (fndecl
));
6092 /* If this is a nested function, save away the sizes of any
6093 variable-size types so that we can expand them when generating
6099 DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
6100 = nreverse (get_pending_sizes ());
6101 for (t
= DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
;
6104 SAVE_EXPR_CONTEXT (TREE_VALUE (t
)) = context
;
6107 /* This function is being processed in whole-function mode. */
6108 cfun
->x_whole_function_mode_p
= 1;
6110 /* Even though we're inside a function body, we still don't want to
6111 call expand_expr to calculate the size of a variable-sized array.
6112 We haven't necessarily assigned RTL to all variables yet, so it's
6113 not safe to try to expand expressions involving them. */
6114 immediate_size_expand
= 0;
6115 cfun
->x_dont_save_pending_sizes_p
= 1;
6118 /* Finish up a function declaration and compile that function
6119 all the way to assembler language output. The free the storage
6120 for the function definition.
6122 This is called after parsing the body of the function definition. */
6125 finish_function (void)
6127 tree fndecl
= current_function_decl
;
6129 /* When a function declaration is totally empty, e.g.
6131 (the argument list is irrelevant) the compstmt rule will not
6132 bother calling push_scope/pop_scope, which means we get here with
6133 the scope stack out of sync. Detect this situation by noticing
6134 that current_scope is still as store_parm_decls left it, and do
6135 a dummy push/pop to get back to consistency.
6136 Note that the call to push_scope does not actually push another
6137 scope - see there for details. */
6139 if (current_scope
->parm_flag
&& next_is_function_body
)
6145 if (TREE_CODE (fndecl
) == FUNCTION_DECL
6146 && targetm
.calls
.promote_prototypes (TREE_TYPE (fndecl
)))
6148 tree args
= DECL_ARGUMENTS (fndecl
);
6149 for (; args
; args
= TREE_CHAIN (args
))
6151 tree type
= TREE_TYPE (args
);
6152 if (INTEGRAL_TYPE_P (type
)
6153 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
6154 DECL_ARG_TYPE (args
) = integer_type_node
;
6158 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
6159 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
6161 /* Must mark the RESULT_DECL as being in this function. */
6163 if (DECL_RESULT (fndecl
) && DECL_RESULT (fndecl
) != error_mark_node
)
6164 DECL_CONTEXT (DECL_RESULT (fndecl
)) = fndecl
;
6166 if (MAIN_NAME_P (DECL_NAME (fndecl
)) && flag_hosted
)
6168 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl
)))
6169 != integer_type_node
)
6171 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
6172 If warn_main is -1 (-Wno-main) we don't want to be warned. */
6174 pedwarn ("%Jreturn type of '%D' is not `int'", fndecl
, fndecl
);
6178 #ifdef DEFAULT_MAIN_RETURN
6179 /* Make it so that `main' always returns success by default. */
6180 DEFAULT_MAIN_RETURN
;
6183 c_expand_return (integer_zero_node
);
6188 finish_fname_decls ();
6190 /* Tie off the statement tree for this function. */
6191 finish_stmt_tree (&DECL_SAVED_TREE (fndecl
));
6193 /* Complain if there's just no return statement. */
6194 if (warn_return_type
6195 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl
))) != VOID_TYPE
6196 && !current_function_returns_value
&& !current_function_returns_null
6197 /* Don't complain if we abort. */
6198 && !current_function_returns_abnormally
6199 /* Don't warn for main(). */
6200 && !MAIN_NAME_P (DECL_NAME (fndecl
))
6201 /* Or if they didn't actually specify a return type. */
6202 && !C_FUNCTION_IMPLICIT_INT (fndecl
)
6203 /* Normally, with -Wreturn-type, flow will complain. Unless we're an
6204 inline function, as we might never be compiled separately. */
6205 && DECL_INLINE (fndecl
))
6206 warning ("no return statement in function returning non-void");
6208 /* With just -Wextra, complain only if function returns both with
6209 and without a value. */
6211 && current_function_returns_value
6212 && current_function_returns_null
)
6213 warning ("this function may return with or without a value");
6215 /* We're leaving the context of this function, so zap cfun.
6216 It's still in DECL_STRUCT_FUNCTION , and we'll restore it in
6217 tree_rest_of_compilation. */
6220 /* ??? Objc emits functions after finalizing the compilation unit.
6221 This should be cleaned up later and this conditional removed. */
6222 if (!cgraph_global_info_ready
)
6223 cgraph_finalize_function (fndecl
, false);
6225 c_expand_body (fndecl
);
6226 current_function_decl
= NULL
;
6229 /* Generate the RTL for the body of FNDECL. If NESTED_P is nonzero,
6230 then we are already in the process of generating RTL for another
6234 c_expand_body_1 (tree fndecl
, int nested_p
)
6238 /* Make sure that we will evaluate variable-sized types involved
6239 in our function's type. */
6240 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl
)->pending_sizes
);
6242 /* Squirrel away our current state. */
6243 push_function_context ();
6246 tree_rest_of_compilation (fndecl
, nested_p
);
6249 /* Return to the enclosing function. */
6250 pop_function_context ();
6252 if (DECL_STATIC_CONSTRUCTOR (fndecl
))
6254 if (targetm
.have_ctors_dtors
)
6255 targetm
.asm_out
.constructor (XEXP (DECL_RTL (fndecl
), 0),
6256 DEFAULT_INIT_PRIORITY
);
6258 static_ctors
= tree_cons (NULL_TREE
, fndecl
, static_ctors
);
6261 if (DECL_STATIC_DESTRUCTOR (fndecl
))
6263 if (targetm
.have_ctors_dtors
)
6264 targetm
.asm_out
.destructor (XEXP (DECL_RTL (fndecl
), 0),
6265 DEFAULT_INIT_PRIORITY
);
6267 static_dtors
= tree_cons (NULL_TREE
, fndecl
, static_dtors
);
6271 /* Like c_expand_body_1 but only for unnested functions. */
6274 c_expand_body (tree fndecl
)
6277 if (DECL_INITIAL (fndecl
) && DECL_INITIAL (fndecl
) != error_mark_node
)
6278 c_expand_body_1 (fndecl
, 0);
6281 /* Check the declarations given in a for-loop for satisfying the C99
6284 check_for_loop_decls (void)
6286 struct c_binding
*b
;
6290 /* If we get here, declarations have been used in a for loop without
6291 the C99 for loop scope. This doesn't make much sense, so don't
6293 error ("'for' loop initial declaration used outside C99 mode");
6296 /* C99 subclause 6.8.5 paragraph 3:
6298 [#3] The declaration part of a for statement shall only
6299 declare identifiers for objects having storage class auto or
6302 It isn't clear whether, in this sentence, "identifiers" binds to
6303 "shall only declare" or to "objects" - that is, whether all identifiers
6304 declared must be identifiers for objects, or whether the restriction
6305 only applies to those that are. (A question on this in comp.std.c
6306 in November 2000 received no answer.) We implement the strictest
6307 interpretation, to avoid creating an extension which later causes
6310 for (b
= current_scope
->bindings
; b
; b
= b
->prev
)
6313 tree decl
= b
->decl
;
6318 switch (TREE_CODE (decl
))
6321 if (TREE_STATIC (decl
))
6322 error ("%Jdeclaration of static variable '%D' in 'for' loop "
6323 "initial declaration", decl
, decl
);
6324 else if (DECL_EXTERNAL (decl
))
6325 error ("%Jdeclaration of 'extern' variable '%D' in 'for' loop "
6326 "initial declaration", decl
, decl
);
6330 error ("'struct %E' declared in 'for' loop initial declaration", id
);
6333 error ("'union %E' declared in 'for' loop initial declaration", id
);
6336 error ("'enum %E' declared in 'for' loop initial declaration", id
);
6339 error ("%Jdeclaration of non-variable '%D' in 'for' loop "
6340 "initial declaration", decl
, decl
);
6345 /* Save and reinitialize the variables
6346 used during compilation of a C function. */
6349 c_push_function_context (struct function
*f
)
6351 struct language_function
*p
;
6352 p
= ggc_alloc (sizeof (struct language_function
));
6355 p
->base
.x_stmt_tree
= c_stmt_tree
;
6356 p
->base
.x_scope_stmt_stack
= c_scope_stmt_stack
;
6357 p
->x_in_iteration_stmt
= c_in_iteration_stmt
;
6358 p
->x_in_case_stmt
= c_in_case_stmt
;
6359 p
->returns_value
= current_function_returns_value
;
6360 p
->returns_null
= current_function_returns_null
;
6361 p
->returns_abnormally
= current_function_returns_abnormally
;
6362 p
->warn_about_return_type
= warn_about_return_type
;
6363 p
->extern_inline
= current_extern_inline
;
6366 /* Restore the variables used during compilation of a C function. */
6369 c_pop_function_context (struct function
*f
)
6371 struct language_function
*p
= f
->language
;
6373 if (DECL_STRUCT_FUNCTION (current_function_decl
) == 0
6374 && DECL_SAVED_TREE (current_function_decl
) == NULL_TREE
)
6376 /* Stop pointing to the local nodes about to be freed. */
6377 /* But DECL_INITIAL must remain nonzero so we know this
6378 was an actual function definition. */
6379 DECL_INITIAL (current_function_decl
) = error_mark_node
;
6380 DECL_ARGUMENTS (current_function_decl
) = 0;
6383 c_stmt_tree
= p
->base
.x_stmt_tree
;
6384 c_scope_stmt_stack
= p
->base
.x_scope_stmt_stack
;
6385 c_in_iteration_stmt
= p
->x_in_iteration_stmt
;
6386 c_in_case_stmt
= p
->x_in_case_stmt
;
6387 current_function_returns_value
= p
->returns_value
;
6388 current_function_returns_null
= p
->returns_null
;
6389 current_function_returns_abnormally
= p
->returns_abnormally
;
6390 warn_about_return_type
= p
->warn_about_return_type
;
6391 current_extern_inline
= p
->extern_inline
;
6396 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
6399 c_dup_lang_specific_decl (tree decl
)
6401 struct lang_decl
*ld
;
6403 if (!DECL_LANG_SPECIFIC (decl
))
6406 ld
= ggc_alloc (sizeof (struct lang_decl
));
6407 memcpy (ld
, DECL_LANG_SPECIFIC (decl
), sizeof (struct lang_decl
));
6408 DECL_LANG_SPECIFIC (decl
) = ld
;
6411 /* The functions below are required for functionality of doing
6412 function at once processing in the C front end. Currently these
6413 functions are not called from anywhere in the C front end, but as
6414 these changes continue, that will change. */
6416 /* Returns nonzero if the current statement is a full expression,
6417 i.e. temporaries created during that statement should be destroyed
6418 at the end of the statement. */
6421 stmts_are_full_exprs_p (void)
6426 /* Returns the stmt_tree (if any) to which statements are currently
6427 being added. If there is no active statement-tree, NULL is
6431 current_stmt_tree (void)
6433 return &c_stmt_tree
;
6436 /* Returns the stack of SCOPE_STMTs for the current function. */
6439 current_scope_stmt_stack (void)
6441 return &c_scope_stmt_stack
;
6444 /* Nonzero if TYPE is an anonymous union or struct type. Always 0 in
6448 anon_aggr_type_p (tree node ATTRIBUTE_UNUSED
)
6453 /* Dummy function in place of callback used by C++. */
6456 extract_interface_info (void)
6460 /* Return a new COMPOUND_STMT, after adding it to the current
6464 c_begin_compound_stmt (void)
6468 /* Create the COMPOUND_STMT. */
6469 stmt
= add_stmt (build_stmt (COMPOUND_STMT
, NULL_TREE
));
6474 /* Expand T (a DECL_STMT) if it declares an entity not handled by the
6478 c_expand_decl_stmt (tree t
)
6480 tree decl
= DECL_STMT_DECL (t
);
6482 /* Expand nested functions. */
6483 if (TREE_CODE (decl
) == FUNCTION_DECL
6484 && DECL_CONTEXT (decl
) == current_function_decl
6485 && DECL_SAVED_TREE (decl
))
6486 c_expand_body_1 (decl
, 1);
6489 /* Return the global value of T as a symbol. */
6492 identifier_global_value (tree t
)
6494 struct c_binding
*b
;
6496 for (b
= I_SYMBOL_BINDING (t
); b
; b
= b
->shadowed
)
6497 if (b
->contour
== file_scope
|| b
->contour
== external_scope
)
6503 /* Record a builtin type for C. If NAME is non-NULL, it is the name used;
6504 otherwise the name is found in ridpointers from RID_INDEX. */
6507 record_builtin_type (enum rid rid_index
, const char *name
, tree type
)
6511 id
= ridpointers
[(int) rid_index
];
6513 id
= get_identifier (name
);
6514 pushdecl (build_decl (TYPE_DECL
, id
, type
));
6517 /* Build the void_list_node (void_type_node having been created). */
6519 build_void_list_node (void)
6521 tree t
= build_tree_list (NULL_TREE
, void_type_node
);
6525 /* Return something to represent absolute declarators containing a *.
6526 TARGET is the absolute declarator that the * contains.
6527 TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile
6528 to apply to the pointer type, represented as identifiers, possible mixed
6531 We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST,
6532 if attributes are present) and whose type is the modifier list. */
6535 make_pointer_declarator (tree type_quals_attrs
, tree target
)
6538 tree itarget
= target
;
6539 split_specs_attrs (type_quals_attrs
, &quals
, &attrs
);
6540 if (attrs
!= NULL_TREE
)
6541 itarget
= tree_cons (attrs
, target
, NULL_TREE
);
6542 return build1 (INDIRECT_REF
, quals
, itarget
);
6545 /* A wrapper around lhd_set_decl_assembler_name that gives static
6546 variables their C names if they are at file scope and only one
6547 translation unit is being compiled, for backwards compatibility
6548 with certain bizarre assembler hacks (like crtstuff.c). */
6551 c_static_assembler_name (tree decl
)
6553 if (num_in_fnames
== 1
6554 && !TREE_PUBLIC (decl
) && DECL_CONTEXT (decl
)
6555 && TREE_CODE (DECL_CONTEXT (decl
)) == TRANSLATION_UNIT_DECL
)
6556 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
6558 lhd_set_decl_assembler_name (decl
);
6561 /* Perform final processing on file-scope data. */
6563 c_write_global_declarations_1 (tree globals
)
6565 size_t len
= list_length (globals
);
6566 tree
*vec
= xmalloc (sizeof (tree
) * len
);
6570 /* Process the decls in the order they were written. */
6571 for (i
= 0, decl
= globals
; i
< len
; i
++, decl
= TREE_CHAIN (decl
))
6574 wrapup_global_declarations (vec
, len
);
6575 check_global_declarations (vec
, len
);
6581 c_write_global_declarations (void)
6585 /* We don't want to do this if generating a PCH. */
6589 /* Process all file scopes in this compilation. */
6590 for (t
= current_file_decl
; t
; t
= TREE_CHAIN (t
))
6591 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t
)));
6593 /* Now do the same for the externals scope. */
6596 c_write_global_declarations_1 (BLOCK_VARS (t
));
6599 #include "gt-c-decl.h"