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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
54 /* Each tree code class has an associated string representation.
55 These must correspond to the tree_code_class entries. */
57 const char *const tree_code_class_strings[] =
71 /* obstack.[ch] explicitly declined to prototype this. */
72 extern int _obstack_allocated_p (struct obstack *h, void *obj);
74 #ifdef GATHER_STATISTICS
75 /* Statistics-gathering stuff. */
77 int tree_node_counts[(int) all_kinds];
78 int tree_node_sizes[(int) all_kinds];
80 /* Keep in sync with tree.h:enum tree_node_kind. */
81 static const char * const tree_node_kind_names[] = {
101 #endif /* GATHER_STATISTICS */
103 /* Unique id for next decl created. */
104 static GTY(()) int next_decl_uid;
105 /* Unique id for next type created. */
106 static GTY(()) int next_type_uid = 1;
108 /* Since we cannot rehash a type after it is in the table, we have to
109 keep the hash code. */
111 struct type_hash GTY(())
117 /* Initial size of the hash table (rounded to next prime). */
118 #define TYPE_HASH_INITIAL_SIZE 1000
120 /* Now here is the hash table. When recording a type, it is added to
121 the slot whose index is the hash code. Note that the hash table is
122 used for several kinds of types (function types, array types and
123 array index range types, for now). While all these live in the
124 same table, they are completely independent, and the hash code is
125 computed differently for each of these. */
127 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
128 htab_t type_hash_table;
130 /* Hash table and temporary node for larger integer const values. */
131 static GTY (()) tree int_cst_node;
132 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
133 htab_t int_cst_hash_table;
135 /* General tree->tree mapping structure for use in hash tables. */
138 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
139 htab_t debug_expr_for_decl;
141 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
142 htab_t value_expr_for_decl;
144 static GTY ((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
145 htab_t init_priority_for_decl;
147 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
148 htab_t restrict_base_for_decl;
150 struct tree_int_map GTY(())
155 static unsigned int tree_int_map_hash (const void *);
156 static int tree_int_map_eq (const void *, const void *);
157 static int tree_int_map_marked_p (const void *);
158 static void set_type_quals (tree, int);
159 static int type_hash_eq (const void *, const void *);
160 static hashval_t type_hash_hash (const void *);
161 static hashval_t int_cst_hash_hash (const void *);
162 static int int_cst_hash_eq (const void *, const void *);
163 static void print_type_hash_statistics (void);
164 static void print_debug_expr_statistics (void);
165 static void print_value_expr_statistics (void);
166 static tree make_vector_type (tree, int, enum machine_mode);
167 static int type_hash_marked_p (const void *);
168 static unsigned int type_hash_list (tree, hashval_t);
169 static unsigned int attribute_hash_list (tree, hashval_t);
171 tree global_trees[TI_MAX];
172 tree integer_types[itk_none];
174 unsigned char tree_contains_struct[256][64];
182 /* Initialize the hash table of types. */
183 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
186 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
189 value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
191 init_priority_for_decl = htab_create_ggc (512, tree_int_map_hash,
193 restrict_base_for_decl = htab_create_ggc (256, tree_map_hash,
196 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
197 int_cst_hash_eq, NULL);
199 int_cst_node = make_node (INTEGER_CST);
201 tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
202 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
203 tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
206 tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1;
207 tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1;
208 tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1;
209 tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1;
210 tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1;
211 tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1;
212 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1;
213 tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1;
214 tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1;
217 tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1;
218 tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1;
219 tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1;
220 tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1;
221 tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1;
222 tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1;
224 tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1;
225 tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1;
226 tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1;
227 tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1;
228 tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1;
229 tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1;
230 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1;
231 tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1;
232 tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1;
233 tree_contains_struct[STRUCT_FIELD_TAG][TS_DECL_MINIMAL] = 1;
234 tree_contains_struct[NAME_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
235 tree_contains_struct[TYPE_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
237 tree_contains_struct[STRUCT_FIELD_TAG][TS_MEMORY_TAG] = 1;
238 tree_contains_struct[NAME_MEMORY_TAG][TS_MEMORY_TAG] = 1;
239 tree_contains_struct[TYPE_MEMORY_TAG][TS_MEMORY_TAG] = 1;
241 tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1;
242 tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1;
243 tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1;
244 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1;
246 tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1;
247 tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1;
248 tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1;
249 tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1;
250 tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1;
251 tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1;
252 tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1;
253 tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1;
255 lang_hooks.init_ts ();
259 /* The name of the object as the assembler will see it (but before any
260 translations made by ASM_OUTPUT_LABELREF). Often this is the same
261 as DECL_NAME. It is an IDENTIFIER_NODE. */
263 decl_assembler_name (tree decl)
265 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
266 lang_hooks.set_decl_assembler_name (decl);
267 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
270 /* Compute the number of bytes occupied by a tree with code CODE.
271 This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
272 codes, which are of variable length. */
274 tree_code_size (enum tree_code code)
276 switch (TREE_CODE_CLASS (code))
278 case tcc_declaration: /* A decl node */
283 return sizeof (struct tree_field_decl);
285 return sizeof (struct tree_parm_decl);
287 return sizeof (struct tree_var_decl);
289 return sizeof (struct tree_label_decl);
291 return sizeof (struct tree_result_decl);
293 return sizeof (struct tree_const_decl);
295 return sizeof (struct tree_type_decl);
297 return sizeof (struct tree_function_decl);
298 case NAME_MEMORY_TAG:
299 case TYPE_MEMORY_TAG:
300 case STRUCT_FIELD_TAG:
301 return sizeof (struct tree_memory_tag);
303 return sizeof (struct tree_decl_non_common);
307 case tcc_type: /* a type node */
308 return sizeof (struct tree_type);
310 case tcc_reference: /* a reference */
311 case tcc_expression: /* an expression */
312 case tcc_statement: /* an expression with side effects */
313 case tcc_comparison: /* a comparison expression */
314 case tcc_unary: /* a unary arithmetic expression */
315 case tcc_binary: /* a binary arithmetic expression */
316 return (sizeof (struct tree_exp)
317 + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
319 case tcc_constant: /* a constant */
322 case INTEGER_CST: return sizeof (struct tree_int_cst);
323 case REAL_CST: return sizeof (struct tree_real_cst);
324 case COMPLEX_CST: return sizeof (struct tree_complex);
325 case VECTOR_CST: return sizeof (struct tree_vector);
326 case STRING_CST: gcc_unreachable ();
328 return lang_hooks.tree_size (code);
331 case tcc_exceptional: /* something random, like an identifier. */
334 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
335 case TREE_LIST: return sizeof (struct tree_list);
338 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
341 case PHI_NODE: gcc_unreachable ();
343 case SSA_NAME: return sizeof (struct tree_ssa_name);
345 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
346 case BLOCK: return sizeof (struct tree_block);
347 case VALUE_HANDLE: return sizeof (struct tree_value_handle);
348 case CONSTRUCTOR: return sizeof (struct tree_constructor);
351 return lang_hooks.tree_size (code);
359 /* Compute the number of bytes occupied by NODE. This routine only
360 looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
362 tree_size (tree node)
364 enum tree_code code = TREE_CODE (node);
368 return (sizeof (struct tree_phi_node)
369 + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
372 return (offsetof (struct tree_binfo, base_binfos)
373 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
376 return (sizeof (struct tree_vec)
377 + (TREE_VEC_LENGTH (node) - 1) * sizeof(char *));
380 return sizeof (struct tree_string) + TREE_STRING_LENGTH (node) - 1;
383 return tree_code_size (code);
387 /* Return a newly allocated node of code CODE. For decl and type
388 nodes, some other fields are initialized. The rest of the node is
389 initialized to zero. This function cannot be used for PHI_NODE or
390 TREE_VEC nodes, which is enforced by asserts in tree_code_size.
392 Achoo! I got a code in the node. */
395 make_node_stat (enum tree_code code MEM_STAT_DECL)
398 enum tree_code_class type = TREE_CODE_CLASS (code);
399 size_t length = tree_code_size (code);
400 #ifdef GATHER_STATISTICS
405 case tcc_declaration: /* A decl node */
409 case tcc_type: /* a type node */
413 case tcc_statement: /* an expression with side effects */
417 case tcc_reference: /* a reference */
421 case tcc_expression: /* an expression */
422 case tcc_comparison: /* a comparison expression */
423 case tcc_unary: /* a unary arithmetic expression */
424 case tcc_binary: /* a binary arithmetic expression */
428 case tcc_constant: /* a constant */
432 case tcc_exceptional: /* something random, like an identifier. */
435 case IDENTIFIER_NODE:
452 kind = ssa_name_kind;
473 tree_node_counts[(int) kind]++;
474 tree_node_sizes[(int) kind] += length;
477 if (code == IDENTIFIER_NODE)
478 t = ggc_alloc_zone_pass_stat (length, &tree_id_zone);
480 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
482 memset (t, 0, length);
484 TREE_SET_CODE (t, code);
489 TREE_SIDE_EFFECTS (t) = 1;
492 case tcc_declaration:
493 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
494 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
495 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
497 if (code != FUNCTION_DECL)
499 DECL_USER_ALIGN (t) = 0;
500 /* We have not yet computed the alias set for this declaration. */
501 DECL_POINTER_ALIAS_SET (t) = -1;
503 DECL_SOURCE_LOCATION (t) = input_location;
504 DECL_UID (t) = next_decl_uid++;
509 TYPE_UID (t) = next_type_uid++;
510 TYPE_ALIGN (t) = BITS_PER_UNIT;
511 TYPE_USER_ALIGN (t) = 0;
512 TYPE_MAIN_VARIANT (t) = t;
514 /* Default to no attributes for type, but let target change that. */
515 TYPE_ATTRIBUTES (t) = NULL_TREE;
516 targetm.set_default_type_attributes (t);
518 /* We have not yet computed the alias set for this type. */
519 TYPE_ALIAS_SET (t) = -1;
523 TREE_CONSTANT (t) = 1;
524 TREE_INVARIANT (t) = 1;
533 case PREDECREMENT_EXPR:
534 case PREINCREMENT_EXPR:
535 case POSTDECREMENT_EXPR:
536 case POSTINCREMENT_EXPR:
537 /* All of these have side-effects, no matter what their
539 TREE_SIDE_EFFECTS (t) = 1;
548 /* Other classes need no special treatment. */
555 /* Return a new node with the same contents as NODE except that its
556 TREE_CHAIN is zero and it has a fresh uid. */
559 copy_node_stat (tree node MEM_STAT_DECL)
562 enum tree_code code = TREE_CODE (node);
565 gcc_assert (code != STATEMENT_LIST);
567 length = tree_size (node);
568 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
569 memcpy (t, node, length);
572 TREE_ASM_WRITTEN (t) = 0;
573 TREE_VISITED (t) = 0;
576 if (TREE_CODE_CLASS (code) == tcc_declaration)
578 DECL_UID (t) = next_decl_uid++;
579 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
580 && DECL_HAS_VALUE_EXPR_P (node))
582 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
583 DECL_HAS_VALUE_EXPR_P (t) = 1;
585 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
587 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
588 DECL_HAS_INIT_PRIORITY_P (t) = 1;
590 if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node))
592 SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node));
593 DECL_BASED_ON_RESTRICT_P (t) = 1;
596 else if (TREE_CODE_CLASS (code) == tcc_type)
598 TYPE_UID (t) = next_type_uid++;
599 /* The following is so that the debug code for
600 the copy is different from the original type.
601 The two statements usually duplicate each other
602 (because they clear fields of the same union),
603 but the optimizer should catch that. */
604 TYPE_SYMTAB_POINTER (t) = 0;
605 TYPE_SYMTAB_ADDRESS (t) = 0;
607 /* Do not copy the values cache. */
608 if (TYPE_CACHED_VALUES_P(t))
610 TYPE_CACHED_VALUES_P (t) = 0;
611 TYPE_CACHED_VALUES (t) = NULL_TREE;
618 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
619 For example, this can copy a list made of TREE_LIST nodes. */
622 copy_list (tree list)
630 head = prev = copy_node (list);
631 next = TREE_CHAIN (list);
634 TREE_CHAIN (prev) = copy_node (next);
635 prev = TREE_CHAIN (prev);
636 next = TREE_CHAIN (next);
642 /* Create an INT_CST node with a LOW value sign extended. */
645 build_int_cst (tree type, HOST_WIDE_INT low)
647 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
650 /* Create an INT_CST node with a LOW value zero extended. */
653 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
655 return build_int_cst_wide (type, low, 0);
658 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
659 if it is negative. This function is similar to build_int_cst, but
660 the extra bits outside of the type precision are cleared. Constants
661 with these extra bits may confuse the fold so that it detects overflows
662 even in cases when they do not occur, and in general should be avoided.
663 We cannot however make this a default behavior of build_int_cst without
664 more intrusive changes, since there are parts of gcc that rely on the extra
665 precision of the integer constants. */
668 build_int_cst_type (tree type, HOST_WIDE_INT low)
670 unsigned HOST_WIDE_INT val = (unsigned HOST_WIDE_INT) low;
671 unsigned HOST_WIDE_INT hi, mask;
677 type = integer_type_node;
679 bits = TYPE_PRECISION (type);
680 signed_p = !TYPE_UNSIGNED (type);
682 if (bits >= HOST_BITS_PER_WIDE_INT)
683 negative = (low < 0);
686 /* If the sign bit is inside precision of LOW, use it to determine
687 the sign of the constant. */
688 negative = ((val >> (bits - 1)) & 1) != 0;
690 /* Mask out the bits outside of the precision of the constant. */
691 mask = (((unsigned HOST_WIDE_INT) 2) << (bits - 1)) - 1;
693 if (signed_p && negative)
699 /* Determine the high bits. */
700 hi = (negative ? ~(unsigned HOST_WIDE_INT) 0 : 0);
702 /* For unsigned type we need to mask out the bits outside of the type
706 if (bits <= HOST_BITS_PER_WIDE_INT)
710 bits -= HOST_BITS_PER_WIDE_INT;
711 mask = (((unsigned HOST_WIDE_INT) 2) << (bits - 1)) - 1;
716 return build_int_cst_wide (type, val, hi);
719 /* These are the hash table functions for the hash table of INTEGER_CST
720 nodes of a sizetype. */
722 /* Return the hash code code X, an INTEGER_CST. */
725 int_cst_hash_hash (const void *x)
729 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
730 ^ htab_hash_pointer (TREE_TYPE (t)));
733 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
734 is the same as that given by *Y, which is the same. */
737 int_cst_hash_eq (const void *x, const void *y)
742 return (TREE_TYPE (xt) == TREE_TYPE (yt)
743 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
744 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
747 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
748 integer_type_node is used. The returned node is always shared.
749 For small integers we use a per-type vector cache, for larger ones
750 we use a single hash table. */
753 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
760 type = integer_type_node;
762 switch (TREE_CODE (type))
766 /* Cache NULL pointer. */
775 /* Cache false or true. */
784 if (TYPE_UNSIGNED (type))
787 limit = INTEGER_SHARE_LIMIT;
788 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
794 limit = INTEGER_SHARE_LIMIT + 1;
795 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
797 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
807 /* Look for it in the type's vector of small shared ints. */
808 if (!TYPE_CACHED_VALUES_P (type))
810 TYPE_CACHED_VALUES_P (type) = 1;
811 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
814 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
817 /* Make sure no one is clobbering the shared constant. */
818 gcc_assert (TREE_TYPE (t) == type);
819 gcc_assert (TREE_INT_CST_LOW (t) == low);
820 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
824 /* Create a new shared int. */
825 t = make_node (INTEGER_CST);
827 TREE_INT_CST_LOW (t) = low;
828 TREE_INT_CST_HIGH (t) = hi;
829 TREE_TYPE (t) = type;
831 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
836 /* Use the cache of larger shared ints. */
839 TREE_INT_CST_LOW (int_cst_node) = low;
840 TREE_INT_CST_HIGH (int_cst_node) = hi;
841 TREE_TYPE (int_cst_node) = type;
843 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
847 /* Insert this one into the hash table. */
850 /* Make a new node for next time round. */
851 int_cst_node = make_node (INTEGER_CST);
858 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
859 and the rest are zeros. */
862 build_low_bits_mask (tree type, unsigned bits)
864 unsigned HOST_WIDE_INT low;
866 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
868 gcc_assert (bits <= TYPE_PRECISION (type));
870 if (bits == TYPE_PRECISION (type)
871 && !TYPE_UNSIGNED (type))
873 /* Sign extended all-ones mask. */
877 else if (bits <= HOST_BITS_PER_WIDE_INT)
879 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
884 bits -= HOST_BITS_PER_WIDE_INT;
886 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
889 return build_int_cst_wide (type, low, high);
892 /* Checks that X is integer constant that can be expressed in (unsigned)
893 HOST_WIDE_INT without loss of precision. */
896 cst_and_fits_in_hwi (tree x)
898 if (TREE_CODE (x) != INTEGER_CST)
901 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
904 return (TREE_INT_CST_HIGH (x) == 0
905 || TREE_INT_CST_HIGH (x) == -1);
908 /* Return a new VECTOR_CST node whose type is TYPE and whose values
909 are in a list pointed to by VALS. */
912 build_vector (tree type, tree vals)
914 tree v = make_node (VECTOR_CST);
915 int over1 = 0, over2 = 0;
918 TREE_VECTOR_CST_ELTS (v) = vals;
919 TREE_TYPE (v) = type;
921 /* Iterate through elements and check for overflow. */
922 for (link = vals; link; link = TREE_CHAIN (link))
924 tree value = TREE_VALUE (link);
926 over1 |= TREE_OVERFLOW (value);
927 over2 |= TREE_CONSTANT_OVERFLOW (value);
930 TREE_OVERFLOW (v) = over1;
931 TREE_CONSTANT_OVERFLOW (v) = over2;
936 /* Return a new VECTOR_CST node whose type is TYPE and whose values
937 are extracted from V, a vector of CONSTRUCTOR_ELT. */
940 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
942 tree list = NULL_TREE;
943 unsigned HOST_WIDE_INT idx;
946 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
947 list = tree_cons (NULL_TREE, value, list);
948 return build_vector (type, nreverse (list));
951 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
952 are in the VEC pointed to by VALS. */
954 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
956 tree c = make_node (CONSTRUCTOR);
957 TREE_TYPE (c) = type;
958 CONSTRUCTOR_ELTS (c) = vals;
962 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
965 build_constructor_single (tree type, tree index, tree value)
967 VEC(constructor_elt,gc) *v;
968 constructor_elt *elt;
970 v = VEC_alloc (constructor_elt, gc, 1);
971 elt = VEC_quick_push (constructor_elt, v, NULL);
975 return build_constructor (type, v);
979 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
980 are in a list pointed to by VALS. */
982 build_constructor_from_list (tree type, tree vals)
985 VEC(constructor_elt,gc) *v = NULL;
989 v = VEC_alloc (constructor_elt, gc, list_length (vals));
990 for (t = vals; t; t = TREE_CHAIN (t))
992 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
993 elt->index = TREE_PURPOSE (t);
994 elt->value = TREE_VALUE (t);
998 return build_constructor (type, v);
1002 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1005 build_real (tree type, REAL_VALUE_TYPE d)
1008 REAL_VALUE_TYPE *dp;
1011 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1012 Consider doing it via real_convert now. */
1014 v = make_node (REAL_CST);
1015 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
1016 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1018 TREE_TYPE (v) = type;
1019 TREE_REAL_CST_PTR (v) = dp;
1020 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
1024 /* Return a new REAL_CST node whose type is TYPE
1025 and whose value is the integer value of the INTEGER_CST node I. */
1028 real_value_from_int_cst (tree type, tree i)
1032 /* Clear all bits of the real value type so that we can later do
1033 bitwise comparisons to see if two values are the same. */
1034 memset (&d, 0, sizeof d);
1036 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1037 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1038 TYPE_UNSIGNED (TREE_TYPE (i)));
1042 /* Given a tree representing an integer constant I, return a tree
1043 representing the same value as a floating-point constant of type TYPE. */
1046 build_real_from_int_cst (tree type, tree i)
1049 int overflow = TREE_OVERFLOW (i);
1051 v = build_real (type, real_value_from_int_cst (type, i));
1053 TREE_OVERFLOW (v) |= overflow;
1054 TREE_CONSTANT_OVERFLOW (v) |= overflow;
1058 /* Return a newly constructed STRING_CST node whose value is
1059 the LEN characters at STR.
1060 The TREE_TYPE is not initialized. */
1063 build_string (int len, const char *str)
1068 length = len + sizeof (struct tree_string);
1070 #ifdef GATHER_STATISTICS
1071 tree_node_counts[(int) c_kind]++;
1072 tree_node_sizes[(int) c_kind] += length;
1075 s = ggc_alloc_tree (length);
1077 memset (s, 0, sizeof (struct tree_common));
1078 TREE_SET_CODE (s, STRING_CST);
1079 TREE_CONSTANT (s) = 1;
1080 TREE_INVARIANT (s) = 1;
1081 TREE_STRING_LENGTH (s) = len;
1082 memcpy ((char *) TREE_STRING_POINTER (s), str, len);
1083 ((char *) TREE_STRING_POINTER (s))[len] = '\0';
1088 /* Return a newly constructed COMPLEX_CST node whose value is
1089 specified by the real and imaginary parts REAL and IMAG.
1090 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1091 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1094 build_complex (tree type, tree real, tree imag)
1096 tree t = make_node (COMPLEX_CST);
1098 TREE_REALPART (t) = real;
1099 TREE_IMAGPART (t) = imag;
1100 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1101 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1102 TREE_CONSTANT_OVERFLOW (t)
1103 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
1107 /* Build a BINFO with LEN language slots. */
1110 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1113 size_t length = (offsetof (struct tree_binfo, base_binfos)
1114 + VEC_embedded_size (tree, base_binfos));
1116 #ifdef GATHER_STATISTICS
1117 tree_node_counts[(int) binfo_kind]++;
1118 tree_node_sizes[(int) binfo_kind] += length;
1121 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
1123 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1125 TREE_SET_CODE (t, TREE_BINFO);
1127 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1133 /* Build a newly constructed TREE_VEC node of length LEN. */
1136 make_tree_vec_stat (int len MEM_STAT_DECL)
1139 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1141 #ifdef GATHER_STATISTICS
1142 tree_node_counts[(int) vec_kind]++;
1143 tree_node_sizes[(int) vec_kind] += length;
1146 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
1148 memset (t, 0, length);
1150 TREE_SET_CODE (t, TREE_VEC);
1151 TREE_VEC_LENGTH (t) = len;
1156 /* Return 1 if EXPR is the integer constant zero or a complex constant
1160 integer_zerop (tree expr)
1164 return ((TREE_CODE (expr) == INTEGER_CST
1165 && ! TREE_CONSTANT_OVERFLOW (expr)
1166 && TREE_INT_CST_LOW (expr) == 0
1167 && TREE_INT_CST_HIGH (expr) == 0)
1168 || (TREE_CODE (expr) == COMPLEX_CST
1169 && integer_zerop (TREE_REALPART (expr))
1170 && integer_zerop (TREE_IMAGPART (expr))));
1173 /* Return 1 if EXPR is the integer constant one or the corresponding
1174 complex constant. */
1177 integer_onep (tree expr)
1181 return ((TREE_CODE (expr) == INTEGER_CST
1182 && ! TREE_CONSTANT_OVERFLOW (expr)
1183 && TREE_INT_CST_LOW (expr) == 1
1184 && TREE_INT_CST_HIGH (expr) == 0)
1185 || (TREE_CODE (expr) == COMPLEX_CST
1186 && integer_onep (TREE_REALPART (expr))
1187 && integer_zerop (TREE_IMAGPART (expr))));
1190 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1191 it contains. Likewise for the corresponding complex constant. */
1194 integer_all_onesp (tree expr)
1201 if (TREE_CODE (expr) == COMPLEX_CST
1202 && integer_all_onesp (TREE_REALPART (expr))
1203 && integer_zerop (TREE_IMAGPART (expr)))
1206 else if (TREE_CODE (expr) != INTEGER_CST
1207 || TREE_CONSTANT_OVERFLOW (expr))
1210 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1212 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1213 && TREE_INT_CST_HIGH (expr) == -1);
1215 /* Note that using TYPE_PRECISION here is wrong. We care about the
1216 actual bits, not the (arbitrary) range of the type. */
1217 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1218 if (prec >= HOST_BITS_PER_WIDE_INT)
1220 HOST_WIDE_INT high_value;
1223 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1225 /* Can not handle precisions greater than twice the host int size. */
1226 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1227 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1228 /* Shifting by the host word size is undefined according to the ANSI
1229 standard, so we must handle this as a special case. */
1232 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1234 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1235 && TREE_INT_CST_HIGH (expr) == high_value);
1238 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1241 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1245 integer_pow2p (tree expr)
1248 HOST_WIDE_INT high, low;
1252 if (TREE_CODE (expr) == COMPLEX_CST
1253 && integer_pow2p (TREE_REALPART (expr))
1254 && integer_zerop (TREE_IMAGPART (expr)))
1257 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
1260 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1261 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1262 high = TREE_INT_CST_HIGH (expr);
1263 low = TREE_INT_CST_LOW (expr);
1265 /* First clear all bits that are beyond the type's precision in case
1266 we've been sign extended. */
1268 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1270 else if (prec > HOST_BITS_PER_WIDE_INT)
1271 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1275 if (prec < HOST_BITS_PER_WIDE_INT)
1276 low &= ~((HOST_WIDE_INT) (-1) << prec);
1279 if (high == 0 && low == 0)
1282 return ((high == 0 && (low & (low - 1)) == 0)
1283 || (low == 0 && (high & (high - 1)) == 0));
1286 /* Return 1 if EXPR is an integer constant other than zero or a
1287 complex constant other than zero. */
1290 integer_nonzerop (tree expr)
1294 return ((TREE_CODE (expr) == INTEGER_CST
1295 && ! TREE_CONSTANT_OVERFLOW (expr)
1296 && (TREE_INT_CST_LOW (expr) != 0
1297 || TREE_INT_CST_HIGH (expr) != 0))
1298 || (TREE_CODE (expr) == COMPLEX_CST
1299 && (integer_nonzerop (TREE_REALPART (expr))
1300 || integer_nonzerop (TREE_IMAGPART (expr)))));
1303 /* Return the power of two represented by a tree node known to be a
1307 tree_log2 (tree expr)
1310 HOST_WIDE_INT high, low;
1314 if (TREE_CODE (expr) == COMPLEX_CST)
1315 return tree_log2 (TREE_REALPART (expr));
1317 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1318 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1320 high = TREE_INT_CST_HIGH (expr);
1321 low = TREE_INT_CST_LOW (expr);
1323 /* First clear all bits that are beyond the type's precision in case
1324 we've been sign extended. */
1326 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1328 else if (prec > HOST_BITS_PER_WIDE_INT)
1329 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1333 if (prec < HOST_BITS_PER_WIDE_INT)
1334 low &= ~((HOST_WIDE_INT) (-1) << prec);
1337 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1338 : exact_log2 (low));
1341 /* Similar, but return the largest integer Y such that 2 ** Y is less
1342 than or equal to EXPR. */
1345 tree_floor_log2 (tree expr)
1348 HOST_WIDE_INT high, low;
1352 if (TREE_CODE (expr) == COMPLEX_CST)
1353 return tree_log2 (TREE_REALPART (expr));
1355 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1356 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1358 high = TREE_INT_CST_HIGH (expr);
1359 low = TREE_INT_CST_LOW (expr);
1361 /* First clear all bits that are beyond the type's precision in case
1362 we've been sign extended. Ignore if type's precision hasn't been set
1363 since what we are doing is setting it. */
1365 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1367 else if (prec > HOST_BITS_PER_WIDE_INT)
1368 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1372 if (prec < HOST_BITS_PER_WIDE_INT)
1373 low &= ~((HOST_WIDE_INT) (-1) << prec);
1376 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1377 : floor_log2 (low));
1380 /* Return 1 if EXPR is the real constant zero. */
1383 real_zerop (tree expr)
1387 return ((TREE_CODE (expr) == REAL_CST
1388 && ! TREE_CONSTANT_OVERFLOW (expr)
1389 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1390 || (TREE_CODE (expr) == COMPLEX_CST
1391 && real_zerop (TREE_REALPART (expr))
1392 && real_zerop (TREE_IMAGPART (expr))));
1395 /* Return 1 if EXPR is the real constant one in real or complex form. */
1398 real_onep (tree expr)
1402 return ((TREE_CODE (expr) == REAL_CST
1403 && ! TREE_CONSTANT_OVERFLOW (expr)
1404 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1405 || (TREE_CODE (expr) == COMPLEX_CST
1406 && real_onep (TREE_REALPART (expr))
1407 && real_zerop (TREE_IMAGPART (expr))));
1410 /* Return 1 if EXPR is the real constant two. */
1413 real_twop (tree expr)
1417 return ((TREE_CODE (expr) == REAL_CST
1418 && ! TREE_CONSTANT_OVERFLOW (expr)
1419 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1420 || (TREE_CODE (expr) == COMPLEX_CST
1421 && real_twop (TREE_REALPART (expr))
1422 && real_zerop (TREE_IMAGPART (expr))));
1425 /* Return 1 if EXPR is the real constant minus one. */
1428 real_minus_onep (tree expr)
1432 return ((TREE_CODE (expr) == REAL_CST
1433 && ! TREE_CONSTANT_OVERFLOW (expr)
1434 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1435 || (TREE_CODE (expr) == COMPLEX_CST
1436 && real_minus_onep (TREE_REALPART (expr))
1437 && real_zerop (TREE_IMAGPART (expr))));
1440 /* Nonzero if EXP is a constant or a cast of a constant. */
1443 really_constant_p (tree exp)
1445 /* This is not quite the same as STRIP_NOPS. It does more. */
1446 while (TREE_CODE (exp) == NOP_EXPR
1447 || TREE_CODE (exp) == CONVERT_EXPR
1448 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1449 exp = TREE_OPERAND (exp, 0);
1450 return TREE_CONSTANT (exp);
1453 /* Return first list element whose TREE_VALUE is ELEM.
1454 Return 0 if ELEM is not in LIST. */
1457 value_member (tree elem, tree list)
1461 if (elem == TREE_VALUE (list))
1463 list = TREE_CHAIN (list);
1468 /* Return first list element whose TREE_PURPOSE is ELEM.
1469 Return 0 if ELEM is not in LIST. */
1472 purpose_member (tree elem, tree list)
1476 if (elem == TREE_PURPOSE (list))
1478 list = TREE_CHAIN (list);
1483 /* Return nonzero if ELEM is part of the chain CHAIN. */
1486 chain_member (tree elem, tree chain)
1492 chain = TREE_CHAIN (chain);
1498 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1499 We expect a null pointer to mark the end of the chain.
1500 This is the Lisp primitive `length'. */
1503 list_length (tree t)
1506 #ifdef ENABLE_TREE_CHECKING
1514 #ifdef ENABLE_TREE_CHECKING
1517 gcc_assert (p != q);
1525 /* Returns the number of FIELD_DECLs in TYPE. */
1528 fields_length (tree type)
1530 tree t = TYPE_FIELDS (type);
1533 for (; t; t = TREE_CHAIN (t))
1534 if (TREE_CODE (t) == FIELD_DECL)
1540 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1541 by modifying the last node in chain 1 to point to chain 2.
1542 This is the Lisp primitive `nconc'. */
1545 chainon (tree op1, tree op2)
1554 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1556 TREE_CHAIN (t1) = op2;
1558 #ifdef ENABLE_TREE_CHECKING
1561 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1562 gcc_assert (t2 != t1);
1569 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1572 tree_last (tree chain)
1576 while ((next = TREE_CHAIN (chain)))
1581 /* Reverse the order of elements in the chain T,
1582 and return the new head of the chain (old last element). */
1587 tree prev = 0, decl, next;
1588 for (decl = t; decl; decl = next)
1590 next = TREE_CHAIN (decl);
1591 TREE_CHAIN (decl) = prev;
1597 /* Return a newly created TREE_LIST node whose
1598 purpose and value fields are PARM and VALUE. */
1601 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1603 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1604 TREE_PURPOSE (t) = parm;
1605 TREE_VALUE (t) = value;
1609 /* Return a newly created TREE_LIST node whose
1610 purpose and value fields are PURPOSE and VALUE
1611 and whose TREE_CHAIN is CHAIN. */
1614 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1618 node = ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
1620 memset (node, 0, sizeof (struct tree_common));
1622 #ifdef GATHER_STATISTICS
1623 tree_node_counts[(int) x_kind]++;
1624 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1627 TREE_SET_CODE (node, TREE_LIST);
1628 TREE_CHAIN (node) = chain;
1629 TREE_PURPOSE (node) = purpose;
1630 TREE_VALUE (node) = value;
1635 /* Return the size nominally occupied by an object of type TYPE
1636 when it resides in memory. The value is measured in units of bytes,
1637 and its data type is that normally used for type sizes
1638 (which is the first type created by make_signed_type or
1639 make_unsigned_type). */
1642 size_in_bytes (tree type)
1646 if (type == error_mark_node)
1647 return integer_zero_node;
1649 type = TYPE_MAIN_VARIANT (type);
1650 t = TYPE_SIZE_UNIT (type);
1654 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1655 return size_zero_node;
1658 if (TREE_CODE (t) == INTEGER_CST)
1659 t = force_fit_type (t, 0, false, false);
1664 /* Return the size of TYPE (in bytes) as a wide integer
1665 or return -1 if the size can vary or is larger than an integer. */
1668 int_size_in_bytes (tree type)
1672 if (type == error_mark_node)
1675 type = TYPE_MAIN_VARIANT (type);
1676 t = TYPE_SIZE_UNIT (type);
1678 || TREE_CODE (t) != INTEGER_CST
1679 || TREE_OVERFLOW (t)
1680 || TREE_INT_CST_HIGH (t) != 0
1681 /* If the result would appear negative, it's too big to represent. */
1682 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1685 return TREE_INT_CST_LOW (t);
1688 /* Return the bit position of FIELD, in bits from the start of the record.
1689 This is a tree of type bitsizetype. */
1692 bit_position (tree field)
1694 return bit_from_pos (DECL_FIELD_OFFSET (field),
1695 DECL_FIELD_BIT_OFFSET (field));
1698 /* Likewise, but return as an integer. It must be representable in
1699 that way (since it could be a signed value, we don't have the
1700 option of returning -1 like int_size_in_byte can. */
1703 int_bit_position (tree field)
1705 return tree_low_cst (bit_position (field), 0);
1708 /* Return the byte position of FIELD, in bytes from the start of the record.
1709 This is a tree of type sizetype. */
1712 byte_position (tree field)
1714 return byte_from_pos (DECL_FIELD_OFFSET (field),
1715 DECL_FIELD_BIT_OFFSET (field));
1718 /* Likewise, but return as an integer. It must be representable in
1719 that way (since it could be a signed value, we don't have the
1720 option of returning -1 like int_size_in_byte can. */
1723 int_byte_position (tree field)
1725 return tree_low_cst (byte_position (field), 0);
1728 /* Return the strictest alignment, in bits, that T is known to have. */
1733 unsigned int align0, align1;
1735 switch (TREE_CODE (t))
1737 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1738 /* If we have conversions, we know that the alignment of the
1739 object must meet each of the alignments of the types. */
1740 align0 = expr_align (TREE_OPERAND (t, 0));
1741 align1 = TYPE_ALIGN (TREE_TYPE (t));
1742 return MAX (align0, align1);
1744 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1745 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1746 case CLEANUP_POINT_EXPR:
1747 /* These don't change the alignment of an object. */
1748 return expr_align (TREE_OPERAND (t, 0));
1751 /* The best we can do is say that the alignment is the least aligned
1753 align0 = expr_align (TREE_OPERAND (t, 1));
1754 align1 = expr_align (TREE_OPERAND (t, 2));
1755 return MIN (align0, align1);
1757 case LABEL_DECL: case CONST_DECL:
1758 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1759 if (DECL_ALIGN (t) != 0)
1760 return DECL_ALIGN (t);
1764 return FUNCTION_BOUNDARY;
1770 /* Otherwise take the alignment from that of the type. */
1771 return TYPE_ALIGN (TREE_TYPE (t));
1774 /* Return, as a tree node, the number of elements for TYPE (which is an
1775 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1778 array_type_nelts (tree type)
1780 tree index_type, min, max;
1782 /* If they did it with unspecified bounds, then we should have already
1783 given an error about it before we got here. */
1784 if (! TYPE_DOMAIN (type))
1785 return error_mark_node;
1787 index_type = TYPE_DOMAIN (type);
1788 min = TYPE_MIN_VALUE (index_type);
1789 max = TYPE_MAX_VALUE (index_type);
1791 return (integer_zerop (min)
1793 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
1796 /* If arg is static -- a reference to an object in static storage -- then
1797 return the object. This is not the same as the C meaning of `static'.
1798 If arg isn't static, return NULL. */
1803 switch (TREE_CODE (arg))
1806 /* Nested functions are static, even though taking their address will
1807 involve a trampoline as we unnest the nested function and create
1808 the trampoline on the tree level. */
1812 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1813 && ! DECL_THREAD_LOCAL_P (arg)
1814 && ! DECL_DLLIMPORT_P (arg)
1818 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1822 return TREE_STATIC (arg) ? arg : NULL;
1829 /* If the thing being referenced is not a field, then it is
1830 something language specific. */
1831 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
1832 return (*lang_hooks.staticp) (arg);
1834 /* If we are referencing a bitfield, we can't evaluate an
1835 ADDR_EXPR at compile time and so it isn't a constant. */
1836 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
1839 return staticp (TREE_OPERAND (arg, 0));
1844 case MISALIGNED_INDIRECT_REF:
1845 case ALIGN_INDIRECT_REF:
1847 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
1850 case ARRAY_RANGE_REF:
1851 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1852 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1853 return staticp (TREE_OPERAND (arg, 0));
1858 if ((unsigned int) TREE_CODE (arg)
1859 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1860 return lang_hooks.staticp (arg);
1866 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1867 Do this to any expression which may be used in more than one place,
1868 but must be evaluated only once.
1870 Normally, expand_expr would reevaluate the expression each time.
1871 Calling save_expr produces something that is evaluated and recorded
1872 the first time expand_expr is called on it. Subsequent calls to
1873 expand_expr just reuse the recorded value.
1875 The call to expand_expr that generates code that actually computes
1876 the value is the first call *at compile time*. Subsequent calls
1877 *at compile time* generate code to use the saved value.
1878 This produces correct result provided that *at run time* control
1879 always flows through the insns made by the first expand_expr
1880 before reaching the other places where the save_expr was evaluated.
1881 You, the caller of save_expr, must make sure this is so.
1883 Constants, and certain read-only nodes, are returned with no
1884 SAVE_EXPR because that is safe. Expressions containing placeholders
1885 are not touched; see tree.def for an explanation of what these
1889 save_expr (tree expr)
1891 tree t = fold (expr);
1894 /* If the tree evaluates to a constant, then we don't want to hide that
1895 fact (i.e. this allows further folding, and direct checks for constants).
1896 However, a read-only object that has side effects cannot be bypassed.
1897 Since it is no problem to reevaluate literals, we just return the
1899 inner = skip_simple_arithmetic (t);
1901 if (TREE_INVARIANT (inner)
1902 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1903 || TREE_CODE (inner) == SAVE_EXPR
1904 || TREE_CODE (inner) == ERROR_MARK)
1907 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1908 it means that the size or offset of some field of an object depends on
1909 the value within another field.
1911 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1912 and some variable since it would then need to be both evaluated once and
1913 evaluated more than once. Front-ends must assure this case cannot
1914 happen by surrounding any such subexpressions in their own SAVE_EXPR
1915 and forcing evaluation at the proper time. */
1916 if (contains_placeholder_p (inner))
1919 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
1921 /* This expression might be placed ahead of a jump to ensure that the
1922 value was computed on both sides of the jump. So make sure it isn't
1923 eliminated as dead. */
1924 TREE_SIDE_EFFECTS (t) = 1;
1925 TREE_INVARIANT (t) = 1;
1929 /* Look inside EXPR and into any simple arithmetic operations. Return
1930 the innermost non-arithmetic node. */
1933 skip_simple_arithmetic (tree expr)
1937 /* We don't care about whether this can be used as an lvalue in this
1939 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
1940 expr = TREE_OPERAND (expr, 0);
1942 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1943 a constant, it will be more efficient to not make another SAVE_EXPR since
1944 it will allow better simplification and GCSE will be able to merge the
1945 computations if they actually occur. */
1949 if (UNARY_CLASS_P (inner))
1950 inner = TREE_OPERAND (inner, 0);
1951 else if (BINARY_CLASS_P (inner))
1953 if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
1954 inner = TREE_OPERAND (inner, 0);
1955 else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
1956 inner = TREE_OPERAND (inner, 1);
1967 /* Return which tree structure is used by T. */
1969 enum tree_node_structure_enum
1970 tree_node_structure (tree t)
1972 enum tree_code code = TREE_CODE (t);
1974 switch (TREE_CODE_CLASS (code))
1976 case tcc_declaration:
1981 return TS_FIELD_DECL;
1983 return TS_PARM_DECL;
1987 return TS_LABEL_DECL;
1989 return TS_RESULT_DECL;
1991 return TS_CONST_DECL;
1993 return TS_TYPE_DECL;
1995 return TS_FUNCTION_DECL;
1996 case TYPE_MEMORY_TAG:
1997 case NAME_MEMORY_TAG:
1998 case STRUCT_FIELD_TAG:
1999 return TS_MEMORY_TAG;
2001 return TS_DECL_NON_COMMON;
2007 case tcc_comparison:
2010 case tcc_expression:
2013 default: /* tcc_constant and tcc_exceptional */
2018 /* tcc_constant cases. */
2019 case INTEGER_CST: return TS_INT_CST;
2020 case REAL_CST: return TS_REAL_CST;
2021 case COMPLEX_CST: return TS_COMPLEX;
2022 case VECTOR_CST: return TS_VECTOR;
2023 case STRING_CST: return TS_STRING;
2024 /* tcc_exceptional cases. */
2025 case ERROR_MARK: return TS_COMMON;
2026 case IDENTIFIER_NODE: return TS_IDENTIFIER;
2027 case TREE_LIST: return TS_LIST;
2028 case TREE_VEC: return TS_VEC;
2029 case PHI_NODE: return TS_PHI_NODE;
2030 case SSA_NAME: return TS_SSA_NAME;
2031 case PLACEHOLDER_EXPR: return TS_COMMON;
2032 case STATEMENT_LIST: return TS_STATEMENT_LIST;
2033 case BLOCK: return TS_BLOCK;
2034 case CONSTRUCTOR: return TS_CONSTRUCTOR;
2035 case TREE_BINFO: return TS_BINFO;
2036 case VALUE_HANDLE: return TS_VALUE_HANDLE;
2043 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2044 or offset that depends on a field within a record. */
2047 contains_placeholder_p (tree exp)
2049 enum tree_code code;
2054 code = TREE_CODE (exp);
2055 if (code == PLACEHOLDER_EXPR)
2058 switch (TREE_CODE_CLASS (code))
2061 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2062 position computations since they will be converted into a
2063 WITH_RECORD_EXPR involving the reference, which will assume
2064 here will be valid. */
2065 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2067 case tcc_exceptional:
2068 if (code == TREE_LIST)
2069 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
2070 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
2075 case tcc_comparison:
2076 case tcc_expression:
2080 /* Ignoring the first operand isn't quite right, but works best. */
2081 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
2084 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2085 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
2086 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
2089 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
2095 switch (TREE_CODE_LENGTH (code))
2098 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2100 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2101 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
2112 /* Return true if any part of the computation of TYPE involves a
2113 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2114 (for QUAL_UNION_TYPE) and field positions. */
2117 type_contains_placeholder_1 (tree type)
2119 /* If the size contains a placeholder or the parent type (component type in
2120 the case of arrays) type involves a placeholder, this type does. */
2121 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
2122 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
2123 || (TREE_TYPE (type) != 0
2124 && type_contains_placeholder_p (TREE_TYPE (type))))
2127 /* Now do type-specific checks. Note that the last part of the check above
2128 greatly limits what we have to do below. */
2129 switch (TREE_CODE (type))
2138 case REFERENCE_TYPE:
2146 /* Here we just check the bounds. */
2147 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
2148 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
2151 /* We're already checked the component type (TREE_TYPE), so just check
2153 return type_contains_placeholder_p (TYPE_DOMAIN (type));
2157 case QUAL_UNION_TYPE:
2161 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
2162 if (TREE_CODE (field) == FIELD_DECL
2163 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
2164 || (TREE_CODE (type) == QUAL_UNION_TYPE
2165 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
2166 || type_contains_placeholder_p (TREE_TYPE (field))))
2178 type_contains_placeholder_p (tree type)
2182 /* If the contains_placeholder_bits field has been initialized,
2183 then we know the answer. */
2184 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
2185 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
2187 /* Indicate that we've seen this type node, and the answer is false.
2188 This is what we want to return if we run into recursion via fields. */
2189 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
2191 /* Compute the real value. */
2192 result = type_contains_placeholder_1 (type);
2194 /* Store the real value. */
2195 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
2200 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2201 return a tree with all occurrences of references to F in a
2202 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2203 contains only arithmetic expressions or a CALL_EXPR with a
2204 PLACEHOLDER_EXPR occurring only in its arglist. */
2207 substitute_in_expr (tree exp, tree f, tree r)
2209 enum tree_code code = TREE_CODE (exp);
2210 tree op0, op1, op2, op3;
2214 /* We handle TREE_LIST and COMPONENT_REF separately. */
2215 if (code == TREE_LIST)
2217 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
2218 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
2219 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2222 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2224 else if (code == COMPONENT_REF)
2226 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2227 and it is the right field, replace it with R. */
2228 for (inner = TREE_OPERAND (exp, 0);
2229 REFERENCE_CLASS_P (inner);
2230 inner = TREE_OPERAND (inner, 0))
2232 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2233 && TREE_OPERAND (exp, 1) == f)
2236 /* If this expression hasn't been completed let, leave it alone. */
2237 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
2240 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2241 if (op0 == TREE_OPERAND (exp, 0))
2244 new = fold_build3 (COMPONENT_REF, TREE_TYPE (exp),
2245 op0, TREE_OPERAND (exp, 1), NULL_TREE);
2248 switch (TREE_CODE_CLASS (code))
2251 case tcc_declaration:
2254 case tcc_exceptional:
2257 case tcc_comparison:
2258 case tcc_expression:
2260 switch (TREE_CODE_LENGTH (code))
2266 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2267 if (op0 == TREE_OPERAND (exp, 0))
2270 new = fold_build1 (code, TREE_TYPE (exp), op0);
2274 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2275 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2277 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2280 new = fold_build2 (code, TREE_TYPE (exp), op0, op1);
2284 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2285 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2286 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2288 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2289 && op2 == TREE_OPERAND (exp, 2))
2292 new = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2296 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2297 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2298 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2299 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
2301 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2302 && op2 == TREE_OPERAND (exp, 2)
2303 && op3 == TREE_OPERAND (exp, 3))
2306 new = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2318 TREE_READONLY (new) = TREE_READONLY (exp);
2322 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2323 for it within OBJ, a tree that is an object or a chain of references. */
2326 substitute_placeholder_in_expr (tree exp, tree obj)
2328 enum tree_code code = TREE_CODE (exp);
2329 tree op0, op1, op2, op3;
2331 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2332 in the chain of OBJ. */
2333 if (code == PLACEHOLDER_EXPR)
2335 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
2338 for (elt = obj; elt != 0;
2339 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2340 || TREE_CODE (elt) == COND_EXPR)
2341 ? TREE_OPERAND (elt, 1)
2342 : (REFERENCE_CLASS_P (elt)
2343 || UNARY_CLASS_P (elt)
2344 || BINARY_CLASS_P (elt)
2345 || EXPRESSION_CLASS_P (elt))
2346 ? TREE_OPERAND (elt, 0) : 0))
2347 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
2350 for (elt = obj; elt != 0;
2351 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2352 || TREE_CODE (elt) == COND_EXPR)
2353 ? TREE_OPERAND (elt, 1)
2354 : (REFERENCE_CLASS_P (elt)
2355 || UNARY_CLASS_P (elt)
2356 || BINARY_CLASS_P (elt)
2357 || EXPRESSION_CLASS_P (elt))
2358 ? TREE_OPERAND (elt, 0) : 0))
2359 if (POINTER_TYPE_P (TREE_TYPE (elt))
2360 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2362 return fold_build1 (INDIRECT_REF, need_type, elt);
2364 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2365 survives until RTL generation, there will be an error. */
2369 /* TREE_LIST is special because we need to look at TREE_VALUE
2370 and TREE_CHAIN, not TREE_OPERANDS. */
2371 else if (code == TREE_LIST)
2373 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2374 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2375 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2378 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2381 switch (TREE_CODE_CLASS (code))
2384 case tcc_declaration:
2387 case tcc_exceptional:
2390 case tcc_comparison:
2391 case tcc_expression:
2394 switch (TREE_CODE_LENGTH (code))
2400 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2401 if (op0 == TREE_OPERAND (exp, 0))
2404 return fold_build1 (code, TREE_TYPE (exp), op0);
2407 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2408 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2410 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2413 return fold_build2 (code, TREE_TYPE (exp), op0, op1);
2416 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2417 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2418 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2420 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2421 && op2 == TREE_OPERAND (exp, 2))
2424 return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2427 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2428 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2429 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2430 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2432 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2433 && op2 == TREE_OPERAND (exp, 2)
2434 && op3 == TREE_OPERAND (exp, 3))
2437 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2449 /* Stabilize a reference so that we can use it any number of times
2450 without causing its operands to be evaluated more than once.
2451 Returns the stabilized reference. This works by means of save_expr,
2452 so see the caveats in the comments about save_expr.
2454 Also allows conversion expressions whose operands are references.
2455 Any other kind of expression is returned unchanged. */
2458 stabilize_reference (tree ref)
2461 enum tree_code code = TREE_CODE (ref);
2468 /* No action is needed in this case. */
2474 case FIX_TRUNC_EXPR:
2475 case FIX_FLOOR_EXPR:
2476 case FIX_ROUND_EXPR:
2478 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2482 result = build_nt (INDIRECT_REF,
2483 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2487 result = build_nt (COMPONENT_REF,
2488 stabilize_reference (TREE_OPERAND (ref, 0)),
2489 TREE_OPERAND (ref, 1), NULL_TREE);
2493 result = build_nt (BIT_FIELD_REF,
2494 stabilize_reference (TREE_OPERAND (ref, 0)),
2495 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2496 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2500 result = build_nt (ARRAY_REF,
2501 stabilize_reference (TREE_OPERAND (ref, 0)),
2502 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2503 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2506 case ARRAY_RANGE_REF:
2507 result = build_nt (ARRAY_RANGE_REF,
2508 stabilize_reference (TREE_OPERAND (ref, 0)),
2509 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2510 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2514 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2515 it wouldn't be ignored. This matters when dealing with
2517 return stabilize_reference_1 (ref);
2519 /* If arg isn't a kind of lvalue we recognize, make no change.
2520 Caller should recognize the error for an invalid lvalue. */
2525 return error_mark_node;
2528 TREE_TYPE (result) = TREE_TYPE (ref);
2529 TREE_READONLY (result) = TREE_READONLY (ref);
2530 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2531 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2536 /* Subroutine of stabilize_reference; this is called for subtrees of
2537 references. Any expression with side-effects must be put in a SAVE_EXPR
2538 to ensure that it is only evaluated once.
2540 We don't put SAVE_EXPR nodes around everything, because assigning very
2541 simple expressions to temporaries causes us to miss good opportunities
2542 for optimizations. Among other things, the opportunity to fold in the
2543 addition of a constant into an addressing mode often gets lost, e.g.
2544 "y[i+1] += x;". In general, we take the approach that we should not make
2545 an assignment unless we are forced into it - i.e., that any non-side effect
2546 operator should be allowed, and that cse should take care of coalescing
2547 multiple utterances of the same expression should that prove fruitful. */
2550 stabilize_reference_1 (tree e)
2553 enum tree_code code = TREE_CODE (e);
2555 /* We cannot ignore const expressions because it might be a reference
2556 to a const array but whose index contains side-effects. But we can
2557 ignore things that are actual constant or that already have been
2558 handled by this function. */
2560 if (TREE_INVARIANT (e))
2563 switch (TREE_CODE_CLASS (code))
2565 case tcc_exceptional:
2567 case tcc_declaration:
2568 case tcc_comparison:
2570 case tcc_expression:
2572 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2573 so that it will only be evaluated once. */
2574 /* The reference (r) and comparison (<) classes could be handled as
2575 below, but it is generally faster to only evaluate them once. */
2576 if (TREE_SIDE_EFFECTS (e))
2577 return save_expr (e);
2581 /* Constants need no processing. In fact, we should never reach
2586 /* Division is slow and tends to be compiled with jumps,
2587 especially the division by powers of 2 that is often
2588 found inside of an array reference. So do it just once. */
2589 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2590 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2591 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2592 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2593 return save_expr (e);
2594 /* Recursively stabilize each operand. */
2595 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2596 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2600 /* Recursively stabilize each operand. */
2601 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2608 TREE_TYPE (result) = TREE_TYPE (e);
2609 TREE_READONLY (result) = TREE_READONLY (e);
2610 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2611 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2612 TREE_INVARIANT (result) = 1;
2617 /* Low-level constructors for expressions. */
2619 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2620 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2623 recompute_tree_invarant_for_addr_expr (tree t)
2626 bool tc = true, ti = true, se = false;
2628 /* We started out assuming this address is both invariant and constant, but
2629 does not have side effects. Now go down any handled components and see if
2630 any of them involve offsets that are either non-constant or non-invariant.
2631 Also check for side-effects.
2633 ??? Note that this code makes no attempt to deal with the case where
2634 taking the address of something causes a copy due to misalignment. */
2636 #define UPDATE_TITCSE(NODE) \
2637 do { tree _node = (NODE); \
2638 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2639 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2640 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2642 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2643 node = TREE_OPERAND (node, 0))
2645 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2646 array reference (probably made temporarily by the G++ front end),
2647 so ignore all the operands. */
2648 if ((TREE_CODE (node) == ARRAY_REF
2649 || TREE_CODE (node) == ARRAY_RANGE_REF)
2650 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
2652 UPDATE_TITCSE (TREE_OPERAND (node, 1));
2653 if (TREE_OPERAND (node, 2))
2654 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2655 if (TREE_OPERAND (node, 3))
2656 UPDATE_TITCSE (TREE_OPERAND (node, 3));
2658 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2659 FIELD_DECL, apparently. The G++ front end can put something else
2660 there, at least temporarily. */
2661 else if (TREE_CODE (node) == COMPONENT_REF
2662 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
2664 if (TREE_OPERAND (node, 2))
2665 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2667 else if (TREE_CODE (node) == BIT_FIELD_REF)
2668 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2671 node = lang_hooks.expr_to_decl (node, &tc, &ti, &se);
2673 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2674 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2675 invariant and constant if the decl is static. It's also invariant if it's
2676 a decl in the current function. Taking the address of a volatile variable
2677 is not volatile. If it's a constant, the address is both invariant and
2678 constant. Otherwise it's neither. */
2679 if (TREE_CODE (node) == INDIRECT_REF)
2680 UPDATE_TITCSE (TREE_OPERAND (node, 0));
2681 else if (DECL_P (node))
2685 else if (decl_function_context (node) == current_function_decl
2686 /* Addresses of thread-local variables are invariant. */
2687 || (TREE_CODE (node) == VAR_DECL
2688 && DECL_THREAD_LOCAL_P (node)))
2693 else if (CONSTANT_CLASS_P (node))
2698 se |= TREE_SIDE_EFFECTS (node);
2701 TREE_CONSTANT (t) = tc;
2702 TREE_INVARIANT (t) = ti;
2703 TREE_SIDE_EFFECTS (t) = se;
2704 #undef UPDATE_TITCSE
2707 /* Build an expression of code CODE, data type TYPE, and operands as
2708 specified. Expressions and reference nodes can be created this way.
2709 Constants, decls, types and misc nodes cannot be.
2711 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2712 enough for all extant tree codes. */
2715 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
2719 gcc_assert (TREE_CODE_LENGTH (code) == 0);
2721 t = make_node_stat (code PASS_MEM_STAT);
2728 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
2730 int length = sizeof (struct tree_exp);
2731 #ifdef GATHER_STATISTICS
2732 tree_node_kind kind;
2736 #ifdef GATHER_STATISTICS
2737 switch (TREE_CODE_CLASS (code))
2739 case tcc_statement: /* an expression with side effects */
2742 case tcc_reference: /* a reference */
2750 tree_node_counts[(int) kind]++;
2751 tree_node_sizes[(int) kind] += length;
2754 gcc_assert (TREE_CODE_LENGTH (code) == 1);
2756 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
2758 memset (t, 0, sizeof (struct tree_common));
2760 TREE_SET_CODE (t, code);
2762 TREE_TYPE (t) = type;
2763 #ifdef USE_MAPPED_LOCATION
2764 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
2766 SET_EXPR_LOCUS (t, NULL);
2768 TREE_COMPLEXITY (t) = 0;
2769 TREE_OPERAND (t, 0) = node;
2770 TREE_BLOCK (t) = NULL_TREE;
2771 if (node && !TYPE_P (node))
2773 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2774 TREE_READONLY (t) = TREE_READONLY (node);
2777 if (TREE_CODE_CLASS (code) == tcc_statement)
2778 TREE_SIDE_EFFECTS (t) = 1;
2782 /* All of these have side-effects, no matter what their
2784 TREE_SIDE_EFFECTS (t) = 1;
2785 TREE_READONLY (t) = 0;
2788 case MISALIGNED_INDIRECT_REF:
2789 case ALIGN_INDIRECT_REF:
2791 /* Whether a dereference is readonly has nothing to do with whether
2792 its operand is readonly. */
2793 TREE_READONLY (t) = 0;
2798 recompute_tree_invarant_for_addr_expr (t);
2802 if (TREE_CODE_CLASS (code) == tcc_unary
2803 && node && !TYPE_P (node)
2804 && TREE_CONSTANT (node))
2805 TREE_CONSTANT (t) = 1;
2806 if (TREE_CODE_CLASS (code) == tcc_unary
2807 && node && TREE_INVARIANT (node))
2808 TREE_INVARIANT (t) = 1;
2809 if (TREE_CODE_CLASS (code) == tcc_reference
2810 && node && TREE_THIS_VOLATILE (node))
2811 TREE_THIS_VOLATILE (t) = 1;
2818 #define PROCESS_ARG(N) \
2820 TREE_OPERAND (t, N) = arg##N; \
2821 if (arg##N &&!TYPE_P (arg##N)) \
2823 if (TREE_SIDE_EFFECTS (arg##N)) \
2825 if (!TREE_READONLY (arg##N)) \
2827 if (!TREE_CONSTANT (arg##N)) \
2829 if (!TREE_INVARIANT (arg##N)) \
2835 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
2837 bool constant, read_only, side_effects, invariant;
2840 gcc_assert (TREE_CODE_LENGTH (code) == 2);
2842 t = make_node_stat (code PASS_MEM_STAT);
2845 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2846 result based on those same flags for the arguments. But if the
2847 arguments aren't really even `tree' expressions, we shouldn't be trying
2850 /* Expressions without side effects may be constant if their
2851 arguments are as well. */
2852 constant = (TREE_CODE_CLASS (code) == tcc_comparison
2853 || TREE_CODE_CLASS (code) == tcc_binary);
2855 side_effects = TREE_SIDE_EFFECTS (t);
2856 invariant = constant;
2861 TREE_READONLY (t) = read_only;
2862 TREE_CONSTANT (t) = constant;
2863 TREE_INVARIANT (t) = invariant;
2864 TREE_SIDE_EFFECTS (t) = side_effects;
2865 TREE_THIS_VOLATILE (t)
2866 = (TREE_CODE_CLASS (code) == tcc_reference
2867 && arg0 && TREE_THIS_VOLATILE (arg0));
2873 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2874 tree arg2 MEM_STAT_DECL)
2876 bool constant, read_only, side_effects, invariant;
2879 gcc_assert (TREE_CODE_LENGTH (code) == 3);
2881 t = make_node_stat (code PASS_MEM_STAT);
2884 side_effects = TREE_SIDE_EFFECTS (t);
2890 if (code == CALL_EXPR && !side_effects)
2895 /* Calls have side-effects, except those to const or
2897 i = call_expr_flags (t);
2898 if (!(i & (ECF_CONST | ECF_PURE)))
2901 /* And even those have side-effects if their arguments do. */
2902 else for (node = arg1; node; node = TREE_CHAIN (node))
2903 if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
2910 TREE_SIDE_EFFECTS (t) = side_effects;
2911 TREE_THIS_VOLATILE (t)
2912 = (TREE_CODE_CLASS (code) == tcc_reference
2913 && arg0 && TREE_THIS_VOLATILE (arg0));
2919 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2920 tree arg2, tree arg3 MEM_STAT_DECL)
2922 bool constant, read_only, side_effects, invariant;
2925 gcc_assert (TREE_CODE_LENGTH (code) == 4);
2927 t = make_node_stat (code PASS_MEM_STAT);
2930 side_effects = TREE_SIDE_EFFECTS (t);
2937 TREE_SIDE_EFFECTS (t) = side_effects;
2938 TREE_THIS_VOLATILE (t)
2939 = (TREE_CODE_CLASS (code) == tcc_reference
2940 && arg0 && TREE_THIS_VOLATILE (arg0));
2946 build7_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2947 tree arg2, tree arg3, tree arg4, tree arg5,
2948 tree arg6 MEM_STAT_DECL)
2950 bool constant, read_only, side_effects, invariant;
2953 gcc_assert (code == TARGET_MEM_REF);
2955 t = make_node_stat (code PASS_MEM_STAT);
2958 side_effects = TREE_SIDE_EFFECTS (t);
2968 TREE_SIDE_EFFECTS (t) = side_effects;
2969 TREE_THIS_VOLATILE (t) = 0;
2974 /* Similar except don't specify the TREE_TYPE
2975 and leave the TREE_SIDE_EFFECTS as 0.
2976 It is permissible for arguments to be null,
2977 or even garbage if their values do not matter. */
2980 build_nt (enum tree_code code, ...)
2989 t = make_node (code);
2990 length = TREE_CODE_LENGTH (code);
2992 for (i = 0; i < length; i++)
2993 TREE_OPERAND (t, i) = va_arg (p, tree);
2999 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3000 We do NOT enter this node in any sort of symbol table.
3002 layout_decl is used to set up the decl's storage layout.
3003 Other slots are initialized to 0 or null pointers. */
3006 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
3010 t = make_node_stat (code PASS_MEM_STAT);
3012 /* if (type == error_mark_node)
3013 type = integer_type_node; */
3014 /* That is not done, deliberately, so that having error_mark_node
3015 as the type can suppress useless errors in the use of this variable. */
3017 DECL_NAME (t) = name;
3018 TREE_TYPE (t) = type;
3020 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
3022 else if (code == FUNCTION_DECL)
3023 DECL_MODE (t) = FUNCTION_MODE;
3025 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
3027 /* Set default visibility to whatever the user supplied with
3028 visibility_specified depending on #pragma GCC visibility. */
3029 DECL_VISIBILITY (t) = default_visibility;
3030 DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
3036 /* Builds and returns function declaration with NAME and TYPE. */
3039 build_fn_decl (const char *name, tree type)
3041 tree id = get_identifier (name);
3042 tree decl = build_decl (FUNCTION_DECL, id, type);
3044 DECL_EXTERNAL (decl) = 1;
3045 TREE_PUBLIC (decl) = 1;
3046 DECL_ARTIFICIAL (decl) = 1;
3047 TREE_NOTHROW (decl) = 1;
3053 /* BLOCK nodes are used to represent the structure of binding contours
3054 and declarations, once those contours have been exited and their contents
3055 compiled. This information is used for outputting debugging info. */
3058 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
3060 tree block = make_node (BLOCK);
3062 BLOCK_VARS (block) = vars;
3063 BLOCK_SUBBLOCKS (block) = subblocks;
3064 BLOCK_SUPERCONTEXT (block) = supercontext;
3065 BLOCK_CHAIN (block) = chain;
3069 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
3070 /* ??? gengtype doesn't handle conditionals */
3071 static GTY(()) location_t *last_annotated_node;
3074 #ifdef USE_MAPPED_LOCATION
3077 expand_location (source_location loc)
3079 expanded_location xloc;
3080 if (loc == 0) { xloc.file = NULL; xloc.line = 0; xloc.column = 0; }
3083 const struct line_map *map = linemap_lookup (&line_table, loc);
3084 xloc.file = map->to_file;
3085 xloc.line = SOURCE_LINE (map, loc);
3086 xloc.column = SOURCE_COLUMN (map, loc);
3093 /* Record the exact location where an expression or an identifier were
3097 annotate_with_file_line (tree node, const char *file, int line)
3099 /* Roughly one percent of the calls to this function are to annotate
3100 a node with the same information already attached to that node!
3101 Just return instead of wasting memory. */
3102 if (EXPR_LOCUS (node)
3103 && EXPR_LINENO (node) == line
3104 && (EXPR_FILENAME (node) == file
3105 || !strcmp (EXPR_FILENAME (node), file)))
3107 last_annotated_node = EXPR_LOCUS (node);
3111 /* In heavily macroized code (such as GCC itself) this single
3112 entry cache can reduce the number of allocations by more
3114 if (last_annotated_node
3115 && last_annotated_node->line == line
3116 && (last_annotated_node->file == file
3117 || !strcmp (last_annotated_node->file, file)))
3119 SET_EXPR_LOCUS (node, last_annotated_node);
3123 SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t)));
3124 EXPR_LINENO (node) = line;
3125 EXPR_FILENAME (node) = file;
3126 last_annotated_node = EXPR_LOCUS (node);
3130 annotate_with_locus (tree node, location_t locus)
3132 annotate_with_file_line (node, locus.file, locus.line);
3136 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3140 build_decl_attribute_variant (tree ddecl, tree attribute)
3142 DECL_ATTRIBUTES (ddecl) = attribute;
3146 /* Borrowed from hashtab.c iterative_hash implementation. */
3147 #define mix(a,b,c) \
3149 a -= b; a -= c; a ^= (c>>13); \
3150 b -= c; b -= a; b ^= (a<< 8); \
3151 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3152 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3153 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3154 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3155 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3156 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3157 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3161 /* Produce good hash value combining VAL and VAL2. */
3162 static inline hashval_t
3163 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
3165 /* the golden ratio; an arbitrary value. */
3166 hashval_t a = 0x9e3779b9;
3172 /* Produce good hash value combining PTR and VAL2. */
3173 static inline hashval_t
3174 iterative_hash_pointer (void *ptr, hashval_t val2)
3176 if (sizeof (ptr) == sizeof (hashval_t))
3177 return iterative_hash_hashval_t ((size_t) ptr, val2);
3180 hashval_t a = (hashval_t) (size_t) ptr;
3181 /* Avoid warnings about shifting of more than the width of the type on
3182 hosts that won't execute this path. */
3184 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
3190 /* Produce good hash value combining VAL and VAL2. */
3191 static inline hashval_t
3192 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
3194 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
3195 return iterative_hash_hashval_t (val, val2);
3198 hashval_t a = (hashval_t) val;
3199 /* Avoid warnings about shifting of more than the width of the type on
3200 hosts that won't execute this path. */
3202 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
3204 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
3206 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
3207 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
3214 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3217 Record such modified types already made so we don't make duplicates. */
3220 build_type_attribute_variant (tree ttype, tree attribute)
3222 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
3224 hashval_t hashcode = 0;
3226 enum tree_code code = TREE_CODE (ttype);
3228 ntype = copy_node (ttype);
3230 TYPE_POINTER_TO (ntype) = 0;
3231 TYPE_REFERENCE_TO (ntype) = 0;
3232 TYPE_ATTRIBUTES (ntype) = attribute;
3234 /* Create a new main variant of TYPE. */
3235 TYPE_MAIN_VARIANT (ntype) = ntype;
3236 TYPE_NEXT_VARIANT (ntype) = 0;
3237 set_type_quals (ntype, TYPE_UNQUALIFIED);
3239 hashcode = iterative_hash_object (code, hashcode);
3240 if (TREE_TYPE (ntype))
3241 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
3243 hashcode = attribute_hash_list (attribute, hashcode);
3245 switch (TREE_CODE (ntype))
3248 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
3251 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
3255 hashcode = iterative_hash_object
3256 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
3257 hashcode = iterative_hash_object
3258 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
3262 unsigned int precision = TYPE_PRECISION (ntype);
3263 hashcode = iterative_hash_object (precision, hashcode);
3270 ntype = type_hash_canon (hashcode, ntype);
3271 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
3278 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3281 We try both `text' and `__text__', ATTR may be either one. */
3282 /* ??? It might be a reasonable simplification to require ATTR to be only
3283 `text'. One might then also require attribute lists to be stored in
3284 their canonicalized form. */
3287 is_attribute_with_length_p (const char *attr, int attr_len, tree ident)
3292 if (TREE_CODE (ident) != IDENTIFIER_NODE)
3295 p = IDENTIFIER_POINTER (ident);
3296 ident_len = IDENTIFIER_LENGTH (ident);
3298 if (ident_len == attr_len
3299 && strcmp (attr, p) == 0)
3302 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3305 gcc_assert (attr[1] == '_');
3306 gcc_assert (attr[attr_len - 2] == '_');
3307 gcc_assert (attr[attr_len - 1] == '_');
3308 gcc_assert (attr[1] == '_');
3309 if (ident_len == attr_len - 4
3310 && strncmp (attr + 2, p, attr_len - 4) == 0)
3315 if (ident_len == attr_len + 4
3316 && p[0] == '_' && p[1] == '_'
3317 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
3318 && strncmp (attr, p + 2, attr_len) == 0)
3325 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3328 We try both `text' and `__text__', ATTR may be either one. */
3331 is_attribute_p (const char *attr, tree ident)
3333 return is_attribute_with_length_p (attr, strlen (attr), ident);
3336 /* Given an attribute name and a list of attributes, return a pointer to the
3337 attribute's list element if the attribute is part of the list, or NULL_TREE
3338 if not found. If the attribute appears more than once, this only
3339 returns the first occurrence; the TREE_CHAIN of the return value should
3340 be passed back in if further occurrences are wanted. */
3343 lookup_attribute (const char *attr_name, tree list)
3346 size_t attr_len = strlen (attr_name);
3348 for (l = list; l; l = TREE_CHAIN (l))
3350 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3351 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3358 /* Return an attribute list that is the union of a1 and a2. */
3361 merge_attributes (tree a1, tree a2)
3365 /* Either one unset? Take the set one. */
3367 if ((attributes = a1) == 0)
3370 /* One that completely contains the other? Take it. */
3372 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3374 if (attribute_list_contained (a2, a1))
3378 /* Pick the longest list, and hang on the other list. */
3380 if (list_length (a1) < list_length (a2))
3381 attributes = a2, a2 = a1;
3383 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3386 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3389 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3392 if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
3397 a1 = copy_node (a2);
3398 TREE_CHAIN (a1) = attributes;
3407 /* Given types T1 and T2, merge their attributes and return
3411 merge_type_attributes (tree t1, tree t2)
3413 return merge_attributes (TYPE_ATTRIBUTES (t1),
3414 TYPE_ATTRIBUTES (t2));
3417 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3421 merge_decl_attributes (tree olddecl, tree newdecl)
3423 return merge_attributes (DECL_ATTRIBUTES (olddecl),
3424 DECL_ATTRIBUTES (newdecl));
3427 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3429 /* Specialization of merge_decl_attributes for various Windows targets.
3431 This handles the following situation:
3433 __declspec (dllimport) int foo;
3436 The second instance of `foo' nullifies the dllimport. */
3439 merge_dllimport_decl_attributes (tree old, tree new)
3442 int delete_dllimport_p = 1;
3444 /* What we need to do here is remove from `old' dllimport if it doesn't
3445 appear in `new'. dllimport behaves like extern: if a declaration is
3446 marked dllimport and a definition appears later, then the object
3447 is not dllimport'd. We also remove a `new' dllimport if the old list
3448 contains dllexport: dllexport always overrides dllimport, regardless
3449 of the order of declaration. */
3450 if (!VAR_OR_FUNCTION_DECL_P (new))
3451 delete_dllimport_p = 0;
3452 else if (DECL_DLLIMPORT_P (new)
3453 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
3455 DECL_DLLIMPORT_P (new) = 0;
3456 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
3457 "dllimport ignored", new);
3459 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new))
3461 /* Warn about overriding a symbol that has already been used. eg:
3462 extern int __attribute__ ((dllimport)) foo;
3463 int* bar () {return &foo;}
3466 if (TREE_USED (old))
3468 warning (0, "%q+D redeclared without dllimport attribute "
3469 "after being referenced with dll linkage", new);
3470 /* If we have used a variable's address with dllimport linkage,
3471 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
3472 decl may already have had TREE_INVARIANT and TREE_CONSTANT
3474 We still remove the attribute so that assembler code refers
3475 to '&foo rather than '_imp__foo'. */
3476 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
3477 DECL_DLLIMPORT_P (new) = 1;
3480 /* Let an inline definition silently override the external reference,
3481 but otherwise warn about attribute inconsistency. */
3482 else if (TREE_CODE (new) == VAR_DECL
3483 || !DECL_DECLARED_INLINE_P (new))
3484 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
3485 "previous dllimport ignored", new);
3488 delete_dllimport_p = 0;
3490 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new));
3492 if (delete_dllimport_p)
3495 const size_t attr_len = strlen ("dllimport");
3497 /* Scan the list for dllimport and delete it. */
3498 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
3500 if (is_attribute_with_length_p ("dllimport", attr_len,
3503 if (prev == NULL_TREE)
3506 TREE_CHAIN (prev) = TREE_CHAIN (t);
3515 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
3516 struct attribute_spec.handler. */
3519 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
3524 /* These attributes may apply to structure and union types being created,
3525 but otherwise should pass to the declaration involved. */
3528 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
3529 | (int) ATTR_FLAG_ARRAY_NEXT))
3531 *no_add_attrs = true;
3532 return tree_cons (name, args, NULL_TREE);
3534 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
3536 warning (OPT_Wattributes, "%qs attribute ignored",
3537 IDENTIFIER_POINTER (name));
3538 *no_add_attrs = true;
3544 /* Report error on dllimport ambiguities seen now before they cause
3546 if (is_attribute_p ("dllimport", name))
3548 /* Honor any target-specific overrides. */
3549 if (!targetm.valid_dllimport_attribute_p (node))
3550 *no_add_attrs = true;
3552 else if (TREE_CODE (node) == FUNCTION_DECL
3553 && DECL_DECLARED_INLINE_P (node))
3555 warning (OPT_Wattributes, "inline function %q+D declared as "
3556 " dllimport: attribute ignored", node);
3557 *no_add_attrs = true;
3559 /* Like MS, treat definition of dllimported variables and
3560 non-inlined functions on declaration as syntax errors. */
3561 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
3563 error ("function %q+D definition is marked dllimport", node);
3564 *no_add_attrs = true;
3567 else if (TREE_CODE (node) == VAR_DECL)
3569 if (DECL_INITIAL (node))
3571 error ("variable %q+D definition is marked dllimport",
3573 *no_add_attrs = true;
3576 /* `extern' needn't be specified with dllimport.
3577 Specify `extern' now and hope for the best. Sigh. */
3578 DECL_EXTERNAL (node) = 1;
3579 /* Also, implicitly give dllimport'd variables declared within
3580 a function global scope, unless declared static. */
3581 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
3582 TREE_PUBLIC (node) = 1;
3585 if (*no_add_attrs == false)
3586 DECL_DLLIMPORT_P (node) = 1;
3589 /* Report error if symbol is not accessible at global scope. */
3590 if (!TREE_PUBLIC (node)
3591 && (TREE_CODE (node) == VAR_DECL
3592 || TREE_CODE (node) == FUNCTION_DECL))
3594 error ("external linkage required for symbol %q+D because of "
3595 "%qs attribute", node, IDENTIFIER_POINTER (name));
3596 *no_add_attrs = true;
3602 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
3604 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3605 of the various TYPE_QUAL values. */
3608 set_type_quals (tree type, int type_quals)
3610 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3611 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3612 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3615 /* Returns true iff cand is equivalent to base with type_quals. */
3618 check_qualified_type (tree cand, tree base, int type_quals)
3620 return (TYPE_QUALS (cand) == type_quals
3621 && TYPE_NAME (cand) == TYPE_NAME (base)
3622 /* Apparently this is needed for Objective-C. */
3623 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
3624 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
3625 TYPE_ATTRIBUTES (base)));
3628 /* Return a version of the TYPE, qualified as indicated by the
3629 TYPE_QUALS, if one exists. If no qualified version exists yet,
3630 return NULL_TREE. */
3633 get_qualified_type (tree type, int type_quals)
3637 if (TYPE_QUALS (type) == type_quals)
3640 /* Search the chain of variants to see if there is already one there just
3641 like the one we need to have. If so, use that existing one. We must
3642 preserve the TYPE_NAME, since there is code that depends on this. */
3643 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3644 if (check_qualified_type (t, type, type_quals))
3650 /* Like get_qualified_type, but creates the type if it does not
3651 exist. This function never returns NULL_TREE. */
3654 build_qualified_type (tree type, int type_quals)
3658 /* See if we already have the appropriate qualified variant. */
3659 t = get_qualified_type (type, type_quals);
3661 /* If not, build it. */
3664 t = build_variant_type_copy (type);
3665 set_type_quals (t, type_quals);
3667 /* If it's a pointer type, the new variant points to the same type. */
3668 if (TREE_CODE (type) == POINTER_TYPE)
3670 TYPE_NEXT_PTR_TO (t) = TYPE_NEXT_PTR_TO (type);
3671 TYPE_NEXT_PTR_TO (type) = t;
3674 /* Same for a reference type. */
3675 else if (TREE_CODE (type) == REFERENCE_TYPE)
3677 TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (type);
3678 TYPE_NEXT_REF_TO (type) = t;
3685 /* Create a new distinct copy of TYPE. The new type is made its own
3689 build_distinct_type_copy (tree type)
3691 tree t = copy_node (type);
3693 TYPE_POINTER_TO (t) = 0;
3694 TYPE_REFERENCE_TO (t) = 0;
3696 /* Make it its own variant. */
3697 TYPE_MAIN_VARIANT (t) = t;
3698 TYPE_NEXT_VARIANT (t) = 0;
3703 /* Create a new variant of TYPE, equivalent but distinct.
3704 This is so the caller can modify it. */
3707 build_variant_type_copy (tree type)
3709 tree t, m = TYPE_MAIN_VARIANT (type);
3711 t = build_distinct_type_copy (type);
3713 /* Add the new type to the chain of variants of TYPE. */
3714 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3715 TYPE_NEXT_VARIANT (m) = t;
3716 TYPE_MAIN_VARIANT (t) = m;
3721 /* Return true if the from tree in both tree maps are equal. */
3724 tree_map_eq (const void *va, const void *vb)
3726 const struct tree_map *a = va, *b = vb;
3727 return (a->from == b->from);
3730 /* Hash a from tree in a tree_map. */
3733 tree_map_hash (const void *item)
3735 return (((const struct tree_map *) item)->hash);
3738 /* Return true if this tree map structure is marked for garbage collection
3739 purposes. We simply return true if the from tree is marked, so that this
3740 structure goes away when the from tree goes away. */
3743 tree_map_marked_p (const void *p)
3745 tree from = ((struct tree_map *) p)->from;
3747 return ggc_marked_p (from);
3750 /* Return true if the trees in the tree_int_map *'s VA and VB are equal. */
3753 tree_int_map_eq (const void *va, const void *vb)
3755 const struct tree_int_map *a = va, *b = vb;
3756 return (a->from == b->from);
3759 /* Hash a from tree in the tree_int_map * ITEM. */
3762 tree_int_map_hash (const void *item)
3764 return htab_hash_pointer (((const struct tree_int_map *)item)->from);
3767 /* Return true if this tree int map structure is marked for garbage collection
3768 purposes. We simply return true if the from tree_int_map *P's from tree is marked, so that this
3769 structure goes away when the from tree goes away. */
3772 tree_int_map_marked_p (const void *p)
3774 tree from = ((struct tree_int_map *) p)->from;
3776 return ggc_marked_p (from);
3778 /* Lookup an init priority for FROM, and return it if we find one. */
3781 decl_init_priority_lookup (tree from)
3783 struct tree_int_map *h, in;
3786 h = htab_find_with_hash (init_priority_for_decl,
3787 &in, htab_hash_pointer (from));
3793 /* Insert a mapping FROM->TO in the init priority hashtable. */
3796 decl_init_priority_insert (tree from, unsigned short to)
3798 struct tree_int_map *h;
3801 h = ggc_alloc (sizeof (struct tree_int_map));
3804 loc = htab_find_slot_with_hash (init_priority_for_decl, h,
3805 htab_hash_pointer (from), INSERT);
3806 *(struct tree_int_map **) loc = h;
3809 /* Look up a restrict qualified base decl for FROM. */
3812 decl_restrict_base_lookup (tree from)
3818 h = htab_find_with_hash (restrict_base_for_decl, &in,
3819 htab_hash_pointer (from));
3820 return h ? h->to : NULL_TREE;
3823 /* Record the restrict qualified base TO for FROM. */
3826 decl_restrict_base_insert (tree from, tree to)
3831 h = ggc_alloc (sizeof (struct tree_map));
3832 h->hash = htab_hash_pointer (from);
3835 loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT);
3836 *(struct tree_map **) loc = h;
3839 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
3842 print_debug_expr_statistics (void)
3844 fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
3845 (long) htab_size (debug_expr_for_decl),
3846 (long) htab_elements (debug_expr_for_decl),
3847 htab_collisions (debug_expr_for_decl));
3850 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
3853 print_value_expr_statistics (void)
3855 fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
3856 (long) htab_size (value_expr_for_decl),
3857 (long) htab_elements (value_expr_for_decl),
3858 htab_collisions (value_expr_for_decl));
3861 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
3862 don't print anything if the table is empty. */
3865 print_restrict_base_statistics (void)
3867 if (htab_elements (restrict_base_for_decl) != 0)
3869 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
3870 (long) htab_size (restrict_base_for_decl),
3871 (long) htab_elements (restrict_base_for_decl),
3872 htab_collisions (restrict_base_for_decl));
3875 /* Lookup a debug expression for FROM, and return it if we find one. */
3878 decl_debug_expr_lookup (tree from)
3880 struct tree_map *h, in;
3883 h = htab_find_with_hash (debug_expr_for_decl, &in, htab_hash_pointer (from));
3889 /* Insert a mapping FROM->TO in the debug expression hashtable. */
3892 decl_debug_expr_insert (tree from, tree to)
3897 h = ggc_alloc (sizeof (struct tree_map));
3898 h->hash = htab_hash_pointer (from);
3901 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT);
3902 *(struct tree_map **) loc = h;
3905 /* Lookup a value expression for FROM, and return it if we find one. */
3908 decl_value_expr_lookup (tree from)
3910 struct tree_map *h, in;
3913 h = htab_find_with_hash (value_expr_for_decl, &in, htab_hash_pointer (from));
3919 /* Insert a mapping FROM->TO in the value expression hashtable. */
3922 decl_value_expr_insert (tree from, tree to)
3927 h = ggc_alloc (sizeof (struct tree_map));
3928 h->hash = htab_hash_pointer (from);
3931 loc = htab_find_slot_with_hash (value_expr_for_decl, h, h->hash, INSERT);
3932 *(struct tree_map **) loc = h;
3935 /* Hashing of types so that we don't make duplicates.
3936 The entry point is `type_hash_canon'. */
3938 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3939 with types in the TREE_VALUE slots), by adding the hash codes
3940 of the individual types. */
3943 type_hash_list (tree list, hashval_t hashcode)
3947 for (tail = list; tail; tail = TREE_CHAIN (tail))
3948 if (TREE_VALUE (tail) != error_mark_node)
3949 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
3955 /* These are the Hashtable callback functions. */
3957 /* Returns true iff the types are equivalent. */
3960 type_hash_eq (const void *va, const void *vb)
3962 const struct type_hash *a = va, *b = vb;
3964 /* First test the things that are the same for all types. */
3965 if (a->hash != b->hash
3966 || TREE_CODE (a->type) != TREE_CODE (b->type)
3967 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
3968 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
3969 TYPE_ATTRIBUTES (b->type))
3970 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
3971 || TYPE_MODE (a->type) != TYPE_MODE (b->type))
3974 switch (TREE_CODE (a->type))
3979 case REFERENCE_TYPE:
3983 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
3986 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
3987 && !(TYPE_VALUES (a->type)
3988 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
3989 && TYPE_VALUES (b->type)
3990 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
3991 && type_list_equal (TYPE_VALUES (a->type),
3992 TYPE_VALUES (b->type))))
3995 /* ... fall through ... */
4001 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
4002 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
4003 TYPE_MAX_VALUE (b->type)))
4004 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
4005 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
4006 TYPE_MIN_VALUE (b->type))));
4009 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
4012 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
4013 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
4014 || (TYPE_ARG_TYPES (a->type)
4015 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
4016 && TYPE_ARG_TYPES (b->type)
4017 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
4018 && type_list_equal (TYPE_ARG_TYPES (a->type),
4019 TYPE_ARG_TYPES (b->type)))));
4022 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
4026 case QUAL_UNION_TYPE:
4027 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
4028 || (TYPE_FIELDS (a->type)
4029 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
4030 && TYPE_FIELDS (b->type)
4031 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
4032 && type_list_equal (TYPE_FIELDS (a->type),
4033 TYPE_FIELDS (b->type))));
4036 return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
4037 || (TYPE_ARG_TYPES (a->type)
4038 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
4039 && TYPE_ARG_TYPES (b->type)
4040 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
4041 && type_list_equal (TYPE_ARG_TYPES (a->type),
4042 TYPE_ARG_TYPES (b->type))));
4049 /* Return the cached hash value. */
4052 type_hash_hash (const void *item)
4054 return ((const struct type_hash *) item)->hash;
4057 /* Look in the type hash table for a type isomorphic to TYPE.
4058 If one is found, return it. Otherwise return 0. */
4061 type_hash_lookup (hashval_t hashcode, tree type)
4063 struct type_hash *h, in;
4065 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4066 must call that routine before comparing TYPE_ALIGNs. */
4072 h = htab_find_with_hash (type_hash_table, &in, hashcode);
4078 /* Add an entry to the type-hash-table
4079 for a type TYPE whose hash code is HASHCODE. */
4082 type_hash_add (hashval_t hashcode, tree type)
4084 struct type_hash *h;
4087 h = ggc_alloc (sizeof (struct type_hash));
4090 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
4091 *(struct type_hash **) loc = h;
4094 /* Given TYPE, and HASHCODE its hash code, return the canonical
4095 object for an identical type if one already exists.
4096 Otherwise, return TYPE, and record it as the canonical object.
4098 To use this function, first create a type of the sort you want.
4099 Then compute its hash code from the fields of the type that
4100 make it different from other similar types.
4101 Then call this function and use the value. */
4104 type_hash_canon (unsigned int hashcode, tree type)
4108 /* The hash table only contains main variants, so ensure that's what we're
4110 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
4112 if (!lang_hooks.types.hash_types)
4115 /* See if the type is in the hash table already. If so, return it.
4116 Otherwise, add the type. */
4117 t1 = type_hash_lookup (hashcode, type);
4120 #ifdef GATHER_STATISTICS
4121 tree_node_counts[(int) t_kind]--;
4122 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
4128 type_hash_add (hashcode, type);
4133 /* See if the data pointed to by the type hash table is marked. We consider
4134 it marked if the type is marked or if a debug type number or symbol
4135 table entry has been made for the type. This reduces the amount of
4136 debugging output and eliminates that dependency of the debug output on
4137 the number of garbage collections. */
4140 type_hash_marked_p (const void *p)
4142 tree type = ((struct type_hash *) p)->type;
4144 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
4148 print_type_hash_statistics (void)
4150 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
4151 (long) htab_size (type_hash_table),
4152 (long) htab_elements (type_hash_table),
4153 htab_collisions (type_hash_table));
4156 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4157 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4158 by adding the hash codes of the individual attributes. */
4161 attribute_hash_list (tree list, hashval_t hashcode)
4165 for (tail = list; tail; tail = TREE_CHAIN (tail))
4166 /* ??? Do we want to add in TREE_VALUE too? */
4167 hashcode = iterative_hash_object
4168 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
4172 /* Given two lists of attributes, return true if list l2 is
4173 equivalent to l1. */
4176 attribute_list_equal (tree l1, tree l2)
4178 return attribute_list_contained (l1, l2)
4179 && attribute_list_contained (l2, l1);
4182 /* Given two lists of attributes, return true if list L2 is
4183 completely contained within L1. */
4184 /* ??? This would be faster if attribute names were stored in a canonicalized
4185 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4186 must be used to show these elements are equivalent (which they are). */
4187 /* ??? It's not clear that attributes with arguments will always be handled
4191 attribute_list_contained (tree l1, tree l2)
4195 /* First check the obvious, maybe the lists are identical. */
4199 /* Maybe the lists are similar. */
4200 for (t1 = l1, t2 = l2;
4202 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
4203 && TREE_VALUE (t1) == TREE_VALUE (t2);
4204 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
4206 /* Maybe the lists are equal. */
4207 if (t1 == 0 && t2 == 0)
4210 for (; t2 != 0; t2 = TREE_CHAIN (t2))
4213 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
4215 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
4218 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
4225 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
4232 /* Given two lists of types
4233 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4234 return 1 if the lists contain the same types in the same order.
4235 Also, the TREE_PURPOSEs must match. */
4238 type_list_equal (tree l1, tree l2)
4242 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
4243 if (TREE_VALUE (t1) != TREE_VALUE (t2)
4244 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
4245 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
4246 && (TREE_TYPE (TREE_PURPOSE (t1))
4247 == TREE_TYPE (TREE_PURPOSE (t2))))))
4253 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4254 given by TYPE. If the argument list accepts variable arguments,
4255 then this function counts only the ordinary arguments. */
4258 type_num_arguments (tree type)
4263 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
4264 /* If the function does not take a variable number of arguments,
4265 the last element in the list will have type `void'. */
4266 if (VOID_TYPE_P (TREE_VALUE (t)))
4274 /* Nonzero if integer constants T1 and T2
4275 represent the same constant value. */
4278 tree_int_cst_equal (tree t1, tree t2)
4283 if (t1 == 0 || t2 == 0)
4286 if (TREE_CODE (t1) == INTEGER_CST
4287 && TREE_CODE (t2) == INTEGER_CST
4288 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
4289 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
4295 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4296 The precise way of comparison depends on their data type. */
4299 tree_int_cst_lt (tree t1, tree t2)
4304 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
4306 int t1_sgn = tree_int_cst_sgn (t1);
4307 int t2_sgn = tree_int_cst_sgn (t2);
4309 if (t1_sgn < t2_sgn)
4311 else if (t1_sgn > t2_sgn)
4313 /* Otherwise, both are non-negative, so we compare them as
4314 unsigned just in case one of them would overflow a signed
4317 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
4318 return INT_CST_LT (t1, t2);
4320 return INT_CST_LT_UNSIGNED (t1, t2);
4323 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
4326 tree_int_cst_compare (tree t1, tree t2)
4328 if (tree_int_cst_lt (t1, t2))
4330 else if (tree_int_cst_lt (t2, t1))
4336 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
4337 the host. If POS is zero, the value can be represented in a single
4338 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
4339 be represented in a single unsigned HOST_WIDE_INT. */
4342 host_integerp (tree t, int pos)
4344 return (TREE_CODE (t) == INTEGER_CST
4345 && ! TREE_OVERFLOW (t)
4346 && ((TREE_INT_CST_HIGH (t) == 0
4347 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
4348 || (! pos && TREE_INT_CST_HIGH (t) == -1
4349 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
4350 && !TYPE_UNSIGNED (TREE_TYPE (t)))
4351 || (pos && TREE_INT_CST_HIGH (t) == 0)));
4354 /* Return the HOST_WIDE_INT least significant bits of T if it is an
4355 INTEGER_CST and there is no overflow. POS is nonzero if the result must
4356 be non-negative. We must be able to satisfy the above conditions. */
4359 tree_low_cst (tree t, int pos)
4361 gcc_assert (host_integerp (t, pos));
4362 return TREE_INT_CST_LOW (t);
4365 /* Return the most significant bit of the integer constant T. */
4368 tree_int_cst_msb (tree t)
4372 unsigned HOST_WIDE_INT l;
4374 /* Note that using TYPE_PRECISION here is wrong. We care about the
4375 actual bits, not the (arbitrary) range of the type. */
4376 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
4377 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
4378 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
4379 return (l & 1) == 1;
4382 /* Return an indication of the sign of the integer constant T.
4383 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
4384 Note that -1 will never be returned if T's type is unsigned. */
4387 tree_int_cst_sgn (tree t)
4389 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
4391 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
4393 else if (TREE_INT_CST_HIGH (t) < 0)
4399 /* Compare two constructor-element-type constants. Return 1 if the lists
4400 are known to be equal; otherwise return 0. */
4403 simple_cst_list_equal (tree l1, tree l2)
4405 while (l1 != NULL_TREE && l2 != NULL_TREE)
4407 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
4410 l1 = TREE_CHAIN (l1);
4411 l2 = TREE_CHAIN (l2);
4417 /* Return truthvalue of whether T1 is the same tree structure as T2.
4418 Return 1 if they are the same.
4419 Return 0 if they are understandably different.
4420 Return -1 if either contains tree structure not understood by
4424 simple_cst_equal (tree t1, tree t2)
4426 enum tree_code code1, code2;
4432 if (t1 == 0 || t2 == 0)
4435 code1 = TREE_CODE (t1);
4436 code2 = TREE_CODE (t2);
4438 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
4440 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
4441 || code2 == NON_LVALUE_EXPR)
4442 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4444 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
4447 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
4448 || code2 == NON_LVALUE_EXPR)
4449 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
4457 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
4458 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
4461 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
4464 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
4465 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
4466 TREE_STRING_LENGTH (t1)));
4470 unsigned HOST_WIDE_INT idx;
4471 VEC(constructor_elt, gc) *v1 = CONSTRUCTOR_ELTS (t1);
4472 VEC(constructor_elt, gc) *v2 = CONSTRUCTOR_ELTS (t2);
4474 if (VEC_length (constructor_elt, v1) != VEC_length (constructor_elt, v2))
4477 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
4478 /* ??? Should we handle also fields here? */
4479 if (!simple_cst_equal (VEC_index (constructor_elt, v1, idx)->value,
4480 VEC_index (constructor_elt, v2, idx)->value))
4486 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4489 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4493 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
4496 /* Special case: if either target is an unallocated VAR_DECL,
4497 it means that it's going to be unified with whatever the
4498 TARGET_EXPR is really supposed to initialize, so treat it
4499 as being equivalent to anything. */
4500 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
4501 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
4502 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
4503 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
4504 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
4505 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
4508 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4513 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
4515 case WITH_CLEANUP_EXPR:
4516 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4520 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
4523 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
4524 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4538 /* This general rule works for most tree codes. All exceptions should be
4539 handled above. If this is a language-specific tree code, we can't
4540 trust what might be in the operand, so say we don't know
4542 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
4545 switch (TREE_CODE_CLASS (code1))
4549 case tcc_comparison:
4550 case tcc_expression:
4554 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
4556 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
4568 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
4569 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
4570 than U, respectively. */
4573 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
4575 if (tree_int_cst_sgn (t) < 0)
4577 else if (TREE_INT_CST_HIGH (t) != 0)
4579 else if (TREE_INT_CST_LOW (t) == u)
4581 else if (TREE_INT_CST_LOW (t) < u)
4587 /* Return true if CODE represents an associative tree code. Otherwise
4590 associative_tree_code (enum tree_code code)
4609 /* Return true if CODE represents a commutative tree code. Otherwise
4612 commutative_tree_code (enum tree_code code)
4625 case UNORDERED_EXPR:
4629 case TRUTH_AND_EXPR:
4630 case TRUTH_XOR_EXPR:
4640 /* Generate a hash value for an expression. This can be used iteratively
4641 by passing a previous result as the "val" argument.
4643 This function is intended to produce the same hash for expressions which
4644 would compare equal using operand_equal_p. */
4647 iterative_hash_expr (tree t, hashval_t val)
4650 enum tree_code code;
4654 return iterative_hash_pointer (t, val);
4656 code = TREE_CODE (t);
4660 /* Alas, constants aren't shared, so we can't rely on pointer
4663 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
4664 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
4667 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
4669 return iterative_hash_hashval_t (val2, val);
4672 return iterative_hash (TREE_STRING_POINTER (t),
4673 TREE_STRING_LENGTH (t), val);
4675 val = iterative_hash_expr (TREE_REALPART (t), val);
4676 return iterative_hash_expr (TREE_IMAGPART (t), val);
4678 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
4682 /* we can just compare by pointer. */
4683 return iterative_hash_pointer (t, val);
4686 /* A list of expressions, for a CALL_EXPR or as the elements of a
4688 for (; t; t = TREE_CHAIN (t))
4689 val = iterative_hash_expr (TREE_VALUE (t), val);
4693 unsigned HOST_WIDE_INT idx;
4695 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
4697 val = iterative_hash_expr (field, val);
4698 val = iterative_hash_expr (value, val);
4703 /* When referring to a built-in FUNCTION_DECL, use the
4704 __builtin__ form. Otherwise nodes that compare equal
4705 according to operand_equal_p might get different
4707 if (DECL_BUILT_IN (t))
4709 val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)],
4713 /* else FALL THROUGH */
4715 class = TREE_CODE_CLASS (code);
4717 if (class == tcc_declaration)
4719 /* Otherwise, we can just compare decls by pointer. */
4720 val = iterative_hash_pointer (t, val);
4724 gcc_assert (IS_EXPR_CODE_CLASS (class));
4726 val = iterative_hash_object (code, val);
4728 /* Don't hash the type, that can lead to having nodes which
4729 compare equal according to operand_equal_p, but which
4730 have different hash codes. */
4731 if (code == NOP_EXPR
4732 || code == CONVERT_EXPR
4733 || code == NON_LVALUE_EXPR)
4735 /* Make sure to include signness in the hash computation. */
4736 val += TYPE_UNSIGNED (TREE_TYPE (t));
4737 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
4740 else if (commutative_tree_code (code))
4742 /* It's a commutative expression. We want to hash it the same
4743 however it appears. We do this by first hashing both operands
4744 and then rehashing based on the order of their independent
4746 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
4747 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
4751 t = one, one = two, two = t;
4753 val = iterative_hash_hashval_t (one, val);
4754 val = iterative_hash_hashval_t (two, val);
4757 for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; --i)
4758 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
4765 /* Constructors for pointer, array and function types.
4766 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
4767 constructed by language-dependent code, not here.) */
4769 /* Construct, lay out and return the type of pointers to TO_TYPE with
4770 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
4771 reference all of memory. If such a type has already been
4772 constructed, reuse it. */
4775 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
4780 if (to_type == error_mark_node)
4781 return error_mark_node;
4783 /* In some cases, languages will have things that aren't a POINTER_TYPE
4784 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
4785 In that case, return that type without regard to the rest of our
4788 ??? This is a kludge, but consistent with the way this function has
4789 always operated and there doesn't seem to be a good way to avoid this
4791 if (TYPE_POINTER_TO (to_type) != 0
4792 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
4793 return TYPE_POINTER_TO (to_type);
4795 /* First, if we already have an unqualified type for pointers to TO_TYPE
4796 and it's the proper mode, use it. */
4797 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
4798 if (TYPE_MODE (t) == mode
4800 && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4803 t = make_node (POINTER_TYPE);
4805 TREE_TYPE (t) = to_type;
4806 TYPE_MODE (t) = mode;
4807 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4808 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
4809 TYPE_POINTER_TO (to_type) = t;
4811 /* Lay out the type. This function has many callers that are concerned
4812 with expression-construction, and this simplifies them all. */
4818 /* By default build pointers in ptr_mode. */
4821 build_pointer_type (tree to_type)
4823 return build_pointer_type_for_mode (to_type, ptr_mode, false);
4826 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
4829 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
4834 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
4835 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
4836 In that case, return that type without regard to the rest of our
4839 ??? This is a kludge, but consistent with the way this function has
4840 always operated and there doesn't seem to be a good way to avoid this
4842 if (TYPE_REFERENCE_TO (to_type) != 0
4843 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
4844 return TYPE_REFERENCE_TO (to_type);
4846 /* First, if we already have an unqualified type for references to TO_TYPE
4847 and it's the proper mode, use it. */
4848 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
4849 if (TYPE_MODE (t) == mode
4851 && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4854 t = make_node (REFERENCE_TYPE);
4856 TREE_TYPE (t) = to_type;
4857 TYPE_MODE (t) = mode;
4858 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4859 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
4860 TYPE_REFERENCE_TO (to_type) = t;
4868 /* Build the node for the type of references-to-TO_TYPE by default
4872 build_reference_type (tree to_type)
4874 return build_reference_type_for_mode (to_type, ptr_mode, false);
4877 /* Build a type that is compatible with t but has no cv quals anywhere
4880 const char *const *const * -> char ***. */
4883 build_type_no_quals (tree t)
4885 switch (TREE_CODE (t))
4888 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4890 TYPE_REF_CAN_ALIAS_ALL (t));
4891 case REFERENCE_TYPE:
4893 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4895 TYPE_REF_CAN_ALIAS_ALL (t));
4897 return TYPE_MAIN_VARIANT (t);
4901 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4902 MAXVAL should be the maximum value in the domain
4903 (one less than the length of the array).
4905 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4906 We don't enforce this limit, that is up to caller (e.g. language front end).
4907 The limit exists because the result is a signed type and we don't handle
4908 sizes that use more than one HOST_WIDE_INT. */
4911 build_index_type (tree maxval)
4913 tree itype = make_node (INTEGER_TYPE);
4915 TREE_TYPE (itype) = sizetype;
4916 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
4917 TYPE_MIN_VALUE (itype) = size_zero_node;
4918 TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
4919 TYPE_MODE (itype) = TYPE_MODE (sizetype);
4920 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
4921 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
4922 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
4923 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
4925 if (host_integerp (maxval, 1))
4926 return type_hash_canon (tree_low_cst (maxval, 1), itype);
4931 /* Builds a signed or unsigned integer type of precision PRECISION.
4932 Used for C bitfields whose precision does not match that of
4933 built-in target types. */
4935 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
4938 tree itype = make_node (INTEGER_TYPE);
4940 TYPE_PRECISION (itype) = precision;
4943 fixup_unsigned_type (itype);
4945 fixup_signed_type (itype);
4947 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
4948 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
4953 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4954 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4955 low bound LOWVAL and high bound HIGHVAL.
4956 if TYPE==NULL_TREE, sizetype is used. */
4959 build_range_type (tree type, tree lowval, tree highval)
4961 tree itype = make_node (INTEGER_TYPE);
4963 TREE_TYPE (itype) = type;
4964 if (type == NULL_TREE)
4967 TYPE_MIN_VALUE (itype) = convert (type, lowval);
4968 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
4970 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
4971 TYPE_MODE (itype) = TYPE_MODE (type);
4972 TYPE_SIZE (itype) = TYPE_SIZE (type);
4973 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
4974 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
4975 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
4977 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
4978 return type_hash_canon (tree_low_cst (highval, 0)
4979 - tree_low_cst (lowval, 0),
4985 /* Just like build_index_type, but takes lowval and highval instead
4986 of just highval (maxval). */
4989 build_index_2_type (tree lowval, tree highval)
4991 return build_range_type (sizetype, lowval, highval);
4994 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4995 and number of elements specified by the range of values of INDEX_TYPE.
4996 If such a type has already been constructed, reuse it. */
4999 build_array_type (tree elt_type, tree index_type)
5002 hashval_t hashcode = 0;
5004 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
5006 error ("arrays of functions are not meaningful");
5007 elt_type = integer_type_node;
5010 t = make_node (ARRAY_TYPE);
5011 TREE_TYPE (t) = elt_type;
5012 TYPE_DOMAIN (t) = index_type;
5014 if (index_type == 0)
5020 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
5021 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
5022 t = type_hash_canon (hashcode, t);
5024 if (!COMPLETE_TYPE_P (t))
5029 /* Return the TYPE of the elements comprising
5030 the innermost dimension of ARRAY. */
5033 get_inner_array_type (tree array)
5035 tree type = TREE_TYPE (array);
5037 while (TREE_CODE (type) == ARRAY_TYPE)
5038 type = TREE_TYPE (type);
5043 /* Construct, lay out and return
5044 the type of functions returning type VALUE_TYPE
5045 given arguments of types ARG_TYPES.
5046 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5047 are data type nodes for the arguments of the function.
5048 If such a type has already been constructed, reuse it. */
5051 build_function_type (tree value_type, tree arg_types)
5054 hashval_t hashcode = 0;
5056 if (TREE_CODE (value_type) == FUNCTION_TYPE)
5058 error ("function return type cannot be function");
5059 value_type = integer_type_node;
5062 /* Make a node of the sort we want. */
5063 t = make_node (FUNCTION_TYPE);
5064 TREE_TYPE (t) = value_type;
5065 TYPE_ARG_TYPES (t) = arg_types;
5067 /* If we already have such a type, use the old one. */
5068 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
5069 hashcode = type_hash_list (arg_types, hashcode);
5070 t = type_hash_canon (hashcode, t);
5072 if (!COMPLETE_TYPE_P (t))
5077 /* Build a function type. The RETURN_TYPE is the type returned by the
5078 function. If additional arguments are provided, they are
5079 additional argument types. The list of argument types must always
5080 be terminated by NULL_TREE. */
5083 build_function_type_list (tree return_type, ...)
5088 va_start (p, return_type);
5090 t = va_arg (p, tree);
5091 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
5092 args = tree_cons (NULL_TREE, t, args);
5094 if (args == NULL_TREE)
5095 args = void_list_node;
5099 args = nreverse (args);
5100 TREE_CHAIN (last) = void_list_node;
5102 args = build_function_type (return_type, args);
5108 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
5109 and ARGTYPES (a TREE_LIST) are the return type and arguments types
5110 for the method. An implicit additional parameter (of type
5111 pointer-to-BASETYPE) is added to the ARGTYPES. */
5114 build_method_type_directly (tree basetype,
5122 /* Make a node of the sort we want. */
5123 t = make_node (METHOD_TYPE);
5125 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
5126 TREE_TYPE (t) = rettype;
5127 ptype = build_pointer_type (basetype);
5129 /* The actual arglist for this function includes a "hidden" argument
5130 which is "this". Put it into the list of argument types. */
5131 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
5132 TYPE_ARG_TYPES (t) = argtypes;
5134 /* If we already have such a type, use the old one. */
5135 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
5136 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
5137 hashcode = type_hash_list (argtypes, hashcode);
5138 t = type_hash_canon (hashcode, t);
5140 if (!COMPLETE_TYPE_P (t))
5146 /* Construct, lay out and return the type of methods belonging to class
5147 BASETYPE and whose arguments and values are described by TYPE.
5148 If that type exists already, reuse it.
5149 TYPE must be a FUNCTION_TYPE node. */
5152 build_method_type (tree basetype, tree type)
5154 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
5156 return build_method_type_directly (basetype,
5158 TYPE_ARG_TYPES (type));
5161 /* Construct, lay out and return the type of offsets to a value
5162 of type TYPE, within an object of type BASETYPE.
5163 If a suitable offset type exists already, reuse it. */
5166 build_offset_type (tree basetype, tree type)
5169 hashval_t hashcode = 0;
5171 /* Make a node of the sort we want. */
5172 t = make_node (OFFSET_TYPE);
5174 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
5175 TREE_TYPE (t) = type;
5177 /* If we already have such a type, use the old one. */
5178 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
5179 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
5180 t = type_hash_canon (hashcode, t);
5182 if (!COMPLETE_TYPE_P (t))
5188 /* Create a complex type whose components are COMPONENT_TYPE. */
5191 build_complex_type (tree component_type)
5196 /* Make a node of the sort we want. */
5197 t = make_node (COMPLEX_TYPE);
5199 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
5201 /* If we already have such a type, use the old one. */
5202 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
5203 t = type_hash_canon (hashcode, t);
5205 if (!COMPLETE_TYPE_P (t))
5208 /* If we are writing Dwarf2 output we need to create a name,
5209 since complex is a fundamental type. */
5210 if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
5214 if (component_type == char_type_node)
5215 name = "complex char";
5216 else if (component_type == signed_char_type_node)
5217 name = "complex signed char";
5218 else if (component_type == unsigned_char_type_node)
5219 name = "complex unsigned char";
5220 else if (component_type == short_integer_type_node)
5221 name = "complex short int";
5222 else if (component_type == short_unsigned_type_node)
5223 name = "complex short unsigned int";
5224 else if (component_type == integer_type_node)
5225 name = "complex int";
5226 else if (component_type == unsigned_type_node)
5227 name = "complex unsigned int";
5228 else if (component_type == long_integer_type_node)
5229 name = "complex long int";
5230 else if (component_type == long_unsigned_type_node)
5231 name = "complex long unsigned int";
5232 else if (component_type == long_long_integer_type_node)
5233 name = "complex long long int";
5234 else if (component_type == long_long_unsigned_type_node)
5235 name = "complex long long unsigned int";
5240 TYPE_NAME (t) = get_identifier (name);
5243 return build_qualified_type (t, TYPE_QUALS (component_type));
5246 /* Return OP, stripped of any conversions to wider types as much as is safe.
5247 Converting the value back to OP's type makes a value equivalent to OP.
5249 If FOR_TYPE is nonzero, we return a value which, if converted to
5250 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
5252 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
5253 narrowest type that can hold the value, even if they don't exactly fit.
5254 Otherwise, bit-field references are changed to a narrower type
5255 only if they can be fetched directly from memory in that type.
5257 OP must have integer, real or enumeral type. Pointers are not allowed!
5259 There are some cases where the obvious value we could return
5260 would regenerate to OP if converted to OP's type,
5261 but would not extend like OP to wider types.
5262 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
5263 For example, if OP is (unsigned short)(signed char)-1,
5264 we avoid returning (signed char)-1 if FOR_TYPE is int,
5265 even though extending that to an unsigned short would regenerate OP,
5266 since the result of extending (signed char)-1 to (int)
5267 is different from (int) OP. */
5270 get_unwidened (tree op, tree for_type)
5272 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
5273 tree type = TREE_TYPE (op);
5275 = TYPE_PRECISION (for_type != 0 ? for_type : type);
5277 = (for_type != 0 && for_type != type
5278 && final_prec > TYPE_PRECISION (type)
5279 && TYPE_UNSIGNED (type));
5282 while (TREE_CODE (op) == NOP_EXPR
5283 || TREE_CODE (op) == CONVERT_EXPR)
5287 /* TYPE_PRECISION on vector types has different meaning
5288 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
5289 so avoid them here. */
5290 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
5293 bitschange = TYPE_PRECISION (TREE_TYPE (op))
5294 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
5296 /* Truncations are many-one so cannot be removed.
5297 Unless we are later going to truncate down even farther. */
5299 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
5302 /* See what's inside this conversion. If we decide to strip it,
5304 op = TREE_OPERAND (op, 0);
5306 /* If we have not stripped any zero-extensions (uns is 0),
5307 we can strip any kind of extension.
5308 If we have previously stripped a zero-extension,
5309 only zero-extensions can safely be stripped.
5310 Any extension can be stripped if the bits it would produce
5311 are all going to be discarded later by truncating to FOR_TYPE. */
5315 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
5317 /* TYPE_UNSIGNED says whether this is a zero-extension.
5318 Let's avoid computing it if it does not affect WIN
5319 and if UNS will not be needed again. */
5321 || TREE_CODE (op) == NOP_EXPR
5322 || TREE_CODE (op) == CONVERT_EXPR)
5323 && TYPE_UNSIGNED (TREE_TYPE (op)))
5331 if (TREE_CODE (op) == COMPONENT_REF
5332 /* Since type_for_size always gives an integer type. */
5333 && TREE_CODE (type) != REAL_TYPE
5334 /* Don't crash if field not laid out yet. */
5335 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
5336 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
5338 unsigned int innerprec
5339 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
5340 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
5341 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
5342 type = lang_hooks.types.type_for_size (innerprec, unsignedp);
5344 /* We can get this structure field in the narrowest type it fits in.
5345 If FOR_TYPE is 0, do this only for a field that matches the
5346 narrower type exactly and is aligned for it
5347 The resulting extension to its nominal type (a fullword type)
5348 must fit the same conditions as for other extensions. */
5351 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
5352 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
5353 && (! uns || final_prec <= innerprec || unsignedp))
5355 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
5356 TREE_OPERAND (op, 1), NULL_TREE);
5357 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
5358 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
5365 /* Return OP or a simpler expression for a narrower value
5366 which can be sign-extended or zero-extended to give back OP.
5367 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
5368 or 0 if the value should be sign-extended. */
5371 get_narrower (tree op, int *unsignedp_ptr)
5376 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
5378 while (TREE_CODE (op) == NOP_EXPR)
5381 = (TYPE_PRECISION (TREE_TYPE (op))
5382 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
5384 /* Truncations are many-one so cannot be removed. */
5388 /* See what's inside this conversion. If we decide to strip it,
5393 op = TREE_OPERAND (op, 0);
5394 /* An extension: the outermost one can be stripped,
5395 but remember whether it is zero or sign extension. */
5397 uns = TYPE_UNSIGNED (TREE_TYPE (op));
5398 /* Otherwise, if a sign extension has been stripped,
5399 only sign extensions can now be stripped;
5400 if a zero extension has been stripped, only zero-extensions. */
5401 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
5405 else /* bitschange == 0 */
5407 /* A change in nominal type can always be stripped, but we must
5408 preserve the unsignedness. */
5410 uns = TYPE_UNSIGNED (TREE_TYPE (op));
5412 op = TREE_OPERAND (op, 0);
5413 /* Keep trying to narrow, but don't assign op to win if it
5414 would turn an integral type into something else. */
5415 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
5422 if (TREE_CODE (op) == COMPONENT_REF
5423 /* Since type_for_size always gives an integer type. */
5424 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
5425 /* Ensure field is laid out already. */
5426 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
5427 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
5429 unsigned HOST_WIDE_INT innerprec
5430 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
5431 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
5432 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
5433 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
5435 /* We can get this structure field in a narrower type that fits it,
5436 but the resulting extension to its nominal type (a fullword type)
5437 must satisfy the same conditions as for other extensions.
5439 Do this only for fields that are aligned (not bit-fields),
5440 because when bit-field insns will be used there is no
5441 advantage in doing this. */
5443 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
5444 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
5445 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
5449 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
5450 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
5451 TREE_OPERAND (op, 1), NULL_TREE);
5452 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
5453 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
5456 *unsignedp_ptr = uns;
5460 /* Nonzero if integer constant C has a value that is permissible
5461 for type TYPE (an INTEGER_TYPE). */
5464 int_fits_type_p (tree c, tree type)
5466 tree type_low_bound = TYPE_MIN_VALUE (type);
5467 tree type_high_bound = TYPE_MAX_VALUE (type);
5468 bool ok_for_low_bound, ok_for_high_bound;
5471 /* If at least one bound of the type is a constant integer, we can check
5472 ourselves and maybe make a decision. If no such decision is possible, but
5473 this type is a subtype, try checking against that. Otherwise, use
5474 force_fit_type, which checks against the precision.
5476 Compute the status for each possibly constant bound, and return if we see
5477 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
5478 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
5479 for "constant known to fit". */
5481 /* Check if C >= type_low_bound. */
5482 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
5484 if (tree_int_cst_lt (c, type_low_bound))
5486 ok_for_low_bound = true;
5489 ok_for_low_bound = false;
5491 /* Check if c <= type_high_bound. */
5492 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
5494 if (tree_int_cst_lt (type_high_bound, c))
5496 ok_for_high_bound = true;
5499 ok_for_high_bound = false;
5501 /* If the constant fits both bounds, the result is known. */
5502 if (ok_for_low_bound && ok_for_high_bound)
5505 /* Perform some generic filtering which may allow making a decision
5506 even if the bounds are not constant. First, negative integers
5507 never fit in unsigned types, */
5508 if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
5511 /* Second, narrower types always fit in wider ones. */
5512 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
5515 /* Third, unsigned integers with top bit set never fit signed types. */
5516 if (! TYPE_UNSIGNED (type)
5517 && TYPE_UNSIGNED (TREE_TYPE (c))
5518 && tree_int_cst_msb (c))
5521 /* If we haven't been able to decide at this point, there nothing more we
5522 can check ourselves here. Look at the base type if we have one and it
5523 has the same precision. */
5524 if (TREE_CODE (type) == INTEGER_TYPE
5525 && TREE_TYPE (type) != 0
5526 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
5527 return int_fits_type_p (c, TREE_TYPE (type));
5529 /* Or to force_fit_type, if nothing else. */
5530 tmp = copy_node (c);
5531 TREE_TYPE (tmp) = type;
5532 tmp = force_fit_type (tmp, -1, false, false);
5533 return TREE_INT_CST_HIGH (tmp) == TREE_INT_CST_HIGH (c)
5534 && TREE_INT_CST_LOW (tmp) == TREE_INT_CST_LOW (c);
5537 /* Subprogram of following function. Called by walk_tree.
5539 Return *TP if it is an automatic variable or parameter of the
5540 function passed in as DATA. */
5543 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
5545 tree fn = (tree) data;
5550 else if (DECL_P (*tp)
5551 && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn))
5557 /* Returns true if T is, contains, or refers to a type with variable
5558 size. If FN is nonzero, only return true if a modifier of the type
5559 or position of FN is a variable or parameter inside FN.
5561 This concept is more general than that of C99 'variably modified types':
5562 in C99, a struct type is never variably modified because a VLA may not
5563 appear as a structure member. However, in GNU C code like:
5565 struct S { int i[f()]; };
5567 is valid, and other languages may define similar constructs. */
5570 variably_modified_type_p (tree type, tree fn)
5574 /* Test if T is either variable (if FN is zero) or an expression containing
5575 a variable in FN. */
5576 #define RETURN_TRUE_IF_VAR(T) \
5577 do { tree _t = (T); \
5578 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
5579 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
5580 return true; } while (0)
5582 if (type == error_mark_node)
5585 /* If TYPE itself has variable size, it is variably modified.
5587 We do not yet have a representation of the C99 '[*]' syntax.
5588 When a representation is chosen, this function should be modified
5589 to test for that case as well. */
5590 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
5591 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type));
5593 switch (TREE_CODE (type))
5596 case REFERENCE_TYPE:
5599 if (variably_modified_type_p (TREE_TYPE (type), fn))
5605 /* If TYPE is a function type, it is variably modified if any of the
5606 parameters or the return type are variably modified. */
5607 if (variably_modified_type_p (TREE_TYPE (type), fn))
5610 for (t = TYPE_ARG_TYPES (type);
5611 t && t != void_list_node;
5613 if (variably_modified_type_p (TREE_VALUE (t), fn))
5622 /* Scalar types are variably modified if their end points
5624 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
5625 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
5630 case QUAL_UNION_TYPE:
5631 /* We can't see if any of the field are variably-modified by the
5632 definition we normally use, since that would produce infinite
5633 recursion via pointers. */
5634 /* This is variably modified if some field's type is. */
5635 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
5636 if (TREE_CODE (t) == FIELD_DECL)
5638 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
5639 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
5640 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
5642 if (TREE_CODE (type) == QUAL_UNION_TYPE)
5643 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
5651 /* The current language may have other cases to check, but in general,
5652 all other types are not variably modified. */
5653 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
5655 #undef RETURN_TRUE_IF_VAR
5658 /* Given a DECL or TYPE, return the scope in which it was declared, or
5659 NULL_TREE if there is no containing scope. */
5662 get_containing_scope (tree t)
5664 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
5667 /* Return the innermost context enclosing DECL that is
5668 a FUNCTION_DECL, or zero if none. */
5671 decl_function_context (tree decl)
5675 if (TREE_CODE (decl) == ERROR_MARK)
5678 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
5679 where we look up the function at runtime. Such functions always take
5680 a first argument of type 'pointer to real context'.
5682 C++ should really be fixed to use DECL_CONTEXT for the real context,
5683 and use something else for the "virtual context". */
5684 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
5687 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5689 context = DECL_CONTEXT (decl);
5691 while (context && TREE_CODE (context) != FUNCTION_DECL)
5693 if (TREE_CODE (context) == BLOCK)
5694 context = BLOCK_SUPERCONTEXT (context);
5696 context = get_containing_scope (context);
5702 /* Return the innermost context enclosing DECL that is
5703 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
5704 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
5707 decl_type_context (tree decl)
5709 tree context = DECL_CONTEXT (decl);
5712 switch (TREE_CODE (context))
5714 case NAMESPACE_DECL:
5715 case TRANSLATION_UNIT_DECL:
5720 case QUAL_UNION_TYPE:
5725 context = DECL_CONTEXT (context);
5729 context = BLOCK_SUPERCONTEXT (context);
5739 /* CALL is a CALL_EXPR. Return the declaration for the function
5740 called, or NULL_TREE if the called function cannot be
5744 get_callee_fndecl (tree call)
5748 /* It's invalid to call this function with anything but a
5750 gcc_assert (TREE_CODE (call) == CALL_EXPR);
5752 /* The first operand to the CALL is the address of the function
5754 addr = TREE_OPERAND (call, 0);
5758 /* If this is a readonly function pointer, extract its initial value. */
5759 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
5760 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
5761 && DECL_INITIAL (addr))
5762 addr = DECL_INITIAL (addr);
5764 /* If the address is just `&f' for some function `f', then we know
5765 that `f' is being called. */
5766 if (TREE_CODE (addr) == ADDR_EXPR
5767 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
5768 return TREE_OPERAND (addr, 0);
5770 /* We couldn't figure out what was being called. Maybe the front
5771 end has some idea. */
5772 return lang_hooks.lang_get_callee_fndecl (call);
5775 /* Print debugging information about tree nodes generated during the compile,
5776 and any language-specific information. */
5779 dump_tree_statistics (void)
5781 #ifdef GATHER_STATISTICS
5783 int total_nodes, total_bytes;
5786 fprintf (stderr, "\n??? tree nodes created\n\n");
5787 #ifdef GATHER_STATISTICS
5788 fprintf (stderr, "Kind Nodes Bytes\n");
5789 fprintf (stderr, "---------------------------------------\n");
5790 total_nodes = total_bytes = 0;
5791 for (i = 0; i < (int) all_kinds; i++)
5793 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
5794 tree_node_counts[i], tree_node_sizes[i]);
5795 total_nodes += tree_node_counts[i];
5796 total_bytes += tree_node_sizes[i];
5798 fprintf (stderr, "---------------------------------------\n");
5799 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
5800 fprintf (stderr, "---------------------------------------\n");
5801 ssanames_print_statistics ();
5802 phinodes_print_statistics ();
5804 fprintf (stderr, "(No per-node statistics)\n");
5806 print_type_hash_statistics ();
5807 print_debug_expr_statistics ();
5808 print_value_expr_statistics ();
5809 print_restrict_base_statistics ();
5810 lang_hooks.print_statistics ();
5813 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
5815 /* Generate a crc32 of a string. */
5818 crc32_string (unsigned chksum, const char *string)
5822 unsigned value = *string << 24;
5825 for (ix = 8; ix--; value <<= 1)
5829 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
5838 /* P is a string that will be used in a symbol. Mask out any characters
5839 that are not valid in that context. */
5842 clean_symbol_name (char *p)
5846 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5849 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5856 /* Generate a name for a function unique to this translation unit.
5857 TYPE is some string to identify the purpose of this function to the
5858 linker or collect2. */
5861 get_file_function_name_long (const char *type)
5867 if (first_global_object_name)
5868 p = first_global_object_name;
5871 /* We don't have anything that we know to be unique to this translation
5872 unit, so use what we do have and throw in some randomness. */
5874 const char *name = weak_global_object_name;
5875 const char *file = main_input_filename;
5880 file = input_filename;
5882 len = strlen (file);
5883 q = alloca (9 * 2 + len + 1);
5884 memcpy (q, file, len + 1);
5885 clean_symbol_name (q);
5887 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
5888 crc32_string (0, flag_random_seed));
5893 buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
5895 /* Set up the name of the file-level functions we may need.
5896 Use a global object (which is already required to be unique over
5897 the program) rather than the file name (which imposes extra
5899 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
5901 return get_identifier (buf);
5904 /* If KIND=='I', return a suitable global initializer (constructor) name.
5905 If KIND=='D', return a suitable global clean-up (destructor) name. */
5908 get_file_function_name (int kind)
5915 return get_file_function_name_long (p);
5918 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5920 /* Complain that the tree code of NODE does not match the expected 0
5921 terminated list of trailing codes. The trailing code list can be
5922 empty, for a more vague error message. FILE, LINE, and FUNCTION
5923 are of the caller. */
5926 tree_check_failed (const tree node, const char *file,
5927 int line, const char *function, ...)
5931 unsigned length = 0;
5934 va_start (args, function);
5935 while ((code = va_arg (args, int)))
5936 length += 4 + strlen (tree_code_name[code]);
5940 va_start (args, function);
5941 length += strlen ("expected ");
5942 buffer = alloca (length);
5944 while ((code = va_arg (args, int)))
5946 const char *prefix = length ? " or " : "expected ";
5948 strcpy (buffer + length, prefix);
5949 length += strlen (prefix);
5950 strcpy (buffer + length, tree_code_name[code]);
5951 length += strlen (tree_code_name[code]);
5956 buffer = (char *)"unexpected node";
5958 internal_error ("tree check: %s, have %s in %s, at %s:%d",
5959 buffer, tree_code_name[TREE_CODE (node)],
5960 function, trim_filename (file), line);
5963 /* Complain that the tree code of NODE does match the expected 0
5964 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5968 tree_not_check_failed (const tree node, const char *file,
5969 int line, const char *function, ...)
5973 unsigned length = 0;
5976 va_start (args, function);
5977 while ((code = va_arg (args, int)))
5978 length += 4 + strlen (tree_code_name[code]);
5980 va_start (args, function);
5981 buffer = alloca (length);
5983 while ((code = va_arg (args, int)))
5987 strcpy (buffer + length, " or ");
5990 strcpy (buffer + length, tree_code_name[code]);
5991 length += strlen (tree_code_name[code]);
5995 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
5996 buffer, tree_code_name[TREE_CODE (node)],
5997 function, trim_filename (file), line);
6000 /* Similar to tree_check_failed, except that we check for a class of tree
6001 code, given in CL. */
6004 tree_class_check_failed (const tree node, const enum tree_code_class cl,
6005 const char *file, int line, const char *function)
6008 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
6009 TREE_CODE_CLASS_STRING (cl),
6010 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
6011 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
6013 #undef DEFTREESTRUCT
6014 #define DEFTREESTRUCT(VAL, NAME) NAME,
6016 static const char *ts_enum_names[] = {
6017 #include "treestruct.def"
6019 #undef DEFTREESTRUCT
6021 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
6023 /* Similar to tree_class_check_failed, except that we check for
6024 whether CODE contains the tree structure identified by EN. */
6027 tree_contains_struct_check_failed (const tree node,
6028 const enum tree_node_structure_enum en,
6029 const char *file, int line,
6030 const char *function)
6033 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
6035 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
6039 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
6040 (dynamically sized) vector. */
6043 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
6044 const char *function)
6047 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
6048 idx + 1, len, function, trim_filename (file), line);
6051 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
6052 (dynamically sized) vector. */
6055 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
6056 const char *function)
6059 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
6060 idx + 1, len, function, trim_filename (file), line);
6063 /* Similar to above, except that the check is for the bounds of the operand
6064 vector of an expression node. */
6067 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
6068 int line, const char *function)
6071 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
6072 idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
6073 function, trim_filename (file), line);
6075 #endif /* ENABLE_TREE_CHECKING */
6077 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
6078 and mapped to the machine mode MODE. Initialize its fields and build
6079 the information necessary for debugging output. */
6082 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
6084 tree t = make_node (VECTOR_TYPE);
6086 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
6087 SET_TYPE_VECTOR_SUBPARTS (t, nunits);
6088 TYPE_MODE (t) = mode;
6089 TYPE_READONLY (t) = TYPE_READONLY (innertype);
6090 TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
6095 tree index = build_int_cst (NULL_TREE, nunits - 1);
6096 tree array = build_array_type (innertype, build_index_type (index));
6097 tree rt = make_node (RECORD_TYPE);
6099 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
6100 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
6102 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
6103 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
6104 the representation type, and we want to find that die when looking up
6105 the vector type. This is most easily achieved by making the TYPE_UID
6107 TYPE_UID (rt) = TYPE_UID (t);
6110 /* Build our main variant, based on the main variant of the inner type. */
6111 if (TYPE_MAIN_VARIANT (innertype) != innertype)
6113 tree innertype_main_variant = TYPE_MAIN_VARIANT (innertype);
6114 unsigned int hash = TYPE_HASH (innertype_main_variant);
6115 TYPE_MAIN_VARIANT (t)
6116 = type_hash_canon (hash, make_vector_type (innertype_main_variant,
6124 make_or_reuse_type (unsigned size, int unsignedp)
6126 if (size == INT_TYPE_SIZE)
6127 return unsignedp ? unsigned_type_node : integer_type_node;
6128 if (size == CHAR_TYPE_SIZE)
6129 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
6130 if (size == SHORT_TYPE_SIZE)
6131 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
6132 if (size == LONG_TYPE_SIZE)
6133 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
6134 if (size == LONG_LONG_TYPE_SIZE)
6135 return (unsignedp ? long_long_unsigned_type_node
6136 : long_long_integer_type_node);
6139 return make_unsigned_type (size);
6141 return make_signed_type (size);
6144 /* Create nodes for all integer types (and error_mark_node) using the sizes
6145 of C datatypes. The caller should call set_sizetype soon after calling
6146 this function to select one of the types as sizetype. */
6149 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
6151 error_mark_node = make_node (ERROR_MARK);
6152 TREE_TYPE (error_mark_node) = error_mark_node;
6154 initialize_sizetypes (signed_sizetype);
6156 /* Define both `signed char' and `unsigned char'. */
6157 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
6158 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
6160 /* Define `char', which is like either `signed char' or `unsigned char'
6161 but not the same as either. */
6164 ? make_signed_type (CHAR_TYPE_SIZE)
6165 : make_unsigned_type (CHAR_TYPE_SIZE));
6167 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
6168 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
6169 integer_type_node = make_signed_type (INT_TYPE_SIZE);
6170 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
6171 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
6172 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
6173 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
6174 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
6176 /* Define a boolean type. This type only represents boolean values but
6177 may be larger than char depending on the value of BOOL_TYPE_SIZE.
6178 Front ends which want to override this size (i.e. Java) can redefine
6179 boolean_type_node before calling build_common_tree_nodes_2. */
6180 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
6181 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
6182 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
6183 TYPE_PRECISION (boolean_type_node) = 1;
6185 /* Fill in the rest of the sized types. Reuse existing type nodes
6187 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
6188 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
6189 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
6190 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
6191 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
6193 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
6194 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
6195 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
6196 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
6197 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
6199 access_public_node = get_identifier ("public");
6200 access_protected_node = get_identifier ("protected");
6201 access_private_node = get_identifier ("private");
6204 /* Call this function after calling build_common_tree_nodes and set_sizetype.
6205 It will create several other common tree nodes. */
6208 build_common_tree_nodes_2 (int short_double)
6210 /* Define these next since types below may used them. */
6211 integer_zero_node = build_int_cst (NULL_TREE, 0);
6212 integer_one_node = build_int_cst (NULL_TREE, 1);
6213 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
6215 size_zero_node = size_int (0);
6216 size_one_node = size_int (1);
6217 bitsize_zero_node = bitsize_int (0);
6218 bitsize_one_node = bitsize_int (1);
6219 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
6221 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
6222 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
6224 void_type_node = make_node (VOID_TYPE);
6225 layout_type (void_type_node);
6227 /* We are not going to have real types in C with less than byte alignment,
6228 so we might as well not have any types that claim to have it. */
6229 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
6230 TYPE_USER_ALIGN (void_type_node) = 0;
6232 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
6233 layout_type (TREE_TYPE (null_pointer_node));
6235 ptr_type_node = build_pointer_type (void_type_node);
6237 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
6238 fileptr_type_node = ptr_type_node;
6240 float_type_node = make_node (REAL_TYPE);
6241 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
6242 layout_type (float_type_node);
6244 double_type_node = make_node (REAL_TYPE);
6246 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
6248 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
6249 layout_type (double_type_node);
6251 long_double_type_node = make_node (REAL_TYPE);
6252 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
6253 layout_type (long_double_type_node);
6255 float_ptr_type_node = build_pointer_type (float_type_node);
6256 double_ptr_type_node = build_pointer_type (double_type_node);
6257 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
6258 integer_ptr_type_node = build_pointer_type (integer_type_node);
6260 complex_integer_type_node = make_node (COMPLEX_TYPE);
6261 TREE_TYPE (complex_integer_type_node) = integer_type_node;
6262 layout_type (complex_integer_type_node);
6264 complex_float_type_node = make_node (COMPLEX_TYPE);
6265 TREE_TYPE (complex_float_type_node) = float_type_node;
6266 layout_type (complex_float_type_node);
6268 complex_double_type_node = make_node (COMPLEX_TYPE);
6269 TREE_TYPE (complex_double_type_node) = double_type_node;
6270 layout_type (complex_double_type_node);
6272 complex_long_double_type_node = make_node (COMPLEX_TYPE);
6273 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
6274 layout_type (complex_long_double_type_node);
6277 tree t = targetm.build_builtin_va_list ();
6279 /* Many back-ends define record types without setting TYPE_NAME.
6280 If we copied the record type here, we'd keep the original
6281 record type without a name. This breaks name mangling. So,
6282 don't copy record types and let c_common_nodes_and_builtins()
6283 declare the type to be __builtin_va_list. */
6284 if (TREE_CODE (t) != RECORD_TYPE)
6285 t = build_variant_type_copy (t);
6287 va_list_type_node = t;
6291 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
6294 local_define_builtin (const char *name, tree type, enum built_in_function code,
6295 const char *library_name, int ecf_flags)
6299 decl = lang_hooks.builtin_function (name, type, code, BUILT_IN_NORMAL,
6300 library_name, NULL_TREE);
6301 if (ecf_flags & ECF_CONST)
6302 TREE_READONLY (decl) = 1;
6303 if (ecf_flags & ECF_PURE)
6304 DECL_IS_PURE (decl) = 1;
6305 if (ecf_flags & ECF_NORETURN)
6306 TREE_THIS_VOLATILE (decl) = 1;
6307 if (ecf_flags & ECF_NOTHROW)
6308 TREE_NOTHROW (decl) = 1;
6309 if (ecf_flags & ECF_MALLOC)
6310 DECL_IS_MALLOC (decl) = 1;
6312 built_in_decls[code] = decl;
6313 implicit_built_in_decls[code] = decl;
6316 /* Call this function after instantiating all builtins that the language
6317 front end cares about. This will build the rest of the builtins that
6318 are relied upon by the tree optimizers and the middle-end. */
6321 build_common_builtin_nodes (void)
6325 if (built_in_decls[BUILT_IN_MEMCPY] == NULL
6326 || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
6328 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
6329 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
6330 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
6331 ftype = build_function_type (ptr_type_node, tmp);
6333 if (built_in_decls[BUILT_IN_MEMCPY] == NULL)
6334 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
6335 "memcpy", ECF_NOTHROW);
6336 if (built_in_decls[BUILT_IN_MEMMOVE] == NULL)
6337 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
6338 "memmove", ECF_NOTHROW);
6341 if (built_in_decls[BUILT_IN_MEMCMP] == NULL)
6343 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
6344 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
6345 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
6346 ftype = build_function_type (integer_type_node, tmp);
6347 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
6348 "memcmp", ECF_PURE | ECF_NOTHROW);
6351 if (built_in_decls[BUILT_IN_MEMSET] == NULL)
6353 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
6354 tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
6355 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
6356 ftype = build_function_type (ptr_type_node, tmp);
6357 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
6358 "memset", ECF_NOTHROW);
6361 if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
6363 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
6364 ftype = build_function_type (ptr_type_node, tmp);
6365 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
6366 "alloca", ECF_NOTHROW | ECF_MALLOC);
6369 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
6370 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
6371 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
6372 ftype = build_function_type (void_type_node, tmp);
6373 local_define_builtin ("__builtin_init_trampoline", ftype,
6374 BUILT_IN_INIT_TRAMPOLINE,
6375 "__builtin_init_trampoline", ECF_NOTHROW);
6377 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
6378 ftype = build_function_type (ptr_type_node, tmp);
6379 local_define_builtin ("__builtin_adjust_trampoline", ftype,
6380 BUILT_IN_ADJUST_TRAMPOLINE,
6381 "__builtin_adjust_trampoline",
6382 ECF_CONST | ECF_NOTHROW);
6384 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
6385 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
6386 ftype = build_function_type (void_type_node, tmp);
6387 local_define_builtin ("__builtin_nonlocal_goto", ftype,
6388 BUILT_IN_NONLOCAL_GOTO,
6389 "__builtin_nonlocal_goto",
6390 ECF_NORETURN | ECF_NOTHROW);
6392 ftype = build_function_type (ptr_type_node, void_list_node);
6393 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
6394 "__builtin_stack_save", ECF_NOTHROW);
6396 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
6397 ftype = build_function_type (void_type_node, tmp);
6398 local_define_builtin ("__builtin_stack_restore", ftype,
6399 BUILT_IN_STACK_RESTORE,
6400 "__builtin_stack_restore", ECF_NOTHROW);
6402 ftype = build_function_type (void_type_node, void_list_node);
6403 local_define_builtin ("__builtin_profile_func_enter", ftype,
6404 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0);
6405 local_define_builtin ("__builtin_profile_func_exit", ftype,
6406 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0);
6408 /* Complex multiplication and division. These are handled as builtins
6409 rather than optabs because emit_library_call_value doesn't support
6410 complex. Further, we can do slightly better with folding these
6411 beasties if the real and complex parts of the arguments are separate. */
6413 enum machine_mode mode;
6415 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
6417 char mode_name_buf[4], *q;
6419 enum built_in_function mcode, dcode;
6420 tree type, inner_type;
6422 type = lang_hooks.types.type_for_mode (mode, 0);
6425 inner_type = TREE_TYPE (type);
6427 tmp = tree_cons (NULL_TREE, inner_type, void_list_node);
6428 tmp = tree_cons (NULL_TREE, inner_type, tmp);
6429 tmp = tree_cons (NULL_TREE, inner_type, tmp);
6430 tmp = tree_cons (NULL_TREE, inner_type, tmp);
6431 ftype = build_function_type (type, tmp);
6433 mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
6434 dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
6436 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
6440 built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL);
6441 local_define_builtin (built_in_names[mcode], ftype, mcode,
6442 built_in_names[mcode], ECF_CONST | ECF_NOTHROW);
6444 built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL);
6445 local_define_builtin (built_in_names[dcode], ftype, dcode,
6446 built_in_names[dcode], ECF_CONST | ECF_NOTHROW);
6451 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
6454 If we requested a pointer to a vector, build up the pointers that
6455 we stripped off while looking for the inner type. Similarly for
6456 return values from functions.
6458 The argument TYPE is the top of the chain, and BOTTOM is the
6459 new type which we will point to. */
6462 reconstruct_complex_type (tree type, tree bottom)
6466 if (POINTER_TYPE_P (type))
6468 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
6469 outer = build_pointer_type (inner);
6471 else if (TREE_CODE (type) == ARRAY_TYPE)
6473 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
6474 outer = build_array_type (inner, TYPE_DOMAIN (type));
6476 else if (TREE_CODE (type) == FUNCTION_TYPE)
6478 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
6479 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
6481 else if (TREE_CODE (type) == METHOD_TYPE)
6484 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
6485 /* The build_method_type_directly() routine prepends 'this' to argument list,
6486 so we must compensate by getting rid of it. */
6487 argtypes = TYPE_ARG_TYPES (type);
6488 outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
6490 TYPE_ARG_TYPES (type));
6491 TYPE_ARG_TYPES (outer) = argtypes;
6496 TYPE_READONLY (outer) = TYPE_READONLY (type);
6497 TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
6502 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
6505 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
6509 switch (GET_MODE_CLASS (mode))
6511 case MODE_VECTOR_INT:
6512 case MODE_VECTOR_FLOAT:
6513 nunits = GET_MODE_NUNITS (mode);
6517 /* Check that there are no leftover bits. */
6518 gcc_assert (GET_MODE_BITSIZE (mode)
6519 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
6521 nunits = GET_MODE_BITSIZE (mode)
6522 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
6529 return make_vector_type (innertype, nunits, mode);
6532 /* Similarly, but takes the inner type and number of units, which must be
6536 build_vector_type (tree innertype, int nunits)
6538 return make_vector_type (innertype, nunits, VOIDmode);
6541 /* Build RESX_EXPR with given REGION_NUMBER. */
6543 build_resx (int region_number)
6546 t = build1 (RESX_EXPR, void_type_node,
6547 build_int_cst (NULL_TREE, region_number));
6551 /* Given an initializer INIT, return TRUE if INIT is zero or some
6552 aggregate of zeros. Otherwise return FALSE. */
6554 initializer_zerop (tree init)
6560 switch (TREE_CODE (init))
6563 return integer_zerop (init);
6566 /* ??? Note that this is not correct for C4X float formats. There,
6567 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
6568 negative exponent. */
6569 return real_zerop (init)
6570 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
6573 return integer_zerop (init)
6574 || (real_zerop (init)
6575 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
6576 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
6579 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
6580 if (!initializer_zerop (TREE_VALUE (elt)))
6586 unsigned HOST_WIDE_INT idx;
6588 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
6589 if (!initializer_zerop (elt))
6600 add_var_to_bind_expr (tree bind_expr, tree var)
6602 BIND_EXPR_VARS (bind_expr)
6603 = chainon (BIND_EXPR_VARS (bind_expr), var);
6604 if (BIND_EXPR_BLOCK (bind_expr))
6605 BLOCK_VARS (BIND_EXPR_BLOCK (bind_expr))
6606 = BIND_EXPR_VARS (bind_expr);
6609 /* Build an empty statement. */
6612 build_empty_stmt (void)
6614 return build1 (NOP_EXPR, void_type_node, size_zero_node);
6618 /* Returns true if it is possible to prove that the index of
6619 an array access REF (an ARRAY_REF expression) falls into the
6623 in_array_bounds_p (tree ref)
6625 tree idx = TREE_OPERAND (ref, 1);
6628 if (TREE_CODE (idx) != INTEGER_CST)
6631 min = array_ref_low_bound (ref);
6632 max = array_ref_up_bound (ref);
6635 || TREE_CODE (min) != INTEGER_CST
6636 || TREE_CODE (max) != INTEGER_CST)
6639 if (tree_int_cst_lt (idx, min)
6640 || tree_int_cst_lt (max, idx))
6646 /* Return true if T (assumed to be a DECL) is a global variable. */
6649 is_global_var (tree t)
6652 return (TREE_STATIC (t) || MTAG_GLOBAL (t));
6654 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
6657 /* Return true if T (assumed to be a DECL) must be assigned a memory
6661 needs_to_live_in_memory (tree t)
6663 return (TREE_ADDRESSABLE (t)
6664 || is_global_var (t)
6665 || (TREE_CODE (t) == RESULT_DECL
6666 && aggregate_value_p (t, current_function_decl)));
6669 /* There are situations in which a language considers record types
6670 compatible which have different field lists. Decide if two fields
6671 are compatible. It is assumed that the parent records are compatible. */
6674 fields_compatible_p (tree f1, tree f2)
6676 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
6677 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
6680 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
6681 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
6684 if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
6690 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
6693 find_compatible_field (tree record, tree orig_field)
6697 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
6698 if (TREE_CODE (f) == FIELD_DECL
6699 && fields_compatible_p (f, orig_field))
6702 /* ??? Why isn't this on the main fields list? */
6703 f = TYPE_VFIELD (record);
6704 if (f && TREE_CODE (f) == FIELD_DECL
6705 && fields_compatible_p (f, orig_field))
6708 /* ??? We should abort here, but Java appears to do Bad Things
6709 with inherited fields. */
6713 /* Return value of a constant X. */
6716 int_cst_value (tree x)
6718 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
6719 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
6720 bool negative = ((val >> (bits - 1)) & 1) != 0;
6722 gcc_assert (bits <= HOST_BITS_PER_WIDE_INT);
6725 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
6727 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
6732 /* Returns the greatest common divisor of A and B, which must be
6736 tree_fold_gcd (tree a, tree b)
6739 tree type = TREE_TYPE (a);
6741 gcc_assert (TREE_CODE (a) == INTEGER_CST);
6742 gcc_assert (TREE_CODE (b) == INTEGER_CST);
6744 if (integer_zerop (a))
6747 if (integer_zerop (b))
6750 if (tree_int_cst_sgn (a) == -1)
6751 a = fold_build2 (MULT_EXPR, type, a,
6752 convert (type, integer_minus_one_node));
6754 if (tree_int_cst_sgn (b) == -1)
6755 b = fold_build2 (MULT_EXPR, type, b,
6756 convert (type, integer_minus_one_node));
6760 a_mod_b = fold_build2 (FLOOR_MOD_EXPR, type, a, b);
6762 if (!TREE_INT_CST_LOW (a_mod_b)
6763 && !TREE_INT_CST_HIGH (a_mod_b))
6771 /* Returns unsigned variant of TYPE. */
6774 unsigned_type_for (tree type)
6776 return lang_hooks.types.unsigned_type (type);
6779 /* Returns signed variant of TYPE. */
6782 signed_type_for (tree type)
6784 return lang_hooks.types.signed_type (type);
6787 /* Returns the largest value obtainable by casting something in INNER type to
6791 upper_bound_in_type (tree outer, tree inner)
6793 unsigned HOST_WIDE_INT lo, hi;
6794 unsigned int det = 0;
6795 unsigned oprec = TYPE_PRECISION (outer);
6796 unsigned iprec = TYPE_PRECISION (inner);
6799 /* Compute a unique number for every combination. */
6800 det |= (oprec > iprec) ? 4 : 0;
6801 det |= TYPE_UNSIGNED (outer) ? 2 : 0;
6802 det |= TYPE_UNSIGNED (inner) ? 1 : 0;
6804 /* Determine the exponent to use. */
6809 /* oprec <= iprec, outer: signed, inner: don't care. */
6814 /* oprec <= iprec, outer: unsigned, inner: don't care. */
6818 /* oprec > iprec, outer: signed, inner: signed. */
6822 /* oprec > iprec, outer: signed, inner: unsigned. */
6826 /* oprec > iprec, outer: unsigned, inner: signed. */
6830 /* oprec > iprec, outer: unsigned, inner: unsigned. */
6837 /* Compute 2^^prec - 1. */
6838 if (prec <= HOST_BITS_PER_WIDE_INT)
6841 lo = ((~(unsigned HOST_WIDE_INT) 0)
6842 >> (HOST_BITS_PER_WIDE_INT - prec));
6846 hi = ((~(unsigned HOST_WIDE_INT) 0)
6847 >> (2 * HOST_BITS_PER_WIDE_INT - prec));
6848 lo = ~(unsigned HOST_WIDE_INT) 0;
6851 return build_int_cst_wide (outer, lo, hi);
6854 /* Returns the smallest value obtainable by casting something in INNER type to
6858 lower_bound_in_type (tree outer, tree inner)
6860 unsigned HOST_WIDE_INT lo, hi;
6861 unsigned oprec = TYPE_PRECISION (outer);
6862 unsigned iprec = TYPE_PRECISION (inner);
6864 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
6866 if (TYPE_UNSIGNED (outer)
6867 /* If we are widening something of an unsigned type, OUTER type
6868 contains all values of INNER type. In particular, both INNER
6869 and OUTER types have zero in common. */
6870 || (oprec > iprec && TYPE_UNSIGNED (inner)))
6874 /* If we are widening a signed type to another signed type, we
6875 want to obtain -2^^(iprec-1). If we are keeping the
6876 precision or narrowing to a signed type, we want to obtain
6878 unsigned prec = oprec > iprec ? iprec : oprec;
6880 if (prec <= HOST_BITS_PER_WIDE_INT)
6882 hi = ~(unsigned HOST_WIDE_INT) 0;
6883 lo = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1);
6887 hi = ((~(unsigned HOST_WIDE_INT) 0)
6888 << (prec - HOST_BITS_PER_WIDE_INT - 1));
6893 return build_int_cst_wide (outer, lo, hi);
6896 /* Return nonzero if two operands that are suitable for PHI nodes are
6897 necessarily equal. Specifically, both ARG0 and ARG1 must be either
6898 SSA_NAME or invariant. Note that this is strictly an optimization.
6899 That is, callers of this function can directly call operand_equal_p
6900 and get the same result, only slower. */
6903 operand_equal_for_phi_arg_p (tree arg0, tree arg1)
6907 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
6909 return operand_equal_p (arg0, arg1, 0);
6912 /* Returns number of zeros at the end of binary representation of X.
6914 ??? Use ffs if available? */
6917 num_ending_zeros (tree x)
6919 unsigned HOST_WIDE_INT fr, nfr;
6920 unsigned num, abits;
6921 tree type = TREE_TYPE (x);
6923 if (TREE_INT_CST_LOW (x) == 0)
6925 num = HOST_BITS_PER_WIDE_INT;
6926 fr = TREE_INT_CST_HIGH (x);
6931 fr = TREE_INT_CST_LOW (x);
6934 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
6937 if (nfr << abits == fr)
6944 if (num > TYPE_PRECISION (type))
6945 num = TYPE_PRECISION (type);
6947 return build_int_cst_type (type, num);
6951 #define WALK_SUBTREE(NODE) \
6954 result = walk_tree (&(NODE), func, data, pset); \
6960 /* This is a subroutine of walk_tree that walks field of TYPE that are to
6961 be walked whenever a type is seen in the tree. Rest of operands and return
6962 value are as for walk_tree. */
6965 walk_type_fields (tree type, walk_tree_fn func, void *data,
6966 struct pointer_set_t *pset)
6968 tree result = NULL_TREE;
6970 switch (TREE_CODE (type))
6973 case REFERENCE_TYPE:
6974 /* We have to worry about mutually recursive pointers. These can't
6975 be written in C. They can in Ada. It's pathological, but
6976 there's an ACATS test (c38102a) that checks it. Deal with this
6977 by checking if we're pointing to another pointer, that one
6978 points to another pointer, that one does too, and we have no htab.
6979 If so, get a hash table. We check three levels deep to avoid
6980 the cost of the hash table if we don't need one. */
6981 if (POINTER_TYPE_P (TREE_TYPE (type))
6982 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
6983 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
6986 result = walk_tree_without_duplicates (&TREE_TYPE (type),
6994 /* ... fall through ... */
6997 WALK_SUBTREE (TREE_TYPE (type));
7001 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
7006 WALK_SUBTREE (TREE_TYPE (type));
7010 /* We never want to walk into default arguments. */
7011 for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
7012 WALK_SUBTREE (TREE_VALUE (arg));
7017 /* Don't follow this nodes's type if a pointer for fear that we'll
7018 have infinite recursion. Those types are uninteresting anyway. */
7019 if (!POINTER_TYPE_P (TREE_TYPE (type))
7020 && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE)
7021 WALK_SUBTREE (TREE_TYPE (type));
7022 WALK_SUBTREE (TYPE_DOMAIN (type));
7030 WALK_SUBTREE (TYPE_MIN_VALUE (type));
7031 WALK_SUBTREE (TYPE_MAX_VALUE (type));
7035 WALK_SUBTREE (TREE_TYPE (type));
7036 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
7046 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
7047 called with the DATA and the address of each sub-tree. If FUNC returns a
7048 non-NULL value, the traversal is stopped, and the value returned by FUNC
7049 is returned. If PSET is non-NULL it is used to record the nodes visited,
7050 and to avoid visiting a node more than once. */
7053 walk_tree (tree *tp, walk_tree_fn func, void *data, struct pointer_set_t *pset)
7055 enum tree_code code;
7059 #define WALK_SUBTREE_TAIL(NODE) \
7063 goto tail_recurse; \
7068 /* Skip empty subtrees. */
7072 /* Don't walk the same tree twice, if the user has requested
7073 that we avoid doing so. */
7074 if (pset && pointer_set_insert (pset, *tp))
7077 /* Call the function. */
7079 result = (*func) (tp, &walk_subtrees, data);
7081 /* If we found something, return it. */
7085 code = TREE_CODE (*tp);
7087 /* Even if we didn't, FUNC may have decided that there was nothing
7088 interesting below this point in the tree. */
7091 if (code == TREE_LIST)
7092 /* But we still need to check our siblings. */
7093 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
7098 result = lang_hooks.tree_inlining.walk_subtrees (tp, &walk_subtrees, func,
7100 if (result || ! walk_subtrees)
7103 /* If this is a DECL_EXPR, walk into various fields of the type that it's
7104 defining. We only want to walk into these fields of a type in this
7105 case. Note that decls get walked as part of the processing of a
7108 ??? Precisely which fields of types that we are supposed to walk in
7109 this case vs. the normal case aren't well defined. */
7110 if (code == DECL_EXPR
7111 && TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL
7112 && TREE_CODE (TREE_TYPE (DECL_EXPR_DECL (*tp))) != ERROR_MARK)
7114 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
7116 /* Call the function for the type. See if it returns anything or
7117 doesn't want us to continue. If we are to continue, walk both
7118 the normal fields and those for the declaration case. */
7119 result = (*func) (type_p, &walk_subtrees, data);
7120 if (result || !walk_subtrees)
7123 result = walk_type_fields (*type_p, func, data, pset);
7127 WALK_SUBTREE (TYPE_SIZE (*type_p));
7128 WALK_SUBTREE (TYPE_SIZE_UNIT (*type_p));
7130 /* If this is a record type, also walk the fields. */
7131 if (TREE_CODE (*type_p) == RECORD_TYPE
7132 || TREE_CODE (*type_p) == UNION_TYPE
7133 || TREE_CODE (*type_p) == QUAL_UNION_TYPE)
7137 for (field = TYPE_FIELDS (*type_p); field;
7138 field = TREE_CHAIN (field))
7140 /* We'd like to look at the type of the field, but we can easily
7141 get infinite recursion. So assume it's pointed to elsewhere
7142 in the tree. Also, ignore things that aren't fields. */
7143 if (TREE_CODE (field) != FIELD_DECL)
7146 WALK_SUBTREE (DECL_FIELD_OFFSET (field));
7147 WALK_SUBTREE (DECL_SIZE (field));
7148 WALK_SUBTREE (DECL_SIZE_UNIT (field));
7149 if (TREE_CODE (*type_p) == QUAL_UNION_TYPE)
7150 WALK_SUBTREE (DECL_QUALIFIER (field));
7155 else if (code != SAVE_EXPR
7156 && code != BIND_EXPR
7157 && IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
7161 /* Walk over all the sub-trees of this operand. */
7162 len = TREE_CODE_LENGTH (code);
7163 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
7164 But, we only want to walk once. */
7165 if (code == TARGET_EXPR
7166 && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1))
7169 /* Go through the subtrees. We need to do this in forward order so
7170 that the scope of a FOR_EXPR is handled properly. */
7171 #ifdef DEBUG_WALK_TREE
7172 for (i = 0; i < len; ++i)
7173 WALK_SUBTREE (TREE_OPERAND (*tp, i));
7175 for (i = 0; i < len - 1; ++i)
7176 WALK_SUBTREE (TREE_OPERAND (*tp, i));
7180 /* The common case is that we may tail recurse here. */
7181 if (code != BIND_EXPR
7182 && !TREE_CHAIN (*tp))
7183 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len - 1));
7185 WALK_SUBTREE (TREE_OPERAND (*tp, len - 1));
7190 /* If this is a type, walk the needed fields in the type. */
7191 else if (TYPE_P (*tp))
7193 result = walk_type_fields (*tp, func, data, pset);
7199 /* Not one of the easy cases. We must explicitly go through the
7204 case IDENTIFIER_NODE:
7210 case PLACEHOLDER_EXPR:
7214 /* None of these have subtrees other than those already walked
7219 WALK_SUBTREE (TREE_VALUE (*tp));
7220 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
7225 int len = TREE_VEC_LENGTH (*tp);
7230 /* Walk all elements but the first. */
7232 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
7234 /* Now walk the first one as a tail call. */
7235 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
7239 WALK_SUBTREE (TREE_REALPART (*tp));
7240 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
7244 unsigned HOST_WIDE_INT idx;
7245 constructor_elt *ce;
7248 VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce);
7250 WALK_SUBTREE (ce->value);
7255 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
7260 for (decl = BIND_EXPR_VARS (*tp); decl; decl = TREE_CHAIN (decl))
7262 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
7263 into declarations that are just mentioned, rather than
7264 declared; they don't really belong to this part of the tree.
7265 And, we can see cycles: the initializer for a declaration
7266 can refer to the declaration itself. */
7267 WALK_SUBTREE (DECL_INITIAL (decl));
7268 WALK_SUBTREE (DECL_SIZE (decl));
7269 WALK_SUBTREE (DECL_SIZE_UNIT (decl));
7271 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp));
7274 case STATEMENT_LIST:
7276 tree_stmt_iterator i;
7277 for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
7278 WALK_SUBTREE (*tsi_stmt_ptr (i));
7283 /* ??? This could be a language-defined node. We really should make
7284 a hook for it, but right now just ignore it. */
7289 /* We didn't find what we were looking for. */
7292 #undef WALK_SUBTREE_TAIL
7296 /* Like walk_tree, but does not walk duplicate nodes more than once. */
7299 walk_tree_without_duplicates (tree *tp, walk_tree_fn func, void *data)
7302 struct pointer_set_t *pset;
7304 pset = pointer_set_create ();
7305 result = walk_tree (tp, func, data, pset);
7306 pointer_set_destroy (pset);
7310 #include "gt-tree.h"