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