00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "config.h"
00034 #include "system.h"
00035 #include "coretypes.h"
00036 #include "input.h"
00037 #include "tm.h"
00038 #include "intl.h"
00039 #include "tree.h"
00040 #include "tree-inline.h"
00041 #include "rtl.h"
00042 #include "flags.h"
00043 #include "function.h"
00044 #include "output.h"
00045 #include "expr.h"
00046 #include "c-tree.h"
00047 #include "toplev.h"
00048 #include "ggc.h"
00049 #include "tm_p.h"
00050 #include "cpplib.h"
00051 #include "target.h"
00052 #include "debug.h"
00053 #include "opts.h"
00054 #include "timevar.h"
00055 #include "c-common.h"
00056 #include "c-pragma.h"
00057 #include "langhooks.h"
00058 #include "tree-mudflap.h"
00059 #include "tree-gimple.h"
00060 #include "diagnostic.h"
00061 #include "tree-dump.h"
00062 #include "cgraph.h"
00063 #include "hashtab.h"
00064 #include "libfuncs.h"
00065 #include "except.h"
00066 #include "langhooks-def.h"
00067
00068
00069 enum decl_context
00070 { NORMAL,
00071 FUNCDEF,
00072 PARM,
00073 FIELD,
00074 TYPENAME};
00075
00076
00077
00078
00079 tree pending_invalid_xref;
00080
00081
00082 location_t pending_invalid_xref_location;
00083
00084
00085 bool c_eh_initialized_p;
00086
00087
00088
00089
00090
00091
00092
00093 static tree enum_next_value;
00094
00095
00096
00097 static int enum_overflow;
00098
00099
00100
00101
00102
00103 static location_t current_function_prototype_locus;
00104
00105
00106
00107 static bool current_function_prototype_built_in;
00108
00109
00110
00111 static tree current_function_prototype_arg_types;
00112
00113
00114
00115
00116 static struct c_arg_info *current_function_arg_info;
00117
00118
00119
00120
00121 struct obstack parser_obstack;
00122
00123
00124
00125 static GTY(()) struct stmt_tree_s c_stmt_tree;
00126
00127
00128 tree c_break_label;
00129 tree c_cont_label;
00130
00131
00132
00133
00134
00135 static GTY(()) tree all_translation_units;
00136
00137
00138 static GTY(()) tree visible_builtins;
00139
00140
00141
00142
00143 int current_function_returns_value;
00144
00145
00146
00147
00148 int current_function_returns_null;
00149
00150
00151
00152
00153 int current_function_returns_abnormally;
00154
00155
00156
00157
00158 static int warn_about_return_type;
00159
00160
00161
00162 static int current_extern_inline;
00163
00164
00165
00166
00167 static bool undef_nested_function;
00168
00169
00170
00171 bool c_override_global_bindings_to_false;
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 struct c_binding GTY((chain_next ("%h.prev")))
00208 {
00209 tree decl;
00210 tree type;
00211 tree id;
00212 struct c_binding *prev;
00213 struct c_binding *shadowed;
00214 unsigned int depth : 28;
00215 BOOL_BITFIELD invisible : 1;
00216 BOOL_BITFIELD nested : 1;
00217 BOOL_BITFIELD inner_comp : 1;
00218
00219 };
00220 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
00221 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
00222 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 )
00223 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 )
00224
00225 #define I_SYMBOL_BINDING(node) \
00226 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding)
00227 #define I_SYMBOL_DECL(node) \
00228 (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
00229
00230 #define I_TAG_BINDING(node) \
00231 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->tag_binding)
00232 #define I_TAG_DECL(node) \
00233 (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
00234
00235 #define I_LABEL_BINDING(node) \
00236 (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->label_binding)
00237 #define I_LABEL_DECL(node) \
00238 (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
00239
00240
00241
00242
00243
00244 struct lang_identifier GTY(())
00245 {
00246 struct c_common_identifier common_id;
00247 struct c_binding *symbol_binding;
00248 struct c_binding *tag_binding;
00249 struct c_binding *label_binding;
00250 };
00251
00252
00253 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
00254 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
00255
00256
00257
00258 union lang_tree_node
00259 GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
00260 chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : (union lang_tree_node *) TREE_CHAIN (&%h.generic)")))
00261 {
00262 union tree_node GTY ((tag ("0"),
00263 desc ("tree_node_structure (&%h)")))
00264 generic;
00265 struct lang_identifier GTY ((tag ("1"))) identifier;
00266 };
00267
00268 /* Each c_scope structure describes the complete contents of one
00269 scope. Four scopes are distinguished specially: the innermost or
00270 current scope, the innermost function scope, the file scope (always
00271 the second to outermost) and the outermost or external scope.
00272
00273 Most declarations are recorded in the current scope.
00274
00275 All normal label declarations are recorded in the innermost
00276 function scope, as are bindings of undeclared identifiers to
00277 error_mark_node. (GCC permits nested functions as an extension,
00278 hence the 'innermost' qualifier.) Explicitly declared labels
00279 (using the __label__ extension) appear in the current scope.
00280
00281 Being in the file scope (current_scope == file_scope) causes
00282 special behavior in several places below. Also, under some
00283 conditions the Objective-C front end records declarations in the
00284 file scope even though that isn't the current scope.
00285
00286 All declarations with external linkage are recorded in the external
00287 scope, even if they aren't visible there; this models the fact that
00288 such declarations are visible to the entire program, and (with a
00289 bit of cleverness, see pushdecl) allows diagnosis of some violations
00290 of C99 6.2.2p7 and 6.2.7p2:
00291
00292 If, within the same translation unit, the same identifier appears
00293 with both internal and external linkage, the behavior is
00294 undefined.
00295
00296 All declarations that refer to the same object or function shall
00297 have compatible type; otherwise, the behavior is undefined.
00298
00299 Initially only the built-in declarations, which describe compiler
00300 intrinsic functions plus a subset of the standard library, are in
00301 this scope.
00302
00303 The order of the blocks list matters, and it is frequently appended
00304 to. To avoid having to walk all the way to the end of the list on
00305 each insertion, or reverse the list later, we maintain a pointer to
00306 the last list entry. (FIXME: It should be feasible to use a reversed
00307 list here.)
00308
00309 The bindings list is strictly in reverse order of declarations;
00310 pop_scope relies on this. */
00311
00312
00313 struct c_scope GTY((chain_next ("%h.outer")))
00314 {
00315 /* The scope containing this one. */
00316 struct c_scope *outer;
00317
00318 /* The next outermost function scope. */
00319 struct c_scope *outer_function;
00320
00321 /* All bindings in this scope. */
00322 struct c_binding *bindings;
00323
00324 /* For each scope (except the global one), a chain of BLOCK nodes
00325 for all the scopes that were entered and exited one level down. */
00326 tree blocks;
00327 tree blocks_last;
00328
00329 /* The depth of this scope. Used to keep the ->shadowed chain of
00330 bindings sorted innermost to outermost. */
00331 unsigned int depth : 28;
00332
00333 /* True if we are currently filling this scope with parameter
00334 declarations. */
00335 BOOL_BITFIELD parm_flag : 1;
00336
00337 /* True if we already complained about forward parameter decls
00338 in this scope. This prevents double warnings on
00339 foo (int a; int b; ...) */
00340 BOOL_BITFIELD warned_forward_parm_decls : 1;
00341
00342 /* True if this is the outermost block scope of a function body.
00343 This scope contains the parameters, the local variables declared
00344 in the outermost block, and all the labels (except those in
00345 nested functions, or declared at block scope with __label__). */
00346 BOOL_BITFIELD function_body : 1;
00347
00348 /* True means make a BLOCK for this scope no matter what. */
00349 BOOL_BITFIELD keep : 1;
00350 };
00351
00352 /* The scope currently in effect. */
00353
00354 static GTY(()) struct c_scope *current_scope;
00355
00356 /* The innermost function scope. Ordinary (not explicitly declared)
00357 labels, bindings to error_mark_node, and the lazily-created
00358 bindings of __func__ and its friends get this scope. */
00359
00360 static GTY(()) struct c_scope *current_function_scope;
00361
00362 /* The C file scope. This is reset for each input translation unit. */
00363
00364 static GTY(()) struct c_scope *file_scope;
00365
00366 /* The outermost scope. This is used for all declarations with
00367 external linkage, and only these, hence the name. */
00368
00369 static GTY(()) struct c_scope *external_scope;
00370
00371 /* A chain of c_scope structures awaiting reuse. */
00372
00373 static GTY((deletable)) struct c_scope *scope_freelist;
00374
00375 /* A chain of c_binding structures awaiting reuse. */
00376
00377 static GTY((deletable)) struct c_binding *binding_freelist;
00378
00379 /* Append VAR to LIST in scope SCOPE. */
00380 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
00381 struct c_scope *s_ = (scope); \
00382 tree d_ = (decl); \
00383 if (s_->list##_last) \
00384 TREE_CHAIN (s_->list##_last) = d_; \
00385 else \
00386 s_->list = d_; \
00387 s_->list##_last = d_; \
00388 } while (0)
00389
00390 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
00391 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
00392 struct c_scope *t_ = (tscope); \
00393 struct c_scope *f_ = (fscope); \
00394 if (t_->to##_last) \
00395 TREE_CHAIN (t_->to##_last) = f_->from; \
00396 else \
00397 t_->to = f_->from; \
00398 t_->to##_last = f_->from##_last; \
00399 } while (0)
00400
00401 /* True means unconditionally make a BLOCK for the next scope pushed. */
00402
00403 static bool keep_next_level_flag;
00404
00405 /* True means the next call to push_scope will be the outermost scope
00406 of a function body, so do not push a new scope, merely cease
00407 expecting parameter decls. */
00408
00409 static bool next_is_function_body;
00410
00411 /* Functions called automatically at the beginning and end of execution. */
00412
00413 static GTY(()) tree static_ctors;
00414 static GTY(()) tree static_dtors;
00415
00416 /* Forward declarations. */
00417 static tree lookup_name_in_scope (tree, struct c_scope *);
00418 static tree c_make_fname_decl (tree, int);
00419 static tree grokdeclarator (const struct c_declarator *,
00420 struct c_declspecs *,
00421 enum decl_context, bool, tree *);
00422 static tree grokparms (struct c_arg_info *, bool);
00423 static void layout_array_type (tree);
00424
00425 /* States indicating how grokdeclarator() should handle declspecs marked
00426 with __attribute__((deprecated)). An object declared as
00427 __attribute__((deprecated)) suppresses warnings of uses of other
00428 deprecated items. */
00429
00430 enum deprecated_states {
00431 DEPRECATED_NORMAL,
00432 DEPRECATED_SUPPRESS
00433 };
00434
00435 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00436
00437 void
00438 c_print_identifier (FILE *file, tree node, int indent)
00439 {
00440 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
00441 print_node (file, "tag", I_TAG_DECL (node), indent + 4);
00442 print_node (file, "label", I_LABEL_DECL (node), indent + 4);
00443 if (C_IS_RESERVED_WORD (node))
00444 {
00445 tree rid = ridpointers[C_RID_CODE (node)];
00446 indent_to (file, indent + 4);
00447 fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
00448 (void *) rid, IDENTIFIER_POINTER (rid));
00449 }
00450 }
00451
00452
00453
00454
00455 static void
00456 bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested)
00457 {
00458 struct c_binding *b, **here;
00459
00460 if (binding_freelist)
00461 {
00462 b = binding_freelist;
00463 binding_freelist = b->prev;
00464 }
00465 else
00466 b = GGC_NEW (struct c_binding);
00467
00468 b->shadowed = 0;
00469 b->decl = decl;
00470 b->id = name;
00471 b->depth = scope->depth;
00472 b->invisible = invisible;
00473 b->nested = nested;
00474 b->inner_comp = 0;
00475
00476 b->type = 0;
00477
00478 b->prev = scope->bindings;
00479 scope->bindings = b;
00480
00481 if (!name)
00482 return;
00483
00484 switch (TREE_CODE (decl))
00485 {
00486 case LABEL_DECL: here = &I_LABEL_BINDING (name); break;
00487 case ENUMERAL_TYPE:
00488 case UNION_TYPE:
00489 case RECORD_TYPE: here = &I_TAG_BINDING (name); break;
00490 case VAR_DECL:
00491 case FUNCTION_DECL:
00492 case TYPE_DECL:
00493 case CONST_DECL:
00494 case PARM_DECL:
00495 case ERROR_MARK: here = &I_SYMBOL_BINDING (name); break;
00496
00497 default:
00498 gcc_unreachable ();
00499 }
00500
00501
00502
00503
00504 while (*here && (*here)->depth > scope->depth)
00505 here = &(*here)->shadowed;
00506
00507 b->shadowed = *here;
00508 *here = b;
00509 }
00510
00511
00512
00513
00514
00515 static struct c_binding *
00516 free_binding_and_advance (struct c_binding *b)
00517 {
00518 struct c_binding *prev = b->prev;
00519
00520 memset (b, 0, sizeof (struct c_binding));
00521 b->prev = binding_freelist;
00522 binding_freelist = b;
00523
00524 return prev;
00525 }
00526
00527
00528
00529
00530
00531 void
00532 c_finish_incomplete_decl (tree decl)
00533 {
00534 if (TREE_CODE (decl) == VAR_DECL)
00535 {
00536 tree type = TREE_TYPE (decl);
00537 if (type != error_mark_node
00538 && TREE_CODE (type) == ARRAY_TYPE
00539 && !DECL_EXTERNAL (decl)
00540 && TYPE_DOMAIN (type) == 0)
00541 {
00542 warning ("%Jarray %qD assumed to have one element", decl, decl);
00543
00544 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
00545
00546 layout_decl (decl, 0);
00547 }
00548 }
00549 }
00550
00551
00552
00553 void *
00554 objc_get_current_scope (void)
00555 {
00556 return current_scope;
00557 }
00558
00559
00560
00561
00562 void
00563 objc_mark_locals_volatile (void *enclosing_blk)
00564 {
00565 struct c_scope *scope;
00566 struct c_binding *b;
00567
00568 for (scope = current_scope;
00569 scope && scope != enclosing_blk;
00570 scope = scope->outer)
00571 {
00572 for (b = scope->bindings; b; b = b->prev)
00573 {
00574 if (TREE_CODE (b->decl) == VAR_DECL
00575 || TREE_CODE (b->decl) == PARM_DECL)
00576 {
00577 C_DECL_REGISTER (b->decl) = 0;
00578 DECL_REGISTER (b->decl) = 0;
00579 TREE_THIS_VOLATILE (b->decl) = 1;
00580 }
00581 }
00582
00583
00584 if (scope->function_body)
00585 break;
00586 }
00587 }
00588
00589
00590
00591 int
00592 global_bindings_p (void)
00593 {
00594 return current_scope == file_scope && !c_override_global_bindings_to_false;
00595 }
00596
00597 void
00598 keep_next_level (void)
00599 {
00600 keep_next_level_flag = true;
00601 }
00602
00603
00604
00605 void
00606 declare_parm_level (void)
00607 {
00608 current_scope->parm_flag = true;
00609 }
00610
00611 void
00612 push_scope (void)
00613 {
00614 if (next_is_function_body)
00615 {
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626 current_scope->parm_flag = false;
00627 current_scope->function_body = true;
00628 current_scope->keep = true;
00629 current_scope->outer_function = current_function_scope;
00630 current_function_scope = current_scope;
00631
00632 keep_next_level_flag = false;
00633 next_is_function_body = false;
00634 }
00635 else
00636 {
00637 struct c_scope *scope;
00638 if (scope_freelist)
00639 {
00640 scope = scope_freelist;
00641 scope_freelist = scope->outer;
00642 }
00643 else
00644 scope = GGC_CNEW (struct c_scope);
00645
00646 scope->keep = keep_next_level_flag;
00647 scope->outer = current_scope;
00648 scope->depth = current_scope ? (current_scope->depth + 1) : 0;
00649
00650
00651
00652 if (current_scope && scope->depth == 0)
00653 {
00654 scope->depth--;
00655 sorry ("GCC supports only %u nested scopes", scope->depth);
00656 }
00657
00658 current_scope = scope;
00659 keep_next_level_flag = false;
00660 }
00661 }
00662
00663
00664
00665 static void
00666 set_type_context (tree type, tree context)
00667 {
00668 for (type = TYPE_MAIN_VARIANT (type); type;
00669 type = TYPE_NEXT_VARIANT (type))
00670 TYPE_CONTEXT (type) = context;
00671 }
00672
00673
00674
00675
00676
00677
00678 tree
00679 pop_scope (void)
00680 {
00681 struct c_scope *scope = current_scope;
00682 tree block, context, p;
00683 struct c_binding *b;
00684
00685 bool functionbody = scope->function_body;
00686 bool keep = functionbody || scope->keep || scope->bindings;
00687
00688 c_end_vm_scope (scope->depth);
00689
00690
00691
00692 block = 0;
00693 if (keep)
00694 {
00695 block = make_node (BLOCK);
00696 BLOCK_SUBBLOCKS (block) = scope->blocks;
00697 TREE_USED (block) = 1;
00698
00699
00700 for (p = scope->blocks; p; p = TREE_CHAIN (p))
00701 BLOCK_SUPERCONTEXT (p) = block;
00702
00703 BLOCK_VARS (block) = 0;
00704 }
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719 if (scope->function_body)
00720 context = current_function_decl;
00721 else if (scope == file_scope)
00722 {
00723 tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
00724 TREE_CHAIN (file_decl) = all_translation_units;
00725 all_translation_units = file_decl;
00726 context = file_decl;
00727 }
00728 else
00729 context = block;
00730
00731
00732 for (b = scope->bindings; b; b = free_binding_and_advance (b))
00733 {
00734 p = b->decl;
00735 switch (TREE_CODE (p))
00736 {
00737 case LABEL_DECL:
00738
00739 if (TREE_USED (p) && !DECL_INITIAL (p))
00740 {
00741 error ("%Jlabel %qD used but not defined", p, p);
00742 DECL_INITIAL (p) = error_mark_node;
00743 }
00744 else if (!TREE_USED (p) && warn_unused_label)
00745 {
00746 if (DECL_INITIAL (p))
00747 warning ("%Jlabel %qD defined but not used", p, p);
00748 else
00749 warning ("%Jlabel %qD declared but not defined", p, p);
00750 }
00751
00752 TREE_CHAIN (p) = BLOCK_VARS (block);
00753 BLOCK_VARS (block) = p;
00754 gcc_assert (I_LABEL_BINDING (b->id) == b);
00755 I_LABEL_BINDING (b->id) = b->shadowed;
00756 break;
00757
00758 case ENUMERAL_TYPE:
00759 case UNION_TYPE:
00760 case RECORD_TYPE:
00761 set_type_context (p, context);
00762
00763
00764
00765 if (b->id)
00766 {
00767 gcc_assert (I_TAG_BINDING (b->id) == b);
00768 I_TAG_BINDING (b->id) = b->shadowed;
00769 }
00770 break;
00771
00772 case FUNCTION_DECL:
00773
00774
00775 if (!TREE_ASM_WRITTEN (p)
00776 && DECL_INITIAL (p) != 0
00777 && TREE_ADDRESSABLE (p)
00778 && DECL_ABSTRACT_ORIGIN (p) != 0
00779 && DECL_ABSTRACT_ORIGIN (p) != p)
00780 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
00781 if (!DECL_EXTERNAL (p)
00782 && DECL_INITIAL (p) == 0)
00783 {
00784 error ("%Jnested function %qD declared but never defined", p, p);
00785 undef_nested_function = true;
00786 }
00787 goto common_symbol;
00788
00789 case VAR_DECL:
00790
00791 if (warn_unused_variable
00792 && !TREE_USED (p)
00793 && !DECL_IN_SYSTEM_HEADER (p)
00794 && DECL_NAME (p)
00795 && !DECL_ARTIFICIAL (p)
00796 && scope != file_scope
00797 && scope != external_scope)
00798 warning ("%Junused variable %qD", p, p);
00799
00800 if (b->inner_comp)
00801 {
00802 error ("%Jtype of array %qD completed incompatibly with"
00803 " implicit initialization", p, p);
00804 }
00805
00806
00807 case TYPE_DECL:
00808 case CONST_DECL:
00809 common_symbol:
00810
00811
00812 if (!b->nested)
00813 {
00814 TREE_CHAIN (p) = BLOCK_VARS (block);
00815 BLOCK_VARS (block) = p;
00816 }
00817
00818
00819
00820
00821
00822 if (scope == file_scope && num_in_fnames > 1)
00823 {
00824 DECL_CONTEXT (p) = context;
00825 if (TREE_CODE (p) == TYPE_DECL)
00826 set_type_context (TREE_TYPE (p), context);
00827 }
00828
00829
00830
00831
00832
00833
00834
00835 case PARM_DECL:
00836 case ERROR_MARK:
00837
00838
00839 if (b->id)
00840 {
00841 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
00842 I_SYMBOL_BINDING (b->id) = b->shadowed;
00843 if (b->shadowed && b->shadowed->type)
00844 TREE_TYPE (b->shadowed->decl) = b->shadowed->type;
00845 }
00846 break;
00847
00848 default:
00849 gcc_unreachable ();
00850 }
00851 }
00852
00853
00854
00855 if ((scope->function_body || scope == file_scope) && context)
00856 {
00857 DECL_INITIAL (context) = block;
00858 BLOCK_SUPERCONTEXT (block) = context;
00859 }
00860 else if (scope->outer)
00861 {
00862 if (block)
00863 SCOPE_LIST_APPEND (scope->outer, blocks, block);
00864
00865
00866
00867 else if (scope->blocks)
00868 SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
00869 }
00870
00871
00872 current_scope = scope->outer;
00873 if (scope->function_body)
00874 current_function_scope = scope->outer_function;
00875
00876 memset (scope, 0, sizeof (struct c_scope));
00877 scope->outer = scope_freelist;
00878 scope_freelist = scope;
00879
00880 return block;
00881 }
00882
00883 void
00884 push_file_scope (void)
00885 {
00886 tree decl;
00887
00888 if (file_scope)
00889 return;
00890
00891 push_scope ();
00892 file_scope = current_scope;
00893
00894 start_fname_decls ();
00895
00896 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
00897 bind (DECL_NAME (decl), decl, file_scope,
00898 false, true);
00899 }
00900
00901 void
00902 pop_file_scope (void)
00903 {
00904
00905
00906 while (current_scope != file_scope)
00907 pop_scope ();
00908
00909
00910
00911
00912 finish_fname_decls ();
00913
00914
00915
00916 if (pch_file)
00917 {
00918 c_common_write_pch ();
00919 return;
00920 }
00921
00922
00923 pop_scope ();
00924 file_scope = 0;
00925
00926 maybe_apply_pending_pragma_weaks ();
00927 cgraph_finalize_compilation_unit ();
00928 }
00929
00930
00931
00932
00933
00934 void
00935 insert_block (tree block)
00936 {
00937 TREE_USED (block) = 1;
00938 SCOPE_LIST_APPEND (current_scope, blocks, block);
00939 }
00940
00941
00942
00943
00944
00945
00946
00947
00948 static void
00949 pushtag (tree name, tree type)
00950 {
00951
00952 if (name && !TYPE_NAME (type))
00953 TYPE_NAME (type) = name;
00954 bind (name, type, current_scope, false, false);
00955
00956
00957
00958
00959
00960
00961
00962
00963 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
00964
00965
00966
00967 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
00968 }
00969
00970
00971
00972
00973
00974 static tree
00975 match_builtin_function_types (tree newtype, tree oldtype)
00976 {
00977 tree newrettype, oldrettype;
00978 tree newargs, oldargs;
00979 tree trytype, tryargs;
00980
00981
00982 oldrettype = TREE_TYPE (oldtype);
00983 newrettype = TREE_TYPE (newtype);
00984
00985 if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype))
00986 return 0;
00987
00988 oldargs = TYPE_ARG_TYPES (oldtype);
00989 newargs = TYPE_ARG_TYPES (newtype);
00990 tryargs = newargs;
00991
00992 while (oldargs || newargs)
00993 {
00994 if (!oldargs
00995 || !newargs
00996 || !TREE_VALUE (oldargs)
00997 || !TREE_VALUE (newargs)
00998 || TYPE_MODE (TREE_VALUE (oldargs))
00999 != TYPE_MODE (TREE_VALUE (newargs)))
01000 return 0;
01001
01002 oldargs = TREE_CHAIN (oldargs);
01003 newargs = TREE_CHAIN (newargs);
01004 }
01005
01006 trytype = build_function_type (newrettype, tryargs);
01007 return build_type_attribute_variant (trytype, TYPE_ATTRIBUTES (oldtype));
01008 }
01009
01010
01011
01012
01013 static void
01014 diagnose_arglist_conflict (tree newdecl, tree olddecl,
01015 tree newtype, tree oldtype)
01016 {
01017 tree t;
01018
01019 if (TREE_CODE (olddecl) != FUNCTION_DECL
01020 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
01021 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0)
01022 ||
01023 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
01024 return;
01025
01026 t = TYPE_ARG_TYPES (oldtype);
01027 if (t == 0)
01028 t = TYPE_ARG_TYPES (newtype);
01029 for (; t; t = TREE_CHAIN (t))
01030 {
01031 tree type = TREE_VALUE (t);
01032
01033 if (TREE_CHAIN (t) == 0
01034 && TYPE_MAIN_VARIANT (type) != void_type_node)
01035 {
01036 inform ("a parameter list with an ellipsis can%'t match "
01037 "an empty parameter name list declaration");
01038 break;
01039 }
01040
01041 if (c_type_promotes_to (type) != type)
01042 {
01043 inform ("an argument type that has a default promotion can%'t match "
01044 "an empty parameter name list declaration");
01045 break;
01046 }
01047 }
01048 }
01049
01050
01051
01052
01053
01054 static bool
01055 validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
01056 {
01057 tree newargs, oldargs;
01058 int i;
01059
01060 #define END_OF_ARGLIST(t) ((t) == void_type_node)
01061
01062 oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
01063 newargs = TYPE_ARG_TYPES (newtype);
01064 i = 1;
01065
01066 for (;;)
01067 {
01068 tree oldargtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
01069 tree newargtype = TYPE_MAIN_VARIANT (TREE_VALUE (newargs));
01070
01071 if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
01072 break;
01073
01074
01075
01076 if (END_OF_ARGLIST (oldargtype))
01077 {
01078 error ("%Jprototype for %qD declares more arguments "
01079 "than previous old-style definition", newdecl, newdecl);
01080 return false;
01081 }
01082 else if (END_OF_ARGLIST (newargtype))
01083 {
01084 error ("%Jprototype for %qD declares fewer arguments "
01085 "than previous old-style definition", newdecl, newdecl);
01086 return false;
01087 }
01088
01089
01090
01091 else if (!comptypes (oldargtype, newargtype))
01092 {
01093 error ("%Jprototype for %qD declares argument %d"
01094 " with incompatible type",
01095 newdecl, newdecl, i);
01096 return false;
01097 }
01098
01099 oldargs = TREE_CHAIN (oldargs);
01100 newargs = TREE_CHAIN (newargs);
01101 i++;
01102 }
01103
01104
01105
01106 warning ("%Jprototype for %qD follows non-prototype definition",
01107 newdecl, newdecl);
01108 return true;
01109 #undef END_OF_ARGLIST
01110 }
01111
01112
01113
01114
01115 static void
01116 locate_old_decl (tree decl, void (*diag)(const char *, ...))
01117 {
01118 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
01119 ;
01120 else if (DECL_INITIAL (decl))
01121 diag (G_("%Jprevious definition of %qD was here"), decl, decl);
01122 else if (C_DECL_IMPLICIT (decl))
01123 diag (G_("%Jprevious implicit declaration of %qD was here"), decl, decl);
01124 else
01125 diag (G_("%Jprevious declaration of %qD was here"), decl, decl);
01126 }
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136 static bool
01137 diagnose_mismatched_decls (tree newdecl, tree olddecl,
01138 tree *newtypep, tree *oldtypep)
01139 {
01140 tree newtype, oldtype;
01141 bool pedwarned = false;
01142 bool warned = false;
01143 bool retval = true;
01144
01145
01146
01147 if (olddecl == error_mark_node || newdecl == error_mark_node)
01148 return false;
01149 *oldtypep = oldtype = TREE_TYPE (olddecl);
01150 *newtypep = newtype = TREE_TYPE (newdecl);
01151 if (oldtype == error_mark_node || newtype == error_mark_node)
01152 return false;
01153
01154
01155
01156 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
01157 {
01158 if (!(TREE_CODE (olddecl) == FUNCTION_DECL
01159 && DECL_BUILT_IN (olddecl)
01160 && !C_DECL_DECLARED_BUILTIN (olddecl)))
01161 {
01162 error ("%J%qD redeclared as different kind of symbol",
01163 newdecl, newdecl);
01164 locate_old_decl (olddecl, error);
01165 }
01166 else if (TREE_PUBLIC (newdecl))
01167 warning ("%Jbuilt-in function %qD declared as non-function",
01168 newdecl, newdecl);
01169 else if (warn_shadow)
01170 warning ("%Jdeclaration of %qD shadows a built-in function",
01171 newdecl, newdecl);
01172 return false;
01173 }
01174
01175
01176
01177 if (TREE_CODE (olddecl) == CONST_DECL)
01178 {
01179 error ("%Jredeclaration of enumerator %qD", newdecl, newdecl);
01180 locate_old_decl (olddecl, error);
01181 return false;
01182 }
01183
01184 if (!comptypes (oldtype, newtype))
01185 {
01186 if (TREE_CODE (olddecl) == FUNCTION_DECL
01187 && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
01188 {
01189
01190
01191 tree trytype = match_builtin_function_types (newtype, oldtype);
01192
01193 if (trytype && comptypes (newtype, trytype))
01194 *oldtypep = oldtype = trytype;
01195 else
01196 {
01197
01198
01199
01200 warning ("%Jconflicting types for built-in function %qD",
01201 newdecl, newdecl);
01202 return false;
01203 }
01204 }
01205 else if (TREE_CODE (olddecl) == FUNCTION_DECL
01206 && DECL_IS_BUILTIN (olddecl))
01207 {
01208
01209
01210
01211
01212
01213 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01214 return false;
01215 }
01216
01217
01218
01219 else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
01220 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
01221 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
01222 && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
01223 {
01224 pedwarn ("%Jconflicting types for %qD", newdecl, newdecl);
01225
01226 TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
01227 C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
01228 pedwarned = true;
01229 }
01230
01231
01232 else if (TREE_CODE (newdecl) == FUNCTION_DECL
01233 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
01234 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
01235 && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
01236 {
01237 pedwarn ("%Jconflicting types for %qD", newdecl, newdecl);
01238
01239 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
01240 pedwarned = true;
01241 }
01242 else
01243 {
01244 if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype))
01245 error ("%J conflicting type qualifiers for %qD", newdecl, newdecl);
01246 else
01247 error ("%Jconflicting types for %qD", newdecl, newdecl);
01248 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
01249 locate_old_decl (olddecl, error);
01250 return false;
01251 }
01252 }
01253
01254
01255
01256
01257 if (TREE_CODE (newdecl) == TYPE_DECL)
01258 {
01259 if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl))
01260 return true;
01261
01262 error ("%Jredefinition of typedef %qD", newdecl, newdecl);
01263 locate_old_decl (olddecl, error);
01264 return false;
01265 }
01266
01267
01268
01269
01270
01271
01272
01273 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
01274 {
01275
01276
01277
01278
01279 if (DECL_BUILT_IN (olddecl)
01280 && !C_DECL_DECLARED_BUILTIN (olddecl)
01281 && (!TREE_PUBLIC (newdecl)
01282 || (DECL_INITIAL (newdecl)
01283 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
01284 {
01285 if (warn_shadow)
01286 warning ("%Jdeclaration of %qD shadows a built-in function",
01287 newdecl, newdecl);
01288
01289 return false;
01290 }
01291
01292 if (DECL_INITIAL (newdecl))
01293 {
01294 if (DECL_INITIAL (olddecl))
01295 {
01296
01297
01298 if (DECL_DECLARED_INLINE_P (olddecl)
01299 && DECL_EXTERNAL (olddecl)
01300 && DECL_DECLARED_INLINE_P (newdecl)
01301 && DECL_EXTERNAL (newdecl)
01302 && same_translation_unit_p (newdecl, olddecl))
01303 {
01304 error ("%Jredefinition of %qD", newdecl, newdecl);
01305 locate_old_decl (olddecl, error);
01306 return false;
01307 }
01308
01309 if (!DECL_DECLARED_INLINE_P (olddecl)
01310 && !DECL_EXTERNAL (olddecl)
01311 && !DECL_DECLARED_INLINE_P (newdecl)
01312 && !DECL_EXTERNAL (newdecl))
01313 {
01314 error ("%Jredefinition of %qD", newdecl, newdecl);
01315 locate_old_decl (olddecl, error);
01316 return false;
01317 }
01318
01319
01320 if (!DECL_DECLARED_INLINE_P (olddecl)
01321 && !DECL_EXTERNAL (olddecl)
01322 && DECL_DECLARED_INLINE_P (newdecl)
01323 && DECL_EXTERNAL (newdecl))
01324 {
01325 if (same_translation_unit_p (newdecl, olddecl))
01326 {
01327 error ("%Jredefinition of %qD", newdecl, newdecl);
01328 locate_old_decl (olddecl, error);
01329 return false;
01330 }
01331 else
01332 retval = false;
01333 }
01334 }
01335 }
01336
01337
01338 else if (DECL_INITIAL (olddecl)
01339 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype)
01340 && TYPE_ACTUAL_ARG_TYPES (oldtype)
01341 && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
01342 {
01343 locate_old_decl (olddecl, error);
01344 return false;
01345 }
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355 if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
01356 {
01357
01358
01359
01360
01361
01362 if (!DECL_IS_BUILTIN (olddecl)
01363 && !(DECL_EXTERNAL (olddecl)
01364 && DECL_DECLARED_INLINE_P (olddecl)))
01365 {
01366 error ("%Jstatic declaration of %qD follows "
01367 "non-static declaration", newdecl, newdecl);
01368 locate_old_decl (olddecl, error);
01369 }
01370 return false;
01371 }
01372 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
01373 {
01374 if (DECL_CONTEXT (olddecl))
01375 {
01376 error ("%Jnon-static declaration of %qD follows "
01377 "static declaration", newdecl, newdecl);
01378 locate_old_decl (olddecl, error);
01379 return false;
01380 }
01381 else if (warn_traditional)
01382 {
01383 warning ("%Jnon-static declaration of %qD follows "
01384 "static declaration", newdecl, newdecl);
01385 warned = true;
01386 }
01387 }
01388 }
01389 else if (TREE_CODE (newdecl) == VAR_DECL)
01390 {
01391
01392
01393 if (DECL_THREAD_LOCAL (newdecl) != DECL_THREAD_LOCAL (olddecl))
01394 {
01395 if (DECL_THREAD_LOCAL (newdecl))
01396 error ("%Jthread-local declaration of %qD follows "
01397 "non-thread-local declaration", newdecl, newdecl);
01398 else
01399 error ("%Jnon-thread-local declaration of %qD follows "
01400 "thread-local declaration", newdecl, newdecl);
01401
01402 locate_old_decl (olddecl, error);
01403 return false;
01404 }
01405
01406
01407 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
01408 {
01409 error ("%Jredefinition of %qD", newdecl, newdecl);
01410 locate_old_decl (olddecl, error);
01411 return false;
01412 }
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422 if (DECL_FILE_SCOPE_P (newdecl)
01423 && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
01424 {
01425 if (DECL_EXTERNAL (newdecl))
01426 {
01427 if (!DECL_FILE_SCOPE_P (olddecl))
01428 {
01429 error ("%Jextern declaration of %qD follows "
01430 "declaration with no linkage", newdecl, newdecl);
01431 locate_old_decl (olddecl, error);
01432 return false;
01433 }
01434 else if (warn_traditional)
01435 {
01436 warning ("%Jnon-static declaration of %qD follows "
01437 "static declaration", newdecl, newdecl);
01438 warned = true;
01439 }
01440 }
01441 else
01442 {
01443 if (TREE_PUBLIC (newdecl))
01444 error ("%Jnon-static declaration of %qD follows "
01445 "static declaration", newdecl, newdecl);
01446 else
01447 error ("%Jstatic declaration of %qD follows "
01448 "non-static declaration", newdecl, newdecl);
01449
01450 locate_old_decl (olddecl, error);
01451 return false;
01452 }
01453 }
01454
01455
01456 else if (!DECL_FILE_SCOPE_P (newdecl))
01457 {
01458 if (DECL_EXTERNAL (newdecl))
01459 {
01460
01461
01462 }
01463 else if (DECL_EXTERNAL (olddecl))
01464 {
01465 error ("%Jdeclaration of %qD with no linkage follows "
01466 "extern declaration", newdecl, newdecl);
01467 locate_old_decl (olddecl, error);
01468 }
01469 else
01470 {
01471 error ("%Jredeclaration of %qD with no linkage",
01472 newdecl, newdecl);
01473 locate_old_decl (olddecl, error);
01474 }
01475
01476 return false;
01477 }
01478 }
01479
01480
01481
01482 if (DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
01483 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
01484 {
01485 warning ("%Jredeclaration of %qD with different visibility "
01486 "(old visibility preserved)", newdecl, newdecl);
01487 warned = true;
01488 }
01489
01490 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01491 {
01492
01493 if (DECL_DECLARED_INLINE_P (newdecl)
01494 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01495 {
01496 warning ("%Jinline declaration of %qD follows "
01497 "declaration with attribute noinline", newdecl, newdecl);
01498 warned = true;
01499 }
01500 else if (DECL_DECLARED_INLINE_P (olddecl)
01501 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01502 {
01503 warning ("%Jdeclaration of %qD with attribute noinline follows "
01504 "inline declaration ", newdecl, newdecl);
01505 warned = true;
01506 }
01507
01508
01509
01510
01511
01512
01513 if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
01514 && same_translation_unit_p (olddecl, newdecl))
01515 {
01516 if (TREE_USED (olddecl))
01517 {
01518 warning ("%J%qD declared inline after being called",
01519 olddecl, olddecl);
01520 warned = true;
01521 }
01522 else if (DECL_INITIAL (olddecl))
01523 {
01524 warning ("%J%qD declared inline after its definition",
01525 olddecl, olddecl);
01526 warned = true;
01527 }
01528 }
01529 }
01530 else
01531 {
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541 if (TREE_CODE (newdecl) == PARM_DECL
01542 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
01543 {
01544 error ("%Jredefinition of parameter %qD", newdecl, newdecl);
01545 locate_old_decl (olddecl, error);
01546 return false;
01547 }
01548 }
01549
01550
01551 if (!warned && !pedwarned
01552 && warn_redundant_decls
01553
01554
01555 && !(TREE_CODE (newdecl) == FUNCTION_DECL
01556 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
01557
01558 && !(TREE_CODE (newdecl) == FUNCTION_DECL
01559 && !DECL_BUILT_IN (newdecl)
01560 && DECL_BUILT_IN (olddecl)
01561 && !C_DECL_DECLARED_BUILTIN (olddecl))
01562
01563 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
01564
01565 && !(TREE_CODE (newdecl) == PARM_DECL
01566 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
01567
01568 && !(TREE_CODE (newdecl) == VAR_DECL
01569 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
01570 {
01571 warning ("%Jredundant redeclaration of %qD", newdecl, newdecl);
01572 warned = true;
01573 }
01574
01575
01576 if (warned || pedwarned)
01577 locate_old_decl (olddecl, pedwarned ? pedwarn : warning);
01578
01579 return retval;
01580 }
01581
01582
01583
01584
01585
01586
01587 static void
01588 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
01589 {
01590 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
01591 && DECL_INITIAL (newdecl) != 0);
01592 int new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
01593 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
01594 int old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
01595 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
01596
01597
01598
01599
01600 if (TREE_CODE (newdecl) == PARM_DECL
01601 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
01602 {
01603 struct c_binding *b, **here;
01604
01605 for (here = ¤t_scope->bindings; *here; here = &(*here)->prev)
01606 if ((*here)->decl == olddecl)
01607 goto found;
01608 gcc_unreachable ();
01609
01610 found:
01611 b = *here;
01612 *here = b->prev;
01613 b->prev = current_scope->bindings;
01614 current_scope->bindings = b;
01615
01616 TREE_ASM_WRITTEN (olddecl) = 0;
01617 }
01618
01619 DECL_ATTRIBUTES (newdecl)
01620 = targetm.merge_decl_attributes (olddecl, newdecl);
01621
01622
01623 TREE_TYPE (newdecl)
01624 = TREE_TYPE (olddecl)
01625 = composite_type (newtype, oldtype);
01626
01627
01628 if (!comptypes (oldtype, TREE_TYPE (newdecl)))
01629 {
01630 if (TREE_TYPE (newdecl) != error_mark_node)
01631 layout_type (TREE_TYPE (newdecl));
01632 if (TREE_CODE (newdecl) != FUNCTION_DECL
01633 && TREE_CODE (newdecl) != TYPE_DECL
01634 && TREE_CODE (newdecl) != CONST_DECL)
01635 layout_decl (newdecl, 0);
01636 }
01637 else
01638 {
01639
01640 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
01641 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
01642 DECL_MODE (newdecl) = DECL_MODE (olddecl);
01643 if (TREE_CODE (olddecl) != FUNCTION_DECL)
01644 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
01645 {
01646 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
01647 DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl);
01648 }
01649 }
01650
01651
01652 COPY_DECL_RTL (olddecl, newdecl);
01653
01654
01655 if (TREE_READONLY (newdecl))
01656 TREE_READONLY (olddecl) = 1;
01657
01658 if (TREE_THIS_VOLATILE (newdecl))
01659 {
01660 TREE_THIS_VOLATILE (olddecl) = 1;
01661 if (TREE_CODE (newdecl) == VAR_DECL)
01662 make_var_volatile (newdecl);
01663 }
01664
01665
01666 if (TREE_DEPRECATED (newdecl))
01667 TREE_DEPRECATED (olddecl) = 1;
01668
01669
01670
01671
01672 if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
01673 || (old_is_prototype && !new_is_prototype
01674 && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
01675 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
01676
01677
01678 if (DECL_IN_SYSTEM_HEADER (olddecl))
01679 DECL_IN_SYSTEM_HEADER (newdecl) = 1;
01680 else if (DECL_IN_SYSTEM_HEADER (newdecl))
01681 DECL_IN_SYSTEM_HEADER (olddecl) = 1;
01682
01683
01684 if (DECL_INITIAL (newdecl) == 0)
01685 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01686
01687
01688
01689
01690
01691 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
01692 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
01693
01694
01695
01696 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
01697
01698
01699 if (DECL_VISIBILITY_SPECIFIED (olddecl))
01700 {
01701 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
01702 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
01703 }
01704
01705 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01706 {
01707 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
01708 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
01709 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
01710 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
01711 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
01712 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01713 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
01714 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
01715 DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
01716 }
01717
01718
01719 merge_weak (newdecl, olddecl);
01720
01721
01722 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01723 {
01724 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
01725
01726
01727 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
01728
01729 if (!TREE_PUBLIC (olddecl))
01730 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
01731 }
01732 if (DECL_EXTERNAL (newdecl))
01733 {
01734 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
01735 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
01736
01737
01738 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
01739 if (!DECL_EXTERNAL (newdecl))
01740 {
01741 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
01742 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
01743 }
01744 }
01745 else
01746 {
01747 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
01748 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
01749 }
01750
01751 if (TREE_CODE (newdecl) == FUNCTION_DECL)
01752 {
01753
01754
01755
01756
01757 if (new_is_definition && DECL_INITIAL (olddecl))
01758 {
01759 if (TREE_USED (olddecl)
01760
01761
01762 && !flag_unit_at_a_time
01763 && cgraph_function_possibly_inlined_p (olddecl))
01764 (*debug_hooks->outlining_inline_function) (olddecl);
01765
01766
01767 DECL_INLINE (newdecl) = 0;
01768 DECL_UNINLINABLE (newdecl) = 1;
01769 }
01770 else
01771 {
01772
01773
01774 if (DECL_DECLARED_INLINE_P (newdecl)
01775 || DECL_DECLARED_INLINE_P (olddecl))
01776 DECL_DECLARED_INLINE_P (newdecl) = 1;
01777
01778 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
01779 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
01780 }
01781
01782 if (DECL_BUILT_IN (olddecl))
01783 {
01784
01785
01786 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
01787 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
01788 C_DECL_DECLARED_BUILTIN (newdecl) = 1;
01789 if (new_is_prototype)
01790 C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
01791 else
01792 C_DECL_BUILTIN_PROTOTYPE (newdecl)
01793 = C_DECL_BUILTIN_PROTOTYPE (olddecl);
01794 }
01795
01796
01797 if (!new_is_definition)
01798 {
01799 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
01800 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01801 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
01802 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
01803 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
01804
01805
01806
01807 if (DECL_INLINE (olddecl) && !DECL_UNINLINABLE (newdecl))
01808 {
01809 DECL_INLINE (newdecl) = 1;
01810 DECL_ABSTRACT_ORIGIN (newdecl)
01811 = DECL_ABSTRACT_ORIGIN (olddecl);
01812 }
01813 }
01814 else
01815 {
01816
01817
01818 if (DECL_DECLARED_INLINE_P (newdecl)
01819 && !DECL_UNINLINABLE (newdecl))
01820 DECL_INLINE (newdecl) = 1;
01821 }
01822 }
01823
01824
01825
01826 {
01827 unsigned olddecl_uid = DECL_UID (olddecl);
01828 tree olddecl_context = DECL_CONTEXT (olddecl);
01829
01830 memcpy ((char *) olddecl + sizeof (struct tree_common),
01831 (char *) newdecl + sizeof (struct tree_common),
01832 sizeof (struct tree_decl) - sizeof (struct tree_common));
01833 DECL_UID (olddecl) = olddecl_uid;
01834 DECL_CONTEXT (olddecl) = olddecl_context;
01835 }
01836
01837
01838
01839
01840 if (DECL_RTL_SET_P (olddecl)
01841 && (TREE_CODE (olddecl) == FUNCTION_DECL
01842 || (TREE_CODE (olddecl) == VAR_DECL
01843 && TREE_STATIC (olddecl))))
01844 make_decl_rtl (olddecl);
01845 }
01846
01847
01848
01849
01850
01851
01852
01853
01854 static bool
01855 duplicate_decls (tree newdecl, tree olddecl)
01856 {
01857 tree newtype = NULL, oldtype = NULL;
01858
01859 if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
01860 return false;
01861
01862 merge_decls (newdecl, olddecl, newtype, oldtype);
01863 return true;
01864 }
01865
01866
01867
01868 static void
01869 warn_if_shadowing (tree new_decl)
01870 {
01871 struct c_binding *b;
01872
01873
01874 if (!warn_shadow
01875
01876 || DECL_IS_BUILTIN (new_decl)
01877
01878 || DECL_FROM_INLINE (new_decl)
01879
01880
01881
01882
01883
01884 || (TREE_CODE (new_decl) == PARM_DECL && current_scope->outer->parm_flag))
01885 return;
01886
01887
01888 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
01889 if (b->decl && b->decl != new_decl && !b->invisible)
01890 {
01891 tree old_decl = b->decl;
01892
01893 if (old_decl == error_mark_node)
01894 {
01895 warning ("%Jdeclaration of %qD shadows previous non-variable",
01896 new_decl, new_decl);
01897 break;
01898 }
01899 else if (TREE_CODE (old_decl) == PARM_DECL)
01900 warning ("%Jdeclaration of %qD shadows a parameter",
01901 new_decl, new_decl);
01902 else if (DECL_FILE_SCOPE_P (old_decl))
01903 warning ("%Jdeclaration of %qD shadows a global declaration",
01904 new_decl, new_decl);
01905 else if (TREE_CODE (old_decl) == FUNCTION_DECL
01906 && DECL_BUILT_IN (old_decl))
01907 {
01908 warning ("%Jdeclaration of %qD shadows a built-in function",
01909 new_decl, new_decl);
01910 break;
01911 }
01912 else
01913 warning ("%Jdeclaration of %qD shadows a previous local",
01914 new_decl, new_decl);
01915
01916 warning ("%Jshadowed declaration is here", old_decl);
01917
01918 break;
01919 }
01920 }
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967 static void
01968 clone_underlying_type (tree x)
01969 {
01970 if (DECL_IS_BUILTIN (x))
01971 {
01972 if (TYPE_NAME (TREE_TYPE (x)) == 0)
01973 TYPE_NAME (TREE_TYPE (x)) = x;
01974 }
01975 else if (TREE_TYPE (x) != error_mark_node
01976 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
01977 {
01978 tree tt = TREE_TYPE (x);
01979 DECL_ORIGINAL_TYPE (x) = tt;
01980 tt = build_variant_type_copy (tt);
01981 TYPE_NAME (tt) = x;
01982 TREE_USED (tt) = TREE_USED (x);
01983 TREE_TYPE (x) = tt;
01984 }
01985 }
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995 tree
01996 pushdecl (tree x)
01997 {
01998 tree name = DECL_NAME (x);
01999 struct c_scope *scope = current_scope;
02000 struct c_binding *b;
02001 bool nested = false;
02002
02003
02004 if (TREE_CODE (x) == FUNCTION_DECL && !DECL_LANG_SPECIFIC (x))
02005 DECL_LANG_SPECIFIC (x) = GGC_CNEW (struct lang_decl);
02006
02007
02008
02009
02010 if (current_function_decl
02011 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
02012 || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
02013 DECL_CONTEXT (x) = current_function_decl;
02014
02015
02016
02017 if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL)
02018 && variably_modified_type_p (TREE_TYPE (x), NULL_TREE))
02019 c_begin_vm_scope (scope->depth);
02020
02021
02022 if (!name)
02023 {
02024 bind (name, x, scope, false, false);
02025 return x;
02026 }
02027
02028
02029
02030
02031
02032
02033
02034
02035 b = I_SYMBOL_BINDING (name);
02036 if (b && B_IN_SCOPE (b, scope))
02037 {
02038 struct c_binding *b_ext, *b_use;
02039 tree type = TREE_TYPE (x);
02040 tree visdecl = b->decl;
02041 tree vistype = TREE_TYPE (visdecl);
02042 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
02043 && COMPLETE_TYPE_P (TREE_TYPE (x)))
02044 b->inner_comp = false;
02045 b_use = b;
02046 b_ext = b;
02047
02048
02049
02050
02051 if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
02052 {
02053 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
02054 b_ext = b_ext->shadowed;
02055 if (b_ext)
02056 {
02057 b_use = b_ext;
02058 if (b_use->type)
02059 TREE_TYPE (b_use->decl) = b_use->type;
02060 }
02061 }
02062 if (duplicate_decls (x, b_use->decl))
02063 {
02064 if (b_use != b)
02065 {
02066
02067
02068 tree thistype;
02069 if (comptypes (vistype, type))
02070 thistype = composite_type (vistype, type);
02071 else
02072 thistype = TREE_TYPE (b_use->decl);
02073 b_use->type = TREE_TYPE (b_use->decl);
02074 if (TREE_CODE (b_use->decl) == FUNCTION_DECL
02075 && DECL_BUILT_IN (b_use->decl))
02076 thistype
02077 = build_type_attribute_variant (thistype,
02078 TYPE_ATTRIBUTES
02079 (b_use->type));
02080 TREE_TYPE (b_use->decl) = thistype;
02081 }
02082 return b_use->decl;
02083 }
02084 else
02085 goto skip_external_and_shadow_checks;
02086 }
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100 if (DECL_EXTERNAL (x) || scope == file_scope)
02101 {
02102 tree type = TREE_TYPE (x);
02103 tree vistype = 0;
02104 tree visdecl = 0;
02105 bool type_saved = false;
02106 if (b && !B_IN_EXTERNAL_SCOPE (b)
02107 && (TREE_CODE (b->decl) == FUNCTION_DECL
02108 || TREE_CODE (b->decl) == VAR_DECL)
02109 && DECL_FILE_SCOPE_P (b->decl))
02110 {
02111 visdecl = b->decl;
02112 vistype = TREE_TYPE (visdecl);
02113 }
02114 if (warn_nested_externs
02115 && scope != file_scope
02116 && !DECL_IN_SYSTEM_HEADER (x))
02117 warning ("nested extern declaration of %qD", x);
02118
02119 while (b && !B_IN_EXTERNAL_SCOPE (b))
02120 {
02121
02122
02123
02124
02125
02126
02127
02128
02129 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
02130 {
02131 b->type = TREE_TYPE (b->decl);
02132 type_saved = true;
02133 }
02134 if (B_IN_FILE_SCOPE (b)
02135 && TREE_CODE (b->decl) == VAR_DECL
02136 && TREE_STATIC (b->decl)
02137 && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
02138 && !TYPE_DOMAIN (TREE_TYPE (b->decl))
02139 && TREE_CODE (type) == ARRAY_TYPE
02140 && TYPE_DOMAIN (type)
02141 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
02142 && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
02143 {
02144
02145
02146
02147 b->inner_comp = true;
02148 }
02149 b = b->shadowed;
02150 }
02151
02152
02153
02154
02155
02156 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
02157 && b->type)
02158 TREE_TYPE (b->decl) = b->type;
02159
02160
02161
02162
02163
02164
02165 if (b
02166 && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
02167 && duplicate_decls (x, b->decl))
02168 {
02169 tree thistype;
02170 if (vistype)
02171 {
02172 if (comptypes (vistype, type))
02173 thistype = composite_type (vistype, type);
02174 else
02175 thistype = TREE_TYPE (b->decl);
02176 }
02177 else
02178 thistype = type;
02179 b->type = TREE_TYPE (b->decl);
02180 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
02181 thistype
02182 = build_type_attribute_variant (thistype,
02183 TYPE_ATTRIBUTES (b->type));
02184 TREE_TYPE (b->decl) = thistype;
02185 bind (name, b->decl, scope, false, true);
02186 return b->decl;
02187 }
02188 else if (TREE_PUBLIC (x))
02189 {
02190 if (visdecl && !b && duplicate_decls (x, visdecl))
02191 {
02192
02193
02194
02195
02196
02197 nested = true;
02198 x = visdecl;
02199 }
02200 else
02201 {
02202 bind (name, x, external_scope, true,
02203 false);
02204 nested = true;
02205 }
02206 }
02207 }
02208
02209 warn_if_shadowing (x);
02210
02211 skip_external_and_shadow_checks:
02212 if (TREE_CODE (x) == TYPE_DECL)
02213 clone_underlying_type (x);
02214
02215 bind (name, x, scope, false, nested);
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226 if (TREE_TYPE (x) != error_mark_node
02227 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
02228 {
02229 tree element = TREE_TYPE (x);
02230
02231 while (TREE_CODE (element) == ARRAY_TYPE)
02232 element = TREE_TYPE (element);
02233 element = TYPE_MAIN_VARIANT (element);
02234
02235 if ((TREE_CODE (element) == RECORD_TYPE
02236 || TREE_CODE (element) == UNION_TYPE)
02237 && (TREE_CODE (x) != TYPE_DECL
02238 || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
02239 && !COMPLETE_TYPE_P (element))
02240 C_TYPE_INCOMPLETE_VARS (element)
02241 = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
02242 }
02243 return x;
02244 }
02245
02246
02247
02248
02249
02250
02251 tree
02252 pushdecl_top_level (tree x)
02253 {
02254 tree name;
02255 bool nested = false;
02256 gcc_assert (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == CONST_DECL);
02257
02258 name = DECL_NAME (x);
02259
02260 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
02261
02262 if (TREE_PUBLIC (x))
02263 {
02264 bind (name, x, external_scope, true, false);
02265 nested = true;
02266 }
02267 if (file_scope)
02268 bind (name, x, file_scope, false, nested);
02269
02270 return x;
02271 }
02272
02273 static void
02274 implicit_decl_warning (tree id, tree olddecl)
02275 {
02276 void (*diag) (const char *, ...);
02277 switch (mesg_implicit_function_declaration)
02278 {
02279 case 0: return;
02280 case 1: diag = warning; break;
02281 case 2: diag = error; break;
02282 default: gcc_unreachable ();
02283 }
02284
02285 diag (G_("implicit declaration of function %qE"), id);
02286 if (olddecl)
02287 locate_old_decl (olddecl, diag);
02288 }
02289
02290
02291
02292
02293 tree
02294 implicitly_declare (tree functionid)
02295 {
02296 struct c_binding *b;
02297 tree decl = 0;
02298 tree asmspec_tree;
02299
02300 for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
02301 {
02302 if (B_IN_SCOPE (b, external_scope))
02303 {
02304 decl = b->decl;
02305 break;
02306 }
02307 }
02308
02309 if (decl)
02310 {
02311 if (decl == error_mark_node)
02312 return decl;
02313
02314
02315
02316
02317
02318
02319 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
02320 {
02321 bind (functionid, decl, file_scope,
02322 false, true);
02323 return decl;
02324 }
02325 else
02326 {
02327 tree newtype = default_function_type;
02328 if (b->type)
02329 TREE_TYPE (decl) = b->type;
02330
02331
02332
02333
02334 if (!C_DECL_IMPLICIT (decl))
02335 {
02336 implicit_decl_warning (functionid, decl);
02337 C_DECL_IMPLICIT (decl) = 1;
02338 }
02339 if (DECL_BUILT_IN (decl))
02340 {
02341 newtype = build_type_attribute_variant (newtype,
02342 TYPE_ATTRIBUTES
02343 (TREE_TYPE (decl)));
02344 if (!comptypes (newtype, TREE_TYPE (decl)))
02345 {
02346 warning ("incompatible implicit declaration of built-in"
02347 " function %qD", decl);
02348 newtype = TREE_TYPE (decl);
02349 }
02350 }
02351 else
02352 {
02353 if (!comptypes (newtype, TREE_TYPE (decl)))
02354 {
02355 error ("incompatible implicit declaration of function %qD",
02356 decl);
02357 locate_old_decl (decl, error);
02358 }
02359 }
02360 b->type = TREE_TYPE (decl);
02361 TREE_TYPE (decl) = newtype;
02362 bind (functionid, decl, current_scope,
02363 false, true);
02364 return decl;
02365 }
02366 }
02367
02368
02369 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
02370 DECL_EXTERNAL (decl) = 1;
02371 TREE_PUBLIC (decl) = 1;
02372 C_DECL_IMPLICIT (decl) = 1;
02373 implicit_decl_warning (functionid, 0);
02374 asmspec_tree = maybe_apply_renaming_pragma (decl, NULL);
02375 if (asmspec_tree)
02376 set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
02377
02378
02379
02380 decl = pushdecl (decl);
02381
02382
02383 rest_of_decl_compilation (decl, 0, 0);
02384
02385
02386
02387 gen_aux_info_record (decl, 0, 1, 0);
02388
02389
02390 decl_attributes (&decl, NULL_TREE, 0);
02391
02392 return decl;
02393 }
02394
02395
02396
02397
02398
02399
02400 void
02401 undeclared_variable (tree id)
02402 {
02403 static bool already = false;
02404 struct c_scope *scope;
02405
02406 if (current_function_decl == 0)
02407 {
02408 error ("%qE undeclared here (not in a function)", id);
02409 scope = current_scope;
02410 }
02411 else
02412 {
02413 error ("%qE undeclared (first use in this function)", id);
02414
02415 if (!already)
02416 {
02417 error ("(Each undeclared identifier is reported only once");
02418 error ("for each function it appears in.)");
02419 already = true;
02420 }
02421
02422
02423
02424 scope = current_function_scope ? current_function_scope : current_scope;
02425 }
02426 bind (id, error_mark_node, scope, false, false);
02427 }
02428
02429
02430
02431
02432 static tree
02433 make_label (tree name, location_t location)
02434 {
02435 tree label = build_decl (LABEL_DECL, name, void_type_node);
02436
02437 DECL_CONTEXT (label) = current_function_decl;
02438 DECL_MODE (label) = VOIDmode;
02439 DECL_SOURCE_LOCATION (label) = location;
02440
02441 return label;
02442 }
02443
02444
02445
02446
02447
02448
02449 tree
02450 lookup_label (tree name)
02451 {
02452 tree label;
02453
02454 if (current_function_decl == 0)
02455 {
02456 error ("label %qs referenced outside of any function",
02457 IDENTIFIER_POINTER (name));
02458 return 0;
02459 }
02460
02461
02462
02463
02464 label = I_LABEL_DECL (name);
02465 if (label && (DECL_CONTEXT (label) == current_function_decl
02466 || C_DECLARED_LABEL_FLAG (label)))
02467 {
02468
02469
02470
02471 if (!TREE_USED (label))
02472 DECL_SOURCE_LOCATION (label) = input_location;
02473 return label;
02474 }
02475
02476
02477 label = make_label (name, input_location);
02478
02479
02480 bind (name, label, current_function_scope,
02481 false, false);
02482 return label;
02483 }
02484
02485
02486
02487
02488
02489 tree
02490 declare_label (tree name)
02491 {
02492 struct c_binding *b = I_LABEL_BINDING (name);
02493 tree label;
02494
02495
02496
02497 if (b && B_IN_CURRENT_SCOPE (b))
02498 {
02499 error ("duplicate label declaration %qs", IDENTIFIER_POINTER (name));
02500 locate_old_decl (b->decl, error);
02501
02502
02503 return b->decl;
02504 }
02505
02506 label = make_label (name, input_location);
02507 C_DECLARED_LABEL_FLAG (label) = 1;
02508
02509
02510 bind (name, label, current_scope,
02511 false, false);
02512 return label;
02513 }
02514
02515
02516
02517
02518
02519 tree
02520 define_label (location_t location, tree name)
02521 {
02522
02523
02524
02525
02526 tree label = I_LABEL_DECL (name);
02527 struct c_label_list *nlist_se, *nlist_vm;
02528
02529 if (label
02530 && ((DECL_CONTEXT (label) == current_function_decl
02531 && DECL_INITIAL (label) != 0)
02532 || (DECL_CONTEXT (label) != current_function_decl
02533 && C_DECLARED_LABEL_FLAG (label))))
02534 {
02535 error ("%Hduplicate label %qD", &location, label);
02536 locate_old_decl (label, error);
02537 return 0;
02538 }
02539 else if (label && DECL_CONTEXT (label) == current_function_decl)
02540 {
02541
02542
02543
02544 if (C_DECL_UNDEFINABLE_STMT_EXPR (label))
02545 error ("%Jjump into statement expression", label);
02546 if (C_DECL_UNDEFINABLE_VM (label))
02547 error ("%Jjump into scope of identifier with variably modified type",
02548 label);
02549 DECL_SOURCE_LOCATION (label) = location;
02550 }
02551 else
02552 {
02553
02554 label = make_label (name, location);
02555
02556
02557 bind (name, label, current_function_scope,
02558 false, false);
02559 }
02560
02561 if (warn_traditional && !in_system_header && lookup_name (name))
02562 warning ("%Htraditional C lacks a separate namespace for labels, "
02563 "identifier %qs conflicts", &location,
02564 IDENTIFIER_POINTER (name));
02565
02566 nlist_se = XOBNEW (&parser_obstack, struct c_label_list);
02567 nlist_se->next = label_context_stack_se->labels_def;
02568 nlist_se->label = label;
02569 label_context_stack_se->labels_def = nlist_se;
02570
02571 nlist_vm = XOBNEW (&parser_obstack, struct c_label_list);
02572 nlist_vm->next = label_context_stack_vm->labels_def;
02573 nlist_vm->label = label;
02574 label_context_stack_vm->labels_def = nlist_vm;
02575
02576
02577 DECL_INITIAL (label) = error_mark_node;
02578 return label;
02579 }
02580
02581
02582
02583
02584
02585
02586
02587
02588 static tree
02589 lookup_tag (enum tree_code code, tree name, int thislevel_only)
02590 {
02591 struct c_binding *b = I_TAG_BINDING (name);
02592 int thislevel = 0;
02593
02594 if (!b || !b->decl)
02595 return 0;
02596
02597
02598
02599 if (thislevel_only || TREE_CODE (b->decl) != code)
02600 {
02601
02602
02603
02604
02605 if (B_IN_CURRENT_SCOPE (b)
02606 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
02607 thislevel = 1;
02608 }
02609
02610 if (thislevel_only && !thislevel)
02611 return 0;
02612
02613 if (TREE_CODE (b->decl) != code)
02614 {
02615
02616 pending_invalid_xref = name;
02617 pending_invalid_xref_location = input_location;
02618
02619
02620
02621
02622
02623 if (thislevel)
02624 pending_xref_error ();
02625 }
02626 return b->decl;
02627 }
02628
02629
02630
02631
02632
02633
02634 void
02635 pending_xref_error (void)
02636 {
02637 if (pending_invalid_xref != 0)
02638 error ("%H%qs defined as wrong kind of tag",
02639 &pending_invalid_xref_location,
02640 IDENTIFIER_POINTER (pending_invalid_xref));
02641 pending_invalid_xref = 0;
02642 }
02643
02644
02645
02646
02647
02648
02649
02650 tree
02651 lookup_name (tree name)
02652 {
02653 struct c_binding *b = I_SYMBOL_BINDING (name);
02654 if (b && !b->invisible)
02655 return b->decl;
02656 return 0;
02657 }
02658
02659
02660
02661 static tree
02662 lookup_name_in_scope (tree name, struct c_scope *scope)
02663 {
02664 struct c_binding *b;
02665
02666 for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
02667 if (B_IN_SCOPE (b, scope))
02668 return b->decl;
02669 return 0;
02670 }
02671
02672
02673
02674
02675
02676
02677 void
02678 c_init_decl_processing (void)
02679 {
02680 tree endlink;
02681 tree ptr_ftype_void, ptr_ftype_ptr;
02682 location_t save_loc = input_location;
02683
02684
02685 c_parse_init ();
02686
02687 current_function_decl = 0;
02688
02689 gcc_obstack_init (&parser_obstack);
02690
02691
02692 push_scope ();
02693 external_scope = current_scope;
02694
02695
02696
02697
02698 #ifdef USE_MAPPED_LOCATION
02699 input_location = BUILTINS_LOCATION;
02700 #else
02701 input_location.file = "<built-in>";
02702 input_location.line = 0;
02703 #endif
02704
02705 build_common_tree_nodes (flag_signed_char, false);
02706
02707 c_common_nodes_and_builtins ();
02708
02709
02710 truthvalue_type_node = integer_type_node;
02711 truthvalue_true_node = integer_one_node;
02712 truthvalue_false_node = integer_zero_node;
02713
02714
02715 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
02716 boolean_type_node));
02717
02718 endlink = void_list_node;
02719 ptr_ftype_void = build_function_type (ptr_type_node, endlink);
02720 ptr_ftype_ptr
02721 = build_function_type (ptr_type_node,
02722 tree_cons (NULL_TREE, ptr_type_node, endlink));
02723
02724 input_location = save_loc;
02725
02726 pedantic_lvalues = true;
02727
02728 make_fname_decl = c_make_fname_decl;
02729 start_fname_decls ();
02730 }
02731
02732
02733
02734
02735
02736
02737
02738
02739 static tree
02740 c_make_fname_decl (tree id, int type_dep)
02741 {
02742 const char *name = fname_as_string (type_dep);
02743 tree decl, type, init;
02744 size_t length = strlen (name);
02745
02746 type = build_array_type (char_type_node,
02747 build_index_type (size_int (length)));
02748 type = c_build_qualified_type (type, TYPE_QUAL_CONST);
02749
02750 decl = build_decl (VAR_DECL, id, type);
02751
02752 TREE_STATIC (decl) = 1;
02753 TREE_READONLY (decl) = 1;
02754 DECL_ARTIFICIAL (decl) = 1;
02755
02756 init = build_string (length + 1, name);
02757 free ((char *) name);
02758 TREE_TYPE (init) = type;
02759 DECL_INITIAL (decl) = init;
02760
02761 TREE_USED (decl) = 1;
02762
02763 if (current_function_decl)
02764 {
02765 DECL_CONTEXT (decl) = current_function_decl;
02766 bind (id, decl, current_function_scope,
02767 false, false);
02768 }
02769
02770 finish_decl (decl, init, NULL_TREE);
02771
02772 return decl;
02773 }
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784 tree
02785 builtin_function (const char *name, tree type, int function_code,
02786 enum built_in_class cl, const char *library_name,
02787 tree attrs)
02788 {
02789 tree id = get_identifier (name);
02790 tree decl = build_decl (FUNCTION_DECL, id, type);
02791 TREE_PUBLIC (decl) = 1;
02792 DECL_EXTERNAL (decl) = 1;
02793 DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
02794 DECL_BUILT_IN_CLASS (decl) = cl;
02795 DECL_FUNCTION_CODE (decl) = function_code;
02796 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
02797 if (library_name)
02798 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
02799
02800
02801 gcc_assert (!I_SYMBOL_BINDING (id));
02802
02803 bind (id, decl, external_scope, true, false);
02804
02805
02806
02807 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
02808 {
02809 TREE_CHAIN (decl) = visible_builtins;
02810 visible_builtins = decl;
02811 }
02812
02813
02814 if (attrs)
02815 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
02816 else
02817 decl_attributes (&decl, NULL_TREE, 0);
02818
02819 return decl;
02820 }
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830 void
02831 shadow_tag (const struct c_declspecs *declspecs)
02832 {
02833 shadow_tag_warned (declspecs, 0);
02834 }
02835
02836
02837
02838 void
02839 shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
02840 {
02841 bool found_tag = false;
02842
02843 if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
02844 {
02845 tree value = declspecs->type;
02846 enum tree_code code = TREE_CODE (value);
02847
02848 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
02849
02850
02851 {
02852 tree name = TYPE_NAME (value);
02853 tree t;
02854
02855 found_tag = true;
02856
02857 if (name == 0)
02858 {
02859 if (warned != 1 && code != ENUMERAL_TYPE)
02860
02861 {
02862 pedwarn ("unnamed struct/union that defines no instances");
02863 warned = 1;
02864 }
02865 }
02866 else if (!declspecs->tag_defined_p
02867 && declspecs->storage_class != csc_none)
02868 {
02869 if (warned != 1)
02870 pedwarn ("empty declaration with storage class specifier "
02871 "does not redeclare tag");
02872 warned = 1;
02873 pending_xref_error ();
02874 }
02875 else if (!declspecs->tag_defined_p
02876 && (declspecs->const_p
02877 || declspecs->volatile_p
02878 || declspecs->restrict_p))
02879 {
02880 if (warned != 1)
02881 pedwarn ("empty declaration with type qualifier "
02882 "does not redeclare tag");
02883 warned = 1;
02884 pending_xref_error ();
02885 }
02886 else
02887 {
02888 pending_invalid_xref = 0;
02889 t = lookup_tag (code, name, 1);
02890
02891 if (t == 0)
02892 {
02893 t = make_node (code);
02894 pushtag (name, t);
02895 }
02896 }
02897 }
02898 else
02899 {
02900 if (warned != 1 && !in_system_header)
02901 {
02902 pedwarn ("useless type name in empty declaration");
02903 warned = 1;
02904 }
02905 }
02906 }
02907 else if (warned != 1 && !in_system_header && declspecs->typedef_p)
02908 {
02909 pedwarn ("useless type name in empty declaration");
02910 warned = 1;
02911 }
02912
02913 pending_invalid_xref = 0;
02914
02915 if (declspecs->inline_p)
02916 {
02917 error ("%<inline%> in empty declaration");
02918 warned = 1;
02919 }
02920
02921 if (current_scope == file_scope && declspecs->storage_class == csc_auto)
02922 {
02923 error ("%<auto%> in file-scope empty declaration");
02924 warned = 1;
02925 }
02926
02927 if (current_scope == file_scope && declspecs->storage_class == csc_register)
02928 {
02929 error ("%<register%> in file-scope empty declaration");
02930 warned = 1;
02931 }
02932
02933 if (!warned && !in_system_header && declspecs->storage_class != csc_none)
02934 {
02935 warning ("useless storage class specifier in empty declaration");
02936 warned = 2;
02937 }
02938
02939 if (!warned && !in_system_header && declspecs->thread_p)
02940 {
02941 warning ("useless %<__thread%> in empty declaration");
02942 warned = 2;
02943 }
02944
02945 if (!warned && !in_system_header && (declspecs->const_p
02946 || declspecs->volatile_p
02947 || declspecs->restrict_p))
02948 {
02949 warning ("useless type qualifier in empty declaration");
02950 warned = 2;
02951 }
02952
02953 if (warned != 1)
02954 {
02955 if (!found_tag)
02956 pedwarn ("empty declaration");
02957 }
02958 }
02959
02960
02961
02962
02963
02964
02965 int
02966 quals_from_declspecs (const struct c_declspecs *specs)
02967 {
02968 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
02969 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
02970 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0));
02971 gcc_assert (!specs->type
02972 && !specs->decl_attr
02973 && specs->typespec_word == cts_none
02974 && specs->storage_class == csc_none
02975 && !specs->typedef_p
02976 && !specs->explicit_signed_p
02977 && !specs->deprecated_p
02978 && !specs->long_p
02979 && !specs->long_long_p
02980 && !specs->short_p
02981 && !specs->signed_p
02982 && !specs->unsigned_p
02983 && !specs->complex_p
02984 && !specs->inline_p
02985 && !specs->thread_p);
02986 return quals;
02987 }
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998 struct c_declarator *
02999 build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p,
03000 bool vla_unspec_p)
03001 {
03002 struct c_declarator *declarator = XOBNEW (&parser_obstack,
03003 struct c_declarator);
03004 declarator->kind = cdk_array;
03005 declarator->declarator = 0;
03006 declarator->u.array.dimen = expr;
03007 if (quals)
03008 {
03009 declarator->u.array.attrs = quals->attrs;
03010 declarator->u.array.quals = quals_from_declspecs (quals);
03011 }
03012 else
03013 {
03014 declarator->u.array.attrs = NULL_TREE;
03015 declarator->u.array.quals = 0;
03016 }
03017 declarator->u.array.static_p = static_p;
03018 declarator->u.array.vla_unspec_p = vla_unspec_p;
03019 if (pedantic && !flag_isoc99)
03020 {
03021 if (static_p || quals != NULL)
03022 pedwarn ("ISO C90 does not support %<static%> or type "
03023 "qualifiers in parameter array declarators");
03024 if (vla_unspec_p)
03025 pedwarn ("ISO C90 does not support %<[*]%> array declarators");
03026 }
03027 if (vla_unspec_p)
03028 warning ("GCC does not yet properly implement %<[*]%> array declarators");
03029 return declarator;
03030 }
03031
03032
03033
03034
03035
03036
03037
03038
03039 struct c_declarator *
03040 set_array_declarator_inner (struct c_declarator *decl,
03041 struct c_declarator *inner, bool abstract_p)
03042 {
03043 decl->declarator = inner;
03044 if (abstract_p && (decl->u.array.quals != TYPE_UNQUALIFIED
03045 || decl->u.array.attrs != NULL_TREE
03046 || decl->u.array.static_p))
03047 error ("static or type qualifiers in abstract declarator");
03048 return decl;
03049 }
03050
03051
03052
03053 tree
03054 groktypename (struct c_type_name *type_name)
03055 {
03056 tree type;
03057 tree attrs = type_name->specs->attrs;
03058
03059 type_name->specs->attrs = NULL_TREE;
03060
03061 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
03062 false, NULL);
03063
03064
03065 decl_attributes (&type, attrs, 0);
03066
03067 return type;
03068 }
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083
03084
03085 tree
03086 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
03087 bool initialized, tree attributes)
03088 {
03089 tree decl;
03090 tree tem;
03091
03092
03093
03094 if (lookup_attribute ("deprecated", attributes))
03095 deprecated_state = DEPRECATED_SUPPRESS;
03096
03097 decl = grokdeclarator (declarator, declspecs,
03098 NORMAL, initialized, NULL);
03099 if (!decl)
03100 return 0;
03101
03102 deprecated_state = DEPRECATED_NORMAL;
03103
03104 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
03105 && MAIN_NAME_P (DECL_NAME (decl)))
03106 warning ("%J%qD is usually a function", decl, decl);
03107
03108 if (initialized)
03109
03110
03111
03112 switch (TREE_CODE (decl))
03113 {
03114 case TYPE_DECL:
03115 error ("typedef %qD is initialized (use __typeof__ instead)", decl);
03116 initialized = 0;
03117 break;
03118
03119 case FUNCTION_DECL:
03120 error ("function %qD is initialized like a variable", decl);
03121 initialized = 0;
03122 break;
03123
03124 case PARM_DECL:
03125
03126 error ("parameter %qD is initialized", decl);
03127 initialized = 0;
03128 break;
03129
03130 default:
03131
03132
03133
03134
03135
03136 if (TREE_TYPE (decl) == error_mark_node)
03137 initialized = 0;
03138 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
03139 {
03140
03141
03142 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
03143 || C_DECL_VARIABLE_SIZE (decl))
03144 {
03145 error ("variable-sized object may not be initialized");
03146 initialized = 0;
03147 }
03148 }
03149 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
03150 {
03151 error ("variable %qD has initializer but incomplete type", decl);
03152 initialized = 0;
03153 }
03154 else if (C_DECL_VARIABLE_SIZE (decl))
03155 {
03156
03157
03158
03159
03160 error ("variable-sized object may not be initialized");
03161 initialized = 0;
03162 }
03163 }
03164
03165 if (initialized)
03166 {
03167 if (current_scope == file_scope)
03168 TREE_STATIC (decl) = 1;
03169
03170
03171
03172
03173 DECL_INITIAL (decl) = error_mark_node;
03174 }
03175
03176
03177
03178
03179 if (TREE_CODE (decl) == FUNCTION_DECL)
03180 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193 if (TREE_CODE (decl) == VAR_DECL
03194 && !initialized
03195 && TREE_PUBLIC (decl)
03196 && !DECL_THREAD_LOCAL (decl)
03197 && !flag_no_common)
03198 DECL_COMMON (decl) = 1;
03199
03200
03201 decl_attributes (&decl, attributes, 0);
03202
03203 if (TREE_CODE (decl) == FUNCTION_DECL
03204 && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
03205 {
03206 struct c_declarator *ce = declarator;
03207
03208 if (ce->kind == cdk_pointer)
03209 ce = declarator->declarator;
03210 if (ce->kind == cdk_function)
03211 {
03212 tree args = ce->u.arg_info->parms;
03213 for (; args; args = TREE_CHAIN (args))
03214 {
03215 tree type = TREE_TYPE (args);
03216 if (type && INTEGRAL_TYPE_P (type)
03217 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
03218 DECL_ARG_TYPE (args) = integer_type_node;
03219 }
03220 }
03221 }
03222
03223 if (TREE_CODE (decl) == FUNCTION_DECL
03224 && DECL_DECLARED_INLINE_P (decl)
03225 && DECL_UNINLINABLE (decl)
03226 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
03227 warning ("%Jinline function %qD given attribute noinline", decl, decl);
03228
03229
03230
03231 tem = pushdecl (decl);
03232
03233 if (initialized && DECL_EXTERNAL (tem))
03234 {
03235 DECL_EXTERNAL (tem) = 0;
03236 TREE_STATIC (tem) = 1;
03237 }
03238
03239 return tem;
03240 }
03241
03242
03243
03244
03245
03246
03247 void
03248 finish_decl (tree decl, tree init, tree asmspec_tree)
03249 {
03250 tree type = TREE_TYPE (decl);
03251 int was_incomplete = (DECL_SIZE (decl) == 0);
03252 const char *asmspec = 0;
03253
03254
03255 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
03256 && DECL_FILE_SCOPE_P (decl))
03257 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
03258 if (asmspec_tree)
03259 asmspec = TREE_STRING_POINTER (asmspec_tree);
03260
03261
03262 if (init != 0 && DECL_INITIAL (decl) == 0)
03263 init = 0;
03264
03265
03266 if (TREE_CODE (decl) == PARM_DECL)
03267 init = 0;
03268
03269 if (init)
03270 store_init_value (decl, init);
03271
03272 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
03273 || TREE_CODE (decl) == FUNCTION_DECL
03274 || TREE_CODE (decl) == FIELD_DECL))
03275 objc_check_decl (decl);
03276
03277
03278 if (TREE_CODE (type) == ARRAY_TYPE
03279 && TYPE_DOMAIN (type) == 0
03280 && TREE_CODE (decl) != TYPE_DECL)
03281 {
03282 bool do_default
03283 = (TREE_STATIC (decl)
03284
03285
03286 ? pedantic && !TREE_PUBLIC (decl)
03287 : !DECL_EXTERNAL (decl));
03288 int failure
03289 = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
03290 do_default);
03291
03292
03293 type = TREE_TYPE (decl);
03294
03295 switch (failure)
03296 {
03297 case 1:
03298 error ("%Jinitializer fails to determine size of %qD", decl, decl);
03299 break;
03300
03301 case 2:
03302 if (do_default)
03303 error ("%Jarray size missing in %qD", decl, decl);
03304
03305
03306
03307
03308
03309
03310 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
03311 DECL_EXTERNAL (decl) = 1;
03312 break;
03313
03314 case 3:
03315 error ("%Jzero or negative size array %qD", decl, decl);
03316 break;
03317
03318 case 0:
03319
03320
03321 if (TREE_PUBLIC (decl))
03322 {
03323 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
03324 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
03325 b_ext = b_ext->shadowed;
03326 if (b_ext)
03327 {
03328 if (b_ext->type)
03329 b_ext->type = composite_type (b_ext->type, type);
03330 else
03331 b_ext->type = type;
03332 }
03333 }
03334 break;
03335
03336 default:
03337 gcc_unreachable ();
03338 }
03339
03340 if (DECL_INITIAL (decl))
03341 TREE_TYPE (DECL_INITIAL (decl)) = type;
03342
03343 layout_decl (decl, 0);
03344 }
03345
03346 if (TREE_CODE (decl) == VAR_DECL)
03347 {
03348 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
03349 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
03350 layout_decl (decl, 0);
03351
03352 if (DECL_SIZE (decl) == 0
03353
03354 && TREE_TYPE (decl) != error_mark_node
03355 && (TREE_STATIC (decl)
03356
03357
03358
03359
03360
03361 ? (DECL_INITIAL (decl) != 0
03362 || !DECL_FILE_SCOPE_P (decl))
03363
03364
03365 : !DECL_EXTERNAL (decl)))
03366 {
03367 error ("%Jstorage size of %qD isn%'t known", decl, decl);
03368 TREE_TYPE (decl) = error_mark_node;
03369 }
03370
03371 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
03372 && DECL_SIZE (decl) != 0)
03373 {
03374 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
03375 constant_expression_warning (DECL_SIZE (decl));
03376 else
03377 error ("%Jstorage size of %qD isn%'t constant", decl, decl);
03378 }
03379
03380 if (TREE_USED (type))
03381 TREE_USED (decl) = 1;
03382 }
03383
03384
03385
03386
03387 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
03388 {
03389 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
03390 set_builtin_user_assembler_name (decl, asmspec);
03391 set_user_assembler_name (decl, asmspec);
03392 }
03393
03394
03395 maybe_apply_pragma_weak (decl);
03396
03397
03398 if (TREE_CODE (decl) == VAR_DECL
03399 && TREE_STATIC (decl)
03400 && !DECL_EXTERNAL (decl))
03401 c_determine_visibility (decl);
03402
03403
03404
03405
03406
03407 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
03408 {
03409
03410 if (c_dialect_objc ())
03411 objc_check_decl (decl);
03412
03413 if (asmspec)
03414 {
03415
03416
03417
03418
03419
03420 if (!DECL_FILE_SCOPE_P (decl)
03421 && TREE_CODE (decl) == VAR_DECL
03422 && !C_DECL_REGISTER (decl)
03423 && !TREE_STATIC (decl))
03424 warning ("%Jignoring asm-specifier for non-static local "
03425 "variable %qD", decl, decl);
03426 else if (C_DECL_REGISTER (decl))
03427 change_decl_assembler_name (decl, get_identifier (asmspec));
03428 else
03429 set_user_assembler_name (decl, asmspec);
03430 }
03431
03432 if (DECL_FILE_SCOPE_P (decl))
03433 {
03434 if (DECL_INITIAL (decl) == NULL_TREE
03435 || DECL_INITIAL (decl) == error_mark_node)
03436
03437
03438
03439 DECL_DEFER_OUTPUT (decl) = 1;
03440 rest_of_decl_compilation (decl, true, 0);
03441 }
03442 else
03443 {
03444
03445
03446
03447 if (asmspec && C_DECL_REGISTER (decl))
03448 {
03449 DECL_HARD_REGISTER (decl) = 1;
03450
03451
03452
03453 if (!DECL_REGISTER (decl))
03454 error ("cannot put object with volatile field into register");
03455 }
03456
03457 if (TREE_CODE (decl) != FUNCTION_DECL)
03458 {
03459
03460
03461
03462
03463
03464 if (DECL_SIZE (decl)
03465 && !TREE_CONSTANT (DECL_SIZE (decl))
03466 && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
03467 {
03468 tree bind;
03469 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
03470 TREE_SIDE_EFFECTS (bind) = 1;
03471 add_stmt (bind);
03472 BIND_EXPR_BODY (bind) = push_stmt_list ();
03473 }
03474 add_stmt (build_stmt (DECL_EXPR, decl));
03475 }
03476 }
03477
03478
03479 if (!DECL_FILE_SCOPE_P (decl))
03480 {
03481
03482
03483 if (was_incomplete
03484 && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
03485 {
03486
03487 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
03488
03489 if (DECL_SIZE (decl) == 0)
03490 DECL_INITIAL (decl) = 0;
03491 }
03492 }
03493 }
03494
03495
03496 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
03497 mark_decl_referenced (decl);
03498
03499 if (TREE_CODE (decl) == TYPE_DECL)
03500 {
03501 if (!DECL_FILE_SCOPE_P (decl)
03502 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
03503 add_stmt (build_stmt (DECL_EXPR, decl));
03504
03505 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
03506 }
03507
03508
03509
03510
03511 if (current_scope == file_scope)
03512 get_pending_sizes ();
03513
03514
03515 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
03516 {
03517 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
03518 if (attr)
03519 {
03520 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
03521 tree cleanup_decl = lookup_name (cleanup_id);
03522 tree cleanup;
03523
03524
03525 cleanup = build_unary_op (ADDR_EXPR, decl, 0);
03526 cleanup = build_tree_list (NULL_TREE, cleanup);
03527 cleanup = build_function_call (cleanup_decl, cleanup);
03528
03529
03530 TREE_USED (decl) = 1;
03531 TREE_USED (cleanup_decl) = 1;
03532
03533
03534 if (flag_exceptions && !c_eh_initialized_p)
03535 {
03536 c_eh_initialized_p = true;
03537 eh_personality_libfunc
03538 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
03539 ? "__gcc_personality_sj0"
03540 : "__gcc_personality_v0");
03541 using_eh_for_cleanups ();
03542 }
03543
03544 push_cleanup (decl, cleanup, false);
03545 }
03546 }
03547 }
03548
03549
03550
03551 tree
03552 grokparm (const struct c_parm *parm)
03553 {
03554 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
03555 NULL);
03556
03557 decl_attributes (&decl, parm->attrs, 0);
03558
03559 return decl;
03560 }
03561
03562
03563
03564
03565 void
03566 push_parm_decl (const struct c_parm *parm)
03567 {
03568 tree decl;
03569
03570 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL);
03571 decl_attributes (&decl, parm->attrs, 0);
03572
03573 decl = pushdecl (decl);
03574
03575 finish_decl (decl, NULL_TREE, NULL_TREE);
03576 }
03577
03578
03579
03580
03581 void
03582 mark_forward_parm_decls (void)
03583 {
03584 struct c_binding *b;
03585
03586 if (pedantic && !current_scope->warned_forward_parm_decls)
03587 {
03588 pedwarn ("ISO C forbids forward parameter declarations");
03589 current_scope->warned_forward_parm_decls = true;
03590 }
03591
03592 for (b = current_scope->bindings; b; b = b->prev)
03593 if (TREE_CODE (b->decl) == PARM_DECL)
03594 TREE_ASM_WRITTEN (b->decl) = 1;
03595 }
03596
03597 static GTY(()) int compound_literal_number;
03598
03599
03600
03601
03602
03603
03604 tree
03605 build_compound_literal (tree type, tree init)
03606 {
03607
03608
03609
03610 tree decl;
03611 tree complit;
03612 tree stmt;
03613
03614 if (type == error_mark_node)
03615 return error_mark_node;
03616
03617 decl = build_decl (VAR_DECL, NULL_TREE, type);
03618 DECL_EXTERNAL (decl) = 0;
03619 TREE_PUBLIC (decl) = 0;
03620 TREE_STATIC (decl) = (current_scope == file_scope);
03621 DECL_CONTEXT (decl) = current_function_decl;
03622 TREE_USED (decl) = 1;
03623 TREE_TYPE (decl) = type;
03624 TREE_READONLY (decl) = TYPE_READONLY (type);
03625 store_init_value (decl, init);
03626
03627 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
03628 {
03629 int failure = complete_array_type (&TREE_TYPE (decl),
03630 DECL_INITIAL (decl), true);
03631 gcc_assert (!failure);
03632
03633 type = TREE_TYPE (decl);
03634 TREE_TYPE (DECL_INITIAL (decl)) = type;
03635 }
03636
03637 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
03638 return error_mark_node;
03639
03640 stmt = build_stmt (DECL_EXPR, decl);
03641 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
03642 TREE_SIDE_EFFECTS (complit) = 1;
03643
03644 layout_decl (decl, 0);
03645
03646 if (TREE_STATIC (decl))
03647 {
03648
03649
03650 char *name;
03651
03652 ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
03653 compound_literal_number);
03654 compound_literal_number++;
03655 DECL_NAME (decl) = get_identifier (name);
03656 DECL_DEFER_OUTPUT (decl) = 1;
03657 DECL_COMDAT (decl) = 1;
03658 DECL_ARTIFICIAL (decl) = 1;
03659 DECL_IGNORED_P (decl) = 1;
03660 pushdecl (decl);
03661 rest_of_decl_compilation (decl, 1, 0);
03662 }
03663
03664 return complit;
03665 }
03666
03667
03668
03669
03670 static bool
03671 flexible_array_type_p (tree type)
03672 {
03673 tree x;
03674 switch (TREE_CODE (type))
03675 {
03676 case RECORD_TYPE:
03677 x = TYPE_FIELDS (type);
03678 if (x == NULL_TREE)
03679 return false;
03680 while (TREE_CHAIN (x) != NULL_TREE)
03681 x = TREE_CHAIN (x);
03682 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
03683 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
03684 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
03685 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
03686 return true;
03687 return false;
03688 case UNION_TYPE:
03689 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
03690 {
03691 if (flexible_array_type_p (TREE_TYPE (x)))
03692 return true;
03693 }
03694 return false;
03695 default:
03696 return false;
03697 }
03698 }
03699
03700
03701
03702 static void
03703 check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
03704 {
03705 tree type_mv;
03706 unsigned int max_width;
03707 unsigned HOST_WIDE_INT w;
03708 const char *name = orig_name ? orig_name: _("<anonymous>");
03709
03710
03711 STRIP_NOPS (*width);
03712
03713
03714
03715 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))
03716 || TREE_CODE (*width) != INTEGER_CST)
03717 {
03718 error ("bit-field %qs width not an integer constant", name);
03719 *width = integer_one_node;
03720 }
03721 else
03722 {
03723 constant_expression_warning (*width);
03724 if (tree_int_cst_sgn (*width) < 0)
03725 {
03726 error ("negative width in bit-field %qs", name);
03727 *width = integer_one_node;
03728 }
03729 else if (integer_zerop (*width) && orig_name)
03730 {
03731 error ("zero width for bit-field %qs", name);
03732 *width = integer_one_node;
03733 }
03734 }
03735
03736
03737 if (TREE_CODE (*type) != INTEGER_TYPE
03738 && TREE_CODE (*type) != BOOLEAN_TYPE
03739 && TREE_CODE (*type) != ENUMERAL_TYPE)
03740 {
03741 error ("bit-field %qs has invalid type", name);
03742 *type = unsigned_type_node;
03743 }
03744
03745 type_mv = TYPE_MAIN_VARIANT (*type);
03746 if (pedantic
03747 && type_mv != integer_type_node
03748 && type_mv != unsigned_type_node
03749 && type_mv != boolean_type_node)
03750 pedwarn ("type of bit-field %qs is a GCC extension", name);
03751
03752 if (type_mv == boolean_type_node)
03753 max_width = CHAR_TYPE_SIZE;
03754 else
03755 max_width = TYPE_PRECISION (*type);
03756
03757 if (0 < compare_tree_int (*width, max_width))
03758 {
03759 error ("width of %qs exceeds its type", name);
03760 w = max_width;
03761 *width = build_int_cst (NULL_TREE, w);
03762 }
03763 else
03764 w = tree_low_cst (*width, 1);
03765
03766 if (TREE_CODE (*type) == ENUMERAL_TYPE)
03767 {
03768 struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
03769 if (!lt
03770 || w < min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
03771 || w < min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
03772 warning ("%qs is narrower than values of its type", name);
03773 }
03774 }
03775
03776
03777 static tree
03778 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
03779 {
03780
03781
03782
03783
03784
03785
03786 if (width == TYPE_PRECISION (integer_type_node))
03787 return unsignedp ? unsigned_type_node : integer_type_node;
03788 if (width == TYPE_PRECISION (signed_char_type_node))
03789 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
03790 if (width == TYPE_PRECISION (short_integer_type_node))
03791 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
03792 if (width == TYPE_PRECISION (long_integer_type_node))
03793 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
03794 if (width == TYPE_PRECISION (long_long_integer_type_node))
03795 {
03796 #ifdef TARG_SL
03797
03798 if (Long_Long_Support == TRUE)
03799 {
03800 return (unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node);
03801 }
03802 else
03803 {
03804 warning("\"long long\" is mapped to \"long\", "
03805 "Please use \"-mlong-long\" option to enbale long long type suporting");
03806 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
03807 }
03808
03809 #else
03810
03811 return (unsignedp ? long_long_unsigned_type_node
03812 : long_long_integer_type_node);
03813
03814 #endif
03815
03816 }
03817 return build_nonstandard_integer_type (width, unsignedp);
03818 }
03819
03820
03821
03822
03823
03824
03825
03826
03827
03828
03829
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845
03846
03847
03848
03849 static tree
03850 grokdeclarator (const struct c_declarator *declarator,
03851 struct c_declspecs *declspecs,
03852 enum decl_context decl_context, bool initialized, tree *width)
03853 {
03854 tree type = declspecs->type;
03855 bool threadp = declspecs->thread_p;
03856 enum c_storage_class storage_class = declspecs->storage_class;
03857 int constp;
03858 int restrictp;
03859 int volatilep;
03860 int type_quals = TYPE_UNQUALIFIED;
03861 const char *name, *orig_name;
03862 tree typedef_type = 0;
03863 int funcdef_flag = 0;
03864 bool funcdef_syntax = false;
03865 int size_varies = 0;
03866 tree decl_attr = declspecs->decl_attr;
03867 int array_ptr_quals = TYPE_UNQUALIFIED;
03868 tree array_ptr_attrs = NULL_TREE;
03869 int array_parm_static = 0;
03870 tree returned_attrs = NULL_TREE;
03871 bool bitfield = width != NULL;
03872 tree element_type;
03873 struct c_arg_info *arg_info = 0;
03874
03875 if (decl_context == FUNCDEF)
03876 funcdef_flag = 1, decl_context = NORMAL;
03877
03878
03879
03880 {
03881 const struct c_declarator *decl = declarator;
03882 name = 0;
03883
03884 while (decl)
03885 switch (decl->kind)
03886 {
03887 case cdk_function:
03888 case cdk_array:
03889 case cdk_pointer:
03890 funcdef_syntax = (decl->kind == cdk_function);
03891 decl = decl->declarator;
03892 break;
03893
03894 case cdk_attrs:
03895 decl = decl->declarator;
03896 break;
03897
03898 case cdk_id:
03899 if (decl->u.id)
03900 name = IDENTIFIER_POINTER (decl->u.id);
03901 decl = 0;
03902 break;
03903
03904 default:
03905 gcc_unreachable ();
03906 }
03907 orig_name = name;
03908 if (name == 0)
03909 name = "type name";
03910 }
03911
03912
03913
03914
03915 if (funcdef_flag && !funcdef_syntax)
03916 return 0;
03917
03918
03919
03920
03921 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
03922 decl_context = PARM;
03923
03924 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
03925 warn_deprecated_use (declspecs->type);
03926
03927 typedef_type = type;
03928 size_varies = C_TYPE_VARIABLE_SIZE (type);
03929
03930
03931
03932 if (declspecs->default_int_p && !in_system_header)
03933 {
03934
03935
03936
03937 if ((warn_implicit_int || warn_return_type || flag_isoc99)
03938 && funcdef_flag)
03939 warn_about_return_type = 1;
03940 else if (warn_implicit_int || flag_isoc99)
03941 pedwarn_c99 ("type defaults to %<int%> in declaration of %qs", name);
03942 }
03943
03944
03945
03946
03947 if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
03948 && TREE_CODE (type) == INTEGER_TYPE)
03949 type = c_common_unsigned_type (type);
03950
03951
03952
03953
03954
03955
03956
03957
03958
03959
03960
03961
03962 element_type = strip_array_types (type);
03963 constp = declspecs->const_p + TYPE_READONLY (element_type);
03964 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
03965 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
03966 if (pedantic && !flag_isoc99)
03967 {
03968 if (constp > 1)
03969 pedwarn ("duplicate %<const%>");
03970 if (restrictp > 1)
03971 pedwarn ("duplicate %<restrict%>");
03972 if (volatilep > 1)
03973 pedwarn ("duplicate %<volatile%>");
03974 }
03975 if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
03976 type = TYPE_MAIN_VARIANT (type);
03977 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
03978 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
03979 | (volatilep ? TYPE_QUAL_VOLATILE : 0));
03980
03981
03982
03983
03984 if (funcdef_flag
03985 && (threadp
03986 || storage_class == csc_auto
03987 || storage_class == csc_register
03988 || storage_class == csc_typedef))
03989 {
03990 if (storage_class == csc_auto
03991 && (pedantic || current_scope == file_scope))
03992 pedwarn ("function definition declared %<auto%>");
03993 if (storage_class == csc_register)
03994 error ("function definition declared %<register%>");
03995 if (storage_class == csc_typedef)
03996 error ("function definition declared %<typedef%>");
03997 if (threadp)
03998 error ("function definition declared %<__thread%>");
03999 threadp = false;
04000 if (storage_class == csc_auto
04001 || storage_class == csc_register
04002 || storage_class == csc_typedef)
04003 storage_class = csc_none;
04004 }
04005 else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
04006 {
04007 if (decl_context == PARM && storage_class == csc_register)
04008 ;
04009 else
04010 {
04011 switch (decl_context)
04012 {
04013 case FIELD:
04014 error ("storage class specified for structure field %qs",
04015 name);
04016 break;
04017 case PARM:
04018 error ("storage class specified for parameter %qs", name);
04019 break;
04020 default:
04021 error ("storage class specified for typename");
04022 break;
04023 }
04024 storage_class = csc_none;
04025 threadp = false;
04026 }
04027 }
04028 else if (storage_class == csc_extern
04029 && initialized
04030 && !funcdef_flag)
04031 {
04032
04033 if (current_scope == file_scope)
04034 warning ("%qs initialized and declared %<extern%>", name);
04035 else
04036 error ("%qs has both %<extern%> and initializer", name);
04037 }
04038 else if (current_scope == file_scope)
04039 {
04040 if (storage_class == csc_auto)
04041 error ("file-scope declaration of %qs specifies %<auto%>", name);
04042 if (pedantic && storage_class == csc_register)
04043 pedwarn ("file-scope declaration of %qs specifies %<register%>", name);
04044 }
04045 else
04046 {
04047 if (storage_class == csc_extern && funcdef_flag)
04048 error ("nested function %qs declared %<extern%>", name);
04049 else if (threadp && storage_class == csc_none)
04050 {
04051 error ("function-scope %qs implicitly auto and declared "
04052 "%<__thread%>",
04053 name);
04054 threadp = false;
04055 }
04056 }
04057
04058
04059
04060
04061
04062
04063
04064
04065
04066
04067
04068 while (declarator && declarator->kind != cdk_id)
04069 {
04070 if (type == error_mark_node)
04071 {
04072 declarator = declarator->declarator;
04073 continue;
04074 }
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091 if (array_ptr_quals != TYPE_UNQUALIFIED
04092 || array_ptr_attrs != NULL_TREE
04093 || array_parm_static)
04094 {
04095
04096
04097
04098 error ("static or type qualifiers in non-parameter array declarator");
04099 array_ptr_quals = TYPE_UNQUALIFIED;
04100 array_ptr_attrs = NULL_TREE;
04101 array_parm_static = 0;
04102 }
04103
04104 switch (declarator->kind)
04105 {
04106 case cdk_attrs:
04107 {
04108
04109 tree attrs = declarator->u.attrs;
04110 const struct c_declarator *inner_decl;
04111 int attr_flags = 0;
04112 declarator = declarator->declarator;
04113 inner_decl = declarator;
04114 while (inner_decl->kind == cdk_attrs)
04115 inner_decl = inner_decl->declarator;
04116 if (inner_decl->kind == cdk_id)
04117 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
04118 else if (inner_decl->kind == cdk_function)
04119 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
04120 else if (inner_decl->kind == cdk_array)
04121 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
04122 returned_attrs = decl_attributes (&type,
04123 chainon (returned_attrs, attrs),
04124 attr_flags);
04125 break;
04126 }
04127 case cdk_array:
04128 {
04129 tree itype = NULL_TREE;
04130 tree size = declarator->u.array.dimen;
04131
04132 tree index_type = c_common_signed_type (sizetype);
04133
04134 array_ptr_quals = declarator->u.array.quals;
04135 array_ptr_attrs = declarator->u.array.attrs;
04136 array_parm_static = declarator->u.array.static_p;
04137
04138 declarator = declarator->declarator;
04139
04140
04141
04142 if (VOID_TYPE_P (type))
04143 {
04144 error ("declaration of %qs as array of voids", name);
04145 type = error_mark_node;
04146 }
04147
04148 if (TREE_CODE (type) == FUNCTION_TYPE)
04149 {
04150 error ("declaration of %qs as array of functions", name);
04151 type = error_mark_node;
04152 }
04153
04154 if (pedantic && !in_system_header && flexible_array_type_p (type))
04155 pedwarn ("invalid use of structure with flexible array member");
04156
04157 if (size == error_mark_node)
04158 type = error_mark_node;
04159
04160 if (type == error_mark_node)
04161 continue;
04162
04163
04164
04165
04166
04167 if (size)
04168 {
04169
04170
04171 STRIP_TYPE_NOPS (size);
04172
04173 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
04174 {
04175 error ("size of array %qs has non-integer type", name);
04176 size = integer_one_node;
04177 }
04178
04179 if (pedantic && integer_zerop (size))
04180 pedwarn ("ISO C forbids zero-size array %qs", name);
04181
04182 if (TREE_CODE (size) == INTEGER_CST)
04183 {
04184 constant_expression_warning (size);
04185 if (tree_int_cst_sgn (size) < 0)
04186 {
04187 error ("size of array %qs is negative", name);
04188 size = integer_one_node;
04189 }
04190 }
04191 else
04192 {
04193
04194
04195
04196 size_varies = 1;
04197
04198 if (!flag_isoc99 && pedantic)
04199 {
04200 if (TREE_CONSTANT (size))
04201 pedwarn ("ISO C90 forbids array %qs whose size "
04202 "can%'t be evaluated",
04203 name);
04204 else
04205 pedwarn ("ISO C90 forbids variable-size array %qs",
04206 name);
04207 }
04208 }
04209
04210 if (integer_zerop (size))
04211 {
04212
04213
04214
04215
04216 itype = build_range_type (sizetype, size, NULL_TREE);
04217 }
04218 else
04219 {
04220
04221
04222
04223 if (size_varies)
04224 size = variable_size (size);
04225
04226
04227
04228
04229
04230 itype = fold (build2 (MINUS_EXPR, index_type,
04231 convert (index_type, size),
04232 convert (index_type,
04233 size_one_node)));
04234
04235
04236
04237
04238
04239
04240
04241
04242 if (TREE_OVERFLOW (itype))
04243 {
04244 error ("size of array %qs is too large", name);
04245 type = error_mark_node;
04246 continue;
04247 }
04248
04249 itype = build_index_type (itype);
04250 }
04251 }
04252 else if (decl_context == FIELD)
04253 {
04254 if (pedantic && !flag_isoc99 && !in_system_header)
04255 pedwarn ("ISO C90 does not support flexible array members");
04256
04257
04258
04259 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
04260 }
04261
04262
04263 if (!COMPLETE_TYPE_P (type))
04264 {
04265 error ("array type has incomplete element type");
04266 type = error_mark_node;
04267 }
04268 else
04269 type = build_array_type (type, itype);
04270
04271 if (size_varies)
04272 C_TYPE_VARIABLE_SIZE (type) = 1;
04273
04274
04275
04276
04277 if (size && integer_zerop (size))
04278 {
04279 TYPE_SIZE (type) = bitsize_zero_node;
04280 TYPE_SIZE_UNIT (type) = size_zero_node;
04281 }
04282
04283 if (decl_context != PARM
04284 && (array_ptr_quals != TYPE_UNQUALIFIED
04285 || array_ptr_attrs != NULL_TREE
04286 || array_parm_static))
04287 {
04288 error ("static or type qualifiers in non-parameter array declarator");
04289 array_ptr_quals = TYPE_UNQUALIFIED;
04290 array_ptr_attrs = NULL_TREE;
04291 array_parm_static = 0;
04292 }
04293 break;
04294 }
04295 case cdk_function:
04296 {
04297
04298
04299
04300 bool really_funcdef = false;
04301 tree arg_types;
04302 if (funcdef_flag)
04303 {
04304 const struct c_declarator *t = declarator->declarator;
04305 while (t->kind == cdk_attrs)
04306 t = t->declarator;
04307 really_funcdef = (t->kind == cdk_id);
04308 }
04309
04310
04311
04312 if (type == error_mark_node)
04313 continue;
04314
04315 size_varies = 0;
04316
04317
04318 if (TREE_CODE (type) == FUNCTION_TYPE)
04319 {
04320 error ("%qs declared as function returning a function", name);
04321 type = integer_type_node;
04322 }
04323 if (TREE_CODE (type) == ARRAY_TYPE)
04324 {
04325 error ("%qs declared as function returning an array", name);
04326 type = integer_type_node;
04327 }
04328
04329
04330
04331 arg_info = declarator->u.arg_info;
04332 arg_types = grokparms (arg_info, really_funcdef);
04333
04334
04335
04336 if (type_quals)
04337 {
04338
04339
04340
04341
04342
04343
04344 if (VOID_TYPE_P (type) && really_funcdef)
04345 pedwarn ("function definition has qualified void return type");
04346 else if (warn_return_type)
04347 warning ("type qualifiers ignored on function return type");
04348
04349 type = c_build_qualified_type (type, type_quals);
04350 }
04351 type_quals = TYPE_UNQUALIFIED;
04352
04353 type = build_function_type (type, arg_types);
04354 declarator = declarator->declarator;
04355
04356
04357
04358
04359 {
04360 tree link;
04361
04362 for (link = arg_info->tags;
04363 link;
04364 link = TREE_CHAIN (link))
04365 TYPE_CONTEXT (TREE_VALUE (link)) = type;
04366 }
04367 break;
04368 }
04369 case cdk_pointer:
04370 {
04371
04372
04373
04374 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
04375 && type_quals)
04376 pedwarn ("ISO C forbids qualified function types");
04377 if (type_quals)
04378 type = c_build_qualified_type (type, type_quals);
04379 size_varies = 0;
04380
04381 type = build_pointer_type (type);
04382
04383
04384
04385 type_quals = declarator->u.pointer_quals;
04386
04387 declarator = declarator->declarator;
04388 break;
04389 }
04390 default:
04391 gcc_unreachable ();
04392 }
04393 }
04394
04395
04396
04397
04398
04399 if (bitfield)
04400 check_bitfield_type_and_width (&type, width, orig_name);
04401
04402
04403
04404 if (TREE_CODE (type) == ARRAY_TYPE
04405 && COMPLETE_TYPE_P (type)
04406 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
04407 {
04408 error ("size of array %qs is too large", name);
04409
04410
04411 type = error_mark_node;
04412 }
04413
04414
04415
04416 if (storage_class == csc_typedef)
04417 {
04418 tree decl;
04419 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
04420 && type_quals)
04421 pedwarn ("ISO C forbids qualified function types");
04422 if (type_quals)
04423 type = c_build_qualified_type (type, type_quals);
04424 decl = build_decl (TYPE_DECL, declarator->u.id, type);
04425 if (declspecs->explicit_signed_p)
04426 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
04427 decl_attributes (&decl, returned_attrs, 0);
04428 if (declspecs->inline_p)
04429 pedwarn ("%Jtypedef %qD declared %<inline%>", decl, decl);
04430 return decl;
04431 }
04432
04433
04434
04435
04436
04437
04438
04439 if (type != 0 && typedef_type != 0
04440 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
04441 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
04442 {
04443 type = build_array_type (TREE_TYPE (type), 0);
04444 if (size_varies)
04445 C_TYPE_VARIABLE_SIZE (type) = 1;
04446 }
04447
04448
04449
04450
04451 if (decl_context == TYPENAME)
04452 {
04453
04454
04455 gcc_assert (storage_class == csc_none && !threadp
04456 && !declspecs->inline_p);
04457 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
04458 && type_quals)
04459 pedwarn ("ISO C forbids const or volatile function types");
04460 if (type_quals)
04461 type = c_build_qualified_type (type, type_quals);
04462 decl_attributes (&type, returned_attrs, 0);
04463 return type;
04464 }
04465
04466
04467
04468
04469
04470
04471
04472 if (VOID_TYPE_P (type) && decl_context != PARM
04473 && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
04474 && (storage_class == csc_extern
04475 || (current_scope == file_scope
04476 && !(storage_class == csc_static
04477 || storage_class == csc_register)))))
04478 {
04479 error ("variable or field %qs declared void", name);
04480 type = integer_type_node;
04481 }
04482
04483
04484
04485
04486 {
04487 tree decl;
04488
04489 if (decl_context == PARM)
04490 {
04491 tree type_as_written;
04492 tree promoted_type;
04493
04494
04495
04496
04497 if (TREE_CODE (type) == ARRAY_TYPE)
04498 {
04499
04500 type = TREE_TYPE (type);
04501 if (type_quals)
04502 type = c_build_qualified_type (type, type_quals);
04503 type = build_pointer_type (type);
04504 type_quals = array_ptr_quals;
04505
04506
04507 if (array_ptr_attrs != NULL_TREE)
04508 warning ("attributes in parameter array declarator ignored");
04509
04510 size_varies = 0;
04511 }
04512 else if (TREE_CODE (type) == FUNCTION_TYPE)
04513 {
04514 if (pedantic && type_quals)
04515 pedwarn ("ISO C forbids qualified function types");
04516 if (type_quals)
04517 type = c_build_qualified_type (type, type_quals);
04518 type = build_pointer_type (type);
04519 type_quals = TYPE_UNQUALIFIED;
04520 }
04521 else if (type_quals)
04522 type = c_build_qualified_type (type, type_quals);
04523
04524 type_as_written = type;
04525
04526 decl = build_decl (PARM_DECL, declarator->u.id, type);
04527 if (size_varies)
04528 C_DECL_VARIABLE_SIZE (decl) = 1;
04529
04530
04531
04532
04533
04534
04535 if (type == error_mark_node)
04536 promoted_type = type;
04537 else
04538 promoted_type = c_type_promotes_to (type);
04539
04540 DECL_ARG_TYPE (decl) = promoted_type;
04541 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
04542 if (declspecs->inline_p)
04543 pedwarn ("%Jparameter %qD declared %<inline%>", decl, decl);
04544 }
04545 else if (decl_context == FIELD)
04546 {
04547
04548
04549 gcc_assert (storage_class == csc_none && !threadp
04550 && !declspecs->inline_p);
04551
04552
04553
04554 if (TREE_CODE (type) == FUNCTION_TYPE)
04555 {
04556 error ("field %qs declared as a function", name);
04557 type = build_pointer_type (type);
04558 }
04559 else if (TREE_CODE (type) != ERROR_MARK
04560 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
04561 {
04562 error ("field %qs has incomplete type", name);
04563 type = error_mark_node;
04564 }
04565 type = c_build_qualified_type (type, type_quals);
04566 decl = build_decl (FIELD_DECL, declarator->u.id, type);
04567 DECL_NONADDRESSABLE_P (decl) = bitfield;
04568
04569 if (size_varies)
04570 C_DECL_VARIABLE_SIZE (decl) = 1;
04571 }
04572 else if (TREE_CODE (type) == FUNCTION_TYPE)
04573 {
04574 if (storage_class == csc_register || threadp)
04575 {
04576 error ("invalid storage class for function %qs", name);
04577 }
04578 else if (current_scope != file_scope)
04579 {
04580
04581
04582
04583
04584
04585 if (storage_class == csc_auto)
04586 {
04587 if (pedantic)
04588 pedwarn ("invalid storage class for function %qs", name);
04589 }
04590 else if (storage_class == csc_static)
04591 {
04592 error ("invalid storage class for function %qs", name);
04593 if (funcdef_flag)
04594 storage_class = declspecs->storage_class = csc_none;
04595 else
04596 return 0;
04597 }
04598 }
04599
04600 decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
04601 decl = build_decl_attribute_variant (decl, decl_attr);
04602
04603 DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
04604
04605 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
04606 pedwarn ("ISO C forbids qualified function types");
04607
04608
04609
04610 if ((type_quals & TYPE_QUAL_VOLATILE)
04611 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
04612 warning ("%<noreturn%> function returns non-void value");
04613
04614
04615
04616
04617
04618
04619 if (storage_class == csc_auto && current_scope != file_scope)
04620 DECL_EXTERNAL (decl) = 0;
04621 else
04622 DECL_EXTERNAL (decl) = 1;
04623
04624
04625 TREE_PUBLIC (decl)
04626 = !(storage_class == csc_static || storage_class == csc_auto);
04627
04628
04629
04630 if (funcdef_flag)
04631 current_function_arg_info = arg_info;
04632
04633 if (declspecs->default_int_p)
04634 C_FUNCTION_IMPLICIT_INT (decl) = 1;
04635
04636
04637 if (flag_hosted && MAIN_NAME_P (declarator->u.id))
04638 {
04639 if (declspecs->inline_p)
04640 pedwarn ("cannot inline function %<main%>");
04641 }
04642 else if (declspecs->inline_p)
04643 {
04644
04645 DECL_DECLARED_INLINE_P (decl) = 1;
04646
04647
04648
04649
04650
04651 if (initialized)
04652 {
04653 DECL_INLINE (decl) = 1;
04654 if (storage_class == csc_extern)
04655 current_extern_inline = 1;
04656 }
04657 }
04658
04659
04660
04661 else if (flag_inline_trees == 2 && initialized)
04662 DECL_INLINE (decl) = 1;
04663 }
04664 else
04665 {
04666
04667
04668 int extern_ref = !initialized && storage_class == csc_extern;
04669
04670 type = c_build_qualified_type (type, type_quals);
04671
04672
04673
04674
04675
04676
04677
04678 if (extern_ref && current_scope != file_scope)
04679 {
04680 tree global_decl = identifier_global_value (declarator->u.id);
04681 tree visible_decl = lookup_name (declarator->u.id);
04682
04683 if (global_decl
04684 && global_decl != visible_decl
04685 && TREE_CODE (global_decl) == VAR_DECL
04686 && !TREE_PUBLIC (global_decl))
04687 error ("variable previously declared %<static%> redeclared "
04688 "%<extern%>");
04689 }
04690
04691 decl = build_decl (VAR_DECL, declarator->u.id, type);
04692 if (size_varies)
04693 C_DECL_VARIABLE_SIZE (decl) = 1;
04694
04695 if (declspecs->inline_p)
04696 pedwarn ("%Jvariable %qD declared %<inline%>", decl, decl);
04697
04698
04699
04700
04701 DECL_EXTERNAL (decl) = (storage_class == csc_extern);
04702
04703
04704
04705
04706
04707 if (current_scope == file_scope)
04708 {
04709 TREE_PUBLIC (decl) = !(storage_class == csc_static
04710 || storage_class == csc_register);
04711 TREE_STATIC (decl) = !extern_ref;
04712 }
04713
04714 else
04715 {
04716 TREE_STATIC (decl) = (storage_class == csc_static);
04717 TREE_PUBLIC (decl) = extern_ref;
04718 }
04719
04720 if (threadp)
04721 {
04722 if (targetm.have_tls)
04723 DECL_THREAD_LOCAL (decl) = 1;
04724 else
04725
04726
04727 error ("thread-local storage not supported for this target");
04728 }
04729 }
04730
04731
04732
04733
04734 if (storage_class == csc_register)
04735 {
04736 C_DECL_REGISTER (decl) = 1;
04737 DECL_REGISTER (decl) = 1;
04738 }
04739
04740
04741 c_apply_type_quals_to_decl (type_quals, decl);
04742
04743
04744
04745
04746 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
04747 {
04748
04749
04750
04751 int was_reg = C_DECL_REGISTER (decl);
04752 C_DECL_REGISTER (decl) = 0;
04753 DECL_REGISTER (decl) = 0;
04754 c_mark_addressable (decl);
04755 C_DECL_REGISTER (decl) = was_reg;
04756 }
04757
04758
04759
04760 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
04761
04762 decl_attributes (&decl, returned_attrs, 0);
04763
04764 return decl;
04765 }
04766 }
04767
04768
04769
04770
04771
04772
04773
04774
04775
04776
04777
04778
04779
04780
04781
04782 static tree
04783 grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
04784 {
04785 tree arg_types = arg_info->types;
04786
04787 if (warn_strict_prototypes && arg_types == 0 && !funcdef_flag
04788 && !in_system_header)
04789 warning ("function declaration isn%'t a prototype");
04790
04791 if (arg_types == error_mark_node)
04792 return 0;
04793
04794 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
04795 {
04796 if (!funcdef_flag)
04797 pedwarn ("parameter names (without types) in function declaration");
04798
04799 arg_info->parms = arg_info->types;
04800 arg_info->types = 0;
04801 return 0;
04802 }
04803 else
04804 {
04805 tree parm, type, typelt;
04806 unsigned int parmno;
04807
04808
04809
04810
04811
04812
04813
04814
04815
04816
04817 for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
04818 parm;
04819 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
04820 {
04821 type = TREE_VALUE (typelt);
04822 if (type == error_mark_node)
04823 continue;
04824
04825 if (!COMPLETE_TYPE_P (type))
04826 {
04827 if (funcdef_flag)
04828 {
04829 if (DECL_NAME (parm))
04830 error ("%Jparameter %u (%qD) has incomplete type",
04831 parm, parmno, parm);
04832 else
04833 error ("%Jparameter %u has incomplete type",
04834 parm, parmno);
04835
04836 TREE_VALUE (typelt) = error_mark_node;
04837 TREE_TYPE (parm) = error_mark_node;
04838 }
04839 else if (VOID_TYPE_P (type))
04840 {
04841 if (DECL_NAME (parm))
04842 warning ("%Jparameter %u (%qD) has void type",
04843 parm, parmno, parm);
04844 else
04845 warning ("%Jparameter %u has void type",
04846 parm, parmno);
04847 }
04848 }
04849 }
04850 return arg_types;
04851 }
04852 }
04853
04854
04855
04856
04857
04858
04859
04860
04861
04862 struct c_arg_info *
04863 get_parm_info (bool ellipsis)
04864 {
04865 struct c_binding *b = current_scope->bindings;
04866 struct c_arg_info *arg_info = XOBNEW (&parser_obstack,
04867 struct c_arg_info);
04868 tree parms = 0;
04869 tree tags = 0;
04870 tree types = 0;
04871 tree others = 0;
04872
04873 static bool explained_incomplete_types = false;
04874 bool gave_void_only_once_err = false;
04875
04876 arg_info->parms = 0;
04877 arg_info->tags = 0;
04878 arg_info->types = 0;
04879 arg_info->others = 0;
04880
04881
04882
04883 current_scope->bindings = 0;
04884
04885
04886
04887 gcc_assert (b);
04888
04889
04890
04891
04892
04893
04894 if (b->prev == 0
04895 && TREE_CODE (b->decl) == PARM_DECL
04896 && !DECL_NAME (b->decl)
04897 && VOID_TYPE_P (TREE_TYPE (b->decl)))
04898 {
04899 if (TREE_THIS_VOLATILE (b->decl)
04900 || TREE_READONLY (b->decl)
04901 || C_DECL_REGISTER (b->decl))
04902 error ("%<void%> as only parameter may not be qualified");
04903
04904
04905 if (ellipsis)
04906 error ("%<void%> must be the only parameter");
04907
04908 arg_info->types = void_list_node;
04909 return arg_info;
04910 }
04911
04912 if (!ellipsis)
04913 types = void_list_node;
04914
04915
04916
04917 while (b)
04918 {
04919 tree decl = b->decl;
04920 tree type = TREE_TYPE (decl);
04921 const char *keyword;
04922
04923 switch (TREE_CODE (decl))
04924 {
04925 case PARM_DECL:
04926 if (b->id)
04927 {
04928 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
04929 I_SYMBOL_BINDING (b->id) = b->shadowed;
04930 }
04931
04932
04933 if (TREE_ASM_WRITTEN (decl))
04934 error ("%Jparameter %qD has just a forward declaration",
04935 decl, decl);
04936
04937 else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
04938 {
04939 if (!gave_void_only_once_err)
04940 {
04941 error ("%<void%> must be the only parameter");
04942 gave_void_only_once_err = true;
04943 }
04944 }
04945 else
04946 {
04947
04948 TREE_CHAIN (decl) = parms;
04949 parms = decl;
04950
04951
04952
04953 DECL_ARG_TYPE (decl) = type;
04954 types = tree_cons (0, type, types);
04955 }
04956 break;
04957
04958 case ENUMERAL_TYPE: keyword = "enum"; goto tag;
04959 case UNION_TYPE: keyword = "union"; goto tag;
04960 case RECORD_TYPE: keyword = "struct"; goto tag;
04961 tag:
04962
04963
04964 if (b->id)
04965 {
04966 gcc_assert (I_TAG_BINDING (b->id) == b);
04967 I_TAG_BINDING (b->id) = b->shadowed;
04968 }
04969
04970
04971
04972
04973
04974
04975
04976 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
04977 {
04978 if (b->id)
04979
04980 warning ("%<%s %E%> declared inside parameter list",
04981 keyword, b->id);
04982 else
04983
04984 warning ("anonymous %s declared inside parameter list",
04985 keyword);
04986
04987 if (!explained_incomplete_types)
04988 {
04989 warning ("its scope is only this definition or declaration,"
04990 " which is probably not what you want");
04991 explained_incomplete_types = true;
04992 }
04993 }
04994
04995 tags = tree_cons (b->id, decl, tags);
04996 break;
04997
04998 case CONST_DECL:
04999 case TYPE_DECL:
05000 case FUNCTION_DECL:
05001
05002
05003
05004
05005
05006
05007 TREE_CHAIN (decl) = others;
05008 others = decl;
05009
05010
05011 case ERROR_MARK:
05012
05013
05014 if (b->id)
05015 {
05016 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
05017 I_SYMBOL_BINDING (b->id) = b->shadowed;
05018 }
05019 break;
05020
05021
05022 case LABEL_DECL:
05023 case VAR_DECL:
05024 default:
05025 gcc_unreachable ();
05026 }
05027
05028 b = free_binding_and_advance (b);
05029 }
05030
05031 arg_info->parms = parms;
05032 arg_info->tags = tags;
05033 arg_info->types = types;
05034 arg_info->others = others;
05035 return arg_info;
05036 }
05037
05038
05039
05040
05041
05042 struct c_typespec
05043 parser_xref_tag (enum tree_code code, tree name)
05044 {
05045 struct c_typespec ret;
05046
05047
05048
05049 tree ref = lookup_tag (code, name, 0);
05050
05051
05052
05053
05054
05055
05056
05057
05058
05059
05060
05061 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
05062 if (ref && TREE_CODE (ref) == code)
05063 {
05064 ret.spec = ref;
05065 return ret;
05066 }
05067
05068
05069
05070
05071
05072
05073 ref = make_node (code);
05074 if (code == ENUMERAL_TYPE)
05075 {
05076
05077
05078 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
05079 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
05080 TYPE_USER_ALIGN (ref) = 0;
05081 TYPE_UNSIGNED (ref) = 1;
05082 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
05083 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
05084 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
05085 }
05086
05087 pushtag (name, ref);
05088
05089 ret.spec = ref;
05090 return ret;
05091 }
05092
05093
05094
05095
05096
05097 tree
05098 xref_tag (enum tree_code code, tree name)
05099 {
05100 return parser_xref_tag (code, name).spec;
05101 }
05102
05103
05104
05105
05106
05107 tree
05108 start_struct (enum tree_code code, tree name)
05109 {
05110
05111
05112
05113 tree ref = 0;
05114
05115 if (name != 0)
05116 ref = lookup_tag (code, name, 1);
05117 if (ref && TREE_CODE (ref) == code)
05118 {
05119 if (TYPE_SIZE (ref))
05120 {
05121 if (code == UNION_TYPE)
05122 error ("redefinition of %<union %s%>", IDENTIFIER_POINTER (name));
05123 else
05124 error ("redefinition of %<struct %s%>", IDENTIFIER_POINTER (name));
05125 }
05126 else if (C_TYPE_BEING_DEFINED (ref))
05127 {
05128 if (code == UNION_TYPE)
05129 error ("nested redefinition of %<union %s%>",
05130 IDENTIFIER_POINTER (name));
05131 else
05132 error ("nested redefinition of %<struct %s%>",
05133 IDENTIFIER_POINTER (name));
05134 }
05135 }
05136 else
05137 {
05138
05139
05140 ref = make_node (code);
05141 pushtag (name, ref);
05142 }
05143
05144 C_TYPE_BEING_DEFINED (ref) = 1;
05145 TYPE_PACKED (ref) = flag_pack_struct;
05146 return ref;
05147 }
05148
05149
05150
05151
05152
05153
05154
05155
05156
05157 tree
05158 grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs,
05159 tree width)
05160 {
05161 tree value;
05162
05163 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
05164 && width == NULL_TREE)
05165 {
05166
05167
05168
05169
05170
05171
05172
05173
05174
05175
05176
05177
05178
05179
05180
05181
05182
05183
05184
05185 tree type = declspecs->type;
05186 bool type_ok = (TREE_CODE (type) == RECORD_TYPE
05187 || TREE_CODE (type) == UNION_TYPE);
05188 bool ok = false;
05189
05190 if (type_ok
05191 && (flag_ms_extensions || !declspecs->typedef_p))
05192 {
05193 if (flag_ms_extensions)
05194 ok = true;
05195 else if (flag_iso)
05196 ok = false;
05197 else if (TYPE_NAME (type) == NULL)
05198 ok = true;
05199 else
05200 ok = false;
05201 }
05202 if (!ok)
05203 {
05204 pedwarn ("declaration does not declare anything");
05205 return NULL_TREE;
05206 }
05207 if (pedantic)
05208 pedwarn ("ISO C doesn%'t support unnamed structs/unions");
05209 }
05210
05211 value = grokdeclarator (declarator, declspecs, FIELD, false,
05212 width ? &width : NULL);
05213
05214 finish_decl (value, NULL_TREE, NULL_TREE);
05215 DECL_INITIAL (value) = width;
05216
05217 return value;
05218 }
05219
05220
05221
05222
05223 static void
05224 detect_field_duplicates (tree fieldlist)
05225 {
05226 tree x, y;
05227 int timeout = 10;
05228
05229
05230
05231 if (!fieldlist)
05232 return;
05233 x = TREE_CHAIN (fieldlist);
05234 if (!x)
05235 return;
05236 do {
05237 timeout--;
05238 x = TREE_CHAIN (x);
05239 } while (timeout > 0 && x);
05240
05241
05242
05243 if (timeout > 0)
05244 {
05245 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x))
05246 if (DECL_NAME (x))
05247 {
05248 for (y = fieldlist; y != x; y = TREE_CHAIN (y))
05249 if (DECL_NAME (y) == DECL_NAME (x))
05250 {
05251 error ("%Jduplicate member %qD", x, x);
05252 DECL_NAME (x) = NULL_TREE;
05253 }
05254 }
05255 }
05256 else
05257 {
05258 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
05259 void **slot;
05260
05261 for (x = fieldlist; x ; x = TREE_CHAIN (x))
05262 if ((y = DECL_NAME (x)) != 0)
05263 {
05264 slot = htab_find_slot (htab, y, INSERT);
05265 if (*slot)
05266 {
05267 error ("%Jduplicate member %qD", x, x);
05268 DECL_NAME (x) = NULL_TREE;
05269 }
05270 *slot = y;
05271 }
05272
05273 htab_delete (htab);
05274 }
05275 }
05276
05277
05278
05279
05280
05281 tree
05282 finish_struct (tree t, tree fieldlist, tree attributes)
05283 {
05284 tree x;
05285 bool toplevel = file_scope == current_scope;
05286 int saw_named_field;
05287
05288
05289
05290
05291 TYPE_SIZE (t) = 0;
05292
05293 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
05294
05295 if (pedantic)
05296 {
05297 for (x = fieldlist; x; x = TREE_CHAIN (x))
05298 if (DECL_NAME (x) != 0)
05299 break;
05300
05301 if (x == 0)
05302 {
05303 if (TREE_CODE (t) == UNION_TYPE)
05304 {
05305 if (fieldlist)
05306 pedwarn ("union has no named members");
05307 else
05308 pedwarn ("union has no members");
05309 }
05310 else
05311 {
05312 if (fieldlist)
05313 pedwarn ("struct has no named members");
05314 else
05315 pedwarn ("struct has no members");
05316 }
05317 }
05318 }
05319
05320
05321
05322
05323
05324
05325
05326
05327 saw_named_field = 0;
05328 for (x = fieldlist; x; x = TREE_CHAIN (x))
05329 {
05330 DECL_CONTEXT (x) = t;
05331 DECL_PACKED (x) |= TYPE_PACKED (t);
05332
05333
05334 if (TREE_READONLY (x))
05335 C_TYPE_FIELDS_READONLY (t) = 1;
05336 else
05337 {
05338
05339 tree t1 = TREE_TYPE (x);
05340 while (TREE_CODE (t1) == ARRAY_TYPE)
05341 t1 = TREE_TYPE (t1);
05342 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
05343 && C_TYPE_FIELDS_READONLY (t1))
05344 C_TYPE_FIELDS_READONLY (t) = 1;
05345 }
05346
05347
05348
05349 if (TREE_THIS_VOLATILE (x))
05350 C_TYPE_FIELDS_VOLATILE (t) = 1;
05351
05352
05353 if (C_DECL_VARIABLE_SIZE (x))
05354 C_TYPE_VARIABLE_SIZE (t) = 1;
05355
05356 if (DECL_INITIAL (x))
05357 {
05358 unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
05359 DECL_SIZE (x) = bitsize_int (width);
05360 DECL_BIT_FIELD (x) = 1;
05361 SET_DECL_C_BIT_FIELD (x);
05362 }
05363
05364
05365 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
05366 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
05367 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
05368 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
05369 {
05370 if (TREE_CODE (t) == UNION_TYPE)
05371 {
05372 error ("%Jflexible array member in union", x);
05373 TREE_TYPE (x) = error_mark_node;
05374 }
05375 else if (TREE_CHAIN (x) != NULL_TREE)
05376 {
05377 error ("%Jflexible array member not at end of struct", x);
05378 TREE_TYPE (x) = error_mark_node;
05379 }
05380 else if (!saw_named_field)
05381 {
05382 error ("%Jflexible array member in otherwise empty struct", x);
05383 TREE_TYPE (x) = error_mark_node;
05384 }
05385 }
05386
05387 if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
05388 && flexible_array_type_p (TREE_TYPE (x)))
05389 pedwarn ("%Jinvalid use of structure with flexible array member", x);
05390
05391 if (DECL_NAME (x))
05392 saw_named_field = 1;
05393 }
05394
05395 detect_field_duplicates (fieldlist);
05396
05397
05398
05399
05400 TYPE_FIELDS (t) = fieldlist;
05401
05402 layout_type (t);
05403
05404
05405 {
05406 tree *fieldlistp = &fieldlist;
05407 while (*fieldlistp)
05408 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
05409 && TREE_TYPE (*fieldlistp) != error_mark_node)
05410 {
05411 unsigned HOST_WIDE_INT width
05412 = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
05413 tree type = TREE_TYPE (*fieldlistp);
05414 if (width != TYPE_PRECISION (type))
05415 {
05416 TREE_TYPE (*fieldlistp)
05417 = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type));
05418 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
05419 }
05420 DECL_INITIAL (*fieldlistp) = 0;
05421 }
05422 else
05423 fieldlistp = &TREE_CHAIN (*fieldlistp);
05424 }
05425
05426
05427
05428
05429 TYPE_FIELDS (t) = fieldlist;
05430
05431
05432
05433
05434 {
05435 int len = 0;
05436
05437 for (x = fieldlist; x; x = TREE_CHAIN (x))
05438 {
05439 if (len > 15 || DECL_NAME (x) == NULL)
05440 break;
05441 len += 1;
05442 }
05443
05444 if (len > 15)
05445 {
05446 tree *field_array;
05447 struct lang_type *space;
05448 struct sorted_fields_type *space2;
05449
05450 len += list_length (x);
05451
05452
05453
05454
05455
05456 space = GGC_CNEW (struct lang_type);
05457 space2 = GGC_NEWVAR (struct sorted_fields_type,
05458 sizeof (struct sorted_fields_type) + len * sizeof (tree));
05459
05460 len = 0;
05461 space->s = space2;
05462 field_array = &space2->elts[0];
05463 for (x = fieldlist; x; x = TREE_CHAIN (x))
05464 {
05465 field_array[len++] = x;
05466
05467
05468 if (DECL_NAME (x) == NULL)
05469 break;
05470 }
05471
05472 if (x == NULL)
05473 {
05474 TYPE_LANG_SPECIFIC (t) = space;
05475 TYPE_LANG_SPECIFIC (t)->s->len = len;
05476 field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
05477 qsort (field_array, len, sizeof (tree), field_decl_cmp);
05478 }
05479 }
05480 }
05481
05482 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
05483 {
05484 TYPE_FIELDS (x) = TYPE_FIELDS (t);
05485 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
05486 TYPE_ALIGN (x) = TYPE_ALIGN (t);
05487 TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t);
05488 C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
05489 C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
05490 C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
05491 }
05492
05493
05494
05495 if (TREE_CODE (t) == UNION_TYPE
05496 && TYPE_TRANSPARENT_UNION (t)
05497 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
05498 {
05499 TYPE_TRANSPARENT_UNION (t) = 0;
05500 warning ("union cannot be made transparent");
05501 }
05502
05503
05504
05505 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
05506 x;
05507 x = TREE_CHAIN (x))
05508 {
05509 tree decl = TREE_VALUE (x);
05510 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
05511 layout_array_type (TREE_TYPE (decl));
05512 if (TREE_CODE (decl) != TYPE_DECL)
05513 {
05514 layout_decl (decl, 0);
05515 if (c_dialect_objc ())
05516 objc_check_decl (decl);
05517 rest_of_decl_compilation (decl, toplevel, 0);
05518 if (!toplevel)
05519 expand_decl (decl);
05520 }
05521 }
05522 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
05523
05524
05525 rest_of_type_compilation (t, toplevel);
05526
05527
05528
05529
05530 if (cur_stmt_list && variably_modified_type_p (t, NULL))
05531 add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t)));
05532
05533 return t;
05534 }
05535
05536
05537
05538 static void
05539 layout_array_type (tree t)
05540 {
05541 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
05542 layout_array_type (TREE_TYPE (t));
05543 layout_type (t);
05544 }
05545
05546
05547
05548
05549
05550
05551
05552 tree
05553 start_enum (tree name)
05554 {
05555 tree enumtype = 0;
05556
05557
05558
05559
05560
05561 if (name != 0)
05562 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1);
05563
05564 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
05565 {
05566 enumtype = make_node (ENUMERAL_TYPE);
05567 pushtag (name, enumtype);
05568 }
05569
05570 if (C_TYPE_BEING_DEFINED (enumtype))
05571 error ("nested redefinition of %<enum %s%>", IDENTIFIER_POINTER (name));
05572
05573 C_TYPE_BEING_DEFINED (enumtype) = 1;
05574
05575 if (TYPE_VALUES (enumtype) != 0)
05576 {
05577
05578 error ("redeclaration of %<enum %s%>", IDENTIFIER_POINTER (name));
05579
05580
05581
05582 TYPE_VALUES (enumtype) = 0;
05583 }
05584
05585 enum_next_value = integer_zero_node;
05586 enum_overflow = 0;
05587
05588 if (flag_short_enums)
05589 TYPE_PACKED (enumtype) = 1;
05590
05591 return enumtype;
05592 }
05593
05594
05595
05596
05597
05598
05599
05600 tree
05601 finish_enum (tree enumtype, tree values, tree attributes)
05602 {
05603 tree pair, tem;
05604 tree minnode = 0, maxnode = 0;
05605 int precision, unsign;
05606 bool toplevel = (file_scope == current_scope);
05607 struct lang_type *lt;
05608
05609 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
05610
05611
05612
05613 if (values == error_mark_node)
05614 minnode = maxnode = integer_zero_node;
05615 else
05616 {
05617 minnode = maxnode = TREE_VALUE (values);
05618 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
05619 {
05620 tree value = TREE_VALUE (pair);
05621 if (tree_int_cst_lt (maxnode, value))
05622 maxnode = value;
05623 if (tree_int_cst_lt (value, minnode))
05624 minnode = value;
05625 }
05626 }
05627
05628
05629
05630
05631
05632 unsign = (tree_int_cst_sgn (minnode) >= 0);
05633 precision = MAX (min_precision (minnode, unsign),
05634 min_precision (maxnode, unsign));
05635
05636 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
05637 {
05638 tem = c_common_type_for_size (precision, unsign);
05639 if (tem == NULL)
05640 {
05641 #ifdef TARG_SL
05642 if (Long_Long_Support == TRUE)
05643 {
05644 warning ("enumeration values exceed range of largest integer");
05645 tem = long_long_integer_type_node;
05646 }
05647 else
05648 {
05649 error("\"long long\" is mapped to \"long\", "
05650 "Please use \"-mlong-long\" option to enbale long long type suporting."
05651 "enumeration values exceed range of largest integer");
05652 }
05653 #else
05654 warning ("enumeration values exceed range of largest integer");
05655 tem = long_long_integer_type_node;
05656 #endif
05657 }
05658 }
05659 else
05660 tem = unsign ? unsigned_type_node : integer_type_node;
05661
05662 TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
05663 TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
05664 TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
05665 TYPE_SIZE (enumtype) = 0;
05666
05667
05668
05669 if (TYPE_PRECISION (enumtype))
05670 {
05671 if (precision > TYPE_PRECISION (enumtype))
05672 error ("specified mode too small for enumeral values");
05673 }
05674 else
05675 TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
05676
05677 layout_type (enumtype);
05678
05679 if (values != error_mark_node)
05680 {
05681
05682
05683
05684
05685
05686
05687
05688 for (pair = values; pair; pair = TREE_CHAIN (pair))
05689 {
05690 tree enu = TREE_PURPOSE (pair);
05691 tree ini = DECL_INITIAL (enu);
05692
05693 TREE_TYPE (enu) = enumtype;
05694
05695
05696
05697
05698
05699
05700
05701
05702 if (int_fits_type_p (ini, integer_type_node))
05703 tem = integer_type_node;
05704 else
05705 tem = enumtype;
05706 ini = convert (tem, ini);
05707
05708 DECL_INITIAL (enu) = ini;
05709 TREE_PURPOSE (pair) = DECL_NAME (enu);
05710 TREE_VALUE (pair) = ini;
05711 }
05712
05713 TYPE_VALUES (enumtype) = values;
05714 }
05715
05716
05717
05718 lt = GGC_CNEW (struct lang_type);
05719 lt->enum_min = minnode;
05720 lt->enum_max = maxnode;
05721 TYPE_LANG_SPECIFIC (enumtype) = lt;
05722
05723
05724 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
05725 {
05726 if (tem == enumtype)
05727 continue;
05728 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
05729 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
05730 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
05731 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
05732 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
05733 TYPE_MODE (tem) = TYPE_MODE (enumtype);
05734 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
05735 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
05736 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
05737 TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
05738 TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
05739 }
05740
05741
05742 rest_of_type_compilation (enumtype, toplevel);
05743
05744 return enumtype;
05745 }
05746
05747
05748
05749
05750
05751
05752 tree
05753 build_enumerator (tree name, tree value)
05754 {
05755 tree decl, type;
05756
05757
05758
05759
05760 if (value)
05761 STRIP_TYPE_NOPS (value);
05762
05763 if (value != 0)
05764 {
05765
05766
05767 if (value == error_mark_node)
05768 value = 0;
05769 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
05770 || TREE_CODE (value) != INTEGER_CST)
05771 {
05772 error ("enumerator value for %qE is not an integer constant", name);
05773 value = 0;
05774 }
05775 else
05776 {
05777 value = default_conversion (value);
05778 constant_expression_warning (value);
05779 }
05780 }
05781
05782
05783
05784
05785 if (value == 0)
05786 {
05787 value = enum_next_value;
05788 if (enum_overflow)
05789 error ("overflow in enumeration values");
05790 }
05791
05792 if (pedantic && !int_fits_type_p (value, integer_type_node))
05793 {
05794 pedwarn ("ISO C restricts enumerator values to range of %<int%>");
05795
05796
05797 value = convert (integer_type_node, value);
05798 }
05799
05800
05801 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
05802 enum_overflow = tree_int_cst_lt (enum_next_value, value);
05803
05804
05805
05806 type = TREE_TYPE (value);
05807 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
05808 TYPE_PRECISION (integer_type_node)),
05809 (TYPE_PRECISION (type)
05810 >= TYPE_PRECISION (integer_type_node)
05811 && TYPE_UNSIGNED (type)));
05812
05813 decl = build_decl (CONST_DECL, name, type);
05814 DECL_INITIAL (decl) = convert (type, value);
05815 pushdecl (decl);
05816
05817 return tree_cons (decl, value, NULL_TREE);
05818 }
05819
05820
05821
05822
05823
05824
05825
05826
05827
05828
05829
05830
05831
05832
05833 int
05834 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
05835 tree attributes)
05836 {
05837 tree decl1, old_decl;
05838 tree restype, resdecl;
05839 struct c_label_context_se *nstack_se;
05840 struct c_label_context_vm *nstack_vm;
05841
05842 current_function_returns_value = 0;
05843 current_function_returns_null = 0;
05844 current_function_returns_abnormally = 0;
05845 warn_about_return_type = 0;
05846 current_extern_inline = 0;
05847 c_switch_stack = NULL;
05848
05849 nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
05850 nstack_se->labels_def = NULL;
05851 nstack_se->labels_used = NULL;
05852 nstack_se->next = label_context_stack_se;
05853 label_context_stack_se = nstack_se;
05854
05855 nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm);
05856 nstack_vm->labels_def = NULL;
05857 nstack_vm->labels_used = NULL;
05858 nstack_vm->scope = 0;
05859 nstack_vm->next = label_context_stack_vm;
05860 label_context_stack_vm = nstack_vm;
05861
05862
05863
05864
05865 c_break_label = c_cont_label = size_zero_node;
05866
05867 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL);
05868
05869
05870
05871 if (decl1 == 0)
05872 {
05873 label_context_stack_se = label_context_stack_se->next;
05874 label_context_stack_vm = label_context_stack_vm->next;
05875 return 0;
05876 }
05877
05878 decl_attributes (&decl1, attributes, 0);
05879
05880 if (DECL_DECLARED_INLINE_P (decl1)
05881 && DECL_UNINLINABLE (decl1)
05882 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
05883 warning ("%Jinline function %qD given attribute noinline", decl1, decl1);
05884
05885 announce_function (decl1);
05886
05887 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
05888 {
05889 error ("return type is an incomplete type");
05890
05891 TREE_TYPE (decl1)
05892 = build_function_type (void_type_node,
05893 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
05894 }
05895
05896 if (warn_about_return_type)
05897 pedwarn_c99 ("return type defaults to %<int%>");
05898
05899
05900
05901 DECL_INITIAL (decl1) = error_mark_node;
05902
05903
05904
05905 old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
05906 current_function_prototype_locus = UNKNOWN_LOCATION;
05907 current_function_prototype_built_in = false;
05908 current_function_prototype_arg_types = NULL_TREE;
05909 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
05910 {
05911 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
05912 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
05913 TREE_TYPE (TREE_TYPE (old_decl))))
05914 {
05915 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
05916 TREE_TYPE (decl1));
05917 current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
05918 current_function_prototype_built_in
05919 = C_DECL_BUILTIN_PROTOTYPE (old_decl);
05920 current_function_prototype_arg_types
05921 = TYPE_ARG_TYPES (TREE_TYPE (decl1));
05922 }
05923 if (TREE_PUBLIC (decl1))
05924 {
05925
05926
05927
05928
05929
05930
05931 struct c_binding *b;
05932 for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
05933 if (B_IN_SCOPE (b, external_scope))
05934 break;
05935 if (b)
05936 {
05937 tree ext_decl, ext_type;
05938 ext_decl = b->decl;
05939 ext_type = b->type ? b->type : TREE_TYPE (ext_decl);
05940 if (TREE_CODE (ext_type) == FUNCTION_TYPE
05941 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
05942 TREE_TYPE (ext_type)))
05943 {
05944 current_function_prototype_locus
05945 = DECL_SOURCE_LOCATION (ext_decl);
05946 current_function_prototype_built_in
05947 = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
05948 current_function_prototype_arg_types
05949 = TYPE_ARG_TYPES (ext_type);
05950 }
05951 }
05952 }
05953 }
05954
05955
05956 if (warn_strict_prototypes
05957 && old_decl != error_mark_node
05958 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
05959 && C_DECL_ISNT_PROTOTYPE (old_decl))
05960 warning ("function declaration isn%'t a prototype");
05961
05962 else if (warn_missing_prototypes
05963 && old_decl != error_mark_node
05964 && TREE_PUBLIC (decl1)
05965 && !MAIN_NAME_P (DECL_NAME (decl1))
05966 && C_DECL_ISNT_PROTOTYPE (old_decl))
05967 warning ("%Jno previous prototype for %qD", decl1, decl1);
05968
05969
05970 else if (warn_missing_prototypes
05971 && old_decl != 0
05972 && old_decl != error_mark_node
05973 && TREE_USED (old_decl)
05974 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
05975 warning ("%J%qD was used with no prototype before its definition",
05976 decl1, decl1);
05977
05978 else if (warn_missing_declarations
05979 && TREE_PUBLIC (decl1)
05980 && old_decl == 0
05981 && !MAIN_NAME_P (DECL_NAME (decl1)))
05982 warning ("%Jno previous declaration for %qD", decl1, decl1);
05983
05984
05985 else if (warn_missing_declarations
05986 && old_decl != 0
05987 && old_decl != error_mark_node
05988 && TREE_USED (old_decl)
05989 && C_DECL_IMPLICIT (old_decl))
05990 warning ("%J%qD was used with no declaration before its definition",
05991 decl1, decl1);
05992
05993
05994
05995
05996
05997 DECL_EXTERNAL (decl1) = current_extern_inline;
05998
05999
06000
06001 TREE_STATIC (decl1) = 1;
06002
06003
06004 if (current_function_decl != 0)
06005 TREE_PUBLIC (decl1) = 0;
06006
06007
06008
06009 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
06010
06011
06012 if (current_scope == file_scope)
06013 maybe_apply_pragma_weak (decl1);
06014
06015
06016 if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
06017 {
06018 tree args;
06019 int argct = 0;
06020
06021 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
06022 != integer_type_node)
06023 pedwarn ("%Jreturn type of %qD is not %<int%>", decl1, decl1);
06024
06025 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
06026 args = TREE_CHAIN (args))
06027 {
06028 tree type = args ? TREE_VALUE (args) : 0;
06029
06030 if (type == void_type_node)
06031 break;
06032
06033 ++argct;
06034 switch (argct)
06035 {
06036 case 1:
06037 if (TYPE_MAIN_VARIANT (type) != integer_type_node)
06038 pedwarn ("%Jfirst argument of %qD should be %<int%>",
06039 decl1, decl1);
06040 break;
06041
06042 case 2:
06043 if (TREE_CODE (type) != POINTER_TYPE
06044 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
06045 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
06046 != char_type_node))
06047 pedwarn ("%Jsecond argument of %qD should be %<char **%>",
06048 decl1, decl1);
06049 break;
06050
06051 case 3:
06052 if (TREE_CODE (type) != POINTER_TYPE
06053 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
06054 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
06055 != char_type_node))
06056 pedwarn ("%Jthird argument of %qD should probably be "
06057 "%<char **%>", decl1, decl1);
06058 break;
06059 }
06060 }
06061
06062
06063
06064
06065 if (argct > 0 && (argct < 2 || argct > 3))
06066 pedwarn ("%J%qD takes only zero or two arguments", decl1, decl1);
06067
06068 if (!TREE_PUBLIC (decl1))
06069 pedwarn ("%J%qD is normally a non-static function", decl1, decl1);
06070 }
06071
06072
06073
06074
06075
06076 current_function_decl = pushdecl (decl1);
06077
06078 push_scope ();
06079 declare_parm_level ();
06080
06081 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
06082
06083 if (c_promoting_integer_type_p (restype))
06084 {
06085
06086 if (TYPE_UNSIGNED (restype)
06087 && (TYPE_PRECISION (restype)
06088 == TYPE_PRECISION (integer_type_node)))
06089 restype = unsigned_type_node;
06090 else
06091 restype = integer_type_node;
06092 }
06093
06094 resdecl = build_decl (RESULT_DECL, NULL_TREE, restype);
06095 DECL_ARTIFICIAL (resdecl) = 1;
06096 DECL_IGNORED_P (resdecl) = 1;
06097 DECL_RESULT (current_function_decl) = resdecl;
06098
06099 start_fname_decls ();
06100
06101 return 1;
06102 }
06103
06104
06105
06106
06107
06108 static void
06109 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
06110 {
06111 tree decl;
06112
06113 if (current_scope->bindings)
06114 {
06115 error ("%Jold-style parameter declarations in prototyped "
06116 "function definition", fndecl);
06117
06118
06119 pop_scope ();
06120 push_scope ();
06121 }
06122
06123
06124
06125
06126 else if (warn_traditional && !in_system_header && !current_function_scope
06127 && arg_info->types != error_mark_node)
06128 warning ("%Jtraditional C rejects ISO C style function definitions",
06129 fndecl);
06130
06131
06132
06133 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl))
06134 {
06135 DECL_CONTEXT (decl) = current_function_decl;
06136 if (DECL_NAME (decl))
06137 bind (DECL_NAME (decl), decl, current_scope,
06138 false, false);
06139 else
06140 error ("%Jparameter name omitted", decl);
06141 }
06142
06143
06144 DECL_ARGUMENTS (fndecl) = arg_info->parms;
06145
06146
06147 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl))
06148 {
06149 DECL_CONTEXT (decl) = current_function_decl;
06150 if (DECL_NAME (decl))
06151 bind (DECL_NAME (decl), decl, current_scope,
06152 false, false);
06153 }
06154
06155
06156 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl))
06157 if (TREE_PURPOSE (decl))
06158 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
06159 false, false);
06160 }
06161
06162
06163
06164
06165 static void
06166 store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
06167 {
06168 struct c_binding *b;
06169 tree parm, decl, last;
06170 tree parmids = arg_info->parms;
06171
06172
06173
06174 #ifdef ENABLE_CHECKING
06175 for (b = current_scope->bindings; b; b = b->prev)
06176 gcc_assert (TREE_CODE (b->decl) != PARM_DECL || !DECL_WEAK (b->decl));
06177 #endif
06178
06179 #ifdef TARG_SL
06180
06181 tree parm_t;
06182 int float_flag = 0;
06183 for (parm_t = parmids; parm_t != NULL; parm_t = TREE_CHAIN(parm_t))
06184 {
06185 tree type_node = TYPE_MAIN_VARIANT(TREE_TYPE((I_SYMBOL_BINDING (TREE_VALUE (parm_t))->decl)));
06186 if (type_node == float_type_node || type_node == double_type_node)
06187 {
06188 float_flag = 1;
06189 break;
06190 }
06191 }
06192 if (float_flag == 1)
06193 {
06194 error("Old-style function definition is not supported for float/double type");
06195 }
06196 else
06197 {
06198 warning("Old-style function definition");
06199 }
06200 #endif
06201
06202 if (warn_old_style_definition && !in_system_header)
06203 warning ("%Jold-style function definition", fndecl);
06204
06205
06206
06207 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
06208 {
06209 if (TREE_VALUE (parm) == 0)
06210 {
06211 error ("%Jparameter name missing from parameter list", fndecl);
06212 TREE_PURPOSE (parm) = 0;
06213 continue;
06214 }
06215
06216 b = I_SYMBOL_BINDING (TREE_VALUE (parm));
06217 if (b && B_IN_CURRENT_SCOPE (b))
06218 {
06219 decl = b->decl;
06220
06221 if (TREE_CODE (decl) != PARM_DECL)
06222 error ("%J%qD declared as a non-parameter", decl, decl);
06223
06224
06225 else if (DECL_WEAK (decl))
06226 {
06227 error ("%Jmultiple parameters named %qD", decl, decl);
06228 TREE_PURPOSE (parm) = 0;
06229 continue;
06230 }
06231
06232
06233 else if (VOID_TYPE_P (TREE_TYPE (decl)))
06234 {
06235 error ("%Jparameter %qD declared with void type", decl, decl);
06236 TREE_TYPE (decl) = integer_type_node;
06237 DECL_ARG_TYPE (decl) = integer_type_node;
06238 layout_decl (decl, 0);
06239 }
06240 }
06241
06242 else
06243 {
06244 decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node);
06245 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
06246 DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl);
06247 pushdecl (decl);
06248
06249 if (flag_isoc99)
06250 pedwarn ("%Jtype of %qD defaults to %<int%>", decl, decl);
06251 else if (extra_warnings)
06252 warning ("%Jtype of %qD defaults to %<int%>", decl, decl);
06253 }
06254
06255 TREE_PURPOSE (parm) = decl;
06256 DECL_WEAK (decl) = 1;
06257 }
06258
06259
06260
06261
06262 for (b = current_scope->bindings; b; b = b->prev)
06263 {
06264 parm = b->decl;
06265 if (TREE_CODE (parm) != PARM_DECL)
06266 continue;
06267
06268 if (TREE_TYPE (parm) != error_mark_node
06269 && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
06270 {
06271 error ("%Jparameter %qD has incomplete type", parm, parm);
06272 TREE_TYPE (parm) = error_mark_node;
06273 }
06274
06275 if (!DECL_WEAK (parm))
06276 {
06277 error ("%Jdeclaration for parameter %qD but no such parameter",
06278 parm, parm);
06279
06280
06281
06282
06283 parmids = chainon (parmids, tree_cons (parm, 0, 0));
06284 }
06285 }
06286
06287
06288
06289
06290 DECL_ARGUMENTS (fndecl) = 0;
06291
06292 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
06293 if (TREE_PURPOSE (parm))
06294 break;
06295 if (parm && TREE_PURPOSE (parm))
06296 {
06297 last = TREE_PURPOSE (parm);
06298 DECL_ARGUMENTS (fndecl) = last;
06299 DECL_WEAK (last) = 0;
06300
06301 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
06302 if (TREE_PURPOSE (parm))
06303 {
06304 TREE_CHAIN (last) = TREE_PURPOSE (parm);
06305 last = TREE_PURPOSE (parm);
06306 DECL_WEAK (last) = 0;
06307 }
06308 TREE_CHAIN (last) = 0;
06309 }
06310
06311
06312
06313
06314
06315 if (current_function_prototype_arg_types)
06316 {
06317 tree type;
06318 for (parm = DECL_ARGUMENTS (fndecl),
06319 type = current_function_prototype_arg_types;
06320 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
06321 != void_type_node));
06322 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
06323 {
06324 if (parm == 0 || type == 0
06325 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
06326 {
06327 if (current_function_prototype_built_in)
06328 warning ("number of arguments doesn%'t match "
06329 "built-in prototype");
06330 else
06331 {
06332 error ("number of arguments doesn%'t match prototype");
06333 error ("%Hprototype declaration",
06334 ¤t_function_prototype_locus);
06335 }
06336 break;
06337 }
06338
06339
06340
06341 if (!comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
06342 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
06343 {
06344 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
06345 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
06346 {
06347
06348
06349
06350
06351
06352 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
06353
06354 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
06355 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
06356 && TYPE_PRECISION (TREE_TYPE (parm))
06357 < TYPE_PRECISION (integer_type_node))
06358 DECL_ARG_TYPE (parm) = integer_type_node;
06359
06360 if (pedantic)
06361 {
06362
06363
06364
06365
06366 if (current_function_prototype_built_in)
06367 warning ("promoted argument %qD "
06368 "doesn%'t match built-in prototype", parm);
06369 else
06370 {
06371 pedwarn ("promoted argument %qD "
06372 "doesn%'t match prototype", parm);
06373 pedwarn ("%Hprototype declaration",
06374 ¤t_function_prototype_locus);
06375 }
06376 }
06377 }
06378 else
06379 {
06380 if (current_function_prototype_built_in)
06381 warning ("argument %qD doesn%'t match "
06382 "built-in prototype", parm);
06383 else
06384 {
06385 error ("argument %qD doesn%'t match prototype", parm);
06386 error ("%Hprototype declaration",
06387 ¤t_function_prototype_locus);
06388 }
06389 }
06390 }
06391 }
06392 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
06393 }
06394
06395
06396
06397 else
06398 {
06399 tree actual = 0, last = 0, type;
06400
06401 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
06402 {
06403 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
06404 if (last)
06405 TREE_CHAIN (last) = type;
06406 else
06407 actual = type;
06408 last = type;
06409 }
06410 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
06411 if (last)
06412 TREE_CHAIN (last) = type;
06413 else
06414 actual = type;
06415
06416
06417
06418
06419
06420
06421
06422
06423
06424 TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
06425
06426 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
06427 }
06428 }
06429
06430
06431
06432
06433 void
06434 store_parm_decls_from (struct c_arg_info *arg_info)
06435 {
06436 current_function_arg_info = arg_info;
06437 store_parm_decls ();
06438 }
06439
06440
06441
06442
06443
06444
06445
06446
06447 void
06448 store_parm_decls (void)
06449 {
06450 tree fndecl = current_function_decl;
06451 bool proto;
06452
06453
06454 struct c_arg_info *arg_info = current_function_arg_info;
06455 current_function_arg_info = 0;
06456
06457
06458
06459
06460
06461
06462 proto = arg_info->types != 0;
06463
06464 if (proto)
06465 store_parm_decls_newstyle (fndecl, arg_info);
06466 else
06467 store_parm_decls_oldstyle (fndecl, arg_info);
06468
06469
06470
06471 next_is_function_body = true;
06472
06473
06474
06475
06476 gen_aux_info_record (fndecl, 1, 0, proto);
06477
06478
06479 allocate_struct_function (fndecl);
06480
06481
06482 DECL_SAVED_TREE (fndecl) = push_stmt_list ();
06483
06484
06485
06486
06487
06488
06489
06490 {
06491 tree t;
06492 for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t))
06493 add_stmt (TREE_VALUE (t));
06494 }
06495
06496
06497
06498
06499
06500 cfun->x_dont_save_pending_sizes_p = 1;
06501 }
06502
06503
06504
06505
06506 static void
06507 c_warn_unused_result_recursively (tree fndecl)
06508 {
06509 struct cgraph_node *cgn;
06510
06511
06512 c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
06513
06514
06515 cgn = cgraph_node (fndecl);
06516 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
06517 c_warn_unused_result_recursively (cgn->decl);
06518 }
06519
06520
06521
06522
06523
06524
06525
06526 void
06527 finish_function (void)
06528 {
06529 tree fndecl = current_function_decl;
06530
06531 label_context_stack_se = label_context_stack_se->next;
06532 label_context_stack_vm = label_context_stack_vm->next;
06533
06534 if (TREE_CODE (fndecl) == FUNCTION_DECL
06535 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
06536 {
06537 tree args = DECL_ARGUMENTS (fndecl);
06538 for (; args; args = TREE_CHAIN (args))
06539 {
06540 tree type = TREE_TYPE (args);
06541 if (INTEGRAL_TYPE_P (type)
06542 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
06543 DECL_ARG_TYPE (args) = integer_type_node;
06544 }
06545 }
06546
06547 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
06548 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
06549
06550
06551
06552 if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
06553 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
06554
06555 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
06556 {
06557 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
06558 != integer_type_node)
06559 {
06560
06561
06562 if (!warn_main)
06563 pedwarn ("%Jreturn type of %qD is not %<int%>", fndecl, fndecl);
06564 }
06565 else
06566 {
06567 if (flag_isoc99)
06568 {
06569 tree stmt = c_finish_return (integer_zero_node);
06570
06571
06572
06573 annotate_with_file_line (stmt, input_filename, 0);
06574 }
06575 }
06576 }
06577
06578
06579 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
06580
06581 finish_fname_decls ();
06582
06583
06584 if (warn_return_type
06585 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
06586 && !current_function_returns_value && !current_function_returns_null
06587
06588 && !current_function_returns_abnormally
06589
06590 && !MAIN_NAME_P (DECL_NAME (fndecl))
06591
06592 && !C_FUNCTION_IMPLICIT_INT (fndecl)
06593
06594
06595 && DECL_INLINE (fndecl))
06596 warning ("no return statement in function returning non-void");
06597
06598
06599
06600 if (extra_warnings
06601 && current_function_returns_value
06602 && current_function_returns_null)
06603 warning ("this function may return with or without a value");
06604
06605
06606
06607 cfun->function_end_locus = input_location;
06608
06609
06610
06611 if (DECL_STATIC_CONSTRUCTOR (fndecl)
06612 && !targetm.have_ctors_dtors)
06613 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
06614 if (DECL_STATIC_DESTRUCTOR (fndecl)
06615 && !targetm.have_ctors_dtors)
06616 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
06617
06618
06619 c_determine_visibility (fndecl);
06620
06621
06622
06623
06624
06625 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
06626 && !undef_nested_function)
06627 {
06628 if (!decl_function_context (fndecl))
06629 {
06630 #ifdef KEY
06631
06632
06633
06634 if (flag_spin_file)
06635 gspin (fndecl);
06636 #endif
06637 c_genericize (fndecl);
06638 c_warn_unused_result_recursively (fndecl);
06639
06640
06641
06642 if (cgraph_global_info_ready)
06643 {
06644 c_expand_body (fndecl);
06645 return;
06646 }
06647
06648 cgraph_finalize_function (fndecl, false);
06649 }
06650 else
06651 {
06652 #ifdef KEY
06653 error ("Nested functions not supported");
06654 #endif
06655
06656
06657
06658 (void) cgraph_node (fndecl);
06659 }
06660 }
06661
06662 if (!decl_function_context (fndecl))
06663 undef_nested_function = false;
06664
06665
06666
06667
06668 cfun = NULL;
06669 current_function_decl = NULL;
06670 }
06671
06672
06673
06674 void
06675 c_expand_body (tree fndecl)
06676 {
06677
06678 if (!DECL_INITIAL (fndecl)
06679 || DECL_INITIAL (fndecl) == error_mark_node)
06680 return;
06681
06682 tree_rest_of_compilation (fndecl);
06683
06684 if (DECL_STATIC_CONSTRUCTOR (fndecl)
06685 && targetm.have_ctors_dtors)
06686 targetm.asm_out.constructor (XEXP (DECL_RTL (fndecl), 0),
06687 DEFAULT_INIT_PRIORITY);
06688 if (DECL_STATIC_DESTRUCTOR (fndecl)
06689 && targetm.have_ctors_dtors)
06690 targetm.asm_out.destructor (XEXP (DECL_RTL (fndecl), 0),
06691 DEFAULT_INIT_PRIORITY);
06692 }
06693
06694
06695
06696 void
06697 check_for_loop_decls (void)
06698 {
06699 struct c_binding *b;
06700
06701 if (!flag_isoc99)
06702 {
06703
06704
06705
06706 error ("%<for%> loop initial declaration used outside C99 mode");
06707 return;
06708 }
06709
06710
06711
06712
06713
06714
06715
06716
06717
06718
06719
06720
06721
06722
06723 for (b = current_scope->bindings; b; b = b->prev)
06724 {
06725 tree id = b->id;
06726 tree decl = b->decl;
06727
06728 if (!id)
06729 continue;
06730
06731 switch (TREE_CODE (decl))
06732 {
06733 case VAR_DECL:
06734 if (TREE_STATIC (decl))
06735 error ("%Jdeclaration of static variable %qD in %<for%> loop "
06736 "initial declaration", decl, decl);
06737 else if (DECL_EXTERNAL (decl))
06738 error ("%Jdeclaration of %<extern%> variable %qD in %<for%> loop "
06739 "initial declaration", decl, decl);
06740 break;
06741
06742 case RECORD_TYPE:
06743 error ("%<struct %E%> declared in %<for%> loop initial declaration",
06744 id);
06745 break;
06746 case UNION_TYPE:
06747 error ("%<union %E%> declared in %<for%> loop initial declaration",
06748 id);
06749 break;
06750 case ENUMERAL_TYPE:
06751 error ("%<enum %E%> declared in %<for%> loop initial declaration",
06752 id);
06753 break;
06754 default:
06755 error ("%Jdeclaration of non-variable %qD in %<for%> loop "
06756 "initial declaration", decl, decl);
06757 }
06758 }
06759 }
06760
06761
06762
06763
06764 void
06765 c_push_function_context (struct function *f)
06766 {
06767 struct language_function *p;
06768 p = GGC_NEW (struct language_function);
06769 f->language = p;
06770
06771 p->base.x_stmt_tree = c_stmt_tree;
06772 p->x_break_label = c_break_label;
06773 p->x_cont_label = c_cont_label;
06774 p->x_switch_stack = c_switch_stack;
06775 p->arg_info = current_function_arg_info;
06776 p->returns_value = current_function_returns_value;
06777 p->returns_null = current_function_returns_null;
06778 p->returns_abnormally = current_function_returns_abnormally;
06779 p->warn_about_return_type = warn_about_return_type;
06780 p->extern_inline = current_extern_inline;
06781 }
06782
06783
06784
06785 void
06786 c_pop_function_context (struct function *f)
06787 {
06788 struct language_function *p = f->language;
06789
06790 if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
06791 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
06792 {
06793
06794
06795
06796 DECL_INITIAL (current_function_decl) = error_mark_node;
06797 DECL_ARGUMENTS (current_function_decl) = 0;
06798 }
06799
06800 c_stmt_tree = p->base.x_stmt_tree;
06801 c_break_label = p->x_break_label;
06802 c_cont_label = p->x_cont_label;
06803 c_switch_stack = p->x_switch_stack;
06804 current_function_arg_info = p->arg_info;
06805 current_function_returns_value = p->returns_value;
06806 current_function_returns_null = p->returns_null;
06807 current_function_returns_abnormally = p->returns_abnormally;
06808 warn_about_return_type = p->warn_about_return_type;
06809 current_extern_inline = p->extern_inline;
06810
06811 f->language = NULL;
06812 }
06813
06814
06815
06816 void
06817 c_dup_lang_specific_decl (tree decl)
06818 {
06819 struct lang_decl *ld;
06820
06821 if (!DECL_LANG_SPECIFIC (decl))
06822 return;
06823
06824 ld = GGC_NEW (struct lang_decl);
06825 memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl));
06826 DECL_LANG_SPECIFIC (decl) = ld;
06827 }
06828
06829
06830
06831
06832
06833
06834
06835
06836
06837
06838 int
06839 stmts_are_full_exprs_p (void)
06840 {
06841 return 0;
06842 }
06843
06844
06845
06846
06847
06848 stmt_tree
06849 current_stmt_tree (void)
06850 {
06851 return &c_stmt_tree;
06852 }
06853
06854
06855
06856
06857 int
06858 anon_aggr_type_p (tree ARG_UNUSED (node))
06859 {
06860 return 0;
06861 }
06862
06863
06864
06865 tree
06866 identifier_global_value (tree t)
06867 {
06868 struct c_binding *b;
06869
06870 for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
06871 if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
06872 return b->decl;
06873
06874 return 0;
06875 }
06876
06877
06878
06879
06880 void
06881 record_builtin_type (enum rid rid_index, const char *name, tree type)
06882 {
06883 tree id, decl;
06884 if (name == 0)
06885 id = ridpointers[(int) rid_index];
06886 else
06887 id = get_identifier (name);
06888 decl = build_decl (TYPE_DECL, id, type);
06889 pushdecl (decl);
06890 if (debug_hooks->type_decl)
06891 debug_hooks->type_decl (decl, false);
06892 }
06893
06894
06895 tree
06896 build_void_list_node (void)
06897 {
06898 tree t = build_tree_list (NULL_TREE, void_type_node);
06899 return t;
06900 }
06901
06902
06903
06904 struct c_parm *
06905 build_c_parm (struct c_declspecs *specs, tree attrs,
06906 struct c_declarator *declarator)
06907 {
06908 struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
06909 ret->specs = specs;
06910 ret->attrs = attrs;
06911 ret->declarator = declarator;
06912 return ret;
06913 }
06914
06915
06916
06917
06918
06919 struct c_declarator *
06920 build_attrs_declarator (tree attrs, struct c_declarator *target)
06921 {
06922 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06923 ret->kind = cdk_attrs;
06924 ret->declarator = target;
06925 ret->u.attrs = attrs;
06926 return ret;
06927 }
06928
06929
06930
06931
06932 struct c_declarator *
06933 build_function_declarator (struct c_arg_info *args,
06934 struct c_declarator *target)
06935 {
06936 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06937 ret->kind = cdk_function;
06938 ret->declarator = target;
06939 ret->u.arg_info = args;
06940 return ret;
06941 }
06942
06943
06944
06945
06946 struct c_declarator *
06947 build_id_declarator (tree ident)
06948 {
06949 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06950 ret->kind = cdk_id;
06951 ret->declarator = 0;
06952 ret->u.id = ident;
06953 return ret;
06954 }
06955
06956
06957
06958
06959
06960
06961 struct c_declarator *
06962 make_pointer_declarator (struct c_declspecs *type_quals_attrs,
06963 struct c_declarator *target)
06964 {
06965 tree attrs;
06966 int quals = 0;
06967 struct c_declarator *itarget = target;
06968 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06969 if (type_quals_attrs)
06970 {
06971 attrs = type_quals_attrs->attrs;
06972 quals = quals_from_declspecs (type_quals_attrs);
06973 if (attrs != NULL_TREE)
06974 itarget = build_attrs_declarator (attrs, target);
06975 }
06976 ret->kind = cdk_pointer;
06977 ret->declarator = itarget;
06978 ret->u.pointer_quals = quals;
06979 return ret;
06980 }
06981
06982
06983
06984
06985 struct c_declspecs *
06986 build_null_declspecs (void)
06987 {
06988 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
06989 ret->type = 0;
06990 ret->decl_attr = 0;
06991 ret->attrs = 0;
06992 ret->typespec_word = cts_none;
06993 ret->storage_class = csc_none;
06994 ret->non_sc_seen_p = false;
06995 ret->typedef_p = false;
06996 ret->tag_defined_p = false;
06997 ret->explicit_signed_p = false;
06998 ret->deprecated_p = false;
06999 ret->default_int_p = false;
07000 ret->long_p = false;
07001 ret->long_long_p = false;
07002 ret->short_p = false;
07003 ret->signed_p = false;
07004 ret->unsigned_p = false;
07005 ret->complex_p = false;
07006 ret->inline_p = false;
07007 ret->thread_p = false;
07008 ret->const_p = false;
07009 ret->volatile_p = false;
07010 ret->restrict_p = false;
07011 return ret;
07012 }
07013
07014
07015
07016
07017 struct c_declspecs *
07018 declspecs_add_qual (struct c_declspecs *specs, tree qual)
07019 {
07020 enum rid i;
07021 bool dupe = false;
07022 specs->non_sc_seen_p = true;
07023 gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
07024 && C_IS_RESERVED_WORD (qual));
07025 i = C_RID_CODE (qual);
07026 switch (i)
07027 {
07028 case RID_CONST:
07029 dupe = specs->const_p;
07030 specs->const_p = true;
07031 break;
07032 case RID_VOLATILE:
07033 dupe = specs->volatile_p;
07034 specs->volatile_p = true;
07035 break;
07036 case RID_RESTRICT:
07037 dupe = specs->restrict_p;
07038 specs->restrict_p = true;
07039 break;
07040 default:
07041 gcc_unreachable ();
07042 }
07043 if (dupe && pedantic && !flag_isoc99)
07044 pedwarn ("duplicate %qs", IDENTIFIER_POINTER (qual));
07045 return specs;
07046 }
07047
07048
07049
07050
07051 struct c_declspecs *
07052 declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec)
07053 {
07054 tree type = spec.spec;
07055 specs->non_sc_seen_p = true;
07056 if (TREE_DEPRECATED (type))
07057 specs->deprecated_p = true;
07058
07059
07060 if (TREE_CODE (type) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (type))
07061 {
07062 enum rid i = C_RID_CODE (type);
07063 if (specs->type)
07064 {
07065 error ("two or more data types in declaration specifiers");
07066 return specs;
07067 }
07068 if ((int) i <= (int) RID_LAST_MODIFIER)
07069 {
07070
07071 bool dupe = false;
07072 switch (i)
07073 {
07074 case RID_LONG:
07075 if (specs->long_long_p)
07076 {
07077 error ("%<long long long%> is too long for GCC");
07078 break;
07079 }
07080 if (specs->long_p)
07081 {
07082 if (specs->typespec_word == cts_double)
07083 {
07084 error ("both %<long long%> and %<double%> in "
07085 "declaration specifiers");
07086 break;
07087 }
07088 if (pedantic && !flag_isoc99 && !in_system_header
07089 && warn_long_long)
07090 pedwarn ("ISO C90 does not support %<long long%>");
07091 specs->long_long_p = 1;
07092 break;
07093 }
07094 if (specs->short_p)
07095 error ("both %<long%> and %<short%> in "
07096 "declaration specifiers");
07097 else if (specs->typespec_word == cts_void)
07098 error ("both %<long%> and %<void%> in "
07099 "declaration specifiers");
07100 else if (specs->typespec_word == cts_bool)
07101 error ("both %<long%> and %<_Bool%> in "
07102 "declaration specifiers");
07103 else if (specs->typespec_word == cts_char)
07104 error ("both %<long%> and %<char%> in "
07105 "declaration specifiers");
07106 else if (specs->typespec_word == cts_float)
07107 error ("both %<long%> and %<float%> in "
07108 "declaration specifiers");
07109 else
07110 specs->long_p = true;
07111 break;
07112 case RID_SHORT:
07113 dupe = specs->short_p;
07114 if (specs->long_p)
07115 error ("both %<long%> and %<short%> in "
07116 "declaration specifiers");
07117 else if (specs->typespec_word == cts_void)
07118 error ("both %<short%> and %<void%> in "
07119 "declaration specifiers");
07120 else if (specs->typespec_word == cts_bool)
07121 error ("both %<short%> and %<_Bool%> in "
07122 "declaration specifiers");
07123 else if (specs->typespec_word == cts_char)
07124 error ("both %<short%> and %<char%> in "
07125 "declaration specifiers");
07126 else if (specs->typespec_word == cts_float)
07127 error ("both %<short%> and %<float%> in "
07128 "declaration specifiers");
07129 else if (specs->typespec_word == cts_double)
07130 error ("both %<short%> and %<double%> in "
07131 "declaration specifiers");
07132 else
07133 specs->short_p = true;
07134 break;
07135 case RID_SIGNED:
07136 dupe = specs->signed_p;
07137 if (specs->unsigned_p)
07138 error ("both %<signed%> and %<unsigned%> in "
07139 "declaration specifiers");
07140 else if (specs->typespec_word == cts_void)
07141 error ("both %<signed%> and %<void%> in "
07142 "declaration specifiers");
07143 else if (specs->typespec_word == cts_bool)
07144 error ("both %<signed%> and %<_Bool%> in "
07145 "declaration specifiers");
07146 else if (specs->typespec_word == cts_float)
07147 error ("both %<signed%> and %<float%> in "
07148 "declaration specifiers");
07149 else if (specs->typespec_word == cts_double)
07150 error ("both %<signed%> and %<double%> in "
07151 "declaration specifiers");
07152 else
07153 specs->signed_p = true;
07154 break;
07155 case RID_UNSIGNED:
07156 dupe = specs->unsigned_p;
07157 if (specs->signed_p)
07158 error ("both %<signed%> and %<unsigned%> in "
07159 "declaration specifiers");
07160 else if (specs->typespec_word == cts_void)
07161 error ("both %<unsigned%> and %<void%> in "
07162 "declaration specifiers");
07163 else if (specs->typespec_word == cts_bool)
07164 error ("both %<unsigned%> and %<_Bool%> in "
07165 "declaration specifiers");
07166 else if (specs->typespec_word == cts_float)
07167 error ("both %<unsigned%> and %<float%> in "
07168 "declaration specifiers");
07169 else if (specs->typespec_word == cts_double)
07170 error ("both %<unsigned%> and %<double%> in "
07171 "declaration specifiers");
07172 else
07173 specs->unsigned_p = true;
07174 break;
07175 case RID_COMPLEX:
07176 dupe = specs->complex_p;
07177 if (pedantic && !flag_isoc99 && !in_system_header)
07178 pedwarn ("ISO C90 does not support complex types");
07179 if (specs->typespec_word == cts_void)
07180 error ("both %<complex%> and %<void%> in "
07181 "declaration specifiers");
07182 else if (specs->typespec_word == cts_bool)
07183 error ("both %<complex%> and %<_Bool%> in "
07184 "declaration specifiers");
07185 else
07186 specs->complex_p = true;
07187 break;
07188 default:
07189 gcc_unreachable ();
07190 }
07191
07192 if (dupe)
07193 error ("duplicate %qs", IDENTIFIER_POINTER (type));
07194
07195 return specs;
07196 }
07197 else
07198 {
07199
07200 if (specs->typespec_word != cts_none)
07201 {
07202 error ("two or more data types in declaration specifiers");
07203 return specs;
07204 }
07205 switch (i)
07206 {
07207 case RID_VOID:
07208 if (specs->long_p)
07209 error ("both %<long%> and %<void%> in "
07210 "declaration specifiers");
07211 else if (specs->short_p)
07212 error ("both %<short%> and %<void%> in "
07213 "declaration specifiers");
07214 else if (specs->signed_p)
07215 error ("both %<signed%> and %<void%> in "
07216 "declaration specifiers");
07217 else if (specs->unsigned_p)
07218 error ("both %<unsigned%> and %<void%> in "
07219 "declaration specifiers");
07220 else if (specs->complex_p)
07221 error ("both %<complex%> and %<void%> in "
07222 "declaration specifiers");
07223 else
07224 specs->typespec_word = cts_void;
07225 return specs;
07226 case RID_BOOL:
07227 if (specs->long_p)
07228 error ("both %<long%> and %<_Bool%> in "
07229 "declaration specifiers");
07230 else if (specs->short_p)
07231 error ("both %<short%> and %<_Bool%> in "
07232 "declaration specifiers");
07233 else if (specs->signed_p)
07234 error ("both %<signed%> and %<_Bool%> in "
07235 "declaration specifiers");
07236 else if (specs->unsigned_p)
07237 error ("both %<unsigned%> and %<_Bool%> in "
07238 "declaration specifiers");
07239 else if (specs->complex_p)
07240 error ("both %<complex%> and %<_Bool%> in "
07241 "declaration specifiers");
07242 else
07243 specs->typespec_word = cts_bool;
07244 return specs;
07245 case RID_CHAR:
07246 if (specs->long_p)
07247 error ("both %<long%> and %<char%> in "
07248 "declaration specifiers");
07249 else if (specs->short_p)
07250 error ("both %<short%> and %<char%> in "
07251 "declaration specifiers");
07252 else
07253 specs->typespec_word = cts_char;
07254 return specs;
07255 case RID_INT:
07256 specs->typespec_word = cts_int;
07257 return specs;
07258 case RID_FLOAT:
07259 if (specs->long_p)
07260 error ("both %<long%> and %<float%> in "
07261 "declaration specifiers");
07262 else if (specs->short_p)
07263 error ("both %<short%> and %<float%> in "
07264 "declaration specifiers");
07265 else if (specs->signed_p)
07266 error ("both %<signed%> and %<float%> in "
07267 "declaration specifiers");
07268 else if (specs->unsigned_p)
07269 error ("both %<unsigned%> and %<float%> in "
07270 "declaration specifiers");
07271 else
07272 specs->typespec_word = cts_float;
07273 return specs;
07274 case RID_DOUBLE:
07275 if (specs->long_long_p)
07276 error ("both %<long long%> and %<double%> in "
07277 "declaration specifiers");
07278 else if (specs->short_p)
07279 error ("both %<short%> and %<double%> in "
07280 "declaration specifiers");
07281 else if (specs->signed_p)
07282 error ("both %<signed%> and %<double%> in "
07283 "declaration specifiers");
07284 else if (specs->unsigned_p)
07285 error ("both %<unsigned%> and %<double%> in "
07286 "declaration specifiers");
07287 else
07288 specs->typespec_word = cts_double;
07289 return specs;
07290 default:
07291
07292 break;
07293 }
07294 }
07295 }
07296
07297
07298
07299
07300
07301
07302 if (specs->type || specs->typespec_word != cts_none
07303 || specs->long_p || specs->short_p || specs->signed_p
07304 || specs->unsigned_p || specs->complex_p)
07305 error ("two or more data types in declaration specifiers");
07306 else if (TREE_CODE (type) == TYPE_DECL)
07307 {
07308 if (TREE_TYPE (type) == error_mark_node)
07309 ;
07310 else
07311 {
07312 specs->type = TREE_TYPE (type);
07313 specs->decl_attr = DECL_ATTRIBUTES (type);
07314 specs->typedef_p = true;
07315 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
07316 }
07317 }
07318 else if (TREE_CODE (type) == IDENTIFIER_NODE)
07319 {
07320 tree t = lookup_name (type);
07321 if (!t || TREE_CODE (t) != TYPE_DECL)
07322 error ("%qs fails to be a typedef or built in type",
07323 IDENTIFIER_POINTER (type));
07324 else if (TREE_TYPE (t) == error_mark_node)
07325 ;
07326 else
07327 specs->type = TREE_TYPE (t);
07328 }
07329 else if (TREE_CODE (type) != ERROR_MARK)
07330 {
07331 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref)
07332 specs->tag_defined_p = true;
07333 if (spec.kind == ctsk_typeof)
07334 specs->typedef_p = true;
07335 specs->type = type;
07336 }
07337
07338 return specs;
07339 }
07340
07341
07342
07343
07344 struct c_declspecs *
07345 declspecs_add_scspec (struct c_declspecs *specs, tree scspec)
07346 {
07347 enum rid i;
07348 enum c_storage_class n = csc_none;
07349 bool dupe = false;
07350 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
07351 && C_IS_RESERVED_WORD (scspec));
07352 i = C_RID_CODE (scspec);
07353 if (extra_warnings && specs->non_sc_seen_p)
07354 warning ("%qs is not at beginning of declaration",
07355 IDENTIFIER_POINTER (scspec));
07356 switch (i)
07357 {
07358 case RID_INLINE:
07359
07360
07361
07362
07363 dupe = false;
07364 specs->inline_p = true;
07365 break;
07366 case RID_THREAD:
07367 dupe = specs->thread_p;
07368 if (specs->storage_class == csc_auto)
07369 error ("%<__thread%> used with %<auto%>");
07370 else if (specs->storage_class == csc_register)
07371 error ("%<__thread%> used with %<register%>");
07372 else if (specs->storage_class == csc_typedef)
07373 error ("%<__thread%> used with %<typedef%>");
07374 else
07375 specs->thread_p = true;
07376 break;
07377 case RID_AUTO:
07378 n = csc_auto;
07379 break;
07380 case RID_EXTERN:
07381 n = csc_extern;
07382
07383 if (specs->thread_p)
07384 error ("%<__thread%> before %<extern%>");
07385 break;
07386 case RID_REGISTER:
07387 n = csc_register;
07388 break;
07389 case RID_STATIC:
07390 n = csc_static;
07391
07392 if (specs->thread_p)
07393 error ("%<__thread%> before %<static%>");
07394 break;
07395 case RID_TYPEDEF:
07396 n = csc_typedef;
07397 break;
07398 default:
07399 gcc_unreachable ();
07400 }
07401 if (n != csc_none && n == specs->storage_class)
07402 dupe = true;
07403 if (dupe)
07404 error ("duplicate %qs", IDENTIFIER_POINTER (scspec));
07405 if (n != csc_none)
07406 {
07407 if (specs->storage_class != csc_none && n != specs->storage_class)
07408 {
07409 error ("multiple storage classes in declaration specifiers");
07410 }
07411 else
07412 {
07413 specs->storage_class = n;
07414 if (n != csc_extern && n != csc_static && specs->thread_p)
07415 {
07416 error ("%<__thread%> used with %qs",
07417 IDENTIFIER_POINTER (scspec));
07418 specs->thread_p = false;
07419 }
07420 }
07421 }
07422 return specs;
07423 }
07424
07425
07426
07427
07428 struct c_declspecs *
07429 declspecs_add_attrs (struct c_declspecs *specs, tree attrs)
07430 {
07431 specs->attrs = chainon (attrs, specs->attrs);
07432 return specs;
07433 }
07434
07435
07436
07437
07438
07439
07440
07441 struct c_declspecs *
07442 finish_declspecs (struct c_declspecs *specs)
07443 {
07444
07445
07446 if (specs->type != NULL_TREE)
07447 {
07448 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
07449 && !specs->signed_p && !specs->unsigned_p
07450 && !specs->complex_p);
07451 return specs;
07452 }
07453
07454
07455
07456
07457
07458
07459 if (specs->typespec_word == cts_none)
07460 {
07461 if (specs->long_p || specs->short_p
07462 || specs->signed_p || specs->unsigned_p)
07463 {
07464 specs->typespec_word = cts_int;
07465 }
07466 else if (specs->complex_p)
07467 {
07468 specs->typespec_word = cts_double;
07469 if (pedantic)
07470 pedwarn ("ISO C does not support plain %<complex%> meaning "
07471 "%<double complex%>");
07472 }
07473 else
07474 {
07475 specs->typespec_word = cts_int;
07476 specs->default_int_p = true;
07477
07478
07479
07480 }
07481 }
07482
07483
07484
07485
07486 specs->explicit_signed_p = specs->signed_p;
07487
07488
07489 switch (specs->typespec_word)
07490 {
07491 case cts_void:
07492 gcc_assert (!specs->long_p && !specs->short_p
07493 && !specs->signed_p && !specs->unsigned_p
07494 && !specs->complex_p);
07495 specs->type = void_type_node;
07496 break;
07497 case cts_bool:
07498 gcc_assert (!specs->long_p && !specs->short_p
07499 && !specs->signed_p && !specs->unsigned_p
07500 && !specs->complex_p);
07501 specs->type = boolean_type_node;
07502 break;
07503 case cts_char:
07504 gcc_assert (!specs->long_p && !specs->short_p);
07505 gcc_assert (!(specs->signed_p && specs->unsigned_p));
07506 if (specs->signed_p)
07507 specs->type = signed_char_type_node;
07508 else if (specs->unsigned_p)
07509 specs->type = unsigned_char_type_node;
07510 else
07511 specs->type = char_type_node;
07512 if (specs->complex_p)
07513 {
07514 if (pedantic)
07515 pedwarn ("ISO C does not support complex integer types");
07516 specs->type = build_complex_type (specs->type);
07517 }
07518 break;
07519 case cts_int:
07520 gcc_assert (!(specs->long_p && specs->short_p));
07521 gcc_assert (!(specs->signed_p && specs->unsigned_p));
07522 if (specs->long_long_p)
07523 {
07524 #ifdef TARG_SL
07525 if (Long_Long_Support == TRUE)
07526 {
07527 specs->type = (specs->unsigned_p
07528 ? long_long_unsigned_type_node
07529 : long_long_integer_type_node);
07530 }
07531 else
07532 {
07533 warning("\"long long\" is mapped to \"long\", "
07534 "Please use \"-mlong-long\" option to enbale long long type suporting");
07535 specs->type = (specs->unsigned_p
07536 ? long_unsigned_type_node
07537 : long_integer_type_node);
07538 }
07539 #else
07540 specs->type = (specs->unsigned_p
07541 ? long_long_unsigned_type_node
07542 : long_long_integer_type_node);
07543
07544 #endif
07545 }
07546 else if (specs->long_p)
07547 specs->type = (specs->unsigned_p
07548 ? long_unsigned_type_node
07549 : long_integer_type_node);
07550 else if (specs->short_p)
07551 specs->type = (specs->unsigned_p
07552 ? short_unsigned_type_node
07553 : short_integer_type_node);
07554 else
07555 specs->type = (specs->unsigned_p
07556 ? unsigned_type_node
07557 : integer_type_node);
07558 if (specs->complex_p)
07559 {
07560 #ifdef TARG_SL
07561 error("Unsupported type: \"complex\"");
07562 #endif
07563 if (pedantic)
07564 pedwarn ("ISO C does not support complex integer types");
07565 specs->type = build_complex_type (specs->type);
07566 }
07567 break;
07568 case cts_float:
07569 gcc_assert (!specs->long_p && !specs->short_p
07570 && !specs->signed_p && !specs->unsigned_p);
07571 specs->type = (specs->complex_p
07572 ? complex_float_type_node
07573 : float_type_node);
07574
07575 #ifdef TARG_SL
07576 if (TYPE_MAIN_VARIANT(specs->type) == float_type_node)
07577 {
07578 if (Float_Point_Support == FALSE)
07579 {
07580 error("\"float\" type is not supported in default mode, "
07581 "Please use \"-msoft-float\" option to enable float point emulation");
07582 }
07583 }
07584 else
07585 {
07586 warning("Unsupported type: \"complex float\"");
07587 }
07588 #endif
07589
07590 break;
07591 case cts_double:
07592 gcc_assert (!specs->long_long_p && !specs->short_p
07593 && !specs->signed_p && !specs->unsigned_p);
07594 if (specs->long_p)
07595 {
07596 specs->type = (specs->complex_p
07597 ? complex_long_double_type_node
07598 : long_double_type_node);
07599 }
07600 else
07601 {
07602 specs->type = (specs->complex_p
07603 ? complex_double_type_node
07604 : double_type_node);
07605 }
07606
07607 #ifdef TARG_SL
07608 if (TYPE_MAIN_VARIANT(specs->type) == double_type_node)
07609 {
07610 if (Float_Point_Support == FALSE)
07611 {
07612 error("\"double\" type is not supported in default mode, "
07613 "Please use \"-msoft-float\" option to enable float point emulation");
07614 }
07615 }
07616 else
07617 {
07618 warning("Unsupported type: \"complex/long double\"");
07619 }
07620 #endif
07621
07622 break;
07623 default:
07624 gcc_unreachable ();
07625 }
07626
07627 return specs;
07628 }
07629
07630
07631
07632
07633 static void
07634 build_cdtor (int method_type, tree cdtors)
07635 {
07636 tree body = 0;
07637
07638 if (!cdtors)
07639 return;
07640
07641 for (; cdtors; cdtors = TREE_CHAIN (cdtors))
07642 append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
07643 &body);
07644
07645 cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
07646 }
07647
07648
07649
07650
07651
07652 #include <stdlib.h>
07653
07654 static void
07655 c_write_global_declarations_1 (tree globals)
07656 {
07657 tree decl;
07658
07659
07660 for (decl = globals; decl; decl = TREE_CHAIN (decl))
07661 {
07662
07663
07664
07665 if (TREE_CODE (decl) == FUNCTION_DECL
07666 && DECL_INITIAL (decl) == 0
07667 && DECL_EXTERNAL (decl)
07668 && !TREE_PUBLIC (decl)
07669 && C_DECL_USED (decl))
07670 {
07671 pedwarn ("%J%qF used but never defined", decl, decl);
07672 TREE_NO_WARNING (decl) = 1;
07673 }
07674
07675 wrapup_global_declaration_1 (decl);
07676 wrapup_global_declaration_2 (decl);
07677 check_global_declaration_1 (decl);
07678
07679 #ifdef KEY
07680 if (!DECL_IS_BUILTIN (decl)) {
07681 if (flag_spin_file)
07682 gspin (decl);
07683 }
07684 #endif
07685 }
07686 }
07687
07688
07689
07690
07691 static void
07692 c_write_global_declarations_2 (tree globals)
07693 {
07694 tree decl;
07695
07696 for (decl = globals; decl ; decl = TREE_CHAIN (decl))
07697 debug_hooks->global_decl (decl);
07698 }
07699
07700
07701 static GTY(()) tree ext_block;
07702
07703 void
07704 c_write_global_declarations (void)
07705 {
07706 tree t;
07707 #ifdef KEY
07708 extern void remove_asm_file (void);
07709 #endif
07710
07711
07712 if (pch_file)
07713 return;
07714
07715
07716
07717 if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in))
07718 return;
07719
07720
07721 ext_block = pop_scope ();
07722 external_scope = 0;
07723 gcc_assert (!current_scope);
07724
07725
07726
07727 for (t = all_translation_units; t; t = TREE_CHAIN (t))
07728 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
07729 c_write_global_declarations_1 (BLOCK_VARS (ext_block));
07730
07731
07732
07733
07734 build_cdtor ('I', static_ctors); static_ctors = 0;
07735 build_cdtor ('D', static_dtors); static_dtors = 0;
07736
07737 #ifdef KEY
07738 if (flag_spin_file) {
07739 remove_asm_file ();
07740 if (!errorcount)
07741 exit (EXIT_SUCCESS);
07742 else
07743 exit (2);
07744 }
07745 #endif
07746
07747
07748
07749 cgraph_optimize ();
07750
07751
07752
07753 if (errorcount == 0 && sorrycount == 0)
07754 {
07755 timevar_push (TV_SYMOUT);
07756 for (t = all_translation_units; t; t = TREE_CHAIN (t))
07757 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
07758 c_write_global_declarations_2 (