OSDN Git Service

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