c-decl.c revision 117421
1/* Process declarations and variables for C compiler. 2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3 2001, 2002 Free Software Foundation, Inc. 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify it under 8the terms of the GNU General Public License as published by the Free 9Software Foundation; either version 2, or (at your option) any later 10version. 11 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13WARRANTY; without even the implied warranty of MERCHANTABILITY or 14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15for more details. 16 17You should have received a copy of the GNU General Public License 18along with GCC; see the file COPYING. If not, write to the Free 19Software Foundation, 59 Temple Place - Suite 330, Boston, MA 2002111-1307, USA. */ 21 22/* $FreeBSD: head/contrib/gcc/c-decl.c 117421 2003-07-11 05:11:14Z kan $ */ 23 24/* Process declarations and symbol lookup for C front end. 25 Also constructs types; the standard scalar types at initialization, 26 and structure, union, array and enum types when they are declared. */ 27 28/* ??? not all decl nodes are given the most useful possible 29 line numbers. For example, the CONST_DECLs for enum values. */ 30 31#include "config.h" 32#include "system.h" 33#include "intl.h" 34#include "tree.h" 35#include "tree-inline.h" 36#include "rtl.h" 37#include "flags.h" 38#include "function.h" 39#include "output.h" 40#include "expr.h" 41#include "c-tree.h" 42#include "toplev.h" 43#include "ggc.h" 44#include "tm_p.h" 45#include "cpplib.h" 46#include "target.h" 47#include "debug.h" 48#include "timevar.h" 49#include "c-common.h" 50#include "c-pragma.h" 51#include "libfuncs.h" 52#include "except.h" 53 54/* In grokdeclarator, distinguish syntactic contexts of declarators. */ 55enum decl_context 56{ NORMAL, /* Ordinary declaration */ 57 FUNCDEF, /* Function definition */ 58 PARM, /* Declaration of parm before function body */ 59 FIELD, /* Declaration inside struct or union */ 60 BITFIELD, /* Likewise but with specified width */ 61 TYPENAME}; /* Typename (inside cast or sizeof) */ 62 63 64/* Nonzero if we have seen an invalid cross reference 65 to a struct, union, or enum, but not yet printed the message. */ 66 67tree pending_invalid_xref; 68/* File and line to appear in the eventual error message. */ 69const char *pending_invalid_xref_file; 70int pending_invalid_xref_line; 71 72/* While defining an enum type, this is 1 plus the last enumerator 73 constant value. Note that will do not have to save this or `enum_overflow' 74 around nested function definition since such a definition could only 75 occur in an enum value expression and we don't use these variables in 76 that case. */ 77 78static tree enum_next_value; 79 80/* Nonzero means that there was overflow computing enum_next_value. */ 81 82static int enum_overflow; 83 84/* Parsing a function declarator leaves a list of parameter names 85 or a chain or parameter decls here. */ 86 87static tree last_function_parms; 88 89/* Parsing a function declarator leaves here a chain of structure 90 and enum types declared in the parmlist. */ 91 92static tree last_function_parm_tags; 93 94/* After parsing the declarator that starts a function definition, 95 `start_function' puts here the list of parameter names or chain of decls. 96 `store_parm_decls' finds it here. */ 97 98static tree current_function_parms; 99 100/* Similar, for last_function_parm_tags. */ 101static tree current_function_parm_tags; 102 103/* Similar, for the file and line that the prototype came from if this is 104 an old-style definition. */ 105static const char *current_function_prototype_file; 106static int current_function_prototype_line; 107 108/* The current statement tree. */ 109 110static GTY(()) struct stmt_tree_s c_stmt_tree; 111 112/* The current scope statement stack. */ 113 114static GTY(()) tree c_scope_stmt_stack; 115 116/* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function 117 that have names. Here so we can clear out their names' definitions 118 at the end of the function. */ 119 120static GTY(()) tree named_labels; 121 122/* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ 123 124static GTY(()) tree shadowed_labels; 125 126/* Set to 0 at beginning of a function definition, set to 1 if 127 a return statement that specifies a return value is seen. */ 128 129int current_function_returns_value; 130 131/* Set to 0 at beginning of a function definition, set to 1 if 132 a return statement with no argument is seen. */ 133 134int current_function_returns_null; 135 136/* Set to 0 at beginning of a function definition, set to 1 if 137 a call to a noreturn function is seen. */ 138 139int current_function_returns_abnormally; 140 141/* Set to nonzero by `grokdeclarator' for a function 142 whose return type is defaulted, if warnings for this are desired. */ 143 144static int warn_about_return_type; 145 146/* Nonzero when starting a function declared `extern inline'. */ 147 148static int current_extern_inline; 149 150/* For each binding contour we allocate a binding_level structure 151 * which records the names defined in that contour. 152 * Contours include: 153 * 0) the global one 154 * 1) one for each function definition, 155 * where internal declarations of the parameters appear. 156 * 2) one for each compound statement, 157 * to record its declarations. 158 * 159 * The current meaning of a name can be found by searching the levels from 160 * the current one out to the global one. 161 */ 162 163/* Note that the information in the `names' component of the global contour 164 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ 165 166struct binding_level GTY(()) 167 { 168 /* A chain of _DECL nodes for all variables, constants, functions, 169 and typedef types. These are in the reverse of the order supplied. 170 */ 171 tree names; 172 173 /* A list of structure, union and enum definitions, 174 * for looking up tag names. 175 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, 176 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, 177 * or ENUMERAL_TYPE node. 178 */ 179 tree tags; 180 181 /* For each level, a list of shadowed outer-level local definitions 182 to be restored when this level is popped. 183 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and 184 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ 185 tree shadowed; 186 187 /* For each level (except not the global one), 188 a chain of BLOCK nodes for all the levels 189 that were entered and exited one level down. */ 190 tree blocks; 191 192 /* The BLOCK node for this level, if one has been preallocated. 193 If 0, the BLOCK is allocated (if needed) when the level is popped. */ 194 tree this_block; 195 196 /* The binding level which this one is contained in (inherits from). */ 197 struct binding_level *level_chain; 198 199 /* Nonzero for the level that holds the parameters of a function. */ 200 char parm_flag; 201 202 /* Nonzero if this level "doesn't exist" for tags. */ 203 char tag_transparent; 204 205 /* Nonzero if sublevels of this level "don't exist" for tags. 206 This is set in the parm level of a function definition 207 while reading the function body, so that the outermost block 208 of the function body will be tag-transparent. */ 209 char subblocks_tag_transparent; 210 211 /* Nonzero means make a BLOCK for this level regardless of all else. */ 212 char keep; 213 214 /* Nonzero means make a BLOCK if this level has any subblocks. */ 215 char keep_if_subblocks; 216 217 /* List of decls in `names' that have incomplete structure or 218 union types. */ 219 tree incomplete_list; 220 221 /* A list of decls giving the (reversed) specified order of parms, 222 not including any forward-decls in the parmlist. 223 This is so we can put the parms in proper order for assign_parms. */ 224 tree parm_order; 225 }; 226 227#define NULL_BINDING_LEVEL (struct binding_level *) NULL 228 229/* The binding level currently in effect. */ 230 231static GTY(()) struct binding_level *current_binding_level; 232 233/* A chain of binding_level structures awaiting reuse. */ 234 235static GTY((deletable (""))) struct binding_level *free_binding_level; 236 237/* The outermost binding level, for names of file scope. 238 This is created when the compiler is started and exists 239 through the entire run. */ 240 241static GTY(()) struct binding_level *global_binding_level; 242 243/* Binding level structures are initialized by copying this one. */ 244 245static struct binding_level clear_binding_level 246 = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, NULL, 247 NULL}; 248 249/* Nonzero means unconditionally make a BLOCK for the next level pushed. */ 250 251static int keep_next_level_flag; 252 253/* Nonzero means make a BLOCK for the next level pushed 254 if it has subblocks. */ 255 256static int keep_next_if_subblocks; 257 258/* The chain of outer levels of label scopes. 259 This uses the same data structure used for binding levels, 260 but it works differently: each link in the chain records 261 saved values of named_labels and shadowed_labels for 262 a label binding level outside the current one. */ 263 264static GTY(()) struct binding_level *label_level_chain; 265 266/* Functions called automatically at the beginning and end of execution. */ 267 268tree static_ctors, static_dtors; 269 270/* Forward declarations. */ 271 272static struct binding_level * make_binding_level PARAMS ((void)); 273static void pop_binding_level PARAMS ((struct binding_level **)); 274static void clear_limbo_values PARAMS ((tree)); 275static int duplicate_decls PARAMS ((tree, tree, int)); 276static int redeclaration_error_message PARAMS ((tree, tree)); 277static void storedecls PARAMS ((tree)); 278static void storetags PARAMS ((tree)); 279static tree lookup_tag PARAMS ((enum tree_code, tree, 280 struct binding_level *, int)); 281static tree lookup_tag_reverse PARAMS ((tree)); 282static tree grokdeclarator PARAMS ((tree, tree, enum decl_context, 283 int)); 284static tree grokparms PARAMS ((tree, int)); 285static void layout_array_type PARAMS ((tree)); 286static tree c_make_fname_decl PARAMS ((tree, int)); 287static void c_expand_body PARAMS ((tree, int, int)); 288static void warn_if_shadowing PARAMS ((tree, tree)); 289static bool flexible_array_type_p PARAMS ((tree)); 290static tree set_save_expr_context PARAMS ((tree *, int *, void *)); 291 292/* States indicating how grokdeclarator() should handle declspecs marked 293 with __attribute__((deprecated)). An object declared as 294 __attribute__((deprecated)) suppresses warnings of uses of other 295 deprecated items. */ 296 297enum deprecated_states { 298 DEPRECATED_NORMAL, 299 DEPRECATED_SUPPRESS 300}; 301 302static enum deprecated_states deprecated_state = DEPRECATED_NORMAL; 303 304void 305c_print_identifier (file, node, indent) 306 FILE *file; 307 tree node; 308 int indent; 309{ 310 print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4); 311 print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); 312 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); 313 print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); 314 print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); 315 print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4); 316 if (C_IS_RESERVED_WORD (node)) 317 { 318 tree rid = ridpointers[C_RID_CODE (node)]; 319 indent_to (file, indent + 4); 320 fprintf (file, "rid "); 321 fprintf (file, HOST_PTR_PRINTF, (void *)rid); 322 fprintf (file, " \"%s\"", IDENTIFIER_POINTER (rid)); 323 } 324} 325 326/* Hook called at end of compilation to assume 1 elt 327 for a top-level tentative array defn that wasn't complete before. */ 328 329void 330c_finish_incomplete_decl (decl) 331 tree decl; 332{ 333 if (TREE_CODE (decl) == VAR_DECL) 334 { 335 tree type = TREE_TYPE (decl); 336 if (type != error_mark_node 337 && TREE_CODE (type) == ARRAY_TYPE 338 && ! DECL_EXTERNAL (decl) 339 && TYPE_DOMAIN (type) == 0) 340 { 341 warning_with_decl (decl, "array `%s' assumed to have one element"); 342 343 complete_array_type (type, NULL_TREE, 1); 344 345 layout_decl (decl, 0); 346 } 347 } 348} 349 350/* Reuse or create a struct for this binding level. */ 351 352static struct binding_level * 353make_binding_level () 354{ 355 if (free_binding_level) 356 { 357 struct binding_level *result = free_binding_level; 358 free_binding_level = result->level_chain; 359 return result; 360 } 361 else 362 return (struct binding_level *) ggc_alloc (sizeof (struct binding_level)); 363} 364 365/* Remove a binding level from a list and add it to the level chain. */ 366 367static void 368pop_binding_level (lp) 369 struct binding_level **lp; 370{ 371 struct binding_level *l = *lp; 372 *lp = l->level_chain; 373 374 memset (l, 0, sizeof (struct binding_level)); 375 l->level_chain = free_binding_level; 376 free_binding_level = l; 377} 378 379/* Nonzero if we are currently in the global binding level. */ 380 381int 382global_bindings_p () 383{ 384 return current_binding_level == global_binding_level; 385} 386 387void 388keep_next_level () 389{ 390 keep_next_level_flag = 1; 391} 392 393/* Nonzero if the current level needs to have a BLOCK made. */ 394 395int 396kept_level_p () 397{ 398 return ((current_binding_level->keep_if_subblocks 399 && current_binding_level->blocks != 0) 400 || current_binding_level->keep 401 || current_binding_level->names != 0 402 || (current_binding_level->tags != 0 403 && !current_binding_level->tag_transparent)); 404} 405 406/* Identify this binding level as a level of parameters. 407 DEFINITION_FLAG is 1 for a definition, 0 for a declaration. 408 But it turns out there is no way to pass the right value for 409 DEFINITION_FLAG, so we ignore it. */ 410 411void 412declare_parm_level (definition_flag) 413 int definition_flag ATTRIBUTE_UNUSED; 414{ 415 current_binding_level->parm_flag = 1; 416} 417 418/* Nonzero if currently making parm declarations. */ 419 420int 421in_parm_level_p () 422{ 423 return current_binding_level->parm_flag; 424} 425 426/* Enter a new binding level. 427 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, 428 not for that of tags. */ 429 430void 431pushlevel (tag_transparent) 432 int tag_transparent; 433{ 434 struct binding_level *newlevel = NULL_BINDING_LEVEL; 435 436 /* If this is the top level of a function, 437 just make sure that NAMED_LABELS is 0. */ 438 439 if (current_binding_level == global_binding_level) 440 { 441 named_labels = 0; 442 } 443 444 newlevel = make_binding_level (); 445 446 /* Add this level to the front of the chain (stack) of levels that 447 are active. */ 448 449 *newlevel = clear_binding_level; 450 newlevel->tag_transparent 451 = (tag_transparent 452 || (current_binding_level 453 ? current_binding_level->subblocks_tag_transparent 454 : 0)); 455 newlevel->level_chain = current_binding_level; 456 current_binding_level = newlevel; 457 newlevel->keep = keep_next_level_flag; 458 keep_next_level_flag = 0; 459 newlevel->keep_if_subblocks = keep_next_if_subblocks; 460 keep_next_if_subblocks = 0; 461} 462 463/* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */ 464 465static void 466clear_limbo_values (block) 467 tree block; 468{ 469 tree tem; 470 471 for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem)) 472 if (DECL_NAME (tem) != 0) 473 IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0; 474 475 for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem)) 476 clear_limbo_values (tem); 477} 478 479/* Exit a binding level. 480 Pop the level off, and restore the state of the identifier-decl mappings 481 that were in effect when this level was entered. 482 483 If KEEP is nonzero, this level had explicit declarations, so 484 and create a "block" (a BLOCK node) for the level 485 to record its declarations and subblocks for symbol table output. 486 487 If FUNCTIONBODY is nonzero, this level is the body of a function, 488 so create a block as if KEEP were set and also clear out all 489 label names. 490 491 If REVERSE is nonzero, reverse the order of decls before putting 492 them into the BLOCK. */ 493 494tree 495poplevel (keep, reverse, functionbody) 496 int keep; 497 int reverse; 498 int functionbody; 499{ 500 tree link; 501 /* The chain of decls was accumulated in reverse order. 502 Put it into forward order, just for cleanliness. */ 503 tree decls; 504 tree tags = current_binding_level->tags; 505 tree subblocks = current_binding_level->blocks; 506 tree block = 0; 507 tree decl; 508 int block_previously_created; 509 510 keep |= current_binding_level->keep; 511 512 /* This warning is turned off because it causes warnings for 513 declarations like `extern struct foo *x'. */ 514#if 0 515 /* Warn about incomplete structure types in this level. */ 516 for (link = tags; link; link = TREE_CHAIN (link)) 517 if (!COMPLETE_TYPE_P (TREE_VALUE (link))) 518 { 519 tree type = TREE_VALUE (link); 520 tree type_name = TYPE_NAME (type); 521 char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE 522 ? type_name 523 : DECL_NAME (type_name)); 524 switch (TREE_CODE (type)) 525 { 526 case RECORD_TYPE: 527 error ("`struct %s' incomplete in scope ending here", id); 528 break; 529 case UNION_TYPE: 530 error ("`union %s' incomplete in scope ending here", id); 531 break; 532 case ENUMERAL_TYPE: 533 error ("`enum %s' incomplete in scope ending here", id); 534 break; 535 } 536 } 537#endif /* 0 */ 538 539 /* Get the decls in the order they were written. 540 Usually current_binding_level->names is in reverse order. 541 But parameter decls were previously put in forward order. */ 542 543 if (reverse) 544 current_binding_level->names 545 = decls = nreverse (current_binding_level->names); 546 else 547 decls = current_binding_level->names; 548 549 /* Output any nested inline functions within this block 550 if they weren't already output. */ 551 552 for (decl = decls; decl; decl = TREE_CHAIN (decl)) 553 if (TREE_CODE (decl) == FUNCTION_DECL 554 && ! TREE_ASM_WRITTEN (decl) 555 && DECL_INITIAL (decl) != 0 556 && TREE_ADDRESSABLE (decl)) 557 { 558 /* If this decl was copied from a file-scope decl 559 on account of a block-scope extern decl, 560 propagate TREE_ADDRESSABLE to the file-scope decl. 561 562 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is 563 true, since then the decl goes through save_for_inline_copying. */ 564 if (DECL_ABSTRACT_ORIGIN (decl) != 0 565 && DECL_ABSTRACT_ORIGIN (decl) != decl) 566 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; 567 } 568 569 /* We used to warn about unused variables in expand_end_bindings, 570 i.e. while generating RTL. But in function-at-a-time mode we may 571 choose to never expand a function at all (e.g. auto inlining), so 572 we do this explicitly now. */ 573 warn_about_unused_variables (getdecls ()); 574 575 /* If there were any declarations or structure tags in that level, 576 or if this level is a function body, 577 create a BLOCK to record them for the life of this function. */ 578 579 block = 0; 580 block_previously_created = (current_binding_level->this_block != 0); 581 if (block_previously_created) 582 block = current_binding_level->this_block; 583 else if (keep || functionbody 584 || (current_binding_level->keep_if_subblocks && subblocks != 0)) 585 block = make_node (BLOCK); 586 if (block != 0) 587 { 588 BLOCK_VARS (block) = decls; 589 BLOCK_SUBBLOCKS (block) = subblocks; 590 } 591 592 /* In each subblock, record that this is its superior. */ 593 594 for (link = subblocks; link; link = TREE_CHAIN (link)) 595 BLOCK_SUPERCONTEXT (link) = block; 596 597 /* Clear out the meanings of the local variables of this level. */ 598 599 for (link = decls; link; link = TREE_CHAIN (link)) 600 { 601 if (DECL_NAME (link) != 0) 602 { 603 /* If the ident. was used or addressed via a local extern decl, 604 don't forget that fact. */ 605 if (DECL_EXTERNAL (link)) 606 { 607 if (TREE_USED (link)) 608 TREE_USED (DECL_NAME (link)) = 1; 609 if (TREE_ADDRESSABLE (link)) 610 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; 611 } 612 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; 613 } 614 } 615 616 /* Restore all name-meanings of the outer levels 617 that were shadowed by this level. */ 618 619 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) 620 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 621 622 /* If the level being exited is the top level of a function, 623 check over all the labels, and clear out the current 624 (function local) meanings of their names. */ 625 626 if (functionbody) 627 { 628 clear_limbo_values (block); 629 630 /* If this is the top level block of a function, 631 the vars are the function's parameters. 632 Don't leave them in the BLOCK because they are 633 found in the FUNCTION_DECL instead. */ 634 635 BLOCK_VARS (block) = 0; 636 637 /* Clear out the definitions of all label names, 638 since their scopes end here, 639 and add them to BLOCK_VARS. */ 640 641 for (link = named_labels; link; link = TREE_CHAIN (link)) 642 { 643 tree label = TREE_VALUE (link); 644 645 if (DECL_INITIAL (label) == 0) 646 { 647 error_with_decl (label, "label `%s' used but not defined"); 648 /* Avoid crashing later. */ 649 define_label (input_filename, lineno, 650 DECL_NAME (label)); 651 } 652 else if (warn_unused_label && !TREE_USED (label)) 653 warning_with_decl (label, "label `%s' defined but not used"); 654 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0; 655 656 /* Put the labels into the "variables" of the 657 top-level block, so debugger can see them. */ 658 TREE_CHAIN (label) = BLOCK_VARS (block); 659 BLOCK_VARS (block) = label; 660 } 661 } 662 663 /* Pop the current level, and free the structure for reuse. */ 664 665 pop_binding_level (¤t_binding_level); 666 667 /* Dispose of the block that we just made inside some higher level. */ 668 if (functionbody) 669 DECL_INITIAL (current_function_decl) = block; 670 else if (block) 671 { 672 if (!block_previously_created) 673 current_binding_level->blocks 674 = chainon (current_binding_level->blocks, block); 675 } 676 /* If we did not make a block for the level just exited, 677 any blocks made for inner levels 678 (since they cannot be recorded as subblocks in that level) 679 must be carried forward so they will later become subblocks 680 of something else. */ 681 else if (subblocks) 682 current_binding_level->blocks 683 = chainon (current_binding_level->blocks, subblocks); 684 685 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this 686 binding contour so that they point to the appropriate construct, i.e. 687 either to the current FUNCTION_DECL node, or else to the BLOCK node 688 we just constructed. 689 690 Note that for tagged types whose scope is just the formal parameter 691 list for some function type specification, we can't properly set 692 their TYPE_CONTEXTs here, because we don't have a pointer to the 693 appropriate FUNCTION_TYPE node readily available to us. For those 694 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set 695 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE 696 node which will represent the "scope" for these "parameter list local" 697 tagged types. */ 698 699 if (functionbody) 700 for (link = tags; link; link = TREE_CHAIN (link)) 701 TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl; 702 else if (block) 703 for (link = tags; link; link = TREE_CHAIN (link)) 704 TYPE_CONTEXT (TREE_VALUE (link)) = block; 705 706 if (block) 707 TREE_USED (block) = 1; 708 709 return block; 710} 711 712/* Insert BLOCK at the end of the list of subblocks of the 713 current binding level. This is used when a BIND_EXPR is expanded, 714 to handle the BLOCK node inside the BIND_EXPR. */ 715 716void 717insert_block (block) 718 tree block; 719{ 720 TREE_USED (block) = 1; 721 current_binding_level->blocks 722 = chainon (current_binding_level->blocks, block); 723} 724 725/* Set the BLOCK node for the innermost scope 726 (the one we are currently in). */ 727 728void 729set_block (block) 730 tree block; 731{ 732 current_binding_level->this_block = block; 733 current_binding_level->names = chainon (current_binding_level->names, 734 BLOCK_VARS (block)); 735 current_binding_level->blocks = chainon (current_binding_level->blocks, 736 BLOCK_SUBBLOCKS (block)); 737} 738 739void 740push_label_level () 741{ 742 struct binding_level *newlevel; 743 744 newlevel = make_binding_level (); 745 746 /* Add this level to the front of the chain (stack) of label levels. */ 747 748 newlevel->level_chain = label_level_chain; 749 label_level_chain = newlevel; 750 751 newlevel->names = named_labels; 752 newlevel->shadowed = shadowed_labels; 753 named_labels = 0; 754 shadowed_labels = 0; 755} 756 757void 758pop_label_level () 759{ 760 struct binding_level *level = label_level_chain; 761 tree link, prev; 762 763 /* Clear out the definitions of the declared labels in this level. 764 Leave in the list any ordinary, non-declared labels. */ 765 for (link = named_labels, prev = 0; link;) 766 { 767 if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link))) 768 { 769 if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0) 770 { 771 error_with_decl (TREE_VALUE (link), 772 "label `%s' used but not defined"); 773 /* Avoid crashing later. */ 774 define_label (input_filename, lineno, 775 DECL_NAME (TREE_VALUE (link))); 776 } 777 else if (warn_unused_label && !TREE_USED (TREE_VALUE (link))) 778 warning_with_decl (TREE_VALUE (link), 779 "label `%s' defined but not used"); 780 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0; 781 782 /* Delete this element from the list. */ 783 link = TREE_CHAIN (link); 784 if (prev) 785 TREE_CHAIN (prev) = link; 786 else 787 named_labels = link; 788 } 789 else 790 { 791 prev = link; 792 link = TREE_CHAIN (link); 793 } 794 } 795 796 /* Bring back all the labels that were shadowed. */ 797 for (link = shadowed_labels; link; link = TREE_CHAIN (link)) 798 if (DECL_NAME (TREE_VALUE (link)) != 0) 799 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) 800 = TREE_VALUE (link); 801 802 named_labels = chainon (named_labels, level->names); 803 shadowed_labels = level->shadowed; 804 805 /* Pop the current level, and free the structure for reuse. */ 806 pop_binding_level (&label_level_chain); 807} 808 809/* Push a definition or a declaration of struct, union or enum tag "name". 810 "type" should be the type node. 811 We assume that the tag "name" is not already defined. 812 813 Note that the definition may really be just a forward reference. 814 In that case, the TYPE_SIZE will be zero. */ 815 816void 817pushtag (name, type) 818 tree name, type; 819{ 820 struct binding_level *b; 821 822 /* Find the proper binding level for this type tag. */ 823 824 for (b = current_binding_level; b->tag_transparent; b = b->level_chain) 825 continue; 826 827 if (name) 828 { 829 /* Record the identifier as the type's name if it has none. */ 830 831 if (TYPE_NAME (type) == 0) 832 TYPE_NAME (type) = name; 833 } 834 835 b->tags = tree_cons (name, type, b->tags); 836 837 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the 838 tagged type we just added to the current binding level. This fake 839 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs 840 to output a representation of a tagged type, and it also gives 841 us a convenient place to record the "scope start" address for the 842 tagged type. */ 843 844 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); 845 846 /* An approximation for now, so we can tell this is a function-scope tag. 847 This will be updated in poplevel. */ 848 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type)); 849} 850 851/* Handle when a new declaration NEWDECL 852 has the same name as an old one OLDDECL 853 in the same binding contour. 854 Prints an error message if appropriate. 855 856 If safely possible, alter OLDDECL to look like NEWDECL, and return 1. 857 Otherwise, return 0. 858 859 When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration, 860 and OLDDECL is in an outer binding level and should thus not be changed. */ 861 862static int 863duplicate_decls (newdecl, olddecl, different_binding_level) 864 tree newdecl, olddecl; 865 int different_binding_level; 866{ 867 int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); 868 int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL 869 && DECL_INITIAL (newdecl) != 0); 870 tree oldtype = TREE_TYPE (olddecl); 871 tree newtype = TREE_TYPE (newdecl); 872 int errmsg = 0; 873 874 if (DECL_P (olddecl)) 875 { 876 if (TREE_CODE (newdecl) == FUNCTION_DECL 877 && TREE_CODE (olddecl) == FUNCTION_DECL 878 && (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl))) 879 { 880 if (DECL_DECLARED_INLINE_P (newdecl) 881 && DECL_UNINLINABLE (newdecl) 882 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) 883 /* Already warned elsewhere. */; 884 else if (DECL_DECLARED_INLINE_P (olddecl) 885 && DECL_UNINLINABLE (olddecl) 886 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) 887 /* Already warned. */; 888 else if (DECL_DECLARED_INLINE_P (newdecl) 889 && ! DECL_DECLARED_INLINE_P (olddecl) 890 && DECL_UNINLINABLE (olddecl) 891 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) 892 { 893 warning_with_decl (newdecl, 894 "function `%s' redeclared as inline"); 895 warning_with_decl (olddecl, 896 "previous declaration of function `%s' with attribute noinline"); 897 } 898 else if (DECL_DECLARED_INLINE_P (olddecl) 899 && DECL_UNINLINABLE (newdecl) 900 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) 901 { 902 warning_with_decl (newdecl, 903 "function `%s' redeclared with attribute noinline"); 904 warning_with_decl (olddecl, 905 "previous declaration of function `%s' was inline"); 906 } 907 } 908 909 DECL_ATTRIBUTES (newdecl) 910 = (*targetm.merge_decl_attributes) (olddecl, newdecl); 911 } 912 913 if (TREE_CODE (newtype) == ERROR_MARK 914 || TREE_CODE (oldtype) == ERROR_MARK) 915 types_match = 0; 916 917 /* New decl is completely inconsistent with the old one => 918 tell caller to replace the old one. 919 This is always an error except in the case of shadowing a builtin. */ 920 if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) 921 { 922 if (TREE_CODE (olddecl) == FUNCTION_DECL 923 && (DECL_BUILT_IN (olddecl) 924 || DECL_BUILT_IN_NONANSI (olddecl))) 925 { 926 /* If you declare a built-in or predefined function name as static, 927 the old definition is overridden, 928 but optionally warn this was a bad choice of name. */ 929 if (!TREE_PUBLIC (newdecl)) 930 { 931 if (!warn_shadow) 932 ; 933 else if (DECL_BUILT_IN (olddecl)) 934 warning_with_decl (newdecl, "shadowing built-in function `%s'"); 935 else 936 warning_with_decl (newdecl, "shadowing library function `%s'"); 937 } 938 /* Likewise, if the built-in is not ansi, then programs can 939 override it even globally without an error. */ 940 else if (! DECL_BUILT_IN (olddecl)) 941 warning_with_decl (newdecl, 942 "library function `%s' declared as non-function"); 943 944 else if (DECL_BUILT_IN_NONANSI (olddecl)) 945 warning_with_decl (newdecl, 946 "built-in function `%s' declared as non-function"); 947 else 948 warning_with_decl (newdecl, 949 "built-in function `%s' declared as non-function"); 950 } 951 else 952 { 953 error_with_decl (newdecl, "`%s' redeclared as different kind of symbol"); 954 error_with_decl (olddecl, "previous declaration of `%s'"); 955 } 956 957 return 0; 958 } 959 960 /* For real parm decl following a forward decl, 961 return 1 so old decl will be reused. */ 962 if (types_match && TREE_CODE (newdecl) == PARM_DECL 963 && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl)) 964 return 1; 965 966 /* The new declaration is the same kind of object as the old one. 967 The declarations may partially match. Print warnings if they don't 968 match enough. Ultimately, copy most of the information from the new 969 decl to the old one, and keep using the old one. */ 970 971 if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_BUILT_IN (olddecl)) 972 { 973 /* A function declaration for a built-in function. */ 974 if (!TREE_PUBLIC (newdecl)) 975 { 976 /* If you declare a built-in function name as static, the 977 built-in definition is overridden, 978 but optionally warn this was a bad choice of name. */ 979 if (warn_shadow) 980 warning_with_decl (newdecl, "shadowing built-in function `%s'"); 981 /* Discard the old built-in function. */ 982 return 0; 983 } 984 else if (!types_match) 985 { 986 /* Accept the return type of the new declaration if same modes. */ 987 tree oldreturntype = TREE_TYPE (oldtype); 988 tree newreturntype = TREE_TYPE (newtype); 989 990 if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype)) 991 { 992 /* Function types may be shared, so we can't just modify 993 the return type of olddecl's function type. */ 994 tree trytype 995 = build_function_type (newreturntype, 996 TYPE_ARG_TYPES (oldtype)); 997 trytype = build_type_attribute_variant (trytype, 998 TYPE_ATTRIBUTES (oldtype)); 999 1000 types_match = comptypes (newtype, trytype); 1001 if (types_match) 1002 oldtype = trytype; 1003 } 1004 /* Accept harmless mismatch in first argument type also. 1005 This is for the ffs and fprintf builtins. */ 1006 if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0 1007 && TYPE_ARG_TYPES (oldtype) != 0 1008 && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0 1009 && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0 1010 && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype))) 1011 == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype))))) 1012 { 1013 /* Function types may be shared, so we can't just modify 1014 the return type of olddecl's function type. */ 1015 tree trytype 1016 = build_function_type (TREE_TYPE (oldtype), 1017 tree_cons (NULL_TREE, 1018 TREE_VALUE (TYPE_ARG_TYPES (newtype)), 1019 TREE_CHAIN (TYPE_ARG_TYPES (oldtype)))); 1020 trytype = build_type_attribute_variant (trytype, 1021 TYPE_ATTRIBUTES (oldtype)); 1022 1023 types_match = comptypes (newtype, trytype); 1024 if (types_match) 1025 oldtype = trytype; 1026 } 1027 if (! different_binding_level) 1028 TREE_TYPE (olddecl) = oldtype; 1029 } 1030 else if (TYPE_ARG_TYPES (oldtype) == NULL 1031 && TYPE_ARG_TYPES (newtype) != NULL) 1032 { 1033 /* For bcmp, bzero, fputs the builtin type has arguments not 1034 specified. Use the ones from the prototype so that type checking 1035 is done for them. */ 1036 tree trytype 1037 = build_function_type (TREE_TYPE (oldtype), 1038 TYPE_ARG_TYPES (newtype)); 1039 trytype = build_type_attribute_variant (trytype, 1040 TYPE_ATTRIBUTES (oldtype)); 1041 1042 oldtype = trytype; 1043 if (! different_binding_level) 1044 TREE_TYPE (olddecl) = oldtype; 1045 } 1046 if (!types_match) 1047 { 1048 /* If types don't match for a built-in, throw away the built-in. */ 1049 warning_with_decl (newdecl, "conflicting types for built-in function `%s'"); 1050 return 0; 1051 } 1052 } 1053 else if (TREE_CODE (olddecl) == FUNCTION_DECL 1054 && DECL_SOURCE_LINE (olddecl) == 0) 1055 { 1056 /* A function declaration for a predeclared function 1057 that isn't actually built in. */ 1058 if (!TREE_PUBLIC (newdecl)) 1059 { 1060 /* If you declare it as static, the 1061 default definition is overridden. */ 1062 return 0; 1063 } 1064 else if (!types_match) 1065 { 1066 /* If the types don't match, preserve volatility indication. 1067 Later on, we will discard everything else about the 1068 default declaration. */ 1069 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); 1070 } 1071 } 1072 /* Permit char *foo () to match void *foo (...) if not pedantic, 1073 if one of them came from a system header file. */ 1074 else if (!types_match 1075 && TREE_CODE (olddecl) == FUNCTION_DECL 1076 && TREE_CODE (newdecl) == FUNCTION_DECL 1077 && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE 1078 && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE 1079 && (DECL_IN_SYSTEM_HEADER (olddecl) 1080 || DECL_IN_SYSTEM_HEADER (newdecl)) 1081 && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node 1082 && TYPE_ARG_TYPES (oldtype) == 0 1083 && self_promoting_args_p (TYPE_ARG_TYPES (newtype)) 1084 && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node) 1085 || 1086 (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node 1087 && TYPE_ARG_TYPES (newtype) == 0 1088 && self_promoting_args_p (TYPE_ARG_TYPES (oldtype)) 1089 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node))) 1090 { 1091 if (pedantic) 1092 pedwarn_with_decl (newdecl, "conflicting types for `%s'"); 1093 /* Make sure we keep void * as ret type, not char *. */ 1094 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node) 1095 TREE_TYPE (newdecl) = newtype = oldtype; 1096 1097 /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration 1098 we will come back here again. */ 1099 DECL_IN_SYSTEM_HEADER (newdecl) = 1; 1100 } 1101 else if (!types_match 1102 /* Permit char *foo (int, ...); followed by char *foo (); 1103 if not pedantic. */ 1104 && ! (TREE_CODE (olddecl) == FUNCTION_DECL 1105 && ! pedantic 1106 /* Return types must still match. */ 1107 && comptypes (TREE_TYPE (oldtype), 1108 TREE_TYPE (newtype)) 1109 && TYPE_ARG_TYPES (newtype) == 0)) 1110 { 1111 error_with_decl (newdecl, "conflicting types for `%s'"); 1112 /* Check for function type mismatch 1113 involving an empty arglist vs a nonempty one. */ 1114 if (TREE_CODE (olddecl) == FUNCTION_DECL 1115 && comptypes (TREE_TYPE (oldtype), 1116 TREE_TYPE (newtype)) 1117 && ((TYPE_ARG_TYPES (oldtype) == 0 1118 && DECL_INITIAL (olddecl) == 0) 1119 || 1120 (TYPE_ARG_TYPES (newtype) == 0 1121 && DECL_INITIAL (newdecl) == 0))) 1122 { 1123 /* Classify the problem further. */ 1124 tree t = TYPE_ARG_TYPES (oldtype); 1125 if (t == 0) 1126 t = TYPE_ARG_TYPES (newtype); 1127 for (; t; t = TREE_CHAIN (t)) 1128 { 1129 tree type = TREE_VALUE (t); 1130 1131 if (TREE_CHAIN (t) == 0 1132 && TYPE_MAIN_VARIANT (type) != void_type_node) 1133 { 1134 error ("a parameter list with an ellipsis can't match an empty parameter name list declaration"); 1135 break; 1136 } 1137 1138 if (c_type_promotes_to (type) != type) 1139 { 1140 error ("an argument type that has a default promotion can't match an empty parameter name list declaration"); 1141 break; 1142 } 1143 } 1144 } 1145 error_with_decl (olddecl, "previous declaration of `%s'"); 1146 1147 /* This is safer because the initializer might contain references 1148 to variables that were declared between olddecl and newdecl. This 1149 will make the initializer invalid for olddecl in case it gets 1150 assigned to olddecl below. */ 1151 if (TREE_CODE (newdecl) == VAR_DECL) 1152 DECL_INITIAL (newdecl) = 0; 1153 } 1154 /* TLS cannot follow non-TLS declaration. */ 1155 else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL 1156 && !DECL_THREAD_LOCAL (olddecl) && DECL_THREAD_LOCAL (newdecl)) 1157 { 1158 error_with_decl (newdecl, "thread-local declaration of `%s' follows non thread-local declaration"); 1159 error_with_decl (olddecl, "previous declaration of `%s'"); 1160 } 1161 /* non-TLS declaration cannot follow TLS declaration. */ 1162 else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL 1163 && DECL_THREAD_LOCAL (olddecl) && !DECL_THREAD_LOCAL (newdecl)) 1164 { 1165 error_with_decl (newdecl, "non thread-local declaration of `%s' follows thread-local declaration"); 1166 error_with_decl (olddecl, "previous declaration of `%s'"); 1167 } 1168 else 1169 { 1170 errmsg = redeclaration_error_message (newdecl, olddecl); 1171 if (errmsg) 1172 { 1173 switch (errmsg) 1174 { 1175 case 1: 1176 error_with_decl (newdecl, "redefinition of `%s'"); 1177 break; 1178 case 2: 1179 error_with_decl (newdecl, "redeclaration of `%s'"); 1180 break; 1181 case 3: 1182 error_with_decl (newdecl, "conflicting declarations of `%s'"); 1183 break; 1184 default: 1185 abort (); 1186 } 1187 1188 error_with_decl (olddecl, 1189 ((DECL_INITIAL (olddecl) 1190 && current_binding_level == global_binding_level) 1191 ? "`%s' previously defined here" 1192 : "`%s' previously declared here")); 1193 return 0; 1194 } 1195 else if (TREE_CODE (newdecl) == TYPE_DECL 1196 && (DECL_IN_SYSTEM_HEADER (olddecl) 1197 || DECL_IN_SYSTEM_HEADER (newdecl))) 1198 { 1199 warning_with_decl (newdecl, "redefinition of `%s'"); 1200 warning_with_decl 1201 (olddecl, 1202 ((DECL_INITIAL (olddecl) 1203 && current_binding_level == global_binding_level) 1204 ? "`%s' previously defined here" 1205 : "`%s' previously declared here")); 1206 } 1207 else if (TREE_CODE (olddecl) == FUNCTION_DECL 1208 && DECL_INITIAL (olddecl) != 0 1209 && TYPE_ARG_TYPES (oldtype) == 0 1210 && TYPE_ARG_TYPES (newtype) != 0 1211 && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0) 1212 { 1213 tree type, parm; 1214 int nargs; 1215 /* Prototype decl follows defn w/o prototype. */ 1216 1217 for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype), 1218 type = TYPE_ARG_TYPES (newtype), 1219 nargs = 1; 1220 ; 1221 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++) 1222 { 1223 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node 1224 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) 1225 { 1226 warning_with_decl (newdecl, "prototype for `%s' follows"); 1227 warning_with_decl (olddecl, "non-prototype definition here"); 1228 break; 1229 } 1230 if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node 1231 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) 1232 { 1233 error_with_decl (newdecl, 1234 "prototype for `%s' follows and number of arguments doesn't match"); 1235 error_with_decl (olddecl, "non-prototype definition here"); 1236 errmsg = 1; 1237 break; 1238 } 1239 /* Type for passing arg must be consistent 1240 with that declared for the arg. */ 1241 if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type))) 1242 { 1243 error_with_decl (newdecl, 1244 "prototype for `%s' follows and argument %d doesn't match", 1245 nargs); 1246 error_with_decl (olddecl, "non-prototype definition here"); 1247 errmsg = 1; 1248 break; 1249 } 1250 } 1251 } 1252 /* Warn about mismatches in various flags. */ 1253 else 1254 { 1255 /* Warn if function is now inline 1256 but was previously declared not inline and has been called. */ 1257 if (TREE_CODE (olddecl) == FUNCTION_DECL 1258 && ! DECL_DECLARED_INLINE_P (olddecl) 1259 && DECL_DECLARED_INLINE_P (newdecl) 1260 && TREE_USED (olddecl)) 1261 warning_with_decl (newdecl, 1262 "`%s' declared inline after being called"); 1263 if (TREE_CODE (olddecl) == FUNCTION_DECL 1264 && ! DECL_DECLARED_INLINE_P (olddecl) 1265 && DECL_DECLARED_INLINE_P (newdecl) 1266 && DECL_INITIAL (olddecl) != 0) 1267 warning_with_decl (newdecl, 1268 "`%s' declared inline after its definition"); 1269 1270 /* If pedantic, warn when static declaration follows a non-static 1271 declaration. Otherwise, do so only for functions. */ 1272 if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL) 1273 && TREE_PUBLIC (olddecl) 1274 && !TREE_PUBLIC (newdecl)) 1275 warning_with_decl (newdecl, "static declaration for `%s' follows non-static"); 1276 1277 /* If warn_traditional, warn when a non-static function 1278 declaration follows a static one. */ 1279 if (warn_traditional && !in_system_header 1280 && TREE_CODE (olddecl) == FUNCTION_DECL 1281 && !TREE_PUBLIC (olddecl) 1282 && TREE_PUBLIC (newdecl)) 1283 warning_with_decl (newdecl, "non-static declaration for `%s' follows static"); 1284 1285 /* Warn when const declaration follows a non-const 1286 declaration, but not for functions. */ 1287 if (TREE_CODE (olddecl) != FUNCTION_DECL 1288 && !TREE_READONLY (olddecl) 1289 && TREE_READONLY (newdecl)) 1290 warning_with_decl (newdecl, "const declaration for `%s' follows non-const"); 1291 /* These bits are logically part of the type, for variables. 1292 But not for functions 1293 (where qualifiers are not valid ANSI anyway). */ 1294 else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL 1295 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) 1296 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) 1297 pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl"); 1298 } 1299 } 1300 1301 /* Optionally warn about more than one declaration for the same name. */ 1302 if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0 1303 /* Don't warn about a function declaration 1304 followed by a definition. */ 1305 && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0 1306 && DECL_INITIAL (olddecl) == 0) 1307 /* Don't warn about extern decl followed by (tentative) definition. */ 1308 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) 1309 { 1310 warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope"); 1311 warning_with_decl (olddecl, "previous declaration of `%s'"); 1312 } 1313 1314 /* Copy all the DECL_... slots specified in the new decl 1315 except for any that we copy here from the old type. 1316 1317 Past this point, we don't change OLDTYPE and NEWTYPE 1318 even if we change the types of NEWDECL and OLDDECL. */ 1319 1320 if (types_match) 1321 { 1322 /* When copying info to olddecl, we store into write_olddecl 1323 instead. This allows us to avoid modifying olddecl when 1324 different_binding_level is true. */ 1325 tree write_olddecl = different_binding_level ? newdecl : olddecl; 1326 1327 /* Merge the data types specified in the two decls. */ 1328 if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl)) 1329 { 1330 if (different_binding_level) 1331 { 1332 if (TYPE_ARG_TYPES (oldtype) != 0 1333 && TYPE_ARG_TYPES (newtype) == 0) 1334 TREE_TYPE (newdecl) = common_type (newtype, oldtype); 1335 else 1336 TREE_TYPE (newdecl) 1337 = build_type_attribute_variant 1338 (newtype, 1339 merge_attributes (TYPE_ATTRIBUTES (newtype), 1340 TYPE_ATTRIBUTES (oldtype))); 1341 } 1342 else 1343 TREE_TYPE (newdecl) 1344 = TREE_TYPE (olddecl) 1345 = common_type (newtype, oldtype); 1346 } 1347 1348 /* Lay the type out, unless already done. */ 1349 if (oldtype != TREE_TYPE (newdecl)) 1350 { 1351 if (TREE_TYPE (newdecl) != error_mark_node) 1352 layout_type (TREE_TYPE (newdecl)); 1353 if (TREE_CODE (newdecl) != FUNCTION_DECL 1354 && TREE_CODE (newdecl) != TYPE_DECL 1355 && TREE_CODE (newdecl) != CONST_DECL) 1356 layout_decl (newdecl, 0); 1357 } 1358 else 1359 { 1360 /* Since the type is OLDDECL's, make OLDDECL's size go with. */ 1361 DECL_SIZE (newdecl) = DECL_SIZE (olddecl); 1362 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl); 1363 DECL_MODE (newdecl) = DECL_MODE (olddecl); 1364 if (TREE_CODE (olddecl) != FUNCTION_DECL) 1365 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) 1366 { 1367 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); 1368 DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl); 1369 } 1370 } 1371 1372 /* Keep the old rtl since we can safely use it. */ 1373 COPY_DECL_RTL (olddecl, newdecl); 1374 1375 /* Merge the type qualifiers. */ 1376 if (TREE_READONLY (newdecl)) 1377 TREE_READONLY (write_olddecl) = 1; 1378 1379 if (TREE_THIS_VOLATILE (newdecl)) 1380 { 1381 TREE_THIS_VOLATILE (write_olddecl) = 1; 1382 if (TREE_CODE (newdecl) == VAR_DECL 1383 /* If an automatic variable is re-declared in the same 1384 function scope, but the old declaration was not 1385 volatile, make_var_volatile() would crash because the 1386 variable would have been assigned to a pseudo, not a 1387 MEM. Since this duplicate declaration is invalid 1388 anyway, we just skip the call. */ 1389 && errmsg == 0) 1390 make_var_volatile (newdecl); 1391 } 1392 1393 /* Keep source location of definition rather than declaration. */ 1394 /* When called with different_binding_level set, keep the old 1395 information so that meaningful diagnostics can be given. */ 1396 if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0 1397 && ! different_binding_level) 1398 { 1399 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); 1400 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); 1401 } 1402 1403 /* Merge the unused-warning information. */ 1404 if (DECL_IN_SYSTEM_HEADER (olddecl)) 1405 DECL_IN_SYSTEM_HEADER (newdecl) = 1; 1406 else if (DECL_IN_SYSTEM_HEADER (newdecl)) 1407 DECL_IN_SYSTEM_HEADER (write_olddecl) = 1; 1408 1409 /* Merge the initialization information. */ 1410 /* When called with different_binding_level set, don't copy over 1411 DECL_INITIAL, so that we don't accidentally change function 1412 declarations into function definitions. */ 1413 if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level) 1414 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 1415 1416 /* Merge the section attribute. 1417 We want to issue an error if the sections conflict but that must be 1418 done later in decl_attributes since we are called before attributes 1419 are assigned. */ 1420 if (DECL_SECTION_NAME (newdecl) == NULL_TREE) 1421 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); 1422 1423 /* Copy the assembler name. 1424 Currently, it can only be defined in the prototype. */ 1425 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); 1426 1427 if (TREE_CODE (newdecl) == FUNCTION_DECL) 1428 { 1429 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); 1430 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); 1431 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); 1432 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) 1433 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); 1434 } 1435 } 1436 /* If cannot merge, then use the new type and qualifiers, 1437 and don't preserve the old rtl. */ 1438 else if (! different_binding_level) 1439 { 1440 TREE_TYPE (olddecl) = TREE_TYPE (newdecl); 1441 TREE_READONLY (olddecl) = TREE_READONLY (newdecl); 1442 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); 1443 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); 1444 } 1445 1446 /* Merge the storage class information. */ 1447 merge_weak (newdecl, olddecl); 1448 1449 /* For functions, static overrides non-static. */ 1450 if (TREE_CODE (newdecl) == FUNCTION_DECL) 1451 { 1452 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); 1453 /* This is since we don't automatically 1454 copy the attributes of NEWDECL into OLDDECL. */ 1455 /* No need to worry about different_binding_level here because 1456 then TREE_PUBLIC (newdecl) was true. */ 1457 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); 1458 /* If this clears `static', clear it in the identifier too. */ 1459 if (! TREE_PUBLIC (olddecl)) 1460 TREE_PUBLIC (DECL_NAME (olddecl)) = 0; 1461 } 1462 if (DECL_EXTERNAL (newdecl)) 1463 { 1464 if (! different_binding_level) 1465 { 1466 /* Don't mess with these flags on local externs; they remain 1467 external even if there's a declaration at file scope which 1468 isn't. */ 1469 TREE_STATIC (newdecl) = TREE_STATIC (olddecl); 1470 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); 1471 } 1472 /* An extern decl does not override previous storage class. */ 1473 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); 1474 if (! DECL_EXTERNAL (newdecl)) 1475 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); 1476 } 1477 else 1478 { 1479 TREE_STATIC (olddecl) = TREE_STATIC (newdecl); 1480 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); 1481 } 1482 1483 if (TREE_CODE (newdecl) == FUNCTION_DECL) 1484 { 1485 /* If we're redefining a function previously defined as extern 1486 inline, make sure we emit debug info for the inline before we 1487 throw it away, in case it was inlined into a function that hasn't 1488 been written out yet. */ 1489 if (new_is_definition && DECL_INITIAL (olddecl)) 1490 { 1491 if (TREE_USED (olddecl)) 1492 (*debug_hooks->outlining_inline_function) (olddecl); 1493 1494 /* The new defn must not be inline. */ 1495 DECL_INLINE (newdecl) = 0; 1496 DECL_UNINLINABLE (newdecl) = 1; 1497 } 1498 else 1499 { 1500 /* If either decl says `inline', this fn is inline, 1501 unless its definition was passed already. */ 1502 if (DECL_DECLARED_INLINE_P (newdecl) 1503 || DECL_DECLARED_INLINE_P (olddecl)) 1504 DECL_DECLARED_INLINE_P (newdecl) = 1; 1505 1506 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) 1507 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); 1508 } 1509 1510 if (DECL_BUILT_IN (olddecl)) 1511 { 1512 /* Get rid of any built-in function if new arg types don't match it 1513 or if we have a function definition. */ 1514 if (! types_match || new_is_definition) 1515 { 1516 if (! different_binding_level) 1517 { 1518 TREE_TYPE (olddecl) = TREE_TYPE (newdecl); 1519 DECL_BUILT_IN_CLASS (olddecl) = NOT_BUILT_IN; 1520 } 1521 } 1522 else 1523 { 1524 /* If redeclaring a builtin function, and not a definition, 1525 it stays built in. */ 1526 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); 1527 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); 1528 } 1529 } 1530 1531 /* Also preserve various other info from the definition. */ 1532 if (! new_is_definition) 1533 { 1534 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); 1535 /* When called with different_binding_level set, don't copy over 1536 DECL_INITIAL, so that we don't accidentally change function 1537 declarations into function definitions. */ 1538 if (! different_binding_level) 1539 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 1540 DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl); 1541 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); 1542 DECL_NUM_STMTS (newdecl) = DECL_NUM_STMTS (olddecl); 1543 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); 1544 1545 /* Set DECL_INLINE on the declaration if we've got a body 1546 from which to instantiate. */ 1547 if (DECL_INLINE (olddecl) && ! DECL_UNINLINABLE (newdecl)) 1548 { 1549 DECL_INLINE (newdecl) = 1; 1550 DECL_ABSTRACT_ORIGIN (newdecl) 1551 = (different_binding_level 1552 ? DECL_ORIGIN (olddecl) 1553 : DECL_ABSTRACT_ORIGIN (olddecl)); 1554 } 1555 } 1556 else 1557 { 1558 /* If a previous declaration said inline, mark the 1559 definition as inlinable. */ 1560 if (DECL_DECLARED_INLINE_P (newdecl) 1561 && ! DECL_UNINLINABLE (newdecl)) 1562 DECL_INLINE (newdecl) = 1; 1563 } 1564 } 1565 if (different_binding_level) 1566 return 0; 1567 1568 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. 1569 But preserve OLDDECL's DECL_UID. */ 1570 { 1571 unsigned olddecl_uid = DECL_UID (olddecl); 1572 1573 memcpy ((char *) olddecl + sizeof (struct tree_common), 1574 (char *) newdecl + sizeof (struct tree_common), 1575 sizeof (struct tree_decl) - sizeof (struct tree_common)); 1576 DECL_UID (olddecl) = olddecl_uid; 1577 } 1578 1579 /* NEWDECL contains the merged attribute lists. 1580 Update OLDDECL to be the same. */ 1581 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl); 1582 1583 return 1; 1584} 1585 1586/* Check whether decl-node X shadows an existing declaration. 1587 OLDLOCAL is the old IDENTIFIER_LOCAL_VALUE of the DECL_NAME of X, 1588 which might be a NULL_TREE. */ 1589static void 1590warn_if_shadowing (x, oldlocal) 1591 tree x, oldlocal; 1592{ 1593 tree name; 1594 1595 if (DECL_EXTERNAL (x)) 1596 return; 1597 1598 name = DECL_NAME (x); 1599 1600 /* Warn if shadowing an argument at the top level of the body. */ 1601 if (oldlocal != 0 1602 /* This warning doesn't apply to the parms of a nested fcn. */ 1603 && ! current_binding_level->parm_flag 1604 /* Check that this is one level down from the parms. */ 1605 && current_binding_level->level_chain->parm_flag 1606 /* Check that the decl being shadowed 1607 comes from the parm level, one level up. */ 1608 && chain_member (oldlocal, current_binding_level->level_chain->names)) 1609 { 1610 if (TREE_CODE (oldlocal) == PARM_DECL) 1611 pedwarn ("declaration of `%s' shadows a parameter", 1612 IDENTIFIER_POINTER (name)); 1613 else 1614 pedwarn ("declaration of `%s' shadows a symbol from the parameter list", 1615 IDENTIFIER_POINTER (name)); 1616 } 1617 /* Maybe warn if shadowing something else. */ 1618 else if (warn_shadow 1619 /* No shadow warnings for internally generated vars. */ 1620 && DECL_SOURCE_LINE (x) != 0 1621 /* No shadow warnings for vars made for inlining. */ 1622 && ! DECL_FROM_INLINE (x)) 1623 { 1624 if (TREE_CODE (x) == PARM_DECL 1625 && current_binding_level->level_chain->parm_flag) 1626 /* Don't warn about the parm names in function declarator 1627 within a function declarator. 1628 It would be nice to avoid warning in any function 1629 declarator in a declaration, as opposed to a definition, 1630 but there is no way to tell it's not a definition. */ 1631 ; 1632 else if (oldlocal) 1633 { 1634 if (TREE_CODE (oldlocal) == PARM_DECL) 1635 shadow_warning ("a parameter", name, oldlocal); 1636 else 1637 shadow_warning ("a previous local", name, oldlocal); 1638 } 1639 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0 1640 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node) 1641 shadow_warning ("a global declaration", name, 1642 IDENTIFIER_GLOBAL_VALUE (name)); 1643 } 1644} 1645 1646/* Record a decl-node X as belonging to the current lexical scope. 1647 Check for errors (such as an incompatible declaration for the same 1648 name already seen in the same scope). 1649 1650 Returns either X or an old decl for the same name. 1651 If an old decl is returned, it may have been smashed 1652 to agree with what X says. */ 1653 1654tree 1655pushdecl (x) 1656 tree x; 1657{ 1658 tree t; 1659 tree name = DECL_NAME (x); 1660 struct binding_level *b = current_binding_level; 1661 1662 /* Functions need the lang_decl data. */ 1663 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x)) 1664 DECL_LANG_SPECIFIC (x) = (struct lang_decl *) 1665 ggc_alloc_cleared (sizeof (struct lang_decl)); 1666 1667 DECL_CONTEXT (x) = current_function_decl; 1668 /* A local extern declaration for a function doesn't constitute nesting. 1669 A local auto declaration does, since it's a forward decl 1670 for a nested function coming later. */ 1671 if ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) 1672 && DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x)) 1673 DECL_CONTEXT (x) = 0; 1674 1675 if (name) 1676 { 1677 int different_binding_level = 0; 1678 1679 if (warn_nested_externs 1680 && DECL_EXTERNAL (x) 1681 && b != global_binding_level 1682 && x != IDENTIFIER_IMPLICIT_DECL (name) 1683 /* No error messages for __FUNCTION__ and __PRETTY_FUNCTION__. */ 1684 && !DECL_IN_SYSTEM_HEADER (x)) 1685 warning ("nested extern declaration of `%s'", 1686 IDENTIFIER_POINTER (name)); 1687 1688 t = lookup_name_current_level (name); 1689 if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) 1690 { 1691 t = IDENTIFIER_GLOBAL_VALUE (name); 1692 /* Type decls at global scope don't conflict with externs declared 1693 inside lexical blocks. */ 1694 if (! t || TREE_CODE (t) == TYPE_DECL) 1695 /* If there's no visible global declaration, try for an 1696 invisible one. */ 1697 t = IDENTIFIER_LIMBO_VALUE (name); 1698 different_binding_level = 1; 1699 } 1700 if (t != 0 && t == error_mark_node) 1701 /* error_mark_node is 0 for a while during initialization! */ 1702 { 1703 t = 0; 1704 error_with_decl (x, "`%s' used prior to declaration"); 1705 } 1706 1707 /* If this decl is `static' and an implicit decl was seen previously, 1708 warn. */ 1709 if (TREE_PUBLIC (name) 1710 /* Don't test for DECL_EXTERNAL, because grokdeclarator 1711 sets this for all functions. */ 1712 && ! TREE_PUBLIC (x) 1713 && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level) 1714 /* We used to warn also for explicit extern followed by static, 1715 but sometimes you need to do it that way. */ 1716 && IDENTIFIER_IMPLICIT_DECL (name) != 0) 1717 { 1718 pedwarn ("`%s' was declared implicitly `extern' and later `static'", 1719 IDENTIFIER_POINTER (name)); 1720 pedwarn_with_file_and_line 1721 (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)), 1722 DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)), 1723 "previous declaration of `%s'", 1724 IDENTIFIER_POINTER (name)); 1725 TREE_THIS_VOLATILE (name) = 1; 1726 } 1727 1728 if (t != 0 && duplicate_decls (x, t, different_binding_level)) 1729 { 1730 if (TREE_CODE (t) == PARM_DECL) 1731 { 1732 /* Don't allow more than one "real" duplicate 1733 of a forward parm decl. */ 1734 TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x); 1735 return t; 1736 } 1737 return t; 1738 } 1739 1740 /* If we are processing a typedef statement, generate a whole new 1741 ..._TYPE node (which will be just a variant of the existing 1742 ..._TYPE node with identical properties) and then install the 1743 TYPE_DECL node generated to represent the typedef name as the 1744 TYPE_NAME of this brand new (duplicate) ..._TYPE node. 1745 1746 The whole point here is to end up with a situation where each 1747 and every ..._TYPE node the compiler creates will be uniquely 1748 associated with AT MOST one node representing a typedef name. 1749 This way, even though the compiler substitutes corresponding 1750 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very 1751 early on, later parts of the compiler can always do the reverse 1752 translation and get back the corresponding typedef name. For 1753 example, given: 1754 1755 typedef struct S MY_TYPE; 1756 MY_TYPE object; 1757 1758 Later parts of the compiler might only know that `object' was of 1759 type `struct S' if it were not for code just below. With this 1760 code however, later parts of the compiler see something like: 1761 1762 struct S' == struct S 1763 typedef struct S' MY_TYPE; 1764 struct S' object; 1765 1766 And they can then deduce (from the node for type struct S') that 1767 the original object declaration was: 1768 1769 MY_TYPE object; 1770 1771 Being able to do this is important for proper support of protoize, 1772 and also for generating precise symbolic debugging information 1773 which takes full account of the programmer's (typedef) vocabulary. 1774 1775 Obviously, we don't want to generate a duplicate ..._TYPE node if 1776 the TYPE_DECL node that we are now processing really represents a 1777 standard built-in type. 1778 1779 Since all standard types are effectively declared at line zero 1780 in the source file, we can easily check to see if we are working 1781 on a standard type by checking the current value of lineno. */ 1782 1783 if (TREE_CODE (x) == TYPE_DECL) 1784 { 1785 if (DECL_SOURCE_LINE (x) == 0) 1786 { 1787 if (TYPE_NAME (TREE_TYPE (x)) == 0) 1788 TYPE_NAME (TREE_TYPE (x)) = x; 1789 } 1790 else if (TREE_TYPE (x) != error_mark_node 1791 && DECL_ORIGINAL_TYPE (x) == NULL_TREE) 1792 { 1793 tree tt = TREE_TYPE (x); 1794 DECL_ORIGINAL_TYPE (x) = tt; 1795 tt = build_type_copy (tt); 1796 TYPE_NAME (tt) = x; 1797 TREE_USED (tt) = TREE_USED (x); 1798 TREE_TYPE (x) = tt; 1799 } 1800 } 1801 1802 /* Multiple external decls of the same identifier ought to match. 1803 We get warnings about inline functions where they are defined. 1804 Avoid duplicate warnings where they are used. */ 1805 if (TREE_PUBLIC (x) 1806 && ! (TREE_CODE (x) == FUNCTION_DECL && DECL_INLINE (x))) 1807 { 1808 tree decl; 1809 1810 if (IDENTIFIER_LIMBO_VALUE (name) != 0) 1811 /* Decls in limbo are always extern, so no need to check that. */ 1812 decl = IDENTIFIER_LIMBO_VALUE (name); 1813 else 1814 decl = 0; 1815 1816 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl)) 1817 /* If old decl is built-in, we already warned if we should. */ 1818 && !DECL_BUILT_IN (decl)) 1819 { 1820 pedwarn_with_decl (x, 1821 "type mismatch with previous external decl"); 1822 pedwarn_with_decl (decl, "previous external decl of `%s'"); 1823 } 1824 } 1825 1826 /* If a function has had an implicit declaration, and then is defined, 1827 make sure they are compatible. */ 1828 1829 if (IDENTIFIER_IMPLICIT_DECL (name) != 0 1830 && IDENTIFIER_GLOBAL_VALUE (name) == 0 1831 && TREE_CODE (x) == FUNCTION_DECL 1832 && ! comptypes (TREE_TYPE (x), 1833 TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name)))) 1834 { 1835 warning_with_decl (x, "type mismatch with previous implicit declaration"); 1836 warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name), 1837 "previous implicit declaration of `%s'"); 1838 } 1839 1840 /* This name is new in its binding level. 1841 Install the new declaration and return it. */ 1842 if (b == global_binding_level) 1843 { 1844 /* Install a global value. */ 1845 1846 /* If the first global decl has external linkage, 1847 warn if we later see static one. */ 1848 if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x)) 1849 TREE_PUBLIC (name) = 1; 1850 1851 IDENTIFIER_GLOBAL_VALUE (name) = x; 1852 1853 /* We no longer care about any previous block level declarations. */ 1854 IDENTIFIER_LIMBO_VALUE (name) = 0; 1855 1856 /* Don't forget if the function was used via an implicit decl. */ 1857 if (IDENTIFIER_IMPLICIT_DECL (name) 1858 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) 1859 TREE_USED (x) = 1, TREE_USED (name) = 1; 1860 1861 /* Don't forget if its address was taken in that way. */ 1862 if (IDENTIFIER_IMPLICIT_DECL (name) 1863 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) 1864 TREE_ADDRESSABLE (x) = 1; 1865 1866 /* Warn about mismatches against previous implicit decl. */ 1867 if (IDENTIFIER_IMPLICIT_DECL (name) != 0 1868 /* If this real decl matches the implicit, don't complain. */ 1869 && ! (TREE_CODE (x) == FUNCTION_DECL 1870 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x))) 1871 == integer_type_node))) 1872 pedwarn ("`%s' was previously implicitly declared to return `int'", 1873 IDENTIFIER_POINTER (name)); 1874 1875 /* If this decl is `static' and an `extern' was seen previously, 1876 that is erroneous. */ 1877 if (TREE_PUBLIC (name) 1878 && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)) 1879 { 1880 /* Okay to redeclare an ANSI built-in as static. */ 1881 if (t != 0 && DECL_BUILT_IN (t)) 1882 ; 1883 /* Okay to declare a non-ANSI built-in as anything. */ 1884 else if (t != 0 && DECL_BUILT_IN_NONANSI (t)) 1885 ; 1886 /* Okay to have global type decl after an earlier extern 1887 declaration inside a lexical block. */ 1888 else if (TREE_CODE (x) == TYPE_DECL) 1889 ; 1890 else if (IDENTIFIER_IMPLICIT_DECL (name)) 1891 { 1892 if (! TREE_THIS_VOLATILE (name)) 1893 pedwarn ("`%s' was declared implicitly `extern' and later `static'", 1894 IDENTIFIER_POINTER (name)); 1895 } 1896 else 1897 pedwarn ("`%s' was declared `extern' and later `static'", 1898 IDENTIFIER_POINTER (name)); 1899 } 1900 } 1901 else 1902 { 1903 /* Here to install a non-global value. */ 1904 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); 1905 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); 1906 1907 IDENTIFIER_LOCAL_VALUE (name) = x; 1908 1909 /* If this is an extern function declaration, see if we 1910 have a global definition or declaration for the function. */ 1911 if (oldlocal == 0 1912 && oldglobal != 0 1913 && TREE_CODE (x) == FUNCTION_DECL 1914 && TREE_CODE (oldglobal) == FUNCTION_DECL 1915 && DECL_EXTERNAL (x) 1916 && ! DECL_DECLARED_INLINE_P (x)) 1917 { 1918 /* We have one. Their types must agree. */ 1919 if (! comptypes (TREE_TYPE (x), 1920 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)))) 1921 pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one"); 1922 else 1923 { 1924 /* Inner extern decl is inline if global one is. 1925 Copy enough to really inline it. */ 1926 if (DECL_DECLARED_INLINE_P (oldglobal)) 1927 { 1928 DECL_DECLARED_INLINE_P (x) 1929 = DECL_DECLARED_INLINE_P (oldglobal); 1930 DECL_INLINE (x) = DECL_INLINE (oldglobal); 1931 DECL_INITIAL (x) = (current_function_decl == oldglobal 1932 ? 0 : DECL_INITIAL (oldglobal)); 1933 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal); 1934 DECL_NUM_STMTS (x) = DECL_NUM_STMTS (oldglobal); 1935 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal); 1936 DECL_RESULT (x) = DECL_RESULT (oldglobal); 1937 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal); 1938 DECL_ABSTRACT_ORIGIN (x) 1939 = DECL_ABSTRACT_ORIGIN (oldglobal); 1940 } 1941 /* Inner extern decl is built-in if global one is. */ 1942 if (DECL_BUILT_IN (oldglobal)) 1943 { 1944 DECL_BUILT_IN_CLASS (x) = DECL_BUILT_IN_CLASS (oldglobal); 1945 DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal); 1946 } 1947 /* Keep the arg types from a file-scope fcn defn. */ 1948 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0 1949 && DECL_INITIAL (oldglobal) 1950 && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0) 1951 TREE_TYPE (x) = TREE_TYPE (oldglobal); 1952 } 1953 } 1954 1955#if 0 1956 /* This case is probably sometimes the right thing to do. */ 1957 /* If we have a local external declaration, 1958 then any file-scope declaration should not 1959 have been static. */ 1960 if (oldlocal == 0 && oldglobal != 0 1961 && !TREE_PUBLIC (oldglobal) 1962 && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) 1963 warning ("`%s' locally external but globally static", 1964 IDENTIFIER_POINTER (name)); 1965#endif 1966 1967 /* If we have a local external declaration, 1968 and no file-scope declaration has yet been seen, 1969 then if we later have a file-scope decl it must not be static. */ 1970 if (oldlocal == 0 1971 && DECL_EXTERNAL (x) 1972 && TREE_PUBLIC (x)) 1973 { 1974 if (oldglobal == 0) 1975 TREE_PUBLIC (name) = 1; 1976 1977 /* Save this decl, so that we can do type checking against 1978 other decls after it falls out of scope. 1979 1980 Only save it once. This prevents temporary decls created in 1981 expand_inline_function from being used here, since this 1982 will have been set when the inline function was parsed. 1983 It also helps give slightly better warnings. */ 1984 if (IDENTIFIER_LIMBO_VALUE (name) == 0) 1985 IDENTIFIER_LIMBO_VALUE (name) = x; 1986 } 1987 1988 warn_if_shadowing (x, oldlocal); 1989 1990 /* If storing a local value, there may already be one (inherited). 1991 If so, record it for restoration when this binding level ends. */ 1992 if (oldlocal != 0) 1993 b->shadowed = tree_cons (name, oldlocal, b->shadowed); 1994 } 1995 1996 /* Keep list of variables in this level with incomplete type. 1997 If the input is erroneous, we can have error_mark in the type 1998 slot (e.g. "f(void a, ...)") - that doesn't count as an 1999 incomplete type. */ 2000 if (TREE_TYPE (x) != error_mark_node 2001 && !COMPLETE_TYPE_P (TREE_TYPE (x))) 2002 { 2003 tree element = TREE_TYPE (x); 2004 2005 while (TREE_CODE (element) == ARRAY_TYPE) 2006 element = TREE_TYPE (element); 2007 if (TREE_CODE (element) == RECORD_TYPE 2008 || TREE_CODE (element) == UNION_TYPE) 2009 b->incomplete_list = tree_cons (NULL_TREE, x, b->incomplete_list); 2010 } 2011 } 2012 2013 /* Put decls on list in reverse order. 2014 We will reverse them later if necessary. */ 2015 TREE_CHAIN (x) = b->names; 2016 b->names = x; 2017 2018 return x; 2019} 2020 2021/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ 2022 2023tree 2024pushdecl_top_level (x) 2025 tree x; 2026{ 2027 tree t; 2028 struct binding_level *b = current_binding_level; 2029 2030 current_binding_level = global_binding_level; 2031 t = pushdecl (x); 2032 current_binding_level = b; 2033 return t; 2034} 2035 2036/* Generate an implicit declaration for identifier FUNCTIONID 2037 as a function of type int (). Print a warning if appropriate. */ 2038 2039tree 2040implicitly_declare (functionid) 2041 tree functionid; 2042{ 2043 tree decl; 2044 int traditional_warning = 0; 2045 /* Only one "implicit declaration" warning per identifier. */ 2046 int implicit_warning; 2047 2048 /* We used to reuse an old implicit decl here, 2049 but this loses with inline functions because it can clobber 2050 the saved decl chains. */ 2051#if 0 2052 if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0) 2053 decl = IDENTIFIER_IMPLICIT_DECL (functionid); 2054 else 2055#endif 2056 decl = build_decl (FUNCTION_DECL, functionid, default_function_type); 2057 2058 /* Warn of implicit decl following explicit local extern decl. 2059 This is probably a program designed for traditional C. */ 2060 if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0) 2061 traditional_warning = 1; 2062 2063 /* Warn once of an implicit declaration. */ 2064 implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0); 2065 2066 DECL_EXTERNAL (decl) = 1; 2067 TREE_PUBLIC (decl) = 1; 2068 2069 /* Record that we have an implicit decl and this is it. */ 2070 IDENTIFIER_IMPLICIT_DECL (functionid) = decl; 2071 2072 /* ANSI standard says implicit declarations are in the innermost block. 2073 So we record the decl in the standard fashion. */ 2074 pushdecl (decl); 2075 2076 /* This is a no-op in c-lang.c or something real in objc-act.c. */ 2077 if (flag_objc) 2078 objc_check_decl (decl); 2079 2080 rest_of_decl_compilation (decl, NULL, 0, 0); 2081 2082 if (implicit_warning) 2083 implicit_decl_warning (functionid); 2084 else if (warn_traditional && traditional_warning) 2085 warning ("function `%s' was previously declared within a block", 2086 IDENTIFIER_POINTER (functionid)); 2087 2088 /* Write a record describing this implicit function declaration to the 2089 prototypes file (if requested). */ 2090 2091 gen_aux_info_record (decl, 0, 1, 0); 2092 2093 /* Possibly apply some default attributes to this implicit declaration. */ 2094 decl_attributes (&decl, NULL_TREE, 0); 2095 2096 return decl; 2097} 2098 2099void 2100implicit_decl_warning (id) 2101 tree id; 2102{ 2103 const char *name = IDENTIFIER_POINTER (id); 2104 if (mesg_implicit_function_declaration == 2) 2105 error ("implicit declaration of function `%s'", name); 2106 else if (mesg_implicit_function_declaration == 1) 2107 warning ("implicit declaration of function `%s'", name); 2108} 2109 2110/* Return zero if the declaration NEWDECL is valid 2111 when the declaration OLDDECL (assumed to be for the same name) 2112 has already been seen. 2113 Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration, 2114 and 3 if it is a conflicting declaration. */ 2115 2116static int 2117redeclaration_error_message (newdecl, olddecl) 2118 tree newdecl, olddecl; 2119{ 2120 if (TREE_CODE (newdecl) == TYPE_DECL) 2121 { 2122 /* Do not complain about type redeclarations where at least one 2123 declaration was in a system header. */ 2124 if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl)) 2125 return 0; 2126 return 1; 2127 } 2128 else if (TREE_CODE (newdecl) == FUNCTION_DECL) 2129 { 2130 /* Declarations of functions can insist on internal linkage 2131 but they can't be inconsistent with internal linkage, 2132 so there can be no error on that account. 2133 However defining the same name twice is no good. */ 2134 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0 2135 /* However, defining once as extern inline and a second 2136 time in another way is ok. */ 2137 && ! (DECL_DECLARED_INLINE_P (olddecl) && DECL_EXTERNAL (olddecl) 2138 && ! (DECL_DECLARED_INLINE_P (newdecl) 2139 && DECL_EXTERNAL (newdecl)))) 2140 return 1; 2141 return 0; 2142 } 2143 else if (DECL_CONTEXT (newdecl) == NULL_TREE) 2144 { 2145 /* Objects declared at top level: */ 2146 /* If at least one is a reference, it's ok. */ 2147 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) 2148 return 0; 2149 /* Reject two definitions. */ 2150 if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0) 2151 return 1; 2152 /* Now we have two tentative defs, or one tentative and one real def. */ 2153 /* Insist that the linkage match. */ 2154 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl)) 2155 return 3; 2156 return 0; 2157 } 2158 else if (current_binding_level->parm_flag 2159 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) 2160 return 0; 2161 else 2162 { 2163 /* Newdecl has block scope. If olddecl has block scope also, then 2164 reject two definitions, and reject a definition together with an 2165 external reference. Otherwise, it is OK, because newdecl must 2166 be an extern reference to olddecl. */ 2167 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)) 2168 && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)) 2169 return 2; 2170 return 0; 2171 } 2172} 2173 2174/* Get the LABEL_DECL corresponding to identifier ID as a label. 2175 Create one if none exists so far for the current function. 2176 This function is called for both label definitions and label references. */ 2177 2178tree 2179lookup_label (id) 2180 tree id; 2181{ 2182 tree decl = IDENTIFIER_LABEL_VALUE (id); 2183 2184 if (current_function_decl == 0) 2185 { 2186 error ("label %s referenced outside of any function", 2187 IDENTIFIER_POINTER (id)); 2188 return 0; 2189 } 2190 2191 /* Use a label already defined or ref'd with this name. */ 2192 if (decl != 0) 2193 { 2194 /* But not if it is inherited and wasn't declared to be inheritable. */ 2195 if (DECL_CONTEXT (decl) != current_function_decl 2196 && ! C_DECLARED_LABEL_FLAG (decl)) 2197 return shadow_label (id); 2198 return decl; 2199 } 2200 2201 decl = build_decl (LABEL_DECL, id, void_type_node); 2202 2203 /* A label not explicitly declared must be local to where it's ref'd. */ 2204 DECL_CONTEXT (decl) = current_function_decl; 2205 2206 DECL_MODE (decl) = VOIDmode; 2207 2208 /* Say where one reference is to the label, 2209 for the sake of the error if it is not defined. */ 2210 DECL_SOURCE_LINE (decl) = lineno; 2211 DECL_SOURCE_FILE (decl) = input_filename; 2212 2213 IDENTIFIER_LABEL_VALUE (id) = decl; 2214 2215 named_labels = tree_cons (NULL_TREE, decl, named_labels); 2216 2217 return decl; 2218} 2219 2220/* Make a label named NAME in the current function, 2221 shadowing silently any that may be inherited from containing functions 2222 or containing scopes. 2223 2224 Note that valid use, if the label being shadowed 2225 comes from another scope in the same function, 2226 requires calling declare_nonlocal_label right away. */ 2227 2228tree 2229shadow_label (name) 2230 tree name; 2231{ 2232 tree decl = IDENTIFIER_LABEL_VALUE (name); 2233 2234 if (decl != 0) 2235 { 2236 tree dup; 2237 2238 /* Check to make sure that the label hasn't already been declared 2239 at this label scope */ 2240 for (dup = named_labels; dup; dup = TREE_CHAIN (dup)) 2241 if (TREE_VALUE (dup) == decl) 2242 { 2243 error ("duplicate label declaration `%s'", 2244 IDENTIFIER_POINTER (name)); 2245 error_with_decl (TREE_VALUE (dup), 2246 "this is a previous declaration"); 2247 /* Just use the previous declaration. */ 2248 return lookup_label (name); 2249 } 2250 2251 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); 2252 IDENTIFIER_LABEL_VALUE (name) = decl = 0; 2253 } 2254 2255 return lookup_label (name); 2256} 2257 2258/* Define a label, specifying the location in the source file. 2259 Return the LABEL_DECL node for the label, if the definition is valid. 2260 Otherwise return 0. */ 2261 2262tree 2263define_label (filename, line, name) 2264 const char *filename; 2265 int line; 2266 tree name; 2267{ 2268 tree decl = lookup_label (name); 2269 2270 /* If label with this name is known from an outer context, shadow it. */ 2271 if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl) 2272 { 2273 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); 2274 IDENTIFIER_LABEL_VALUE (name) = 0; 2275 decl = lookup_label (name); 2276 } 2277 2278 if (warn_traditional && !in_system_header && lookup_name (name)) 2279 warning_with_file_and_line (filename, line, 2280 "traditional C lacks a separate namespace for labels, identifier `%s' conflicts", 2281 IDENTIFIER_POINTER (name)); 2282 2283 if (DECL_INITIAL (decl) != 0) 2284 { 2285 error_with_file_and_line (filename, line, "duplicate label `%s'", 2286 IDENTIFIER_POINTER (name)); 2287 return 0; 2288 } 2289 else 2290 { 2291 /* Mark label as having been defined. */ 2292 DECL_INITIAL (decl) = error_mark_node; 2293 /* Say where in the source. */ 2294 DECL_SOURCE_FILE (decl) = filename; 2295 DECL_SOURCE_LINE (decl) = line; 2296 return decl; 2297 } 2298} 2299 2300/* Return the list of declarations of the current level. 2301 Note that this list is in reverse order unless/until 2302 you nreverse it; and when you do nreverse it, you must 2303 store the result back using `storedecls' or you will lose. */ 2304 2305tree 2306getdecls () 2307{ 2308 return current_binding_level->names; 2309} 2310 2311/* Return the list of type-tags (for structs, etc) of the current level. */ 2312 2313tree 2314gettags () 2315{ 2316 return current_binding_level->tags; 2317} 2318 2319/* Store the list of declarations of the current level. 2320 This is done for the parameter declarations of a function being defined, 2321 after they are modified in the light of any missing parameters. */ 2322 2323static void 2324storedecls (decls) 2325 tree decls; 2326{ 2327 current_binding_level->names = decls; 2328} 2329 2330/* Similarly, store the list of tags of the current level. */ 2331 2332static void 2333storetags (tags) 2334 tree tags; 2335{ 2336 current_binding_level->tags = tags; 2337} 2338 2339/* Given NAME, an IDENTIFIER_NODE, 2340 return the structure (or union or enum) definition for that name. 2341 Searches binding levels from BINDING_LEVEL up to the global level. 2342 If THISLEVEL_ONLY is nonzero, searches only the specified context 2343 (but skips any tag-transparent contexts to find one that is 2344 meaningful for tags). 2345 CODE says which kind of type the caller wants; 2346 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. 2347 If the wrong kind of type is found, an error is reported. */ 2348 2349static tree 2350lookup_tag (code, name, binding_level, thislevel_only) 2351 enum tree_code code; 2352 struct binding_level *binding_level; 2353 tree name; 2354 int thislevel_only; 2355{ 2356 struct binding_level *level; 2357 int thislevel = 1; 2358 2359 for (level = binding_level; level; level = level->level_chain) 2360 { 2361 tree tail; 2362 for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 2363 { 2364 if (TREE_PURPOSE (tail) == name) 2365 { 2366 if (TREE_CODE (TREE_VALUE (tail)) != code) 2367 { 2368 /* Definition isn't the kind we were looking for. */ 2369 pending_invalid_xref = name; 2370 pending_invalid_xref_file = input_filename; 2371 pending_invalid_xref_line = lineno; 2372 /* If in the same binding level as a declaration as a tag 2373 of a different type, this must not be allowed to 2374 shadow that tag, so give the error immediately. 2375 (For example, "struct foo; union foo;" is invalid.) */ 2376 if (thislevel) 2377 pending_xref_error (); 2378 } 2379 return TREE_VALUE (tail); 2380 } 2381 } 2382 if (! level->tag_transparent) 2383 { 2384 if (thislevel_only) 2385 return NULL_TREE; 2386 thislevel = 0; 2387 } 2388 } 2389 return NULL_TREE; 2390} 2391 2392/* Print an error message now 2393 for a recent invalid struct, union or enum cross reference. 2394 We don't print them immediately because they are not invalid 2395 when used in the `struct foo;' construct for shadowing. */ 2396 2397void 2398pending_xref_error () 2399{ 2400 if (pending_invalid_xref != 0) 2401 error_with_file_and_line (pending_invalid_xref_file, 2402 pending_invalid_xref_line, 2403 "`%s' defined as wrong kind of tag", 2404 IDENTIFIER_POINTER (pending_invalid_xref)); 2405 pending_invalid_xref = 0; 2406} 2407 2408/* Given a type, find the tag that was defined for it and return the tag name. 2409 Otherwise return 0. */ 2410 2411static tree 2412lookup_tag_reverse (type) 2413 tree type; 2414{ 2415 struct binding_level *level; 2416 2417 for (level = current_binding_level; level; level = level->level_chain) 2418 { 2419 tree tail; 2420 for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 2421 { 2422 if (TREE_VALUE (tail) == type) 2423 return TREE_PURPOSE (tail); 2424 } 2425 } 2426 return NULL_TREE; 2427} 2428 2429/* Look up NAME in the current binding level and its superiors 2430 in the namespace of variables, functions and typedefs. 2431 Return a ..._DECL node of some kind representing its definition, 2432 or return 0 if it is undefined. */ 2433 2434tree 2435lookup_name (name) 2436 tree name; 2437{ 2438 tree val; 2439 2440 if (current_binding_level != global_binding_level 2441 && IDENTIFIER_LOCAL_VALUE (name)) 2442 val = IDENTIFIER_LOCAL_VALUE (name); 2443 else 2444 val = IDENTIFIER_GLOBAL_VALUE (name); 2445 return val; 2446} 2447 2448/* Similar to `lookup_name' but look only at current binding level. */ 2449 2450tree 2451lookup_name_current_level (name) 2452 tree name; 2453{ 2454 tree t; 2455 2456 if (current_binding_level == global_binding_level) 2457 return IDENTIFIER_GLOBAL_VALUE (name); 2458 2459 if (IDENTIFIER_LOCAL_VALUE (name) == 0) 2460 return 0; 2461 2462 for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) 2463 if (DECL_NAME (t) == name) 2464 break; 2465 2466 return t; 2467} 2468 2469/* Create the predefined scalar types of C, 2470 and some nodes representing standard constants (0, 1, (void *) 0). 2471 Initialize the global binding level. 2472 Make definitions for built-in primitive functions. */ 2473 2474void 2475c_init_decl_processing () 2476{ 2477 tree endlink; 2478 tree ptr_ftype_void, ptr_ftype_ptr; 2479 2480 /* Adds some ggc roots, and reserved words for c-parse.in. */ 2481 c_parse_init (); 2482 2483 current_function_decl = NULL; 2484 named_labels = NULL; 2485 current_binding_level = NULL_BINDING_LEVEL; 2486 free_binding_level = NULL_BINDING_LEVEL; 2487 2488 /* Make the binding_level structure for global names. */ 2489 pushlevel (0); 2490 global_binding_level = current_binding_level; 2491 2492 build_common_tree_nodes (flag_signed_char); 2493 2494 c_common_nodes_and_builtins (); 2495 2496 boolean_type_node = integer_type_node; 2497 boolean_true_node = integer_one_node; 2498 boolean_false_node = integer_zero_node; 2499 2500 c_bool_type_node = make_unsigned_type (BOOL_TYPE_SIZE); 2501 TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE); 2502 TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0); 2503 TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node; 2504 TYPE_PRECISION (c_bool_type_node) = 1; 2505 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"), 2506 c_bool_type_node)); 2507 c_bool_false_node = build_int_2 (0, 0); 2508 TREE_TYPE (c_bool_false_node) = c_bool_type_node; 2509 c_bool_true_node = build_int_2 (1, 0); 2510 TREE_TYPE (c_bool_true_node) = c_bool_type_node; 2511 2512 endlink = void_list_node; 2513 ptr_ftype_void = build_function_type (ptr_type_node, endlink); 2514 ptr_ftype_ptr 2515 = build_function_type (ptr_type_node, 2516 tree_cons (NULL_TREE, ptr_type_node, endlink)); 2517 2518 pedantic_lvalues = pedantic; 2519 2520 make_fname_decl = c_make_fname_decl; 2521 start_fname_decls (); 2522} 2523 2524/* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the 2525 decl, NAME is the initialization string and TYPE_DEP indicates whether 2526 NAME depended on the type of the function. As we don't yet implement 2527 delayed emission of static data, we mark the decl as emitted 2528 so it is not placed in the output. Anything using it must therefore pull 2529 out the STRING_CST initializer directly. This does mean that these names 2530 are string merging candidates, which is wrong for C99's __func__. FIXME. */ 2531 2532static tree 2533c_make_fname_decl (id, type_dep) 2534 tree id; 2535 int type_dep; 2536{ 2537 const char *name = fname_as_string (type_dep); 2538 tree decl, type, init; 2539 size_t length = strlen (name); 2540 2541 type = build_array_type 2542 (build_qualified_type (char_type_node, TYPE_QUAL_CONST), 2543 build_index_type (size_int (length))); 2544 2545 decl = build_decl (VAR_DECL, id, type); 2546 /* We don't push the decl, so have to set its context here. */ 2547 DECL_CONTEXT (decl) = current_function_decl; 2548 2549 TREE_STATIC (decl) = 1; 2550 TREE_READONLY (decl) = 1; 2551 DECL_ARTIFICIAL (decl) = 1; 2552 2553 init = build_string (length + 1, name); 2554 TREE_TYPE (init) = type; 2555 DECL_INITIAL (decl) = init; 2556 2557 TREE_USED (decl) = 1; 2558 2559 finish_decl (decl, init, NULL_TREE); 2560 2561 return decl; 2562} 2563 2564/* Return a definition for a builtin function named NAME and whose data type 2565 is TYPE. TYPE should be a function type with argument types. 2566 FUNCTION_CODE tells later passes how to compile calls to this function. 2567 See tree.h for its possible values. 2568 2569 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, 2570 the name to be called if we can't opencode the function. If 2571 ATTRS is nonzero, use that for the function's attribute list. */ 2572 2573tree 2574builtin_function (name, type, function_code, class, library_name, attrs) 2575 const char *name; 2576 tree type; 2577 int function_code; 2578 enum built_in_class class; 2579 const char *library_name; 2580 tree attrs; 2581{ 2582 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type); 2583 DECL_EXTERNAL (decl) = 1; 2584 TREE_PUBLIC (decl) = 1; 2585 if (library_name) 2586 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name)); 2587 make_decl_rtl (decl, NULL); 2588 pushdecl (decl); 2589 DECL_BUILT_IN_CLASS (decl) = class; 2590 DECL_FUNCTION_CODE (decl) = function_code; 2591 2592 /* Warn if a function in the namespace for users 2593 is used without an occasion to consider it declared. */ 2594 if (name[0] != '_' || name[1] != '_') 2595 C_DECL_ANTICIPATED (decl) = 1; 2596 2597 /* Possibly apply some default attributes to this built-in function. */ 2598 if (attrs) 2599 decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN); 2600 else 2601 decl_attributes (&decl, NULL_TREE, 0); 2602 2603 return decl; 2604} 2605 2606/* Apply default attributes to a function, if a system function with default 2607 attributes. */ 2608 2609void 2610c_insert_default_attributes (decl) 2611 tree decl; 2612{ 2613 if (!TREE_PUBLIC (decl)) 2614 return; 2615 c_common_insert_default_attributes (decl); 2616} 2617 2618/* Called when a declaration is seen that contains no names to declare. 2619 If its type is a reference to a structure, union or enum inherited 2620 from a containing scope, shadow that tag name for the current scope 2621 with a forward reference. 2622 If its type defines a new named structure or union 2623 or defines an enum, it is valid but we need not do anything here. 2624 Otherwise, it is an error. */ 2625 2626void 2627shadow_tag (declspecs) 2628 tree declspecs; 2629{ 2630 shadow_tag_warned (declspecs, 0); 2631} 2632 2633void 2634shadow_tag_warned (declspecs, warned) 2635 tree declspecs; 2636 int warned; 2637 /* 1 => we have done a pedwarn. 2 => we have done a warning, but 2638 no pedwarn. */ 2639{ 2640 int found_tag = 0; 2641 tree link; 2642 tree specs, attrs; 2643 2644 pending_invalid_xref = 0; 2645 2646 /* Remove the attributes from declspecs, since they will confuse the 2647 following code. */ 2648 split_specs_attrs (declspecs, &specs, &attrs); 2649 2650 for (link = specs; link; link = TREE_CHAIN (link)) 2651 { 2652 tree value = TREE_VALUE (link); 2653 enum tree_code code = TREE_CODE (value); 2654 2655 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) 2656 /* Used to test also that TYPE_SIZE (value) != 0. 2657 That caused warning for `struct foo;' at top level in the file. */ 2658 { 2659 tree name = lookup_tag_reverse (value); 2660 tree t; 2661 2662 found_tag++; 2663 2664 if (name == 0) 2665 { 2666 if (warned != 1 && code != ENUMERAL_TYPE) 2667 /* Empty unnamed enum OK */ 2668 { 2669 pedwarn ("unnamed struct/union that defines no instances"); 2670 warned = 1; 2671 } 2672 } 2673 else 2674 { 2675 t = lookup_tag (code, name, current_binding_level, 1); 2676 2677 if (t == 0) 2678 { 2679 t = make_node (code); 2680 pushtag (name, t); 2681 } 2682 } 2683 } 2684 else 2685 { 2686 if (!warned && ! in_system_header) 2687 { 2688 warning ("useless keyword or type name in empty declaration"); 2689 warned = 2; 2690 } 2691 } 2692 } 2693 2694 if (found_tag > 1) 2695 error ("two types specified in one empty declaration"); 2696 2697 if (warned != 1) 2698 { 2699 if (found_tag == 0) 2700 pedwarn ("empty declaration"); 2701 } 2702} 2703 2704/* Construct an array declarator. EXPR is the expression inside [], or 2705 NULL_TREE. QUALS are the type qualifiers inside the [] (to be applied 2706 to the pointer to which a parameter array is converted). STATIC_P is 2707 nonzero if "static" is inside the [], zero otherwise. VLA_UNSPEC_P 2708 is nonzero is the array is [*], a VLA of unspecified length which is 2709 nevertheless a complete type (not currently implemented by GCC), 2710 zero otherwise. The declarator is constructed as an ARRAY_REF 2711 (to be decoded by grokdeclarator), whose operand 0 is what's on the 2712 left of the [] (filled by in set_array_declarator_type) and operand 1 2713 is the expression inside; whose TREE_TYPE is the type qualifiers and 2714 which has TREE_STATIC set if "static" is used. */ 2715 2716tree 2717build_array_declarator (expr, quals, static_p, vla_unspec_p) 2718 tree expr; 2719 tree quals; 2720 int static_p; 2721 int vla_unspec_p; 2722{ 2723 tree decl; 2724 decl = build_nt (ARRAY_REF, NULL_TREE, expr); 2725 TREE_TYPE (decl) = quals; 2726 TREE_STATIC (decl) = (static_p ? 1 : 0); 2727 if (pedantic && !flag_isoc99) 2728 { 2729 if (static_p || quals != NULL_TREE) 2730 pedwarn ("ISO C90 does not support `static' or type qualifiers in parameter array declarators"); 2731 if (vla_unspec_p) 2732 pedwarn ("ISO C90 does not support `[*]' array declarators"); 2733 } 2734 if (vla_unspec_p) 2735 warning ("GCC does not yet properly implement `[*]' array declarators"); 2736 return decl; 2737} 2738 2739/* Set the type of an array declarator. DECL is the declarator, as 2740 constructed by build_array_declarator; TYPE is what appears on the left 2741 of the [] and goes in operand 0. ABSTRACT_P is nonzero if it is an 2742 abstract declarator, zero otherwise; this is used to reject static and 2743 type qualifiers in abstract declarators, where they are not in the 2744 C99 grammar. */ 2745 2746tree 2747set_array_declarator_type (decl, type, abstract_p) 2748 tree decl; 2749 tree type; 2750 int abstract_p; 2751{ 2752 TREE_OPERAND (decl, 0) = type; 2753 if (abstract_p && (TREE_TYPE (decl) != NULL_TREE || TREE_STATIC (decl))) 2754 error ("static or type qualifiers in abstract declarator"); 2755 return decl; 2756} 2757 2758/* Decode a "typename", such as "int **", returning a ..._TYPE node. */ 2759 2760tree 2761groktypename (typename) 2762 tree typename; 2763{ 2764 tree specs, attrs; 2765 2766 if (TREE_CODE (typename) != TREE_LIST) 2767 return typename; 2768 2769 split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs); 2770 2771 typename = grokdeclarator (TREE_VALUE (typename), specs, TYPENAME, 0); 2772 2773 /* Apply attributes. */ 2774 decl_attributes (&typename, attrs, 0); 2775 2776 return typename; 2777} 2778 2779/* Return a PARM_DECL node for a given pair of specs and declarator. */ 2780 2781tree 2782groktypename_in_parm_context (typename) 2783 tree typename; 2784{ 2785 if (TREE_CODE (typename) != TREE_LIST) 2786 return typename; 2787 return grokdeclarator (TREE_VALUE (typename), 2788 TREE_PURPOSE (typename), 2789 PARM, 0); 2790} 2791 2792/* Decode a declarator in an ordinary declaration or data definition. 2793 This is called as soon as the type information and variable name 2794 have been parsed, before parsing the initializer if any. 2795 Here we create the ..._DECL node, fill in its type, 2796 and put it on the list of decls for the current context. 2797 The ..._DECL node is returned as the value. 2798 2799 Exception: for arrays where the length is not specified, 2800 the type is left null, to be filled in by `finish_decl'. 2801 2802 Function definitions do not come here; they go to start_function 2803 instead. However, external and forward declarations of functions 2804 do go through here. Structure field declarations are done by 2805 grokfield and not through here. */ 2806 2807tree 2808start_decl (declarator, declspecs, initialized, attributes) 2809 tree declarator, declspecs; 2810 int initialized; 2811 tree attributes; 2812{ 2813 tree decl; 2814 tree tem; 2815 2816 /* An object declared as __attribute__((deprecated)) suppresses 2817 warnings of uses of other deprecated items. */ 2818 if (lookup_attribute ("deprecated", attributes)) 2819 deprecated_state = DEPRECATED_SUPPRESS; 2820 2821 decl = grokdeclarator (declarator, declspecs, 2822 NORMAL, initialized); 2823 2824 deprecated_state = DEPRECATED_NORMAL; 2825 2826 if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL 2827 && MAIN_NAME_P (DECL_NAME (decl))) 2828 warning_with_decl (decl, "`%s' is usually a function"); 2829 2830 if (initialized) 2831 /* Is it valid for this decl to have an initializer at all? 2832 If not, set INITIALIZED to zero, which will indirectly 2833 tell `finish_decl' to ignore the initializer once it is parsed. */ 2834 switch (TREE_CODE (decl)) 2835 { 2836 case TYPE_DECL: 2837 error ("typedef `%s' is initialized (use __typeof__ instead)", 2838 IDENTIFIER_POINTER (DECL_NAME (decl))); 2839 initialized = 0; 2840 break; 2841 2842 case FUNCTION_DECL: 2843 error ("function `%s' is initialized like a variable", 2844 IDENTIFIER_POINTER (DECL_NAME (decl))); 2845 initialized = 0; 2846 break; 2847 2848 case PARM_DECL: 2849 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ 2850 error ("parameter `%s' is initialized", 2851 IDENTIFIER_POINTER (DECL_NAME (decl))); 2852 initialized = 0; 2853 break; 2854 2855 default: 2856 /* Don't allow initializations for incomplete types 2857 except for arrays which might be completed by the initialization. */ 2858 2859 /* This can happen if the array size is an undefined macro. We already 2860 gave a warning, so we don't need another one. */ 2861 if (TREE_TYPE (decl) == error_mark_node) 2862 initialized = 0; 2863 else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) 2864 { 2865 /* A complete type is ok if size is fixed. */ 2866 2867 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST 2868 || C_DECL_VARIABLE_SIZE (decl)) 2869 { 2870 error ("variable-sized object may not be initialized"); 2871 initialized = 0; 2872 } 2873 } 2874 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) 2875 { 2876 error ("variable `%s' has initializer but incomplete type", 2877 IDENTIFIER_POINTER (DECL_NAME (decl))); 2878 initialized = 0; 2879 } 2880 else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) 2881 { 2882 error ("elements of array `%s' have incomplete type", 2883 IDENTIFIER_POINTER (DECL_NAME (decl))); 2884 initialized = 0; 2885 } 2886 } 2887 2888 if (initialized) 2889 { 2890#if 0 2891 /* Seems redundant with grokdeclarator. */ 2892 if (current_binding_level != global_binding_level 2893 && DECL_EXTERNAL (decl) 2894 && TREE_CODE (decl) != FUNCTION_DECL) 2895 warning ("declaration of `%s' has `extern' and is initialized", 2896 IDENTIFIER_POINTER (DECL_NAME (decl))); 2897#endif 2898 DECL_EXTERNAL (decl) = 0; 2899 if (current_binding_level == global_binding_level) 2900 TREE_STATIC (decl) = 1; 2901 2902 /* Tell `pushdecl' this is an initialized decl 2903 even though we don't yet have the initializer expression. 2904 Also tell `finish_decl' it may store the real initializer. */ 2905 DECL_INITIAL (decl) = error_mark_node; 2906 } 2907 2908 /* If this is a function declaration, write a record describing it to the 2909 prototypes file (if requested). */ 2910 2911 if (TREE_CODE (decl) == FUNCTION_DECL) 2912 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0); 2913 2914 /* ANSI specifies that a tentative definition which is not merged with 2915 a non-tentative definition behaves exactly like a definition with an 2916 initializer equal to zero. (Section 3.7.2) 2917 2918 -fno-common gives strict ANSI behavior, though this tends to break 2919 a large body of code that grew up without this rule. 2920 2921 Thread-local variables are never common, since there's no entrenched 2922 body of code to break, and it allows more efficient variable references 2923 in the presense of dynamic linking. */ 2924 2925 if (TREE_CODE (decl) == VAR_DECL 2926 && !initialized 2927 && TREE_PUBLIC (decl) 2928 && !DECL_THREAD_LOCAL (decl) 2929 && !flag_no_common) 2930 DECL_COMMON (decl) = 1; 2931 2932 /* Set attributes here so if duplicate decl, will have proper attributes. */ 2933 decl_attributes (&decl, attributes, 0); 2934 2935 /* If #pragma weak was used, mark the decl weak now. */ 2936 if (current_binding_level == global_binding_level) 2937 maybe_apply_pragma_weak (decl); 2938 2939 if (TREE_CODE (decl) == FUNCTION_DECL 2940 && DECL_DECLARED_INLINE_P (decl) 2941 && DECL_UNINLINABLE (decl) 2942 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl))) 2943 warning_with_decl (decl, 2944 "inline function `%s' given attribute noinline"); 2945 2946 /* Add this decl to the current binding level. 2947 TEM may equal DECL or it may be a previous decl of the same name. */ 2948 tem = pushdecl (decl); 2949 2950 /* For a local variable, define the RTL now. */ 2951 if (current_binding_level != global_binding_level 2952 /* But not if this is a duplicate decl 2953 and we preserved the rtl from the previous one 2954 (which may or may not happen). */ 2955 && !DECL_RTL_SET_P (tem) 2956 && !DECL_CONTEXT (tem)) 2957 { 2958 if (TREE_TYPE (tem) != error_mark_node 2959 && COMPLETE_TYPE_P (TREE_TYPE (tem))) 2960 expand_decl (tem); 2961 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE 2962 && DECL_INITIAL (tem) != 0) 2963 expand_decl (tem); 2964 } 2965 2966 return tem; 2967} 2968 2969/* Finish processing of a declaration; 2970 install its initial value. 2971 If the length of an array type is not known before, 2972 it must be determined now, from the initial value, or it is an error. */ 2973 2974void 2975finish_decl (decl, init, asmspec_tree) 2976 tree decl, init; 2977 tree asmspec_tree; 2978{ 2979 tree type = TREE_TYPE (decl); 2980 int was_incomplete = (DECL_SIZE (decl) == 0); 2981 const char *asmspec = 0; 2982 2983 /* If a name was specified, get the string. */ 2984 if (current_binding_level == global_binding_level) 2985 asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree); 2986 if (asmspec_tree) 2987 asmspec = TREE_STRING_POINTER (asmspec_tree); 2988 2989 /* If `start_decl' didn't like having an initialization, ignore it now. */ 2990 if (init != 0 && DECL_INITIAL (decl) == 0) 2991 init = 0; 2992 2993 /* Don't crash if parm is initialized. */ 2994 if (TREE_CODE (decl) == PARM_DECL) 2995 init = 0; 2996 2997 if (init) 2998 store_init_value (decl, init); 2999 3000 /* Deduce size of array from initialization, if not already known */ 3001 if (TREE_CODE (type) == ARRAY_TYPE 3002 && TYPE_DOMAIN (type) == 0 3003 && TREE_CODE (decl) != TYPE_DECL) 3004 { 3005 int do_default 3006 = (TREE_STATIC (decl) 3007 /* Even if pedantic, an external linkage array 3008 may have incomplete type at first. */ 3009 ? pedantic && !TREE_PUBLIC (decl) 3010 : !DECL_EXTERNAL (decl)); 3011 int failure 3012 = complete_array_type (type, DECL_INITIAL (decl), do_default); 3013 3014 /* Get the completed type made by complete_array_type. */ 3015 type = TREE_TYPE (decl); 3016 3017 if (failure == 1) 3018 error_with_decl (decl, "initializer fails to determine size of `%s'"); 3019 3020 else if (failure == 2) 3021 { 3022 if (do_default) 3023 error_with_decl (decl, "array size missing in `%s'"); 3024 /* If a `static' var's size isn't known, 3025 make it extern as well as static, so it does not get 3026 allocated. 3027 If it is not `static', then do not mark extern; 3028 finish_incomplete_decl will give it a default size 3029 and it will get allocated. */ 3030 else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl)) 3031 DECL_EXTERNAL (decl) = 1; 3032 } 3033 3034 /* TYPE_MAX_VALUE is always one less than the number of elements 3035 in the array, because we start counting at zero. Therefore, 3036 warn only if the value is less than zero. */ 3037 else if (pedantic && TYPE_DOMAIN (type) != 0 3038 && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0) 3039 error_with_decl (decl, "zero or negative size array `%s'"); 3040 3041 layout_decl (decl, 0); 3042 } 3043 3044 if (TREE_CODE (decl) == VAR_DECL) 3045 { 3046 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node 3047 && COMPLETE_TYPE_P (TREE_TYPE (decl))) 3048 layout_decl (decl, 0); 3049 3050 if (DECL_SIZE (decl) == 0 3051 /* Don't give an error if we already gave one earlier. */ 3052 && TREE_TYPE (decl) != error_mark_node 3053 && (TREE_STATIC (decl) 3054 ? 3055 /* A static variable with an incomplete type 3056 is an error if it is initialized. 3057 Also if it is not file scope. 3058 Otherwise, let it through, but if it is not `extern' 3059 then it may cause an error message later. */ 3060 (DECL_INITIAL (decl) != 0 3061 || DECL_CONTEXT (decl) != 0) 3062 : 3063 /* An automatic variable with an incomplete type 3064 is an error. */ 3065 !DECL_EXTERNAL (decl))) 3066 { 3067 error_with_decl (decl, "storage size of `%s' isn't known"); 3068 TREE_TYPE (decl) = error_mark_node; 3069 } 3070 3071 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) 3072 && DECL_SIZE (decl) != 0) 3073 { 3074 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) 3075 constant_expression_warning (DECL_SIZE (decl)); 3076 else 3077 error_with_decl (decl, "storage size of `%s' isn't constant"); 3078 } 3079 3080 if (TREE_USED (type)) 3081 TREE_USED (decl) = 1; 3082 } 3083 3084 /* If this is a function and an assembler name is specified, it isn't 3085 builtin any more. Also reset DECL_RTL so we can give it its new 3086 name. */ 3087 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) 3088 { 3089 DECL_BUILT_IN_CLASS (decl) = NOT_BUILT_IN; 3090 SET_DECL_RTL (decl, NULL_RTX); 3091 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec)); 3092 } 3093 3094 /* Output the assembler code and/or RTL code for variables and functions, 3095 unless the type is an undefined structure or union. 3096 If not, it will get done when the type is completed. */ 3097 3098 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) 3099 { 3100 /* This is a no-op in c-lang.c or something real in objc-act.c. */ 3101 if (flag_objc) 3102 objc_check_decl (decl); 3103 3104 if (!DECL_CONTEXT (decl)) 3105 { 3106 if (DECL_INITIAL (decl) == NULL_TREE 3107 || DECL_INITIAL (decl) == error_mark_node) 3108 /* Don't output anything 3109 when a tentative file-scope definition is seen. 3110 But at end of compilation, do output code for them. */ 3111 DECL_DEFER_OUTPUT (decl) = 1; 3112 rest_of_decl_compilation (decl, asmspec, 3113 (DECL_CONTEXT (decl) == 0 3114 || TREE_ASM_WRITTEN (decl)), 0); 3115 } 3116 else 3117 { 3118 /* This is a local variable. If there is an ASMSPEC, the 3119 user has requested that we handle it specially. */ 3120 if (asmspec) 3121 { 3122 /* In conjunction with an ASMSPEC, the `register' 3123 keyword indicates that we should place the variable 3124 in a particular register. */ 3125 if (DECL_REGISTER (decl)) 3126 DECL_C_HARD_REGISTER (decl) = 1; 3127 3128 /* If this is not a static variable, issue a warning. 3129 It doesn't make any sense to give an ASMSPEC for an 3130 ordinary, non-register local variable. Historically, 3131 GCC has accepted -- but ignored -- the ASMSPEC in 3132 this case. */ 3133 if (TREE_CODE (decl) == VAR_DECL 3134 && !DECL_REGISTER (decl) 3135 && !TREE_STATIC (decl)) 3136 warning_with_decl (decl, 3137 "ignoring asm-specifier for non-static local variable `%s'"); 3138 else 3139 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec)); 3140 } 3141 3142 if (TREE_CODE (decl) != FUNCTION_DECL) 3143 add_decl_stmt (decl); 3144 } 3145 3146 if (DECL_CONTEXT (decl) != 0) 3147 { 3148 /* Recompute the RTL of a local array now 3149 if it used to be an incomplete type. */ 3150 if (was_incomplete 3151 && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl)) 3152 { 3153 /* If we used it already as memory, it must stay in memory. */ 3154 TREE_ADDRESSABLE (decl) = TREE_USED (decl); 3155 /* If it's still incomplete now, no init will save it. */ 3156 if (DECL_SIZE (decl) == 0) 3157 DECL_INITIAL (decl) = 0; 3158 } 3159 } 3160 } 3161 3162 if (TREE_CODE (decl) == TYPE_DECL) 3163 { 3164 /* This is a no-op in c-lang.c or something real in objc-act.c. */ 3165 if (flag_objc) 3166 objc_check_decl (decl); 3167 rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0, 0); 3168 } 3169 3170 /* At the end of a declaration, throw away any variable type sizes 3171 of types defined inside that declaration. There is no use 3172 computing them in the following function definition. */ 3173 if (current_binding_level == global_binding_level) 3174 get_pending_sizes (); 3175 3176 /* Install a cleanup (aka destructor) if one was given. */ 3177 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl)) 3178 { 3179 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl)); 3180 if (attr) 3181 { 3182 static bool eh_initialized_p; 3183 3184 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); 3185 tree cleanup_decl = lookup_name (cleanup_id); 3186 tree cleanup; 3187 3188 /* Build "cleanup(&decl)" for the destructor. */ 3189 cleanup = build_unary_op (ADDR_EXPR, decl, 0); 3190 cleanup = build_tree_list (NULL_TREE, cleanup); 3191 cleanup = build_function_call (cleanup_decl, cleanup); 3192 3193 /* Don't warn about decl unused; the cleanup uses it. */ 3194 TREE_USED (decl) = 1; 3195 3196 /* Initialize EH, if we've been told to do so. */ 3197 if (flag_exceptions && !eh_initialized_p) 3198 { 3199 eh_initialized_p = true; 3200 eh_personality_libfunc 3201 = init_one_libfunc (USING_SJLJ_EXCEPTIONS 3202 ? "__gcc_personality_sj0" 3203 : "__gcc_personality_v0"); 3204 using_eh_for_cleanups (); 3205 } 3206 3207 add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup)); 3208 } 3209 } 3210} 3211 3212/* Given a parsed parameter declaration, 3213 decode it into a PARM_DECL and push that on the current binding level. 3214 Also, for the sake of forward parm decls, 3215 record the given order of parms in `parm_order'. */ 3216 3217void 3218push_parm_decl (parm) 3219 tree parm; 3220{ 3221 tree decl; 3222 int old_immediate_size_expand = immediate_size_expand; 3223 /* Don't try computing parm sizes now -- wait till fn is called. */ 3224 immediate_size_expand = 0; 3225 3226 decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)), 3227 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0); 3228 decl_attributes (&decl, TREE_VALUE (parm), 0); 3229 3230#if 0 3231 if (DECL_NAME (decl)) 3232 { 3233 tree olddecl; 3234 olddecl = lookup_name (DECL_NAME (decl)); 3235 if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL) 3236 pedwarn_with_decl (decl, 3237 "ISO C forbids parameter `%s' shadowing typedef"); 3238 } 3239#endif 3240 3241 decl = pushdecl (decl); 3242 3243 immediate_size_expand = old_immediate_size_expand; 3244 3245 current_binding_level->parm_order 3246 = tree_cons (NULL_TREE, decl, current_binding_level->parm_order); 3247 3248 /* Add this decl to the current binding level. */ 3249 finish_decl (decl, NULL_TREE, NULL_TREE); 3250} 3251 3252/* Clear the given order of parms in `parm_order'. 3253 Used at start of parm list, 3254 and also at semicolon terminating forward decls. */ 3255 3256void 3257clear_parm_order () 3258{ 3259 current_binding_level->parm_order = NULL_TREE; 3260} 3261 3262/* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound 3263 literal, which may be an incomplete array type completed by the 3264 initializer; INIT is a CONSTRUCTOR that initializes the compound 3265 literal. */ 3266 3267tree 3268build_compound_literal (type, init) 3269 tree type; 3270 tree init; 3271{ 3272 /* We do not use start_decl here because we have a type, not a declarator; 3273 and do not use finish_decl because the decl should be stored inside 3274 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */ 3275 tree decl = build_decl (VAR_DECL, NULL_TREE, type); 3276 tree complit; 3277 tree stmt; 3278 DECL_EXTERNAL (decl) = 0; 3279 TREE_PUBLIC (decl) = 0; 3280 TREE_STATIC (decl) = (current_binding_level == global_binding_level); 3281 DECL_CONTEXT (decl) = current_function_decl; 3282 TREE_USED (decl) = 1; 3283 TREE_TYPE (decl) = type; 3284 TREE_READONLY (decl) = TREE_READONLY (type); 3285 store_init_value (decl, init); 3286 3287 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) 3288 { 3289 int failure = complete_array_type (type, DECL_INITIAL (decl), 1); 3290 if (failure) 3291 abort (); 3292 } 3293 3294 type = TREE_TYPE (decl); 3295 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) 3296 return error_mark_node; 3297 3298 stmt = build_stmt (DECL_STMT, decl); 3299 complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt); 3300 TREE_SIDE_EFFECTS (complit) = 1; 3301 3302 layout_decl (decl, 0); 3303 3304 if (TREE_STATIC (decl)) 3305 { 3306 /* This decl needs a name for the assembler output. We also need 3307 a unique suffix to be added to the name. */ 3308 char *name; 3309 extern int var_labelno; 3310 3311 ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal", var_labelno); 3312 var_labelno++; 3313 DECL_NAME (decl) = get_identifier (name); 3314 DECL_DEFER_OUTPUT (decl) = 1; 3315 DECL_COMDAT (decl) = 1; 3316 DECL_ARTIFICIAL (decl) = 1; 3317 pushdecl (decl); 3318 rest_of_decl_compilation (decl, NULL, 1, 0); 3319 } 3320 3321 return complit; 3322} 3323 3324/* Make TYPE a complete type based on INITIAL_VALUE. 3325 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, 3326 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ 3327 3328int 3329complete_array_type (type, initial_value, do_default) 3330 tree type; 3331 tree initial_value; 3332 int do_default; 3333{ 3334 tree maxindex = NULL_TREE; 3335 int value = 0; 3336 3337 if (initial_value) 3338 { 3339 /* Note MAXINDEX is really the maximum index, 3340 one less than the size. */ 3341 if (TREE_CODE (initial_value) == STRING_CST) 3342 { 3343 int eltsize 3344 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); 3345 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) 3346 / eltsize) - 1, 0); 3347 } 3348 else if (TREE_CODE (initial_value) == CONSTRUCTOR) 3349 { 3350 tree elts = CONSTRUCTOR_ELTS (initial_value); 3351 maxindex = build_int_2 (-1, -1); 3352 for (; elts; elts = TREE_CHAIN (elts)) 3353 { 3354 if (TREE_PURPOSE (elts)) 3355 maxindex = TREE_PURPOSE (elts); 3356 else 3357 maxindex = fold (build (PLUS_EXPR, integer_type_node, 3358 maxindex, integer_one_node)); 3359 } 3360 maxindex = copy_node (maxindex); 3361 } 3362 else 3363 { 3364 /* Make an error message unless that happened already. */ 3365 if (initial_value != error_mark_node) 3366 value = 1; 3367 3368 /* Prevent further error messages. */ 3369 maxindex = build_int_2 (0, 0); 3370 } 3371 } 3372 3373 if (!maxindex) 3374 { 3375 if (do_default) 3376 maxindex = build_int_2 (0, 0); 3377 value = 2; 3378 } 3379 3380 if (maxindex) 3381 { 3382 TYPE_DOMAIN (type) = build_index_type (maxindex); 3383 if (!TREE_TYPE (maxindex)) 3384 TREE_TYPE (maxindex) = TYPE_DOMAIN (type); 3385 } 3386 3387 /* Lay out the type now that we can get the real answer. */ 3388 3389 layout_type (type); 3390 3391 return value; 3392} 3393 3394/* Determine whether TYPE is a structure with a flexible array member, 3395 or a union containing such a structure (possibly recursively). */ 3396 3397static bool 3398flexible_array_type_p (type) 3399 tree type; 3400{ 3401 tree x; 3402 switch (TREE_CODE (type)) 3403 { 3404 case RECORD_TYPE: 3405 x = TYPE_FIELDS (type); 3406 if (x == NULL_TREE) 3407 return false; 3408 while (TREE_CHAIN (x) != NULL_TREE) 3409 x = TREE_CHAIN (x); 3410 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 3411 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 3412 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE 3413 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) 3414 return true; 3415 return false; 3416 case UNION_TYPE: 3417 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x)) 3418 { 3419 if (flexible_array_type_p (TREE_TYPE (x))) 3420 return true; 3421 } 3422 return false; 3423 default: 3424 return false; 3425 } 3426} 3427 3428/* Given declspecs and a declarator, 3429 determine the name and type of the object declared 3430 and construct a ..._DECL node for it. 3431 (In one case we can return a ..._TYPE node instead. 3432 For invalid input we sometimes return 0.) 3433 3434 DECLSPECS is a chain of tree_list nodes whose value fields 3435 are the storage classes and type specifiers. 3436 3437 DECL_CONTEXT says which syntactic context this declaration is in: 3438 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. 3439 FUNCDEF for a function definition. Like NORMAL but a few different 3440 error messages in each case. Return value may be zero meaning 3441 this definition is too screwy to try to parse. 3442 PARM for a parameter declaration (either within a function prototype 3443 or before a function body). Make a PARM_DECL, or return void_type_node. 3444 TYPENAME if for a typename (in a cast or sizeof). 3445 Don't make a DECL node; just return the ..._TYPE node. 3446 FIELD for a struct or union field; make a FIELD_DECL. 3447 BITFIELD for a field with specified width. 3448 INITIALIZED is 1 if the decl has an initializer. 3449 3450 In the TYPENAME case, DECLARATOR is really an absolute declarator. 3451 It may also be so in the PARM case, for a prototype where the 3452 argument type is specified but not the name. 3453 3454 This function is where the complicated C meanings of `static' 3455 and `extern' are interpreted. */ 3456 3457static tree 3458grokdeclarator (declarator, declspecs, decl_context, initialized) 3459 tree declspecs; 3460 tree declarator; 3461 enum decl_context decl_context; 3462 int initialized; 3463{ 3464 int specbits = 0; 3465 tree spec; 3466 tree type = NULL_TREE; 3467 int longlong = 0; 3468 int constp; 3469 int restrictp; 3470 int volatilep; 3471 int type_quals = TYPE_UNQUALIFIED; 3472 int inlinep; 3473 int explicit_int = 0; 3474 int explicit_char = 0; 3475 int defaulted_int = 0; 3476 tree typedef_decl = 0; 3477 const char *name; 3478 tree typedef_type = 0; 3479 int funcdef_flag = 0; 3480 enum tree_code innermost_code = ERROR_MARK; 3481 int bitfield = 0; 3482 int size_varies = 0; 3483 tree decl_attr = NULL_TREE; 3484 tree array_ptr_quals = NULL_TREE; 3485 int array_parm_static = 0; 3486 tree returned_attrs = NULL_TREE; 3487 3488 if (decl_context == BITFIELD) 3489 bitfield = 1, decl_context = FIELD; 3490 3491 if (decl_context == FUNCDEF) 3492 funcdef_flag = 1, decl_context = NORMAL; 3493 3494 /* Look inside a declarator for the name being declared 3495 and get it as a string, for an error message. */ 3496 { 3497 tree decl = declarator; 3498 name = 0; 3499 3500 while (decl) 3501 switch (TREE_CODE (decl)) 3502 { 3503 case ARRAY_REF: 3504 case INDIRECT_REF: 3505 case CALL_EXPR: 3506 innermost_code = TREE_CODE (decl); 3507 decl = TREE_OPERAND (decl, 0); 3508 break; 3509 3510 case TREE_LIST: 3511 decl = TREE_VALUE (decl); 3512 break; 3513 3514 case IDENTIFIER_NODE: 3515 name = IDENTIFIER_POINTER (decl); 3516 decl = 0; 3517 break; 3518 3519 default: 3520 abort (); 3521 } 3522 if (name == 0) 3523 name = "type name"; 3524 } 3525 3526 /* A function definition's declarator must have the form of 3527 a function declarator. */ 3528 3529 if (funcdef_flag && innermost_code != CALL_EXPR) 3530 return 0; 3531 3532 /* Anything declared one level down from the top level 3533 must be one of the parameters of a function 3534 (because the body is at least two levels down). */ 3535 3536 /* If this looks like a function definition, make it one, 3537 even if it occurs where parms are expected. 3538 Then store_parm_decls will reject it and not use it as a parm. */ 3539 if (decl_context == NORMAL && !funcdef_flag 3540 && current_binding_level->parm_flag) 3541 decl_context = PARM; 3542 3543 /* Look through the decl specs and record which ones appear. 3544 Some typespecs are defined as built-in typenames. 3545 Others, the ones that are modifiers of other types, 3546 are represented by bits in SPECBITS: set the bits for 3547 the modifiers that appear. Storage class keywords are also in SPECBITS. 3548 3549 If there is a typedef name or a type, store the type in TYPE. 3550 This includes builtin typedefs such as `int'. 3551 3552 Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char' 3553 and did not come from a user typedef. 3554 3555 Set LONGLONG if `long' is mentioned twice. */ 3556 3557 for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) 3558 { 3559 tree id = TREE_VALUE (spec); 3560 3561 /* If the entire declaration is itself tagged as deprecated then 3562 suppress reports of deprecated items. */ 3563 if (id && TREE_DEPRECATED (id)) 3564 { 3565 if (deprecated_state != DEPRECATED_SUPPRESS) 3566 warn_deprecated_use (id); 3567 } 3568 3569 if (id == ridpointers[(int) RID_INT]) 3570 explicit_int = 1; 3571 if (id == ridpointers[(int) RID_CHAR]) 3572 explicit_char = 1; 3573 3574 if (TREE_CODE (id) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (id)) 3575 { 3576 enum rid i = C_RID_CODE (id); 3577 if ((int) i <= (int) RID_LAST_MODIFIER) 3578 { 3579 if (i == RID_LONG && (specbits & (1 << (int) RID_LONG))) 3580 { 3581 if (longlong) 3582 error ("`long long long' is too long for GCC"); 3583 else 3584 { 3585 if (pedantic && !flag_isoc99 && ! in_system_header 3586 && warn_long_long) 3587 pedwarn ("ISO C90 does not support `long long'"); 3588 longlong = 1; 3589 } 3590 } 3591 else if (specbits & (1 << (int) i)) 3592 { 3593 if (i == RID_CONST || i == RID_VOLATILE || i == RID_RESTRICT) 3594 { 3595 if (!flag_isoc99) 3596 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); 3597 } 3598 else 3599 error ("duplicate `%s'", IDENTIFIER_POINTER (id)); 3600 } 3601 3602 /* Diagnose "__thread extern". Recall that this list 3603 is in the reverse order seen in the text. */ 3604 if (i == RID_THREAD 3605 && (specbits & (1 << (int) RID_EXTERN 3606 | 1 << (int) RID_STATIC))) 3607 { 3608 if (specbits & 1 << (int) RID_EXTERN) 3609 error ("`__thread' before `extern'"); 3610 else 3611 error ("`__thread' before `static'"); 3612 } 3613 3614 specbits |= 1 << (int) i; 3615 goto found; 3616 } 3617 } 3618 if (type) 3619 error ("two or more data types in declaration of `%s'", name); 3620 /* Actual typedefs come to us as TYPE_DECL nodes. */ 3621 else if (TREE_CODE (id) == TYPE_DECL) 3622 { 3623 if (TREE_TYPE (id) == error_mark_node) 3624 ; /* Allow the type to default to int to avoid cascading errors. */ 3625 else 3626 { 3627 type = TREE_TYPE (id); 3628 decl_attr = DECL_ATTRIBUTES (id); 3629 typedef_decl = id; 3630 } 3631 } 3632 /* Built-in types come as identifiers. */ 3633 else if (TREE_CODE (id) == IDENTIFIER_NODE) 3634 { 3635 tree t = lookup_name (id); 3636 if (TREE_TYPE (t) == error_mark_node) 3637 ; 3638 else if (!t || TREE_CODE (t) != TYPE_DECL) 3639 error ("`%s' fails to be a typedef or built in type", 3640 IDENTIFIER_POINTER (id)); 3641 else 3642 { 3643 type = TREE_TYPE (t); 3644 typedef_decl = t; 3645 } 3646 } 3647 else if (TREE_CODE (id) != ERROR_MARK) 3648 type = id; 3649 3650 found: 3651 ; 3652 } 3653 3654 typedef_type = type; 3655 if (type) 3656 size_varies = C_TYPE_VARIABLE_SIZE (type); 3657 3658 /* No type at all: default to `int', and set DEFAULTED_INT 3659 because it was not a user-defined typedef. */ 3660 3661 if (type == 0) 3662 { 3663 if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) 3664 | (1 << (int) RID_SIGNED) 3665 | (1 << (int) RID_UNSIGNED) 3666 | (1 << (int) RID_COMPLEX)))) 3667 /* Don't warn about typedef foo = bar. */ 3668 && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized) 3669 && ! in_system_header) 3670 { 3671 /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type 3672 and this is a function, or if -Wimplicit; prefer the former 3673 warning since it is more explicit. */ 3674 if ((warn_implicit_int || warn_return_type || flag_isoc99) 3675 && funcdef_flag) 3676 warn_about_return_type = 1; 3677 else if (warn_implicit_int || flag_isoc99) 3678 pedwarn_c99 ("type defaults to `int' in declaration of `%s'", 3679 name); 3680 } 3681 3682 defaulted_int = 1; 3683 type = integer_type_node; 3684 } 3685 3686 /* Now process the modifiers that were specified 3687 and check for invalid combinations. */ 3688 3689 /* Long double is a special combination. */ 3690 3691 if ((specbits & 1 << (int) RID_LONG) && ! longlong 3692 && TYPE_MAIN_VARIANT (type) == double_type_node) 3693 { 3694 specbits &= ~(1 << (int) RID_LONG); 3695 type = long_double_type_node; 3696 } 3697 3698 /* Check all other uses of type modifiers. */ 3699 3700 if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) 3701 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED))) 3702 { 3703 int ok = 0; 3704 3705 if ((specbits & 1 << (int) RID_LONG) 3706 && (specbits & 1 << (int) RID_SHORT)) 3707 error ("both long and short specified for `%s'", name); 3708 else if (((specbits & 1 << (int) RID_LONG) 3709 || (specbits & 1 << (int) RID_SHORT)) 3710 && explicit_char) 3711 error ("long or short specified with char for `%s'", name); 3712 else if (((specbits & 1 << (int) RID_LONG) 3713 || (specbits & 1 << (int) RID_SHORT)) 3714 && TREE_CODE (type) == REAL_TYPE) 3715 { 3716 static int already = 0; 3717 3718 error ("long or short specified with floating type for `%s'", name); 3719 if (! already && ! pedantic) 3720 { 3721 error ("the only valid combination is `long double'"); 3722 already = 1; 3723 } 3724 } 3725 else if ((specbits & 1 << (int) RID_SIGNED) 3726 && (specbits & 1 << (int) RID_UNSIGNED)) 3727 error ("both signed and unsigned specified for `%s'", name); 3728 else if (TREE_CODE (type) != INTEGER_TYPE) 3729 error ("long, short, signed or unsigned invalid for `%s'", name); 3730 else 3731 { 3732 ok = 1; 3733 if (!explicit_int && !defaulted_int && !explicit_char) 3734 { 3735 error ("long, short, signed or unsigned used invalidly for `%s'", 3736 name); 3737 ok = 0; 3738 } 3739 } 3740 3741 /* Discard the type modifiers if they are invalid. */ 3742 if (! ok) 3743 { 3744 specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) 3745 | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)); 3746 longlong = 0; 3747 } 3748 } 3749 3750 if ((specbits & (1 << (int) RID_COMPLEX)) 3751 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) 3752 { 3753 error ("complex invalid for `%s'", name); 3754 specbits &= ~(1 << (int) RID_COMPLEX); 3755 } 3756 3757 /* Decide whether an integer type is signed or not. 3758 Optionally treat bitfields as signed by default. */ 3759 if (specbits & 1 << (int) RID_UNSIGNED 3760 || (bitfield && ! flag_signed_bitfields 3761 && (explicit_int || defaulted_int || explicit_char 3762 /* A typedef for plain `int' without `signed' 3763 can be controlled just like plain `int'. */ 3764 || ! (typedef_decl != 0 3765 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) 3766 && TREE_CODE (type) != ENUMERAL_TYPE 3767 && !(specbits & 1 << (int) RID_SIGNED))) 3768 { 3769 if (longlong) 3770 type = long_long_unsigned_type_node; 3771 else if (specbits & 1 << (int) RID_LONG) 3772 type = long_unsigned_type_node; 3773 else if (specbits & 1 << (int) RID_SHORT) 3774 type = short_unsigned_type_node; 3775 else if (type == char_type_node) 3776 type = unsigned_char_type_node; 3777 else if (typedef_decl) 3778 type = c_common_unsigned_type (type); 3779 else 3780 type = unsigned_type_node; 3781 } 3782 else if ((specbits & 1 << (int) RID_SIGNED) 3783 && type == char_type_node) 3784 type = signed_char_type_node; 3785 else if (longlong) 3786 type = long_long_integer_type_node; 3787 else if (specbits & 1 << (int) RID_LONG) 3788 type = long_integer_type_node; 3789 else if (specbits & 1 << (int) RID_SHORT) 3790 type = short_integer_type_node; 3791 3792 if (specbits & 1 << (int) RID_COMPLEX) 3793 { 3794 if (pedantic && !flag_isoc99) 3795 pedwarn ("ISO C90 does not support complex types"); 3796 /* If we just have "complex", it is equivalent to 3797 "complex double", but if any modifiers at all are specified it is 3798 the complex form of TYPE. E.g, "complex short" is 3799 "complex short int". */ 3800 3801 if (defaulted_int && ! longlong 3802 && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) 3803 | (1 << (int) RID_SIGNED) 3804 | (1 << (int) RID_UNSIGNED)))) 3805 { 3806 if (pedantic) 3807 pedwarn ("ISO C does not support plain `complex' meaning `double complex'"); 3808 type = complex_double_type_node; 3809 } 3810 else if (type == integer_type_node) 3811 { 3812 if (pedantic) 3813 pedwarn ("ISO C does not support complex integer types"); 3814 type = complex_integer_type_node; 3815 } 3816 else if (type == float_type_node) 3817 type = complex_float_type_node; 3818 else if (type == double_type_node) 3819 type = complex_double_type_node; 3820 else if (type == long_double_type_node) 3821 type = complex_long_double_type_node; 3822 else 3823 { 3824 if (pedantic) 3825 pedwarn ("ISO C does not support complex integer types"); 3826 type = build_complex_type (type); 3827 } 3828 } 3829 3830 /* Figure out the type qualifiers for the declaration. There are 3831 two ways a declaration can become qualified. One is something 3832 like `const int i' where the `const' is explicit. Another is 3833 something like `typedef const int CI; CI i' where the type of the 3834 declaration contains the `const'. */ 3835 constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type); 3836 restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type); 3837 volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type); 3838 inlinep = !! (specbits & (1 << (int) RID_INLINE)); 3839 if (constp > 1 && ! flag_isoc99) 3840 pedwarn ("duplicate `const'"); 3841 if (restrictp > 1 && ! flag_isoc99) 3842 pedwarn ("duplicate `restrict'"); 3843 if (volatilep > 1 && ! flag_isoc99) 3844 pedwarn ("duplicate `volatile'"); 3845 if (! flag_gen_aux_info && (TYPE_QUALS (type))) 3846 type = TYPE_MAIN_VARIANT (type); 3847 type_quals = ((constp ? TYPE_QUAL_CONST : 0) 3848 | (restrictp ? TYPE_QUAL_RESTRICT : 0) 3849 | (volatilep ? TYPE_QUAL_VOLATILE : 0)); 3850 3851 /* Warn if two storage classes are given. Default to `auto'. */ 3852 3853 { 3854 int nclasses = 0; 3855 3856 if (specbits & 1 << (int) RID_AUTO) nclasses++; 3857 if (specbits & 1 << (int) RID_STATIC) nclasses++; 3858 if (specbits & 1 << (int) RID_EXTERN) nclasses++; 3859 if (specbits & 1 << (int) RID_REGISTER) nclasses++; 3860 if (specbits & 1 << (int) RID_TYPEDEF) nclasses++; 3861 3862 /* "static __thread" and "extern __thread" are allowed. */ 3863 if ((specbits & (1 << (int) RID_THREAD 3864 | 1 << (int) RID_STATIC 3865 | 1 << (int) RID_EXTERN)) == (1 << (int) RID_THREAD)) 3866 nclasses++; 3867 3868 /* Warn about storage classes that are invalid for certain 3869 kinds of declarations (parameters, typenames, etc.). */ 3870 3871 if (nclasses > 1) 3872 error ("multiple storage classes in declaration of `%s'", name); 3873 else if (funcdef_flag 3874 && (specbits 3875 & ((1 << (int) RID_REGISTER) 3876 | (1 << (int) RID_AUTO) 3877 | (1 << (int) RID_TYPEDEF) 3878 | (1 << (int) RID_THREAD)))) 3879 { 3880 if (specbits & 1 << (int) RID_AUTO 3881 && (pedantic || current_binding_level == global_binding_level)) 3882 pedwarn ("function definition declared `auto'"); 3883 if (specbits & 1 << (int) RID_REGISTER) 3884 error ("function definition declared `register'"); 3885 if (specbits & 1 << (int) RID_TYPEDEF) 3886 error ("function definition declared `typedef'"); 3887 if (specbits & 1 << (int) RID_THREAD) 3888 error ("function definition declared `__thread'"); 3889 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) 3890 | (1 << (int) RID_AUTO) | (1 << (int) RID_THREAD)); 3891 } 3892 else if (decl_context != NORMAL && nclasses > 0) 3893 { 3894 if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER) 3895 ; 3896 else 3897 { 3898 switch (decl_context) 3899 { 3900 case FIELD: 3901 error ("storage class specified for structure field `%s'", 3902 name); 3903 break; 3904 case PARM: 3905 error ("storage class specified for parameter `%s'", name); 3906 break; 3907 default: 3908 error ("storage class specified for typename"); 3909 break; 3910 } 3911 specbits &= ~((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) 3912 | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC) 3913 | (1 << (int) RID_EXTERN) | (1 << (int) RID_THREAD)); 3914 } 3915 } 3916 else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag) 3917 { 3918 /* `extern' with initialization is invalid if not at top level. */ 3919 if (current_binding_level == global_binding_level) 3920 warning ("`%s' initialized and declared `extern'", name); 3921 else 3922 error ("`%s' has both `extern' and initializer", name); 3923 } 3924 else if (current_binding_level == global_binding_level) 3925 { 3926 if (specbits & 1 << (int) RID_AUTO) 3927 error ("top-level declaration of `%s' specifies `auto'", name); 3928 } 3929 else 3930 { 3931 if (specbits & 1 << (int) RID_EXTERN && funcdef_flag) 3932 error ("nested function `%s' declared `extern'", name); 3933 else if ((specbits & (1 << (int) RID_THREAD 3934 | 1 << (int) RID_EXTERN 3935 | 1 << (int) RID_STATIC)) 3936 == (1 << (int) RID_THREAD)) 3937 { 3938 error ("function-scope `%s' implicitly auto and declared `__thread'", 3939 name); 3940 specbits &= ~(1 << (int) RID_THREAD); 3941 } 3942 } 3943 } 3944 3945 /* Now figure out the structure of the declarator proper. 3946 Descend through it, creating more complex types, until we reach 3947 the declared identifier (or NULL_TREE, in an absolute declarator). */ 3948 3949 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) 3950 { 3951 if (type == error_mark_node) 3952 { 3953 declarator = TREE_OPERAND (declarator, 0); 3954 continue; 3955 } 3956 3957 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), 3958 an INDIRECT_REF (for *...), 3959 a CALL_EXPR (for ...(...)), 3960 a TREE_LIST (for nested attributes), 3961 an identifier (for the name being declared) 3962 or a null pointer (for the place in an absolute declarator 3963 where the name was omitted). 3964 For the last two cases, we have just exited the loop. 3965 3966 At this point, TYPE is the type of elements of an array, 3967 or for a function to return, or for a pointer to point to. 3968 After this sequence of ifs, TYPE is the type of the 3969 array or function or pointer, and DECLARATOR has had its 3970 outermost layer removed. */ 3971 3972 if (array_ptr_quals != NULL_TREE || array_parm_static) 3973 { 3974 /* Only the innermost declarator (making a parameter be of 3975 array type which is converted to pointer type) 3976 may have static or type qualifiers. */ 3977 error ("static or type qualifiers in non-parameter array declarator"); 3978 array_ptr_quals = NULL_TREE; 3979 array_parm_static = 0; 3980 } 3981 3982 if (TREE_CODE (declarator) == TREE_LIST) 3983 { 3984 /* We encode a declarator with embedded attributes using 3985 a TREE_LIST. */ 3986 tree attrs = TREE_PURPOSE (declarator); 3987 tree inner_decl; 3988 int attr_flags = 0; 3989 declarator = TREE_VALUE (declarator); 3990 inner_decl = declarator; 3991 while (inner_decl != NULL_TREE 3992 && TREE_CODE (inner_decl) == TREE_LIST) 3993 inner_decl = TREE_VALUE (inner_decl); 3994 if (inner_decl == NULL_TREE 3995 || TREE_CODE (inner_decl) == IDENTIFIER_NODE) 3996 attr_flags |= (int) ATTR_FLAG_DECL_NEXT; 3997 else if (TREE_CODE (inner_decl) == CALL_EXPR) 3998 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT; 3999 else if (TREE_CODE (inner_decl) == ARRAY_REF) 4000 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT; 4001 returned_attrs = decl_attributes (&type, 4002 chainon (returned_attrs, attrs), 4003 attr_flags); 4004 } 4005 else if (TREE_CODE (declarator) == ARRAY_REF) 4006 { 4007 tree itype = NULL_TREE; 4008 tree size = TREE_OPERAND (declarator, 1); 4009 /* The index is a signed object `sizetype' bits wide. */ 4010 tree index_type = c_common_signed_type (sizetype); 4011 4012 array_ptr_quals = TREE_TYPE (declarator); 4013 array_parm_static = TREE_STATIC (declarator); 4014 4015 declarator = TREE_OPERAND (declarator, 0); 4016 4017 /* Check for some types that there cannot be arrays of. */ 4018 4019 if (VOID_TYPE_P (type)) 4020 { 4021 error ("declaration of `%s' as array of voids", name); 4022 type = error_mark_node; 4023 } 4024 4025 if (TREE_CODE (type) == FUNCTION_TYPE) 4026 { 4027 error ("declaration of `%s' as array of functions", name); 4028 type = error_mark_node; 4029 } 4030 4031 if (pedantic && flexible_array_type_p (type)) 4032 pedwarn ("invalid use of structure with flexible array member"); 4033 4034 if (size == error_mark_node) 4035 type = error_mark_node; 4036 4037 if (type == error_mark_node) 4038 continue; 4039 4040 /* If size was specified, set ITYPE to a range-type for that size. 4041 Otherwise, ITYPE remains null. finish_decl may figure it out 4042 from an initial value. */ 4043 4044 if (size) 4045 { 4046 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ 4047 STRIP_TYPE_NOPS (size); 4048 4049 if (! INTEGRAL_TYPE_P (TREE_TYPE (size))) 4050 { 4051 error ("size of array `%s' has non-integer type", name); 4052 size = integer_one_node; 4053 } 4054 4055 if (pedantic && integer_zerop (size)) 4056 pedwarn ("ISO C forbids zero-size array `%s'", name); 4057 4058 if (TREE_CODE (size) == INTEGER_CST) 4059 { 4060 constant_expression_warning (size); 4061 if (tree_int_cst_sgn (size) < 0) 4062 { 4063 error ("size of array `%s' is negative", name); 4064 size = integer_one_node; 4065 } 4066 } 4067 else 4068 { 4069 /* Make sure the array size remains visibly nonconstant 4070 even if it is (eg) a const variable with known value. */ 4071 size_varies = 1; 4072 4073 if (!flag_isoc99 && pedantic) 4074 { 4075 if (TREE_CONSTANT (size)) 4076 pedwarn ("ISO C90 forbids array `%s' whose size can't be evaluated", 4077 name); 4078 else 4079 pedwarn ("ISO C90 forbids variable-size array `%s'", 4080 name); 4081 } 4082 } 4083 4084 if (integer_zerop (size)) 4085 { 4086 /* A zero-length array cannot be represented with an 4087 unsigned index type, which is what we'll get with 4088 build_index_type. Create an open-ended range instead. */ 4089 itype = build_range_type (sizetype, size, NULL_TREE); 4090 } 4091 else 4092 { 4093 /* Compute the maximum valid index, that is, size - 1. 4094 Do the calculation in index_type, so that if it is 4095 a variable the computations will be done in the 4096 proper mode. */ 4097 itype = fold (build (MINUS_EXPR, index_type, 4098 convert (index_type, size), 4099 convert (index_type, size_one_node))); 4100 4101 /* If that overflowed, the array is too big. 4102 ??? While a size of INT_MAX+1 technically shouldn't 4103 cause an overflow (because we subtract 1), the overflow 4104 is recorded during the conversion to index_type, before 4105 the subtraction. Handling this case seems like an 4106 unnecessary complication. */ 4107 if (TREE_OVERFLOW (itype)) 4108 { 4109 error ("size of array `%s' is too large", name); 4110 type = error_mark_node; 4111 continue; 4112 } 4113 4114 if (size_varies) 4115 { 4116 /* We must be able to distinguish the 4117 SAVE_EXPR_CONTEXT for the variably-sized type 4118 so that we can set it correctly in 4119 set_save_expr_context. The convention is 4120 that all SAVE_EXPRs that need to be reset 4121 have NULL_TREE for their SAVE_EXPR_CONTEXT. */ 4122 tree cfd = current_function_decl; 4123 if (decl_context == PARM) 4124 current_function_decl = NULL_TREE; 4125 itype = variable_size (itype); 4126 if (decl_context == PARM) 4127 current_function_decl = cfd; 4128 } 4129 itype = build_index_type (itype); 4130 } 4131 } 4132 else if (decl_context == FIELD) 4133 { 4134 if (pedantic && !flag_isoc99 && !in_system_header) 4135 pedwarn ("ISO C90 does not support flexible array members"); 4136 4137 /* ISO C99 Flexible array members are effectively identical 4138 to GCC's zero-length array extension. */ 4139 itype = build_range_type (sizetype, size_zero_node, NULL_TREE); 4140 } 4141 4142 /* If pedantic, complain about arrays of incomplete types. */ 4143 4144 if (pedantic && !COMPLETE_TYPE_P (type)) 4145 pedwarn ("array type has incomplete element type"); 4146 4147#if 0 4148 /* We shouldn't have a function type here at all! 4149 Functions aren't allowed as array elements. */ 4150 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 4151 && (constp || volatilep)) 4152 pedwarn ("ISO C forbids const or volatile function types"); 4153#endif 4154 4155 /* Build the array type itself, then merge any constancy or 4156 volatility into the target type. We must do it in this order 4157 to ensure that the TYPE_MAIN_VARIANT field of the array type 4158 is set correctly. */ 4159 4160 type = build_array_type (type, itype); 4161 if (type_quals) 4162 type = c_build_qualified_type (type, type_quals); 4163 4164 if (size_varies) 4165 C_TYPE_VARIABLE_SIZE (type) = 1; 4166 4167 /* The GCC extension for zero-length arrays differs from 4168 ISO flexible array members in that sizeof yields zero. */ 4169 if (size && integer_zerop (size)) 4170 { 4171 layout_type (type); 4172 TYPE_SIZE (type) = bitsize_zero_node; 4173 TYPE_SIZE_UNIT (type) = size_zero_node; 4174 } 4175 if (decl_context != PARM 4176 && (array_ptr_quals != NULL_TREE || array_parm_static)) 4177 { 4178 error ("static or type qualifiers in non-parameter array declarator"); 4179 array_ptr_quals = NULL_TREE; 4180 array_parm_static = 0; 4181 } 4182 } 4183 else if (TREE_CODE (declarator) == CALL_EXPR) 4184 { 4185 tree arg_types; 4186 4187 /* Declaring a function type. 4188 Make sure we have a valid type for the function to return. */ 4189 if (type == error_mark_node) 4190 continue; 4191 4192 size_varies = 0; 4193 4194 /* Warn about some types functions can't return. */ 4195 4196 if (TREE_CODE (type) == FUNCTION_TYPE) 4197 { 4198 error ("`%s' declared as function returning a function", name); 4199 type = integer_type_node; 4200 } 4201 if (TREE_CODE (type) == ARRAY_TYPE) 4202 { 4203 error ("`%s' declared as function returning an array", name); 4204 type = integer_type_node; 4205 } 4206 4207 /* Construct the function type and go to the next 4208 inner layer of declarator. */ 4209 4210 arg_types = grokparms (TREE_OPERAND (declarator, 1), 4211 funcdef_flag 4212 /* Say it's a definition 4213 only for the CALL_EXPR 4214 closest to the identifier. */ 4215 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE); 4216 /* Type qualifiers before the return type of the function 4217 qualify the return type, not the function type. */ 4218 if (type_quals) 4219 { 4220 /* Type qualifiers on a function return type are normally 4221 permitted by the standard but have no effect, so give a 4222 warning at -W. Qualifiers on a void return type have 4223 meaning as a GNU extension, and are banned on function 4224 definitions in ISO C. FIXME: strictly we shouldn't 4225 pedwarn for qualified void return types except on function 4226 definitions, but not doing so could lead to the undesirable 4227 state of a "volatile void" function return type not being 4228 warned about, and a use of the function being compiled 4229 with GNU semantics, with no diagnostics under -pedantic. */ 4230 if (VOID_TYPE_P (type) && pedantic && !in_system_header) 4231 pedwarn ("ISO C forbids qualified void function return type"); 4232 else if (extra_warnings 4233 && !(VOID_TYPE_P (type) 4234 && type_quals == TYPE_QUAL_VOLATILE)) 4235 warning ("type qualifiers ignored on function return type"); 4236 4237 type = c_build_qualified_type (type, type_quals); 4238 } 4239 type_quals = TYPE_UNQUALIFIED; 4240 4241 type = build_function_type (type, arg_types); 4242 declarator = TREE_OPERAND (declarator, 0); 4243 4244 /* Set the TYPE_CONTEXTs for each tagged type which is local to 4245 the formal parameter list of this FUNCTION_TYPE to point to 4246 the FUNCTION_TYPE node itself. */ 4247 4248 { 4249 tree link; 4250 4251 for (link = last_function_parm_tags; 4252 link; 4253 link = TREE_CHAIN (link)) 4254 TYPE_CONTEXT (TREE_VALUE (link)) = type; 4255 } 4256 } 4257 else if (TREE_CODE (declarator) == INDIRECT_REF) 4258 { 4259 /* Merge any constancy or volatility into the target type 4260 for the pointer. */ 4261 4262 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 4263 && type_quals) 4264 pedwarn ("ISO C forbids qualified function types"); 4265 if (type_quals) 4266 type = c_build_qualified_type (type, type_quals); 4267 type_quals = TYPE_UNQUALIFIED; 4268 size_varies = 0; 4269 4270 type = build_pointer_type (type); 4271 4272 /* Process a list of type modifier keywords 4273 (such as const or volatile) that were given inside the `*'. */ 4274 4275 if (TREE_TYPE (declarator)) 4276 { 4277 tree typemodlist; 4278 int erred = 0; 4279 4280 constp = 0; 4281 volatilep = 0; 4282 restrictp = 0; 4283 for (typemodlist = TREE_TYPE (declarator); typemodlist; 4284 typemodlist = TREE_CHAIN (typemodlist)) 4285 { 4286 tree qualifier = TREE_VALUE (typemodlist); 4287 4288 if (C_IS_RESERVED_WORD (qualifier)) 4289 { 4290 if (C_RID_CODE (qualifier) == RID_CONST) 4291 constp++; 4292 else if (C_RID_CODE (qualifier) == RID_VOLATILE) 4293 volatilep++; 4294 else if (C_RID_CODE (qualifier) == RID_RESTRICT) 4295 restrictp++; 4296 else 4297 erred++; 4298 } 4299 else 4300 erred++; 4301 } 4302 4303 if (erred) 4304 error ("invalid type modifier within pointer declarator"); 4305 if (constp > 1 && ! flag_isoc99) 4306 pedwarn ("duplicate `const'"); 4307 if (volatilep > 1 && ! flag_isoc99) 4308 pedwarn ("duplicate `volatile'"); 4309 if (restrictp > 1 && ! flag_isoc99) 4310 pedwarn ("duplicate `restrict'"); 4311 4312 type_quals = ((constp ? TYPE_QUAL_CONST : 0) 4313 | (restrictp ? TYPE_QUAL_RESTRICT : 0) 4314 | (volatilep ? TYPE_QUAL_VOLATILE : 0)); 4315 } 4316 4317 declarator = TREE_OPERAND (declarator, 0); 4318 } 4319 else 4320 abort (); 4321 4322 } 4323 4324 /* Now TYPE has the actual type. */ 4325 4326 /* Did array size calculations overflow? */ 4327 4328 if (TREE_CODE (type) == ARRAY_TYPE 4329 && COMPLETE_TYPE_P (type) 4330 && TREE_OVERFLOW (TYPE_SIZE (type))) 4331 { 4332 error ("size of array `%s' is too large", name); 4333 /* If we proceed with the array type as it is, we'll eventually 4334 crash in tree_low_cst(). */ 4335 type = error_mark_node; 4336 } 4337 4338 /* If this is declaring a typedef name, return a TYPE_DECL. */ 4339 4340 if (specbits & (1 << (int) RID_TYPEDEF)) 4341 { 4342 tree decl; 4343 /* Note that the grammar rejects storage classes 4344 in typenames, fields or parameters */ 4345 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 4346 && type_quals) 4347 pedwarn ("ISO C forbids qualified function types"); 4348 if (type_quals) 4349 type = c_build_qualified_type (type, type_quals); 4350 decl = build_decl (TYPE_DECL, declarator, type); 4351 if ((specbits & (1 << (int) RID_SIGNED)) 4352 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) 4353 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; 4354 decl_attributes (&decl, returned_attrs, 0); 4355 return decl; 4356 } 4357 4358 /* Detect the case of an array type of unspecified size 4359 which came, as such, direct from a typedef name. 4360 We must copy the type, so that each identifier gets 4361 a distinct type, so that each identifier's size can be 4362 controlled separately by its own initializer. */ 4363 4364 if (type != 0 && typedef_type != 0 4365 && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0 4366 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)) 4367 { 4368 type = build_array_type (TREE_TYPE (type), 0); 4369 if (size_varies) 4370 C_TYPE_VARIABLE_SIZE (type) = 1; 4371 } 4372 4373 /* If this is a type name (such as, in a cast or sizeof), 4374 compute the type and return it now. */ 4375 4376 if (decl_context == TYPENAME) 4377 { 4378 /* Note that the grammar rejects storage classes 4379 in typenames, fields or parameters */ 4380 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 4381 && type_quals) 4382 pedwarn ("ISO C forbids const or volatile function types"); 4383 if (type_quals) 4384 type = c_build_qualified_type (type, type_quals); 4385 decl_attributes (&type, returned_attrs, 0); 4386 return type; 4387 } 4388 4389 /* Aside from typedefs and type names (handle above), 4390 `void' at top level (not within pointer) 4391 is allowed only in public variables. 4392 We don't complain about parms either, but that is because 4393 a better error message can be made later. */ 4394 4395 if (VOID_TYPE_P (type) && decl_context != PARM 4396 && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE) 4397 && ((specbits & (1 << (int) RID_EXTERN)) 4398 || (current_binding_level == global_binding_level 4399 && !(specbits 4400 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))))))) 4401 { 4402 error ("variable or field `%s' declared void", name); 4403 type = integer_type_node; 4404 } 4405 4406 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL 4407 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ 4408 4409 { 4410 tree decl; 4411 4412 if (decl_context == PARM) 4413 { 4414 tree type_as_written; 4415 tree promoted_type; 4416 4417 /* A parameter declared as an array of T is really a pointer to T. 4418 One declared as a function is really a pointer to a function. */ 4419 4420 if (TREE_CODE (type) == ARRAY_TYPE) 4421 { 4422 /* Transfer const-ness of array into that of type pointed to. */ 4423 type = TREE_TYPE (type); 4424 if (type_quals) 4425 type = c_build_qualified_type (type, type_quals); 4426 type = build_pointer_type (type); 4427 type_quals = TYPE_UNQUALIFIED; 4428 if (array_ptr_quals) 4429 { 4430 tree new_ptr_quals, new_ptr_attrs; 4431 int erred = 0; 4432 split_specs_attrs (array_ptr_quals, &new_ptr_quals, &new_ptr_attrs); 4433 /* We don't yet implement attributes in this context. */ 4434 if (new_ptr_attrs != NULL_TREE) 4435 warning ("attributes in parameter array declarator ignored"); 4436 4437 constp = 0; 4438 volatilep = 0; 4439 restrictp = 0; 4440 for (; new_ptr_quals; new_ptr_quals = TREE_CHAIN (new_ptr_quals)) 4441 { 4442 tree qualifier = TREE_VALUE (new_ptr_quals); 4443 4444 if (C_IS_RESERVED_WORD (qualifier)) 4445 { 4446 if (C_RID_CODE (qualifier) == RID_CONST) 4447 constp++; 4448 else if (C_RID_CODE (qualifier) == RID_VOLATILE) 4449 volatilep++; 4450 else if (C_RID_CODE (qualifier) == RID_RESTRICT) 4451 restrictp++; 4452 else 4453 erred++; 4454 } 4455 else 4456 erred++; 4457 } 4458 4459 if (erred) 4460 error ("invalid type modifier within array declarator"); 4461 4462 type_quals = ((constp ? TYPE_QUAL_CONST : 0) 4463 | (restrictp ? TYPE_QUAL_RESTRICT : 0) 4464 | (volatilep ? TYPE_QUAL_VOLATILE : 0)); 4465 } 4466 size_varies = 0; 4467 } 4468 else if (TREE_CODE (type) == FUNCTION_TYPE) 4469 { 4470 if (pedantic && type_quals) 4471 pedwarn ("ISO C forbids qualified function types"); 4472 if (type_quals) 4473 type = c_build_qualified_type (type, type_quals); 4474 type = build_pointer_type (type); 4475 type_quals = TYPE_UNQUALIFIED; 4476 } 4477 else if (type_quals) 4478 type = c_build_qualified_type (type, type_quals); 4479 4480 type_as_written = type; 4481 4482 decl = build_decl (PARM_DECL, declarator, type); 4483 if (size_varies) 4484 C_DECL_VARIABLE_SIZE (decl) = 1; 4485 4486 /* Compute the type actually passed in the parmlist, 4487 for the case where there is no prototype. 4488 (For example, shorts and chars are passed as ints.) 4489 When there is a prototype, this is overridden later. */ 4490 4491 if (type == error_mark_node) 4492 promoted_type = type; 4493 else 4494 promoted_type = c_type_promotes_to (type); 4495 4496 DECL_ARG_TYPE (decl) = promoted_type; 4497 DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written; 4498 } 4499 else if (decl_context == FIELD) 4500 { 4501 /* Structure field. It may not be a function. */ 4502 4503 if (TREE_CODE (type) == FUNCTION_TYPE) 4504 { 4505 error ("field `%s' declared as a function", name); 4506 type = build_pointer_type (type); 4507 } 4508 else if (TREE_CODE (type) != ERROR_MARK 4509 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) 4510 { 4511 error ("field `%s' has incomplete type", name); 4512 type = error_mark_node; 4513 } 4514 /* Move type qualifiers down to element of an array. */ 4515 if (TREE_CODE (type) == ARRAY_TYPE && type_quals) 4516 { 4517 type = build_array_type (c_build_qualified_type (TREE_TYPE (type), 4518 type_quals), 4519 TYPE_DOMAIN (type)); 4520#if 0 4521 /* Leave the field const or volatile as well. */ 4522 type_quals = TYPE_UNQUALIFIED; 4523#endif 4524 } 4525 decl = build_decl (FIELD_DECL, declarator, type); 4526 DECL_NONADDRESSABLE_P (decl) = bitfield; 4527 4528 if (size_varies) 4529 C_DECL_VARIABLE_SIZE (decl) = 1; 4530 } 4531 else if (TREE_CODE (type) == FUNCTION_TYPE) 4532 { 4533 /* Every function declaration is "external" 4534 except for those which are inside a function body 4535 in which `auto' is used. 4536 That is a case not specified by ANSI C, 4537 and we use it for forward declarations for nested functions. */ 4538 int extern_ref = (!(specbits & (1 << (int) RID_AUTO)) 4539 || current_binding_level == global_binding_level); 4540 4541 if (specbits & (1 << (int) RID_AUTO) 4542 && (pedantic || current_binding_level == global_binding_level)) 4543 pedwarn ("invalid storage class for function `%s'", name); 4544 if (specbits & (1 << (int) RID_REGISTER)) 4545 error ("invalid storage class for function `%s'", name); 4546 if (specbits & (1 << (int) RID_THREAD)) 4547 error ("invalid storage class for function `%s'", name); 4548 /* Function declaration not at top level. 4549 Storage classes other than `extern' are not allowed 4550 and `extern' makes no difference. */ 4551 if (current_binding_level != global_binding_level 4552 && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE))) 4553 && pedantic) 4554 pedwarn ("invalid storage class for function `%s'", name); 4555 4556 decl = build_decl (FUNCTION_DECL, declarator, type); 4557 decl = build_decl_attribute_variant (decl, decl_attr); 4558 4559 DECL_LANG_SPECIFIC (decl) = (struct lang_decl *) 4560 ggc_alloc_cleared (sizeof (struct lang_decl)); 4561 4562 if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl)) 4563 pedwarn ("ISO C forbids qualified function types"); 4564 4565 /* GNU C interprets a `volatile void' return type to indicate 4566 that the function does not return. */ 4567 if ((type_quals & TYPE_QUAL_VOLATILE) 4568 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) 4569 warning ("`noreturn' function returns non-void value"); 4570 4571 if (extern_ref) 4572 DECL_EXTERNAL (decl) = 1; 4573 /* Record absence of global scope for `static' or `auto'. */ 4574 TREE_PUBLIC (decl) 4575 = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO))); 4576 4577 if (defaulted_int) 4578 C_FUNCTION_IMPLICIT_INT (decl) = 1; 4579 4580 /* Record presence of `inline', if it is reasonable. */ 4581 if (MAIN_NAME_P (declarator)) 4582 { 4583 if (inlinep) 4584 warning ("cannot inline function `main'"); 4585 } 4586 else if (inlinep) 4587 { 4588 /* Assume that otherwise the function can be inlined. */ 4589 DECL_DECLARED_INLINE_P (decl) = 1; 4590 4591 /* Do not mark bare declarations as DECL_INLINE. Doing so 4592 in the presence of multiple declarations can result in 4593 the abstract origin pointing between the declarations, 4594 which will confuse dwarf2out. */ 4595 if (initialized) 4596 { 4597 DECL_INLINE (decl) = 1; 4598 if (specbits & (1 << (int) RID_EXTERN)) 4599 current_extern_inline = 1; 4600 } 4601 } 4602 /* If -finline-functions, assume it can be inlined. This does 4603 two things: let the function be deferred until it is actually 4604 needed, and let dwarf2 know that the function is inlinable. */ 4605 else if (flag_inline_trees == 2 && initialized) 4606 { 4607 if (!DECL_INLINE (decl)) 4608 DID_INLINE_FUNC (decl) = 1; 4609 DECL_INLINE (decl) = 1; 4610 DECL_DECLARED_INLINE_P (decl) = 0; 4611 } 4612 } 4613 else 4614 { 4615 /* It's a variable. */ 4616 /* An uninitialized decl with `extern' is a reference. */ 4617 int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN)); 4618 4619 /* Move type qualifiers down to element of an array. */ 4620 if (TREE_CODE (type) == ARRAY_TYPE && type_quals) 4621 { 4622 int saved_align = TYPE_ALIGN(type); 4623 type = build_array_type (c_build_qualified_type (TREE_TYPE (type), 4624 type_quals), 4625 TYPE_DOMAIN (type)); 4626 TYPE_ALIGN (type) = saved_align; 4627#if 0 /* Leave the variable const or volatile as well. */ 4628 type_quals = TYPE_UNQUALIFIED; 4629#endif 4630 } 4631 else if (type_quals) 4632 type = c_build_qualified_type (type, type_quals); 4633 4634 decl = build_decl (VAR_DECL, declarator, type); 4635 if (size_varies) 4636 C_DECL_VARIABLE_SIZE (decl) = 1; 4637 4638 if (inlinep) 4639 pedwarn_with_decl (decl, "variable `%s' declared `inline'"); 4640 4641 DECL_EXTERNAL (decl) = extern_ref; 4642 4643 /* At top level, the presence of a `static' or `register' storage 4644 class specifier, or the absence of all storage class specifiers 4645 makes this declaration a definition (perhaps tentative). Also, 4646 the absence of both `static' and `register' makes it public. */ 4647 if (current_binding_level == global_binding_level) 4648 { 4649 TREE_PUBLIC (decl) = !(specbits & ((1 << (int) RID_STATIC) 4650 | (1 << (int) RID_REGISTER))); 4651 TREE_STATIC (decl) = !extern_ref; 4652 } 4653 /* Not at top level, only `static' makes a static definition. */ 4654 else 4655 { 4656 TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0; 4657 TREE_PUBLIC (decl) = extern_ref; 4658 } 4659 4660 if (specbits & 1 << (int) RID_THREAD) 4661 { 4662 if (targetm.have_tls) 4663 DECL_THREAD_LOCAL (decl) = 1; 4664 else 4665 /* A mere warning is sure to result in improper semantics 4666 at runtime. Don't bother to allow this to compile. */ 4667 error ("thread-local storage not supported for this target"); 4668 } 4669 } 4670 4671 /* Record `register' declaration for warnings on & 4672 and in case doing stupid register allocation. */ 4673 4674 if (specbits & (1 << (int) RID_REGISTER)) 4675 DECL_REGISTER (decl) = 1; 4676 4677 /* Record constancy and volatility. */ 4678 c_apply_type_quals_to_decl (type_quals, decl); 4679 4680 /* If a type has volatile components, it should be stored in memory. 4681 Otherwise, the fact that those components are volatile 4682 will be ignored, and would even crash the compiler. */ 4683 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))) 4684 c_mark_addressable (decl); 4685 4686 decl_attributes (&decl, returned_attrs, 0); 4687 4688 return decl; 4689 } 4690} 4691 4692/* Decode the parameter-list info for a function type or function definition. 4693 The argument is the value returned by `get_parm_info' (or made in parse.y 4694 if there is an identifier list instead of a parameter decl list). 4695 These two functions are separate because when a function returns 4696 or receives functions then each is called multiple times but the order 4697 of calls is different. The last call to `grokparms' is always the one 4698 that contains the formal parameter names of a function definition. 4699 4700 Store in `last_function_parms' a chain of the decls of parms. 4701 Also store in `last_function_parm_tags' a chain of the struct, union, 4702 and enum tags declared among the parms. 4703 4704 Return a list of arg types to use in the FUNCTION_TYPE for this function. 4705 4706 FUNCDEF_FLAG is nonzero for a function definition, 0 for 4707 a mere declaration. A nonempty identifier-list gets an error message 4708 when FUNCDEF_FLAG is zero. */ 4709 4710static tree 4711grokparms (parms_info, funcdef_flag) 4712 tree parms_info; 4713 int funcdef_flag; 4714{ 4715 tree first_parm = TREE_CHAIN (parms_info); 4716 4717 last_function_parms = TREE_PURPOSE (parms_info); 4718 last_function_parm_tags = TREE_VALUE (parms_info); 4719 4720 if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag 4721 && !in_system_header) 4722 warning ("function declaration isn't a prototype"); 4723 4724 if (first_parm != 0 4725 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) 4726 { 4727 if (! funcdef_flag) 4728 pedwarn ("parameter names (without types) in function declaration"); 4729 4730 last_function_parms = first_parm; 4731 return 0; 4732 } 4733 else 4734 { 4735 tree parm; 4736 tree typelt; 4737 /* We no longer test FUNCDEF_FLAG. 4738 If the arg types are incomplete in a declaration, 4739 they must include undefined tags. 4740 These tags can never be defined in the scope of the declaration, 4741 so the types can never be completed, 4742 and no call can be compiled successfully. */ 4743#if 0 4744 /* In a fcn definition, arg types must be complete. */ 4745 if (funcdef_flag) 4746#endif 4747 for (parm = last_function_parms, typelt = first_parm; 4748 parm; 4749 parm = TREE_CHAIN (parm)) 4750 /* Skip over any enumeration constants declared here. */ 4751 if (TREE_CODE (parm) == PARM_DECL) 4752 { 4753 /* Barf if the parameter itself has an incomplete type. */ 4754 tree type = TREE_VALUE (typelt); 4755 if (type == error_mark_node) 4756 continue; 4757 if (!COMPLETE_TYPE_P (type)) 4758 { 4759 if (funcdef_flag && DECL_NAME (parm) != 0) 4760 error ("parameter `%s' has incomplete type", 4761 IDENTIFIER_POINTER (DECL_NAME (parm))); 4762 else 4763 warning ("parameter has incomplete type"); 4764 if (funcdef_flag) 4765 { 4766 TREE_VALUE (typelt) = error_mark_node; 4767 TREE_TYPE (parm) = error_mark_node; 4768 } 4769 } 4770#if 0 4771 /* This has been replaced by parm_tags_warning, which 4772 uses a more accurate criterion for what to warn 4773 about. */ 4774 else 4775 { 4776 /* Now warn if is a pointer to an incomplete type. */ 4777 while (TREE_CODE (type) == POINTER_TYPE 4778 || TREE_CODE (type) == REFERENCE_TYPE) 4779 type = TREE_TYPE (type); 4780 type = TYPE_MAIN_VARIANT (type); 4781 if (!COMPLETE_TYPE_P (type)) 4782 { 4783 if (DECL_NAME (parm) != 0) 4784 warning ("parameter `%s' points to incomplete type", 4785 IDENTIFIER_POINTER (DECL_NAME (parm))); 4786 else 4787 warning ("parameter points to incomplete type"); 4788 } 4789 } 4790#endif 4791 typelt = TREE_CHAIN (typelt); 4792 } 4793 4794 return first_parm; 4795 } 4796} 4797 4798/* Return a tree_list node with info on a parameter list just parsed. 4799 The TREE_PURPOSE is a chain of decls of those parms. 4800 The TREE_VALUE is a list of structure, union and enum tags defined. 4801 The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE. 4802 This tree_list node is later fed to `grokparms'. 4803 4804 VOID_AT_END nonzero means append `void' to the end of the type-list. 4805 Zero means the parmlist ended with an ellipsis so don't append `void'. */ 4806 4807tree 4808get_parm_info (void_at_end) 4809 int void_at_end; 4810{ 4811 tree decl, t; 4812 tree types = 0; 4813 int erred = 0; 4814 tree tags = gettags (); 4815 tree parms = getdecls (); 4816 tree new_parms = 0; 4817 tree order = current_binding_level->parm_order; 4818 4819 /* Just `void' (and no ellipsis) is special. There are really no parms. 4820 But if the `void' is qualified (by `const' or `volatile') or has a 4821 storage class specifier (`register'), then the behavior is undefined; 4822 by not counting it as the special case of `void' we will cause an 4823 error later. Typedefs for `void' are OK (see DR#157). */ 4824 if (void_at_end && parms != 0 4825 && TREE_CHAIN (parms) == 0 4826 && VOID_TYPE_P (TREE_TYPE (parms)) 4827 && ! TREE_THIS_VOLATILE (parms) 4828 && ! TREE_READONLY (parms) 4829 && ! DECL_REGISTER (parms) 4830 && DECL_NAME (parms) == 0) 4831 { 4832 parms = NULL_TREE; 4833 storedecls (NULL_TREE); 4834 return tree_cons (NULL_TREE, NULL_TREE, 4835 tree_cons (NULL_TREE, void_type_node, NULL_TREE)); 4836 } 4837 4838 /* Extract enumerator values and other non-parms declared with the parms. 4839 Likewise any forward parm decls that didn't have real parm decls. */ 4840 for (decl = parms; decl;) 4841 { 4842 tree next = TREE_CHAIN (decl); 4843 4844 if (TREE_CODE (decl) != PARM_DECL) 4845 { 4846 TREE_CHAIN (decl) = new_parms; 4847 new_parms = decl; 4848 } 4849 else if (TREE_ASM_WRITTEN (decl)) 4850 { 4851 error_with_decl (decl, 4852 "parameter `%s' has just a forward declaration"); 4853 TREE_CHAIN (decl) = new_parms; 4854 new_parms = decl; 4855 } 4856 decl = next; 4857 } 4858 4859 /* Put the parm decls back in the order they were in in the parm list. */ 4860 for (t = order; t; t = TREE_CHAIN (t)) 4861 { 4862 if (TREE_CHAIN (t)) 4863 TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t)); 4864 else 4865 TREE_CHAIN (TREE_VALUE (t)) = 0; 4866 } 4867 4868 new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0, 4869 new_parms); 4870 4871 /* Store the parmlist in the binding level since the old one 4872 is no longer a valid list. (We have changed the chain pointers.) */ 4873 storedecls (new_parms); 4874 4875 for (decl = new_parms; decl; decl = TREE_CHAIN (decl)) 4876 /* There may also be declarations for enumerators if an enumeration 4877 type is declared among the parms. Ignore them here. */ 4878 if (TREE_CODE (decl) == PARM_DECL) 4879 { 4880 /* Since there is a prototype, 4881 args are passed in their declared types. */ 4882 tree type = TREE_TYPE (decl); 4883 DECL_ARG_TYPE (decl) = type; 4884 if (PROMOTE_PROTOTYPES 4885 && INTEGRAL_TYPE_P (type) 4886 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 4887 DECL_ARG_TYPE (decl) = integer_type_node; 4888 4889 types = tree_cons (NULL_TREE, TREE_TYPE (decl), types); 4890 if (VOID_TYPE_P (TREE_VALUE (types)) && ! erred 4891 && DECL_NAME (decl) == 0) 4892 { 4893 error ("`void' in parameter list must be the entire list"); 4894 erred = 1; 4895 } 4896 } 4897 4898 if (void_at_end) 4899 return tree_cons (new_parms, tags, 4900 nreverse (tree_cons (NULL_TREE, void_type_node, types))); 4901 4902 return tree_cons (new_parms, tags, nreverse (types)); 4903} 4904 4905/* At end of parameter list, warn about any struct, union or enum tags 4906 defined within. Do so because these types cannot ever become complete. */ 4907 4908void 4909parmlist_tags_warning () 4910{ 4911 tree elt; 4912 static int already; 4913 4914 for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt)) 4915 { 4916 enum tree_code code = TREE_CODE (TREE_VALUE (elt)); 4917 /* An anonymous union parm type is meaningful as a GNU extension. 4918 So don't warn for that. */ 4919 if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic) 4920 continue; 4921 if (TREE_PURPOSE (elt) != 0) 4922 { 4923 if (code == RECORD_TYPE) 4924 warning ("`struct %s' declared inside parameter list", 4925 IDENTIFIER_POINTER (TREE_PURPOSE (elt))); 4926 else if (code == UNION_TYPE) 4927 warning ("`union %s' declared inside parameter list", 4928 IDENTIFIER_POINTER (TREE_PURPOSE (elt))); 4929 else 4930 warning ("`enum %s' declared inside parameter list", 4931 IDENTIFIER_POINTER (TREE_PURPOSE (elt))); 4932 } 4933 else 4934 { 4935 /* For translation these need to be separate warnings */ 4936 if (code == RECORD_TYPE) 4937 warning ("anonymous struct declared inside parameter list"); 4938 else if (code == UNION_TYPE) 4939 warning ("anonymous union declared inside parameter list"); 4940 else 4941 warning ("anonymous enum declared inside parameter list"); 4942 } 4943 if (! already) 4944 { 4945 warning ("its scope is only this definition or declaration, which is probably not what you want"); 4946 already = 1; 4947 } 4948 } 4949} 4950 4951/* Get the struct, enum or union (CODE says which) with tag NAME. 4952 Define the tag as a forward-reference if it is not defined. */ 4953 4954tree 4955xref_tag (code, name) 4956 enum tree_code code; 4957 tree name; 4958{ 4959 /* If a cross reference is requested, look up the type 4960 already defined for this tag and return it. */ 4961 4962 tree ref = lookup_tag (code, name, current_binding_level, 0); 4963 /* If this is the right type of tag, return what we found. 4964 (This reference will be shadowed by shadow_tag later if appropriate.) 4965 If this is the wrong type of tag, do not return it. If it was the 4966 wrong type in the same binding level, we will have had an error 4967 message already; if in a different binding level and declaring 4968 a name, pending_xref_error will give an error message; but if in a 4969 different binding level and not declaring a name, this tag should 4970 shadow the previous declaration of a different type of tag, and 4971 this would not work properly if we return the reference found. 4972 (For example, with "struct foo" in an outer scope, "union foo;" 4973 must shadow that tag with a new one of union type.) */ 4974 if (ref && TREE_CODE (ref) == code) 4975 return ref; 4976 4977 /* If no such tag is yet defined, create a forward-reference node 4978 and record it as the "definition". 4979 When a real declaration of this type is found, 4980 the forward-reference will be altered into a real type. */ 4981 4982 ref = make_node (code); 4983 if (code == ENUMERAL_TYPE) 4984 { 4985 /* Give the type a default layout like unsigned int 4986 to avoid crashing if it does not get defined. */ 4987 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); 4988 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); 4989 TYPE_USER_ALIGN (ref) = 0; 4990 TREE_UNSIGNED (ref) = 1; 4991 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); 4992 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); 4993 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); 4994 } 4995 4996 pushtag (name, ref); 4997 4998 return ref; 4999} 5000 5001/* Make sure that the tag NAME is defined *in the current binding level* 5002 at least as a forward reference. 5003 CODE says which kind of tag NAME ought to be. */ 5004 5005tree 5006start_struct (code, name) 5007 enum tree_code code; 5008 tree name; 5009{ 5010 /* If there is already a tag defined at this binding level 5011 (as a forward reference), just return it. */ 5012 5013 tree ref = 0; 5014 5015 if (name != 0) 5016 ref = lookup_tag (code, name, current_binding_level, 1); 5017 if (ref && TREE_CODE (ref) == code) 5018 { 5019 if (TYPE_FIELDS (ref)) 5020 { 5021 if (code == UNION_TYPE) 5022 error ("redefinition of `union %s'", IDENTIFIER_POINTER (name)); 5023 else 5024 error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name)); 5025 } 5026 } 5027 else 5028 { 5029 /* Otherwise create a forward-reference just so the tag is in scope. */ 5030 5031 ref = make_node (code); 5032 pushtag (name, ref); 5033 } 5034 5035 C_TYPE_BEING_DEFINED (ref) = 1; 5036 TYPE_PACKED (ref) = flag_pack_struct; 5037 return ref; 5038} 5039 5040/* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) 5041 of a structure component, returning a FIELD_DECL node. 5042 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. 5043 5044 This is done during the parsing of the struct declaration. 5045 The FIELD_DECL nodes are chained together and the lot of them 5046 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */ 5047 5048tree 5049grokfield (filename, line, declarator, declspecs, width) 5050 const char *filename ATTRIBUTE_UNUSED; 5051 int line ATTRIBUTE_UNUSED; 5052 tree declarator, declspecs, width; 5053{ 5054 tree value; 5055 5056 if (declarator == NULL_TREE && width == NULL_TREE) 5057 { 5058 /* This is an unnamed decl. 5059 5060 If we have something of the form "union { list } ;" then this 5061 is the anonymous union extension. Similarly for struct. 5062 5063 If this is something of the form "struct foo;", then 5064 If MS extensions are enabled, this is handled as an 5065 anonymous struct. 5066 Otherwise this is a forward declaration of a structure tag. 5067 5068 If this is something of the form "foo;" and foo is a TYPE_DECL, then 5069 If MS extensions are enabled and foo names a structure, then 5070 again this is an anonymous struct. 5071 Otherwise this is an error. 5072 5073 Oh what a horrid tangled web we weave. I wonder if MS consiously 5074 took this from Plan 9 or if it was an accident of implementation 5075 that took root before someone noticed the bug... */ 5076 5077 tree type = TREE_VALUE (declspecs); 5078 5079 if (flag_ms_extensions && TREE_CODE (type) == TYPE_DECL) 5080 type = TREE_TYPE (type); 5081 if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE) 5082 { 5083 if (flag_ms_extensions) 5084 ; /* ok */ 5085 else if (flag_iso) 5086 goto warn_unnamed_field; 5087 else if (TYPE_NAME (type) == NULL) 5088 ; /* ok */ 5089 else 5090 goto warn_unnamed_field; 5091 } 5092 else 5093 { 5094 warn_unnamed_field: 5095 warning ("declaration does not declare anything"); 5096 return NULL_TREE; 5097 } 5098 } 5099 5100 value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0); 5101 5102 finish_decl (value, NULL_TREE, NULL_TREE); 5103 DECL_INITIAL (value) = width; 5104 5105 if (flag_objc) 5106 objc_check_decl (value); 5107 return value; 5108} 5109 5110/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. 5111 FIELDLIST is a chain of FIELD_DECL nodes for the fields. 5112 ATTRIBUTES are attributes to be applied to the structure. */ 5113 5114tree 5115finish_struct (t, fieldlist, attributes) 5116 tree t; 5117 tree fieldlist; 5118 tree attributes; 5119{ 5120 tree x; 5121 int toplevel = global_binding_level == current_binding_level; 5122 int saw_named_field; 5123 5124 /* If this type was previously laid out as a forward reference, 5125 make sure we lay it out again. */ 5126 5127 TYPE_SIZE (t) = 0; 5128 5129 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); 5130 5131 /* Nameless union parm types are useful as GCC extension. */ 5132 if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic) 5133 /* Otherwise, warn about any struct or union def. in parmlist. */ 5134 if (in_parm_level_p ()) 5135 { 5136 if (pedantic) 5137 pedwarn ("%s defined inside parms", 5138 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure")); 5139 else 5140 warning ("%s defined inside parms", 5141 TREE_CODE (t) == UNION_TYPE ? _("union") : _("structure")); 5142 } 5143 5144 if (pedantic) 5145 { 5146 for (x = fieldlist; x; x = TREE_CHAIN (x)) 5147 if (DECL_NAME (x) != 0) 5148 break; 5149 5150 if (x == 0) 5151 pedwarn ("%s has no %s", 5152 TREE_CODE (t) == UNION_TYPE ? _("union") : _("struct"), 5153 fieldlist ? _("named members") : _("members")); 5154 } 5155 5156 /* Install struct as DECL_CONTEXT of each field decl. 5157 Also process specified field sizes,m which is found in the DECL_INITIAL. 5158 Store 0 there, except for ": 0" fields (so we can find them 5159 and delete them, below). */ 5160 5161 saw_named_field = 0; 5162 for (x = fieldlist; x; x = TREE_CHAIN (x)) 5163 { 5164 DECL_CONTEXT (x) = t; 5165 DECL_PACKED (x) |= TYPE_PACKED (t); 5166 5167 /* If any field is const, the structure type is pseudo-const. */ 5168 if (TREE_READONLY (x)) 5169 C_TYPE_FIELDS_READONLY (t) = 1; 5170 else 5171 { 5172 /* A field that is pseudo-const makes the structure likewise. */ 5173 tree t1 = TREE_TYPE (x); 5174 while (TREE_CODE (t1) == ARRAY_TYPE) 5175 t1 = TREE_TYPE (t1); 5176 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) 5177 && C_TYPE_FIELDS_READONLY (t1)) 5178 C_TYPE_FIELDS_READONLY (t) = 1; 5179 } 5180 5181 /* Any field that is volatile means variables of this type must be 5182 treated in some ways as volatile. */ 5183 if (TREE_THIS_VOLATILE (x)) 5184 C_TYPE_FIELDS_VOLATILE (t) = 1; 5185 5186 /* Any field of nominal variable size implies structure is too. */ 5187 if (C_DECL_VARIABLE_SIZE (x)) 5188 C_TYPE_VARIABLE_SIZE (t) = 1; 5189 5190 /* Detect invalid nested redefinition. */ 5191 if (TREE_TYPE (x) == t) 5192 error ("nested redefinition of `%s'", 5193 IDENTIFIER_POINTER (TYPE_NAME (t))); 5194 5195 /* Detect invalid bit-field size. */ 5196 if (DECL_INITIAL (x)) 5197 STRIP_NOPS (DECL_INITIAL (x)); 5198 if (DECL_INITIAL (x)) 5199 { 5200 if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST) 5201 constant_expression_warning (DECL_INITIAL (x)); 5202 else 5203 { 5204 error_with_decl (x, 5205 "bit-field `%s' width not an integer constant"); 5206 DECL_INITIAL (x) = NULL; 5207 } 5208 } 5209 5210 /* Detect invalid bit-field type. */ 5211 if (DECL_INITIAL (x) 5212 && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE 5213 && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE 5214 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) 5215 { 5216 error_with_decl (x, "bit-field `%s' has invalid type"); 5217 DECL_INITIAL (x) = NULL; 5218 } 5219 5220 if (DECL_INITIAL (x) && pedantic 5221 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node 5222 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node 5223 && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node 5224 /* Accept an enum that's equivalent to int or unsigned int. */ 5225 && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE 5226 && (TYPE_PRECISION (TREE_TYPE (x)) 5227 == TYPE_PRECISION (integer_type_node)))) 5228 pedwarn_with_decl (x, "bit-field `%s' type invalid in ISO C"); 5229 5230 /* Detect and ignore out of range field width and process valid 5231 field widths. */ 5232 if (DECL_INITIAL (x)) 5233 { 5234 int max_width 5235 = (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node 5236 ? CHAR_TYPE_SIZE : TYPE_PRECISION (TREE_TYPE (x))); 5237 5238 if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0) 5239 error_with_decl (x, "negative width in bit-field `%s'"); 5240 else if (0 < compare_tree_int (DECL_INITIAL (x), max_width)) 5241 pedwarn_with_decl (x, "width of `%s' exceeds its type"); 5242 else if (integer_zerop (DECL_INITIAL (x)) && DECL_NAME (x) != 0) 5243 error_with_decl (x, "zero width for bit-field `%s'"); 5244 else 5245 { 5246 /* The test above has assured us that TREE_INT_CST_HIGH is 0. */ 5247 unsigned HOST_WIDE_INT width 5248 = tree_low_cst (DECL_INITIAL (x), 1); 5249 5250 if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE 5251 && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)), 5252 TREE_UNSIGNED (TREE_TYPE (x))) 5253 || (width 5254 < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)), 5255 TREE_UNSIGNED (TREE_TYPE (x)))))) 5256 warning_with_decl (x, 5257 "`%s' is narrower than values of its type"); 5258 5259 DECL_SIZE (x) = bitsize_int (width); 5260 DECL_BIT_FIELD (x) = 1; 5261 SET_DECL_C_BIT_FIELD (x); 5262 5263 if (width == 0 5264 && ! (* targetm.ms_bitfield_layout_p) (t)) 5265 { 5266 /* field size 0 => force desired amount of alignment. */ 5267#ifdef EMPTY_FIELD_BOUNDARY 5268 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY); 5269#endif 5270#ifdef PCC_BITFIELD_TYPE_MATTERS 5271 if (PCC_BITFIELD_TYPE_MATTERS) 5272 { 5273 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), 5274 TYPE_ALIGN (TREE_TYPE (x))); 5275 DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x)); 5276 } 5277#endif 5278 } 5279 } 5280 } 5281 5282 DECL_INITIAL (x) = 0; 5283 5284 /* Detect flexible array member in an invalid context. */ 5285 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 5286 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 5287 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE 5288 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) 5289 { 5290 if (TREE_CODE (t) == UNION_TYPE) 5291 error_with_decl (x, "flexible array member in union"); 5292 else if (TREE_CHAIN (x) != NULL_TREE) 5293 error_with_decl (x, "flexible array member not at end of struct"); 5294 else if (! saw_named_field) 5295 error_with_decl (x, "flexible array member in otherwise empty struct"); 5296 } 5297 5298 if (pedantic && TREE_CODE (t) == RECORD_TYPE 5299 && flexible_array_type_p (TREE_TYPE (x))) 5300 pedwarn_with_decl (x, "invalid use of structure with flexible array member"); 5301 5302 if (DECL_NAME (x)) 5303 saw_named_field = 1; 5304 } 5305 5306 /* Delete all duplicate fields from the fieldlist */ 5307 for (x = fieldlist; x && TREE_CHAIN (x);) 5308 /* Anonymous fields aren't duplicates. */ 5309 if (DECL_NAME (TREE_CHAIN (x)) == 0) 5310 x = TREE_CHAIN (x); 5311 else 5312 { 5313 tree y = fieldlist; 5314 5315 while (1) 5316 { 5317 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) 5318 break; 5319 if (y == x) 5320 break; 5321 y = TREE_CHAIN (y); 5322 } 5323 if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) 5324 { 5325 error_with_decl (TREE_CHAIN (x), "duplicate member `%s'"); 5326 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); 5327 } 5328 else 5329 x = TREE_CHAIN (x); 5330 } 5331 5332 /* Now we have the nearly final fieldlist. Record it, 5333 then lay out the structure or union (including the fields). */ 5334 5335 TYPE_FIELDS (t) = fieldlist; 5336 5337 layout_type (t); 5338 5339 /* Delete all zero-width bit-fields from the fieldlist */ 5340 { 5341 tree *fieldlistp = &fieldlist; 5342 while (*fieldlistp) 5343 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)) 5344 *fieldlistp = TREE_CHAIN (*fieldlistp); 5345 else 5346 fieldlistp = &TREE_CHAIN (*fieldlistp); 5347 } 5348 5349 /* Now we have the truly final field list. 5350 Store it in this type and in the variants. */ 5351 5352 TYPE_FIELDS (t) = fieldlist; 5353 5354 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) 5355 { 5356 TYPE_FIELDS (x) = TYPE_FIELDS (t); 5357 TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t); 5358 TYPE_ALIGN (x) = TYPE_ALIGN (t); 5359 TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t); 5360 } 5361 5362 /* If this was supposed to be a transparent union, but we can't 5363 make it one, warn and turn off the flag. */ 5364 if (TREE_CODE (t) == UNION_TYPE 5365 && TYPE_TRANSPARENT_UNION (t) 5366 && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))) 5367 { 5368 TYPE_TRANSPARENT_UNION (t) = 0; 5369 warning ("union cannot be made transparent"); 5370 } 5371 5372 /* If this structure or union completes the type of any previous 5373 variable declaration, lay it out and output its rtl. */ 5374 5375 if (current_binding_level->incomplete_list != NULL_TREE) 5376 { 5377 tree prev = NULL_TREE; 5378 5379 for (x = current_binding_level->incomplete_list; x; x = TREE_CHAIN (x)) 5380 { 5381 tree decl = TREE_VALUE (x); 5382 5383 if (TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TYPE_MAIN_VARIANT (t) 5384 && TREE_CODE (decl) != TYPE_DECL) 5385 { 5386 layout_decl (decl, 0); 5387 /* This is a no-op in c-lang.c or something real in objc-act.c. */ 5388 if (flag_objc) 5389 objc_check_decl (decl); 5390 rest_of_decl_compilation (decl, NULL, toplevel, 0); 5391 if (! toplevel) 5392 expand_decl (decl); 5393 /* Unlink X from the incomplete list. */ 5394 if (prev) 5395 TREE_CHAIN (prev) = TREE_CHAIN (x); 5396 else 5397 current_binding_level->incomplete_list = TREE_CHAIN (x); 5398 } 5399 else if (!COMPLETE_TYPE_P (TREE_TYPE (decl)) 5400 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) 5401 { 5402 tree element = TREE_TYPE (decl); 5403 while (TREE_CODE (element) == ARRAY_TYPE) 5404 element = TREE_TYPE (element); 5405 if (element == t) 5406 { 5407 layout_array_type (TREE_TYPE (decl)); 5408 if (TREE_CODE (decl) != TYPE_DECL) 5409 { 5410 layout_decl (decl, 0); 5411 if (flag_objc) 5412 objc_check_decl (decl); 5413 rest_of_decl_compilation (decl, NULL, toplevel, 0); 5414 if (! toplevel) 5415 expand_decl (decl); 5416 } 5417 /* Unlink X from the incomplete list. */ 5418 if (prev) 5419 TREE_CHAIN (prev) = TREE_CHAIN (x); 5420 else 5421 current_binding_level->incomplete_list = TREE_CHAIN (x); 5422 } 5423 } 5424 } 5425 } 5426 5427 /* Finish debugging output for this type. */ 5428 rest_of_type_compilation (t, toplevel); 5429 5430 return t; 5431} 5432 5433/* Lay out the type T, and its element type, and so on. */ 5434 5435static void 5436layout_array_type (t) 5437 tree t; 5438{ 5439 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) 5440 layout_array_type (TREE_TYPE (t)); 5441 layout_type (t); 5442} 5443 5444/* Begin compiling the definition of an enumeration type. 5445 NAME is its name (or null if anonymous). 5446 Returns the type object, as yet incomplete. 5447 Also records info about it so that build_enumerator 5448 may be used to declare the individual values as they are read. */ 5449 5450tree 5451start_enum (name) 5452 tree name; 5453{ 5454 tree enumtype = 0; 5455 5456 /* If this is the real definition for a previous forward reference, 5457 fill in the contents in the same object that used to be the 5458 forward reference. */ 5459 5460 if (name != 0) 5461 enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1); 5462 5463 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) 5464 { 5465 enumtype = make_node (ENUMERAL_TYPE); 5466 pushtag (name, enumtype); 5467 } 5468 5469 C_TYPE_BEING_DEFINED (enumtype) = 1; 5470 5471 if (TYPE_VALUES (enumtype) != 0) 5472 { 5473 /* This enum is a named one that has been declared already. */ 5474 error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name)); 5475 5476 /* Completely replace its old definition. 5477 The old enumerators remain defined, however. */ 5478 TYPE_VALUES (enumtype) = 0; 5479 } 5480 5481 enum_next_value = integer_zero_node; 5482 enum_overflow = 0; 5483 5484 if (flag_short_enums) 5485 TYPE_PACKED (enumtype) = 1; 5486 5487 return enumtype; 5488} 5489 5490/* After processing and defining all the values of an enumeration type, 5491 install their decls in the enumeration type and finish it off. 5492 ENUMTYPE is the type object, VALUES a list of decl-value pairs, 5493 and ATTRIBUTES are the specified attributes. 5494 Returns ENUMTYPE. */ 5495 5496tree 5497finish_enum (enumtype, values, attributes) 5498 tree enumtype; 5499 tree values; 5500 tree attributes; 5501{ 5502 tree pair, tem; 5503 tree minnode = 0, maxnode = 0, enum_value_type; 5504 int precision, unsign; 5505 int toplevel = (global_binding_level == current_binding_level); 5506 5507 if (in_parm_level_p ()) 5508 warning ("enum defined inside parms"); 5509 5510 decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); 5511 5512 /* Calculate the maximum value of any enumerator in this type. */ 5513 5514 if (values == error_mark_node) 5515 minnode = maxnode = integer_zero_node; 5516 else 5517 { 5518 minnode = maxnode = TREE_VALUE (values); 5519 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) 5520 { 5521 tree value = TREE_VALUE (pair); 5522 if (tree_int_cst_lt (maxnode, value)) 5523 maxnode = value; 5524 if (tree_int_cst_lt (value, minnode)) 5525 minnode = value; 5526 } 5527 } 5528 5529 /* Construct the final type of this enumeration. It is the same 5530 as one of the integral types - the narrowest one that fits, except 5531 that normally we only go as narrow as int - and signed iff any of 5532 the values are negative. */ 5533 unsign = (tree_int_cst_sgn (minnode) >= 0); 5534 precision = MAX (min_precision (minnode, unsign), 5535 min_precision (maxnode, unsign)); 5536 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node)) 5537 { 5538 tree narrowest = c_common_type_for_size (precision, unsign); 5539 if (narrowest == 0) 5540 { 5541 warning ("enumeration values exceed range of largest integer"); 5542 narrowest = long_long_integer_type_node; 5543 } 5544 5545 precision = TYPE_PRECISION (narrowest); 5546 } 5547 else 5548 precision = TYPE_PRECISION (integer_type_node); 5549 5550 if (precision == TYPE_PRECISION (integer_type_node)) 5551 enum_value_type = c_common_type_for_size (precision, 0); 5552 else 5553 enum_value_type = enumtype; 5554 5555 TYPE_MIN_VALUE (enumtype) = minnode; 5556 TYPE_MAX_VALUE (enumtype) = maxnode; 5557 TYPE_PRECISION (enumtype) = precision; 5558 TREE_UNSIGNED (enumtype) = unsign; 5559 TYPE_SIZE (enumtype) = 0; 5560 layout_type (enumtype); 5561 5562 if (values != error_mark_node) 5563 { 5564 /* Change the type of the enumerators to be the enum type. We 5565 need to do this irrespective of the size of the enum, for 5566 proper type checking. Replace the DECL_INITIALs of the 5567 enumerators, and the value slots of the list, with copies 5568 that have the enum type; they cannot be modified in place 5569 because they may be shared (e.g. integer_zero_node) Finally, 5570 change the purpose slots to point to the names of the decls. */ 5571 for (pair = values; pair; pair = TREE_CHAIN (pair)) 5572 { 5573 tree enu = TREE_PURPOSE (pair); 5574 5575 TREE_TYPE (enu) = enumtype; 5576 DECL_SIZE (enu) = TYPE_SIZE (enumtype); 5577 DECL_SIZE_UNIT (enu) = TYPE_SIZE_UNIT (enumtype); 5578 DECL_ALIGN (enu) = TYPE_ALIGN (enumtype); 5579 DECL_USER_ALIGN (enu) = TYPE_USER_ALIGN (enumtype); 5580 DECL_MODE (enu) = TYPE_MODE (enumtype); 5581 5582 /* The ISO C Standard mandates enumerators to have type int, 5583 even though the underlying type of an enum type is 5584 unspecified. Here we convert any enumerators that fit in 5585 an int to type int, to avoid promotions to unsigned types 5586 when comparing integers with enumerators that fit in the 5587 int range. When -pedantic is given, build_enumerator() 5588 would have already taken care of those that don't fit. */ 5589 if (int_fits_type_p (DECL_INITIAL (enu), enum_value_type)) 5590 DECL_INITIAL (enu) = convert (enum_value_type, DECL_INITIAL (enu)); 5591 else 5592 DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu)); 5593 5594 TREE_PURPOSE (pair) = DECL_NAME (enu); 5595 TREE_VALUE (pair) = DECL_INITIAL (enu); 5596 } 5597 5598 TYPE_VALUES (enumtype) = values; 5599 } 5600 5601 /* Fix up all variant types of this enum type. */ 5602 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) 5603 { 5604 if (tem == enumtype) 5605 continue; 5606 TYPE_VALUES (tem) = TYPE_VALUES (enumtype); 5607 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); 5608 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); 5609 TYPE_SIZE (tem) = TYPE_SIZE (enumtype); 5610 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype); 5611 TYPE_MODE (tem) = TYPE_MODE (enumtype); 5612 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); 5613 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); 5614 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype); 5615 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); 5616 } 5617 5618 /* Finish debugging output for this type. */ 5619 rest_of_type_compilation (enumtype, toplevel); 5620 5621 return enumtype; 5622} 5623 5624/* Build and install a CONST_DECL for one value of the 5625 current enumeration type (one that was begun with start_enum). 5626 Return a tree-list containing the CONST_DECL and its value. 5627 Assignment of sequential values by default is handled here. */ 5628 5629tree 5630build_enumerator (name, value) 5631 tree name, value; 5632{ 5633 tree decl, type; 5634 5635 /* Validate and default VALUE. */ 5636 5637 /* Remove no-op casts from the value. */ 5638 if (value) 5639 STRIP_TYPE_NOPS (value); 5640 5641 if (value != 0) 5642 { 5643 if (TREE_CODE (value) == INTEGER_CST) 5644 { 5645 value = default_conversion (value); 5646 constant_expression_warning (value); 5647 } 5648 else 5649 { 5650 error ("enumerator value for `%s' not integer constant", 5651 IDENTIFIER_POINTER (name)); 5652 value = 0; 5653 } 5654 } 5655 5656 /* Default based on previous value. */ 5657 /* It should no longer be possible to have NON_LVALUE_EXPR 5658 in the default. */ 5659 if (value == 0) 5660 { 5661 value = enum_next_value; 5662 if (enum_overflow) 5663 error ("overflow in enumeration values"); 5664 } 5665 5666 if (pedantic && ! int_fits_type_p (value, integer_type_node)) 5667 { 5668 pedwarn ("ISO C restricts enumerator values to range of `int'"); 5669 value = convert (integer_type_node, value); 5670 } 5671 5672 /* Set basis for default for next value. */ 5673 enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0); 5674 enum_overflow = tree_int_cst_lt (enum_next_value, value); 5675 5676 /* Now create a declaration for the enum value name. */ 5677 5678 type = TREE_TYPE (value); 5679 type = c_common_type_for_size (MAX (TYPE_PRECISION (type), 5680 TYPE_PRECISION (integer_type_node)), 5681 (TYPE_PRECISION (type) 5682 >= TYPE_PRECISION (integer_type_node) 5683 && TREE_UNSIGNED (type))); 5684 5685 decl = build_decl (CONST_DECL, name, type); 5686 DECL_INITIAL (decl) = convert (type, value); 5687 pushdecl (decl); 5688 5689 return tree_cons (decl, value, NULL_TREE); 5690} 5691 5692 5693/* Create the FUNCTION_DECL for a function definition. 5694 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of 5695 the declaration; they describe the function's name and the type it returns, 5696 but twisted together in a fashion that parallels the syntax of C. 5697 5698 This function creates a binding context for the function body 5699 as well as setting up the FUNCTION_DECL in current_function_decl. 5700 5701 Returns 1 on success. If the DECLARATOR is not suitable for a function 5702 (it defines a datum instead), we return 0, which tells 5703 yyparse to report a parse error. */ 5704 5705int 5706start_function (declspecs, declarator, attributes) 5707 tree declarator, declspecs, attributes; 5708{ 5709 tree decl1, old_decl; 5710 tree restype; 5711 int old_immediate_size_expand = immediate_size_expand; 5712 5713 current_function_returns_value = 0; /* Assume, until we see it does. */ 5714 current_function_returns_null = 0; 5715 current_function_returns_abnormally = 0; 5716 warn_about_return_type = 0; 5717 current_extern_inline = 0; 5718 named_labels = 0; 5719 shadowed_labels = 0; 5720 5721 /* Don't expand any sizes in the return type of the function. */ 5722 immediate_size_expand = 0; 5723 5724 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1); 5725 5726 /* If the declarator is not suitable for a function definition, 5727 cause a syntax error. */ 5728 if (decl1 == 0) 5729 { 5730 immediate_size_expand = old_immediate_size_expand; 5731 return 0; 5732 } 5733 5734 decl_attributes (&decl1, attributes, 0); 5735 5736 /* If #pragma weak was used, mark the decl weak now. */ 5737 if (current_binding_level == global_binding_level) 5738 maybe_apply_pragma_weak (decl1); 5739 5740 if (DECL_DECLARED_INLINE_P (decl1) 5741 && DECL_UNINLINABLE (decl1) 5742 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1))) 5743 warning_with_decl (decl1, 5744 "inline function `%s' given attribute noinline"); 5745 5746 announce_function (decl1); 5747 5748 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1)))) 5749 { 5750 error ("return type is an incomplete type"); 5751 /* Make it return void instead. */ 5752 TREE_TYPE (decl1) 5753 = build_function_type (void_type_node, 5754 TYPE_ARG_TYPES (TREE_TYPE (decl1))); 5755 } 5756 5757 if (warn_about_return_type) 5758 pedwarn_c99 ("return type defaults to `int'"); 5759 5760 /* Save the parm names or decls from this function's declarator 5761 where store_parm_decls will find them. */ 5762 current_function_parms = last_function_parms; 5763 current_function_parm_tags = last_function_parm_tags; 5764 5765 /* Make the init_value nonzero so pushdecl knows this is not tentative. 5766 error_mark_node is replaced below (in poplevel) with the BLOCK. */ 5767 DECL_INITIAL (decl1) = error_mark_node; 5768 5769 /* If this definition isn't a prototype and we had a prototype declaration 5770 before, copy the arg type info from that prototype. 5771 But not if what we had before was a builtin function. */ 5772 old_decl = lookup_name_current_level (DECL_NAME (decl1)); 5773 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE 5774 && !DECL_BUILT_IN (old_decl) 5775 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) 5776 == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl)))) 5777 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) 5778 { 5779 TREE_TYPE (decl1) = TREE_TYPE (old_decl); 5780 current_function_prototype_file = DECL_SOURCE_FILE (old_decl); 5781 current_function_prototype_line = DECL_SOURCE_LINE (old_decl); 5782 } 5783 5784 /* If there is no explicit declaration, look for any out-of-scope implicit 5785 declarations. */ 5786 if (old_decl == 0) 5787 old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)); 5788 5789 /* Optionally warn of old-fashioned def with no previous prototype. */ 5790 if (warn_strict_prototypes 5791 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 5792 && !(old_decl != 0 5793 && (TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0 5794 || (DECL_BUILT_IN (old_decl) 5795 && ! C_DECL_ANTICIPATED (old_decl)))) 5796 && !(flag_bsd_no_warn_kr_main && 0 == 5797 strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))) 5798 warning ("function declaration isn't a prototype"); 5799 /* Optionally warn of any global def with no previous prototype. */ 5800 else if (warn_missing_prototypes 5801 && TREE_PUBLIC (decl1) 5802 && !(old_decl != 0 5803 && (TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0 5804 || (DECL_BUILT_IN (old_decl) 5805 && ! C_DECL_ANTICIPATED (old_decl)))) 5806 && ! MAIN_NAME_P (DECL_NAME (decl1))) 5807 warning_with_decl (decl1, "no previous prototype for `%s'"); 5808 /* Optionally warn of any def with no previous prototype 5809 if the function has already been used. */ 5810 else if (warn_missing_prototypes 5811 && old_decl != 0 && TREE_USED (old_decl) 5812 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) 5813 warning_with_decl (decl1, 5814 "`%s' was used with no prototype before its definition"); 5815 /* Optionally warn of any global def with no previous declaration. */ 5816 else if (warn_missing_declarations 5817 && TREE_PUBLIC (decl1) 5818 && old_decl == 0 5819 && ! MAIN_NAME_P (DECL_NAME (decl1))) 5820 warning_with_decl (decl1, "no previous declaration for `%s'"); 5821 /* Optionally warn of any def with no previous declaration 5822 if the function has already been used. */ 5823 else if (warn_missing_declarations 5824 && old_decl != 0 && TREE_USED (old_decl) 5825 && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))) 5826 warning_with_decl (decl1, 5827 "`%s' was used with no declaration before its definition"); 5828 5829 /* This is a definition, not a reference. 5830 So normally clear DECL_EXTERNAL. 5831 However, `extern inline' acts like a declaration 5832 except for defining how to inline. So set DECL_EXTERNAL in that case. */ 5833 DECL_EXTERNAL (decl1) = current_extern_inline; 5834 5835 /* This function exists in static storage. 5836 (This does not mean `static' in the C sense!) */ 5837 TREE_STATIC (decl1) = 1; 5838 5839 /* A nested function is not global. */ 5840 if (current_function_decl != 0) 5841 TREE_PUBLIC (decl1) = 0; 5842 5843 /* Warn for unlikely, improbable, or stupid declarations of `main'. */ 5844 if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1))) 5845 { 5846 tree args; 5847 int argct = 0; 5848 5849 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) 5850 != integer_type_node) 5851 pedwarn_with_decl (decl1, "return type of `%s' is not `int'"); 5852 5853 for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args; 5854 args = TREE_CHAIN (args)) 5855 { 5856 tree type = args ? TREE_VALUE (args) : 0; 5857 5858 if (type == void_type_node) 5859 break; 5860 5861 ++argct; 5862 switch (argct) 5863 { 5864 case 1: 5865 if (TYPE_MAIN_VARIANT (type) != integer_type_node) 5866 pedwarn_with_decl (decl1, 5867 "first argument of `%s' should be `int'"); 5868 break; 5869 5870 case 2: 5871 if (TREE_CODE (type) != POINTER_TYPE 5872 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE 5873 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) 5874 != char_type_node)) 5875 pedwarn_with_decl (decl1, 5876 "second argument of `%s' should be `char **'"); 5877 break; 5878 5879 case 3: 5880 if (TREE_CODE (type) != POINTER_TYPE 5881 || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE 5882 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) 5883 != char_type_node)) 5884 pedwarn_with_decl (decl1, 5885 "third argument of `%s' should probably be `char **'"); 5886 break; 5887 } 5888 } 5889 5890 /* It is intentional that this message does not mention the third 5891 argument because it's only mentioned in an appendix of the 5892 standard. */ 5893 if (argct > 0 && (argct < 2 || argct > 3)) 5894 pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments"); 5895 5896 if (! TREE_PUBLIC (decl1)) 5897 pedwarn_with_decl (decl1, "`%s' is normally a non-static function"); 5898 } 5899 5900 /* Record the decl so that the function name is defined. 5901 If we already have a decl for this name, and it is a FUNCTION_DECL, 5902 use the old decl. */ 5903 5904 current_function_decl = pushdecl (decl1); 5905 5906 pushlevel (0); 5907 declare_parm_level (1); 5908 current_binding_level->subblocks_tag_transparent = 1; 5909 5910 make_decl_rtl (current_function_decl, NULL); 5911 5912 restype = TREE_TYPE (TREE_TYPE (current_function_decl)); 5913 /* Promote the value to int before returning it. */ 5914 if (c_promoting_integer_type_p (restype)) 5915 { 5916 /* It retains unsignedness if not really getting wider. */ 5917 if (TREE_UNSIGNED (restype) 5918 && (TYPE_PRECISION (restype) 5919 == TYPE_PRECISION (integer_type_node))) 5920 restype = unsigned_type_node; 5921 else 5922 restype = integer_type_node; 5923 } 5924 DECL_RESULT (current_function_decl) 5925 = build_decl (RESULT_DECL, NULL_TREE, restype); 5926 5927 /* If this fcn was already referenced via a block-scope `extern' decl 5928 (or an implicit decl), propagate certain information about the usage. */ 5929 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl))) 5930 TREE_ADDRESSABLE (current_function_decl) = 1; 5931 5932 immediate_size_expand = old_immediate_size_expand; 5933 5934 start_fname_decls (); 5935 5936 return 1; 5937} 5938 5939/* Store the parameter declarations into the current function declaration. 5940 This is called after parsing the parameter declarations, before 5941 digesting the body of the function. 5942 5943 For an old-style definition, modify the function's type 5944 to specify at least the number of arguments. */ 5945 5946void 5947store_parm_decls () 5948{ 5949 tree fndecl = current_function_decl; 5950 tree parm; 5951 5952 /* This is either a chain of PARM_DECLs (if a prototype was used) 5953 or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */ 5954 tree specparms = current_function_parms; 5955 5956 /* This is a list of types declared among parms in a prototype. */ 5957 tree parmtags = current_function_parm_tags; 5958 5959 /* This is a chain of PARM_DECLs from old-style parm declarations. */ 5960 tree parmdecls = getdecls (); 5961 5962 /* This is a chain of any other decls that came in among the parm 5963 declarations. If a parm is declared with enum {foo, bar} x; 5964 then CONST_DECLs for foo and bar are put here. */ 5965 tree nonparms = 0; 5966 5967 /* The function containing FNDECL, if any. */ 5968 tree context = decl_function_context (fndecl); 5969 5970 /* Nonzero if this definition is written with a prototype. */ 5971 int prototype = 0; 5972 5973 int saved_warn_shadow = warn_shadow; 5974 5975 /* Don't re-emit shadow warnings. */ 5976 warn_shadow = 0; 5977 5978 if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST) 5979 { 5980 /* This case is when the function was defined with an ANSI prototype. 5981 The parms already have decls, so we need not do anything here 5982 except record them as in effect 5983 and complain if any redundant old-style parm decls were written. */ 5984 5985 tree next; 5986 tree others = 0; 5987 5988 prototype = 1; 5989 5990 if (parmdecls != 0) 5991 { 5992 tree decl, link; 5993 5994 error_with_decl (fndecl, 5995 "parm types given both in parmlist and separately"); 5996 /* Get rid of the erroneous decls; don't keep them on 5997 the list of parms, since they might not be PARM_DECLs. */ 5998 for (decl = current_binding_level->names; 5999 decl; decl = TREE_CHAIN (decl)) 6000 if (DECL_NAME (decl)) 6001 IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0; 6002 for (link = current_binding_level->shadowed; 6003 link; link = TREE_CHAIN (link)) 6004 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 6005 current_binding_level->names = 0; 6006 current_binding_level->shadowed = 0; 6007 } 6008 6009 specparms = nreverse (specparms); 6010 for (parm = specparms; parm; parm = next) 6011 { 6012 next = TREE_CHAIN (parm); 6013 if (TREE_CODE (parm) == PARM_DECL) 6014 { 6015 if (DECL_NAME (parm) == 0) 6016 error_with_decl (parm, "parameter name omitted"); 6017 else if (TREE_CODE (TREE_TYPE (parm)) != ERROR_MARK 6018 && VOID_TYPE_P (TREE_TYPE (parm))) 6019 { 6020 error_with_decl (parm, "parameter `%s' declared void"); 6021 /* Change the type to error_mark_node so this parameter 6022 will be ignored by assign_parms. */ 6023 TREE_TYPE (parm) = error_mark_node; 6024 } 6025 pushdecl (parm); 6026 } 6027 else 6028 { 6029 /* If we find an enum constant or a type tag, 6030 put it aside for the moment. */ 6031 TREE_CHAIN (parm) = 0; 6032 others = chainon (others, parm); 6033 } 6034 } 6035 6036 /* Get the decls in their original chain order 6037 and record in the function. */ 6038 DECL_ARGUMENTS (fndecl) = getdecls (); 6039 6040#if 0 6041 /* If this function takes a variable number of arguments, 6042 add a phony parameter to the end of the parm list, 6043 to represent the position of the first unnamed argument. */ 6044 if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))) 6045 != void_type_node) 6046 { 6047 tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node); 6048 /* Let's hope the address of the unnamed parm 6049 won't depend on its type. */ 6050 TREE_TYPE (dummy) = integer_type_node; 6051 DECL_ARG_TYPE (dummy) = integer_type_node; 6052 DECL_ARGUMENTS (fndecl) = chainon (DECL_ARGUMENTS (fndecl), dummy); 6053 } 6054#endif 6055 6056 /* Now pushdecl the enum constants. */ 6057 for (parm = others; parm; parm = next) 6058 { 6059 next = TREE_CHAIN (parm); 6060 if (DECL_NAME (parm) == 0) 6061 ; 6062 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) 6063 ; 6064 else if (TREE_CODE (parm) != PARM_DECL) 6065 pushdecl (parm); 6066 } 6067 6068 storetags (chainon (parmtags, gettags ())); 6069 } 6070 else 6071 { 6072 /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes 6073 each with a parm name as the TREE_VALUE. 6074 6075 PARMDECLS is a chain of declarations for parameters. 6076 Warning! It can also contain CONST_DECLs which are not parameters 6077 but are names of enumerators of any enum types 6078 declared among the parameters. 6079 6080 First match each formal parameter name with its declaration. 6081 Associate decls with the names and store the decls 6082 into the TREE_PURPOSE slots. */ 6083 6084 /* We use DECL_WEAK as a flag to show which parameters have been 6085 seen already since it is not used on PARM_DECL or CONST_DECL. */ 6086 for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) 6087 DECL_WEAK (parm) = 0; 6088 6089 for (parm = specparms; parm; parm = TREE_CHAIN (parm)) 6090 { 6091 tree tail, found = NULL; 6092 6093 if (TREE_VALUE (parm) == 0) 6094 { 6095 error_with_decl (fndecl, 6096 "parameter name missing from parameter list"); 6097 TREE_PURPOSE (parm) = 0; 6098 continue; 6099 } 6100 6101 /* See if any of the parmdecls specifies this parm by name. 6102 Ignore any enumerator decls. */ 6103 for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) 6104 if (DECL_NAME (tail) == TREE_VALUE (parm) 6105 && TREE_CODE (tail) == PARM_DECL) 6106 { 6107 found = tail; 6108 break; 6109 } 6110 6111 /* If declaration already marked, we have a duplicate name. 6112 Complain, and don't use this decl twice. */ 6113 if (found && DECL_WEAK (found)) 6114 { 6115 error_with_decl (found, "multiple parameters named `%s'"); 6116 found = 0; 6117 } 6118 6119 /* If the declaration says "void", complain and ignore it. */ 6120 if (found && VOID_TYPE_P (TREE_TYPE (found))) 6121 { 6122 error_with_decl (found, "parameter `%s' declared void"); 6123 TREE_TYPE (found) = integer_type_node; 6124 DECL_ARG_TYPE (found) = integer_type_node; 6125 layout_decl (found, 0); 6126 } 6127 6128 /* If no declaration found, default to int. */ 6129 if (!found) 6130 { 6131 found = build_decl (PARM_DECL, TREE_VALUE (parm), 6132 integer_type_node); 6133 DECL_ARG_TYPE (found) = TREE_TYPE (found); 6134 DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); 6135 DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); 6136 if (flag_isoc99) 6137 pedwarn_with_decl (found, "type of `%s' defaults to `int'"); 6138 else if (extra_warnings) 6139 warning_with_decl (found, "type of `%s' defaults to `int'"); 6140 pushdecl (found); 6141 } 6142 6143 TREE_PURPOSE (parm) = found; 6144 6145 /* Mark this decl as "already found". */ 6146 DECL_WEAK (found) = 1; 6147 } 6148 6149 /* Put anything which is on the parmdecls chain and which is 6150 not a PARM_DECL onto the list NONPARMS. (The types of 6151 non-parm things which might appear on the list include 6152 enumerators and NULL-named TYPE_DECL nodes.) Complain about 6153 any actual PARM_DECLs not matched with any names. */ 6154 6155 nonparms = 0; 6156 for (parm = parmdecls; parm;) 6157 { 6158 tree next = TREE_CHAIN (parm); 6159 TREE_CHAIN (parm) = 0; 6160 6161 if (TREE_CODE (parm) != PARM_DECL) 6162 nonparms = chainon (nonparms, parm); 6163 else 6164 { 6165 /* Complain about args with incomplete types. */ 6166 if (!COMPLETE_TYPE_P (TREE_TYPE (parm))) 6167 { 6168 error_with_decl (parm, "parameter `%s' has incomplete type"); 6169 TREE_TYPE (parm) = error_mark_node; 6170 } 6171 6172 if (! DECL_WEAK (parm)) 6173 { 6174 error_with_decl (parm, 6175 "declaration for parameter `%s' but no such parameter"); 6176 /* Pretend the parameter was not missing. 6177 This gets us to a standard state and minimizes 6178 further error messages. */ 6179 specparms 6180 = chainon (specparms, 6181 tree_cons (parm, NULL_TREE, NULL_TREE)); 6182 } 6183 } 6184 6185 parm = next; 6186 } 6187 6188 /* Chain the declarations together in the order of the list of 6189 names. Store that chain in the function decl, replacing the 6190 list of names. */ 6191 parm = specparms; 6192 DECL_ARGUMENTS (fndecl) = 0; 6193 { 6194 tree last; 6195 for (last = 0; parm; parm = TREE_CHAIN (parm)) 6196 if (TREE_PURPOSE (parm)) 6197 { 6198 if (last == 0) 6199 DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm); 6200 else 6201 TREE_CHAIN (last) = TREE_PURPOSE (parm); 6202 last = TREE_PURPOSE (parm); 6203 TREE_CHAIN (last) = 0; 6204 } 6205 } 6206 6207 /* If there was a previous prototype, 6208 set the DECL_ARG_TYPE of each argument according to 6209 the type previously specified, and report any mismatches. */ 6210 6211 if (TYPE_ARG_TYPES (TREE_TYPE (fndecl))) 6212 { 6213 tree type; 6214 for (parm = DECL_ARGUMENTS (fndecl), 6215 type = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); 6216 parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) 6217 != void_type_node)); 6218 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) 6219 { 6220 if (parm == 0 || type == 0 6221 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) 6222 { 6223 error ("number of arguments doesn't match prototype"); 6224 error_with_file_and_line (current_function_prototype_file, 6225 current_function_prototype_line, 6226 "prototype declaration"); 6227 break; 6228 } 6229 /* Type for passing arg must be consistent with that 6230 declared for the arg. ISO C says we take the unqualified 6231 type for parameters declared with qualified type. */ 6232 if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)), 6233 TYPE_MAIN_VARIANT (TREE_VALUE (type)))) 6234 { 6235 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) 6236 == TYPE_MAIN_VARIANT (TREE_VALUE (type))) 6237 { 6238 /* Adjust argument to match prototype. E.g. a previous 6239 `int foo(float);' prototype causes 6240 `int foo(x) float x; {...}' to be treated like 6241 `int foo(float x) {...}'. This is particularly 6242 useful for argument types like uid_t. */ 6243 DECL_ARG_TYPE (parm) = TREE_TYPE (parm); 6244 6245 if (PROMOTE_PROTOTYPES 6246 && INTEGRAL_TYPE_P (TREE_TYPE (parm)) 6247 && TYPE_PRECISION (TREE_TYPE (parm)) 6248 < TYPE_PRECISION (integer_type_node)) 6249 DECL_ARG_TYPE (parm) = integer_type_node; 6250 6251 if (pedantic) 6252 { 6253 pedwarn ("promoted argument `%s' doesn't match prototype", 6254 IDENTIFIER_POINTER (DECL_NAME (parm))); 6255 warning_with_file_and_line 6256 (current_function_prototype_file, 6257 current_function_prototype_line, 6258 "prototype declaration"); 6259 } 6260 } 6261 else 6262 { 6263 error ("argument `%s' doesn't match prototype", 6264 IDENTIFIER_POINTER (DECL_NAME (parm))); 6265 error_with_file_and_line (current_function_prototype_file, 6266 current_function_prototype_line, 6267 "prototype declaration"); 6268 } 6269 } 6270 } 6271 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; 6272 } 6273 6274 /* Otherwise, create a prototype that would match. */ 6275 6276 else 6277 { 6278 tree actual = 0, last = 0, type; 6279 6280 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) 6281 { 6282 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); 6283 if (last) 6284 TREE_CHAIN (last) = type; 6285 else 6286 actual = type; 6287 last = type; 6288 } 6289 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE); 6290 if (last) 6291 TREE_CHAIN (last) = type; 6292 else 6293 actual = type; 6294 6295 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES 6296 of the type of this function, but we need to avoid having this 6297 affect the types of other similarly-typed functions, so we must 6298 first force the generation of an identical (but separate) type 6299 node for the relevant function type. The new node we create 6300 will be a variant of the main variant of the original function 6301 type. */ 6302 6303 TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl)); 6304 6305 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual; 6306 } 6307 6308 /* Now store the final chain of decls for the arguments 6309 as the decl-chain of the current lexical scope. 6310 Put the enumerators in as well, at the front so that 6311 DECL_ARGUMENTS is not modified. */ 6312 6313 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); 6314 } 6315 6316 /* Make sure the binding level for the top of the function body 6317 gets a BLOCK if there are any in the function. 6318 Otherwise, the dbx output is wrong. */ 6319 6320 keep_next_if_subblocks = 1; 6321 6322 /* ??? This might be an improvement, 6323 but needs to be thought about some more. */ 6324#if 0 6325 keep_next_level_flag = 1; 6326#endif 6327 6328 /* Write a record describing this function definition to the prototypes 6329 file (if requested). */ 6330 6331 gen_aux_info_record (fndecl, 1, 0, prototype); 6332 6333 /* Initialize the RTL code for the function. */ 6334 init_function_start (fndecl, input_filename, lineno); 6335 6336 /* Begin the statement tree for this function. */ 6337 begin_stmt_tree (&DECL_SAVED_TREE (current_function_decl)); 6338 6339 /* If this is a nested function, save away the sizes of any 6340 variable-size types so that we can expand them when generating 6341 RTL. */ 6342 if (context) 6343 { 6344 tree t; 6345 6346 DECL_LANG_SPECIFIC (fndecl)->pending_sizes 6347 = nreverse (get_pending_sizes ()); 6348 for (t = DECL_LANG_SPECIFIC (fndecl)->pending_sizes; 6349 t; 6350 t = TREE_CHAIN (t)) 6351 SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = context; 6352 } 6353 6354 /* This function is being processed in whole-function mode. */ 6355 cfun->x_whole_function_mode_p = 1; 6356 6357 /* Even though we're inside a function body, we still don't want to 6358 call expand_expr to calculate the size of a variable-sized array. 6359 We haven't necessarily assigned RTL to all variables yet, so it's 6360 not safe to try to expand expressions involving them. */ 6361 immediate_size_expand = 0; 6362 cfun->x_dont_save_pending_sizes_p = 1; 6363 6364 warn_shadow = saved_warn_shadow; 6365} 6366 6367/* Finish up a function declaration and compile that function 6368 all the way to assembler language output. The free the storage 6369 for the function definition. 6370 6371 This is called after parsing the body of the function definition. 6372 6373 NESTED is nonzero if the function being finished is nested in another. 6374 CAN_DEFER_P is nonzero if the function may be deferred. */ 6375 6376void 6377finish_function (nested, can_defer_p) 6378 int nested; 6379 int can_defer_p; 6380{ 6381 tree fndecl = current_function_decl; 6382 6383#if 0 6384 /* This caused &foo to be of type ptr-to-const-function which then 6385 got a warning when stored in a ptr-to-function variable. */ 6386 TREE_READONLY (fndecl) = 1; 6387#endif 6388 6389 poplevel (1, 0, 1); 6390 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; 6391 6392 /* Must mark the RESULT_DECL as being in this function. */ 6393 6394 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; 6395 6396 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted) 6397 { 6398 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) 6399 != integer_type_node) 6400 { 6401 /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned. 6402 If warn_main is -1 (-Wno-main) we don't want to be warned. */ 6403 if (! warn_main) 6404 pedwarn_with_decl (fndecl, "return type of `%s' is not `int'"); 6405 } 6406 else 6407 { 6408#ifdef DEFAULT_MAIN_RETURN 6409 /* Make it so that `main' always returns success by default. */ 6410 DEFAULT_MAIN_RETURN; 6411#else 6412 if (flag_isoc99) 6413 c_expand_return (integer_zero_node); 6414#endif 6415 } 6416 } 6417 6418 finish_fname_decls (); 6419 6420 /* Tie off the statement tree for this function. */ 6421 finish_stmt_tree (&DECL_SAVED_TREE (fndecl)); 6422 6423 /* Complain if there's just no return statement. */ 6424 if (warn_return_type 6425 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE 6426 && !current_function_returns_value && !current_function_returns_null 6427 /* Don't complain if we abort. */ 6428 && !current_function_returns_abnormally 6429 /* Don't warn for main(). */ 6430 && !MAIN_NAME_P (DECL_NAME (fndecl)) 6431 /* Or if they didn't actually specify a return type. */ 6432 && !C_FUNCTION_IMPLICIT_INT (fndecl) 6433 /* Normally, with -Wreturn-type, flow will complain. Unless we're an 6434 inline function, as we might never be compiled separately. */ 6435 && DECL_INLINE (fndecl)) 6436 warning ("no return statement in function returning non-void"); 6437 6438 /* Clear out memory we no longer need. */ 6439 free_after_parsing (cfun); 6440 /* Since we never call rest_of_compilation, we never clear 6441 CFUN. Do so explicitly. */ 6442 free_after_compilation (cfun); 6443 cfun = NULL; 6444 6445 if (! nested) 6446 { 6447 /* Generate RTL for the body of this function. */ 6448 c_expand_body (fndecl, nested, can_defer_p); 6449 6450 /* Let the error reporting routines know that we're outside a 6451 function. For a nested function, this value is used in 6452 c_pop_function_context and then reset via pop_function_context. */ 6453 current_function_decl = NULL; 6454 } 6455} 6456 6457/* Generate the RTL for a deferred function FNDECL. */ 6458 6459void 6460c_expand_deferred_function (fndecl) 6461 tree fndecl; 6462{ 6463 /* DECL_INLINE or DECL_RESULT might got cleared after the inline 6464 function was deferred, e.g. in duplicate_decls. */ 6465 if (DECL_INLINE (fndecl) && DECL_RESULT (fndecl)) 6466 { 6467 c_expand_body (fndecl, 0, 0); 6468 current_function_decl = NULL; 6469 } 6470} 6471 6472/* Called to move the SAVE_EXPRs for parameter declarations in a 6473 nested function into the nested function. DATA is really the 6474 nested FUNCTION_DECL. */ 6475 6476static tree 6477set_save_expr_context (tp, walk_subtrees, data) 6478 tree *tp; 6479 int *walk_subtrees; 6480 void *data; 6481{ 6482 if (TREE_CODE (*tp) == SAVE_EXPR && !SAVE_EXPR_CONTEXT (*tp)) 6483 SAVE_EXPR_CONTEXT (*tp) = (tree) data; 6484 /* Do not walk back into the SAVE_EXPR_CONTEXT; that will cause 6485 circularity. */ 6486 else if (DECL_P (*tp)) 6487 *walk_subtrees = 0; 6488 6489 return NULL_TREE; 6490} 6491 6492/* Generate the RTL for the body of FNDECL. If NESTED_P is nonzero, 6493 then we are already in the process of generating RTL for another 6494 function. If can_defer_p is zero, we won't attempt to defer the 6495 generation of RTL. */ 6496 6497static void 6498c_expand_body (fndecl, nested_p, can_defer_p) 6499 tree fndecl; 6500 int nested_p, can_defer_p; 6501{ 6502 int uninlinable = 1; 6503 int saved_lineno; 6504 const char *saved_input_filename; 6505 6506 /* There's no reason to do any of the work here if we're only doing 6507 semantic analysis; this code just generates RTL. */ 6508 if (flag_syntax_only) 6509 return; 6510 6511 saved_lineno = lineno; 6512 saved_input_filename = input_filename; 6513 lineno = DECL_SOURCE_LINE (fndecl); 6514 input_filename = DECL_SOURCE_FILE (fndecl); 6515 6516 if (flag_inline_trees) 6517 { 6518 /* First, cache whether the current function is inlinable. Some 6519 predicates depend on cfun and current_function_decl to 6520 function completely. */ 6521 timevar_push (TV_INTEGRATION); 6522 uninlinable = ! tree_inlinable_function_p (fndecl); 6523 6524 if (! uninlinable && can_defer_p 6525 /* Save function tree for inlining. Should return 0 if the 6526 language does not support function deferring or the 6527 function could not be deferred. */ 6528 && defer_fn (fndecl)) 6529 { 6530 /* Let the back-end know that this function exists. */ 6531 (*debug_hooks->deferred_inline_function) (fndecl); 6532 timevar_pop (TV_INTEGRATION); 6533 lineno = saved_lineno; 6534 input_filename = saved_input_filename; 6535 return; 6536 } 6537 6538 /* Then, inline any functions called in it. */ 6539 optimize_inline_calls (fndecl); 6540 timevar_pop (TV_INTEGRATION); 6541 } 6542 6543 timevar_push (TV_EXPAND); 6544 6545 if (nested_p) 6546 { 6547 /* Make sure that we will evaluate variable-sized types involved 6548 in our function's type. */ 6549 expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes); 6550 /* Squirrel away our current state. */ 6551 push_function_context (); 6552 } 6553 6554 /* Initialize the RTL code for the function. */ 6555 current_function_decl = fndecl; 6556 init_function_start (fndecl, input_filename, DECL_SOURCE_LINE (fndecl)); 6557 6558 /* This function is being processed in whole-function mode. */ 6559 cfun->x_whole_function_mode_p = 1; 6560 6561 /* Even though we're inside a function body, we still don't want to 6562 call expand_expr to calculate the size of a variable-sized array. 6563 We haven't necessarily assigned RTL to all variables yet, so it's 6564 not safe to try to expand expressions involving them. */ 6565 immediate_size_expand = 0; 6566 cfun->x_dont_save_pending_sizes_p = 1; 6567 6568 /* Set up parameters and prepare for return, for the function. */ 6569 expand_function_start (fndecl, 0); 6570 6571 /* If the function has a variably modified type, there may be 6572 SAVE_EXPRs in the parameter types. Their context must be set to 6573 refer to this function; they cannot be expanded in the containing 6574 function. */ 6575 if (decl_function_context (fndecl) 6576 && variably_modified_type_p (TREE_TYPE (fndecl))) 6577 walk_tree (&TREE_TYPE (fndecl), set_save_expr_context, fndecl, 6578 NULL); 6579 6580 /* If this function is `main', emit a call to `__main' 6581 to run global initializers, etc. */ 6582 if (DECL_NAME (fndecl) 6583 && MAIN_NAME_P (DECL_NAME (fndecl)) 6584 && DECL_CONTEXT (fndecl) == NULL_TREE) 6585 expand_main_function (); 6586 6587 /* Generate the RTL for this function. */ 6588 expand_stmt (DECL_SAVED_TREE (fndecl)); 6589 6590 /* Keep the function body if it's needed for inlining or dumping. */ 6591 if (uninlinable && !dump_enabled_p (TDI_all)) 6592 { 6593 /* Allow the body of the function to be garbage collected. */ 6594 DECL_SAVED_TREE (fndecl) = NULL_TREE; 6595 } 6596 6597 /* We hard-wired immediate_size_expand to zero above. 6598 expand_function_end will decrement this variable. So, we set the 6599 variable to one here, so that after the decrement it will remain 6600 zero. */ 6601 immediate_size_expand = 1; 6602 6603 /* Allow language dialects to perform special processing. */ 6604 if (lang_expand_function_end) 6605 (*lang_expand_function_end) (); 6606 6607 /* Generate rtl for function exit. */ 6608 expand_function_end (input_filename, lineno, 0); 6609 6610 /* If this is a nested function, protect the local variables in the stack 6611 above us from being collected while we're compiling this function. */ 6612 if (nested_p) 6613 ggc_push_context (); 6614 6615 /* Run the optimizers and output the assembler code for this function. */ 6616 rest_of_compilation (fndecl); 6617 6618 /* Undo the GC context switch. */ 6619 if (nested_p) 6620 ggc_pop_context (); 6621 6622 /* With just -W, complain only if function returns both with 6623 and without a value. */ 6624 if (extra_warnings 6625 && current_function_returns_value 6626 && current_function_returns_null) 6627 warning ("this function may return with or without a value"); 6628 6629 /* If requested, warn about function definitions where the function will 6630 return a value (usually of some struct or union type) which itself will 6631 take up a lot of stack space. */ 6632 6633 if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl)) 6634 { 6635 tree ret_type = TREE_TYPE (TREE_TYPE (fndecl)); 6636 6637 if (ret_type && TYPE_SIZE_UNIT (ret_type) 6638 && TREE_CODE (TYPE_SIZE_UNIT (ret_type)) == INTEGER_CST 6639 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type), 6640 larger_than_size)) 6641 { 6642 unsigned int size_as_int 6643 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type)); 6644 6645 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type), size_as_int) == 0) 6646 warning_with_decl (fndecl, 6647 "size of return value of `%s' is %u bytes", 6648 size_as_int); 6649 else 6650 warning_with_decl (fndecl, 6651 "size of return value of `%s' is larger than %d bytes", 6652 larger_than_size); 6653 } 6654 } 6655 6656 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested_p 6657 && ! flag_inline_trees) 6658 { 6659 /* Stop pointing to the local nodes about to be freed. 6660 But DECL_INITIAL must remain nonzero so we know this 6661 was an actual function definition. 6662 For a nested function, this is done in c_pop_function_context. 6663 If rest_of_compilation set this to 0, leave it 0. */ 6664 if (DECL_INITIAL (fndecl) != 0) 6665 DECL_INITIAL (fndecl) = error_mark_node; 6666 6667 DECL_ARGUMENTS (fndecl) = 0; 6668 } 6669 6670 if (DECL_STATIC_CONSTRUCTOR (fndecl)) 6671 { 6672 if (targetm.have_ctors_dtors) 6673 (* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0), 6674 DEFAULT_INIT_PRIORITY); 6675 else 6676 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors); 6677 } 6678 6679 if (DECL_STATIC_DESTRUCTOR (fndecl)) 6680 { 6681 if (targetm.have_ctors_dtors) 6682 (* targetm.asm_out.destructor) (XEXP (DECL_RTL (fndecl), 0), 6683 DEFAULT_INIT_PRIORITY); 6684 else 6685 static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors); 6686 } 6687 6688 if (nested_p) 6689 /* Return to the enclosing function. */ 6690 pop_function_context (); 6691 timevar_pop (TV_EXPAND); 6692 6693 lineno = saved_lineno; 6694 input_filename = saved_input_filename; 6695} 6696 6697/* Check the declarations given in a for-loop for satisfying the C99 6698 constraints. */ 6699void 6700check_for_loop_decls () 6701{ 6702 tree t; 6703 6704 if (!flag_isoc99) 6705 { 6706 /* If we get here, declarations have been used in a for loop without 6707 the C99 for loop scope. This doesn't make much sense, so don't 6708 allow it. */ 6709 error ("`for' loop initial declaration used outside C99 mode"); 6710 return; 6711 } 6712 /* C99 subclause 6.8.5 paragraph 3: 6713 6714 [#3] The declaration part of a for statement shall only 6715 declare identifiers for objects having storage class auto or 6716 register. 6717 6718 It isn't clear whether, in this sentence, "identifiers" binds to 6719 "shall only declare" or to "objects" - that is, whether all identifiers 6720 declared must be identifiers for objects, or whether the restriction 6721 only applies to those that are. (A question on this in comp.std.c 6722 in November 2000 received no answer.) We implement the strictest 6723 interpretation, to avoid creating an extension which later causes 6724 problems. */ 6725 6726 for (t = gettags (); t; t = TREE_CHAIN (t)) 6727 { 6728 if (TREE_PURPOSE (t) != 0) 6729 { 6730 enum tree_code code = TREE_CODE (TREE_VALUE (t)); 6731 6732 if (code == RECORD_TYPE) 6733 error ("`struct %s' declared in `for' loop initial declaration", 6734 IDENTIFIER_POINTER (TREE_PURPOSE (t))); 6735 else if (code == UNION_TYPE) 6736 error ("`union %s' declared in `for' loop initial declaration", 6737 IDENTIFIER_POINTER (TREE_PURPOSE (t))); 6738 else 6739 error ("`enum %s' declared in `for' loop initial declaration", 6740 IDENTIFIER_POINTER (TREE_PURPOSE (t))); 6741 } 6742 } 6743 6744 for (t = getdecls (); t; t = TREE_CHAIN (t)) 6745 { 6746 if (TREE_CODE (t) != VAR_DECL && DECL_NAME (t)) 6747 error_with_decl (t, "declaration of non-variable `%s' in `for' loop initial declaration"); 6748 else if (TREE_STATIC (t)) 6749 error_with_decl (t, "declaration of static variable `%s' in `for' loop initial declaration"); 6750 else if (DECL_EXTERNAL (t)) 6751 error_with_decl (t, "declaration of `extern' variable `%s' in `for' loop initial declaration"); 6752 } 6753} 6754 6755/* Save and restore the variables in this file and elsewhere 6756 that keep track of the progress of compilation of the current function. 6757 Used for nested functions. */ 6758 6759struct language_function GTY(()) 6760{ 6761 struct c_language_function base; 6762 tree named_labels; 6763 tree shadowed_labels; 6764 int returns_value; 6765 int returns_null; 6766 int returns_abnormally; 6767 int warn_about_return_type; 6768 int extern_inline; 6769 struct binding_level *binding_level; 6770}; 6771 6772/* Save and reinitialize the variables 6773 used during compilation of a C function. */ 6774 6775void 6776c_push_function_context (f) 6777 struct function *f; 6778{ 6779 struct language_function *p; 6780 p = ((struct language_function *) 6781 ggc_alloc (sizeof (struct language_function))); 6782 f->language = p; 6783 6784 p->base.x_stmt_tree = c_stmt_tree; 6785 p->base.x_scope_stmt_stack = c_scope_stmt_stack; 6786 p->named_labels = named_labels; 6787 p->shadowed_labels = shadowed_labels; 6788 p->returns_value = current_function_returns_value; 6789 p->returns_null = current_function_returns_null; 6790 p->returns_abnormally = current_function_returns_abnormally; 6791 p->warn_about_return_type = warn_about_return_type; 6792 p->extern_inline = current_extern_inline; 6793 p->binding_level = current_binding_level; 6794} 6795 6796/* Restore the variables used during compilation of a C function. */ 6797 6798void 6799c_pop_function_context (f) 6800 struct function *f; 6801{ 6802 struct language_function *p = f->language; 6803 tree link; 6804 6805 /* Bring back all the labels that were shadowed. */ 6806 for (link = shadowed_labels; link; link = TREE_CHAIN (link)) 6807 if (DECL_NAME (TREE_VALUE (link)) != 0) 6808 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) 6809 = TREE_VALUE (link); 6810 6811 if (DECL_SAVED_INSNS (current_function_decl) == 0 6812 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE) 6813 { 6814 /* Stop pointing to the local nodes about to be freed. */ 6815 /* But DECL_INITIAL must remain nonzero so we know this 6816 was an actual function definition. */ 6817 DECL_INITIAL (current_function_decl) = error_mark_node; 6818 DECL_ARGUMENTS (current_function_decl) = 0; 6819 } 6820 6821 c_stmt_tree = p->base.x_stmt_tree; 6822 c_scope_stmt_stack = p->base.x_scope_stmt_stack; 6823 named_labels = p->named_labels; 6824 shadowed_labels = p->shadowed_labels; 6825 current_function_returns_value = p->returns_value; 6826 current_function_returns_null = p->returns_null; 6827 current_function_returns_abnormally = p->returns_abnormally; 6828 warn_about_return_type = p->warn_about_return_type; 6829 current_extern_inline = p->extern_inline; 6830 current_binding_level = p->binding_level; 6831 6832 f->language = NULL; 6833} 6834 6835/* Copy the DECL_LANG_SPECIFIC data associated with DECL. */ 6836 6837void 6838c_dup_lang_specific_decl (decl) 6839 tree decl; 6840{ 6841 struct lang_decl *ld; 6842 6843 if (!DECL_LANG_SPECIFIC (decl)) 6844 return; 6845 6846 ld = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl)); 6847 memcpy ((char *) ld, (char *) DECL_LANG_SPECIFIC (decl), 6848 sizeof (struct lang_decl)); 6849 DECL_LANG_SPECIFIC (decl) = ld; 6850} 6851 6852/* The functions below are required for functionality of doing 6853 function at once processing in the C front end. Currently these 6854 functions are not called from anywhere in the C front end, but as 6855 these changes continue, that will change. */ 6856 6857/* Returns nonzero if the current statement is a full expression, 6858 i.e. temporaries created during that statement should be destroyed 6859 at the end of the statement. */ 6860 6861int 6862stmts_are_full_exprs_p () 6863{ 6864 return 0; 6865} 6866 6867/* Returns the stmt_tree (if any) to which statements are currently 6868 being added. If there is no active statement-tree, NULL is 6869 returned. */ 6870 6871stmt_tree 6872current_stmt_tree () 6873{ 6874 return &c_stmt_tree; 6875} 6876 6877/* Returns the stack of SCOPE_STMTs for the current function. */ 6878 6879tree * 6880current_scope_stmt_stack () 6881{ 6882 return &c_scope_stmt_stack; 6883} 6884 6885/* Nonzero if TYPE is an anonymous union or struct type. Always 0 in 6886 C. */ 6887 6888int 6889anon_aggr_type_p (node) 6890 tree node ATTRIBUTE_UNUSED; 6891{ 6892 return 0; 6893} 6894 6895/* Dummy function in place of callback used by C++. */ 6896 6897void 6898extract_interface_info () 6899{ 6900} 6901 6902/* Return a new COMPOUND_STMT, after adding it to the current 6903 statement tree. */ 6904 6905tree 6906c_begin_compound_stmt () 6907{ 6908 tree stmt; 6909 6910 /* Create the COMPOUND_STMT. */ 6911 stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE)); 6912 6913 return stmt; 6914} 6915 6916/* Expand T (a DECL_STMT) if it declares an entity not handled by the 6917 common code. */ 6918 6919void 6920c_expand_decl_stmt (t) 6921 tree t; 6922{ 6923 tree decl = DECL_STMT_DECL (t); 6924 6925 /* Expand nested functions. */ 6926 if (TREE_CODE (decl) == FUNCTION_DECL 6927 && DECL_CONTEXT (decl) == current_function_decl 6928 && DECL_SAVED_TREE (decl)) 6929 c_expand_body (decl, /*nested_p=*/1, /*can_defer_p=*/0); 6930} 6931 6932/* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since 6933 the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */ 6934 6935tree 6936identifier_global_value (t) 6937 tree t; 6938{ 6939 return IDENTIFIER_GLOBAL_VALUE (t); 6940} 6941 6942/* Record a builtin type for C. If NAME is non-NULL, it is the name used; 6943 otherwise the name is found in ridpointers from RID_INDEX. */ 6944 6945void 6946record_builtin_type (rid_index, name, type) 6947 enum rid rid_index; 6948 const char *name; 6949 tree type; 6950{ 6951 tree id; 6952 if (name == 0) 6953 id = ridpointers[(int) rid_index]; 6954 else 6955 id = get_identifier (name); 6956 pushdecl (build_decl (TYPE_DECL, id, type)); 6957} 6958 6959/* Build the void_list_node (void_type_node having been created). */ 6960tree 6961build_void_list_node () 6962{ 6963 tree t = build_tree_list (NULL_TREE, void_type_node); 6964 return t; 6965} 6966 6967/* Return something to represent absolute declarators containing a *. 6968 TARGET is the absolute declarator that the * contains. 6969 TYPE_QUALS_ATTRS is a list of modifiers such as const or volatile 6970 to apply to the pointer type, represented as identifiers, possible mixed 6971 with attributes. 6972 6973 We return an INDIRECT_REF whose "contents" are TARGET (inside a TREE_LIST, 6974 if attributes are present) and whose type is the modifier list. */ 6975 6976tree 6977make_pointer_declarator (type_quals_attrs, target) 6978 tree type_quals_attrs, target; 6979{ 6980 tree quals, attrs; 6981 tree itarget = target; 6982 split_specs_attrs (type_quals_attrs, &quals, &attrs); 6983 if (attrs != NULL_TREE) 6984 itarget = tree_cons (attrs, target, NULL_TREE); 6985 return build1 (INDIRECT_REF, quals, itarget); 6986} 6987 6988#include "gt-c-decl.h" 6989