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