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