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