1 /* Language-independent node constructors for parse phase of GNU compiler. 2 Copyright (C) 1987-2013 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 6 GCC is free software; you can redistribute it and/or modify it under 7 the terms of the GNU General Public License as published by the Free 8 Software Foundation; either version 3, or (at your option) any later 9 version. 10 11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GCC; see the file COPYING3. If not see 18 <http://www.gnu.org/licenses/>. */ 19 20 /* This file contains the low level primitives for operating on tree nodes, 21 including allocation, list operations, interning of identifiers, 22 construction of data type nodes and statement nodes, 23 and construction of type conversion nodes. It also contains 24 tables index by tree code that describe how to take apart 25 nodes of that code. 26 27 It is intended to be language-independent, but occasionally 28 calls language-dependent routines defined (for C) in typecheck.c. */ 29 30 #include "config.h" 31 #include "system.h" 32 #include "coretypes.h" 33 #include "tm.h" 34 #include "flags.h" 35 #include "tree.h" 36 #include "tm_p.h" 37 #include "function.h" 38 #include "obstack.h" 39 #include "toplev.h" /* get_random_seed */ 40 #include "ggc.h" 41 #include "hashtab.h" 42 #include "filenames.h" 43 #include "output.h" 44 #include "target.h" 45 #include "common/common-target.h" 46 #include "langhooks.h" 47 #include "tree-inline.h" 48 #include "tree-iterator.h" 49 #include "basic-block.h" 50 #include "tree-flow.h" 51 #include "params.h" 52 #include "pointer-set.h" 53 #include "tree-pass.h" 54 #include "langhooks-def.h" 55 #include "diagnostic.h" 56 #include "tree-diagnostic.h" 57 #include "tree-pretty-print.h" 58 #include "cgraph.h" 59 #include "except.h" 60 #include "debug.h" 61 #include "intl.h" 62 63 /* Tree code classes. */ 64 65 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, 66 #define END_OF_BASE_TREE_CODES tcc_exceptional, 67 68 const enum tree_code_class tree_code_type[] = { 69 #include "all-tree.def" 70 }; 71 72 #undef DEFTREECODE 73 #undef END_OF_BASE_TREE_CODES 74 75 /* Table indexed by tree code giving number of expression 76 operands beyond the fixed part of the node structure. 77 Not used for types or decls. */ 78 79 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, 80 #define END_OF_BASE_TREE_CODES 0, 81 82 const unsigned char tree_code_length[] = { 83 #include "all-tree.def" 84 }; 85 86 #undef DEFTREECODE 87 #undef END_OF_BASE_TREE_CODES 88 89 /* Names of tree components. 90 Used for printing out the tree and error messages. */ 91 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, 92 #define END_OF_BASE_TREE_CODES "@dummy", 93 94 const char *const tree_code_name[] = { 95 #include "all-tree.def" 96 }; 97 98 #undef DEFTREECODE 99 #undef END_OF_BASE_TREE_CODES 100 101 /* Each tree code class has an associated string representation. 102 These must correspond to the tree_code_class entries. */ 103 104 const char *const tree_code_class_strings[] = 105 { 106 "exceptional", 107 "constant", 108 "type", 109 "declaration", 110 "reference", 111 "comparison", 112 "unary", 113 "binary", 114 "statement", 115 "vl_exp", 116 "expression" 117 }; 118 119 /* obstack.[ch] explicitly declined to prototype this. */ 120 extern int _obstack_allocated_p (struct obstack *h, void *obj); 121 122 /* Statistics-gathering stuff. */ 123 124 static int tree_code_counts[MAX_TREE_CODES]; 125 int tree_node_counts[(int) all_kinds]; 126 int tree_node_sizes[(int) all_kinds]; 127 128 /* Keep in sync with tree.h:enum tree_node_kind. */ 129 static const char * const tree_node_kind_names[] = { 130 "decls", 131 "types", 132 "blocks", 133 "stmts", 134 "refs", 135 "exprs", 136 "constants", 137 "identifiers", 138 "vecs", 139 "binfos", 140 "ssa names", 141 "constructors", 142 "random kinds", 143 "lang_decl kinds", 144 "lang_type kinds", 145 "omp clauses", 146 }; 147 148 /* Unique id for next decl created. */ 149 static GTY(()) int next_decl_uid; 150 /* Unique id for next type created. */ 151 static GTY(()) int next_type_uid = 1; 152 /* Unique id for next debug decl created. Use negative numbers, 153 to catch erroneous uses. */ 154 static GTY(()) int next_debug_decl_uid; 155 156 /* Since we cannot rehash a type after it is in the table, we have to 157 keep the hash code. */ 158 159 struct GTY(()) type_hash { 160 unsigned long hash; 161 tree type; 162 }; 163 164 /* Initial size of the hash table (rounded to next prime). */ 165 #define TYPE_HASH_INITIAL_SIZE 1000 166 167 /* Now here is the hash table. When recording a type, it is added to 168 the slot whose index is the hash code. Note that the hash table is 169 used for several kinds of types (function types, array types and 170 array index range types, for now). While all these live in the 171 same table, they are completely independent, and the hash code is 172 computed differently for each of these. */ 173 174 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash))) 175 htab_t type_hash_table; 176 177 /* Hash table and temporary node for larger integer const values. */ 178 static GTY (()) tree int_cst_node; 179 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node))) 180 htab_t int_cst_hash_table; 181 182 /* Hash table for optimization flags and target option flags. Use the same 183 hash table for both sets of options. Nodes for building the current 184 optimization and target option nodes. The assumption is most of the time 185 the options created will already be in the hash table, so we avoid 186 allocating and freeing up a node repeatably. */ 187 static GTY (()) tree cl_optimization_node; 188 static GTY (()) tree cl_target_option_node; 189 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node))) 190 htab_t cl_option_hash_table; 191 192 /* General tree->tree mapping structure for use in hash tables. */ 193 194 195 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map))) 196 htab_t debug_expr_for_decl; 197 198 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map))) 199 htab_t value_expr_for_decl; 200 201 static GTY ((if_marked ("tree_vec_map_marked_p"), param_is (struct tree_vec_map))) 202 htab_t debug_args_for_decl; 203 204 static GTY ((if_marked ("tree_priority_map_marked_p"), 205 param_is (struct tree_priority_map))) 206 htab_t init_priority_for_decl; 207 208 static void set_type_quals (tree, int); 209 static int type_hash_eq (const void *, const void *); 210 static hashval_t type_hash_hash (const void *); 211 static hashval_t int_cst_hash_hash (const void *); 212 static int int_cst_hash_eq (const void *, const void *); 213 static hashval_t cl_option_hash_hash (const void *); 214 static int cl_option_hash_eq (const void *, const void *); 215 static void print_type_hash_statistics (void); 216 static void print_debug_expr_statistics (void); 217 static void print_value_expr_statistics (void); 218 static int type_hash_marked_p (const void *); 219 static unsigned int type_hash_list (const_tree, hashval_t); 220 static unsigned int attribute_hash_list (const_tree, hashval_t); 221 222 tree global_trees[TI_MAX]; 223 tree integer_types[itk_none]; 224 225 unsigned char tree_contains_struct[MAX_TREE_CODES][64]; 226 227 /* Number of operands for each OpenMP clause. */ 228 unsigned const char omp_clause_num_ops[] = 229 { 230 0, /* OMP_CLAUSE_ERROR */ 231 1, /* OMP_CLAUSE_PRIVATE */ 232 1, /* OMP_CLAUSE_SHARED */ 233 1, /* OMP_CLAUSE_FIRSTPRIVATE */ 234 2, /* OMP_CLAUSE_LASTPRIVATE */ 235 4, /* OMP_CLAUSE_REDUCTION */ 236 1, /* OMP_CLAUSE_COPYIN */ 237 1, /* OMP_CLAUSE_COPYPRIVATE */ 238 1, /* OMP_CLAUSE_IF */ 239 1, /* OMP_CLAUSE_NUM_THREADS */ 240 1, /* OMP_CLAUSE_SCHEDULE */ 241 0, /* OMP_CLAUSE_NOWAIT */ 242 0, /* OMP_CLAUSE_ORDERED */ 243 0, /* OMP_CLAUSE_DEFAULT */ 244 3, /* OMP_CLAUSE_COLLAPSE */ 245 0, /* OMP_CLAUSE_UNTIED */ 246 1, /* OMP_CLAUSE_FINAL */ 247 0 /* OMP_CLAUSE_MERGEABLE */ 248 }; 249 250 const char * const omp_clause_code_name[] = 251 { 252 "error_clause", 253 "private", 254 "shared", 255 "firstprivate", 256 "lastprivate", 257 "reduction", 258 "copyin", 259 "copyprivate", 260 "if", 261 "num_threads", 262 "schedule", 263 "nowait", 264 "ordered", 265 "default", 266 "collapse", 267 "untied", 268 "final", 269 "mergeable" 270 }; 271 272 273 /* Return the tree node structure used by tree code CODE. */ 274 275 static inline enum tree_node_structure_enum 276 tree_node_structure_for_code (enum tree_code code) 277 { 278 switch (TREE_CODE_CLASS (code)) 279 { 280 case tcc_declaration: 281 { 282 switch (code) 283 { 284 case FIELD_DECL: 285 return TS_FIELD_DECL; 286 case PARM_DECL: 287 return TS_PARM_DECL; 288 case VAR_DECL: 289 return TS_VAR_DECL; 290 case LABEL_DECL: 291 return TS_LABEL_DECL; 292 case RESULT_DECL: 293 return TS_RESULT_DECL; 294 case DEBUG_EXPR_DECL: 295 return TS_DECL_WRTL; 296 case CONST_DECL: 297 return TS_CONST_DECL; 298 case TYPE_DECL: 299 return TS_TYPE_DECL; 300 case FUNCTION_DECL: 301 return TS_FUNCTION_DECL; 302 case TRANSLATION_UNIT_DECL: 303 return TS_TRANSLATION_UNIT_DECL; 304 default: 305 return TS_DECL_NON_COMMON; 306 } 307 } 308 case tcc_type: 309 return TS_TYPE_NON_COMMON; 310 case tcc_reference: 311 case tcc_comparison: 312 case tcc_unary: 313 case tcc_binary: 314 case tcc_expression: 315 case tcc_statement: 316 case tcc_vl_exp: 317 return TS_EXP; 318 default: /* tcc_constant and tcc_exceptional */ 319 break; 320 } 321 switch (code) 322 { 323 /* tcc_constant cases. */ 324 case INTEGER_CST: return TS_INT_CST; 325 case REAL_CST: return TS_REAL_CST; 326 case FIXED_CST: return TS_FIXED_CST; 327 case COMPLEX_CST: return TS_COMPLEX; 328 case VECTOR_CST: return TS_VECTOR; 329 case STRING_CST: return TS_STRING; 330 /* tcc_exceptional cases. */ 331 case ERROR_MARK: return TS_COMMON; 332 case IDENTIFIER_NODE: return TS_IDENTIFIER; 333 case TREE_LIST: return TS_LIST; 334 case TREE_VEC: return TS_VEC; 335 case SSA_NAME: return TS_SSA_NAME; 336 case PLACEHOLDER_EXPR: return TS_COMMON; 337 case STATEMENT_LIST: return TS_STATEMENT_LIST; 338 case BLOCK: return TS_BLOCK; 339 case CONSTRUCTOR: return TS_CONSTRUCTOR; 340 case TREE_BINFO: return TS_BINFO; 341 case OMP_CLAUSE: return TS_OMP_CLAUSE; 342 case OPTIMIZATION_NODE: return TS_OPTIMIZATION; 343 case TARGET_OPTION_NODE: return TS_TARGET_OPTION; 344 345 default: 346 gcc_unreachable (); 347 } 348 } 349 350 351 /* Initialize tree_contains_struct to describe the hierarchy of tree 352 nodes. */ 353 354 static void 355 initialize_tree_contains_struct (void) 356 { 357 unsigned i; 358 359 for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++) 360 { 361 enum tree_code code; 362 enum tree_node_structure_enum ts_code; 363 364 code = (enum tree_code) i; 365 ts_code = tree_node_structure_for_code (code); 366 367 /* Mark the TS structure itself. */ 368 tree_contains_struct[code][ts_code] = 1; 369 370 /* Mark all the structures that TS is derived from. */ 371 switch (ts_code) 372 { 373 case TS_TYPED: 374 case TS_BLOCK: 375 MARK_TS_BASE (code); 376 break; 377 378 case TS_COMMON: 379 case TS_INT_CST: 380 case TS_REAL_CST: 381 case TS_FIXED_CST: 382 case TS_VECTOR: 383 case TS_STRING: 384 case TS_COMPLEX: 385 case TS_SSA_NAME: 386 case TS_CONSTRUCTOR: 387 case TS_EXP: 388 case TS_STATEMENT_LIST: 389 MARK_TS_TYPED (code); 390 break; 391 392 case TS_IDENTIFIER: 393 case TS_DECL_MINIMAL: 394 case TS_TYPE_COMMON: 395 case TS_LIST: 396 case TS_VEC: 397 case TS_BINFO: 398 case TS_OMP_CLAUSE: 399 case TS_OPTIMIZATION: 400 case TS_TARGET_OPTION: 401 MARK_TS_COMMON (code); 402 break; 403 404 case TS_TYPE_WITH_LANG_SPECIFIC: 405 MARK_TS_TYPE_COMMON (code); 406 break; 407 408 case TS_TYPE_NON_COMMON: 409 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code); 410 break; 411 412 case TS_DECL_COMMON: 413 MARK_TS_DECL_MINIMAL (code); 414 break; 415 416 case TS_DECL_WRTL: 417 case TS_CONST_DECL: 418 MARK_TS_DECL_COMMON (code); 419 break; 420 421 case TS_DECL_NON_COMMON: 422 MARK_TS_DECL_WITH_VIS (code); 423 break; 424 425 case TS_DECL_WITH_VIS: 426 case TS_PARM_DECL: 427 case TS_LABEL_DECL: 428 case TS_RESULT_DECL: 429 MARK_TS_DECL_WRTL (code); 430 break; 431 432 case TS_FIELD_DECL: 433 MARK_TS_DECL_COMMON (code); 434 break; 435 436 case TS_VAR_DECL: 437 MARK_TS_DECL_WITH_VIS (code); 438 break; 439 440 case TS_TYPE_DECL: 441 case TS_FUNCTION_DECL: 442 MARK_TS_DECL_NON_COMMON (code); 443 break; 444 445 case TS_TRANSLATION_UNIT_DECL: 446 MARK_TS_DECL_COMMON (code); 447 break; 448 449 default: 450 gcc_unreachable (); 451 } 452 } 453 454 /* Basic consistency checks for attributes used in fold. */ 455 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]); 456 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]); 457 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]); 458 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]); 459 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]); 460 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]); 461 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]); 462 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]); 463 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]); 464 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]); 465 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]); 466 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]); 467 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]); 468 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]); 469 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]); 470 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]); 471 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]); 472 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]); 473 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]); 474 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]); 475 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]); 476 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]); 477 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]); 478 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]); 479 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]); 480 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]); 481 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]); 482 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]); 483 gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]); 484 gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]); 485 gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]); 486 gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]); 487 gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]); 488 gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]); 489 gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]); 490 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]); 491 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]); 492 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]); 493 } 494 495 496 /* Init tree.c. */ 497 498 void 499 init_ttree (void) 500 { 501 /* Initialize the hash table of types. */ 502 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash, 503 type_hash_eq, 0); 504 505 debug_expr_for_decl = htab_create_ggc (512, tree_decl_map_hash, 506 tree_decl_map_eq, 0); 507 508 value_expr_for_decl = htab_create_ggc (512, tree_decl_map_hash, 509 tree_decl_map_eq, 0); 510 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash, 511 tree_priority_map_eq, 0); 512 513 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash, 514 int_cst_hash_eq, NULL); 515 516 int_cst_node = make_node (INTEGER_CST); 517 518 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash, 519 cl_option_hash_eq, NULL); 520 521 cl_optimization_node = make_node (OPTIMIZATION_NODE); 522 cl_target_option_node = make_node (TARGET_OPTION_NODE); 523 524 /* Initialize the tree_contains_struct array. */ 525 initialize_tree_contains_struct (); 526 lang_hooks.init_ts (); 527 } 528 529 530 /* The name of the object as the assembler will see it (but before any 531 translations made by ASM_OUTPUT_LABELREF). Often this is the same 532 as DECL_NAME. It is an IDENTIFIER_NODE. */ 533 tree 534 decl_assembler_name (tree decl) 535 { 536 if (!DECL_ASSEMBLER_NAME_SET_P (decl)) 537 lang_hooks.set_decl_assembler_name (decl); 538 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name; 539 } 540 541 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */ 542 543 bool 544 decl_assembler_name_equal (tree decl, const_tree asmname) 545 { 546 tree decl_asmname = DECL_ASSEMBLER_NAME (decl); 547 const char *decl_str; 548 const char *asmname_str; 549 bool test = false; 550 551 if (decl_asmname == asmname) 552 return true; 553 554 decl_str = IDENTIFIER_POINTER (decl_asmname); 555 asmname_str = IDENTIFIER_POINTER (asmname); 556 557 558 /* If the target assembler name was set by the user, things are trickier. 559 We have a leading '*' to begin with. After that, it's arguable what 560 is the correct thing to do with -fleading-underscore. Arguably, we've 561 historically been doing the wrong thing in assemble_alias by always 562 printing the leading underscore. Since we're not changing that, make 563 sure user_label_prefix follows the '*' before matching. */ 564 if (decl_str[0] == '*') 565 { 566 size_t ulp_len = strlen (user_label_prefix); 567 568 decl_str ++; 569 570 if (ulp_len == 0) 571 test = true; 572 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) 573 decl_str += ulp_len, test=true; 574 else 575 decl_str --; 576 } 577 if (asmname_str[0] == '*') 578 { 579 size_t ulp_len = strlen (user_label_prefix); 580 581 asmname_str ++; 582 583 if (ulp_len == 0) 584 test = true; 585 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0) 586 asmname_str += ulp_len, test=true; 587 else 588 asmname_str --; 589 } 590 591 if (!test) 592 return false; 593 return strcmp (decl_str, asmname_str) == 0; 594 } 595 596 /* Hash asmnames ignoring the user specified marks. */ 597 598 hashval_t 599 decl_assembler_name_hash (const_tree asmname) 600 { 601 if (IDENTIFIER_POINTER (asmname)[0] == '*') 602 { 603 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1; 604 size_t ulp_len = strlen (user_label_prefix); 605 606 if (ulp_len == 0) 607 ; 608 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) 609 decl_str += ulp_len; 610 611 return htab_hash_string (decl_str); 612 } 613 614 return htab_hash_string (IDENTIFIER_POINTER (asmname)); 615 } 616 617 /* Compute the number of bytes occupied by a tree with code CODE. 618 This function cannot be used for nodes that have variable sizes, 619 including TREE_VEC, STRING_CST, and CALL_EXPR. */ 620 size_t 621 tree_code_size (enum tree_code code) 622 { 623 switch (TREE_CODE_CLASS (code)) 624 { 625 case tcc_declaration: /* A decl node */ 626 { 627 switch (code) 628 { 629 case FIELD_DECL: 630 return sizeof (struct tree_field_decl); 631 case PARM_DECL: 632 return sizeof (struct tree_parm_decl); 633 case VAR_DECL: 634 return sizeof (struct tree_var_decl); 635 case LABEL_DECL: 636 return sizeof (struct tree_label_decl); 637 case RESULT_DECL: 638 return sizeof (struct tree_result_decl); 639 case CONST_DECL: 640 return sizeof (struct tree_const_decl); 641 case TYPE_DECL: 642 return sizeof (struct tree_type_decl); 643 case FUNCTION_DECL: 644 return sizeof (struct tree_function_decl); 645 case DEBUG_EXPR_DECL: 646 return sizeof (struct tree_decl_with_rtl); 647 default: 648 return sizeof (struct tree_decl_non_common); 649 } 650 } 651 652 case tcc_type: /* a type node */ 653 return sizeof (struct tree_type_non_common); 654 655 case tcc_reference: /* a reference */ 656 case tcc_expression: /* an expression */ 657 case tcc_statement: /* an expression with side effects */ 658 case tcc_comparison: /* a comparison expression */ 659 case tcc_unary: /* a unary arithmetic expression */ 660 case tcc_binary: /* a binary arithmetic expression */ 661 return (sizeof (struct tree_exp) 662 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree)); 663 664 case tcc_constant: /* a constant */ 665 switch (code) 666 { 667 case INTEGER_CST: return sizeof (struct tree_int_cst); 668 case REAL_CST: return sizeof (struct tree_real_cst); 669 case FIXED_CST: return sizeof (struct tree_fixed_cst); 670 case COMPLEX_CST: return sizeof (struct tree_complex); 671 case VECTOR_CST: return sizeof (struct tree_vector); 672 case STRING_CST: gcc_unreachable (); 673 default: 674 return lang_hooks.tree_size (code); 675 } 676 677 case tcc_exceptional: /* something random, like an identifier. */ 678 switch (code) 679 { 680 case IDENTIFIER_NODE: return lang_hooks.identifier_size; 681 case TREE_LIST: return sizeof (struct tree_list); 682 683 case ERROR_MARK: 684 case PLACEHOLDER_EXPR: return sizeof (struct tree_common); 685 686 case TREE_VEC: 687 case OMP_CLAUSE: gcc_unreachable (); 688 689 case SSA_NAME: return sizeof (struct tree_ssa_name); 690 691 case STATEMENT_LIST: return sizeof (struct tree_statement_list); 692 case BLOCK: return sizeof (struct tree_block); 693 case CONSTRUCTOR: return sizeof (struct tree_constructor); 694 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option); 695 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option); 696 697 default: 698 return lang_hooks.tree_size (code); 699 } 700 701 default: 702 gcc_unreachable (); 703 } 704 } 705 706 /* Compute the number of bytes occupied by NODE. This routine only 707 looks at TREE_CODE, except for those nodes that have variable sizes. */ 708 size_t 709 tree_size (const_tree node) 710 { 711 const enum tree_code code = TREE_CODE (node); 712 switch (code) 713 { 714 case TREE_BINFO: 715 return (offsetof (struct tree_binfo, base_binfos) 716 + vec<tree, va_gc> 717 ::embedded_size (BINFO_N_BASE_BINFOS (node))); 718 719 case TREE_VEC: 720 return (sizeof (struct tree_vec) 721 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree)); 722 723 case VECTOR_CST: 724 return (sizeof (struct tree_vector) 725 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node)) - 1) * sizeof (tree)); 726 727 case STRING_CST: 728 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1; 729 730 case OMP_CLAUSE: 731 return (sizeof (struct tree_omp_clause) 732 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1) 733 * sizeof (tree)); 734 735 default: 736 if (TREE_CODE_CLASS (code) == tcc_vl_exp) 737 return (sizeof (struct tree_exp) 738 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree)); 739 else 740 return tree_code_size (code); 741 } 742 } 743 744 /* Record interesting allocation statistics for a tree node with CODE 745 and LENGTH. */ 746 747 static void 748 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED, 749 size_t length ATTRIBUTE_UNUSED) 750 { 751 enum tree_code_class type = TREE_CODE_CLASS (code); 752 tree_node_kind kind; 753 754 if (!GATHER_STATISTICS) 755 return; 756 757 switch (type) 758 { 759 case tcc_declaration: /* A decl node */ 760 kind = d_kind; 761 break; 762 763 case tcc_type: /* a type node */ 764 kind = t_kind; 765 break; 766 767 case tcc_statement: /* an expression with side effects */ 768 kind = s_kind; 769 break; 770 771 case tcc_reference: /* a reference */ 772 kind = r_kind; 773 break; 774 775 case tcc_expression: /* an expression */ 776 case tcc_comparison: /* a comparison expression */ 777 case tcc_unary: /* a unary arithmetic expression */ 778 case tcc_binary: /* a binary arithmetic expression */ 779 kind = e_kind; 780 break; 781 782 case tcc_constant: /* a constant */ 783 kind = c_kind; 784 break; 785 786 case tcc_exceptional: /* something random, like an identifier. */ 787 switch (code) 788 { 789 case IDENTIFIER_NODE: 790 kind = id_kind; 791 break; 792 793 case TREE_VEC: 794 kind = vec_kind; 795 break; 796 797 case TREE_BINFO: 798 kind = binfo_kind; 799 break; 800 801 case SSA_NAME: 802 kind = ssa_name_kind; 803 break; 804 805 case BLOCK: 806 kind = b_kind; 807 break; 808 809 case CONSTRUCTOR: 810 kind = constr_kind; 811 break; 812 813 case OMP_CLAUSE: 814 kind = omp_clause_kind; 815 break; 816 817 default: 818 kind = x_kind; 819 break; 820 } 821 break; 822 823 case tcc_vl_exp: 824 kind = e_kind; 825 break; 826 827 default: 828 gcc_unreachable (); 829 } 830 831 tree_code_counts[(int) code]++; 832 tree_node_counts[(int) kind]++; 833 tree_node_sizes[(int) kind] += length; 834 } 835 836 /* Allocate and return a new UID from the DECL_UID namespace. */ 837 838 int 839 allocate_decl_uid (void) 840 { 841 return next_decl_uid++; 842 } 843 844 /* Return a newly allocated node of code CODE. For decl and type 845 nodes, some other fields are initialized. The rest of the node is 846 initialized to zero. This function cannot be used for TREE_VEC or 847 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size. 848 849 Achoo! I got a code in the node. */ 850 851 tree 852 make_node_stat (enum tree_code code MEM_STAT_DECL) 853 { 854 tree t; 855 enum tree_code_class type = TREE_CODE_CLASS (code); 856 size_t length = tree_code_size (code); 857 858 record_node_allocation_statistics (code, length); 859 860 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT); 861 TREE_SET_CODE (t, code); 862 863 switch (type) 864 { 865 case tcc_statement: 866 TREE_SIDE_EFFECTS (t) = 1; 867 break; 868 869 case tcc_declaration: 870 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) 871 { 872 if (code == FUNCTION_DECL) 873 { 874 DECL_ALIGN (t) = FUNCTION_BOUNDARY; 875 DECL_MODE (t) = FUNCTION_MODE; 876 } 877 else 878 DECL_ALIGN (t) = 1; 879 } 880 DECL_SOURCE_LOCATION (t) = input_location; 881 if (TREE_CODE (t) == DEBUG_EXPR_DECL) 882 DECL_UID (t) = --next_debug_decl_uid; 883 else 884 { 885 DECL_UID (t) = allocate_decl_uid (); 886 SET_DECL_PT_UID (t, -1); 887 } 888 if (TREE_CODE (t) == LABEL_DECL) 889 LABEL_DECL_UID (t) = -1; 890 891 break; 892 893 case tcc_type: 894 TYPE_UID (t) = next_type_uid++; 895 TYPE_ALIGN (t) = BITS_PER_UNIT; 896 TYPE_USER_ALIGN (t) = 0; 897 TYPE_MAIN_VARIANT (t) = t; 898 TYPE_CANONICAL (t) = t; 899 900 /* Default to no attributes for type, but let target change that. */ 901 TYPE_ATTRIBUTES (t) = NULL_TREE; 902 targetm.set_default_type_attributes (t); 903 904 /* We have not yet computed the alias set for this type. */ 905 TYPE_ALIAS_SET (t) = -1; 906 break; 907 908 case tcc_constant: 909 TREE_CONSTANT (t) = 1; 910 break; 911 912 case tcc_expression: 913 switch (code) 914 { 915 case INIT_EXPR: 916 case MODIFY_EXPR: 917 case VA_ARG_EXPR: 918 case PREDECREMENT_EXPR: 919 case PREINCREMENT_EXPR: 920 case POSTDECREMENT_EXPR: 921 case POSTINCREMENT_EXPR: 922 /* All of these have side-effects, no matter what their 923 operands are. */ 924 TREE_SIDE_EFFECTS (t) = 1; 925 break; 926 927 default: 928 break; 929 } 930 break; 931 932 default: 933 /* Other classes need no special treatment. */ 934 break; 935 } 936 937 return t; 938 } 939 940 /* Return a new node with the same contents as NODE except that its 941 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */ 942 943 tree 944 copy_node_stat (tree node MEM_STAT_DECL) 945 { 946 tree t; 947 enum tree_code code = TREE_CODE (node); 948 size_t length; 949 950 gcc_assert (code != STATEMENT_LIST); 951 952 length = tree_size (node); 953 record_node_allocation_statistics (code, length); 954 t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT); 955 memcpy (t, node, length); 956 957 if (CODE_CONTAINS_STRUCT (code, TS_COMMON)) 958 TREE_CHAIN (t) = 0; 959 TREE_ASM_WRITTEN (t) = 0; 960 TREE_VISITED (t) = 0; 961 962 if (TREE_CODE_CLASS (code) == tcc_declaration) 963 { 964 if (code == DEBUG_EXPR_DECL) 965 DECL_UID (t) = --next_debug_decl_uid; 966 else 967 { 968 DECL_UID (t) = allocate_decl_uid (); 969 if (DECL_PT_UID_SET_P (node)) 970 SET_DECL_PT_UID (t, DECL_PT_UID (node)); 971 } 972 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL) 973 && DECL_HAS_VALUE_EXPR_P (node)) 974 { 975 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node)); 976 DECL_HAS_VALUE_EXPR_P (t) = 1; 977 } 978 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node)) 979 { 980 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node)); 981 DECL_HAS_INIT_PRIORITY_P (t) = 1; 982 } 983 if (TREE_CODE (node) == FUNCTION_DECL) 984 DECL_STRUCT_FUNCTION (t) = NULL; 985 } 986 else if (TREE_CODE_CLASS (code) == tcc_type) 987 { 988 TYPE_UID (t) = next_type_uid++; 989 /* The following is so that the debug code for 990 the copy is different from the original type. 991 The two statements usually duplicate each other 992 (because they clear fields of the same union), 993 but the optimizer should catch that. */ 994 TYPE_SYMTAB_POINTER (t) = 0; 995 TYPE_SYMTAB_ADDRESS (t) = 0; 996 997 /* Do not copy the values cache. */ 998 if (TYPE_CACHED_VALUES_P(t)) 999 { 1000 TYPE_CACHED_VALUES_P (t) = 0; 1001 TYPE_CACHED_VALUES (t) = NULL_TREE; 1002 } 1003 } 1004 1005 return t; 1006 } 1007 1008 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field. 1009 For example, this can copy a list made of TREE_LIST nodes. */ 1010 1011 tree 1012 copy_list (tree list) 1013 { 1014 tree head; 1015 tree prev, next; 1016 1017 if (list == 0) 1018 return 0; 1019 1020 head = prev = copy_node (list); 1021 next = TREE_CHAIN (list); 1022 while (next) 1023 { 1024 TREE_CHAIN (prev) = copy_node (next); 1025 prev = TREE_CHAIN (prev); 1026 next = TREE_CHAIN (next); 1027 } 1028 return head; 1029 } 1030 1031 1032 /* Create an INT_CST node with a LOW value sign extended to TYPE. */ 1033 1034 tree 1035 build_int_cst (tree type, HOST_WIDE_INT low) 1036 { 1037 /* Support legacy code. */ 1038 if (!type) 1039 type = integer_type_node; 1040 1041 return double_int_to_tree (type, double_int::from_shwi (low)); 1042 } 1043 1044 /* Create an INT_CST node with a LOW value sign extended to TYPE. */ 1045 1046 tree 1047 build_int_cst_type (tree type, HOST_WIDE_INT low) 1048 { 1049 gcc_assert (type); 1050 1051 return double_int_to_tree (type, double_int::from_shwi (low)); 1052 } 1053 1054 /* Constructs tree in type TYPE from with value given by CST. Signedness 1055 of CST is assumed to be the same as the signedness of TYPE. */ 1056 1057 tree 1058 double_int_to_tree (tree type, double_int cst) 1059 { 1060 bool sign_extended_type = !TYPE_UNSIGNED (type); 1061 1062 cst = cst.ext (TYPE_PRECISION (type), !sign_extended_type); 1063 1064 return build_int_cst_wide (type, cst.low, cst.high); 1065 } 1066 1067 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed 1068 to be the same as the signedness of TYPE. */ 1069 1070 bool 1071 double_int_fits_to_tree_p (const_tree type, double_int cst) 1072 { 1073 bool sign_extended_type = !TYPE_UNSIGNED (type); 1074 1075 double_int ext 1076 = cst.ext (TYPE_PRECISION (type), !sign_extended_type); 1077 1078 return cst == ext; 1079 } 1080 1081 /* We force the double_int CST to the range of the type TYPE by sign or 1082 zero extending it. OVERFLOWABLE indicates if we are interested in 1083 overflow of the value, when >0 we are only interested in signed 1084 overflow, for <0 we are interested in any overflow. OVERFLOWED 1085 indicates whether overflow has already occurred. CONST_OVERFLOWED 1086 indicates whether constant overflow has already occurred. We force 1087 T's value to be within range of T's type (by setting to 0 or 1 all 1088 the bits outside the type's range). We set TREE_OVERFLOWED if, 1089 OVERFLOWED is nonzero, 1090 or OVERFLOWABLE is >0 and signed overflow occurs 1091 or OVERFLOWABLE is <0 and any overflow occurs 1092 We return a new tree node for the extended double_int. The node 1093 is shared if no overflow flags are set. */ 1094 1095 1096 tree 1097 force_fit_type_double (tree type, double_int cst, int overflowable, 1098 bool overflowed) 1099 { 1100 bool sign_extended_type = !TYPE_UNSIGNED (type); 1101 1102 /* If we need to set overflow flags, return a new unshared node. */ 1103 if (overflowed || !double_int_fits_to_tree_p(type, cst)) 1104 { 1105 if (overflowed 1106 || overflowable < 0 1107 || (overflowable > 0 && sign_extended_type)) 1108 { 1109 tree t = make_node (INTEGER_CST); 1110 TREE_INT_CST (t) 1111 = cst.ext (TYPE_PRECISION (type), !sign_extended_type); 1112 TREE_TYPE (t) = type; 1113 TREE_OVERFLOW (t) = 1; 1114 return t; 1115 } 1116 } 1117 1118 /* Else build a shared node. */ 1119 return double_int_to_tree (type, cst); 1120 } 1121 1122 /* These are the hash table functions for the hash table of INTEGER_CST 1123 nodes of a sizetype. */ 1124 1125 /* Return the hash code code X, an INTEGER_CST. */ 1126 1127 static hashval_t 1128 int_cst_hash_hash (const void *x) 1129 { 1130 const_tree const t = (const_tree) x; 1131 1132 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t) 1133 ^ TYPE_UID (TREE_TYPE (t))); 1134 } 1135 1136 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node) 1137 is the same as that given by *Y, which is the same. */ 1138 1139 static int 1140 int_cst_hash_eq (const void *x, const void *y) 1141 { 1142 const_tree const xt = (const_tree) x; 1143 const_tree const yt = (const_tree) y; 1144 1145 return (TREE_TYPE (xt) == TREE_TYPE (yt) 1146 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt) 1147 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt)); 1148 } 1149 1150 /* Create an INT_CST node of TYPE and value HI:LOW. 1151 The returned node is always shared. For small integers we use a 1152 per-type vector cache, for larger ones we use a single hash table. */ 1153 1154 tree 1155 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) 1156 { 1157 tree t; 1158 int ix = -1; 1159 int limit = 0; 1160 1161 gcc_assert (type); 1162 1163 switch (TREE_CODE (type)) 1164 { 1165 case NULLPTR_TYPE: 1166 gcc_assert (hi == 0 && low == 0); 1167 /* Fallthru. */ 1168 1169 case POINTER_TYPE: 1170 case REFERENCE_TYPE: 1171 /* Cache NULL pointer. */ 1172 if (!hi && !low) 1173 { 1174 limit = 1; 1175 ix = 0; 1176 } 1177 break; 1178 1179 case BOOLEAN_TYPE: 1180 /* Cache false or true. */ 1181 limit = 2; 1182 if (!hi && low < 2) 1183 ix = low; 1184 break; 1185 1186 case INTEGER_TYPE: 1187 case OFFSET_TYPE: 1188 if (TYPE_UNSIGNED (type)) 1189 { 1190 /* Cache 0..N */ 1191 limit = INTEGER_SHARE_LIMIT; 1192 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) 1193 ix = low; 1194 } 1195 else 1196 { 1197 /* Cache -1..N */ 1198 limit = INTEGER_SHARE_LIMIT + 1; 1199 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) 1200 ix = low + 1; 1201 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1) 1202 ix = 0; 1203 } 1204 break; 1205 1206 case ENUMERAL_TYPE: 1207 break; 1208 1209 default: 1210 gcc_unreachable (); 1211 } 1212 1213 if (ix >= 0) 1214 { 1215 /* Look for it in the type's vector of small shared ints. */ 1216 if (!TYPE_CACHED_VALUES_P (type)) 1217 { 1218 TYPE_CACHED_VALUES_P (type) = 1; 1219 TYPE_CACHED_VALUES (type) = make_tree_vec (limit); 1220 } 1221 1222 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix); 1223 if (t) 1224 { 1225 /* Make sure no one is clobbering the shared constant. */ 1226 gcc_assert (TREE_TYPE (t) == type); 1227 gcc_assert (TREE_INT_CST_LOW (t) == low); 1228 gcc_assert (TREE_INT_CST_HIGH (t) == hi); 1229 } 1230 else 1231 { 1232 /* Create a new shared int. */ 1233 t = make_node (INTEGER_CST); 1234 1235 TREE_INT_CST_LOW (t) = low; 1236 TREE_INT_CST_HIGH (t) = hi; 1237 TREE_TYPE (t) = type; 1238 1239 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t; 1240 } 1241 } 1242 else 1243 { 1244 /* Use the cache of larger shared ints. */ 1245 void **slot; 1246 1247 TREE_INT_CST_LOW (int_cst_node) = low; 1248 TREE_INT_CST_HIGH (int_cst_node) = hi; 1249 TREE_TYPE (int_cst_node) = type; 1250 1251 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT); 1252 t = (tree) *slot; 1253 if (!t) 1254 { 1255 /* Insert this one into the hash table. */ 1256 t = int_cst_node; 1257 *slot = t; 1258 /* Make a new node for next time round. */ 1259 int_cst_node = make_node (INTEGER_CST); 1260 } 1261 } 1262 1263 return t; 1264 } 1265 1266 /* Builds an integer constant in TYPE such that lowest BITS bits are ones 1267 and the rest are zeros. */ 1268 1269 tree 1270 build_low_bits_mask (tree type, unsigned bits) 1271 { 1272 double_int mask; 1273 1274 gcc_assert (bits <= TYPE_PRECISION (type)); 1275 1276 if (bits == TYPE_PRECISION (type) 1277 && !TYPE_UNSIGNED (type)) 1278 /* Sign extended all-ones mask. */ 1279 mask = double_int_minus_one; 1280 else 1281 mask = double_int::mask (bits); 1282 1283 return build_int_cst_wide (type, mask.low, mask.high); 1284 } 1285 1286 /* Checks that X is integer constant that can be expressed in (unsigned) 1287 HOST_WIDE_INT without loss of precision. */ 1288 1289 bool 1290 cst_and_fits_in_hwi (const_tree x) 1291 { 1292 if (TREE_CODE (x) != INTEGER_CST) 1293 return false; 1294 1295 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT) 1296 return false; 1297 1298 return (TREE_INT_CST_HIGH (x) == 0 1299 || TREE_INT_CST_HIGH (x) == -1); 1300 } 1301 1302 /* Build a newly constructed TREE_VEC node of length LEN. */ 1303 1304 tree 1305 make_vector_stat (unsigned len MEM_STAT_DECL) 1306 { 1307 tree t; 1308 unsigned length = (len - 1) * sizeof (tree) + sizeof (struct tree_vector); 1309 1310 record_node_allocation_statistics (VECTOR_CST, length); 1311 1312 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT); 1313 1314 TREE_SET_CODE (t, VECTOR_CST); 1315 TREE_CONSTANT (t) = 1; 1316 1317 return t; 1318 } 1319 1320 /* Return a new VECTOR_CST node whose type is TYPE and whose values 1321 are in a list pointed to by VALS. */ 1322 1323 tree 1324 build_vector_stat (tree type, tree *vals MEM_STAT_DECL) 1325 { 1326 int over = 0; 1327 unsigned cnt = 0; 1328 tree v = make_vector (TYPE_VECTOR_SUBPARTS (type)); 1329 TREE_TYPE (v) = type; 1330 1331 /* Iterate through elements and check for overflow. */ 1332 for (cnt = 0; cnt < TYPE_VECTOR_SUBPARTS (type); ++cnt) 1333 { 1334 tree value = vals[cnt]; 1335 1336 VECTOR_CST_ELT (v, cnt) = value; 1337 1338 /* Don't crash if we get an address constant. */ 1339 if (!CONSTANT_CLASS_P (value)) 1340 continue; 1341 1342 over |= TREE_OVERFLOW (value); 1343 } 1344 1345 TREE_OVERFLOW (v) = over; 1346 return v; 1347 } 1348 1349 /* Return a new VECTOR_CST node whose type is TYPE and whose values 1350 are extracted from V, a vector of CONSTRUCTOR_ELT. */ 1351 1352 tree 1353 build_vector_from_ctor (tree type, vec<constructor_elt, va_gc> *v) 1354 { 1355 tree *vec = XALLOCAVEC (tree, TYPE_VECTOR_SUBPARTS (type)); 1356 unsigned HOST_WIDE_INT idx; 1357 tree value; 1358 1359 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) 1360 vec[idx] = value; 1361 for (; idx < TYPE_VECTOR_SUBPARTS (type); ++idx) 1362 vec[idx] = build_zero_cst (TREE_TYPE (type)); 1363 1364 return build_vector (type, vec); 1365 } 1366 1367 /* Build a vector of type VECTYPE where all the elements are SCs. */ 1368 tree 1369 build_vector_from_val (tree vectype, tree sc) 1370 { 1371 int i, nunits = TYPE_VECTOR_SUBPARTS (vectype); 1372 1373 if (sc == error_mark_node) 1374 return sc; 1375 1376 /* Verify that the vector type is suitable for SC. Note that there 1377 is some inconsistency in the type-system with respect to restrict 1378 qualifications of pointers. Vector types always have a main-variant 1379 element type and the qualification is applied to the vector-type. 1380 So TREE_TYPE (vector-type) does not return a properly qualified 1381 vector element-type. */ 1382 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)), 1383 TREE_TYPE (vectype))); 1384 1385 if (CONSTANT_CLASS_P (sc)) 1386 { 1387 tree *v = XALLOCAVEC (tree, nunits); 1388 for (i = 0; i < nunits; ++i) 1389 v[i] = sc; 1390 return build_vector (vectype, v); 1391 } 1392 else 1393 { 1394 vec<constructor_elt, va_gc> *v; 1395 vec_alloc (v, nunits); 1396 for (i = 0; i < nunits; ++i) 1397 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc); 1398 return build_constructor (vectype, v); 1399 } 1400 } 1401 1402 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values 1403 are in the vec pointed to by VALS. */ 1404 tree 1405 build_constructor (tree type, vec<constructor_elt, va_gc> *vals) 1406 { 1407 tree c = make_node (CONSTRUCTOR); 1408 unsigned int i; 1409 constructor_elt *elt; 1410 bool constant_p = true; 1411 bool side_effects_p = false; 1412 1413 TREE_TYPE (c) = type; 1414 CONSTRUCTOR_ELTS (c) = vals; 1415 1416 FOR_EACH_VEC_SAFE_ELT (vals, i, elt) 1417 { 1418 /* Mostly ctors will have elts that don't have side-effects, so 1419 the usual case is to scan all the elements. Hence a single 1420 loop for both const and side effects, rather than one loop 1421 each (with early outs). */ 1422 if (!TREE_CONSTANT (elt->value)) 1423 constant_p = false; 1424 if (TREE_SIDE_EFFECTS (elt->value)) 1425 side_effects_p = true; 1426 } 1427 1428 TREE_SIDE_EFFECTS (c) = side_effects_p; 1429 TREE_CONSTANT (c) = constant_p; 1430 1431 return c; 1432 } 1433 1434 /* Build a CONSTRUCTOR node made of a single initializer, with the specified 1435 INDEX and VALUE. */ 1436 tree 1437 build_constructor_single (tree type, tree index, tree value) 1438 { 1439 vec<constructor_elt, va_gc> *v; 1440 constructor_elt elt = {index, value}; 1441 1442 vec_alloc (v, 1); 1443 v->quick_push (elt); 1444 1445 return build_constructor (type, v); 1446 } 1447 1448 1449 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values 1450 are in a list pointed to by VALS. */ 1451 tree 1452 build_constructor_from_list (tree type, tree vals) 1453 { 1454 tree t; 1455 vec<constructor_elt, va_gc> *v = NULL; 1456 1457 if (vals) 1458 { 1459 vec_alloc (v, list_length (vals)); 1460 for (t = vals; t; t = TREE_CHAIN (t)) 1461 CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t)); 1462 } 1463 1464 return build_constructor (type, v); 1465 } 1466 1467 /* Return a new FIXED_CST node whose type is TYPE and value is F. */ 1468 1469 tree 1470 build_fixed (tree type, FIXED_VALUE_TYPE f) 1471 { 1472 tree v; 1473 FIXED_VALUE_TYPE *fp; 1474 1475 v = make_node (FIXED_CST); 1476 fp = ggc_alloc_fixed_value (); 1477 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE)); 1478 1479 TREE_TYPE (v) = type; 1480 TREE_FIXED_CST_PTR (v) = fp; 1481 return v; 1482 } 1483 1484 /* Return a new REAL_CST node whose type is TYPE and value is D. */ 1485 1486 tree 1487 build_real (tree type, REAL_VALUE_TYPE d) 1488 { 1489 tree v; 1490 REAL_VALUE_TYPE *dp; 1491 int overflow = 0; 1492 1493 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE. 1494 Consider doing it via real_convert now. */ 1495 1496 v = make_node (REAL_CST); 1497 dp = ggc_alloc_real_value (); 1498 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE)); 1499 1500 TREE_TYPE (v) = type; 1501 TREE_REAL_CST_PTR (v) = dp; 1502 TREE_OVERFLOW (v) = overflow; 1503 return v; 1504 } 1505 1506 /* Return a new REAL_CST node whose type is TYPE 1507 and whose value is the integer value of the INTEGER_CST node I. */ 1508 1509 REAL_VALUE_TYPE 1510 real_value_from_int_cst (const_tree type, const_tree i) 1511 { 1512 REAL_VALUE_TYPE d; 1513 1514 /* Clear all bits of the real value type so that we can later do 1515 bitwise comparisons to see if two values are the same. */ 1516 memset (&d, 0, sizeof d); 1517 1518 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, 1519 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i), 1520 TYPE_UNSIGNED (TREE_TYPE (i))); 1521 return d; 1522 } 1523 1524 /* Given a tree representing an integer constant I, return a tree 1525 representing the same value as a floating-point constant of type TYPE. */ 1526 1527 tree 1528 build_real_from_int_cst (tree type, const_tree i) 1529 { 1530 tree v; 1531 int overflow = TREE_OVERFLOW (i); 1532 1533 v = build_real (type, real_value_from_int_cst (type, i)); 1534 1535 TREE_OVERFLOW (v) |= overflow; 1536 return v; 1537 } 1538 1539 /* Return a newly constructed STRING_CST node whose value is 1540 the LEN characters at STR. 1541 Note that for a C string literal, LEN should include the trailing NUL. 1542 The TREE_TYPE is not initialized. */ 1543 1544 tree 1545 build_string (int len, const char *str) 1546 { 1547 tree s; 1548 size_t length; 1549 1550 /* Do not waste bytes provided by padding of struct tree_string. */ 1551 length = len + offsetof (struct tree_string, str) + 1; 1552 1553 record_node_allocation_statistics (STRING_CST, length); 1554 1555 s = ggc_alloc_tree_node (length); 1556 1557 memset (s, 0, sizeof (struct tree_typed)); 1558 TREE_SET_CODE (s, STRING_CST); 1559 TREE_CONSTANT (s) = 1; 1560 TREE_STRING_LENGTH (s) = len; 1561 memcpy (s->string.str, str, len); 1562 s->string.str[len] = '\0'; 1563 1564 return s; 1565 } 1566 1567 /* Return a newly constructed COMPLEX_CST node whose value is 1568 specified by the real and imaginary parts REAL and IMAG. 1569 Both REAL and IMAG should be constant nodes. TYPE, if specified, 1570 will be the type of the COMPLEX_CST; otherwise a new type will be made. */ 1571 1572 tree 1573 build_complex (tree type, tree real, tree imag) 1574 { 1575 tree t = make_node (COMPLEX_CST); 1576 1577 TREE_REALPART (t) = real; 1578 TREE_IMAGPART (t) = imag; 1579 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real)); 1580 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag); 1581 return t; 1582 } 1583 1584 /* Return a constant of arithmetic type TYPE which is the 1585 multiplicative identity of the set TYPE. */ 1586 1587 tree 1588 build_one_cst (tree type) 1589 { 1590 switch (TREE_CODE (type)) 1591 { 1592 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: 1593 case POINTER_TYPE: case REFERENCE_TYPE: 1594 case OFFSET_TYPE: 1595 return build_int_cst (type, 1); 1596 1597 case REAL_TYPE: 1598 return build_real (type, dconst1); 1599 1600 case FIXED_POINT_TYPE: 1601 /* We can only generate 1 for accum types. */ 1602 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type))); 1603 return build_fixed (type, FCONST1(TYPE_MODE (type))); 1604 1605 case VECTOR_TYPE: 1606 { 1607 tree scalar = build_one_cst (TREE_TYPE (type)); 1608 1609 return build_vector_from_val (type, scalar); 1610 } 1611 1612 case COMPLEX_TYPE: 1613 return build_complex (type, 1614 build_one_cst (TREE_TYPE (type)), 1615 build_zero_cst (TREE_TYPE (type))); 1616 1617 default: 1618 gcc_unreachable (); 1619 } 1620 } 1621 1622 /* Return an integer of type TYPE containing all 1's in as much precision as 1623 it contains, or a complex or vector whose subparts are such integers. */ 1624 1625 tree 1626 build_all_ones_cst (tree type) 1627 { 1628 if (TREE_CODE (type) == COMPLEX_TYPE) 1629 { 1630 tree scalar = build_all_ones_cst (TREE_TYPE (type)); 1631 return build_complex (type, scalar, scalar); 1632 } 1633 else 1634 return build_minus_one_cst (type); 1635 } 1636 1637 /* Return a constant of arithmetic type TYPE which is the 1638 opposite of the multiplicative identity of the set TYPE. */ 1639 1640 tree 1641 build_minus_one_cst (tree type) 1642 { 1643 switch (TREE_CODE (type)) 1644 { 1645 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: 1646 case POINTER_TYPE: case REFERENCE_TYPE: 1647 case OFFSET_TYPE: 1648 return build_int_cst (type, -1); 1649 1650 case REAL_TYPE: 1651 return build_real (type, dconstm1); 1652 1653 case FIXED_POINT_TYPE: 1654 /* We can only generate 1 for accum types. */ 1655 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type))); 1656 return build_fixed (type, fixed_from_double_int (double_int_minus_one, 1657 TYPE_MODE (type))); 1658 1659 case VECTOR_TYPE: 1660 { 1661 tree scalar = build_minus_one_cst (TREE_TYPE (type)); 1662 1663 return build_vector_from_val (type, scalar); 1664 } 1665 1666 case COMPLEX_TYPE: 1667 return build_complex (type, 1668 build_minus_one_cst (TREE_TYPE (type)), 1669 build_zero_cst (TREE_TYPE (type))); 1670 1671 default: 1672 gcc_unreachable (); 1673 } 1674 } 1675 1676 /* Build 0 constant of type TYPE. This is used by constructor folding 1677 and thus the constant should be represented in memory by 1678 zero(es). */ 1679 1680 tree 1681 build_zero_cst (tree type) 1682 { 1683 switch (TREE_CODE (type)) 1684 { 1685 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: 1686 case POINTER_TYPE: case REFERENCE_TYPE: 1687 case OFFSET_TYPE: case NULLPTR_TYPE: 1688 return build_int_cst (type, 0); 1689 1690 case REAL_TYPE: 1691 return build_real (type, dconst0); 1692 1693 case FIXED_POINT_TYPE: 1694 return build_fixed (type, FCONST0 (TYPE_MODE (type))); 1695 1696 case VECTOR_TYPE: 1697 { 1698 tree scalar = build_zero_cst (TREE_TYPE (type)); 1699 1700 return build_vector_from_val (type, scalar); 1701 } 1702 1703 case COMPLEX_TYPE: 1704 { 1705 tree zero = build_zero_cst (TREE_TYPE (type)); 1706 1707 return build_complex (type, zero, zero); 1708 } 1709 1710 default: 1711 if (!AGGREGATE_TYPE_P (type)) 1712 return fold_convert (type, integer_zero_node); 1713 return build_constructor (type, NULL); 1714 } 1715 } 1716 1717 1718 /* Build a BINFO with LEN language slots. */ 1719 1720 tree 1721 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL) 1722 { 1723 tree t; 1724 size_t length = (offsetof (struct tree_binfo, base_binfos) 1725 + vec<tree, va_gc>::embedded_size (base_binfos)); 1726 1727 record_node_allocation_statistics (TREE_BINFO, length); 1728 1729 t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT); 1730 1731 memset (t, 0, offsetof (struct tree_binfo, base_binfos)); 1732 1733 TREE_SET_CODE (t, TREE_BINFO); 1734 1735 BINFO_BASE_BINFOS (t)->embedded_init (base_binfos); 1736 1737 return t; 1738 } 1739 1740 /* Create a CASE_LABEL_EXPR tree node and return it. */ 1741 1742 tree 1743 build_case_label (tree low_value, tree high_value, tree label_decl) 1744 { 1745 tree t = make_node (CASE_LABEL_EXPR); 1746 1747 TREE_TYPE (t) = void_type_node; 1748 SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl)); 1749 1750 CASE_LOW (t) = low_value; 1751 CASE_HIGH (t) = high_value; 1752 CASE_LABEL (t) = label_decl; 1753 CASE_CHAIN (t) = NULL_TREE; 1754 1755 return t; 1756 } 1757 1758 /* Build a newly constructed TREE_VEC node of length LEN. */ 1759 1760 tree 1761 make_tree_vec_stat (int len MEM_STAT_DECL) 1762 { 1763 tree t; 1764 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec); 1765 1766 record_node_allocation_statistics (TREE_VEC, length); 1767 1768 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT); 1769 1770 TREE_SET_CODE (t, TREE_VEC); 1771 TREE_VEC_LENGTH (t) = len; 1772 1773 return t; 1774 } 1775 1776 /* Return 1 if EXPR is the integer constant zero or a complex constant 1777 of zero. */ 1778 1779 int 1780 integer_zerop (const_tree expr) 1781 { 1782 STRIP_NOPS (expr); 1783 1784 switch (TREE_CODE (expr)) 1785 { 1786 case INTEGER_CST: 1787 return (TREE_INT_CST_LOW (expr) == 0 1788 && TREE_INT_CST_HIGH (expr) == 0); 1789 case COMPLEX_CST: 1790 return (integer_zerop (TREE_REALPART (expr)) 1791 && integer_zerop (TREE_IMAGPART (expr))); 1792 case VECTOR_CST: 1793 { 1794 unsigned i; 1795 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 1796 if (!integer_zerop (VECTOR_CST_ELT (expr, i))) 1797 return false; 1798 return true; 1799 } 1800 default: 1801 return false; 1802 } 1803 } 1804 1805 /* Return 1 if EXPR is the integer constant one or the corresponding 1806 complex constant. */ 1807 1808 int 1809 integer_onep (const_tree expr) 1810 { 1811 STRIP_NOPS (expr); 1812 1813 switch (TREE_CODE (expr)) 1814 { 1815 case INTEGER_CST: 1816 return (TREE_INT_CST_LOW (expr) == 1 1817 && TREE_INT_CST_HIGH (expr) == 0); 1818 case COMPLEX_CST: 1819 return (integer_onep (TREE_REALPART (expr)) 1820 && integer_zerop (TREE_IMAGPART (expr))); 1821 case VECTOR_CST: 1822 { 1823 unsigned i; 1824 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 1825 if (!integer_onep (VECTOR_CST_ELT (expr, i))) 1826 return false; 1827 return true; 1828 } 1829 default: 1830 return false; 1831 } 1832 } 1833 1834 /* Return 1 if EXPR is an integer containing all 1's in as much precision as 1835 it contains. Likewise for the corresponding complex constant. */ 1836 1837 int 1838 integer_all_onesp (const_tree expr) 1839 { 1840 int prec; 1841 int uns; 1842 1843 STRIP_NOPS (expr); 1844 1845 if (TREE_CODE (expr) == COMPLEX_CST 1846 && integer_all_onesp (TREE_REALPART (expr)) 1847 && integer_zerop (TREE_IMAGPART (expr))) 1848 return 1; 1849 1850 else if (TREE_CODE (expr) == VECTOR_CST) 1851 { 1852 unsigned i; 1853 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 1854 if (!integer_all_onesp (VECTOR_CST_ELT (expr, i))) 1855 return 0; 1856 return 1; 1857 } 1858 1859 else if (TREE_CODE (expr) != INTEGER_CST) 1860 return 0; 1861 1862 uns = TYPE_UNSIGNED (TREE_TYPE (expr)); 1863 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 1864 && TREE_INT_CST_HIGH (expr) == -1) 1865 return 1; 1866 if (!uns) 1867 return 0; 1868 1869 prec = TYPE_PRECISION (TREE_TYPE (expr)); 1870 if (prec >= HOST_BITS_PER_WIDE_INT) 1871 { 1872 HOST_WIDE_INT high_value; 1873 int shift_amount; 1874 1875 shift_amount = prec - HOST_BITS_PER_WIDE_INT; 1876 1877 /* Can not handle precisions greater than twice the host int size. */ 1878 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT); 1879 if (shift_amount == HOST_BITS_PER_WIDE_INT) 1880 /* Shifting by the host word size is undefined according to the ANSI 1881 standard, so we must handle this as a special case. */ 1882 high_value = -1; 1883 else 1884 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1; 1885 1886 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 1887 && TREE_INT_CST_HIGH (expr) == high_value); 1888 } 1889 else 1890 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; 1891 } 1892 1893 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only 1894 one bit on). */ 1895 1896 int 1897 integer_pow2p (const_tree expr) 1898 { 1899 int prec; 1900 unsigned HOST_WIDE_INT high, low; 1901 1902 STRIP_NOPS (expr); 1903 1904 if (TREE_CODE (expr) == COMPLEX_CST 1905 && integer_pow2p (TREE_REALPART (expr)) 1906 && integer_zerop (TREE_IMAGPART (expr))) 1907 return 1; 1908 1909 if (TREE_CODE (expr) != INTEGER_CST) 1910 return 0; 1911 1912 prec = TYPE_PRECISION (TREE_TYPE (expr)); 1913 high = TREE_INT_CST_HIGH (expr); 1914 low = TREE_INT_CST_LOW (expr); 1915 1916 /* First clear all bits that are beyond the type's precision in case 1917 we've been sign extended. */ 1918 1919 if (prec == HOST_BITS_PER_DOUBLE_INT) 1920 ; 1921 else if (prec > HOST_BITS_PER_WIDE_INT) 1922 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); 1923 else 1924 { 1925 high = 0; 1926 if (prec < HOST_BITS_PER_WIDE_INT) 1927 low &= ~((HOST_WIDE_INT) (-1) << prec); 1928 } 1929 1930 if (high == 0 && low == 0) 1931 return 0; 1932 1933 return ((high == 0 && (low & (low - 1)) == 0) 1934 || (low == 0 && (high & (high - 1)) == 0)); 1935 } 1936 1937 /* Return 1 if EXPR is an integer constant other than zero or a 1938 complex constant other than zero. */ 1939 1940 int 1941 integer_nonzerop (const_tree expr) 1942 { 1943 STRIP_NOPS (expr); 1944 1945 return ((TREE_CODE (expr) == INTEGER_CST 1946 && (TREE_INT_CST_LOW (expr) != 0 1947 || TREE_INT_CST_HIGH (expr) != 0)) 1948 || (TREE_CODE (expr) == COMPLEX_CST 1949 && (integer_nonzerop (TREE_REALPART (expr)) 1950 || integer_nonzerop (TREE_IMAGPART (expr))))); 1951 } 1952 1953 /* Return 1 if EXPR is the fixed-point constant zero. */ 1954 1955 int 1956 fixed_zerop (const_tree expr) 1957 { 1958 return (TREE_CODE (expr) == FIXED_CST 1959 && TREE_FIXED_CST (expr).data.is_zero ()); 1960 } 1961 1962 /* Return the power of two represented by a tree node known to be a 1963 power of two. */ 1964 1965 int 1966 tree_log2 (const_tree expr) 1967 { 1968 int prec; 1969 HOST_WIDE_INT high, low; 1970 1971 STRIP_NOPS (expr); 1972 1973 if (TREE_CODE (expr) == COMPLEX_CST) 1974 return tree_log2 (TREE_REALPART (expr)); 1975 1976 prec = TYPE_PRECISION (TREE_TYPE (expr)); 1977 high = TREE_INT_CST_HIGH (expr); 1978 low = TREE_INT_CST_LOW (expr); 1979 1980 /* First clear all bits that are beyond the type's precision in case 1981 we've been sign extended. */ 1982 1983 if (prec == HOST_BITS_PER_DOUBLE_INT) 1984 ; 1985 else if (prec > HOST_BITS_PER_WIDE_INT) 1986 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); 1987 else 1988 { 1989 high = 0; 1990 if (prec < HOST_BITS_PER_WIDE_INT) 1991 low &= ~((HOST_WIDE_INT) (-1) << prec); 1992 } 1993 1994 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high) 1995 : exact_log2 (low)); 1996 } 1997 1998 /* Similar, but return the largest integer Y such that 2 ** Y is less 1999 than or equal to EXPR. */ 2000 2001 int 2002 tree_floor_log2 (const_tree expr) 2003 { 2004 int prec; 2005 HOST_WIDE_INT high, low; 2006 2007 STRIP_NOPS (expr); 2008 2009 if (TREE_CODE (expr) == COMPLEX_CST) 2010 return tree_log2 (TREE_REALPART (expr)); 2011 2012 prec = TYPE_PRECISION (TREE_TYPE (expr)); 2013 high = TREE_INT_CST_HIGH (expr); 2014 low = TREE_INT_CST_LOW (expr); 2015 2016 /* First clear all bits that are beyond the type's precision in case 2017 we've been sign extended. Ignore if type's precision hasn't been set 2018 since what we are doing is setting it. */ 2019 2020 if (prec == HOST_BITS_PER_DOUBLE_INT || prec == 0) 2021 ; 2022 else if (prec > HOST_BITS_PER_WIDE_INT) 2023 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); 2024 else 2025 { 2026 high = 0; 2027 if (prec < HOST_BITS_PER_WIDE_INT) 2028 low &= ~((HOST_WIDE_INT) (-1) << prec); 2029 } 2030 2031 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high) 2032 : floor_log2 (low)); 2033 } 2034 2035 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for 2036 decimal float constants, so don't return 1 for them. */ 2037 2038 int 2039 real_zerop (const_tree expr) 2040 { 2041 STRIP_NOPS (expr); 2042 2043 switch (TREE_CODE (expr)) 2044 { 2045 case REAL_CST: 2046 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0) 2047 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))); 2048 case COMPLEX_CST: 2049 return real_zerop (TREE_REALPART (expr)) 2050 && real_zerop (TREE_IMAGPART (expr)); 2051 case VECTOR_CST: 2052 { 2053 unsigned i; 2054 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2055 if (!real_zerop (VECTOR_CST_ELT (expr, i))) 2056 return false; 2057 return true; 2058 } 2059 default: 2060 return false; 2061 } 2062 } 2063 2064 /* Return 1 if EXPR is the real constant one in real or complex form. 2065 Trailing zeroes matter for decimal float constants, so don't return 2066 1 for them. */ 2067 2068 int 2069 real_onep (const_tree expr) 2070 { 2071 STRIP_NOPS (expr); 2072 2073 switch (TREE_CODE (expr)) 2074 { 2075 case REAL_CST: 2076 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1) 2077 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))); 2078 case COMPLEX_CST: 2079 return real_onep (TREE_REALPART (expr)) 2080 && real_zerop (TREE_IMAGPART (expr)); 2081 case VECTOR_CST: 2082 { 2083 unsigned i; 2084 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2085 if (!real_onep (VECTOR_CST_ELT (expr, i))) 2086 return false; 2087 return true; 2088 } 2089 default: 2090 return false; 2091 } 2092 } 2093 2094 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter 2095 for decimal float constants, so don't return 1 for them. */ 2096 2097 int 2098 real_twop (const_tree expr) 2099 { 2100 STRIP_NOPS (expr); 2101 2102 switch (TREE_CODE (expr)) 2103 { 2104 case REAL_CST: 2105 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2) 2106 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))); 2107 case COMPLEX_CST: 2108 return real_twop (TREE_REALPART (expr)) 2109 && real_zerop (TREE_IMAGPART (expr)); 2110 case VECTOR_CST: 2111 { 2112 unsigned i; 2113 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2114 if (!real_twop (VECTOR_CST_ELT (expr, i))) 2115 return false; 2116 return true; 2117 } 2118 default: 2119 return false; 2120 } 2121 } 2122 2123 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes 2124 matter for decimal float constants, so don't return 1 for them. */ 2125 2126 int 2127 real_minus_onep (const_tree expr) 2128 { 2129 STRIP_NOPS (expr); 2130 2131 switch (TREE_CODE (expr)) 2132 { 2133 case REAL_CST: 2134 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1) 2135 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))); 2136 case COMPLEX_CST: 2137 return real_minus_onep (TREE_REALPART (expr)) 2138 && real_zerop (TREE_IMAGPART (expr)); 2139 case VECTOR_CST: 2140 { 2141 unsigned i; 2142 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2143 if (!real_minus_onep (VECTOR_CST_ELT (expr, i))) 2144 return false; 2145 return true; 2146 } 2147 default: 2148 return false; 2149 } 2150 } 2151 2152 /* Nonzero if EXP is a constant or a cast of a constant. */ 2153 2154 int 2155 really_constant_p (const_tree exp) 2156 { 2157 /* This is not quite the same as STRIP_NOPS. It does more. */ 2158 while (CONVERT_EXPR_P (exp) 2159 || TREE_CODE (exp) == NON_LVALUE_EXPR) 2160 exp = TREE_OPERAND (exp, 0); 2161 return TREE_CONSTANT (exp); 2162 } 2163 2164 /* Return first list element whose TREE_VALUE is ELEM. 2165 Return 0 if ELEM is not in LIST. */ 2166 2167 tree 2168 value_member (tree elem, tree list) 2169 { 2170 while (list) 2171 { 2172 if (elem == TREE_VALUE (list)) 2173 return list; 2174 list = TREE_CHAIN (list); 2175 } 2176 return NULL_TREE; 2177 } 2178 2179 /* Return first list element whose TREE_PURPOSE is ELEM. 2180 Return 0 if ELEM is not in LIST. */ 2181 2182 tree 2183 purpose_member (const_tree elem, tree list) 2184 { 2185 while (list) 2186 { 2187 if (elem == TREE_PURPOSE (list)) 2188 return list; 2189 list = TREE_CHAIN (list); 2190 } 2191 return NULL_TREE; 2192 } 2193 2194 /* Return true if ELEM is in V. */ 2195 2196 bool 2197 vec_member (const_tree elem, vec<tree, va_gc> *v) 2198 { 2199 unsigned ix; 2200 tree t; 2201 FOR_EACH_VEC_SAFE_ELT (v, ix, t) 2202 if (elem == t) 2203 return true; 2204 return false; 2205 } 2206 2207 /* Returns element number IDX (zero-origin) of chain CHAIN, or 2208 NULL_TREE. */ 2209 2210 tree 2211 chain_index (int idx, tree chain) 2212 { 2213 for (; chain && idx > 0; --idx) 2214 chain = TREE_CHAIN (chain); 2215 return chain; 2216 } 2217 2218 /* Return nonzero if ELEM is part of the chain CHAIN. */ 2219 2220 int 2221 chain_member (const_tree elem, const_tree chain) 2222 { 2223 while (chain) 2224 { 2225 if (elem == chain) 2226 return 1; 2227 chain = DECL_CHAIN (chain); 2228 } 2229 2230 return 0; 2231 } 2232 2233 /* Return the length of a chain of nodes chained through TREE_CHAIN. 2234 We expect a null pointer to mark the end of the chain. 2235 This is the Lisp primitive `length'. */ 2236 2237 int 2238 list_length (const_tree t) 2239 { 2240 const_tree p = t; 2241 #ifdef ENABLE_TREE_CHECKING 2242 const_tree q = t; 2243 #endif 2244 int len = 0; 2245 2246 while (p) 2247 { 2248 p = TREE_CHAIN (p); 2249 #ifdef ENABLE_TREE_CHECKING 2250 if (len % 2) 2251 q = TREE_CHAIN (q); 2252 gcc_assert (p != q); 2253 #endif 2254 len++; 2255 } 2256 2257 return len; 2258 } 2259 2260 /* Returns the number of FIELD_DECLs in TYPE. */ 2261 2262 int 2263 fields_length (const_tree type) 2264 { 2265 tree t = TYPE_FIELDS (type); 2266 int count = 0; 2267 2268 for (; t; t = DECL_CHAIN (t)) 2269 if (TREE_CODE (t) == FIELD_DECL) 2270 ++count; 2271 2272 return count; 2273 } 2274 2275 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or 2276 UNION_TYPE TYPE, or NULL_TREE if none. */ 2277 2278 tree 2279 first_field (const_tree type) 2280 { 2281 tree t = TYPE_FIELDS (type); 2282 while (t && TREE_CODE (t) != FIELD_DECL) 2283 t = TREE_CHAIN (t); 2284 return t; 2285 } 2286 2287 /* Concatenate two chains of nodes (chained through TREE_CHAIN) 2288 by modifying the last node in chain 1 to point to chain 2. 2289 This is the Lisp primitive `nconc'. */ 2290 2291 tree 2292 chainon (tree op1, tree op2) 2293 { 2294 tree t1; 2295 2296 if (!op1) 2297 return op2; 2298 if (!op2) 2299 return op1; 2300 2301 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1)) 2302 continue; 2303 TREE_CHAIN (t1) = op2; 2304 2305 #ifdef ENABLE_TREE_CHECKING 2306 { 2307 tree t2; 2308 for (t2 = op2; t2; t2 = TREE_CHAIN (t2)) 2309 gcc_assert (t2 != t1); 2310 } 2311 #endif 2312 2313 return op1; 2314 } 2315 2316 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */ 2317 2318 tree 2319 tree_last (tree chain) 2320 { 2321 tree next; 2322 if (chain) 2323 while ((next = TREE_CHAIN (chain))) 2324 chain = next; 2325 return chain; 2326 } 2327 2328 /* Reverse the order of elements in the chain T, 2329 and return the new head of the chain (old last element). */ 2330 2331 tree 2332 nreverse (tree t) 2333 { 2334 tree prev = 0, decl, next; 2335 for (decl = t; decl; decl = next) 2336 { 2337 /* We shouldn't be using this function to reverse BLOCK chains; we 2338 have blocks_nreverse for that. */ 2339 gcc_checking_assert (TREE_CODE (decl) != BLOCK); 2340 next = TREE_CHAIN (decl); 2341 TREE_CHAIN (decl) = prev; 2342 prev = decl; 2343 } 2344 return prev; 2345 } 2346 2347 /* Return a newly created TREE_LIST node whose 2348 purpose and value fields are PARM and VALUE. */ 2349 2350 tree 2351 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL) 2352 { 2353 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT); 2354 TREE_PURPOSE (t) = parm; 2355 TREE_VALUE (t) = value; 2356 return t; 2357 } 2358 2359 /* Build a chain of TREE_LIST nodes from a vector. */ 2360 2361 tree 2362 build_tree_list_vec_stat (const vec<tree, va_gc> *vec MEM_STAT_DECL) 2363 { 2364 tree ret = NULL_TREE; 2365 tree *pp = &ret; 2366 unsigned int i; 2367 tree t; 2368 FOR_EACH_VEC_SAFE_ELT (vec, i, t) 2369 { 2370 *pp = build_tree_list_stat (NULL, t PASS_MEM_STAT); 2371 pp = &TREE_CHAIN (*pp); 2372 } 2373 return ret; 2374 } 2375 2376 /* Return a newly created TREE_LIST node whose 2377 purpose and value fields are PURPOSE and VALUE 2378 and whose TREE_CHAIN is CHAIN. */ 2379 2380 tree 2381 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL) 2382 { 2383 tree node; 2384 2385 node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT); 2386 memset (node, 0, sizeof (struct tree_common)); 2387 2388 record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list)); 2389 2390 TREE_SET_CODE (node, TREE_LIST); 2391 TREE_CHAIN (node) = chain; 2392 TREE_PURPOSE (node) = purpose; 2393 TREE_VALUE (node) = value; 2394 return node; 2395 } 2396 2397 /* Return the values of the elements of a CONSTRUCTOR as a vector of 2398 trees. */ 2399 2400 vec<tree, va_gc> * 2401 ctor_to_vec (tree ctor) 2402 { 2403 vec<tree, va_gc> *vec; 2404 vec_alloc (vec, CONSTRUCTOR_NELTS (ctor)); 2405 unsigned int ix; 2406 tree val; 2407 2408 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val) 2409 vec->quick_push (val); 2410 2411 return vec; 2412 } 2413 2414 /* Return the size nominally occupied by an object of type TYPE 2415 when it resides in memory. The value is measured in units of bytes, 2416 and its data type is that normally used for type sizes 2417 (which is the first type created by make_signed_type or 2418 make_unsigned_type). */ 2419 2420 tree 2421 size_in_bytes (const_tree type) 2422 { 2423 tree t; 2424 2425 if (type == error_mark_node) 2426 return integer_zero_node; 2427 2428 type = TYPE_MAIN_VARIANT (type); 2429 t = TYPE_SIZE_UNIT (type); 2430 2431 if (t == 0) 2432 { 2433 lang_hooks.types.incomplete_type_error (NULL_TREE, type); 2434 return size_zero_node; 2435 } 2436 2437 return t; 2438 } 2439 2440 /* Return the size of TYPE (in bytes) as a wide integer 2441 or return -1 if the size can vary or is larger than an integer. */ 2442 2443 HOST_WIDE_INT 2444 int_size_in_bytes (const_tree type) 2445 { 2446 tree t; 2447 2448 if (type == error_mark_node) 2449 return 0; 2450 2451 type = TYPE_MAIN_VARIANT (type); 2452 t = TYPE_SIZE_UNIT (type); 2453 if (t == 0 2454 || TREE_CODE (t) != INTEGER_CST 2455 || TREE_INT_CST_HIGH (t) != 0 2456 /* If the result would appear negative, it's too big to represent. */ 2457 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0) 2458 return -1; 2459 2460 return TREE_INT_CST_LOW (t); 2461 } 2462 2463 /* Return the maximum size of TYPE (in bytes) as a wide integer 2464 or return -1 if the size can vary or is larger than an integer. */ 2465 2466 HOST_WIDE_INT 2467 max_int_size_in_bytes (const_tree type) 2468 { 2469 HOST_WIDE_INT size = -1; 2470 tree size_tree; 2471 2472 /* If this is an array type, check for a possible MAX_SIZE attached. */ 2473 2474 if (TREE_CODE (type) == ARRAY_TYPE) 2475 { 2476 size_tree = TYPE_ARRAY_MAX_SIZE (type); 2477 2478 if (size_tree && host_integerp (size_tree, 1)) 2479 size = tree_low_cst (size_tree, 1); 2480 } 2481 2482 /* If we still haven't been able to get a size, see if the language 2483 can compute a maximum size. */ 2484 2485 if (size == -1) 2486 { 2487 size_tree = lang_hooks.types.max_size (type); 2488 2489 if (size_tree && host_integerp (size_tree, 1)) 2490 size = tree_low_cst (size_tree, 1); 2491 } 2492 2493 return size; 2494 } 2495 2496 /* Returns a tree for the size of EXP in bytes. */ 2497 2498 tree 2499 tree_expr_size (const_tree exp) 2500 { 2501 if (DECL_P (exp) 2502 && DECL_SIZE_UNIT (exp) != 0) 2503 return DECL_SIZE_UNIT (exp); 2504 else 2505 return size_in_bytes (TREE_TYPE (exp)); 2506 } 2507 2508 /* Return the bit position of FIELD, in bits from the start of the record. 2509 This is a tree of type bitsizetype. */ 2510 2511 tree 2512 bit_position (const_tree field) 2513 { 2514 return bit_from_pos (DECL_FIELD_OFFSET (field), 2515 DECL_FIELD_BIT_OFFSET (field)); 2516 } 2517 2518 /* Likewise, but return as an integer. It must be representable in 2519 that way (since it could be a signed value, we don't have the 2520 option of returning -1 like int_size_in_byte can. */ 2521 2522 HOST_WIDE_INT 2523 int_bit_position (const_tree field) 2524 { 2525 return tree_low_cst (bit_position (field), 0); 2526 } 2527 2528 /* Return the byte position of FIELD, in bytes from the start of the record. 2529 This is a tree of type sizetype. */ 2530 2531 tree 2532 byte_position (const_tree field) 2533 { 2534 return byte_from_pos (DECL_FIELD_OFFSET (field), 2535 DECL_FIELD_BIT_OFFSET (field)); 2536 } 2537 2538 /* Likewise, but return as an integer. It must be representable in 2539 that way (since it could be a signed value, we don't have the 2540 option of returning -1 like int_size_in_byte can. */ 2541 2542 HOST_WIDE_INT 2543 int_byte_position (const_tree field) 2544 { 2545 return tree_low_cst (byte_position (field), 0); 2546 } 2547 2548 /* Return the strictest alignment, in bits, that T is known to have. */ 2549 2550 unsigned int 2551 expr_align (const_tree t) 2552 { 2553 unsigned int align0, align1; 2554 2555 switch (TREE_CODE (t)) 2556 { 2557 CASE_CONVERT: case NON_LVALUE_EXPR: 2558 /* If we have conversions, we know that the alignment of the 2559 object must meet each of the alignments of the types. */ 2560 align0 = expr_align (TREE_OPERAND (t, 0)); 2561 align1 = TYPE_ALIGN (TREE_TYPE (t)); 2562 return MAX (align0, align1); 2563 2564 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR: 2565 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR: 2566 case CLEANUP_POINT_EXPR: 2567 /* These don't change the alignment of an object. */ 2568 return expr_align (TREE_OPERAND (t, 0)); 2569 2570 case COND_EXPR: 2571 /* The best we can do is say that the alignment is the least aligned 2572 of the two arms. */ 2573 align0 = expr_align (TREE_OPERAND (t, 1)); 2574 align1 = expr_align (TREE_OPERAND (t, 2)); 2575 return MIN (align0, align1); 2576 2577 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set 2578 meaningfully, it's always 1. */ 2579 case LABEL_DECL: case CONST_DECL: 2580 case VAR_DECL: case PARM_DECL: case RESULT_DECL: 2581 case FUNCTION_DECL: 2582 gcc_assert (DECL_ALIGN (t) != 0); 2583 return DECL_ALIGN (t); 2584 2585 default: 2586 break; 2587 } 2588 2589 /* Otherwise take the alignment from that of the type. */ 2590 return TYPE_ALIGN (TREE_TYPE (t)); 2591 } 2592 2593 /* Return, as a tree node, the number of elements for TYPE (which is an 2594 ARRAY_TYPE) minus one. This counts only elements of the top array. */ 2595 2596 tree 2597 array_type_nelts (const_tree type) 2598 { 2599 tree index_type, min, max; 2600 2601 /* If they did it with unspecified bounds, then we should have already 2602 given an error about it before we got here. */ 2603 if (! TYPE_DOMAIN (type)) 2604 return error_mark_node; 2605 2606 index_type = TYPE_DOMAIN (type); 2607 min = TYPE_MIN_VALUE (index_type); 2608 max = TYPE_MAX_VALUE (index_type); 2609 2610 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */ 2611 if (!max) 2612 return error_mark_node; 2613 2614 return (integer_zerop (min) 2615 ? max 2616 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min)); 2617 } 2618 2619 /* If arg is static -- a reference to an object in static storage -- then 2620 return the object. This is not the same as the C meaning of `static'. 2621 If arg isn't static, return NULL. */ 2622 2623 tree 2624 staticp (tree arg) 2625 { 2626 switch (TREE_CODE (arg)) 2627 { 2628 case FUNCTION_DECL: 2629 /* Nested functions are static, even though taking their address will 2630 involve a trampoline as we unnest the nested function and create 2631 the trampoline on the tree level. */ 2632 return arg; 2633 2634 case VAR_DECL: 2635 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) 2636 && ! DECL_THREAD_LOCAL_P (arg) 2637 && ! DECL_DLLIMPORT_P (arg) 2638 ? arg : NULL); 2639 2640 case CONST_DECL: 2641 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) 2642 ? arg : NULL); 2643 2644 case CONSTRUCTOR: 2645 return TREE_STATIC (arg) ? arg : NULL; 2646 2647 case LABEL_DECL: 2648 case STRING_CST: 2649 return arg; 2650 2651 case COMPONENT_REF: 2652 /* If the thing being referenced is not a field, then it is 2653 something language specific. */ 2654 gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL); 2655 2656 /* If we are referencing a bitfield, we can't evaluate an 2657 ADDR_EXPR at compile time and so it isn't a constant. */ 2658 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1))) 2659 return NULL; 2660 2661 return staticp (TREE_OPERAND (arg, 0)); 2662 2663 case BIT_FIELD_REF: 2664 return NULL; 2665 2666 case INDIRECT_REF: 2667 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL; 2668 2669 case ARRAY_REF: 2670 case ARRAY_RANGE_REF: 2671 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST 2672 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) 2673 return staticp (TREE_OPERAND (arg, 0)); 2674 else 2675 return NULL; 2676 2677 case COMPOUND_LITERAL_EXPR: 2678 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL; 2679 2680 default: 2681 return NULL; 2682 } 2683 } 2684 2685 2686 2687 2688 /* Return whether OP is a DECL whose address is function-invariant. */ 2689 2690 bool 2691 decl_address_invariant_p (const_tree op) 2692 { 2693 /* The conditions below are slightly less strict than the one in 2694 staticp. */ 2695 2696 switch (TREE_CODE (op)) 2697 { 2698 case PARM_DECL: 2699 case RESULT_DECL: 2700 case LABEL_DECL: 2701 case FUNCTION_DECL: 2702 return true; 2703 2704 case VAR_DECL: 2705 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)) 2706 || DECL_THREAD_LOCAL_P (op) 2707 || DECL_CONTEXT (op) == current_function_decl 2708 || decl_function_context (op) == current_function_decl) 2709 return true; 2710 break; 2711 2712 case CONST_DECL: 2713 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)) 2714 || decl_function_context (op) == current_function_decl) 2715 return true; 2716 break; 2717 2718 default: 2719 break; 2720 } 2721 2722 return false; 2723 } 2724 2725 /* Return whether OP is a DECL whose address is interprocedural-invariant. */ 2726 2727 bool 2728 decl_address_ip_invariant_p (const_tree op) 2729 { 2730 /* The conditions below are slightly less strict than the one in 2731 staticp. */ 2732 2733 switch (TREE_CODE (op)) 2734 { 2735 case LABEL_DECL: 2736 case FUNCTION_DECL: 2737 case STRING_CST: 2738 return true; 2739 2740 case VAR_DECL: 2741 if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) 2742 && !DECL_DLLIMPORT_P (op)) 2743 || DECL_THREAD_LOCAL_P (op)) 2744 return true; 2745 break; 2746 2747 case CONST_DECL: 2748 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))) 2749 return true; 2750 break; 2751 2752 default: 2753 break; 2754 } 2755 2756 return false; 2757 } 2758 2759 2760 /* Return true if T is function-invariant (internal function, does 2761 not handle arithmetic; that's handled in skip_simple_arithmetic and 2762 tree_invariant_p). */ 2763 2764 static bool tree_invariant_p (tree t); 2765 2766 static bool 2767 tree_invariant_p_1 (tree t) 2768 { 2769 tree op; 2770 2771 if (TREE_CONSTANT (t) 2772 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t))) 2773 return true; 2774 2775 switch (TREE_CODE (t)) 2776 { 2777 case SAVE_EXPR: 2778 return true; 2779 2780 case ADDR_EXPR: 2781 op = TREE_OPERAND (t, 0); 2782 while (handled_component_p (op)) 2783 { 2784 switch (TREE_CODE (op)) 2785 { 2786 case ARRAY_REF: 2787 case ARRAY_RANGE_REF: 2788 if (!tree_invariant_p (TREE_OPERAND (op, 1)) 2789 || TREE_OPERAND (op, 2) != NULL_TREE 2790 || TREE_OPERAND (op, 3) != NULL_TREE) 2791 return false; 2792 break; 2793 2794 case COMPONENT_REF: 2795 if (TREE_OPERAND (op, 2) != NULL_TREE) 2796 return false; 2797 break; 2798 2799 default:; 2800 } 2801 op = TREE_OPERAND (op, 0); 2802 } 2803 2804 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op); 2805 2806 default: 2807 break; 2808 } 2809 2810 return false; 2811 } 2812 2813 /* Return true if T is function-invariant. */ 2814 2815 static bool 2816 tree_invariant_p (tree t) 2817 { 2818 tree inner = skip_simple_arithmetic (t); 2819 return tree_invariant_p_1 (inner); 2820 } 2821 2822 /* Wrap a SAVE_EXPR around EXPR, if appropriate. 2823 Do this to any expression which may be used in more than one place, 2824 but must be evaluated only once. 2825 2826 Normally, expand_expr would reevaluate the expression each time. 2827 Calling save_expr produces something that is evaluated and recorded 2828 the first time expand_expr is called on it. Subsequent calls to 2829 expand_expr just reuse the recorded value. 2830 2831 The call to expand_expr that generates code that actually computes 2832 the value is the first call *at compile time*. Subsequent calls 2833 *at compile time* generate code to use the saved value. 2834 This produces correct result provided that *at run time* control 2835 always flows through the insns made by the first expand_expr 2836 before reaching the other places where the save_expr was evaluated. 2837 You, the caller of save_expr, must make sure this is so. 2838 2839 Constants, and certain read-only nodes, are returned with no 2840 SAVE_EXPR because that is safe. Expressions containing placeholders 2841 are not touched; see tree.def for an explanation of what these 2842 are used for. */ 2843 2844 tree 2845 save_expr (tree expr) 2846 { 2847 tree t = fold (expr); 2848 tree inner; 2849 2850 /* If the tree evaluates to a constant, then we don't want to hide that 2851 fact (i.e. this allows further folding, and direct checks for constants). 2852 However, a read-only object that has side effects cannot be bypassed. 2853 Since it is no problem to reevaluate literals, we just return the 2854 literal node. */ 2855 inner = skip_simple_arithmetic (t); 2856 if (TREE_CODE (inner) == ERROR_MARK) 2857 return inner; 2858 2859 if (tree_invariant_p_1 (inner)) 2860 return t; 2861 2862 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since 2863 it means that the size or offset of some field of an object depends on 2864 the value within another field. 2865 2866 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR 2867 and some variable since it would then need to be both evaluated once and 2868 evaluated more than once. Front-ends must assure this case cannot 2869 happen by surrounding any such subexpressions in their own SAVE_EXPR 2870 and forcing evaluation at the proper time. */ 2871 if (contains_placeholder_p (inner)) 2872 return t; 2873 2874 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t); 2875 SET_EXPR_LOCATION (t, EXPR_LOCATION (expr)); 2876 2877 /* This expression might be placed ahead of a jump to ensure that the 2878 value was computed on both sides of the jump. So make sure it isn't 2879 eliminated as dead. */ 2880 TREE_SIDE_EFFECTS (t) = 1; 2881 return t; 2882 } 2883 2884 /* Look inside EXPR and into any simple arithmetic operations. Return 2885 the innermost non-arithmetic node. */ 2886 2887 tree 2888 skip_simple_arithmetic (tree expr) 2889 { 2890 tree inner; 2891 2892 /* We don't care about whether this can be used as an lvalue in this 2893 context. */ 2894 while (TREE_CODE (expr) == NON_LVALUE_EXPR) 2895 expr = TREE_OPERAND (expr, 0); 2896 2897 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and 2898 a constant, it will be more efficient to not make another SAVE_EXPR since 2899 it will allow better simplification and GCSE will be able to merge the 2900 computations if they actually occur. */ 2901 inner = expr; 2902 while (1) 2903 { 2904 if (UNARY_CLASS_P (inner)) 2905 inner = TREE_OPERAND (inner, 0); 2906 else if (BINARY_CLASS_P (inner)) 2907 { 2908 if (tree_invariant_p (TREE_OPERAND (inner, 1))) 2909 inner = TREE_OPERAND (inner, 0); 2910 else if (tree_invariant_p (TREE_OPERAND (inner, 0))) 2911 inner = TREE_OPERAND (inner, 1); 2912 else 2913 break; 2914 } 2915 else 2916 break; 2917 } 2918 2919 return inner; 2920 } 2921 2922 2923 /* Return which tree structure is used by T. */ 2924 2925 enum tree_node_structure_enum 2926 tree_node_structure (const_tree t) 2927 { 2928 const enum tree_code code = TREE_CODE (t); 2929 return tree_node_structure_for_code (code); 2930 } 2931 2932 /* Set various status flags when building a CALL_EXPR object T. */ 2933 2934 static void 2935 process_call_operands (tree t) 2936 { 2937 bool side_effects = TREE_SIDE_EFFECTS (t); 2938 bool read_only = false; 2939 int i = call_expr_flags (t); 2940 2941 /* Calls have side-effects, except those to const or pure functions. */ 2942 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE))) 2943 side_effects = true; 2944 /* Propagate TREE_READONLY of arguments for const functions. */ 2945 if (i & ECF_CONST) 2946 read_only = true; 2947 2948 if (!side_effects || read_only) 2949 for (i = 1; i < TREE_OPERAND_LENGTH (t); i++) 2950 { 2951 tree op = TREE_OPERAND (t, i); 2952 if (op && TREE_SIDE_EFFECTS (op)) 2953 side_effects = true; 2954 if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op)) 2955 read_only = false; 2956 } 2957 2958 TREE_SIDE_EFFECTS (t) = side_effects; 2959 TREE_READONLY (t) = read_only; 2960 } 2961 2962 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a 2963 size or offset that depends on a field within a record. */ 2964 2965 bool 2966 contains_placeholder_p (const_tree exp) 2967 { 2968 enum tree_code code; 2969 2970 if (!exp) 2971 return 0; 2972 2973 code = TREE_CODE (exp); 2974 if (code == PLACEHOLDER_EXPR) 2975 return 1; 2976 2977 switch (TREE_CODE_CLASS (code)) 2978 { 2979 case tcc_reference: 2980 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit 2981 position computations since they will be converted into a 2982 WITH_RECORD_EXPR involving the reference, which will assume 2983 here will be valid. */ 2984 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)); 2985 2986 case tcc_exceptional: 2987 if (code == TREE_LIST) 2988 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp)) 2989 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp))); 2990 break; 2991 2992 case tcc_unary: 2993 case tcc_binary: 2994 case tcc_comparison: 2995 case tcc_expression: 2996 switch (code) 2997 { 2998 case COMPOUND_EXPR: 2999 /* Ignoring the first operand isn't quite right, but works best. */ 3000 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)); 3001 3002 case COND_EXPR: 3003 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)) 3004 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)) 3005 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2))); 3006 3007 case SAVE_EXPR: 3008 /* The save_expr function never wraps anything containing 3009 a PLACEHOLDER_EXPR. */ 3010 return 0; 3011 3012 default: 3013 break; 3014 } 3015 3016 switch (TREE_CODE_LENGTH (code)) 3017 { 3018 case 1: 3019 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)); 3020 case 2: 3021 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)) 3022 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))); 3023 default: 3024 return 0; 3025 } 3026 3027 case tcc_vl_exp: 3028 switch (code) 3029 { 3030 case CALL_EXPR: 3031 { 3032 const_tree arg; 3033 const_call_expr_arg_iterator iter; 3034 FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp) 3035 if (CONTAINS_PLACEHOLDER_P (arg)) 3036 return 1; 3037 return 0; 3038 } 3039 default: 3040 return 0; 3041 } 3042 3043 default: 3044 return 0; 3045 } 3046 return 0; 3047 } 3048 3049 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR 3050 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and 3051 field positions. */ 3052 3053 static bool 3054 type_contains_placeholder_1 (const_tree type) 3055 { 3056 /* If the size contains a placeholder or the parent type (component type in 3057 the case of arrays) type involves a placeholder, this type does. */ 3058 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type)) 3059 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type)) 3060 || (!POINTER_TYPE_P (type) 3061 && TREE_TYPE (type) 3062 && type_contains_placeholder_p (TREE_TYPE (type)))) 3063 return true; 3064 3065 /* Now do type-specific checks. Note that the last part of the check above 3066 greatly limits what we have to do below. */ 3067 switch (TREE_CODE (type)) 3068 { 3069 case VOID_TYPE: 3070 case COMPLEX_TYPE: 3071 case ENUMERAL_TYPE: 3072 case BOOLEAN_TYPE: 3073 case POINTER_TYPE: 3074 case OFFSET_TYPE: 3075 case REFERENCE_TYPE: 3076 case METHOD_TYPE: 3077 case FUNCTION_TYPE: 3078 case VECTOR_TYPE: 3079 case NULLPTR_TYPE: 3080 return false; 3081 3082 case INTEGER_TYPE: 3083 case REAL_TYPE: 3084 case FIXED_POINT_TYPE: 3085 /* Here we just check the bounds. */ 3086 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type)) 3087 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type))); 3088 3089 case ARRAY_TYPE: 3090 /* We have already checked the component type above, so just check the 3091 domain type. */ 3092 return type_contains_placeholder_p (TYPE_DOMAIN (type)); 3093 3094 case RECORD_TYPE: 3095 case UNION_TYPE: 3096 case QUAL_UNION_TYPE: 3097 { 3098 tree field; 3099 3100 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) 3101 if (TREE_CODE (field) == FIELD_DECL 3102 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field)) 3103 || (TREE_CODE (type) == QUAL_UNION_TYPE 3104 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field))) 3105 || type_contains_placeholder_p (TREE_TYPE (field)))) 3106 return true; 3107 3108 return false; 3109 } 3110 3111 default: 3112 gcc_unreachable (); 3113 } 3114 } 3115 3116 /* Wrapper around above function used to cache its result. */ 3117 3118 bool 3119 type_contains_placeholder_p (tree type) 3120 { 3121 bool result; 3122 3123 /* If the contains_placeholder_bits field has been initialized, 3124 then we know the answer. */ 3125 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0) 3126 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1; 3127 3128 /* Indicate that we've seen this type node, and the answer is false. 3129 This is what we want to return if we run into recursion via fields. */ 3130 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1; 3131 3132 /* Compute the real value. */ 3133 result = type_contains_placeholder_1 (type); 3134 3135 /* Store the real value. */ 3136 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1; 3137 3138 return result; 3139 } 3140 3141 /* Push tree EXP onto vector QUEUE if it is not already present. */ 3142 3143 static void 3144 push_without_duplicates (tree exp, vec<tree> *queue) 3145 { 3146 unsigned int i; 3147 tree iter; 3148 3149 FOR_EACH_VEC_ELT (*queue, i, iter) 3150 if (simple_cst_equal (iter, exp) == 1) 3151 break; 3152 3153 if (!iter) 3154 queue->safe_push (exp); 3155 } 3156 3157 /* Given a tree EXP, find all occurrences of references to fields 3158 in a PLACEHOLDER_EXPR and place them in vector REFS without 3159 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that 3160 we assume here that EXP contains only arithmetic expressions 3161 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their 3162 argument list. */ 3163 3164 void 3165 find_placeholder_in_expr (tree exp, vec<tree> *refs) 3166 { 3167 enum tree_code code = TREE_CODE (exp); 3168 tree inner; 3169 int i; 3170 3171 /* We handle TREE_LIST and COMPONENT_REF separately. */ 3172 if (code == TREE_LIST) 3173 { 3174 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs); 3175 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs); 3176 } 3177 else if (code == COMPONENT_REF) 3178 { 3179 for (inner = TREE_OPERAND (exp, 0); 3180 REFERENCE_CLASS_P (inner); 3181 inner = TREE_OPERAND (inner, 0)) 3182 ; 3183 3184 if (TREE_CODE (inner) == PLACEHOLDER_EXPR) 3185 push_without_duplicates (exp, refs); 3186 else 3187 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs); 3188 } 3189 else 3190 switch (TREE_CODE_CLASS (code)) 3191 { 3192 case tcc_constant: 3193 break; 3194 3195 case tcc_declaration: 3196 /* Variables allocated to static storage can stay. */ 3197 if (!TREE_STATIC (exp)) 3198 push_without_duplicates (exp, refs); 3199 break; 3200 3201 case tcc_expression: 3202 /* This is the pattern built in ada/make_aligning_type. */ 3203 if (code == ADDR_EXPR 3204 && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR) 3205 { 3206 push_without_duplicates (exp, refs); 3207 break; 3208 } 3209 3210 /* Fall through... */ 3211 3212 case tcc_exceptional: 3213 case tcc_unary: 3214 case tcc_binary: 3215 case tcc_comparison: 3216 case tcc_reference: 3217 for (i = 0; i < TREE_CODE_LENGTH (code); i++) 3218 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs); 3219 break; 3220 3221 case tcc_vl_exp: 3222 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) 3223 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs); 3224 break; 3225 3226 default: 3227 gcc_unreachable (); 3228 } 3229 } 3230 3231 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R, 3232 return a tree with all occurrences of references to F in a 3233 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and 3234 CONST_DECLs. Note that we assume here that EXP contains only 3235 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs 3236 occurring only in their argument list. */ 3237 3238 tree 3239 substitute_in_expr (tree exp, tree f, tree r) 3240 { 3241 enum tree_code code = TREE_CODE (exp); 3242 tree op0, op1, op2, op3; 3243 tree new_tree; 3244 3245 /* We handle TREE_LIST and COMPONENT_REF separately. */ 3246 if (code == TREE_LIST) 3247 { 3248 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r); 3249 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r); 3250 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) 3251 return exp; 3252 3253 return tree_cons (TREE_PURPOSE (exp), op1, op0); 3254 } 3255 else if (code == COMPONENT_REF) 3256 { 3257 tree inner; 3258 3259 /* If this expression is getting a value from a PLACEHOLDER_EXPR 3260 and it is the right field, replace it with R. */ 3261 for (inner = TREE_OPERAND (exp, 0); 3262 REFERENCE_CLASS_P (inner); 3263 inner = TREE_OPERAND (inner, 0)) 3264 ; 3265 3266 /* The field. */ 3267 op1 = TREE_OPERAND (exp, 1); 3268 3269 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f) 3270 return r; 3271 3272 /* If this expression hasn't been completed let, leave it alone. */ 3273 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner)) 3274 return exp; 3275 3276 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); 3277 if (op0 == TREE_OPERAND (exp, 0)) 3278 return exp; 3279 3280 new_tree 3281 = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE); 3282 } 3283 else 3284 switch (TREE_CODE_CLASS (code)) 3285 { 3286 case tcc_constant: 3287 return exp; 3288 3289 case tcc_declaration: 3290 if (exp == f) 3291 return r; 3292 else 3293 return exp; 3294 3295 case tcc_expression: 3296 if (exp == f) 3297 return r; 3298 3299 /* Fall through... */ 3300 3301 case tcc_exceptional: 3302 case tcc_unary: 3303 case tcc_binary: 3304 case tcc_comparison: 3305 case tcc_reference: 3306 switch (TREE_CODE_LENGTH (code)) 3307 { 3308 case 0: 3309 return exp; 3310 3311 case 1: 3312 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); 3313 if (op0 == TREE_OPERAND (exp, 0)) 3314 return exp; 3315 3316 new_tree = fold_build1 (code, TREE_TYPE (exp), op0); 3317 break; 3318 3319 case 2: 3320 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); 3321 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r); 3322 3323 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) 3324 return exp; 3325 3326 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1); 3327 break; 3328 3329 case 3: 3330 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); 3331 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r); 3332 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r); 3333 3334 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3335 && op2 == TREE_OPERAND (exp, 2)) 3336 return exp; 3337 3338 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); 3339 break; 3340 3341 case 4: 3342 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); 3343 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r); 3344 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r); 3345 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r); 3346 3347 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3348 && op2 == TREE_OPERAND (exp, 2) 3349 && op3 == TREE_OPERAND (exp, 3)) 3350 return exp; 3351 3352 new_tree 3353 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); 3354 break; 3355 3356 default: 3357 gcc_unreachable (); 3358 } 3359 break; 3360 3361 case tcc_vl_exp: 3362 { 3363 int i; 3364 3365 new_tree = NULL_TREE; 3366 3367 /* If we are trying to replace F with a constant, inline back 3368 functions which do nothing else than computing a value from 3369 the arguments they are passed. This makes it possible to 3370 fold partially or entirely the replacement expression. */ 3371 if (CONSTANT_CLASS_P (r) && code == CALL_EXPR) 3372 { 3373 tree t = maybe_inline_call_in_expr (exp); 3374 if (t) 3375 return SUBSTITUTE_IN_EXPR (t, f, r); 3376 } 3377 3378 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) 3379 { 3380 tree op = TREE_OPERAND (exp, i); 3381 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r); 3382 if (new_op != op) 3383 { 3384 if (!new_tree) 3385 new_tree = copy_node (exp); 3386 TREE_OPERAND (new_tree, i) = new_op; 3387 } 3388 } 3389 3390 if (new_tree) 3391 { 3392 new_tree = fold (new_tree); 3393 if (TREE_CODE (new_tree) == CALL_EXPR) 3394 process_call_operands (new_tree); 3395 } 3396 else 3397 return exp; 3398 } 3399 break; 3400 3401 default: 3402 gcc_unreachable (); 3403 } 3404 3405 TREE_READONLY (new_tree) |= TREE_READONLY (exp); 3406 3407 if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF) 3408 TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp); 3409 3410 return new_tree; 3411 } 3412 3413 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement 3414 for it within OBJ, a tree that is an object or a chain of references. */ 3415 3416 tree 3417 substitute_placeholder_in_expr (tree exp, tree obj) 3418 { 3419 enum tree_code code = TREE_CODE (exp); 3420 tree op0, op1, op2, op3; 3421 tree new_tree; 3422 3423 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type 3424 in the chain of OBJ. */ 3425 if (code == PLACEHOLDER_EXPR) 3426 { 3427 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp)); 3428 tree elt; 3429 3430 for (elt = obj; elt != 0; 3431 elt = ((TREE_CODE (elt) == COMPOUND_EXPR 3432 || TREE_CODE (elt) == COND_EXPR) 3433 ? TREE_OPERAND (elt, 1) 3434 : (REFERENCE_CLASS_P (elt) 3435 || UNARY_CLASS_P (elt) 3436 || BINARY_CLASS_P (elt) 3437 || VL_EXP_CLASS_P (elt) 3438 || EXPRESSION_CLASS_P (elt)) 3439 ? TREE_OPERAND (elt, 0) : 0)) 3440 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type) 3441 return elt; 3442 3443 for (elt = obj; elt != 0; 3444 elt = ((TREE_CODE (elt) == COMPOUND_EXPR 3445 || TREE_CODE (elt) == COND_EXPR) 3446 ? TREE_OPERAND (elt, 1) 3447 : (REFERENCE_CLASS_P (elt) 3448 || UNARY_CLASS_P (elt) 3449 || BINARY_CLASS_P (elt) 3450 || VL_EXP_CLASS_P (elt) 3451 || EXPRESSION_CLASS_P (elt)) 3452 ? TREE_OPERAND (elt, 0) : 0)) 3453 if (POINTER_TYPE_P (TREE_TYPE (elt)) 3454 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt))) 3455 == need_type)) 3456 return fold_build1 (INDIRECT_REF, need_type, elt); 3457 3458 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it 3459 survives until RTL generation, there will be an error. */ 3460 return exp; 3461 } 3462 3463 /* TREE_LIST is special because we need to look at TREE_VALUE 3464 and TREE_CHAIN, not TREE_OPERANDS. */ 3465 else if (code == TREE_LIST) 3466 { 3467 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj); 3468 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj); 3469 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) 3470 return exp; 3471 3472 return tree_cons (TREE_PURPOSE (exp), op1, op0); 3473 } 3474 else 3475 switch (TREE_CODE_CLASS (code)) 3476 { 3477 case tcc_constant: 3478 case tcc_declaration: 3479 return exp; 3480 3481 case tcc_exceptional: 3482 case tcc_unary: 3483 case tcc_binary: 3484 case tcc_comparison: 3485 case tcc_expression: 3486 case tcc_reference: 3487 case tcc_statement: 3488 switch (TREE_CODE_LENGTH (code)) 3489 { 3490 case 0: 3491 return exp; 3492 3493 case 1: 3494 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3495 if (op0 == TREE_OPERAND (exp, 0)) 3496 return exp; 3497 3498 new_tree = fold_build1 (code, TREE_TYPE (exp), op0); 3499 break; 3500 3501 case 2: 3502 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3503 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); 3504 3505 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) 3506 return exp; 3507 3508 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1); 3509 break; 3510 3511 case 3: 3512 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3513 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); 3514 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); 3515 3516 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3517 && op2 == TREE_OPERAND (exp, 2)) 3518 return exp; 3519 3520 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); 3521 break; 3522 3523 case 4: 3524 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3525 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); 3526 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); 3527 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj); 3528 3529 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3530 && op2 == TREE_OPERAND (exp, 2) 3531 && op3 == TREE_OPERAND (exp, 3)) 3532 return exp; 3533 3534 new_tree 3535 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); 3536 break; 3537 3538 default: 3539 gcc_unreachable (); 3540 } 3541 break; 3542 3543 case tcc_vl_exp: 3544 { 3545 int i; 3546 3547 new_tree = NULL_TREE; 3548 3549 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) 3550 { 3551 tree op = TREE_OPERAND (exp, i); 3552 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj); 3553 if (new_op != op) 3554 { 3555 if (!new_tree) 3556 new_tree = copy_node (exp); 3557 TREE_OPERAND (new_tree, i) = new_op; 3558 } 3559 } 3560 3561 if (new_tree) 3562 { 3563 new_tree = fold (new_tree); 3564 if (TREE_CODE (new_tree) == CALL_EXPR) 3565 process_call_operands (new_tree); 3566 } 3567 else 3568 return exp; 3569 } 3570 break; 3571 3572 default: 3573 gcc_unreachable (); 3574 } 3575 3576 TREE_READONLY (new_tree) |= TREE_READONLY (exp); 3577 3578 if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF) 3579 TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp); 3580 3581 return new_tree; 3582 } 3583 3584 /* Stabilize a reference so that we can use it any number of times 3585 without causing its operands to be evaluated more than once. 3586 Returns the stabilized reference. This works by means of save_expr, 3587 so see the caveats in the comments about save_expr. 3588 3589 Also allows conversion expressions whose operands are references. 3590 Any other kind of expression is returned unchanged. */ 3591 3592 tree 3593 stabilize_reference (tree ref) 3594 { 3595 tree result; 3596 enum tree_code code = TREE_CODE (ref); 3597 3598 switch (code) 3599 { 3600 case VAR_DECL: 3601 case PARM_DECL: 3602 case RESULT_DECL: 3603 /* No action is needed in this case. */ 3604 return ref; 3605 3606 CASE_CONVERT: 3607 case FLOAT_EXPR: 3608 case FIX_TRUNC_EXPR: 3609 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0))); 3610 break; 3611 3612 case INDIRECT_REF: 3613 result = build_nt (INDIRECT_REF, 3614 stabilize_reference_1 (TREE_OPERAND (ref, 0))); 3615 break; 3616 3617 case COMPONENT_REF: 3618 result = build_nt (COMPONENT_REF, 3619 stabilize_reference (TREE_OPERAND (ref, 0)), 3620 TREE_OPERAND (ref, 1), NULL_TREE); 3621 break; 3622 3623 case BIT_FIELD_REF: 3624 result = build_nt (BIT_FIELD_REF, 3625 stabilize_reference (TREE_OPERAND (ref, 0)), 3626 TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2)); 3627 break; 3628 3629 case ARRAY_REF: 3630 result = build_nt (ARRAY_REF, 3631 stabilize_reference (TREE_OPERAND (ref, 0)), 3632 stabilize_reference_1 (TREE_OPERAND (ref, 1)), 3633 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3)); 3634 break; 3635 3636 case ARRAY_RANGE_REF: 3637 result = build_nt (ARRAY_RANGE_REF, 3638 stabilize_reference (TREE_OPERAND (ref, 0)), 3639 stabilize_reference_1 (TREE_OPERAND (ref, 1)), 3640 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3)); 3641 break; 3642 3643 case COMPOUND_EXPR: 3644 /* We cannot wrap the first expression in a SAVE_EXPR, as then 3645 it wouldn't be ignored. This matters when dealing with 3646 volatiles. */ 3647 return stabilize_reference_1 (ref); 3648 3649 /* If arg isn't a kind of lvalue we recognize, make no change. 3650 Caller should recognize the error for an invalid lvalue. */ 3651 default: 3652 return ref; 3653 3654 case ERROR_MARK: 3655 return error_mark_node; 3656 } 3657 3658 TREE_TYPE (result) = TREE_TYPE (ref); 3659 TREE_READONLY (result) = TREE_READONLY (ref); 3660 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref); 3661 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref); 3662 3663 return result; 3664 } 3665 3666 /* Subroutine of stabilize_reference; this is called for subtrees of 3667 references. Any expression with side-effects must be put in a SAVE_EXPR 3668 to ensure that it is only evaluated once. 3669 3670 We don't put SAVE_EXPR nodes around everything, because assigning very 3671 simple expressions to temporaries causes us to miss good opportunities 3672 for optimizations. Among other things, the opportunity to fold in the 3673 addition of a constant into an addressing mode often gets lost, e.g. 3674 "y[i+1] += x;". In general, we take the approach that we should not make 3675 an assignment unless we are forced into it - i.e., that any non-side effect 3676 operator should be allowed, and that cse should take care of coalescing 3677 multiple utterances of the same expression should that prove fruitful. */ 3678 3679 tree 3680 stabilize_reference_1 (tree e) 3681 { 3682 tree result; 3683 enum tree_code code = TREE_CODE (e); 3684 3685 /* We cannot ignore const expressions because it might be a reference 3686 to a const array but whose index contains side-effects. But we can 3687 ignore things that are actual constant or that already have been 3688 handled by this function. */ 3689 3690 if (tree_invariant_p (e)) 3691 return e; 3692 3693 switch (TREE_CODE_CLASS (code)) 3694 { 3695 case tcc_exceptional: 3696 case tcc_type: 3697 case tcc_declaration: 3698 case tcc_comparison: 3699 case tcc_statement: 3700 case tcc_expression: 3701 case tcc_reference: 3702 case tcc_vl_exp: 3703 /* If the expression has side-effects, then encase it in a SAVE_EXPR 3704 so that it will only be evaluated once. */ 3705 /* The reference (r) and comparison (<) classes could be handled as 3706 below, but it is generally faster to only evaluate them once. */ 3707 if (TREE_SIDE_EFFECTS (e)) 3708 return save_expr (e); 3709 return e; 3710 3711 case tcc_constant: 3712 /* Constants need no processing. In fact, we should never reach 3713 here. */ 3714 return e; 3715 3716 case tcc_binary: 3717 /* Division is slow and tends to be compiled with jumps, 3718 especially the division by powers of 2 that is often 3719 found inside of an array reference. So do it just once. */ 3720 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR 3721 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR 3722 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR 3723 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR) 3724 return save_expr (e); 3725 /* Recursively stabilize each operand. */ 3726 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)), 3727 stabilize_reference_1 (TREE_OPERAND (e, 1))); 3728 break; 3729 3730 case tcc_unary: 3731 /* Recursively stabilize each operand. */ 3732 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0))); 3733 break; 3734 3735 default: 3736 gcc_unreachable (); 3737 } 3738 3739 TREE_TYPE (result) = TREE_TYPE (e); 3740 TREE_READONLY (result) = TREE_READONLY (e); 3741 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e); 3742 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e); 3743 3744 return result; 3745 } 3746 3747 /* Low-level constructors for expressions. */ 3748 3749 /* A helper function for build1 and constant folders. Set TREE_CONSTANT, 3750 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */ 3751 3752 void 3753 recompute_tree_invariant_for_addr_expr (tree t) 3754 { 3755 tree node; 3756 bool tc = true, se = false; 3757 3758 /* We started out assuming this address is both invariant and constant, but 3759 does not have side effects. Now go down any handled components and see if 3760 any of them involve offsets that are either non-constant or non-invariant. 3761 Also check for side-effects. 3762 3763 ??? Note that this code makes no attempt to deal with the case where 3764 taking the address of something causes a copy due to misalignment. */ 3765 3766 #define UPDATE_FLAGS(NODE) \ 3767 do { tree _node = (NODE); \ 3768 if (_node && !TREE_CONSTANT (_node)) tc = false; \ 3769 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0) 3770 3771 for (node = TREE_OPERAND (t, 0); handled_component_p (node); 3772 node = TREE_OPERAND (node, 0)) 3773 { 3774 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus 3775 array reference (probably made temporarily by the G++ front end), 3776 so ignore all the operands. */ 3777 if ((TREE_CODE (node) == ARRAY_REF 3778 || TREE_CODE (node) == ARRAY_RANGE_REF) 3779 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE) 3780 { 3781 UPDATE_FLAGS (TREE_OPERAND (node, 1)); 3782 if (TREE_OPERAND (node, 2)) 3783 UPDATE_FLAGS (TREE_OPERAND (node, 2)); 3784 if (TREE_OPERAND (node, 3)) 3785 UPDATE_FLAGS (TREE_OPERAND (node, 3)); 3786 } 3787 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a 3788 FIELD_DECL, apparently. The G++ front end can put something else 3789 there, at least temporarily. */ 3790 else if (TREE_CODE (node) == COMPONENT_REF 3791 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL) 3792 { 3793 if (TREE_OPERAND (node, 2)) 3794 UPDATE_FLAGS (TREE_OPERAND (node, 2)); 3795 } 3796 } 3797 3798 node = lang_hooks.expr_to_decl (node, &tc, &se); 3799 3800 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from 3801 the address, since &(*a)->b is a form of addition. If it's a constant, the 3802 address is constant too. If it's a decl, its address is constant if the 3803 decl is static. Everything else is not constant and, furthermore, 3804 taking the address of a volatile variable is not volatile. */ 3805 if (TREE_CODE (node) == INDIRECT_REF 3806 || TREE_CODE (node) == MEM_REF) 3807 UPDATE_FLAGS (TREE_OPERAND (node, 0)); 3808 else if (CONSTANT_CLASS_P (node)) 3809 ; 3810 else if (DECL_P (node)) 3811 tc &= (staticp (node) != NULL_TREE); 3812 else 3813 { 3814 tc = false; 3815 se |= TREE_SIDE_EFFECTS (node); 3816 } 3817 3818 3819 TREE_CONSTANT (t) = tc; 3820 TREE_SIDE_EFFECTS (t) = se; 3821 #undef UPDATE_FLAGS 3822 } 3823 3824 /* Build an expression of code CODE, data type TYPE, and operands as 3825 specified. Expressions and reference nodes can be created this way. 3826 Constants, decls, types and misc nodes cannot be. 3827 3828 We define 5 non-variadic functions, from 0 to 4 arguments. This is 3829 enough for all extant tree codes. */ 3830 3831 tree 3832 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL) 3833 { 3834 tree t; 3835 3836 gcc_assert (TREE_CODE_LENGTH (code) == 0); 3837 3838 t = make_node_stat (code PASS_MEM_STAT); 3839 TREE_TYPE (t) = tt; 3840 3841 return t; 3842 } 3843 3844 tree 3845 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL) 3846 { 3847 int length = sizeof (struct tree_exp); 3848 tree t; 3849 3850 record_node_allocation_statistics (code, length); 3851 3852 gcc_assert (TREE_CODE_LENGTH (code) == 1); 3853 3854 t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT); 3855 3856 memset (t, 0, sizeof (struct tree_common)); 3857 3858 TREE_SET_CODE (t, code); 3859 3860 TREE_TYPE (t) = type; 3861 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION); 3862 TREE_OPERAND (t, 0) = node; 3863 if (node && !TYPE_P (node)) 3864 { 3865 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node); 3866 TREE_READONLY (t) = TREE_READONLY (node); 3867 } 3868 3869 if (TREE_CODE_CLASS (code) == tcc_statement) 3870 TREE_SIDE_EFFECTS (t) = 1; 3871 else switch (code) 3872 { 3873 case VA_ARG_EXPR: 3874 /* All of these have side-effects, no matter what their 3875 operands are. */ 3876 TREE_SIDE_EFFECTS (t) = 1; 3877 TREE_READONLY (t) = 0; 3878 break; 3879 3880 case INDIRECT_REF: 3881 /* Whether a dereference is readonly has nothing to do with whether 3882 its operand is readonly. */ 3883 TREE_READONLY (t) = 0; 3884 break; 3885 3886 case ADDR_EXPR: 3887 if (node) 3888 recompute_tree_invariant_for_addr_expr (t); 3889 break; 3890 3891 default: 3892 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR) 3893 && node && !TYPE_P (node) 3894 && TREE_CONSTANT (node)) 3895 TREE_CONSTANT (t) = 1; 3896 if (TREE_CODE_CLASS (code) == tcc_reference 3897 && node && TREE_THIS_VOLATILE (node)) 3898 TREE_THIS_VOLATILE (t) = 1; 3899 break; 3900 } 3901 3902 return t; 3903 } 3904 3905 #define PROCESS_ARG(N) \ 3906 do { \ 3907 TREE_OPERAND (t, N) = arg##N; \ 3908 if (arg##N &&!TYPE_P (arg##N)) \ 3909 { \ 3910 if (TREE_SIDE_EFFECTS (arg##N)) \ 3911 side_effects = 1; \ 3912 if (!TREE_READONLY (arg##N) \ 3913 && !CONSTANT_CLASS_P (arg##N)) \ 3914 (void) (read_only = 0); \ 3915 if (!TREE_CONSTANT (arg##N)) \ 3916 (void) (constant = 0); \ 3917 } \ 3918 } while (0) 3919 3920 tree 3921 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) 3922 { 3923 bool constant, read_only, side_effects; 3924 tree t; 3925 3926 gcc_assert (TREE_CODE_LENGTH (code) == 2); 3927 3928 if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR) 3929 && arg0 && arg1 && tt && POINTER_TYPE_P (tt) 3930 /* When sizetype precision doesn't match that of pointers 3931 we need to be able to build explicit extensions or truncations 3932 of the offset argument. */ 3933 && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt)) 3934 gcc_assert (TREE_CODE (arg0) == INTEGER_CST 3935 && TREE_CODE (arg1) == INTEGER_CST); 3936 3937 if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt) 3938 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0)) 3939 && ptrofftype_p (TREE_TYPE (arg1))); 3940 3941 t = make_node_stat (code PASS_MEM_STAT); 3942 TREE_TYPE (t) = tt; 3943 3944 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the 3945 result based on those same flags for the arguments. But if the 3946 arguments aren't really even `tree' expressions, we shouldn't be trying 3947 to do this. */ 3948 3949 /* Expressions without side effects may be constant if their 3950 arguments are as well. */ 3951 constant = (TREE_CODE_CLASS (code) == tcc_comparison 3952 || TREE_CODE_CLASS (code) == tcc_binary); 3953 read_only = 1; 3954 side_effects = TREE_SIDE_EFFECTS (t); 3955 3956 PROCESS_ARG(0); 3957 PROCESS_ARG(1); 3958 3959 TREE_READONLY (t) = read_only; 3960 TREE_CONSTANT (t) = constant; 3961 TREE_SIDE_EFFECTS (t) = side_effects; 3962 TREE_THIS_VOLATILE (t) 3963 = (TREE_CODE_CLASS (code) == tcc_reference 3964 && arg0 && TREE_THIS_VOLATILE (arg0)); 3965 3966 return t; 3967 } 3968 3969 3970 tree 3971 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1, 3972 tree arg2 MEM_STAT_DECL) 3973 { 3974 bool constant, read_only, side_effects; 3975 tree t; 3976 3977 gcc_assert (TREE_CODE_LENGTH (code) == 3); 3978 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); 3979 3980 t = make_node_stat (code PASS_MEM_STAT); 3981 TREE_TYPE (t) = tt; 3982 3983 read_only = 1; 3984 3985 /* As a special exception, if COND_EXPR has NULL branches, we 3986 assume that it is a gimple statement and always consider 3987 it to have side effects. */ 3988 if (code == COND_EXPR 3989 && tt == void_type_node 3990 && arg1 == NULL_TREE 3991 && arg2 == NULL_TREE) 3992 side_effects = true; 3993 else 3994 side_effects = TREE_SIDE_EFFECTS (t); 3995 3996 PROCESS_ARG(0); 3997 PROCESS_ARG(1); 3998 PROCESS_ARG(2); 3999 4000 if (code == COND_EXPR) 4001 TREE_READONLY (t) = read_only; 4002 4003 TREE_SIDE_EFFECTS (t) = side_effects; 4004 TREE_THIS_VOLATILE (t) 4005 = (TREE_CODE_CLASS (code) == tcc_reference 4006 && arg0 && TREE_THIS_VOLATILE (arg0)); 4007 4008 return t; 4009 } 4010 4011 tree 4012 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1, 4013 tree arg2, tree arg3 MEM_STAT_DECL) 4014 { 4015 bool constant, read_only, side_effects; 4016 tree t; 4017 4018 gcc_assert (TREE_CODE_LENGTH (code) == 4); 4019 4020 t = make_node_stat (code PASS_MEM_STAT); 4021 TREE_TYPE (t) = tt; 4022 4023 side_effects = TREE_SIDE_EFFECTS (t); 4024 4025 PROCESS_ARG(0); 4026 PROCESS_ARG(1); 4027 PROCESS_ARG(2); 4028 PROCESS_ARG(3); 4029 4030 TREE_SIDE_EFFECTS (t) = side_effects; 4031 TREE_THIS_VOLATILE (t) 4032 = (TREE_CODE_CLASS (code) == tcc_reference 4033 && arg0 && TREE_THIS_VOLATILE (arg0)); 4034 4035 return t; 4036 } 4037 4038 tree 4039 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1, 4040 tree arg2, tree arg3, tree arg4 MEM_STAT_DECL) 4041 { 4042 bool constant, read_only, side_effects; 4043 tree t; 4044 4045 gcc_assert (TREE_CODE_LENGTH (code) == 5); 4046 4047 t = make_node_stat (code PASS_MEM_STAT); 4048 TREE_TYPE (t) = tt; 4049 4050 side_effects = TREE_SIDE_EFFECTS (t); 4051 4052 PROCESS_ARG(0); 4053 PROCESS_ARG(1); 4054 PROCESS_ARG(2); 4055 PROCESS_ARG(3); 4056 PROCESS_ARG(4); 4057 4058 TREE_SIDE_EFFECTS (t) = side_effects; 4059 TREE_THIS_VOLATILE (t) 4060 = (TREE_CODE_CLASS (code) == tcc_reference 4061 && arg0 && TREE_THIS_VOLATILE (arg0)); 4062 4063 return t; 4064 } 4065 4066 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF 4067 on the pointer PTR. */ 4068 4069 tree 4070 build_simple_mem_ref_loc (location_t loc, tree ptr) 4071 { 4072 HOST_WIDE_INT offset = 0; 4073 tree ptype = TREE_TYPE (ptr); 4074 tree tem; 4075 /* For convenience allow addresses that collapse to a simple base 4076 and offset. */ 4077 if (TREE_CODE (ptr) == ADDR_EXPR 4078 && (handled_component_p (TREE_OPERAND (ptr, 0)) 4079 || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF)) 4080 { 4081 ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset); 4082 gcc_assert (ptr); 4083 ptr = build_fold_addr_expr (ptr); 4084 gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr)); 4085 } 4086 tem = build2 (MEM_REF, TREE_TYPE (ptype), 4087 ptr, build_int_cst (ptype, offset)); 4088 SET_EXPR_LOCATION (tem, loc); 4089 return tem; 4090 } 4091 4092 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */ 4093 4094 double_int 4095 mem_ref_offset (const_tree t) 4096 { 4097 tree toff = TREE_OPERAND (t, 1); 4098 return tree_to_double_int (toff).sext (TYPE_PRECISION (TREE_TYPE (toff))); 4099 } 4100 4101 /* Return the pointer-type relevant for TBAA purposes from the 4102 gimple memory reference tree T. This is the type to be used for 4103 the offset operand of MEM_REF or TARGET_MEM_REF replacements of T. */ 4104 4105 tree 4106 reference_alias_ptr_type (const_tree t) 4107 { 4108 const_tree base = t; 4109 while (handled_component_p (base)) 4110 base = TREE_OPERAND (base, 0); 4111 if (TREE_CODE (base) == MEM_REF) 4112 return TREE_TYPE (TREE_OPERAND (base, 1)); 4113 else if (TREE_CODE (base) == TARGET_MEM_REF) 4114 return TREE_TYPE (TMR_OFFSET (base)); 4115 else 4116 return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (base))); 4117 } 4118 4119 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE 4120 offsetted by OFFSET units. */ 4121 4122 tree 4123 build_invariant_address (tree type, tree base, HOST_WIDE_INT offset) 4124 { 4125 tree ref = fold_build2 (MEM_REF, TREE_TYPE (type), 4126 build_fold_addr_expr (base), 4127 build_int_cst (ptr_type_node, offset)); 4128 tree addr = build1 (ADDR_EXPR, type, ref); 4129 recompute_tree_invariant_for_addr_expr (addr); 4130 return addr; 4131 } 4132 4133 /* Similar except don't specify the TREE_TYPE 4134 and leave the TREE_SIDE_EFFECTS as 0. 4135 It is permissible for arguments to be null, 4136 or even garbage if their values do not matter. */ 4137 4138 tree 4139 build_nt (enum tree_code code, ...) 4140 { 4141 tree t; 4142 int length; 4143 int i; 4144 va_list p; 4145 4146 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); 4147 4148 va_start (p, code); 4149 4150 t = make_node (code); 4151 length = TREE_CODE_LENGTH (code); 4152 4153 for (i = 0; i < length; i++) 4154 TREE_OPERAND (t, i) = va_arg (p, tree); 4155 4156 va_end (p); 4157 return t; 4158 } 4159 4160 /* Similar to build_nt, but for creating a CALL_EXPR object with a 4161 tree vec. */ 4162 4163 tree 4164 build_nt_call_vec (tree fn, vec<tree, va_gc> *args) 4165 { 4166 tree ret, t; 4167 unsigned int ix; 4168 4169 ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3); 4170 CALL_EXPR_FN (ret) = fn; 4171 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; 4172 FOR_EACH_VEC_SAFE_ELT (args, ix, t) 4173 CALL_EXPR_ARG (ret, ix) = t; 4174 return ret; 4175 } 4176 4177 /* Create a DECL_... node of code CODE, name NAME and data type TYPE. 4178 We do NOT enter this node in any sort of symbol table. 4179 4180 LOC is the location of the decl. 4181 4182 layout_decl is used to set up the decl's storage layout. 4183 Other slots are initialized to 0 or null pointers. */ 4184 4185 tree 4186 build_decl_stat (location_t loc, enum tree_code code, tree name, 4187 tree type MEM_STAT_DECL) 4188 { 4189 tree t; 4190 4191 t = make_node_stat (code PASS_MEM_STAT); 4192 DECL_SOURCE_LOCATION (t) = loc; 4193 4194 /* if (type == error_mark_node) 4195 type = integer_type_node; */ 4196 /* That is not done, deliberately, so that having error_mark_node 4197 as the type can suppress useless errors in the use of this variable. */ 4198 4199 DECL_NAME (t) = name; 4200 TREE_TYPE (t) = type; 4201 4202 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL) 4203 layout_decl (t, 0); 4204 4205 return t; 4206 } 4207 4208 /* Builds and returns function declaration with NAME and TYPE. */ 4209 4210 tree 4211 build_fn_decl (const char *name, tree type) 4212 { 4213 tree id = get_identifier (name); 4214 tree decl = build_decl (input_location, FUNCTION_DECL, id, type); 4215 4216 DECL_EXTERNAL (decl) = 1; 4217 TREE_PUBLIC (decl) = 1; 4218 DECL_ARTIFICIAL (decl) = 1; 4219 TREE_NOTHROW (decl) = 1; 4220 4221 return decl; 4222 } 4223 4224 vec<tree, va_gc> *all_translation_units; 4225 4226 /* Builds a new translation-unit decl with name NAME, queues it in the 4227 global list of translation-unit decls and returns it. */ 4228 4229 tree 4230 build_translation_unit_decl (tree name) 4231 { 4232 tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL, 4233 name, NULL_TREE); 4234 TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name; 4235 vec_safe_push (all_translation_units, tu); 4236 return tu; 4237 } 4238 4239 4240 /* BLOCK nodes are used to represent the structure of binding contours 4241 and declarations, once those contours have been exited and their contents 4242 compiled. This information is used for outputting debugging info. */ 4243 4244 tree 4245 build_block (tree vars, tree subblocks, tree supercontext, tree chain) 4246 { 4247 tree block = make_node (BLOCK); 4248 4249 BLOCK_VARS (block) = vars; 4250 BLOCK_SUBBLOCKS (block) = subblocks; 4251 BLOCK_SUPERCONTEXT (block) = supercontext; 4252 BLOCK_CHAIN (block) = chain; 4253 return block; 4254 } 4255 4256 4257 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location. 4258 4259 LOC is the location to use in tree T. */ 4260 4261 void 4262 protected_set_expr_location (tree t, location_t loc) 4263 { 4264 if (t && CAN_HAVE_LOCATION_P (t)) 4265 SET_EXPR_LOCATION (t, loc); 4266 } 4267 4268 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES 4269 is ATTRIBUTE. */ 4270 4271 tree 4272 build_decl_attribute_variant (tree ddecl, tree attribute) 4273 { 4274 DECL_ATTRIBUTES (ddecl) = attribute; 4275 return ddecl; 4276 } 4277 4278 /* Borrowed from hashtab.c iterative_hash implementation. */ 4279 #define mix(a,b,c) \ 4280 { \ 4281 a -= b; a -= c; a ^= (c>>13); \ 4282 b -= c; b -= a; b ^= (a<< 8); \ 4283 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \ 4284 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \ 4285 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \ 4286 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \ 4287 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \ 4288 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \ 4289 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \ 4290 } 4291 4292 4293 /* Produce good hash value combining VAL and VAL2. */ 4294 hashval_t 4295 iterative_hash_hashval_t (hashval_t val, hashval_t val2) 4296 { 4297 /* the golden ratio; an arbitrary value. */ 4298 hashval_t a = 0x9e3779b9; 4299 4300 mix (a, val, val2); 4301 return val2; 4302 } 4303 4304 /* Produce good hash value combining VAL and VAL2. */ 4305 hashval_t 4306 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) 4307 { 4308 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t)) 4309 return iterative_hash_hashval_t (val, val2); 4310 else 4311 { 4312 hashval_t a = (hashval_t) val; 4313 /* Avoid warnings about shifting of more than the width of the type on 4314 hosts that won't execute this path. */ 4315 int zero = 0; 4316 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero)); 4317 mix (a, b, val2); 4318 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t)) 4319 { 4320 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero)); 4321 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero)); 4322 mix (a, b, val2); 4323 } 4324 return val2; 4325 } 4326 } 4327 4328 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE 4329 is ATTRIBUTE and its qualifiers are QUALS. 4330 4331 Record such modified types already made so we don't make duplicates. */ 4332 4333 tree 4334 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) 4335 { 4336 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) 4337 { 4338 hashval_t hashcode = 0; 4339 tree ntype; 4340 enum tree_code code = TREE_CODE (ttype); 4341 4342 /* Building a distinct copy of a tagged type is inappropriate; it 4343 causes breakage in code that expects there to be a one-to-one 4344 relationship between a struct and its fields. 4345 build_duplicate_type is another solution (as used in 4346 handle_transparent_union_attribute), but that doesn't play well 4347 with the stronger C++ type identity model. */ 4348 if (TREE_CODE (ttype) == RECORD_TYPE 4349 || TREE_CODE (ttype) == UNION_TYPE 4350 || TREE_CODE (ttype) == QUAL_UNION_TYPE 4351 || TREE_CODE (ttype) == ENUMERAL_TYPE) 4352 { 4353 warning (OPT_Wattributes, 4354 "ignoring attributes applied to %qT after definition", 4355 TYPE_MAIN_VARIANT (ttype)); 4356 return build_qualified_type (ttype, quals); 4357 } 4358 4359 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED); 4360 ntype = build_distinct_type_copy (ttype); 4361 4362 TYPE_ATTRIBUTES (ntype) = attribute; 4363 4364 hashcode = iterative_hash_object (code, hashcode); 4365 if (TREE_TYPE (ntype)) 4366 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)), 4367 hashcode); 4368 hashcode = attribute_hash_list (attribute, hashcode); 4369 4370 switch (TREE_CODE (ntype)) 4371 { 4372 case FUNCTION_TYPE: 4373 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode); 4374 break; 4375 case ARRAY_TYPE: 4376 if (TYPE_DOMAIN (ntype)) 4377 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)), 4378 hashcode); 4379 break; 4380 case INTEGER_TYPE: 4381 hashcode = iterative_hash_object 4382 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode); 4383 hashcode = iterative_hash_object 4384 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode); 4385 break; 4386 case REAL_TYPE: 4387 case FIXED_POINT_TYPE: 4388 { 4389 unsigned int precision = TYPE_PRECISION (ntype); 4390 hashcode = iterative_hash_object (precision, hashcode); 4391 } 4392 break; 4393 default: 4394 break; 4395 } 4396 4397 ntype = type_hash_canon (hashcode, ntype); 4398 4399 /* If the target-dependent attributes make NTYPE different from 4400 its canonical type, we will need to use structural equality 4401 checks for this type. */ 4402 if (TYPE_STRUCTURAL_EQUALITY_P (ttype) 4403 || !comp_type_attributes (ntype, ttype)) 4404 SET_TYPE_STRUCTURAL_EQUALITY (ntype); 4405 else if (TYPE_CANONICAL (ntype) == ntype) 4406 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype); 4407 4408 ttype = build_qualified_type (ntype, quals); 4409 } 4410 else if (TYPE_QUALS (ttype) != quals) 4411 ttype = build_qualified_type (ttype, quals); 4412 4413 return ttype; 4414 } 4415 4416 /* Compare two attributes for their value identity. Return true if the 4417 attribute values are known to be equal; otherwise return false. 4418 */ 4419 4420 static bool 4421 attribute_value_equal (const_tree attr1, const_tree attr2) 4422 { 4423 if (TREE_VALUE (attr1) == TREE_VALUE (attr2)) 4424 return true; 4425 4426 if (TREE_VALUE (attr1) != NULL_TREE 4427 && TREE_CODE (TREE_VALUE (attr1)) == TREE_LIST 4428 && TREE_VALUE (attr2) != NULL 4429 && TREE_CODE (TREE_VALUE (attr2)) == TREE_LIST) 4430 return (simple_cst_list_equal (TREE_VALUE (attr1), 4431 TREE_VALUE (attr2)) == 1); 4432 4433 return (simple_cst_equal (TREE_VALUE (attr1), TREE_VALUE (attr2)) == 1); 4434 } 4435 4436 /* Return 0 if the attributes for two types are incompatible, 1 if they 4437 are compatible, and 2 if they are nearly compatible (which causes a 4438 warning to be generated). */ 4439 int 4440 comp_type_attributes (const_tree type1, const_tree type2) 4441 { 4442 const_tree a1 = TYPE_ATTRIBUTES (type1); 4443 const_tree a2 = TYPE_ATTRIBUTES (type2); 4444 const_tree a; 4445 4446 if (a1 == a2) 4447 return 1; 4448 for (a = a1; a != NULL_TREE; a = TREE_CHAIN (a)) 4449 { 4450 const struct attribute_spec *as; 4451 const_tree attr; 4452 4453 as = lookup_attribute_spec (get_attribute_name (a)); 4454 if (!as || as->affects_type_identity == false) 4455 continue; 4456 4457 attr = lookup_attribute (as->name, CONST_CAST_TREE (a2)); 4458 if (!attr || !attribute_value_equal (a, attr)) 4459 break; 4460 } 4461 if (!a) 4462 { 4463 for (a = a2; a != NULL_TREE; a = TREE_CHAIN (a)) 4464 { 4465 const struct attribute_spec *as; 4466 4467 as = lookup_attribute_spec (get_attribute_name (a)); 4468 if (!as || as->affects_type_identity == false) 4469 continue; 4470 4471 if (!lookup_attribute (as->name, CONST_CAST_TREE (a1))) 4472 break; 4473 /* We don't need to compare trees again, as we did this 4474 already in first loop. */ 4475 } 4476 /* All types - affecting identity - are equal, so 4477 there is no need to call target hook for comparison. */ 4478 if (!a) 4479 return 1; 4480 } 4481 /* As some type combinations - like default calling-convention - might 4482 be compatible, we have to call the target hook to get the final result. */ 4483 return targetm.comp_type_attributes (type1, type2); 4484 } 4485 4486 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE 4487 is ATTRIBUTE. 4488 4489 Record such modified types already made so we don't make duplicates. */ 4490 4491 tree 4492 build_type_attribute_variant (tree ttype, tree attribute) 4493 { 4494 return build_type_attribute_qual_variant (ttype, attribute, 4495 TYPE_QUALS (ttype)); 4496 } 4497 4498 4499 /* Reset the expression *EXPR_P, a size or position. 4500 4501 ??? We could reset all non-constant sizes or positions. But it's cheap 4502 enough to not do so and refrain from adding workarounds to dwarf2out.c. 4503 4504 We need to reset self-referential sizes or positions because they cannot 4505 be gimplified and thus can contain a CALL_EXPR after the gimplification 4506 is finished, which will run afoul of LTO streaming. And they need to be 4507 reset to something essentially dummy but not constant, so as to preserve 4508 the properties of the object they are attached to. */ 4509 4510 static inline void 4511 free_lang_data_in_one_sizepos (tree *expr_p) 4512 { 4513 tree expr = *expr_p; 4514 if (CONTAINS_PLACEHOLDER_P (expr)) 4515 *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr)); 4516 } 4517 4518 4519 /* Reset all the fields in a binfo node BINFO. We only keep 4520 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */ 4521 4522 static void 4523 free_lang_data_in_binfo (tree binfo) 4524 { 4525 unsigned i; 4526 tree t; 4527 4528 gcc_assert (TREE_CODE (binfo) == TREE_BINFO); 4529 4530 BINFO_VIRTUALS (binfo) = NULL_TREE; 4531 BINFO_BASE_ACCESSES (binfo) = NULL; 4532 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE; 4533 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE; 4534 4535 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t) 4536 free_lang_data_in_binfo (t); 4537 } 4538 4539 4540 /* Reset all language specific information still present in TYPE. */ 4541 4542 static void 4543 free_lang_data_in_type (tree type) 4544 { 4545 gcc_assert (TYPE_P (type)); 4546 4547 /* Give the FE a chance to remove its own data first. */ 4548 lang_hooks.free_lang_data (type); 4549 4550 TREE_LANG_FLAG_0 (type) = 0; 4551 TREE_LANG_FLAG_1 (type) = 0; 4552 TREE_LANG_FLAG_2 (type) = 0; 4553 TREE_LANG_FLAG_3 (type) = 0; 4554 TREE_LANG_FLAG_4 (type) = 0; 4555 TREE_LANG_FLAG_5 (type) = 0; 4556 TREE_LANG_FLAG_6 (type) = 0; 4557 4558 if (TREE_CODE (type) == FUNCTION_TYPE) 4559 { 4560 /* Remove the const and volatile qualifiers from arguments. The 4561 C++ front end removes them, but the C front end does not, 4562 leading to false ODR violation errors when merging two 4563 instances of the same function signature compiled by 4564 different front ends. */ 4565 tree p; 4566 4567 for (p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p)) 4568 { 4569 tree arg_type = TREE_VALUE (p); 4570 4571 if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type)) 4572 { 4573 int quals = TYPE_QUALS (arg_type) 4574 & ~TYPE_QUAL_CONST 4575 & ~TYPE_QUAL_VOLATILE; 4576 TREE_VALUE (p) = build_qualified_type (arg_type, quals); 4577 free_lang_data_in_type (TREE_VALUE (p)); 4578 } 4579 } 4580 } 4581 4582 /* Remove members that are not actually FIELD_DECLs from the field 4583 list of an aggregate. These occur in C++. */ 4584 if (RECORD_OR_UNION_TYPE_P (type)) 4585 { 4586 tree prev, member; 4587 4588 /* Note that TYPE_FIELDS can be shared across distinct 4589 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is 4590 to be removed, we cannot set its TREE_CHAIN to NULL. 4591 Otherwise, we would not be able to find all the other fields 4592 in the other instances of this TREE_TYPE. 4593 4594 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */ 4595 prev = NULL_TREE; 4596 member = TYPE_FIELDS (type); 4597 while (member) 4598 { 4599 if (TREE_CODE (member) == FIELD_DECL 4600 || TREE_CODE (member) == TYPE_DECL) 4601 { 4602 if (prev) 4603 TREE_CHAIN (prev) = member; 4604 else 4605 TYPE_FIELDS (type) = member; 4606 prev = member; 4607 } 4608 4609 member = TREE_CHAIN (member); 4610 } 4611 4612 if (prev) 4613 TREE_CHAIN (prev) = NULL_TREE; 4614 else 4615 TYPE_FIELDS (type) = NULL_TREE; 4616 4617 TYPE_METHODS (type) = NULL_TREE; 4618 if (TYPE_BINFO (type)) 4619 free_lang_data_in_binfo (TYPE_BINFO (type)); 4620 } 4621 else 4622 { 4623 /* For non-aggregate types, clear out the language slot (which 4624 overloads TYPE_BINFO). */ 4625 TYPE_LANG_SLOT_1 (type) = NULL_TREE; 4626 4627 if (INTEGRAL_TYPE_P (type) 4628 || SCALAR_FLOAT_TYPE_P (type) 4629 || FIXED_POINT_TYPE_P (type)) 4630 { 4631 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type)); 4632 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type)); 4633 } 4634 } 4635 4636 free_lang_data_in_one_sizepos (&TYPE_SIZE (type)); 4637 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type)); 4638 4639 if (TYPE_CONTEXT (type) 4640 && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK) 4641 { 4642 tree ctx = TYPE_CONTEXT (type); 4643 do 4644 { 4645 ctx = BLOCK_SUPERCONTEXT (ctx); 4646 } 4647 while (ctx && TREE_CODE (ctx) == BLOCK); 4648 TYPE_CONTEXT (type) = ctx; 4649 } 4650 } 4651 4652 4653 /* Return true if DECL may need an assembler name to be set. */ 4654 4655 static inline bool 4656 need_assembler_name_p (tree decl) 4657 { 4658 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */ 4659 if (TREE_CODE (decl) != FUNCTION_DECL 4660 && TREE_CODE (decl) != VAR_DECL) 4661 return false; 4662 4663 /* If DECL already has its assembler name set, it does not need a 4664 new one. */ 4665 if (!HAS_DECL_ASSEMBLER_NAME_P (decl) 4666 || DECL_ASSEMBLER_NAME_SET_P (decl)) 4667 return false; 4668 4669 /* Abstract decls do not need an assembler name. */ 4670 if (DECL_ABSTRACT (decl)) 4671 return false; 4672 4673 /* For VAR_DECLs, only static, public and external symbols need an 4674 assembler name. */ 4675 if (TREE_CODE (decl) == VAR_DECL 4676 && !TREE_STATIC (decl) 4677 && !TREE_PUBLIC (decl) 4678 && !DECL_EXTERNAL (decl)) 4679 return false; 4680 4681 if (TREE_CODE (decl) == FUNCTION_DECL) 4682 { 4683 /* Do not set assembler name on builtins. Allow RTL expansion to 4684 decide whether to expand inline or via a regular call. */ 4685 if (DECL_BUILT_IN (decl) 4686 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND) 4687 return false; 4688 4689 /* Functions represented in the callgraph need an assembler name. */ 4690 if (cgraph_get_node (decl) != NULL) 4691 return true; 4692 4693 /* Unused and not public functions don't need an assembler name. */ 4694 if (!TREE_USED (decl) && !TREE_PUBLIC (decl)) 4695 return false; 4696 } 4697 4698 return true; 4699 } 4700 4701 4702 /* Reset all language specific information still present in symbol 4703 DECL. */ 4704 4705 static void 4706 free_lang_data_in_decl (tree decl) 4707 { 4708 gcc_assert (DECL_P (decl)); 4709 4710 /* Give the FE a chance to remove its own data first. */ 4711 lang_hooks.free_lang_data (decl); 4712 4713 TREE_LANG_FLAG_0 (decl) = 0; 4714 TREE_LANG_FLAG_1 (decl) = 0; 4715 TREE_LANG_FLAG_2 (decl) = 0; 4716 TREE_LANG_FLAG_3 (decl) = 0; 4717 TREE_LANG_FLAG_4 (decl) = 0; 4718 TREE_LANG_FLAG_5 (decl) = 0; 4719 TREE_LANG_FLAG_6 (decl) = 0; 4720 4721 free_lang_data_in_one_sizepos (&DECL_SIZE (decl)); 4722 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl)); 4723 if (TREE_CODE (decl) == FIELD_DECL) 4724 { 4725 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl)); 4726 if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE) 4727 DECL_QUALIFIER (decl) = NULL_TREE; 4728 } 4729 4730 if (TREE_CODE (decl) == FUNCTION_DECL) 4731 { 4732 if (gimple_has_body_p (decl)) 4733 { 4734 tree t; 4735 4736 /* If DECL has a gimple body, then the context for its 4737 arguments must be DECL. Otherwise, it doesn't really 4738 matter, as we will not be emitting any code for DECL. In 4739 general, there may be other instances of DECL created by 4740 the front end and since PARM_DECLs are generally shared, 4741 their DECL_CONTEXT changes as the replicas of DECL are 4742 created. The only time where DECL_CONTEXT is important 4743 is for the FUNCTION_DECLs that have a gimple body (since 4744 the PARM_DECL will be used in the function's body). */ 4745 for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t)) 4746 DECL_CONTEXT (t) = decl; 4747 } 4748 4749 /* DECL_SAVED_TREE holds the GENERIC representation for DECL. 4750 At this point, it is not needed anymore. */ 4751 DECL_SAVED_TREE (decl) = NULL_TREE; 4752 4753 /* Clear the abstract origin if it refers to a method. Otherwise 4754 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the 4755 origin will not be output correctly. */ 4756 if (DECL_ABSTRACT_ORIGIN (decl) 4757 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl)) 4758 && RECORD_OR_UNION_TYPE_P 4759 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl)))) 4760 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE; 4761 4762 /* Sometimes the C++ frontend doesn't manage to transform a temporary 4763 DECL_VINDEX referring to itself into a vtable slot number as it 4764 should. Happens with functions that are copied and then forgotten 4765 about. Just clear it, it won't matter anymore. */ 4766 if (DECL_VINDEX (decl) && !host_integerp (DECL_VINDEX (decl), 0)) 4767 DECL_VINDEX (decl) = NULL_TREE; 4768 } 4769 else if (TREE_CODE (decl) == VAR_DECL) 4770 { 4771 if ((DECL_EXTERNAL (decl) 4772 && (!TREE_STATIC (decl) || !TREE_READONLY (decl))) 4773 || (decl_function_context (decl) && !TREE_STATIC (decl))) 4774 DECL_INITIAL (decl) = NULL_TREE; 4775 } 4776 else if (TREE_CODE (decl) == TYPE_DECL 4777 || TREE_CODE (decl) == FIELD_DECL) 4778 DECL_INITIAL (decl) = NULL_TREE; 4779 else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL 4780 && DECL_INITIAL (decl) 4781 && TREE_CODE (DECL_INITIAL (decl)) == BLOCK) 4782 { 4783 /* Strip builtins from the translation-unit BLOCK. We still have targets 4784 without builtin_decl_explicit support and also builtins are shared 4785 nodes and thus we can't use TREE_CHAIN in multiple lists. */ 4786 tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl)); 4787 while (*nextp) 4788 { 4789 tree var = *nextp; 4790 if (TREE_CODE (var) == FUNCTION_DECL 4791 && DECL_BUILT_IN (var)) 4792 *nextp = TREE_CHAIN (var); 4793 else 4794 nextp = &TREE_CHAIN (var); 4795 } 4796 } 4797 } 4798 4799 4800 /* Data used when collecting DECLs and TYPEs for language data removal. */ 4801 4802 struct free_lang_data_d 4803 { 4804 /* Worklist to avoid excessive recursion. */ 4805 vec<tree> worklist; 4806 4807 /* Set of traversed objects. Used to avoid duplicate visits. */ 4808 struct pointer_set_t *pset; 4809 4810 /* Array of symbols to process with free_lang_data_in_decl. */ 4811 vec<tree> decls; 4812 4813 /* Array of types to process with free_lang_data_in_type. */ 4814 vec<tree> types; 4815 }; 4816 4817 4818 /* Save all language fields needed to generate proper debug information 4819 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */ 4820 4821 static void 4822 save_debug_info_for_decl (tree t) 4823 { 4824 /*struct saved_debug_info_d *sdi;*/ 4825 4826 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && DECL_P (t)); 4827 4828 /* FIXME. Partial implementation for saving debug info removed. */ 4829 } 4830 4831 4832 /* Save all language fields needed to generate proper debug information 4833 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */ 4834 4835 static void 4836 save_debug_info_for_type (tree t) 4837 { 4838 /*struct saved_debug_info_d *sdi;*/ 4839 4840 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && TYPE_P (t)); 4841 4842 /* FIXME. Partial implementation for saving debug info removed. */ 4843 } 4844 4845 4846 /* Add type or decl T to one of the list of tree nodes that need their 4847 language data removed. The lists are held inside FLD. */ 4848 4849 static void 4850 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld) 4851 { 4852 if (DECL_P (t)) 4853 { 4854 fld->decls.safe_push (t); 4855 if (debug_info_level > DINFO_LEVEL_TERSE) 4856 save_debug_info_for_decl (t); 4857 } 4858 else if (TYPE_P (t)) 4859 { 4860 fld->types.safe_push (t); 4861 if (debug_info_level > DINFO_LEVEL_TERSE) 4862 save_debug_info_for_type (t); 4863 } 4864 else 4865 gcc_unreachable (); 4866 } 4867 4868 /* Push tree node T into FLD->WORKLIST. */ 4869 4870 static inline void 4871 fld_worklist_push (tree t, struct free_lang_data_d *fld) 4872 { 4873 if (t && !is_lang_specific (t) && !pointer_set_contains (fld->pset, t)) 4874 fld->worklist.safe_push ((t)); 4875 } 4876 4877 4878 /* Operand callback helper for free_lang_data_in_node. *TP is the 4879 subtree operand being considered. */ 4880 4881 static tree 4882 find_decls_types_r (tree *tp, int *ws, void *data) 4883 { 4884 tree t = *tp; 4885 struct free_lang_data_d *fld = (struct free_lang_data_d *) data; 4886 4887 if (TREE_CODE (t) == TREE_LIST) 4888 return NULL_TREE; 4889 4890 /* Language specific nodes will be removed, so there is no need 4891 to gather anything under them. */ 4892 if (is_lang_specific (t)) 4893 { 4894 *ws = 0; 4895 return NULL_TREE; 4896 } 4897 4898 if (DECL_P (t)) 4899 { 4900 /* Note that walk_tree does not traverse every possible field in 4901 decls, so we have to do our own traversals here. */ 4902 add_tree_to_fld_list (t, fld); 4903 4904 fld_worklist_push (DECL_NAME (t), fld); 4905 fld_worklist_push (DECL_CONTEXT (t), fld); 4906 fld_worklist_push (DECL_SIZE (t), fld); 4907 fld_worklist_push (DECL_SIZE_UNIT (t), fld); 4908 4909 /* We are going to remove everything under DECL_INITIAL for 4910 TYPE_DECLs. No point walking them. */ 4911 if (TREE_CODE (t) != TYPE_DECL) 4912 fld_worklist_push (DECL_INITIAL (t), fld); 4913 4914 fld_worklist_push (DECL_ATTRIBUTES (t), fld); 4915 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld); 4916 4917 if (TREE_CODE (t) == FUNCTION_DECL) 4918 { 4919 fld_worklist_push (DECL_ARGUMENTS (t), fld); 4920 fld_worklist_push (DECL_RESULT (t), fld); 4921 } 4922 else if (TREE_CODE (t) == TYPE_DECL) 4923 { 4924 fld_worklist_push (DECL_ARGUMENT_FLD (t), fld); 4925 fld_worklist_push (DECL_VINDEX (t), fld); 4926 fld_worklist_push (DECL_ORIGINAL_TYPE (t), fld); 4927 } 4928 else if (TREE_CODE (t) == FIELD_DECL) 4929 { 4930 fld_worklist_push (DECL_FIELD_OFFSET (t), fld); 4931 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld); 4932 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld); 4933 fld_worklist_push (DECL_FCONTEXT (t), fld); 4934 } 4935 else if (TREE_CODE (t) == VAR_DECL) 4936 { 4937 fld_worklist_push (DECL_SECTION_NAME (t), fld); 4938 fld_worklist_push (DECL_COMDAT_GROUP (t), fld); 4939 } 4940 4941 if ((TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == PARM_DECL) 4942 && DECL_HAS_VALUE_EXPR_P (t)) 4943 fld_worklist_push (DECL_VALUE_EXPR (t), fld); 4944 4945 if (TREE_CODE (t) != FIELD_DECL 4946 && TREE_CODE (t) != TYPE_DECL) 4947 fld_worklist_push (TREE_CHAIN (t), fld); 4948 *ws = 0; 4949 } 4950 else if (TYPE_P (t)) 4951 { 4952 /* Note that walk_tree does not traverse every possible field in 4953 types, so we have to do our own traversals here. */ 4954 add_tree_to_fld_list (t, fld); 4955 4956 if (!RECORD_OR_UNION_TYPE_P (t)) 4957 fld_worklist_push (TYPE_CACHED_VALUES (t), fld); 4958 fld_worklist_push (TYPE_SIZE (t), fld); 4959 fld_worklist_push (TYPE_SIZE_UNIT (t), fld); 4960 fld_worklist_push (TYPE_ATTRIBUTES (t), fld); 4961 fld_worklist_push (TYPE_POINTER_TO (t), fld); 4962 fld_worklist_push (TYPE_REFERENCE_TO (t), fld); 4963 fld_worklist_push (TYPE_NAME (t), fld); 4964 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream 4965 them and thus do not and want not to reach unused pointer types 4966 this way. */ 4967 if (!POINTER_TYPE_P (t)) 4968 fld_worklist_push (TYPE_MINVAL (t), fld); 4969 if (!RECORD_OR_UNION_TYPE_P (t)) 4970 fld_worklist_push (TYPE_MAXVAL (t), fld); 4971 fld_worklist_push (TYPE_MAIN_VARIANT (t), fld); 4972 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus 4973 do not and want not to reach unused variants this way. */ 4974 if (TYPE_CONTEXT (t)) 4975 { 4976 tree ctx = TYPE_CONTEXT (t); 4977 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one. 4978 So push that instead. */ 4979 while (ctx && TREE_CODE (ctx) == BLOCK) 4980 ctx = BLOCK_SUPERCONTEXT (ctx); 4981 fld_worklist_push (ctx, fld); 4982 } 4983 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not 4984 and want not to reach unused types this way. */ 4985 4986 if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t)) 4987 { 4988 unsigned i; 4989 tree tem; 4990 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem) 4991 fld_worklist_push (TREE_TYPE (tem), fld); 4992 tem = BINFO_VIRTUALS (TYPE_BINFO (t)); 4993 if (tem 4994 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */ 4995 && TREE_CODE (tem) == TREE_LIST) 4996 do 4997 { 4998 fld_worklist_push (TREE_VALUE (tem), fld); 4999 tem = TREE_CHAIN (tem); 5000 } 5001 while (tem); 5002 } 5003 if (RECORD_OR_UNION_TYPE_P (t)) 5004 { 5005 tree tem; 5006 /* Push all TYPE_FIELDS - there can be interleaving interesting 5007 and non-interesting things. */ 5008 tem = TYPE_FIELDS (t); 5009 while (tem) 5010 { 5011 if (TREE_CODE (tem) == FIELD_DECL 5012 || TREE_CODE (tem) == TYPE_DECL) 5013 fld_worklist_push (tem, fld); 5014 tem = TREE_CHAIN (tem); 5015 } 5016 } 5017 5018 fld_worklist_push (TYPE_STUB_DECL (t), fld); 5019 *ws = 0; 5020 } 5021 else if (TREE_CODE (t) == BLOCK) 5022 { 5023 tree tem; 5024 for (tem = BLOCK_VARS (t); tem; tem = TREE_CHAIN (tem)) 5025 fld_worklist_push (tem, fld); 5026 for (tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem)) 5027 fld_worklist_push (tem, fld); 5028 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld); 5029 } 5030 5031 if (TREE_CODE (t) != IDENTIFIER_NODE 5032 && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED)) 5033 fld_worklist_push (TREE_TYPE (t), fld); 5034 5035 return NULL_TREE; 5036 } 5037 5038 5039 /* Find decls and types in T. */ 5040 5041 static void 5042 find_decls_types (tree t, struct free_lang_data_d *fld) 5043 { 5044 while (1) 5045 { 5046 if (!pointer_set_contains (fld->pset, t)) 5047 walk_tree (&t, find_decls_types_r, fld, fld->pset); 5048 if (fld->worklist.is_empty ()) 5049 break; 5050 t = fld->worklist.pop (); 5051 } 5052 } 5053 5054 /* Translate all the types in LIST with the corresponding runtime 5055 types. */ 5056 5057 static tree 5058 get_eh_types_for_runtime (tree list) 5059 { 5060 tree head, prev; 5061 5062 if (list == NULL_TREE) 5063 return NULL_TREE; 5064 5065 head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list))); 5066 prev = head; 5067 list = TREE_CHAIN (list); 5068 while (list) 5069 { 5070 tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list))); 5071 TREE_CHAIN (prev) = n; 5072 prev = TREE_CHAIN (prev); 5073 list = TREE_CHAIN (list); 5074 } 5075 5076 return head; 5077 } 5078 5079 5080 /* Find decls and types referenced in EH region R and store them in 5081 FLD->DECLS and FLD->TYPES. */ 5082 5083 static void 5084 find_decls_types_in_eh_region (eh_region r, struct free_lang_data_d *fld) 5085 { 5086 switch (r->type) 5087 { 5088 case ERT_CLEANUP: 5089 break; 5090 5091 case ERT_TRY: 5092 { 5093 eh_catch c; 5094 5095 /* The types referenced in each catch must first be changed to the 5096 EH types used at runtime. This removes references to FE types 5097 in the region. */ 5098 for (c = r->u.eh_try.first_catch; c ; c = c->next_catch) 5099 { 5100 c->type_list = get_eh_types_for_runtime (c->type_list); 5101 walk_tree (&c->type_list, find_decls_types_r, fld, fld->pset); 5102 } 5103 } 5104 break; 5105 5106 case ERT_ALLOWED_EXCEPTIONS: 5107 r->u.allowed.type_list 5108 = get_eh_types_for_runtime (r->u.allowed.type_list); 5109 walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, fld->pset); 5110 break; 5111 5112 case ERT_MUST_NOT_THROW: 5113 walk_tree (&r->u.must_not_throw.failure_decl, 5114 find_decls_types_r, fld, fld->pset); 5115 break; 5116 } 5117 } 5118 5119 5120 /* Find decls and types referenced in cgraph node N and store them in 5121 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will 5122 look for *every* kind of DECL and TYPE node reachable from N, 5123 including those embedded inside types and decls (i.e,, TYPE_DECLs, 5124 NAMESPACE_DECLs, etc). */ 5125 5126 static void 5127 find_decls_types_in_node (struct cgraph_node *n, struct free_lang_data_d *fld) 5128 { 5129 basic_block bb; 5130 struct function *fn; 5131 unsigned ix; 5132 tree t; 5133 5134 find_decls_types (n->symbol.decl, fld); 5135 5136 if (!gimple_has_body_p (n->symbol.decl)) 5137 return; 5138 5139 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL); 5140 5141 fn = DECL_STRUCT_FUNCTION (n->symbol.decl); 5142 5143 /* Traverse locals. */ 5144 FOR_EACH_LOCAL_DECL (fn, ix, t) 5145 find_decls_types (t, fld); 5146 5147 /* Traverse EH regions in FN. */ 5148 { 5149 eh_region r; 5150 FOR_ALL_EH_REGION_FN (r, fn) 5151 find_decls_types_in_eh_region (r, fld); 5152 } 5153 5154 /* Traverse every statement in FN. */ 5155 FOR_EACH_BB_FN (bb, fn) 5156 { 5157 gimple_stmt_iterator si; 5158 unsigned i; 5159 5160 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si)) 5161 { 5162 gimple phi = gsi_stmt (si); 5163 5164 for (i = 0; i < gimple_phi_num_args (phi); i++) 5165 { 5166 tree *arg_p = gimple_phi_arg_def_ptr (phi, i); 5167 find_decls_types (*arg_p, fld); 5168 } 5169 } 5170 5171 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) 5172 { 5173 gimple stmt = gsi_stmt (si); 5174 5175 if (is_gimple_call (stmt)) 5176 find_decls_types (gimple_call_fntype (stmt), fld); 5177 5178 for (i = 0; i < gimple_num_ops (stmt); i++) 5179 { 5180 tree arg = gimple_op (stmt, i); 5181 find_decls_types (arg, fld); 5182 } 5183 } 5184 } 5185 } 5186 5187 5188 /* Find decls and types referenced in varpool node N and store them in 5189 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will 5190 look for *every* kind of DECL and TYPE node reachable from N, 5191 including those embedded inside types and decls (i.e,, TYPE_DECLs, 5192 NAMESPACE_DECLs, etc). */ 5193 5194 static void 5195 find_decls_types_in_var (struct varpool_node *v, struct free_lang_data_d *fld) 5196 { 5197 find_decls_types (v->symbol.decl, fld); 5198 } 5199 5200 /* If T needs an assembler name, have one created for it. */ 5201 5202 void 5203 assign_assembler_name_if_neeeded (tree t) 5204 { 5205 if (need_assembler_name_p (t)) 5206 { 5207 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit 5208 diagnostics that use input_location to show locus 5209 information. The problem here is that, at this point, 5210 input_location is generally anchored to the end of the file 5211 (since the parser is long gone), so we don't have a good 5212 position to pin it to. 5213 5214 To alleviate this problem, this uses the location of T's 5215 declaration. Examples of this are 5216 testsuite/g++.dg/template/cond2.C and 5217 testsuite/g++.dg/template/pr35240.C. */ 5218 location_t saved_location = input_location; 5219 input_location = DECL_SOURCE_LOCATION (t); 5220 5221 decl_assembler_name (t); 5222 5223 input_location = saved_location; 5224 } 5225 } 5226 5227 5228 /* Free language specific information for every operand and expression 5229 in every node of the call graph. This process operates in three stages: 5230 5231 1- Every callgraph node and varpool node is traversed looking for 5232 decls and types embedded in them. This is a more exhaustive 5233 search than that done by find_referenced_vars, because it will 5234 also collect individual fields, decls embedded in types, etc. 5235 5236 2- All the decls found are sent to free_lang_data_in_decl. 5237 5238 3- All the types found are sent to free_lang_data_in_type. 5239 5240 The ordering between decls and types is important because 5241 free_lang_data_in_decl sets assembler names, which includes 5242 mangling. So types cannot be freed up until assembler names have 5243 been set up. */ 5244 5245 static void 5246 free_lang_data_in_cgraph (void) 5247 { 5248 struct cgraph_node *n; 5249 struct varpool_node *v; 5250 struct free_lang_data_d fld; 5251 tree t; 5252 unsigned i; 5253 alias_pair *p; 5254 5255 /* Initialize sets and arrays to store referenced decls and types. */ 5256 fld.pset = pointer_set_create (); 5257 fld.worklist.create (0); 5258 fld.decls.create (100); 5259 fld.types.create (100); 5260 5261 /* Find decls and types in the body of every function in the callgraph. */ 5262 FOR_EACH_FUNCTION (n) 5263 find_decls_types_in_node (n, &fld); 5264 5265 FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p) 5266 find_decls_types (p->decl, &fld); 5267 5268 /* Find decls and types in every varpool symbol. */ 5269 FOR_EACH_VARIABLE (v) 5270 find_decls_types_in_var (v, &fld); 5271 5272 /* Set the assembler name on every decl found. We need to do this 5273 now because free_lang_data_in_decl will invalidate data needed 5274 for mangling. This breaks mangling on interdependent decls. */ 5275 FOR_EACH_VEC_ELT (fld.decls, i, t) 5276 assign_assembler_name_if_neeeded (t); 5277 5278 /* Traverse every decl found freeing its language data. */ 5279 FOR_EACH_VEC_ELT (fld.decls, i, t) 5280 free_lang_data_in_decl (t); 5281 5282 /* Traverse every type found freeing its language data. */ 5283 FOR_EACH_VEC_ELT (fld.types, i, t) 5284 free_lang_data_in_type (t); 5285 5286 pointer_set_destroy (fld.pset); 5287 fld.worklist.release (); 5288 fld.decls.release (); 5289 fld.types.release (); 5290 } 5291 5292 5293 /* Free resources that are used by FE but are not needed once they are done. */ 5294 5295 static unsigned 5296 free_lang_data (void) 5297 { 5298 unsigned i; 5299 5300 /* If we are the LTO frontend we have freed lang-specific data already. */ 5301 if (in_lto_p 5302 || !flag_generate_lto) 5303 return 0; 5304 5305 /* Allocate and assign alias sets to the standard integer types 5306 while the slots are still in the way the frontends generated them. */ 5307 for (i = 0; i < itk_none; ++i) 5308 if (integer_types[i]) 5309 TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]); 5310 5311 /* Traverse the IL resetting language specific information for 5312 operands, expressions, etc. */ 5313 free_lang_data_in_cgraph (); 5314 5315 /* Create gimple variants for common types. */ 5316 ptrdiff_type_node = integer_type_node; 5317 fileptr_type_node = ptr_type_node; 5318 5319 /* Reset some langhooks. Do not reset types_compatible_p, it may 5320 still be used indirectly via the get_alias_set langhook. */ 5321 lang_hooks.dwarf_name = lhd_dwarf_name; 5322 lang_hooks.decl_printable_name = gimple_decl_printable_name; 5323 /* We do not want the default decl_assembler_name implementation, 5324 rather if we have fixed everything we want a wrapper around it 5325 asserting that all non-local symbols already got their assembler 5326 name and only produce assembler names for local symbols. Or rather 5327 make sure we never call decl_assembler_name on local symbols and 5328 devise a separate, middle-end private scheme for it. */ 5329 5330 /* Reset diagnostic machinery. */ 5331 tree_diagnostics_defaults (global_dc); 5332 5333 return 0; 5334 } 5335 5336 5337 struct simple_ipa_opt_pass pass_ipa_free_lang_data = 5338 { 5339 { 5340 SIMPLE_IPA_PASS, 5341 "*free_lang_data", /* name */ 5342 OPTGROUP_NONE, /* optinfo_flags */ 5343 NULL, /* gate */ 5344 free_lang_data, /* execute */ 5345 NULL, /* sub */ 5346 NULL, /* next */ 5347 0, /* static_pass_number */ 5348 TV_IPA_FREE_LANG_DATA, /* tv_id */ 5349 0, /* properties_required */ 5350 0, /* properties_provided */ 5351 0, /* properties_destroyed */ 5352 0, /* todo_flags_start */ 5353 TODO_ggc_collect /* todo_flags_finish */ 5354 } 5355 }; 5356 5357 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of 5358 ATTR_NAME. Also used internally by remove_attribute(). */ 5359 bool 5360 private_is_attribute_p (const char *attr_name, size_t attr_len, const_tree ident) 5361 { 5362 size_t ident_len = IDENTIFIER_LENGTH (ident); 5363 5364 if (ident_len == attr_len) 5365 { 5366 if (strcmp (attr_name, IDENTIFIER_POINTER (ident)) == 0) 5367 return true; 5368 } 5369 else if (ident_len == attr_len + 4) 5370 { 5371 /* There is the possibility that ATTR is 'text' and IDENT is 5372 '__text__'. */ 5373 const char *p = IDENTIFIER_POINTER (ident); 5374 if (p[0] == '_' && p[1] == '_' 5375 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_' 5376 && strncmp (attr_name, p + 2, attr_len) == 0) 5377 return true; 5378 } 5379 5380 return false; 5381 } 5382 5383 /* The backbone of lookup_attribute(). ATTR_LEN is the string length 5384 of ATTR_NAME, and LIST is not NULL_TREE. */ 5385 tree 5386 private_lookup_attribute (const char *attr_name, size_t attr_len, tree list) 5387 { 5388 while (list) 5389 { 5390 size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list)); 5391 5392 if (ident_len == attr_len) 5393 { 5394 if (!strcmp (attr_name, 5395 IDENTIFIER_POINTER (get_attribute_name (list)))) 5396 break; 5397 } 5398 /* TODO: If we made sure that attributes were stored in the 5399 canonical form without '__...__' (ie, as in 'text' as opposed 5400 to '__text__') then we could avoid the following case. */ 5401 else if (ident_len == attr_len + 4) 5402 { 5403 const char *p = IDENTIFIER_POINTER (get_attribute_name (list)); 5404 if (p[0] == '_' && p[1] == '_' 5405 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_' 5406 && strncmp (attr_name, p + 2, attr_len) == 0) 5407 break; 5408 } 5409 list = TREE_CHAIN (list); 5410 } 5411 5412 return list; 5413 } 5414 5415 /* A variant of lookup_attribute() that can be used with an identifier 5416 as the first argument, and where the identifier can be either 5417 'text' or '__text__'. 5418 5419 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST, 5420 return a pointer to the attribute's list element if the attribute 5421 is part of the list, or NULL_TREE if not found. If the attribute 5422 appears more than once, this only returns the first occurrence; the 5423 TREE_CHAIN of the return value should be passed back in if further 5424 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but 5425 can be in the form 'text' or '__text__'. */ 5426 static tree 5427 lookup_ident_attribute (tree attr_identifier, tree list) 5428 { 5429 gcc_checking_assert (TREE_CODE (attr_identifier) == IDENTIFIER_NODE); 5430 5431 while (list) 5432 { 5433 gcc_checking_assert (TREE_CODE (get_attribute_name (list)) 5434 == IDENTIFIER_NODE); 5435 5436 /* Identifiers can be compared directly for equality. */ 5437 if (attr_identifier == get_attribute_name (list)) 5438 break; 5439 5440 /* If they are not equal, they may still be one in the form 5441 'text' while the other one is in the form '__text__'. TODO: 5442 If we were storing attributes in normalized 'text' form, then 5443 this could all go away and we could take full advantage of 5444 the fact that we're comparing identifiers. :-) */ 5445 { 5446 size_t attr_len = IDENTIFIER_LENGTH (attr_identifier); 5447 size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list)); 5448 5449 if (ident_len == attr_len + 4) 5450 { 5451 const char *p = IDENTIFIER_POINTER (get_attribute_name (list)); 5452 const char *q = IDENTIFIER_POINTER (attr_identifier); 5453 if (p[0] == '_' && p[1] == '_' 5454 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_' 5455 && strncmp (q, p + 2, attr_len) == 0) 5456 break; 5457 } 5458 else if (ident_len + 4 == attr_len) 5459 { 5460 const char *p = IDENTIFIER_POINTER (get_attribute_name (list)); 5461 const char *q = IDENTIFIER_POINTER (attr_identifier); 5462 if (q[0] == '_' && q[1] == '_' 5463 && q[attr_len - 2] == '_' && q[attr_len - 1] == '_' 5464 && strncmp (q + 2, p, ident_len) == 0) 5465 break; 5466 } 5467 } 5468 list = TREE_CHAIN (list); 5469 } 5470 5471 return list; 5472 } 5473 5474 /* Remove any instances of attribute ATTR_NAME in LIST and return the 5475 modified list. */ 5476 5477 tree 5478 remove_attribute (const char *attr_name, tree list) 5479 { 5480 tree *p; 5481 size_t attr_len = strlen (attr_name); 5482 5483 gcc_checking_assert (attr_name[0] != '_'); 5484 5485 for (p = &list; *p; ) 5486 { 5487 tree l = *p; 5488 /* TODO: If we were storing attributes in normalized form, here 5489 we could use a simple strcmp(). */ 5490 if (private_is_attribute_p (attr_name, attr_len, get_attribute_name (l))) 5491 *p = TREE_CHAIN (l); 5492 else 5493 p = &TREE_CHAIN (l); 5494 } 5495 5496 return list; 5497 } 5498 5499 /* Return an attribute list that is the union of a1 and a2. */ 5500 5501 tree 5502 merge_attributes (tree a1, tree a2) 5503 { 5504 tree attributes; 5505 5506 /* Either one unset? Take the set one. */ 5507 5508 if ((attributes = a1) == 0) 5509 attributes = a2; 5510 5511 /* One that completely contains the other? Take it. */ 5512 5513 else if (a2 != 0 && ! attribute_list_contained (a1, a2)) 5514 { 5515 if (attribute_list_contained (a2, a1)) 5516 attributes = a2; 5517 else 5518 { 5519 /* Pick the longest list, and hang on the other list. */ 5520 5521 if (list_length (a1) < list_length (a2)) 5522 attributes = a2, a2 = a1; 5523 5524 for (; a2 != 0; a2 = TREE_CHAIN (a2)) 5525 { 5526 tree a; 5527 for (a = lookup_ident_attribute (get_attribute_name (a2), 5528 attributes); 5529 a != NULL_TREE && !attribute_value_equal (a, a2); 5530 a = lookup_ident_attribute (get_attribute_name (a2), 5531 TREE_CHAIN (a))) 5532 ; 5533 if (a == NULL_TREE) 5534 { 5535 a1 = copy_node (a2); 5536 TREE_CHAIN (a1) = attributes; 5537 attributes = a1; 5538 } 5539 } 5540 } 5541 } 5542 return attributes; 5543 } 5544 5545 /* Given types T1 and T2, merge their attributes and return 5546 the result. */ 5547 5548 tree 5549 merge_type_attributes (tree t1, tree t2) 5550 { 5551 return merge_attributes (TYPE_ATTRIBUTES (t1), 5552 TYPE_ATTRIBUTES (t2)); 5553 } 5554 5555 /* Given decls OLDDECL and NEWDECL, merge their attributes and return 5556 the result. */ 5557 5558 tree 5559 merge_decl_attributes (tree olddecl, tree newdecl) 5560 { 5561 return merge_attributes (DECL_ATTRIBUTES (olddecl), 5562 DECL_ATTRIBUTES (newdecl)); 5563 } 5564 5565 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES 5566 5567 /* Specialization of merge_decl_attributes for various Windows targets. 5568 5569 This handles the following situation: 5570 5571 __declspec (dllimport) int foo; 5572 int foo; 5573 5574 The second instance of `foo' nullifies the dllimport. */ 5575 5576 tree 5577 merge_dllimport_decl_attributes (tree old, tree new_tree) 5578 { 5579 tree a; 5580 int delete_dllimport_p = 1; 5581 5582 /* What we need to do here is remove from `old' dllimport if it doesn't 5583 appear in `new'. dllimport behaves like extern: if a declaration is 5584 marked dllimport and a definition appears later, then the object 5585 is not dllimport'd. We also remove a `new' dllimport if the old list 5586 contains dllexport: dllexport always overrides dllimport, regardless 5587 of the order of declaration. */ 5588 if (!VAR_OR_FUNCTION_DECL_P (new_tree)) 5589 delete_dllimport_p = 0; 5590 else if (DECL_DLLIMPORT_P (new_tree) 5591 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old))) 5592 { 5593 DECL_DLLIMPORT_P (new_tree) = 0; 5594 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: " 5595 "dllimport ignored", new_tree); 5596 } 5597 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree)) 5598 { 5599 /* Warn about overriding a symbol that has already been used, e.g.: 5600 extern int __attribute__ ((dllimport)) foo; 5601 int* bar () {return &foo;} 5602 int foo; 5603 */ 5604 if (TREE_USED (old)) 5605 { 5606 warning (0, "%q+D redeclared without dllimport attribute " 5607 "after being referenced with dll linkage", new_tree); 5608 /* If we have used a variable's address with dllimport linkage, 5609 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the 5610 decl may already have had TREE_CONSTANT computed. 5611 We still remove the attribute so that assembler code refers 5612 to '&foo rather than '_imp__foo'. */ 5613 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old)) 5614 DECL_DLLIMPORT_P (new_tree) = 1; 5615 } 5616 5617 /* Let an inline definition silently override the external reference, 5618 but otherwise warn about attribute inconsistency. */ 5619 else if (TREE_CODE (new_tree) == VAR_DECL 5620 || !DECL_DECLARED_INLINE_P (new_tree)) 5621 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: " 5622 "previous dllimport ignored", new_tree); 5623 } 5624 else 5625 delete_dllimport_p = 0; 5626 5627 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree)); 5628 5629 if (delete_dllimport_p) 5630 a = remove_attribute ("dllimport", a); 5631 5632 return a; 5633 } 5634 5635 /* Handle a "dllimport" or "dllexport" attribute; arguments as in 5636 struct attribute_spec.handler. */ 5637 5638 tree 5639 handle_dll_attribute (tree * pnode, tree name, tree args, int flags, 5640 bool *no_add_attrs) 5641 { 5642 tree node = *pnode; 5643 bool is_dllimport; 5644 5645 /* These attributes may apply to structure and union types being created, 5646 but otherwise should pass to the declaration involved. */ 5647 if (!DECL_P (node)) 5648 { 5649 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT 5650 | (int) ATTR_FLAG_ARRAY_NEXT)) 5651 { 5652 *no_add_attrs = true; 5653 return tree_cons (name, args, NULL_TREE); 5654 } 5655 if (TREE_CODE (node) == RECORD_TYPE 5656 || TREE_CODE (node) == UNION_TYPE) 5657 { 5658 node = TYPE_NAME (node); 5659 if (!node) 5660 return NULL_TREE; 5661 } 5662 else 5663 { 5664 warning (OPT_Wattributes, "%qE attribute ignored", 5665 name); 5666 *no_add_attrs = true; 5667 return NULL_TREE; 5668 } 5669 } 5670 5671 if (TREE_CODE (node) != FUNCTION_DECL 5672 && TREE_CODE (node) != VAR_DECL 5673 && TREE_CODE (node) != TYPE_DECL) 5674 { 5675 *no_add_attrs = true; 5676 warning (OPT_Wattributes, "%qE attribute ignored", 5677 name); 5678 return NULL_TREE; 5679 } 5680 5681 if (TREE_CODE (node) == TYPE_DECL 5682 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE 5683 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE) 5684 { 5685 *no_add_attrs = true; 5686 warning (OPT_Wattributes, "%qE attribute ignored", 5687 name); 5688 return NULL_TREE; 5689 } 5690 5691 is_dllimport = is_attribute_p ("dllimport", name); 5692 5693 /* Report error on dllimport ambiguities seen now before they cause 5694 any damage. */ 5695 if (is_dllimport) 5696 { 5697 /* Honor any target-specific overrides. */ 5698 if (!targetm.valid_dllimport_attribute_p (node)) 5699 *no_add_attrs = true; 5700 5701 else if (TREE_CODE (node) == FUNCTION_DECL 5702 && DECL_DECLARED_INLINE_P (node)) 5703 { 5704 warning (OPT_Wattributes, "inline function %q+D declared as " 5705 " dllimport: attribute ignored", node); 5706 *no_add_attrs = true; 5707 } 5708 /* Like MS, treat definition of dllimported variables and 5709 non-inlined functions on declaration as syntax errors. */ 5710 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)) 5711 { 5712 error ("function %q+D definition is marked dllimport", node); 5713 *no_add_attrs = true; 5714 } 5715 5716 else if (TREE_CODE (node) == VAR_DECL) 5717 { 5718 if (DECL_INITIAL (node)) 5719 { 5720 error ("variable %q+D definition is marked dllimport", 5721 node); 5722 *no_add_attrs = true; 5723 } 5724 5725 /* `extern' needn't be specified with dllimport. 5726 Specify `extern' now and hope for the best. Sigh. */ 5727 DECL_EXTERNAL (node) = 1; 5728 /* Also, implicitly give dllimport'd variables declared within 5729 a function global scope, unless declared static. */ 5730 if (current_function_decl != NULL_TREE && !TREE_STATIC (node)) 5731 TREE_PUBLIC (node) = 1; 5732 } 5733 5734 if (*no_add_attrs == false) 5735 DECL_DLLIMPORT_P (node) = 1; 5736 } 5737 else if (TREE_CODE (node) == FUNCTION_DECL 5738 && DECL_DECLARED_INLINE_P (node) 5739 && flag_keep_inline_dllexport) 5740 /* An exported function, even if inline, must be emitted. */ 5741 DECL_EXTERNAL (node) = 0; 5742 5743 /* Report error if symbol is not accessible at global scope. */ 5744 if (!TREE_PUBLIC (node) 5745 && (TREE_CODE (node) == VAR_DECL 5746 || TREE_CODE (node) == FUNCTION_DECL)) 5747 { 5748 error ("external linkage required for symbol %q+D because of " 5749 "%qE attribute", node, name); 5750 *no_add_attrs = true; 5751 } 5752 5753 /* A dllexport'd entity must have default visibility so that other 5754 program units (shared libraries or the main executable) can see 5755 it. A dllimport'd entity must have default visibility so that 5756 the linker knows that undefined references within this program 5757 unit can be resolved by the dynamic linker. */ 5758 if (!*no_add_attrs) 5759 { 5760 if (DECL_VISIBILITY_SPECIFIED (node) 5761 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT) 5762 error ("%qE implies default visibility, but %qD has already " 5763 "been declared with a different visibility", 5764 name, node); 5765 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT; 5766 DECL_VISIBILITY_SPECIFIED (node) = 1; 5767 } 5768 5769 return NULL_TREE; 5770 } 5771 5772 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */ 5773 5774 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask 5775 of the various TYPE_QUAL values. */ 5776 5777 static void 5778 set_type_quals (tree type, int type_quals) 5779 { 5780 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; 5781 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0; 5782 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; 5783 TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals); 5784 } 5785 5786 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */ 5787 5788 bool 5789 check_qualified_type (const_tree cand, const_tree base, int type_quals) 5790 { 5791 return (TYPE_QUALS (cand) == type_quals 5792 && TYPE_NAME (cand) == TYPE_NAME (base) 5793 /* Apparently this is needed for Objective-C. */ 5794 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base) 5795 /* Check alignment. */ 5796 && TYPE_ALIGN (cand) == TYPE_ALIGN (base) 5797 && attribute_list_equal (TYPE_ATTRIBUTES (cand), 5798 TYPE_ATTRIBUTES (base))); 5799 } 5800 5801 /* Returns true iff CAND is equivalent to BASE with ALIGN. */ 5802 5803 static bool 5804 check_aligned_type (const_tree cand, const_tree base, unsigned int align) 5805 { 5806 return (TYPE_QUALS (cand) == TYPE_QUALS (base) 5807 && TYPE_NAME (cand) == TYPE_NAME (base) 5808 /* Apparently this is needed for Objective-C. */ 5809 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base) 5810 /* Check alignment. */ 5811 && TYPE_ALIGN (cand) == align 5812 && attribute_list_equal (TYPE_ATTRIBUTES (cand), 5813 TYPE_ATTRIBUTES (base))); 5814 } 5815 5816 /* Return a version of the TYPE, qualified as indicated by the 5817 TYPE_QUALS, if one exists. If no qualified version exists yet, 5818 return NULL_TREE. */ 5819 5820 tree 5821 get_qualified_type (tree type, int type_quals) 5822 { 5823 tree t; 5824 5825 if (TYPE_QUALS (type) == type_quals) 5826 return type; 5827 5828 /* Search the chain of variants to see if there is already one there just 5829 like the one we need to have. If so, use that existing one. We must 5830 preserve the TYPE_NAME, since there is code that depends on this. */ 5831 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) 5832 if (check_qualified_type (t, type, type_quals)) 5833 return t; 5834 5835 return NULL_TREE; 5836 } 5837 5838 /* Like get_qualified_type, but creates the type if it does not 5839 exist. This function never returns NULL_TREE. */ 5840 5841 tree 5842 build_qualified_type (tree type, int type_quals) 5843 { 5844 tree t; 5845 5846 /* See if we already have the appropriate qualified variant. */ 5847 t = get_qualified_type (type, type_quals); 5848 5849 /* If not, build it. */ 5850 if (!t) 5851 { 5852 t = build_variant_type_copy (type); 5853 set_type_quals (t, type_quals); 5854 5855 if (TYPE_STRUCTURAL_EQUALITY_P (type)) 5856 /* Propagate structural equality. */ 5857 SET_TYPE_STRUCTURAL_EQUALITY (t); 5858 else if (TYPE_CANONICAL (type) != type) 5859 /* Build the underlying canonical type, since it is different 5860 from TYPE. */ 5861 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type), 5862 type_quals); 5863 else 5864 /* T is its own canonical type. */ 5865 TYPE_CANONICAL (t) = t; 5866 5867 } 5868 5869 return t; 5870 } 5871 5872 /* Create a variant of type T with alignment ALIGN. */ 5873 5874 tree 5875 build_aligned_type (tree type, unsigned int align) 5876 { 5877 tree t; 5878 5879 if (TYPE_PACKED (type) 5880 || TYPE_ALIGN (type) == align) 5881 return type; 5882 5883 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) 5884 if (check_aligned_type (t, type, align)) 5885 return t; 5886 5887 t = build_variant_type_copy (type); 5888 TYPE_ALIGN (t) = align; 5889 5890 return t; 5891 } 5892 5893 /* Create a new distinct copy of TYPE. The new type is made its own 5894 MAIN_VARIANT. If TYPE requires structural equality checks, the 5895 resulting type requires structural equality checks; otherwise, its 5896 TYPE_CANONICAL points to itself. */ 5897 5898 tree 5899 build_distinct_type_copy (tree type) 5900 { 5901 tree t = copy_node (type); 5902 5903 TYPE_POINTER_TO (t) = 0; 5904 TYPE_REFERENCE_TO (t) = 0; 5905 5906 /* Set the canonical type either to a new equivalence class, or 5907 propagate the need for structural equality checks. */ 5908 if (TYPE_STRUCTURAL_EQUALITY_P (type)) 5909 SET_TYPE_STRUCTURAL_EQUALITY (t); 5910 else 5911 TYPE_CANONICAL (t) = t; 5912 5913 /* Make it its own variant. */ 5914 TYPE_MAIN_VARIANT (t) = t; 5915 TYPE_NEXT_VARIANT (t) = 0; 5916 5917 /* Note that it is now possible for TYPE_MIN_VALUE to be a value 5918 whose TREE_TYPE is not t. This can also happen in the Ada 5919 frontend when using subtypes. */ 5920 5921 return t; 5922 } 5923 5924 /* Create a new variant of TYPE, equivalent but distinct. This is so 5925 the caller can modify it. TYPE_CANONICAL for the return type will 5926 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types 5927 are considered equal by the language itself (or that both types 5928 require structural equality checks). */ 5929 5930 tree 5931 build_variant_type_copy (tree type) 5932 { 5933 tree t, m = TYPE_MAIN_VARIANT (type); 5934 5935 t = build_distinct_type_copy (type); 5936 5937 /* Since we're building a variant, assume that it is a non-semantic 5938 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */ 5939 TYPE_CANONICAL (t) = TYPE_CANONICAL (type); 5940 5941 /* Add the new type to the chain of variants of TYPE. */ 5942 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); 5943 TYPE_NEXT_VARIANT (m) = t; 5944 TYPE_MAIN_VARIANT (t) = m; 5945 5946 return t; 5947 } 5948 5949 /* Return true if the from tree in both tree maps are equal. */ 5950 5951 int 5952 tree_map_base_eq (const void *va, const void *vb) 5953 { 5954 const struct tree_map_base *const a = (const struct tree_map_base *) va, 5955 *const b = (const struct tree_map_base *) vb; 5956 return (a->from == b->from); 5957 } 5958 5959 /* Hash a from tree in a tree_base_map. */ 5960 5961 unsigned int 5962 tree_map_base_hash (const void *item) 5963 { 5964 return htab_hash_pointer (((const struct tree_map_base *)item)->from); 5965 } 5966 5967 /* Return true if this tree map structure is marked for garbage collection 5968 purposes. We simply return true if the from tree is marked, so that this 5969 structure goes away when the from tree goes away. */ 5970 5971 int 5972 tree_map_base_marked_p (const void *p) 5973 { 5974 return ggc_marked_p (((const struct tree_map_base *) p)->from); 5975 } 5976 5977 /* Hash a from tree in a tree_map. */ 5978 5979 unsigned int 5980 tree_map_hash (const void *item) 5981 { 5982 return (((const struct tree_map *) item)->hash); 5983 } 5984 5985 /* Hash a from tree in a tree_decl_map. */ 5986 5987 unsigned int 5988 tree_decl_map_hash (const void *item) 5989 { 5990 return DECL_UID (((const struct tree_decl_map *) item)->base.from); 5991 } 5992 5993 /* Return the initialization priority for DECL. */ 5994 5995 priority_type 5996 decl_init_priority_lookup (tree decl) 5997 { 5998 struct tree_priority_map *h; 5999 struct tree_map_base in; 6000 6001 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); 6002 in.from = decl; 6003 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in); 6004 return h ? h->init : DEFAULT_INIT_PRIORITY; 6005 } 6006 6007 /* Return the finalization priority for DECL. */ 6008 6009 priority_type 6010 decl_fini_priority_lookup (tree decl) 6011 { 6012 struct tree_priority_map *h; 6013 struct tree_map_base in; 6014 6015 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); 6016 in.from = decl; 6017 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in); 6018 return h ? h->fini : DEFAULT_INIT_PRIORITY; 6019 } 6020 6021 /* Return the initialization and finalization priority information for 6022 DECL. If there is no previous priority information, a freshly 6023 allocated structure is returned. */ 6024 6025 static struct tree_priority_map * 6026 decl_priority_info (tree decl) 6027 { 6028 struct tree_priority_map in; 6029 struct tree_priority_map *h; 6030 void **loc; 6031 6032 in.base.from = decl; 6033 loc = htab_find_slot (init_priority_for_decl, &in, INSERT); 6034 h = (struct tree_priority_map *) *loc; 6035 if (!h) 6036 { 6037 h = ggc_alloc_cleared_tree_priority_map (); 6038 *loc = h; 6039 h->base.from = decl; 6040 h->init = DEFAULT_INIT_PRIORITY; 6041 h->fini = DEFAULT_INIT_PRIORITY; 6042 } 6043 6044 return h; 6045 } 6046 6047 /* Set the initialization priority for DECL to PRIORITY. */ 6048 6049 void 6050 decl_init_priority_insert (tree decl, priority_type priority) 6051 { 6052 struct tree_priority_map *h; 6053 6054 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); 6055 if (priority == DEFAULT_INIT_PRIORITY) 6056 return; 6057 h = decl_priority_info (decl); 6058 h->init = priority; 6059 } 6060 6061 /* Set the finalization priority for DECL to PRIORITY. */ 6062 6063 void 6064 decl_fini_priority_insert (tree decl, priority_type priority) 6065 { 6066 struct tree_priority_map *h; 6067 6068 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); 6069 if (priority == DEFAULT_INIT_PRIORITY) 6070 return; 6071 h = decl_priority_info (decl); 6072 h->fini = priority; 6073 } 6074 6075 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */ 6076 6077 static void 6078 print_debug_expr_statistics (void) 6079 { 6080 fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n", 6081 (long) htab_size (debug_expr_for_decl), 6082 (long) htab_elements (debug_expr_for_decl), 6083 htab_collisions (debug_expr_for_decl)); 6084 } 6085 6086 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */ 6087 6088 static void 6089 print_value_expr_statistics (void) 6090 { 6091 fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n", 6092 (long) htab_size (value_expr_for_decl), 6093 (long) htab_elements (value_expr_for_decl), 6094 htab_collisions (value_expr_for_decl)); 6095 } 6096 6097 /* Lookup a debug expression for FROM, and return it if we find one. */ 6098 6099 tree 6100 decl_debug_expr_lookup (tree from) 6101 { 6102 struct tree_decl_map *h, in; 6103 in.base.from = from; 6104 6105 h = (struct tree_decl_map *) 6106 htab_find_with_hash (debug_expr_for_decl, &in, DECL_UID (from)); 6107 if (h) 6108 return h->to; 6109 return NULL_TREE; 6110 } 6111 6112 /* Insert a mapping FROM->TO in the debug expression hashtable. */ 6113 6114 void 6115 decl_debug_expr_insert (tree from, tree to) 6116 { 6117 struct tree_decl_map *h; 6118 void **loc; 6119 6120 h = ggc_alloc_tree_decl_map (); 6121 h->base.from = from; 6122 h->to = to; 6123 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, DECL_UID (from), 6124 INSERT); 6125 *(struct tree_decl_map **) loc = h; 6126 } 6127 6128 /* Lookup a value expression for FROM, and return it if we find one. */ 6129 6130 tree 6131 decl_value_expr_lookup (tree from) 6132 { 6133 struct tree_decl_map *h, in; 6134 in.base.from = from; 6135 6136 h = (struct tree_decl_map *) 6137 htab_find_with_hash (value_expr_for_decl, &in, DECL_UID (from)); 6138 if (h) 6139 return h->to; 6140 return NULL_TREE; 6141 } 6142 6143 /* Insert a mapping FROM->TO in the value expression hashtable. */ 6144 6145 void 6146 decl_value_expr_insert (tree from, tree to) 6147 { 6148 struct tree_decl_map *h; 6149 void **loc; 6150 6151 h = ggc_alloc_tree_decl_map (); 6152 h->base.from = from; 6153 h->to = to; 6154 loc = htab_find_slot_with_hash (value_expr_for_decl, h, DECL_UID (from), 6155 INSERT); 6156 *(struct tree_decl_map **) loc = h; 6157 } 6158 6159 /* Lookup a vector of debug arguments for FROM, and return it if we 6160 find one. */ 6161 6162 vec<tree, va_gc> ** 6163 decl_debug_args_lookup (tree from) 6164 { 6165 struct tree_vec_map *h, in; 6166 6167 if (!DECL_HAS_DEBUG_ARGS_P (from)) 6168 return NULL; 6169 gcc_checking_assert (debug_args_for_decl != NULL); 6170 in.base.from = from; 6171 h = (struct tree_vec_map *) 6172 htab_find_with_hash (debug_args_for_decl, &in, DECL_UID (from)); 6173 if (h) 6174 return &h->to; 6175 return NULL; 6176 } 6177 6178 /* Insert a mapping FROM->empty vector of debug arguments in the value 6179 expression hashtable. */ 6180 6181 vec<tree, va_gc> ** 6182 decl_debug_args_insert (tree from) 6183 { 6184 struct tree_vec_map *h; 6185 void **loc; 6186 6187 if (DECL_HAS_DEBUG_ARGS_P (from)) 6188 return decl_debug_args_lookup (from); 6189 if (debug_args_for_decl == NULL) 6190 debug_args_for_decl = htab_create_ggc (64, tree_vec_map_hash, 6191 tree_vec_map_eq, 0); 6192 h = ggc_alloc_tree_vec_map (); 6193 h->base.from = from; 6194 h->to = NULL; 6195 loc = htab_find_slot_with_hash (debug_args_for_decl, h, DECL_UID (from), 6196 INSERT); 6197 *(struct tree_vec_map **) loc = h; 6198 DECL_HAS_DEBUG_ARGS_P (from) = 1; 6199 return &h->to; 6200 } 6201 6202 /* Hashing of types so that we don't make duplicates. 6203 The entry point is `type_hash_canon'. */ 6204 6205 /* Compute a hash code for a list of types (chain of TREE_LIST nodes 6206 with types in the TREE_VALUE slots), by adding the hash codes 6207 of the individual types. */ 6208 6209 static unsigned int 6210 type_hash_list (const_tree list, hashval_t hashcode) 6211 { 6212 const_tree tail; 6213 6214 for (tail = list; tail; tail = TREE_CHAIN (tail)) 6215 if (TREE_VALUE (tail) != error_mark_node) 6216 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)), 6217 hashcode); 6218 6219 return hashcode; 6220 } 6221 6222 /* These are the Hashtable callback functions. */ 6223 6224 /* Returns true iff the types are equivalent. */ 6225 6226 static int 6227 type_hash_eq (const void *va, const void *vb) 6228 { 6229 const struct type_hash *const a = (const struct type_hash *) va, 6230 *const b = (const struct type_hash *) vb; 6231 6232 /* First test the things that are the same for all types. */ 6233 if (a->hash != b->hash 6234 || TREE_CODE (a->type) != TREE_CODE (b->type) 6235 || TREE_TYPE (a->type) != TREE_TYPE (b->type) 6236 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type), 6237 TYPE_ATTRIBUTES (b->type)) 6238 || (TREE_CODE (a->type) != COMPLEX_TYPE 6239 && TYPE_NAME (a->type) != TYPE_NAME (b->type))) 6240 return 0; 6241 6242 /* Be careful about comparing arrays before and after the element type 6243 has been completed; don't compare TYPE_ALIGN unless both types are 6244 complete. */ 6245 if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type) 6246 && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) 6247 || TYPE_MODE (a->type) != TYPE_MODE (b->type))) 6248 return 0; 6249 6250 switch (TREE_CODE (a->type)) 6251 { 6252 case VOID_TYPE: 6253 case COMPLEX_TYPE: 6254 case POINTER_TYPE: 6255 case REFERENCE_TYPE: 6256 case NULLPTR_TYPE: 6257 return 1; 6258 6259 case VECTOR_TYPE: 6260 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type); 6261 6262 case ENUMERAL_TYPE: 6263 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type) 6264 && !(TYPE_VALUES (a->type) 6265 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST 6266 && TYPE_VALUES (b->type) 6267 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST 6268 && type_list_equal (TYPE_VALUES (a->type), 6269 TYPE_VALUES (b->type)))) 6270 return 0; 6271 6272 /* ... fall through ... */ 6273 6274 case INTEGER_TYPE: 6275 case REAL_TYPE: 6276 case BOOLEAN_TYPE: 6277 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type) 6278 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type), 6279 TYPE_MAX_VALUE (b->type))) 6280 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type) 6281 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type), 6282 TYPE_MIN_VALUE (b->type)))); 6283 6284 case FIXED_POINT_TYPE: 6285 return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type); 6286 6287 case OFFSET_TYPE: 6288 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type); 6289 6290 case METHOD_TYPE: 6291 if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type) 6292 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type) 6293 || (TYPE_ARG_TYPES (a->type) 6294 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST 6295 && TYPE_ARG_TYPES (b->type) 6296 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST 6297 && type_list_equal (TYPE_ARG_TYPES (a->type), 6298 TYPE_ARG_TYPES (b->type))))) 6299 break; 6300 return 0; 6301 case ARRAY_TYPE: 6302 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type); 6303 6304 case RECORD_TYPE: 6305 case UNION_TYPE: 6306 case QUAL_UNION_TYPE: 6307 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type) 6308 || (TYPE_FIELDS (a->type) 6309 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST 6310 && TYPE_FIELDS (b->type) 6311 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST 6312 && type_list_equal (TYPE_FIELDS (a->type), 6313 TYPE_FIELDS (b->type)))); 6314 6315 case FUNCTION_TYPE: 6316 if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type) 6317 || (TYPE_ARG_TYPES (a->type) 6318 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST 6319 && TYPE_ARG_TYPES (b->type) 6320 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST 6321 && type_list_equal (TYPE_ARG_TYPES (a->type), 6322 TYPE_ARG_TYPES (b->type)))) 6323 break; 6324 return 0; 6325 6326 default: 6327 return 0; 6328 } 6329 6330 if (lang_hooks.types.type_hash_eq != NULL) 6331 return lang_hooks.types.type_hash_eq (a->type, b->type); 6332 6333 return 1; 6334 } 6335 6336 /* Return the cached hash value. */ 6337 6338 static hashval_t 6339 type_hash_hash (const void *item) 6340 { 6341 return ((const struct type_hash *) item)->hash; 6342 } 6343 6344 /* Look in the type hash table for a type isomorphic to TYPE. 6345 If one is found, return it. Otherwise return 0. */ 6346 6347 tree 6348 type_hash_lookup (hashval_t hashcode, tree type) 6349 { 6350 struct type_hash *h, in; 6351 6352 /* The TYPE_ALIGN field of a type is set by layout_type(), so we 6353 must call that routine before comparing TYPE_ALIGNs. */ 6354 layout_type (type); 6355 6356 in.hash = hashcode; 6357 in.type = type; 6358 6359 h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in, 6360 hashcode); 6361 if (h) 6362 return h->type; 6363 return NULL_TREE; 6364 } 6365 6366 /* Add an entry to the type-hash-table 6367 for a type TYPE whose hash code is HASHCODE. */ 6368 6369 void 6370 type_hash_add (hashval_t hashcode, tree type) 6371 { 6372 struct type_hash *h; 6373 void **loc; 6374 6375 h = ggc_alloc_type_hash (); 6376 h->hash = hashcode; 6377 h->type = type; 6378 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT); 6379 *loc = (void *)h; 6380 } 6381 6382 /* Given TYPE, and HASHCODE its hash code, return the canonical 6383 object for an identical type if one already exists. 6384 Otherwise, return TYPE, and record it as the canonical object. 6385 6386 To use this function, first create a type of the sort you want. 6387 Then compute its hash code from the fields of the type that 6388 make it different from other similar types. 6389 Then call this function and use the value. */ 6390 6391 tree 6392 type_hash_canon (unsigned int hashcode, tree type) 6393 { 6394 tree t1; 6395 6396 /* The hash table only contains main variants, so ensure that's what we're 6397 being passed. */ 6398 gcc_assert (TYPE_MAIN_VARIANT (type) == type); 6399 6400 /* See if the type is in the hash table already. If so, return it. 6401 Otherwise, add the type. */ 6402 t1 = type_hash_lookup (hashcode, type); 6403 if (t1 != 0) 6404 { 6405 if (GATHER_STATISTICS) 6406 { 6407 tree_code_counts[(int) TREE_CODE (type)]--; 6408 tree_node_counts[(int) t_kind]--; 6409 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type_non_common); 6410 } 6411 return t1; 6412 } 6413 else 6414 { 6415 type_hash_add (hashcode, type); 6416 return type; 6417 } 6418 } 6419 6420 /* See if the data pointed to by the type hash table is marked. We consider 6421 it marked if the type is marked or if a debug type number or symbol 6422 table entry has been made for the type. */ 6423 6424 static int 6425 type_hash_marked_p (const void *p) 6426 { 6427 const_tree const type = ((const struct type_hash *) p)->type; 6428 6429 return ggc_marked_p (type); 6430 } 6431 6432 static void 6433 print_type_hash_statistics (void) 6434 { 6435 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n", 6436 (long) htab_size (type_hash_table), 6437 (long) htab_elements (type_hash_table), 6438 htab_collisions (type_hash_table)); 6439 } 6440 6441 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes 6442 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots), 6443 by adding the hash codes of the individual attributes. */ 6444 6445 static unsigned int 6446 attribute_hash_list (const_tree list, hashval_t hashcode) 6447 { 6448 const_tree tail; 6449 6450 for (tail = list; tail; tail = TREE_CHAIN (tail)) 6451 /* ??? Do we want to add in TREE_VALUE too? */ 6452 hashcode = iterative_hash_object 6453 (IDENTIFIER_HASH_VALUE (get_attribute_name (tail)), hashcode); 6454 return hashcode; 6455 } 6456 6457 /* Given two lists of attributes, return true if list l2 is 6458 equivalent to l1. */ 6459 6460 int 6461 attribute_list_equal (const_tree l1, const_tree l2) 6462 { 6463 if (l1 == l2) 6464 return 1; 6465 6466 return attribute_list_contained (l1, l2) 6467 && attribute_list_contained (l2, l1); 6468 } 6469 6470 /* Given two lists of attributes, return true if list L2 is 6471 completely contained within L1. */ 6472 /* ??? This would be faster if attribute names were stored in a canonicalized 6473 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method 6474 must be used to show these elements are equivalent (which they are). */ 6475 /* ??? It's not clear that attributes with arguments will always be handled 6476 correctly. */ 6477 6478 int 6479 attribute_list_contained (const_tree l1, const_tree l2) 6480 { 6481 const_tree t1, t2; 6482 6483 /* First check the obvious, maybe the lists are identical. */ 6484 if (l1 == l2) 6485 return 1; 6486 6487 /* Maybe the lists are similar. */ 6488 for (t1 = l1, t2 = l2; 6489 t1 != 0 && t2 != 0 6490 && get_attribute_name (t1) == get_attribute_name (t2) 6491 && TREE_VALUE (t1) == TREE_VALUE (t2); 6492 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) 6493 ; 6494 6495 /* Maybe the lists are equal. */ 6496 if (t1 == 0 && t2 == 0) 6497 return 1; 6498 6499 for (; t2 != 0; t2 = TREE_CHAIN (t2)) 6500 { 6501 const_tree attr; 6502 /* This CONST_CAST is okay because lookup_attribute does not 6503 modify its argument and the return value is assigned to a 6504 const_tree. */ 6505 for (attr = lookup_ident_attribute (get_attribute_name (t2), CONST_CAST_TREE(l1)); 6506 attr != NULL_TREE && !attribute_value_equal (t2, attr); 6507 attr = lookup_ident_attribute (get_attribute_name (t2), TREE_CHAIN (attr))) 6508 ; 6509 6510 if (attr == NULL_TREE) 6511 return 0; 6512 } 6513 6514 return 1; 6515 } 6516 6517 /* Given two lists of types 6518 (chains of TREE_LIST nodes with types in the TREE_VALUE slots) 6519 return 1 if the lists contain the same types in the same order. 6520 Also, the TREE_PURPOSEs must match. */ 6521 6522 int 6523 type_list_equal (const_tree l1, const_tree l2) 6524 { 6525 const_tree t1, t2; 6526 6527 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) 6528 if (TREE_VALUE (t1) != TREE_VALUE (t2) 6529 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2) 6530 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)) 6531 && (TREE_TYPE (TREE_PURPOSE (t1)) 6532 == TREE_TYPE (TREE_PURPOSE (t2)))))) 6533 return 0; 6534 6535 return t1 == t2; 6536 } 6537 6538 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE 6539 given by TYPE. If the argument list accepts variable arguments, 6540 then this function counts only the ordinary arguments. */ 6541 6542 int 6543 type_num_arguments (const_tree type) 6544 { 6545 int i = 0; 6546 tree t; 6547 6548 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t)) 6549 /* If the function does not take a variable number of arguments, 6550 the last element in the list will have type `void'. */ 6551 if (VOID_TYPE_P (TREE_VALUE (t))) 6552 break; 6553 else 6554 ++i; 6555 6556 return i; 6557 } 6558 6559 /* Nonzero if integer constants T1 and T2 6560 represent the same constant value. */ 6561 6562 int 6563 tree_int_cst_equal (const_tree t1, const_tree t2) 6564 { 6565 if (t1 == t2) 6566 return 1; 6567 6568 if (t1 == 0 || t2 == 0) 6569 return 0; 6570 6571 if (TREE_CODE (t1) == INTEGER_CST 6572 && TREE_CODE (t2) == INTEGER_CST 6573 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) 6574 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2)) 6575 return 1; 6576 6577 return 0; 6578 } 6579 6580 /* Nonzero if integer constants T1 and T2 represent values that satisfy <. 6581 The precise way of comparison depends on their data type. */ 6582 6583 int 6584 tree_int_cst_lt (const_tree t1, const_tree t2) 6585 { 6586 if (t1 == t2) 6587 return 0; 6588 6589 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2))) 6590 { 6591 int t1_sgn = tree_int_cst_sgn (t1); 6592 int t2_sgn = tree_int_cst_sgn (t2); 6593 6594 if (t1_sgn < t2_sgn) 6595 return 1; 6596 else if (t1_sgn > t2_sgn) 6597 return 0; 6598 /* Otherwise, both are non-negative, so we compare them as 6599 unsigned just in case one of them would overflow a signed 6600 type. */ 6601 } 6602 else if (!TYPE_UNSIGNED (TREE_TYPE (t1))) 6603 return INT_CST_LT (t1, t2); 6604 6605 return INT_CST_LT_UNSIGNED (t1, t2); 6606 } 6607 6608 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */ 6609 6610 int 6611 tree_int_cst_compare (const_tree t1, const_tree t2) 6612 { 6613 if (tree_int_cst_lt (t1, t2)) 6614 return -1; 6615 else if (tree_int_cst_lt (t2, t1)) 6616 return 1; 6617 else 6618 return 0; 6619 } 6620 6621 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on 6622 the host. If POS is zero, the value can be represented in a single 6623 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can 6624 be represented in a single unsigned HOST_WIDE_INT. */ 6625 6626 int 6627 host_integerp (const_tree t, int pos) 6628 { 6629 if (t == NULL_TREE) 6630 return 0; 6631 6632 return (TREE_CODE (t) == INTEGER_CST 6633 && ((TREE_INT_CST_HIGH (t) == 0 6634 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0) 6635 || (! pos && TREE_INT_CST_HIGH (t) == -1 6636 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0 6637 && !TYPE_UNSIGNED (TREE_TYPE (t))) 6638 || (pos && TREE_INT_CST_HIGH (t) == 0))); 6639 } 6640 6641 /* Return the HOST_WIDE_INT least significant bits of T if it is an 6642 INTEGER_CST and there is no overflow. POS is nonzero if the result must 6643 be non-negative. We must be able to satisfy the above conditions. */ 6644 6645 HOST_WIDE_INT 6646 tree_low_cst (const_tree t, int pos) 6647 { 6648 gcc_assert (host_integerp (t, pos)); 6649 return TREE_INT_CST_LOW (t); 6650 } 6651 6652 /* Return the HOST_WIDE_INT least significant bits of T, a sizetype 6653 kind INTEGER_CST. This makes sure to properly sign-extend the 6654 constant. */ 6655 6656 HOST_WIDE_INT 6657 size_low_cst (const_tree t) 6658 { 6659 double_int d = tree_to_double_int (t); 6660 return d.sext (TYPE_PRECISION (TREE_TYPE (t))).low; 6661 } 6662 6663 /* Return the most significant (sign) bit of T. */ 6664 6665 int 6666 tree_int_cst_sign_bit (const_tree t) 6667 { 6668 unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1; 6669 unsigned HOST_WIDE_INT w; 6670 6671 if (bitno < HOST_BITS_PER_WIDE_INT) 6672 w = TREE_INT_CST_LOW (t); 6673 else 6674 { 6675 w = TREE_INT_CST_HIGH (t); 6676 bitno -= HOST_BITS_PER_WIDE_INT; 6677 } 6678 6679 return (w >> bitno) & 1; 6680 } 6681 6682 /* Return an indication of the sign of the integer constant T. 6683 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0. 6684 Note that -1 will never be returned if T's type is unsigned. */ 6685 6686 int 6687 tree_int_cst_sgn (const_tree t) 6688 { 6689 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0) 6690 return 0; 6691 else if (TYPE_UNSIGNED (TREE_TYPE (t))) 6692 return 1; 6693 else if (TREE_INT_CST_HIGH (t) < 0) 6694 return -1; 6695 else 6696 return 1; 6697 } 6698 6699 /* Return the minimum number of bits needed to represent VALUE in a 6700 signed or unsigned type, UNSIGNEDP says which. */ 6701 6702 unsigned int 6703 tree_int_cst_min_precision (tree value, bool unsignedp) 6704 { 6705 int log; 6706 6707 /* If the value is negative, compute its negative minus 1. The latter 6708 adjustment is because the absolute value of the largest negative value 6709 is one larger than the largest positive value. This is equivalent to 6710 a bit-wise negation, so use that operation instead. */ 6711 6712 if (tree_int_cst_sgn (value) < 0) 6713 value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value); 6714 6715 /* Return the number of bits needed, taking into account the fact 6716 that we need one more bit for a signed than unsigned type. */ 6717 6718 if (integer_zerop (value)) 6719 log = 0; 6720 else 6721 log = tree_floor_log2 (value); 6722 6723 return log + 1 + !unsignedp; 6724 } 6725 6726 /* Compare two constructor-element-type constants. Return 1 if the lists 6727 are known to be equal; otherwise return 0. */ 6728 6729 int 6730 simple_cst_list_equal (const_tree l1, const_tree l2) 6731 { 6732 while (l1 != NULL_TREE && l2 != NULL_TREE) 6733 { 6734 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1) 6735 return 0; 6736 6737 l1 = TREE_CHAIN (l1); 6738 l2 = TREE_CHAIN (l2); 6739 } 6740 6741 return l1 == l2; 6742 } 6743 6744 /* Return truthvalue of whether T1 is the same tree structure as T2. 6745 Return 1 if they are the same. 6746 Return 0 if they are understandably different. 6747 Return -1 if either contains tree structure not understood by 6748 this function. */ 6749 6750 int 6751 simple_cst_equal (const_tree t1, const_tree t2) 6752 { 6753 enum tree_code code1, code2; 6754 int cmp; 6755 int i; 6756 6757 if (t1 == t2) 6758 return 1; 6759 if (t1 == 0 || t2 == 0) 6760 return 0; 6761 6762 code1 = TREE_CODE (t1); 6763 code2 = TREE_CODE (t2); 6764 6765 if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR) 6766 { 6767 if (CONVERT_EXPR_CODE_P (code2) 6768 || code2 == NON_LVALUE_EXPR) 6769 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 6770 else 6771 return simple_cst_equal (TREE_OPERAND (t1, 0), t2); 6772 } 6773 6774 else if (CONVERT_EXPR_CODE_P (code2) 6775 || code2 == NON_LVALUE_EXPR) 6776 return simple_cst_equal (t1, TREE_OPERAND (t2, 0)); 6777 6778 if (code1 != code2) 6779 return 0; 6780 6781 switch (code1) 6782 { 6783 case INTEGER_CST: 6784 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) 6785 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2)); 6786 6787 case REAL_CST: 6788 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); 6789 6790 case FIXED_CST: 6791 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2)); 6792 6793 case STRING_CST: 6794 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) 6795 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), 6796 TREE_STRING_LENGTH (t1))); 6797 6798 case CONSTRUCTOR: 6799 { 6800 unsigned HOST_WIDE_INT idx; 6801 vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1); 6802 vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2); 6803 6804 if (vec_safe_length (v1) != vec_safe_length (v2)) 6805 return false; 6806 6807 for (idx = 0; idx < vec_safe_length (v1); ++idx) 6808 /* ??? Should we handle also fields here? */ 6809 if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value)) 6810 return false; 6811 return true; 6812 } 6813 6814 case SAVE_EXPR: 6815 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 6816 6817 case CALL_EXPR: 6818 cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)); 6819 if (cmp <= 0) 6820 return cmp; 6821 if (call_expr_nargs (t1) != call_expr_nargs (t2)) 6822 return 0; 6823 { 6824 const_tree arg1, arg2; 6825 const_call_expr_arg_iterator iter1, iter2; 6826 for (arg1 = first_const_call_expr_arg (t1, &iter1), 6827 arg2 = first_const_call_expr_arg (t2, &iter2); 6828 arg1 && arg2; 6829 arg1 = next_const_call_expr_arg (&iter1), 6830 arg2 = next_const_call_expr_arg (&iter2)) 6831 { 6832 cmp = simple_cst_equal (arg1, arg2); 6833 if (cmp <= 0) 6834 return cmp; 6835 } 6836 return arg1 == arg2; 6837 } 6838 6839 case TARGET_EXPR: 6840 /* Special case: if either target is an unallocated VAR_DECL, 6841 it means that it's going to be unified with whatever the 6842 TARGET_EXPR is really supposed to initialize, so treat it 6843 as being equivalent to anything. */ 6844 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL 6845 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE 6846 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0))) 6847 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL 6848 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE 6849 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0)))) 6850 cmp = 1; 6851 else 6852 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 6853 6854 if (cmp <= 0) 6855 return cmp; 6856 6857 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); 6858 6859 case WITH_CLEANUP_EXPR: 6860 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 6861 if (cmp <= 0) 6862 return cmp; 6863 6864 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1)); 6865 6866 case COMPONENT_REF: 6867 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1)) 6868 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); 6869 6870 return 0; 6871 6872 case VAR_DECL: 6873 case PARM_DECL: 6874 case CONST_DECL: 6875 case FUNCTION_DECL: 6876 return 0; 6877 6878 default: 6879 break; 6880 } 6881 6882 /* This general rule works for most tree codes. All exceptions should be 6883 handled above. If this is a language-specific tree code, we can't 6884 trust what might be in the operand, so say we don't know 6885 the situation. */ 6886 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE) 6887 return -1; 6888 6889 switch (TREE_CODE_CLASS (code1)) 6890 { 6891 case tcc_unary: 6892 case tcc_binary: 6893 case tcc_comparison: 6894 case tcc_expression: 6895 case tcc_reference: 6896 case tcc_statement: 6897 cmp = 1; 6898 for (i = 0; i < TREE_CODE_LENGTH (code1); i++) 6899 { 6900 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); 6901 if (cmp <= 0) 6902 return cmp; 6903 } 6904 6905 return cmp; 6906 6907 default: 6908 return -1; 6909 } 6910 } 6911 6912 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value. 6913 Return -1, 0, or 1 if the value of T is less than, equal to, or greater 6914 than U, respectively. */ 6915 6916 int 6917 compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u) 6918 { 6919 if (tree_int_cst_sgn (t) < 0) 6920 return -1; 6921 else if (TREE_INT_CST_HIGH (t) != 0) 6922 return 1; 6923 else if (TREE_INT_CST_LOW (t) == u) 6924 return 0; 6925 else if (TREE_INT_CST_LOW (t) < u) 6926 return -1; 6927 else 6928 return 1; 6929 } 6930 6931 /* Return true if SIZE represents a constant size that is in bounds of 6932 what the middle-end and the backend accepts (covering not more than 6933 half of the address-space). */ 6934 6935 bool 6936 valid_constant_size_p (const_tree size) 6937 { 6938 if (! host_integerp (size, 1) 6939 || TREE_OVERFLOW (size) 6940 || tree_int_cst_sign_bit (size) != 0) 6941 return false; 6942 return true; 6943 } 6944 6945 /* Return true if CODE represents an associative tree code. Otherwise 6946 return false. */ 6947 bool 6948 associative_tree_code (enum tree_code code) 6949 { 6950 switch (code) 6951 { 6952 case BIT_IOR_EXPR: 6953 case BIT_AND_EXPR: 6954 case BIT_XOR_EXPR: 6955 case PLUS_EXPR: 6956 case MULT_EXPR: 6957 case MIN_EXPR: 6958 case MAX_EXPR: 6959 return true; 6960 6961 default: 6962 break; 6963 } 6964 return false; 6965 } 6966 6967 /* Return true if CODE represents a commutative tree code. Otherwise 6968 return false. */ 6969 bool 6970 commutative_tree_code (enum tree_code code) 6971 { 6972 switch (code) 6973 { 6974 case PLUS_EXPR: 6975 case MULT_EXPR: 6976 case MULT_HIGHPART_EXPR: 6977 case MIN_EXPR: 6978 case MAX_EXPR: 6979 case BIT_IOR_EXPR: 6980 case BIT_XOR_EXPR: 6981 case BIT_AND_EXPR: 6982 case NE_EXPR: 6983 case EQ_EXPR: 6984 case UNORDERED_EXPR: 6985 case ORDERED_EXPR: 6986 case UNEQ_EXPR: 6987 case LTGT_EXPR: 6988 case TRUTH_AND_EXPR: 6989 case TRUTH_XOR_EXPR: 6990 case TRUTH_OR_EXPR: 6991 case WIDEN_MULT_EXPR: 6992 case VEC_WIDEN_MULT_HI_EXPR: 6993 case VEC_WIDEN_MULT_LO_EXPR: 6994 case VEC_WIDEN_MULT_EVEN_EXPR: 6995 case VEC_WIDEN_MULT_ODD_EXPR: 6996 return true; 6997 6998 default: 6999 break; 7000 } 7001 return false; 7002 } 7003 7004 /* Return true if CODE represents a ternary tree code for which the 7005 first two operands are commutative. Otherwise return false. */ 7006 bool 7007 commutative_ternary_tree_code (enum tree_code code) 7008 { 7009 switch (code) 7010 { 7011 case WIDEN_MULT_PLUS_EXPR: 7012 case WIDEN_MULT_MINUS_EXPR: 7013 return true; 7014 7015 default: 7016 break; 7017 } 7018 return false; 7019 } 7020 7021 /* Generate a hash value for an expression. This can be used iteratively 7022 by passing a previous result as the VAL argument. 7023 7024 This function is intended to produce the same hash for expressions which 7025 would compare equal using operand_equal_p. */ 7026 7027 hashval_t 7028 iterative_hash_expr (const_tree t, hashval_t val) 7029 { 7030 int i; 7031 enum tree_code code; 7032 char tclass; 7033 7034 if (t == NULL_TREE) 7035 return iterative_hash_hashval_t (0, val); 7036 7037 code = TREE_CODE (t); 7038 7039 switch (code) 7040 { 7041 /* Alas, constants aren't shared, so we can't rely on pointer 7042 identity. */ 7043 case INTEGER_CST: 7044 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val); 7045 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val); 7046 case REAL_CST: 7047 { 7048 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t)); 7049 7050 return iterative_hash_hashval_t (val2, val); 7051 } 7052 case FIXED_CST: 7053 { 7054 unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t)); 7055 7056 return iterative_hash_hashval_t (val2, val); 7057 } 7058 case STRING_CST: 7059 return iterative_hash (TREE_STRING_POINTER (t), 7060 TREE_STRING_LENGTH (t), val); 7061 case COMPLEX_CST: 7062 val = iterative_hash_expr (TREE_REALPART (t), val); 7063 return iterative_hash_expr (TREE_IMAGPART (t), val); 7064 case VECTOR_CST: 7065 { 7066 unsigned i; 7067 for (i = 0; i < VECTOR_CST_NELTS (t); ++i) 7068 val = iterative_hash_expr (VECTOR_CST_ELT (t, i), val); 7069 return val; 7070 } 7071 case SSA_NAME: 7072 /* We can just compare by pointer. */ 7073 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t), val); 7074 case PLACEHOLDER_EXPR: 7075 /* The node itself doesn't matter. */ 7076 return val; 7077 case TREE_LIST: 7078 /* A list of expressions, for a CALL_EXPR or as the elements of a 7079 VECTOR_CST. */ 7080 for (; t; t = TREE_CHAIN (t)) 7081 val = iterative_hash_expr (TREE_VALUE (t), val); 7082 return val; 7083 case CONSTRUCTOR: 7084 { 7085 unsigned HOST_WIDE_INT idx; 7086 tree field, value; 7087 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value) 7088 { 7089 val = iterative_hash_expr (field, val); 7090 val = iterative_hash_expr (value, val); 7091 } 7092 return val; 7093 } 7094 case MEM_REF: 7095 { 7096 /* The type of the second operand is relevant, except for 7097 its top-level qualifiers. */ 7098 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t, 1))); 7099 7100 val = iterative_hash_object (TYPE_HASH (type), val); 7101 7102 /* We could use the standard hash computation from this point 7103 on. */ 7104 val = iterative_hash_object (code, val); 7105 val = iterative_hash_expr (TREE_OPERAND (t, 1), val); 7106 val = iterative_hash_expr (TREE_OPERAND (t, 0), val); 7107 return val; 7108 } 7109 case FUNCTION_DECL: 7110 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form. 7111 Otherwise nodes that compare equal according to operand_equal_p might 7112 get different hash codes. However, don't do this for machine specific 7113 or front end builtins, since the function code is overloaded in those 7114 cases. */ 7115 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL 7116 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t))) 7117 { 7118 t = builtin_decl_explicit (DECL_FUNCTION_CODE (t)); 7119 code = TREE_CODE (t); 7120 } 7121 /* FALL THROUGH */ 7122 default: 7123 tclass = TREE_CODE_CLASS (code); 7124 7125 if (tclass == tcc_declaration) 7126 { 7127 /* DECL's have a unique ID */ 7128 val = iterative_hash_host_wide_int (DECL_UID (t), val); 7129 } 7130 else 7131 { 7132 gcc_assert (IS_EXPR_CODE_CLASS (tclass)); 7133 7134 val = iterative_hash_object (code, val); 7135 7136 /* Don't hash the type, that can lead to having nodes which 7137 compare equal according to operand_equal_p, but which 7138 have different hash codes. */ 7139 if (CONVERT_EXPR_CODE_P (code) 7140 || code == NON_LVALUE_EXPR) 7141 { 7142 /* Make sure to include signness in the hash computation. */ 7143 val += TYPE_UNSIGNED (TREE_TYPE (t)); 7144 val = iterative_hash_expr (TREE_OPERAND (t, 0), val); 7145 } 7146 7147 else if (commutative_tree_code (code)) 7148 { 7149 /* It's a commutative expression. We want to hash it the same 7150 however it appears. We do this by first hashing both operands 7151 and then rehashing based on the order of their independent 7152 hashes. */ 7153 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0); 7154 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0); 7155 hashval_t t; 7156 7157 if (one > two) 7158 t = one, one = two, two = t; 7159 7160 val = iterative_hash_hashval_t (one, val); 7161 val = iterative_hash_hashval_t (two, val); 7162 } 7163 else 7164 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i) 7165 val = iterative_hash_expr (TREE_OPERAND (t, i), val); 7166 } 7167 return val; 7168 } 7169 } 7170 7171 /* Generate a hash value for a pair of expressions. This can be used 7172 iteratively by passing a previous result as the VAL argument. 7173 7174 The same hash value is always returned for a given pair of expressions, 7175 regardless of the order in which they are presented. This is useful in 7176 hashing the operands of commutative functions. */ 7177 7178 hashval_t 7179 iterative_hash_exprs_commutative (const_tree t1, 7180 const_tree t2, hashval_t val) 7181 { 7182 hashval_t one = iterative_hash_expr (t1, 0); 7183 hashval_t two = iterative_hash_expr (t2, 0); 7184 hashval_t t; 7185 7186 if (one > two) 7187 t = one, one = two, two = t; 7188 val = iterative_hash_hashval_t (one, val); 7189 val = iterative_hash_hashval_t (two, val); 7190 7191 return val; 7192 } 7193 7194 /* Constructors for pointer, array and function types. 7195 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are 7196 constructed by language-dependent code, not here.) */ 7197 7198 /* Construct, lay out and return the type of pointers to TO_TYPE with 7199 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can 7200 reference all of memory. If such a type has already been 7201 constructed, reuse it. */ 7202 7203 tree 7204 build_pointer_type_for_mode (tree to_type, enum machine_mode mode, 7205 bool can_alias_all) 7206 { 7207 tree t; 7208 7209 if (to_type == error_mark_node) 7210 return error_mark_node; 7211 7212 /* If the pointed-to type has the may_alias attribute set, force 7213 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */ 7214 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type))) 7215 can_alias_all = true; 7216 7217 /* In some cases, languages will have things that aren't a POINTER_TYPE 7218 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO. 7219 In that case, return that type without regard to the rest of our 7220 operands. 7221 7222 ??? This is a kludge, but consistent with the way this function has 7223 always operated and there doesn't seem to be a good way to avoid this 7224 at the moment. */ 7225 if (TYPE_POINTER_TO (to_type) != 0 7226 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE) 7227 return TYPE_POINTER_TO (to_type); 7228 7229 /* First, if we already have a type for pointers to TO_TYPE and it's 7230 the proper mode, use it. */ 7231 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t)) 7232 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all) 7233 return t; 7234 7235 t = make_node (POINTER_TYPE); 7236 7237 TREE_TYPE (t) = to_type; 7238 SET_TYPE_MODE (t, mode); 7239 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all; 7240 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type); 7241 TYPE_POINTER_TO (to_type) = t; 7242 7243 if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) 7244 SET_TYPE_STRUCTURAL_EQUALITY (t); 7245 else if (TYPE_CANONICAL (to_type) != to_type) 7246 TYPE_CANONICAL (t) 7247 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type), 7248 mode, can_alias_all); 7249 7250 /* Lay out the type. This function has many callers that are concerned 7251 with expression-construction, and this simplifies them all. */ 7252 layout_type (t); 7253 7254 return t; 7255 } 7256 7257 /* By default build pointers in ptr_mode. */ 7258 7259 tree 7260 build_pointer_type (tree to_type) 7261 { 7262 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC 7263 : TYPE_ADDR_SPACE (to_type); 7264 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as); 7265 return build_pointer_type_for_mode (to_type, pointer_mode, false); 7266 } 7267 7268 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */ 7269 7270 tree 7271 build_reference_type_for_mode (tree to_type, enum machine_mode mode, 7272 bool can_alias_all) 7273 { 7274 tree t; 7275 7276 if (to_type == error_mark_node) 7277 return error_mark_node; 7278 7279 /* If the pointed-to type has the may_alias attribute set, force 7280 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */ 7281 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type))) 7282 can_alias_all = true; 7283 7284 /* In some cases, languages will have things that aren't a REFERENCE_TYPE 7285 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO. 7286 In that case, return that type without regard to the rest of our 7287 operands. 7288 7289 ??? This is a kludge, but consistent with the way this function has 7290 always operated and there doesn't seem to be a good way to avoid this 7291 at the moment. */ 7292 if (TYPE_REFERENCE_TO (to_type) != 0 7293 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE) 7294 return TYPE_REFERENCE_TO (to_type); 7295 7296 /* First, if we already have a type for pointers to TO_TYPE and it's 7297 the proper mode, use it. */ 7298 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t)) 7299 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all) 7300 return t; 7301 7302 t = make_node (REFERENCE_TYPE); 7303 7304 TREE_TYPE (t) = to_type; 7305 SET_TYPE_MODE (t, mode); 7306 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all; 7307 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type); 7308 TYPE_REFERENCE_TO (to_type) = t; 7309 7310 if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) 7311 SET_TYPE_STRUCTURAL_EQUALITY (t); 7312 else if (TYPE_CANONICAL (to_type) != to_type) 7313 TYPE_CANONICAL (t) 7314 = build_reference_type_for_mode (TYPE_CANONICAL (to_type), 7315 mode, can_alias_all); 7316 7317 layout_type (t); 7318 7319 return t; 7320 } 7321 7322 7323 /* Build the node for the type of references-to-TO_TYPE by default 7324 in ptr_mode. */ 7325 7326 tree 7327 build_reference_type (tree to_type) 7328 { 7329 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC 7330 : TYPE_ADDR_SPACE (to_type); 7331 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as); 7332 return build_reference_type_for_mode (to_type, pointer_mode, false); 7333 } 7334 7335 /* Build a type that is compatible with t but has no cv quals anywhere 7336 in its type, thus 7337 7338 const char *const *const * -> char ***. */ 7339 7340 tree 7341 build_type_no_quals (tree t) 7342 { 7343 switch (TREE_CODE (t)) 7344 { 7345 case POINTER_TYPE: 7346 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)), 7347 TYPE_MODE (t), 7348 TYPE_REF_CAN_ALIAS_ALL (t)); 7349 case REFERENCE_TYPE: 7350 return 7351 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)), 7352 TYPE_MODE (t), 7353 TYPE_REF_CAN_ALIAS_ALL (t)); 7354 default: 7355 return TYPE_MAIN_VARIANT (t); 7356 } 7357 } 7358 7359 #define MAX_INT_CACHED_PREC \ 7360 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64) 7361 static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2]; 7362 7363 /* Builds a signed or unsigned integer type of precision PRECISION. 7364 Used for C bitfields whose precision does not match that of 7365 built-in target types. */ 7366 tree 7367 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision, 7368 int unsignedp) 7369 { 7370 tree itype, ret; 7371 7372 if (unsignedp) 7373 unsignedp = MAX_INT_CACHED_PREC + 1; 7374 7375 if (precision <= MAX_INT_CACHED_PREC) 7376 { 7377 itype = nonstandard_integer_type_cache[precision + unsignedp]; 7378 if (itype) 7379 return itype; 7380 } 7381 7382 itype = make_node (INTEGER_TYPE); 7383 TYPE_PRECISION (itype) = precision; 7384 7385 if (unsignedp) 7386 fixup_unsigned_type (itype); 7387 else 7388 fixup_signed_type (itype); 7389 7390 ret = itype; 7391 if (host_integerp (TYPE_MAX_VALUE (itype), 1)) 7392 ret = type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype); 7393 if (precision <= MAX_INT_CACHED_PREC) 7394 nonstandard_integer_type_cache[precision + unsignedp] = ret; 7395 7396 return ret; 7397 } 7398 7399 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE 7400 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED 7401 is true, reuse such a type that has already been constructed. */ 7402 7403 static tree 7404 build_range_type_1 (tree type, tree lowval, tree highval, bool shared) 7405 { 7406 tree itype = make_node (INTEGER_TYPE); 7407 hashval_t hashcode = 0; 7408 7409 TREE_TYPE (itype) = type; 7410 7411 TYPE_MIN_VALUE (itype) = fold_convert (type, lowval); 7412 TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL; 7413 7414 TYPE_PRECISION (itype) = TYPE_PRECISION (type); 7415 SET_TYPE_MODE (itype, TYPE_MODE (type)); 7416 TYPE_SIZE (itype) = TYPE_SIZE (type); 7417 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type); 7418 TYPE_ALIGN (itype) = TYPE_ALIGN (type); 7419 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type); 7420 7421 if (!shared) 7422 return itype; 7423 7424 if ((TYPE_MIN_VALUE (itype) 7425 && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST) 7426 || (TYPE_MAX_VALUE (itype) 7427 && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST)) 7428 { 7429 /* Since we cannot reliably merge this type, we need to compare it using 7430 structural equality checks. */ 7431 SET_TYPE_STRUCTURAL_EQUALITY (itype); 7432 return itype; 7433 } 7434 7435 hashcode = iterative_hash_expr (TYPE_MIN_VALUE (itype), hashcode); 7436 hashcode = iterative_hash_expr (TYPE_MAX_VALUE (itype), hashcode); 7437 hashcode = iterative_hash_hashval_t (TYPE_HASH (type), hashcode); 7438 itype = type_hash_canon (hashcode, itype); 7439 7440 return itype; 7441 } 7442 7443 /* Wrapper around build_range_type_1 with SHARED set to true. */ 7444 7445 tree 7446 build_range_type (tree type, tree lowval, tree highval) 7447 { 7448 return build_range_type_1 (type, lowval, highval, true); 7449 } 7450 7451 /* Wrapper around build_range_type_1 with SHARED set to false. */ 7452 7453 tree 7454 build_nonshared_range_type (tree type, tree lowval, tree highval) 7455 { 7456 return build_range_type_1 (type, lowval, highval, false); 7457 } 7458 7459 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE. 7460 MAXVAL should be the maximum value in the domain 7461 (one less than the length of the array). 7462 7463 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT. 7464 We don't enforce this limit, that is up to caller (e.g. language front end). 7465 The limit exists because the result is a signed type and we don't handle 7466 sizes that use more than one HOST_WIDE_INT. */ 7467 7468 tree 7469 build_index_type (tree maxval) 7470 { 7471 return build_range_type (sizetype, size_zero_node, maxval); 7472 } 7473 7474 /* Return true if the debug information for TYPE, a subtype, should be emitted 7475 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the 7476 high bound, respectively. Sometimes doing so unnecessarily obfuscates the 7477 debug info and doesn't reflect the source code. */ 7478 7479 bool 7480 subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval) 7481 { 7482 tree base_type = TREE_TYPE (type), low, high; 7483 7484 /* Subrange types have a base type which is an integral type. */ 7485 if (!INTEGRAL_TYPE_P (base_type)) 7486 return false; 7487 7488 /* Get the real bounds of the subtype. */ 7489 if (lang_hooks.types.get_subrange_bounds) 7490 lang_hooks.types.get_subrange_bounds (type, &low, &high); 7491 else 7492 { 7493 low = TYPE_MIN_VALUE (type); 7494 high = TYPE_MAX_VALUE (type); 7495 } 7496 7497 /* If the type and its base type have the same representation and the same 7498 name, then the type is not a subrange but a copy of the base type. */ 7499 if ((TREE_CODE (base_type) == INTEGER_TYPE 7500 || TREE_CODE (base_type) == BOOLEAN_TYPE) 7501 && int_size_in_bytes (type) == int_size_in_bytes (base_type) 7502 && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type)) 7503 && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))) 7504 { 7505 tree type_name = TYPE_NAME (type); 7506 tree base_type_name = TYPE_NAME (base_type); 7507 7508 if (type_name && TREE_CODE (type_name) == TYPE_DECL) 7509 type_name = DECL_NAME (type_name); 7510 7511 if (base_type_name && TREE_CODE (base_type_name) == TYPE_DECL) 7512 base_type_name = DECL_NAME (base_type_name); 7513 7514 if (type_name == base_type_name) 7515 return false; 7516 } 7517 7518 if (lowval) 7519 *lowval = low; 7520 if (highval) 7521 *highval = high; 7522 return true; 7523 } 7524 7525 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE 7526 and number of elements specified by the range of values of INDEX_TYPE. 7527 If SHARED is true, reuse such a type that has already been constructed. */ 7528 7529 static tree 7530 build_array_type_1 (tree elt_type, tree index_type, bool shared) 7531 { 7532 tree t; 7533 7534 if (TREE_CODE (elt_type) == FUNCTION_TYPE) 7535 { 7536 error ("arrays of functions are not meaningful"); 7537 elt_type = integer_type_node; 7538 } 7539 7540 t = make_node (ARRAY_TYPE); 7541 TREE_TYPE (t) = elt_type; 7542 TYPE_DOMAIN (t) = index_type; 7543 TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type); 7544 layout_type (t); 7545 7546 /* If the element type is incomplete at this point we get marked for 7547 structural equality. Do not record these types in the canonical 7548 type hashtable. */ 7549 if (TYPE_STRUCTURAL_EQUALITY_P (t)) 7550 return t; 7551 7552 if (shared) 7553 { 7554 hashval_t hashcode = iterative_hash_object (TYPE_HASH (elt_type), 0); 7555 if (index_type) 7556 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); 7557 t = type_hash_canon (hashcode, t); 7558 } 7559 7560 if (TYPE_CANONICAL (t) == t) 7561 { 7562 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) 7563 || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))) 7564 SET_TYPE_STRUCTURAL_EQUALITY (t); 7565 else if (TYPE_CANONICAL (elt_type) != elt_type 7566 || (index_type && TYPE_CANONICAL (index_type) != index_type)) 7567 TYPE_CANONICAL (t) 7568 = build_array_type_1 (TYPE_CANONICAL (elt_type), 7569 index_type 7570 ? TYPE_CANONICAL (index_type) : NULL_TREE, 7571 shared); 7572 } 7573 7574 return t; 7575 } 7576 7577 /* Wrapper around build_array_type_1 with SHARED set to true. */ 7578 7579 tree 7580 build_array_type (tree elt_type, tree index_type) 7581 { 7582 return build_array_type_1 (elt_type, index_type, true); 7583 } 7584 7585 /* Wrapper around build_array_type_1 with SHARED set to false. */ 7586 7587 tree 7588 build_nonshared_array_type (tree elt_type, tree index_type) 7589 { 7590 return build_array_type_1 (elt_type, index_type, false); 7591 } 7592 7593 /* Return a representation of ELT_TYPE[NELTS], using indices of type 7594 sizetype. */ 7595 7596 tree 7597 build_array_type_nelts (tree elt_type, unsigned HOST_WIDE_INT nelts) 7598 { 7599 return build_array_type (elt_type, build_index_type (size_int (nelts - 1))); 7600 } 7601 7602 /* Recursively examines the array elements of TYPE, until a non-array 7603 element type is found. */ 7604 7605 tree 7606 strip_array_types (tree type) 7607 { 7608 while (TREE_CODE (type) == ARRAY_TYPE) 7609 type = TREE_TYPE (type); 7610 7611 return type; 7612 } 7613 7614 /* Computes the canonical argument types from the argument type list 7615 ARGTYPES. 7616 7617 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true 7618 on entry to this function, or if any of the ARGTYPES are 7619 structural. 7620 7621 Upon return, *ANY_NONCANONICAL_P will be true iff either it was 7622 true on entry to this function, or if any of the ARGTYPES are 7623 non-canonical. 7624 7625 Returns a canonical argument list, which may be ARGTYPES when the 7626 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is 7627 true) or would not differ from ARGTYPES. */ 7628 7629 static tree 7630 maybe_canonicalize_argtypes(tree argtypes, 7631 bool *any_structural_p, 7632 bool *any_noncanonical_p) 7633 { 7634 tree arg; 7635 bool any_noncanonical_argtypes_p = false; 7636 7637 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg)) 7638 { 7639 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node) 7640 /* Fail gracefully by stating that the type is structural. */ 7641 *any_structural_p = true; 7642 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg))) 7643 *any_structural_p = true; 7644 else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg) 7645 || TREE_PURPOSE (arg)) 7646 /* If the argument has a default argument, we consider it 7647 non-canonical even though the type itself is canonical. 7648 That way, different variants of function and method types 7649 with default arguments will all point to the variant with 7650 no defaults as their canonical type. */ 7651 any_noncanonical_argtypes_p = true; 7652 } 7653 7654 if (*any_structural_p) 7655 return argtypes; 7656 7657 if (any_noncanonical_argtypes_p) 7658 { 7659 /* Build the canonical list of argument types. */ 7660 tree canon_argtypes = NULL_TREE; 7661 bool is_void = false; 7662 7663 for (arg = argtypes; arg; arg = TREE_CHAIN (arg)) 7664 { 7665 if (arg == void_list_node) 7666 is_void = true; 7667 else 7668 canon_argtypes = tree_cons (NULL_TREE, 7669 TYPE_CANONICAL (TREE_VALUE (arg)), 7670 canon_argtypes); 7671 } 7672 7673 canon_argtypes = nreverse (canon_argtypes); 7674 if (is_void) 7675 canon_argtypes = chainon (canon_argtypes, void_list_node); 7676 7677 /* There is a non-canonical type. */ 7678 *any_noncanonical_p = true; 7679 return canon_argtypes; 7680 } 7681 7682 /* The canonical argument types are the same as ARGTYPES. */ 7683 return argtypes; 7684 } 7685 7686 /* Construct, lay out and return 7687 the type of functions returning type VALUE_TYPE 7688 given arguments of types ARG_TYPES. 7689 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs 7690 are data type nodes for the arguments of the function. 7691 If such a type has already been constructed, reuse it. */ 7692 7693 tree 7694 build_function_type (tree value_type, tree arg_types) 7695 { 7696 tree t; 7697 hashval_t hashcode = 0; 7698 bool any_structural_p, any_noncanonical_p; 7699 tree canon_argtypes; 7700 7701 if (TREE_CODE (value_type) == FUNCTION_TYPE) 7702 { 7703 error ("function return type cannot be function"); 7704 value_type = integer_type_node; 7705 } 7706 7707 /* Make a node of the sort we want. */ 7708 t = make_node (FUNCTION_TYPE); 7709 TREE_TYPE (t) = value_type; 7710 TYPE_ARG_TYPES (t) = arg_types; 7711 7712 /* If we already have such a type, use the old one. */ 7713 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode); 7714 hashcode = type_hash_list (arg_types, hashcode); 7715 t = type_hash_canon (hashcode, t); 7716 7717 /* Set up the canonical type. */ 7718 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type); 7719 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type; 7720 canon_argtypes = maybe_canonicalize_argtypes (arg_types, 7721 &any_structural_p, 7722 &any_noncanonical_p); 7723 if (any_structural_p) 7724 SET_TYPE_STRUCTURAL_EQUALITY (t); 7725 else if (any_noncanonical_p) 7726 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type), 7727 canon_argtypes); 7728 7729 if (!COMPLETE_TYPE_P (t)) 7730 layout_type (t); 7731 return t; 7732 } 7733 7734 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP and the 7735 return value if SKIP_RETURN is true. */ 7736 7737 static tree 7738 build_function_type_skip_args (tree orig_type, bitmap args_to_skip, 7739 bool skip_return) 7740 { 7741 tree new_type = NULL; 7742 tree args, new_args = NULL, t; 7743 tree new_reversed; 7744 int i = 0; 7745 7746 for (args = TYPE_ARG_TYPES (orig_type); args && args != void_list_node; 7747 args = TREE_CHAIN (args), i++) 7748 if (!args_to_skip || !bitmap_bit_p (args_to_skip, i)) 7749 new_args = tree_cons (NULL_TREE, TREE_VALUE (args), new_args); 7750 7751 new_reversed = nreverse (new_args); 7752 if (args) 7753 { 7754 if (new_reversed) 7755 TREE_CHAIN (new_args) = void_list_node; 7756 else 7757 new_reversed = void_list_node; 7758 } 7759 7760 /* Use copy_node to preserve as much as possible from original type 7761 (debug info, attribute lists etc.) 7762 Exception is METHOD_TYPEs must have THIS argument. 7763 When we are asked to remove it, we need to build new FUNCTION_TYPE 7764 instead. */ 7765 if (TREE_CODE (orig_type) != METHOD_TYPE 7766 || !args_to_skip 7767 || !bitmap_bit_p (args_to_skip, 0)) 7768 { 7769 new_type = build_distinct_type_copy (orig_type); 7770 TYPE_ARG_TYPES (new_type) = new_reversed; 7771 } 7772 else 7773 { 7774 new_type 7775 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type), 7776 new_reversed)); 7777 TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type); 7778 } 7779 7780 if (skip_return) 7781 TREE_TYPE (new_type) = void_type_node; 7782 7783 /* This is a new type, not a copy of an old type. Need to reassociate 7784 variants. We can handle everything except the main variant lazily. */ 7785 t = TYPE_MAIN_VARIANT (orig_type); 7786 if (t != orig_type) 7787 { 7788 t = build_function_type_skip_args (t, args_to_skip, skip_return); 7789 TYPE_MAIN_VARIANT (new_type) = t; 7790 TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t); 7791 TYPE_NEXT_VARIANT (t) = new_type; 7792 } 7793 else 7794 { 7795 TYPE_MAIN_VARIANT (new_type) = new_type; 7796 TYPE_NEXT_VARIANT (new_type) = NULL; 7797 } 7798 7799 return new_type; 7800 } 7801 7802 /* Build variant of function decl ORIG_DECL skipping ARGS_TO_SKIP and the 7803 return value if SKIP_RETURN is true. 7804 7805 Arguments from DECL_ARGUMENTS list can't be removed now, since they are 7806 linked by TREE_CHAIN directly. The caller is responsible for eliminating 7807 them when they are being duplicated (i.e. copy_arguments_for_versioning). */ 7808 7809 tree 7810 build_function_decl_skip_args (tree orig_decl, bitmap args_to_skip, 7811 bool skip_return) 7812 { 7813 tree new_decl = copy_node (orig_decl); 7814 tree new_type; 7815 7816 new_type = TREE_TYPE (orig_decl); 7817 if (prototype_p (new_type) 7818 || (skip_return && !VOID_TYPE_P (TREE_TYPE (new_type)))) 7819 new_type 7820 = build_function_type_skip_args (new_type, args_to_skip, skip_return); 7821 TREE_TYPE (new_decl) = new_type; 7822 7823 /* For declarations setting DECL_VINDEX (i.e. methods) 7824 we expect first argument to be THIS pointer. */ 7825 if (args_to_skip && bitmap_bit_p (args_to_skip, 0)) 7826 DECL_VINDEX (new_decl) = NULL_TREE; 7827 7828 /* When signature changes, we need to clear builtin info. */ 7829 if (DECL_BUILT_IN (new_decl) 7830 && args_to_skip 7831 && !bitmap_empty_p (args_to_skip)) 7832 { 7833 DECL_BUILT_IN_CLASS (new_decl) = NOT_BUILT_IN; 7834 DECL_FUNCTION_CODE (new_decl) = (enum built_in_function) 0; 7835 } 7836 return new_decl; 7837 } 7838 7839 /* Build a function type. The RETURN_TYPE is the type returned by the 7840 function. If VAARGS is set, no void_type_node is appended to the 7841 the list. ARGP must be always be terminated be a NULL_TREE. */ 7842 7843 static tree 7844 build_function_type_list_1 (bool vaargs, tree return_type, va_list argp) 7845 { 7846 tree t, args, last; 7847 7848 t = va_arg (argp, tree); 7849 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree)) 7850 args = tree_cons (NULL_TREE, t, args); 7851 7852 if (vaargs) 7853 { 7854 last = args; 7855 if (args != NULL_TREE) 7856 args = nreverse (args); 7857 gcc_assert (last != void_list_node); 7858 } 7859 else if (args == NULL_TREE) 7860 args = void_list_node; 7861 else 7862 { 7863 last = args; 7864 args = nreverse (args); 7865 TREE_CHAIN (last) = void_list_node; 7866 } 7867 args = build_function_type (return_type, args); 7868 7869 return args; 7870 } 7871 7872 /* Build a function type. The RETURN_TYPE is the type returned by the 7873 function. If additional arguments are provided, they are 7874 additional argument types. The list of argument types must always 7875 be terminated by NULL_TREE. */ 7876 7877 tree 7878 build_function_type_list (tree return_type, ...) 7879 { 7880 tree args; 7881 va_list p; 7882 7883 va_start (p, return_type); 7884 args = build_function_type_list_1 (false, return_type, p); 7885 va_end (p); 7886 return args; 7887 } 7888 7889 /* Build a variable argument function type. The RETURN_TYPE is the 7890 type returned by the function. If additional arguments are provided, 7891 they are additional argument types. The list of argument types must 7892 always be terminated by NULL_TREE. */ 7893 7894 tree 7895 build_varargs_function_type_list (tree return_type, ...) 7896 { 7897 tree args; 7898 va_list p; 7899 7900 va_start (p, return_type); 7901 args = build_function_type_list_1 (true, return_type, p); 7902 va_end (p); 7903 7904 return args; 7905 } 7906 7907 /* Build a function type. RETURN_TYPE is the type returned by the 7908 function; VAARGS indicates whether the function takes varargs. The 7909 function takes N named arguments, the types of which are provided in 7910 ARG_TYPES. */ 7911 7912 static tree 7913 build_function_type_array_1 (bool vaargs, tree return_type, int n, 7914 tree *arg_types) 7915 { 7916 int i; 7917 tree t = vaargs ? NULL_TREE : void_list_node; 7918 7919 for (i = n - 1; i >= 0; i--) 7920 t = tree_cons (NULL_TREE, arg_types[i], t); 7921 7922 return build_function_type (return_type, t); 7923 } 7924 7925 /* Build a function type. RETURN_TYPE is the type returned by the 7926 function. The function takes N named arguments, the types of which 7927 are provided in ARG_TYPES. */ 7928 7929 tree 7930 build_function_type_array (tree return_type, int n, tree *arg_types) 7931 { 7932 return build_function_type_array_1 (false, return_type, n, arg_types); 7933 } 7934 7935 /* Build a variable argument function type. RETURN_TYPE is the type 7936 returned by the function. The function takes N named arguments, the 7937 types of which are provided in ARG_TYPES. */ 7938 7939 tree 7940 build_varargs_function_type_array (tree return_type, int n, tree *arg_types) 7941 { 7942 return build_function_type_array_1 (true, return_type, n, arg_types); 7943 } 7944 7945 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE) 7946 and ARGTYPES (a TREE_LIST) are the return type and arguments types 7947 for the method. An implicit additional parameter (of type 7948 pointer-to-BASETYPE) is added to the ARGTYPES. */ 7949 7950 tree 7951 build_method_type_directly (tree basetype, 7952 tree rettype, 7953 tree argtypes) 7954 { 7955 tree t; 7956 tree ptype; 7957 int hashcode = 0; 7958 bool any_structural_p, any_noncanonical_p; 7959 tree canon_argtypes; 7960 7961 /* Make a node of the sort we want. */ 7962 t = make_node (METHOD_TYPE); 7963 7964 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); 7965 TREE_TYPE (t) = rettype; 7966 ptype = build_pointer_type (basetype); 7967 7968 /* The actual arglist for this function includes a "hidden" argument 7969 which is "this". Put it into the list of argument types. */ 7970 argtypes = tree_cons (NULL_TREE, ptype, argtypes); 7971 TYPE_ARG_TYPES (t) = argtypes; 7972 7973 /* If we already have such a type, use the old one. */ 7974 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode); 7975 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode); 7976 hashcode = type_hash_list (argtypes, hashcode); 7977 t = type_hash_canon (hashcode, t); 7978 7979 /* Set up the canonical type. */ 7980 any_structural_p 7981 = (TYPE_STRUCTURAL_EQUALITY_P (basetype) 7982 || TYPE_STRUCTURAL_EQUALITY_P (rettype)); 7983 any_noncanonical_p 7984 = (TYPE_CANONICAL (basetype) != basetype 7985 || TYPE_CANONICAL (rettype) != rettype); 7986 canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes), 7987 &any_structural_p, 7988 &any_noncanonical_p); 7989 if (any_structural_p) 7990 SET_TYPE_STRUCTURAL_EQUALITY (t); 7991 else if (any_noncanonical_p) 7992 TYPE_CANONICAL (t) 7993 = build_method_type_directly (TYPE_CANONICAL (basetype), 7994 TYPE_CANONICAL (rettype), 7995 canon_argtypes); 7996 if (!COMPLETE_TYPE_P (t)) 7997 layout_type (t); 7998 7999 return t; 8000 } 8001 8002 /* Construct, lay out and return the type of methods belonging to class 8003 BASETYPE and whose arguments and values are described by TYPE. 8004 If that type exists already, reuse it. 8005 TYPE must be a FUNCTION_TYPE node. */ 8006 8007 tree 8008 build_method_type (tree basetype, tree type) 8009 { 8010 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE); 8011 8012 return build_method_type_directly (basetype, 8013 TREE_TYPE (type), 8014 TYPE_ARG_TYPES (type)); 8015 } 8016 8017 /* Construct, lay out and return the type of offsets to a value 8018 of type TYPE, within an object of type BASETYPE. 8019 If a suitable offset type exists already, reuse it. */ 8020 8021 tree 8022 build_offset_type (tree basetype, tree type) 8023 { 8024 tree t; 8025 hashval_t hashcode = 0; 8026 8027 /* Make a node of the sort we want. */ 8028 t = make_node (OFFSET_TYPE); 8029 8030 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); 8031 TREE_TYPE (t) = type; 8032 8033 /* If we already have such a type, use the old one. */ 8034 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode); 8035 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode); 8036 t = type_hash_canon (hashcode, t); 8037 8038 if (!COMPLETE_TYPE_P (t)) 8039 layout_type (t); 8040 8041 if (TYPE_CANONICAL (t) == t) 8042 { 8043 if (TYPE_STRUCTURAL_EQUALITY_P (basetype) 8044 || TYPE_STRUCTURAL_EQUALITY_P (type)) 8045 SET_TYPE_STRUCTURAL_EQUALITY (t); 8046 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype 8047 || TYPE_CANONICAL (type) != type) 8048 TYPE_CANONICAL (t) 8049 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)), 8050 TYPE_CANONICAL (type)); 8051 } 8052 8053 return t; 8054 } 8055 8056 /* Create a complex type whose components are COMPONENT_TYPE. */ 8057 8058 tree 8059 build_complex_type (tree component_type) 8060 { 8061 tree t; 8062 hashval_t hashcode; 8063 8064 gcc_assert (INTEGRAL_TYPE_P (component_type) 8065 || SCALAR_FLOAT_TYPE_P (component_type) 8066 || FIXED_POINT_TYPE_P (component_type)); 8067 8068 /* Make a node of the sort we want. */ 8069 t = make_node (COMPLEX_TYPE); 8070 8071 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type); 8072 8073 /* If we already have such a type, use the old one. */ 8074 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0); 8075 t = type_hash_canon (hashcode, t); 8076 8077 if (!COMPLETE_TYPE_P (t)) 8078 layout_type (t); 8079 8080 if (TYPE_CANONICAL (t) == t) 8081 { 8082 if (TYPE_STRUCTURAL_EQUALITY_P (component_type)) 8083 SET_TYPE_STRUCTURAL_EQUALITY (t); 8084 else if (TYPE_CANONICAL (component_type) != component_type) 8085 TYPE_CANONICAL (t) 8086 = build_complex_type (TYPE_CANONICAL (component_type)); 8087 } 8088 8089 /* We need to create a name, since complex is a fundamental type. */ 8090 if (! TYPE_NAME (t)) 8091 { 8092 const char *name; 8093 if (component_type == char_type_node) 8094 name = "complex char"; 8095 else if (component_type == signed_char_type_node) 8096 name = "complex signed char"; 8097 else if (component_type == unsigned_char_type_node) 8098 name = "complex unsigned char"; 8099 else if (component_type == short_integer_type_node) 8100 name = "complex short int"; 8101 else if (component_type == short_unsigned_type_node) 8102 name = "complex short unsigned int"; 8103 else if (component_type == integer_type_node) 8104 name = "complex int"; 8105 else if (component_type == unsigned_type_node) 8106 name = "complex unsigned int"; 8107 else if (component_type == long_integer_type_node) 8108 name = "complex long int"; 8109 else if (component_type == long_unsigned_type_node) 8110 name = "complex long unsigned int"; 8111 else if (component_type == long_long_integer_type_node) 8112 name = "complex long long int"; 8113 else if (component_type == long_long_unsigned_type_node) 8114 name = "complex long long unsigned int"; 8115 else 8116 name = 0; 8117 8118 if (name != 0) 8119 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, 8120 get_identifier (name), t); 8121 } 8122 8123 return build_qualified_type (t, TYPE_QUALS (component_type)); 8124 } 8125 8126 /* If TYPE is a real or complex floating-point type and the target 8127 does not directly support arithmetic on TYPE then return the wider 8128 type to be used for arithmetic on TYPE. Otherwise, return 8129 NULL_TREE. */ 8130 8131 tree 8132 excess_precision_type (tree type) 8133 { 8134 if (flag_excess_precision != EXCESS_PRECISION_FAST) 8135 { 8136 int flt_eval_method = TARGET_FLT_EVAL_METHOD; 8137 switch (TREE_CODE (type)) 8138 { 8139 case REAL_TYPE: 8140 switch (flt_eval_method) 8141 { 8142 case 1: 8143 if (TYPE_MODE (type) == TYPE_MODE (float_type_node)) 8144 return double_type_node; 8145 break; 8146 case 2: 8147 if (TYPE_MODE (type) == TYPE_MODE (float_type_node) 8148 || TYPE_MODE (type) == TYPE_MODE (double_type_node)) 8149 return long_double_type_node; 8150 break; 8151 default: 8152 gcc_unreachable (); 8153 } 8154 break; 8155 case COMPLEX_TYPE: 8156 if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE) 8157 return NULL_TREE; 8158 switch (flt_eval_method) 8159 { 8160 case 1: 8161 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)) 8162 return complex_double_type_node; 8163 break; 8164 case 2: 8165 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node) 8166 || (TYPE_MODE (TREE_TYPE (type)) 8167 == TYPE_MODE (double_type_node))) 8168 return complex_long_double_type_node; 8169 break; 8170 default: 8171 gcc_unreachable (); 8172 } 8173 break; 8174 default: 8175 break; 8176 } 8177 } 8178 return NULL_TREE; 8179 } 8180 8181 /* Return OP, stripped of any conversions to wider types as much as is safe. 8182 Converting the value back to OP's type makes a value equivalent to OP. 8183 8184 If FOR_TYPE is nonzero, we return a value which, if converted to 8185 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE. 8186 8187 OP must have integer, real or enumeral type. Pointers are not allowed! 8188 8189 There are some cases where the obvious value we could return 8190 would regenerate to OP if converted to OP's type, 8191 but would not extend like OP to wider types. 8192 If FOR_TYPE indicates such extension is contemplated, we eschew such values. 8193 For example, if OP is (unsigned short)(signed char)-1, 8194 we avoid returning (signed char)-1 if FOR_TYPE is int, 8195 even though extending that to an unsigned short would regenerate OP, 8196 since the result of extending (signed char)-1 to (int) 8197 is different from (int) OP. */ 8198 8199 tree 8200 get_unwidened (tree op, tree for_type) 8201 { 8202 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */ 8203 tree type = TREE_TYPE (op); 8204 unsigned final_prec 8205 = TYPE_PRECISION (for_type != 0 ? for_type : type); 8206 int uns 8207 = (for_type != 0 && for_type != type 8208 && final_prec > TYPE_PRECISION (type) 8209 && TYPE_UNSIGNED (type)); 8210 tree win = op; 8211 8212 while (CONVERT_EXPR_P (op)) 8213 { 8214 int bitschange; 8215 8216 /* TYPE_PRECISION on vector types has different meaning 8217 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions, 8218 so avoid them here. */ 8219 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE) 8220 break; 8221 8222 bitschange = TYPE_PRECISION (TREE_TYPE (op)) 8223 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))); 8224 8225 /* Truncations are many-one so cannot be removed. 8226 Unless we are later going to truncate down even farther. */ 8227 if (bitschange < 0 8228 && final_prec > TYPE_PRECISION (TREE_TYPE (op))) 8229 break; 8230 8231 /* See what's inside this conversion. If we decide to strip it, 8232 we will set WIN. */ 8233 op = TREE_OPERAND (op, 0); 8234 8235 /* If we have not stripped any zero-extensions (uns is 0), 8236 we can strip any kind of extension. 8237 If we have previously stripped a zero-extension, 8238 only zero-extensions can safely be stripped. 8239 Any extension can be stripped if the bits it would produce 8240 are all going to be discarded later by truncating to FOR_TYPE. */ 8241 8242 if (bitschange > 0) 8243 { 8244 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op))) 8245 win = op; 8246 /* TYPE_UNSIGNED says whether this is a zero-extension. 8247 Let's avoid computing it if it does not affect WIN 8248 and if UNS will not be needed again. */ 8249 if ((uns 8250 || CONVERT_EXPR_P (op)) 8251 && TYPE_UNSIGNED (TREE_TYPE (op))) 8252 { 8253 uns = 1; 8254 win = op; 8255 } 8256 } 8257 } 8258 8259 /* If we finally reach a constant see if it fits in for_type and 8260 in that case convert it. */ 8261 if (for_type 8262 && TREE_CODE (win) == INTEGER_CST 8263 && TREE_TYPE (win) != for_type 8264 && int_fits_type_p (win, for_type)) 8265 win = fold_convert (for_type, win); 8266 8267 return win; 8268 } 8269 8270 /* Return OP or a simpler expression for a narrower value 8271 which can be sign-extended or zero-extended to give back OP. 8272 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended 8273 or 0 if the value should be sign-extended. */ 8274 8275 tree 8276 get_narrower (tree op, int *unsignedp_ptr) 8277 { 8278 int uns = 0; 8279 int first = 1; 8280 tree win = op; 8281 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op)); 8282 8283 while (TREE_CODE (op) == NOP_EXPR) 8284 { 8285 int bitschange 8286 = (TYPE_PRECISION (TREE_TYPE (op)) 8287 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)))); 8288 8289 /* Truncations are many-one so cannot be removed. */ 8290 if (bitschange < 0) 8291 break; 8292 8293 /* See what's inside this conversion. If we decide to strip it, 8294 we will set WIN. */ 8295 8296 if (bitschange > 0) 8297 { 8298 op = TREE_OPERAND (op, 0); 8299 /* An extension: the outermost one can be stripped, 8300 but remember whether it is zero or sign extension. */ 8301 if (first) 8302 uns = TYPE_UNSIGNED (TREE_TYPE (op)); 8303 /* Otherwise, if a sign extension has been stripped, 8304 only sign extensions can now be stripped; 8305 if a zero extension has been stripped, only zero-extensions. */ 8306 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op))) 8307 break; 8308 first = 0; 8309 } 8310 else /* bitschange == 0 */ 8311 { 8312 /* A change in nominal type can always be stripped, but we must 8313 preserve the unsignedness. */ 8314 if (first) 8315 uns = TYPE_UNSIGNED (TREE_TYPE (op)); 8316 first = 0; 8317 op = TREE_OPERAND (op, 0); 8318 /* Keep trying to narrow, but don't assign op to win if it 8319 would turn an integral type into something else. */ 8320 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p) 8321 continue; 8322 } 8323 8324 win = op; 8325 } 8326 8327 if (TREE_CODE (op) == COMPONENT_REF 8328 /* Since type_for_size always gives an integer type. */ 8329 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE 8330 && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE 8331 /* Ensure field is laid out already. */ 8332 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0 8333 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1)) 8334 { 8335 unsigned HOST_WIDE_INT innerprec 8336 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1); 8337 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1)) 8338 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1)))); 8339 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp); 8340 8341 /* We can get this structure field in a narrower type that fits it, 8342 but the resulting extension to its nominal type (a fullword type) 8343 must satisfy the same conditions as for other extensions. 8344 8345 Do this only for fields that are aligned (not bit-fields), 8346 because when bit-field insns will be used there is no 8347 advantage in doing this. */ 8348 8349 if (innerprec < TYPE_PRECISION (TREE_TYPE (op)) 8350 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)) 8351 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1))) 8352 && type != 0) 8353 { 8354 if (first) 8355 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1)); 8356 win = fold_convert (type, op); 8357 } 8358 } 8359 8360 *unsignedp_ptr = uns; 8361 return win; 8362 } 8363 8364 /* Returns true if integer constant C has a value that is permissible 8365 for type TYPE (an INTEGER_TYPE). */ 8366 8367 bool 8368 int_fits_type_p (const_tree c, const_tree type) 8369 { 8370 tree type_low_bound, type_high_bound; 8371 bool ok_for_low_bound, ok_for_high_bound, unsc; 8372 double_int dc, dd; 8373 8374 dc = tree_to_double_int (c); 8375 unsc = TYPE_UNSIGNED (TREE_TYPE (c)); 8376 8377 retry: 8378 type_low_bound = TYPE_MIN_VALUE (type); 8379 type_high_bound = TYPE_MAX_VALUE (type); 8380 8381 /* If at least one bound of the type is a constant integer, we can check 8382 ourselves and maybe make a decision. If no such decision is possible, but 8383 this type is a subtype, try checking against that. Otherwise, use 8384 double_int_fits_to_tree_p, which checks against the precision. 8385 8386 Compute the status for each possibly constant bound, and return if we see 8387 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1 8388 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1 8389 for "constant known to fit". */ 8390 8391 /* Check if c >= type_low_bound. */ 8392 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST) 8393 { 8394 dd = tree_to_double_int (type_low_bound); 8395 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_low_bound))) 8396 { 8397 int c_neg = (!unsc && dc.is_negative ()); 8398 int t_neg = (unsc && dd.is_negative ()); 8399 8400 if (c_neg && !t_neg) 8401 return false; 8402 if ((c_neg || !t_neg) && dc.ult (dd)) 8403 return false; 8404 } 8405 else if (dc.cmp (dd, unsc) < 0) 8406 return false; 8407 ok_for_low_bound = true; 8408 } 8409 else 8410 ok_for_low_bound = false; 8411 8412 /* Check if c <= type_high_bound. */ 8413 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST) 8414 { 8415 dd = tree_to_double_int (type_high_bound); 8416 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_high_bound))) 8417 { 8418 int c_neg = (!unsc && dc.is_negative ()); 8419 int t_neg = (unsc && dd.is_negative ()); 8420 8421 if (t_neg && !c_neg) 8422 return false; 8423 if ((t_neg || !c_neg) && dc.ugt (dd)) 8424 return false; 8425 } 8426 else if (dc.cmp (dd, unsc) > 0) 8427 return false; 8428 ok_for_high_bound = true; 8429 } 8430 else 8431 ok_for_high_bound = false; 8432 8433 /* If the constant fits both bounds, the result is known. */ 8434 if (ok_for_low_bound && ok_for_high_bound) 8435 return true; 8436 8437 /* Perform some generic filtering which may allow making a decision 8438 even if the bounds are not constant. First, negative integers 8439 never fit in unsigned types, */ 8440 if (TYPE_UNSIGNED (type) && !unsc && dc.is_negative ()) 8441 return false; 8442 8443 /* Second, narrower types always fit in wider ones. */ 8444 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c))) 8445 return true; 8446 8447 /* Third, unsigned integers with top bit set never fit signed types. */ 8448 if (! TYPE_UNSIGNED (type) && unsc) 8449 { 8450 int prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c))) - 1; 8451 if (prec < HOST_BITS_PER_WIDE_INT) 8452 { 8453 if (((((unsigned HOST_WIDE_INT) 1) << prec) & dc.low) != 0) 8454 return false; 8455 } 8456 else if (((((unsigned HOST_WIDE_INT) 1) 8457 << (prec - HOST_BITS_PER_WIDE_INT)) & dc.high) != 0) 8458 return false; 8459 } 8460 8461 /* If we haven't been able to decide at this point, there nothing more we 8462 can check ourselves here. Look at the base type if we have one and it 8463 has the same precision. */ 8464 if (TREE_CODE (type) == INTEGER_TYPE 8465 && TREE_TYPE (type) != 0 8466 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type))) 8467 { 8468 type = TREE_TYPE (type); 8469 goto retry; 8470 } 8471 8472 /* Or to double_int_fits_to_tree_p, if nothing else. */ 8473 return double_int_fits_to_tree_p (type, dc); 8474 } 8475 8476 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant 8477 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be 8478 represented (assuming two's-complement arithmetic) within the bit 8479 precision of the type are returned instead. */ 8480 8481 void 8482 get_type_static_bounds (const_tree type, mpz_t min, mpz_t max) 8483 { 8484 if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type) 8485 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST) 8486 mpz_set_double_int (min, tree_to_double_int (TYPE_MIN_VALUE (type)), 8487 TYPE_UNSIGNED (type)); 8488 else 8489 { 8490 if (TYPE_UNSIGNED (type)) 8491 mpz_set_ui (min, 0); 8492 else 8493 { 8494 double_int mn; 8495 mn = double_int::mask (TYPE_PRECISION (type) - 1); 8496 mn = (mn + double_int_one).sext (TYPE_PRECISION (type)); 8497 mpz_set_double_int (min, mn, false); 8498 } 8499 } 8500 8501 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type) 8502 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) 8503 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)), 8504 TYPE_UNSIGNED (type)); 8505 else 8506 { 8507 if (TYPE_UNSIGNED (type)) 8508 mpz_set_double_int (max, double_int::mask (TYPE_PRECISION (type)), 8509 true); 8510 else 8511 mpz_set_double_int (max, double_int::mask (TYPE_PRECISION (type) - 1), 8512 true); 8513 } 8514 } 8515 8516 /* Return true if VAR is an automatic variable defined in function FN. */ 8517 8518 bool 8519 auto_var_in_fn_p (const_tree var, const_tree fn) 8520 { 8521 return (DECL_P (var) && DECL_CONTEXT (var) == fn 8522 && ((((TREE_CODE (var) == VAR_DECL && ! DECL_EXTERNAL (var)) 8523 || TREE_CODE (var) == PARM_DECL) 8524 && ! TREE_STATIC (var)) 8525 || TREE_CODE (var) == LABEL_DECL 8526 || TREE_CODE (var) == RESULT_DECL)); 8527 } 8528 8529 /* Subprogram of following function. Called by walk_tree. 8530 8531 Return *TP if it is an automatic variable or parameter of the 8532 function passed in as DATA. */ 8533 8534 static tree 8535 find_var_from_fn (tree *tp, int *walk_subtrees, void *data) 8536 { 8537 tree fn = (tree) data; 8538 8539 if (TYPE_P (*tp)) 8540 *walk_subtrees = 0; 8541 8542 else if (DECL_P (*tp) 8543 && auto_var_in_fn_p (*tp, fn)) 8544 return *tp; 8545 8546 return NULL_TREE; 8547 } 8548 8549 /* Returns true if T is, contains, or refers to a type with variable 8550 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the 8551 arguments, but not the return type. If FN is nonzero, only return 8552 true if a modifier of the type or position of FN is a variable or 8553 parameter inside FN. 8554 8555 This concept is more general than that of C99 'variably modified types': 8556 in C99, a struct type is never variably modified because a VLA may not 8557 appear as a structure member. However, in GNU C code like: 8558 8559 struct S { int i[f()]; }; 8560 8561 is valid, and other languages may define similar constructs. */ 8562 8563 bool 8564 variably_modified_type_p (tree type, tree fn) 8565 { 8566 tree t; 8567 8568 /* Test if T is either variable (if FN is zero) or an expression containing 8569 a variable in FN. If TYPE isn't gimplified, return true also if 8570 gimplify_one_sizepos would gimplify the expression into a local 8571 variable. */ 8572 #define RETURN_TRUE_IF_VAR(T) \ 8573 do { tree _t = (T); \ 8574 if (_t != NULL_TREE \ 8575 && _t != error_mark_node \ 8576 && TREE_CODE (_t) != INTEGER_CST \ 8577 && TREE_CODE (_t) != PLACEHOLDER_EXPR \ 8578 && (!fn \ 8579 || (!TYPE_SIZES_GIMPLIFIED (type) \ 8580 && !is_gimple_sizepos (_t)) \ 8581 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \ 8582 return true; } while (0) 8583 8584 if (type == error_mark_node) 8585 return false; 8586 8587 /* If TYPE itself has variable size, it is variably modified. */ 8588 RETURN_TRUE_IF_VAR (TYPE_SIZE (type)); 8589 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type)); 8590 8591 switch (TREE_CODE (type)) 8592 { 8593 case POINTER_TYPE: 8594 case REFERENCE_TYPE: 8595 case VECTOR_TYPE: 8596 if (variably_modified_type_p (TREE_TYPE (type), fn)) 8597 return true; 8598 break; 8599 8600 case FUNCTION_TYPE: 8601 case METHOD_TYPE: 8602 /* If TYPE is a function type, it is variably modified if the 8603 return type is variably modified. */ 8604 if (variably_modified_type_p (TREE_TYPE (type), fn)) 8605 return true; 8606 break; 8607 8608 case INTEGER_TYPE: 8609 case REAL_TYPE: 8610 case FIXED_POINT_TYPE: 8611 case ENUMERAL_TYPE: 8612 case BOOLEAN_TYPE: 8613 /* Scalar types are variably modified if their end points 8614 aren't constant. */ 8615 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type)); 8616 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type)); 8617 break; 8618 8619 case RECORD_TYPE: 8620 case UNION_TYPE: 8621 case QUAL_UNION_TYPE: 8622 /* We can't see if any of the fields are variably-modified by the 8623 definition we normally use, since that would produce infinite 8624 recursion via pointers. */ 8625 /* This is variably modified if some field's type is. */ 8626 for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t)) 8627 if (TREE_CODE (t) == FIELD_DECL) 8628 { 8629 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t)); 8630 RETURN_TRUE_IF_VAR (DECL_SIZE (t)); 8631 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t)); 8632 8633 if (TREE_CODE (type) == QUAL_UNION_TYPE) 8634 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t)); 8635 } 8636 break; 8637 8638 case ARRAY_TYPE: 8639 /* Do not call ourselves to avoid infinite recursion. This is 8640 variably modified if the element type is. */ 8641 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type))); 8642 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type))); 8643 break; 8644 8645 default: 8646 break; 8647 } 8648 8649 /* The current language may have other cases to check, but in general, 8650 all other types are not variably modified. */ 8651 return lang_hooks.tree_inlining.var_mod_type_p (type, fn); 8652 8653 #undef RETURN_TRUE_IF_VAR 8654 } 8655 8656 /* Given a DECL or TYPE, return the scope in which it was declared, or 8657 NULL_TREE if there is no containing scope. */ 8658 8659 tree 8660 get_containing_scope (const_tree t) 8661 { 8662 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t)); 8663 } 8664 8665 /* Return the innermost context enclosing DECL that is 8666 a FUNCTION_DECL, or zero if none. */ 8667 8668 tree 8669 decl_function_context (const_tree decl) 8670 { 8671 tree context; 8672 8673 if (TREE_CODE (decl) == ERROR_MARK) 8674 return 0; 8675 8676 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable 8677 where we look up the function at runtime. Such functions always take 8678 a first argument of type 'pointer to real context'. 8679 8680 C++ should really be fixed to use DECL_CONTEXT for the real context, 8681 and use something else for the "virtual context". */ 8682 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl)) 8683 context 8684 = TYPE_MAIN_VARIANT 8685 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); 8686 else 8687 context = DECL_CONTEXT (decl); 8688 8689 while (context && TREE_CODE (context) != FUNCTION_DECL) 8690 { 8691 if (TREE_CODE (context) == BLOCK) 8692 context = BLOCK_SUPERCONTEXT (context); 8693 else 8694 context = get_containing_scope (context); 8695 } 8696 8697 return context; 8698 } 8699 8700 /* Return the innermost context enclosing DECL that is 8701 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none. 8702 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */ 8703 8704 tree 8705 decl_type_context (const_tree decl) 8706 { 8707 tree context = DECL_CONTEXT (decl); 8708 8709 while (context) 8710 switch (TREE_CODE (context)) 8711 { 8712 case NAMESPACE_DECL: 8713 case TRANSLATION_UNIT_DECL: 8714 return NULL_TREE; 8715 8716 case RECORD_TYPE: 8717 case UNION_TYPE: 8718 case QUAL_UNION_TYPE: 8719 return context; 8720 8721 case TYPE_DECL: 8722 case FUNCTION_DECL: 8723 context = DECL_CONTEXT (context); 8724 break; 8725 8726 case BLOCK: 8727 context = BLOCK_SUPERCONTEXT (context); 8728 break; 8729 8730 default: 8731 gcc_unreachable (); 8732 } 8733 8734 return NULL_TREE; 8735 } 8736 8737 /* CALL is a CALL_EXPR. Return the declaration for the function 8738 called, or NULL_TREE if the called function cannot be 8739 determined. */ 8740 8741 tree 8742 get_callee_fndecl (const_tree call) 8743 { 8744 tree addr; 8745 8746 if (call == error_mark_node) 8747 return error_mark_node; 8748 8749 /* It's invalid to call this function with anything but a 8750 CALL_EXPR. */ 8751 gcc_assert (TREE_CODE (call) == CALL_EXPR); 8752 8753 /* The first operand to the CALL is the address of the function 8754 called. */ 8755 addr = CALL_EXPR_FN (call); 8756 8757 STRIP_NOPS (addr); 8758 8759 /* If this is a readonly function pointer, extract its initial value. */ 8760 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL 8761 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr) 8762 && DECL_INITIAL (addr)) 8763 addr = DECL_INITIAL (addr); 8764 8765 /* If the address is just `&f' for some function `f', then we know 8766 that `f' is being called. */ 8767 if (TREE_CODE (addr) == ADDR_EXPR 8768 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL) 8769 return TREE_OPERAND (addr, 0); 8770 8771 /* We couldn't figure out what was being called. */ 8772 return NULL_TREE; 8773 } 8774 8775 /* Print debugging information about tree nodes generated during the compile, 8776 and any language-specific information. */ 8777 8778 void 8779 dump_tree_statistics (void) 8780 { 8781 if (GATHER_STATISTICS) 8782 { 8783 int i; 8784 int total_nodes, total_bytes; 8785 fprintf (stderr, "Kind Nodes Bytes\n"); 8786 fprintf (stderr, "---------------------------------------\n"); 8787 total_nodes = total_bytes = 0; 8788 for (i = 0; i < (int) all_kinds; i++) 8789 { 8790 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i], 8791 tree_node_counts[i], tree_node_sizes[i]); 8792 total_nodes += tree_node_counts[i]; 8793 total_bytes += tree_node_sizes[i]; 8794 } 8795 fprintf (stderr, "---------------------------------------\n"); 8796 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes); 8797 fprintf (stderr, "---------------------------------------\n"); 8798 fprintf (stderr, "Code Nodes\n"); 8799 fprintf (stderr, "----------------------------\n"); 8800 for (i = 0; i < (int) MAX_TREE_CODES; i++) 8801 fprintf (stderr, "%-20s %7d\n", tree_code_name[i], tree_code_counts[i]); 8802 fprintf (stderr, "----------------------------\n"); 8803 ssanames_print_statistics (); 8804 phinodes_print_statistics (); 8805 } 8806 else 8807 fprintf (stderr, "(No per-node statistics)\n"); 8808 8809 print_type_hash_statistics (); 8810 print_debug_expr_statistics (); 8811 print_value_expr_statistics (); 8812 lang_hooks.print_statistics (); 8813 } 8814 8815 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s" 8816 8817 /* Generate a crc32 of a byte. */ 8818 8819 static unsigned 8820 crc32_unsigned_bits (unsigned chksum, unsigned value, unsigned bits) 8821 { 8822 unsigned ix; 8823 8824 for (ix = bits; ix--; value <<= 1) 8825 { 8826 unsigned feedback; 8827 8828 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0; 8829 chksum <<= 1; 8830 chksum ^= feedback; 8831 } 8832 return chksum; 8833 } 8834 8835 /* Generate a crc32 of a 32-bit unsigned. */ 8836 8837 unsigned 8838 crc32_unsigned (unsigned chksum, unsigned value) 8839 { 8840 return crc32_unsigned_bits (chksum, value, 32); 8841 } 8842 8843 /* Generate a crc32 of a byte. */ 8844 8845 unsigned 8846 crc32_byte (unsigned chksum, char byte) 8847 { 8848 return crc32_unsigned_bits (chksum, (unsigned) byte << 24, 8); 8849 } 8850 8851 /* Generate a crc32 of a string. */ 8852 8853 unsigned 8854 crc32_string (unsigned chksum, const char *string) 8855 { 8856 do 8857 { 8858 chksum = crc32_byte (chksum, *string); 8859 } 8860 while (*string++); 8861 return chksum; 8862 } 8863 8864 /* P is a string that will be used in a symbol. Mask out any characters 8865 that are not valid in that context. */ 8866 8867 void 8868 clean_symbol_name (char *p) 8869 { 8870 for (; *p; p++) 8871 if (! (ISALNUM (*p) 8872 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ 8873 || *p == '$' 8874 #endif 8875 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ 8876 || *p == '.' 8877 #endif 8878 )) 8879 *p = '_'; 8880 } 8881 8882 /* Generate a name for a special-purpose function. 8883 The generated name may need to be unique across the whole link. 8884 Changes to this function may also require corresponding changes to 8885 xstrdup_mask_random. 8886 TYPE is some string to identify the purpose of this function to the 8887 linker or collect2; it must start with an uppercase letter, 8888 one of: 8889 I - for constructors 8890 D - for destructors 8891 N - for C++ anonymous namespaces 8892 F - for DWARF unwind frame information. */ 8893 8894 tree 8895 get_file_function_name (const char *type) 8896 { 8897 char *buf; 8898 const char *p; 8899 char *q; 8900 8901 /* If we already have a name we know to be unique, just use that. */ 8902 if (first_global_object_name) 8903 p = q = ASTRDUP (first_global_object_name); 8904 /* If the target is handling the constructors/destructors, they 8905 will be local to this file and the name is only necessary for 8906 debugging purposes. 8907 We also assign sub_I and sub_D sufixes to constructors called from 8908 the global static constructors. These are always local. */ 8909 else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors) 8910 || (strncmp (type, "sub_", 4) == 0 8911 && (type[4] == 'I' || type[4] == 'D'))) 8912 { 8913 const char *file = main_input_filename; 8914 if (! file) 8915 file = input_filename; 8916 /* Just use the file's basename, because the full pathname 8917 might be quite long. */ 8918 p = q = ASTRDUP (lbasename (file)); 8919 } 8920 else 8921 { 8922 /* Otherwise, the name must be unique across the entire link. 8923 We don't have anything that we know to be unique to this translation 8924 unit, so use what we do have and throw in some randomness. */ 8925 unsigned len; 8926 const char *name = weak_global_object_name; 8927 const char *file = main_input_filename; 8928 8929 if (! name) 8930 name = ""; 8931 if (! file) 8932 file = input_filename; 8933 8934 len = strlen (file); 8935 q = (char *) alloca (9 + 17 + len + 1); 8936 memcpy (q, file, len + 1); 8937 8938 snprintf (q + len, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX, 8939 crc32_string (0, name), get_random_seed (false)); 8940 8941 p = q; 8942 } 8943 8944 clean_symbol_name (q); 8945 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) 8946 + strlen (type)); 8947 8948 /* Set up the name of the file-level functions we may need. 8949 Use a global object (which is already required to be unique over 8950 the program) rather than the file name (which imposes extra 8951 constraints). */ 8952 sprintf (buf, FILE_FUNCTION_FORMAT, type, p); 8953 8954 return get_identifier (buf); 8955 } 8956 8957 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) 8958 8959 /* Complain that the tree code of NODE does not match the expected 0 8960 terminated list of trailing codes. The trailing code list can be 8961 empty, for a more vague error message. FILE, LINE, and FUNCTION 8962 are of the caller. */ 8963 8964 void 8965 tree_check_failed (const_tree node, const char *file, 8966 int line, const char *function, ...) 8967 { 8968 va_list args; 8969 const char *buffer; 8970 unsigned length = 0; 8971 int code; 8972 8973 va_start (args, function); 8974 while ((code = va_arg (args, int))) 8975 length += 4 + strlen (tree_code_name[code]); 8976 va_end (args); 8977 if (length) 8978 { 8979 char *tmp; 8980 va_start (args, function); 8981 length += strlen ("expected "); 8982 buffer = tmp = (char *) alloca (length); 8983 length = 0; 8984 while ((code = va_arg (args, int))) 8985 { 8986 const char *prefix = length ? " or " : "expected "; 8987 8988 strcpy (tmp + length, prefix); 8989 length += strlen (prefix); 8990 strcpy (tmp + length, tree_code_name[code]); 8991 length += strlen (tree_code_name[code]); 8992 } 8993 va_end (args); 8994 } 8995 else 8996 buffer = "unexpected node"; 8997 8998 internal_error ("tree check: %s, have %s in %s, at %s:%d", 8999 buffer, tree_code_name[TREE_CODE (node)], 9000 function, trim_filename (file), line); 9001 } 9002 9003 /* Complain that the tree code of NODE does match the expected 0 9004 terminated list of trailing codes. FILE, LINE, and FUNCTION are of 9005 the caller. */ 9006 9007 void 9008 tree_not_check_failed (const_tree node, const char *file, 9009 int line, const char *function, ...) 9010 { 9011 va_list args; 9012 char *buffer; 9013 unsigned length = 0; 9014 int code; 9015 9016 va_start (args, function); 9017 while ((code = va_arg (args, int))) 9018 length += 4 + strlen (tree_code_name[code]); 9019 va_end (args); 9020 va_start (args, function); 9021 buffer = (char *) alloca (length); 9022 length = 0; 9023 while ((code = va_arg (args, int))) 9024 { 9025 if (length) 9026 { 9027 strcpy (buffer + length, " or "); 9028 length += 4; 9029 } 9030 strcpy (buffer + length, tree_code_name[code]); 9031 length += strlen (tree_code_name[code]); 9032 } 9033 va_end (args); 9034 9035 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d", 9036 buffer, tree_code_name[TREE_CODE (node)], 9037 function, trim_filename (file), line); 9038 } 9039 9040 /* Similar to tree_check_failed, except that we check for a class of tree 9041 code, given in CL. */ 9042 9043 void 9044 tree_class_check_failed (const_tree node, const enum tree_code_class cl, 9045 const char *file, int line, const char *function) 9046 { 9047 internal_error 9048 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d", 9049 TREE_CODE_CLASS_STRING (cl), 9050 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))), 9051 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); 9052 } 9053 9054 /* Similar to tree_check_failed, except that instead of specifying a 9055 dozen codes, use the knowledge that they're all sequential. */ 9056 9057 void 9058 tree_range_check_failed (const_tree node, const char *file, int line, 9059 const char *function, enum tree_code c1, 9060 enum tree_code c2) 9061 { 9062 char *buffer; 9063 unsigned length = 0; 9064 unsigned int c; 9065 9066 for (c = c1; c <= c2; ++c) 9067 length += 4 + strlen (tree_code_name[c]); 9068 9069 length += strlen ("expected "); 9070 buffer = (char *) alloca (length); 9071 length = 0; 9072 9073 for (c = c1; c <= c2; ++c) 9074 { 9075 const char *prefix = length ? " or " : "expected "; 9076 9077 strcpy (buffer + length, prefix); 9078 length += strlen (prefix); 9079 strcpy (buffer + length, tree_code_name[c]); 9080 length += strlen (tree_code_name[c]); 9081 } 9082 9083 internal_error ("tree check: %s, have %s in %s, at %s:%d", 9084 buffer, tree_code_name[TREE_CODE (node)], 9085 function, trim_filename (file), line); 9086 } 9087 9088 9089 /* Similar to tree_check_failed, except that we check that a tree does 9090 not have the specified code, given in CL. */ 9091 9092 void 9093 tree_not_class_check_failed (const_tree node, const enum tree_code_class cl, 9094 const char *file, int line, const char *function) 9095 { 9096 internal_error 9097 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d", 9098 TREE_CODE_CLASS_STRING (cl), 9099 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))), 9100 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); 9101 } 9102 9103 9104 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */ 9105 9106 void 9107 omp_clause_check_failed (const_tree node, const char *file, int line, 9108 const char *function, enum omp_clause_code code) 9109 { 9110 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d", 9111 omp_clause_code_name[code], tree_code_name[TREE_CODE (node)], 9112 function, trim_filename (file), line); 9113 } 9114 9115 9116 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */ 9117 9118 void 9119 omp_clause_range_check_failed (const_tree node, const char *file, int line, 9120 const char *function, enum omp_clause_code c1, 9121 enum omp_clause_code c2) 9122 { 9123 char *buffer; 9124 unsigned length = 0; 9125 unsigned int c; 9126 9127 for (c = c1; c <= c2; ++c) 9128 length += 4 + strlen (omp_clause_code_name[c]); 9129 9130 length += strlen ("expected "); 9131 buffer = (char *) alloca (length); 9132 length = 0; 9133 9134 for (c = c1; c <= c2; ++c) 9135 { 9136 const char *prefix = length ? " or " : "expected "; 9137 9138 strcpy (buffer + length, prefix); 9139 length += strlen (prefix); 9140 strcpy (buffer + length, omp_clause_code_name[c]); 9141 length += strlen (omp_clause_code_name[c]); 9142 } 9143 9144 internal_error ("tree check: %s, have %s in %s, at %s:%d", 9145 buffer, omp_clause_code_name[TREE_CODE (node)], 9146 function, trim_filename (file), line); 9147 } 9148 9149 9150 #undef DEFTREESTRUCT 9151 #define DEFTREESTRUCT(VAL, NAME) NAME, 9152 9153 static const char *ts_enum_names[] = { 9154 #include "treestruct.def" 9155 }; 9156 #undef DEFTREESTRUCT 9157 9158 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)]) 9159 9160 /* Similar to tree_class_check_failed, except that we check for 9161 whether CODE contains the tree structure identified by EN. */ 9162 9163 void 9164 tree_contains_struct_check_failed (const_tree node, 9165 const enum tree_node_structure_enum en, 9166 const char *file, int line, 9167 const char *function) 9168 { 9169 internal_error 9170 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d", 9171 TS_ENUM_NAME(en), 9172 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); 9173 } 9174 9175 9176 /* Similar to above, except that the check is for the bounds of a TREE_VEC's 9177 (dynamically sized) vector. */ 9178 9179 void 9180 tree_vec_elt_check_failed (int idx, int len, const char *file, int line, 9181 const char *function) 9182 { 9183 internal_error 9184 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d", 9185 idx + 1, len, function, trim_filename (file), line); 9186 } 9187 9188 /* Similar to above, except that the check is for the bounds of the operand 9189 vector of an expression node EXP. */ 9190 9191 void 9192 tree_operand_check_failed (int idx, const_tree exp, const char *file, 9193 int line, const char *function) 9194 { 9195 int code = TREE_CODE (exp); 9196 internal_error 9197 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d", 9198 idx + 1, tree_code_name[code], TREE_OPERAND_LENGTH (exp), 9199 function, trim_filename (file), line); 9200 } 9201 9202 /* Similar to above, except that the check is for the number of 9203 operands of an OMP_CLAUSE node. */ 9204 9205 void 9206 omp_clause_operand_check_failed (int idx, const_tree t, const char *file, 9207 int line, const char *function) 9208 { 9209 internal_error 9210 ("tree check: accessed operand %d of omp_clause %s with %d operands " 9211 "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)], 9212 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function, 9213 trim_filename (file), line); 9214 } 9215 #endif /* ENABLE_TREE_CHECKING */ 9216 9217 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE, 9218 and mapped to the machine mode MODE. Initialize its fields and build 9219 the information necessary for debugging output. */ 9220 9221 static tree 9222 make_vector_type (tree innertype, int nunits, enum machine_mode mode) 9223 { 9224 tree t; 9225 hashval_t hashcode = 0; 9226 9227 t = make_node (VECTOR_TYPE); 9228 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); 9229 SET_TYPE_VECTOR_SUBPARTS (t, nunits); 9230 SET_TYPE_MODE (t, mode); 9231 9232 if (TYPE_STRUCTURAL_EQUALITY_P (innertype)) 9233 SET_TYPE_STRUCTURAL_EQUALITY (t); 9234 else if (TYPE_CANONICAL (innertype) != innertype 9235 || mode != VOIDmode) 9236 TYPE_CANONICAL (t) 9237 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode); 9238 9239 layout_type (t); 9240 9241 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode); 9242 hashcode = iterative_hash_host_wide_int (nunits, hashcode); 9243 hashcode = iterative_hash_host_wide_int (mode, hashcode); 9244 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (t)), hashcode); 9245 t = type_hash_canon (hashcode, t); 9246 9247 /* We have built a main variant, based on the main variant of the 9248 inner type. Use it to build the variant we return. */ 9249 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype)) 9250 && TREE_TYPE (t) != innertype) 9251 return build_type_attribute_qual_variant (t, 9252 TYPE_ATTRIBUTES (innertype), 9253 TYPE_QUALS (innertype)); 9254 9255 return t; 9256 } 9257 9258 static tree 9259 make_or_reuse_type (unsigned size, int unsignedp) 9260 { 9261 if (size == INT_TYPE_SIZE) 9262 return unsignedp ? unsigned_type_node : integer_type_node; 9263 if (size == CHAR_TYPE_SIZE) 9264 return unsignedp ? unsigned_char_type_node : signed_char_type_node; 9265 if (size == SHORT_TYPE_SIZE) 9266 return unsignedp ? short_unsigned_type_node : short_integer_type_node; 9267 if (size == LONG_TYPE_SIZE) 9268 return unsignedp ? long_unsigned_type_node : long_integer_type_node; 9269 if (size == LONG_LONG_TYPE_SIZE) 9270 return (unsignedp ? long_long_unsigned_type_node 9271 : long_long_integer_type_node); 9272 if (size == 128 && int128_integer_type_node) 9273 return (unsignedp ? int128_unsigned_type_node 9274 : int128_integer_type_node); 9275 9276 if (unsignedp) 9277 return make_unsigned_type (size); 9278 else 9279 return make_signed_type (size); 9280 } 9281 9282 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */ 9283 9284 static tree 9285 make_or_reuse_fract_type (unsigned size, int unsignedp, int satp) 9286 { 9287 if (satp) 9288 { 9289 if (size == SHORT_FRACT_TYPE_SIZE) 9290 return unsignedp ? sat_unsigned_short_fract_type_node 9291 : sat_short_fract_type_node; 9292 if (size == FRACT_TYPE_SIZE) 9293 return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node; 9294 if (size == LONG_FRACT_TYPE_SIZE) 9295 return unsignedp ? sat_unsigned_long_fract_type_node 9296 : sat_long_fract_type_node; 9297 if (size == LONG_LONG_FRACT_TYPE_SIZE) 9298 return unsignedp ? sat_unsigned_long_long_fract_type_node 9299 : sat_long_long_fract_type_node; 9300 } 9301 else 9302 { 9303 if (size == SHORT_FRACT_TYPE_SIZE) 9304 return unsignedp ? unsigned_short_fract_type_node 9305 : short_fract_type_node; 9306 if (size == FRACT_TYPE_SIZE) 9307 return unsignedp ? unsigned_fract_type_node : fract_type_node; 9308 if (size == LONG_FRACT_TYPE_SIZE) 9309 return unsignedp ? unsigned_long_fract_type_node 9310 : long_fract_type_node; 9311 if (size == LONG_LONG_FRACT_TYPE_SIZE) 9312 return unsignedp ? unsigned_long_long_fract_type_node 9313 : long_long_fract_type_node; 9314 } 9315 9316 return make_fract_type (size, unsignedp, satp); 9317 } 9318 9319 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */ 9320 9321 static tree 9322 make_or_reuse_accum_type (unsigned size, int unsignedp, int satp) 9323 { 9324 if (satp) 9325 { 9326 if (size == SHORT_ACCUM_TYPE_SIZE) 9327 return unsignedp ? sat_unsigned_short_accum_type_node 9328 : sat_short_accum_type_node; 9329 if (size == ACCUM_TYPE_SIZE) 9330 return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node; 9331 if (size == LONG_ACCUM_TYPE_SIZE) 9332 return unsignedp ? sat_unsigned_long_accum_type_node 9333 : sat_long_accum_type_node; 9334 if (size == LONG_LONG_ACCUM_TYPE_SIZE) 9335 return unsignedp ? sat_unsigned_long_long_accum_type_node 9336 : sat_long_long_accum_type_node; 9337 } 9338 else 9339 { 9340 if (size == SHORT_ACCUM_TYPE_SIZE) 9341 return unsignedp ? unsigned_short_accum_type_node 9342 : short_accum_type_node; 9343 if (size == ACCUM_TYPE_SIZE) 9344 return unsignedp ? unsigned_accum_type_node : accum_type_node; 9345 if (size == LONG_ACCUM_TYPE_SIZE) 9346 return unsignedp ? unsigned_long_accum_type_node 9347 : long_accum_type_node; 9348 if (size == LONG_LONG_ACCUM_TYPE_SIZE) 9349 return unsignedp ? unsigned_long_long_accum_type_node 9350 : long_long_accum_type_node; 9351 } 9352 9353 return make_accum_type (size, unsignedp, satp); 9354 } 9355 9356 /* Create nodes for all integer types (and error_mark_node) using the sizes 9357 of C datatypes. SIGNED_CHAR specifies whether char is signed, 9358 SHORT_DOUBLE specifies whether double should be of the same precision 9359 as float. */ 9360 9361 void 9362 build_common_tree_nodes (bool signed_char, bool short_double) 9363 { 9364 error_mark_node = make_node (ERROR_MARK); 9365 TREE_TYPE (error_mark_node) = error_mark_node; 9366 9367 initialize_sizetypes (); 9368 9369 /* Define both `signed char' and `unsigned char'. */ 9370 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); 9371 TYPE_STRING_FLAG (signed_char_type_node) = 1; 9372 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); 9373 TYPE_STRING_FLAG (unsigned_char_type_node) = 1; 9374 9375 /* Define `char', which is like either `signed char' or `unsigned char' 9376 but not the same as either. */ 9377 char_type_node 9378 = (signed_char 9379 ? make_signed_type (CHAR_TYPE_SIZE) 9380 : make_unsigned_type (CHAR_TYPE_SIZE)); 9381 TYPE_STRING_FLAG (char_type_node) = 1; 9382 9383 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); 9384 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); 9385 integer_type_node = make_signed_type (INT_TYPE_SIZE); 9386 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); 9387 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); 9388 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); 9389 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); 9390 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); 9391 #if HOST_BITS_PER_WIDE_INT >= 64 9392 /* TODO: This isn't correct, but as logic depends at the moment on 9393 host's instead of target's wide-integer. 9394 If there is a target not supporting TImode, but has an 128-bit 9395 integer-scalar register, this target check needs to be adjusted. */ 9396 if (targetm.scalar_mode_supported_p (TImode)) 9397 { 9398 int128_integer_type_node = make_signed_type (128); 9399 int128_unsigned_type_node = make_unsigned_type (128); 9400 } 9401 #endif 9402 9403 /* Define a boolean type. This type only represents boolean values but 9404 may be larger than char depending on the value of BOOL_TYPE_SIZE. 9405 Front ends which want to override this size (i.e. Java) can redefine 9406 boolean_type_node before calling build_common_tree_nodes_2. */ 9407 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); 9408 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); 9409 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1); 9410 TYPE_PRECISION (boolean_type_node) = 1; 9411 9412 /* Define what type to use for size_t. */ 9413 if (strcmp (SIZE_TYPE, "unsigned int") == 0) 9414 size_type_node = unsigned_type_node; 9415 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0) 9416 size_type_node = long_unsigned_type_node; 9417 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0) 9418 size_type_node = long_long_unsigned_type_node; 9419 else if (strcmp (SIZE_TYPE, "short unsigned int") == 0) 9420 size_type_node = short_unsigned_type_node; 9421 else 9422 gcc_unreachable (); 9423 9424 /* Fill in the rest of the sized types. Reuse existing type nodes 9425 when possible. */ 9426 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0); 9427 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0); 9428 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0); 9429 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0); 9430 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0); 9431 9432 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1); 9433 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1); 9434 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1); 9435 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1); 9436 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1); 9437 9438 access_public_node = get_identifier ("public"); 9439 access_protected_node = get_identifier ("protected"); 9440 access_private_node = get_identifier ("private"); 9441 9442 /* Define these next since types below may used them. */ 9443 integer_zero_node = build_int_cst (integer_type_node, 0); 9444 integer_one_node = build_int_cst (integer_type_node, 1); 9445 integer_three_node = build_int_cst (integer_type_node, 3); 9446 integer_minus_one_node = build_int_cst (integer_type_node, -1); 9447 9448 size_zero_node = size_int (0); 9449 size_one_node = size_int (1); 9450 bitsize_zero_node = bitsize_int (0); 9451 bitsize_one_node = bitsize_int (1); 9452 bitsize_unit_node = bitsize_int (BITS_PER_UNIT); 9453 9454 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node); 9455 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node); 9456 9457 void_type_node = make_node (VOID_TYPE); 9458 layout_type (void_type_node); 9459 9460 /* We are not going to have real types in C with less than byte alignment, 9461 so we might as well not have any types that claim to have it. */ 9462 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; 9463 TYPE_USER_ALIGN (void_type_node) = 0; 9464 9465 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0); 9466 layout_type (TREE_TYPE (null_pointer_node)); 9467 9468 ptr_type_node = build_pointer_type (void_type_node); 9469 const_ptr_type_node 9470 = build_pointer_type (build_type_variant (void_type_node, 1, 0)); 9471 fileptr_type_node = ptr_type_node; 9472 9473 float_type_node = make_node (REAL_TYPE); 9474 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; 9475 layout_type (float_type_node); 9476 9477 double_type_node = make_node (REAL_TYPE); 9478 if (short_double) 9479 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; 9480 else 9481 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; 9482 layout_type (double_type_node); 9483 9484 long_double_type_node = make_node (REAL_TYPE); 9485 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; 9486 layout_type (long_double_type_node); 9487 9488 float_ptr_type_node = build_pointer_type (float_type_node); 9489 double_ptr_type_node = build_pointer_type (double_type_node); 9490 long_double_ptr_type_node = build_pointer_type (long_double_type_node); 9491 integer_ptr_type_node = build_pointer_type (integer_type_node); 9492 9493 /* Fixed size integer types. */ 9494 uint16_type_node = build_nonstandard_integer_type (16, true); 9495 uint32_type_node = build_nonstandard_integer_type (32, true); 9496 uint64_type_node = build_nonstandard_integer_type (64, true); 9497 9498 /* Decimal float types. */ 9499 dfloat32_type_node = make_node (REAL_TYPE); 9500 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; 9501 layout_type (dfloat32_type_node); 9502 SET_TYPE_MODE (dfloat32_type_node, SDmode); 9503 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); 9504 9505 dfloat64_type_node = make_node (REAL_TYPE); 9506 TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE; 9507 layout_type (dfloat64_type_node); 9508 SET_TYPE_MODE (dfloat64_type_node, DDmode); 9509 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); 9510 9511 dfloat128_type_node = make_node (REAL_TYPE); 9512 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; 9513 layout_type (dfloat128_type_node); 9514 SET_TYPE_MODE (dfloat128_type_node, TDmode); 9515 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); 9516 9517 complex_integer_type_node = build_complex_type (integer_type_node); 9518 complex_float_type_node = build_complex_type (float_type_node); 9519 complex_double_type_node = build_complex_type (double_type_node); 9520 complex_long_double_type_node = build_complex_type (long_double_type_node); 9521 9522 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */ 9523 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \ 9524 sat_ ## KIND ## _type_node = \ 9525 make_sat_signed_ ## KIND ## _type (SIZE); \ 9526 sat_unsigned_ ## KIND ## _type_node = \ 9527 make_sat_unsigned_ ## KIND ## _type (SIZE); \ 9528 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \ 9529 unsigned_ ## KIND ## _type_node = \ 9530 make_unsigned_ ## KIND ## _type (SIZE); 9531 9532 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \ 9533 sat_ ## WIDTH ## KIND ## _type_node = \ 9534 make_sat_signed_ ## KIND ## _type (SIZE); \ 9535 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \ 9536 make_sat_unsigned_ ## KIND ## _type (SIZE); \ 9537 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \ 9538 unsigned_ ## WIDTH ## KIND ## _type_node = \ 9539 make_unsigned_ ## KIND ## _type (SIZE); 9540 9541 /* Make fixed-point type nodes based on four different widths. */ 9542 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \ 9543 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \ 9544 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \ 9545 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \ 9546 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE) 9547 9548 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */ 9549 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \ 9550 NAME ## _type_node = \ 9551 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \ 9552 u ## NAME ## _type_node = \ 9553 make_or_reuse_unsigned_ ## KIND ## _type \ 9554 (GET_MODE_BITSIZE (U ## MODE ## mode)); \ 9555 sat_ ## NAME ## _type_node = \ 9556 make_or_reuse_sat_signed_ ## KIND ## _type \ 9557 (GET_MODE_BITSIZE (MODE ## mode)); \ 9558 sat_u ## NAME ## _type_node = \ 9559 make_or_reuse_sat_unsigned_ ## KIND ## _type \ 9560 (GET_MODE_BITSIZE (U ## MODE ## mode)); 9561 9562 /* Fixed-point type and mode nodes. */ 9563 MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT) 9564 MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM) 9565 MAKE_FIXED_MODE_NODE (fract, qq, QQ) 9566 MAKE_FIXED_MODE_NODE (fract, hq, HQ) 9567 MAKE_FIXED_MODE_NODE (fract, sq, SQ) 9568 MAKE_FIXED_MODE_NODE (fract, dq, DQ) 9569 MAKE_FIXED_MODE_NODE (fract, tq, TQ) 9570 MAKE_FIXED_MODE_NODE (accum, ha, HA) 9571 MAKE_FIXED_MODE_NODE (accum, sa, SA) 9572 MAKE_FIXED_MODE_NODE (accum, da, DA) 9573 MAKE_FIXED_MODE_NODE (accum, ta, TA) 9574 9575 { 9576 tree t = targetm.build_builtin_va_list (); 9577 9578 /* Many back-ends define record types without setting TYPE_NAME. 9579 If we copied the record type here, we'd keep the original 9580 record type without a name. This breaks name mangling. So, 9581 don't copy record types and let c_common_nodes_and_builtins() 9582 declare the type to be __builtin_va_list. */ 9583 if (TREE_CODE (t) != RECORD_TYPE) 9584 t = build_variant_type_copy (t); 9585 9586 va_list_type_node = t; 9587 } 9588 } 9589 9590 /* Modify DECL for given flags. */ 9591 void 9592 set_call_expr_flags (tree decl, int flags) 9593 { 9594 if (flags & ECF_NOTHROW) 9595 TREE_NOTHROW (decl) = 1; 9596 if (flags & ECF_CONST) 9597 TREE_READONLY (decl) = 1; 9598 if (flags & ECF_PURE) 9599 DECL_PURE_P (decl) = 1; 9600 if (flags & ECF_LOOPING_CONST_OR_PURE) 9601 DECL_LOOPING_CONST_OR_PURE_P (decl) = 1; 9602 if (flags & ECF_NOVOPS) 9603 DECL_IS_NOVOPS (decl) = 1; 9604 if (flags & ECF_NORETURN) 9605 TREE_THIS_VOLATILE (decl) = 1; 9606 if (flags & ECF_MALLOC) 9607 DECL_IS_MALLOC (decl) = 1; 9608 if (flags & ECF_RETURNS_TWICE) 9609 DECL_IS_RETURNS_TWICE (decl) = 1; 9610 if (flags & ECF_LEAF) 9611 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"), 9612 NULL, DECL_ATTRIBUTES (decl)); 9613 if ((flags & ECF_TM_PURE) && flag_tm) 9614 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("transaction_pure"), 9615 NULL, DECL_ATTRIBUTES (decl)); 9616 /* Looping const or pure is implied by noreturn. 9617 There is currently no way to declare looping const or looping pure alone. */ 9618 gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE) 9619 || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE)))); 9620 } 9621 9622 9623 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */ 9624 9625 static void 9626 local_define_builtin (const char *name, tree type, enum built_in_function code, 9627 const char *library_name, int ecf_flags) 9628 { 9629 tree decl; 9630 9631 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL, 9632 library_name, NULL_TREE); 9633 set_call_expr_flags (decl, ecf_flags); 9634 9635 set_builtin_decl (code, decl, true); 9636 } 9637 9638 /* Call this function after instantiating all builtins that the language 9639 front end cares about. This will build the rest of the builtins that 9640 are relied upon by the tree optimizers and the middle-end. */ 9641 9642 void 9643 build_common_builtin_nodes (void) 9644 { 9645 tree tmp, ftype; 9646 int ecf_flags; 9647 9648 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)) 9649 { 9650 ftype = build_function_type (void_type_node, void_list_node); 9651 local_define_builtin ("__builtin_unreachable", ftype, BUILT_IN_UNREACHABLE, 9652 "__builtin_unreachable", 9653 ECF_NOTHROW | ECF_LEAF | ECF_NORETURN 9654 | ECF_CONST | ECF_LEAF); 9655 } 9656 9657 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY) 9658 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE)) 9659 { 9660 ftype = build_function_type_list (ptr_type_node, 9661 ptr_type_node, const_ptr_type_node, 9662 size_type_node, NULL_TREE); 9663 9664 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)) 9665 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY, 9666 "memcpy", ECF_NOTHROW | ECF_LEAF); 9667 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE)) 9668 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE, 9669 "memmove", ECF_NOTHROW | ECF_LEAF); 9670 } 9671 9672 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP)) 9673 { 9674 ftype = build_function_type_list (integer_type_node, const_ptr_type_node, 9675 const_ptr_type_node, size_type_node, 9676 NULL_TREE); 9677 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP, 9678 "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF); 9679 } 9680 9681 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET)) 9682 { 9683 ftype = build_function_type_list (ptr_type_node, 9684 ptr_type_node, integer_type_node, 9685 size_type_node, NULL_TREE); 9686 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET, 9687 "memset", ECF_NOTHROW | ECF_LEAF); 9688 } 9689 9690 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA)) 9691 { 9692 ftype = build_function_type_list (ptr_type_node, 9693 size_type_node, NULL_TREE); 9694 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA, 9695 "alloca", ECF_MALLOC | ECF_NOTHROW | ECF_LEAF); 9696 } 9697 9698 ftype = build_function_type_list (ptr_type_node, size_type_node, 9699 size_type_node, NULL_TREE); 9700 local_define_builtin ("__builtin_alloca_with_align", ftype, 9701 BUILT_IN_ALLOCA_WITH_ALIGN, "alloca", 9702 ECF_MALLOC | ECF_NOTHROW | ECF_LEAF); 9703 9704 /* If we're checking the stack, `alloca' can throw. */ 9705 if (flag_stack_check) 9706 { 9707 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA)) = 0; 9708 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN)) = 0; 9709 } 9710 9711 ftype = build_function_type_list (void_type_node, 9712 ptr_type_node, ptr_type_node, 9713 ptr_type_node, NULL_TREE); 9714 local_define_builtin ("__builtin_init_trampoline", ftype, 9715 BUILT_IN_INIT_TRAMPOLINE, 9716 "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF); 9717 local_define_builtin ("__builtin_init_heap_trampoline", ftype, 9718 BUILT_IN_INIT_HEAP_TRAMPOLINE, 9719 "__builtin_init_heap_trampoline", 9720 ECF_NOTHROW | ECF_LEAF); 9721 9722 ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE); 9723 local_define_builtin ("__builtin_adjust_trampoline", ftype, 9724 BUILT_IN_ADJUST_TRAMPOLINE, 9725 "__builtin_adjust_trampoline", 9726 ECF_CONST | ECF_NOTHROW); 9727 9728 ftype = build_function_type_list (void_type_node, 9729 ptr_type_node, ptr_type_node, NULL_TREE); 9730 local_define_builtin ("__builtin_nonlocal_goto", ftype, 9731 BUILT_IN_NONLOCAL_GOTO, 9732 "__builtin_nonlocal_goto", 9733 ECF_NORETURN | ECF_NOTHROW); 9734 9735 ftype = build_function_type_list (void_type_node, 9736 ptr_type_node, ptr_type_node, NULL_TREE); 9737 local_define_builtin ("__builtin_setjmp_setup", ftype, 9738 BUILT_IN_SETJMP_SETUP, 9739 "__builtin_setjmp_setup", ECF_NOTHROW); 9740 9741 ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE); 9742 local_define_builtin ("__builtin_setjmp_dispatcher", ftype, 9743 BUILT_IN_SETJMP_DISPATCHER, 9744 "__builtin_setjmp_dispatcher", 9745 ECF_PURE | ECF_NOTHROW); 9746 9747 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); 9748 local_define_builtin ("__builtin_setjmp_receiver", ftype, 9749 BUILT_IN_SETJMP_RECEIVER, 9750 "__builtin_setjmp_receiver", ECF_NOTHROW); 9751 9752 ftype = build_function_type_list (ptr_type_node, NULL_TREE); 9753 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE, 9754 "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF); 9755 9756 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); 9757 local_define_builtin ("__builtin_stack_restore", ftype, 9758 BUILT_IN_STACK_RESTORE, 9759 "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF); 9760 9761 /* If there's a possibility that we might use the ARM EABI, build the 9762 alternate __cxa_end_cleanup node used to resume from C++ and Java. */ 9763 if (targetm.arm_eabi_unwinder) 9764 { 9765 ftype = build_function_type_list (void_type_node, NULL_TREE); 9766 local_define_builtin ("__builtin_cxa_end_cleanup", ftype, 9767 BUILT_IN_CXA_END_CLEANUP, 9768 "__cxa_end_cleanup", ECF_NORETURN | ECF_LEAF); 9769 } 9770 9771 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); 9772 local_define_builtin ("__builtin_unwind_resume", ftype, 9773 BUILT_IN_UNWIND_RESUME, 9774 ((targetm_common.except_unwind_info (&global_options) 9775 == UI_SJLJ) 9776 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"), 9777 ECF_NORETURN); 9778 9779 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE) 9780 { 9781 ftype = build_function_type_list (ptr_type_node, integer_type_node, 9782 NULL_TREE); 9783 local_define_builtin ("__builtin_return_address", ftype, 9784 BUILT_IN_RETURN_ADDRESS, 9785 "__builtin_return_address", 9786 ECF_NOTHROW); 9787 } 9788 9789 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER) 9790 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT)) 9791 { 9792 ftype = build_function_type_list (void_type_node, ptr_type_node, 9793 ptr_type_node, NULL_TREE); 9794 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)) 9795 local_define_builtin ("__cyg_profile_func_enter", ftype, 9796 BUILT_IN_PROFILE_FUNC_ENTER, 9797 "__cyg_profile_func_enter", 0); 9798 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT)) 9799 local_define_builtin ("__cyg_profile_func_exit", ftype, 9800 BUILT_IN_PROFILE_FUNC_EXIT, 9801 "__cyg_profile_func_exit", 0); 9802 } 9803 9804 /* The exception object and filter values from the runtime. The argument 9805 must be zero before exception lowering, i.e. from the front end. After 9806 exception lowering, it will be the region number for the exception 9807 landing pad. These functions are PURE instead of CONST to prevent 9808 them from being hoisted past the exception edge that will initialize 9809 its value in the landing pad. */ 9810 ftype = build_function_type_list (ptr_type_node, 9811 integer_type_node, NULL_TREE); 9812 ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF; 9813 /* Only use TM_PURE if we we have TM language support. */ 9814 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1)) 9815 ecf_flags |= ECF_TM_PURE; 9816 local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER, 9817 "__builtin_eh_pointer", ecf_flags); 9818 9819 tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0); 9820 ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE); 9821 local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER, 9822 "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF); 9823 9824 ftype = build_function_type_list (void_type_node, 9825 integer_type_node, integer_type_node, 9826 NULL_TREE); 9827 local_define_builtin ("__builtin_eh_copy_values", ftype, 9828 BUILT_IN_EH_COPY_VALUES, 9829 "__builtin_eh_copy_values", ECF_NOTHROW); 9830 9831 /* Complex multiplication and division. These are handled as builtins 9832 rather than optabs because emit_library_call_value doesn't support 9833 complex. Further, we can do slightly better with folding these 9834 beasties if the real and complex parts of the arguments are separate. */ 9835 { 9836 int mode; 9837 9838 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode) 9839 { 9840 char mode_name_buf[4], *q; 9841 const char *p; 9842 enum built_in_function mcode, dcode; 9843 tree type, inner_type; 9844 const char *prefix = "__"; 9845 9846 if (targetm.libfunc_gnu_prefix) 9847 prefix = "__gnu_"; 9848 9849 type = lang_hooks.types.type_for_mode ((enum machine_mode) mode, 0); 9850 if (type == NULL) 9851 continue; 9852 inner_type = TREE_TYPE (type); 9853 9854 ftype = build_function_type_list (type, inner_type, inner_type, 9855 inner_type, inner_type, NULL_TREE); 9856 9857 mcode = ((enum built_in_function) 9858 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT)); 9859 dcode = ((enum built_in_function) 9860 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT)); 9861 9862 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++) 9863 *q = TOLOWER (*p); 9864 *q = '\0'; 9865 9866 built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3", 9867 NULL); 9868 local_define_builtin (built_in_names[mcode], ftype, mcode, 9869 built_in_names[mcode], 9870 ECF_CONST | ECF_NOTHROW | ECF_LEAF); 9871 9872 built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3", 9873 NULL); 9874 local_define_builtin (built_in_names[dcode], ftype, dcode, 9875 built_in_names[dcode], 9876 ECF_CONST | ECF_NOTHROW | ECF_LEAF); 9877 } 9878 } 9879 } 9880 9881 /* HACK. GROSS. This is absolutely disgusting. I wish there was a 9882 better way. 9883 9884 If we requested a pointer to a vector, build up the pointers that 9885 we stripped off while looking for the inner type. Similarly for 9886 return values from functions. 9887 9888 The argument TYPE is the top of the chain, and BOTTOM is the 9889 new type which we will point to. */ 9890 9891 tree 9892 reconstruct_complex_type (tree type, tree bottom) 9893 { 9894 tree inner, outer; 9895 9896 if (TREE_CODE (type) == POINTER_TYPE) 9897 { 9898 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9899 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type), 9900 TYPE_REF_CAN_ALIAS_ALL (type)); 9901 } 9902 else if (TREE_CODE (type) == REFERENCE_TYPE) 9903 { 9904 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9905 outer = build_reference_type_for_mode (inner, TYPE_MODE (type), 9906 TYPE_REF_CAN_ALIAS_ALL (type)); 9907 } 9908 else if (TREE_CODE (type) == ARRAY_TYPE) 9909 { 9910 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9911 outer = build_array_type (inner, TYPE_DOMAIN (type)); 9912 } 9913 else if (TREE_CODE (type) == FUNCTION_TYPE) 9914 { 9915 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9916 outer = build_function_type (inner, TYPE_ARG_TYPES (type)); 9917 } 9918 else if (TREE_CODE (type) == METHOD_TYPE) 9919 { 9920 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9921 /* The build_method_type_directly() routine prepends 'this' to argument list, 9922 so we must compensate by getting rid of it. */ 9923 outer 9924 = build_method_type_directly 9925 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))), 9926 inner, 9927 TREE_CHAIN (TYPE_ARG_TYPES (type))); 9928 } 9929 else if (TREE_CODE (type) == OFFSET_TYPE) 9930 { 9931 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9932 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner); 9933 } 9934 else 9935 return bottom; 9936 9937 return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type), 9938 TYPE_QUALS (type)); 9939 } 9940 9941 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and 9942 the inner type. */ 9943 tree 9944 build_vector_type_for_mode (tree innertype, enum machine_mode mode) 9945 { 9946 int nunits; 9947 9948 switch (GET_MODE_CLASS (mode)) 9949 { 9950 case MODE_VECTOR_INT: 9951 case MODE_VECTOR_FLOAT: 9952 case MODE_VECTOR_FRACT: 9953 case MODE_VECTOR_UFRACT: 9954 case MODE_VECTOR_ACCUM: 9955 case MODE_VECTOR_UACCUM: 9956 nunits = GET_MODE_NUNITS (mode); 9957 break; 9958 9959 case MODE_INT: 9960 /* Check that there are no leftover bits. */ 9961 gcc_assert (GET_MODE_BITSIZE (mode) 9962 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0); 9963 9964 nunits = GET_MODE_BITSIZE (mode) 9965 / TREE_INT_CST_LOW (TYPE_SIZE (innertype)); 9966 break; 9967 9968 default: 9969 gcc_unreachable (); 9970 } 9971 9972 return make_vector_type (innertype, nunits, mode); 9973 } 9974 9975 /* Similarly, but takes the inner type and number of units, which must be 9976 a power of two. */ 9977 9978 tree 9979 build_vector_type (tree innertype, int nunits) 9980 { 9981 return make_vector_type (innertype, nunits, VOIDmode); 9982 } 9983 9984 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */ 9985 9986 tree 9987 build_opaque_vector_type (tree innertype, int nunits) 9988 { 9989 tree t = make_vector_type (innertype, nunits, VOIDmode); 9990 tree cand; 9991 /* We always build the non-opaque variant before the opaque one, 9992 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */ 9993 cand = TYPE_NEXT_VARIANT (t); 9994 if (cand 9995 && TYPE_VECTOR_OPAQUE (cand) 9996 && check_qualified_type (cand, t, TYPE_QUALS (t))) 9997 return cand; 9998 /* Othewise build a variant type and make sure to queue it after 9999 the non-opaque type. */ 10000 cand = build_distinct_type_copy (t); 10001 TYPE_VECTOR_OPAQUE (cand) = true; 10002 TYPE_CANONICAL (cand) = TYPE_CANONICAL (t); 10003 TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t); 10004 TYPE_NEXT_VARIANT (t) = cand; 10005 TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t); 10006 return cand; 10007 } 10008 10009 10010 /* Given an initializer INIT, return TRUE if INIT is zero or some 10011 aggregate of zeros. Otherwise return FALSE. */ 10012 bool 10013 initializer_zerop (const_tree init) 10014 { 10015 tree elt; 10016 10017 STRIP_NOPS (init); 10018 10019 switch (TREE_CODE (init)) 10020 { 10021 case INTEGER_CST: 10022 return integer_zerop (init); 10023 10024 case REAL_CST: 10025 /* ??? Note that this is not correct for C4X float formats. There, 10026 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most 10027 negative exponent. */ 10028 return real_zerop (init) 10029 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)); 10030 10031 case FIXED_CST: 10032 return fixed_zerop (init); 10033 10034 case COMPLEX_CST: 10035 return integer_zerop (init) 10036 || (real_zerop (init) 10037 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init))) 10038 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))); 10039 10040 case VECTOR_CST: 10041 { 10042 unsigned i; 10043 for (i = 0; i < VECTOR_CST_NELTS (init); ++i) 10044 if (!initializer_zerop (VECTOR_CST_ELT (init, i))) 10045 return false; 10046 return true; 10047 } 10048 10049 case CONSTRUCTOR: 10050 { 10051 unsigned HOST_WIDE_INT idx; 10052 10053 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt) 10054 if (!initializer_zerop (elt)) 10055 return false; 10056 return true; 10057 } 10058 10059 case STRING_CST: 10060 { 10061 int i; 10062 10063 /* We need to loop through all elements to handle cases like 10064 "\0" and "\0foobar". */ 10065 for (i = 0; i < TREE_STRING_LENGTH (init); ++i) 10066 if (TREE_STRING_POINTER (init)[i] != '\0') 10067 return false; 10068 10069 return true; 10070 } 10071 10072 default: 10073 return false; 10074 } 10075 } 10076 10077 /* Build an empty statement at location LOC. */ 10078 10079 tree 10080 build_empty_stmt (location_t loc) 10081 { 10082 tree t = build1 (NOP_EXPR, void_type_node, size_zero_node); 10083 SET_EXPR_LOCATION (t, loc); 10084 return t; 10085 } 10086 10087 10088 /* Build an OpenMP clause with code CODE. LOC is the location of the 10089 clause. */ 10090 10091 tree 10092 build_omp_clause (location_t loc, enum omp_clause_code code) 10093 { 10094 tree t; 10095 int size, length; 10096 10097 length = omp_clause_num_ops[code]; 10098 size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree)); 10099 10100 record_node_allocation_statistics (OMP_CLAUSE, size); 10101 10102 t = ggc_alloc_tree_node (size); 10103 memset (t, 0, size); 10104 TREE_SET_CODE (t, OMP_CLAUSE); 10105 OMP_CLAUSE_SET_CODE (t, code); 10106 OMP_CLAUSE_LOCATION (t) = loc; 10107 10108 return t; 10109 } 10110 10111 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN 10112 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1. 10113 Except for the CODE and operand count field, other storage for the 10114 object is initialized to zeros. */ 10115 10116 tree 10117 build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL) 10118 { 10119 tree t; 10120 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp); 10121 10122 gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp); 10123 gcc_assert (len >= 1); 10124 10125 record_node_allocation_statistics (code, length); 10126 10127 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT); 10128 10129 TREE_SET_CODE (t, code); 10130 10131 /* Can't use TREE_OPERAND to store the length because if checking is 10132 enabled, it will try to check the length before we store it. :-P */ 10133 t->exp.operands[0] = build_int_cst (sizetype, len); 10134 10135 return t; 10136 } 10137 10138 /* Helper function for build_call_* functions; build a CALL_EXPR with 10139 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of 10140 the argument slots. */ 10141 10142 static tree 10143 build_call_1 (tree return_type, tree fn, int nargs) 10144 { 10145 tree t; 10146 10147 t = build_vl_exp (CALL_EXPR, nargs + 3); 10148 TREE_TYPE (t) = return_type; 10149 CALL_EXPR_FN (t) = fn; 10150 CALL_EXPR_STATIC_CHAIN (t) = NULL; 10151 10152 return t; 10153 } 10154 10155 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and 10156 FN and a null static chain slot. NARGS is the number of call arguments 10157 which are specified as "..." arguments. */ 10158 10159 tree 10160 build_call_nary (tree return_type, tree fn, int nargs, ...) 10161 { 10162 tree ret; 10163 va_list args; 10164 va_start (args, nargs); 10165 ret = build_call_valist (return_type, fn, nargs, args); 10166 va_end (args); 10167 return ret; 10168 } 10169 10170 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and 10171 FN and a null static chain slot. NARGS is the number of call arguments 10172 which are specified as a va_list ARGS. */ 10173 10174 tree 10175 build_call_valist (tree return_type, tree fn, int nargs, va_list args) 10176 { 10177 tree t; 10178 int i; 10179 10180 t = build_call_1 (return_type, fn, nargs); 10181 for (i = 0; i < nargs; i++) 10182 CALL_EXPR_ARG (t, i) = va_arg (args, tree); 10183 process_call_operands (t); 10184 return t; 10185 } 10186 10187 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and 10188 FN and a null static chain slot. NARGS is the number of call arguments 10189 which are specified as a tree array ARGS. */ 10190 10191 tree 10192 build_call_array_loc (location_t loc, tree return_type, tree fn, 10193 int nargs, const tree *args) 10194 { 10195 tree t; 10196 int i; 10197 10198 t = build_call_1 (return_type, fn, nargs); 10199 for (i = 0; i < nargs; i++) 10200 CALL_EXPR_ARG (t, i) = args[i]; 10201 process_call_operands (t); 10202 SET_EXPR_LOCATION (t, loc); 10203 return t; 10204 } 10205 10206 /* Like build_call_array, but takes a vec. */ 10207 10208 tree 10209 build_call_vec (tree return_type, tree fn, vec<tree, va_gc> *args) 10210 { 10211 tree ret, t; 10212 unsigned int ix; 10213 10214 ret = build_call_1 (return_type, fn, vec_safe_length (args)); 10215 FOR_EACH_VEC_SAFE_ELT (args, ix, t) 10216 CALL_EXPR_ARG (ret, ix) = t; 10217 process_call_operands (ret); 10218 return ret; 10219 } 10220 10221 10222 /* Returns true if it is possible to prove that the index of 10223 an array access REF (an ARRAY_REF expression) falls into the 10224 array bounds. */ 10225 10226 bool 10227 in_array_bounds_p (tree ref) 10228 { 10229 tree idx = TREE_OPERAND (ref, 1); 10230 tree min, max; 10231 10232 if (TREE_CODE (idx) != INTEGER_CST) 10233 return false; 10234 10235 min = array_ref_low_bound (ref); 10236 max = array_ref_up_bound (ref); 10237 if (!min 10238 || !max 10239 || TREE_CODE (min) != INTEGER_CST 10240 || TREE_CODE (max) != INTEGER_CST) 10241 return false; 10242 10243 if (tree_int_cst_lt (idx, min) 10244 || tree_int_cst_lt (max, idx)) 10245 return false; 10246 10247 return true; 10248 } 10249 10250 /* Returns true if it is possible to prove that the range of 10251 an array access REF (an ARRAY_RANGE_REF expression) falls 10252 into the array bounds. */ 10253 10254 bool 10255 range_in_array_bounds_p (tree ref) 10256 { 10257 tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref)); 10258 tree range_min, range_max, min, max; 10259 10260 range_min = TYPE_MIN_VALUE (domain_type); 10261 range_max = TYPE_MAX_VALUE (domain_type); 10262 if (!range_min 10263 || !range_max 10264 || TREE_CODE (range_min) != INTEGER_CST 10265 || TREE_CODE (range_max) != INTEGER_CST) 10266 return false; 10267 10268 min = array_ref_low_bound (ref); 10269 max = array_ref_up_bound (ref); 10270 if (!min 10271 || !max 10272 || TREE_CODE (min) != INTEGER_CST 10273 || TREE_CODE (max) != INTEGER_CST) 10274 return false; 10275 10276 if (tree_int_cst_lt (range_min, min) 10277 || tree_int_cst_lt (max, range_max)) 10278 return false; 10279 10280 return true; 10281 } 10282 10283 /* Return true if T (assumed to be a DECL) must be assigned a memory 10284 location. */ 10285 10286 bool 10287 needs_to_live_in_memory (const_tree t) 10288 { 10289 return (TREE_ADDRESSABLE (t) 10290 || is_global_var (t) 10291 || (TREE_CODE (t) == RESULT_DECL 10292 && !DECL_BY_REFERENCE (t) 10293 && aggregate_value_p (t, current_function_decl))); 10294 } 10295 10296 /* Return value of a constant X and sign-extend it. */ 10297 10298 HOST_WIDE_INT 10299 int_cst_value (const_tree x) 10300 { 10301 unsigned bits = TYPE_PRECISION (TREE_TYPE (x)); 10302 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x); 10303 10304 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */ 10305 gcc_assert (TREE_INT_CST_HIGH (x) == 0 10306 || TREE_INT_CST_HIGH (x) == -1); 10307 10308 if (bits < HOST_BITS_PER_WIDE_INT) 10309 { 10310 bool negative = ((val >> (bits - 1)) & 1) != 0; 10311 if (negative) 10312 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1; 10313 else 10314 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1); 10315 } 10316 10317 return val; 10318 } 10319 10320 /* Return value of a constant X and sign-extend it. */ 10321 10322 HOST_WIDEST_INT 10323 widest_int_cst_value (const_tree x) 10324 { 10325 unsigned bits = TYPE_PRECISION (TREE_TYPE (x)); 10326 unsigned HOST_WIDEST_INT val = TREE_INT_CST_LOW (x); 10327 10328 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT 10329 gcc_assert (HOST_BITS_PER_WIDEST_INT >= HOST_BITS_PER_DOUBLE_INT); 10330 val |= (((unsigned HOST_WIDEST_INT) TREE_INT_CST_HIGH (x)) 10331 << HOST_BITS_PER_WIDE_INT); 10332 #else 10333 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */ 10334 gcc_assert (TREE_INT_CST_HIGH (x) == 0 10335 || TREE_INT_CST_HIGH (x) == -1); 10336 #endif 10337 10338 if (bits < HOST_BITS_PER_WIDEST_INT) 10339 { 10340 bool negative = ((val >> (bits - 1)) & 1) != 0; 10341 if (negative) 10342 val |= (~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1; 10343 else 10344 val &= ~((~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1); 10345 } 10346 10347 return val; 10348 } 10349 10350 /* If TYPE is an integral or pointer type, return an integer type with 10351 the same precision which is unsigned iff UNSIGNEDP is true, or itself 10352 if TYPE is already an integer type of signedness UNSIGNEDP. */ 10353 10354 tree 10355 signed_or_unsigned_type_for (int unsignedp, tree type) 10356 { 10357 if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type) == unsignedp) 10358 return type; 10359 10360 if (TREE_CODE (type) == VECTOR_TYPE) 10361 { 10362 tree inner = TREE_TYPE (type); 10363 tree inner2 = signed_or_unsigned_type_for (unsignedp, inner); 10364 if (!inner2) 10365 return NULL_TREE; 10366 if (inner == inner2) 10367 return type; 10368 return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type)); 10369 } 10370 10371 if (!INTEGRAL_TYPE_P (type) 10372 && !POINTER_TYPE_P (type)) 10373 return NULL_TREE; 10374 10375 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp); 10376 } 10377 10378 /* If TYPE is an integral or pointer type, return an integer type with 10379 the same precision which is unsigned, or itself if TYPE is already an 10380 unsigned integer type. */ 10381 10382 tree 10383 unsigned_type_for (tree type) 10384 { 10385 return signed_or_unsigned_type_for (1, type); 10386 } 10387 10388 /* If TYPE is an integral or pointer type, return an integer type with 10389 the same precision which is signed, or itself if TYPE is already a 10390 signed integer type. */ 10391 10392 tree 10393 signed_type_for (tree type) 10394 { 10395 return signed_or_unsigned_type_for (0, type); 10396 } 10397 10398 /* If TYPE is a vector type, return a signed integer vector type with the 10399 same width and number of subparts. Otherwise return boolean_type_node. */ 10400 10401 tree 10402 truth_type_for (tree type) 10403 { 10404 if (TREE_CODE (type) == VECTOR_TYPE) 10405 { 10406 tree elem = lang_hooks.types.type_for_size 10407 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))), 0); 10408 return build_opaque_vector_type (elem, TYPE_VECTOR_SUBPARTS (type)); 10409 } 10410 else 10411 return boolean_type_node; 10412 } 10413 10414 /* Returns the largest value obtainable by casting something in INNER type to 10415 OUTER type. */ 10416 10417 tree 10418 upper_bound_in_type (tree outer, tree inner) 10419 { 10420 double_int high; 10421 unsigned int det = 0; 10422 unsigned oprec = TYPE_PRECISION (outer); 10423 unsigned iprec = TYPE_PRECISION (inner); 10424 unsigned prec; 10425 10426 /* Compute a unique number for every combination. */ 10427 det |= (oprec > iprec) ? 4 : 0; 10428 det |= TYPE_UNSIGNED (outer) ? 2 : 0; 10429 det |= TYPE_UNSIGNED (inner) ? 1 : 0; 10430 10431 /* Determine the exponent to use. */ 10432 switch (det) 10433 { 10434 case 0: 10435 case 1: 10436 /* oprec <= iprec, outer: signed, inner: don't care. */ 10437 prec = oprec - 1; 10438 break; 10439 case 2: 10440 case 3: 10441 /* oprec <= iprec, outer: unsigned, inner: don't care. */ 10442 prec = oprec; 10443 break; 10444 case 4: 10445 /* oprec > iprec, outer: signed, inner: signed. */ 10446 prec = iprec - 1; 10447 break; 10448 case 5: 10449 /* oprec > iprec, outer: signed, inner: unsigned. */ 10450 prec = iprec; 10451 break; 10452 case 6: 10453 /* oprec > iprec, outer: unsigned, inner: signed. */ 10454 prec = oprec; 10455 break; 10456 case 7: 10457 /* oprec > iprec, outer: unsigned, inner: unsigned. */ 10458 prec = iprec; 10459 break; 10460 default: 10461 gcc_unreachable (); 10462 } 10463 10464 /* Compute 2^^prec - 1. */ 10465 if (prec <= HOST_BITS_PER_WIDE_INT) 10466 { 10467 high.high = 0; 10468 high.low = ((~(unsigned HOST_WIDE_INT) 0) 10469 >> (HOST_BITS_PER_WIDE_INT - prec)); 10470 } 10471 else 10472 { 10473 high.high = ((~(unsigned HOST_WIDE_INT) 0) 10474 >> (HOST_BITS_PER_DOUBLE_INT - prec)); 10475 high.low = ~(unsigned HOST_WIDE_INT) 0; 10476 } 10477 10478 return double_int_to_tree (outer, high); 10479 } 10480 10481 /* Returns the smallest value obtainable by casting something in INNER type to 10482 OUTER type. */ 10483 10484 tree 10485 lower_bound_in_type (tree outer, tree inner) 10486 { 10487 double_int low; 10488 unsigned oprec = TYPE_PRECISION (outer); 10489 unsigned iprec = TYPE_PRECISION (inner); 10490 10491 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type 10492 and obtain 0. */ 10493 if (TYPE_UNSIGNED (outer) 10494 /* If we are widening something of an unsigned type, OUTER type 10495 contains all values of INNER type. In particular, both INNER 10496 and OUTER types have zero in common. */ 10497 || (oprec > iprec && TYPE_UNSIGNED (inner))) 10498 low.low = low.high = 0; 10499 else 10500 { 10501 /* If we are widening a signed type to another signed type, we 10502 want to obtain -2^^(iprec-1). If we are keeping the 10503 precision or narrowing to a signed type, we want to obtain 10504 -2^(oprec-1). */ 10505 unsigned prec = oprec > iprec ? iprec : oprec; 10506 10507 if (prec <= HOST_BITS_PER_WIDE_INT) 10508 { 10509 low.high = ~(unsigned HOST_WIDE_INT) 0; 10510 low.low = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1); 10511 } 10512 else 10513 { 10514 low.high = ((~(unsigned HOST_WIDE_INT) 0) 10515 << (prec - HOST_BITS_PER_WIDE_INT - 1)); 10516 low.low = 0; 10517 } 10518 } 10519 10520 return double_int_to_tree (outer, low); 10521 } 10522 10523 /* Return nonzero if two operands that are suitable for PHI nodes are 10524 necessarily equal. Specifically, both ARG0 and ARG1 must be either 10525 SSA_NAME or invariant. Note that this is strictly an optimization. 10526 That is, callers of this function can directly call operand_equal_p 10527 and get the same result, only slower. */ 10528 10529 int 10530 operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1) 10531 { 10532 if (arg0 == arg1) 10533 return 1; 10534 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME) 10535 return 0; 10536 return operand_equal_p (arg0, arg1, 0); 10537 } 10538 10539 /* Returns number of zeros at the end of binary representation of X. 10540 10541 ??? Use ffs if available? */ 10542 10543 tree 10544 num_ending_zeros (const_tree x) 10545 { 10546 unsigned HOST_WIDE_INT fr, nfr; 10547 unsigned num, abits; 10548 tree type = TREE_TYPE (x); 10549 10550 if (TREE_INT_CST_LOW (x) == 0) 10551 { 10552 num = HOST_BITS_PER_WIDE_INT; 10553 fr = TREE_INT_CST_HIGH (x); 10554 } 10555 else 10556 { 10557 num = 0; 10558 fr = TREE_INT_CST_LOW (x); 10559 } 10560 10561 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2) 10562 { 10563 nfr = fr >> abits; 10564 if (nfr << abits == fr) 10565 { 10566 num += abits; 10567 fr = nfr; 10568 } 10569 } 10570 10571 if (num > TYPE_PRECISION (type)) 10572 num = TYPE_PRECISION (type); 10573 10574 return build_int_cst_type (type, num); 10575 } 10576 10577 10578 #define WALK_SUBTREE(NODE) \ 10579 do \ 10580 { \ 10581 result = walk_tree_1 (&(NODE), func, data, pset, lh); \ 10582 if (result) \ 10583 return result; \ 10584 } \ 10585 while (0) 10586 10587 /* This is a subroutine of walk_tree that walks field of TYPE that are to 10588 be walked whenever a type is seen in the tree. Rest of operands and return 10589 value are as for walk_tree. */ 10590 10591 static tree 10592 walk_type_fields (tree type, walk_tree_fn func, void *data, 10593 struct pointer_set_t *pset, walk_tree_lh lh) 10594 { 10595 tree result = NULL_TREE; 10596 10597 switch (TREE_CODE (type)) 10598 { 10599 case POINTER_TYPE: 10600 case REFERENCE_TYPE: 10601 /* We have to worry about mutually recursive pointers. These can't 10602 be written in C. They can in Ada. It's pathological, but 10603 there's an ACATS test (c38102a) that checks it. Deal with this 10604 by checking if we're pointing to another pointer, that one 10605 points to another pointer, that one does too, and we have no htab. 10606 If so, get a hash table. We check three levels deep to avoid 10607 the cost of the hash table if we don't need one. */ 10608 if (POINTER_TYPE_P (TREE_TYPE (type)) 10609 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type))) 10610 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type)))) 10611 && !pset) 10612 { 10613 result = walk_tree_without_duplicates (&TREE_TYPE (type), 10614 func, data); 10615 if (result) 10616 return result; 10617 10618 break; 10619 } 10620 10621 /* ... fall through ... */ 10622 10623 case COMPLEX_TYPE: 10624 WALK_SUBTREE (TREE_TYPE (type)); 10625 break; 10626 10627 case METHOD_TYPE: 10628 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type)); 10629 10630 /* Fall through. */ 10631 10632 case FUNCTION_TYPE: 10633 WALK_SUBTREE (TREE_TYPE (type)); 10634 { 10635 tree arg; 10636 10637 /* We never want to walk into default arguments. */ 10638 for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg)) 10639 WALK_SUBTREE (TREE_VALUE (arg)); 10640 } 10641 break; 10642 10643 case ARRAY_TYPE: 10644 /* Don't follow this nodes's type if a pointer for fear that 10645 we'll have infinite recursion. If we have a PSET, then we 10646 need not fear. */ 10647 if (pset 10648 || (!POINTER_TYPE_P (TREE_TYPE (type)) 10649 && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE)) 10650 WALK_SUBTREE (TREE_TYPE (type)); 10651 WALK_SUBTREE (TYPE_DOMAIN (type)); 10652 break; 10653 10654 case OFFSET_TYPE: 10655 WALK_SUBTREE (TREE_TYPE (type)); 10656 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type)); 10657 break; 10658 10659 default: 10660 break; 10661 } 10662 10663 return NULL_TREE; 10664 } 10665 10666 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is 10667 called with the DATA and the address of each sub-tree. If FUNC returns a 10668 non-NULL value, the traversal is stopped, and the value returned by FUNC 10669 is returned. If PSET is non-NULL it is used to record the nodes visited, 10670 and to avoid visiting a node more than once. */ 10671 10672 tree 10673 walk_tree_1 (tree *tp, walk_tree_fn func, void *data, 10674 struct pointer_set_t *pset, walk_tree_lh lh) 10675 { 10676 enum tree_code code; 10677 int walk_subtrees; 10678 tree result; 10679 10680 #define WALK_SUBTREE_TAIL(NODE) \ 10681 do \ 10682 { \ 10683 tp = & (NODE); \ 10684 goto tail_recurse; \ 10685 } \ 10686 while (0) 10687 10688 tail_recurse: 10689 /* Skip empty subtrees. */ 10690 if (!*tp) 10691 return NULL_TREE; 10692 10693 /* Don't walk the same tree twice, if the user has requested 10694 that we avoid doing so. */ 10695 if (pset && pointer_set_insert (pset, *tp)) 10696 return NULL_TREE; 10697 10698 /* Call the function. */ 10699 walk_subtrees = 1; 10700 result = (*func) (tp, &walk_subtrees, data); 10701 10702 /* If we found something, return it. */ 10703 if (result) 10704 return result; 10705 10706 code = TREE_CODE (*tp); 10707 10708 /* Even if we didn't, FUNC may have decided that there was nothing 10709 interesting below this point in the tree. */ 10710 if (!walk_subtrees) 10711 { 10712 /* But we still need to check our siblings. */ 10713 if (code == TREE_LIST) 10714 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp)); 10715 else if (code == OMP_CLAUSE) 10716 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); 10717 else 10718 return NULL_TREE; 10719 } 10720 10721 if (lh) 10722 { 10723 result = (*lh) (tp, &walk_subtrees, func, data, pset); 10724 if (result || !walk_subtrees) 10725 return result; 10726 } 10727 10728 switch (code) 10729 { 10730 case ERROR_MARK: 10731 case IDENTIFIER_NODE: 10732 case INTEGER_CST: 10733 case REAL_CST: 10734 case FIXED_CST: 10735 case VECTOR_CST: 10736 case STRING_CST: 10737 case BLOCK: 10738 case PLACEHOLDER_EXPR: 10739 case SSA_NAME: 10740 case FIELD_DECL: 10741 case RESULT_DECL: 10742 /* None of these have subtrees other than those already walked 10743 above. */ 10744 break; 10745 10746 case TREE_LIST: 10747 WALK_SUBTREE (TREE_VALUE (*tp)); 10748 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp)); 10749 break; 10750 10751 case TREE_VEC: 10752 { 10753 int len = TREE_VEC_LENGTH (*tp); 10754 10755 if (len == 0) 10756 break; 10757 10758 /* Walk all elements but the first. */ 10759 while (--len) 10760 WALK_SUBTREE (TREE_VEC_ELT (*tp, len)); 10761 10762 /* Now walk the first one as a tail call. */ 10763 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0)); 10764 } 10765 10766 case COMPLEX_CST: 10767 WALK_SUBTREE (TREE_REALPART (*tp)); 10768 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp)); 10769 10770 case CONSTRUCTOR: 10771 { 10772 unsigned HOST_WIDE_INT idx; 10773 constructor_elt *ce; 10774 10775 for (idx = 0; vec_safe_iterate(CONSTRUCTOR_ELTS (*tp), idx, &ce); idx++) 10776 WALK_SUBTREE (ce->value); 10777 } 10778 break; 10779 10780 case SAVE_EXPR: 10781 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0)); 10782 10783 case BIND_EXPR: 10784 { 10785 tree decl; 10786 for (decl = BIND_EXPR_VARS (*tp); decl; decl = DECL_CHAIN (decl)) 10787 { 10788 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk 10789 into declarations that are just mentioned, rather than 10790 declared; they don't really belong to this part of the tree. 10791 And, we can see cycles: the initializer for a declaration 10792 can refer to the declaration itself. */ 10793 WALK_SUBTREE (DECL_INITIAL (decl)); 10794 WALK_SUBTREE (DECL_SIZE (decl)); 10795 WALK_SUBTREE (DECL_SIZE_UNIT (decl)); 10796 } 10797 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp)); 10798 } 10799 10800 case STATEMENT_LIST: 10801 { 10802 tree_stmt_iterator i; 10803 for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i)) 10804 WALK_SUBTREE (*tsi_stmt_ptr (i)); 10805 } 10806 break; 10807 10808 case OMP_CLAUSE: 10809 switch (OMP_CLAUSE_CODE (*tp)) 10810 { 10811 case OMP_CLAUSE_PRIVATE: 10812 case OMP_CLAUSE_SHARED: 10813 case OMP_CLAUSE_FIRSTPRIVATE: 10814 case OMP_CLAUSE_COPYIN: 10815 case OMP_CLAUSE_COPYPRIVATE: 10816 case OMP_CLAUSE_FINAL: 10817 case OMP_CLAUSE_IF: 10818 case OMP_CLAUSE_NUM_THREADS: 10819 case OMP_CLAUSE_SCHEDULE: 10820 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0)); 10821 /* FALLTHRU */ 10822 10823 case OMP_CLAUSE_NOWAIT: 10824 case OMP_CLAUSE_ORDERED: 10825 case OMP_CLAUSE_DEFAULT: 10826 case OMP_CLAUSE_UNTIED: 10827 case OMP_CLAUSE_MERGEABLE: 10828 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); 10829 10830 case OMP_CLAUSE_LASTPRIVATE: 10831 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp)); 10832 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp)); 10833 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); 10834 10835 case OMP_CLAUSE_COLLAPSE: 10836 { 10837 int i; 10838 for (i = 0; i < 3; i++) 10839 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i)); 10840 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); 10841 } 10842 10843 case OMP_CLAUSE_REDUCTION: 10844 { 10845 int i; 10846 for (i = 0; i < 4; i++) 10847 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i)); 10848 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); 10849 } 10850 10851 default: 10852 gcc_unreachable (); 10853 } 10854 break; 10855 10856 case TARGET_EXPR: 10857 { 10858 int i, len; 10859 10860 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same. 10861 But, we only want to walk once. */ 10862 len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3; 10863 for (i = 0; i < len; ++i) 10864 WALK_SUBTREE (TREE_OPERAND (*tp, i)); 10865 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len)); 10866 } 10867 10868 case DECL_EXPR: 10869 /* If this is a TYPE_DECL, walk into the fields of the type that it's 10870 defining. We only want to walk into these fields of a type in this 10871 case and not in the general case of a mere reference to the type. 10872 10873 The criterion is as follows: if the field can be an expression, it 10874 must be walked only here. This should be in keeping with the fields 10875 that are directly gimplified in gimplify_type_sizes in order for the 10876 mark/copy-if-shared/unmark machinery of the gimplifier to work with 10877 variable-sized types. 10878 10879 Note that DECLs get walked as part of processing the BIND_EXPR. */ 10880 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL) 10881 { 10882 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp)); 10883 if (TREE_CODE (*type_p) == ERROR_MARK) 10884 return NULL_TREE; 10885 10886 /* Call the function for the type. See if it returns anything or 10887 doesn't want us to continue. If we are to continue, walk both 10888 the normal fields and those for the declaration case. */ 10889 result = (*func) (type_p, &walk_subtrees, data); 10890 if (result || !walk_subtrees) 10891 return result; 10892 10893 /* But do not walk a pointed-to type since it may itself need to 10894 be walked in the declaration case if it isn't anonymous. */ 10895 if (!POINTER_TYPE_P (*type_p)) 10896 { 10897 result = walk_type_fields (*type_p, func, data, pset, lh); 10898 if (result) 10899 return result; 10900 } 10901 10902 /* If this is a record type, also walk the fields. */ 10903 if (RECORD_OR_UNION_TYPE_P (*type_p)) 10904 { 10905 tree field; 10906 10907 for (field = TYPE_FIELDS (*type_p); field; 10908 field = DECL_CHAIN (field)) 10909 { 10910 /* We'd like to look at the type of the field, but we can 10911 easily get infinite recursion. So assume it's pointed 10912 to elsewhere in the tree. Also, ignore things that 10913 aren't fields. */ 10914 if (TREE_CODE (field) != FIELD_DECL) 10915 continue; 10916 10917 WALK_SUBTREE (DECL_FIELD_OFFSET (field)); 10918 WALK_SUBTREE (DECL_SIZE (field)); 10919 WALK_SUBTREE (DECL_SIZE_UNIT (field)); 10920 if (TREE_CODE (*type_p) == QUAL_UNION_TYPE) 10921 WALK_SUBTREE (DECL_QUALIFIER (field)); 10922 } 10923 } 10924 10925 /* Same for scalar types. */ 10926 else if (TREE_CODE (*type_p) == BOOLEAN_TYPE 10927 || TREE_CODE (*type_p) == ENUMERAL_TYPE 10928 || TREE_CODE (*type_p) == INTEGER_TYPE 10929 || TREE_CODE (*type_p) == FIXED_POINT_TYPE 10930 || TREE_CODE (*type_p) == REAL_TYPE) 10931 { 10932 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p)); 10933 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p)); 10934 } 10935 10936 WALK_SUBTREE (TYPE_SIZE (*type_p)); 10937 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p)); 10938 } 10939 /* FALLTHRU */ 10940 10941 default: 10942 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))) 10943 { 10944 int i, len; 10945 10946 /* Walk over all the sub-trees of this operand. */ 10947 len = TREE_OPERAND_LENGTH (*tp); 10948 10949 /* Go through the subtrees. We need to do this in forward order so 10950 that the scope of a FOR_EXPR is handled properly. */ 10951 if (len) 10952 { 10953 for (i = 0; i < len - 1; ++i) 10954 WALK_SUBTREE (TREE_OPERAND (*tp, i)); 10955 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len - 1)); 10956 } 10957 } 10958 /* If this is a type, walk the needed fields in the type. */ 10959 else if (TYPE_P (*tp)) 10960 return walk_type_fields (*tp, func, data, pset, lh); 10961 break; 10962 } 10963 10964 /* We didn't find what we were looking for. */ 10965 return NULL_TREE; 10966 10967 #undef WALK_SUBTREE_TAIL 10968 } 10969 #undef WALK_SUBTREE 10970 10971 /* Like walk_tree, but does not walk duplicate nodes more than once. */ 10972 10973 tree 10974 walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data, 10975 walk_tree_lh lh) 10976 { 10977 tree result; 10978 struct pointer_set_t *pset; 10979 10980 pset = pointer_set_create (); 10981 result = walk_tree_1 (tp, func, data, pset, lh); 10982 pointer_set_destroy (pset); 10983 return result; 10984 } 10985 10986 10987 tree 10988 tree_block (tree t) 10989 { 10990 char const c = TREE_CODE_CLASS (TREE_CODE (t)); 10991 10992 if (IS_EXPR_CODE_CLASS (c)) 10993 return LOCATION_BLOCK (t->exp.locus); 10994 gcc_unreachable (); 10995 return NULL; 10996 } 10997 10998 void 10999 tree_set_block (tree t, tree b) 11000 { 11001 char const c = TREE_CODE_CLASS (TREE_CODE (t)); 11002 11003 if (IS_EXPR_CODE_CLASS (c)) 11004 { 11005 if (b) 11006 t->exp.locus = COMBINE_LOCATION_DATA (line_table, t->exp.locus, b); 11007 else 11008 t->exp.locus = LOCATION_LOCUS (t->exp.locus); 11009 } 11010 else 11011 gcc_unreachable (); 11012 } 11013 11014 /* Create a nameless artificial label and put it in the current 11015 function context. The label has a location of LOC. Returns the 11016 newly created label. */ 11017 11018 tree 11019 create_artificial_label (location_t loc) 11020 { 11021 tree lab = build_decl (loc, 11022 LABEL_DECL, NULL_TREE, void_type_node); 11023 11024 DECL_ARTIFICIAL (lab) = 1; 11025 DECL_IGNORED_P (lab) = 1; 11026 DECL_CONTEXT (lab) = current_function_decl; 11027 return lab; 11028 } 11029 11030 /* Given a tree, try to return a useful variable name that we can use 11031 to prefix a temporary that is being assigned the value of the tree. 11032 I.E. given <temp> = &A, return A. */ 11033 11034 const char * 11035 get_name (tree t) 11036 { 11037 tree stripped_decl; 11038 11039 stripped_decl = t; 11040 STRIP_NOPS (stripped_decl); 11041 if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl)) 11042 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl)); 11043 else if (TREE_CODE (stripped_decl) == SSA_NAME) 11044 { 11045 tree name = SSA_NAME_IDENTIFIER (stripped_decl); 11046 if (!name) 11047 return NULL; 11048 return IDENTIFIER_POINTER (name); 11049 } 11050 else 11051 { 11052 switch (TREE_CODE (stripped_decl)) 11053 { 11054 case ADDR_EXPR: 11055 return get_name (TREE_OPERAND (stripped_decl, 0)); 11056 default: 11057 return NULL; 11058 } 11059 } 11060 } 11061 11062 /* Return true if TYPE has a variable argument list. */ 11063 11064 bool 11065 stdarg_p (const_tree fntype) 11066 { 11067 function_args_iterator args_iter; 11068 tree n = NULL_TREE, t; 11069 11070 if (!fntype) 11071 return false; 11072 11073 FOREACH_FUNCTION_ARGS(fntype, t, args_iter) 11074 { 11075 n = t; 11076 } 11077 11078 return n != NULL_TREE && n != void_type_node; 11079 } 11080 11081 /* Return true if TYPE has a prototype. */ 11082 11083 bool 11084 prototype_p (tree fntype) 11085 { 11086 tree t; 11087 11088 gcc_assert (fntype != NULL_TREE); 11089 11090 t = TYPE_ARG_TYPES (fntype); 11091 return (t != NULL_TREE); 11092 } 11093 11094 /* If BLOCK is inlined from an __attribute__((__artificial__)) 11095 routine, return pointer to location from where it has been 11096 called. */ 11097 location_t * 11098 block_nonartificial_location (tree block) 11099 { 11100 location_t *ret = NULL; 11101 11102 while (block && TREE_CODE (block) == BLOCK 11103 && BLOCK_ABSTRACT_ORIGIN (block)) 11104 { 11105 tree ao = BLOCK_ABSTRACT_ORIGIN (block); 11106 11107 while (TREE_CODE (ao) == BLOCK 11108 && BLOCK_ABSTRACT_ORIGIN (ao) 11109 && BLOCK_ABSTRACT_ORIGIN (ao) != ao) 11110 ao = BLOCK_ABSTRACT_ORIGIN (ao); 11111 11112 if (TREE_CODE (ao) == FUNCTION_DECL) 11113 { 11114 /* If AO is an artificial inline, point RET to the 11115 call site locus at which it has been inlined and continue 11116 the loop, in case AO's caller is also an artificial 11117 inline. */ 11118 if (DECL_DECLARED_INLINE_P (ao) 11119 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao))) 11120 ret = &BLOCK_SOURCE_LOCATION (block); 11121 else 11122 break; 11123 } 11124 else if (TREE_CODE (ao) != BLOCK) 11125 break; 11126 11127 block = BLOCK_SUPERCONTEXT (block); 11128 } 11129 return ret; 11130 } 11131 11132 11133 /* If EXP is inlined from an __attribute__((__artificial__)) 11134 function, return the location of the original call expression. */ 11135 11136 location_t 11137 tree_nonartificial_location (tree exp) 11138 { 11139 location_t *loc = block_nonartificial_location (TREE_BLOCK (exp)); 11140 11141 if (loc) 11142 return *loc; 11143 else 11144 return EXPR_LOCATION (exp); 11145 } 11146 11147 11148 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq 11149 nodes. */ 11150 11151 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */ 11152 11153 static hashval_t 11154 cl_option_hash_hash (const void *x) 11155 { 11156 const_tree const t = (const_tree) x; 11157 const char *p; 11158 size_t i; 11159 size_t len = 0; 11160 hashval_t hash = 0; 11161 11162 if (TREE_CODE (t) == OPTIMIZATION_NODE) 11163 { 11164 p = (const char *)TREE_OPTIMIZATION (t); 11165 len = sizeof (struct cl_optimization); 11166 } 11167 11168 else if (TREE_CODE (t) == TARGET_OPTION_NODE) 11169 { 11170 p = (const char *)TREE_TARGET_OPTION (t); 11171 len = sizeof (struct cl_target_option); 11172 } 11173 11174 else 11175 gcc_unreachable (); 11176 11177 /* assume most opt flags are just 0/1, some are 2-3, and a few might be 11178 something else. */ 11179 for (i = 0; i < len; i++) 11180 if (p[i]) 11181 hash = (hash << 4) ^ ((i << 2) | p[i]); 11182 11183 return hash; 11184 } 11185 11186 /* Return nonzero if the value represented by *X (an OPTIMIZATION or 11187 TARGET_OPTION tree node) is the same as that given by *Y, which is the 11188 same. */ 11189 11190 static int 11191 cl_option_hash_eq (const void *x, const void *y) 11192 { 11193 const_tree const xt = (const_tree) x; 11194 const_tree const yt = (const_tree) y; 11195 const char *xp; 11196 const char *yp; 11197 size_t len; 11198 11199 if (TREE_CODE (xt) != TREE_CODE (yt)) 11200 return 0; 11201 11202 if (TREE_CODE (xt) == OPTIMIZATION_NODE) 11203 { 11204 xp = (const char *)TREE_OPTIMIZATION (xt); 11205 yp = (const char *)TREE_OPTIMIZATION (yt); 11206 len = sizeof (struct cl_optimization); 11207 } 11208 11209 else if (TREE_CODE (xt) == TARGET_OPTION_NODE) 11210 { 11211 xp = (const char *)TREE_TARGET_OPTION (xt); 11212 yp = (const char *)TREE_TARGET_OPTION (yt); 11213 len = sizeof (struct cl_target_option); 11214 } 11215 11216 else 11217 gcc_unreachable (); 11218 11219 return (memcmp (xp, yp, len) == 0); 11220 } 11221 11222 /* Build an OPTIMIZATION_NODE based on the current options. */ 11223 11224 tree 11225 build_optimization_node (void) 11226 { 11227 tree t; 11228 void **slot; 11229 11230 /* Use the cache of optimization nodes. */ 11231 11232 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node), 11233 &global_options); 11234 11235 slot = htab_find_slot (cl_option_hash_table, cl_optimization_node, INSERT); 11236 t = (tree) *slot; 11237 if (!t) 11238 { 11239 /* Insert this one into the hash table. */ 11240 t = cl_optimization_node; 11241 *slot = t; 11242 11243 /* Make a new node for next time round. */ 11244 cl_optimization_node = make_node (OPTIMIZATION_NODE); 11245 } 11246 11247 return t; 11248 } 11249 11250 /* Build a TARGET_OPTION_NODE based on the current options. */ 11251 11252 tree 11253 build_target_option_node (void) 11254 { 11255 tree t; 11256 void **slot; 11257 11258 /* Use the cache of optimization nodes. */ 11259 11260 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node), 11261 &global_options); 11262 11263 slot = htab_find_slot (cl_option_hash_table, cl_target_option_node, INSERT); 11264 t = (tree) *slot; 11265 if (!t) 11266 { 11267 /* Insert this one into the hash table. */ 11268 t = cl_target_option_node; 11269 *slot = t; 11270 11271 /* Make a new node for next time round. */ 11272 cl_target_option_node = make_node (TARGET_OPTION_NODE); 11273 } 11274 11275 return t; 11276 } 11277 11278 /* Determine the "ultimate origin" of a block. The block may be an inlined 11279 instance of an inlined instance of a block which is local to an inline 11280 function, so we have to trace all of the way back through the origin chain 11281 to find out what sort of node actually served as the original seed for the 11282 given block. */ 11283 11284 tree 11285 block_ultimate_origin (const_tree block) 11286 { 11287 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); 11288 11289 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the 11290 nodes in the function to point to themselves; ignore that if 11291 we're trying to output the abstract instance of this function. */ 11292 if (BLOCK_ABSTRACT (block) && immediate_origin == block) 11293 return NULL_TREE; 11294 11295 if (immediate_origin == NULL_TREE) 11296 return NULL_TREE; 11297 else 11298 { 11299 tree ret_val; 11300 tree lookahead = immediate_origin; 11301 11302 do 11303 { 11304 ret_val = lookahead; 11305 lookahead = (TREE_CODE (ret_val) == BLOCK 11306 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); 11307 } 11308 while (lookahead != NULL && lookahead != ret_val); 11309 11310 /* The block's abstract origin chain may not be the *ultimate* origin of 11311 the block. It could lead to a DECL that has an abstract origin set. 11312 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN 11313 will give us if it has one). Note that DECL's abstract origins are 11314 supposed to be the most distant ancestor (or so decl_ultimate_origin 11315 claims), so we don't need to loop following the DECL origins. */ 11316 if (DECL_P (ret_val)) 11317 return DECL_ORIGIN (ret_val); 11318 11319 return ret_val; 11320 } 11321 } 11322 11323 /* Return true if T1 and T2 are equivalent lists. */ 11324 11325 bool 11326 list_equal_p (const_tree t1, const_tree t2) 11327 { 11328 for (; t1 && t2; t1 = TREE_CHAIN (t1) , t2 = TREE_CHAIN (t2)) 11329 if (TREE_VALUE (t1) != TREE_VALUE (t2)) 11330 return false; 11331 return !t1 && !t2; 11332 } 11333 11334 /* Return true iff conversion in EXP generates no instruction. Mark 11335 it inline so that we fully inline into the stripping functions even 11336 though we have two uses of this function. */ 11337 11338 static inline bool 11339 tree_nop_conversion (const_tree exp) 11340 { 11341 tree outer_type, inner_type; 11342 11343 if (!CONVERT_EXPR_P (exp) 11344 && TREE_CODE (exp) != NON_LVALUE_EXPR) 11345 return false; 11346 if (TREE_OPERAND (exp, 0) == error_mark_node) 11347 return false; 11348 11349 outer_type = TREE_TYPE (exp); 11350 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0)); 11351 11352 if (!inner_type) 11353 return false; 11354 11355 /* Use precision rather then machine mode when we can, which gives 11356 the correct answer even for submode (bit-field) types. */ 11357 if ((INTEGRAL_TYPE_P (outer_type) 11358 || POINTER_TYPE_P (outer_type) 11359 || TREE_CODE (outer_type) == OFFSET_TYPE) 11360 && (INTEGRAL_TYPE_P (inner_type) 11361 || POINTER_TYPE_P (inner_type) 11362 || TREE_CODE (inner_type) == OFFSET_TYPE)) 11363 return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type); 11364 11365 /* Otherwise fall back on comparing machine modes (e.g. for 11366 aggregate types, floats). */ 11367 return TYPE_MODE (outer_type) == TYPE_MODE (inner_type); 11368 } 11369 11370 /* Return true iff conversion in EXP generates no instruction. Don't 11371 consider conversions changing the signedness. */ 11372 11373 static bool 11374 tree_sign_nop_conversion (const_tree exp) 11375 { 11376 tree outer_type, inner_type; 11377 11378 if (!tree_nop_conversion (exp)) 11379 return false; 11380 11381 outer_type = TREE_TYPE (exp); 11382 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0)); 11383 11384 return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type) 11385 && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type)); 11386 } 11387 11388 /* Strip conversions from EXP according to tree_nop_conversion and 11389 return the resulting expression. */ 11390 11391 tree 11392 tree_strip_nop_conversions (tree exp) 11393 { 11394 while (tree_nop_conversion (exp)) 11395 exp = TREE_OPERAND (exp, 0); 11396 return exp; 11397 } 11398 11399 /* Strip conversions from EXP according to tree_sign_nop_conversion 11400 and return the resulting expression. */ 11401 11402 tree 11403 tree_strip_sign_nop_conversions (tree exp) 11404 { 11405 while (tree_sign_nop_conversion (exp)) 11406 exp = TREE_OPERAND (exp, 0); 11407 return exp; 11408 } 11409 11410 /* Avoid any floating point extensions from EXP. */ 11411 tree 11412 strip_float_extensions (tree exp) 11413 { 11414 tree sub, expt, subt; 11415 11416 /* For floating point constant look up the narrowest type that can hold 11417 it properly and handle it like (type)(narrowest_type)constant. 11418 This way we can optimize for instance a=a*2.0 where "a" is float 11419 but 2.0 is double constant. */ 11420 if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp))) 11421 { 11422 REAL_VALUE_TYPE orig; 11423 tree type = NULL; 11424 11425 orig = TREE_REAL_CST (exp); 11426 if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node) 11427 && exact_real_truncate (TYPE_MODE (float_type_node), &orig)) 11428 type = float_type_node; 11429 else if (TYPE_PRECISION (TREE_TYPE (exp)) 11430 > TYPE_PRECISION (double_type_node) 11431 && exact_real_truncate (TYPE_MODE (double_type_node), &orig)) 11432 type = double_type_node; 11433 if (type) 11434 return build_real (type, real_value_truncate (TYPE_MODE (type), orig)); 11435 } 11436 11437 if (!CONVERT_EXPR_P (exp)) 11438 return exp; 11439 11440 sub = TREE_OPERAND (exp, 0); 11441 subt = TREE_TYPE (sub); 11442 expt = TREE_TYPE (exp); 11443 11444 if (!FLOAT_TYPE_P (subt)) 11445 return exp; 11446 11447 if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt)) 11448 return exp; 11449 11450 if (TYPE_PRECISION (subt) > TYPE_PRECISION (expt)) 11451 return exp; 11452 11453 return strip_float_extensions (sub); 11454 } 11455 11456 /* Strip out all handled components that produce invariant 11457 offsets. */ 11458 11459 const_tree 11460 strip_invariant_refs (const_tree op) 11461 { 11462 while (handled_component_p (op)) 11463 { 11464 switch (TREE_CODE (op)) 11465 { 11466 case ARRAY_REF: 11467 case ARRAY_RANGE_REF: 11468 if (!is_gimple_constant (TREE_OPERAND (op, 1)) 11469 || TREE_OPERAND (op, 2) != NULL_TREE 11470 || TREE_OPERAND (op, 3) != NULL_TREE) 11471 return NULL; 11472 break; 11473 11474 case COMPONENT_REF: 11475 if (TREE_OPERAND (op, 2) != NULL_TREE) 11476 return NULL; 11477 break; 11478 11479 default:; 11480 } 11481 op = TREE_OPERAND (op, 0); 11482 } 11483 11484 return op; 11485 } 11486 11487 static GTY(()) tree gcc_eh_personality_decl; 11488 11489 /* Return the GCC personality function decl. */ 11490 11491 tree 11492 lhd_gcc_personality (void) 11493 { 11494 if (!gcc_eh_personality_decl) 11495 gcc_eh_personality_decl = build_personality_function ("gcc"); 11496 return gcc_eh_personality_decl; 11497 } 11498 11499 /* Try to find a base info of BINFO that would have its field decl at offset 11500 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be 11501 found, return, otherwise return NULL_TREE. */ 11502 11503 tree 11504 get_binfo_at_offset (tree binfo, HOST_WIDE_INT offset, tree expected_type) 11505 { 11506 tree type = BINFO_TYPE (binfo); 11507 11508 while (true) 11509 { 11510 HOST_WIDE_INT pos, size; 11511 tree fld; 11512 int i; 11513 11514 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (expected_type)) 11515 return binfo; 11516 if (offset < 0) 11517 return NULL_TREE; 11518 11519 for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld)) 11520 { 11521 if (TREE_CODE (fld) != FIELD_DECL) 11522 continue; 11523 11524 pos = int_bit_position (fld); 11525 size = tree_low_cst (DECL_SIZE (fld), 1); 11526 if (pos <= offset && (pos + size) > offset) 11527 break; 11528 } 11529 if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE) 11530 return NULL_TREE; 11531 11532 if (!DECL_ARTIFICIAL (fld)) 11533 { 11534 binfo = TYPE_BINFO (TREE_TYPE (fld)); 11535 if (!binfo) 11536 return NULL_TREE; 11537 } 11538 /* Offset 0 indicates the primary base, whose vtable contents are 11539 represented in the binfo for the derived class. */ 11540 else if (offset != 0) 11541 { 11542 tree base_binfo, found_binfo = NULL_TREE; 11543 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++) 11544 if (TREE_TYPE (base_binfo) == TREE_TYPE (fld)) 11545 { 11546 found_binfo = base_binfo; 11547 break; 11548 } 11549 if (!found_binfo) 11550 return NULL_TREE; 11551 binfo = found_binfo; 11552 } 11553 11554 type = TREE_TYPE (fld); 11555 offset -= pos; 11556 } 11557 } 11558 11559 /* Returns true if X is a typedef decl. */ 11560 11561 bool 11562 is_typedef_decl (tree x) 11563 { 11564 return (x && TREE_CODE (x) == TYPE_DECL 11565 && DECL_ORIGINAL_TYPE (x) != NULL_TREE); 11566 } 11567 11568 /* Returns true iff TYPE is a type variant created for a typedef. */ 11569 11570 bool 11571 typedef_variant_p (tree type) 11572 { 11573 return is_typedef_decl (TYPE_NAME (type)); 11574 } 11575 11576 /* Warn about a use of an identifier which was marked deprecated. */ 11577 void 11578 warn_deprecated_use (tree node, tree attr) 11579 { 11580 const char *msg; 11581 11582 if (node == 0 || !warn_deprecated_decl) 11583 return; 11584 11585 if (!attr) 11586 { 11587 if (DECL_P (node)) 11588 attr = DECL_ATTRIBUTES (node); 11589 else if (TYPE_P (node)) 11590 { 11591 tree decl = TYPE_STUB_DECL (node); 11592 if (decl) 11593 attr = lookup_attribute ("deprecated", 11594 TYPE_ATTRIBUTES (TREE_TYPE (decl))); 11595 } 11596 } 11597 11598 if (attr) 11599 attr = lookup_attribute ("deprecated", attr); 11600 11601 if (attr) 11602 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); 11603 else 11604 msg = NULL; 11605 11606 if (DECL_P (node)) 11607 { 11608 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node)); 11609 if (msg) 11610 warning (OPT_Wdeprecated_declarations, 11611 "%qD is deprecated (declared at %s:%d): %s", 11612 node, xloc.file, xloc.line, msg); 11613 else 11614 warning (OPT_Wdeprecated_declarations, 11615 "%qD is deprecated (declared at %s:%d)", 11616 node, xloc.file, xloc.line); 11617 } 11618 else if (TYPE_P (node)) 11619 { 11620 tree what = NULL_TREE; 11621 tree decl = TYPE_STUB_DECL (node); 11622 11623 if (TYPE_NAME (node)) 11624 { 11625 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE) 11626 what = TYPE_NAME (node); 11627 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL 11628 && DECL_NAME (TYPE_NAME (node))) 11629 what = DECL_NAME (TYPE_NAME (node)); 11630 } 11631 11632 if (decl) 11633 { 11634 expanded_location xloc 11635 = expand_location (DECL_SOURCE_LOCATION (decl)); 11636 if (what) 11637 { 11638 if (msg) 11639 warning (OPT_Wdeprecated_declarations, 11640 "%qE is deprecated (declared at %s:%d): %s", 11641 what, xloc.file, xloc.line, msg); 11642 else 11643 warning (OPT_Wdeprecated_declarations, 11644 "%qE is deprecated (declared at %s:%d)", what, 11645 xloc.file, xloc.line); 11646 } 11647 else 11648 { 11649 if (msg) 11650 warning (OPT_Wdeprecated_declarations, 11651 "type is deprecated (declared at %s:%d): %s", 11652 xloc.file, xloc.line, msg); 11653 else 11654 warning (OPT_Wdeprecated_declarations, 11655 "type is deprecated (declared at %s:%d)", 11656 xloc.file, xloc.line); 11657 } 11658 } 11659 else 11660 { 11661 if (what) 11662 { 11663 if (msg) 11664 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s", 11665 what, msg); 11666 else 11667 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what); 11668 } 11669 else 11670 { 11671 if (msg) 11672 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s", 11673 msg); 11674 else 11675 warning (OPT_Wdeprecated_declarations, "type is deprecated"); 11676 } 11677 } 11678 } 11679 } 11680 11681 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration 11682 somewhere in it. */ 11683 11684 bool 11685 contains_bitfld_component_ref_p (const_tree ref) 11686 { 11687 while (handled_component_p (ref)) 11688 { 11689 if (TREE_CODE (ref) == COMPONENT_REF 11690 && DECL_BIT_FIELD (TREE_OPERAND (ref, 1))) 11691 return true; 11692 ref = TREE_OPERAND (ref, 0); 11693 } 11694 11695 return false; 11696 } 11697 11698 #include "gt-tree.h" 11699