Home | History | Annotate | Line # | Download | only in gcc
      1 /* Language-independent node constructors for parse phase of GNU compiler.
      2    Copyright (C) 1987-2024 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 can occasionally
     28    calls language-dependent routines.  */
     29 
     30 #include "config.h"
     31 #include "system.h"
     32 #include "coretypes.h"
     33 #include "backend.h"
     34 #include "target.h"
     35 #include "tree.h"
     36 #include "gimple.h"
     37 #include "tree-pass.h"
     38 #include "ssa.h"
     39 #include "cgraph.h"
     40 #include "diagnostic.h"
     41 #include "flags.h"
     42 #include "alias.h"
     43 #include "fold-const.h"
     44 #include "stor-layout.h"
     45 #include "calls.h"
     46 #include "attribs.h"
     47 #include "toplev.h" /* get_random_seed */
     48 #include "output.h"
     49 #include "common/common-target.h"
     50 #include "langhooks.h"
     51 #include "tree-inline.h"
     52 #include "tree-iterator.h"
     53 #include "internal-fn.h"
     54 #include "gimple-iterator.h"
     55 #include "gimplify.h"
     56 #include "tree-dfa.h"
     57 #include "langhooks-def.h"
     58 #include "tree-diagnostic.h"
     59 #include "except.h"
     60 #include "builtins.h"
     61 #include "print-tree.h"
     62 #include "ipa-utils.h"
     63 #include "selftest.h"
     64 #include "stringpool.h"
     65 #include "attribs.h"
     66 #include "rtl.h"
     67 #include "regs.h"
     68 #include "tree-vector-builder.h"
     69 #include "gimple-fold.h"
     70 #include "escaped_string.h"
     71 #include "gimple-range.h"
     72 #include "gomp-constants.h"
     73 #include "dfp.h"
     74 #include "asan.h"
     75 #include "ubsan.h"
     76 
     77 /* Names of tree components.
     78    Used for printing out the tree and error messages.  */
     79 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
     80 #define END_OF_BASE_TREE_CODES "@dummy",
     81 
     82 static const char *const tree_code_name[] = {
     83 #include "all-tree.def"
     84 };
     85 
     86 #undef DEFTREECODE
     87 #undef END_OF_BASE_TREE_CODES
     88 
     89 /* Each tree code class has an associated string representation.
     90    These must correspond to the tree_code_class entries.  */
     91 
     92 const char *const tree_code_class_strings[] =
     93 {
     94   "exceptional",
     95   "constant",
     96   "type",
     97   "declaration",
     98   "reference",
     99   "comparison",
    100   "unary",
    101   "binary",
    102   "statement",
    103   "vl_exp",
    104   "expression"
    105 };
    106 
    107 /* obstack.[ch] explicitly declined to prototype this.  */
    108 extern int _obstack_allocated_p (struct obstack *h, void *obj);
    109 
    110 /* Statistics-gathering stuff.  */
    111 
    112 static uint64_t tree_code_counts[MAX_TREE_CODES];
    113 uint64_t tree_node_counts[(int) all_kinds];
    114 uint64_t tree_node_sizes[(int) all_kinds];
    115 
    116 /* Keep in sync with tree.h:enum tree_node_kind.  */
    117 static const char * const tree_node_kind_names[] = {
    118   "decls",
    119   "types",
    120   "blocks",
    121   "stmts",
    122   "refs",
    123   "exprs",
    124   "constants",
    125   "identifiers",
    126   "vecs",
    127   "binfos",
    128   "ssa names",
    129   "constructors",
    130   "random kinds",
    131   "lang_decl kinds",
    132   "lang_type kinds",
    133   "omp clauses",
    134 };
    135 
    136 /* Unique id for next decl created.  */
    137 static GTY(()) int next_decl_uid;
    138 /* Unique id for next type created.  */
    139 static GTY(()) unsigned next_type_uid = 1;
    140 /* Unique id for next debug decl created.  Use negative numbers,
    141    to catch erroneous uses.  */
    142 static GTY(()) int next_debug_decl_uid;
    143 
    144 /* Since we cannot rehash a type after it is in the table, we have to
    145    keep the hash code.  */
    146 
    147 struct GTY((for_user)) type_hash {
    148   unsigned long hash;
    149   tree type;
    150 };
    151 
    152 /* Initial size of the hash table (rounded to next prime).  */
    153 #define TYPE_HASH_INITIAL_SIZE 1000
    154 
    155 struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
    156 {
    157   static hashval_t hash (type_hash *t) { return t->hash; }
    158   static bool equal (type_hash *a, type_hash *b);
    159 
    160   static int
    161   keep_cache_entry (type_hash *&t)
    162   {
    163     return ggc_marked_p (t->type);
    164   }
    165 };
    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 ((cache)) hash_table<type_cache_hasher> *type_hash_table;
    175 
    176 /* Hash table and temporary node for larger integer const values.  */
    177 static GTY (()) tree int_cst_node;
    178 
    179 struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
    180 {
    181   static hashval_t hash (tree t);
    182   static bool equal (tree x, tree y);
    183 };
    184 
    185 static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
    186 
    187 /* Class and variable for making sure that there is a single POLY_INT_CST
    188    for a given value.  */
    189 struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
    190 {
    191   typedef std::pair<tree, const poly_wide_int *> compare_type;
    192   static hashval_t hash (tree t);
    193   static bool equal (tree x, const compare_type &y);
    194 };
    195 
    196 static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
    197 
    198 /* Hash table for optimization flags and target option flags.  Use the same
    199    hash table for both sets of options.  Nodes for building the current
    200    optimization and target option nodes.  The assumption is most of the time
    201    the options created will already be in the hash table, so we avoid
    202    allocating and freeing up a node repeatably.  */
    203 static GTY (()) tree cl_optimization_node;
    204 static GTY (()) tree cl_target_option_node;
    205 
    206 struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
    207 {
    208   static hashval_t hash (tree t);
    209   static bool equal (tree x, tree y);
    210 };
    211 
    212 static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
    213 
    214 /* General tree->tree mapping  structure for use in hash tables.  */
    215 
    216 
    217 static GTY ((cache))
    218      hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
    219 
    220 static GTY ((cache))
    221      hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
    222 
    223 static GTY ((cache))
    224      hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
    225 
    226 static void set_type_quals (tree, int);
    227 static void print_type_hash_statistics (void);
    228 static void print_debug_expr_statistics (void);
    229 static void print_value_expr_statistics (void);
    230 
    231 tree global_trees[TI_MAX];
    232 tree integer_types[itk_none];
    233 
    234 bool int_n_enabled_p[NUM_INT_N_ENTS];
    235 struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
    236 
    237 bool tree_contains_struct[MAX_TREE_CODES][64];
    238 
    239 /* Number of operands for each OMP clause.  */
    240 unsigned const char omp_clause_num_ops[] =
    241 {
    242   0, /* OMP_CLAUSE_ERROR  */
    243   1, /* OMP_CLAUSE_PRIVATE  */
    244   1, /* OMP_CLAUSE_SHARED  */
    245   1, /* OMP_CLAUSE_FIRSTPRIVATE  */
    246   2, /* OMP_CLAUSE_LASTPRIVATE  */
    247   5, /* OMP_CLAUSE_REDUCTION  */
    248   5, /* OMP_CLAUSE_TASK_REDUCTION  */
    249   5, /* OMP_CLAUSE_IN_REDUCTION  */
    250   1, /* OMP_CLAUSE_COPYIN  */
    251   1, /* OMP_CLAUSE_COPYPRIVATE  */
    252   3, /* OMP_CLAUSE_LINEAR  */
    253   1, /* OMP_CLAUSE_AFFINITY  */
    254   2, /* OMP_CLAUSE_ALIGNED  */
    255   3, /* OMP_CLAUSE_ALLOCATE  */
    256   1, /* OMP_CLAUSE_DEPEND  */
    257   1, /* OMP_CLAUSE_NONTEMPORAL  */
    258   1, /* OMP_CLAUSE_UNIFORM  */
    259   1, /* OMP_CLAUSE_ENTER  */
    260   1, /* OMP_CLAUSE_LINK  */
    261   1, /* OMP_CLAUSE_DETACH  */
    262   1, /* OMP_CLAUSE_USE_DEVICE_PTR  */
    263   1, /* OMP_CLAUSE_USE_DEVICE_ADDR  */
    264   1, /* OMP_CLAUSE_IS_DEVICE_PTR  */
    265   1, /* OMP_CLAUSE_INCLUSIVE  */
    266   1, /* OMP_CLAUSE_EXCLUSIVE  */
    267   2, /* OMP_CLAUSE_FROM  */
    268   2, /* OMP_CLAUSE_TO  */
    269   2, /* OMP_CLAUSE_MAP  */
    270   1, /* OMP_CLAUSE_HAS_DEVICE_ADDR  */
    271   1, /* OMP_CLAUSE_DOACROSS  */
    272   2, /* OMP_CLAUSE__CACHE_  */
    273   2, /* OMP_CLAUSE_GANG  */
    274   1, /* OMP_CLAUSE_ASYNC  */
    275   1, /* OMP_CLAUSE_WAIT  */
    276   0, /* OMP_CLAUSE_AUTO  */
    277   0, /* OMP_CLAUSE_SEQ  */
    278   1, /* OMP_CLAUSE__LOOPTEMP_  */
    279   1, /* OMP_CLAUSE__REDUCTEMP_  */
    280   1, /* OMP_CLAUSE__CONDTEMP_  */
    281   1, /* OMP_CLAUSE__SCANTEMP_  */
    282   1, /* OMP_CLAUSE_IF  */
    283   1, /* OMP_CLAUSE_SELF */
    284   1, /* OMP_CLAUSE_NUM_THREADS  */
    285   1, /* OMP_CLAUSE_SCHEDULE  */
    286   0, /* OMP_CLAUSE_NOWAIT  */
    287   1, /* OMP_CLAUSE_ORDERED  */
    288   0, /* OMP_CLAUSE_DEFAULT  */
    289   3, /* OMP_CLAUSE_COLLAPSE  */
    290   0, /* OMP_CLAUSE_UNTIED   */
    291   1, /* OMP_CLAUSE_FINAL  */
    292   0, /* OMP_CLAUSE_MERGEABLE  */
    293   1, /* OMP_CLAUSE_DEVICE  */
    294   1, /* OMP_CLAUSE_DIST_SCHEDULE  */
    295   0, /* OMP_CLAUSE_INBRANCH  */
    296   0, /* OMP_CLAUSE_NOTINBRANCH  */
    297   2, /* OMP_CLAUSE_NUM_TEAMS  */
    298   1, /* OMP_CLAUSE_THREAD_LIMIT  */
    299   0, /* OMP_CLAUSE_PROC_BIND  */
    300   1, /* OMP_CLAUSE_SAFELEN  */
    301   1, /* OMP_CLAUSE_SIMDLEN  */
    302   0, /* OMP_CLAUSE_DEVICE_TYPE  */
    303   0, /* OMP_CLAUSE_FOR  */
    304   0, /* OMP_CLAUSE_PARALLEL  */
    305   0, /* OMP_CLAUSE_SECTIONS  */
    306   0, /* OMP_CLAUSE_TASKGROUP  */
    307   1, /* OMP_CLAUSE_PRIORITY  */
    308   1, /* OMP_CLAUSE_GRAINSIZE  */
    309   1, /* OMP_CLAUSE_NUM_TASKS  */
    310   0, /* OMP_CLAUSE_NOGROUP  */
    311   0, /* OMP_CLAUSE_THREADS  */
    312   0, /* OMP_CLAUSE_SIMD  */
    313   1, /* OMP_CLAUSE_HINT  */
    314   0, /* OMP_CLAUSE_DEFAULTMAP  */
    315   0, /* OMP_CLAUSE_ORDER  */
    316   0, /* OMP_CLAUSE_BIND  */
    317   1, /* OMP_CLAUSE_FILTER  */
    318   1, /* OMP_CLAUSE_INDIRECT  */
    319   1, /* OMP_CLAUSE__SIMDUID_  */
    320   0, /* OMP_CLAUSE__SIMT_  */
    321   0, /* OMP_CLAUSE_INDEPENDENT  */
    322   1, /* OMP_CLAUSE_WORKER  */
    323   1, /* OMP_CLAUSE_VECTOR  */
    324   1, /* OMP_CLAUSE_NUM_GANGS  */
    325   1, /* OMP_CLAUSE_NUM_WORKERS  */
    326   1, /* OMP_CLAUSE_VECTOR_LENGTH  */
    327   3, /* OMP_CLAUSE_TILE  */
    328   0, /* OMP_CLAUSE_IF_PRESENT */
    329   0, /* OMP_CLAUSE_FINALIZE */
    330   0, /* OMP_CLAUSE_NOHOST */
    331 };
    332 
    333 const char * const omp_clause_code_name[] =
    334 {
    335   "error_clause",
    336   "private",
    337   "shared",
    338   "firstprivate",
    339   "lastprivate",
    340   "reduction",
    341   "task_reduction",
    342   "in_reduction",
    343   "copyin",
    344   "copyprivate",
    345   "linear",
    346   "affinity",
    347   "aligned",
    348   "allocate",
    349   "depend",
    350   "nontemporal",
    351   "uniform",
    352   "enter",
    353   "link",
    354   "detach",
    355   "use_device_ptr",
    356   "use_device_addr",
    357   "is_device_ptr",
    358   "inclusive",
    359   "exclusive",
    360   "from",
    361   "to",
    362   "map",
    363   "has_device_addr",
    364   "doacross",
    365   "_cache_",
    366   "gang",
    367   "async",
    368   "wait",
    369   "auto",
    370   "seq",
    371   "_looptemp_",
    372   "_reductemp_",
    373   "_condtemp_",
    374   "_scantemp_",
    375   "if",
    376   "self",
    377   "num_threads",
    378   "schedule",
    379   "nowait",
    380   "ordered",
    381   "default",
    382   "collapse",
    383   "untied",
    384   "final",
    385   "mergeable",
    386   "device",
    387   "dist_schedule",
    388   "inbranch",
    389   "notinbranch",
    390   "num_teams",
    391   "thread_limit",
    392   "proc_bind",
    393   "safelen",
    394   "simdlen",
    395   "device_type",
    396   "for",
    397   "parallel",
    398   "sections",
    399   "taskgroup",
    400   "priority",
    401   "grainsize",
    402   "num_tasks",
    403   "nogroup",
    404   "threads",
    405   "simd",
    406   "hint",
    407   "defaultmap",
    408   "order",
    409   "bind",
    410   "filter",
    411   "indirect",
    412   "_simduid_",
    413   "_simt_",
    414   "independent",
    415   "worker",
    416   "vector",
    417   "num_gangs",
    418   "num_workers",
    419   "vector_length",
    420   "tile",
    421   "if_present",
    422   "finalize",
    423   "nohost",
    424 };
    425 
    426 /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
    427    clause names, but for use in diagnostics etc. would like to use the "user"
    428    clause names.  */
    429 
    430 const char *
    431 user_omp_clause_code_name (tree clause, bool oacc)
    432 {
    433   /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
    434      distinguish clauses as seen by the user.  See also where front ends do
    435      'build_omp_clause' with 'OMP_CLAUSE_MAP'.  */
    436   if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
    437     switch (OMP_CLAUSE_MAP_KIND (clause))
    438       {
    439       case GOMP_MAP_FORCE_ALLOC:
    440       case GOMP_MAP_ALLOC: return "create";
    441       case GOMP_MAP_FORCE_TO:
    442       case GOMP_MAP_TO: return "copyin";
    443       case GOMP_MAP_FORCE_FROM:
    444       case GOMP_MAP_FROM: return "copyout";
    445       case GOMP_MAP_FORCE_TOFROM:
    446       case GOMP_MAP_TOFROM: return "copy";
    447       case GOMP_MAP_RELEASE: return "delete";
    448       case GOMP_MAP_FORCE_PRESENT: return "present";
    449       case GOMP_MAP_ATTACH: return "attach";
    450       case GOMP_MAP_FORCE_DETACH:
    451       case GOMP_MAP_DETACH: return "detach";
    452       case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
    453       case GOMP_MAP_LINK: return "link";
    454       case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
    455       default: break;
    456       }
    457 
    458   return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
    459 }
    460 
    461 
    462 /* Return the tree node structure used by tree code CODE.  */
    463 
    464 static inline enum tree_node_structure_enum
    465 tree_node_structure_for_code (enum tree_code code)
    466 {
    467   switch (TREE_CODE_CLASS (code))
    468     {
    469     case tcc_declaration:
    470       switch (code)
    471 	{
    472 	case CONST_DECL:	return TS_CONST_DECL;
    473 	case DEBUG_EXPR_DECL:	return TS_DECL_WRTL;
    474 	case FIELD_DECL:	return TS_FIELD_DECL;
    475 	case FUNCTION_DECL:	return TS_FUNCTION_DECL;
    476 	case LABEL_DECL:	return TS_LABEL_DECL;
    477 	case PARM_DECL:		return TS_PARM_DECL;
    478 	case RESULT_DECL:	return TS_RESULT_DECL;
    479 	case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
    480 	case TYPE_DECL:		return TS_TYPE_DECL;
    481 	case VAR_DECL:		return TS_VAR_DECL;
    482 	default: 		return TS_DECL_NON_COMMON;
    483 	}
    484 
    485     case tcc_type:		return TS_TYPE_NON_COMMON;
    486 
    487     case tcc_binary:
    488     case tcc_comparison:
    489     case tcc_expression:
    490     case tcc_reference:
    491     case tcc_statement:
    492     case tcc_unary:
    493     case tcc_vl_exp:		return TS_EXP;
    494 
    495     default:  /* tcc_constant and tcc_exceptional */
    496       break;
    497     }
    498 
    499   switch (code)
    500     {
    501       /* tcc_constant cases.  */
    502     case COMPLEX_CST:		return TS_COMPLEX;
    503     case FIXED_CST:		return TS_FIXED_CST;
    504     case INTEGER_CST:		return TS_INT_CST;
    505     case POLY_INT_CST:		return TS_POLY_INT_CST;
    506     case REAL_CST:		return TS_REAL_CST;
    507     case STRING_CST:		return TS_STRING;
    508     case VECTOR_CST:		return TS_VECTOR;
    509     case VOID_CST:		return TS_TYPED;
    510 
    511       /* tcc_exceptional cases.  */
    512     case BLOCK:			return TS_BLOCK;
    513     case CONSTRUCTOR:		return TS_CONSTRUCTOR;
    514     case ERROR_MARK:		return TS_COMMON;
    515     case IDENTIFIER_NODE:	return TS_IDENTIFIER;
    516     case OMP_CLAUSE:		return TS_OMP_CLAUSE;
    517     case OPTIMIZATION_NODE:	return TS_OPTIMIZATION;
    518     case PLACEHOLDER_EXPR:	return TS_COMMON;
    519     case SSA_NAME:		return TS_SSA_NAME;
    520     case STATEMENT_LIST:	return TS_STATEMENT_LIST;
    521     case TARGET_OPTION_NODE:	return TS_TARGET_OPTION;
    522     case TREE_BINFO:		return TS_BINFO;
    523     case TREE_LIST:		return TS_LIST;
    524     case TREE_VEC:		return TS_VEC;
    525 
    526     default:
    527       gcc_unreachable ();
    528     }
    529 }
    530 
    531 
    532 /* Initialize tree_contains_struct to describe the hierarchy of tree
    533    nodes.  */
    534 
    535 static void
    536 initialize_tree_contains_struct (void)
    537 {
    538   unsigned i;
    539 
    540   for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
    541     {
    542       enum tree_code code;
    543       enum tree_node_structure_enum ts_code;
    544 
    545       code = (enum tree_code) i;
    546       ts_code = tree_node_structure_for_code (code);
    547 
    548       /* Mark the TS structure itself.  */
    549       tree_contains_struct[code][ts_code] = 1;
    550 
    551       /* Mark all the structures that TS is derived from.  */
    552       switch (ts_code)
    553 	{
    554 	case TS_TYPED:
    555 	case TS_BLOCK:
    556 	case TS_OPTIMIZATION:
    557 	case TS_TARGET_OPTION:
    558 	  MARK_TS_BASE (code);
    559 	  break;
    560 
    561 	case TS_COMMON:
    562 	case TS_INT_CST:
    563 	case TS_POLY_INT_CST:
    564 	case TS_REAL_CST:
    565 	case TS_FIXED_CST:
    566 	case TS_VECTOR:
    567 	case TS_STRING:
    568 	case TS_COMPLEX:
    569 	case TS_SSA_NAME:
    570 	case TS_CONSTRUCTOR:
    571 	case TS_EXP:
    572 	case TS_STATEMENT_LIST:
    573 	  MARK_TS_TYPED (code);
    574 	  break;
    575 
    576 	case TS_IDENTIFIER:
    577 	case TS_DECL_MINIMAL:
    578 	case TS_TYPE_COMMON:
    579 	case TS_LIST:
    580 	case TS_VEC:
    581 	case TS_BINFO:
    582 	case TS_OMP_CLAUSE:
    583 	  MARK_TS_COMMON (code);
    584 	  break;
    585 
    586 	case TS_TYPE_WITH_LANG_SPECIFIC:
    587 	  MARK_TS_TYPE_COMMON (code);
    588 	  break;
    589 
    590 	case TS_TYPE_NON_COMMON:
    591 	  MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
    592 	  break;
    593 
    594 	case TS_DECL_COMMON:
    595 	  MARK_TS_DECL_MINIMAL (code);
    596 	  break;
    597 
    598 	case TS_DECL_WRTL:
    599 	case TS_CONST_DECL:
    600 	  MARK_TS_DECL_COMMON (code);
    601 	  break;
    602 
    603 	case TS_DECL_NON_COMMON:
    604 	  MARK_TS_DECL_WITH_VIS (code);
    605 	  break;
    606 
    607 	case TS_DECL_WITH_VIS:
    608 	case TS_PARM_DECL:
    609 	case TS_LABEL_DECL:
    610 	case TS_RESULT_DECL:
    611 	  MARK_TS_DECL_WRTL (code);
    612 	  break;
    613 
    614 	case TS_FIELD_DECL:
    615 	  MARK_TS_DECL_COMMON (code);
    616 	  break;
    617 
    618 	case TS_VAR_DECL:
    619 	  MARK_TS_DECL_WITH_VIS (code);
    620 	  break;
    621 
    622 	case TS_TYPE_DECL:
    623 	case TS_FUNCTION_DECL:
    624 	  MARK_TS_DECL_NON_COMMON (code);
    625 	  break;
    626 
    627 	case TS_TRANSLATION_UNIT_DECL:
    628 	  MARK_TS_DECL_COMMON (code);
    629 	  break;
    630 
    631 	default:
    632 	  gcc_unreachable ();
    633 	}
    634     }
    635 
    636   /* Basic consistency checks for attributes used in fold.  */
    637   gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
    638   gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
    639   gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
    640   gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
    641   gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
    642   gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
    643   gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
    644   gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
    645   gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
    646   gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
    647   gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
    648   gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
    649   gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
    650   gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
    651   gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
    652   gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
    653   gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
    654   gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
    655   gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
    656   gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
    657   gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
    658   gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
    659   gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
    660   gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
    661   gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
    662   gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
    663   gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
    664   gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
    665   gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
    666   gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
    667   gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
    668   gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
    669   gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
    670   gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
    671   gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
    672   gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
    673   gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
    674   gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
    675   gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
    676   gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
    677 }
    678 
    679 
    680 /* Init tree.cc.  */
    681 
    682 void
    683 init_ttree (void)
    684 {
    685   /* Initialize the hash table of types.  */
    686   type_hash_table
    687     = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
    688 
    689   debug_expr_for_decl
    690     = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
    691 
    692   value_expr_for_decl
    693     = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
    694 
    695   int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
    696 
    697   poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
    698 
    699   int_cst_node = make_int_cst (1, 1);
    700 
    701   cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
    702 
    703   cl_optimization_node = make_node (OPTIMIZATION_NODE);
    704   cl_target_option_node = make_node (TARGET_OPTION_NODE);
    705 
    706   /* Initialize the tree_contains_struct array.  */
    707   initialize_tree_contains_struct ();
    708   lang_hooks.init_ts ();
    709 }
    710 
    711 
    712 /* The name of the object as the assembler will see it (but before any
    714    translations made by ASM_OUTPUT_LABELREF).  Often this is the same
    715    as DECL_NAME.  It is an IDENTIFIER_NODE.  */
    716 tree
    717 decl_assembler_name (tree decl)
    718 {
    719   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
    720     lang_hooks.set_decl_assembler_name (decl);
    721   return DECL_ASSEMBLER_NAME_RAW (decl);
    722 }
    723 
    724 /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
    725    (either of which may be NULL).  Inform the FE, if this changes the
    726    name.  */
    727 
    728 void
    729 overwrite_decl_assembler_name (tree decl, tree name)
    730 {
    731   if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
    732     lang_hooks.overwrite_decl_assembler_name (decl, name);
    733 }
    734 
    735 /* Return true if DECL may need an assembler name to be set.  */
    736 
    737 static inline bool
    738 need_assembler_name_p (tree decl)
    739 {
    740   /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
    741      Rule merging.  This makes type_odr_p to return true on those types during
    742      LTO and by comparing the mangled name, we can say what types are intended
    743      to be equivalent across compilation unit.
    744 
    745      We do not store names of type_in_anonymous_namespace_p.
    746 
    747      Record, union and enumeration type have linkage that allows use
    748      to check type_in_anonymous_namespace_p. We do not mangle compound types
    749      that always can be compared structurally.
    750 
    751      Similarly for builtin types, we compare properties of their main variant.
    752      A special case are integer types where mangling do make differences
    753      between char/signed char/unsigned char etc.  Storing name for these makes
    754      e.g.  -fno-signed-char/-fsigned-char mismatches to be handled well.
    755      See cp/mangle.cc:write_builtin_type for details.  */
    756 
    757   if (TREE_CODE (decl) == TYPE_DECL)
    758     {
    759       if (DECL_NAME (decl)
    760 	  && decl == TYPE_NAME (TREE_TYPE (decl))
    761 	  && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
    762 	  && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
    763 	  && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
    764 	       && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
    765 	      || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
    766 	  && (type_with_linkage_p (TREE_TYPE (decl))
    767 	      || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
    768 	  && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
    769 	return !DECL_ASSEMBLER_NAME_SET_P (decl);
    770       return false;
    771     }
    772   /* Only FUNCTION_DECLs and VAR_DECLs are considered.  */
    773   if (!VAR_OR_FUNCTION_DECL_P (decl))
    774     return false;
    775 
    776   /* If DECL already has its assembler name set, it does not need a
    777      new one.  */
    778   if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
    779       || DECL_ASSEMBLER_NAME_SET_P (decl))
    780     return false;
    781 
    782   /* Abstract decls do not need an assembler name.  */
    783   if (DECL_ABSTRACT_P (decl))
    784     return false;
    785 
    786   /* For VAR_DECLs, only static, public and external symbols need an
    787      assembler name.  */
    788   if (VAR_P (decl)
    789       && !TREE_STATIC (decl)
    790       && !TREE_PUBLIC (decl)
    791       && !DECL_EXTERNAL (decl))
    792     return false;
    793 
    794   if (TREE_CODE (decl) == FUNCTION_DECL)
    795     {
    796       /* Do not set assembler name on builtins.  Allow RTL expansion to
    797 	 decide whether to expand inline or via a regular call.  */
    798       if (fndecl_built_in_p (decl)
    799 	  && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
    800 	return false;
    801 
    802       /* Functions represented in the callgraph need an assembler name.  */
    803       if (cgraph_node::get (decl) != NULL)
    804 	return true;
    805 
    806       /* Unused and not public functions don't need an assembler name.  */
    807       if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
    808 	return false;
    809     }
    810 
    811   return true;
    812 }
    813 
    814 /* If T needs an assembler name, have one created for it.  */
    815 
    816 void
    817 assign_assembler_name_if_needed (tree t)
    818 {
    819   if (need_assembler_name_p (t))
    820     {
    821       /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
    822 	 diagnostics that use input_location to show locus
    823 	 information.  The problem here is that, at this point,
    824 	 input_location is generally anchored to the end of the file
    825 	 (since the parser is long gone), so we don't have a good
    826 	 position to pin it to.
    827 
    828 	 To alleviate this problem, this uses the location of T's
    829 	 declaration.  Examples of this are
    830 	 testsuite/g++.dg/template/cond2.C and
    831 	 testsuite/g++.dg/template/pr35240.C.  */
    832       location_t saved_location = input_location;
    833       input_location = DECL_SOURCE_LOCATION (t);
    834 
    835       decl_assembler_name (t);
    836 
    837       input_location = saved_location;
    838     }
    839 }
    840 
    841 /* When the target supports COMDAT groups, this indicates which group the
    842    DECL is associated with.  This can be either an IDENTIFIER_NODE or a
    843    decl, in which case its DECL_ASSEMBLER_NAME identifies the group.  */
    844 tree
    845 decl_comdat_group (const_tree node)
    846 {
    847   struct symtab_node *snode = symtab_node::get (node);
    848   if (!snode)
    849     return NULL;
    850   return snode->get_comdat_group ();
    851 }
    852 
    853 /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE.  */
    854 tree
    855 decl_comdat_group_id (const_tree node)
    856 {
    857   struct symtab_node *snode = symtab_node::get (node);
    858   if (!snode)
    859     return NULL;
    860   return snode->get_comdat_group_id ();
    861 }
    862 
    863 /* When the target supports named section, return its name as IDENTIFIER_NODE
    864    or NULL if it is in no section.  */
    865 const char *
    866 decl_section_name (const_tree node)
    867 {
    868   struct symtab_node *snode = symtab_node::get (node);
    869   if (!snode)
    870     return NULL;
    871   return snode->get_section ();
    872 }
    873 
    874 /* Set section name of NODE to VALUE (that is expected to be
    875    identifier node) */
    876 void
    877 set_decl_section_name (tree node, const char *value)
    878 {
    879   struct symtab_node *snode;
    880 
    881   if (value == NULL)
    882     {
    883       snode = symtab_node::get (node);
    884       if (!snode)
    885 	return;
    886     }
    887   else if (VAR_P (node))
    888     snode = varpool_node::get_create (node);
    889   else
    890     snode = cgraph_node::get_create (node);
    891   snode->set_section (value);
    892 }
    893 
    894 /* Set section name of NODE to match the section name of OTHER.
    895 
    896    set_decl_section_name (decl, other) is equivalent to
    897    set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
    898    efficient.  */
    899 void
    900 set_decl_section_name (tree decl, const_tree other)
    901 {
    902   struct symtab_node *other_node = symtab_node::get (other);
    903   if (other_node)
    904     {
    905       struct symtab_node *decl_node;
    906       if (VAR_P (decl))
    907     decl_node = varpool_node::get_create (decl);
    908       else
    909     decl_node = cgraph_node::get_create (decl);
    910       decl_node->set_section (*other_node);
    911     }
    912   else
    913     {
    914       struct symtab_node *decl_node = symtab_node::get (decl);
    915       if (!decl_node)
    916     return;
    917       decl_node->set_section (NULL);
    918     }
    919 }
    920 
    921 /* Return TLS model of a variable NODE.  */
    922 enum tls_model
    923 decl_tls_model (const_tree node)
    924 {
    925   struct varpool_node *snode = varpool_node::get (node);
    926   if (!snode)
    927     return TLS_MODEL_NONE;
    928   return snode->tls_model;
    929 }
    930 
    931 /* Set TLS model of variable NODE to MODEL.  */
    932 void
    933 set_decl_tls_model (tree node, enum tls_model model)
    934 {
    935   struct varpool_node *vnode;
    936 
    937   if (model == TLS_MODEL_NONE)
    938     {
    939       vnode = varpool_node::get (node);
    940       if (!vnode)
    941 	return;
    942     }
    943   else
    944     vnode = varpool_node::get_create (node);
    945   vnode->tls_model = model;
    946 }
    947 
    948 /* Compute the number of bytes occupied by a tree with code CODE.
    949    This function cannot be used for nodes that have variable sizes,
    950    including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR.  */
    951 size_t
    952 tree_code_size (enum tree_code code)
    953 {
    954   switch (TREE_CODE_CLASS (code))
    955     {
    956     case tcc_declaration:  /* A decl node */
    957       switch (code)
    958 	{
    959 	case FIELD_DECL:	return sizeof (tree_field_decl);
    960 	case PARM_DECL:		return sizeof (tree_parm_decl);
    961 	case VAR_DECL:		return sizeof (tree_var_decl);
    962 	case LABEL_DECL:	return sizeof (tree_label_decl);
    963 	case RESULT_DECL:	return sizeof (tree_result_decl);
    964 	case CONST_DECL:	return sizeof (tree_const_decl);
    965 	case TYPE_DECL:		return sizeof (tree_type_decl);
    966 	case FUNCTION_DECL:	return sizeof (tree_function_decl);
    967 	case DEBUG_EXPR_DECL:	return sizeof (tree_decl_with_rtl);
    968 	case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
    969 	case NAMESPACE_DECL:
    970 	case IMPORTED_DECL:
    971 	case NAMELIST_DECL:	return sizeof (tree_decl_non_common);
    972 	default:
    973 	  gcc_checking_assert (code >= NUM_TREE_CODES);
    974 	  return lang_hooks.tree_size (code);
    975 	}
    976 
    977     case tcc_type:  /* a type node */
    978       switch (code)
    979 	{
    980 	case OFFSET_TYPE:
    981 	case ENUMERAL_TYPE:
    982 	case BOOLEAN_TYPE:
    983 	case INTEGER_TYPE:
    984 	case REAL_TYPE:
    985 	case OPAQUE_TYPE:
    986 	case POINTER_TYPE:
    987 	case REFERENCE_TYPE:
    988 	case NULLPTR_TYPE:
    989 	case FIXED_POINT_TYPE:
    990 	case COMPLEX_TYPE:
    991 	case VECTOR_TYPE:
    992 	case ARRAY_TYPE:
    993 	case RECORD_TYPE:
    994 	case UNION_TYPE:
    995 	case QUAL_UNION_TYPE:
    996 	case VOID_TYPE:
    997 	case FUNCTION_TYPE:
    998 	case METHOD_TYPE:
    999 	case BITINT_TYPE:
   1000 	case LANG_TYPE:		return sizeof (tree_type_non_common);
   1001 	default:
   1002 	  gcc_checking_assert (code >= NUM_TREE_CODES);
   1003 	  return lang_hooks.tree_size (code);
   1004 	}
   1005 
   1006     case tcc_reference:   /* a reference */
   1007     case tcc_expression:  /* an expression */
   1008     case tcc_statement:   /* an expression with side effects */
   1009     case tcc_comparison:  /* a comparison expression */
   1010     case tcc_unary:       /* a unary arithmetic expression */
   1011     case tcc_binary:      /* a binary arithmetic expression */
   1012       return (sizeof (struct tree_exp)
   1013 	      + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
   1014 
   1015     case tcc_constant:  /* a constant */
   1016       switch (code)
   1017 	{
   1018 	case VOID_CST:		return sizeof (tree_typed);
   1019 	case INTEGER_CST:	gcc_unreachable ();
   1020 	case POLY_INT_CST:	return sizeof (tree_poly_int_cst);
   1021 	case REAL_CST:		return sizeof (tree_real_cst);
   1022 	case FIXED_CST:		return sizeof (tree_fixed_cst);
   1023 	case COMPLEX_CST:	return sizeof (tree_complex);
   1024 	case VECTOR_CST:	gcc_unreachable ();
   1025 	case STRING_CST:	gcc_unreachable ();
   1026 	default:
   1027 	  gcc_checking_assert (code >= NUM_TREE_CODES);
   1028 	  return lang_hooks.tree_size (code);
   1029 	}
   1030 
   1031     case tcc_exceptional:  /* something random, like an identifier.  */
   1032       switch (code)
   1033 	{
   1034 	case IDENTIFIER_NODE:	return lang_hooks.identifier_size;
   1035 	case TREE_LIST:		return sizeof (tree_list);
   1036 
   1037 	case ERROR_MARK:
   1038 	case PLACEHOLDER_EXPR:	return sizeof (tree_common);
   1039 
   1040 	case TREE_VEC:		gcc_unreachable ();
   1041 	case OMP_CLAUSE:	gcc_unreachable ();
   1042 
   1043 	case SSA_NAME:		return sizeof (tree_ssa_name);
   1044 
   1045 	case STATEMENT_LIST:	return sizeof (tree_statement_list);
   1046 	case BLOCK:		return sizeof (struct tree_block);
   1047 	case CONSTRUCTOR:	return sizeof (tree_constructor);
   1048 	case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
   1049 	case TARGET_OPTION_NODE: return sizeof (tree_target_option);
   1050 
   1051 	default:
   1052 	  gcc_checking_assert (code >= NUM_TREE_CODES);
   1053 	  return lang_hooks.tree_size (code);
   1054 	}
   1055 
   1056     default:
   1057       gcc_unreachable ();
   1058     }
   1059 }
   1060 
   1061 /* Compute the number of bytes occupied by NODE.  This routine only
   1062    looks at TREE_CODE, except for those nodes that have variable sizes.  */
   1063 size_t
   1064 tree_size (const_tree node)
   1065 {
   1066   const enum tree_code code = TREE_CODE (node);
   1067   switch (code)
   1068     {
   1069     case INTEGER_CST:
   1070       return (sizeof (struct tree_int_cst)
   1071 	      + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
   1072 
   1073     case TREE_BINFO:
   1074       return (offsetof (struct tree_binfo, base_binfos)
   1075 	      + vec<tree, va_gc>
   1076 		  ::embedded_size (BINFO_N_BASE_BINFOS (node)));
   1077 
   1078     case TREE_VEC:
   1079       return (sizeof (struct tree_vec)
   1080 	      + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
   1081 
   1082     case VECTOR_CST:
   1083       return (sizeof (struct tree_vector)
   1084 	      + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
   1085 
   1086     case STRING_CST:
   1087       return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
   1088 
   1089     case OMP_CLAUSE:
   1090       return (sizeof (struct tree_omp_clause)
   1091 	      + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
   1092 	        * sizeof (tree));
   1093 
   1094     default:
   1095       if (TREE_CODE_CLASS (code) == tcc_vl_exp)
   1096 	return (sizeof (struct tree_exp)
   1097 		+ (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
   1098       else
   1099 	return tree_code_size (code);
   1100     }
   1101 }
   1102 
   1103 /* Return tree node kind based on tree CODE.  */
   1104 
   1105 static tree_node_kind
   1106 get_stats_node_kind (enum tree_code code)
   1107 {
   1108   enum tree_code_class type = TREE_CODE_CLASS (code);
   1109 
   1110   switch (type)
   1111     {
   1112     case tcc_declaration:  /* A decl node */
   1113       return d_kind;
   1114     case tcc_type:  /* a type node */
   1115       return t_kind;
   1116     case tcc_statement:  /* an expression with side effects */
   1117       return s_kind;
   1118     case tcc_reference:  /* a reference */
   1119       return r_kind;
   1120     case tcc_expression:  /* an expression */
   1121     case tcc_comparison:  /* a comparison expression */
   1122     case tcc_unary:  /* a unary arithmetic expression */
   1123     case tcc_binary:  /* a binary arithmetic expression */
   1124       return e_kind;
   1125     case tcc_constant:  /* a constant */
   1126       return c_kind;
   1127     case tcc_exceptional:  /* something random, like an identifier.  */
   1128       switch (code)
   1129 	{
   1130 	case IDENTIFIER_NODE:
   1131 	  return id_kind;
   1132 	case TREE_VEC:
   1133 	  return vec_kind;
   1134 	case TREE_BINFO:
   1135 	  return binfo_kind;
   1136 	case SSA_NAME:
   1137 	  return ssa_name_kind;
   1138 	case BLOCK:
   1139 	  return b_kind;
   1140 	case CONSTRUCTOR:
   1141 	  return constr_kind;
   1142 	case OMP_CLAUSE:
   1143 	  return omp_clause_kind;
   1144 	default:
   1145 	  return x_kind;
   1146 	}
   1147       break;
   1148     case tcc_vl_exp:
   1149       return e_kind;
   1150     default:
   1151       gcc_unreachable ();
   1152     }
   1153 }
   1154 
   1155 /* Record interesting allocation statistics for a tree node with CODE
   1156    and LENGTH.  */
   1157 
   1158 static void
   1159 record_node_allocation_statistics (enum tree_code code, size_t length)
   1160 {
   1161   if (!GATHER_STATISTICS)
   1162     return;
   1163 
   1164   tree_node_kind kind = get_stats_node_kind (code);
   1165 
   1166   tree_code_counts[(int) code]++;
   1167   tree_node_counts[(int) kind]++;
   1168   tree_node_sizes[(int) kind] += length;
   1169 }
   1170 
   1171 /* Allocate and return a new UID from the DECL_UID namespace.  */
   1172 
   1173 int
   1174 allocate_decl_uid (void)
   1175 {
   1176   return next_decl_uid++;
   1177 }
   1178 
   1179 /* Return a newly allocated node of code CODE.  For decl and type
   1180    nodes, some other fields are initialized.  The rest of the node is
   1181    initialized to zero.  This function cannot be used for TREE_VEC,
   1182    INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
   1183    tree_code_size.
   1184 
   1185    Achoo!  I got a code in the node.  */
   1186 
   1187 tree
   1188 make_node (enum tree_code code MEM_STAT_DECL)
   1189 {
   1190   tree t;
   1191   enum tree_code_class type = TREE_CODE_CLASS (code);
   1192   size_t length = tree_code_size (code);
   1193 
   1194   record_node_allocation_statistics (code, length);
   1195 
   1196   t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
   1197   TREE_SET_CODE (t, code);
   1198 
   1199   switch (type)
   1200     {
   1201     case tcc_statement:
   1202       if (code != DEBUG_BEGIN_STMT)
   1203 	TREE_SIDE_EFFECTS (t) = 1;
   1204       break;
   1205 
   1206     case tcc_declaration:
   1207       if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
   1208 	{
   1209 	  if (code == FUNCTION_DECL)
   1210 	    {
   1211 	      SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
   1212 	      SET_DECL_MODE (t, FUNCTION_MODE);
   1213 	    }
   1214 	  else
   1215 	    SET_DECL_ALIGN (t, 1);
   1216 	}
   1217       DECL_SOURCE_LOCATION (t) = input_location;
   1218       if (TREE_CODE (t) == DEBUG_EXPR_DECL)
   1219 	DECL_UID (t) = --next_debug_decl_uid;
   1220       else
   1221 	{
   1222 	  DECL_UID (t) = allocate_decl_uid ();
   1223 	  SET_DECL_PT_UID (t, -1);
   1224 	}
   1225       if (TREE_CODE (t) == LABEL_DECL)
   1226 	LABEL_DECL_UID (t) = -1;
   1227 
   1228       break;
   1229 
   1230     case tcc_type:
   1231       TYPE_UID (t) = next_type_uid++;
   1232       SET_TYPE_ALIGN (t, BITS_PER_UNIT);
   1233       TYPE_USER_ALIGN (t) = 0;
   1234       TYPE_MAIN_VARIANT (t) = t;
   1235       TYPE_CANONICAL (t) = t;
   1236 
   1237       /* Default to no attributes for type, but let target change that.  */
   1238       TYPE_ATTRIBUTES (t) = NULL_TREE;
   1239       targetm.set_default_type_attributes (t);
   1240 
   1241       /* We have not yet computed the alias set for this type.  */
   1242       TYPE_ALIAS_SET (t) = -1;
   1243       break;
   1244 
   1245     case tcc_constant:
   1246       TREE_CONSTANT (t) = 1;
   1247       break;
   1248 
   1249     case tcc_expression:
   1250       switch (code)
   1251 	{
   1252 	case INIT_EXPR:
   1253 	case MODIFY_EXPR:
   1254 	case VA_ARG_EXPR:
   1255 	case PREDECREMENT_EXPR:
   1256 	case PREINCREMENT_EXPR:
   1257 	case POSTDECREMENT_EXPR:
   1258 	case POSTINCREMENT_EXPR:
   1259 	  /* All of these have side-effects, no matter what their
   1260 	     operands are.  */
   1261 	  TREE_SIDE_EFFECTS (t) = 1;
   1262 	  break;
   1263 
   1264 	default:
   1265 	  break;
   1266 	}
   1267       break;
   1268 
   1269     case tcc_exceptional:
   1270       switch (code)
   1271         {
   1272 	case TARGET_OPTION_NODE:
   1273 	  TREE_TARGET_OPTION(t)
   1274 			    = ggc_cleared_alloc<struct cl_target_option> ();
   1275 	  break;
   1276 
   1277 	case OPTIMIZATION_NODE:
   1278 	  TREE_OPTIMIZATION (t)
   1279 			    = ggc_cleared_alloc<struct cl_optimization> ();
   1280 	  break;
   1281 
   1282 	default:
   1283 	  break;
   1284 	}
   1285       break;
   1286 
   1287     default:
   1288       /* Other classes need no special treatment.  */
   1289       break;
   1290     }
   1291 
   1292   return t;
   1293 }
   1294 
   1295 /* Free tree node.  */
   1296 
   1297 void
   1298 free_node (tree node)
   1299 {
   1300   enum tree_code code = TREE_CODE (node);
   1301   if (GATHER_STATISTICS)
   1302     {
   1303       enum tree_node_kind kind = get_stats_node_kind (code);
   1304 
   1305       gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
   1306       gcc_checking_assert (tree_node_counts[(int) kind] != 0);
   1307       gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
   1308 
   1309       tree_code_counts[(int) TREE_CODE (node)]--;
   1310       tree_node_counts[(int) kind]--;
   1311       tree_node_sizes[(int) kind] -= tree_size (node);
   1312     }
   1313   if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
   1314     vec_free (CONSTRUCTOR_ELTS (node));
   1315   else if (code == BLOCK)
   1316     vec_free (BLOCK_NONLOCALIZED_VARS (node));
   1317   else if (code == TREE_BINFO)
   1318     vec_free (BINFO_BASE_ACCESSES (node));
   1319   else if (code == OPTIMIZATION_NODE)
   1320     cl_optimization_option_free (TREE_OPTIMIZATION (node));
   1321   else if (code == TARGET_OPTION_NODE)
   1322     cl_target_option_free (TREE_TARGET_OPTION (node));
   1323   ggc_free (node);
   1324 }
   1325 
   1326 /* Return a new node with the same contents as NODE except that its
   1328    TREE_CHAIN, if it has one, is zero and it has a fresh uid.  */
   1329 
   1330 tree
   1331 copy_node (tree node MEM_STAT_DECL)
   1332 {
   1333   tree t;
   1334   enum tree_code code = TREE_CODE (node);
   1335   size_t length;
   1336 
   1337   gcc_assert (code != STATEMENT_LIST);
   1338 
   1339   length = tree_size (node);
   1340   record_node_allocation_statistics (code, length);
   1341   t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
   1342   memcpy (t, node, length);
   1343 
   1344   if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
   1345     TREE_CHAIN (t) = 0;
   1346   TREE_ASM_WRITTEN (t) = 0;
   1347   TREE_VISITED (t) = 0;
   1348 
   1349   if (TREE_CODE_CLASS (code) == tcc_declaration)
   1350     {
   1351       if (code == DEBUG_EXPR_DECL)
   1352 	DECL_UID (t) = --next_debug_decl_uid;
   1353       else
   1354 	{
   1355 	  DECL_UID (t) = allocate_decl_uid ();
   1356 	  if (DECL_PT_UID_SET_P (node))
   1357 	    SET_DECL_PT_UID (t, DECL_PT_UID (node));
   1358 	}
   1359       if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
   1360 	  && DECL_HAS_VALUE_EXPR_P (node))
   1361 	{
   1362 	  SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
   1363 	  DECL_HAS_VALUE_EXPR_P (t) = 1;
   1364 	}
   1365       /* DECL_DEBUG_EXPR is copied explicitly by callers.  */
   1366       if (VAR_P (node))
   1367 	{
   1368 	  DECL_HAS_DEBUG_EXPR_P (t) = 0;
   1369 	  t->decl_with_vis.symtab_node = NULL;
   1370 	}
   1371       if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
   1372 	{
   1373 	  SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
   1374 	  DECL_HAS_INIT_PRIORITY_P (t) = 1;
   1375 	}
   1376       if (TREE_CODE (node) == FUNCTION_DECL)
   1377 	{
   1378 	  DECL_STRUCT_FUNCTION (t) = NULL;
   1379 	  t->decl_with_vis.symtab_node = NULL;
   1380 	}
   1381     }
   1382   else if (TREE_CODE_CLASS (code) == tcc_type)
   1383     {
   1384       TYPE_UID (t) = next_type_uid++;
   1385       /* The following is so that the debug code for
   1386 	 the copy is different from the original type.
   1387 	 The two statements usually duplicate each other
   1388 	 (because they clear fields of the same union),
   1389 	 but the optimizer should catch that.  */
   1390       TYPE_SYMTAB_ADDRESS (t) = 0;
   1391       TYPE_SYMTAB_DIE (t) = 0;
   1392 
   1393       /* Do not copy the values cache.  */
   1394       if (TYPE_CACHED_VALUES_P (t))
   1395 	{
   1396 	  TYPE_CACHED_VALUES_P (t) = 0;
   1397 	  TYPE_CACHED_VALUES (t) = NULL_TREE;
   1398 	}
   1399     }
   1400     else if (code == TARGET_OPTION_NODE)
   1401       {
   1402 	TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
   1403 	memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
   1404 		sizeof (struct cl_target_option));
   1405       }
   1406     else if (code == OPTIMIZATION_NODE)
   1407       {
   1408 	TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
   1409 	memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
   1410 		sizeof (struct cl_optimization));
   1411       }
   1412 
   1413   return t;
   1414 }
   1415 
   1416 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
   1417    For example, this can copy a list made of TREE_LIST nodes.  */
   1418 
   1419 tree
   1420 copy_list (tree list)
   1421 {
   1422   tree head;
   1423   tree prev, next;
   1424 
   1425   if (list == 0)
   1426     return 0;
   1427 
   1428   head = prev = copy_node (list);
   1429   next = TREE_CHAIN (list);
   1430   while (next)
   1431     {
   1432       TREE_CHAIN (prev) = copy_node (next);
   1433       prev = TREE_CHAIN (prev);
   1434       next = TREE_CHAIN (next);
   1435     }
   1436   return head;
   1437 }
   1438 
   1439 
   1440 /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
   1442    INTEGER_CST with value CST and type TYPE.   */
   1443 
   1444 static unsigned int
   1445 get_int_cst_ext_nunits (tree type, const wide_int &cst)
   1446 {
   1447   gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
   1448   /* We need extra HWIs if CST is an unsigned integer with its
   1449      upper bit set.  */
   1450   if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
   1451     return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
   1452   return cst.get_len ();
   1453 }
   1454 
   1455 /* Return a new INTEGER_CST with value CST and type TYPE.  */
   1456 
   1457 static tree
   1458 build_new_int_cst (tree type, const wide_int &cst)
   1459 {
   1460   unsigned int len = cst.get_len ();
   1461   unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
   1462   tree nt = make_int_cst (len, ext_len);
   1463 
   1464   if (len < ext_len)
   1465     {
   1466       --ext_len;
   1467       TREE_INT_CST_ELT (nt, ext_len)
   1468 	= zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
   1469       for (unsigned int i = len; i < ext_len; ++i)
   1470 	TREE_INT_CST_ELT (nt, i) = -1;
   1471     }
   1472   else if (TYPE_UNSIGNED (type)
   1473 	   && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
   1474     {
   1475       len--;
   1476       TREE_INT_CST_ELT (nt, len)
   1477 	= zext_hwi (cst.elt (len),
   1478 		    cst.get_precision () % HOST_BITS_PER_WIDE_INT);
   1479     }
   1480 
   1481   for (unsigned int i = 0; i < len; i++)
   1482     TREE_INT_CST_ELT (nt, i) = cst.elt (i);
   1483   TREE_TYPE (nt) = type;
   1484   return nt;
   1485 }
   1486 
   1487 /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE.  */
   1488 
   1489 static tree
   1490 build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
   1491 			CXX_MEM_STAT_INFO)
   1492 {
   1493   size_t length = sizeof (struct tree_poly_int_cst);
   1494   record_node_allocation_statistics (POLY_INT_CST, length);
   1495 
   1496   tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
   1497 
   1498   TREE_SET_CODE (t, POLY_INT_CST);
   1499   TREE_CONSTANT (t) = 1;
   1500   TREE_TYPE (t) = type;
   1501   for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   1502     POLY_INT_CST_COEFF (t, i) = coeffs[i];
   1503   return t;
   1504 }
   1505 
   1506 /* Create a constant tree that contains CST sign-extended to TYPE.  */
   1507 
   1508 tree
   1509 build_int_cst (tree type, poly_int64 cst)
   1510 {
   1511   /* Support legacy code.  */
   1512   if (!type)
   1513     type = integer_type_node;
   1514 
   1515   return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
   1516 }
   1517 
   1518 /* Create a constant tree that contains CST zero-extended to TYPE.  */
   1519 
   1520 tree
   1521 build_int_cstu (tree type, poly_uint64 cst)
   1522 {
   1523   return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
   1524 }
   1525 
   1526 /* Create a constant tree that contains CST sign-extended to TYPE.  */
   1527 
   1528 tree
   1529 build_int_cst_type (tree type, poly_int64 cst)
   1530 {
   1531   gcc_assert (type);
   1532   return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
   1533 }
   1534 
   1535 /* Constructs tree in type TYPE from with value given by CST.  Signedness
   1536    of CST is assumed to be the same as the signedness of TYPE.  */
   1537 
   1538 tree
   1539 double_int_to_tree (tree type, double_int cst)
   1540 {
   1541   return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
   1542 }
   1543 
   1544 /* We force the wide_int CST to the range of the type TYPE by sign or
   1545    zero extending it.  OVERFLOWABLE indicates if we are interested in
   1546    overflow of the value, when >0 we are only interested in signed
   1547    overflow, for <0 we are interested in any overflow.  OVERFLOWED
   1548    indicates whether overflow has already occurred.  CONST_OVERFLOWED
   1549    indicates whether constant overflow has already occurred.  We force
   1550    T's value to be within range of T's type (by setting to 0 or 1 all
   1551    the bits outside the type's range).  We set TREE_OVERFLOWED if,
   1552         OVERFLOWED is nonzero,
   1553         or OVERFLOWABLE is >0 and signed overflow occurs
   1554         or OVERFLOWABLE is <0 and any overflow occurs
   1555    We return a new tree node for the extended wide_int.  The node
   1556    is shared if no overflow flags are set.  */
   1557 
   1558 
   1559 tree
   1560 force_fit_type (tree type, const poly_wide_int_ref &cst,
   1561 		int overflowable, bool overflowed)
   1562 {
   1563   signop sign = TYPE_SIGN (type);
   1564 
   1565   /* If we need to set overflow flags, return a new unshared node.  */
   1566   if (overflowed || !wi::fits_to_tree_p (cst, type))
   1567     {
   1568       if (overflowed
   1569 	  || overflowable < 0
   1570 	  || (overflowable > 0 && sign == SIGNED))
   1571 	{
   1572 	  poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
   1573 						   sign);
   1574 	  tree t;
   1575 	  if (tmp.is_constant ())
   1576 	    t = build_new_int_cst (type, tmp.coeffs[0]);
   1577 	  else
   1578 	    {
   1579 	      tree coeffs[NUM_POLY_INT_COEFFS];
   1580 	      for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   1581 		{
   1582 		  coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
   1583 		  TREE_OVERFLOW (coeffs[i]) = 1;
   1584 		}
   1585 	      t = build_new_poly_int_cst (type, coeffs);
   1586 	    }
   1587 	  TREE_OVERFLOW (t) = 1;
   1588 	  return t;
   1589 	}
   1590     }
   1591 
   1592   /* Else build a shared node.  */
   1593   return wide_int_to_tree (type, cst);
   1594 }
   1595 
   1596 /* These are the hash table functions for the hash table of INTEGER_CST
   1597    nodes of a sizetype.  */
   1598 
   1599 /* Return the hash code X, an INTEGER_CST.  */
   1600 
   1601 hashval_t
   1602 int_cst_hasher::hash (tree x)
   1603 {
   1604   const_tree const t = x;
   1605   hashval_t code = TYPE_UID (TREE_TYPE (t));
   1606   int i;
   1607 
   1608   for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
   1609     code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
   1610 
   1611   return code;
   1612 }
   1613 
   1614 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
   1615    is the same as that given by *Y, which is the same.  */
   1616 
   1617 bool
   1618 int_cst_hasher::equal (tree x, tree y)
   1619 {
   1620   const_tree const xt = x;
   1621   const_tree const yt = y;
   1622 
   1623   if (TREE_TYPE (xt) != TREE_TYPE (yt)
   1624       || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
   1625       || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
   1626     return false;
   1627 
   1628   for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
   1629     if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
   1630       return false;
   1631 
   1632   return true;
   1633 }
   1634 
   1635 /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
   1636    SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
   1637    number of slots that can be cached for the type.  */
   1638 
   1639 static inline tree
   1640 cache_wide_int_in_type_cache (tree type, const wide_int &cst,
   1641 			      int slot, int max_slots)
   1642 {
   1643   gcc_checking_assert (slot >= 0);
   1644   /* Initialize cache.  */
   1645   if (!TYPE_CACHED_VALUES_P (type))
   1646     {
   1647       TYPE_CACHED_VALUES_P (type) = 1;
   1648       TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
   1649     }
   1650   tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
   1651   if (!t)
   1652     {
   1653       /* Create a new shared int.  */
   1654       t = build_new_int_cst (type, cst);
   1655       TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
   1656     }
   1657   return t;
   1658 }
   1659 
   1660 /* Create an INT_CST node of TYPE and value CST.
   1661    The returned node is always shared.  For small integers we use a
   1662    per-type vector cache, for larger ones we use a single hash table.
   1663    The value is extended from its precision according to the sign of
   1664    the type to be a multiple of HOST_BITS_PER_WIDE_INT.  This defines
   1665    the upper bits and ensures that hashing and value equality based
   1666    upon the underlying HOST_WIDE_INTs works without masking.  */
   1667 
   1668 static tree
   1669 wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
   1670 {
   1671   tree t;
   1672   int ix = -1;
   1673   int limit = 0;
   1674 
   1675   gcc_assert (type);
   1676   unsigned int prec = TYPE_PRECISION (type);
   1677   signop sgn = TYPE_SIGN (type);
   1678 
   1679   /* Verify that everything is canonical.  */
   1680   int l = pcst.get_len ();
   1681   if (l > 1)
   1682     {
   1683       if (pcst.elt (l - 1) == 0)
   1684 	gcc_checking_assert (pcst.elt (l - 2) < 0);
   1685       if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
   1686 	gcc_checking_assert (pcst.elt (l - 2) >= 0);
   1687     }
   1688 
   1689   wide_int cst = wide_int::from (pcst, prec, sgn);
   1690   unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
   1691 
   1692   enum tree_code code = TREE_CODE (type);
   1693   if (code == POINTER_TYPE || code == REFERENCE_TYPE)
   1694     {
   1695       /* Cache NULL pointer and zero bounds.  */
   1696       if (cst == 0)
   1697 	ix = 0;
   1698       /* Cache upper bounds of pointers.  */
   1699       else if (cst == wi::max_value (prec, sgn))
   1700 	ix = 1;
   1701       /* Cache 1 which is used for a non-zero range.  */
   1702       else if (cst == 1)
   1703 	ix = 2;
   1704 
   1705       if (ix >= 0)
   1706 	{
   1707 	  t = cache_wide_int_in_type_cache (type, cst, ix, 3);
   1708 	  /* Make sure no one is clobbering the shared constant.  */
   1709 	  gcc_checking_assert (TREE_TYPE (t) == type
   1710 			       && cst == wi::to_wide (t));
   1711 	  return t;
   1712 	}
   1713     }
   1714   if (ext_len == 1)
   1715     {
   1716       /* We just need to store a single HOST_WIDE_INT.  */
   1717       HOST_WIDE_INT hwi;
   1718       if (TYPE_UNSIGNED (type))
   1719 	hwi = cst.to_uhwi ();
   1720       else
   1721 	hwi = cst.to_shwi ();
   1722 
   1723       switch (code)
   1724 	{
   1725 	case NULLPTR_TYPE:
   1726 	  gcc_assert (hwi == 0);
   1727 	  /* Fallthru.  */
   1728 
   1729 	case POINTER_TYPE:
   1730 	case REFERENCE_TYPE:
   1731 	  /* Ignore pointers, as they were already handled above.  */
   1732 	  break;
   1733 
   1734 	case BOOLEAN_TYPE:
   1735 	  /* Cache false or true.  */
   1736 	  limit = 2;
   1737 	  if (IN_RANGE (hwi, 0, 1))
   1738 	    ix = hwi;
   1739 	  break;
   1740 
   1741 	case INTEGER_TYPE:
   1742 	case OFFSET_TYPE:
   1743 	case BITINT_TYPE:
   1744 	  if (TYPE_SIGN (type) == UNSIGNED)
   1745 	    {
   1746 	      /* Cache [0, N).  */
   1747 	      limit = param_integer_share_limit;
   1748 	      if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
   1749 		ix = hwi;
   1750 	    }
   1751 	  else
   1752 	    {
   1753 	      /* Cache [-1, N).  */
   1754 	      limit = param_integer_share_limit + 1;
   1755 	      if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
   1756 		ix = hwi + 1;
   1757 	    }
   1758 	  break;
   1759 
   1760 	case ENUMERAL_TYPE:
   1761 	  break;
   1762 
   1763 	default:
   1764 	  gcc_unreachable ();
   1765 	}
   1766 
   1767       if (ix >= 0)
   1768 	{
   1769 	  t = cache_wide_int_in_type_cache (type, cst, ix, limit);
   1770 	  /* Make sure no one is clobbering the shared constant.  */
   1771 	  gcc_checking_assert (TREE_TYPE (t) == type
   1772 			       && TREE_INT_CST_NUNITS (t) == 1
   1773 			       && TREE_INT_CST_EXT_NUNITS (t) == 1
   1774 			       && TREE_INT_CST_ELT (t, 0) == hwi);
   1775 	  return t;
   1776 	}
   1777       else
   1778 	{
   1779 	  /* Use the cache of larger shared ints, using int_cst_node as
   1780 	     a temporary.  */
   1781 
   1782 	  TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
   1783 	  TREE_TYPE (int_cst_node) = type;
   1784 
   1785 	  tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
   1786 	  t = *slot;
   1787 	  if (!t)
   1788 	    {
   1789 	      /* Insert this one into the hash table.  */
   1790 	      t = int_cst_node;
   1791 	      *slot = t;
   1792 	      /* Make a new node for next time round.  */
   1793 	      int_cst_node = make_int_cst (1, 1);
   1794 	    }
   1795 	}
   1796     }
   1797   else
   1798     {
   1799       /* The value either hashes properly or we drop it on the floor
   1800 	 for the gc to take care of.  There will not be enough of them
   1801 	 to worry about.  */
   1802 
   1803       tree nt = build_new_int_cst (type, cst);
   1804       tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
   1805       t = *slot;
   1806       if (!t)
   1807 	{
   1808 	  /* Insert this one into the hash table.  */
   1809 	  t = nt;
   1810 	  *slot = t;
   1811 	}
   1812       else
   1813 	ggc_free (nt);
   1814     }
   1815 
   1816   return t;
   1817 }
   1818 
   1819 hashval_t
   1820 poly_int_cst_hasher::hash (tree t)
   1821 {
   1822   inchash::hash hstate;
   1823 
   1824   hstate.add_int (TYPE_UID (TREE_TYPE (t)));
   1825   for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   1826     hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
   1827 
   1828   return hstate.end ();
   1829 }
   1830 
   1831 bool
   1832 poly_int_cst_hasher::equal (tree x, const compare_type &y)
   1833 {
   1834   if (TREE_TYPE (x) != y.first)
   1835     return false;
   1836   for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   1837     if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
   1838       return false;
   1839   return true;
   1840 }
   1841 
   1842 /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
   1843    The elements must also have type TYPE.  */
   1844 
   1845 tree
   1846 build_poly_int_cst (tree type, const poly_wide_int_ref &values)
   1847 {
   1848   unsigned int prec = TYPE_PRECISION (type);
   1849   gcc_assert (prec <= values.coeffs[0].get_precision ());
   1850   poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
   1851 
   1852   inchash::hash h;
   1853   h.add_int (TYPE_UID (type));
   1854   for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   1855     h.add_wide_int (c.coeffs[i]);
   1856   poly_int_cst_hasher::compare_type comp (type, &c);
   1857   tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
   1858 							     INSERT);
   1859   if (*slot == NULL_TREE)
   1860     {
   1861       tree coeffs[NUM_POLY_INT_COEFFS];
   1862       for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   1863 	coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
   1864       *slot = build_new_poly_int_cst (type, coeffs);
   1865     }
   1866   return *slot;
   1867 }
   1868 
   1869 /* Create a constant tree with value VALUE in type TYPE.  */
   1870 
   1871 tree
   1872 wide_int_to_tree (tree type, const poly_wide_int_ref &value)
   1873 {
   1874   if (value.is_constant ())
   1875     return wide_int_to_tree_1 (type, value.coeffs[0]);
   1876   return build_poly_int_cst (type, value);
   1877 }
   1878 
   1879 /* Insert INTEGER_CST T into a cache of integer constants.  And return
   1880    the cached constant (which may or may not be T).  If MIGHT_DUPLICATE
   1881    is false, and T falls into the type's 'smaller values' range, there
   1882    cannot be an existing entry.  Otherwise, if MIGHT_DUPLICATE is true,
   1883    or the value is large, should an existing entry exist, it is
   1884    returned (rather than inserting T).  */
   1885 
   1886 tree
   1887 cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
   1888 {
   1889   tree type = TREE_TYPE (t);
   1890   int ix = -1;
   1891   int limit = 0;
   1892   int prec = TYPE_PRECISION (type);
   1893 
   1894   gcc_assert (!TREE_OVERFLOW (t));
   1895 
   1896   /* The caching indices here must match those in
   1897      wide_int_to_type_1.  */
   1898   switch (TREE_CODE (type))
   1899     {
   1900     case NULLPTR_TYPE:
   1901       gcc_checking_assert (integer_zerop (t));
   1902       /* Fallthru.  */
   1903 
   1904     case POINTER_TYPE:
   1905     case REFERENCE_TYPE:
   1906       {
   1907 	if (integer_zerop (t))
   1908 	  ix = 0;
   1909 	else if (integer_onep (t))
   1910 	  ix = 2;
   1911 
   1912 	if (ix >= 0)
   1913 	  limit = 3;
   1914       }
   1915       break;
   1916 
   1917     case BOOLEAN_TYPE:
   1918       /* Cache false or true.  */
   1919       limit = 2;
   1920       if (wi::ltu_p (wi::to_wide (t), 2))
   1921 	ix = TREE_INT_CST_ELT (t, 0);
   1922       break;
   1923 
   1924     case INTEGER_TYPE:
   1925     case OFFSET_TYPE:
   1926     case BITINT_TYPE:
   1927       if (TYPE_UNSIGNED (type))
   1928 	{
   1929 	  /* Cache 0..N */
   1930 	  limit = param_integer_share_limit;
   1931 
   1932 	  /* This is a little hokie, but if the prec is smaller than
   1933 	     what is necessary to hold param_integer_share_limit, then the
   1934 	     obvious test will not get the correct answer.  */
   1935 	  if (prec < HOST_BITS_PER_WIDE_INT)
   1936 	    {
   1937 	      if (tree_to_uhwi (t)
   1938 		  < (unsigned HOST_WIDE_INT) param_integer_share_limit)
   1939 		ix = tree_to_uhwi (t);
   1940 	    }
   1941 	  else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
   1942 	    ix = tree_to_uhwi (t);
   1943 	}
   1944       else
   1945 	{
   1946 	  /* Cache -1..N */
   1947 	  limit = param_integer_share_limit + 1;
   1948 
   1949 	  if (integer_minus_onep (t))
   1950 	    ix = 0;
   1951 	  else if (!wi::neg_p (wi::to_wide (t)))
   1952 	    {
   1953 	      if (prec < HOST_BITS_PER_WIDE_INT)
   1954 		{
   1955 		  if (tree_to_shwi (t) < param_integer_share_limit)
   1956 		    ix = tree_to_shwi (t) + 1;
   1957 		}
   1958 	      else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
   1959 		ix = tree_to_shwi (t) + 1;
   1960 	    }
   1961 	}
   1962       break;
   1963 
   1964     case ENUMERAL_TYPE:
   1965       /* The slot used by TYPE_CACHED_VALUES is used for the enum
   1966 	 members.  */
   1967       break;
   1968 
   1969     default:
   1970       gcc_unreachable ();
   1971     }
   1972 
   1973   if (ix >= 0)
   1974     {
   1975       /* Look for it in the type's vector of small shared ints.  */
   1976       if (!TYPE_CACHED_VALUES_P (type))
   1977 	{
   1978 	  TYPE_CACHED_VALUES_P (type) = 1;
   1979 	  TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
   1980 	}
   1981 
   1982       if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
   1983 	{
   1984 	  gcc_checking_assert (might_duplicate);
   1985 	  t = r;
   1986 	}
   1987       else
   1988 	TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
   1989     }
   1990   else
   1991     {
   1992       /* Use the cache of larger shared ints.  */
   1993       tree *slot = int_cst_hash_table->find_slot (t, INSERT);
   1994       if (tree r = *slot)
   1995 	{
   1996 	  /* If there is already an entry for the number verify it's the
   1997 	     same value.  */
   1998 	  gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
   1999 	  /* And return the cached value.  */
   2000 	  t = r;
   2001 	}
   2002       else
   2003 	/* Otherwise insert this one into the hash table.  */
   2004 	*slot = t;
   2005     }
   2006 
   2007   return t;
   2008 }
   2009 
   2010 
   2011 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
   2012    and the rest are zeros.  */
   2013 
   2014 tree
   2015 build_low_bits_mask (tree type, unsigned bits)
   2016 {
   2017   gcc_assert (bits <= TYPE_PRECISION (type));
   2018 
   2019   return wide_int_to_tree (type, wi::mask (bits, false,
   2020 					   TYPE_PRECISION (type)));
   2021 }
   2022 
   2023 /* Checks that X is integer constant that can be expressed in (unsigned)
   2024    HOST_WIDE_INT without loss of precision.  */
   2025 
   2026 bool
   2027 cst_and_fits_in_hwi (const_tree x)
   2028 {
   2029   return (TREE_CODE (x) == INTEGER_CST
   2030 	  && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
   2031 }
   2032 
   2033 /* Build a newly constructed VECTOR_CST with the given values of
   2034    (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN.  */
   2035 
   2036 tree
   2037 make_vector (unsigned log2_npatterns,
   2038 	     unsigned int nelts_per_pattern MEM_STAT_DECL)
   2039 {
   2040   gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
   2041   tree t;
   2042   unsigned npatterns = 1 << log2_npatterns;
   2043   unsigned encoded_nelts = npatterns * nelts_per_pattern;
   2044   unsigned length = (sizeof (struct tree_vector)
   2045 		     + (encoded_nelts - 1) * sizeof (tree));
   2046 
   2047   record_node_allocation_statistics (VECTOR_CST, length);
   2048 
   2049   t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
   2050 
   2051   TREE_SET_CODE (t, VECTOR_CST);
   2052   TREE_CONSTANT (t) = 1;
   2053   VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
   2054   VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
   2055 
   2056   return t;
   2057 }
   2058 
   2059 /* Return a new VECTOR_CST node whose type is TYPE and whose values
   2060    are extracted from V, a vector of CONSTRUCTOR_ELT.  */
   2061 
   2062 tree
   2063 build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
   2064 {
   2065   if (vec_safe_length (v) == 0)
   2066     return build_zero_cst (type);
   2067 
   2068   unsigned HOST_WIDE_INT idx, nelts;
   2069   tree value;
   2070 
   2071   /* We can't construct a VECTOR_CST for a variable number of elements.  */
   2072   nelts = TYPE_VECTOR_SUBPARTS (type).to_constant ();
   2073   tree_vector_builder vec (type, nelts, 1);
   2074   FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
   2075     {
   2076       if (TREE_CODE (value) == VECTOR_CST)
   2077 	{
   2078 	  /* If NELTS is constant then this must be too.  */
   2079 	  unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
   2080 	  for (unsigned i = 0; i < sub_nelts; ++i)
   2081 	    vec.quick_push (VECTOR_CST_ELT (value, i));
   2082 	}
   2083       else
   2084 	vec.quick_push (value);
   2085     }
   2086   while (vec.length () < nelts)
   2087     vec.quick_push (build_zero_cst (TREE_TYPE (type)));
   2088 
   2089   return vec.build ();
   2090 }
   2091 
   2092 /* Build a vector of type VECTYPE where all the elements are SCs.  */
   2093 tree
   2094 build_vector_from_val (tree vectype, tree sc)
   2095 {
   2096   unsigned HOST_WIDE_INT i, nunits;
   2097 
   2098   if (sc == error_mark_node)
   2099     return sc;
   2100 
   2101   /* Verify that the vector type is suitable for SC.  Note that there
   2102      is some inconsistency in the type-system with respect to restrict
   2103      qualifications of pointers.  Vector types always have a main-variant
   2104      element type and the qualification is applied to the vector-type.
   2105      So TREE_TYPE (vector-type) does not return a properly qualified
   2106      vector element-type.  */
   2107   gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
   2108 					   TREE_TYPE (vectype)));
   2109 
   2110   if (CONSTANT_CLASS_P (sc))
   2111     {
   2112       tree_vector_builder v (vectype, 1, 1);
   2113       v.quick_push (sc);
   2114       return v.build ();
   2115     }
   2116   else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
   2117     return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
   2118   else
   2119     {
   2120       vec<constructor_elt, va_gc> *v;
   2121       vec_alloc (v, nunits);
   2122       for (i = 0; i < nunits; ++i)
   2123 	CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
   2124       return build_constructor (vectype, v);
   2125     }
   2126 }
   2127 
   2128 /* If TYPE is not a vector type, just return SC, otherwise return
   2129    build_vector_from_val (TYPE, SC).  */
   2130 
   2131 tree
   2132 build_uniform_cst (tree type, tree sc)
   2133 {
   2134   if (!VECTOR_TYPE_P (type))
   2135     return sc;
   2136 
   2137   return build_vector_from_val (type, sc);
   2138 }
   2139 
   2140 /* Build a vector series of type TYPE in which element I has the value
   2141    BASE + I * STEP.  The result is a constant if BASE and STEP are constant
   2142    and a VEC_SERIES_EXPR otherwise.  */
   2143 
   2144 tree
   2145 build_vec_series (tree type, tree base, tree step)
   2146 {
   2147   if (integer_zerop (step))
   2148     return build_vector_from_val (type, base);
   2149   if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
   2150     {
   2151       tree_vector_builder builder (type, 1, 3);
   2152       tree elt1 = wide_int_to_tree (TREE_TYPE (base),
   2153 				    wi::to_wide (base) + wi::to_wide (step));
   2154       tree elt2 = wide_int_to_tree (TREE_TYPE (base),
   2155 				    wi::to_wide (elt1) + wi::to_wide (step));
   2156       builder.quick_push (base);
   2157       builder.quick_push (elt1);
   2158       builder.quick_push (elt2);
   2159       return builder.build ();
   2160     }
   2161   return build2 (VEC_SERIES_EXPR, type, base, step);
   2162 }
   2163 
   2164 /* Return a vector with the same number of units and number of bits
   2165    as VEC_TYPE, but in which the elements are a linear series of unsigned
   2166    integers { BASE, BASE + STEP, BASE + STEP * 2, ... }.  */
   2167 
   2168 tree
   2169 build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
   2170 {
   2171   tree index_vec_type = vec_type;
   2172   tree index_elt_type = TREE_TYPE (vec_type);
   2173   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
   2174   if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
   2175     {
   2176       index_elt_type = build_nonstandard_integer_type
   2177 	(GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
   2178       index_vec_type = build_vector_type (index_elt_type, nunits);
   2179     }
   2180 
   2181   tree_vector_builder v (index_vec_type, 1, 3);
   2182   for (unsigned int i = 0; i < 3; ++i)
   2183     v.quick_push (build_int_cstu (index_elt_type, base + i * step));
   2184   return v.build ();
   2185 }
   2186 
   2187 /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
   2188    elements are A and the rest are B.  */
   2189 
   2190 tree
   2191 build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
   2192 {
   2193   gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
   2194   unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
   2195   /* Optimize the constant case.  */
   2196   if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
   2197     count /= 2;
   2198   tree_vector_builder builder (vec_type, count, 2);
   2199   for (unsigned int i = 0; i < count * 2; ++i)
   2200     builder.quick_push (i < num_a ? a : b);
   2201   return builder.build ();
   2202 }
   2203 
   2204 /* Something has messed with the elements of CONSTRUCTOR C after it was built;
   2205    calculate TREE_CONSTANT and TREE_SIDE_EFFECTS.  */
   2206 
   2207 void
   2208 recompute_constructor_flags (tree c)
   2209 {
   2210   unsigned int i;
   2211   tree val;
   2212   bool constant_p = true;
   2213   bool side_effects_p = false;
   2214   vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
   2215 
   2216   FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
   2217     {
   2218       /* Mostly ctors will have elts that don't have side-effects, so
   2219 	 the usual case is to scan all the elements.  Hence a single
   2220 	 loop for both const and side effects, rather than one loop
   2221 	 each (with early outs).  */
   2222       if (!TREE_CONSTANT (val))
   2223 	constant_p = false;
   2224       if (TREE_SIDE_EFFECTS (val))
   2225 	side_effects_p = true;
   2226     }
   2227 
   2228   TREE_SIDE_EFFECTS (c) = side_effects_p;
   2229   TREE_CONSTANT (c) = constant_p;
   2230 }
   2231 
   2232 /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
   2233    CONSTRUCTOR C.  */
   2234 
   2235 void
   2236 verify_constructor_flags (tree c)
   2237 {
   2238   unsigned int i;
   2239   tree val;
   2240   bool constant_p = TREE_CONSTANT (c);
   2241   bool side_effects_p = TREE_SIDE_EFFECTS (c);
   2242   vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
   2243 
   2244   FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
   2245     {
   2246       if (constant_p && !TREE_CONSTANT (val))
   2247 	internal_error ("non-constant element in constant CONSTRUCTOR");
   2248       if (!side_effects_p && TREE_SIDE_EFFECTS (val))
   2249 	internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
   2250     }
   2251 }
   2252 
   2253 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
   2254    are in the vec pointed to by VALS.  */
   2255 tree
   2256 build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
   2257 {
   2258   tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
   2259 
   2260   TREE_TYPE (c) = type;
   2261   CONSTRUCTOR_ELTS (c) = vals;
   2262 
   2263   recompute_constructor_flags (c);
   2264 
   2265   return c;
   2266 }
   2267 
   2268 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
   2269    INDEX and VALUE.  */
   2270 tree
   2271 build_constructor_single (tree type, tree index, tree value)
   2272 {
   2273   vec<constructor_elt, va_gc> *v;
   2274   constructor_elt elt = {index, value};
   2275 
   2276   vec_alloc (v, 1);
   2277   v->quick_push (elt);
   2278 
   2279   return build_constructor (type, v);
   2280 }
   2281 
   2282 
   2283 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
   2284    are in a list pointed to by VALS.  */
   2285 tree
   2286 build_constructor_from_list (tree type, tree vals)
   2287 {
   2288   tree t;
   2289   vec<constructor_elt, va_gc> *v = NULL;
   2290 
   2291   if (vals)
   2292     {
   2293       vec_alloc (v, list_length (vals));
   2294       for (t = vals; t; t = TREE_CHAIN (t))
   2295 	CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
   2296     }
   2297 
   2298   return build_constructor (type, v);
   2299 }
   2300 
   2301 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
   2302    are in a vector pointed to by VALS.  Note that the TREE_PURPOSE
   2303    fields in the constructor remain null.  */
   2304 
   2305 tree
   2306 build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
   2307 {
   2308   vec<constructor_elt, va_gc> *v = NULL;
   2309 
   2310   for (tree t : vals)
   2311     CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
   2312 
   2313   return build_constructor (type, v);
   2314 }
   2315 
   2316 /* Return a new CONSTRUCTOR node whose type is TYPE.  NELTS is the number
   2317    of elements, provided as index/value pairs.  */
   2318 
   2319 tree
   2320 build_constructor_va (tree type, int nelts, ...)
   2321 {
   2322   vec<constructor_elt, va_gc> *v = NULL;
   2323   va_list p;
   2324 
   2325   va_start (p, nelts);
   2326   vec_alloc (v, nelts);
   2327   while (nelts--)
   2328     {
   2329       tree index = va_arg (p, tree);
   2330       tree value = va_arg (p, tree);
   2331       CONSTRUCTOR_APPEND_ELT (v, index, value);
   2332     }
   2333   va_end (p);
   2334   return build_constructor (type, v);
   2335 }
   2336 
   2337 /* Return a node of type TYPE for which TREE_CLOBBER_P is true.  */
   2338 
   2339 tree
   2340 build_clobber (tree type, enum clobber_kind kind)
   2341 {
   2342   tree clobber = build_constructor (type, NULL);
   2343   TREE_THIS_VOLATILE (clobber) = true;
   2344   CLOBBER_KIND (clobber) = kind;
   2345   return clobber;
   2346 }
   2347 
   2348 /* Return a new FIXED_CST node whose type is TYPE and value is F.  */
   2349 
   2350 tree
   2351 build_fixed (tree type, FIXED_VALUE_TYPE f)
   2352 {
   2353   tree v;
   2354   FIXED_VALUE_TYPE *fp;
   2355 
   2356   v = make_node (FIXED_CST);
   2357   fp = ggc_alloc<fixed_value> ();
   2358   memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
   2359 
   2360   TREE_TYPE (v) = type;
   2361   TREE_FIXED_CST_PTR (v) = fp;
   2362   return v;
   2363 }
   2364 
   2365 /* Return a new REAL_CST node whose type is TYPE and value is D.  */
   2366 
   2367 tree
   2368 build_real (tree type, REAL_VALUE_TYPE d)
   2369 {
   2370   tree v;
   2371   int overflow = 0;
   2372 
   2373   /* dconst{0,1,2,m1,half} are used in various places in
   2374      the middle-end and optimizers, allow them here
   2375      even for decimal floating point types as an exception
   2376      by converting them to decimal.  */
   2377   if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
   2378       && (d.cl == rvc_normal || d.cl == rvc_zero)
   2379       && !d.decimal)
   2380     {
   2381       if (memcmp (&d, &dconst1, sizeof (d)) == 0)
   2382 	decimal_real_from_string (&d, "1");
   2383       else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
   2384 	decimal_real_from_string (&d, "2");
   2385       else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
   2386 	decimal_real_from_string (&d, "-1");
   2387       else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
   2388 	decimal_real_from_string (&d, "0.5");
   2389       else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
   2390 	{
   2391 	  /* Make sure to give zero the minimum quantum exponent for
   2392 	     the type (which corresponds to all bits zero).  */
   2393 	  const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
   2394 	  char buf[16];
   2395 	  sprintf (buf, "0e%d", fmt->emin - fmt->p);
   2396 	  decimal_real_from_string (&d, buf);
   2397 	}
   2398       else
   2399 	gcc_unreachable ();
   2400     }
   2401 
   2402   /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
   2403      Consider doing it via real_convert now.  */
   2404 
   2405   v = make_node (REAL_CST);
   2406   TREE_TYPE (v) = type;
   2407   memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
   2408   TREE_OVERFLOW (v) = overflow;
   2409   return v;
   2410 }
   2411 
   2412 /* Like build_real, but first truncate D to the type.  */
   2413 
   2414 tree
   2415 build_real_truncate (tree type, REAL_VALUE_TYPE d)
   2416 {
   2417   return build_real (type, real_value_truncate (TYPE_MODE (type), d));
   2418 }
   2419 
   2420 /* Return a new REAL_CST node whose type is TYPE
   2421    and whose value is the integer value of the INTEGER_CST node I.  */
   2422 
   2423 REAL_VALUE_TYPE
   2424 real_value_from_int_cst (const_tree type, const_tree i)
   2425 {
   2426   REAL_VALUE_TYPE d;
   2427 
   2428   /* Clear all bits of the real value type so that we can later do
   2429      bitwise comparisons to see if two values are the same.  */
   2430   memset (&d, 0, sizeof d);
   2431 
   2432   real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
   2433 		     TYPE_SIGN (TREE_TYPE (i)));
   2434   return d;
   2435 }
   2436 
   2437 /* Given a tree representing an integer constant I, return a tree
   2438    representing the same value as a floating-point constant of type TYPE.  */
   2439 
   2440 tree
   2441 build_real_from_int_cst (tree type, const_tree i)
   2442 {
   2443   tree v;
   2444   int overflow = TREE_OVERFLOW (i);
   2445 
   2446   v = build_real (type, real_value_from_int_cst (type, i));
   2447 
   2448   TREE_OVERFLOW (v) |= overflow;
   2449   return v;
   2450 }
   2451 
   2452 /* Return a new REAL_CST node whose type is TYPE
   2453    and whose value is the integer value I which has sign SGN.  */
   2454 
   2455 tree
   2456 build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
   2457 {
   2458   REAL_VALUE_TYPE d;
   2459 
   2460   /* Clear all bits of the real value type so that we can later do
   2461      bitwise comparisons to see if two values are the same.  */
   2462   memset (&d, 0, sizeof d);
   2463 
   2464   real_from_integer (&d, TYPE_MODE (type), i, sgn);
   2465   return build_real (type, d);
   2466 }
   2467 
   2468 /* Return a newly constructed STRING_CST node whose value is the LEN
   2469    characters at STR when STR is nonnull, or all zeros otherwise.
   2470    Note that for a C string literal, LEN should include the trailing NUL.
   2471    The TREE_TYPE is not initialized.  */
   2472 
   2473 tree
   2474 build_string (unsigned len, const char *str /*= NULL */)
   2475 {
   2476   /* Do not waste bytes provided by padding of struct tree_string.  */
   2477   unsigned size = len + offsetof (struct tree_string, str) + 1;
   2478 
   2479   record_node_allocation_statistics (STRING_CST, size);
   2480 
   2481   tree s = (tree) ggc_internal_alloc (size);
   2482 
   2483   memset (s, 0, sizeof (struct tree_typed));
   2484   TREE_SET_CODE (s, STRING_CST);
   2485   TREE_CONSTANT (s) = 1;
   2486   TREE_STRING_LENGTH (s) = len;
   2487   if (str)
   2488     memcpy (s->string.str, str, len);
   2489   else
   2490     memset (s->string.str, 0, len);
   2491   s->string.str[len] = '\0';
   2492 
   2493   return s;
   2494 }
   2495 
   2496 /* Return a newly constructed COMPLEX_CST node whose value is
   2497    specified by the real and imaginary parts REAL and IMAG.
   2498    Both REAL and IMAG should be constant nodes.  TYPE, if specified,
   2499    will be the type of the COMPLEX_CST; otherwise a new type will be made.  */
   2500 
   2501 tree
   2502 build_complex (tree type, tree real, tree imag)
   2503 {
   2504   gcc_assert (CONSTANT_CLASS_P (real));
   2505   gcc_assert (CONSTANT_CLASS_P (imag));
   2506 
   2507   tree t = make_node (COMPLEX_CST);
   2508 
   2509   TREE_REALPART (t) = real;
   2510   TREE_IMAGPART (t) = imag;
   2511   TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
   2512   TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
   2513   return t;
   2514 }
   2515 
   2516 /* Build a complex (inf +- 0i), such as for the result of cproj.
   2517    TYPE is the complex tree type of the result.  If NEG is true, the
   2518    imaginary zero is negative.  */
   2519 
   2520 tree
   2521 build_complex_inf (tree type, bool neg)
   2522 {
   2523   REAL_VALUE_TYPE rzero = dconst0;
   2524 
   2525   rzero.sign = neg;
   2526   return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
   2527 			build_real (TREE_TYPE (type), rzero));
   2528 }
   2529 
   2530 /* Return the constant 1 in type TYPE.  If TYPE has several elements, each
   2531    element is set to 1.  In particular, this is 1 + i for complex types.  */
   2532 
   2533 tree
   2534 build_each_one_cst (tree type)
   2535 {
   2536   if (TREE_CODE (type) == COMPLEX_TYPE)
   2537     {
   2538       tree scalar = build_one_cst (TREE_TYPE (type));
   2539       return build_complex (type, scalar, scalar);
   2540     }
   2541   else
   2542     return build_one_cst (type);
   2543 }
   2544 
   2545 /* Return a constant of arithmetic type TYPE which is the
   2546    multiplicative identity of the set TYPE.  */
   2547 
   2548 tree
   2549 build_one_cst (tree type)
   2550 {
   2551   switch (TREE_CODE (type))
   2552     {
   2553     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
   2554     case POINTER_TYPE: case REFERENCE_TYPE:
   2555     case OFFSET_TYPE: case BITINT_TYPE:
   2556       return build_int_cst (type, 1);
   2557 
   2558     case REAL_TYPE:
   2559       return build_real (type, dconst1);
   2560 
   2561     case FIXED_POINT_TYPE:
   2562       /* We can only generate 1 for accum types.  */
   2563       gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
   2564       return build_fixed (type, FCONST1 (TYPE_MODE (type)));
   2565 
   2566     case VECTOR_TYPE:
   2567       {
   2568 	tree scalar = build_one_cst (TREE_TYPE (type));
   2569 
   2570 	return build_vector_from_val (type, scalar);
   2571       }
   2572 
   2573     case COMPLEX_TYPE:
   2574       return build_complex (type,
   2575 			    build_one_cst (TREE_TYPE (type)),
   2576 			    build_zero_cst (TREE_TYPE (type)));
   2577 
   2578     default:
   2579       gcc_unreachable ();
   2580     }
   2581 }
   2582 
   2583 /* Return an integer of type TYPE containing all 1's in as much precision as
   2584    it contains, or a complex or vector whose subparts are such integers.  */
   2585 
   2586 tree
   2587 build_all_ones_cst (tree type)
   2588 {
   2589   if (TREE_CODE (type) == COMPLEX_TYPE)
   2590     {
   2591       tree scalar = build_all_ones_cst (TREE_TYPE (type));
   2592       return build_complex (type, scalar, scalar);
   2593     }
   2594   else
   2595     return build_minus_one_cst (type);
   2596 }
   2597 
   2598 /* Return a constant of arithmetic type TYPE which is the
   2599    opposite of the multiplicative identity of the set TYPE.  */
   2600 
   2601 tree
   2602 build_minus_one_cst (tree type)
   2603 {
   2604   switch (TREE_CODE (type))
   2605     {
   2606     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
   2607     case POINTER_TYPE: case REFERENCE_TYPE:
   2608     case OFFSET_TYPE: case BITINT_TYPE:
   2609       return build_int_cst (type, -1);
   2610 
   2611     case REAL_TYPE:
   2612       return build_real (type, dconstm1);
   2613 
   2614     case FIXED_POINT_TYPE:
   2615       /* We can only generate 1 for accum types.  */
   2616       gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
   2617       return build_fixed (type,
   2618 			  fixed_from_double_int (double_int_minus_one,
   2619 						 SCALAR_TYPE_MODE (type)));
   2620 
   2621     case VECTOR_TYPE:
   2622       {
   2623 	tree scalar = build_minus_one_cst (TREE_TYPE (type));
   2624 
   2625 	return build_vector_from_val (type, scalar);
   2626       }
   2627 
   2628     case COMPLEX_TYPE:
   2629       return build_complex (type,
   2630 			    build_minus_one_cst (TREE_TYPE (type)),
   2631 			    build_zero_cst (TREE_TYPE (type)));
   2632 
   2633     default:
   2634       gcc_unreachable ();
   2635     }
   2636 }
   2637 
   2638 /* Build 0 constant of type TYPE.  This is used by constructor folding
   2639    and thus the constant should be represented in memory by
   2640    zero(es).  */
   2641 
   2642 tree
   2643 build_zero_cst (tree type)
   2644 {
   2645   switch (TREE_CODE (type))
   2646     {
   2647     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
   2648     case POINTER_TYPE: case REFERENCE_TYPE:
   2649     case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
   2650       return build_int_cst (type, 0);
   2651 
   2652     case REAL_TYPE:
   2653       return build_real (type, dconst0);
   2654 
   2655     case FIXED_POINT_TYPE:
   2656       return build_fixed (type, FCONST0 (TYPE_MODE (type)));
   2657 
   2658     case VECTOR_TYPE:
   2659       {
   2660 	tree scalar = build_zero_cst (TREE_TYPE (type));
   2661 
   2662 	return build_vector_from_val (type, scalar);
   2663       }
   2664 
   2665     case COMPLEX_TYPE:
   2666       {
   2667 	tree zero = build_zero_cst (TREE_TYPE (type));
   2668 
   2669 	return build_complex (type, zero, zero);
   2670       }
   2671 
   2672     default:
   2673       if (!AGGREGATE_TYPE_P (type))
   2674 	return fold_convert (type, integer_zero_node);
   2675       return build_constructor (type, NULL);
   2676     }
   2677 }
   2678 
   2679 /* Build a constant of integer type TYPE, made of VALUE's bits replicated
   2680    every WIDTH bits to fit TYPE's precision.  */
   2681 
   2682 tree
   2683 build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
   2684 {
   2685   int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
   2686 	   / HOST_BITS_PER_WIDE_INT);
   2687   unsigned HOST_WIDE_INT low, mask;
   2688   HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
   2689   int i;
   2690 
   2691   gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
   2692 
   2693   if (width == HOST_BITS_PER_WIDE_INT)
   2694     low = value;
   2695   else
   2696     {
   2697       mask = (HOST_WIDE_INT_1U << width) - 1;
   2698       low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
   2699     }
   2700 
   2701   for (i = 0; i < n; i++)
   2702     a[i] = low;
   2703 
   2704   gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
   2705   return wide_int_to_tree (type, wide_int::from_array (a, n,
   2706 						       TYPE_PRECISION (type)));
   2707 }
   2708 
   2709 /* If floating-point type TYPE has an IEEE-style sign bit, return an
   2710    unsigned constant in which only the sign bit is set.  Return null
   2711    otherwise.  */
   2712 
   2713 tree
   2714 sign_mask_for (tree type)
   2715 {
   2716   /* Avoid having to choose between a real-only sign and a pair of signs.
   2717      This could be relaxed if the choice becomes obvious later.  */
   2718   if (TREE_CODE (type) == COMPLEX_TYPE)
   2719     return NULL_TREE;
   2720 
   2721   auto eltmode = as_a<scalar_float_mode> (element_mode (type));
   2722   auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
   2723   if (!bits || !pow2p_hwi (bits))
   2724     return NULL_TREE;
   2725 
   2726   tree inttype = unsigned_type_for (type);
   2727   if (!inttype)
   2728     return NULL_TREE;
   2729 
   2730   auto mask = wi::set_bit_in_zero (bits - 1, bits);
   2731   if (VECTOR_TYPE_P (inttype))
   2732     {
   2733       tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
   2734       return build_vector_from_val (inttype, elt);
   2735     }
   2736   return wide_int_to_tree (inttype, mask);
   2737 }
   2738 
   2739 /* Build a BINFO with LEN language slots.  */
   2740 
   2741 tree
   2742 make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
   2743 {
   2744   tree t;
   2745   size_t length = (offsetof (struct tree_binfo, base_binfos)
   2746 		   + vec<tree, va_gc>::embedded_size (base_binfos));
   2747 
   2748   record_node_allocation_statistics (TREE_BINFO, length);
   2749 
   2750   t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
   2751 
   2752   memset (t, 0, offsetof (struct tree_binfo, base_binfos));
   2753 
   2754   TREE_SET_CODE (t, TREE_BINFO);
   2755 
   2756   BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
   2757 
   2758   return t;
   2759 }
   2760 
   2761 /* Create a CASE_LABEL_EXPR tree node and return it.  */
   2762 
   2763 tree
   2764 build_case_label (tree low_value, tree high_value, tree label_decl)
   2765 {
   2766   tree t = make_node (CASE_LABEL_EXPR);
   2767 
   2768   TREE_TYPE (t) = void_type_node;
   2769   SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
   2770 
   2771   CASE_LOW (t) = low_value;
   2772   CASE_HIGH (t) = high_value;
   2773   CASE_LABEL (t) = label_decl;
   2774   CASE_CHAIN (t) = NULL_TREE;
   2775 
   2776   return t;
   2777 }
   2778 
   2779 /* Build a newly constructed INTEGER_CST node.  LEN and EXT_LEN are the
   2780    values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
   2781    The latter determines the length of the HOST_WIDE_INT vector.  */
   2782 
   2783 tree
   2784 make_int_cst (int len, int ext_len MEM_STAT_DECL)
   2785 {
   2786   tree t;
   2787   int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
   2788 		+ sizeof (struct tree_int_cst));
   2789 
   2790   gcc_assert (len);
   2791   record_node_allocation_statistics (INTEGER_CST, length);
   2792 
   2793   t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
   2794 
   2795   TREE_SET_CODE (t, INTEGER_CST);
   2796   TREE_INT_CST_NUNITS (t) = len;
   2797   TREE_INT_CST_EXT_NUNITS (t) = ext_len;
   2798   TREE_CONSTANT (t) = 1;
   2799 
   2800   return t;
   2801 }
   2802 
   2803 /* Build a newly constructed TREE_VEC node of length LEN.  */
   2804 
   2805 tree
   2806 make_tree_vec (int len MEM_STAT_DECL)
   2807 {
   2808   tree t;
   2809   size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
   2810 
   2811   record_node_allocation_statistics (TREE_VEC, length);
   2812 
   2813   t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
   2814 
   2815   TREE_SET_CODE (t, TREE_VEC);
   2816   TREE_VEC_LENGTH (t) = len;
   2817 
   2818   return t;
   2819 }
   2820 
   2821 /* Grow a TREE_VEC node to new length LEN.  */
   2822 
   2823 tree
   2824 grow_tree_vec (tree v, int len MEM_STAT_DECL)
   2825 {
   2826   gcc_assert (TREE_CODE (v) == TREE_VEC);
   2827 
   2828   int oldlen = TREE_VEC_LENGTH (v);
   2829   gcc_assert (len > oldlen);
   2830 
   2831   size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
   2832   size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
   2833 
   2834   record_node_allocation_statistics (TREE_VEC, length - oldlength);
   2835 
   2836   v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
   2837 
   2838   TREE_VEC_LENGTH (v) = len;
   2839 
   2840   return v;
   2841 }
   2842 
   2843 /* Return true if EXPR is the constant zero, whether it is integral, float or
   2845    fixed, and scalar, complex or vector.  */
   2846 
   2847 bool
   2848 zerop (const_tree expr)
   2849 {
   2850   return (integer_zerop (expr)
   2851 	  || real_zerop (expr)
   2852 	  || fixed_zerop (expr));
   2853 }
   2854 
   2855 /* Return true if EXPR is the integer constant zero or a complex constant
   2856    of zero, or a location wrapper for such a constant.  */
   2857 
   2858 bool
   2859 integer_zerop (const_tree expr)
   2860 {
   2861   STRIP_ANY_LOCATION_WRAPPER (expr);
   2862 
   2863   switch (TREE_CODE (expr))
   2864     {
   2865     case INTEGER_CST:
   2866       return wi::to_wide (expr) == 0;
   2867     case COMPLEX_CST:
   2868       return (integer_zerop (TREE_REALPART (expr))
   2869 	      && integer_zerop (TREE_IMAGPART (expr)));
   2870     case VECTOR_CST:
   2871       return (VECTOR_CST_NPATTERNS (expr) == 1
   2872 	      && VECTOR_CST_DUPLICATE_P (expr)
   2873 	      && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
   2874     default:
   2875       return false;
   2876     }
   2877 }
   2878 
   2879 /* Return true if EXPR is the integer constant one or the corresponding
   2880    complex constant, or a location wrapper for such a constant.  */
   2881 
   2882 bool
   2883 integer_onep (const_tree expr)
   2884 {
   2885   STRIP_ANY_LOCATION_WRAPPER (expr);
   2886 
   2887   switch (TREE_CODE (expr))
   2888     {
   2889     case INTEGER_CST:
   2890       return wi::eq_p (wi::to_widest (expr), 1);
   2891     case COMPLEX_CST:
   2892       return (integer_onep (TREE_REALPART (expr))
   2893 	      && integer_zerop (TREE_IMAGPART (expr)));
   2894     case VECTOR_CST:
   2895       return (VECTOR_CST_NPATTERNS (expr) == 1
   2896 	      && VECTOR_CST_DUPLICATE_P (expr)
   2897 	      && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
   2898     default:
   2899       return false;
   2900     }
   2901 }
   2902 
   2903 /* Return true if EXPR is the integer constant one.  For complex and vector,
   2904    return true if every piece is the integer constant one.
   2905    Also return true for location wrappers for such a constant.  */
   2906 
   2907 bool
   2908 integer_each_onep (const_tree expr)
   2909 {
   2910   STRIP_ANY_LOCATION_WRAPPER (expr);
   2911 
   2912   if (TREE_CODE (expr) == COMPLEX_CST)
   2913     return (integer_onep (TREE_REALPART (expr))
   2914 	    && integer_onep (TREE_IMAGPART (expr)));
   2915   else
   2916     return integer_onep (expr);
   2917 }
   2918 
   2919 /* Return true if EXPR is an integer containing all 1's in as much precision
   2920    as it contains, or a complex or vector whose subparts are such integers,
   2921    or a location wrapper for such a constant.  */
   2922 
   2923 bool
   2924 integer_all_onesp (const_tree expr)
   2925 {
   2926   STRIP_ANY_LOCATION_WRAPPER (expr);
   2927 
   2928   if (TREE_CODE (expr) == COMPLEX_CST
   2929       && integer_all_onesp (TREE_REALPART (expr))
   2930       && integer_all_onesp (TREE_IMAGPART (expr)))
   2931     return true;
   2932 
   2933   else if (TREE_CODE (expr) == VECTOR_CST)
   2934     return (VECTOR_CST_NPATTERNS (expr) == 1
   2935 	    && VECTOR_CST_DUPLICATE_P (expr)
   2936 	    && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
   2937 
   2938   else if (TREE_CODE (expr) != INTEGER_CST)
   2939     return false;
   2940 
   2941   return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
   2942 	  == wi::to_wide (expr));
   2943 }
   2944 
   2945 /* Return true if EXPR is the integer constant minus one, or a location
   2946    wrapper for such a constant.  */
   2947 
   2948 bool
   2949 integer_minus_onep (const_tree expr)
   2950 {
   2951   STRIP_ANY_LOCATION_WRAPPER (expr);
   2952 
   2953   if (TREE_CODE (expr) == COMPLEX_CST)
   2954     return (integer_all_onesp (TREE_REALPART (expr))
   2955 	    && integer_zerop (TREE_IMAGPART (expr)));
   2956   else
   2957     return integer_all_onesp (expr);
   2958 }
   2959 
   2960 /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
   2961    only one bit on), or a location wrapper for such a constant.  */
   2962 
   2963 bool
   2964 integer_pow2p (const_tree expr)
   2965 {
   2966   STRIP_ANY_LOCATION_WRAPPER (expr);
   2967 
   2968   if (TREE_CODE (expr) == COMPLEX_CST
   2969       && integer_pow2p (TREE_REALPART (expr))
   2970       && integer_zerop (TREE_IMAGPART (expr)))
   2971     return true;
   2972 
   2973   if (TREE_CODE (expr) != INTEGER_CST)
   2974     return false;
   2975 
   2976   return wi::popcount (wi::to_wide (expr)) == 1;
   2977 }
   2978 
   2979 /* Return true if EXPR is an integer constant other than zero or a
   2980    complex constant other than zero, or a location wrapper for such a
   2981    constant.  */
   2982 
   2983 bool
   2984 integer_nonzerop (const_tree expr)
   2985 {
   2986   STRIP_ANY_LOCATION_WRAPPER (expr);
   2987 
   2988   return ((TREE_CODE (expr) == INTEGER_CST
   2989 	   && wi::to_wide (expr) != 0)
   2990 	  || (TREE_CODE (expr) == COMPLEX_CST
   2991 	      && (integer_nonzerop (TREE_REALPART (expr))
   2992 		  || integer_nonzerop (TREE_IMAGPART (expr)))));
   2993 }
   2994 
   2995 /* Return true if EXPR is the integer constant one.  For vector,
   2996    return true if every piece is the integer constant minus one
   2997    (representing the value TRUE).
   2998    Also return true for location wrappers for such a constant.  */
   2999 
   3000 bool
   3001 integer_truep (const_tree expr)
   3002 {
   3003   STRIP_ANY_LOCATION_WRAPPER (expr);
   3004 
   3005   if (TREE_CODE (expr) == VECTOR_CST)
   3006     return integer_all_onesp (expr);
   3007   return integer_onep (expr);
   3008 }
   3009 
   3010 /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
   3011    for such a constant.  */
   3012 
   3013 bool
   3014 fixed_zerop (const_tree expr)
   3015 {
   3016   STRIP_ANY_LOCATION_WRAPPER (expr);
   3017 
   3018   return (TREE_CODE (expr) == FIXED_CST
   3019 	  && TREE_FIXED_CST (expr).data.is_zero ());
   3020 }
   3021 
   3022 /* Return the power of two represented by a tree node known to be a
   3023    power of two.  */
   3024 
   3025 int
   3026 tree_log2 (const_tree expr)
   3027 {
   3028   if (TREE_CODE (expr) == COMPLEX_CST)
   3029     return tree_log2 (TREE_REALPART (expr));
   3030 
   3031   return wi::exact_log2 (wi::to_wide (expr));
   3032 }
   3033 
   3034 /* Similar, but return the largest integer Y such that 2 ** Y is less
   3035    than or equal to EXPR.  */
   3036 
   3037 int
   3038 tree_floor_log2 (const_tree expr)
   3039 {
   3040   if (TREE_CODE (expr) == COMPLEX_CST)
   3041     return tree_log2 (TREE_REALPART (expr));
   3042 
   3043   return wi::floor_log2 (wi::to_wide (expr));
   3044 }
   3045 
   3046 /* Return number of known trailing zero bits in EXPR, or, if the value of
   3047    EXPR is known to be zero, the precision of it's type.  */
   3048 
   3049 unsigned int
   3050 tree_ctz (const_tree expr)
   3051 {
   3052   if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
   3053       && !POINTER_TYPE_P (TREE_TYPE (expr)))
   3054     return 0;
   3055 
   3056   unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
   3057   switch (TREE_CODE (expr))
   3058     {
   3059     case INTEGER_CST:
   3060       ret1 = wi::ctz (wi::to_wide (expr));
   3061       return MIN (ret1, prec);
   3062     case SSA_NAME:
   3063       ret1 = wi::ctz (get_nonzero_bits (expr));
   3064       return MIN (ret1, prec);
   3065     case PLUS_EXPR:
   3066     case MINUS_EXPR:
   3067     case BIT_IOR_EXPR:
   3068     case BIT_XOR_EXPR:
   3069     case MIN_EXPR:
   3070     case MAX_EXPR:
   3071       ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3072       if (ret1 == 0)
   3073 	return ret1;
   3074       ret2 = tree_ctz (TREE_OPERAND (expr, 1));
   3075       return MIN (ret1, ret2);
   3076     case POINTER_PLUS_EXPR:
   3077       ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3078       ret2 = tree_ctz (TREE_OPERAND (expr, 1));
   3079       /* Second operand is sizetype, which could be in theory
   3080 	 wider than pointer's precision.  Make sure we never
   3081 	 return more than prec.  */
   3082       ret2 = MIN (ret2, prec);
   3083       return MIN (ret1, ret2);
   3084     case BIT_AND_EXPR:
   3085       ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3086       ret2 = tree_ctz (TREE_OPERAND (expr, 1));
   3087       return MAX (ret1, ret2);
   3088     case MULT_EXPR:
   3089       ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3090       ret2 = tree_ctz (TREE_OPERAND (expr, 1));
   3091       return MIN (ret1 + ret2, prec);
   3092     case LSHIFT_EXPR:
   3093       ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3094       if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
   3095 	  && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
   3096 	{
   3097 	  ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
   3098 	  return MIN (ret1 + ret2, prec);
   3099 	}
   3100       return ret1;
   3101     case RSHIFT_EXPR:
   3102       if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
   3103 	  && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
   3104 	{
   3105 	  ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3106 	  ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
   3107 	  if (ret1 > ret2)
   3108 	    return ret1 - ret2;
   3109 	}
   3110       return 0;
   3111     case TRUNC_DIV_EXPR:
   3112     case CEIL_DIV_EXPR:
   3113     case FLOOR_DIV_EXPR:
   3114     case ROUND_DIV_EXPR:
   3115     case EXACT_DIV_EXPR:
   3116       if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
   3117 	  && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
   3118 	{
   3119 	  int l = tree_log2 (TREE_OPERAND (expr, 1));
   3120 	  if (l >= 0)
   3121 	    {
   3122 	      ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3123 	      ret2 = l;
   3124 	      if (ret1 > ret2)
   3125 		return ret1 - ret2;
   3126 	    }
   3127 	}
   3128       return 0;
   3129     CASE_CONVERT:
   3130       ret1 = tree_ctz (TREE_OPERAND (expr, 0));
   3131       if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
   3132 	ret1 = prec;
   3133       return MIN (ret1, prec);
   3134     case SAVE_EXPR:
   3135       return tree_ctz (TREE_OPERAND (expr, 0));
   3136     case COND_EXPR:
   3137       ret1 = tree_ctz (TREE_OPERAND (expr, 1));
   3138       if (ret1 == 0)
   3139 	return 0;
   3140       ret2 = tree_ctz (TREE_OPERAND (expr, 2));
   3141       return MIN (ret1, ret2);
   3142     case COMPOUND_EXPR:
   3143       return tree_ctz (TREE_OPERAND (expr, 1));
   3144     case ADDR_EXPR:
   3145       ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
   3146       if (ret1 > BITS_PER_UNIT)
   3147 	{
   3148 	  ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
   3149 	  return MIN (ret1, prec);
   3150 	}
   3151       return 0;
   3152     default:
   3153       return 0;
   3154     }
   3155 }
   3156 
   3157 /* Return true if EXPR is the real constant zero.  Trailing zeroes matter for
   3158    decimal float constants, so don't return true for them.
   3159    Also return true for location wrappers around such a constant.  */
   3160 
   3161 bool
   3162 real_zerop (const_tree expr)
   3163 {
   3164   STRIP_ANY_LOCATION_WRAPPER (expr);
   3165 
   3166   switch (TREE_CODE (expr))
   3167     {
   3168     case REAL_CST:
   3169       return real_equal (&TREE_REAL_CST (expr), &dconst0)
   3170 	     && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
   3171     case COMPLEX_CST:
   3172       return real_zerop (TREE_REALPART (expr))
   3173 	     && real_zerop (TREE_IMAGPART (expr));
   3174     case VECTOR_CST:
   3175       {
   3176 	/* Don't simply check for a duplicate because the predicate
   3177 	   accepts both +0.0 and -0.0.  */
   3178 	unsigned count = vector_cst_encoded_nelts (expr);
   3179 	for (unsigned int i = 0; i < count; ++i)
   3180 	  if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
   3181 	    return false;
   3182 	return true;
   3183       }
   3184     default:
   3185       return false;
   3186     }
   3187 }
   3188 
   3189 /* Return true if EXPR is the real constant one in real or complex form.
   3190    Trailing zeroes matter for decimal float constants, so don't return
   3191    true for them.
   3192    Also return true for location wrappers around such a constant.  */
   3193 
   3194 bool
   3195 real_onep (const_tree expr)
   3196 {
   3197   STRIP_ANY_LOCATION_WRAPPER (expr);
   3198 
   3199   switch (TREE_CODE (expr))
   3200     {
   3201     case REAL_CST:
   3202       return real_equal (&TREE_REAL_CST (expr), &dconst1)
   3203 	     && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
   3204     case COMPLEX_CST:
   3205       return real_onep (TREE_REALPART (expr))
   3206 	     && real_zerop (TREE_IMAGPART (expr));
   3207     case VECTOR_CST:
   3208       return (VECTOR_CST_NPATTERNS (expr) == 1
   3209 	      && VECTOR_CST_DUPLICATE_P (expr)
   3210 	      && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
   3211     default:
   3212       return false;
   3213     }
   3214 }
   3215 
   3216 /* Return true if EXPR is the real constant minus one.  Trailing zeroes
   3217    matter for decimal float constants, so don't return true for them.
   3218    Also return true for location wrappers around such a constant.  */
   3219 
   3220 bool
   3221 real_minus_onep (const_tree expr)
   3222 {
   3223   STRIP_ANY_LOCATION_WRAPPER (expr);
   3224 
   3225   switch (TREE_CODE (expr))
   3226     {
   3227     case REAL_CST:
   3228       return real_equal (&TREE_REAL_CST (expr), &dconstm1)
   3229 	     && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
   3230     case COMPLEX_CST:
   3231       return real_minus_onep (TREE_REALPART (expr))
   3232 	     && real_zerop (TREE_IMAGPART (expr));
   3233     case VECTOR_CST:
   3234       return (VECTOR_CST_NPATTERNS (expr) == 1
   3235 	      && VECTOR_CST_DUPLICATE_P (expr)
   3236 	      && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
   3237     default:
   3238       return false;
   3239     }
   3240 }
   3241 
   3242 /* Return true if T could be a floating point zero.  */
   3243 
   3244 bool
   3245 real_maybe_zerop (const_tree expr)
   3246 {
   3247   switch (TREE_CODE (expr))
   3248     {
   3249     case REAL_CST:
   3250       /* Can't use real_zerop here, as it always returns false for decimal
   3251 	 floats.  And can't use TREE_REAL_CST (expr).cl == rvc_zero
   3252 	 either, as decimal zeros are rvc_normal.  */
   3253       return real_equal (&TREE_REAL_CST (expr), &dconst0);
   3254     case COMPLEX_CST:
   3255       return (real_maybe_zerop (TREE_REALPART (expr))
   3256 	      || real_maybe_zerop (TREE_IMAGPART (expr)));
   3257     case VECTOR_CST:
   3258       {
   3259 	unsigned count = vector_cst_encoded_nelts (expr);
   3260 	for (unsigned int i = 0; i < count; ++i)
   3261 	  if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
   3262 	    return true;
   3263 	return false;
   3264       }
   3265     default:
   3266       /* Perhaps for SSA_NAMEs we could query frange.  */
   3267       return true;
   3268     }
   3269 }
   3270 
   3271 /* True if EXP is a constant or a cast of a constant.  */
   3272 
   3273 bool
   3274 really_constant_p (const_tree exp)
   3275 {
   3276   /* This is not quite the same as STRIP_NOPS.  It does more.  */
   3277   while (CONVERT_EXPR_P (exp)
   3278 	 || TREE_CODE (exp) == NON_LVALUE_EXPR)
   3279     exp = TREE_OPERAND (exp, 0);
   3280   return TREE_CONSTANT (exp);
   3281 }
   3282 
   3283 /* Return true if T holds a polynomial pointer difference, storing it in
   3284    *VALUE if so.  A true return means that T's precision is no greater
   3285    than 64 bits, which is the largest address space we support, so *VALUE
   3286    never loses precision.  However, the signedness of the result does
   3287    not necessarily match the signedness of T: sometimes an unsigned type
   3288    like sizetype is used to encode a value that is actually negative.  */
   3289 
   3290 bool
   3291 ptrdiff_tree_p (const_tree t, poly_int64 *value)
   3292 {
   3293   if (!t)
   3294     return false;
   3295   if (TREE_CODE (t) == INTEGER_CST)
   3296     {
   3297       if (!cst_and_fits_in_hwi (t))
   3298 	return false;
   3299       *value = int_cst_value (t);
   3300       return true;
   3301     }
   3302   if (POLY_INT_CST_P (t))
   3303     {
   3304       for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   3305 	if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
   3306 	  return false;
   3307       for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   3308 	value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
   3309       return true;
   3310     }
   3311   return false;
   3312 }
   3313 
   3314 poly_int64
   3315 tree_to_poly_int64 (const_tree t)
   3316 {
   3317   gcc_assert (tree_fits_poly_int64_p (t));
   3318   if (POLY_INT_CST_P (t))
   3319     return poly_int_cst_value (t).force_shwi ();
   3320   return TREE_INT_CST_LOW (t);
   3321 }
   3322 
   3323 poly_uint64
   3324 tree_to_poly_uint64 (const_tree t)
   3325 {
   3326   gcc_assert (tree_fits_poly_uint64_p (t));
   3327   if (POLY_INT_CST_P (t))
   3328     return poly_int_cst_value (t).force_uhwi ();
   3329   return TREE_INT_CST_LOW (t);
   3330 }
   3331 
   3332 /* Return first list element whose TREE_VALUE is ELEM.
   3334    Return 0 if ELEM is not in LIST.  */
   3335 
   3336 tree
   3337 value_member (tree elem, tree list)
   3338 {
   3339   while (list)
   3340     {
   3341       if (elem == TREE_VALUE (list))
   3342 	return list;
   3343       list = TREE_CHAIN (list);
   3344     }
   3345   return NULL_TREE;
   3346 }
   3347 
   3348 /* Return first list element whose TREE_PURPOSE is ELEM.
   3349    Return 0 if ELEM is not in LIST.  */
   3350 
   3351 tree
   3352 purpose_member (const_tree elem, tree list)
   3353 {
   3354   while (list)
   3355     {
   3356       if (elem == TREE_PURPOSE (list))
   3357 	return list;
   3358       list = TREE_CHAIN (list);
   3359     }
   3360   return NULL_TREE;
   3361 }
   3362 
   3363 /* Return true if ELEM is in V.  */
   3364 
   3365 bool
   3366 vec_member (const_tree elem, vec<tree, va_gc> *v)
   3367 {
   3368   unsigned ix;
   3369   tree t;
   3370   FOR_EACH_VEC_SAFE_ELT (v, ix, t)
   3371     if (elem == t)
   3372       return true;
   3373   return false;
   3374 }
   3375 
   3376 /* Returns element number IDX (zero-origin) of chain CHAIN, or
   3377    NULL_TREE.  */
   3378 
   3379 tree
   3380 chain_index (int idx, tree chain)
   3381 {
   3382   for (; chain && idx > 0; --idx)
   3383     chain = TREE_CHAIN (chain);
   3384   return chain;
   3385 }
   3386 
   3387 /* Return true if ELEM is part of the chain CHAIN.  */
   3388 
   3389 bool
   3390 chain_member (const_tree elem, const_tree chain)
   3391 {
   3392   while (chain)
   3393     {
   3394       if (elem == chain)
   3395 	return true;
   3396       chain = DECL_CHAIN (chain);
   3397     }
   3398 
   3399   return false;
   3400 }
   3401 
   3402 /* Return the length of a chain of nodes chained through TREE_CHAIN.
   3403    We expect a null pointer to mark the end of the chain.
   3404    This is the Lisp primitive `length'.  */
   3405 
   3406 int
   3407 list_length (const_tree t)
   3408 {
   3409   const_tree p = t;
   3410 #ifdef ENABLE_TREE_CHECKING
   3411   const_tree q = t;
   3412 #endif
   3413   int len = 0;
   3414 
   3415   while (p)
   3416     {
   3417       p = TREE_CHAIN (p);
   3418 #ifdef ENABLE_TREE_CHECKING
   3419       if (len % 2)
   3420 	q = TREE_CHAIN (q);
   3421       gcc_assert (p != q);
   3422 #endif
   3423       len++;
   3424     }
   3425 
   3426   return len;
   3427 }
   3428 
   3429 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
   3430    UNION_TYPE TYPE, or NULL_TREE if none.  */
   3431 
   3432 tree
   3433 first_field (const_tree type)
   3434 {
   3435   tree t = TYPE_FIELDS (type);
   3436   while (t && TREE_CODE (t) != FIELD_DECL)
   3437     t = TREE_CHAIN (t);
   3438   return t;
   3439 }
   3440 
   3441 /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
   3442    UNION_TYPE TYPE, or NULL_TREE if none.  */
   3443 
   3444 tree
   3445 last_field (const_tree type)
   3446 {
   3447   tree last = NULL_TREE;
   3448 
   3449   for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
   3450     {
   3451       if (TREE_CODE (fld) != FIELD_DECL)
   3452 	continue;
   3453 
   3454       last = fld;
   3455     }
   3456 
   3457   return last;
   3458 }
   3459 
   3460 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
   3461    by modifying the last node in chain 1 to point to chain 2.
   3462    This is the Lisp primitive `nconc'.  */
   3463 
   3464 tree
   3465 chainon (tree op1, tree op2)
   3466 {
   3467   tree t1;
   3468 
   3469   if (!op1)
   3470     return op2;
   3471   if (!op2)
   3472     return op1;
   3473 
   3474   for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
   3475     continue;
   3476   TREE_CHAIN (t1) = op2;
   3477 
   3478 #ifdef ENABLE_TREE_CHECKING
   3479   {
   3480     tree t2;
   3481     for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
   3482       gcc_assert (t2 != t1);
   3483   }
   3484 #endif
   3485 
   3486   return op1;
   3487 }
   3488 
   3489 /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
   3490 
   3491 tree
   3492 tree_last (tree chain)
   3493 {
   3494   tree next;
   3495   if (chain)
   3496     while ((next = TREE_CHAIN (chain)))
   3497       chain = next;
   3498   return chain;
   3499 }
   3500 
   3501 /* Reverse the order of elements in the chain T,
   3502    and return the new head of the chain (old last element).  */
   3503 
   3504 tree
   3505 nreverse (tree t)
   3506 {
   3507   tree prev = 0, decl, next;
   3508   for (decl = t; decl; decl = next)
   3509     {
   3510       /* We shouldn't be using this function to reverse BLOCK chains; we
   3511 	 have blocks_nreverse for that.  */
   3512       gcc_checking_assert (TREE_CODE (decl) != BLOCK);
   3513       next = TREE_CHAIN (decl);
   3514       TREE_CHAIN (decl) = prev;
   3515       prev = decl;
   3516     }
   3517   return prev;
   3518 }
   3519 
   3520 /* Return a newly created TREE_LIST node whose
   3522    purpose and value fields are PARM and VALUE.  */
   3523 
   3524 tree
   3525 build_tree_list (tree parm, tree value MEM_STAT_DECL)
   3526 {
   3527   tree t = make_node (TREE_LIST PASS_MEM_STAT);
   3528   TREE_PURPOSE (t) = parm;
   3529   TREE_VALUE (t) = value;
   3530   return t;
   3531 }
   3532 
   3533 /* Build a chain of TREE_LIST nodes from a vector.  */
   3534 
   3535 tree
   3536 build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
   3537 {
   3538   tree ret = NULL_TREE;
   3539   tree *pp = &ret;
   3540   unsigned int i;
   3541   tree t;
   3542   FOR_EACH_VEC_SAFE_ELT (vec, i, t)
   3543     {
   3544       *pp = build_tree_list (NULL, t PASS_MEM_STAT);
   3545       pp = &TREE_CHAIN (*pp);
   3546     }
   3547   return ret;
   3548 }
   3549 
   3550 /* Return a newly created TREE_LIST node whose
   3551    purpose and value fields are PURPOSE and VALUE
   3552    and whose TREE_CHAIN is CHAIN.  */
   3553 
   3554 tree
   3555 tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
   3556 {
   3557   tree node;
   3558 
   3559   node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
   3560   memset (node, 0, sizeof (struct tree_common));
   3561 
   3562   record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
   3563 
   3564   TREE_SET_CODE (node, TREE_LIST);
   3565   TREE_CHAIN (node) = chain;
   3566   TREE_PURPOSE (node) = purpose;
   3567   TREE_VALUE (node) = value;
   3568   return node;
   3569 }
   3570 
   3571 /* Return the values of the elements of a CONSTRUCTOR as a vector of
   3572    trees.  */
   3573 
   3574 vec<tree, va_gc> *
   3575 ctor_to_vec (tree ctor)
   3576 {
   3577   vec<tree, va_gc> *vec;
   3578   vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
   3579   unsigned int ix;
   3580   tree val;
   3581 
   3582   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
   3583     vec->quick_push (val);
   3584 
   3585   return vec;
   3586 }
   3587 
   3588 /* Return the size nominally occupied by an object of type TYPE
   3590    when it resides in memory.  The value is measured in units of bytes,
   3591    and its data type is that normally used for type sizes
   3592    (which is the first type created by make_signed_type or
   3593    make_unsigned_type).  */
   3594 
   3595 tree
   3596 size_in_bytes_loc (location_t loc, const_tree type)
   3597 {
   3598   tree t;
   3599 
   3600   if (type == error_mark_node)
   3601     return integer_zero_node;
   3602 
   3603   type = TYPE_MAIN_VARIANT (type);
   3604   t = TYPE_SIZE_UNIT (type);
   3605 
   3606   if (t == 0)
   3607     {
   3608       lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
   3609       return size_zero_node;
   3610     }
   3611 
   3612   return t;
   3613 }
   3614 
   3615 /* Return the size of TYPE (in bytes) as a wide integer
   3616    or return -1 if the size can vary or is larger than an integer.  */
   3617 
   3618 HOST_WIDE_INT
   3619 int_size_in_bytes (const_tree type)
   3620 {
   3621   tree t;
   3622 
   3623   if (type == error_mark_node)
   3624     return 0;
   3625 
   3626   type = TYPE_MAIN_VARIANT (type);
   3627   t = TYPE_SIZE_UNIT (type);
   3628 
   3629   if (t && tree_fits_uhwi_p (t))
   3630     return TREE_INT_CST_LOW (t);
   3631   else
   3632     return -1;
   3633 }
   3634 
   3635 /* Return the maximum size of TYPE (in bytes) as a wide integer
   3636    or return -1 if the size can vary or is larger than an integer.  */
   3637 
   3638 HOST_WIDE_INT
   3639 max_int_size_in_bytes (const_tree type)
   3640 {
   3641   HOST_WIDE_INT size = -1;
   3642   tree size_tree;
   3643 
   3644   /* If this is an array type, check for a possible MAX_SIZE attached.  */
   3645 
   3646   if (TREE_CODE (type) == ARRAY_TYPE)
   3647     {
   3648       size_tree = TYPE_ARRAY_MAX_SIZE (type);
   3649 
   3650       if (size_tree && tree_fits_uhwi_p (size_tree))
   3651 	size = tree_to_uhwi (size_tree);
   3652     }
   3653 
   3654   /* If we still haven't been able to get a size, see if the language
   3655      can compute a maximum size.  */
   3656 
   3657   if (size == -1)
   3658     {
   3659       size_tree = lang_hooks.types.max_size (type);
   3660 
   3661       if (size_tree && tree_fits_uhwi_p (size_tree))
   3662 	size = tree_to_uhwi (size_tree);
   3663     }
   3664 
   3665   return size;
   3666 }
   3667 
   3668 /* Return the bit position of FIELD, in bits from the start of the record.
   3670    This is a tree of type bitsizetype.  */
   3671 
   3672 tree
   3673 bit_position (const_tree field)
   3674 {
   3675   return bit_from_pos (DECL_FIELD_OFFSET (field),
   3676 		       DECL_FIELD_BIT_OFFSET (field));
   3677 }
   3678 
   3679 /* Return the byte position of FIELD, in bytes from the start of the record.
   3681    This is a tree of type sizetype.  */
   3682 
   3683 tree
   3684 byte_position (const_tree field)
   3685 {
   3686   return byte_from_pos (DECL_FIELD_OFFSET (field),
   3687 			DECL_FIELD_BIT_OFFSET (field));
   3688 }
   3689 
   3690 /* Likewise, but return as an integer.  It must be representable in
   3691    that way (since it could be a signed value, we don't have the
   3692    option of returning -1 like int_size_in_byte can.  */
   3693 
   3694 HOST_WIDE_INT
   3695 int_byte_position (const_tree field)
   3696 {
   3697   return tree_to_shwi (byte_position (field));
   3698 }
   3699 
   3700 /* Return, as a tree node, the number of elements for TYPE (which is an
   3702    ARRAY_TYPE) minus one.  This counts only elements of the top array.  */
   3703 
   3704 tree
   3705 array_type_nelts (const_tree type)
   3706 {
   3707   tree index_type, min, max;
   3708 
   3709   /* If they did it with unspecified bounds, then we should have already
   3710      given an error about it before we got here.  */
   3711   if (! TYPE_DOMAIN (type))
   3712     return error_mark_node;
   3713 
   3714   index_type = TYPE_DOMAIN (type);
   3715   min = TYPE_MIN_VALUE (index_type);
   3716   max = TYPE_MAX_VALUE (index_type);
   3717 
   3718   /* TYPE_MAX_VALUE may not be set if the array has unknown length.  */
   3719   if (!max)
   3720     {
   3721       /* zero sized arrays are represented from C FE as complete types with
   3722 	 NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
   3723 	 them as min 0, max -1.  */
   3724       if (COMPLETE_TYPE_P (type)
   3725 	  && integer_zerop (TYPE_SIZE (type))
   3726 	  && integer_zerop (min))
   3727 	return build_int_cst (TREE_TYPE (min), -1);
   3728 
   3729       return error_mark_node;
   3730     }
   3731 
   3732   return (integer_zerop (min)
   3733 	  ? max
   3734 	  : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
   3735 }
   3736 
   3737 /* If arg is static -- a reference to an object in static storage -- then
   3739    return the object.  This is not the same as the C meaning of `static'.
   3740    If arg isn't static, return NULL.  */
   3741 
   3742 tree
   3743 staticp (tree arg)
   3744 {
   3745   switch (TREE_CODE (arg))
   3746     {
   3747     case FUNCTION_DECL:
   3748       /* Nested functions are static, even though taking their address will
   3749 	 involve a trampoline as we unnest the nested function and create
   3750 	 the trampoline on the tree level.  */
   3751       return arg;
   3752 
   3753     case VAR_DECL:
   3754       return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
   3755 	      && ! DECL_THREAD_LOCAL_P (arg)
   3756 	      && ! DECL_DLLIMPORT_P (arg)
   3757 	      ? arg : NULL);
   3758 
   3759     case CONST_DECL:
   3760       return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
   3761 	      ? arg : NULL);
   3762 
   3763     case CONSTRUCTOR:
   3764       return TREE_STATIC (arg) ? arg : NULL;
   3765 
   3766     case LABEL_DECL:
   3767     case STRING_CST:
   3768       return arg;
   3769 
   3770     case COMPONENT_REF:
   3771       /* If the thing being referenced is not a field, then it is
   3772 	 something language specific.  */
   3773       gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
   3774 
   3775       /* If we are referencing a bitfield, we can't evaluate an
   3776 	 ADDR_EXPR at compile time and so it isn't a constant.  */
   3777       if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
   3778 	return NULL;
   3779 
   3780       return staticp (TREE_OPERAND (arg, 0));
   3781 
   3782     case BIT_FIELD_REF:
   3783       return NULL;
   3784 
   3785     case INDIRECT_REF:
   3786       return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
   3787 
   3788     case ARRAY_REF:
   3789     case ARRAY_RANGE_REF:
   3790       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
   3791 	  && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
   3792 	return staticp (TREE_OPERAND (arg, 0));
   3793       else
   3794 	return NULL;
   3795 
   3796     case COMPOUND_LITERAL_EXPR:
   3797       return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
   3798 
   3799     default:
   3800       return NULL;
   3801     }
   3802 }
   3803 
   3804 
   3805 
   3807 
   3808 /* Return whether OP is a DECL whose address is function-invariant.  */
   3809 
   3810 bool
   3811 decl_address_invariant_p (const_tree op)
   3812 {
   3813   /* The conditions below are slightly less strict than the one in
   3814      staticp.  */
   3815 
   3816   switch (TREE_CODE (op))
   3817     {
   3818     case PARM_DECL:
   3819     case RESULT_DECL:
   3820     case LABEL_DECL:
   3821     case FUNCTION_DECL:
   3822       return true;
   3823 
   3824     case VAR_DECL:
   3825       if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
   3826           || DECL_THREAD_LOCAL_P (op)
   3827           || DECL_CONTEXT (op) == current_function_decl
   3828           || decl_function_context (op) == current_function_decl)
   3829         return true;
   3830       break;
   3831 
   3832     case CONST_DECL:
   3833       if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
   3834           || decl_function_context (op) == current_function_decl)
   3835         return true;
   3836       break;
   3837 
   3838     default:
   3839       break;
   3840     }
   3841 
   3842   return false;
   3843 }
   3844 
   3845 /* Return whether OP is a DECL whose address is interprocedural-invariant.  */
   3846 
   3847 bool
   3848 decl_address_ip_invariant_p (const_tree op)
   3849 {
   3850   /* The conditions below are slightly less strict than the one in
   3851      staticp.  */
   3852 
   3853   switch (TREE_CODE (op))
   3854     {
   3855     case LABEL_DECL:
   3856     case FUNCTION_DECL:
   3857     case STRING_CST:
   3858       return true;
   3859 
   3860     case VAR_DECL:
   3861       if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
   3862            && !DECL_DLLIMPORT_P (op))
   3863           || DECL_THREAD_LOCAL_P (op))
   3864         return true;
   3865       break;
   3866 
   3867     case CONST_DECL:
   3868       if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
   3869         return true;
   3870       break;
   3871 
   3872     default:
   3873       break;
   3874     }
   3875 
   3876   return false;
   3877 }
   3878 
   3879 
   3880 /* Return true if T is function-invariant (internal function, does
   3881    not handle arithmetic; that's handled in skip_simple_arithmetic and
   3882    tree_invariant_p).  */
   3883 
   3884 static bool
   3885 tree_invariant_p_1 (tree t)
   3886 {
   3887   tree op;
   3888 
   3889   if (TREE_CONSTANT (t)
   3890       || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
   3891     return true;
   3892 
   3893   switch (TREE_CODE (t))
   3894     {
   3895     case SAVE_EXPR:
   3896       return true;
   3897 
   3898     case ADDR_EXPR:
   3899       op = TREE_OPERAND (t, 0);
   3900       while (handled_component_p (op))
   3901 	{
   3902 	  switch (TREE_CODE (op))
   3903 	    {
   3904 	    case ARRAY_REF:
   3905 	    case ARRAY_RANGE_REF:
   3906 	      if (!tree_invariant_p (TREE_OPERAND (op, 1))
   3907 		  || TREE_OPERAND (op, 2) != NULL_TREE
   3908 		  || TREE_OPERAND (op, 3) != NULL_TREE)
   3909 		return false;
   3910 	      break;
   3911 
   3912 	    case COMPONENT_REF:
   3913 	      if (TREE_OPERAND (op, 2) != NULL_TREE)
   3914 		return false;
   3915 	      break;
   3916 
   3917 	    default:;
   3918 	    }
   3919 	  op = TREE_OPERAND (op, 0);
   3920 	}
   3921 
   3922       return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
   3923 
   3924     default:
   3925       break;
   3926     }
   3927 
   3928   return false;
   3929 }
   3930 
   3931 /* Return true if T is function-invariant.  */
   3932 
   3933 bool
   3934 tree_invariant_p (tree t)
   3935 {
   3936   tree inner = skip_simple_arithmetic (t);
   3937   return tree_invariant_p_1 (inner);
   3938 }
   3939 
   3940 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
   3941    Do this to any expression which may be used in more than one place,
   3942    but must be evaluated only once.
   3943 
   3944    Normally, expand_expr would reevaluate the expression each time.
   3945    Calling save_expr produces something that is evaluated and recorded
   3946    the first time expand_expr is called on it.  Subsequent calls to
   3947    expand_expr just reuse the recorded value.
   3948 
   3949    The call to expand_expr that generates code that actually computes
   3950    the value is the first call *at compile time*.  Subsequent calls
   3951    *at compile time* generate code to use the saved value.
   3952    This produces correct result provided that *at run time* control
   3953    always flows through the insns made by the first expand_expr
   3954    before reaching the other places where the save_expr was evaluated.
   3955    You, the caller of save_expr, must make sure this is so.
   3956 
   3957    Constants, and certain read-only nodes, are returned with no
   3958    SAVE_EXPR because that is safe.  Expressions containing placeholders
   3959    are not touched; see tree.def for an explanation of what these
   3960    are used for.  */
   3961 
   3962 tree
   3963 save_expr (tree expr)
   3964 {
   3965   tree inner;
   3966 
   3967   /* If the tree evaluates to a constant, then we don't want to hide that
   3968      fact (i.e. this allows further folding, and direct checks for constants).
   3969      However, a read-only object that has side effects cannot be bypassed.
   3970      Since it is no problem to reevaluate literals, we just return the
   3971      literal node.  */
   3972   inner = skip_simple_arithmetic (expr);
   3973   if (TREE_CODE (inner) == ERROR_MARK)
   3974     return inner;
   3975 
   3976   if (tree_invariant_p_1 (inner))
   3977     return expr;
   3978 
   3979   /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
   3980      it means that the size or offset of some field of an object depends on
   3981      the value within another field.
   3982 
   3983      Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
   3984      and some variable since it would then need to be both evaluated once and
   3985      evaluated more than once.  Front-ends must assure this case cannot
   3986      happen by surrounding any such subexpressions in their own SAVE_EXPR
   3987      and forcing evaluation at the proper time.  */
   3988   if (contains_placeholder_p (inner))
   3989     return expr;
   3990 
   3991   expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
   3992 
   3993   /* This expression might be placed ahead of a jump to ensure that the
   3994      value was computed on both sides of the jump.  So make sure it isn't
   3995      eliminated as dead.  */
   3996   TREE_SIDE_EFFECTS (expr) = 1;
   3997   return expr;
   3998 }
   3999 
   4000 /* Look inside EXPR into any simple arithmetic operations.  Return the
   4001    outermost non-arithmetic or non-invariant node.  */
   4002 
   4003 tree
   4004 skip_simple_arithmetic (tree expr)
   4005 {
   4006   /* We don't care about whether this can be used as an lvalue in this
   4007      context.  */
   4008   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
   4009     expr = TREE_OPERAND (expr, 0);
   4010 
   4011   /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
   4012      a constant, it will be more efficient to not make another SAVE_EXPR since
   4013      it will allow better simplification and GCSE will be able to merge the
   4014      computations if they actually occur.  */
   4015   while (true)
   4016     {
   4017       if (UNARY_CLASS_P (expr))
   4018 	expr = TREE_OPERAND (expr, 0);
   4019       else if (BINARY_CLASS_P (expr))
   4020 	{
   4021 	  /* Before commutative binary operands are canonicalized,
   4022 	     it is quite common to have constants in the first operand.
   4023 	     Check for that common case first so that we don't walk
   4024 	     large expressions with tree_invariant_p unnecessarily.
   4025 	     This can still have terrible compile time complexity,
   4026 	     we should limit the depth of the tree_invariant_p and
   4027 	     skip_simple_arithmetic recursion.  */
   4028 	  if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
   4029 	       || (TREE_READONLY (TREE_OPERAND (expr, 0))
   4030 		   && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
   4031 	      && tree_invariant_p (TREE_OPERAND (expr, 0)))
   4032 	    expr = TREE_OPERAND (expr, 1);
   4033 	  else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
   4034 	    expr = TREE_OPERAND (expr, 0);
   4035 	  else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
   4036 	    expr = TREE_OPERAND (expr, 1);
   4037 	  else
   4038 	    break;
   4039 	}
   4040       else
   4041 	break;
   4042     }
   4043 
   4044   return expr;
   4045 }
   4046 
   4047 /* Look inside EXPR into simple arithmetic operations involving constants.
   4048    Return the outermost non-arithmetic or non-constant node.  */
   4049 
   4050 tree
   4051 skip_simple_constant_arithmetic (tree expr)
   4052 {
   4053   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
   4054     expr = TREE_OPERAND (expr, 0);
   4055 
   4056   while (true)
   4057     {
   4058       if (UNARY_CLASS_P (expr))
   4059 	expr = TREE_OPERAND (expr, 0);
   4060       else if (BINARY_CLASS_P (expr))
   4061 	{
   4062 	  if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
   4063 	    expr = TREE_OPERAND (expr, 0);
   4064 	  else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
   4065 	    expr = TREE_OPERAND (expr, 1);
   4066 	  else
   4067 	    break;
   4068 	}
   4069       else
   4070 	break;
   4071     }
   4072 
   4073   return expr;
   4074 }
   4075 
   4076 /* Return which tree structure is used by T.  */
   4077 
   4078 enum tree_node_structure_enum
   4079 tree_node_structure (const_tree t)
   4080 {
   4081   const enum tree_code code = TREE_CODE (t);
   4082   return tree_node_structure_for_code (code);
   4083 }
   4084 
   4085 /* Set various status flags when building a CALL_EXPR object T.  */
   4086 
   4087 static void
   4088 process_call_operands (tree t)
   4089 {
   4090   bool side_effects = TREE_SIDE_EFFECTS (t);
   4091   bool read_only = false;
   4092   int i = call_expr_flags (t);
   4093 
   4094   /* Calls have side-effects, except those to const or pure functions.  */
   4095   if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
   4096     side_effects = true;
   4097   /* Propagate TREE_READONLY of arguments for const functions.  */
   4098   if (i & ECF_CONST)
   4099     read_only = true;
   4100 
   4101   if (!side_effects || read_only)
   4102     for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
   4103       {
   4104 	tree op = TREE_OPERAND (t, i);
   4105 	if (op && TREE_SIDE_EFFECTS (op))
   4106 	  side_effects = true;
   4107 	if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
   4108 	  read_only = false;
   4109       }
   4110 
   4111   TREE_SIDE_EFFECTS (t) = side_effects;
   4112   TREE_READONLY (t) = read_only;
   4113 }
   4114 
   4115 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
   4117    size or offset that depends on a field within a record.  */
   4118 
   4119 bool
   4120 contains_placeholder_p (const_tree exp)
   4121 {
   4122   enum tree_code code;
   4123 
   4124   if (!exp)
   4125     return false;
   4126 
   4127   code = TREE_CODE (exp);
   4128   if (code == PLACEHOLDER_EXPR)
   4129     return true;
   4130 
   4131   switch (TREE_CODE_CLASS (code))
   4132     {
   4133     case tcc_reference:
   4134       /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
   4135 	 position computations since they will be converted into a
   4136 	 WITH_RECORD_EXPR involving the reference, which will assume
   4137 	 here will be valid.  */
   4138       return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
   4139 
   4140     case tcc_exceptional:
   4141       if (code == TREE_LIST)
   4142 	return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
   4143 		|| CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
   4144       break;
   4145 
   4146     case tcc_unary:
   4147     case tcc_binary:
   4148     case tcc_comparison:
   4149     case tcc_expression:
   4150       switch (code)
   4151 	{
   4152 	case COMPOUND_EXPR:
   4153 	  /* Ignoring the first operand isn't quite right, but works best.  */
   4154 	  return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
   4155 
   4156 	case COND_EXPR:
   4157 	  return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
   4158 		  || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
   4159 		  || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
   4160 
   4161 	case SAVE_EXPR:
   4162 	  /* The save_expr function never wraps anything containing
   4163 	     a PLACEHOLDER_EXPR. */
   4164 	  return false;
   4165 
   4166 	default:
   4167 	  break;
   4168 	}
   4169 
   4170       switch (TREE_CODE_LENGTH (code))
   4171 	{
   4172 	case 1:
   4173 	  return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
   4174 	case 2:
   4175 	  return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
   4176 		  || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
   4177 	default:
   4178 	  return false;
   4179 	}
   4180 
   4181     case tcc_vl_exp:
   4182       switch (code)
   4183 	{
   4184 	case CALL_EXPR:
   4185 	  {
   4186 	    const_tree arg;
   4187 	    const_call_expr_arg_iterator iter;
   4188 	    FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
   4189 	      if (CONTAINS_PLACEHOLDER_P (arg))
   4190 		return true;
   4191 	    return false;
   4192 	  }
   4193 	default:
   4194 	  return false;
   4195 	}
   4196 
   4197     default:
   4198       return false;
   4199     }
   4200   return false;
   4201 }
   4202 
   4203 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
   4204    directly.  This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
   4205    field positions.  */
   4206 
   4207 static bool
   4208 type_contains_placeholder_1 (const_tree type)
   4209 {
   4210   /* If the size contains a placeholder or the parent type (component type in
   4211      the case of arrays) type involves a placeholder, this type does.  */
   4212   if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
   4213       || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
   4214       || (!POINTER_TYPE_P (type)
   4215 	  && TREE_TYPE (type)
   4216 	  && type_contains_placeholder_p (TREE_TYPE (type))))
   4217     return true;
   4218 
   4219   /* Now do type-specific checks.  Note that the last part of the check above
   4220      greatly limits what we have to do below.  */
   4221   switch (TREE_CODE (type))
   4222     {
   4223     case VOID_TYPE:
   4224     case OPAQUE_TYPE:
   4225     case COMPLEX_TYPE:
   4226     case ENUMERAL_TYPE:
   4227     case BOOLEAN_TYPE:
   4228     case POINTER_TYPE:
   4229     case OFFSET_TYPE:
   4230     case REFERENCE_TYPE:
   4231     case METHOD_TYPE:
   4232     case FUNCTION_TYPE:
   4233     case VECTOR_TYPE:
   4234     case NULLPTR_TYPE:
   4235       return false;
   4236 
   4237     case INTEGER_TYPE:
   4238     case BITINT_TYPE:
   4239     case REAL_TYPE:
   4240     case FIXED_POINT_TYPE:
   4241       /* Here we just check the bounds.  */
   4242       return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
   4243 	      || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
   4244 
   4245     case ARRAY_TYPE:
   4246       /* We have already checked the component type above, so just check
   4247 	 the domain type.  Flexible array members have a null domain.  */
   4248       return TYPE_DOMAIN (type) ?
   4249 	type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
   4250 
   4251     case RECORD_TYPE:
   4252     case UNION_TYPE:
   4253     case QUAL_UNION_TYPE:
   4254       {
   4255 	tree field;
   4256 
   4257 	for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   4258 	  if (TREE_CODE (field) == FIELD_DECL
   4259 	      && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
   4260 		  || (TREE_CODE (type) == QUAL_UNION_TYPE
   4261 		      && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
   4262 		  || type_contains_placeholder_p (TREE_TYPE (field))))
   4263 	    return true;
   4264 
   4265 	return false;
   4266       }
   4267 
   4268     default:
   4269       gcc_unreachable ();
   4270     }
   4271 }
   4272 
   4273 /* Wrapper around above function used to cache its result.  */
   4274 
   4275 bool
   4276 type_contains_placeholder_p (tree type)
   4277 {
   4278   bool result;
   4279 
   4280   /* If the contains_placeholder_bits field has been initialized,
   4281      then we know the answer.  */
   4282   if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
   4283     return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
   4284 
   4285   /* Indicate that we've seen this type node, and the answer is false.
   4286      This is what we want to return if we run into recursion via fields.  */
   4287   TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
   4288 
   4289   /* Compute the real value.  */
   4290   result = type_contains_placeholder_1 (type);
   4291 
   4292   /* Store the real value.  */
   4293   TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
   4294 
   4295   return result;
   4296 }
   4297 
   4298 /* Push tree EXP onto vector QUEUE if it is not already present.  */
   4300 
   4301 static void
   4302 push_without_duplicates (tree exp, vec<tree> *queue)
   4303 {
   4304   unsigned int i;
   4305   tree iter;
   4306 
   4307   FOR_EACH_VEC_ELT (*queue, i, iter)
   4308     if (simple_cst_equal (iter, exp) == 1)
   4309       break;
   4310 
   4311   if (!iter)
   4312     queue->safe_push (exp);
   4313 }
   4314 
   4315 /* Given a tree EXP, find all occurrences of references to fields
   4316    in a PLACEHOLDER_EXPR and place them in vector REFS without
   4317    duplicates.  Also record VAR_DECLs and CONST_DECLs.  Note that
   4318    we assume here that EXP contains only arithmetic expressions
   4319    or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
   4320    argument list.  */
   4321 
   4322 void
   4323 find_placeholder_in_expr (tree exp, vec<tree> *refs)
   4324 {
   4325   enum tree_code code = TREE_CODE (exp);
   4326   tree inner;
   4327   int i;
   4328 
   4329   /* We handle TREE_LIST and COMPONENT_REF separately.  */
   4330   if (code == TREE_LIST)
   4331     {
   4332       FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
   4333       FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
   4334     }
   4335   else if (code == COMPONENT_REF)
   4336     {
   4337       for (inner = TREE_OPERAND (exp, 0);
   4338 	   REFERENCE_CLASS_P (inner);
   4339 	   inner = TREE_OPERAND (inner, 0))
   4340 	;
   4341 
   4342       if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
   4343 	push_without_duplicates (exp, refs);
   4344       else
   4345 	FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
   4346    }
   4347   else
   4348     switch (TREE_CODE_CLASS (code))
   4349       {
   4350       case tcc_constant:
   4351 	break;
   4352 
   4353       case tcc_declaration:
   4354 	/* Variables allocated to static storage can stay.  */
   4355         if (!TREE_STATIC (exp))
   4356 	  push_without_duplicates (exp, refs);
   4357 	break;
   4358 
   4359       case tcc_expression:
   4360 	/* This is the pattern built in ada/make_aligning_type.  */
   4361 	if (code == ADDR_EXPR
   4362 	    && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
   4363 	  {
   4364 	    push_without_duplicates (exp, refs);
   4365 	    break;
   4366 	  }
   4367 
   4368         /* Fall through.  */
   4369 
   4370       case tcc_exceptional:
   4371       case tcc_unary:
   4372       case tcc_binary:
   4373       case tcc_comparison:
   4374       case tcc_reference:
   4375 	for (i = 0; i < TREE_CODE_LENGTH (code); i++)
   4376 	  FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
   4377 	break;
   4378 
   4379       case tcc_vl_exp:
   4380 	for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
   4381 	  FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
   4382 	break;
   4383 
   4384       default:
   4385 	gcc_unreachable ();
   4386       }
   4387 }
   4388 
   4389 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
   4390    return a tree with all occurrences of references to F in a
   4391    PLACEHOLDER_EXPR replaced by R.  Also handle VAR_DECLs and
   4392    CONST_DECLs.  Note that we assume here that EXP contains only
   4393    arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
   4394    occurring only in their argument list.  */
   4395 
   4396 tree
   4397 substitute_in_expr (tree exp, tree f, tree r)
   4398 {
   4399   enum tree_code code = TREE_CODE (exp);
   4400   tree op0, op1, op2, op3;
   4401   tree new_tree;
   4402 
   4403   /* We handle TREE_LIST and COMPONENT_REF separately.  */
   4404   if (code == TREE_LIST)
   4405     {
   4406       op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
   4407       op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
   4408       if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
   4409 	return exp;
   4410 
   4411       return tree_cons (TREE_PURPOSE (exp), op1, op0);
   4412     }
   4413   else if (code == COMPONENT_REF)
   4414     {
   4415       tree inner;
   4416 
   4417       /* If this expression is getting a value from a PLACEHOLDER_EXPR
   4418 	 and it is the right field, replace it with R.  */
   4419       for (inner = TREE_OPERAND (exp, 0);
   4420 	   REFERENCE_CLASS_P (inner);
   4421 	   inner = TREE_OPERAND (inner, 0))
   4422 	;
   4423 
   4424       /* The field.  */
   4425       op1 = TREE_OPERAND (exp, 1);
   4426 
   4427       if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
   4428 	return r;
   4429 
   4430       /* If this expression hasn't been completed let, leave it alone.  */
   4431       if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
   4432 	return exp;
   4433 
   4434       op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
   4435       if (op0 == TREE_OPERAND (exp, 0))
   4436 	return exp;
   4437 
   4438       new_tree
   4439 	= fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
   4440    }
   4441   else
   4442     switch (TREE_CODE_CLASS (code))
   4443       {
   4444       case tcc_constant:
   4445 	return exp;
   4446 
   4447       case tcc_declaration:
   4448 	if (exp == f)
   4449 	  return r;
   4450 	else
   4451 	  return exp;
   4452 
   4453       case tcc_expression:
   4454 	if (exp == f)
   4455 	  return r;
   4456 
   4457         /* Fall through.  */
   4458 
   4459       case tcc_exceptional:
   4460       case tcc_unary:
   4461       case tcc_binary:
   4462       case tcc_comparison:
   4463       case tcc_reference:
   4464 	switch (TREE_CODE_LENGTH (code))
   4465 	  {
   4466 	  case 0:
   4467 	    return exp;
   4468 
   4469 	  case 1:
   4470 	    op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
   4471 	    if (op0 == TREE_OPERAND (exp, 0))
   4472 	      return exp;
   4473 
   4474 	    new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
   4475 	    break;
   4476 
   4477 	  case 2:
   4478 	    op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
   4479 	    op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
   4480 
   4481 	    if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
   4482 	      return exp;
   4483 
   4484 	    new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
   4485 	    break;
   4486 
   4487 	  case 3:
   4488 	    op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
   4489 	    op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
   4490 	    op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
   4491 
   4492 	    if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
   4493 		&& op2 == TREE_OPERAND (exp, 2))
   4494 	      return exp;
   4495 
   4496 	    new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
   4497 	    break;
   4498 
   4499 	  case 4:
   4500 	    op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
   4501 	    op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
   4502 	    op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
   4503 	    op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
   4504 
   4505 	    if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
   4506 		&& op2 == TREE_OPERAND (exp, 2)
   4507 		&& op3 == TREE_OPERAND (exp, 3))
   4508 	      return exp;
   4509 
   4510 	    new_tree
   4511 	      = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
   4512 	    break;
   4513 
   4514 	  default:
   4515 	    gcc_unreachable ();
   4516 	  }
   4517 	break;
   4518 
   4519       case tcc_vl_exp:
   4520 	{
   4521 	  int i;
   4522 
   4523 	  new_tree = NULL_TREE;
   4524 
   4525 	  /* If we are trying to replace F with a constant or with another
   4526 	     instance of one of the arguments of the call, inline back
   4527 	     functions which do nothing else than computing a value from
   4528 	     the arguments they are passed.  This makes it possible to
   4529 	     fold partially or entirely the replacement expression.  */
   4530 	  if (code == CALL_EXPR)
   4531 	    {
   4532 	      bool maybe_inline = false;
   4533 	      if (CONSTANT_CLASS_P (r))
   4534 		maybe_inline = true;
   4535 	      else
   4536 		for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
   4537 		  if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
   4538 		    {
   4539 		      maybe_inline = true;
   4540 		      break;
   4541 		    }
   4542 	      if (maybe_inline)
   4543 		{
   4544 		  tree t = maybe_inline_call_in_expr (exp);
   4545 		  if (t)
   4546 		    return SUBSTITUTE_IN_EXPR (t, f, r);
   4547 		}
   4548 	    }
   4549 
   4550 	  for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
   4551 	    {
   4552 	      tree op = TREE_OPERAND (exp, i);
   4553 	      tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
   4554 	      if (new_op != op)
   4555 		{
   4556 		  if (!new_tree)
   4557 		    new_tree = copy_node (exp);
   4558 		  TREE_OPERAND (new_tree, i) = new_op;
   4559 		}
   4560 	    }
   4561 
   4562 	  if (new_tree)
   4563 	    {
   4564 	      new_tree = fold (new_tree);
   4565 	      if (TREE_CODE (new_tree) == CALL_EXPR)
   4566 		process_call_operands (new_tree);
   4567 	    }
   4568 	  else
   4569 	    return exp;
   4570 	}
   4571 	break;
   4572 
   4573       default:
   4574 	gcc_unreachable ();
   4575       }
   4576 
   4577   TREE_READONLY (new_tree) |= TREE_READONLY (exp);
   4578 
   4579   if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
   4580     TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
   4581 
   4582   return new_tree;
   4583 }
   4584 
   4585 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
   4586    for it within OBJ, a tree that is an object or a chain of references.  */
   4587 
   4588 tree
   4589 substitute_placeholder_in_expr (tree exp, tree obj)
   4590 {
   4591   enum tree_code code = TREE_CODE (exp);
   4592   tree op0, op1, op2, op3;
   4593   tree new_tree;
   4594 
   4595   /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
   4596      in the chain of OBJ.  */
   4597   if (code == PLACEHOLDER_EXPR)
   4598     {
   4599       tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
   4600       tree elt;
   4601 
   4602       for (elt = obj; elt != 0;
   4603 	   elt = ((TREE_CODE (elt) == COMPOUND_EXPR
   4604 		   || TREE_CODE (elt) == COND_EXPR)
   4605 		  ? TREE_OPERAND (elt, 1)
   4606 		  : (REFERENCE_CLASS_P (elt)
   4607 		     || UNARY_CLASS_P (elt)
   4608 		     || BINARY_CLASS_P (elt)
   4609 		     || VL_EXP_CLASS_P (elt)
   4610 		     || EXPRESSION_CLASS_P (elt))
   4611 		  ? TREE_OPERAND (elt, 0) : 0))
   4612 	if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
   4613 	  return elt;
   4614 
   4615       for (elt = obj; elt != 0;
   4616 	   elt = ((TREE_CODE (elt) == COMPOUND_EXPR
   4617 		   || TREE_CODE (elt) == COND_EXPR)
   4618 		  ? TREE_OPERAND (elt, 1)
   4619 		  : (REFERENCE_CLASS_P (elt)
   4620 		     || UNARY_CLASS_P (elt)
   4621 		     || BINARY_CLASS_P (elt)
   4622 		     || VL_EXP_CLASS_P (elt)
   4623 		     || EXPRESSION_CLASS_P (elt))
   4624 		  ? TREE_OPERAND (elt, 0) : 0))
   4625 	if (POINTER_TYPE_P (TREE_TYPE (elt))
   4626 	    && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
   4627 		== need_type))
   4628 	  return fold_build1 (INDIRECT_REF, need_type, elt);
   4629 
   4630       /* If we didn't find it, return the original PLACEHOLDER_EXPR.  If it
   4631 	 survives until RTL generation, there will be an error.  */
   4632       return exp;
   4633     }
   4634 
   4635   /* TREE_LIST is special because we need to look at TREE_VALUE
   4636      and TREE_CHAIN, not TREE_OPERANDS.  */
   4637   else if (code == TREE_LIST)
   4638     {
   4639       op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
   4640       op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
   4641       if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
   4642 	return exp;
   4643 
   4644       return tree_cons (TREE_PURPOSE (exp), op1, op0);
   4645     }
   4646   else
   4647     switch (TREE_CODE_CLASS (code))
   4648       {
   4649       case tcc_constant:
   4650       case tcc_declaration:
   4651 	return exp;
   4652 
   4653       case tcc_exceptional:
   4654       case tcc_unary:
   4655       case tcc_binary:
   4656       case tcc_comparison:
   4657       case tcc_expression:
   4658       case tcc_reference:
   4659       case tcc_statement:
   4660 	switch (TREE_CODE_LENGTH (code))
   4661 	  {
   4662 	  case 0:
   4663 	    return exp;
   4664 
   4665 	  case 1:
   4666 	    op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
   4667 	    if (op0 == TREE_OPERAND (exp, 0))
   4668 	      return exp;
   4669 
   4670 	    new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
   4671 	    break;
   4672 
   4673 	  case 2:
   4674 	    op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
   4675 	    op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
   4676 
   4677 	    if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
   4678 	      return exp;
   4679 
   4680 	    new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
   4681 	    break;
   4682 
   4683 	  case 3:
   4684 	    op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
   4685 	    op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
   4686 	    op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
   4687 
   4688 	    if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
   4689 		&& op2 == TREE_OPERAND (exp, 2))
   4690 	      return exp;
   4691 
   4692 	    new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
   4693 	    break;
   4694 
   4695 	  case 4:
   4696 	    op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
   4697 	    op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
   4698 	    op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
   4699 	    op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
   4700 
   4701 	    if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
   4702 		&& op2 == TREE_OPERAND (exp, 2)
   4703 		&& op3 == TREE_OPERAND (exp, 3))
   4704 	      return exp;
   4705 
   4706 	    new_tree
   4707 	      = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
   4708 	    break;
   4709 
   4710 	  default:
   4711 	    gcc_unreachable ();
   4712 	  }
   4713 	break;
   4714 
   4715       case tcc_vl_exp:
   4716 	{
   4717 	  int i;
   4718 
   4719 	  new_tree = NULL_TREE;
   4720 
   4721 	  for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
   4722 	    {
   4723 	      tree op = TREE_OPERAND (exp, i);
   4724 	      tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
   4725 	      if (new_op != op)
   4726 		{
   4727 		  if (!new_tree)
   4728 		    new_tree = copy_node (exp);
   4729 		  TREE_OPERAND (new_tree, i) = new_op;
   4730 		}
   4731 	    }
   4732 
   4733 	  if (new_tree)
   4734 	    {
   4735 	      new_tree = fold (new_tree);
   4736 	      if (TREE_CODE (new_tree) == CALL_EXPR)
   4737 		process_call_operands (new_tree);
   4738 	    }
   4739 	  else
   4740 	    return exp;
   4741 	}
   4742 	break;
   4743 
   4744       default:
   4745 	gcc_unreachable ();
   4746       }
   4747 
   4748   TREE_READONLY (new_tree) |= TREE_READONLY (exp);
   4749 
   4750   if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
   4751     TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
   4752 
   4753   return new_tree;
   4754 }
   4755 
   4756 
   4758 /* Subroutine of stabilize_reference; this is called for subtrees of
   4759    references.  Any expression with side-effects must be put in a SAVE_EXPR
   4760    to ensure that it is only evaluated once.
   4761 
   4762    We don't put SAVE_EXPR nodes around everything, because assigning very
   4763    simple expressions to temporaries causes us to miss good opportunities
   4764    for optimizations.  Among other things, the opportunity to fold in the
   4765    addition of a constant into an addressing mode often gets lost, e.g.
   4766    "y[i+1] += x;".  In general, we take the approach that we should not make
   4767    an assignment unless we are forced into it - i.e., that any non-side effect
   4768    operator should be allowed, and that cse should take care of coalescing
   4769    multiple utterances of the same expression should that prove fruitful.  */
   4770 
   4771 static tree
   4772 stabilize_reference_1 (tree e)
   4773 {
   4774   tree result;
   4775   enum tree_code code = TREE_CODE (e);
   4776 
   4777   /* We cannot ignore const expressions because it might be a reference
   4778      to a const array but whose index contains side-effects.  But we can
   4779      ignore things that are actual constant or that already have been
   4780      handled by this function.  */
   4781 
   4782   if (tree_invariant_p (e))
   4783     return e;
   4784 
   4785   switch (TREE_CODE_CLASS (code))
   4786     {
   4787     case tcc_exceptional:
   4788       /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
   4789 	 have side-effects.  */
   4790       if (code == STATEMENT_LIST)
   4791 	return save_expr (e);
   4792       /* FALLTHRU */
   4793     case tcc_type:
   4794     case tcc_declaration:
   4795     case tcc_comparison:
   4796     case tcc_statement:
   4797     case tcc_expression:
   4798     case tcc_reference:
   4799     case tcc_vl_exp:
   4800       /* If the expression has side-effects, then encase it in a SAVE_EXPR
   4801 	 so that it will only be evaluated once.  */
   4802       /* The reference (r) and comparison (<) classes could be handled as
   4803 	 below, but it is generally faster to only evaluate them once.  */
   4804       if (TREE_SIDE_EFFECTS (e))
   4805 	return save_expr (e);
   4806       return e;
   4807 
   4808     case tcc_constant:
   4809       /* Constants need no processing.  In fact, we should never reach
   4810 	 here.  */
   4811       return e;
   4812 
   4813     case tcc_binary:
   4814       /* Division is slow and tends to be compiled with jumps,
   4815 	 especially the division by powers of 2 that is often
   4816 	 found inside of an array reference.  So do it just once.  */
   4817       if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
   4818 	  || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
   4819 	  || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
   4820 	  || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
   4821 	return save_expr (e);
   4822       /* Recursively stabilize each operand.  */
   4823       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
   4824 			 stabilize_reference_1 (TREE_OPERAND (e, 1)));
   4825       break;
   4826 
   4827     case tcc_unary:
   4828       /* Recursively stabilize each operand.  */
   4829       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
   4830       break;
   4831 
   4832     default:
   4833       gcc_unreachable ();
   4834     }
   4835 
   4836   TREE_TYPE (result) = TREE_TYPE (e);
   4837   TREE_READONLY (result) = TREE_READONLY (e);
   4838   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
   4839   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
   4840 
   4841   return result;
   4842 }
   4843 
   4844 /* Stabilize a reference so that we can use it any number of times
   4845    without causing its operands to be evaluated more than once.
   4846    Returns the stabilized reference.  This works by means of save_expr,
   4847    so see the caveats in the comments about save_expr.
   4848 
   4849    Also allows conversion expressions whose operands are references.
   4850    Any other kind of expression is returned unchanged.  */
   4851 
   4852 tree
   4853 stabilize_reference (tree ref)
   4854 {
   4855   tree result;
   4856   enum tree_code code = TREE_CODE (ref);
   4857 
   4858   switch (code)
   4859     {
   4860     case VAR_DECL:
   4861     case PARM_DECL:
   4862     case RESULT_DECL:
   4863       /* No action is needed in this case.  */
   4864       return ref;
   4865 
   4866     CASE_CONVERT:
   4867     case FLOAT_EXPR:
   4868     case FIX_TRUNC_EXPR:
   4869       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
   4870       break;
   4871 
   4872     case INDIRECT_REF:
   4873       result = build_nt (INDIRECT_REF,
   4874 			 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
   4875       break;
   4876 
   4877     case COMPONENT_REF:
   4878       result = build_nt (COMPONENT_REF,
   4879 			 stabilize_reference (TREE_OPERAND (ref, 0)),
   4880 			 TREE_OPERAND (ref, 1), NULL_TREE);
   4881       break;
   4882 
   4883     case BIT_FIELD_REF:
   4884       result = build_nt (BIT_FIELD_REF,
   4885 			 stabilize_reference (TREE_OPERAND (ref, 0)),
   4886 			 TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
   4887       REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
   4888       break;
   4889 
   4890     case ARRAY_REF:
   4891       result = build_nt (ARRAY_REF,
   4892 			 stabilize_reference (TREE_OPERAND (ref, 0)),
   4893 			 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
   4894 			 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
   4895       break;
   4896 
   4897     case ARRAY_RANGE_REF:
   4898       result = build_nt (ARRAY_RANGE_REF,
   4899 			 stabilize_reference (TREE_OPERAND (ref, 0)),
   4900 			 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
   4901 			 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
   4902       break;
   4903 
   4904     case COMPOUND_EXPR:
   4905       /* We cannot wrap the first expression in a SAVE_EXPR, as then
   4906 	 it wouldn't be ignored.  This matters when dealing with
   4907 	 volatiles.  */
   4908       return stabilize_reference_1 (ref);
   4909 
   4910       /* If arg isn't a kind of lvalue we recognize, make no change.
   4911 	 Caller should recognize the error for an invalid lvalue.  */
   4912     default:
   4913       return ref;
   4914 
   4915     case ERROR_MARK:
   4916       return error_mark_node;
   4917     }
   4918 
   4919   TREE_TYPE (result) = TREE_TYPE (ref);
   4920   TREE_READONLY (result) = TREE_READONLY (ref);
   4921   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
   4922   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
   4923   protected_set_expr_location (result, EXPR_LOCATION (ref));
   4924 
   4925   return result;
   4926 }
   4927 
   4928 /* Low-level constructors for expressions.  */
   4930 
   4931 /* A helper function for build1 and constant folders.  Set TREE_CONSTANT,
   4932    and TREE_SIDE_EFFECTS for an ADDR_EXPR.  */
   4933 
   4934 void
   4935 recompute_tree_invariant_for_addr_expr (tree t)
   4936 {
   4937   tree node;
   4938   bool tc = true, se = false;
   4939 
   4940   gcc_assert (TREE_CODE (t) == ADDR_EXPR);
   4941 
   4942   /* We started out assuming this address is both invariant and constant, but
   4943      does not have side effects.  Now go down any handled components and see if
   4944      any of them involve offsets that are either non-constant or non-invariant.
   4945      Also check for side-effects.
   4946 
   4947      ??? Note that this code makes no attempt to deal with the case where
   4948      taking the address of something causes a copy due to misalignment.  */
   4949 
   4950 #define UPDATE_FLAGS(NODE)  \
   4951 do { tree _node = (NODE); \
   4952      if (_node && !TREE_CONSTANT (_node)) tc = false; \
   4953      if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
   4954 
   4955   for (node = TREE_OPERAND (t, 0); handled_component_p (node);
   4956        node = TREE_OPERAND (node, 0))
   4957     {
   4958       /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
   4959 	 array reference (probably made temporarily by the G++ front end),
   4960 	 so ignore all the operands.  */
   4961       if ((TREE_CODE (node) == ARRAY_REF
   4962 	   || TREE_CODE (node) == ARRAY_RANGE_REF)
   4963 	  && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
   4964 	{
   4965 	  UPDATE_FLAGS (TREE_OPERAND (node, 1));
   4966 	  if (TREE_OPERAND (node, 2))
   4967 	    UPDATE_FLAGS (TREE_OPERAND (node, 2));
   4968 	  if (TREE_OPERAND (node, 3))
   4969 	    UPDATE_FLAGS (TREE_OPERAND (node, 3));
   4970 	}
   4971       /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
   4972 	 FIELD_DECL, apparently.  The G++ front end can put something else
   4973 	 there, at least temporarily.  */
   4974       else if (TREE_CODE (node) == COMPONENT_REF
   4975 	       && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
   4976 	{
   4977 	  if (TREE_OPERAND (node, 2))
   4978 	    UPDATE_FLAGS (TREE_OPERAND (node, 2));
   4979 	}
   4980     }
   4981 
   4982   node = lang_hooks.expr_to_decl (node, &tc, &se);
   4983 
   4984   /* Now see what's inside.  If it's an INDIRECT_REF, copy our properties from
   4985      the address, since &(*a)->b is a form of addition.  If it's a constant, the
   4986      address is constant too.  If it's a decl, its address is constant if the
   4987      decl is static.  Everything else is not constant and, furthermore,
   4988      taking the address of a volatile variable is not volatile.  */
   4989   if (INDIRECT_REF_P (node)
   4990       || TREE_CODE (node) == MEM_REF)
   4991     UPDATE_FLAGS (TREE_OPERAND (node, 0));
   4992   else if (CONSTANT_CLASS_P (node))
   4993     ;
   4994   else if (DECL_P (node))
   4995     tc &= (staticp (node) != NULL_TREE);
   4996   else
   4997     {
   4998       tc = false;
   4999       se |= TREE_SIDE_EFFECTS (node);
   5000     }
   5001 
   5002 
   5003   TREE_CONSTANT (t) = tc;
   5004   TREE_SIDE_EFFECTS (t) = se;
   5005 #undef UPDATE_FLAGS
   5006 }
   5007 
   5008 /* Build an expression of code CODE, data type TYPE, and operands as
   5009    specified.  Expressions and reference nodes can be created this way.
   5010    Constants, decls, types and misc nodes cannot be.
   5011 
   5012    We define 5 non-variadic functions, from 0 to 4 arguments.  This is
   5013    enough for all extant tree codes.  */
   5014 
   5015 tree
   5016 build0 (enum tree_code code, tree tt MEM_STAT_DECL)
   5017 {
   5018   tree t;
   5019 
   5020   gcc_assert (TREE_CODE_LENGTH (code) == 0);
   5021 
   5022   t = make_node (code PASS_MEM_STAT);
   5023   TREE_TYPE (t) = tt;
   5024 
   5025   return t;
   5026 }
   5027 
   5028 tree
   5029 build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
   5030 {
   5031   int length = sizeof (struct tree_exp);
   5032   tree t;
   5033 
   5034   record_node_allocation_statistics (code, length);
   5035 
   5036   gcc_assert (TREE_CODE_LENGTH (code) == 1);
   5037 
   5038   t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
   5039 
   5040   memset (t, 0, sizeof (struct tree_common));
   5041 
   5042   TREE_SET_CODE (t, code);
   5043 
   5044   TREE_TYPE (t) = type;
   5045   SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
   5046   TREE_OPERAND (t, 0) = node;
   5047   if (node && !TYPE_P (node))
   5048     {
   5049       TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
   5050       TREE_READONLY (t) = TREE_READONLY (node);
   5051     }
   5052 
   5053   if (TREE_CODE_CLASS (code) == tcc_statement)
   5054     {
   5055       if (code != DEBUG_BEGIN_STMT)
   5056 	TREE_SIDE_EFFECTS (t) = 1;
   5057     }
   5058   else switch (code)
   5059     {
   5060     case VA_ARG_EXPR:
   5061       /* All of these have side-effects, no matter what their
   5062 	 operands are.  */
   5063       TREE_SIDE_EFFECTS (t) = 1;
   5064       TREE_READONLY (t) = 0;
   5065       break;
   5066 
   5067     case INDIRECT_REF:
   5068       /* Whether a dereference is readonly has nothing to do with whether
   5069 	 its operand is readonly.  */
   5070       TREE_READONLY (t) = 0;
   5071       break;
   5072 
   5073     case ADDR_EXPR:
   5074       if (node)
   5075 	recompute_tree_invariant_for_addr_expr (t);
   5076       break;
   5077 
   5078     default:
   5079       if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
   5080 	  && node && !TYPE_P (node)
   5081 	  && TREE_CONSTANT (node))
   5082 	TREE_CONSTANT (t) = 1;
   5083       if (TREE_CODE_CLASS (code) == tcc_reference
   5084 	  && node && TREE_THIS_VOLATILE (node))
   5085 	TREE_THIS_VOLATILE (t) = 1;
   5086       break;
   5087     }
   5088 
   5089   return t;
   5090 }
   5091 
   5092 #define PROCESS_ARG(N)				\
   5093   do {						\
   5094     TREE_OPERAND (t, N) = arg##N;		\
   5095     if (arg##N &&!TYPE_P (arg##N))		\
   5096       {						\
   5097         if (TREE_SIDE_EFFECTS (arg##N))		\
   5098 	  side_effects = 1;			\
   5099         if (!TREE_READONLY (arg##N)		\
   5100 	    && !CONSTANT_CLASS_P (arg##N))	\
   5101 	  (void) (read_only = 0);		\
   5102         if (!TREE_CONSTANT (arg##N))		\
   5103 	  (void) (constant = 0);		\
   5104       }						\
   5105   } while (0)
   5106 
   5107 tree
   5108 build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
   5109 {
   5110   bool constant, read_only, side_effects, div_by_zero;
   5111   tree t;
   5112 
   5113   gcc_assert (TREE_CODE_LENGTH (code) == 2);
   5114 
   5115   if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
   5116       && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
   5117       /* When sizetype precision doesn't match that of pointers
   5118          we need to be able to build explicit extensions or truncations
   5119 	 of the offset argument.  */
   5120       && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
   5121     gcc_assert (TREE_CODE (arg0) == INTEGER_CST
   5122 		&& TREE_CODE (arg1) == INTEGER_CST);
   5123 
   5124   if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
   5125     gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
   5126 		&& ptrofftype_p (TREE_TYPE (arg1)));
   5127 
   5128   t = make_node (code PASS_MEM_STAT);
   5129   TREE_TYPE (t) = tt;
   5130 
   5131   /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
   5132      result based on those same flags for the arguments.  But if the
   5133      arguments aren't really even `tree' expressions, we shouldn't be trying
   5134      to do this.  */
   5135 
   5136   /* Expressions without side effects may be constant if their
   5137      arguments are as well.  */
   5138   constant = (TREE_CODE_CLASS (code) == tcc_comparison
   5139 	      || TREE_CODE_CLASS (code) == tcc_binary);
   5140   read_only = 1;
   5141   side_effects = TREE_SIDE_EFFECTS (t);
   5142 
   5143   switch (code)
   5144     {
   5145     case TRUNC_DIV_EXPR:
   5146     case CEIL_DIV_EXPR:
   5147     case FLOOR_DIV_EXPR:
   5148     case ROUND_DIV_EXPR:
   5149     case EXACT_DIV_EXPR:
   5150     case CEIL_MOD_EXPR:
   5151     case FLOOR_MOD_EXPR:
   5152     case ROUND_MOD_EXPR:
   5153     case TRUNC_MOD_EXPR:
   5154       div_by_zero = integer_zerop (arg1);
   5155       break;
   5156     default:
   5157       div_by_zero = false;
   5158     }
   5159 
   5160   PROCESS_ARG (0);
   5161   PROCESS_ARG (1);
   5162 
   5163   TREE_SIDE_EFFECTS (t) = side_effects;
   5164   if (code == MEM_REF)
   5165     {
   5166       if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
   5167 	{
   5168 	  tree o = TREE_OPERAND (arg0, 0);
   5169 	  TREE_READONLY (t) = TREE_READONLY (o);
   5170 	  TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
   5171 	}
   5172     }
   5173   else
   5174     {
   5175       TREE_READONLY (t) = read_only;
   5176       /* Don't mark X / 0 as constant.  */
   5177       TREE_CONSTANT (t) = constant && !div_by_zero;
   5178       TREE_THIS_VOLATILE (t)
   5179 	= (TREE_CODE_CLASS (code) == tcc_reference
   5180 	   && arg0 && TREE_THIS_VOLATILE (arg0));
   5181     }
   5182 
   5183   return t;
   5184 }
   5185 
   5186 
   5187 tree
   5188 build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
   5189 	tree arg2 MEM_STAT_DECL)
   5190 {
   5191   bool constant, read_only, side_effects;
   5192   tree t;
   5193 
   5194   gcc_assert (TREE_CODE_LENGTH (code) == 3);
   5195   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
   5196 
   5197   t = make_node (code PASS_MEM_STAT);
   5198   TREE_TYPE (t) = tt;
   5199 
   5200   read_only = 1;
   5201 
   5202   /* As a special exception, if COND_EXPR has NULL branches, we
   5203      assume that it is a gimple statement and always consider
   5204      it to have side effects.  */
   5205   if (code == COND_EXPR
   5206       && tt == void_type_node
   5207       && arg1 == NULL_TREE
   5208       && arg2 == NULL_TREE)
   5209     side_effects = true;
   5210   else
   5211     side_effects = TREE_SIDE_EFFECTS (t);
   5212 
   5213   PROCESS_ARG (0);
   5214   PROCESS_ARG (1);
   5215   PROCESS_ARG (2);
   5216 
   5217   if (code == COND_EXPR)
   5218     TREE_READONLY (t) = read_only;
   5219 
   5220   TREE_SIDE_EFFECTS (t) = side_effects;
   5221   TREE_THIS_VOLATILE (t)
   5222     = (TREE_CODE_CLASS (code) == tcc_reference
   5223        && arg0 && TREE_THIS_VOLATILE (arg0));
   5224 
   5225   return t;
   5226 }
   5227 
   5228 tree
   5229 build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
   5230 	tree arg2, tree arg3 MEM_STAT_DECL)
   5231 {
   5232   bool constant, read_only, side_effects;
   5233   tree t;
   5234 
   5235   gcc_assert (TREE_CODE_LENGTH (code) == 4);
   5236 
   5237   t = make_node (code PASS_MEM_STAT);
   5238   TREE_TYPE (t) = tt;
   5239 
   5240   side_effects = TREE_SIDE_EFFECTS (t);
   5241 
   5242   PROCESS_ARG (0);
   5243   PROCESS_ARG (1);
   5244   PROCESS_ARG (2);
   5245   PROCESS_ARG (3);
   5246 
   5247   TREE_SIDE_EFFECTS (t) = side_effects;
   5248   TREE_THIS_VOLATILE (t)
   5249     = (TREE_CODE_CLASS (code) == tcc_reference
   5250        && arg0 && TREE_THIS_VOLATILE (arg0));
   5251 
   5252   return t;
   5253 }
   5254 
   5255 tree
   5256 build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
   5257 	tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
   5258 {
   5259   bool constant, read_only, side_effects;
   5260   tree t;
   5261 
   5262   gcc_assert (TREE_CODE_LENGTH (code) == 5);
   5263 
   5264   t = make_node (code PASS_MEM_STAT);
   5265   TREE_TYPE (t) = tt;
   5266 
   5267   side_effects = TREE_SIDE_EFFECTS (t);
   5268 
   5269   PROCESS_ARG (0);
   5270   PROCESS_ARG (1);
   5271   PROCESS_ARG (2);
   5272   PROCESS_ARG (3);
   5273   PROCESS_ARG (4);
   5274 
   5275   TREE_SIDE_EFFECTS (t) = side_effects;
   5276   if (code == TARGET_MEM_REF)
   5277     {
   5278       if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
   5279 	{
   5280 	  tree o = TREE_OPERAND (arg0, 0);
   5281 	  TREE_READONLY (t) = TREE_READONLY (o);
   5282 	  TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
   5283 	}
   5284     }
   5285   else
   5286     TREE_THIS_VOLATILE (t)
   5287       = (TREE_CODE_CLASS (code) == tcc_reference
   5288 	 && arg0 && TREE_THIS_VOLATILE (arg0));
   5289 
   5290   return t;
   5291 }
   5292 
   5293 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
   5294    on the pointer PTR.  */
   5295 
   5296 tree
   5297 build_simple_mem_ref_loc (location_t loc, tree ptr)
   5298 {
   5299   poly_int64 offset = 0;
   5300   tree ptype = TREE_TYPE (ptr);
   5301   tree tem;
   5302   /* For convenience allow addresses that collapse to a simple base
   5303      and offset.  */
   5304   if (TREE_CODE (ptr) == ADDR_EXPR
   5305       && (handled_component_p (TREE_OPERAND (ptr, 0))
   5306 	  || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
   5307     {
   5308       ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
   5309       gcc_assert (ptr);
   5310       if (TREE_CODE (ptr) == MEM_REF)
   5311 	{
   5312 	  offset += mem_ref_offset (ptr).force_shwi ();
   5313 	  ptr = TREE_OPERAND (ptr, 0);
   5314 	}
   5315       else
   5316 	ptr = build_fold_addr_expr (ptr);
   5317       gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
   5318     }
   5319   tem = build2 (MEM_REF, TREE_TYPE (ptype),
   5320 		ptr, build_int_cst (ptype, offset));
   5321   SET_EXPR_LOCATION (tem, loc);
   5322   return tem;
   5323 }
   5324 
   5325 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T.  */
   5326 
   5327 poly_offset_int
   5328 mem_ref_offset (const_tree t)
   5329 {
   5330   return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
   5331 				SIGNED);
   5332 }
   5333 
   5334 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
   5335    offsetted by OFFSET units.  */
   5336 
   5337 tree
   5338 build_invariant_address (tree type, tree base, poly_int64 offset)
   5339 {
   5340   tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
   5341 			  build_fold_addr_expr (base),
   5342 			  build_int_cst (ptr_type_node, offset));
   5343   tree addr = build1 (ADDR_EXPR, type, ref);
   5344   recompute_tree_invariant_for_addr_expr (addr);
   5345   return addr;
   5346 }
   5347 
   5348 /* Similar except don't specify the TREE_TYPE
   5349    and leave the TREE_SIDE_EFFECTS as 0.
   5350    It is permissible for arguments to be null,
   5351    or even garbage if their values do not matter.  */
   5352 
   5353 tree
   5354 build_nt (enum tree_code code, ...)
   5355 {
   5356   tree t;
   5357   int length;
   5358   int i;
   5359   va_list p;
   5360 
   5361   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
   5362 
   5363   va_start (p, code);
   5364 
   5365   t = make_node (code);
   5366   length = TREE_CODE_LENGTH (code);
   5367 
   5368   for (i = 0; i < length; i++)
   5369     TREE_OPERAND (t, i) = va_arg (p, tree);
   5370 
   5371   va_end (p);
   5372   return t;
   5373 }
   5374 
   5375 /* Similar to build_nt, but for creating a CALL_EXPR object with a
   5376    tree vec.  */
   5377 
   5378 tree
   5379 build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
   5380 {
   5381   tree ret, t;
   5382   unsigned int ix;
   5383 
   5384   ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
   5385   CALL_EXPR_FN (ret) = fn;
   5386   CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
   5387   FOR_EACH_VEC_SAFE_ELT (args, ix, t)
   5388     CALL_EXPR_ARG (ret, ix) = t;
   5389   return ret;
   5390 }
   5391 
   5392 /* Create a DECL_... node of code CODE, name NAME  (if non-null)
   5394    and data type TYPE.
   5395    We do NOT enter this node in any sort of symbol table.
   5396 
   5397    LOC is the location of the decl.
   5398 
   5399    layout_decl is used to set up the decl's storage layout.
   5400    Other slots are initialized to 0 or null pointers.  */
   5401 
   5402 tree
   5403 build_decl (location_t loc, enum tree_code code, tree name,
   5404     		 tree type MEM_STAT_DECL)
   5405 {
   5406   tree t;
   5407 
   5408   t = make_node (code PASS_MEM_STAT);
   5409   DECL_SOURCE_LOCATION (t) = loc;
   5410 
   5411 /*  if (type == error_mark_node)
   5412     type = integer_type_node; */
   5413 /* That is not done, deliberately, so that having error_mark_node
   5414    as the type can suppress useless errors in the use of this variable.  */
   5415 
   5416   DECL_NAME (t) = name;
   5417   TREE_TYPE (t) = type;
   5418 
   5419   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
   5420     layout_decl (t, 0);
   5421 
   5422   return t;
   5423 }
   5424 
   5425 /* Create and return a DEBUG_EXPR_DECL node of the given TYPE.  */
   5426 
   5427 tree
   5428 build_debug_expr_decl (tree type)
   5429 {
   5430   tree vexpr = make_node (DEBUG_EXPR_DECL);
   5431   DECL_ARTIFICIAL (vexpr) = 1;
   5432   TREE_TYPE (vexpr) = type;
   5433   SET_DECL_MODE (vexpr, TYPE_MODE (type));
   5434   return vexpr;
   5435 }
   5436 
   5437 /* Builds and returns function declaration with NAME and TYPE.  */
   5438 
   5439 tree
   5440 build_fn_decl (const char *name, tree type)
   5441 {
   5442   tree id = get_identifier (name);
   5443   tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
   5444 
   5445   DECL_EXTERNAL (decl) = 1;
   5446   TREE_PUBLIC (decl) = 1;
   5447   DECL_ARTIFICIAL (decl) = 1;
   5448   TREE_NOTHROW (decl) = 1;
   5449 
   5450   return decl;
   5451 }
   5452 
   5453 vec<tree, va_gc> *all_translation_units;
   5454 
   5455 /* Builds a new translation-unit decl with name NAME, queues it in the
   5456    global list of translation-unit decls and returns it.   */
   5457 
   5458 tree
   5459 build_translation_unit_decl (tree name)
   5460 {
   5461   tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
   5462 			name, NULL_TREE);
   5463   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
   5464   vec_safe_push (all_translation_units, tu);
   5465   return tu;
   5466 }
   5467 
   5468 
   5469 /* BLOCK nodes are used to represent the structure of binding contours
   5471    and declarations, once those contours have been exited and their contents
   5472    compiled.  This information is used for outputting debugging info.  */
   5473 
   5474 tree
   5475 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
   5476 {
   5477   tree block = make_node (BLOCK);
   5478 
   5479   BLOCK_VARS (block) = vars;
   5480   BLOCK_SUBBLOCKS (block) = subblocks;
   5481   BLOCK_SUPERCONTEXT (block) = supercontext;
   5482   BLOCK_CHAIN (block) = chain;
   5483   return block;
   5484 }
   5485 
   5486 
   5487 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
   5489 
   5490    LOC is the location to use in tree T.  */
   5491 
   5492 void
   5493 protected_set_expr_location (tree t, location_t loc)
   5494 {
   5495   if (CAN_HAVE_LOCATION_P (t))
   5496     SET_EXPR_LOCATION (t, loc);
   5497   else if (t && TREE_CODE (t) == STATEMENT_LIST)
   5498     {
   5499       t = expr_single (t);
   5500       if (t && CAN_HAVE_LOCATION_P (t))
   5501 	SET_EXPR_LOCATION (t, loc);
   5502     }
   5503 }
   5504 
   5505 /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
   5506    UNKNOWN_LOCATION.  */
   5507 
   5508 void
   5509 protected_set_expr_location_if_unset (tree t, location_t loc)
   5510 {
   5511   t = expr_single (t);
   5512   if (t && !EXPR_HAS_LOCATION (t))
   5513     protected_set_expr_location (t, loc);
   5514 }
   5515 
   5516 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
   5518    of the various TYPE_QUAL values.  */
   5519 
   5520 static void
   5521 set_type_quals (tree type, int type_quals)
   5522 {
   5523   TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
   5524   TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   5525   TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
   5526   TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
   5527   TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
   5528 }
   5529 
   5530 /* Returns true iff CAND and BASE have equivalent language-specific
   5531    qualifiers.  */
   5532 
   5533 bool
   5534 check_lang_type (const_tree cand, const_tree base)
   5535 {
   5536   if (lang_hooks.types.type_hash_eq == NULL)
   5537     return true;
   5538   /* type_hash_eq currently only applies to these types.  */
   5539   if (TREE_CODE (cand) != FUNCTION_TYPE
   5540       && TREE_CODE (cand) != METHOD_TYPE)
   5541     return true;
   5542   return lang_hooks.types.type_hash_eq (cand, base);
   5543 }
   5544 
   5545 /* This function checks to see if TYPE matches the size one of the built-in
   5546    atomic types, and returns that core atomic type.  */
   5547 
   5548 static tree
   5549 find_atomic_core_type (const_tree type)
   5550 {
   5551   tree base_atomic_type;
   5552 
   5553   /* Only handle complete types.  */
   5554   if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
   5555     return NULL_TREE;
   5556 
   5557   switch (tree_to_uhwi (TYPE_SIZE (type)))
   5558     {
   5559     case 8:
   5560       base_atomic_type = atomicQI_type_node;
   5561       break;
   5562 
   5563     case 16:
   5564       base_atomic_type = atomicHI_type_node;
   5565       break;
   5566 
   5567     case 32:
   5568       base_atomic_type = atomicSI_type_node;
   5569       break;
   5570 
   5571     case 64:
   5572       base_atomic_type = atomicDI_type_node;
   5573       break;
   5574 
   5575     case 128:
   5576       base_atomic_type = atomicTI_type_node;
   5577       break;
   5578 
   5579     default:
   5580       base_atomic_type = NULL_TREE;
   5581     }
   5582 
   5583   return base_atomic_type;
   5584 }
   5585 
   5586 /* Returns true iff unqualified CAND and BASE are equivalent.  */
   5587 
   5588 bool
   5589 check_base_type (const_tree cand, const_tree base)
   5590 {
   5591   if (TYPE_NAME (cand) != TYPE_NAME (base)
   5592       /* Apparently this is needed for Objective-C.  */
   5593       || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
   5594       || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
   5595 			        TYPE_ATTRIBUTES (base)))
   5596     return false;
   5597   /* Check alignment.  */
   5598   if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
   5599       && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
   5600     return true;
   5601   /* Atomic types increase minimal alignment.  We must to do so as well
   5602      or we get duplicated canonical types. See PR88686.  */
   5603   if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
   5604     {
   5605       /* See if this object can map to a basic atomic type.  */
   5606       tree atomic_type = find_atomic_core_type (cand);
   5607       if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
   5608        return true;
   5609     }
   5610   return false;
   5611 }
   5612 
   5613 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS.  */
   5614 
   5615 bool
   5616 check_qualified_type (const_tree cand, const_tree base, int type_quals)
   5617 {
   5618   return (TYPE_QUALS (cand) == type_quals
   5619 	  && check_base_type (cand, base)
   5620 	  && check_lang_type (cand, base));
   5621 }
   5622 
   5623 /* Returns true iff CAND is equivalent to BASE with ALIGN.  */
   5624 
   5625 static bool
   5626 check_aligned_type (const_tree cand, const_tree base, unsigned int align)
   5627 {
   5628   return (TYPE_QUALS (cand) == TYPE_QUALS (base)
   5629 	  && TYPE_NAME (cand) == TYPE_NAME (base)
   5630 	  /* Apparently this is needed for Objective-C.  */
   5631 	  && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
   5632 	  /* Check alignment.  */
   5633 	  && TYPE_ALIGN (cand) == align
   5634 	  /* Check this is a user-aligned type as build_aligned_type
   5635 	     would create.  */
   5636 	  && TYPE_USER_ALIGN (cand)
   5637 	  && attribute_list_equal (TYPE_ATTRIBUTES (cand),
   5638 				   TYPE_ATTRIBUTES (base))
   5639 	  && check_lang_type (cand, base));
   5640 }
   5641 
   5642 /* Return a version of the TYPE, qualified as indicated by the
   5643    TYPE_QUALS, if one exists.  If no qualified version exists yet,
   5644    return NULL_TREE.  */
   5645 
   5646 tree
   5647 get_qualified_type (tree type, int type_quals)
   5648 {
   5649   if (TYPE_QUALS (type) == type_quals)
   5650     return type;
   5651 
   5652   tree mv = TYPE_MAIN_VARIANT (type);
   5653   if (check_qualified_type (mv, type, type_quals))
   5654     return mv;
   5655 
   5656   /* Search the chain of variants to see if there is already one there just
   5657      like the one we need to have.  If so, use that existing one.  We must
   5658      preserve the TYPE_NAME, since there is code that depends on this.  */
   5659   for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
   5660     if (check_qualified_type (*tp, type, type_quals))
   5661       {
   5662 	/* Put the found variant at the head of the variant list so
   5663 	   frequently searched variants get found faster.  The C++ FE
   5664 	   benefits greatly from this.  */
   5665 	tree t = *tp;
   5666 	*tp = TYPE_NEXT_VARIANT (t);
   5667 	TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
   5668 	TYPE_NEXT_VARIANT (mv) = t;
   5669 	return t;
   5670       }
   5671 
   5672   return NULL_TREE;
   5673 }
   5674 
   5675 /* Like get_qualified_type, but creates the type if it does not
   5676    exist.  This function never returns NULL_TREE.  */
   5677 
   5678 tree
   5679 build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
   5680 {
   5681   tree t;
   5682 
   5683   /* See if we already have the appropriate qualified variant.  */
   5684   t = get_qualified_type (type, type_quals);
   5685 
   5686   /* If not, build it.  */
   5687   if (!t)
   5688     {
   5689       t = build_variant_type_copy (type PASS_MEM_STAT);
   5690       set_type_quals (t, type_quals);
   5691 
   5692       if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
   5693 	{
   5694 	  /* See if this object can map to a basic atomic type.  */
   5695 	  tree atomic_type = find_atomic_core_type (type);
   5696 	  if (atomic_type)
   5697 	    {
   5698 	      /* Ensure the alignment of this type is compatible with
   5699 		 the required alignment of the atomic type.  */
   5700 	      if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
   5701 		SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
   5702 	    }
   5703 	}
   5704 
   5705       if (TYPE_STRUCTURAL_EQUALITY_P (type))
   5706 	/* Propagate structural equality. */
   5707 	SET_TYPE_STRUCTURAL_EQUALITY (t);
   5708       else if (TYPE_CANONICAL (type) != type)
   5709 	/* Build the underlying canonical type, since it is different
   5710 	   from TYPE. */
   5711 	{
   5712 	  tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
   5713 	  TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
   5714 	}
   5715       else
   5716 	/* T is its own canonical type. */
   5717 	TYPE_CANONICAL (t) = t;
   5718 
   5719     }
   5720 
   5721   return t;
   5722 }
   5723 
   5724 /* Create a variant of type T with alignment ALIGN which
   5725    is measured in bits.  */
   5726 
   5727 tree
   5728 build_aligned_type (tree type, unsigned int align)
   5729 {
   5730   tree t;
   5731 
   5732   if (TYPE_PACKED (type)
   5733       || TYPE_ALIGN (type) == align)
   5734     return type;
   5735 
   5736   for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   5737     if (check_aligned_type (t, type, align))
   5738       return t;
   5739 
   5740   t = build_variant_type_copy (type);
   5741   SET_TYPE_ALIGN (t, align);
   5742   TYPE_USER_ALIGN (t) = 1;
   5743 
   5744   return t;
   5745 }
   5746 
   5747 /* Create a new distinct copy of TYPE.  The new type is made its own
   5748    MAIN_VARIANT. If TYPE requires structural equality checks, the
   5749    resulting type requires structural equality checks; otherwise, its
   5750    TYPE_CANONICAL points to itself. */
   5751 
   5752 tree
   5753 build_distinct_type_copy (tree type MEM_STAT_DECL)
   5754 {
   5755   tree t = copy_node (type PASS_MEM_STAT);
   5756 
   5757   TYPE_POINTER_TO (t) = 0;
   5758   TYPE_REFERENCE_TO (t) = 0;
   5759 
   5760   /* Set the canonical type either to a new equivalence class, or
   5761      propagate the need for structural equality checks. */
   5762   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   5763     SET_TYPE_STRUCTURAL_EQUALITY (t);
   5764   else
   5765     TYPE_CANONICAL (t) = t;
   5766 
   5767   /* Make it its own variant.  */
   5768   TYPE_MAIN_VARIANT (t) = t;
   5769   TYPE_NEXT_VARIANT (t) = 0;
   5770 
   5771   /* Note that it is now possible for TYPE_MIN_VALUE to be a value
   5772      whose TREE_TYPE is not t.  This can also happen in the Ada
   5773      frontend when using subtypes.  */
   5774 
   5775   return t;
   5776 }
   5777 
   5778 /* Create a new variant of TYPE, equivalent but distinct.  This is so
   5779    the caller can modify it. TYPE_CANONICAL for the return type will
   5780    be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
   5781    are considered equal by the language itself (or that both types
   5782    require structural equality checks). */
   5783 
   5784 tree
   5785 build_variant_type_copy (tree type MEM_STAT_DECL)
   5786 {
   5787   tree t, m = TYPE_MAIN_VARIANT (type);
   5788 
   5789   t = build_distinct_type_copy (type PASS_MEM_STAT);
   5790 
   5791   /* Since we're building a variant, assume that it is a non-semantic
   5792      variant.  This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
   5793   TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
   5794   /* Type variants have no alias set defined.  */
   5795   TYPE_ALIAS_SET (t) = -1;
   5796 
   5797   /* Add the new type to the chain of variants of TYPE.  */
   5798   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
   5799   TYPE_NEXT_VARIANT (m) = t;
   5800   TYPE_MAIN_VARIANT (t) = m;
   5801 
   5802   return t;
   5803 }
   5804 
   5805 /* Return true if the from tree in both tree maps are equal.  */
   5807 
   5808 int
   5809 tree_map_base_eq (const void *va, const void *vb)
   5810 {
   5811   const struct tree_map_base  *const a = (const struct tree_map_base *) va,
   5812     *const b = (const struct tree_map_base *) vb;
   5813   return (a->from == b->from);
   5814 }
   5815 
   5816 /* Hash a from tree in a tree_base_map.  */
   5817 
   5818 unsigned int
   5819 tree_map_base_hash (const void *item)
   5820 {
   5821   return htab_hash_pointer (((const struct tree_map_base *)item)->from);
   5822 }
   5823 
   5824 /* Return true if this tree map structure is marked for garbage collection
   5825    purposes.  We simply return true if the from tree is marked, so that this
   5826    structure goes away when the from tree goes away.  */
   5827 
   5828 bool
   5829 tree_map_base_marked_p (const void *p)
   5830 {
   5831   return ggc_marked_p (((const struct tree_map_base *) p)->from);
   5832 }
   5833 
   5834 /* Hash a from tree in a tree_map.  */
   5835 
   5836 unsigned int
   5837 tree_map_hash (const void *item)
   5838 {
   5839   return (((const struct tree_map *) item)->hash);
   5840 }
   5841 
   5842 /* Hash a from tree in a tree_decl_map.  */
   5843 
   5844 unsigned int
   5845 tree_decl_map_hash (const void *item)
   5846 {
   5847   return DECL_UID (((const struct tree_decl_map *) item)->base.from);
   5848 }
   5849 
   5850 /* Return the initialization priority for DECL.  */
   5851 
   5852 priority_type
   5853 decl_init_priority_lookup (tree decl)
   5854 {
   5855   symtab_node *snode = symtab_node::get (decl);
   5856 
   5857   if (!snode)
   5858     return DEFAULT_INIT_PRIORITY;
   5859   return
   5860     snode->get_init_priority ();
   5861 }
   5862 
   5863 /* Return the finalization priority for DECL.  */
   5864 
   5865 priority_type
   5866 decl_fini_priority_lookup (tree decl)
   5867 {
   5868   cgraph_node *node = cgraph_node::get (decl);
   5869 
   5870   if (!node)
   5871     return DEFAULT_INIT_PRIORITY;
   5872   return
   5873     node->get_fini_priority ();
   5874 }
   5875 
   5876 /* Set the initialization priority for DECL to PRIORITY.  */
   5877 
   5878 void
   5879 decl_init_priority_insert (tree decl, priority_type priority)
   5880 {
   5881   struct symtab_node *snode;
   5882 
   5883   if (priority == DEFAULT_INIT_PRIORITY)
   5884     {
   5885       snode = symtab_node::get (decl);
   5886       if (!snode)
   5887 	return;
   5888     }
   5889   else if (VAR_P (decl))
   5890     snode = varpool_node::get_create (decl);
   5891   else
   5892     snode = cgraph_node::get_create (decl);
   5893   snode->set_init_priority (priority);
   5894 }
   5895 
   5896 /* Set the finalization priority for DECL to PRIORITY.  */
   5897 
   5898 void
   5899 decl_fini_priority_insert (tree decl, priority_type priority)
   5900 {
   5901   struct cgraph_node *node;
   5902 
   5903   if (priority == DEFAULT_INIT_PRIORITY)
   5904     {
   5905       node = cgraph_node::get (decl);
   5906       if (!node)
   5907 	return;
   5908     }
   5909   else
   5910     node = cgraph_node::get_create (decl);
   5911   node->set_fini_priority (priority);
   5912 }
   5913 
   5914 /* Print out the statistics for the DECL_DEBUG_EXPR hash table.  */
   5915 
   5916 static void
   5917 print_debug_expr_statistics (void)
   5918 {
   5919   fprintf (stderr, "DECL_DEBUG_EXPR  hash: size " HOST_SIZE_T_PRINT_DEC ", "
   5920 	   HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
   5921 	   (fmt_size_t) debug_expr_for_decl->size (),
   5922 	   (fmt_size_t) debug_expr_for_decl->elements (),
   5923 	   debug_expr_for_decl->collisions ());
   5924 }
   5925 
   5926 /* Print out the statistics for the DECL_VALUE_EXPR hash table.  */
   5927 
   5928 static void
   5929 print_value_expr_statistics (void)
   5930 {
   5931   fprintf (stderr, "DECL_VALUE_EXPR  hash: size " HOST_SIZE_T_PRINT_DEC ", "
   5932 	   HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
   5933 	   (fmt_size_t) value_expr_for_decl->size (),
   5934 	   (fmt_size_t) value_expr_for_decl->elements (),
   5935 	   value_expr_for_decl->collisions ());
   5936 }
   5937 
   5938 /* Lookup a debug expression for FROM, and return it if we find one.  */
   5939 
   5940 tree
   5941 decl_debug_expr_lookup (tree from)
   5942 {
   5943   struct tree_decl_map *h, in;
   5944   in.base.from = from;
   5945 
   5946   h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
   5947   if (h)
   5948     return h->to;
   5949   return NULL_TREE;
   5950 }
   5951 
   5952 /* Insert a mapping FROM->TO in the debug expression hashtable.  */
   5953 
   5954 void
   5955 decl_debug_expr_insert (tree from, tree to)
   5956 {
   5957   struct tree_decl_map *h;
   5958 
   5959   h = ggc_alloc<tree_decl_map> ();
   5960   h->base.from = from;
   5961   h->to = to;
   5962   *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
   5963 }
   5964 
   5965 /* Lookup a value expression for FROM, and return it if we find one.  */
   5966 
   5967 tree
   5968 decl_value_expr_lookup (tree from)
   5969 {
   5970   struct tree_decl_map *h, in;
   5971   in.base.from = from;
   5972 
   5973   h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
   5974   if (h)
   5975     return h->to;
   5976   return NULL_TREE;
   5977 }
   5978 
   5979 /* Insert a mapping FROM->TO in the value expression hashtable.  */
   5980 
   5981 void
   5982 decl_value_expr_insert (tree from, tree to)
   5983 {
   5984   struct tree_decl_map *h;
   5985 
   5986   /* Uses of FROM shouldn't look like they happen at the location of TO.  */
   5987   to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
   5988 
   5989   h = ggc_alloc<tree_decl_map> ();
   5990   h->base.from = from;
   5991   h->to = to;
   5992   *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
   5993 }
   5994 
   5995 /* Lookup a vector of debug arguments for FROM, and return it if we
   5996    find one.  */
   5997 
   5998 vec<tree, va_gc> **
   5999 decl_debug_args_lookup (tree from)
   6000 {
   6001   struct tree_vec_map *h, in;
   6002 
   6003   if (!DECL_HAS_DEBUG_ARGS_P (from))
   6004     return NULL;
   6005   gcc_checking_assert (debug_args_for_decl != NULL);
   6006   in.base.from = from;
   6007   h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
   6008   if (h)
   6009     return &h->to;
   6010   return NULL;
   6011 }
   6012 
   6013 /* Insert a mapping FROM->empty vector of debug arguments in the value
   6014    expression hashtable.  */
   6015 
   6016 vec<tree, va_gc> **
   6017 decl_debug_args_insert (tree from)
   6018 {
   6019   struct tree_vec_map *h;
   6020   tree_vec_map **loc;
   6021 
   6022   if (DECL_HAS_DEBUG_ARGS_P (from))
   6023     return decl_debug_args_lookup (from);
   6024   if (debug_args_for_decl == NULL)
   6025     debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
   6026   h = ggc_alloc<tree_vec_map> ();
   6027   h->base.from = from;
   6028   h->to = NULL;
   6029   loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
   6030   *loc = h;
   6031   DECL_HAS_DEBUG_ARGS_P (from) = 1;
   6032   return &h->to;
   6033 }
   6034 
   6035 /* Hashing of types so that we don't make duplicates.
   6036    The entry point is `type_hash_canon'.  */
   6037 
   6038 /* Generate the default hash code for TYPE.  This is designed for
   6039    speed, rather than maximum entropy.  */
   6040 
   6041 hashval_t
   6042 type_hash_canon_hash (tree type)
   6043 {
   6044   inchash::hash hstate;
   6045 
   6046   hstate.add_int (TREE_CODE (type));
   6047 
   6048   hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
   6049 
   6050   if (TREE_TYPE (type))
   6051     hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
   6052 
   6053   for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
   6054     /* Just the identifier is adequate to distinguish.  */
   6055     hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
   6056 
   6057   switch (TREE_CODE (type))
   6058     {
   6059     case METHOD_TYPE:
   6060       hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
   6061       /* FALLTHROUGH. */
   6062     case FUNCTION_TYPE:
   6063       for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
   6064 	if (TREE_VALUE (t) != error_mark_node)
   6065 	  hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
   6066       break;
   6067 
   6068     case OFFSET_TYPE:
   6069       hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
   6070       break;
   6071 
   6072     case ARRAY_TYPE:
   6073       {
   6074 	if (TYPE_DOMAIN (type))
   6075 	  hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
   6076 	if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
   6077 	  {
   6078 	    unsigned typeless = TYPE_TYPELESS_STORAGE (type);
   6079 	    hstate.add_object (typeless);
   6080 	  }
   6081       }
   6082       break;
   6083 
   6084     case INTEGER_TYPE:
   6085       {
   6086 	tree t = TYPE_MAX_VALUE (type);
   6087 	if (!t)
   6088 	  t = TYPE_MIN_VALUE (type);
   6089 	for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
   6090 	  hstate.add_object (TREE_INT_CST_ELT (t, i));
   6091 	break;
   6092       }
   6093 
   6094     case BITINT_TYPE:
   6095       {
   6096 	unsigned prec = TYPE_PRECISION (type);
   6097 	unsigned uns = TYPE_UNSIGNED (type);
   6098 	hstate.add_object (prec);
   6099 	hstate.add_int (uns);
   6100 	break;
   6101       }
   6102 
   6103     case REAL_TYPE:
   6104     case FIXED_POINT_TYPE:
   6105       {
   6106 	unsigned prec = TYPE_PRECISION (type);
   6107 	hstate.add_object (prec);
   6108 	break;
   6109       }
   6110 
   6111     case VECTOR_TYPE:
   6112       hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
   6113       break;
   6114 
   6115     default:
   6116       break;
   6117     }
   6118 
   6119   return hstate.end ();
   6120 }
   6121 
   6122 /* These are the Hashtable callback functions.  */
   6123 
   6124 /* Returns true iff the types are equivalent.  */
   6125 
   6126 bool
   6127 type_cache_hasher::equal (type_hash *a, type_hash *b)
   6128 {
   6129   /* First test the things that are the same for all types.  */
   6130   if (a->hash != b->hash
   6131       || TREE_CODE (a->type) != TREE_CODE (b->type)
   6132       || TREE_TYPE (a->type) != TREE_TYPE (b->type)
   6133       || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
   6134 				 TYPE_ATTRIBUTES (b->type))
   6135       || (TREE_CODE (a->type) != COMPLEX_TYPE
   6136           && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
   6137     return false;
   6138 
   6139   /* Be careful about comparing arrays before and after the element type
   6140      has been completed; don't compare TYPE_ALIGN unless both types are
   6141      complete.  */
   6142   if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
   6143       && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
   6144 	  || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
   6145     return false;
   6146 
   6147   if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
   6148       != TYPE_STRUCTURAL_EQUALITY_P (b->type))
   6149     return false;
   6150 
   6151   switch (TREE_CODE (a->type))
   6152     {
   6153     case VOID_TYPE:
   6154     case OPAQUE_TYPE:
   6155     case COMPLEX_TYPE:
   6156     case POINTER_TYPE:
   6157     case REFERENCE_TYPE:
   6158     case NULLPTR_TYPE:
   6159       return true;
   6160 
   6161     case VECTOR_TYPE:
   6162       return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
   6163 		       TYPE_VECTOR_SUBPARTS (b->type));
   6164 
   6165     case ENUMERAL_TYPE:
   6166       if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
   6167 	  && !(TYPE_VALUES (a->type)
   6168 	       && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
   6169 	       && TYPE_VALUES (b->type)
   6170 	       && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
   6171 	       && type_list_equal (TYPE_VALUES (a->type),
   6172 				   TYPE_VALUES (b->type))))
   6173 	return false;
   6174 
   6175       /* fall through */
   6176 
   6177     case INTEGER_TYPE:
   6178     case REAL_TYPE:
   6179     case BOOLEAN_TYPE:
   6180       if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
   6181 	return false;
   6182       return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
   6183 	       || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
   6184 				      TYPE_MAX_VALUE (b->type)))
   6185 	      && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
   6186 		  || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
   6187 					 TYPE_MIN_VALUE (b->type))));
   6188 
   6189     case BITINT_TYPE:
   6190       if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
   6191 	return false;
   6192       return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
   6193 
   6194     case FIXED_POINT_TYPE:
   6195       return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
   6196 
   6197     case OFFSET_TYPE:
   6198       return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
   6199 
   6200     case METHOD_TYPE:
   6201       if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
   6202 	  && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
   6203 	      || (TYPE_ARG_TYPES (a->type)
   6204 		  && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
   6205 		  && TYPE_ARG_TYPES (b->type)
   6206 		  && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
   6207 		  && type_list_equal (TYPE_ARG_TYPES (a->type),
   6208 				      TYPE_ARG_TYPES (b->type)))))
   6209         break;
   6210       return false;
   6211     case ARRAY_TYPE:
   6212       /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
   6213 	 where the flag should be inherited from the element type
   6214 	 and can change after ARRAY_TYPEs are created; on non-aggregates
   6215 	 compare it and hash it, scalars will never have that flag set
   6216 	 and we need to differentiate between arrays created by different
   6217 	 front-ends or middle-end created arrays.  */
   6218       return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
   6219 	      && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
   6220 		  || (TYPE_TYPELESS_STORAGE (a->type)
   6221 		      == TYPE_TYPELESS_STORAGE (b->type))));
   6222 
   6223     case RECORD_TYPE:
   6224     case UNION_TYPE:
   6225     case QUAL_UNION_TYPE:
   6226       return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
   6227 	      || (TYPE_FIELDS (a->type)
   6228 		  && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
   6229 		  && TYPE_FIELDS (b->type)
   6230 		  && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
   6231 		  && type_list_equal (TYPE_FIELDS (a->type),
   6232 				      TYPE_FIELDS (b->type))));
   6233 
   6234     case FUNCTION_TYPE:
   6235       if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
   6236 	   && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
   6237 	       == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
   6238 	  || (TYPE_ARG_TYPES (a->type)
   6239 	      && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
   6240 	      && TYPE_ARG_TYPES (b->type)
   6241 	      && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
   6242 	      && type_list_equal (TYPE_ARG_TYPES (a->type),
   6243 				  TYPE_ARG_TYPES (b->type))))
   6244 	break;
   6245       return false;
   6246 
   6247     default:
   6248       return false;
   6249     }
   6250 
   6251   if (lang_hooks.types.type_hash_eq != NULL)
   6252     return lang_hooks.types.type_hash_eq (a->type, b->type);
   6253 
   6254   return true;
   6255 }
   6256 
   6257 /* Given TYPE, and HASHCODE its hash code, return the canonical
   6258    object for an identical type if one already exists.
   6259    Otherwise, return TYPE, and record it as the canonical object.
   6260 
   6261    To use this function, first create a type of the sort you want.
   6262    Then compute its hash code from the fields of the type that
   6263    make it different from other similar types.
   6264    Then call this function and use the value.  */
   6265 
   6266 tree
   6267 type_hash_canon (unsigned int hashcode, tree type)
   6268 {
   6269   type_hash in;
   6270   type_hash **loc;
   6271 
   6272   /* The hash table only contains main variants, so ensure that's what we're
   6273      being passed.  */
   6274   gcc_assert (TYPE_MAIN_VARIANT (type) == type);
   6275 
   6276   /* The TYPE_ALIGN field of a type is set by layout_type(), so we
   6277      must call that routine before comparing TYPE_ALIGNs.  */
   6278   layout_type (type);
   6279 
   6280   in.hash = hashcode;
   6281   in.type = type;
   6282 
   6283   loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
   6284   if (*loc)
   6285     {
   6286       tree t1 = ((type_hash *) *loc)->type;
   6287       gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
   6288 		  && t1 != type);
   6289       if (TYPE_UID (type) + 1 == next_type_uid)
   6290 	--next_type_uid;
   6291       /* Free also min/max values and the cache for integer
   6292 	 types.  This can't be done in free_node, as LTO frees
   6293 	 those on its own.  */
   6294       if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
   6295 	{
   6296 	  if (TYPE_MIN_VALUE (type)
   6297 	      && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
   6298 	    {
   6299 	      /* Zero is always in TYPE_CACHED_VALUES.  */
   6300 	      if (! TYPE_UNSIGNED (type))
   6301 		int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
   6302 	      ggc_free (TYPE_MIN_VALUE (type));
   6303 	    }
   6304 	  if (TYPE_MAX_VALUE (type)
   6305 	      && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
   6306 	    {
   6307 	      int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
   6308 	      ggc_free (TYPE_MAX_VALUE (type));
   6309 	    }
   6310 	  if (TYPE_CACHED_VALUES_P (type))
   6311 	    ggc_free (TYPE_CACHED_VALUES (type));
   6312 	}
   6313       free_node (type);
   6314       return t1;
   6315     }
   6316   else
   6317     {
   6318       struct type_hash *h;
   6319 
   6320       h = ggc_alloc<type_hash> ();
   6321       h->hash = hashcode;
   6322       h->type = type;
   6323       *loc = h;
   6324 
   6325       return type;
   6326     }
   6327 }
   6328 
   6329 static void
   6330 print_type_hash_statistics (void)
   6331 {
   6332   fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
   6333 	   HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
   6334 	   (fmt_size_t) type_hash_table->size (),
   6335 	   (fmt_size_t) type_hash_table->elements (),
   6336 	   type_hash_table->collisions ());
   6337 }
   6338 
   6339 /* Given two lists of types
   6340    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
   6341    return 1 if the lists contain the same types in the same order.
   6342    Also, the TREE_PURPOSEs must match.  */
   6343 
   6344 bool
   6345 type_list_equal (const_tree l1, const_tree l2)
   6346 {
   6347   const_tree t1, t2;
   6348 
   6349   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
   6350     if (TREE_VALUE (t1) != TREE_VALUE (t2)
   6351 	|| (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
   6352 	    && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
   6353 		  && (TREE_TYPE (TREE_PURPOSE (t1))
   6354 		      == TREE_TYPE (TREE_PURPOSE (t2))))))
   6355       return false;
   6356 
   6357   return t1 == t2;
   6358 }
   6359 
   6360 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
   6361    given by TYPE.  If the argument list accepts variable arguments,
   6362    then this function counts only the ordinary arguments.  */
   6363 
   6364 int
   6365 type_num_arguments (const_tree fntype)
   6366 {
   6367   int i = 0;
   6368 
   6369   for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
   6370     /* If the function does not take a variable number of arguments,
   6371        the last element in the list will have type `void'.  */
   6372     if (VOID_TYPE_P (TREE_VALUE (t)))
   6373       break;
   6374     else
   6375       ++i;
   6376 
   6377   return i;
   6378 }
   6379 
   6380 /* Return the type of the function TYPE's argument ARGNO if known.
   6381    For vararg function's where ARGNO refers to one of the variadic
   6382    arguments return null.  Otherwise, return a void_type_node for
   6383    out-of-bounds ARGNO.  */
   6384 
   6385 tree
   6386 type_argument_type (const_tree fntype, unsigned argno)
   6387 {
   6388   /* Treat zero the same as an out-of-bounds argument number.  */
   6389   if (!argno)
   6390     return void_type_node;
   6391 
   6392   function_args_iterator iter;
   6393 
   6394   tree argtype;
   6395   unsigned i = 1;
   6396   FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
   6397     {
   6398       /* A vararg function's argument list ends in a null.  Otherwise,
   6399 	 an ordinary function's argument list ends with void.  Return
   6400 	 null if ARGNO refers to a vararg argument, void_type_node if
   6401 	 it's out of bounds, and the formal argument type otherwise.  */
   6402       if (!argtype)
   6403 	break;
   6404 
   6405       if (i == argno || VOID_TYPE_P (argtype))
   6406 	return argtype;
   6407 
   6408       ++i;
   6409     }
   6410 
   6411   return NULL_TREE;
   6412 }
   6413 
   6414 /* True if integer constants T1 and T2
   6415    represent the same constant value.  */
   6416 
   6417 bool
   6418 tree_int_cst_equal (const_tree t1, const_tree t2)
   6419 {
   6420   if (t1 == t2)
   6421     return true;
   6422 
   6423   if (t1 == 0 || t2 == 0)
   6424     return false;
   6425 
   6426   STRIP_ANY_LOCATION_WRAPPER (t1);
   6427   STRIP_ANY_LOCATION_WRAPPER (t2);
   6428 
   6429   if (TREE_CODE (t1) == INTEGER_CST
   6430       && TREE_CODE (t2) == INTEGER_CST
   6431       && wi::to_widest (t1) == wi::to_widest (t2))
   6432     return true;
   6433 
   6434   return false;
   6435 }
   6436 
   6437 /* Return true if T is an INTEGER_CST whose numerical value (extended
   6438    according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT.  */
   6439 
   6440 bool
   6441 tree_fits_shwi_p (const_tree t)
   6442 {
   6443   return (t != NULL_TREE
   6444 	  && TREE_CODE (t) == INTEGER_CST
   6445 	  && wi::fits_shwi_p (wi::to_widest (t)));
   6446 }
   6447 
   6448 /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
   6449    value (extended according to TYPE_UNSIGNED) fits in a poly_int64.  */
   6450 
   6451 bool
   6452 tree_fits_poly_int64_p (const_tree t)
   6453 {
   6454   if (t == NULL_TREE)
   6455     return false;
   6456   if (POLY_INT_CST_P (t))
   6457     {
   6458       for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
   6459 	if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
   6460 	  return false;
   6461       return true;
   6462     }
   6463   return (TREE_CODE (t) == INTEGER_CST
   6464 	  && wi::fits_shwi_p (wi::to_widest (t)));
   6465 }
   6466 
   6467 /* Return true if T is an INTEGER_CST whose numerical value (extended
   6468    according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT.  */
   6469 
   6470 bool
   6471 tree_fits_uhwi_p (const_tree t)
   6472 {
   6473   return (t != NULL_TREE
   6474 	  && TREE_CODE (t) == INTEGER_CST
   6475 	  && wi::fits_uhwi_p (wi::to_widest (t)));
   6476 }
   6477 
   6478 /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
   6479    value (extended according to TYPE_UNSIGNED) fits in a poly_uint64.  */
   6480 
   6481 bool
   6482 tree_fits_poly_uint64_p (const_tree t)
   6483 {
   6484   if (t == NULL_TREE)
   6485     return false;
   6486   if (POLY_INT_CST_P (t))
   6487     {
   6488       for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
   6489 	if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
   6490 	  return false;
   6491       return true;
   6492     }
   6493   return (TREE_CODE (t) == INTEGER_CST
   6494 	  && wi::fits_uhwi_p (wi::to_widest (t)));
   6495 }
   6496 
   6497 /* T is an INTEGER_CST whose numerical value (extended according to
   6498    TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT.  Return that
   6499    HOST_WIDE_INT.  */
   6500 
   6501 HOST_WIDE_INT
   6502 tree_to_shwi (const_tree t)
   6503 {
   6504   gcc_assert (tree_fits_shwi_p (t));
   6505   return TREE_INT_CST_LOW (t);
   6506 }
   6507 
   6508 /* T is an INTEGER_CST whose numerical value (extended according to
   6509    TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT.  Return that
   6510    HOST_WIDE_INT.  */
   6511 
   6512 unsigned HOST_WIDE_INT
   6513 tree_to_uhwi (const_tree t)
   6514 {
   6515   gcc_assert (tree_fits_uhwi_p (t));
   6516   return TREE_INT_CST_LOW (t);
   6517 }
   6518 
   6519 /* Return the most significant (sign) bit of T.  */
   6520 
   6521 int
   6522 tree_int_cst_sign_bit (const_tree t)
   6523 {
   6524   unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
   6525 
   6526   return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
   6527 }
   6528 
   6529 /* Return an indication of the sign of the integer constant T.
   6530    The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
   6531    Note that -1 will never be returned if T's type is unsigned.  */
   6532 
   6533 int
   6534 tree_int_cst_sgn (const_tree t)
   6535 {
   6536   if (wi::to_wide (t) == 0)
   6537     return 0;
   6538   else if (TYPE_UNSIGNED (TREE_TYPE (t)))
   6539     return 1;
   6540   else if (wi::neg_p (wi::to_wide (t)))
   6541     return -1;
   6542   else
   6543     return 1;
   6544 }
   6545 
   6546 /* Return the minimum number of bits needed to represent VALUE in a
   6547    signed or unsigned type, UNSIGNEDP says which.  */
   6548 
   6549 unsigned int
   6550 tree_int_cst_min_precision (tree value, signop sgn)
   6551 {
   6552   /* If the value is negative, compute its negative minus 1.  The latter
   6553      adjustment is because the absolute value of the largest negative value
   6554      is one larger than the largest positive value.  This is equivalent to
   6555      a bit-wise negation, so use that operation instead.  */
   6556 
   6557   if (tree_int_cst_sgn (value) < 0)
   6558     value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
   6559 
   6560   /* Return the number of bits needed, taking into account the fact
   6561      that we need one more bit for a signed than unsigned type.
   6562      If value is 0 or -1, the minimum precision is 1 no matter
   6563      whether unsignedp is true or false.  */
   6564 
   6565   if (integer_zerop (value))
   6566     return 1;
   6567   else
   6568     return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
   6569 }
   6570 
   6571 /* Return truthvalue of whether T1 is the same tree structure as T2.
   6572    Return 1 if they are the same.
   6573    Return 0 if they are understandably different.
   6574    Return -1 if either contains tree structure not understood by
   6575    this function.  */
   6576 
   6577 int
   6578 simple_cst_equal (const_tree t1, const_tree t2)
   6579 {
   6580   enum tree_code code1, code2;
   6581   int cmp;
   6582   int i;
   6583 
   6584   if (t1 == t2)
   6585     return 1;
   6586   if (t1 == 0 || t2 == 0)
   6587     return 0;
   6588 
   6589   /* For location wrappers to be the same, they must be at the same
   6590      source location (and wrap the same thing).  */
   6591   if (location_wrapper_p (t1) && location_wrapper_p (t2))
   6592     {
   6593       if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
   6594 	return 0;
   6595       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   6596     }
   6597 
   6598   code1 = TREE_CODE (t1);
   6599   code2 = TREE_CODE (t2);
   6600 
   6601   if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
   6602     {
   6603       if (CONVERT_EXPR_CODE_P (code2)
   6604 	  || code2 == NON_LVALUE_EXPR)
   6605 	return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   6606       else
   6607 	return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
   6608     }
   6609 
   6610   else if (CONVERT_EXPR_CODE_P (code2)
   6611 	   || code2 == NON_LVALUE_EXPR)
   6612     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
   6613 
   6614   if (code1 != code2)
   6615     return 0;
   6616 
   6617   switch (code1)
   6618     {
   6619     case INTEGER_CST:
   6620       return wi::to_widest (t1) == wi::to_widest (t2);
   6621 
   6622     case REAL_CST:
   6623       return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
   6624 
   6625     case FIXED_CST:
   6626       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
   6627 
   6628     case STRING_CST:
   6629       return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
   6630 	      && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
   6631 			 TREE_STRING_LENGTH (t1)));
   6632 
   6633     case CONSTRUCTOR:
   6634       {
   6635 	unsigned HOST_WIDE_INT idx;
   6636 	vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
   6637 	vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
   6638 
   6639 	if (vec_safe_length (v1) != vec_safe_length (v2))
   6640 	  return false;
   6641 
   6642         for (idx = 0; idx < vec_safe_length (v1); ++idx)
   6643 	  /* ??? Should we handle also fields here? */
   6644 	  if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
   6645 	    return false;
   6646 	return true;
   6647       }
   6648 
   6649     case SAVE_EXPR:
   6650       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   6651 
   6652     case CALL_EXPR:
   6653       cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
   6654       if (cmp <= 0)
   6655 	return cmp;
   6656       if (call_expr_nargs (t1) != call_expr_nargs (t2))
   6657 	return 0;
   6658       {
   6659 	const_tree arg1, arg2;
   6660 	const_call_expr_arg_iterator iter1, iter2;
   6661 	for (arg1 = first_const_call_expr_arg (t1, &iter1),
   6662 	       arg2 = first_const_call_expr_arg (t2, &iter2);
   6663 	     arg1 && arg2;
   6664 	     arg1 = next_const_call_expr_arg (&iter1),
   6665 	       arg2 = next_const_call_expr_arg (&iter2))
   6666 	  {
   6667 	    cmp = simple_cst_equal (arg1, arg2);
   6668 	    if (cmp <= 0)
   6669 	      return cmp;
   6670 	  }
   6671 	return arg1 == arg2;
   6672       }
   6673 
   6674     case TARGET_EXPR:
   6675       /* Special case: if either target is an unallocated VAR_DECL,
   6676 	 it means that it's going to be unified with whatever the
   6677 	 TARGET_EXPR is really supposed to initialize, so treat it
   6678 	 as being equivalent to anything.  */
   6679       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
   6680 	   && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
   6681 	   && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
   6682 	  || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
   6683 	      && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
   6684 	      && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
   6685 	cmp = 1;
   6686       else
   6687 	cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   6688 
   6689       if (cmp <= 0)
   6690 	return cmp;
   6691 
   6692       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
   6693 
   6694     case WITH_CLEANUP_EXPR:
   6695       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   6696       if (cmp <= 0)
   6697 	return cmp;
   6698 
   6699       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
   6700 
   6701     case COMPONENT_REF:
   6702       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
   6703 	return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   6704 
   6705       return 0;
   6706 
   6707     case VAR_DECL:
   6708     case PARM_DECL:
   6709     case CONST_DECL:
   6710     case FUNCTION_DECL:
   6711       return 0;
   6712 
   6713     default:
   6714       if (POLY_INT_CST_P (t1))
   6715 	/* A false return means maybe_ne rather than known_ne.  */
   6716 	return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
   6717 						TYPE_SIGN (TREE_TYPE (t1))),
   6718 			 poly_widest_int::from (poly_int_cst_value (t2),
   6719 						TYPE_SIGN (TREE_TYPE (t2))));
   6720       break;
   6721     }
   6722 
   6723   /* This general rule works for most tree codes.  All exceptions should be
   6724      handled above.  If this is a language-specific tree code, we can't
   6725      trust what might be in the operand, so say we don't know
   6726      the situation.  */
   6727   if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
   6728     return -1;
   6729 
   6730   switch (TREE_CODE_CLASS (code1))
   6731     {
   6732     case tcc_unary:
   6733     case tcc_binary:
   6734     case tcc_comparison:
   6735     case tcc_expression:
   6736     case tcc_reference:
   6737     case tcc_statement:
   6738       cmp = 1;
   6739       for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
   6740 	{
   6741 	  cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
   6742 	  if (cmp <= 0)
   6743 	    return cmp;
   6744 	}
   6745 
   6746       return cmp;
   6747 
   6748     default:
   6749       return -1;
   6750     }
   6751 }
   6752 
   6753 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
   6754    Return -1, 0, or 1 if the value of T is less than, equal to, or greater
   6755    than U, respectively.  */
   6756 
   6757 int
   6758 compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
   6759 {
   6760   if (tree_int_cst_sgn (t) < 0)
   6761     return -1;
   6762   else if (!tree_fits_uhwi_p (t))
   6763     return 1;
   6764   else if (TREE_INT_CST_LOW (t) == u)
   6765     return 0;
   6766   else if (TREE_INT_CST_LOW (t) < u)
   6767     return -1;
   6768   else
   6769     return 1;
   6770 }
   6771 
   6772 /* Return true if SIZE represents a constant size that is in bounds of
   6773    what the middle-end and the backend accepts (covering not more than
   6774    half of the address-space).
   6775    When PERR is non-null, set *PERR on failure to the description of
   6776    why SIZE is not valid.  */
   6777 
   6778 bool
   6779 valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
   6780 {
   6781   if (POLY_INT_CST_P (size))
   6782     {
   6783       if (TREE_OVERFLOW (size))
   6784 	return false;
   6785       for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
   6786 	if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
   6787 	  return false;
   6788       return true;
   6789     }
   6790 
   6791   cst_size_error error;
   6792   if (!perr)
   6793     perr = &error;
   6794 
   6795   if (TREE_CODE (size) != INTEGER_CST)
   6796     {
   6797       *perr = cst_size_not_constant;
   6798       return false;
   6799     }
   6800 
   6801   if (TREE_OVERFLOW_P (size))
   6802     {
   6803       *perr = cst_size_overflow;
   6804       return false;
   6805     }
   6806 
   6807   if (tree_int_cst_sgn (size) < 0)
   6808     {
   6809       *perr = cst_size_negative;
   6810       return false;
   6811     }
   6812   if (!tree_fits_uhwi_p (size)
   6813       || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
   6814 	  < wi::to_widest (size) * 2))
   6815     {
   6816       *perr = cst_size_too_big;
   6817       return false;
   6818     }
   6819 
   6820   return true;
   6821 }
   6822 
   6823 /* Return the precision of the type, or for a complex or vector type the
   6824    precision of the type of its elements.  */
   6825 
   6826 unsigned int
   6827 element_precision (const_tree type)
   6828 {
   6829   if (!TYPE_P (type))
   6830     type = TREE_TYPE (type);
   6831   enum tree_code code = TREE_CODE (type);
   6832   if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
   6833     type = TREE_TYPE (type);
   6834 
   6835   return TYPE_PRECISION (type);
   6836 }
   6837 
   6838 /* Return true if CODE represents an associative tree code.  Otherwise
   6839    return false.  */
   6840 bool
   6841 associative_tree_code (enum tree_code code)
   6842 {
   6843   switch (code)
   6844     {
   6845     case BIT_IOR_EXPR:
   6846     case BIT_AND_EXPR:
   6847     case BIT_XOR_EXPR:
   6848     case PLUS_EXPR:
   6849     case MULT_EXPR:
   6850     case MIN_EXPR:
   6851     case MAX_EXPR:
   6852       return true;
   6853 
   6854     default:
   6855       break;
   6856     }
   6857   return false;
   6858 }
   6859 
   6860 /* Return true if CODE represents a commutative tree code.  Otherwise
   6861    return false.  */
   6862 bool
   6863 commutative_tree_code (enum tree_code code)
   6864 {
   6865   switch (code)
   6866     {
   6867     case PLUS_EXPR:
   6868     case MULT_EXPR:
   6869     case MULT_HIGHPART_EXPR:
   6870     case MIN_EXPR:
   6871     case MAX_EXPR:
   6872     case BIT_IOR_EXPR:
   6873     case BIT_XOR_EXPR:
   6874     case BIT_AND_EXPR:
   6875     case NE_EXPR:
   6876     case EQ_EXPR:
   6877     case UNORDERED_EXPR:
   6878     case ORDERED_EXPR:
   6879     case UNEQ_EXPR:
   6880     case LTGT_EXPR:
   6881     case TRUTH_AND_EXPR:
   6882     case TRUTH_XOR_EXPR:
   6883     case TRUTH_OR_EXPR:
   6884     case WIDEN_MULT_EXPR:
   6885     case VEC_WIDEN_MULT_HI_EXPR:
   6886     case VEC_WIDEN_MULT_LO_EXPR:
   6887     case VEC_WIDEN_MULT_EVEN_EXPR:
   6888     case VEC_WIDEN_MULT_ODD_EXPR:
   6889       return true;
   6890 
   6891     default:
   6892       break;
   6893     }
   6894   return false;
   6895 }
   6896 
   6897 /* Return true if CODE represents a ternary tree code for which the
   6898    first two operands are commutative.  Otherwise return false.  */
   6899 bool
   6900 commutative_ternary_tree_code (enum tree_code code)
   6901 {
   6902   switch (code)
   6903     {
   6904     case WIDEN_MULT_PLUS_EXPR:
   6905     case WIDEN_MULT_MINUS_EXPR:
   6906     case DOT_PROD_EXPR:
   6907       return true;
   6908 
   6909     default:
   6910       break;
   6911     }
   6912   return false;
   6913 }
   6914 
   6915 /* Returns true if CODE can overflow.  */
   6916 
   6917 bool
   6918 operation_can_overflow (enum tree_code code)
   6919 {
   6920   switch (code)
   6921     {
   6922     case PLUS_EXPR:
   6923     case MINUS_EXPR:
   6924     case MULT_EXPR:
   6925     case LSHIFT_EXPR:
   6926       /* Can overflow in various ways.  */
   6927       return true;
   6928     case TRUNC_DIV_EXPR:
   6929     case EXACT_DIV_EXPR:
   6930     case FLOOR_DIV_EXPR:
   6931     case CEIL_DIV_EXPR:
   6932       /* For INT_MIN / -1.  */
   6933       return true;
   6934     case NEGATE_EXPR:
   6935     case ABS_EXPR:
   6936       /* For -INT_MIN.  */
   6937       return true;
   6938     default:
   6939       /* These operators cannot overflow.  */
   6940       return false;
   6941     }
   6942 }
   6943 
   6944 /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
   6945    ftrapv doesn't generate trapping insns for CODE.  */
   6946 
   6947 bool
   6948 operation_no_trapping_overflow (tree type, enum tree_code code)
   6949 {
   6950   gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
   6951 
   6952   /* We don't generate instructions that trap on overflow for complex or vector
   6953      types.  */
   6954   if (!INTEGRAL_TYPE_P (type))
   6955     return true;
   6956 
   6957   if (!TYPE_OVERFLOW_TRAPS (type))
   6958     return true;
   6959 
   6960   switch (code)
   6961     {
   6962     case PLUS_EXPR:
   6963     case MINUS_EXPR:
   6964     case MULT_EXPR:
   6965     case NEGATE_EXPR:
   6966     case ABS_EXPR:
   6967       /* These operators can overflow, and -ftrapv generates trapping code for
   6968 	 these.  */
   6969       return false;
   6970     case TRUNC_DIV_EXPR:
   6971     case EXACT_DIV_EXPR:
   6972     case FLOOR_DIV_EXPR:
   6973     case CEIL_DIV_EXPR:
   6974     case LSHIFT_EXPR:
   6975       /* These operators can overflow, but -ftrapv does not generate trapping
   6976 	 code for these.  */
   6977       return true;
   6978     default:
   6979       /* These operators cannot overflow.  */
   6980       return true;
   6981     }
   6982 }
   6983 
   6984 /* Constructors for pointer, array and function types.
   6985    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
   6986    constructed by language-dependent code, not here.)  */
   6987 
   6988 /* Construct, lay out and return the type of pointers to TO_TYPE with
   6989    mode MODE.  If MODE is VOIDmode, a pointer mode for the address
   6990    space of TO_TYPE will be picked.  If CAN_ALIAS_ALL is TRUE,
   6991    indicate this type can reference all of memory. If such a type has
   6992    already been constructed, reuse it.  */
   6993 
   6994 tree
   6995 build_pointer_type_for_mode (tree to_type, machine_mode mode,
   6996 			     bool can_alias_all)
   6997 {
   6998   tree t;
   6999   bool could_alias = can_alias_all;
   7000 
   7001   if (to_type == error_mark_node)
   7002     return error_mark_node;
   7003 
   7004   if (mode == VOIDmode)
   7005     {
   7006       addr_space_t as = TYPE_ADDR_SPACE (to_type);
   7007       mode = targetm.addr_space.pointer_mode (as);
   7008     }
   7009 
   7010   /* If the pointed-to type has the may_alias attribute set, force
   7011      a TYPE_REF_CAN_ALIAS_ALL pointer to be generated.  */
   7012   if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
   7013     can_alias_all = true;
   7014 
   7015   /* In some cases, languages will have things that aren't a POINTER_TYPE
   7016      (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
   7017      In that case, return that type without regard to the rest of our
   7018      operands.
   7019 
   7020      ??? This is a kludge, but consistent with the way this function has
   7021      always operated and there doesn't seem to be a good way to avoid this
   7022      at the moment.  */
   7023   if (TYPE_POINTER_TO (to_type) != 0
   7024       && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
   7025     return TYPE_POINTER_TO (to_type);
   7026 
   7027   /* First, if we already have a type for pointers to TO_TYPE and it's
   7028      the proper mode, use it.  */
   7029   for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
   7030     if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
   7031       return t;
   7032 
   7033   t = make_node (POINTER_TYPE);
   7034 
   7035   TREE_TYPE (t) = to_type;
   7036   SET_TYPE_MODE (t, mode);
   7037   TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
   7038   TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
   7039   TYPE_POINTER_TO (to_type) = t;
   7040 
   7041   /* During LTO we do not set TYPE_CANONICAL of pointers and references.  */
   7042   if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
   7043     SET_TYPE_STRUCTURAL_EQUALITY (t);
   7044   else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
   7045     TYPE_CANONICAL (t)
   7046       = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
   7047 				     mode, false);
   7048 
   7049   /* Lay out the type.  This function has many callers that are concerned
   7050      with expression-construction, and this simplifies them all.  */
   7051   layout_type (t);
   7052 
   7053   return t;
   7054 }
   7055 
   7056 /* By default build pointers in ptr_mode.  */
   7057 
   7058 tree
   7059 build_pointer_type (tree to_type)
   7060 {
   7061   return build_pointer_type_for_mode (to_type, VOIDmode, false);
   7062 }
   7063 
   7064 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE.  */
   7065 
   7066 tree
   7067 build_reference_type_for_mode (tree to_type, machine_mode mode,
   7068 			       bool can_alias_all)
   7069 {
   7070   tree t;
   7071   bool could_alias = can_alias_all;
   7072 
   7073   if (to_type == error_mark_node)
   7074     return error_mark_node;
   7075 
   7076   if (mode == VOIDmode)
   7077     {
   7078       addr_space_t as = TYPE_ADDR_SPACE (to_type);
   7079       mode = targetm.addr_space.pointer_mode (as);
   7080     }
   7081 
   7082   /* If the pointed-to type has the may_alias attribute set, force
   7083      a TYPE_REF_CAN_ALIAS_ALL pointer to be generated.  */
   7084   if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
   7085     can_alias_all = true;
   7086 
   7087   /* In some cases, languages will have things that aren't a REFERENCE_TYPE
   7088      (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
   7089      In that case, return that type without regard to the rest of our
   7090      operands.
   7091 
   7092      ??? This is a kludge, but consistent with the way this function has
   7093      always operated and there doesn't seem to be a good way to avoid this
   7094      at the moment.  */
   7095   if (TYPE_REFERENCE_TO (to_type) != 0
   7096       && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
   7097     return TYPE_REFERENCE_TO (to_type);
   7098 
   7099   /* First, if we already have a type for pointers to TO_TYPE and it's
   7100      the proper mode, use it.  */
   7101   for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
   7102     if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
   7103       return t;
   7104 
   7105   t = make_node (REFERENCE_TYPE);
   7106 
   7107   TREE_TYPE (t) = to_type;
   7108   SET_TYPE_MODE (t, mode);
   7109   TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
   7110   TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
   7111   TYPE_REFERENCE_TO (to_type) = t;
   7112 
   7113   /* During LTO we do not set TYPE_CANONICAL of pointers and references.  */
   7114   if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
   7115     SET_TYPE_STRUCTURAL_EQUALITY (t);
   7116   else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
   7117     TYPE_CANONICAL (t)
   7118       = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
   7119 				       mode, false);
   7120 
   7121   layout_type (t);
   7122 
   7123   return t;
   7124 }
   7125 
   7126 
   7127 /* Build the node for the type of references-to-TO_TYPE by default
   7128    in ptr_mode.  */
   7129 
   7130 tree
   7131 build_reference_type (tree to_type)
   7132 {
   7133   return build_reference_type_for_mode (to_type, VOIDmode, false);
   7134 }
   7135 
   7136 #define MAX_INT_CACHED_PREC \
   7137   (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
   7138 static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
   7139 
   7140 static void
   7141 clear_nonstandard_integer_type_cache (void)
   7142 {
   7143   for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
   7144   {
   7145     nonstandard_integer_type_cache[i] = NULL;
   7146   }
   7147 }
   7148 
   7149 /* Builds a signed or unsigned integer type of precision PRECISION.
   7150    Used for C bitfields whose precision does not match that of
   7151    built-in target types.  */
   7152 tree
   7153 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
   7154 				int unsignedp)
   7155 {
   7156   tree itype, ret;
   7157 
   7158   if (unsignedp)
   7159     unsignedp = MAX_INT_CACHED_PREC + 1;
   7160 
   7161   if (precision <= MAX_INT_CACHED_PREC)
   7162     {
   7163       itype = nonstandard_integer_type_cache[precision + unsignedp];
   7164       if (itype)
   7165 	return itype;
   7166     }
   7167 
   7168   itype = make_node (INTEGER_TYPE);
   7169   TYPE_PRECISION (itype) = precision;
   7170 
   7171   if (unsignedp)
   7172     fixup_unsigned_type (itype);
   7173   else
   7174     fixup_signed_type (itype);
   7175 
   7176   inchash::hash hstate;
   7177   inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
   7178   ret = type_hash_canon (hstate.end (), itype);
   7179   if (precision <= MAX_INT_CACHED_PREC)
   7180     nonstandard_integer_type_cache[precision + unsignedp] = ret;
   7181 
   7182   return ret;
   7183 }
   7184 
   7185 #define MAX_BOOL_CACHED_PREC \
   7186   (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
   7187 static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
   7188 
   7189 /* Builds a boolean type of precision PRECISION.
   7190    Used for boolean vectors to choose proper vector element size.  */
   7191 tree
   7192 build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
   7193 {
   7194   tree type;
   7195 
   7196   if (precision <= MAX_BOOL_CACHED_PREC)
   7197     {
   7198       type = nonstandard_boolean_type_cache[precision];
   7199       if (type)
   7200 	return type;
   7201     }
   7202 
   7203   type = make_node (BOOLEAN_TYPE);
   7204   TYPE_PRECISION (type) = precision;
   7205   fixup_signed_type (type);
   7206 
   7207   if (precision <= MAX_INT_CACHED_PREC)
   7208     nonstandard_boolean_type_cache[precision] = type;
   7209 
   7210   return type;
   7211 }
   7212 
   7213 static GTY(()) vec<tree, va_gc> *bitint_type_cache;
   7214 
   7215 /* Builds a signed or unsigned _BitInt(PRECISION) type.  */
   7216 tree
   7217 build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
   7218 {
   7219   tree itype, ret;
   7220 
   7221   gcc_checking_assert (precision >= 1 + !unsignedp);
   7222 
   7223   if (unsignedp)
   7224     unsignedp = MAX_INT_CACHED_PREC + 1;
   7225 
   7226   if (bitint_type_cache == NULL)
   7227     vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
   7228 
   7229   if (precision <= MAX_INT_CACHED_PREC)
   7230     {
   7231       itype = (*bitint_type_cache)[precision + unsignedp];
   7232       if (itype)
   7233 	return itype;
   7234     }
   7235 
   7236   itype = make_node (BITINT_TYPE);
   7237   TYPE_PRECISION (itype) = precision;
   7238 
   7239   if (unsignedp)
   7240     fixup_unsigned_type (itype);
   7241   else
   7242     fixup_signed_type (itype);
   7243 
   7244   inchash::hash hstate;
   7245   inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
   7246   ret = type_hash_canon (hstate.end (), itype);
   7247   if (precision <= MAX_INT_CACHED_PREC)
   7248     (*bitint_type_cache)[precision + unsignedp] = ret;
   7249 
   7250   return ret;
   7251 }
   7252 
   7253 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
   7254    or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL.  If SHARED
   7255    is true, reuse such a type that has already been constructed.  */
   7256 
   7257 static tree
   7258 build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
   7259 {
   7260   tree itype = make_node (INTEGER_TYPE);
   7261 
   7262   TREE_TYPE (itype) = type;
   7263 
   7264   TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
   7265   TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
   7266 
   7267   TYPE_PRECISION (itype) = TYPE_PRECISION (type);
   7268   SET_TYPE_MODE (itype, TYPE_MODE (type));
   7269   TYPE_SIZE (itype) = TYPE_SIZE (type);
   7270   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
   7271   SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
   7272   TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
   7273   SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
   7274 
   7275   if (!shared)
   7276     return itype;
   7277 
   7278   if ((TYPE_MIN_VALUE (itype)
   7279        && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
   7280       || (TYPE_MAX_VALUE (itype)
   7281 	  && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
   7282     {
   7283       /* Since we cannot reliably merge this type, we need to compare it using
   7284 	 structural equality checks.  */
   7285       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   7286       return itype;
   7287     }
   7288 
   7289   hashval_t hash = type_hash_canon_hash (itype);
   7290   itype = type_hash_canon (hash, itype);
   7291 
   7292   return itype;
   7293 }
   7294 
   7295 /* Wrapper around build_range_type_1 with SHARED set to true.  */
   7296 
   7297 tree
   7298 build_range_type (tree type, tree lowval, tree highval)
   7299 {
   7300   return build_range_type_1 (type, lowval, highval, true);
   7301 }
   7302 
   7303 /* Wrapper around build_range_type_1 with SHARED set to false.  */
   7304 
   7305 tree
   7306 build_nonshared_range_type (tree type, tree lowval, tree highval)
   7307 {
   7308   return build_range_type_1 (type, lowval, highval, false);
   7309 }
   7310 
   7311 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
   7312    MAXVAL should be the maximum value in the domain
   7313    (one less than the length of the array).
   7314 
   7315    The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
   7316    We don't enforce this limit, that is up to caller (e.g. language front end).
   7317    The limit exists because the result is a signed type and we don't handle
   7318    sizes that use more than one HOST_WIDE_INT.  */
   7319 
   7320 tree
   7321 build_index_type (tree maxval)
   7322 {
   7323   return build_range_type (sizetype, size_zero_node, maxval);
   7324 }
   7325 
   7326 /* Return true if the debug information for TYPE, a subtype, should be emitted
   7327    as a subrange type.  If so, set LOWVAL to the low bound and HIGHVAL to the
   7328    high bound, respectively.  Sometimes doing so unnecessarily obfuscates the
   7329    debug info and doesn't reflect the source code.  */
   7330 
   7331 bool
   7332 subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
   7333 {
   7334   tree base_type = TREE_TYPE (type), low, high;
   7335 
   7336   /* Subrange types have a base type which is an integral type.  */
   7337   if (!INTEGRAL_TYPE_P (base_type))
   7338     return false;
   7339 
   7340   /* Get the real bounds of the subtype.  */
   7341   if (lang_hooks.types.get_subrange_bounds)
   7342     lang_hooks.types.get_subrange_bounds (type, &low, &high);
   7343   else
   7344     {
   7345       low = TYPE_MIN_VALUE (type);
   7346       high = TYPE_MAX_VALUE (type);
   7347     }
   7348 
   7349   /* If the type and its base type have the same representation and the same
   7350      name, then the type is not a subrange but a copy of the base type.  */
   7351   if ((TREE_CODE (base_type) == INTEGER_TYPE
   7352        || TREE_CODE (base_type) == BOOLEAN_TYPE)
   7353       && int_size_in_bytes (type) == int_size_in_bytes (base_type)
   7354       && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
   7355       && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
   7356       && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
   7357     return false;
   7358 
   7359   if (lowval)
   7360     *lowval = low;
   7361   if (highval)
   7362     *highval = high;
   7363   return true;
   7364 }
   7365 
   7366 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
   7367    and number of elements specified by the range of values of INDEX_TYPE.
   7368    If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
   7369    If SHARED is true, reuse such a type that has already been constructed.
   7370    If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type.  */
   7371 
   7372 tree
   7373 build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
   7374 		    bool shared, bool set_canonical)
   7375 {
   7376   tree t;
   7377 
   7378   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
   7379     {
   7380       error ("arrays of functions are not meaningful");
   7381       elt_type = integer_type_node;
   7382     }
   7383 
   7384   t = make_node (ARRAY_TYPE);
   7385   TREE_TYPE (t) = elt_type;
   7386   TYPE_DOMAIN (t) = index_type;
   7387   TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
   7388   TYPE_TYPELESS_STORAGE (t) = typeless_storage;
   7389 
   7390   /* Set TYPE_STRUCTURAL_EQUALITY_P.  */
   7391   if (set_canonical
   7392       && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
   7393 	  || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
   7394 	  || in_lto_p))
   7395     SET_TYPE_STRUCTURAL_EQUALITY (t);
   7396 
   7397   layout_type (t);
   7398 
   7399   if (shared)
   7400     {
   7401       hashval_t hash = type_hash_canon_hash (t);
   7402       tree probe_type = t;
   7403       t = type_hash_canon (hash, t);
   7404       if (t != probe_type)
   7405 	return t;
   7406     }
   7407 
   7408   if (TYPE_CANONICAL (t) == t && set_canonical)
   7409     {
   7410       if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
   7411 	  || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
   7412 	  || in_lto_p)
   7413 	gcc_unreachable ();
   7414       else if (TYPE_CANONICAL (elt_type) != elt_type
   7415 	       || (index_type && TYPE_CANONICAL (index_type) != index_type))
   7416 	TYPE_CANONICAL (t)
   7417 	  = build_array_type_1 (TYPE_CANONICAL (elt_type),
   7418 				index_type
   7419 				? TYPE_CANONICAL (index_type) : NULL_TREE,
   7420 				typeless_storage, shared, set_canonical);
   7421     }
   7422 
   7423   return t;
   7424 }
   7425 
   7426 /* Wrapper around build_array_type_1 with SHARED set to true.  */
   7427 
   7428 tree
   7429 build_array_type (tree elt_type, tree index_type, bool typeless_storage)
   7430 {
   7431   return
   7432     build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
   7433 }
   7434 
   7435 /* Wrapper around build_array_type_1 with SHARED set to false.  */
   7436 
   7437 tree
   7438 build_nonshared_array_type (tree elt_type, tree index_type)
   7439 {
   7440   return build_array_type_1 (elt_type, index_type, false, false, true);
   7441 }
   7442 
   7443 /* Return a representation of ELT_TYPE[NELTS], using indices of type
   7444    sizetype.  */
   7445 
   7446 tree
   7447 build_array_type_nelts (tree elt_type, poly_uint64 nelts)
   7448 {
   7449   return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
   7450 }
   7451 
   7452 /* Computes the canonical argument types from the argument type list
   7453    ARGTYPES.
   7454 
   7455    Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
   7456    on entry to this function, or if any of the ARGTYPES are
   7457    structural.
   7458 
   7459    Upon return, *ANY_NONCANONICAL_P will be true iff either it was
   7460    true on entry to this function, or if any of the ARGTYPES are
   7461    non-canonical.
   7462 
   7463    Returns a canonical argument list, which may be ARGTYPES when the
   7464    canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
   7465    true) or would not differ from ARGTYPES.  */
   7466 
   7467 static tree
   7468 maybe_canonicalize_argtypes (tree argtypes,
   7469 			     bool *any_structural_p,
   7470 			     bool *any_noncanonical_p)
   7471 {
   7472   tree arg;
   7473   bool any_noncanonical_argtypes_p = false;
   7474 
   7475   for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
   7476     {
   7477       if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
   7478 	/* Fail gracefully by stating that the type is structural.  */
   7479 	*any_structural_p = true;
   7480       else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
   7481 	*any_structural_p = true;
   7482       else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
   7483 	       || TREE_PURPOSE (arg))
   7484 	/* If the argument has a default argument, we consider it
   7485 	   non-canonical even though the type itself is canonical.
   7486 	   That way, different variants of function and method types
   7487 	   with default arguments will all point to the variant with
   7488 	   no defaults as their canonical type.  */
   7489         any_noncanonical_argtypes_p = true;
   7490     }
   7491 
   7492   if (*any_structural_p)
   7493     return argtypes;
   7494 
   7495   if (any_noncanonical_argtypes_p)
   7496     {
   7497       /* Build the canonical list of argument types.  */
   7498       tree canon_argtypes = NULL_TREE;
   7499       bool is_void = false;
   7500 
   7501       for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
   7502         {
   7503           if (arg == void_list_node)
   7504             is_void = true;
   7505           else
   7506             canon_argtypes = tree_cons (NULL_TREE,
   7507                                         TYPE_CANONICAL (TREE_VALUE (arg)),
   7508                                         canon_argtypes);
   7509         }
   7510 
   7511       canon_argtypes = nreverse (canon_argtypes);
   7512       if (is_void)
   7513         canon_argtypes = chainon (canon_argtypes, void_list_node);
   7514 
   7515       /* There is a non-canonical type.  */
   7516       *any_noncanonical_p = true;
   7517       return canon_argtypes;
   7518     }
   7519 
   7520   /* The canonical argument types are the same as ARGTYPES.  */
   7521   return argtypes;
   7522 }
   7523 
   7524 /* Construct, lay out and return
   7525    the type of functions returning type VALUE_TYPE
   7526    given arguments of types ARG_TYPES.
   7527    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
   7528    are data type nodes for the arguments of the function.
   7529    NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
   7530    variable-arguments function with (...) prototype (no named arguments).
   7531    If such a type has already been constructed, reuse it.  */
   7532 
   7533 tree
   7534 build_function_type (tree value_type, tree arg_types,
   7535 		     bool no_named_args_stdarg_p)
   7536 {
   7537   tree t;
   7538   inchash::hash hstate;
   7539   bool any_structural_p, any_noncanonical_p;
   7540   tree canon_argtypes;
   7541 
   7542   gcc_assert (arg_types != error_mark_node);
   7543 
   7544   if (TREE_CODE (value_type) == FUNCTION_TYPE)
   7545     {
   7546       error ("function return type cannot be function");
   7547       value_type = integer_type_node;
   7548     }
   7549 
   7550   /* Make a node of the sort we want.  */
   7551   t = make_node (FUNCTION_TYPE);
   7552   TREE_TYPE (t) = value_type;
   7553   TYPE_ARG_TYPES (t) = arg_types;
   7554   if (no_named_args_stdarg_p)
   7555     {
   7556       gcc_assert (arg_types == NULL_TREE);
   7557       TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
   7558     }
   7559 
   7560   /* Set up the canonical type. */
   7561   any_structural_p   = TYPE_STRUCTURAL_EQUALITY_P (value_type);
   7562   any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
   7563   canon_argtypes = maybe_canonicalize_argtypes (arg_types,
   7564 						&any_structural_p,
   7565 						&any_noncanonical_p);
   7566   /* Set TYPE_STRUCTURAL_EQUALITY_P early.  */
   7567   if (any_structural_p)
   7568     SET_TYPE_STRUCTURAL_EQUALITY (t);
   7569 
   7570   /* If we already have such a type, use the old one.  */
   7571   hashval_t hash = type_hash_canon_hash (t);
   7572   tree probe_type = t;
   7573   t = type_hash_canon (hash, t);
   7574   if (t != probe_type)
   7575     return t;
   7576 
   7577   if (any_structural_p)
   7578     gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
   7579   else if (any_noncanonical_p)
   7580     TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
   7581 					      canon_argtypes);
   7582 
   7583   if (!COMPLETE_TYPE_P (t))
   7584     layout_type (t);
   7585   return t;
   7586 }
   7587 
   7588 /* Build a function type.  The RETURN_TYPE is the type returned by the
   7589    function.  If VAARGS is set, no void_type_node is appended to the
   7590    list.  ARGP must be always be terminated be a NULL_TREE.  */
   7591 
   7592 static tree
   7593 build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
   7594 {
   7595   tree t, args, last;
   7596 
   7597   t = va_arg (argp, tree);
   7598   for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
   7599     args = tree_cons (NULL_TREE, t, args);
   7600 
   7601   if (vaargs)
   7602     {
   7603       last = args;
   7604       if (args != NULL_TREE)
   7605 	args = nreverse (args);
   7606       gcc_assert (last != void_list_node);
   7607     }
   7608   else if (args == NULL_TREE)
   7609     args = void_list_node;
   7610   else
   7611     {
   7612       last = args;
   7613       args = nreverse (args);
   7614       TREE_CHAIN (last) = void_list_node;
   7615     }
   7616   args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
   7617 
   7618   return args;
   7619 }
   7620 
   7621 /* Build a function type.  The RETURN_TYPE is the type returned by the
   7622    function.  If additional arguments are provided, they are
   7623    additional argument types.  The list of argument types must always
   7624    be terminated by NULL_TREE.  */
   7625 
   7626 tree
   7627 build_function_type_list (tree return_type, ...)
   7628 {
   7629   tree args;
   7630   va_list p;
   7631 
   7632   va_start (p, return_type);
   7633   args = build_function_type_list_1 (false, return_type, p);
   7634   va_end (p);
   7635   return args;
   7636 }
   7637 
   7638 /* Build a variable argument function type.  The RETURN_TYPE is the
   7639    type returned by the function.  If additional arguments are provided,
   7640    they are additional argument types.  The list of argument types must
   7641    always be terminated by NULL_TREE.  */
   7642 
   7643 tree
   7644 build_varargs_function_type_list (tree return_type, ...)
   7645 {
   7646   tree args;
   7647   va_list p;
   7648 
   7649   va_start (p, return_type);
   7650   args = build_function_type_list_1 (true, return_type, p);
   7651   va_end (p);
   7652 
   7653   return args;
   7654 }
   7655 
   7656 /* Build a function type.  RETURN_TYPE is the type returned by the
   7657    function; VAARGS indicates whether the function takes varargs.  The
   7658    function takes N named arguments, the types of which are provided in
   7659    ARG_TYPES.  */
   7660 
   7661 static tree
   7662 build_function_type_array_1 (bool vaargs, tree return_type, int n,
   7663 			     tree *arg_types)
   7664 {
   7665   int i;
   7666   tree t = vaargs ? NULL_TREE : void_list_node;
   7667 
   7668   for (i = n - 1; i >= 0; i--)
   7669     t = tree_cons (NULL_TREE, arg_types[i], t);
   7670 
   7671   return build_function_type (return_type, t, vaargs && n == 0);
   7672 }
   7673 
   7674 /* Build a function type.  RETURN_TYPE is the type returned by the
   7675    function.  The function takes N named arguments, the types of which
   7676    are provided in ARG_TYPES.  */
   7677 
   7678 tree
   7679 build_function_type_array (tree return_type, int n, tree *arg_types)
   7680 {
   7681   return build_function_type_array_1 (false, return_type, n, arg_types);
   7682 }
   7683 
   7684 /* Build a variable argument function type.  RETURN_TYPE is the type
   7685    returned by the function.  The function takes N named arguments, the
   7686    types of which are provided in ARG_TYPES.  */
   7687 
   7688 tree
   7689 build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
   7690 {
   7691   return build_function_type_array_1 (true, return_type, n, arg_types);
   7692 }
   7693 
   7694 /* Build a METHOD_TYPE for a member of BASETYPE.  The RETTYPE (a TYPE)
   7695    and ARGTYPES (a TREE_LIST) are the return type and arguments types
   7696    for the method.  An implicit additional parameter (of type
   7697    pointer-to-BASETYPE) is added to the ARGTYPES.  */
   7698 
   7699 tree
   7700 build_method_type_directly (tree basetype,
   7701 			    tree rettype,
   7702 			    tree argtypes)
   7703 {
   7704   tree t;
   7705   tree ptype;
   7706   bool any_structural_p, any_noncanonical_p;
   7707   tree canon_argtypes;
   7708 
   7709   /* Make a node of the sort we want.  */
   7710   t = make_node (METHOD_TYPE);
   7711 
   7712   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
   7713   TREE_TYPE (t) = rettype;
   7714   ptype = build_pointer_type (basetype);
   7715 
   7716   /* The actual arglist for this function includes a "hidden" argument
   7717      which is "this".  Put it into the list of argument types.  */
   7718   argtypes = tree_cons (NULL_TREE, ptype, argtypes);
   7719   TYPE_ARG_TYPES (t) = argtypes;
   7720 
   7721   /* Set up the canonical type. */
   7722   any_structural_p
   7723     = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
   7724        || TYPE_STRUCTURAL_EQUALITY_P (rettype));
   7725   any_noncanonical_p
   7726     = (TYPE_CANONICAL (basetype) != basetype
   7727        || TYPE_CANONICAL (rettype) != rettype);
   7728   canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
   7729 						&any_structural_p,
   7730 						&any_noncanonical_p);
   7731 
   7732   /* Set TYPE_STRUCTURAL_EQUALITY_P early.  */
   7733   if (any_structural_p)
   7734     SET_TYPE_STRUCTURAL_EQUALITY (t);
   7735 
   7736   /* If we already have such a type, use the old one.  */
   7737   hashval_t hash = type_hash_canon_hash (t);
   7738   tree probe_type = t;
   7739   t = type_hash_canon (hash, t);
   7740   if (t != probe_type)
   7741     return t;
   7742 
   7743   if (any_structural_p)
   7744     gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
   7745   else if (any_noncanonical_p)
   7746     TYPE_CANONICAL (t)
   7747       = build_method_type_directly (TYPE_CANONICAL (basetype),
   7748 				    TYPE_CANONICAL (rettype),
   7749 				    canon_argtypes);
   7750   if (!COMPLETE_TYPE_P (t))
   7751     layout_type (t);
   7752 
   7753   return t;
   7754 }
   7755 
   7756 /* Construct, lay out and return the type of methods belonging to class
   7757    BASETYPE and whose arguments and values are described by TYPE.
   7758    If that type exists already, reuse it.
   7759    TYPE must be a FUNCTION_TYPE node.  */
   7760 
   7761 tree
   7762 build_method_type (tree basetype, tree type)
   7763 {
   7764   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
   7765 
   7766   return build_method_type_directly (basetype,
   7767 				     TREE_TYPE (type),
   7768 				     TYPE_ARG_TYPES (type));
   7769 }
   7770 
   7771 /* Construct, lay out and return the type of offsets to a value
   7772    of type TYPE, within an object of type BASETYPE.
   7773    If a suitable offset type exists already, reuse it.  */
   7774 
   7775 tree
   7776 build_offset_type (tree basetype, tree type)
   7777 {
   7778   tree t;
   7779 
   7780   /* Make a node of the sort we want.  */
   7781   t = make_node (OFFSET_TYPE);
   7782 
   7783   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
   7784   TREE_TYPE (t) = type;
   7785   if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
   7786       || TYPE_STRUCTURAL_EQUALITY_P (type))
   7787     SET_TYPE_STRUCTURAL_EQUALITY (t);
   7788 
   7789   /* If we already have such a type, use the old one.  */
   7790   hashval_t hash = type_hash_canon_hash (t);
   7791   tree probe_type = t;
   7792   t = type_hash_canon (hash, t);
   7793   if (t != probe_type)
   7794     return t;
   7795 
   7796   if (!COMPLETE_TYPE_P (t))
   7797     layout_type (t);
   7798 
   7799   if (TYPE_CANONICAL (t) == t)
   7800     {
   7801       if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
   7802 	  || TYPE_STRUCTURAL_EQUALITY_P (type))
   7803 	gcc_unreachable ();
   7804       else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
   7805 	       || TYPE_CANONICAL (type) != type)
   7806 	TYPE_CANONICAL (t)
   7807 	  = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
   7808 			       TYPE_CANONICAL (type));
   7809     }
   7810 
   7811   return t;
   7812 }
   7813 
   7814 /* Create a complex type whose components are COMPONENT_TYPE.
   7815 
   7816    If NAMED is true, the type is given a TYPE_NAME.  We do not always
   7817    do so because this creates a DECL node and thus make the DECL_UIDs
   7818    dependent on the type canonicalization hashtable, which is GC-ed,
   7819    so the DECL_UIDs would not be stable wrt garbage collection.  */
   7820 
   7821 tree
   7822 build_complex_type (tree component_type, bool named)
   7823 {
   7824   gcc_assert (INTEGRAL_TYPE_P (component_type)
   7825 	      || SCALAR_FLOAT_TYPE_P (component_type)
   7826 	      || FIXED_POINT_TYPE_P (component_type));
   7827 
   7828   /* Make a node of the sort we want.  */
   7829   tree probe = make_node (COMPLEX_TYPE);
   7830 
   7831   TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
   7832   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
   7833     SET_TYPE_STRUCTURAL_EQUALITY (probe);
   7834 
   7835   /* If we already have such a type, use the old one.  */
   7836   hashval_t hash = type_hash_canon_hash (probe);
   7837   tree t = type_hash_canon (hash, probe);
   7838 
   7839   if (t == probe)
   7840     {
   7841       /* We created a new type.  The hash insertion will have laid
   7842 	 out the type.  We need to check the canonicalization and
   7843 	 maybe set the name.  */
   7844       gcc_checking_assert (COMPLETE_TYPE_P (t)
   7845 			   && !TYPE_NAME (t));
   7846 
   7847       if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
   7848 	;
   7849       else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
   7850 	TYPE_CANONICAL (t)
   7851 	  = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
   7852 
   7853       /* We need to create a name, since complex is a fundamental type.  */
   7854       if (named)
   7855 	{
   7856 	  const char *name = NULL;
   7857 
   7858 	  if (TREE_TYPE (t) == char_type_node)
   7859 	    name = "complex char";
   7860 	  else if (TREE_TYPE (t) == signed_char_type_node)
   7861 	    name = "complex signed char";
   7862 	  else if (TREE_TYPE (t) == unsigned_char_type_node)
   7863 	    name = "complex unsigned char";
   7864 	  else if (TREE_TYPE (t) == short_integer_type_node)
   7865 	    name = "complex short int";
   7866 	  else if (TREE_TYPE (t) == short_unsigned_type_node)
   7867 	    name = "complex short unsigned int";
   7868 	  else if (TREE_TYPE (t) == integer_type_node)
   7869 	    name = "complex int";
   7870 	  else if (TREE_TYPE (t) == unsigned_type_node)
   7871 	    name = "complex unsigned int";
   7872 	  else if (TREE_TYPE (t) == long_integer_type_node)
   7873 	    name = "complex long int";
   7874 	  else if (TREE_TYPE (t) == long_unsigned_type_node)
   7875 	    name = "complex long unsigned int";
   7876 	  else if (TREE_TYPE (t) == long_long_integer_type_node)
   7877 	    name = "complex long long int";
   7878 	  else if (TREE_TYPE (t) == long_long_unsigned_type_node)
   7879 	    name = "complex long long unsigned int";
   7880 
   7881 	  if (name != NULL)
   7882 	    TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   7883 					get_identifier (name), t);
   7884 	}
   7885     }
   7886 
   7887   return build_qualified_type (t, TYPE_QUALS (component_type));
   7888 }
   7889 
   7890 /* If TYPE is a real or complex floating-point type and the target
   7891    does not directly support arithmetic on TYPE then return the wider
   7892    type to be used for arithmetic on TYPE.  Otherwise, return
   7893    NULL_TREE.  */
   7894 
   7895 tree
   7896 excess_precision_type (tree type)
   7897 {
   7898   /* The target can give two different responses to the question of
   7899      which excess precision mode it would like depending on whether we
   7900      are in -fexcess-precision=standard or -fexcess-precision=fast.  */
   7901 
   7902   enum excess_precision_type requested_type
   7903     = (flag_excess_precision == EXCESS_PRECISION_FAST
   7904        ? EXCESS_PRECISION_TYPE_FAST
   7905        : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
   7906 	  ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
   7907 
   7908   enum flt_eval_method target_flt_eval_method
   7909     = targetm.c.excess_precision (requested_type);
   7910 
   7911   /* The target should not ask for unpredictable float evaluation (though
   7912      it might advertise that implicitly the evaluation is unpredictable,
   7913      but we don't care about that here, it will have been reported
   7914      elsewhere).  If it does ask for unpredictable evaluation, we have
   7915      nothing to do here.  */
   7916   gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
   7917 
   7918   /* Nothing to do.  The target has asked for all types we know about
   7919      to be computed with their native precision and range.  */
   7920   if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
   7921     return NULL_TREE;
   7922 
   7923   /* The target will promote this type in a target-dependent way, so excess
   7924      precision ought to leave it alone.  */
   7925   if (targetm.promoted_type (type) != NULL_TREE)
   7926     return NULL_TREE;
   7927 
   7928   machine_mode float16_type_mode = (float16_type_node
   7929 				    ? TYPE_MODE (float16_type_node)
   7930 				    : VOIDmode);
   7931   machine_mode bfloat16_type_mode = (bfloat16_type_node
   7932 				     ? TYPE_MODE (bfloat16_type_node)
   7933 				     : VOIDmode);
   7934   machine_mode float_type_mode = TYPE_MODE (float_type_node);
   7935   machine_mode double_type_mode = TYPE_MODE (double_type_node);
   7936 
   7937   switch (TREE_CODE (type))
   7938     {
   7939     case REAL_TYPE:
   7940       {
   7941 	machine_mode type_mode = TYPE_MODE (type);
   7942 	switch (target_flt_eval_method)
   7943 	  {
   7944 	  case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
   7945 	    if (type_mode == float16_type_mode
   7946 		|| type_mode == bfloat16_type_mode)
   7947 	      return float_type_node;
   7948 	    break;
   7949 	  case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
   7950 	    if (type_mode == float16_type_mode
   7951 		|| type_mode == bfloat16_type_mode
   7952 		|| type_mode == float_type_mode)
   7953 	      return double_type_node;
   7954 	    break;
   7955 	  case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
   7956 	    if (type_mode == float16_type_mode
   7957 		|| type_mode == bfloat16_type_mode
   7958 		|| type_mode == float_type_mode
   7959 		|| type_mode == double_type_mode)
   7960 	      return long_double_type_node;
   7961 	    break;
   7962 	  default:
   7963 	    gcc_unreachable ();
   7964 	  }
   7965 	break;
   7966       }
   7967     case COMPLEX_TYPE:
   7968       {
   7969 	if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
   7970 	  return NULL_TREE;
   7971 	machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
   7972 	switch (target_flt_eval_method)
   7973 	  {
   7974 	  case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
   7975 	    if (type_mode == float16_type_mode
   7976 		|| type_mode == bfloat16_type_mode)
   7977 	      return complex_float_type_node;
   7978 	    break;
   7979 	  case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
   7980 	    if (type_mode == float16_type_mode
   7981 		|| type_mode == bfloat16_type_mode
   7982 		|| type_mode == float_type_mode)
   7983 	      return complex_double_type_node;
   7984 	    break;
   7985 	  case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
   7986 	    if (type_mode == float16_type_mode
   7987 		|| type_mode == bfloat16_type_mode
   7988 		|| type_mode == float_type_mode
   7989 		|| type_mode == double_type_mode)
   7990 	      return complex_long_double_type_node;
   7991 	    break;
   7992 	  default:
   7993 	    gcc_unreachable ();
   7994 	  }
   7995 	break;
   7996       }
   7997     default:
   7998       break;
   7999     }
   8000 
   8001   return NULL_TREE;
   8002 }
   8003 
   8004 /* Return OP, stripped of any conversions to wider types as much as is safe.
   8006    Converting the value back to OP's type makes a value equivalent to OP.
   8007 
   8008    If FOR_TYPE is nonzero, we return a value which, if converted to
   8009    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
   8010 
   8011    OP must have integer, real or enumeral type.  Pointers are not allowed!
   8012 
   8013    There are some cases where the obvious value we could return
   8014    would regenerate to OP if converted to OP's type,
   8015    but would not extend like OP to wider types.
   8016    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
   8017    For example, if OP is (unsigned short)(signed char)-1,
   8018    we avoid returning (signed char)-1 if FOR_TYPE is int,
   8019    even though extending that to an unsigned short would regenerate OP,
   8020    since the result of extending (signed char)-1 to (int)
   8021    is different from (int) OP.  */
   8022 
   8023 tree
   8024 get_unwidened (tree op, tree for_type)
   8025 {
   8026   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
   8027   tree type = TREE_TYPE (op);
   8028   unsigned final_prec
   8029     = TYPE_PRECISION (for_type != 0 ? for_type : type);
   8030   int uns
   8031     = (for_type != 0 && for_type != type
   8032        && final_prec > TYPE_PRECISION (type)
   8033        && TYPE_UNSIGNED (type));
   8034   tree win = op;
   8035 
   8036   while (CONVERT_EXPR_P (op))
   8037     {
   8038       int bitschange;
   8039 
   8040       /* TYPE_PRECISION on vector types has different meaning
   8041 	 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
   8042 	 so avoid them here.  */
   8043       if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
   8044 	break;
   8045 
   8046       bitschange = TYPE_PRECISION (TREE_TYPE (op))
   8047 		   - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
   8048 
   8049       /* Truncations are many-one so cannot be removed.
   8050 	 Unless we are later going to truncate down even farther.  */
   8051       if (bitschange < 0
   8052 	  && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
   8053 	break;
   8054 
   8055       /* See what's inside this conversion.  If we decide to strip it,
   8056 	 we will set WIN.  */
   8057       op = TREE_OPERAND (op, 0);
   8058 
   8059       /* If we have not stripped any zero-extensions (uns is 0),
   8060 	 we can strip any kind of extension.
   8061 	 If we have previously stripped a zero-extension,
   8062 	 only zero-extensions can safely be stripped.
   8063 	 Any extension can be stripped if the bits it would produce
   8064 	 are all going to be discarded later by truncating to FOR_TYPE.  */
   8065 
   8066       if (bitschange > 0)
   8067 	{
   8068 	  if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
   8069 	    win = op;
   8070 	  /* TYPE_UNSIGNED says whether this is a zero-extension.
   8071 	     Let's avoid computing it if it does not affect WIN
   8072 	     and if UNS will not be needed again.  */
   8073 	  if ((uns
   8074 	       || CONVERT_EXPR_P (op))
   8075 	      && TYPE_UNSIGNED (TREE_TYPE (op)))
   8076 	    {
   8077 	      uns = 1;
   8078 	      win = op;
   8079 	    }
   8080 	}
   8081     }
   8082 
   8083   /* If we finally reach a constant see if it fits in sth smaller and
   8084      in that case convert it.  */
   8085   if (TREE_CODE (win) == INTEGER_CST)
   8086     {
   8087       tree wtype = TREE_TYPE (win);
   8088       unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
   8089       if (for_type)
   8090 	prec = MAX (prec, final_prec);
   8091       if (prec < TYPE_PRECISION (wtype))
   8092 	{
   8093 	  tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
   8094 	  if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
   8095 	    win = fold_convert (t, win);
   8096 	}
   8097     }
   8098 
   8099   return win;
   8100 }
   8101 
   8102 /* Return OP or a simpler expression for a narrower value
   8104    which can be sign-extended or zero-extended to give back OP.
   8105    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
   8106    or 0 if the value should be sign-extended.  */
   8107 
   8108 tree
   8109 get_narrower (tree op, int *unsignedp_ptr)
   8110 {
   8111   int uns = 0;
   8112   bool first = true;
   8113   tree win = op;
   8114   bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
   8115 
   8116   if (TREE_CODE (op) == COMPOUND_EXPR)
   8117     {
   8118       do
   8119 	op = TREE_OPERAND (op, 1);
   8120       while (TREE_CODE (op) == COMPOUND_EXPR);
   8121       tree ret = get_narrower (op, unsignedp_ptr);
   8122       if (ret == op)
   8123 	return win;
   8124       auto_vec <tree, 16> v;
   8125       unsigned int i;
   8126       for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
   8127 	   op = TREE_OPERAND (op, 1))
   8128 	v.safe_push (op);
   8129       FOR_EACH_VEC_ELT_REVERSE (v, i, op)
   8130 	ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
   8131 			  TREE_TYPE (ret), TREE_OPERAND (op, 0),
   8132 			  ret);
   8133       return ret;
   8134     }
   8135   while (TREE_CODE (op) == NOP_EXPR)
   8136     {
   8137       int bitschange
   8138 	= (TYPE_PRECISION (TREE_TYPE (op))
   8139 	   - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
   8140 
   8141       /* Truncations are many-one so cannot be removed.  */
   8142       if (bitschange < 0)
   8143 	break;
   8144 
   8145       /* See what's inside this conversion.  If we decide to strip it,
   8146 	 we will set WIN.  */
   8147 
   8148       if (bitschange > 0)
   8149 	{
   8150 	  op = TREE_OPERAND (op, 0);
   8151 	  /* An extension: the outermost one can be stripped,
   8152 	     but remember whether it is zero or sign extension.  */
   8153 	  if (first)
   8154 	    uns = TYPE_UNSIGNED (TREE_TYPE (op));
   8155 	  /* Otherwise, if a sign extension has been stripped,
   8156 	     only sign extensions can now be stripped;
   8157 	     if a zero extension has been stripped, only zero-extensions.  */
   8158 	  else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
   8159 	    break;
   8160 	  first = false;
   8161 	}
   8162       else /* bitschange == 0 */
   8163 	{
   8164 	  /* A change in nominal type can always be stripped, but we must
   8165 	     preserve the unsignedness.  */
   8166 	  if (first)
   8167 	    uns = TYPE_UNSIGNED (TREE_TYPE (op));
   8168 	  first = false;
   8169 	  op = TREE_OPERAND (op, 0);
   8170 	  /* Keep trying to narrow, but don't assign op to win if it
   8171 	     would turn an integral type into something else.  */
   8172 	  if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
   8173 	    continue;
   8174 	}
   8175 
   8176       win = op;
   8177     }
   8178 
   8179   if (TREE_CODE (op) == COMPONENT_REF
   8180       /* Since type_for_size always gives an integer type.  */
   8181       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
   8182       && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
   8183       /* Ensure field is laid out already.  */
   8184       && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
   8185       && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
   8186     {
   8187       unsigned HOST_WIDE_INT innerprec
   8188 	= tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
   8189       int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
   8190 		       || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
   8191       tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
   8192 
   8193       /* We can get this structure field in a narrower type that fits it,
   8194 	 but the resulting extension to its nominal type (a fullword type)
   8195 	 must satisfy the same conditions as for other extensions.
   8196 
   8197 	 Do this only for fields that are aligned (not bit-fields),
   8198 	 because when bit-field insns will be used there is no
   8199 	 advantage in doing this.  */
   8200 
   8201       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
   8202 	  && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
   8203 	  && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
   8204 	  && type != 0)
   8205 	{
   8206 	  if (first)
   8207 	    uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
   8208 	  win = fold_convert (type, op);
   8209 	}
   8210     }
   8211 
   8212   *unsignedp_ptr = uns;
   8213   return win;
   8214 }
   8215 
   8216 /* Return true if integer constant C has a value that is permissible
   8218    for TYPE, an integral type.  */
   8219 
   8220 bool
   8221 int_fits_type_p (const_tree c, const_tree type)
   8222 {
   8223   tree type_low_bound, type_high_bound;
   8224   bool ok_for_low_bound, ok_for_high_bound;
   8225   signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
   8226 
   8227   /* Non-standard boolean types can have arbitrary precision but various
   8228      transformations assume that they can only take values 0 and +/-1.  */
   8229   if (TREE_CODE (type) == BOOLEAN_TYPE)
   8230     return wi::fits_to_boolean_p (wi::to_wide (c), type);
   8231 
   8232 retry:
   8233   type_low_bound = TYPE_MIN_VALUE (type);
   8234   type_high_bound = TYPE_MAX_VALUE (type);
   8235 
   8236   /* If at least one bound of the type is a constant integer, we can check
   8237      ourselves and maybe make a decision. If no such decision is possible, but
   8238      this type is a subtype, try checking against that.  Otherwise, use
   8239      fits_to_tree_p, which checks against the precision.
   8240 
   8241      Compute the status for each possibly constant bound, and return if we see
   8242      one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
   8243      for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
   8244      for "constant known to fit".  */
   8245 
   8246   /* Check if c >= type_low_bound.  */
   8247   if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
   8248     {
   8249       if (tree_int_cst_lt (c, type_low_bound))
   8250 	return false;
   8251       ok_for_low_bound = true;
   8252     }
   8253   else
   8254     ok_for_low_bound = false;
   8255 
   8256   /* Check if c <= type_high_bound.  */
   8257   if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
   8258     {
   8259       if (tree_int_cst_lt (type_high_bound, c))
   8260 	return false;
   8261       ok_for_high_bound = true;
   8262     }
   8263   else
   8264     ok_for_high_bound = false;
   8265 
   8266   /* If the constant fits both bounds, the result is known.  */
   8267   if (ok_for_low_bound && ok_for_high_bound)
   8268     return true;
   8269 
   8270   /* Perform some generic filtering which may allow making a decision
   8271      even if the bounds are not constant.  First, negative integers
   8272      never fit in unsigned types, */
   8273   if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
   8274     return false;
   8275 
   8276   /* Second, narrower types always fit in wider ones.  */
   8277   if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
   8278     return true;
   8279 
   8280   /* Third, unsigned integers with top bit set never fit signed types.  */
   8281   if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
   8282     {
   8283       int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
   8284       if (prec < TYPE_PRECISION (TREE_TYPE (c)))
   8285 	{
   8286 	  /* When a tree_cst is converted to a wide-int, the precision
   8287 	     is taken from the type.  However, if the precision of the
   8288 	     mode underneath the type is smaller than that, it is
   8289 	     possible that the value will not fit.  The test below
   8290 	     fails if any bit is set between the sign bit of the
   8291 	     underlying mode and the top bit of the type.  */
   8292 	  if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
   8293 	    return false;
   8294 	}
   8295       else if (wi::neg_p (wi::to_wide (c)))
   8296 	return false;
   8297     }
   8298 
   8299   /* If we haven't been able to decide at this point, there nothing more we
   8300      can check ourselves here.  Look at the base type if we have one and it
   8301      has the same precision.  */
   8302   if (TREE_CODE (type) == INTEGER_TYPE
   8303       && TREE_TYPE (type) != 0
   8304       && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
   8305     {
   8306       type = TREE_TYPE (type);
   8307       goto retry;
   8308     }
   8309 
   8310   /* Or to fits_to_tree_p, if nothing else.  */
   8311   return wi::fits_to_tree_p (wi::to_wide (c), type);
   8312 }
   8313 
   8314 /* Stores bounds of an integer TYPE in MIN and MAX.  If TYPE has non-constant
   8315    bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
   8316    represented (assuming two's-complement arithmetic) within the bit
   8317    precision of the type are returned instead.  */
   8318 
   8319 void
   8320 get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
   8321 {
   8322   if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
   8323       && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
   8324     wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
   8325   else
   8326     {
   8327       if (TYPE_UNSIGNED (type))
   8328 	mpz_set_ui (min, 0);
   8329       else
   8330 	{
   8331 	  wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
   8332 	  wi::to_mpz (mn, min, SIGNED);
   8333 	}
   8334     }
   8335 
   8336   if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
   8337       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
   8338     wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
   8339   else
   8340     {
   8341       wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
   8342       wi::to_mpz (mn, max, TYPE_SIGN (type));
   8343     }
   8344 }
   8345 
   8346 /* Return true if VAR is an automatic variable.  */
   8347 
   8348 bool
   8349 auto_var_p (const_tree var)
   8350 {
   8351   return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
   8352 	    || TREE_CODE (var) == PARM_DECL)
   8353 	   && ! TREE_STATIC (var))
   8354 	  || TREE_CODE (var) == RESULT_DECL);
   8355 }
   8356 
   8357 /* Return true if VAR is an automatic variable defined in function FN.  */
   8358 
   8359 bool
   8360 auto_var_in_fn_p (const_tree var, const_tree fn)
   8361 {
   8362   return (DECL_P (var) && DECL_CONTEXT (var) == fn
   8363 	  && (auto_var_p (var)
   8364 	      || TREE_CODE (var) == LABEL_DECL));
   8365 }
   8366 
   8367 /* Subprogram of following function.  Called by walk_tree.
   8368 
   8369    Return *TP if it is an automatic variable or parameter of the
   8370    function passed in as DATA.  */
   8371 
   8372 static tree
   8373 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
   8374 {
   8375   tree fn = (tree) data;
   8376 
   8377   if (TYPE_P (*tp))
   8378     *walk_subtrees = 0;
   8379 
   8380   else if (DECL_P (*tp)
   8381 	   && auto_var_in_fn_p (*tp, fn))
   8382     return *tp;
   8383 
   8384   return NULL_TREE;
   8385 }
   8386 
   8387 /* Returns true if T is, contains, or refers to a type with variable
   8388    size.  For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
   8389    arguments, but not the return type.  If FN is nonzero, only return
   8390    true if a modifier of the type or position of FN is a variable or
   8391    parameter inside FN.
   8392 
   8393    This concept is more general than that of C99 'variably modified types':
   8394    in C99, a struct type is never variably modified because a VLA may not
   8395    appear as a structure member.  However, in GNU C code like:
   8396 
   8397      struct S { int i[f()]; };
   8398 
   8399    is valid, and other languages may define similar constructs.  */
   8400 
   8401 bool
   8402 variably_modified_type_p (tree type, tree fn)
   8403 {
   8404   tree t;
   8405 
   8406 /* Test if T is either variable (if FN is zero) or an expression containing
   8407    a variable in FN.  If TYPE isn't gimplified, return true also if
   8408    gimplify_one_sizepos would gimplify the expression into a local
   8409    variable.  */
   8410 #define RETURN_TRUE_IF_VAR(T)						\
   8411   do { tree _t = (T);							\
   8412     if (_t != NULL_TREE							\
   8413 	&& _t != error_mark_node					\
   8414 	&& !CONSTANT_CLASS_P (_t)					\
   8415 	&& TREE_CODE (_t) != PLACEHOLDER_EXPR				\
   8416 	&& (!fn								\
   8417 	    || (!TYPE_SIZES_GIMPLIFIED (type)				\
   8418 		&& (TREE_CODE (_t) != VAR_DECL				\
   8419 		    && !CONTAINS_PLACEHOLDER_P (_t)))			\
   8420 	    || walk_tree (&_t, find_var_from_fn, fn, NULL)))		\
   8421       return true;  } while (0)
   8422 
   8423   if (type == error_mark_node)
   8424     return false;
   8425 
   8426   /* If TYPE itself has variable size, it is variably modified.  */
   8427   RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
   8428   RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
   8429 
   8430   switch (TREE_CODE (type))
   8431     {
   8432     case POINTER_TYPE:
   8433     case REFERENCE_TYPE:
   8434     case VECTOR_TYPE:
   8435       /* Ada can have pointer types refering to themselves indirectly.  */
   8436       if (TREE_VISITED (type))
   8437 	return false;
   8438       TREE_VISITED (type) = true;
   8439       if (variably_modified_type_p (TREE_TYPE (type), fn))
   8440 	{
   8441 	  TREE_VISITED (type) = false;
   8442 	  return true;
   8443 	}
   8444       TREE_VISITED (type) = false;
   8445       break;
   8446 
   8447     case FUNCTION_TYPE:
   8448     case METHOD_TYPE:
   8449       /* If TYPE is a function type, it is variably modified if the
   8450 	 return type is variably modified.  */
   8451       if (variably_modified_type_p (TREE_TYPE (type), fn))
   8452 	  return true;
   8453       break;
   8454 
   8455     case INTEGER_TYPE:
   8456     case REAL_TYPE:
   8457     case FIXED_POINT_TYPE:
   8458     case ENUMERAL_TYPE:
   8459     case BOOLEAN_TYPE:
   8460       /* Scalar types are variably modified if their end points
   8461 	 aren't constant.  */
   8462       RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
   8463       RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
   8464       break;
   8465 
   8466     case RECORD_TYPE:
   8467     case UNION_TYPE:
   8468     case QUAL_UNION_TYPE:
   8469       /* We can't see if any of the fields are variably-modified by the
   8470 	 definition we normally use, since that would produce infinite
   8471 	 recursion via pointers.  */
   8472       /* This is variably modified if some field's type is.  */
   8473       for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
   8474 	if (TREE_CODE (t) == FIELD_DECL)
   8475 	  {
   8476 	    RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
   8477 	    RETURN_TRUE_IF_VAR (DECL_SIZE (t));
   8478 	    RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
   8479 
   8480 	    /* If the type is a qualified union, then the DECL_QUALIFIER
   8481 	       of fields can also be an expression containing a variable.  */
   8482 	    if (TREE_CODE (type) == QUAL_UNION_TYPE)
   8483 	      RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
   8484 
   8485 	    /* If the field is a qualified union, then it's only a container
   8486 	       for what's inside so we look into it.  That's necessary in LTO
   8487 	       mode because the sizes of the field tested above have been set
   8488 	       to PLACEHOLDER_EXPRs by free_lang_data.  */
   8489 	    if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
   8490 		&& variably_modified_type_p (TREE_TYPE (t), fn))
   8491 	      return true;
   8492 	  }
   8493       break;
   8494 
   8495     case ARRAY_TYPE:
   8496       /* Do not call ourselves to avoid infinite recursion.  This is
   8497 	 variably modified if the element type is.  */
   8498       RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
   8499       RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
   8500       break;
   8501 
   8502     default:
   8503       break;
   8504     }
   8505 
   8506   /* The current language may have other cases to check, but in general,
   8507      all other types are not variably modified.  */
   8508   return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
   8509 
   8510 #undef RETURN_TRUE_IF_VAR
   8511 }
   8512 
   8513 /* Given a DECL or TYPE, return the scope in which it was declared, or
   8514    NULL_TREE if there is no containing scope.  */
   8515 
   8516 tree
   8517 get_containing_scope (const_tree t)
   8518 {
   8519   return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
   8520 }
   8521 
   8522 /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL.  */
   8523 
   8524 const_tree
   8525 get_ultimate_context (const_tree decl)
   8526 {
   8527   while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
   8528     {
   8529       if (TREE_CODE (decl) == BLOCK)
   8530 	decl = BLOCK_SUPERCONTEXT (decl);
   8531       else
   8532 	decl = get_containing_scope (decl);
   8533     }
   8534   return decl;
   8535 }
   8536 
   8537 /* Return the innermost context enclosing DECL that is
   8538    a FUNCTION_DECL, or zero if none.  */
   8539 
   8540 tree
   8541 decl_function_context (const_tree decl)
   8542 {
   8543   tree context;
   8544 
   8545   if (TREE_CODE (decl) == ERROR_MARK)
   8546     return 0;
   8547 
   8548   /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
   8549      where we look up the function at runtime.  Such functions always take
   8550      a first argument of type 'pointer to real context'.
   8551 
   8552      C++ should really be fixed to use DECL_CONTEXT for the real context,
   8553      and use something else for the "virtual context".  */
   8554   else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
   8555     context
   8556       = TYPE_MAIN_VARIANT
   8557 	(TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
   8558   else
   8559     context = DECL_CONTEXT (decl);
   8560 
   8561   while (context && TREE_CODE (context) != FUNCTION_DECL)
   8562     {
   8563       if (TREE_CODE (context) == BLOCK)
   8564 	context = BLOCK_SUPERCONTEXT (context);
   8565       else
   8566 	context = get_containing_scope (context);
   8567     }
   8568 
   8569   return context;
   8570 }
   8571 
   8572 /* Return the innermost context enclosing DECL that is
   8573    a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
   8574    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
   8575 
   8576 tree
   8577 decl_type_context (const_tree decl)
   8578 {
   8579   tree context = DECL_CONTEXT (decl);
   8580 
   8581   while (context)
   8582     switch (TREE_CODE (context))
   8583       {
   8584       case NAMESPACE_DECL:
   8585       case TRANSLATION_UNIT_DECL:
   8586 	return NULL_TREE;
   8587 
   8588       case RECORD_TYPE:
   8589       case UNION_TYPE:
   8590       case QUAL_UNION_TYPE:
   8591 	return context;
   8592 
   8593       case TYPE_DECL:
   8594       case FUNCTION_DECL:
   8595 	context = DECL_CONTEXT (context);
   8596 	break;
   8597 
   8598       case BLOCK:
   8599 	context = BLOCK_SUPERCONTEXT (context);
   8600 	break;
   8601 
   8602       default:
   8603 	gcc_unreachable ();
   8604       }
   8605 
   8606   return NULL_TREE;
   8607 }
   8608 
   8609 /* CALL is a CALL_EXPR.  Return the declaration for the function
   8610    called, or NULL_TREE if the called function cannot be
   8611    determined.  */
   8612 
   8613 tree
   8614 get_callee_fndecl (const_tree call)
   8615 {
   8616   tree addr;
   8617 
   8618   if (call == error_mark_node)
   8619     return error_mark_node;
   8620 
   8621   /* It's invalid to call this function with anything but a
   8622      CALL_EXPR.  */
   8623   gcc_assert (TREE_CODE (call) == CALL_EXPR);
   8624 
   8625   /* The first operand to the CALL is the address of the function
   8626      called.  */
   8627   addr = CALL_EXPR_FN (call);
   8628 
   8629   /* If there is no function, return early.  */
   8630   if (addr == NULL_TREE)
   8631     return NULL_TREE;
   8632 
   8633   STRIP_NOPS (addr);
   8634 
   8635   /* If this is a readonly function pointer, extract its initial value.  */
   8636   if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
   8637       && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
   8638       && DECL_INITIAL (addr))
   8639     addr = DECL_INITIAL (addr);
   8640 
   8641   /* If the address is just `&f' for some function `f', then we know
   8642      that `f' is being called.  */
   8643   if (TREE_CODE (addr) == ADDR_EXPR
   8644       && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
   8645     return TREE_OPERAND (addr, 0);
   8646 
   8647   /* We couldn't figure out what was being called.  */
   8648   return NULL_TREE;
   8649 }
   8650 
   8651 /* Return true when STMTs arguments and return value match those of FNDECL,
   8652    a decl of a builtin function.  */
   8653 
   8654 static bool
   8655 tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
   8656 {
   8657   gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
   8658 
   8659   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
   8660     if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
   8661       fndecl = decl;
   8662 
   8663   bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
   8664   if (gimple_form
   8665       ? !useless_type_conversion_p (TREE_TYPE (call),
   8666 				    TREE_TYPE (TREE_TYPE (fndecl)))
   8667       : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
   8668 	 != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
   8669     return false;
   8670 
   8671   tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
   8672   unsigned nargs = call_expr_nargs (call);
   8673   for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
   8674     {
   8675       /* Variadic args follow.  */
   8676       if (!targs)
   8677 	return true;
   8678       tree arg = CALL_EXPR_ARG (call, i);
   8679       tree type = TREE_VALUE (targs);
   8680       if (gimple_form
   8681 	  ? !useless_type_conversion_p (type, TREE_TYPE (arg))
   8682 	  : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
   8683 	{
   8684 	  /* For pointer arguments be more forgiving, e.g. due to
   8685 	     FILE * vs. fileptr_type_node, or say char * vs. const char *
   8686 	     differences etc.  */
   8687 	  if (!gimple_form
   8688 	      && POINTER_TYPE_P (type)
   8689 	      && POINTER_TYPE_P (TREE_TYPE (arg))
   8690 	      && tree_nop_conversion_p (type, TREE_TYPE (arg)))
   8691 	    continue;
   8692 	  /* char/short integral arguments are promoted to int
   8693 	     by several frontends if targetm.calls.promote_prototypes
   8694 	     is true.  Allow such promotion too.  */
   8695 	  if (INTEGRAL_TYPE_P (type)
   8696 	      && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
   8697 	      && INTEGRAL_TYPE_P (TREE_TYPE (arg))
   8698 	      && !TYPE_UNSIGNED (TREE_TYPE (arg))
   8699 	      && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))
   8700 	      && (gimple_form
   8701 		  ? useless_type_conversion_p (integer_type_node,
   8702 					       TREE_TYPE (arg))
   8703 		  : tree_nop_conversion_p (integer_type_node,
   8704 					   TREE_TYPE (arg))))
   8705 	    continue;
   8706 	  return false;
   8707 	}
   8708     }
   8709   if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
   8710     return false;
   8711   return true;
   8712 }
   8713 
   8714 /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
   8715    return the associated function code, otherwise return CFN_LAST.  */
   8716 
   8717 combined_fn
   8718 get_call_combined_fn (const_tree call)
   8719 {
   8720   /* It's invalid to call this function with anything but a CALL_EXPR.  */
   8721   gcc_assert (TREE_CODE (call) == CALL_EXPR);
   8722 
   8723   if (!CALL_EXPR_FN (call))
   8724     return as_combined_fn (CALL_EXPR_IFN (call));
   8725 
   8726   tree fndecl = get_callee_fndecl (call);
   8727   if (fndecl
   8728       && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
   8729       && tree_builtin_call_types_compatible_p (call, fndecl))
   8730     return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
   8731 
   8732   return CFN_LAST;
   8733 }
   8734 
   8735 /* Comparator of indices based on tree_node_counts.  */
   8736 
   8737 static int
   8738 tree_nodes_cmp (const void *p1, const void *p2)
   8739 {
   8740   const unsigned *n1 = (const unsigned *)p1;
   8741   const unsigned *n2 = (const unsigned *)p2;
   8742 
   8743   return tree_node_counts[*n1] - tree_node_counts[*n2];
   8744 }
   8745 
   8746 /* Comparator of indices based on tree_code_counts.  */
   8747 
   8748 static int
   8749 tree_codes_cmp (const void *p1, const void *p2)
   8750 {
   8751   const unsigned *n1 = (const unsigned *)p1;
   8752   const unsigned *n2 = (const unsigned *)p2;
   8753 
   8754   return tree_code_counts[*n1] - tree_code_counts[*n2];
   8755 }
   8756 
   8757 #define TREE_MEM_USAGE_SPACES 40
   8758 
   8759 /* Print debugging information about tree nodes generated during the compile,
   8760    and any language-specific information.  */
   8761 
   8762 void
   8763 dump_tree_statistics (void)
   8764 {
   8765   if (GATHER_STATISTICS)
   8766     {
   8767       uint64_t total_nodes, total_bytes;
   8768       fprintf (stderr, "\nKind                   Nodes      Bytes\n");
   8769       mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
   8770       total_nodes = total_bytes = 0;
   8771 
   8772       {
   8773 	auto_vec<unsigned> indices (all_kinds);
   8774 	for (unsigned i = 0; i < all_kinds; i++)
   8775 	  indices.quick_push (i);
   8776 	indices.qsort (tree_nodes_cmp);
   8777 
   8778 	for (unsigned i = 0; i < (int) all_kinds; i++)
   8779 	  {
   8780 	    unsigned j = indices[i];
   8781 	    fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
   8782 		     tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
   8783 		     SIZE_AMOUNT (tree_node_sizes[j]));
   8784 	    total_nodes += tree_node_counts[j];
   8785 	    total_bytes += tree_node_sizes[j];
   8786 	  }
   8787 	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
   8788 	fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
   8789 		 SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
   8790 	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
   8791       }
   8792 
   8793       {
   8794 	fprintf (stderr, "Code                              Nodes\n");
   8795 	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
   8796 
   8797 	auto_vec<unsigned> indices (MAX_TREE_CODES);
   8798 	for (unsigned i = 0; i < MAX_TREE_CODES; i++)
   8799 	  indices.quick_push (i);
   8800 	indices.qsort (tree_codes_cmp);
   8801 
   8802 	for (unsigned i = 0; i < MAX_TREE_CODES; i++)
   8803 	  {
   8804 	    unsigned j = indices[i];
   8805 	    fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
   8806 		     get_tree_code_name ((enum tree_code) j),
   8807 		     SIZE_AMOUNT (tree_code_counts[j]));
   8808 	  }
   8809 	mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
   8810 	fprintf (stderr, "\n");
   8811 	ssanames_print_statistics ();
   8812 	fprintf (stderr, "\n");
   8813 	phinodes_print_statistics ();
   8814 	fprintf (stderr, "\n");
   8815       }
   8816     }
   8817   else
   8818     fprintf (stderr, "(No per-node statistics)\n");
   8819 
   8820   print_type_hash_statistics ();
   8821   print_debug_expr_statistics ();
   8822   print_value_expr_statistics ();
   8823   lang_hooks.print_statistics ();
   8824 }
   8825 
   8826 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
   8828 
   8829 /* Generate a crc32 of the low BYTES bytes of VALUE.  */
   8830 
   8831 unsigned
   8832 crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
   8833 {
   8834   /* This relies on the raw feedback's top 4 bits being zero.  */
   8835 #define FEEDBACK(X) ((X) * 0x04c11db7)
   8836 #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
   8837 		     ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
   8838   static const unsigned syndromes[16] =
   8839     {
   8840       SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
   8841       SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
   8842       SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
   8843       SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
   8844     };
   8845 #undef FEEDBACK
   8846 #undef SYNDROME
   8847 
   8848   value <<= (32 - bytes * 8);
   8849   for (unsigned ix = bytes * 2; ix--; value <<= 4)
   8850     {
   8851       unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
   8852 
   8853       chksum = (chksum << 4) ^ feedback;
   8854     }
   8855 
   8856   return chksum;
   8857 }
   8858 
   8859 /* Generate a crc32 of a string.  */
   8860 
   8861 unsigned
   8862 crc32_string (unsigned chksum, const char *string)
   8863 {
   8864   do
   8865     chksum = crc32_byte (chksum, *string);
   8866   while (*string++);
   8867   return chksum;
   8868 }
   8869 
   8870 /* P is a string that will be used in a symbol.  Mask out any characters
   8871    that are not valid in that context.  */
   8872 
   8873 void
   8874 clean_symbol_name (char *p)
   8875 {
   8876   for (; *p; p++)
   8877     if (! (ISALNUM (*p)
   8878 #ifndef NO_DOLLAR_IN_LABEL	/* this for `$'; unlikely, but... -- kr */
   8879 	    || *p == '$'
   8880 #endif
   8881 #ifndef NO_DOT_IN_LABEL		/* this for `.'; unlikely, but...  */
   8882 	    || *p == '.'
   8883 #endif
   8884 	   ))
   8885       *p = '_';
   8886 }
   8887 
   8888 static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH.  */
   8889 
   8890 /* Create a unique anonymous identifier.  The identifier is still a
   8891    valid assembly label.  */
   8892 
   8893 tree
   8894 make_anon_name ()
   8895 {
   8896   const char *fmt =
   8897 #if !defined (NO_DOT_IN_LABEL)
   8898     "."
   8899 #elif !defined (NO_DOLLAR_IN_LABEL)
   8900     "$"
   8901 #else
   8902     "_"
   8903 #endif
   8904     "_anon_%d";
   8905 
   8906   char buf[24];
   8907   int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
   8908   gcc_checking_assert (len < int (sizeof (buf)));
   8909 
   8910   tree id = get_identifier_with_length (buf, len);
   8911   IDENTIFIER_ANON_P (id) = true;
   8912 
   8913   return id;
   8914 }
   8915 
   8916 /* Generate a name for a special-purpose function.
   8917    The generated name may need to be unique across the whole link.
   8918    Changes to this function may also require corresponding changes to
   8919    xstrdup_mask_random.
   8920    TYPE is some string to identify the purpose of this function to the
   8921    linker or collect2; it must start with an uppercase letter,
   8922    one of:
   8923    I - for constructors
   8924    D - for destructors
   8925    N - for C++ anonymous namespaces
   8926    F - for DWARF unwind frame information.  */
   8927 
   8928 tree
   8929 get_file_function_name (const char *type)
   8930 {
   8931   char *buf;
   8932   const char *p;
   8933   char *q;
   8934 
   8935   /* If we already have a name we know to be unique, just use that.  */
   8936   if (first_global_object_name)
   8937     p = q = ASTRDUP (first_global_object_name);
   8938   /* If the target is handling the constructors/destructors, they
   8939      will be local to this file and the name is only necessary for
   8940      debugging purposes.
   8941      We also assign sub_I and sub_D sufixes to constructors called from
   8942      the global static constructors.  These are always local.  */
   8943   else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
   8944 	   || (startswith (type, "sub_")
   8945 	       && (type[4] == 'I' || type[4] == 'D')))
   8946     {
   8947       const char *file = main_input_filename;
   8948       if (! file)
   8949 	file = LOCATION_FILE (input_location);
   8950       /* Just use the file's basename, because the full pathname
   8951 	 might be quite long.  */
   8952       p = q = ASTRDUP (lbasename (file));
   8953     }
   8954   else
   8955     {
   8956       /* Otherwise, the name must be unique across the entire link.
   8957 	 We don't have anything that we know to be unique to this translation
   8958 	 unit, so use what we do have and throw in some randomness.  */
   8959       unsigned len;
   8960       const char *name = weak_global_object_name;
   8961       const char *file = main_input_filename;
   8962 
   8963       if (! name)
   8964 	name = "";
   8965       if (! file)
   8966 	file = LOCATION_FILE (input_location);
   8967 
   8968       len = strlen (file);
   8969       q = (char *) alloca (9 + 19 + len + 1);
   8970       memcpy (q, file, len + 1);
   8971 
   8972       snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
   8973 		crc32_string (0, name), get_random_seed (false));
   8974 
   8975       p = q;
   8976     }
   8977 
   8978   clean_symbol_name (q);
   8979   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
   8980 			 + strlen (type));
   8981 
   8982   /* Set up the name of the file-level functions we may need.
   8983      Use a global object (which is already required to be unique over
   8984      the program) rather than the file name (which imposes extra
   8985      constraints).  */
   8986   sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
   8987 
   8988   return get_identifier (buf);
   8989 }
   8990 
   8991 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
   8993 
   8994 /* Complain that the tree code of NODE does not match the expected 0
   8995    terminated list of trailing codes.  The trailing code list can be
   8996    empty, for a more vague error message.  FILE, LINE, and FUNCTION
   8997    are of the caller.  */
   8998 
   8999 void
   9000 tree_check_failed (const_tree node, const char *file,
   9001 		   int line, const char *function, ...)
   9002 {
   9003   va_list args;
   9004   const char *buffer;
   9005   unsigned length = 0;
   9006   enum tree_code code;
   9007 
   9008   va_start (args, function);
   9009   while ((code = (enum tree_code) va_arg (args, int)))
   9010     length += 4 + strlen (get_tree_code_name (code));
   9011   va_end (args);
   9012   if (length)
   9013     {
   9014       char *tmp;
   9015       va_start (args, function);
   9016       length += strlen ("expected ");
   9017       buffer = tmp = (char *) alloca (length);
   9018       length = 0;
   9019       while ((code = (enum tree_code) va_arg (args, int)))
   9020 	{
   9021 	  const char *prefix = length ? " or " : "expected ";
   9022 
   9023 	  strcpy (tmp + length, prefix);
   9024 	  length += strlen (prefix);
   9025 	  strcpy (tmp + length, get_tree_code_name (code));
   9026 	  length += strlen (get_tree_code_name (code));
   9027 	}
   9028       va_end (args);
   9029     }
   9030   else
   9031     buffer = "unexpected node";
   9032 
   9033   internal_error ("tree check: %s, have %s in %s, at %s:%d",
   9034 		  buffer, get_tree_code_name (TREE_CODE (node)),
   9035 		  function, trim_filename (file), line);
   9036 }
   9037 
   9038 /* Complain that the tree code of NODE does match the expected 0
   9039    terminated list of trailing codes. FILE, LINE, and FUNCTION are of
   9040    the caller.  */
   9041 
   9042 void
   9043 tree_not_check_failed (const_tree node, const char *file,
   9044 		       int line, const char *function, ...)
   9045 {
   9046   va_list args;
   9047   char *buffer;
   9048   unsigned length = 0;
   9049   enum tree_code code;
   9050 
   9051   va_start (args, function);
   9052   while ((code = (enum tree_code) va_arg (args, int)))
   9053     length += 4 + strlen (get_tree_code_name (code));
   9054   va_end (args);
   9055   va_start (args, function);
   9056   buffer = (char *) alloca (length);
   9057   length = 0;
   9058   while ((code = (enum tree_code) va_arg (args, int)))
   9059     {
   9060       if (length)
   9061 	{
   9062 	  strcpy (buffer + length, " or ");
   9063 	  length += 4;
   9064 	}
   9065       strcpy (buffer + length, get_tree_code_name (code));
   9066       length += strlen (get_tree_code_name (code));
   9067     }
   9068   va_end (args);
   9069 
   9070   internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
   9071 		  buffer, get_tree_code_name (TREE_CODE (node)),
   9072 		  function, trim_filename (file), line);
   9073 }
   9074 
   9075 /* Similar to tree_check_failed, except that we check for a class of tree
   9076    code, given in CL.  */
   9077 
   9078 void
   9079 tree_class_check_failed (const_tree node, const enum tree_code_class cl,
   9080 			 const char *file, int line, const char *function)
   9081 {
   9082   internal_error
   9083     ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
   9084      TREE_CODE_CLASS_STRING (cl),
   9085      TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
   9086      get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
   9087 }
   9088 
   9089 /* Similar to tree_check_failed, except that instead of specifying a
   9090    dozen codes, use the knowledge that they're all sequential.  */
   9091 
   9092 void
   9093 tree_range_check_failed (const_tree node, const char *file, int line,
   9094 			 const char *function, enum tree_code c1,
   9095 			 enum tree_code c2)
   9096 {
   9097   char *buffer;
   9098   unsigned length = 0;
   9099   unsigned int c;
   9100 
   9101   for (c = c1; c <= c2; ++c)
   9102     length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
   9103 
   9104   length += strlen ("expected ");
   9105   buffer = (char *) alloca (length);
   9106   length = 0;
   9107 
   9108   for (c = c1; c <= c2; ++c)
   9109     {
   9110       const char *prefix = length ? " or " : "expected ";
   9111 
   9112       strcpy (buffer + length, prefix);
   9113       length += strlen (prefix);
   9114       strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
   9115       length += strlen (get_tree_code_name ((enum tree_code) c));
   9116     }
   9117 
   9118   internal_error ("tree check: %s, have %s in %s, at %s:%d",
   9119 		  buffer, get_tree_code_name (TREE_CODE (node)),
   9120 		  function, trim_filename (file), line);
   9121 }
   9122 
   9123 
   9124 /* Similar to tree_check_failed, except that we check that a tree does
   9125    not have the specified code, given in CL.  */
   9126 
   9127 void
   9128 tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
   9129 			     const char *file, int line, const char *function)
   9130 {
   9131   internal_error
   9132     ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
   9133      TREE_CODE_CLASS_STRING (cl),
   9134      TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
   9135      get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
   9136 }
   9137 
   9138 
   9139 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes.  */
   9140 
   9141 void
   9142 omp_clause_check_failed (const_tree node, const char *file, int line,
   9143                          const char *function, enum omp_clause_code code)
   9144 {
   9145   internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
   9146 		  "in %s, at %s:%d",
   9147 		  omp_clause_code_name[code],
   9148 		  get_tree_code_name (TREE_CODE (node)),
   9149 		  function, trim_filename (file), line);
   9150 }
   9151 
   9152 
   9153 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes.  */
   9154 
   9155 void
   9156 omp_clause_range_check_failed (const_tree node, const char *file, int line,
   9157 			       const char *function, enum omp_clause_code c1,
   9158 			       enum omp_clause_code c2)
   9159 {
   9160   char *buffer;
   9161   unsigned length = 0;
   9162   unsigned int c;
   9163 
   9164   for (c = c1; c <= c2; ++c)
   9165     length += 4 + strlen (omp_clause_code_name[c]);
   9166 
   9167   length += strlen ("expected ");
   9168   buffer = (char *) alloca (length);
   9169   length = 0;
   9170 
   9171   for (c = c1; c <= c2; ++c)
   9172     {
   9173       const char *prefix = length ? " or " : "expected ";
   9174 
   9175       strcpy (buffer + length, prefix);
   9176       length += strlen (prefix);
   9177       strcpy (buffer + length, omp_clause_code_name[c]);
   9178       length += strlen (omp_clause_code_name[c]);
   9179     }
   9180 
   9181   internal_error ("tree check: %s, have %s in %s, at %s:%d",
   9182 		  buffer, omp_clause_code_name[TREE_CODE (node)],
   9183 		  function, trim_filename (file), line);
   9184 }
   9185 
   9186 
   9187 #undef DEFTREESTRUCT
   9188 #define DEFTREESTRUCT(VAL, NAME) NAME,
   9189 
   9190 static const char *ts_enum_names[] = {
   9191 #include "treestruct.def"
   9192 };
   9193 #undef DEFTREESTRUCT
   9194 
   9195 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
   9196 
   9197 /* Similar to tree_class_check_failed, except that we check for
   9198    whether CODE contains the tree structure identified by EN.  */
   9199 
   9200 void
   9201 tree_contains_struct_check_failed (const_tree node,
   9202 				   const enum tree_node_structure_enum en,
   9203 				   const char *file, int line,
   9204 				   const char *function)
   9205 {
   9206   internal_error
   9207     ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
   9208      TS_ENUM_NAME (en),
   9209      get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
   9210 }
   9211 
   9212 
   9213 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
   9214    (dynamically sized) vector.  */
   9215 
   9216 void
   9217 tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
   9218 			       const char *function)
   9219 {
   9220   internal_error
   9221     ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
   9222      "at %s:%d",
   9223      idx + 1, len, function, trim_filename (file), line);
   9224 }
   9225 
   9226 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
   9227    (dynamically sized) vector.  */
   9228 
   9229 void
   9230 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
   9231 			   const char *function)
   9232 {
   9233   internal_error
   9234     ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
   9235      idx + 1, len, function, trim_filename (file), line);
   9236 }
   9237 
   9238 /* Similar to above, except that the check is for the bounds of the operand
   9239    vector of an expression node EXP.  */
   9240 
   9241 void
   9242 tree_operand_check_failed (int idx, const_tree exp, const char *file,
   9243 			   int line, const char *function)
   9244 {
   9245   enum tree_code code = TREE_CODE (exp);
   9246   internal_error
   9247     ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
   9248      idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
   9249      function, trim_filename (file), line);
   9250 }
   9251 
   9252 /* Similar to above, except that the check is for the number of
   9253    operands of an OMP_CLAUSE node.  */
   9254 
   9255 void
   9256 omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
   9257 			         int line, const char *function)
   9258 {
   9259   internal_error
   9260     ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
   9261      "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
   9262      omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
   9263      trim_filename (file), line);
   9264 }
   9265 #endif /* ENABLE_TREE_CHECKING */
   9266 
   9267 /* Create a new vector type node holding NUNITS units of type INNERTYPE,
   9269    and mapped to the machine mode MODE.  Initialize its fields and build
   9270    the information necessary for debugging output.  */
   9271 
   9272 static tree
   9273 make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
   9274 {
   9275   tree t;
   9276   tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
   9277 
   9278   t = make_node (VECTOR_TYPE);
   9279   TREE_TYPE (t) = mv_innertype;
   9280   SET_TYPE_VECTOR_SUBPARTS (t, nunits);
   9281   SET_TYPE_MODE (t, mode);
   9282 
   9283   if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
   9284     SET_TYPE_STRUCTURAL_EQUALITY (t);
   9285   else if ((TYPE_CANONICAL (mv_innertype) != innertype
   9286 	    || mode != VOIDmode)
   9287 	   && !VECTOR_BOOLEAN_TYPE_P (t))
   9288     TYPE_CANONICAL (t)
   9289       = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
   9290 
   9291   layout_type (t);
   9292 
   9293   hashval_t hash = type_hash_canon_hash (t);
   9294   t = type_hash_canon (hash, t);
   9295 
   9296   /* We have built a main variant, based on the main variant of the
   9297      inner type. Use it to build the variant we return.  */
   9298   if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
   9299       && TREE_TYPE (t) != innertype)
   9300     return build_type_attribute_qual_variant (t,
   9301 					      TYPE_ATTRIBUTES (innertype),
   9302 					      TYPE_QUALS (innertype));
   9303 
   9304   return t;
   9305 }
   9306 
   9307 static tree
   9308 make_or_reuse_type (unsigned size, int unsignedp)
   9309 {
   9310   int i;
   9311 
   9312   if (size == INT_TYPE_SIZE)
   9313     return unsignedp ? unsigned_type_node : integer_type_node;
   9314   if (size == CHAR_TYPE_SIZE)
   9315     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
   9316   if (size == SHORT_TYPE_SIZE)
   9317     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
   9318   if (size == LONG_TYPE_SIZE)
   9319     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
   9320   if (size == LONG_LONG_TYPE_SIZE)
   9321     return (unsignedp ? long_long_unsigned_type_node
   9322             : long_long_integer_type_node);
   9323 
   9324   for (i = 0; i < NUM_INT_N_ENTS; i ++)
   9325     if (size == int_n_data[i].bitsize
   9326 	&& int_n_enabled_p[i])
   9327       return (unsignedp ? int_n_trees[i].unsigned_type
   9328 	      : int_n_trees[i].signed_type);
   9329 
   9330   if (unsignedp)
   9331     return make_unsigned_type (size);
   9332   else
   9333     return make_signed_type (size);
   9334 }
   9335 
   9336 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP.  */
   9337 
   9338 static tree
   9339 make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
   9340 {
   9341   if (satp)
   9342     {
   9343       if (size == SHORT_FRACT_TYPE_SIZE)
   9344 	return unsignedp ? sat_unsigned_short_fract_type_node
   9345 			 : sat_short_fract_type_node;
   9346       if (size == FRACT_TYPE_SIZE)
   9347 	return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
   9348       if (size == LONG_FRACT_TYPE_SIZE)
   9349 	return unsignedp ? sat_unsigned_long_fract_type_node
   9350 			 : sat_long_fract_type_node;
   9351       if (size == LONG_LONG_FRACT_TYPE_SIZE)
   9352 	return unsignedp ? sat_unsigned_long_long_fract_type_node
   9353 			 : sat_long_long_fract_type_node;
   9354     }
   9355   else
   9356     {
   9357       if (size == SHORT_FRACT_TYPE_SIZE)
   9358 	return unsignedp ? unsigned_short_fract_type_node
   9359 			 : short_fract_type_node;
   9360       if (size == FRACT_TYPE_SIZE)
   9361 	return unsignedp ? unsigned_fract_type_node : fract_type_node;
   9362       if (size == LONG_FRACT_TYPE_SIZE)
   9363 	return unsignedp ? unsigned_long_fract_type_node
   9364 			 : long_fract_type_node;
   9365       if (size == LONG_LONG_FRACT_TYPE_SIZE)
   9366 	return unsignedp ? unsigned_long_long_fract_type_node
   9367 			 : long_long_fract_type_node;
   9368     }
   9369 
   9370   return make_fract_type (size, unsignedp, satp);
   9371 }
   9372 
   9373 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP.  */
   9374 
   9375 static tree
   9376 make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
   9377 {
   9378   if (satp)
   9379     {
   9380       if (size == SHORT_ACCUM_TYPE_SIZE)
   9381 	return unsignedp ? sat_unsigned_short_accum_type_node
   9382 			 : sat_short_accum_type_node;
   9383       if (size == ACCUM_TYPE_SIZE)
   9384 	return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
   9385       if (size == LONG_ACCUM_TYPE_SIZE)
   9386 	return unsignedp ? sat_unsigned_long_accum_type_node
   9387 			 : sat_long_accum_type_node;
   9388       if (size == LONG_LONG_ACCUM_TYPE_SIZE)
   9389 	return unsignedp ? sat_unsigned_long_long_accum_type_node
   9390 			 : sat_long_long_accum_type_node;
   9391     }
   9392   else
   9393     {
   9394       if (size == SHORT_ACCUM_TYPE_SIZE)
   9395 	return unsignedp ? unsigned_short_accum_type_node
   9396 			 : short_accum_type_node;
   9397       if (size == ACCUM_TYPE_SIZE)
   9398 	return unsignedp ? unsigned_accum_type_node : accum_type_node;
   9399       if (size == LONG_ACCUM_TYPE_SIZE)
   9400 	return unsignedp ? unsigned_long_accum_type_node
   9401 			 : long_accum_type_node;
   9402       if (size == LONG_LONG_ACCUM_TYPE_SIZE)
   9403 	return unsignedp ? unsigned_long_long_accum_type_node
   9404 			 : long_long_accum_type_node;
   9405     }
   9406 
   9407   return make_accum_type (size, unsignedp, satp);
   9408 }
   9409 
   9410 
   9411 /* Create an atomic variant node for TYPE.  This routine is called
   9412    during initialization of data types to create the 5 basic atomic
   9413    types.  The generic build_variant_type function requires these to
   9414    already be set up in order to function properly, so cannot be
   9415    called from there.  If ALIGN is non-zero, then ensure alignment is
   9416    overridden to this value.  */
   9417 
   9418 static tree
   9419 build_atomic_base (tree type, unsigned int align)
   9420 {
   9421   tree t;
   9422 
   9423   /* Make sure its not already registered.  */
   9424   if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
   9425     return t;
   9426 
   9427   t = build_variant_type_copy (type);
   9428   set_type_quals (t, TYPE_QUAL_ATOMIC);
   9429 
   9430   if (align)
   9431     SET_TYPE_ALIGN (t, align);
   9432 
   9433   return t;
   9434 }
   9435 
   9436 /* Information about the _FloatN and _FloatNx types.  This must be in
   9437    the same order as the corresponding TI_* enum values.  */
   9438 const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
   9439   {
   9440     { 16, false },
   9441     { 32, false },
   9442     { 64, false },
   9443     { 128, false },
   9444     { 32, true },
   9445     { 64, true },
   9446     { 128, true },
   9447   };
   9448 
   9449 
   9450 /* Create nodes for all integer types (and error_mark_node) using the sizes
   9451    of C datatypes.  SIGNED_CHAR specifies whether char is signed.  */
   9452 
   9453 void
   9454 build_common_tree_nodes (bool signed_char)
   9455 {
   9456   int i;
   9457 
   9458   error_mark_node = make_node (ERROR_MARK);
   9459   TREE_TYPE (error_mark_node) = error_mark_node;
   9460 
   9461   initialize_sizetypes ();
   9462 
   9463   /* Define both `signed char' and `unsigned char'.  */
   9464   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
   9465   TYPE_STRING_FLAG (signed_char_type_node) = 1;
   9466   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
   9467   TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
   9468 
   9469   /* Define `char', which is like either `signed char' or `unsigned char'
   9470      but not the same as either.  */
   9471   char_type_node
   9472     = (signed_char
   9473        ? make_signed_type (CHAR_TYPE_SIZE)
   9474        : make_unsigned_type (CHAR_TYPE_SIZE));
   9475   TYPE_STRING_FLAG (char_type_node) = 1;
   9476 
   9477   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
   9478   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
   9479   integer_type_node = make_signed_type (INT_TYPE_SIZE);
   9480   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
   9481   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
   9482   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
   9483   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
   9484   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
   9485 
   9486   for (i = 0; i < NUM_INT_N_ENTS; i ++)
   9487     {
   9488       int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
   9489       int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
   9490 
   9491       if (int_n_enabled_p[i])
   9492 	{
   9493 	  integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
   9494 	  integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
   9495 	}
   9496     }
   9497 
   9498   /* Define a boolean type.  This type only represents boolean values but
   9499      may be larger than char depending on the value of BOOL_TYPE_SIZE.  */
   9500   boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
   9501   TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
   9502   TYPE_PRECISION (boolean_type_node) = 1;
   9503   TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
   9504 
   9505   /* Define what type to use for size_t.  */
   9506   if (strcmp (SIZE_TYPE, "unsigned int") == 0)
   9507     size_type_node = unsigned_type_node;
   9508   else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
   9509     size_type_node = long_unsigned_type_node;
   9510   else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
   9511     size_type_node = long_long_unsigned_type_node;
   9512   else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
   9513     size_type_node = short_unsigned_type_node;
   9514   else
   9515     {
   9516       int i;
   9517 
   9518       size_type_node = NULL_TREE;
   9519       for (i = 0; i < NUM_INT_N_ENTS; i++)
   9520 	if (int_n_enabled_p[i])
   9521 	  {
   9522 	    char name[50], altname[50];
   9523 	    sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
   9524 	    sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
   9525 
   9526 	    if (strcmp (name, SIZE_TYPE) == 0
   9527 		|| strcmp (altname, SIZE_TYPE) == 0)
   9528 	      {
   9529 		size_type_node = int_n_trees[i].unsigned_type;
   9530 	      }
   9531 	  }
   9532       if (size_type_node == NULL_TREE)
   9533 	gcc_unreachable ();
   9534     }
   9535 
   9536   /* Define what type to use for ptrdiff_t.  */
   9537   if (strcmp (PTRDIFF_TYPE, "int") == 0)
   9538     ptrdiff_type_node = integer_type_node;
   9539   else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
   9540     ptrdiff_type_node = long_integer_type_node;
   9541   else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
   9542     ptrdiff_type_node = long_long_integer_type_node;
   9543   else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
   9544     ptrdiff_type_node = short_integer_type_node;
   9545   else
   9546     {
   9547       ptrdiff_type_node = NULL_TREE;
   9548       for (int i = 0; i < NUM_INT_N_ENTS; i++)
   9549 	if (int_n_enabled_p[i])
   9550 	  {
   9551 	    char name[50], altname[50];
   9552 	    sprintf (name, "__int%d", int_n_data[i].bitsize);
   9553 	    sprintf (altname, "__int%d__", int_n_data[i].bitsize);
   9554 
   9555 	    if (strcmp (name, PTRDIFF_TYPE) == 0
   9556 		|| strcmp (altname, PTRDIFF_TYPE) == 0)
   9557 	      ptrdiff_type_node = int_n_trees[i].signed_type;
   9558 	  }
   9559       if (ptrdiff_type_node == NULL_TREE)
   9560 	gcc_unreachable ();
   9561     }
   9562 
   9563   /* Fill in the rest of the sized types.  Reuse existing type nodes
   9564      when possible.  */
   9565   intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
   9566   intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
   9567   intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
   9568   intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
   9569   intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
   9570 
   9571   unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
   9572   unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
   9573   unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
   9574   unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
   9575   unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
   9576 
   9577   /* Don't call build_qualified type for atomics.  That routine does
   9578      special processing for atomics, and until they are initialized
   9579      it's better not to make that call.
   9580 
   9581      Check to see if there is a target override for atomic types.  */
   9582 
   9583   atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
   9584 					targetm.atomic_align_for_mode (QImode));
   9585   atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
   9586 					targetm.atomic_align_for_mode (HImode));
   9587   atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
   9588 					targetm.atomic_align_for_mode (SImode));
   9589   atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
   9590 					targetm.atomic_align_for_mode (DImode));
   9591   atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
   9592 					targetm.atomic_align_for_mode (TImode));
   9593 
   9594   access_public_node = get_identifier ("public");
   9595   access_protected_node = get_identifier ("protected");
   9596   access_private_node = get_identifier ("private");
   9597 
   9598   /* Define these next since types below may used them.  */
   9599   integer_zero_node = build_int_cst (integer_type_node, 0);
   9600   integer_one_node = build_int_cst (integer_type_node, 1);
   9601   integer_three_node = build_int_cst (integer_type_node, 3);
   9602   integer_minus_one_node = build_int_cst (integer_type_node, -1);
   9603 
   9604   size_zero_node = size_int (0);
   9605   size_one_node = size_int (1);
   9606   bitsize_zero_node = bitsize_int (0);
   9607   bitsize_one_node = bitsize_int (1);
   9608   bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
   9609 
   9610   boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
   9611   boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
   9612 
   9613   void_type_node = make_node (VOID_TYPE);
   9614   layout_type (void_type_node);
   9615 
   9616   /* We are not going to have real types in C with less than byte alignment,
   9617      so we might as well not have any types that claim to have it.  */
   9618   SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
   9619   TYPE_USER_ALIGN (void_type_node) = 0;
   9620 
   9621   void_node = make_node (VOID_CST);
   9622   TREE_TYPE (void_node) = void_type_node;
   9623 
   9624   void_list_node = build_tree_list (NULL_TREE, void_type_node);
   9625 
   9626   null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
   9627   layout_type (TREE_TYPE (null_pointer_node));
   9628 
   9629   ptr_type_node = build_pointer_type (void_type_node);
   9630   const_ptr_type_node
   9631     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
   9632   for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
   9633     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
   9634 
   9635   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
   9636 
   9637   float_type_node = make_node (REAL_TYPE);
   9638   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
   9639   layout_type (float_type_node);
   9640 
   9641   double_type_node = make_node (REAL_TYPE);
   9642   TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
   9643   layout_type (double_type_node);
   9644 
   9645   long_double_type_node = make_node (REAL_TYPE);
   9646   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
   9647   layout_type (long_double_type_node);
   9648 
   9649   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
   9650     {
   9651       int n = floatn_nx_types[i].n;
   9652       bool extended = floatn_nx_types[i].extended;
   9653       scalar_float_mode mode;
   9654       if (!targetm.floatn_mode (n, extended).exists (&mode))
   9655 	continue;
   9656       int precision = GET_MODE_PRECISION (mode);
   9657       /* Work around the rs6000 KFmode having precision 113 not
   9658 	 128.  */
   9659       const struct real_format *fmt = REAL_MODE_FORMAT (mode);
   9660       gcc_assert (fmt->b == 2 && fmt->emin + fmt->emax == 3);
   9661       int min_precision = fmt->p + ceil_log2 (fmt->emax - fmt->emin);
   9662       if (!extended)
   9663 	gcc_assert (min_precision == n);
   9664       if (precision < min_precision)
   9665 	precision = min_precision;
   9666       FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
   9667       TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
   9668       layout_type (FLOATN_NX_TYPE_NODE (i));
   9669       SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
   9670     }
   9671   float128t_type_node = float128_type_node;
   9672 #ifdef HAVE_BFmode
   9673   if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
   9674       && targetm.scalar_mode_supported_p (BFmode)
   9675       && targetm.libgcc_floating_mode_supported_p (BFmode))
   9676     {
   9677       bfloat16_type_node = make_node (REAL_TYPE);
   9678       TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
   9679       layout_type (bfloat16_type_node);
   9680       SET_TYPE_MODE (bfloat16_type_node, BFmode);
   9681     }
   9682 #endif
   9683 
   9684   float_ptr_type_node = build_pointer_type (float_type_node);
   9685   double_ptr_type_node = build_pointer_type (double_type_node);
   9686   long_double_ptr_type_node = build_pointer_type (long_double_type_node);
   9687   integer_ptr_type_node = build_pointer_type (integer_type_node);
   9688 
   9689   /* Fixed size integer types.  */
   9690   uint16_type_node = make_or_reuse_type (16, 1);
   9691   uint32_type_node = make_or_reuse_type (32, 1);
   9692   uint64_type_node = make_or_reuse_type (64, 1);
   9693   if (targetm.scalar_mode_supported_p (TImode))
   9694     uint128_type_node = make_or_reuse_type (128, 1);
   9695 
   9696   /* Decimal float types. */
   9697   if (targetm.decimal_float_supported_p ())
   9698     {
   9699       dfloat32_type_node = make_node (REAL_TYPE);
   9700       TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
   9701       SET_TYPE_MODE (dfloat32_type_node, SDmode);
   9702       layout_type (dfloat32_type_node);
   9703 
   9704       dfloat64_type_node = make_node (REAL_TYPE);
   9705       TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
   9706       SET_TYPE_MODE (dfloat64_type_node, DDmode);
   9707       layout_type (dfloat64_type_node);
   9708 
   9709       dfloat128_type_node = make_node (REAL_TYPE);
   9710       TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
   9711       SET_TYPE_MODE (dfloat128_type_node, TDmode);
   9712       layout_type (dfloat128_type_node);
   9713     }
   9714 
   9715   complex_integer_type_node = build_complex_type (integer_type_node, true);
   9716   complex_float_type_node = build_complex_type (float_type_node, true);
   9717   complex_double_type_node = build_complex_type (double_type_node, true);
   9718   complex_long_double_type_node = build_complex_type (long_double_type_node,
   9719 						      true);
   9720 
   9721   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
   9722     {
   9723       if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
   9724 	COMPLEX_FLOATN_NX_TYPE_NODE (i)
   9725 	  = build_complex_type (FLOATN_NX_TYPE_NODE (i));
   9726     }
   9727 
   9728 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned.  */
   9729 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
   9730   sat_ ## KIND ## _type_node = \
   9731     make_sat_signed_ ## KIND ## _type (SIZE); \
   9732   sat_unsigned_ ## KIND ## _type_node = \
   9733     make_sat_unsigned_ ## KIND ## _type (SIZE); \
   9734   KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
   9735   unsigned_ ## KIND ## _type_node = \
   9736     make_unsigned_ ## KIND ## _type (SIZE);
   9737 
   9738 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
   9739   sat_ ## WIDTH ## KIND ## _type_node = \
   9740     make_sat_signed_ ## KIND ## _type (SIZE); \
   9741   sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
   9742     make_sat_unsigned_ ## KIND ## _type (SIZE); \
   9743   WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
   9744   unsigned_ ## WIDTH ## KIND ## _type_node = \
   9745     make_unsigned_ ## KIND ## _type (SIZE);
   9746 
   9747 /* Make fixed-point type nodes based on four different widths.  */
   9748 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
   9749   MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
   9750   MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
   9751   MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
   9752   MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
   9753 
   9754 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned.  */
   9755 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
   9756   NAME ## _type_node = \
   9757     make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
   9758   u ## NAME ## _type_node = \
   9759     make_or_reuse_unsigned_ ## KIND ## _type \
   9760       (GET_MODE_BITSIZE (U ## MODE ## mode)); \
   9761   sat_ ## NAME ## _type_node = \
   9762     make_or_reuse_sat_signed_ ## KIND ## _type \
   9763       (GET_MODE_BITSIZE (MODE ## mode)); \
   9764   sat_u ## NAME ## _type_node = \
   9765     make_or_reuse_sat_unsigned_ ## KIND ## _type \
   9766       (GET_MODE_BITSIZE (U ## MODE ## mode));
   9767 
   9768   /* Fixed-point type and mode nodes.  */
   9769   MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
   9770   MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
   9771   MAKE_FIXED_MODE_NODE (fract, qq, QQ)
   9772   MAKE_FIXED_MODE_NODE (fract, hq, HQ)
   9773   MAKE_FIXED_MODE_NODE (fract, sq, SQ)
   9774   MAKE_FIXED_MODE_NODE (fract, dq, DQ)
   9775   MAKE_FIXED_MODE_NODE (fract, tq, TQ)
   9776   MAKE_FIXED_MODE_NODE (accum, ha, HA)
   9777   MAKE_FIXED_MODE_NODE (accum, sa, SA)
   9778   MAKE_FIXED_MODE_NODE (accum, da, DA)
   9779   MAKE_FIXED_MODE_NODE (accum, ta, TA)
   9780 
   9781   {
   9782     tree t = targetm.build_builtin_va_list ();
   9783 
   9784     /* Many back-ends define record types without setting TYPE_NAME.
   9785        If we copied the record type here, we'd keep the original
   9786        record type without a name.  This breaks name mangling.  So,
   9787        don't copy record types and let c_common_nodes_and_builtins()
   9788        declare the type to be __builtin_va_list.  */
   9789     if (TREE_CODE (t) != RECORD_TYPE)
   9790       t = build_variant_type_copy (t);
   9791 
   9792     va_list_type_node = t;
   9793   }
   9794 
   9795   /* SCEV analyzer global shared trees.  */
   9796   chrec_dont_know = make_node (SCEV_NOT_KNOWN);
   9797   TREE_TYPE (chrec_dont_know) = void_type_node;
   9798   chrec_known = make_node (SCEV_KNOWN);
   9799   TREE_TYPE (chrec_known) = void_type_node;
   9800 }
   9801 
   9802 /* Modify DECL for given flags.
   9803    TM_PURE attribute is set only on types, so the function will modify
   9804    DECL's type when ECF_TM_PURE is used.  */
   9805 
   9806 void
   9807 set_call_expr_flags (tree decl, int flags)
   9808 {
   9809   if (flags & ECF_NOTHROW)
   9810     TREE_NOTHROW (decl) = 1;
   9811   if (flags & ECF_CONST)
   9812     TREE_READONLY (decl) = 1;
   9813   if (flags & ECF_PURE)
   9814     DECL_PURE_P (decl) = 1;
   9815   if (flags & ECF_LOOPING_CONST_OR_PURE)
   9816     DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
   9817   if (flags & ECF_NOVOPS)
   9818     DECL_IS_NOVOPS (decl) = 1;
   9819   if (flags & ECF_NORETURN)
   9820     TREE_THIS_VOLATILE (decl) = 1;
   9821   if (flags & ECF_MALLOC)
   9822     DECL_IS_MALLOC (decl) = 1;
   9823   if (flags & ECF_RETURNS_TWICE)
   9824     DECL_IS_RETURNS_TWICE (decl) = 1;
   9825   if (flags & ECF_LEAF)
   9826     DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
   9827 					NULL, DECL_ATTRIBUTES (decl));
   9828   if (flags & ECF_COLD)
   9829     DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
   9830 					NULL, DECL_ATTRIBUTES (decl));
   9831   if (flags & ECF_RET1)
   9832     DECL_ATTRIBUTES (decl)
   9833       = tree_cons (get_identifier ("fn spec"),
   9834 		   build_tree_list (NULL_TREE, build_string (2, "1 ")),
   9835 		   DECL_ATTRIBUTES (decl));
   9836   if ((flags & ECF_TM_PURE) && flag_tm)
   9837     apply_tm_attr (decl, get_identifier ("transaction_pure"));
   9838   if ((flags & ECF_XTHROW))
   9839     DECL_ATTRIBUTES (decl)
   9840       = tree_cons (get_identifier ("expected_throw"),
   9841 		   NULL, DECL_ATTRIBUTES (decl));
   9842   /* Looping const or pure is implied by noreturn.
   9843      There is currently no way to declare looping const or looping pure alone.  */
   9844   gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
   9845 	      || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
   9846 }
   9847 
   9848 
   9849 /* A subroutine of build_common_builtin_nodes.  Define a builtin function.  */
   9850 
   9851 static void
   9852 local_define_builtin (const char *name, tree type, enum built_in_function code,
   9853                       const char *library_name, int ecf_flags)
   9854 {
   9855   tree decl;
   9856 
   9857   decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
   9858 			       library_name, NULL_TREE);
   9859   set_call_expr_flags (decl, ecf_flags);
   9860 
   9861   set_builtin_decl (code, decl, true);
   9862 }
   9863 
   9864 /* Call this function after instantiating all builtins that the language
   9865    front end cares about.  This will build the rest of the builtins
   9866    and internal functions that are relied upon by the tree optimizers and
   9867    the middle-end.  */
   9868 
   9869 void
   9870 build_common_builtin_nodes (void)
   9871 {
   9872   tree tmp, ftype;
   9873   int ecf_flags;
   9874 
   9875   if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
   9876     {
   9877       ftype = build_function_type_list (void_type_node,
   9878 					ptr_type_node,
   9879 					ptr_type_node,
   9880 					integer_type_node,
   9881 					NULL_TREE);
   9882       local_define_builtin ("__builtin_clear_padding", ftype,
   9883 			    BUILT_IN_CLEAR_PADDING,
   9884 			    "__builtin_clear_padding",
   9885 			    ECF_LEAF | ECF_NOTHROW);
   9886     }
   9887 
   9888   if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
   9889       || !builtin_decl_explicit_p (BUILT_IN_TRAP)
   9890       || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
   9891       || !builtin_decl_explicit_p (BUILT_IN_ABORT))
   9892     {
   9893       ftype = build_function_type (void_type_node, void_list_node);
   9894       if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
   9895 	local_define_builtin ("__builtin_unreachable", ftype,
   9896 			      BUILT_IN_UNREACHABLE,
   9897 			      "__builtin_unreachable",
   9898 			      ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
   9899 			      | ECF_CONST | ECF_COLD);
   9900       if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
   9901 	local_define_builtin ("__builtin_unreachable trap", ftype,
   9902 			      BUILT_IN_UNREACHABLE_TRAP,
   9903 			      "__builtin_unreachable trap",
   9904 			      ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
   9905 			      | ECF_CONST | ECF_COLD);
   9906       if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
   9907 	local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
   9908 			      "abort",
   9909 			      ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
   9910       if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
   9911 	local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
   9912 			      "__builtin_trap",
   9913 			      ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
   9914     }
   9915 
   9916   if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
   9917       || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
   9918     {
   9919       ftype = build_function_type_list (ptr_type_node,
   9920 					ptr_type_node, const_ptr_type_node,
   9921 					size_type_node, NULL_TREE);
   9922 
   9923       if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
   9924 	local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
   9925 			      "memcpy", ECF_NOTHROW | ECF_LEAF);
   9926       if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
   9927 	local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
   9928 			      "memmove", ECF_NOTHROW | ECF_LEAF);
   9929     }
   9930 
   9931   if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
   9932     {
   9933       ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
   9934 					const_ptr_type_node, size_type_node,
   9935 					NULL_TREE);
   9936       local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
   9937 			    "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
   9938     }
   9939 
   9940   if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
   9941     {
   9942       ftype = build_function_type_list (ptr_type_node,
   9943 					ptr_type_node, integer_type_node,
   9944 					size_type_node, NULL_TREE);
   9945       local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
   9946 			    "memset", ECF_NOTHROW | ECF_LEAF);
   9947     }
   9948 
   9949   /* If we're checking the stack, `alloca' can throw.  */
   9950   const int alloca_flags
   9951     = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
   9952 
   9953   if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
   9954     {
   9955       ftype = build_function_type_list (ptr_type_node,
   9956 					size_type_node, NULL_TREE);
   9957       local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
   9958 			    "alloca", alloca_flags);
   9959     }
   9960 
   9961   ftype = build_function_type_list (ptr_type_node, size_type_node,
   9962 				    size_type_node, NULL_TREE);
   9963   local_define_builtin ("__builtin_alloca_with_align", ftype,
   9964 			BUILT_IN_ALLOCA_WITH_ALIGN,
   9965 			"__builtin_alloca_with_align",
   9966 			alloca_flags);
   9967 
   9968   ftype = build_function_type_list (ptr_type_node, size_type_node,
   9969 				    size_type_node, size_type_node, NULL_TREE);
   9970   local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
   9971 			BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
   9972 			"__builtin_alloca_with_align_and_max",
   9973 			alloca_flags);
   9974 
   9975   ftype = build_function_type_list (void_type_node,
   9976 				    ptr_type_node, ptr_type_node,
   9977 				    ptr_type_node, NULL_TREE);
   9978   local_define_builtin ("__builtin_init_trampoline", ftype,
   9979 			BUILT_IN_INIT_TRAMPOLINE,
   9980 			"__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
   9981   local_define_builtin ("__builtin_init_heap_trampoline", ftype,
   9982 			BUILT_IN_INIT_HEAP_TRAMPOLINE,
   9983 			"__builtin_init_heap_trampoline",
   9984 			ECF_NOTHROW | ECF_LEAF);
   9985   local_define_builtin ("__builtin_init_descriptor", ftype,
   9986 			BUILT_IN_INIT_DESCRIPTOR,
   9987 			"__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
   9988 
   9989   ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
   9990   local_define_builtin ("__builtin_adjust_trampoline", ftype,
   9991 			BUILT_IN_ADJUST_TRAMPOLINE,
   9992 			"__builtin_adjust_trampoline",
   9993 			ECF_CONST | ECF_NOTHROW);
   9994   local_define_builtin ("__builtin_adjust_descriptor", ftype,
   9995 			BUILT_IN_ADJUST_DESCRIPTOR,
   9996 			"__builtin_adjust_descriptor",
   9997 			ECF_CONST | ECF_NOTHROW);
   9998 
   9999   ftype = build_function_type_list (void_type_node,
   10000 				    ptr_type_node, ptr_type_node, NULL_TREE);
   10001   if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
   10002     local_define_builtin ("__builtin___clear_cache", ftype,
   10003 			  BUILT_IN_CLEAR_CACHE,
   10004 			  "__clear_cache",
   10005 			  ECF_NOTHROW);
   10006 
   10007   local_define_builtin ("__builtin_nonlocal_goto", ftype,
   10008 			BUILT_IN_NONLOCAL_GOTO,
   10009 			"__builtin_nonlocal_goto",
   10010 			ECF_NORETURN | ECF_NOTHROW);
   10011 
   10012   tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
   10013 
   10014   if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
   10015     {
   10016       ftype = build_function_type_list (void_type_node,
   10017 					ptr_type_node, // void *chain
   10018 					ptr_type_node, // void *func
   10019 					ptr_ptr_type_node, // void **dst
   10020 					NULL_TREE);
   10021       local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
   10022 			    BUILT_IN_GCC_NESTED_PTR_CREATED,
   10023 			    "__gcc_nested_func_ptr_created", ECF_NOTHROW);
   10024     }
   10025 
   10026   if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
   10027     {
   10028       ftype = build_function_type_list (void_type_node, NULL_TREE);
   10029       local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
   10030 			    BUILT_IN_GCC_NESTED_PTR_DELETED,
   10031 			    "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
   10032     }
   10033 
   10034   ftype = build_function_type_list (void_type_node,
   10035 				    ptr_type_node, ptr_type_node, NULL_TREE);
   10036   local_define_builtin ("__builtin_setjmp_setup", ftype,
   10037 			BUILT_IN_SETJMP_SETUP,
   10038 			"__builtin_setjmp_setup", ECF_NOTHROW);
   10039 
   10040   ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
   10041   local_define_builtin ("__builtin_setjmp_receiver", ftype,
   10042 			BUILT_IN_SETJMP_RECEIVER,
   10043 			"__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
   10044 
   10045   ftype = build_function_type_list (ptr_type_node, NULL_TREE);
   10046   local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
   10047 			"__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
   10048 
   10049   ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
   10050   local_define_builtin ("__builtin_stack_restore", ftype,
   10051 			BUILT_IN_STACK_RESTORE,
   10052 			"__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
   10053 
   10054   ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
   10055 				    const_ptr_type_node, size_type_node,
   10056 				    NULL_TREE);
   10057   local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
   10058 			"__builtin_memcmp_eq",
   10059 			ECF_PURE | ECF_NOTHROW | ECF_LEAF);
   10060 
   10061   local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
   10062 			"__builtin_strncmp_eq",
   10063 			ECF_PURE | ECF_NOTHROW | ECF_LEAF);
   10064 
   10065   local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
   10066 			"__builtin_strcmp_eq",
   10067 			ECF_PURE | ECF_NOTHROW | ECF_LEAF);
   10068 
   10069   /* If there's a possibility that we might use the ARM EABI, build the
   10070     alternate __cxa_end_cleanup node used to resume from C++.  */
   10071   if (targetm.arm_eabi_unwinder)
   10072     {
   10073       ftype = build_function_type_list (void_type_node, NULL_TREE);
   10074       local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
   10075 			    BUILT_IN_CXA_END_CLEANUP,
   10076 			    "__cxa_end_cleanup",
   10077 			    ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
   10078     }
   10079 
   10080   ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
   10081   local_define_builtin ("__builtin_unwind_resume", ftype,
   10082 			BUILT_IN_UNWIND_RESUME,
   10083 			((targetm_common.except_unwind_info (&global_options)
   10084 			  == UI_SJLJ)
   10085 			 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
   10086 			ECF_NORETURN | ECF_XTHROW);
   10087 
   10088   if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
   10089     {
   10090       ftype = build_function_type_list (ptr_type_node, integer_type_node,
   10091 					NULL_TREE);
   10092       local_define_builtin ("__builtin_return_address", ftype,
   10093 			    BUILT_IN_RETURN_ADDRESS,
   10094 			    "__builtin_return_address",
   10095 			    ECF_NOTHROW);
   10096     }
   10097 
   10098   if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
   10099       || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
   10100     {
   10101       ftype = build_function_type_list (void_type_node, ptr_type_node,
   10102 					ptr_type_node, NULL_TREE);
   10103       if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
   10104 	local_define_builtin ("__cyg_profile_func_enter", ftype,
   10105 			      BUILT_IN_PROFILE_FUNC_ENTER,
   10106 			      "__cyg_profile_func_enter", 0);
   10107       if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
   10108 	local_define_builtin ("__cyg_profile_func_exit", ftype,
   10109 			      BUILT_IN_PROFILE_FUNC_EXIT,
   10110 			      "__cyg_profile_func_exit", 0);
   10111     }
   10112 
   10113   /* The exception object and filter values from the runtime.  The argument
   10114      must be zero before exception lowering, i.e. from the front end.  After
   10115      exception lowering, it will be the region number for the exception
   10116      landing pad.  These functions are PURE instead of CONST to prevent
   10117      them from being hoisted past the exception edge that will initialize
   10118      its value in the landing pad.  */
   10119   ftype = build_function_type_list (ptr_type_node,
   10120 				    integer_type_node, NULL_TREE);
   10121   ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
   10122   /* Only use TM_PURE if we have TM language support.  */
   10123   if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
   10124     ecf_flags |= ECF_TM_PURE;
   10125   local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
   10126 			"__builtin_eh_pointer", ecf_flags);
   10127 
   10128   tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
   10129   ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
   10130   local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
   10131 			"__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
   10132 
   10133   ftype = build_function_type_list (void_type_node,
   10134 				    integer_type_node, integer_type_node,
   10135 				    NULL_TREE);
   10136   local_define_builtin ("__builtin_eh_copy_values", ftype,
   10137 			BUILT_IN_EH_COPY_VALUES,
   10138 			"__builtin_eh_copy_values", ECF_NOTHROW);
   10139 
   10140   /* Complex multiplication and division.  These are handled as builtins
   10141      rather than optabs because emit_library_call_value doesn't support
   10142      complex.  Further, we can do slightly better with folding these
   10143      beasties if the real and complex parts of the arguments are separate.  */
   10144   {
   10145     int mode;
   10146 
   10147     for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
   10148       {
   10149 	char mode_name_buf[4], *q;
   10150 	const char *p;
   10151 	enum built_in_function mcode, dcode;
   10152 	tree type, inner_type;
   10153 	const char *prefix = "__";
   10154 
   10155 	if (targetm.libfunc_gnu_prefix)
   10156 	  prefix = "__gnu_";
   10157 
   10158 	type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
   10159 	if (type == NULL)
   10160 	  continue;
   10161 	inner_type = TREE_TYPE (type);
   10162 
   10163 	ftype = build_function_type_list (type, inner_type, inner_type,
   10164 					  inner_type, inner_type, NULL_TREE);
   10165 
   10166         mcode = ((enum built_in_function)
   10167 		 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
   10168         dcode = ((enum built_in_function)
   10169 		 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
   10170 
   10171         for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
   10172 	  *q = TOLOWER (*p);
   10173 	*q = '\0';
   10174 
   10175 	/* For -ftrapping-math these should throw from a former
   10176 	   -fnon-call-exception stmt.  */
   10177 	built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
   10178 					NULL);
   10179         local_define_builtin (built_in_names[mcode], ftype, mcode,
   10180 			      built_in_names[mcode],
   10181 			      ECF_CONST | ECF_LEAF);
   10182 
   10183 	built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
   10184 					NULL);
   10185         local_define_builtin (built_in_names[dcode], ftype, dcode,
   10186 			      built_in_names[dcode],
   10187 			      ECF_CONST | ECF_LEAF);
   10188       }
   10189   }
   10190 
   10191   init_internal_fns ();
   10192 }
   10193 
   10194 /* HACK.  GROSS.  This is absolutely disgusting.  I wish there was a
   10195    better way.
   10196 
   10197    If we requested a pointer to a vector, build up the pointers that
   10198    we stripped off while looking for the inner type.  Similarly for
   10199    return values from functions.
   10200 
   10201    The argument TYPE is the top of the chain, and BOTTOM is the
   10202    new type which we will point to.  */
   10203 
   10204 tree
   10205 reconstruct_complex_type (tree type, tree bottom)
   10206 {
   10207   tree inner, outer;
   10208 
   10209   if (TREE_CODE (type) == POINTER_TYPE)
   10210     {
   10211       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
   10212       outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
   10213 					   TYPE_REF_CAN_ALIAS_ALL (type));
   10214     }
   10215   else if (TREE_CODE (type) == REFERENCE_TYPE)
   10216     {
   10217       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
   10218       outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
   10219 					     TYPE_REF_CAN_ALIAS_ALL (type));
   10220     }
   10221   else if (TREE_CODE (type) == ARRAY_TYPE)
   10222     {
   10223       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
   10224       outer = build_array_type (inner, TYPE_DOMAIN (type));
   10225     }
   10226   else if (TREE_CODE (type) == FUNCTION_TYPE)
   10227     {
   10228       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
   10229       outer = build_function_type (inner, TYPE_ARG_TYPES (type),
   10230 				   TYPE_NO_NAMED_ARGS_STDARG_P (type));
   10231     }
   10232   else if (TREE_CODE (type) == METHOD_TYPE)
   10233     {
   10234       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
   10235       /* The build_method_type_directly() routine prepends 'this' to argument list,
   10236          so we must compensate by getting rid of it.  */
   10237       outer
   10238 	= build_method_type_directly
   10239 	    (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
   10240 	     inner,
   10241 	     TREE_CHAIN (TYPE_ARG_TYPES (type)));
   10242     }
   10243   else if (TREE_CODE (type) == OFFSET_TYPE)
   10244     {
   10245       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
   10246       outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
   10247     }
   10248   else
   10249     return bottom;
   10250 
   10251   return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
   10252 					    TYPE_QUALS (type));
   10253 }
   10254 
   10255 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
   10256    the inner type.  */
   10257 tree
   10258 build_vector_type_for_mode (tree innertype, machine_mode mode)
   10259 {
   10260   poly_int64 nunits;
   10261   unsigned int bitsize;
   10262 
   10263   switch (GET_MODE_CLASS (mode))
   10264     {
   10265     case MODE_VECTOR_BOOL:
   10266     case MODE_VECTOR_INT:
   10267     case MODE_VECTOR_FLOAT:
   10268     case MODE_VECTOR_FRACT:
   10269     case MODE_VECTOR_UFRACT:
   10270     case MODE_VECTOR_ACCUM:
   10271     case MODE_VECTOR_UACCUM:
   10272       nunits = GET_MODE_NUNITS (mode);
   10273       break;
   10274 
   10275     case MODE_INT:
   10276       /* Check that there are no leftover bits.  */
   10277       bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
   10278       gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
   10279       nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
   10280       break;
   10281 
   10282     default:
   10283       gcc_unreachable ();
   10284     }
   10285 
   10286   return make_vector_type (innertype, nunits, mode);
   10287 }
   10288 
   10289 /* Similarly, but takes the inner type and number of units, which must be
   10290    a power of two.  */
   10291 
   10292 tree
   10293 build_vector_type (tree innertype, poly_int64 nunits)
   10294 {
   10295   return make_vector_type (innertype, nunits, VOIDmode);
   10296 }
   10297 
   10298 /* Build a truth vector with NUNITS units, giving it mode MASK_MODE.  */
   10299 
   10300 tree
   10301 build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
   10302 {
   10303   gcc_assert (mask_mode != BLKmode);
   10304 
   10305   unsigned HOST_WIDE_INT esize;
   10306   if (VECTOR_MODE_P (mask_mode))
   10307     {
   10308       poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
   10309       esize = vector_element_size (vsize, nunits);
   10310     }
   10311   else
   10312     esize = 1;
   10313 
   10314   tree bool_type = build_nonstandard_boolean_type (esize);
   10315 
   10316   return make_vector_type (bool_type, nunits, mask_mode);
   10317 }
   10318 
   10319 /* Build a vector type that holds one boolean result for each element of
   10320    vector type VECTYPE.  The public interface for this operation is
   10321    truth_type_for.  */
   10322 
   10323 static tree
   10324 build_truth_vector_type_for (tree vectype)
   10325 {
   10326   machine_mode vector_mode = TYPE_MODE (vectype);
   10327   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
   10328 
   10329   machine_mode mask_mode;
   10330   if (VECTOR_MODE_P (vector_mode)
   10331       && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
   10332     return build_truth_vector_type_for_mode (nunits, mask_mode);
   10333 
   10334   poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
   10335   unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
   10336   tree bool_type = build_nonstandard_boolean_type (esize);
   10337 
   10338   return make_vector_type (bool_type, nunits, VOIDmode);
   10339 }
   10340 
   10341 /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
   10342    set.  */
   10343 
   10344 tree
   10345 build_opaque_vector_type (tree innertype, poly_int64 nunits)
   10346 {
   10347   tree t = make_vector_type (innertype, nunits, VOIDmode);
   10348   tree cand;
   10349   /* We always build the non-opaque variant before the opaque one,
   10350      so if it already exists, it is TYPE_NEXT_VARIANT of this one.  */
   10351   cand = TYPE_NEXT_VARIANT (t);
   10352   if (cand
   10353       && TYPE_VECTOR_OPAQUE (cand)
   10354       && check_qualified_type (cand, t, TYPE_QUALS (t)))
   10355     return cand;
   10356   /* Othewise build a variant type and make sure to queue it after
   10357      the non-opaque type.  */
   10358   cand = build_distinct_type_copy (t);
   10359   TYPE_VECTOR_OPAQUE (cand) = true;
   10360   TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
   10361   TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
   10362   TYPE_NEXT_VARIANT (t) = cand;
   10363   TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
   10364   /* Type variants have no alias set defined.  */
   10365   TYPE_ALIAS_SET (cand) = -1;
   10366   return cand;
   10367 }
   10368 
   10369 /* Return the value of element I of VECTOR_CST T as a wide_int.  */
   10370 
   10371 static poly_wide_int
   10372 vector_cst_int_elt (const_tree t, unsigned int i)
   10373 {
   10374   /* First handle elements that are directly encoded.  */
   10375   unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
   10376   if (i < encoded_nelts)
   10377     return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
   10378 
   10379   /* Identify the pattern that contains element I and work out the index of
   10380      the last encoded element for that pattern.  */
   10381   unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
   10382   unsigned int pattern = i % npatterns;
   10383   unsigned int count = i / npatterns;
   10384   unsigned int final_i = encoded_nelts - npatterns + pattern;
   10385 
   10386   /* If there are no steps, the final encoded value is the right one.  */
   10387   if (!VECTOR_CST_STEPPED_P (t))
   10388     return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
   10389 
   10390   /* Otherwise work out the value from the last two encoded elements.  */
   10391   tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
   10392   tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
   10393   poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
   10394   return wi::to_poly_wide (v2) + (count - 2) * diff;
   10395 }
   10396 
   10397 /* Return the value of element I of VECTOR_CST T.  */
   10398 
   10399 tree
   10400 vector_cst_elt (const_tree t, unsigned int i)
   10401 {
   10402   /* First handle elements that are directly encoded.  */
   10403   unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
   10404   if (i < encoded_nelts)
   10405     return VECTOR_CST_ENCODED_ELT (t, i);
   10406 
   10407   /* If there are no steps, the final encoded value is the right one.  */
   10408   if (!VECTOR_CST_STEPPED_P (t))
   10409     {
   10410       /* Identify the pattern that contains element I and work out the index of
   10411 	 the last encoded element for that pattern.  */
   10412       unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
   10413       unsigned int pattern = i % npatterns;
   10414       unsigned int final_i = encoded_nelts - npatterns + pattern;
   10415       return VECTOR_CST_ENCODED_ELT (t, final_i);
   10416     }
   10417 
   10418   /* Otherwise work out the value from the last two encoded elements.  */
   10419   return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
   10420 			   vector_cst_int_elt (t, i));
   10421 }
   10422 
   10423 /* Given an initializer INIT, return TRUE if INIT is zero or some
   10424    aggregate of zeros.  Otherwise return FALSE.  If NONZERO is not
   10425    null, set *NONZERO if and only if INIT is known not to be all
   10426    zeros.  The combination of return value of false and *NONZERO
   10427    false implies that INIT may but need not be all zeros.  Other
   10428    combinations indicate definitive answers.  */
   10429 
   10430 bool
   10431 initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
   10432 {
   10433   bool dummy;
   10434   if (!nonzero)
   10435     nonzero = &dummy;
   10436 
   10437   /* Conservatively clear NONZERO and set it only if INIT is definitely
   10438      not all zero.  */
   10439   *nonzero = false;
   10440 
   10441   STRIP_NOPS (init);
   10442 
   10443   unsigned HOST_WIDE_INT off = 0;
   10444 
   10445   switch (TREE_CODE (init))
   10446     {
   10447     case INTEGER_CST:
   10448       if (integer_zerop (init))
   10449 	return true;
   10450 
   10451       *nonzero = true;
   10452       return false;
   10453 
   10454     case REAL_CST:
   10455       /* ??? Note that this is not correct for C4X float formats.  There,
   10456 	 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
   10457 	 negative exponent.  */
   10458       if (real_zerop (init)
   10459 	  && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
   10460 	return true;
   10461 
   10462       *nonzero = true;
   10463       return false;
   10464 
   10465     case FIXED_CST:
   10466       if (fixed_zerop (init))
   10467 	return true;
   10468 
   10469       *nonzero = true;
   10470       return false;
   10471 
   10472     case COMPLEX_CST:
   10473       if (integer_zerop (init)
   10474 	  || (real_zerop (init)
   10475 	      && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
   10476 	      && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
   10477 	return true;
   10478 
   10479       *nonzero = true;
   10480       return false;
   10481 
   10482     case VECTOR_CST:
   10483       if (VECTOR_CST_NPATTERNS (init) == 1
   10484 	  && VECTOR_CST_DUPLICATE_P (init)
   10485 	  && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
   10486 	return true;
   10487 
   10488       *nonzero = true;
   10489       return false;
   10490 
   10491     case CONSTRUCTOR:
   10492       {
   10493 	if (TREE_CLOBBER_P (init))
   10494 	  return false;
   10495 
   10496 	unsigned HOST_WIDE_INT idx;
   10497 	tree elt;
   10498 
   10499 	FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
   10500 	  if (!initializer_zerop (elt, nonzero))
   10501 	    return false;
   10502 
   10503 	return true;
   10504       }
   10505 
   10506     case MEM_REF:
   10507       {
   10508 	tree arg = TREE_OPERAND (init, 0);
   10509 	if (TREE_CODE (arg) != ADDR_EXPR)
   10510 	  return false;
   10511 	tree offset = TREE_OPERAND (init, 1);
   10512 	if (TREE_CODE (offset) != INTEGER_CST
   10513 	    || !tree_fits_uhwi_p (offset))
   10514 	  return false;
   10515 	off = tree_to_uhwi (offset);
   10516 	if (INT_MAX < off)
   10517 	  return false;
   10518 	arg = TREE_OPERAND (arg, 0);
   10519 	if (TREE_CODE (arg) != STRING_CST)
   10520 	  return false;
   10521 	init = arg;
   10522       }
   10523       /* Fall through.  */
   10524 
   10525     case STRING_CST:
   10526       {
   10527 	gcc_assert (off <= INT_MAX);
   10528 
   10529 	int i = off;
   10530 	int n = TREE_STRING_LENGTH (init);
   10531 	if (n <= i)
   10532 	  return false;
   10533 
   10534 	/* We need to loop through all elements to handle cases like
   10535 	   "\0" and "\0foobar".  */
   10536 	for (i = 0; i < n; ++i)
   10537 	  if (TREE_STRING_POINTER (init)[i] != '\0')
   10538 	    {
   10539 	      *nonzero = true;
   10540 	      return false;
   10541 	    }
   10542 
   10543 	return true;
   10544       }
   10545 
   10546     default:
   10547       return false;
   10548     }
   10549 }
   10550 
   10551 /* Return true if EXPR is an initializer expression in which every element
   10552    is a constant that is numerically equal to 0 or 1.  The elements do not
   10553    need to be equal to each other.  */
   10554 
   10555 bool
   10556 initializer_each_zero_or_onep (const_tree expr)
   10557 {
   10558   STRIP_ANY_LOCATION_WRAPPER (expr);
   10559 
   10560   switch (TREE_CODE (expr))
   10561     {
   10562     case INTEGER_CST:
   10563       return integer_zerop (expr) || integer_onep (expr);
   10564 
   10565     case REAL_CST:
   10566       return real_zerop (expr) || real_onep (expr);
   10567 
   10568     case VECTOR_CST:
   10569       {
   10570 	unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
   10571 	if (VECTOR_CST_STEPPED_P (expr)
   10572 	    && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
   10573 	  return false;
   10574 
   10575 	for (unsigned int i = 0; i < nelts; ++i)
   10576 	  {
   10577 	    tree elt = vector_cst_elt (expr, i);
   10578 	    if (!initializer_each_zero_or_onep (elt))
   10579 	      return false;
   10580 	  }
   10581 
   10582 	return true;
   10583       }
   10584 
   10585     default:
   10586       return false;
   10587     }
   10588 }
   10589 
   10590 /* Check if vector VEC consists of all the equal elements and
   10591    that the number of elements corresponds to the type of VEC.
   10592    The function returns first element of the vector
   10593    or NULL_TREE if the vector is not uniform.  */
   10594 tree
   10595 uniform_vector_p (const_tree vec)
   10596 {
   10597   tree first, t;
   10598   unsigned HOST_WIDE_INT i, nelts;
   10599 
   10600   if (vec == NULL_TREE)
   10601     return NULL_TREE;
   10602 
   10603   gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
   10604 
   10605   if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
   10606     return TREE_OPERAND (vec, 0);
   10607 
   10608   else if (TREE_CODE (vec) == VECTOR_CST)
   10609     {
   10610       if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
   10611 	return VECTOR_CST_ENCODED_ELT (vec, 0);
   10612       return NULL_TREE;
   10613     }
   10614 
   10615   else if (TREE_CODE (vec) == CONSTRUCTOR
   10616 	   && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
   10617     {
   10618       first = error_mark_node;
   10619 
   10620       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
   10621         {
   10622           if (i == 0)
   10623             {
   10624               first = t;
   10625               continue;
   10626             }
   10627 	  if (!operand_equal_p (first, t, 0))
   10628 	    return NULL_TREE;
   10629         }
   10630       if (i != nelts)
   10631 	return NULL_TREE;
   10632 
   10633       if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
   10634 	return uniform_vector_p (first);
   10635       return first;
   10636     }
   10637 
   10638   return NULL_TREE;
   10639 }
   10640 
   10641 /* If the argument is INTEGER_CST, return it.  If the argument is vector
   10642    with all elements the same INTEGER_CST, return that INTEGER_CST.  Otherwise
   10643    return NULL_TREE.
   10644    Look through location wrappers. */
   10645 
   10646 tree
   10647 uniform_integer_cst_p (tree t)
   10648 {
   10649   STRIP_ANY_LOCATION_WRAPPER (t);
   10650 
   10651   if (TREE_CODE (t) == INTEGER_CST)
   10652     return t;
   10653 
   10654   if (VECTOR_TYPE_P (TREE_TYPE (t)))
   10655     {
   10656       t = uniform_vector_p (t);
   10657       if (t && TREE_CODE (t) == INTEGER_CST)
   10658 	return t;
   10659     }
   10660 
   10661   return NULL_TREE;
   10662 }
   10663 
   10664 /* Checks to see if T is a constant or a constant vector and if each element E
   10665    adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE.  */
   10666 
   10667 tree
   10668 bitmask_inv_cst_vector_p (tree t)
   10669 {
   10670 
   10671   tree_code code = TREE_CODE (t);
   10672   tree type = TREE_TYPE (t);
   10673 
   10674   if (!INTEGRAL_TYPE_P (type)
   10675       && !VECTOR_INTEGER_TYPE_P (type))
   10676     return NULL_TREE;
   10677 
   10678   unsigned HOST_WIDE_INT nelts = 1;
   10679   tree cst;
   10680   unsigned int idx = 0;
   10681   bool uniform = uniform_integer_cst_p (t);
   10682   tree newtype = unsigned_type_for (type);
   10683   tree_vector_builder builder;
   10684   if (code == INTEGER_CST)
   10685     cst = t;
   10686   else
   10687     {
   10688       if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
   10689 	return NULL_TREE;
   10690 
   10691       cst = vector_cst_elt (t, 0);
   10692       builder.new_vector (newtype, nelts, 1);
   10693     }
   10694 
   10695   tree ty = unsigned_type_for (TREE_TYPE (cst));
   10696 
   10697   do
   10698     {
   10699       if (idx > 0)
   10700 	cst = vector_cst_elt (t, idx);
   10701       wide_int icst = wi::to_wide (cst);
   10702       wide_int inv =  wi::bit_not (icst);
   10703       icst = wi::add (1, inv);
   10704       if (wi::popcount (icst) != 1)
   10705 	return NULL_TREE;
   10706 
   10707       tree newcst = wide_int_to_tree (ty, inv);
   10708 
   10709       if (uniform)
   10710 	return build_uniform_cst (newtype, newcst);
   10711 
   10712       builder.quick_push (newcst);
   10713     }
   10714   while (++idx < nelts);
   10715 
   10716   return builder.build ();
   10717 }
   10718 
   10719 /* If VECTOR_CST T has a single nonzero element, return the index of that
   10720    element, otherwise return -1.  */
   10721 
   10722 int
   10723 single_nonzero_element (const_tree t)
   10724 {
   10725   unsigned HOST_WIDE_INT nelts;
   10726   unsigned int repeat_nelts;
   10727   if (VECTOR_CST_NELTS (t).is_constant (&nelts))
   10728     repeat_nelts = nelts;
   10729   else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
   10730     {
   10731       nelts = vector_cst_encoded_nelts (t);
   10732       repeat_nelts = VECTOR_CST_NPATTERNS (t);
   10733     }
   10734   else
   10735     return -1;
   10736 
   10737   int res = -1;
   10738   for (unsigned int i = 0; i < nelts; ++i)
   10739     {
   10740       tree elt = vector_cst_elt (t, i);
   10741       if (!integer_zerop (elt) && !real_zerop (elt))
   10742 	{
   10743 	  if (res >= 0 || i >= repeat_nelts)
   10744 	    return -1;
   10745 	  res = i;
   10746 	}
   10747     }
   10748   return res;
   10749 }
   10750 
   10751 /* Build an empty statement at location LOC.  */
   10752 
   10753 tree
   10754 build_empty_stmt (location_t loc)
   10755 {
   10756   tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
   10757   SET_EXPR_LOCATION (t, loc);
   10758   return t;
   10759 }
   10760 
   10761 
   10762 /* Build an OMP clause with code CODE.  LOC is the location of the
   10763    clause.  */
   10764 
   10765 tree
   10766 build_omp_clause (location_t loc, enum omp_clause_code code)
   10767 {
   10768   tree t;
   10769   int size, length;
   10770 
   10771   length = omp_clause_num_ops[code];
   10772   size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
   10773 
   10774   record_node_allocation_statistics (OMP_CLAUSE, size);
   10775 
   10776   t = (tree) ggc_internal_alloc (size);
   10777   memset (t, 0, size);
   10778   TREE_SET_CODE (t, OMP_CLAUSE);
   10779   OMP_CLAUSE_SET_CODE (t, code);
   10780   OMP_CLAUSE_LOCATION (t) = loc;
   10781 
   10782   return t;
   10783 }
   10784 
   10785 /* Build a tcc_vl_exp object with code CODE and room for LEN operands.  LEN
   10786    includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
   10787    Except for the CODE and operand count field, other storage for the
   10788    object is initialized to zeros.  */
   10789 
   10790 tree
   10791 build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
   10792 {
   10793   tree t;
   10794   int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
   10795 
   10796   gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
   10797   gcc_assert (len >= 1);
   10798 
   10799   record_node_allocation_statistics (code, length);
   10800 
   10801   t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
   10802 
   10803   TREE_SET_CODE (t, code);
   10804 
   10805   /* Can't use TREE_OPERAND to store the length because if checking is
   10806      enabled, it will try to check the length before we store it.  :-P  */
   10807   t->exp.operands[0] = build_int_cst (sizetype, len);
   10808 
   10809   return t;
   10810 }
   10811 
   10812 /* Helper function for build_call_* functions; build a CALL_EXPR with
   10813    indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
   10814    the argument slots.  */
   10815 
   10816 static tree
   10817 build_call_1 (tree return_type, tree fn, int nargs)
   10818 {
   10819   tree t;
   10820 
   10821   t = build_vl_exp (CALL_EXPR, nargs + 3);
   10822   TREE_TYPE (t) = return_type;
   10823   CALL_EXPR_FN (t) = fn;
   10824   CALL_EXPR_STATIC_CHAIN (t) = NULL;
   10825 
   10826   return t;
   10827 }
   10828 
   10829 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
   10830    FN and a null static chain slot.  NARGS is the number of call arguments
   10831    which are specified as "..." arguments.  */
   10832 
   10833 tree
   10834 build_call_nary (tree return_type, tree fn, int nargs, ...)
   10835 {
   10836   tree ret;
   10837   va_list args;
   10838   va_start (args, nargs);
   10839   ret = build_call_valist (return_type, fn, nargs, args);
   10840   va_end (args);
   10841   return ret;
   10842 }
   10843 
   10844 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
   10845    FN and a null static chain slot.  NARGS is the number of call arguments
   10846    which are specified as a va_list ARGS.  */
   10847 
   10848 tree
   10849 build_call_valist (tree return_type, tree fn, int nargs, va_list args)
   10850 {
   10851   tree t;
   10852   int i;
   10853 
   10854   t = build_call_1 (return_type, fn, nargs);
   10855   for (i = 0; i < nargs; i++)
   10856     CALL_EXPR_ARG (t, i) = va_arg (args, tree);
   10857   process_call_operands (t);
   10858   return t;
   10859 }
   10860 
   10861 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
   10862    FN and a null static chain slot.  NARGS is the number of call arguments
   10863    which are specified as a tree array ARGS.  */
   10864 
   10865 tree
   10866 build_call_array_loc (location_t loc, tree return_type, tree fn,
   10867 		      int nargs, const tree *args)
   10868 {
   10869   tree t;
   10870   int i;
   10871 
   10872   t = build_call_1 (return_type, fn, nargs);
   10873   for (i = 0; i < nargs; i++)
   10874     CALL_EXPR_ARG (t, i) = args[i];
   10875   process_call_operands (t);
   10876   SET_EXPR_LOCATION (t, loc);
   10877   return t;
   10878 }
   10879 
   10880 /* Like build_call_array, but takes a vec.  */
   10881 
   10882 tree
   10883 build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
   10884 {
   10885   tree ret, t;
   10886   unsigned int ix;
   10887 
   10888   ret = build_call_1 (return_type, fn, vec_safe_length (args));
   10889   FOR_EACH_VEC_SAFE_ELT (args, ix, t)
   10890     CALL_EXPR_ARG (ret, ix) = t;
   10891   process_call_operands (ret);
   10892   return ret;
   10893 }
   10894 
   10895 /* Conveniently construct a function call expression.  FNDECL names the
   10896    function to be called and N arguments are passed in the array
   10897    ARGARRAY.  */
   10898 
   10899 tree
   10900 build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
   10901 {
   10902   tree fntype = TREE_TYPE (fndecl);
   10903   tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
   10904 
   10905   return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
   10906 }
   10907 
   10908 /* Conveniently construct a function call expression.  FNDECL names the
   10909    function to be called and the arguments are passed in the vector
   10910    VEC.  */
   10911 
   10912 tree
   10913 build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
   10914 {
   10915   return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
   10916 				    vec_safe_address (vec));
   10917 }
   10918 
   10919 
   10920 /* Conveniently construct a function call expression.  FNDECL names the
   10921    function to be called, N is the number of arguments, and the "..."
   10922    parameters are the argument expressions.  */
   10923 
   10924 tree
   10925 build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
   10926 {
   10927   va_list ap;
   10928   tree *argarray = XALLOCAVEC (tree, n);
   10929   int i;
   10930 
   10931   va_start (ap, n);
   10932   for (i = 0; i < n; i++)
   10933     argarray[i] = va_arg (ap, tree);
   10934   va_end (ap);
   10935   return build_call_expr_loc_array (loc, fndecl, n, argarray);
   10936 }
   10937 
   10938 /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...).  Duplicated because
   10939    varargs macros aren't supported by all bootstrap compilers.  */
   10940 
   10941 tree
   10942 build_call_expr (tree fndecl, int n, ...)
   10943 {
   10944   va_list ap;
   10945   tree *argarray = XALLOCAVEC (tree, n);
   10946   int i;
   10947 
   10948   va_start (ap, n);
   10949   for (i = 0; i < n; i++)
   10950     argarray[i] = va_arg (ap, tree);
   10951   va_end (ap);
   10952   return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
   10953 }
   10954 
   10955 /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
   10956    type TYPE.  This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
   10957    It will get gimplified later into an ordinary internal function.  */
   10958 
   10959 tree
   10960 build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
   10961 				    tree type, int n, const tree *args)
   10962 {
   10963   tree t = build_call_1 (type, NULL_TREE, n);
   10964   for (int i = 0; i < n; ++i)
   10965     CALL_EXPR_ARG (t, i) = args[i];
   10966   SET_EXPR_LOCATION (t, loc);
   10967   CALL_EXPR_IFN (t) = ifn;
   10968   process_call_operands (t);
   10969   return t;
   10970 }
   10971 
   10972 /* Build internal call expression.  This is just like CALL_EXPR, except
   10973    its CALL_EXPR_FN is NULL.  It will get gimplified later into ordinary
   10974    internal function.  */
   10975 
   10976 tree
   10977 build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
   10978 			      tree type, int n, ...)
   10979 {
   10980   va_list ap;
   10981   tree *argarray = XALLOCAVEC (tree, n);
   10982   int i;
   10983 
   10984   va_start (ap, n);
   10985   for (i = 0; i < n; i++)
   10986     argarray[i] = va_arg (ap, tree);
   10987   va_end (ap);
   10988   return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
   10989 }
   10990 
   10991 /* Return a function call to FN, if the target is guaranteed to support it,
   10992    or null otherwise.
   10993 
   10994    N is the number of arguments, passed in the "...", and TYPE is the
   10995    type of the return value.  */
   10996 
   10997 tree
   10998 maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
   10999 			   int n, ...)
   11000 {
   11001   va_list ap;
   11002   tree *argarray = XALLOCAVEC (tree, n);
   11003   int i;
   11004 
   11005   va_start (ap, n);
   11006   for (i = 0; i < n; i++)
   11007     argarray[i] = va_arg (ap, tree);
   11008   va_end (ap);
   11009   if (internal_fn_p (fn))
   11010     {
   11011       internal_fn ifn = as_internal_fn (fn);
   11012       if (direct_internal_fn_p (ifn))
   11013 	{
   11014 	  tree_pair types = direct_internal_fn_types (ifn, type, argarray);
   11015 	  if (!direct_internal_fn_supported_p (ifn, types,
   11016 					       OPTIMIZE_FOR_BOTH))
   11017 	    return NULL_TREE;
   11018 	}
   11019       return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
   11020     }
   11021   else
   11022     {
   11023       tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
   11024       if (!fndecl)
   11025 	return NULL_TREE;
   11026       return build_call_expr_loc_array (loc, fndecl, n, argarray);
   11027     }
   11028 }
   11029 
   11030 /* Return a function call to the appropriate builtin alloca variant.
   11031 
   11032    SIZE is the size to be allocated.  ALIGN, if non-zero, is the requested
   11033    alignment of the allocated area.  MAX_SIZE, if non-negative, is an upper
   11034    bound for SIZE in case it is not a fixed value.  */
   11035 
   11036 tree
   11037 build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
   11038 {
   11039   if (max_size >= 0)
   11040     {
   11041       tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
   11042       return
   11043 	build_call_expr (t, 3, size, size_int (align), size_int (max_size));
   11044     }
   11045   else if (align > 0)
   11046     {
   11047       tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
   11048       return build_call_expr (t, 2, size, size_int (align));
   11049     }
   11050   else
   11051     {
   11052       tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
   11053       return build_call_expr (t, 1, size);
   11054     }
   11055 }
   11056 
   11057 /* The built-in decl to use to mark code points believed to be unreachable.
   11058    Typically __builtin_unreachable, but __builtin_trap if
   11059    -fsanitize=unreachable -fsanitize-trap=unreachable.  If only
   11060    -fsanitize=unreachable, we rely on sanopt to replace calls with the
   11061    appropriate ubsan function.  When building a call directly, use
   11062    {gimple_},build_builtin_unreachable instead.  */
   11063 
   11064 tree
   11065 builtin_decl_unreachable ()
   11066 {
   11067   enum built_in_function fncode = BUILT_IN_UNREACHABLE;
   11068 
   11069   if (sanitize_flags_p (SANITIZE_UNREACHABLE)
   11070       ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
   11071       : flag_unreachable_traps)
   11072     fncode = BUILT_IN_UNREACHABLE_TRAP;
   11073   /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
   11074      in the sanopt pass.  */
   11075 
   11076   return builtin_decl_explicit (fncode);
   11077 }
   11078 
   11079 /* Build a call to __builtin_unreachable, possibly rewritten by
   11080    -fsanitize=unreachable.  Use this rather than the above when practical.  */
   11081 
   11082 tree
   11083 build_builtin_unreachable (location_t loc)
   11084 {
   11085   tree data = NULL_TREE;
   11086   tree fn = sanitize_unreachable_fn (&data, loc);
   11087   return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
   11088 }
   11089 
   11090 /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
   11091    if SIZE == -1) and return a tree node representing char* pointer to
   11092    it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)).  When STR is nonnull
   11093    the STRING_CST value is the LEN bytes at STR (the representation
   11094    of the string, which may be wide).  Otherwise it's all zeros.  */
   11095 
   11096 tree
   11097 build_string_literal (unsigned len, const char *str /* = NULL */,
   11098 		      tree eltype /* = char_type_node */,
   11099 		      unsigned HOST_WIDE_INT size /* = -1 */)
   11100 {
   11101   tree t = build_string (len, str);
   11102   /* Set the maximum valid index based on the string length or SIZE.  */
   11103   unsigned HOST_WIDE_INT maxidx
   11104     = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
   11105 
   11106   tree index = build_index_type (size_int (maxidx));
   11107   eltype = build_type_variant (eltype, 1, 0);
   11108   tree type = build_array_type (eltype, index);
   11109   TREE_TYPE (t) = type;
   11110   TREE_CONSTANT (t) = 1;
   11111   TREE_READONLY (t) = 1;
   11112   TREE_STATIC (t) = 1;
   11113 
   11114   type = build_pointer_type (eltype);
   11115   t = build1 (ADDR_EXPR, type,
   11116 	      build4 (ARRAY_REF, eltype,
   11117 		      t, integer_zero_node, NULL_TREE, NULL_TREE));
   11118   return t;
   11119 }
   11120 
   11121 
   11122 
   11123 /* Return true if T (assumed to be a DECL) must be assigned a memory
   11124    location.  */
   11125 
   11126 bool
   11127 needs_to_live_in_memory (const_tree t)
   11128 {
   11129   return (TREE_ADDRESSABLE (t)
   11130 	  || is_global_var (t)
   11131 	  || (TREE_CODE (t) == RESULT_DECL
   11132 	      && !DECL_BY_REFERENCE (t)
   11133 	      && aggregate_value_p (t, current_function_decl)));
   11134 }
   11135 
   11136 /* Return value of a constant X and sign-extend it.  */
   11137 
   11138 HOST_WIDE_INT
   11139 int_cst_value (const_tree x)
   11140 {
   11141   unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
   11142   unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
   11143 
   11144   /* Make sure the sign-extended value will fit in a HOST_WIDE_INT.  */
   11145   gcc_assert (cst_and_fits_in_hwi (x));
   11146 
   11147   if (bits < HOST_BITS_PER_WIDE_INT)
   11148     {
   11149       bool negative = ((val >> (bits - 1)) & 1) != 0;
   11150       if (negative)
   11151 	val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
   11152       else
   11153 	val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
   11154     }
   11155 
   11156   return val;
   11157 }
   11158 
   11159 /* If TYPE is an integral or pointer type, return an integer type with
   11160    the same precision which is unsigned iff UNSIGNEDP is true, or itself
   11161    if TYPE is already an integer type of signedness UNSIGNEDP.
   11162    If TYPE is a floating-point type, return an integer type with the same
   11163    bitsize and with the signedness given by UNSIGNEDP; this is useful
   11164    when doing bit-level operations on a floating-point value.  */
   11165 
   11166 tree
   11167 signed_or_unsigned_type_for (int unsignedp, tree type)
   11168 {
   11169   if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
   11170     return type;
   11171 
   11172   if (TREE_CODE (type) == VECTOR_TYPE)
   11173     {
   11174       tree inner = TREE_TYPE (type);
   11175       tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
   11176       if (!inner2)
   11177 	return NULL_TREE;
   11178       if (inner == inner2)
   11179 	return type;
   11180       machine_mode new_mode;
   11181       if (VECTOR_MODE_P (TYPE_MODE (type))
   11182 	  && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
   11183 	return build_vector_type_for_mode (inner2, new_mode);
   11184       return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
   11185     }
   11186 
   11187   if (TREE_CODE (type) == COMPLEX_TYPE)
   11188     {
   11189       tree inner = TREE_TYPE (type);
   11190       tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
   11191       if (!inner2)
   11192 	return NULL_TREE;
   11193       if (inner == inner2)
   11194 	return type;
   11195       return build_complex_type (inner2);
   11196     }
   11197 
   11198   unsigned int bits;
   11199   if (INTEGRAL_TYPE_P (type)
   11200       || POINTER_TYPE_P (type)
   11201       || TREE_CODE (type) == OFFSET_TYPE)
   11202     bits = TYPE_PRECISION (type);
   11203   else if (TREE_CODE (type) == REAL_TYPE)
   11204     bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
   11205   else
   11206     return NULL_TREE;
   11207 
   11208   if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
   11209     return build_bitint_type (bits, unsignedp);
   11210   return build_nonstandard_integer_type (bits, unsignedp);
   11211 }
   11212 
   11213 /* If TYPE is an integral or pointer type, return an integer type with
   11214    the same precision which is unsigned, or itself if TYPE is already an
   11215    unsigned integer type.  If TYPE is a floating-point type, return an
   11216    unsigned integer type with the same bitsize as TYPE.  */
   11217 
   11218 tree
   11219 unsigned_type_for (tree type)
   11220 {
   11221   return signed_or_unsigned_type_for (1, type);
   11222 }
   11223 
   11224 /* If TYPE is an integral or pointer type, return an integer type with
   11225    the same precision which is signed, or itself if TYPE is already a
   11226    signed integer type.  If TYPE is a floating-point type, return a
   11227    signed integer type with the same bitsize as TYPE.  */
   11228 
   11229 tree
   11230 signed_type_for (tree type)
   11231 {
   11232   return signed_or_unsigned_type_for (0, type);
   11233 }
   11234 
   11235 /* - For VECTOR_TYPEs:
   11236     - The truth type must be a VECTOR_BOOLEAN_TYPE.
   11237     - The number of elements must match (known_eq).
   11238     - targetm.vectorize.get_mask_mode exists, and exactly
   11239       the same mode as the truth type.
   11240    - Otherwise, the truth type must be a BOOLEAN_TYPE
   11241      or useless_type_conversion_p to BOOLEAN_TYPE.  */
   11242 bool
   11243 is_truth_type_for (tree type, tree truth_type)
   11244 {
   11245   machine_mode mask_mode = TYPE_MODE (truth_type);
   11246   machine_mode vmode = TYPE_MODE (type);
   11247   machine_mode tmask_mode;
   11248 
   11249   if (TREE_CODE (type) == VECTOR_TYPE)
   11250     {
   11251       if (VECTOR_BOOLEAN_TYPE_P (truth_type)
   11252 	  && known_eq (TYPE_VECTOR_SUBPARTS (type),
   11253 		       TYPE_VECTOR_SUBPARTS (truth_type))
   11254 	  && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
   11255 	  && tmask_mode == mask_mode)
   11256 	return true;
   11257 
   11258       return false;
   11259     }
   11260 
   11261   return useless_type_conversion_p (boolean_type_node, truth_type);
   11262 }
   11263 
   11264 /* If TYPE is a vector type, return a signed integer vector type with the
   11265    same width and number of subparts. Otherwise return boolean_type_node.  */
   11266 
   11267 tree
   11268 truth_type_for (tree type)
   11269 {
   11270   if (TREE_CODE (type) == VECTOR_TYPE)
   11271     {
   11272       if (VECTOR_BOOLEAN_TYPE_P (type))
   11273 	return type;
   11274       return build_truth_vector_type_for (type);
   11275     }
   11276   else
   11277     return boolean_type_node;
   11278 }
   11279 
   11280 /* Returns the largest value obtainable by casting something in INNER type to
   11281    OUTER type.  */
   11282 
   11283 tree
   11284 upper_bound_in_type (tree outer, tree inner)
   11285 {
   11286   unsigned int det = 0;
   11287   unsigned oprec = TYPE_PRECISION (outer);
   11288   unsigned iprec = TYPE_PRECISION (inner);
   11289   unsigned prec;
   11290 
   11291   /* Compute a unique number for every combination.  */
   11292   det |= (oprec > iprec) ? 4 : 0;
   11293   det |= TYPE_UNSIGNED (outer) ? 2 : 0;
   11294   det |= TYPE_UNSIGNED (inner) ? 1 : 0;
   11295 
   11296   /* Determine the exponent to use.  */
   11297   switch (det)
   11298     {
   11299     case 0:
   11300     case 1:
   11301       /* oprec <= iprec, outer: signed, inner: don't care.  */
   11302       prec = oprec - 1;
   11303       break;
   11304     case 2:
   11305     case 3:
   11306       /* oprec <= iprec, outer: unsigned, inner: don't care.  */
   11307       prec = oprec;
   11308       break;
   11309     case 4:
   11310       /* oprec > iprec, outer: signed, inner: signed.  */
   11311       prec = iprec - 1;
   11312       break;
   11313     case 5:
   11314       /* oprec > iprec, outer: signed, inner: unsigned.  */
   11315       prec = iprec;
   11316       break;
   11317     case 6:
   11318       /* oprec > iprec, outer: unsigned, inner: signed.  */
   11319       prec = oprec;
   11320       break;
   11321     case 7:
   11322       /* oprec > iprec, outer: unsigned, inner: unsigned.  */
   11323       prec = iprec;
   11324       break;
   11325     default:
   11326       gcc_unreachable ();
   11327     }
   11328 
   11329   return wide_int_to_tree (outer,
   11330 			   wi::mask (prec, false, TYPE_PRECISION (outer)));
   11331 }
   11332 
   11333 /* Returns the smallest value obtainable by casting something in INNER type to
   11334    OUTER type.  */
   11335 
   11336 tree
   11337 lower_bound_in_type (tree outer, tree inner)
   11338 {
   11339   unsigned oprec = TYPE_PRECISION (outer);
   11340   unsigned iprec = TYPE_PRECISION (inner);
   11341 
   11342   /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
   11343      and obtain 0.  */
   11344   if (TYPE_UNSIGNED (outer)
   11345       /* If we are widening something of an unsigned type, OUTER type
   11346 	 contains all values of INNER type.  In particular, both INNER
   11347 	 and OUTER types have zero in common.  */
   11348       || (oprec > iprec && TYPE_UNSIGNED (inner)))
   11349     return build_int_cst (outer, 0);
   11350   else
   11351     {
   11352       /* If we are widening a signed type to another signed type, we
   11353 	 want to obtain -2^^(iprec-1).  If we are keeping the
   11354 	 precision or narrowing to a signed type, we want to obtain
   11355 	 -2^(oprec-1).  */
   11356       unsigned prec = oprec > iprec ? iprec : oprec;
   11357       return wide_int_to_tree (outer,
   11358 			       wi::mask (prec - 1, true,
   11359 					 TYPE_PRECISION (outer)));
   11360     }
   11361 }
   11362 
   11363 /* Return true if two operands that are suitable for PHI nodes are
   11364    necessarily equal.  Specifically, both ARG0 and ARG1 must be either
   11365    SSA_NAME or invariant.  Note that this is strictly an optimization.
   11366    That is, callers of this function can directly call operand_equal_p
   11367    and get the same result, only slower.  */
   11368 
   11369 bool
   11370 operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
   11371 {
   11372   if (arg0 == arg1)
   11373     return true;
   11374   if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
   11375     return false;
   11376   return operand_equal_p (arg0, arg1, 0);
   11377 }
   11378 
   11379 /* Returns number of zeros at the end of binary representation of X.  */
   11380 
   11381 tree
   11382 num_ending_zeros (const_tree x)
   11383 {
   11384   return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
   11385 }
   11386 
   11387 
   11388 #define WALK_SUBTREE(NODE)				\
   11389   do							\
   11390     {							\
   11391       result = walk_tree_1 (&(NODE), func, data, pset, lh);	\
   11392       if (result)					\
   11393 	return result;					\
   11394     }							\
   11395   while (0)
   11396 
   11397 /* This is a subroutine of walk_tree that walks field of TYPE that are to
   11398    be walked whenever a type is seen in the tree.  Rest of operands and return
   11399    value are as for walk_tree.  */
   11400 
   11401 static tree
   11402 walk_type_fields (tree type, walk_tree_fn func, void *data,
   11403 		  hash_set<tree> *pset, walk_tree_lh lh)
   11404 {
   11405   tree result = NULL_TREE;
   11406 
   11407   switch (TREE_CODE (type))
   11408     {
   11409     case POINTER_TYPE:
   11410     case REFERENCE_TYPE:
   11411     case VECTOR_TYPE:
   11412       /* We have to worry about mutually recursive pointers.  These can't
   11413 	 be written in C.  They can in Ada.  It's pathological, but
   11414 	 there's an ACATS test (c38102a) that checks it.  Deal with this
   11415 	 by checking if we're pointing to another pointer, that one
   11416 	 points to another pointer, that one does too, and we have no htab.
   11417 	 If so, get a hash table.  We check three levels deep to avoid
   11418 	 the cost of the hash table if we don't need one.  */
   11419       if (POINTER_TYPE_P (TREE_TYPE (type))
   11420 	  && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
   11421 	  && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
   11422 	  && !pset)
   11423 	{
   11424 	  result = walk_tree_without_duplicates (&TREE_TYPE (type),
   11425 						 func, data);
   11426 	  if (result)
   11427 	    return result;
   11428 
   11429 	  break;
   11430 	}
   11431 
   11432       /* fall through */
   11433 
   11434     case COMPLEX_TYPE:
   11435       WALK_SUBTREE (TREE_TYPE (type));
   11436       break;
   11437 
   11438     case METHOD_TYPE:
   11439       WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
   11440 
   11441       /* Fall through.  */
   11442 
   11443     case FUNCTION_TYPE:
   11444       WALK_SUBTREE (TREE_TYPE (type));
   11445       {
   11446 	tree arg;
   11447 
   11448 	/* We never want to walk into default arguments.  */
   11449 	for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
   11450 	  WALK_SUBTREE (TREE_VALUE (arg));
   11451       }
   11452       break;
   11453 
   11454     case ARRAY_TYPE:
   11455       /* Don't follow this nodes's type if a pointer for fear that
   11456 	 we'll have infinite recursion.  If we have a PSET, then we
   11457 	 need not fear.  */
   11458       if (pset
   11459 	  || (!POINTER_TYPE_P (TREE_TYPE (type))
   11460 	      && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
   11461 	WALK_SUBTREE (TREE_TYPE (type));
   11462       WALK_SUBTREE (TYPE_DOMAIN (type));
   11463       break;
   11464 
   11465     case OFFSET_TYPE:
   11466       WALK_SUBTREE (TREE_TYPE (type));
   11467       WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
   11468       break;
   11469 
   11470     default:
   11471       break;
   11472     }
   11473 
   11474   return NULL_TREE;
   11475 }
   11476 
   11477 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.  FUNC is
   11478    called with the DATA and the address of each sub-tree.  If FUNC returns a
   11479    non-NULL value, the traversal is stopped, and the value returned by FUNC
   11480    is returned.  If PSET is non-NULL it is used to record the nodes visited,
   11481    and to avoid visiting a node more than once.  */
   11482 
   11483 tree
   11484 walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
   11485 	     hash_set<tree> *pset, walk_tree_lh lh)
   11486 {
   11487 #define WALK_SUBTREE_TAIL(NODE)				\
   11488   do							\
   11489     {							\
   11490        tp = & (NODE);					\
   11491        goto tail_recurse;				\
   11492     }							\
   11493   while (0)
   11494 
   11495  tail_recurse:
   11496   /* Skip empty subtrees.  */
   11497   if (!*tp)
   11498     return NULL_TREE;
   11499 
   11500   /* Don't walk the same tree twice, if the user has requested
   11501      that we avoid doing so.  */
   11502   if (pset && pset->add (*tp))
   11503     return NULL_TREE;
   11504 
   11505   /* Call the function.  */
   11506   int walk_subtrees = 1;
   11507   tree result = (*func) (tp, &walk_subtrees, data);
   11508 
   11509   /* If we found something, return it.  */
   11510   if (result)
   11511     return result;
   11512 
   11513   tree t = *tp;
   11514   tree_code code = TREE_CODE (t);
   11515 
   11516   /* Even if we didn't, FUNC may have decided that there was nothing
   11517      interesting below this point in the tree.  */
   11518   if (!walk_subtrees)
   11519     {
   11520       /* But we still need to check our siblings.  */
   11521       if (code == TREE_LIST)
   11522 	WALK_SUBTREE_TAIL (TREE_CHAIN (t));
   11523       else if (code == OMP_CLAUSE)
   11524 	WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
   11525       else
   11526 	return NULL_TREE;
   11527     }
   11528 
   11529   if (lh)
   11530     {
   11531       result = (*lh) (tp, &walk_subtrees, func, data, pset);
   11532       if (result || !walk_subtrees)
   11533         return result;
   11534     }
   11535 
   11536   switch (code)
   11537     {
   11538     case ERROR_MARK:
   11539     case IDENTIFIER_NODE:
   11540     case INTEGER_CST:
   11541     case REAL_CST:
   11542     case FIXED_CST:
   11543     case STRING_CST:
   11544     case BLOCK:
   11545     case PLACEHOLDER_EXPR:
   11546     case SSA_NAME:
   11547     case FIELD_DECL:
   11548     case RESULT_DECL:
   11549       /* None of these have subtrees other than those already walked
   11550 	 above.  */
   11551       break;
   11552 
   11553     case TREE_LIST:
   11554       WALK_SUBTREE (TREE_VALUE (t));
   11555       WALK_SUBTREE_TAIL (TREE_CHAIN (t));
   11556 
   11557     case TREE_VEC:
   11558       {
   11559 	int len = TREE_VEC_LENGTH (t);
   11560 
   11561 	if (len == 0)
   11562 	  break;
   11563 
   11564 	/* Walk all elements but the last.  */
   11565 	for (int i = 0; i < len - 1; ++i)
   11566 	  WALK_SUBTREE (TREE_VEC_ELT (t, i));
   11567 
   11568 	/* Now walk the last one as a tail call.  */
   11569 	WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
   11570       }
   11571 
   11572     case VECTOR_CST:
   11573       {
   11574 	unsigned len = vector_cst_encoded_nelts (t);
   11575 	if (len == 0)
   11576 	  break;
   11577 	/* Walk all elements but the last.  */
   11578 	for (unsigned i = 0; i < len - 1; ++i)
   11579 	  WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
   11580 	/* Now walk the last one as a tail call.  */
   11581 	WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
   11582       }
   11583 
   11584     case COMPLEX_CST:
   11585       WALK_SUBTREE (TREE_REALPART (t));
   11586       WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
   11587 
   11588     case CONSTRUCTOR:
   11589       {
   11590 	unsigned HOST_WIDE_INT idx;
   11591 	constructor_elt *ce;
   11592 
   11593 	for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
   11594 	     idx++)
   11595 	  WALK_SUBTREE (ce->value);
   11596       }
   11597       break;
   11598 
   11599     case SAVE_EXPR:
   11600       WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
   11601 
   11602     case BIND_EXPR:
   11603       {
   11604 	tree decl;
   11605 	for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
   11606 	  {
   11607 	    /* Walk the DECL_INITIAL and DECL_SIZE.  We don't want to walk
   11608 	       into declarations that are just mentioned, rather than
   11609 	       declared; they don't really belong to this part of the tree.
   11610 	       And, we can see cycles: the initializer for a declaration
   11611 	       can refer to the declaration itself.  */
   11612 	    WALK_SUBTREE (DECL_INITIAL (decl));
   11613 	    WALK_SUBTREE (DECL_SIZE (decl));
   11614 	    WALK_SUBTREE (DECL_SIZE_UNIT (decl));
   11615 	  }
   11616 	WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
   11617       }
   11618 
   11619     case STATEMENT_LIST:
   11620       {
   11621 	tree_stmt_iterator i;
   11622 	for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
   11623 	  WALK_SUBTREE (*tsi_stmt_ptr (i));
   11624       }
   11625       break;
   11626 
   11627     case OMP_CLAUSE:
   11628       {
   11629 	int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
   11630 	for (int i = 0; i < len; i++)
   11631 	  WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
   11632 	WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
   11633       }
   11634 
   11635     case TARGET_EXPR:
   11636       {
   11637 	int i, len;
   11638 
   11639 	/* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
   11640 	   But, we only want to walk once.  */
   11641 	len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
   11642 	for (i = 0; i < len; ++i)
   11643 	  WALK_SUBTREE (TREE_OPERAND (t, i));
   11644 	WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
   11645       }
   11646 
   11647     case DECL_EXPR:
   11648       /* If this is a TYPE_DECL, walk into the fields of the type that it's
   11649 	 defining.  We only want to walk into these fields of a type in this
   11650 	 case and not in the general case of a mere reference to the type.
   11651 
   11652 	 The criterion is as follows: if the field can be an expression, it
   11653 	 must be walked only here.  This should be in keeping with the fields
   11654 	 that are directly gimplified in gimplify_type_sizes in order for the
   11655 	 mark/copy-if-shared/unmark machinery of the gimplifier to work with
   11656 	 variable-sized types.
   11657 
   11658 	 Note that DECLs get walked as part of processing the BIND_EXPR.  */
   11659       if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
   11660 	{
   11661 	  /* Call the function for the decl so e.g. copy_tree_body_r can
   11662 	     replace it with the remapped one.  */
   11663 	  result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
   11664 	  if (result || !walk_subtrees)
   11665 	    return result;
   11666 
   11667 	  tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
   11668 	  if (TREE_CODE (*type_p) == ERROR_MARK)
   11669 	    return NULL_TREE;
   11670 
   11671 	  /* Call the function for the type.  See if it returns anything or
   11672 	     doesn't want us to continue.  If we are to continue, walk both
   11673 	     the normal fields and those for the declaration case.  */
   11674 	  result = (*func) (type_p, &walk_subtrees, data);
   11675 	  if (result || !walk_subtrees)
   11676 	    return result;
   11677 
   11678 	  tree type = *type_p;
   11679 
   11680 	  /* But do not walk a pointed-to type since it may itself need to
   11681 	     be walked in the declaration case if it isn't anonymous.  */
   11682 	  if (!POINTER_TYPE_P (type))
   11683 	    {
   11684 	      result = walk_type_fields (type, func, data, pset, lh);
   11685 	      if (result)
   11686 		return result;
   11687 	    }
   11688 
   11689 	  /* If this is a record type, also walk the fields.  */
   11690 	  if (RECORD_OR_UNION_TYPE_P (type))
   11691 	    {
   11692 	      tree field;
   11693 
   11694 	      for (field = TYPE_FIELDS (type); field;
   11695 		   field = DECL_CHAIN (field))
   11696 		{
   11697 		  /* We'd like to look at the type of the field, but we can
   11698 		     easily get infinite recursion.  So assume it's pointed
   11699 		     to elsewhere in the tree.  Also, ignore things that
   11700 		     aren't fields.  */
   11701 		  if (TREE_CODE (field) != FIELD_DECL)
   11702 		    continue;
   11703 
   11704 		  WALK_SUBTREE (DECL_FIELD_OFFSET (field));
   11705 		  WALK_SUBTREE (DECL_SIZE (field));
   11706 		  WALK_SUBTREE (DECL_SIZE_UNIT (field));
   11707 		  if (TREE_CODE (type) == QUAL_UNION_TYPE)
   11708 		    WALK_SUBTREE (DECL_QUALIFIER (field));
   11709 		}
   11710 	    }
   11711 
   11712 	  /* Same for scalar types.  */
   11713 	  else if (TREE_CODE (type) == BOOLEAN_TYPE
   11714 		   || TREE_CODE (type) == ENUMERAL_TYPE
   11715 		   || TREE_CODE (type) == INTEGER_TYPE
   11716 		   || TREE_CODE (type) == FIXED_POINT_TYPE
   11717 		   || TREE_CODE (type) == REAL_TYPE)
   11718 	    {
   11719 	      WALK_SUBTREE (TYPE_MIN_VALUE (type));
   11720 	      WALK_SUBTREE (TYPE_MAX_VALUE (type));
   11721 	    }
   11722 
   11723 	  WALK_SUBTREE (TYPE_SIZE (type));
   11724 	  WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
   11725 	}
   11726       /* FALLTHRU */
   11727 
   11728     default:
   11729       if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
   11730 	{
   11731 	  int i, len;
   11732 
   11733 	  /* Walk over all the sub-trees of this operand.  */
   11734 	  len = TREE_OPERAND_LENGTH (t);
   11735 
   11736 	  /* Go through the subtrees.  We need to do this in forward order so
   11737 	     that the scope of a FOR_EXPR is handled properly.  */
   11738 	  if (len)
   11739 	    {
   11740 	      for (i = 0; i < len - 1; ++i)
   11741 		WALK_SUBTREE (TREE_OPERAND (t, i));
   11742 	      WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
   11743 	    }
   11744 	}
   11745       /* If this is a type, walk the needed fields in the type.  */
   11746       else if (TYPE_P (t))
   11747 	return walk_type_fields (t, func, data, pset, lh);
   11748       break;
   11749     }
   11750 
   11751   /* We didn't find what we were looking for.  */
   11752   return NULL_TREE;
   11753 
   11754 #undef WALK_SUBTREE_TAIL
   11755 }
   11756 #undef WALK_SUBTREE
   11757 
   11758 /* Like walk_tree, but does not walk duplicate nodes more than once.  */
   11759 
   11760 tree
   11761 walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
   11762 				walk_tree_lh lh)
   11763 {
   11764   tree result;
   11765 
   11766   hash_set<tree> pset;
   11767   result = walk_tree_1 (tp, func, data, &pset, lh);
   11768   return result;
   11769 }
   11770 
   11771 
   11772 tree
   11773 tree_block (tree t)
   11774 {
   11775   const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
   11776 
   11777   if (IS_EXPR_CODE_CLASS (c))
   11778     return LOCATION_BLOCK (t->exp.locus);
   11779   gcc_unreachable ();
   11780   return NULL;
   11781 }
   11782 
   11783 void
   11784 tree_set_block (tree t, tree b)
   11785 {
   11786   const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
   11787 
   11788   if (IS_EXPR_CODE_CLASS (c))
   11789     {
   11790       t->exp.locus = set_block (t->exp.locus, b);
   11791     }
   11792   else
   11793     gcc_unreachable ();
   11794 }
   11795 
   11796 /* Create a nameless artificial label and put it in the current
   11797    function context.  The label has a location of LOC.  Returns the
   11798    newly created label.  */
   11799 
   11800 tree
   11801 create_artificial_label (location_t loc)
   11802 {
   11803   tree lab = build_decl (loc,
   11804       			 LABEL_DECL, NULL_TREE, void_type_node);
   11805 
   11806   DECL_ARTIFICIAL (lab) = 1;
   11807   DECL_IGNORED_P (lab) = 1;
   11808   DECL_CONTEXT (lab) = current_function_decl;
   11809   return lab;
   11810 }
   11811 
   11812 /*  Given a tree, try to return a useful variable name that we can use
   11813     to prefix a temporary that is being assigned the value of the tree.
   11814     I.E. given  <temp> = &A, return A.  */
   11815 
   11816 const char *
   11817 get_name (tree t)
   11818 {
   11819   tree stripped_decl;
   11820 
   11821   stripped_decl = t;
   11822   STRIP_NOPS (stripped_decl);
   11823   if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
   11824     return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
   11825   else if (TREE_CODE (stripped_decl) == SSA_NAME)
   11826     {
   11827       tree name = SSA_NAME_IDENTIFIER (stripped_decl);
   11828       if (!name)
   11829 	return NULL;
   11830       return IDENTIFIER_POINTER (name);
   11831     }
   11832   else
   11833     {
   11834       switch (TREE_CODE (stripped_decl))
   11835 	{
   11836 	case ADDR_EXPR:
   11837 	  return get_name (TREE_OPERAND (stripped_decl, 0));
   11838 	default:
   11839 	  return NULL;
   11840 	}
   11841     }
   11842 }
   11843 
   11844 /* Return true if TYPE has a variable argument list.  */
   11845 
   11846 bool
   11847 stdarg_p (const_tree fntype)
   11848 {
   11849   function_args_iterator args_iter;
   11850   tree n = NULL_TREE, t;
   11851 
   11852   if (!fntype)
   11853     return false;
   11854 
   11855   if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
   11856     return true;
   11857 
   11858   FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
   11859     {
   11860       n = t;
   11861     }
   11862 
   11863   return n != NULL_TREE && n != void_type_node;
   11864 }
   11865 
   11866 /* Return true if TYPE has a prototype.  */
   11867 
   11868 bool
   11869 prototype_p (const_tree fntype)
   11870 {
   11871   tree t;
   11872 
   11873   gcc_assert (fntype != NULL_TREE);
   11874 
   11875   if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
   11876     return true;
   11877 
   11878   t = TYPE_ARG_TYPES (fntype);
   11879   return (t != NULL_TREE);
   11880 }
   11881 
   11882 /* If BLOCK is inlined from an __attribute__((__artificial__))
   11883    routine, return pointer to location from where it has been
   11884    called.  */
   11885 location_t *
   11886 block_nonartificial_location (tree block)
   11887 {
   11888   location_t *ret = NULL;
   11889 
   11890   while (block && TREE_CODE (block) == BLOCK
   11891 	 && BLOCK_ABSTRACT_ORIGIN (block))
   11892     {
   11893       tree ao = BLOCK_ABSTRACT_ORIGIN (block);
   11894       if (TREE_CODE (ao) == FUNCTION_DECL)
   11895 	{
   11896 	  /* If AO is an artificial inline, point RET to the
   11897 	     call site locus at which it has been inlined and continue
   11898 	     the loop, in case AO's caller is also an artificial
   11899 	     inline.  */
   11900 	  if (DECL_DECLARED_INLINE_P (ao)
   11901 	      && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
   11902 	    ret = &BLOCK_SOURCE_LOCATION (block);
   11903 	  else
   11904 	    break;
   11905 	}
   11906       else if (TREE_CODE (ao) != BLOCK)
   11907 	break;
   11908 
   11909       block = BLOCK_SUPERCONTEXT (block);
   11910     }
   11911   return ret;
   11912 }
   11913 
   11914 
   11915 /* If EXP is inlined from an __attribute__((__artificial__))
   11916    function, return the location of the original call expression.  */
   11917 
   11918 location_t
   11919 tree_nonartificial_location (tree exp)
   11920 {
   11921   location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
   11922 
   11923   if (loc)
   11924     return *loc;
   11925   else
   11926     return EXPR_LOCATION (exp);
   11927 }
   11928 
   11929 /* Return the location into which EXP has been inlined.  Analogous
   11930    to tree_nonartificial_location() above but not limited to artificial
   11931    functions declared inline.  If SYSTEM_HEADER is true, return
   11932    the macro expansion point of the location if it's in a system header */
   11933 
   11934 location_t
   11935 tree_inlined_location (tree exp, bool system_header /* = true */)
   11936 {
   11937   location_t loc = UNKNOWN_LOCATION;
   11938 
   11939   tree block = TREE_BLOCK (exp);
   11940 
   11941   while (block && TREE_CODE (block) == BLOCK
   11942 	 && BLOCK_ABSTRACT_ORIGIN (block))
   11943     {
   11944       tree ao = BLOCK_ABSTRACT_ORIGIN (block);
   11945       if (TREE_CODE (ao) == FUNCTION_DECL)
   11946 	loc = BLOCK_SOURCE_LOCATION (block);
   11947       else if (TREE_CODE (ao) != BLOCK)
   11948 	break;
   11949 
   11950       block = BLOCK_SUPERCONTEXT (block);
   11951     }
   11952 
   11953   if (loc == UNKNOWN_LOCATION)
   11954     {
   11955       loc = EXPR_LOCATION (exp);
   11956       if (system_header)
   11957 	/* Only consider macro expansion when the block traversal failed
   11958 	   to find a location.  Otherwise it's not relevant.  */
   11959 	return expansion_point_location_if_in_system_header (loc);
   11960     }
   11961 
   11962   return loc;
   11963 }
   11964 
   11965 /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
   11966    nodes.  */
   11967 
   11968 /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code.  */
   11969 
   11970 hashval_t
   11971 cl_option_hasher::hash (tree x)
   11972 {
   11973   const_tree const t = x;
   11974 
   11975   if (TREE_CODE (t) == OPTIMIZATION_NODE)
   11976     return cl_optimization_hash (TREE_OPTIMIZATION (t));
   11977   else if (TREE_CODE (t) == TARGET_OPTION_NODE)
   11978     return cl_target_option_hash (TREE_TARGET_OPTION (t));
   11979   else
   11980     gcc_unreachable ();
   11981 }
   11982 
   11983 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
   11984    TARGET_OPTION tree node) is the same as that given by *Y, which is the
   11985    same.  */
   11986 
   11987 bool
   11988 cl_option_hasher::equal (tree x, tree y)
   11989 {
   11990   const_tree const xt = x;
   11991   const_tree const yt = y;
   11992 
   11993   if (TREE_CODE (xt) != TREE_CODE (yt))
   11994     return false;
   11995 
   11996   if (TREE_CODE (xt) == OPTIMIZATION_NODE)
   11997     return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
   11998 				      TREE_OPTIMIZATION (yt));
   11999   else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
   12000     return cl_target_option_eq (TREE_TARGET_OPTION (xt),
   12001 				TREE_TARGET_OPTION (yt));
   12002   else
   12003     gcc_unreachable ();
   12004 }
   12005 
   12006 /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET.  */
   12007 
   12008 tree
   12009 build_optimization_node (struct gcc_options *opts,
   12010 			 struct gcc_options *opts_set)
   12011 {
   12012   tree t;
   12013 
   12014   /* Use the cache of optimization nodes.  */
   12015 
   12016   cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
   12017 			opts, opts_set);
   12018 
   12019   tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
   12020   t = *slot;
   12021   if (!t)
   12022     {
   12023       /* Insert this one into the hash table.  */
   12024       t = cl_optimization_node;
   12025       *slot = t;
   12026 
   12027       /* Make a new node for next time round.  */
   12028       cl_optimization_node = make_node (OPTIMIZATION_NODE);
   12029     }
   12030 
   12031   return t;
   12032 }
   12033 
   12034 /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET.  */
   12035 
   12036 tree
   12037 build_target_option_node (struct gcc_options *opts,
   12038 			  struct gcc_options *opts_set)
   12039 {
   12040   tree t;
   12041 
   12042   /* Use the cache of optimization nodes.  */
   12043 
   12044   cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
   12045 			 opts, opts_set);
   12046 
   12047   tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
   12048   t = *slot;
   12049   if (!t)
   12050     {
   12051       /* Insert this one into the hash table.  */
   12052       t = cl_target_option_node;
   12053       *slot = t;
   12054 
   12055       /* Make a new node for next time round.  */
   12056       cl_target_option_node = make_node (TARGET_OPTION_NODE);
   12057     }
   12058 
   12059   return t;
   12060 }
   12061 
   12062 /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
   12063    so that they aren't saved during PCH writing.  */
   12064 
   12065 void
   12066 prepare_target_option_nodes_for_pch (void)
   12067 {
   12068   hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
   12069   for (; iter != cl_option_hash_table->end (); ++iter)
   12070     if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
   12071       TREE_TARGET_GLOBALS (*iter) = NULL;
   12072 }
   12073 
   12074 /* Determine the "ultimate origin" of a block.  */
   12075 
   12076 tree
   12077 block_ultimate_origin (const_tree block)
   12078 {
   12079   tree origin = BLOCK_ABSTRACT_ORIGIN (block);
   12080 
   12081   if (origin == NULL_TREE)
   12082     return NULL_TREE;
   12083   else
   12084     {
   12085       gcc_checking_assert ((DECL_P (origin)
   12086 			    && DECL_ORIGIN (origin) == origin)
   12087 			   || BLOCK_ORIGIN (origin) == origin);
   12088       return origin;
   12089     }
   12090 }
   12091 
   12092 /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
   12093    no instruction.  */
   12094 
   12095 bool
   12096 tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
   12097 {
   12098   /* Do not strip casts into or out of differing address spaces.  */
   12099   if (POINTER_TYPE_P (outer_type)
   12100       && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
   12101     {
   12102       if (!POINTER_TYPE_P (inner_type)
   12103 	  || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
   12104 	      != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
   12105 	return false;
   12106     }
   12107   else if (POINTER_TYPE_P (inner_type)
   12108 	   && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
   12109     {
   12110       /* We already know that outer_type is not a pointer with
   12111 	 a non-generic address space.  */
   12112       return false;
   12113     }
   12114 
   12115   /* Use precision rather then machine mode when we can, which gives
   12116      the correct answer even for submode (bit-field) types.  */
   12117   if ((INTEGRAL_TYPE_P (outer_type)
   12118        || POINTER_TYPE_P (outer_type)
   12119        || TREE_CODE (outer_type) == OFFSET_TYPE)
   12120       && (INTEGRAL_TYPE_P (inner_type)
   12121 	  || POINTER_TYPE_P (inner_type)
   12122 	  || TREE_CODE (inner_type) == OFFSET_TYPE))
   12123     return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
   12124 
   12125   /* Otherwise fall back on comparing machine modes (e.g. for
   12126      aggregate types, floats).  */
   12127   return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
   12128 }
   12129 
   12130 /* Return true iff conversion in EXP generates no instruction.  Mark
   12131    it inline so that we fully inline into the stripping functions even
   12132    though we have two uses of this function.  */
   12133 
   12134 static inline bool
   12135 tree_nop_conversion (const_tree exp)
   12136 {
   12137   tree outer_type, inner_type;
   12138 
   12139   if (location_wrapper_p (exp))
   12140     return true;
   12141   if (!CONVERT_EXPR_P (exp)
   12142       && TREE_CODE (exp) != NON_LVALUE_EXPR)
   12143     return false;
   12144 
   12145   outer_type = TREE_TYPE (exp);
   12146   inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
   12147   if (!inner_type || inner_type == error_mark_node)
   12148     return false;
   12149 
   12150   return tree_nop_conversion_p (outer_type, inner_type);
   12151 }
   12152 
   12153 /* Return true iff conversion in EXP generates no instruction.  Don't
   12154    consider conversions changing the signedness.  */
   12155 
   12156 static bool
   12157 tree_sign_nop_conversion (const_tree exp)
   12158 {
   12159   tree outer_type, inner_type;
   12160 
   12161   if (!tree_nop_conversion (exp))
   12162     return false;
   12163 
   12164   outer_type = TREE_TYPE (exp);
   12165   inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
   12166 
   12167   return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
   12168 	  && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
   12169 }
   12170 
   12171 /* Strip conversions from EXP according to tree_nop_conversion and
   12172    return the resulting expression.  */
   12173 
   12174 tree
   12175 tree_strip_nop_conversions (tree exp)
   12176 {
   12177   while (tree_nop_conversion (exp))
   12178     exp = TREE_OPERAND (exp, 0);
   12179   return exp;
   12180 }
   12181 
   12182 /* Strip conversions from EXP according to tree_sign_nop_conversion
   12183    and return the resulting expression.  */
   12184 
   12185 tree
   12186 tree_strip_sign_nop_conversions (tree exp)
   12187 {
   12188   while (tree_sign_nop_conversion (exp))
   12189     exp = TREE_OPERAND (exp, 0);
   12190   return exp;
   12191 }
   12192 
   12193 /* Avoid any floating point extensions from EXP.  */
   12194 tree
   12195 strip_float_extensions (tree exp)
   12196 {
   12197   tree sub, expt, subt;
   12198 
   12199   /*  For floating point constant look up the narrowest type that can hold
   12200       it properly and handle it like (type)(narrowest_type)constant.
   12201       This way we can optimize for instance a=a*2.0 where "a" is float
   12202       but 2.0 is double constant.  */
   12203   if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
   12204     {
   12205       REAL_VALUE_TYPE orig;
   12206       tree type = NULL;
   12207 
   12208       orig = TREE_REAL_CST (exp);
   12209       if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
   12210 	  && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
   12211 	type = float_type_node;
   12212       else if (TYPE_PRECISION (TREE_TYPE (exp))
   12213 	       > TYPE_PRECISION (double_type_node)
   12214 	       && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
   12215 	type = double_type_node;
   12216       if (type)
   12217 	return build_real_truncate (type, orig);
   12218     }
   12219 
   12220   if (!CONVERT_EXPR_P (exp))
   12221     return exp;
   12222 
   12223   sub = TREE_OPERAND (exp, 0);
   12224   subt = TREE_TYPE (sub);
   12225   expt = TREE_TYPE (exp);
   12226 
   12227   if (!FLOAT_TYPE_P (subt))
   12228     return exp;
   12229 
   12230   if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
   12231     return exp;
   12232 
   12233   if (element_precision (subt) > element_precision (expt))
   12234     return exp;
   12235 
   12236   return strip_float_extensions (sub);
   12237 }
   12238 
   12239 /* Strip out all handled components that produce invariant
   12240    offsets.  */
   12241 
   12242 const_tree
   12243 strip_invariant_refs (const_tree op)
   12244 {
   12245   while (handled_component_p (op))
   12246     {
   12247       switch (TREE_CODE (op))
   12248 	{
   12249 	case ARRAY_REF:
   12250 	case ARRAY_RANGE_REF:
   12251 	  if (!is_gimple_constant (TREE_OPERAND (op, 1))
   12252 	      || TREE_OPERAND (op, 2) != NULL_TREE
   12253 	      || TREE_OPERAND (op, 3) != NULL_TREE)
   12254 	    return NULL;
   12255 	  break;
   12256 
   12257 	case COMPONENT_REF:
   12258 	  if (TREE_OPERAND (op, 2) != NULL_TREE)
   12259 	    return NULL;
   12260 	  break;
   12261 
   12262 	default:;
   12263 	}
   12264       op = TREE_OPERAND (op, 0);
   12265     }
   12266 
   12267   return op;
   12268 }
   12269 
   12270 /* Strip handled components with zero offset from OP.  */
   12271 
   12272 tree
   12273 strip_zero_offset_components (tree op)
   12274 {
   12275   while (TREE_CODE (op) == COMPONENT_REF
   12276 	 && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
   12277 	 && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
   12278     op = TREE_OPERAND (op, 0);
   12279   return op;
   12280 }
   12281 
   12282 static GTY(()) tree gcc_eh_personality_decl;
   12283 
   12284 /* Return the GCC personality function decl.  */
   12285 
   12286 tree
   12287 lhd_gcc_personality (void)
   12288 {
   12289   if (!gcc_eh_personality_decl)
   12290     gcc_eh_personality_decl = build_personality_function ("gcc");
   12291   return gcc_eh_personality_decl;
   12292 }
   12293 
   12294 /* TARGET is a call target of GIMPLE call statement
   12295    (obtained by gimple_call_fn).  Return true if it is
   12296    OBJ_TYPE_REF representing an virtual call of C++ method.
   12297    (As opposed to OBJ_TYPE_REF representing objc calls
   12298    through a cast where middle-end devirtualization machinery
   12299    can't apply.)  FOR_DUMP_P is true when being called from
   12300    the dump routines.  */
   12301 
   12302 bool
   12303 virtual_method_call_p (const_tree target, bool for_dump_p)
   12304 {
   12305   if (TREE_CODE (target) != OBJ_TYPE_REF)
   12306     return false;
   12307   tree t = TREE_TYPE (target);
   12308   gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
   12309   t = TREE_TYPE (t);
   12310   if (TREE_CODE (t) == FUNCTION_TYPE)
   12311     return false;
   12312   gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
   12313   /* If we do not have BINFO associated, it means that type was built
   12314      without devirtualization enabled.  Do not consider this a virtual
   12315      call.  */
   12316   if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
   12317     return false;
   12318   return true;
   12319 }
   12320 
   12321 /* Lookup sub-BINFO of BINFO of TYPE at offset POS.  */
   12322 
   12323 static tree
   12324 lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
   12325 {
   12326   unsigned int i;
   12327   tree base_binfo, b;
   12328 
   12329   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   12330     if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
   12331 	&& types_same_for_odr (TREE_TYPE (base_binfo), type))
   12332       return base_binfo;
   12333     else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
   12334       return b;
   12335   return NULL;
   12336 }
   12337 
   12338 /* Try to find a base info of BINFO that would have its field decl at offset
   12339    OFFSET within the BINFO type and which is of EXPECTED_TYPE.  If it can be
   12340    found, return, otherwise return NULL_TREE.  */
   12341 
   12342 tree
   12343 get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
   12344 {
   12345   tree type = BINFO_TYPE (binfo);
   12346 
   12347   while (true)
   12348     {
   12349       HOST_WIDE_INT pos, size;
   12350       tree fld;
   12351       int i;
   12352 
   12353       if (types_same_for_odr (type, expected_type))
   12354 	  return binfo;
   12355       if (maybe_lt (offset, 0))
   12356 	return NULL_TREE;
   12357 
   12358       for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
   12359 	{
   12360 	  if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
   12361 	    continue;
   12362 
   12363 	  pos = int_bit_position (fld);
   12364 	  size = tree_to_uhwi (DECL_SIZE (fld));
   12365 	  if (known_in_range_p (offset, pos, size))
   12366 	    break;
   12367 	}
   12368       if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
   12369 	return NULL_TREE;
   12370 
   12371       /* Offset 0 indicates the primary base, whose vtable contents are
   12372 	 represented in the binfo for the derived class.  */
   12373       else if (maybe_ne (offset, 0))
   12374 	{
   12375 	  tree found_binfo = NULL, base_binfo;
   12376 	  /* Offsets in BINFO are in bytes relative to the whole structure
   12377 	     while POS is in bits relative to the containing field.  */
   12378 	  int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
   12379 			     / BITS_PER_UNIT);
   12380 
   12381 	  for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   12382 	    if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
   12383 		&& types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
   12384 	      {
   12385 		found_binfo = base_binfo;
   12386 		break;
   12387 	      }
   12388 	  if (found_binfo)
   12389 	    binfo = found_binfo;
   12390 	  else
   12391 	    binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
   12392 					    binfo_offset);
   12393 	 }
   12394 
   12395       type = TREE_TYPE (fld);
   12396       offset -= pos;
   12397     }
   12398 }
   12399 
   12400 /* PR 84195: Replace control characters in "unescaped" with their
   12401    escaped equivalents.  Allow newlines if -fmessage-length has
   12402    been set to a non-zero value.  This is done here, rather than
   12403    where the attribute is recorded as the message length can
   12404    change between these two locations.  */
   12405 
   12406 void
   12407 escaped_string::escape (const char *unescaped)
   12408 {
   12409   char *escaped;
   12410   size_t i, new_i, len;
   12411 
   12412   if (m_owned)
   12413     free (m_str);
   12414 
   12415   m_str = const_cast<char *> (unescaped);
   12416   m_owned = false;
   12417 
   12418   if (unescaped == NULL || *unescaped == 0)
   12419     return;
   12420 
   12421   len = strlen (unescaped);
   12422   escaped = NULL;
   12423   new_i = 0;
   12424 
   12425   for (i = 0; i < len; i++)
   12426     {
   12427       char c = unescaped[i];
   12428 
   12429       if (!ISCNTRL (c))
   12430 	{
   12431 	  if (escaped)
   12432 	    escaped[new_i++] = c;
   12433 	  continue;
   12434 	}
   12435 
   12436       if (c != '\n' || !pp_is_wrapping_line (global_dc->printer))
   12437 	{
   12438 	  if (escaped == NULL)
   12439 	    {
   12440 	      /* We only allocate space for a new string if we
   12441 		 actually encounter a control character that
   12442 		 needs replacing.  */
   12443 	      escaped = (char *) xmalloc (len * 2 + 1);
   12444 	      strncpy (escaped, unescaped, i);
   12445 	      new_i = i;
   12446 	    }
   12447 
   12448 	  escaped[new_i++] = '\\';
   12449 
   12450 	  switch (c)
   12451 	    {
   12452 	    case '\a': escaped[new_i++] = 'a'; break;
   12453 	    case '\b': escaped[new_i++] = 'b'; break;
   12454 	    case '\f': escaped[new_i++] = 'f'; break;
   12455 	    case '\n': escaped[new_i++] = 'n'; break;
   12456 	    case '\r': escaped[new_i++] = 'r'; break;
   12457 	    case '\t': escaped[new_i++] = 't'; break;
   12458 	    case '\v': escaped[new_i++] = 'v'; break;
   12459 	    default:   escaped[new_i++] = '?'; break;
   12460 	    }
   12461 	}
   12462       else if (escaped)
   12463 	escaped[new_i++] = c;
   12464     }
   12465 
   12466   if (escaped)
   12467     {
   12468       escaped[new_i] = 0;
   12469       m_str = escaped;
   12470       m_owned = true;
   12471     }
   12472 }
   12473 
   12474 /* Warn about a use of an identifier which was marked deprecated.  Returns
   12475    whether a warning was given.  */
   12476 
   12477 bool
   12478 warn_deprecated_use (tree node, tree attr)
   12479 {
   12480   escaped_string msg;
   12481 
   12482   if (node == 0 || !warn_deprecated_decl)
   12483     return false;
   12484 
   12485   if (!attr)
   12486     {
   12487       if (DECL_P (node))
   12488 	attr = DECL_ATTRIBUTES (node);
   12489       else if (TYPE_P (node))
   12490 	{
   12491 	  tree decl = TYPE_STUB_DECL (node);
   12492 	  if (decl)
   12493 	    attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
   12494 	  else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
   12495 		   != NULL_TREE)
   12496 	    {
   12497 	      node = TREE_TYPE (decl);
   12498 	      attr = TYPE_ATTRIBUTES (node);
   12499 	    }
   12500 	}
   12501     }
   12502 
   12503   if (attr)
   12504     attr = lookup_attribute ("deprecated", attr);
   12505 
   12506   if (attr)
   12507     msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
   12508 
   12509   bool w = false;
   12510   if (DECL_P (node))
   12511     {
   12512       auto_diagnostic_group d;
   12513       if (msg)
   12514 	w = warning (OPT_Wdeprecated_declarations,
   12515 		     "%qD is deprecated: %s", node, (const char *) msg);
   12516       else
   12517 	w = warning (OPT_Wdeprecated_declarations,
   12518 		     "%qD is deprecated", node);
   12519       if (w)
   12520 	inform (DECL_SOURCE_LOCATION (node), "declared here");
   12521     }
   12522   else if (TYPE_P (node))
   12523     {
   12524       tree what = NULL_TREE;
   12525       tree decl = TYPE_STUB_DECL (node);
   12526 
   12527       if (TYPE_NAME (node))
   12528 	{
   12529 	  if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
   12530 	    what = TYPE_NAME (node);
   12531 	  else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
   12532 		   && DECL_NAME (TYPE_NAME (node)))
   12533 	    what = DECL_NAME (TYPE_NAME (node));
   12534 	}
   12535 
   12536       auto_diagnostic_group d;
   12537       if (what)
   12538 	{
   12539 	  if (msg)
   12540 	    w = warning (OPT_Wdeprecated_declarations,
   12541 			 "%qE is deprecated: %s", what, (const char *) msg);
   12542 	  else
   12543 	    w = warning (OPT_Wdeprecated_declarations,
   12544 			 "%qE is deprecated", what);
   12545 	}
   12546       else
   12547 	{
   12548 	  if (msg)
   12549 	    w = warning (OPT_Wdeprecated_declarations,
   12550 			 "type is deprecated: %s", (const char *) msg);
   12551 	  else
   12552 	    w = warning (OPT_Wdeprecated_declarations,
   12553 			 "type is deprecated");
   12554 	}
   12555 
   12556       if (w && decl)
   12557 	inform (DECL_SOURCE_LOCATION (decl), "declared here");
   12558     }
   12559 
   12560   return w;
   12561 }
   12562 
   12563 /* Error out with an identifier which was marked 'unavailable'. */
   12564 void
   12565 error_unavailable_use (tree node, tree attr)
   12566 {
   12567   escaped_string msg;
   12568 
   12569   if (node == 0)
   12570     return;
   12571 
   12572   if (!attr)
   12573     {
   12574       if (DECL_P (node))
   12575 	attr = DECL_ATTRIBUTES (node);
   12576       else if (TYPE_P (node))
   12577 	{
   12578 	  tree decl = TYPE_STUB_DECL (node);
   12579 	  if (decl)
   12580 	    attr = lookup_attribute ("unavailable",
   12581 				     TYPE_ATTRIBUTES (TREE_TYPE (decl)));
   12582 	}
   12583     }
   12584 
   12585   if (attr)
   12586     attr = lookup_attribute ("unavailable", attr);
   12587 
   12588   if (attr)
   12589     msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
   12590 
   12591   if (DECL_P (node))
   12592     {
   12593       auto_diagnostic_group d;
   12594       if (msg)
   12595 	error ("%qD is unavailable: %s", node, (const char *) msg);
   12596       else
   12597 	error ("%qD is unavailable", node);
   12598       inform (DECL_SOURCE_LOCATION (node), "declared here");
   12599     }
   12600   else if (TYPE_P (node))
   12601     {
   12602       tree what = NULL_TREE;
   12603       tree decl = TYPE_STUB_DECL (node);
   12604 
   12605       if (TYPE_NAME (node))
   12606 	{
   12607 	  if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
   12608 	    what = TYPE_NAME (node);
   12609 	  else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
   12610 		   && DECL_NAME (TYPE_NAME (node)))
   12611 	    what = DECL_NAME (TYPE_NAME (node));
   12612 	}
   12613 
   12614       auto_diagnostic_group d;
   12615       if (what)
   12616 	{
   12617 	  if (msg)
   12618 	    error ("%qE is unavailable: %s", what, (const char *) msg);
   12619 	  else
   12620 	    error ("%qE is unavailable", what);
   12621 	}
   12622       else
   12623 	{
   12624 	  if (msg)
   12625 	    error ("type is unavailable: %s", (const char *) msg);
   12626 	  else
   12627 	    error ("type is unavailable");
   12628 	}
   12629 
   12630       if (decl)
   12631 	inform (DECL_SOURCE_LOCATION (decl), "declared here");
   12632     }
   12633 }
   12634 
   12635 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
   12636    somewhere in it.  */
   12637 
   12638 bool
   12639 contains_bitfld_component_ref_p (const_tree ref)
   12640 {
   12641   while (handled_component_p (ref))
   12642     {
   12643       if (TREE_CODE (ref) == COMPONENT_REF
   12644           && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
   12645         return true;
   12646       ref = TREE_OPERAND (ref, 0);
   12647     }
   12648 
   12649   return false;
   12650 }
   12651 
   12652 /* Try to determine whether a TRY_CATCH expression can fall through.
   12653    This is a subroutine of block_may_fallthru.  */
   12654 
   12655 static bool
   12656 try_catch_may_fallthru (const_tree stmt)
   12657 {
   12658   tree_stmt_iterator i;
   12659 
   12660   /* If the TRY block can fall through, the whole TRY_CATCH can
   12661      fall through.  */
   12662   if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
   12663     return true;
   12664 
   12665   switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
   12666     {
   12667     case CATCH_EXPR:
   12668       /* See below.  */
   12669       return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
   12670 
   12671     case EH_FILTER_EXPR:
   12672       /* See below.  */
   12673       return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
   12674 
   12675     case STATEMENT_LIST:
   12676       break;
   12677 
   12678     default:
   12679       /* See below.  */
   12680       return false;
   12681     }
   12682 
   12683   i = tsi_start (TREE_OPERAND (stmt, 1));
   12684   switch (TREE_CODE (tsi_stmt (i)))
   12685     {
   12686     case CATCH_EXPR:
   12687       /* We expect to see a sequence of CATCH_EXPR trees, each with a
   12688 	 catch expression and a body.  The whole TRY_CATCH may fall
   12689 	 through iff any of the catch bodies falls through.  */
   12690       for (; !tsi_end_p (i); tsi_next (&i))
   12691 	{
   12692 	  if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
   12693 	    return true;
   12694 	}
   12695       return false;
   12696 
   12697     case EH_FILTER_EXPR:
   12698       /* The exception filter expression only matters if there is an
   12699 	 exception.  If the exception does not match EH_FILTER_TYPES,
   12700 	 we will execute EH_FILTER_FAILURE, and we will fall through
   12701 	 if that falls through.  If the exception does match
   12702 	 EH_FILTER_TYPES, the stack unwinder will continue up the
   12703 	 stack, so we will not fall through.  We don't know whether we
   12704 	 will throw an exception which matches EH_FILTER_TYPES or not,
   12705 	 so we just ignore EH_FILTER_TYPES and assume that we might
   12706 	 throw an exception which doesn't match.  */
   12707       return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
   12708 
   12709     default:
   12710       /* This case represents statements to be executed when an
   12711 	 exception occurs.  Those statements are implicitly followed
   12712 	 by a RESX statement to resume execution after the exception.
   12713 	 So in this case the TRY_CATCH never falls through.  */
   12714       return false;
   12715     }
   12716 }
   12717 
   12718 /* Try to determine if we can fall out of the bottom of BLOCK.  This guess
   12719    need not be 100% accurate; simply be conservative and return true if we
   12720    don't know.  This is used only to avoid stupidly generating extra code.
   12721    If we're wrong, we'll just delete the extra code later.  */
   12722 
   12723 bool
   12724 block_may_fallthru (const_tree block)
   12725 {
   12726   /* This CONST_CAST is okay because expr_last returns its argument
   12727      unmodified and we assign it to a const_tree.  */
   12728   const_tree stmt = expr_last (CONST_CAST_TREE (block));
   12729 
   12730   switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
   12731     {
   12732     case GOTO_EXPR:
   12733     case RETURN_EXPR:
   12734       /* Easy cases.  If the last statement of the block implies
   12735 	 control transfer, then we can't fall through.  */
   12736       return false;
   12737 
   12738     case SWITCH_EXPR:
   12739       /* If there is a default: label or case labels cover all possible
   12740 	 SWITCH_COND values, then the SWITCH_EXPR will transfer control
   12741 	 to some case label in all cases and all we care is whether the
   12742 	 SWITCH_BODY falls through.  */
   12743       if (SWITCH_ALL_CASES_P (stmt))
   12744 	return block_may_fallthru (SWITCH_BODY (stmt));
   12745       return true;
   12746 
   12747     case COND_EXPR:
   12748       if (block_may_fallthru (COND_EXPR_THEN (stmt)))
   12749 	return true;
   12750       return block_may_fallthru (COND_EXPR_ELSE (stmt));
   12751 
   12752     case BIND_EXPR:
   12753       return block_may_fallthru (BIND_EXPR_BODY (stmt));
   12754 
   12755     case TRY_CATCH_EXPR:
   12756       return try_catch_may_fallthru (stmt);
   12757 
   12758     case TRY_FINALLY_EXPR:
   12759       /* The finally clause is always executed after the try clause,
   12760 	 so if it does not fall through, then the try-finally will not
   12761 	 fall through.  Otherwise, if the try clause does not fall
   12762 	 through, then when the finally clause falls through it will
   12763 	 resume execution wherever the try clause was going.  So the
   12764 	 whole try-finally will only fall through if both the try
   12765 	 clause and the finally clause fall through.  */
   12766       return (block_may_fallthru (TREE_OPERAND (stmt, 0))
   12767 	      && block_may_fallthru (TREE_OPERAND (stmt, 1)));
   12768 
   12769     case EH_ELSE_EXPR:
   12770       return block_may_fallthru (TREE_OPERAND (stmt, 0));
   12771 
   12772     case MODIFY_EXPR:
   12773       if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
   12774 	stmt = TREE_OPERAND (stmt, 1);
   12775       else
   12776 	return true;
   12777       /* FALLTHRU */
   12778 
   12779     case CALL_EXPR:
   12780       /* Functions that do not return do not fall through.  */
   12781       return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
   12782 
   12783     case CLEANUP_POINT_EXPR:
   12784       return block_may_fallthru (TREE_OPERAND (stmt, 0));
   12785 
   12786     case TARGET_EXPR:
   12787       return block_may_fallthru (TREE_OPERAND (stmt, 1));
   12788 
   12789     case ERROR_MARK:
   12790       return true;
   12791 
   12792     default:
   12793       return lang_hooks.block_may_fallthru (stmt);
   12794     }
   12795 }
   12796 
   12797 /* True if we are using EH to handle cleanups.  */
   12798 static bool using_eh_for_cleanups_flag = false;
   12799 
   12800 /* This routine is called from front ends to indicate eh should be used for
   12801    cleanups.  */
   12802 void
   12803 using_eh_for_cleanups (void)
   12804 {
   12805   using_eh_for_cleanups_flag = true;
   12806 }
   12807 
   12808 /* Query whether EH is used for cleanups.  */
   12809 bool
   12810 using_eh_for_cleanups_p (void)
   12811 {
   12812   return using_eh_for_cleanups_flag;
   12813 }
   12814 
   12815 /* Wrapper for tree_code_name to ensure that tree code is valid */
   12816 const char *
   12817 get_tree_code_name (enum tree_code code)
   12818 {
   12819   const char *invalid = "<invalid tree code>";
   12820 
   12821   /* The tree_code enum promotes to signed, but we could be getting
   12822      invalid values, so force an unsigned comparison.  */
   12823   if (unsigned (code) >= MAX_TREE_CODES)
   12824     {
   12825       if ((unsigned)code == 0xa5a5)
   12826 	return "ggc_freed";
   12827       return invalid;
   12828     }
   12829 
   12830   return tree_code_name[code];
   12831 }
   12832 
   12833 /* Drops the TREE_OVERFLOW flag from T.  */
   12834 
   12835 tree
   12836 drop_tree_overflow (tree t)
   12837 {
   12838   gcc_checking_assert (TREE_OVERFLOW (t));
   12839 
   12840   /* For tree codes with a sharing machinery re-build the result.  */
   12841   if (poly_int_tree_p (t))
   12842     return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
   12843 
   12844   /* For VECTOR_CST, remove the overflow bits from the encoded elements
   12845      and canonicalize the result.  */
   12846   if (TREE_CODE (t) == VECTOR_CST)
   12847     {
   12848       tree_vector_builder builder;
   12849       builder.new_unary_operation (TREE_TYPE (t), t, true);
   12850       unsigned int count = builder.encoded_nelts ();
   12851       for (unsigned int i = 0; i < count; ++i)
   12852 	{
   12853 	  tree elt = VECTOR_CST_ELT (t, i);
   12854 	  if (TREE_OVERFLOW (elt))
   12855 	    elt = drop_tree_overflow (elt);
   12856 	  builder.quick_push (elt);
   12857 	}
   12858       return builder.build ();
   12859     }
   12860 
   12861   /* Otherwise, as all tcc_constants are possibly shared, copy the node
   12862      and drop the flag.  */
   12863   t = copy_node (t);
   12864   TREE_OVERFLOW (t) = 0;
   12865 
   12866   /* For constants that contain nested constants, drop the flag
   12867      from those as well.  */
   12868   if (TREE_CODE (t) == COMPLEX_CST)
   12869     {
   12870       if (TREE_OVERFLOW (TREE_REALPART (t)))
   12871 	TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
   12872       if (TREE_OVERFLOW (TREE_IMAGPART (t)))
   12873 	TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
   12874     }
   12875 
   12876   return t;
   12877 }
   12878 
   12879 /* Given a memory reference expression T, return its base address.
   12880    The base address of a memory reference expression is the main
   12881    object being referenced.  For instance, the base address for
   12882    'array[i].fld[j]' is 'array'.  You can think of this as stripping
   12883    away the offset part from a memory address.
   12884 
   12885    This function calls handled_component_p to strip away all the inner
   12886    parts of the memory reference until it reaches the base object.  */
   12887 
   12888 tree
   12889 get_base_address (tree t)
   12890 {
   12891   if (TREE_CODE (t) == WITH_SIZE_EXPR)
   12892     t = TREE_OPERAND (t, 0);
   12893   while (handled_component_p (t))
   12894     t = TREE_OPERAND (t, 0);
   12895 
   12896   if ((TREE_CODE (t) == MEM_REF
   12897        || TREE_CODE (t) == TARGET_MEM_REF)
   12898       && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
   12899     t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
   12900 
   12901   return t;
   12902 }
   12903 
   12904 /* Return a tree of sizetype representing the size, in bytes, of the element
   12905    of EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
   12906 
   12907 tree
   12908 array_ref_element_size (tree exp)
   12909 {
   12910   tree aligned_size = TREE_OPERAND (exp, 3);
   12911   tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
   12912   location_t loc = EXPR_LOCATION (exp);
   12913 
   12914   /* If a size was specified in the ARRAY_REF, it's the size measured
   12915      in alignment units of the element type.  So multiply by that value.  */
   12916   if (aligned_size)
   12917     {
   12918       /* ??? tree_ssa_useless_type_conversion will eliminate casts to
   12919 	 sizetype from another type of the same width and signedness.  */
   12920       if (TREE_TYPE (aligned_size) != sizetype)
   12921 	aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
   12922       return size_binop_loc (loc, MULT_EXPR, aligned_size,
   12923 			     size_int (TYPE_ALIGN_UNIT (elmt_type)));
   12924     }
   12925 
   12926   /* Otherwise, take the size from that of the element type.  Substitute
   12927      any PLACEHOLDER_EXPR that we have.  */
   12928   else
   12929     return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
   12930 }
   12931 
   12932 /* Return a tree representing the lower bound of the array mentioned in
   12933    EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
   12934 
   12935 tree
   12936 array_ref_low_bound (tree exp)
   12937 {
   12938   tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
   12939 
   12940   /* If a lower bound is specified in EXP, use it.  */
   12941   if (TREE_OPERAND (exp, 2))
   12942     return TREE_OPERAND (exp, 2);
   12943 
   12944   /* Otherwise, if there is a domain type and it has a lower bound, use it,
   12945      substituting for a PLACEHOLDER_EXPR as needed.  */
   12946   if (domain_type && TYPE_MIN_VALUE (domain_type))
   12947     return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
   12948 
   12949   /* Otherwise, return a zero of the appropriate type.  */
   12950   tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
   12951   return (idxtype == error_mark_node
   12952 	  ? integer_zero_node : build_int_cst (idxtype, 0));
   12953 }
   12954 
   12955 /* Return a tree representing the upper bound of the array mentioned in
   12956    EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
   12957 
   12958 tree
   12959 array_ref_up_bound (tree exp)
   12960 {
   12961   tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
   12962 
   12963   /* If there is a domain type and it has an upper bound, use it, substituting
   12964      for a PLACEHOLDER_EXPR as needed.  */
   12965   if (domain_type && TYPE_MAX_VALUE (domain_type))
   12966     return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
   12967 
   12968   /* Otherwise fail.  */
   12969   return NULL_TREE;
   12970 }
   12971 
   12972 /* Returns true if REF is an array reference, a component reference,
   12973    or a memory reference to an array whose actual size might be larger
   12974    than its upper bound implies, there are multiple cases:
   12975    A. a ref to a flexible array member at the end of a structure;
   12976    B. a ref to an array with a different type against the original decl;
   12977       for example:
   12978 
   12979    short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
   12980    (*((char(*)[16])&a[0]))[i+8]
   12981 
   12982    C. a ref to an array that was passed as a parameter;
   12983       for example:
   12984 
   12985    int test (uint8_t *p, uint32_t t[1][1], int n) {
   12986    for (int i = 0; i < 4; i++, p++)
   12987      t[i][0] = ...;
   12988 
   12989    If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
   12990 */
   12991 
   12992 bool
   12993 array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
   12994 {
   12995   /* The TYPE for this array referece.  */
   12996   tree atype = NULL_TREE;
   12997   /* The FIELD_DECL for the array field in the containing structure.  */
   12998   tree afield_decl = NULL_TREE;
   12999   /* Whether this array is the trailing array of a structure.  */
   13000   bool is_trailing_array_tmp = false;
   13001   if (!is_trailing_array)
   13002     is_trailing_array = &is_trailing_array_tmp;
   13003 
   13004   if (TREE_CODE (ref) == ARRAY_REF
   13005       || TREE_CODE (ref) == ARRAY_RANGE_REF)
   13006     {
   13007       atype = TREE_TYPE (TREE_OPERAND (ref, 0));
   13008       ref = TREE_OPERAND (ref, 0);
   13009     }
   13010   else if (TREE_CODE (ref) == COMPONENT_REF
   13011 	   && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
   13012     {
   13013       atype = TREE_TYPE (TREE_OPERAND (ref, 1));
   13014       afield_decl = TREE_OPERAND (ref, 1);
   13015     }
   13016   else if (TREE_CODE (ref) == MEM_REF)
   13017     {
   13018       tree arg = TREE_OPERAND (ref, 0);
   13019       if (TREE_CODE (arg) == ADDR_EXPR)
   13020 	arg = TREE_OPERAND (arg, 0);
   13021       tree argtype = TREE_TYPE (arg);
   13022       if (TREE_CODE (argtype) == RECORD_TYPE)
   13023 	{
   13024 	  if (tree fld = last_field (argtype))
   13025 	    {
   13026 	      atype = TREE_TYPE (fld);
   13027 	      afield_decl = fld;
   13028 	      if (TREE_CODE (atype) != ARRAY_TYPE)
   13029 		return false;
   13030 	      if (VAR_P (arg) && DECL_SIZE (fld))
   13031 		return false;
   13032 	    }
   13033 	  else
   13034 	    return false;
   13035 	}
   13036       else
   13037 	return false;
   13038     }
   13039   else
   13040     return false;
   13041 
   13042   if (TREE_CODE (ref) == STRING_CST)
   13043     return false;
   13044 
   13045   tree ref_to_array = ref;
   13046   while (handled_component_p (ref))
   13047     {
   13048       /* If the reference chain contains a component reference to a
   13049          non-union type and there follows another field the reference
   13050 	 is not at the end of a structure.  */
   13051       if (TREE_CODE (ref) == COMPONENT_REF)
   13052 	{
   13053 	  if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
   13054 	    {
   13055 	      tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
   13056 	      while (nextf && TREE_CODE (nextf) != FIELD_DECL)
   13057 		nextf = DECL_CHAIN (nextf);
   13058 	      if (nextf)
   13059 		return false;
   13060 	    }
   13061 	}
   13062       /* If we have a multi-dimensional array we do not consider
   13063          a non-innermost dimension as flex array if the whole
   13064 	 multi-dimensional array is at struct end.
   13065 	 Same for an array of aggregates with a trailing array
   13066 	 member.  */
   13067       else if (TREE_CODE (ref) == ARRAY_REF)
   13068 	return false;
   13069       else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
   13070 	;
   13071       /* If we view an underlying object as sth else then what we
   13072          gathered up to now is what we have to rely on.  */
   13073       else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
   13074 	break;
   13075       else
   13076 	gcc_unreachable ();
   13077 
   13078       ref = TREE_OPERAND (ref, 0);
   13079     }
   13080 
   13081   gcc_assert (!afield_decl
   13082 	      || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
   13083 
   13084   /* The array now is at struct end.  Treat flexible array member as
   13085      always subject to extend, even into just padding constrained by
   13086      an underlying decl.  */
   13087   if (! TYPE_SIZE (atype)
   13088       || ! TYPE_DOMAIN (atype)
   13089       || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
   13090     {
   13091       *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
   13092       return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
   13093     }
   13094 
   13095   /* If the reference is based on a declared entity, the size of the array
   13096      is constrained by its given domain.  (Do not trust commons PR/69368).  */
   13097   ref = get_base_address (ref);
   13098   if (ref
   13099       && DECL_P (ref)
   13100       && !(flag_unconstrained_commons
   13101 	   && VAR_P (ref) && DECL_COMMON (ref))
   13102       && DECL_SIZE_UNIT (ref)
   13103       && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
   13104     {
   13105       /* If the object itself is the array it is not at struct end.  */
   13106       if (DECL_P (ref_to_array))
   13107 	return false;
   13108 
   13109       /* Check whether the array domain covers all of the available
   13110          padding.  */
   13111       poly_int64 offset;
   13112       if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
   13113 	  || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
   13114           || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
   13115 	{
   13116 	  *is_trailing_array
   13117 	    = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
   13118 	  return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
   13119 	}
   13120       if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
   13121 	{
   13122 	  *is_trailing_array
   13123 	    = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
   13124 	  return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
   13125 	}
   13126 
   13127       /* If at least one extra element fits it is a flexarray.  */
   13128       if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
   13129 		     - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
   13130 		     + 2)
   13131 		    * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
   13132 		    wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
   13133 	{
   13134 	  *is_trailing_array
   13135 	    = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
   13136 	  return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
   13137 	}
   13138 
   13139       return false;
   13140     }
   13141 
   13142   *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
   13143   return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
   13144 }
   13145 
   13146 
   13147 /* Return a tree representing the offset, in bytes, of the field referenced
   13148    by EXP.  This does not include any offset in DECL_FIELD_BIT_OFFSET.  */
   13149 
   13150 tree
   13151 component_ref_field_offset (tree exp)
   13152 {
   13153   tree aligned_offset = TREE_OPERAND (exp, 2);
   13154   tree field = TREE_OPERAND (exp, 1);
   13155   location_t loc = EXPR_LOCATION (exp);
   13156 
   13157   /* If an offset was specified in the COMPONENT_REF, it's the offset measured
   13158      in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT.  So multiply by that
   13159      value.  */
   13160   if (aligned_offset)
   13161     {
   13162       /* ??? tree_ssa_useless_type_conversion will eliminate casts to
   13163 	 sizetype from another type of the same width and signedness.  */
   13164       if (TREE_TYPE (aligned_offset) != sizetype)
   13165 	aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
   13166       return size_binop_loc (loc, MULT_EXPR, aligned_offset,
   13167 			     size_int (DECL_OFFSET_ALIGN (field)
   13168 				       / BITS_PER_UNIT));
   13169     }
   13170 
   13171   /* Otherwise, take the offset from that of the field.  Substitute
   13172      any PLACEHOLDER_EXPR that we have.  */
   13173   else
   13174     return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
   13175 }
   13176 
   13177 /* Given the initializer INIT, return the initializer for the field
   13178    DECL if it exists, otherwise null.  Used to obtain the initializer
   13179    for a flexible array member and determine its size.  */
   13180 
   13181 static tree
   13182 get_initializer_for (tree init, tree decl)
   13183 {
   13184   STRIP_NOPS (init);
   13185 
   13186   tree fld, fld_init;
   13187   unsigned HOST_WIDE_INT i;
   13188   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
   13189     {
   13190       if (decl == fld)
   13191 	return fld_init;
   13192 
   13193       if (TREE_CODE (fld) == CONSTRUCTOR)
   13194 	{
   13195 	  fld_init = get_initializer_for (fld_init, decl);
   13196 	  if (fld_init)
   13197 	    return fld_init;
   13198 	}
   13199     }
   13200 
   13201   return NULL_TREE;
   13202 }
   13203 
   13204 /* Determines the special array member type for the array reference REF.  */
   13205 special_array_member
   13206 component_ref_sam_type (tree ref)
   13207 {
   13208   special_array_member sam_type = special_array_member::none;
   13209 
   13210   tree member = TREE_OPERAND (ref, 1);
   13211   tree memsize = DECL_SIZE_UNIT (member);
   13212   if (memsize)
   13213     {
   13214       tree memtype = TREE_TYPE (member);
   13215       if (TREE_CODE (memtype) != ARRAY_TYPE)
   13216 	return sam_type;
   13217 
   13218       bool trailing = false;
   13219       (void) array_ref_flexible_size_p (ref, &trailing);
   13220       bool zero_elts = integer_zerop (memsize);
   13221       if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
   13222 	{
   13223 	  /* If array element has zero size, verify if it is a flexible
   13224 	     array member or zero length array.  Clear zero_elts if
   13225 	     it has one or more members or is a VLA member.  */
   13226 	  if (tree dom = TYPE_DOMAIN (memtype))
   13227 	    if (tree min = TYPE_MIN_VALUE (dom))
   13228 	      if (tree max = TYPE_MAX_VALUE (dom))
   13229 		if (TREE_CODE (min) != INTEGER_CST
   13230 		    || TREE_CODE (max) != INTEGER_CST
   13231 		    || !((integer_zerop (min) && integer_all_onesp (max))
   13232 			 || tree_int_cst_lt (max, min)))
   13233 		  zero_elts = false;
   13234 	}
   13235       if (!trailing && !zero_elts)
   13236 	/* MEMBER is an interior array with more than one element.  */
   13237 	return special_array_member::int_n;
   13238 
   13239       if (zero_elts)
   13240 	{
   13241 	  if (trailing)
   13242 	    return special_array_member::trail_0;
   13243 	  else
   13244 	    return special_array_member::int_0;
   13245 	}
   13246 
   13247       if (!zero_elts)
   13248 	if (tree dom = TYPE_DOMAIN (memtype))
   13249 	  if (tree min = TYPE_MIN_VALUE (dom))
   13250 	    if (tree max = TYPE_MAX_VALUE (dom))
   13251 	      if (TREE_CODE (min) == INTEGER_CST
   13252 		  && TREE_CODE (max) == INTEGER_CST)
   13253 		{
   13254 		  offset_int minidx = wi::to_offset (min);
   13255 		  offset_int maxidx = wi::to_offset (max);
   13256 		  offset_int neltsm1 = maxidx - minidx;
   13257 		  if (neltsm1 > 0)
   13258 		    /* MEMBER is a trailing array with more than
   13259 		       one elements.  */
   13260 		    return special_array_member::trail_n;
   13261 
   13262 		  if (neltsm1 == 0)
   13263 		    return special_array_member::trail_1;
   13264 		}
   13265     }
   13266 
   13267   return sam_type;
   13268 }
   13269 
   13270 /* Determines the size of the member referenced by the COMPONENT_REF
   13271    REF, using its initializer expression if necessary in order to
   13272    determine the size of an initialized flexible array member.
   13273    If non-null, set *SAM to the type of special array member.
   13274    Returns the size as sizetype (which might be zero for an object
   13275    with an uninitialized flexible array member) or null if the size
   13276    cannot be determined.  */
   13277 
   13278 tree
   13279 component_ref_size (tree ref, special_array_member *sam /* = NULL */)
   13280 {
   13281   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
   13282 
   13283   special_array_member sambuf;
   13284   if (!sam)
   13285     sam = &sambuf;
   13286   *sam = component_ref_sam_type (ref);
   13287 
   13288   /* The object/argument referenced by the COMPONENT_REF and its type.  */
   13289   tree arg = TREE_OPERAND (ref, 0);
   13290   tree argtype = TREE_TYPE (arg);
   13291   /* The referenced member.  */
   13292   tree member = TREE_OPERAND (ref, 1);
   13293 
   13294   tree memsize = DECL_SIZE_UNIT (member);
   13295   if (memsize)
   13296     {
   13297       tree memtype = TREE_TYPE (member);
   13298       if (TREE_CODE (memtype) != ARRAY_TYPE)
   13299 	/* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
   13300 	   to the type of a class with a virtual base which doesn't
   13301 	   reflect the size of the virtual's members (see pr97595).
   13302 	   If that's the case fail for now and implement something
   13303 	   more robust in the future.  */
   13304 	return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
   13305 		? memsize : NULL_TREE);
   13306 
   13307       /* 2-or-more elements arrays are treated as normal arrays by default.  */
   13308       if (*sam == special_array_member::int_n
   13309 	  || *sam == special_array_member::trail_n)
   13310 	return memsize;
   13311 
   13312       tree afield_decl = TREE_OPERAND (ref, 1);
   13313       gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
   13314       /* If the trailing array is a not a flexible array member, treat it as
   13315 	 a normal array.  */
   13316       if (DECL_NOT_FLEXARRAY (afield_decl)
   13317 	  && *sam != special_array_member::int_0)
   13318 	return memsize;
   13319 
   13320       if (*sam == special_array_member::int_0)
   13321 	memsize = NULL_TREE;
   13322 
   13323       /* For a reference to a flexible array member of a union
   13324 	 use the size of the union instead of the size of the member.  */
   13325       if (TREE_CODE (argtype) == UNION_TYPE)
   13326 	memsize = TYPE_SIZE_UNIT (argtype);
   13327     }
   13328 
   13329   /* MEMBER is either a bona fide flexible array member, or a zero-elements
   13330      array member, or an array of length one treated as such.  */
   13331 
   13332   /* If the reference is to a declared object and the member a true
   13333      flexible array, try to determine its size from its initializer.  */
   13334   poly_int64 baseoff = 0;
   13335   tree base = get_addr_base_and_unit_offset (ref, &baseoff);
   13336   if (!base || !VAR_P (base))
   13337     {
   13338       if (*sam != special_array_member::int_0)
   13339 	return NULL_TREE;
   13340 
   13341       if (TREE_CODE (arg) != COMPONENT_REF)
   13342 	return NULL_TREE;
   13343 
   13344       base = arg;
   13345       while (TREE_CODE (base) == COMPONENT_REF)
   13346 	base = TREE_OPERAND (base, 0);
   13347       baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
   13348     }
   13349 
   13350   /* BASE is the declared object of which MEMBER is either a member
   13351      or that is cast to ARGTYPE (e.g., a char buffer used to store
   13352      an ARGTYPE object).  */
   13353   tree basetype = TREE_TYPE (base);
   13354 
   13355   /* Determine the base type of the referenced object.  If it's
   13356      the same as ARGTYPE and MEMBER has a known size, return it.  */
   13357   tree bt = basetype;
   13358   if (*sam != special_array_member::int_0)
   13359     while (TREE_CODE (bt) == ARRAY_TYPE)
   13360       bt = TREE_TYPE (bt);
   13361   bool typematch = useless_type_conversion_p (argtype, bt);
   13362   if (memsize && typematch)
   13363     return memsize;
   13364 
   13365   memsize = NULL_TREE;
   13366 
   13367   if (typematch)
   13368     /* MEMBER is a true flexible array member.  Compute its size from
   13369        the initializer of the BASE object if it has one.  */
   13370     if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
   13371       if (init != error_mark_node)
   13372 	{
   13373 	  init = get_initializer_for (init, member);
   13374 	  if (init)
   13375 	    {
   13376 	      memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
   13377 	      if (tree refsize = TYPE_SIZE_UNIT (argtype))
   13378 		{
   13379 		  /* Use the larger of the initializer size and the tail
   13380 		     padding in the enclosing struct.  */
   13381 		  poly_int64 rsz = tree_to_poly_int64 (refsize);
   13382 		  rsz -= baseoff;
   13383 		  if (known_lt (tree_to_poly_int64 (memsize), rsz))
   13384 		    memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
   13385 		}
   13386 
   13387 	      baseoff = 0;
   13388 	    }
   13389 	}
   13390 
   13391   if (!memsize)
   13392     {
   13393       if (typematch)
   13394 	{
   13395 	  if (DECL_P (base)
   13396 	      && DECL_EXTERNAL (base)
   13397 	      && bt == basetype
   13398 	      && *sam != special_array_member::int_0)
   13399 	    /* The size of a flexible array member of an extern struct
   13400 	       with no initializer cannot be determined (it's defined
   13401 	       in another translation unit and can have an initializer
   13402 	       with an arbitrary number of elements).  */
   13403 	    return NULL_TREE;
   13404 
   13405 	  /* Use the size of the base struct or, for interior zero-length
   13406 	     arrays, the size of the enclosing type.  */
   13407 	  memsize = TYPE_SIZE_UNIT (bt);
   13408 	}
   13409       else if (DECL_P (base))
   13410 	/* Use the size of the BASE object (possibly an array of some
   13411 	   other type such as char used to store the struct).  */
   13412 	memsize = DECL_SIZE_UNIT (base);
   13413       else
   13414 	return NULL_TREE;
   13415     }
   13416 
   13417   /* If the flexible array member has a known size use the greater
   13418      of it and the tail padding in the enclosing struct.
   13419      Otherwise, when the size of the flexible array member is unknown
   13420      and the referenced object is not a struct, use the size of its
   13421      type when known.  This detects sizes of array buffers when cast
   13422      to struct types with flexible array members.  */
   13423   if (memsize)
   13424     {
   13425       if (!tree_fits_poly_int64_p (memsize))
   13426 	return NULL_TREE;
   13427       poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
   13428       if (known_lt (baseoff, memsz64))
   13429 	{
   13430 	  memsz64 -= baseoff;
   13431 	  return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
   13432 	}
   13433       return size_zero_node;
   13434     }
   13435 
   13436   /* Return "don't know" for an external non-array object since its
   13437      flexible array member can be initialized to have any number of
   13438      elements.  Otherwise, return zero because the flexible array
   13439      member has no elements.  */
   13440   return (DECL_P (base)
   13441 	  && DECL_EXTERNAL (base)
   13442 	  && (!typematch
   13443 	      || TREE_CODE (basetype) != ARRAY_TYPE)
   13444 	  ? NULL_TREE : size_zero_node);
   13445 }
   13446 
   13447 /* Return the machine mode of T.  For vectors, returns the mode of the
   13448    inner type.  The main use case is to feed the result to HONOR_NANS,
   13449    avoiding the BLKmode that a direct TYPE_MODE (T) might return.  */
   13450 
   13451 machine_mode
   13452 element_mode (const_tree t)
   13453 {
   13454   if (!TYPE_P (t))
   13455     t = TREE_TYPE (t);
   13456   if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
   13457     t = TREE_TYPE (t);
   13458   return TYPE_MODE (t);
   13459 }
   13460 
   13461 /* Vector types need to re-check the target flags each time we report
   13462    the machine mode.  We need to do this because attribute target can
   13463    change the result of vector_mode_supported_p and have_regs_of_mode
   13464    on a per-function basis.  Thus the TYPE_MODE of a VECTOR_TYPE can
   13465    change on a per-function basis.  */
   13466 /* ??? Possibly a better solution is to run through all the types
   13467    referenced by a function and re-compute the TYPE_MODE once, rather
   13468    than make the TYPE_MODE macro call a function.  */
   13469 
   13470 machine_mode
   13471 vector_type_mode (const_tree t)
   13472 {
   13473   machine_mode mode;
   13474 
   13475   gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
   13476 
   13477   mode = t->type_common.mode;
   13478   if (VECTOR_MODE_P (mode)
   13479       && (!targetm.vector_mode_supported_p (mode)
   13480 	  || !have_regs_of_mode[mode]))
   13481     {
   13482       scalar_int_mode innermode;
   13483 
   13484       /* For integers, try mapping it to a same-sized scalar mode.  */
   13485       if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
   13486 	{
   13487 	  poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
   13488 			     * GET_MODE_BITSIZE (innermode));
   13489 	  scalar_int_mode mode;
   13490 	  if (int_mode_for_size (size, 0).exists (&mode)
   13491 	      && have_regs_of_mode[mode])
   13492 	    return mode;
   13493 	}
   13494 
   13495       return BLKmode;
   13496     }
   13497 
   13498   return mode;
   13499 }
   13500 
   13501 /* Return the size in bits of each element of vector type TYPE.  */
   13502 
   13503 unsigned int
   13504 vector_element_bits (const_tree type)
   13505 {
   13506   gcc_checking_assert (VECTOR_TYPE_P (type));
   13507   if (VECTOR_BOOLEAN_TYPE_P (type))
   13508     return TYPE_PRECISION (TREE_TYPE (type));
   13509   return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
   13510 }
   13511 
   13512 /* Calculate the size in bits of each element of vector type TYPE
   13513    and return the result as a tree of type bitsizetype.  */
   13514 
   13515 tree
   13516 vector_element_bits_tree (const_tree type)
   13517 {
   13518   gcc_checking_assert (VECTOR_TYPE_P (type));
   13519   if (VECTOR_BOOLEAN_TYPE_P (type))
   13520     return bitsize_int (vector_element_bits (type));
   13521   return TYPE_SIZE (TREE_TYPE (type));
   13522 }
   13523 
   13524 /* Verify that basic properties of T match TV and thus T can be a variant of
   13525    TV.  TV should be the more specified variant (i.e. the main variant).  */
   13526 
   13527 static bool
   13528 verify_type_variant (const_tree t, tree tv)
   13529 {
   13530   /* Type variant can differ by:
   13531 
   13532      - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
   13533                    ENCODE_QUAL_ADDR_SPACE.
   13534      - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
   13535        in this case some values may not be set in the variant types
   13536        (see TYPE_COMPLETE_P checks).
   13537      - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
   13538      - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
   13539      - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
   13540      - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
   13541      - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
   13542        this is necessary to make it possible to merge types form different TUs
   13543      - arrays, pointers and references may have TREE_TYPE that is a variant
   13544        of TREE_TYPE of their main variants.
   13545      - aggregates may have new TYPE_FIELDS list that list variants of
   13546        the main variant TYPE_FIELDS.
   13547      - vector types may differ by TYPE_VECTOR_OPAQUE
   13548    */
   13549 
   13550   /* Convenience macro for matching individual fields.  */
   13551 #define verify_variant_match(flag)					    \
   13552   do {									    \
   13553     if (flag (tv) != flag (t))						    \
   13554       {									    \
   13555 	error ("type variant differs by %s", #flag);			    \
   13556 	debug_tree (tv);						    \
   13557 	return false;							    \
   13558       }									    \
   13559   } while (false)
   13560 
   13561   /* tree_base checks.  */
   13562 
   13563   verify_variant_match (TREE_CODE);
   13564   /* FIXME: Ada builds non-artificial variants of artificial types.  */
   13565 #if 0
   13566   if (TYPE_ARTIFICIAL (tv))
   13567     verify_variant_match (TYPE_ARTIFICIAL);
   13568 #endif
   13569   if (POINTER_TYPE_P (tv))
   13570     verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
   13571   /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build.  */
   13572   verify_variant_match (TYPE_UNSIGNED);
   13573   verify_variant_match (TYPE_PACKED);
   13574   if (TREE_CODE (t) == REFERENCE_TYPE)
   13575     verify_variant_match (TYPE_REF_IS_RVALUE);
   13576   if (AGGREGATE_TYPE_P (t))
   13577     verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
   13578   else
   13579     verify_variant_match (TYPE_SATURATING);
   13580   /* FIXME: This check trigger during libstdc++ build.  */
   13581 #if 0
   13582   if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
   13583     verify_variant_match (TYPE_FINAL_P);
   13584 #endif
   13585 
   13586   /* tree_type_common checks.  */
   13587 
   13588   if (COMPLETE_TYPE_P (t))
   13589     {
   13590       verify_variant_match (TYPE_MODE);
   13591       if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
   13592 	  && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
   13593 	verify_variant_match (TYPE_SIZE);
   13594       if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
   13595 	  && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
   13596 	  && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
   13597 	{
   13598 	  gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
   13599 					TYPE_SIZE_UNIT (tv), 0));
   13600 	  error ("type variant has different %<TYPE_SIZE_UNIT%>");
   13601 	  debug_tree (tv);
   13602 	  error ("type variant%'s %<TYPE_SIZE_UNIT%>");
   13603 	  debug_tree (TYPE_SIZE_UNIT (tv));
   13604 	  error ("type%'s %<TYPE_SIZE_UNIT%>");
   13605 	  debug_tree (TYPE_SIZE_UNIT (t));
   13606 	  return false;
   13607 	}
   13608       verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
   13609     }
   13610   verify_variant_match (TYPE_PRECISION_RAW);
   13611   if (RECORD_OR_UNION_TYPE_P (t))
   13612     verify_variant_match (TYPE_TRANSPARENT_AGGR);
   13613   else if (TREE_CODE (t) == ARRAY_TYPE)
   13614     verify_variant_match (TYPE_NONALIASED_COMPONENT);
   13615   /* During LTO we merge variant lists from diferent translation units
   13616      that may differ BY TYPE_CONTEXT that in turn may point
   13617      to TRANSLATION_UNIT_DECL.
   13618      Ada also builds variants of types with different TYPE_CONTEXT.   */
   13619 #if 0
   13620   if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
   13621     verify_variant_match (TYPE_CONTEXT);
   13622 #endif
   13623   if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
   13624     verify_variant_match (TYPE_STRING_FLAG);
   13625   if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
   13626     verify_variant_match (TYPE_CXX_ODR_P);
   13627   if (TYPE_ALIAS_SET_KNOWN_P (t))
   13628     {
   13629       error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
   13630       debug_tree (tv);
   13631       return false;
   13632     }
   13633 
   13634   /* tree_type_non_common checks.  */
   13635 
   13636   /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
   13637      and dangle the pointer from time to time.  */
   13638   if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
   13639       && (in_lto_p || !TYPE_VFIELD (tv)
   13640 	  || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
   13641     {
   13642       error ("type variant has different %<TYPE_VFIELD%>");
   13643       debug_tree (tv);
   13644       return false;
   13645     }
   13646   if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
   13647        || TREE_CODE (t) == INTEGER_TYPE
   13648        || TREE_CODE (t) == BOOLEAN_TYPE
   13649        || TREE_CODE (t) == BITINT_TYPE
   13650        || SCALAR_FLOAT_TYPE_P (t)
   13651        || FIXED_POINT_TYPE_P (t))
   13652     {
   13653       verify_variant_match (TYPE_MAX_VALUE);
   13654       verify_variant_match (TYPE_MIN_VALUE);
   13655     }
   13656   if (TREE_CODE (t) == METHOD_TYPE)
   13657     verify_variant_match (TYPE_METHOD_BASETYPE);
   13658   if (TREE_CODE (t) == OFFSET_TYPE)
   13659     verify_variant_match (TYPE_OFFSET_BASETYPE);
   13660   if (TREE_CODE (t) == ARRAY_TYPE)
   13661     verify_variant_match (TYPE_ARRAY_MAX_SIZE);
   13662   /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
   13663      or even type's main variant.  This is needed to make bootstrap pass
   13664      and the bug seems new in GCC 5.
   13665      C++ FE should be updated to make this consistent and we should check
   13666      that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
   13667      is a match with main variant.
   13668 
   13669      Also disable the check for Java for now because of parser hack that builds
   13670      first an dummy BINFO and then sometimes replace it by real BINFO in some
   13671      of the copies.  */
   13672   if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
   13673       && TYPE_BINFO (t) != TYPE_BINFO (tv)
   13674       /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
   13675 	 Since there is no cheap way to tell C++/Java type w/o LTO, do checking
   13676 	 at LTO time only.  */
   13677       && (in_lto_p && odr_type_p (t)))
   13678     {
   13679       error ("type variant has different %<TYPE_BINFO%>");
   13680       debug_tree (tv);
   13681       error ("type variant%'s %<TYPE_BINFO%>");
   13682       debug_tree (TYPE_BINFO (tv));
   13683       error ("type%'s %<TYPE_BINFO%>");
   13684       debug_tree (TYPE_BINFO (t));
   13685       return false;
   13686     }
   13687 
   13688   /* Check various uses of TYPE_VALUES_RAW.  */
   13689   if (TREE_CODE (t) == ENUMERAL_TYPE
   13690       && TYPE_VALUES (t))
   13691     verify_variant_match (TYPE_VALUES);
   13692   else if (TREE_CODE (t) == ARRAY_TYPE)
   13693     verify_variant_match (TYPE_DOMAIN);
   13694   /* Permit incomplete variants of complete type.  While FEs may complete
   13695      all variants, this does not happen for C++ templates in all cases.  */
   13696   else if (RECORD_OR_UNION_TYPE_P (t)
   13697 	   && COMPLETE_TYPE_P (t)
   13698 	   && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
   13699     {
   13700       tree f1, f2;
   13701 
   13702       /* Fortran builds qualified variants as new records with items of
   13703 	 qualified type. Verify that they looks same.  */
   13704       for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
   13705 	   f1 && f2;
   13706 	   f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
   13707 	if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
   13708 	    || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
   13709 		 != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
   13710 		/* FIXME: gfc_nonrestricted_type builds all types as variants
   13711 		   with exception of pointer types.  It deeply copies the type
   13712 		   which means that we may end up with a variant type
   13713 		   referring non-variant pointer.  We may change it to
   13714 		   produce types as variants, too, like
   13715 		   objc_get_protocol_qualified_type does.  */
   13716 		&& !POINTER_TYPE_P (TREE_TYPE (f1)))
   13717 	    || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
   13718 	    || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
   13719 	  break;
   13720       if (f1 || f2)
   13721 	{
   13722 	  error ("type variant has different %<TYPE_FIELDS%>");
   13723 	  debug_tree (tv);
   13724 	  error ("first mismatch is field");
   13725 	  debug_tree (f1);
   13726 	  error ("and field");
   13727 	  debug_tree (f2);
   13728           return false;
   13729 	}
   13730     }
   13731   else if (FUNC_OR_METHOD_TYPE_P (t))
   13732     verify_variant_match (TYPE_ARG_TYPES);
   13733   /* For C++ the qualified variant of array type is really an array type
   13734      of qualified TREE_TYPE.
   13735      objc builds variants of pointer where pointer to type is a variant, too
   13736      in objc_get_protocol_qualified_type.  */
   13737   if (TREE_TYPE (t) != TREE_TYPE (tv)
   13738       && ((TREE_CODE (t) != ARRAY_TYPE
   13739 	   && !POINTER_TYPE_P (t))
   13740 	  || TYPE_MAIN_VARIANT (TREE_TYPE (t))
   13741 	     != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
   13742     {
   13743       error ("type variant has different %<TREE_TYPE%>");
   13744       debug_tree (tv);
   13745       error ("type variant%'s %<TREE_TYPE%>");
   13746       debug_tree (TREE_TYPE (tv));
   13747       error ("type%'s %<TREE_TYPE%>");
   13748       debug_tree (TREE_TYPE (t));
   13749       return false;
   13750     }
   13751   if (type_with_alias_set_p (t)
   13752       && !gimple_canonical_types_compatible_p (t, tv, false))
   13753     {
   13754       error ("type is not compatible with its variant");
   13755       debug_tree (tv);
   13756       error ("type variant%'s %<TREE_TYPE%>");
   13757       debug_tree (TREE_TYPE (tv));
   13758       error ("type%'s %<TREE_TYPE%>");
   13759       debug_tree (TREE_TYPE (t));
   13760       return false;
   13761     }
   13762   return true;
   13763 #undef verify_variant_match
   13764 }
   13765 
   13766 
   13767 /* The TYPE_CANONICAL merging machinery.  It should closely resemble
   13768    the middle-end types_compatible_p function.  It needs to avoid
   13769    claiming types are different for types that should be treated
   13770    the same with respect to TBAA.  Canonical types are also used
   13771    for IL consistency checks via the useless_type_conversion_p
   13772    predicate which does not handle all type kinds itself but falls
   13773    back to pointer-comparison of TYPE_CANONICAL for aggregates
   13774    for example.  */
   13775 
   13776 /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
   13777    type calculation because we need to allow inter-operability between signed
   13778    and unsigned variants.  */
   13779 
   13780 bool
   13781 type_with_interoperable_signedness (const_tree type)
   13782 {
   13783   /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
   13784      signed char and unsigned char.  Similarly fortran FE builds
   13785      C_SIZE_T as signed type, while C defines it unsigned.  */
   13786 
   13787   return tree_code_for_canonical_type_merging (TREE_CODE (type))
   13788 	   == INTEGER_TYPE
   13789          && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
   13790 	     || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
   13791 }
   13792 
   13793 /* Return true iff T1 and T2 are structurally identical for what
   13794    TBAA is concerned.
   13795    This function is used both by lto.cc canonical type merging and by the
   13796    verifier.  If TRUST_TYPE_CANONICAL we do not look into structure of types
   13797    that have TYPE_CANONICAL defined and assume them equivalent.  This is useful
   13798    only for LTO because only in these cases TYPE_CANONICAL equivalence
   13799    correspond to one defined by gimple_canonical_types_compatible_p.  */
   13800 
   13801 bool
   13802 gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
   13803 				     bool trust_type_canonical)
   13804 {
   13805   /* Type variants should be same as the main variant.  When not doing sanity
   13806      checking to verify this fact, go to main variants and save some work.  */
   13807   if (trust_type_canonical)
   13808     {
   13809       t1 = TYPE_MAIN_VARIANT (t1);
   13810       t2 = TYPE_MAIN_VARIANT (t2);
   13811     }
   13812 
   13813   /* Check first for the obvious case of pointer identity.  */
   13814   if (t1 == t2)
   13815     return true;
   13816 
   13817   /* Check that we have two types to compare.  */
   13818   if (t1 == NULL_TREE || t2 == NULL_TREE)
   13819     return false;
   13820 
   13821   /* We consider complete types always compatible with incomplete type.
   13822      This does not make sense for canonical type calculation and thus we
   13823      need to ensure that we are never called on it.
   13824 
   13825      FIXME: For more correctness the function probably should have three modes
   13826 	1) mode assuming that types are complete mathcing their structure
   13827 	2) mode allowing incomplete types but producing equivalence classes
   13828 	   and thus ignoring all info from complete types
   13829 	3) mode allowing incomplete types to match complete but checking
   13830 	   compatibility between complete types.
   13831 
   13832      1 and 2 can be used for canonical type calculation. 3 is the real
   13833      definition of type compatibility that can be used i.e. for warnings during
   13834      declaration merging.  */
   13835 
   13836   gcc_assert (!trust_type_canonical
   13837 	      || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
   13838 
   13839   /* If the types have been previously registered and found equal
   13840      they still are.  */
   13841 
   13842   if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
   13843       && trust_type_canonical)
   13844     {
   13845       /* Do not use TYPE_CANONICAL of pointer types.  For LTO streamed types
   13846 	 they are always NULL, but they are set to non-NULL for types
   13847 	 constructed by build_pointer_type and variants.  In this case the
   13848 	 TYPE_CANONICAL is more fine grained than the equivalnce we test (where
   13849 	 all pointers are considered equal.  Be sure to not return false
   13850 	 negatives.  */
   13851       gcc_checking_assert (canonical_type_used_p (t1)
   13852 			   && canonical_type_used_p (t2));
   13853       return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
   13854     }
   13855 
   13856   /* For types where we do ODR based TBAA the canonical type is always
   13857      set correctly, so we know that types are different if their
   13858      canonical types does not match.  */
   13859   if (trust_type_canonical
   13860       && (odr_type_p (t1) && odr_based_tbaa_p (t1))
   13861 	  != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
   13862     return false;
   13863 
   13864   /* Can't be the same type if the types don't have the same code.  */
   13865   enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
   13866   if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
   13867     return false;
   13868 
   13869   /* Qualifiers do not matter for canonical type comparison purposes.  */
   13870 
   13871   /* Void types and nullptr types are always the same.  */
   13872   if (VOID_TYPE_P (t1)
   13873       || TREE_CODE (t1) == NULLPTR_TYPE)
   13874     return true;
   13875 
   13876   /* Can't be the same type if they have different mode.  */
   13877   if (TYPE_MODE (t1) != TYPE_MODE (t2))
   13878     return false;
   13879 
   13880   /* Non-aggregate types can be handled cheaply.  */
   13881   if (INTEGRAL_TYPE_P (t1)
   13882       || SCALAR_FLOAT_TYPE_P (t1)
   13883       || FIXED_POINT_TYPE_P (t1)
   13884       || VECTOR_TYPE_P (t1)
   13885       || TREE_CODE (t1) == COMPLEX_TYPE
   13886       || TREE_CODE (t1) == OFFSET_TYPE
   13887       || POINTER_TYPE_P (t1))
   13888     {
   13889       /* Can't be the same type if they have different precision.  */
   13890       if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
   13891 	return false;
   13892 
   13893       /* In some cases the signed and unsigned types are required to be
   13894 	 inter-operable.  */
   13895       if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
   13896 	  && !type_with_interoperable_signedness (t1))
   13897 	return false;
   13898 
   13899       /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
   13900 	 interoperable with "signed char".  Unless all frontends are revisited
   13901 	 to agree on these types, we must ignore the flag completely.  */
   13902 
   13903       /* Fortran standard define C_PTR type that is compatible with every
   13904  	 C pointer.  For this reason we need to glob all pointers into one.
   13905 	 Still pointers in different address spaces are not compatible.  */
   13906       if (POINTER_TYPE_P (t1))
   13907 	{
   13908 	  if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
   13909 	      != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
   13910 	    return false;
   13911 	}
   13912 
   13913       /* Tail-recurse to components.  */
   13914       if (VECTOR_TYPE_P (t1)
   13915 	  || TREE_CODE (t1) == COMPLEX_TYPE)
   13916 	return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
   13917 						    TREE_TYPE (t2),
   13918 						    trust_type_canonical);
   13919 
   13920       return true;
   13921     }
   13922 
   13923   /* Do type-specific comparisons.  */
   13924   switch (TREE_CODE (t1))
   13925     {
   13926     case ARRAY_TYPE:
   13927       /* Array types are the same if the element types are the same and
   13928 	 the number of elements are the same.  */
   13929       if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
   13930 						trust_type_canonical)
   13931 	  || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
   13932 	  || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
   13933 	  || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
   13934 	return false;
   13935       else
   13936 	{
   13937 	  tree i1 = TYPE_DOMAIN (t1);
   13938 	  tree i2 = TYPE_DOMAIN (t2);
   13939 
   13940 	  /* For an incomplete external array, the type domain can be
   13941  	     NULL_TREE.  Check this condition also.  */
   13942 	  if (i1 == NULL_TREE && i2 == NULL_TREE)
   13943 	    return true;
   13944 	  else if (i1 == NULL_TREE || i2 == NULL_TREE)
   13945 	    return false;
   13946 	  else
   13947 	    {
   13948 	      tree min1 = TYPE_MIN_VALUE (i1);
   13949 	      tree min2 = TYPE_MIN_VALUE (i2);
   13950 	      tree max1 = TYPE_MAX_VALUE (i1);
   13951 	      tree max2 = TYPE_MAX_VALUE (i2);
   13952 
   13953 	      /* The minimum/maximum values have to be the same.  */
   13954 	      if ((min1 == min2
   13955 		   || (min1 && min2
   13956 		       && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
   13957 			    && TREE_CODE (min2) == PLACEHOLDER_EXPR)
   13958 		           || operand_equal_p (min1, min2, 0))))
   13959 		  && (max1 == max2
   13960 		      || (max1 && max2
   13961 			  && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
   13962 			       && TREE_CODE (max2) == PLACEHOLDER_EXPR)
   13963 			      || operand_equal_p (max1, max2, 0)))))
   13964 		return true;
   13965 	      else
   13966 		return false;
   13967 	    }
   13968 	}
   13969 
   13970     case METHOD_TYPE:
   13971     case FUNCTION_TYPE:
   13972       /* Function types are the same if the return type and arguments types
   13973 	 are the same.  */
   13974       if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
   13975 						trust_type_canonical))
   13976 	return false;
   13977 
   13978       if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
   13979 	  && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
   13980 	      == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
   13981 	return true;
   13982       else
   13983 	{
   13984 	  tree parms1, parms2;
   13985 
   13986 	  for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
   13987 	       parms1 && parms2;
   13988 	       parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
   13989 	    {
   13990 	      if (!gimple_canonical_types_compatible_p
   13991 		     (TREE_VALUE (parms1), TREE_VALUE (parms2),
   13992 		      trust_type_canonical))
   13993 		return false;
   13994 	    }
   13995 
   13996 	  if (parms1 || parms2)
   13997 	    return false;
   13998 
   13999 	  return true;
   14000 	}
   14001 
   14002     case RECORD_TYPE:
   14003     case UNION_TYPE:
   14004     case QUAL_UNION_TYPE:
   14005       {
   14006 	tree f1, f2;
   14007 
   14008 	/* Don't try to compare variants of an incomplete type, before
   14009 	   TYPE_FIELDS has been copied around.  */
   14010 	if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
   14011 	  return true;
   14012 
   14013 
   14014 	if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
   14015 	  return false;
   14016 
   14017 	/* For aggregate types, all the fields must be the same.  */
   14018 	for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
   14019 	     f1 || f2;
   14020 	     f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
   14021 	  {
   14022 	    /* Skip non-fields and zero-sized fields.  */
   14023 	    while (f1 && (TREE_CODE (f1) != FIELD_DECL
   14024 			  || (DECL_SIZE (f1)
   14025 			      && integer_zerop (DECL_SIZE (f1)))))
   14026 	      f1 = TREE_CHAIN (f1);
   14027 	    while (f2 && (TREE_CODE (f2) != FIELD_DECL
   14028 			  || (DECL_SIZE (f2)
   14029 			      && integer_zerop (DECL_SIZE (f2)))))
   14030 	      f2 = TREE_CHAIN (f2);
   14031 	    if (!f1 || !f2)
   14032 	      break;
   14033 	    /* The fields must have the same name, offset and type.  */
   14034 	    if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
   14035 		|| !gimple_compare_field_offset (f1, f2)
   14036 		|| !gimple_canonical_types_compatible_p
   14037 		      (TREE_TYPE (f1), TREE_TYPE (f2),
   14038 		       trust_type_canonical))
   14039 	      return false;
   14040 	  }
   14041 
   14042 	/* If one aggregate has more fields than the other, they
   14043 	   are not the same.  */
   14044 	if (f1 || f2)
   14045 	  return false;
   14046 
   14047 	return true;
   14048       }
   14049 
   14050     default:
   14051       /* Consider all types with language specific trees in them mutually
   14052 	 compatible.  This is executed only from verify_type and false
   14053          positives can be tolerated.  */
   14054       gcc_assert (!in_lto_p);
   14055       return true;
   14056     }
   14057 }
   14058 
   14059 /* For OPAQUE_TYPE T, it should have only size and alignment information
   14060    and its mode should be of class MODE_OPAQUE.  This function verifies
   14061    these properties of T match TV which is the main variant of T and TC
   14062    which is the canonical of T.  */
   14063 
   14064 static void
   14065 verify_opaque_type (const_tree t, tree tv, tree tc)
   14066 {
   14067   gcc_assert (OPAQUE_TYPE_P (t));
   14068   gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
   14069   gcc_assert (tc && tc == TYPE_CANONICAL (tc));
   14070 
   14071   /* For an opaque type T1, check if some of its properties match
   14072      the corresponding ones of the other opaque type T2, emit some
   14073      error messages for those inconsistent ones.  */
   14074   auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
   14075 					     const char *kind_msg)
   14076   {
   14077     if (!OPAQUE_TYPE_P (t2))
   14078       {
   14079 	error ("type %s is not an opaque type", kind_msg);
   14080 	debug_tree (t2);
   14081 	return;
   14082       }
   14083     if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
   14084       {
   14085 	error ("type %s is not with opaque mode", kind_msg);
   14086 	debug_tree (t2);
   14087 	return;
   14088       }
   14089     if (TYPE_MODE (t1) != TYPE_MODE (t2))
   14090       {
   14091 	error ("type %s differs by %<TYPE_MODE%>", kind_msg);
   14092 	debug_tree (t2);
   14093 	return;
   14094       }
   14095     poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
   14096     poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
   14097     if (maybe_ne (t1_size, t2_size))
   14098       {
   14099 	error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
   14100 	debug_tree (t2);
   14101 	return;
   14102       }
   14103     if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
   14104       {
   14105 	error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
   14106 	debug_tree (t2);
   14107 	return;
   14108       }
   14109     if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
   14110       {
   14111 	error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
   14112 	debug_tree (t2);
   14113 	return;
   14114       }
   14115   };
   14116 
   14117   if (t != tv)
   14118     check_properties_for_opaque_type (t, tv, "variant");
   14119 
   14120   if (t != tc)
   14121     check_properties_for_opaque_type (t, tc, "canonical");
   14122 }
   14123 
   14124 /* Verify type T.  */
   14125 
   14126 void
   14127 verify_type (const_tree t)
   14128 {
   14129   bool error_found = false;
   14130   tree mv = TYPE_MAIN_VARIANT (t);
   14131   tree ct = TYPE_CANONICAL (t);
   14132 
   14133   if (OPAQUE_TYPE_P (t))
   14134     {
   14135       verify_opaque_type (t, mv, ct);
   14136       return;
   14137     }
   14138 
   14139   if (!mv)
   14140     {
   14141       error ("main variant is not defined");
   14142       error_found = true;
   14143     }
   14144   else if (mv != TYPE_MAIN_VARIANT (mv))
   14145     {
   14146       error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
   14147       debug_tree (mv);
   14148       error_found = true;
   14149     }
   14150   else if (t != mv && !verify_type_variant (t, mv))
   14151     error_found = true;
   14152 
   14153   if (!ct)
   14154     ;
   14155   else if (TYPE_CANONICAL (ct) != ct)
   14156     {
   14157       error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
   14158       debug_tree (ct);
   14159       error_found = true;
   14160     }
   14161   /* Method and function types cannot be used to address memory and thus
   14162      TYPE_CANONICAL really matters only for determining useless conversions.
   14163 
   14164      FIXME: C++ FE produce declarations of builtin functions that are not
   14165      compatible with main variants.  */
   14166   else if (TREE_CODE (t) == FUNCTION_TYPE)
   14167     ;
   14168   else if (t != ct
   14169 	   /* FIXME: gimple_canonical_types_compatible_p cannot compare types
   14170 	      with variably sized arrays because their sizes possibly
   14171 	      gimplified to different variables.  */
   14172 	   && !variably_modified_type_p (ct, NULL)
   14173 	   && !gimple_canonical_types_compatible_p (t, ct, false)
   14174 	   && COMPLETE_TYPE_P (t))
   14175     {
   14176       error ("%<TYPE_CANONICAL%> is not compatible");
   14177       debug_tree (ct);
   14178       error_found = true;
   14179     }
   14180 
   14181   if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
   14182       && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
   14183     {
   14184       error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
   14185       debug_tree (ct);
   14186       error_found = true;
   14187     }
   14188   if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
   14189    {
   14190       error ("%<TYPE_CANONICAL%> of main variant is not main variant");
   14191       debug_tree (ct);
   14192       debug_tree (TYPE_MAIN_VARIANT (ct));
   14193       error_found = true;
   14194    }
   14195 
   14196 
   14197   /* Check various uses of TYPE_MIN_VALUE_RAW.  */
   14198   if (RECORD_OR_UNION_TYPE_P (t))
   14199     {
   14200       /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
   14201 	 and danagle the pointer from time to time.  */
   14202       if (TYPE_VFIELD (t)
   14203 	  && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
   14204 	  && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
   14205 	{
   14206 	  error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
   14207 	  debug_tree (TYPE_VFIELD (t));
   14208 	  error_found = true;
   14209 	}
   14210     }
   14211   else if (TREE_CODE (t) == POINTER_TYPE)
   14212     {
   14213       if (TYPE_NEXT_PTR_TO (t)
   14214 	  && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
   14215 	{
   14216 	  error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
   14217 	  debug_tree (TYPE_NEXT_PTR_TO (t));
   14218 	  error_found = true;
   14219 	}
   14220     }
   14221   else if (TREE_CODE (t) == REFERENCE_TYPE)
   14222     {
   14223       if (TYPE_NEXT_REF_TO (t)
   14224 	  && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
   14225 	{
   14226 	  error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
   14227 	  debug_tree (TYPE_NEXT_REF_TO (t));
   14228 	  error_found = true;
   14229 	}
   14230     }
   14231   else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
   14232 	   || FIXED_POINT_TYPE_P (t))
   14233     {
   14234       /* FIXME: The following check should pass:
   14235 	  useless_type_conversion_p (const_cast <tree> (t),
   14236 				     TREE_TYPE (TYPE_MIN_VALUE (t))
   14237 	 but does not for C sizetypes in LTO.  */
   14238     }
   14239 
   14240   /* Check various uses of TYPE_MAXVAL_RAW.  */
   14241   if (RECORD_OR_UNION_TYPE_P (t))
   14242     {
   14243       if (!TYPE_BINFO (t))
   14244 	;
   14245       else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
   14246 	{
   14247 	  error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
   14248 	  debug_tree (TYPE_BINFO (t));
   14249 	  error_found = true;
   14250 	}
   14251       else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
   14252 	{
   14253 	  error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
   14254 	  debug_tree (TREE_TYPE (TYPE_BINFO (t)));
   14255 	  error_found = true;
   14256 	}
   14257     }
   14258   else if (FUNC_OR_METHOD_TYPE_P (t))
   14259     {
   14260       if (TYPE_METHOD_BASETYPE (t)
   14261 	  && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
   14262 	  && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
   14263 	{
   14264 	  error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
   14265 	  debug_tree (TYPE_METHOD_BASETYPE (t));
   14266 	  error_found = true;
   14267 	}
   14268     }
   14269   else if (TREE_CODE (t) == OFFSET_TYPE)
   14270     {
   14271       if (TYPE_OFFSET_BASETYPE (t)
   14272 	  && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
   14273 	  && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
   14274 	{
   14275 	  error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
   14276 	  debug_tree (TYPE_OFFSET_BASETYPE (t));
   14277 	  error_found = true;
   14278 	}
   14279     }
   14280   else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
   14281 	   || FIXED_POINT_TYPE_P (t))
   14282     {
   14283       /* FIXME: The following check should pass:
   14284 	  useless_type_conversion_p (const_cast <tree> (t),
   14285 				     TREE_TYPE (TYPE_MAX_VALUE (t))
   14286 	 but does not for C sizetypes in LTO.  */
   14287     }
   14288   else if (TREE_CODE (t) == ARRAY_TYPE)
   14289     {
   14290       if (TYPE_ARRAY_MAX_SIZE (t)
   14291 	  && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
   14292         {
   14293 	  error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
   14294 	  debug_tree (TYPE_ARRAY_MAX_SIZE (t));
   14295 	  error_found = true;
   14296         }
   14297     }
   14298   else if (TYPE_MAX_VALUE_RAW (t))
   14299     {
   14300       error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
   14301       debug_tree (TYPE_MAX_VALUE_RAW (t));
   14302       error_found = true;
   14303     }
   14304 
   14305   if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
   14306     {
   14307       error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
   14308       debug_tree (TYPE_LANG_SLOT_1 (t));
   14309       error_found = true;
   14310     }
   14311 
   14312   /* Check various uses of TYPE_VALUES_RAW.  */
   14313   if (TREE_CODE (t) == ENUMERAL_TYPE)
   14314     for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
   14315       {
   14316 	tree value = TREE_VALUE (l);
   14317 	tree name = TREE_PURPOSE (l);
   14318 
   14319 	/* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
   14320  	   CONST_DECL of ENUMERAL TYPE.  */
   14321 	if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
   14322 	  {
   14323 	    error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
   14324 	    debug_tree (value);
   14325 	    debug_tree (name);
   14326 	    error_found = true;
   14327 	  }
   14328 	if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
   14329 	    && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
   14330 	    && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
   14331 	  {
   14332 	    error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
   14333 		   "to the enum");
   14334 	    debug_tree (value);
   14335 	    debug_tree (name);
   14336 	    error_found = true;
   14337 	  }
   14338 	if (TREE_CODE (name) != IDENTIFIER_NODE)
   14339 	  {
   14340 	    error ("enum value name is not %<IDENTIFIER_NODE%>");
   14341 	    debug_tree (value);
   14342 	    debug_tree (name);
   14343 	    error_found = true;
   14344 	  }
   14345       }
   14346   else if (TREE_CODE (t) == ARRAY_TYPE)
   14347     {
   14348       if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
   14349 	{
   14350 	  error ("array %<TYPE_DOMAIN%> is not integer type");
   14351 	  debug_tree (TYPE_DOMAIN (t));
   14352 	  error_found = true;
   14353 	}
   14354     }
   14355   else if (RECORD_OR_UNION_TYPE_P (t))
   14356     {
   14357       if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
   14358 	{
   14359 	  error ("%<TYPE_FIELDS%> defined in incomplete type");
   14360 	  error_found = true;
   14361 	}
   14362       for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
   14363 	{
   14364 	  /* TODO: verify properties of decls.  */
   14365 	  if (TREE_CODE (fld) == FIELD_DECL)
   14366 	    ;
   14367 	  else if (TREE_CODE (fld) == TYPE_DECL)
   14368 	    ;
   14369 	  else if (TREE_CODE (fld) == CONST_DECL)
   14370 	    ;
   14371 	  else if (VAR_P (fld))
   14372 	    ;
   14373 	  else if (TREE_CODE (fld) == TEMPLATE_DECL)
   14374 	    ;
   14375 	  else if (TREE_CODE (fld) == USING_DECL)
   14376 	    ;
   14377 	  else if (TREE_CODE (fld) == FUNCTION_DECL)
   14378 	    ;
   14379 	  else
   14380 	    {
   14381 	      error ("wrong tree in %<TYPE_FIELDS%> list");
   14382 	      debug_tree (fld);
   14383 	      error_found = true;
   14384 	    }
   14385 	}
   14386     }
   14387   else if (TREE_CODE (t) == INTEGER_TYPE
   14388 	   || TREE_CODE (t) == BOOLEAN_TYPE
   14389 	   || TREE_CODE (t) == BITINT_TYPE
   14390 	   || TREE_CODE (t) == OFFSET_TYPE
   14391 	   || TREE_CODE (t) == REFERENCE_TYPE
   14392 	   || TREE_CODE (t) == NULLPTR_TYPE
   14393 	   || TREE_CODE (t) == POINTER_TYPE)
   14394     {
   14395       if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
   14396 	{
   14397 	  error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
   14398 		 "is %p",
   14399 		 TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
   14400 	  error_found = true;
   14401 	}
   14402       else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
   14403 	{
   14404 	  error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
   14405 	  debug_tree (TYPE_CACHED_VALUES (t));
   14406 	  error_found = true;
   14407 	}
   14408       /* Verify just enough of cache to ensure that no one copied it to new type.
   14409  	 All copying should go by copy_node that should clear it.  */
   14410       else if (TYPE_CACHED_VALUES_P (t))
   14411 	{
   14412 	  int i;
   14413 	  for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
   14414 	    if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
   14415 		&& TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
   14416 	      {
   14417 		error ("wrong %<TYPE_CACHED_VALUES%> entry");
   14418 		debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
   14419 		error_found = true;
   14420 		break;
   14421 	      }
   14422 	}
   14423     }
   14424   else if (FUNC_OR_METHOD_TYPE_P (t))
   14425     for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
   14426       {
   14427 	/* C++ FE uses TREE_PURPOSE to store initial values.  */
   14428 	if (TREE_PURPOSE (l) && in_lto_p)
   14429 	  {
   14430 	    error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
   14431 	    debug_tree (l);
   14432 	    error_found = true;
   14433 	  }
   14434 	if (!TYPE_P (TREE_VALUE (l)))
   14435 	  {
   14436 	    error ("wrong entry in %<TYPE_ARG_TYPES%> list");
   14437 	    debug_tree (l);
   14438 	    error_found = true;
   14439 	  }
   14440       }
   14441   else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
   14442     {
   14443       error ("%<TYPE_VALUES_RAW%> field is non-NULL");
   14444       debug_tree (TYPE_VALUES_RAW (t));
   14445       error_found = true;
   14446     }
   14447   if (TREE_CODE (t) != INTEGER_TYPE
   14448       && TREE_CODE (t) != BOOLEAN_TYPE
   14449       && TREE_CODE (t) != BITINT_TYPE
   14450       && TREE_CODE (t) != OFFSET_TYPE
   14451       && TREE_CODE (t) != REFERENCE_TYPE
   14452       && TREE_CODE (t) != NULLPTR_TYPE
   14453       && TREE_CODE (t) != POINTER_TYPE
   14454       && TYPE_CACHED_VALUES_P (t))
   14455     {
   14456       error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
   14457       error_found = true;
   14458     }
   14459 
   14460   /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
   14461      TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
   14462      of a type. */
   14463   if (TREE_CODE (t) == METHOD_TYPE
   14464       && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
   14465     {
   14466 	error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
   14467 	error_found = true;
   14468     }
   14469 
   14470   if (error_found)
   14471     {
   14472       debug_tree (const_cast <tree> (t));
   14473       internal_error ("%qs failed", __func__);
   14474     }
   14475 }
   14476 
   14477 
   14478 /* Return 1 if ARG interpreted as signed in its precision is known to be
   14479    always positive or 2 if ARG is known to be always negative, or 3 if
   14480    ARG may be positive or negative.  */
   14481 
   14482 int
   14483 get_range_pos_neg (tree arg)
   14484 {
   14485   if (arg == error_mark_node)
   14486     return 3;
   14487 
   14488   int prec = TYPE_PRECISION (TREE_TYPE (arg));
   14489   int cnt = 0;
   14490   if (TREE_CODE (arg) == INTEGER_CST)
   14491     {
   14492       wide_int w = wi::sext (wi::to_wide (arg), prec);
   14493       if (wi::neg_p (w))
   14494 	return 2;
   14495       else
   14496 	return 1;
   14497     }
   14498   while (CONVERT_EXPR_P (arg)
   14499 	 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
   14500 	 && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
   14501     {
   14502       arg = TREE_OPERAND (arg, 0);
   14503       /* Narrower value zero extended into wider type
   14504 	 will always result in positive values.  */
   14505       if (TYPE_UNSIGNED (TREE_TYPE (arg))
   14506 	  && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
   14507 	return 1;
   14508       prec = TYPE_PRECISION (TREE_TYPE (arg));
   14509       if (++cnt > 30)
   14510 	return 3;
   14511     }
   14512 
   14513   if (TREE_CODE (arg) != SSA_NAME)
   14514     return 3;
   14515   value_range r;
   14516   while (!get_global_range_query ()->range_of_expr (r, arg)
   14517 	 || r.undefined_p () || r.varying_p ())
   14518     {
   14519       gimple *g = SSA_NAME_DEF_STMT (arg);
   14520       if (is_gimple_assign (g)
   14521 	  && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
   14522 	{
   14523 	  tree t = gimple_assign_rhs1 (g);
   14524 	  if (INTEGRAL_TYPE_P (TREE_TYPE (t))
   14525 	      && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
   14526 	    {
   14527 	      if (TYPE_UNSIGNED (TREE_TYPE (t))
   14528 		  && TYPE_PRECISION (TREE_TYPE (t)) < prec)
   14529 		return 1;
   14530 	      prec = TYPE_PRECISION (TREE_TYPE (t));
   14531 	      arg = t;
   14532 	      if (++cnt > 30)
   14533 		return 3;
   14534 	      continue;
   14535 	    }
   14536 	}
   14537       return 3;
   14538     }
   14539   if (TYPE_UNSIGNED (TREE_TYPE (arg)))
   14540     {
   14541       /* For unsigned values, the "positive" range comes
   14542 	 below the "negative" range.  */
   14543       if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
   14544 	return 1;
   14545       if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
   14546 	return 2;
   14547     }
   14548   else
   14549     {
   14550       if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
   14551 	return 1;
   14552       if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
   14553 	return 2;
   14554     }
   14555   return 3;
   14556 }
   14557 
   14558 
   14559 
   14560 
   14561 /* Return true if ARG is marked with the nonnull attribute in the
   14562    current function signature.  */
   14563 
   14564 bool
   14565 nonnull_arg_p (const_tree arg)
   14566 {
   14567   tree t, attrs, fntype;
   14568   unsigned HOST_WIDE_INT arg_num;
   14569 
   14570   gcc_assert (TREE_CODE (arg) == PARM_DECL
   14571 	      && (POINTER_TYPE_P (TREE_TYPE (arg))
   14572 		  || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
   14573 
   14574   /* The static chain decl is always non null.  */
   14575   if (arg == cfun->static_chain_decl)
   14576     return true;
   14577 
   14578   /* THIS argument of method is always non-NULL.  */
   14579   if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
   14580       && arg == DECL_ARGUMENTS (cfun->decl)
   14581       && flag_delete_null_pointer_checks)
   14582     return true;
   14583 
   14584   /* Values passed by reference are always non-NULL.  */
   14585   if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
   14586       && flag_delete_null_pointer_checks)
   14587     return true;
   14588 
   14589   fntype = TREE_TYPE (cfun->decl);
   14590   for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
   14591     {
   14592       attrs = lookup_attribute ("nonnull", attrs);
   14593 
   14594       /* If "nonnull" wasn't specified, we know nothing about the argument.  */
   14595       if (attrs == NULL_TREE)
   14596 	return false;
   14597 
   14598       /* If "nonnull" applies to all the arguments, then ARG is non-null.  */
   14599       if (TREE_VALUE (attrs) == NULL_TREE)
   14600 	return true;
   14601 
   14602       /* Get the position number for ARG in the function signature.  */
   14603       for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
   14604 	   t;
   14605 	   t = DECL_CHAIN (t), arg_num++)
   14606 	{
   14607 	  if (t == arg)
   14608 	    break;
   14609 	}
   14610 
   14611       gcc_assert (t == arg);
   14612 
   14613       /* Now see if ARG_NUM is mentioned in the nonnull list.  */
   14614       for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
   14615 	{
   14616 	  if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
   14617 	    return true;
   14618 	}
   14619     }
   14620 
   14621   return false;
   14622 }
   14623 
   14624 /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
   14625    information.  */
   14626 
   14627 location_t
   14628 set_block (location_t loc, tree block)
   14629 {
   14630   location_t pure_loc = get_pure_location (loc);
   14631   source_range src_range = get_range_from_loc (line_table, loc);
   14632   unsigned discriminator = get_discriminator_from_loc (line_table, loc);
   14633   return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
   14634 						 discriminator);
   14635 }
   14636 
   14637 location_t
   14638 set_source_range (tree expr, location_t start, location_t finish)
   14639 {
   14640   source_range src_range;
   14641   src_range.m_start = start;
   14642   src_range.m_finish = finish;
   14643   return set_source_range (expr, src_range);
   14644 }
   14645 
   14646 location_t
   14647 set_source_range (tree expr, source_range src_range)
   14648 {
   14649   if (!EXPR_P (expr))
   14650     return UNKNOWN_LOCATION;
   14651 
   14652   location_t expr_location = EXPR_LOCATION (expr);
   14653   location_t pure_loc = get_pure_location (expr_location);
   14654   unsigned discriminator = get_discriminator_from_loc (expr_location);
   14655   location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
   14656 							     src_range,
   14657 							     nullptr,
   14658 							     discriminator);
   14659   SET_EXPR_LOCATION (expr, adhoc);
   14660   return adhoc;
   14661 }
   14662 
   14663 /* Return EXPR, potentially wrapped with a node expression LOC,
   14664    if !CAN_HAVE_LOCATION_P (expr).
   14665 
   14666    NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
   14667    VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
   14668 
   14669    Wrapper nodes can be identified using location_wrapper_p.  */
   14670 
   14671 tree
   14672 maybe_wrap_with_location (tree expr, location_t loc)
   14673 {
   14674   if (expr == NULL)
   14675     return NULL;
   14676   if (loc == UNKNOWN_LOCATION)
   14677     return expr;
   14678   if (CAN_HAVE_LOCATION_P (expr))
   14679     return expr;
   14680   /* We should only be adding wrappers for constants and for decls,
   14681      or for some exceptional tree nodes (e.g. BASELINK in the C++ FE).  */
   14682   gcc_assert (CONSTANT_CLASS_P (expr)
   14683 	      || DECL_P (expr)
   14684 	      || EXCEPTIONAL_CLASS_P (expr));
   14685 
   14686   /* For now, don't add wrappers to exceptional tree nodes, to minimize
   14687      any impact of the wrapper nodes.  */
   14688   if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
   14689     return expr;
   14690 
   14691   /* Compiler-generated temporary variables don't need a wrapper.  */
   14692   if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
   14693     return expr;
   14694 
   14695   /* If any auto_suppress_location_wrappers are active, don't create
   14696      wrappers.  */
   14697   if (suppress_location_wrappers > 0)
   14698     return expr;
   14699 
   14700   tree_code code
   14701     = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
   14702 	|| (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
   14703        ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
   14704   tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
   14705   /* Mark this node as being a wrapper.  */
   14706   EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
   14707   return wrapper;
   14708 }
   14709 
   14710 int suppress_location_wrappers;
   14711 
   14712 /* Return the name of combined function FN, for debugging purposes.  */
   14713 
   14714 const char *
   14715 combined_fn_name (combined_fn fn)
   14716 {
   14717   if (builtin_fn_p (fn))
   14718     {
   14719       tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
   14720       return IDENTIFIER_POINTER (DECL_NAME (fndecl));
   14721     }
   14722   else
   14723     return internal_fn_name (as_internal_fn (fn));
   14724 }
   14725 
   14726 /* Return a bitmap with a bit set corresponding to each argument in
   14727    a function call type FNTYPE declared with attribute nonnull,
   14728    or null if none of the function's argument are nonnull.  The caller
   14729    must free the bitmap.  */
   14730 
   14731 bitmap
   14732 get_nonnull_args (const_tree fntype)
   14733 {
   14734   if (fntype == NULL_TREE)
   14735     return NULL;
   14736 
   14737   bitmap argmap = NULL;
   14738   if (TREE_CODE (fntype) == METHOD_TYPE)
   14739     {
   14740       /* The this pointer in C++ non-static member functions is
   14741 	 implicitly nonnull whether or not it's declared as such.  */
   14742       argmap = BITMAP_ALLOC (NULL);
   14743       bitmap_set_bit (argmap, 0);
   14744     }
   14745 
   14746   tree attrs = TYPE_ATTRIBUTES (fntype);
   14747   if (!attrs)
   14748     return argmap;
   14749 
   14750   /* A function declaration can specify multiple attribute nonnull,
   14751      each with zero or more arguments.  The loop below creates a bitmap
   14752      representing a union of all the arguments.  An empty (but non-null)
   14753      bitmap means that all arguments have been declaraed nonnull.  */
   14754   for ( ; attrs; attrs = TREE_CHAIN (attrs))
   14755     {
   14756       attrs = lookup_attribute ("nonnull", attrs);
   14757       if (!attrs)
   14758 	break;
   14759 
   14760       if (!argmap)
   14761 	argmap = BITMAP_ALLOC (NULL);
   14762 
   14763       if (!TREE_VALUE (attrs))
   14764 	{
   14765 	  /* Clear the bitmap in case a previous attribute nonnull
   14766 	     set it and this one overrides it for all arguments.  */
   14767 	  bitmap_clear (argmap);
   14768 	  return argmap;
   14769 	}
   14770 
   14771       /* Iterate over the indices of the format arguments declared nonnull
   14772 	 and set a bit for each.  */
   14773       for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
   14774 	{
   14775 	  unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
   14776 	  bitmap_set_bit (argmap, val);
   14777 	}
   14778     }
   14779 
   14780   return argmap;
   14781 }
   14782 
   14783 /* Returns true if TYPE is a type where it and all of its subobjects
   14784    (recursively) are of structure, union, or array type.  */
   14785 
   14786 bool
   14787 is_empty_type (const_tree type)
   14788 {
   14789   if (RECORD_OR_UNION_TYPE_P (type))
   14790     {
   14791       for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   14792 	if (TREE_CODE (field) == FIELD_DECL
   14793 	    && !DECL_PADDING_P (field)
   14794 	    && !is_empty_type (TREE_TYPE (field)))
   14795 	  return false;
   14796       return true;
   14797     }
   14798   else if (TREE_CODE (type) == ARRAY_TYPE)
   14799     return (integer_minus_onep (array_type_nelts (type))
   14800 	    || TYPE_DOMAIN (type) == NULL_TREE
   14801 	    || is_empty_type (TREE_TYPE (type)));
   14802   return false;
   14803 }
   14804 
   14805 /* Implement TARGET_EMPTY_RECORD_P.  Return true if TYPE is an empty type
   14806    that shouldn't be passed via stack.  */
   14807 
   14808 bool
   14809 default_is_empty_record (const_tree type)
   14810 {
   14811   if (!abi_version_at_least (12))
   14812     return false;
   14813 
   14814   if (type == error_mark_node)
   14815     return false;
   14816 
   14817   if (TREE_ADDRESSABLE (type))
   14818     return false;
   14819 
   14820   return is_empty_type (TYPE_MAIN_VARIANT (type));
   14821 }
   14822 
   14823 /* Determine whether TYPE is a structure with a flexible array member,
   14824    or a union containing such a structure (possibly recursively).  */
   14825 
   14826 bool
   14827 flexible_array_type_p (const_tree type)
   14828 {
   14829   tree x, last;
   14830   switch (TREE_CODE (type))
   14831     {
   14832     case RECORD_TYPE:
   14833       last = NULL_TREE;
   14834       for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
   14835 	if (TREE_CODE (x) == FIELD_DECL)
   14836 	  last = x;
   14837       if (last == NULL_TREE)
   14838 	return false;
   14839       if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
   14840 	  && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
   14841 	  && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
   14842 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
   14843 	return true;
   14844       return false;
   14845     case UNION_TYPE:
   14846       for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
   14847 	{
   14848 	  if (TREE_CODE (x) == FIELD_DECL
   14849 	      && flexible_array_type_p (TREE_TYPE (x)))
   14850 	    return true;
   14851 	}
   14852       return false;
   14853     default:
   14854       return false;
   14855   }
   14856 }
   14857 
   14858 /* Like int_size_in_bytes, but handle empty records specially.  */
   14859 
   14860 HOST_WIDE_INT
   14861 arg_int_size_in_bytes (const_tree type)
   14862 {
   14863   return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
   14864 }
   14865 
   14866 /* Like size_in_bytes, but handle empty records specially.  */
   14867 
   14868 tree
   14869 arg_size_in_bytes (const_tree type)
   14870 {
   14871   return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
   14872 }
   14873 
   14874 /* Return true if an expression with CODE has to have the same result type as
   14875    its first operand.  */
   14876 
   14877 bool
   14878 expr_type_first_operand_type_p (tree_code code)
   14879 {
   14880   switch (code)
   14881     {
   14882     case NEGATE_EXPR:
   14883     case ABS_EXPR:
   14884     case BIT_NOT_EXPR:
   14885     case PAREN_EXPR:
   14886     case CONJ_EXPR:
   14887 
   14888     case PLUS_EXPR:
   14889     case MINUS_EXPR:
   14890     case MULT_EXPR:
   14891     case TRUNC_DIV_EXPR:
   14892     case CEIL_DIV_EXPR:
   14893     case FLOOR_DIV_EXPR:
   14894     case ROUND_DIV_EXPR:
   14895     case TRUNC_MOD_EXPR:
   14896     case CEIL_MOD_EXPR:
   14897     case FLOOR_MOD_EXPR:
   14898     case ROUND_MOD_EXPR:
   14899     case RDIV_EXPR:
   14900     case EXACT_DIV_EXPR:
   14901     case MIN_EXPR:
   14902     case MAX_EXPR:
   14903     case BIT_IOR_EXPR:
   14904     case BIT_XOR_EXPR:
   14905     case BIT_AND_EXPR:
   14906 
   14907     case LSHIFT_EXPR:
   14908     case RSHIFT_EXPR:
   14909     case LROTATE_EXPR:
   14910     case RROTATE_EXPR:
   14911       return true;
   14912 
   14913     default:
   14914       return false;
   14915     }
   14916 }
   14917 
   14918 /* Return a typenode for the "standard" C type with a given name.  */
   14919 tree
   14920 get_typenode_from_name (const char *name)
   14921 {
   14922   if (name == NULL || *name == '\0')
   14923     return NULL_TREE;
   14924 
   14925   if (strcmp (name, "char") == 0)
   14926     return char_type_node;
   14927   if (strcmp (name, "unsigned char") == 0)
   14928     return unsigned_char_type_node;
   14929   if (strcmp (name, "signed char") == 0)
   14930     return signed_char_type_node;
   14931 
   14932   if (strcmp (name, "short int") == 0)
   14933     return short_integer_type_node;
   14934   if (strcmp (name, "short unsigned int") == 0)
   14935     return short_unsigned_type_node;
   14936 
   14937   if (strcmp (name, "int") == 0)
   14938     return integer_type_node;
   14939   if (strcmp (name, "unsigned int") == 0)
   14940     return unsigned_type_node;
   14941 
   14942   if (strcmp (name, "long int") == 0)
   14943     return long_integer_type_node;
   14944   if (strcmp (name, "long unsigned int") == 0)
   14945     return long_unsigned_type_node;
   14946 
   14947   if (strcmp (name, "long long int") == 0)
   14948     return long_long_integer_type_node;
   14949   if (strcmp (name, "long long unsigned int") == 0)
   14950     return long_long_unsigned_type_node;
   14951 
   14952   gcc_unreachable ();
   14953 }
   14954 
   14955 /* List of pointer types used to declare builtins before we have seen their
   14956    real declaration.
   14957 
   14958    Keep the size up to date in tree.h !  */
   14959 const builtin_structptr_type builtin_structptr_types[6] =
   14960 {
   14961   { fileptr_type_node, ptr_type_node, "FILE" },
   14962   { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
   14963   { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
   14964   { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
   14965   { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
   14966   { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
   14967 };
   14968 
   14969 /* Return the maximum object size.  */
   14970 
   14971 tree
   14972 max_object_size (void)
   14973 {
   14974   /* To do: Make this a configurable parameter.  */
   14975   return TYPE_MAX_VALUE (ptrdiff_type_node);
   14976 }
   14977 
   14978 /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
   14979    parameter default to false and that weeds out error_mark_node.  */
   14980 
   14981 bool
   14982 verify_type_context (location_t loc, type_context_kind context,
   14983 		     const_tree type, bool silent_p)
   14984 {
   14985   if (type == error_mark_node)
   14986     return true;
   14987 
   14988   gcc_assert (TYPE_P (type));
   14989   return (!targetm.verify_type_context
   14990 	  || targetm.verify_type_context (loc, context, type, silent_p));
   14991 }
   14992 
   14993 /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
   14994    delete operators.  Return false if they may or may not name such
   14995    a pair and, when nonnull, set *PCERTAIN to true if they certainly
   14996    do not.  */
   14997 
   14998 bool
   14999 valid_new_delete_pair_p (tree new_asm, tree delete_asm,
   15000 			 bool *pcertain /* = NULL */)
   15001 {
   15002   bool certain;
   15003   if (!pcertain)
   15004     pcertain = &certain;
   15005 
   15006   const char *new_name = IDENTIFIER_POINTER (new_asm);
   15007   const char *delete_name = IDENTIFIER_POINTER (delete_asm);
   15008   unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
   15009   unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
   15010 
   15011   /* The following failures are due to invalid names so they're not
   15012      considered certain mismatches.  */
   15013   *pcertain = false;
   15014 
   15015   if (new_len < 5 || delete_len < 6)
   15016     return false;
   15017   if (new_name[0] == '_')
   15018     ++new_name, --new_len;
   15019   if (new_name[0] == '_')
   15020     ++new_name, --new_len;
   15021   if (delete_name[0] == '_')
   15022     ++delete_name, --delete_len;
   15023   if (delete_name[0] == '_')
   15024     ++delete_name, --delete_len;
   15025   if (new_len < 4 || delete_len < 5)
   15026     return false;
   15027 
   15028   /* The following failures are due to names of user-defined operators
   15029      so they're also not considered certain mismatches.  */
   15030 
   15031   /* *_len is now just the length after initial underscores.  */
   15032   if (new_name[0] != 'Z' || new_name[1] != 'n')
   15033     return false;
   15034   if (delete_name[0] != 'Z' || delete_name[1] != 'd')
   15035     return false;
   15036 
   15037   /* The following failures are certain mismatches.  */
   15038   *pcertain = true;
   15039 
   15040   /* _Znw must match _Zdl, _Zna must match _Zda.  */
   15041   if ((new_name[2] != 'w' || delete_name[2] != 'l')
   15042       && (new_name[2] != 'a' || delete_name[2] != 'a'))
   15043     return false;
   15044   /* 'j', 'm' and 'y' correspond to size_t.  */
   15045   if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
   15046     return false;
   15047   if (delete_name[3] != 'P' || delete_name[4] != 'v')
   15048     return false;
   15049   if (new_len == 4
   15050       || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
   15051     {
   15052       /* _ZnXY or _ZnXYRKSt9nothrow_t matches
   15053 	 _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t.  */
   15054       if (delete_len == 5)
   15055 	return true;
   15056       if (delete_len == 6 && delete_name[5] == new_name[3])
   15057 	return true;
   15058       if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
   15059 	return true;
   15060     }
   15061   else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
   15062 	   || (new_len == 33
   15063 	       && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
   15064     {
   15065       /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
   15066 	 _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or  or
   15067 	 _ZdXPvSt11align_val_tRKSt9nothrow_t.  */
   15068       if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
   15069 	return true;
   15070       if (delete_len == 21
   15071 	  && delete_name[5] == new_name[3]
   15072 	  && !memcmp (delete_name + 6, "St11align_val_t", 15))
   15073 	return true;
   15074       if (delete_len == 34
   15075 	  && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
   15076 	return true;
   15077     }
   15078 
   15079   /* The negative result is conservative.  */
   15080   *pcertain = false;
   15081   return false;
   15082 }
   15083 
   15084 /* Return the zero-based number corresponding to the argument being
   15085    deallocated if FNDECL is a deallocation function or an out-of-bounds
   15086    value if it isn't.  */
   15087 
   15088 unsigned
   15089 fndecl_dealloc_argno (tree fndecl)
   15090 {
   15091   /* A call to operator delete isn't recognized as one to a built-in.  */
   15092   if (DECL_IS_OPERATOR_DELETE_P (fndecl))
   15093     {
   15094       if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
   15095 	return 0;
   15096 
   15097       /* Avoid placement delete that's not been inlined.  */
   15098       tree fname = DECL_ASSEMBLER_NAME (fndecl);
   15099       if (id_equal (fname, "_ZdlPvS_")       // ordinary form
   15100 	  || id_equal (fname, "_ZdaPvS_"))   // array form
   15101 	return UINT_MAX;
   15102       return 0;
   15103     }
   15104 
   15105   /* TODO: Handle user-defined functions with attribute malloc?  Handle
   15106      known non-built-ins like fopen?  */
   15107   if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
   15108     {
   15109       switch (DECL_FUNCTION_CODE (fndecl))
   15110 	{
   15111 	case BUILT_IN_FREE:
   15112 	case BUILT_IN_REALLOC:
   15113 	case BUILT_IN_GOMP_FREE:
   15114 	case BUILT_IN_GOMP_REALLOC:
   15115 	  return 0;
   15116 	default:
   15117 	  break;
   15118 	}
   15119       return UINT_MAX;
   15120     }
   15121 
   15122   tree attrs = DECL_ATTRIBUTES (fndecl);
   15123   if (!attrs)
   15124     return UINT_MAX;
   15125 
   15126   for (tree atfree = attrs;
   15127        (atfree = lookup_attribute ("*dealloc", atfree));
   15128        atfree = TREE_CHAIN (atfree))
   15129     {
   15130       tree alloc = TREE_VALUE (atfree);
   15131       if (!alloc)
   15132 	continue;
   15133 
   15134       tree pos = TREE_CHAIN (alloc);
   15135       if (!pos)
   15136 	return 0;
   15137 
   15138       pos = TREE_VALUE (pos);
   15139       return TREE_INT_CST_LOW (pos) - 1;
   15140     }
   15141 
   15142   return UINT_MAX;
   15143 }
   15144 
   15145 /* If EXPR refers to a character array or pointer declared attribute
   15146    nonstring, return a decl for that array or pointer and set *REF
   15147    to the referenced enclosing object or pointer.  Otherwise return
   15148    null.  */
   15149 
   15150 tree
   15151 get_attr_nonstring_decl (tree expr, tree *ref)
   15152 {
   15153   tree decl = expr;
   15154   tree var = NULL_TREE;
   15155   if (TREE_CODE (decl) == SSA_NAME)
   15156     {
   15157       gimple *def = SSA_NAME_DEF_STMT (decl);
   15158 
   15159       if (is_gimple_assign (def))
   15160 	{
   15161 	  tree_code code = gimple_assign_rhs_code (def);
   15162 	  if (code == ADDR_EXPR
   15163 	      || code == COMPONENT_REF
   15164 	      || code == VAR_DECL)
   15165 	    decl = gimple_assign_rhs1 (def);
   15166 	}
   15167       else
   15168 	var = SSA_NAME_VAR (decl);
   15169     }
   15170 
   15171   if (TREE_CODE (decl) == ADDR_EXPR)
   15172     decl = TREE_OPERAND (decl, 0);
   15173 
   15174   /* To simplify calling code, store the referenced DECL regardless of
   15175      the attribute determined below, but avoid storing the SSA_NAME_VAR
   15176      obtained above (it's not useful for dataflow purposes).  */
   15177   if (ref)
   15178     *ref = decl;
   15179 
   15180   /* Use the SSA_NAME_VAR that was determined above to see if it's
   15181      declared nonstring.  Otherwise drill down into the referenced
   15182      DECL.  */
   15183   if (var)
   15184     decl = var;
   15185   else if (TREE_CODE (decl) == ARRAY_REF)
   15186     decl = TREE_OPERAND (decl, 0);
   15187   else if (TREE_CODE (decl) == COMPONENT_REF)
   15188     decl = TREE_OPERAND (decl, 1);
   15189   else if (TREE_CODE (decl) == MEM_REF)
   15190     return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
   15191 
   15192   if (DECL_P (decl)
   15193       && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
   15194     return decl;
   15195 
   15196   return NULL_TREE;
   15197 }
   15198 
   15199 /* Return length of attribute names string,
   15200    if arglist chain > 1, -1 otherwise.  */
   15201 
   15202 int
   15203 get_target_clone_attr_len (tree arglist)
   15204 {
   15205   tree arg;
   15206   int str_len_sum = 0;
   15207   int argnum = 0;
   15208 
   15209   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
   15210     {
   15211       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
   15212       size_t len = strlen (str);
   15213       str_len_sum += len + 1;
   15214       for (const char *p = strchr (str, ','); p; p = strchr (p + 1, ','))
   15215 	argnum++;
   15216       argnum++;
   15217     }
   15218   if (argnum <= 1)
   15219     return -1;
   15220   return str_len_sum;
   15221 }
   15222 
   15223 void
   15224 tree_cc_finalize (void)
   15225 {
   15226   clear_nonstandard_integer_type_cache ();
   15227   vec_free (bitint_type_cache);
   15228 }
   15229 
   15230 #if CHECKING_P
   15231 
   15232 namespace selftest {
   15233 
   15234 /* Selftests for tree.  */
   15235 
   15236 /* Verify that integer constants are sane.  */
   15237 
   15238 static void
   15239 test_integer_constants ()
   15240 {
   15241   ASSERT_TRUE (integer_type_node != NULL);
   15242   ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
   15243 
   15244   tree type = integer_type_node;
   15245 
   15246   tree zero = build_zero_cst (type);
   15247   ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
   15248   ASSERT_EQ (type, TREE_TYPE (zero));
   15249 
   15250   tree one = build_int_cst (type, 1);
   15251   ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
   15252   ASSERT_EQ (type, TREE_TYPE (zero));
   15253 }
   15254 
   15255 /* Verify identifiers.  */
   15256 
   15257 static void
   15258 test_identifiers ()
   15259 {
   15260   tree identifier = get_identifier ("foo");
   15261   ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
   15262   ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
   15263 }
   15264 
   15265 /* Verify LABEL_DECL.  */
   15266 
   15267 static void
   15268 test_labels ()
   15269 {
   15270   tree identifier = get_identifier ("err");
   15271   tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
   15272 				identifier, void_type_node);
   15273   ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
   15274   ASSERT_FALSE (FORCED_LABEL (label_decl));
   15275 }
   15276 
   15277 /* Return a new VECTOR_CST node whose type is TYPE and whose values
   15278    are given by VALS.  */
   15279 
   15280 static tree
   15281 build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
   15282 {
   15283   gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
   15284   tree_vector_builder builder (type, vals.length (), 1);
   15285   builder.splice (vals);
   15286   return builder.build ();
   15287 }
   15288 
   15289 /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED.  */
   15290 
   15291 static void
   15292 check_vector_cst (const vec<tree> &expected, tree actual)
   15293 {
   15294   ASSERT_KNOWN_EQ (expected.length (),
   15295 		   TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
   15296   for (unsigned int i = 0; i < expected.length (); ++i)
   15297     ASSERT_EQ (wi::to_wide (expected[i]),
   15298 	       wi::to_wide (vector_cst_elt (actual, i)));
   15299 }
   15300 
   15301 /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
   15302    and that its elements match EXPECTED.  */
   15303 
   15304 static void
   15305 check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
   15306 			    unsigned int npatterns)
   15307 {
   15308   ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
   15309   ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
   15310   ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
   15311   ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
   15312   ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
   15313   check_vector_cst (expected, actual);
   15314 }
   15315 
   15316 /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
   15317    and NPATTERNS background elements, and that its elements match
   15318    EXPECTED.  */
   15319 
   15320 static void
   15321 check_vector_cst_fill (const vec<tree> &expected, tree actual,
   15322 		       unsigned int npatterns)
   15323 {
   15324   ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
   15325   ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
   15326   ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
   15327   ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
   15328   ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
   15329   check_vector_cst (expected, actual);
   15330 }
   15331 
   15332 /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
   15333    and that its elements match EXPECTED.  */
   15334 
   15335 static void
   15336 check_vector_cst_stepped (const vec<tree> &expected, tree actual,
   15337 			  unsigned int npatterns)
   15338 {
   15339   ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
   15340   ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
   15341   ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
   15342   ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
   15343   ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
   15344   check_vector_cst (expected, actual);
   15345 }
   15346 
   15347 /* Test the creation of VECTOR_CSTs.  */
   15348 
   15349 static void
   15350 test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
   15351 {
   15352   auto_vec<tree, 8> elements (8);
   15353   elements.quick_grow (8);
   15354   tree element_type = build_nonstandard_integer_type (16, true);
   15355   tree vector_type = build_vector_type (element_type, 8);
   15356 
   15357   /* Test a simple linear series with a base of 0 and a step of 1:
   15358      { 0, 1, 2, 3, 4, 5, 6, 7 }.  */
   15359   for (unsigned int i = 0; i < 8; ++i)
   15360     elements[i] = build_int_cst (element_type, i);
   15361   tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15362   check_vector_cst_stepped (elements, vector, 1);
   15363 
   15364   /* Try the same with the first element replaced by 100:
   15365      { 100, 1, 2, 3, 4, 5, 6, 7 }.  */
   15366   elements[0] = build_int_cst (element_type, 100);
   15367   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15368   check_vector_cst_stepped (elements, vector, 1);
   15369 
   15370   /* Try a series that wraps around.
   15371      { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }.  */
   15372   for (unsigned int i = 1; i < 8; ++i)
   15373     elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
   15374   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15375   check_vector_cst_stepped (elements, vector, 1);
   15376 
   15377   /* Try a downward series:
   15378      { 100, 79, 78, 77, 76, 75, 75, 73 }.  */
   15379   for (unsigned int i = 1; i < 8; ++i)
   15380     elements[i] = build_int_cst (element_type, 80 - i);
   15381   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15382   check_vector_cst_stepped (elements, vector, 1);
   15383 
   15384   /* Try two interleaved series with different bases and steps:
   15385      { 100, 53, 66, 206, 62, 212, 58, 218 }.  */
   15386   elements[1] = build_int_cst (element_type, 53);
   15387   for (unsigned int i = 2; i < 8; i += 2)
   15388     {
   15389       elements[i] = build_int_cst (element_type, 70 - i * 2);
   15390       elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
   15391     }
   15392   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15393   check_vector_cst_stepped (elements, vector, 2);
   15394 
   15395   /* Try a duplicated value:
   15396      { 100, 100, 100, 100, 100, 100, 100, 100 }.  */
   15397   for (unsigned int i = 1; i < 8; ++i)
   15398     elements[i] = elements[0];
   15399   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15400   check_vector_cst_duplicate (elements, vector, 1);
   15401 
   15402   /* Try an interleaved duplicated value:
   15403      { 100, 55, 100, 55, 100, 55, 100, 55 }.  */
   15404   elements[1] = build_int_cst (element_type, 55);
   15405   for (unsigned int i = 2; i < 8; ++i)
   15406     elements[i] = elements[i - 2];
   15407   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15408   check_vector_cst_duplicate (elements, vector, 2);
   15409 
   15410   /* Try a duplicated value with 2 exceptions
   15411      { 41, 97, 100, 55, 100, 55, 100, 55 }.  */
   15412   elements[0] = build_int_cst (element_type, 41);
   15413   elements[1] = build_int_cst (element_type, 97);
   15414   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15415   check_vector_cst_fill (elements, vector, 2);
   15416 
   15417   /* Try with and without a step
   15418      { 41, 97, 100, 21, 100, 35, 100, 49 }.  */
   15419   for (unsigned int i = 3; i < 8; i += 2)
   15420     elements[i] = build_int_cst (element_type, i * 7);
   15421   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15422   check_vector_cst_stepped (elements, vector, 2);
   15423 
   15424   /* Try a fully-general constant:
   15425      { 41, 97, 100, 21, 100, 9990, 100, 49 }.  */
   15426   elements[5] = build_int_cst (element_type, 9990);
   15427   vector = build_vector (vector_type, elements PASS_MEM_STAT);
   15428   check_vector_cst_fill (elements, vector, 4);
   15429 }
   15430 
   15431 /* Verify that STRIP_NOPS (NODE) is EXPECTED.
   15432    Helper function for test_location_wrappers, to deal with STRIP_NOPS
   15433    modifying its argument in-place.  */
   15434 
   15435 static void
   15436 check_strip_nops (tree node, tree expected)
   15437 {
   15438   STRIP_NOPS (node);
   15439   ASSERT_EQ (expected, node);
   15440 }
   15441 
   15442 /* Verify location wrappers.  */
   15443 
   15444 static void
   15445 test_location_wrappers ()
   15446 {
   15447   location_t loc = BUILTINS_LOCATION;
   15448 
   15449   ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
   15450 
   15451   /* Wrapping a constant.  */
   15452   tree int_cst = build_int_cst (integer_type_node, 42);
   15453   ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
   15454   ASSERT_FALSE (location_wrapper_p (int_cst));
   15455 
   15456   tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
   15457   ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
   15458   ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
   15459   ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
   15460 
   15461   /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION.  */
   15462   ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
   15463 
   15464   /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P.  */
   15465   tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
   15466   ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
   15467   ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
   15468 
   15469   /* Wrapping a STRING_CST.  */
   15470   tree string_cst = build_string (4, "foo");
   15471   ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
   15472   ASSERT_FALSE (location_wrapper_p (string_cst));
   15473 
   15474   tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
   15475   ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
   15476   ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
   15477   ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
   15478   ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
   15479 
   15480 
   15481   /* Wrapping a variable.  */
   15482   tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
   15483 			     get_identifier ("some_int_var"),
   15484 			     integer_type_node);
   15485   ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
   15486   ASSERT_FALSE (location_wrapper_p (int_var));
   15487 
   15488   tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
   15489   ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
   15490   ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
   15491   ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
   15492 
   15493   /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
   15494      wrapper.  */
   15495   tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
   15496   ASSERT_FALSE (location_wrapper_p (r_cast));
   15497   ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
   15498 
   15499   /* Verify that STRIP_NOPS removes wrappers.  */
   15500   check_strip_nops (wrapped_int_cst, int_cst);
   15501   check_strip_nops (wrapped_string_cst, string_cst);
   15502   check_strip_nops (wrapped_int_var, int_var);
   15503 }
   15504 
   15505 /* Test various tree predicates.  Verify that location wrappers don't
   15506    affect the results.  */
   15507 
   15508 static void
   15509 test_predicates ()
   15510 {
   15511   /* Build various constants and wrappers around them.  */
   15512 
   15513   location_t loc = BUILTINS_LOCATION;
   15514 
   15515   tree i_0 = build_int_cst (integer_type_node, 0);
   15516   tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
   15517 
   15518   tree i_1 = build_int_cst (integer_type_node, 1);
   15519   tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
   15520 
   15521   tree i_m1 = build_int_cst (integer_type_node, -1);
   15522   tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
   15523 
   15524   tree f_0 = build_real_from_int_cst (float_type_node, i_0);
   15525   tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
   15526   tree f_1 = build_real_from_int_cst (float_type_node, i_1);
   15527   tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
   15528   tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
   15529   tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
   15530 
   15531   tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
   15532   tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
   15533   tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
   15534 
   15535   tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
   15536   tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
   15537   tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
   15538 
   15539   /* TODO: vector constants.  */
   15540 
   15541   /* Test integer_onep.  */
   15542   ASSERT_FALSE (integer_onep (i_0));
   15543   ASSERT_FALSE (integer_onep (wr_i_0));
   15544   ASSERT_TRUE (integer_onep (i_1));
   15545   ASSERT_TRUE (integer_onep (wr_i_1));
   15546   ASSERT_FALSE (integer_onep (i_m1));
   15547   ASSERT_FALSE (integer_onep (wr_i_m1));
   15548   ASSERT_FALSE (integer_onep (f_0));
   15549   ASSERT_FALSE (integer_onep (wr_f_0));
   15550   ASSERT_FALSE (integer_onep (f_1));
   15551   ASSERT_FALSE (integer_onep (wr_f_1));
   15552   ASSERT_FALSE (integer_onep (f_m1));
   15553   ASSERT_FALSE (integer_onep (wr_f_m1));
   15554   ASSERT_FALSE (integer_onep (c_i_0));
   15555   ASSERT_TRUE (integer_onep (c_i_1));
   15556   ASSERT_FALSE (integer_onep (c_i_m1));
   15557   ASSERT_FALSE (integer_onep (c_f_0));
   15558   ASSERT_FALSE (integer_onep (c_f_1));
   15559   ASSERT_FALSE (integer_onep (c_f_m1));
   15560 
   15561   /* Test integer_zerop.  */
   15562   ASSERT_TRUE (integer_zerop (i_0));
   15563   ASSERT_TRUE (integer_zerop (wr_i_0));
   15564   ASSERT_FALSE (integer_zerop (i_1));
   15565   ASSERT_FALSE (integer_zerop (wr_i_1));
   15566   ASSERT_FALSE (integer_zerop (i_m1));
   15567   ASSERT_FALSE (integer_zerop (wr_i_m1));
   15568   ASSERT_FALSE (integer_zerop (f_0));
   15569   ASSERT_FALSE (integer_zerop (wr_f_0));
   15570   ASSERT_FALSE (integer_zerop (f_1));
   15571   ASSERT_FALSE (integer_zerop (wr_f_1));
   15572   ASSERT_FALSE (integer_zerop (f_m1));
   15573   ASSERT_FALSE (integer_zerop (wr_f_m1));
   15574   ASSERT_TRUE (integer_zerop (c_i_0));
   15575   ASSERT_FALSE (integer_zerop (c_i_1));
   15576   ASSERT_FALSE (integer_zerop (c_i_m1));
   15577   ASSERT_FALSE (integer_zerop (c_f_0));
   15578   ASSERT_FALSE (integer_zerop (c_f_1));
   15579   ASSERT_FALSE (integer_zerop (c_f_m1));
   15580 
   15581   /* Test integer_all_onesp.  */
   15582   ASSERT_FALSE (integer_all_onesp (i_0));
   15583   ASSERT_FALSE (integer_all_onesp (wr_i_0));
   15584   ASSERT_FALSE (integer_all_onesp (i_1));
   15585   ASSERT_FALSE (integer_all_onesp (wr_i_1));
   15586   ASSERT_TRUE (integer_all_onesp (i_m1));
   15587   ASSERT_TRUE (integer_all_onesp (wr_i_m1));
   15588   ASSERT_FALSE (integer_all_onesp (f_0));
   15589   ASSERT_FALSE (integer_all_onesp (wr_f_0));
   15590   ASSERT_FALSE (integer_all_onesp (f_1));
   15591   ASSERT_FALSE (integer_all_onesp (wr_f_1));
   15592   ASSERT_FALSE (integer_all_onesp (f_m1));
   15593   ASSERT_FALSE (integer_all_onesp (wr_f_m1));
   15594   ASSERT_FALSE (integer_all_onesp (c_i_0));
   15595   ASSERT_FALSE (integer_all_onesp (c_i_1));
   15596   ASSERT_FALSE (integer_all_onesp (c_i_m1));
   15597   ASSERT_FALSE (integer_all_onesp (c_f_0));
   15598   ASSERT_FALSE (integer_all_onesp (c_f_1));
   15599   ASSERT_FALSE (integer_all_onesp (c_f_m1));
   15600 
   15601   /* Test integer_minus_onep.  */
   15602   ASSERT_FALSE (integer_minus_onep (i_0));
   15603   ASSERT_FALSE (integer_minus_onep (wr_i_0));
   15604   ASSERT_FALSE (integer_minus_onep (i_1));
   15605   ASSERT_FALSE (integer_minus_onep (wr_i_1));
   15606   ASSERT_TRUE (integer_minus_onep (i_m1));
   15607   ASSERT_TRUE (integer_minus_onep (wr_i_m1));
   15608   ASSERT_FALSE (integer_minus_onep (f_0));
   15609   ASSERT_FALSE (integer_minus_onep (wr_f_0));
   15610   ASSERT_FALSE (integer_minus_onep (f_1));
   15611   ASSERT_FALSE (integer_minus_onep (wr_f_1));
   15612   ASSERT_FALSE (integer_minus_onep (f_m1));
   15613   ASSERT_FALSE (integer_minus_onep (wr_f_m1));
   15614   ASSERT_FALSE (integer_minus_onep (c_i_0));
   15615   ASSERT_FALSE (integer_minus_onep (c_i_1));
   15616   ASSERT_TRUE (integer_minus_onep (c_i_m1));
   15617   ASSERT_FALSE (integer_minus_onep (c_f_0));
   15618   ASSERT_FALSE (integer_minus_onep (c_f_1));
   15619   ASSERT_FALSE (integer_minus_onep (c_f_m1));
   15620 
   15621   /* Test integer_each_onep.  */
   15622   ASSERT_FALSE (integer_each_onep (i_0));
   15623   ASSERT_FALSE (integer_each_onep (wr_i_0));
   15624   ASSERT_TRUE (integer_each_onep (i_1));
   15625   ASSERT_TRUE (integer_each_onep (wr_i_1));
   15626   ASSERT_FALSE (integer_each_onep (i_m1));
   15627   ASSERT_FALSE (integer_each_onep (wr_i_m1));
   15628   ASSERT_FALSE (integer_each_onep (f_0));
   15629   ASSERT_FALSE (integer_each_onep (wr_f_0));
   15630   ASSERT_FALSE (integer_each_onep (f_1));
   15631   ASSERT_FALSE (integer_each_onep (wr_f_1));
   15632   ASSERT_FALSE (integer_each_onep (f_m1));
   15633   ASSERT_FALSE (integer_each_onep (wr_f_m1));
   15634   ASSERT_FALSE (integer_each_onep (c_i_0));
   15635   ASSERT_FALSE (integer_each_onep (c_i_1));
   15636   ASSERT_FALSE (integer_each_onep (c_i_m1));
   15637   ASSERT_FALSE (integer_each_onep (c_f_0));
   15638   ASSERT_FALSE (integer_each_onep (c_f_1));
   15639   ASSERT_FALSE (integer_each_onep (c_f_m1));
   15640 
   15641   /* Test integer_truep.  */
   15642   ASSERT_FALSE (integer_truep (i_0));
   15643   ASSERT_FALSE (integer_truep (wr_i_0));
   15644   ASSERT_TRUE (integer_truep (i_1));
   15645   ASSERT_TRUE (integer_truep (wr_i_1));
   15646   ASSERT_FALSE (integer_truep (i_m1));
   15647   ASSERT_FALSE (integer_truep (wr_i_m1));
   15648   ASSERT_FALSE (integer_truep (f_0));
   15649   ASSERT_FALSE (integer_truep (wr_f_0));
   15650   ASSERT_FALSE (integer_truep (f_1));
   15651   ASSERT_FALSE (integer_truep (wr_f_1));
   15652   ASSERT_FALSE (integer_truep (f_m1));
   15653   ASSERT_FALSE (integer_truep (wr_f_m1));
   15654   ASSERT_FALSE (integer_truep (c_i_0));
   15655   ASSERT_TRUE (integer_truep (c_i_1));
   15656   ASSERT_FALSE (integer_truep (c_i_m1));
   15657   ASSERT_FALSE (integer_truep (c_f_0));
   15658   ASSERT_FALSE (integer_truep (c_f_1));
   15659   ASSERT_FALSE (integer_truep (c_f_m1));
   15660 
   15661   /* Test integer_nonzerop.  */
   15662   ASSERT_FALSE (integer_nonzerop (i_0));
   15663   ASSERT_FALSE (integer_nonzerop (wr_i_0));
   15664   ASSERT_TRUE (integer_nonzerop (i_1));
   15665   ASSERT_TRUE (integer_nonzerop (wr_i_1));
   15666   ASSERT_TRUE (integer_nonzerop (i_m1));
   15667   ASSERT_TRUE (integer_nonzerop (wr_i_m1));
   15668   ASSERT_FALSE (integer_nonzerop (f_0));
   15669   ASSERT_FALSE (integer_nonzerop (wr_f_0));
   15670   ASSERT_FALSE (integer_nonzerop (f_1));
   15671   ASSERT_FALSE (integer_nonzerop (wr_f_1));
   15672   ASSERT_FALSE (integer_nonzerop (f_m1));
   15673   ASSERT_FALSE (integer_nonzerop (wr_f_m1));
   15674   ASSERT_FALSE (integer_nonzerop (c_i_0));
   15675   ASSERT_TRUE (integer_nonzerop (c_i_1));
   15676   ASSERT_TRUE (integer_nonzerop (c_i_m1));
   15677   ASSERT_FALSE (integer_nonzerop (c_f_0));
   15678   ASSERT_FALSE (integer_nonzerop (c_f_1));
   15679   ASSERT_FALSE (integer_nonzerop (c_f_m1));
   15680 
   15681   /* Test real_zerop.  */
   15682   ASSERT_FALSE (real_zerop (i_0));
   15683   ASSERT_FALSE (real_zerop (wr_i_0));
   15684   ASSERT_FALSE (real_zerop (i_1));
   15685   ASSERT_FALSE (real_zerop (wr_i_1));
   15686   ASSERT_FALSE (real_zerop (i_m1));
   15687   ASSERT_FALSE (real_zerop (wr_i_m1));
   15688   ASSERT_TRUE (real_zerop (f_0));
   15689   ASSERT_TRUE (real_zerop (wr_f_0));
   15690   ASSERT_FALSE (real_zerop (f_1));
   15691   ASSERT_FALSE (real_zerop (wr_f_1));
   15692   ASSERT_FALSE (real_zerop (f_m1));
   15693   ASSERT_FALSE (real_zerop (wr_f_m1));
   15694   ASSERT_FALSE (real_zerop (c_i_0));
   15695   ASSERT_FALSE (real_zerop (c_i_1));
   15696   ASSERT_FALSE (real_zerop (c_i_m1));
   15697   ASSERT_TRUE (real_zerop (c_f_0));
   15698   ASSERT_FALSE (real_zerop (c_f_1));
   15699   ASSERT_FALSE (real_zerop (c_f_m1));
   15700 
   15701   /* Test real_onep.  */
   15702   ASSERT_FALSE (real_onep (i_0));
   15703   ASSERT_FALSE (real_onep (wr_i_0));
   15704   ASSERT_FALSE (real_onep (i_1));
   15705   ASSERT_FALSE (real_onep (wr_i_1));
   15706   ASSERT_FALSE (real_onep (i_m1));
   15707   ASSERT_FALSE (real_onep (wr_i_m1));
   15708   ASSERT_FALSE (real_onep (f_0));
   15709   ASSERT_FALSE (real_onep (wr_f_0));
   15710   ASSERT_TRUE (real_onep (f_1));
   15711   ASSERT_TRUE (real_onep (wr_f_1));
   15712   ASSERT_FALSE (real_onep (f_m1));
   15713   ASSERT_FALSE (real_onep (wr_f_m1));
   15714   ASSERT_FALSE (real_onep (c_i_0));
   15715   ASSERT_FALSE (real_onep (c_i_1));
   15716   ASSERT_FALSE (real_onep (c_i_m1));
   15717   ASSERT_FALSE (real_onep (c_f_0));
   15718   ASSERT_TRUE (real_onep (c_f_1));
   15719   ASSERT_FALSE (real_onep (c_f_m1));
   15720 
   15721   /* Test real_minus_onep.  */
   15722   ASSERT_FALSE (real_minus_onep (i_0));
   15723   ASSERT_FALSE (real_minus_onep (wr_i_0));
   15724   ASSERT_FALSE (real_minus_onep (i_1));
   15725   ASSERT_FALSE (real_minus_onep (wr_i_1));
   15726   ASSERT_FALSE (real_minus_onep (i_m1));
   15727   ASSERT_FALSE (real_minus_onep (wr_i_m1));
   15728   ASSERT_FALSE (real_minus_onep (f_0));
   15729   ASSERT_FALSE (real_minus_onep (wr_f_0));
   15730   ASSERT_FALSE (real_minus_onep (f_1));
   15731   ASSERT_FALSE (real_minus_onep (wr_f_1));
   15732   ASSERT_TRUE (real_minus_onep (f_m1));
   15733   ASSERT_TRUE (real_minus_onep (wr_f_m1));
   15734   ASSERT_FALSE (real_minus_onep (c_i_0));
   15735   ASSERT_FALSE (real_minus_onep (c_i_1));
   15736   ASSERT_FALSE (real_minus_onep (c_i_m1));
   15737   ASSERT_FALSE (real_minus_onep (c_f_0));
   15738   ASSERT_FALSE (real_minus_onep (c_f_1));
   15739   ASSERT_TRUE (real_minus_onep (c_f_m1));
   15740 
   15741   /* Test zerop.  */
   15742   ASSERT_TRUE (zerop (i_0));
   15743   ASSERT_TRUE (zerop (wr_i_0));
   15744   ASSERT_FALSE (zerop (i_1));
   15745   ASSERT_FALSE (zerop (wr_i_1));
   15746   ASSERT_FALSE (zerop (i_m1));
   15747   ASSERT_FALSE (zerop (wr_i_m1));
   15748   ASSERT_TRUE (zerop (f_0));
   15749   ASSERT_TRUE (zerop (wr_f_0));
   15750   ASSERT_FALSE (zerop (f_1));
   15751   ASSERT_FALSE (zerop (wr_f_1));
   15752   ASSERT_FALSE (zerop (f_m1));
   15753   ASSERT_FALSE (zerop (wr_f_m1));
   15754   ASSERT_TRUE (zerop (c_i_0));
   15755   ASSERT_FALSE (zerop (c_i_1));
   15756   ASSERT_FALSE (zerop (c_i_m1));
   15757   ASSERT_TRUE (zerop (c_f_0));
   15758   ASSERT_FALSE (zerop (c_f_1));
   15759   ASSERT_FALSE (zerop (c_f_m1));
   15760 
   15761   /* Test tree_expr_nonnegative_p.  */
   15762   ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
   15763   ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
   15764   ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
   15765   ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
   15766   ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
   15767   ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
   15768   ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
   15769   ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
   15770   ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
   15771   ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
   15772   ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
   15773   ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
   15774   ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
   15775   ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
   15776   ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
   15777   ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
   15778   ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
   15779   ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
   15780 
   15781   /* Test tree_expr_nonzero_p.  */
   15782   ASSERT_FALSE (tree_expr_nonzero_p (i_0));
   15783   ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
   15784   ASSERT_TRUE (tree_expr_nonzero_p (i_1));
   15785   ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
   15786   ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
   15787   ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
   15788 
   15789   /* Test integer_valued_real_p.  */
   15790   ASSERT_FALSE (integer_valued_real_p (i_0));
   15791   ASSERT_TRUE (integer_valued_real_p (f_0));
   15792   ASSERT_TRUE (integer_valued_real_p (wr_f_0));
   15793   ASSERT_TRUE (integer_valued_real_p (f_1));
   15794   ASSERT_TRUE (integer_valued_real_p (wr_f_1));
   15795 
   15796   /* Test integer_pow2p.  */
   15797   ASSERT_FALSE (integer_pow2p (i_0));
   15798   ASSERT_TRUE (integer_pow2p (i_1));
   15799   ASSERT_TRUE (integer_pow2p (wr_i_1));
   15800 
   15801   /* Test uniform_integer_cst_p.  */
   15802   ASSERT_TRUE (uniform_integer_cst_p (i_0));
   15803   ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
   15804   ASSERT_TRUE (uniform_integer_cst_p (i_1));
   15805   ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
   15806   ASSERT_TRUE (uniform_integer_cst_p (i_m1));
   15807   ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
   15808   ASSERT_FALSE (uniform_integer_cst_p (f_0));
   15809   ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
   15810   ASSERT_FALSE (uniform_integer_cst_p (f_1));
   15811   ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
   15812   ASSERT_FALSE (uniform_integer_cst_p (f_m1));
   15813   ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
   15814   ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
   15815   ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
   15816   ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
   15817   ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
   15818   ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
   15819   ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
   15820 }
   15821 
   15822 /* Check that string escaping works correctly.  */
   15823 
   15824 static void
   15825 test_escaped_strings (void)
   15826 {
   15827   int saved_cutoff;
   15828   escaped_string msg;
   15829 
   15830   msg.escape (NULL);
   15831   /* ASSERT_STREQ does not accept NULL as a valid test
   15832      result, so we have to use ASSERT_EQ instead.  */
   15833   ASSERT_EQ (NULL, (const char *) msg);
   15834 
   15835   msg.escape ("");
   15836   ASSERT_STREQ ("", (const char *) msg);
   15837 
   15838   msg.escape ("foobar");
   15839   ASSERT_STREQ ("foobar", (const char *) msg);
   15840 
   15841   /* Ensure that we have -fmessage-length set to 0.  */
   15842   saved_cutoff = pp_line_cutoff (global_dc->printer);
   15843   pp_line_cutoff (global_dc->printer) = 0;
   15844 
   15845   msg.escape ("foo\nbar");
   15846   ASSERT_STREQ ("foo\\nbar", (const char *) msg);
   15847 
   15848   msg.escape ("\a\b\f\n\r\t\v");
   15849   ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
   15850 
   15851   /* Now repeat the tests with -fmessage-length set to 5.  */
   15852   pp_line_cutoff (global_dc->printer) = 5;
   15853 
   15854   /* Note that the newline is not translated into an escape.  */
   15855   msg.escape ("foo\nbar");
   15856   ASSERT_STREQ ("foo\nbar", (const char *) msg);
   15857 
   15858   msg.escape ("\a\b\f\n\r\t\v");
   15859   ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
   15860 
   15861   /* Restore the original message length setting.  */
   15862   pp_line_cutoff (global_dc->printer) = saved_cutoff;
   15863 }
   15864 
   15865 /* Run all of the selftests within this file.  */
   15866 
   15867 void
   15868 tree_cc_tests ()
   15869 {
   15870   test_integer_constants ();
   15871   test_identifiers ();
   15872   test_labels ();
   15873   test_vector_cst_patterns ();
   15874   test_location_wrappers ();
   15875   test_predicates ();
   15876   test_escaped_strings ();
   15877 }
   15878 
   15879 } // namespace selftest
   15880 
   15881 #endif /* CHECKING_P */
   15882 
   15883 #include "gt-tree.h"
   15884