1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file contains the low level primitives for operating on tree nodes,
21 including allocation, list operations, interning of identifiers,
22 construction of data type nodes and statement nodes,
23 and construction of type conversion nodes. It also contains
24 tables index by tree code that describe how to take apart
27 It is intended to be language-independent, but occasionally
28 calls language-dependent routines defined (for C) in typecheck.c. */
32 #include "coretypes.h"
39 #include "toplev.h" /* get_random_seed */
42 #include "filenames.h"
45 #include "common/common-target.h"
46 #include "langhooks.h"
47 #include "tree-inline.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
52 #include "gimple-iterator.h"
53 #include "gimple-ssa.h"
55 #include "tree-phinodes.h"
56 #include "tree-ssanames.h"
59 #include "pointer-set.h"
60 #include "tree-pass.h"
61 #include "langhooks-def.h"
62 #include "diagnostic.h"
63 #include "tree-diagnostic.h"
64 #include "tree-pretty-print.h"
69 /* Tree code classes. */
71 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
72 #define END_OF_BASE_TREE_CODES tcc_exceptional,
74 const enum tree_code_class tree_code_type[] = {
75 #include "all-tree.def"
79 #undef END_OF_BASE_TREE_CODES
81 /* Table indexed by tree code giving number of expression
82 operands beyond the fixed part of the node structure.
83 Not used for types or decls. */
85 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
86 #define END_OF_BASE_TREE_CODES 0,
88 const unsigned char tree_code_length[] = {
89 #include "all-tree.def"
93 #undef END_OF_BASE_TREE_CODES
95 /* Names of tree components.
96 Used for printing out the tree and error messages. */
97 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
98 #define END_OF_BASE_TREE_CODES "@dummy",
100 static const char *const tree_code_name[] = {
101 #include "all-tree.def"
105 #undef END_OF_BASE_TREE_CODES
107 /* Each tree code class has an associated string representation.
108 These must correspond to the tree_code_class entries. */
110 const char *const tree_code_class_strings[] =
125 /* obstack.[ch] explicitly declined to prototype this. */
126 extern int _obstack_allocated_p (struct obstack *h, void *obj);
128 /* Statistics-gathering stuff. */
130 static int tree_code_counts[MAX_TREE_CODES];
131 int tree_node_counts[(int) all_kinds];
132 int tree_node_sizes[(int) all_kinds];
134 /* Keep in sync with tree.h:enum tree_node_kind. */
135 static const char * const tree_node_kind_names[] = {
154 /* Unique id for next decl created. */
155 static GTY(()) int next_decl_uid;
156 /* Unique id for next type created. */
157 static GTY(()) int next_type_uid = 1;
158 /* Unique id for next debug decl created. Use negative numbers,
159 to catch erroneous uses. */
160 static GTY(()) int next_debug_decl_uid;
162 /* Since we cannot rehash a type after it is in the table, we have to
163 keep the hash code. */
165 struct GTY(()) type_hash {
170 /* Initial size of the hash table (rounded to next prime). */
171 #define TYPE_HASH_INITIAL_SIZE 1000
173 /* Now here is the hash table. When recording a type, it is added to
174 the slot whose index is the hash code. Note that the hash table is
175 used for several kinds of types (function types, array types and
176 array index range types, for now). While all these live in the
177 same table, they are completely independent, and the hash code is
178 computed differently for each of these. */
180 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
181 htab_t type_hash_table;
183 /* Hash table and temporary node for larger integer const values. */
184 static GTY (()) tree int_cst_node;
185 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
186 htab_t int_cst_hash_table;
188 /* Hash table for optimization flags and target option flags. Use the same
189 hash table for both sets of options. Nodes for building the current
190 optimization and target option nodes. The assumption is most of the time
191 the options created will already be in the hash table, so we avoid
192 allocating and freeing up a node repeatably. */
193 static GTY (()) tree cl_optimization_node;
194 static GTY (()) tree cl_target_option_node;
195 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
196 htab_t cl_option_hash_table;
198 /* General tree->tree mapping structure for use in hash tables. */
201 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map)))
202 htab_t debug_expr_for_decl;
204 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map)))
205 htab_t value_expr_for_decl;
207 static GTY ((if_marked ("tree_vec_map_marked_p"), param_is (struct tree_vec_map)))
208 htab_t debug_args_for_decl;
210 static GTY ((if_marked ("tree_priority_map_marked_p"),
211 param_is (struct tree_priority_map)))
212 htab_t init_priority_for_decl;
214 static void set_type_quals (tree, int);
215 static int type_hash_eq (const void *, const void *);
216 static hashval_t type_hash_hash (const void *);
217 static hashval_t int_cst_hash_hash (const void *);
218 static int int_cst_hash_eq (const void *, const void *);
219 static hashval_t cl_option_hash_hash (const void *);
220 static int cl_option_hash_eq (const void *, const void *);
221 static void print_type_hash_statistics (void);
222 static void print_debug_expr_statistics (void);
223 static void print_value_expr_statistics (void);
224 static int type_hash_marked_p (const void *);
225 static unsigned int type_hash_list (const_tree, hashval_t);
226 static unsigned int attribute_hash_list (const_tree, hashval_t);
227 static bool decls_same_for_odr (tree decl1, tree decl2);
229 tree global_trees[TI_MAX];
230 tree integer_types[itk_none];
232 unsigned char tree_contains_struct[MAX_TREE_CODES][64];
234 /* Number of operands for each OpenMP clause. */
235 unsigned const char omp_clause_num_ops[] =
237 0, /* OMP_CLAUSE_ERROR */
238 1, /* OMP_CLAUSE_PRIVATE */
239 1, /* OMP_CLAUSE_SHARED */
240 1, /* OMP_CLAUSE_FIRSTPRIVATE */
241 2, /* OMP_CLAUSE_LASTPRIVATE */
242 4, /* OMP_CLAUSE_REDUCTION */
243 1, /* OMP_CLAUSE_COPYIN */
244 1, /* OMP_CLAUSE_COPYPRIVATE */
245 2, /* OMP_CLAUSE_LINEAR */
246 2, /* OMP_CLAUSE_ALIGNED */
247 1, /* OMP_CLAUSE_DEPEND */
248 1, /* OMP_CLAUSE_UNIFORM */
249 2, /* OMP_CLAUSE_FROM */
250 2, /* OMP_CLAUSE_TO */
251 2, /* OMP_CLAUSE_MAP */
252 1, /* OMP_CLAUSE__LOOPTEMP_ */
253 1, /* OMP_CLAUSE_IF */
254 1, /* OMP_CLAUSE_NUM_THREADS */
255 1, /* OMP_CLAUSE_SCHEDULE */
256 0, /* OMP_CLAUSE_NOWAIT */
257 0, /* OMP_CLAUSE_ORDERED */
258 0, /* OMP_CLAUSE_DEFAULT */
259 3, /* OMP_CLAUSE_COLLAPSE */
260 0, /* OMP_CLAUSE_UNTIED */
261 1, /* OMP_CLAUSE_FINAL */
262 0, /* OMP_CLAUSE_MERGEABLE */
263 1, /* OMP_CLAUSE_DEVICE */
264 1, /* OMP_CLAUSE_DIST_SCHEDULE */
265 0, /* OMP_CLAUSE_INBRANCH */
266 0, /* OMP_CLAUSE_NOTINBRANCH */
267 1, /* OMP_CLAUSE_NUM_TEAMS */
268 1, /* OMP_CLAUSE_THREAD_LIMIT */
269 0, /* OMP_CLAUSE_PROC_BIND */
270 1, /* OMP_CLAUSE_SAFELEN */
271 1, /* OMP_CLAUSE_SIMDLEN */
272 0, /* OMP_CLAUSE_FOR */
273 0, /* OMP_CLAUSE_PARALLEL */
274 0, /* OMP_CLAUSE_SECTIONS */
275 0, /* OMP_CLAUSE_TASKGROUP */
276 1, /* OMP_CLAUSE__SIMDUID_ */
279 const char * const omp_clause_code_name[] =
324 /* Return the tree node structure used by tree code CODE. */
326 static inline enum tree_node_structure_enum
327 tree_node_structure_for_code (enum tree_code code)
329 switch (TREE_CODE_CLASS (code))
331 case tcc_declaration:
336 return TS_FIELD_DECL;
342 return TS_LABEL_DECL;
344 return TS_RESULT_DECL;
345 case DEBUG_EXPR_DECL:
348 return TS_CONST_DECL;
352 return TS_FUNCTION_DECL;
353 case TRANSLATION_UNIT_DECL:
354 return TS_TRANSLATION_UNIT_DECL;
356 return TS_DECL_NON_COMMON;
360 return TS_TYPE_NON_COMMON;
369 default: /* tcc_constant and tcc_exceptional */
374 /* tcc_constant cases. */
375 case INTEGER_CST: return TS_INT_CST;
376 case REAL_CST: return TS_REAL_CST;
377 case FIXED_CST: return TS_FIXED_CST;
378 case COMPLEX_CST: return TS_COMPLEX;
379 case VECTOR_CST: return TS_VECTOR;
380 case STRING_CST: return TS_STRING;
381 /* tcc_exceptional cases. */
382 case ERROR_MARK: return TS_COMMON;
383 case IDENTIFIER_NODE: return TS_IDENTIFIER;
384 case TREE_LIST: return TS_LIST;
385 case TREE_VEC: return TS_VEC;
386 case SSA_NAME: return TS_SSA_NAME;
387 case PLACEHOLDER_EXPR: return TS_COMMON;
388 case STATEMENT_LIST: return TS_STATEMENT_LIST;
389 case BLOCK: return TS_BLOCK;
390 case CONSTRUCTOR: return TS_CONSTRUCTOR;
391 case TREE_BINFO: return TS_BINFO;
392 case OMP_CLAUSE: return TS_OMP_CLAUSE;
393 case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
394 case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
402 /* Initialize tree_contains_struct to describe the hierarchy of tree
406 initialize_tree_contains_struct (void)
410 for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
413 enum tree_node_structure_enum ts_code;
415 code = (enum tree_code) i;
416 ts_code = tree_node_structure_for_code (code);
418 /* Mark the TS structure itself. */
419 tree_contains_struct[code][ts_code] = 1;
421 /* Mark all the structures that TS is derived from. */
439 case TS_STATEMENT_LIST:
440 MARK_TS_TYPED (code);
444 case TS_DECL_MINIMAL:
450 case TS_OPTIMIZATION:
451 case TS_TARGET_OPTION:
452 MARK_TS_COMMON (code);
455 case TS_TYPE_WITH_LANG_SPECIFIC:
456 MARK_TS_TYPE_COMMON (code);
459 case TS_TYPE_NON_COMMON:
460 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
464 MARK_TS_DECL_MINIMAL (code);
469 MARK_TS_DECL_COMMON (code);
472 case TS_DECL_NON_COMMON:
473 MARK_TS_DECL_WITH_VIS (code);
476 case TS_DECL_WITH_VIS:
480 MARK_TS_DECL_WRTL (code);
484 MARK_TS_DECL_COMMON (code);
488 MARK_TS_DECL_WITH_VIS (code);
492 case TS_FUNCTION_DECL:
493 MARK_TS_DECL_NON_COMMON (code);
496 case TS_TRANSLATION_UNIT_DECL:
497 MARK_TS_DECL_COMMON (code);
505 /* Basic consistency checks for attributes used in fold. */
506 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
507 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
508 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
509 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
510 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
511 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
512 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
513 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
514 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
515 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
516 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
517 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
518 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
519 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
520 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
521 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
522 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
523 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
524 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
525 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
526 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
527 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
528 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
529 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
530 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
531 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
532 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
533 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
534 gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
535 gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
536 gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
537 gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
538 gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
539 gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
540 gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
541 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
542 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
543 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
552 /* Initialize the hash table of types. */
553 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
556 debug_expr_for_decl = htab_create_ggc (512, tree_decl_map_hash,
557 tree_decl_map_eq, 0);
559 value_expr_for_decl = htab_create_ggc (512, tree_decl_map_hash,
560 tree_decl_map_eq, 0);
561 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
562 tree_priority_map_eq, 0);
564 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
565 int_cst_hash_eq, NULL);
567 int_cst_node = make_node (INTEGER_CST);
569 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash,
570 cl_option_hash_eq, NULL);
572 cl_optimization_node = make_node (OPTIMIZATION_NODE);
573 cl_target_option_node = make_node (TARGET_OPTION_NODE);
575 /* Initialize the tree_contains_struct array. */
576 initialize_tree_contains_struct ();
577 lang_hooks.init_ts ();
581 /* The name of the object as the assembler will see it (but before any
582 translations made by ASM_OUTPUT_LABELREF). Often this is the same
583 as DECL_NAME. It is an IDENTIFIER_NODE. */
585 decl_assembler_name (tree decl)
587 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
588 lang_hooks.set_decl_assembler_name (decl);
589 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
592 /* Compute the number of bytes occupied by a tree with code CODE.
593 This function cannot be used for nodes that have variable sizes,
594 including TREE_VEC, STRING_CST, and CALL_EXPR. */
596 tree_code_size (enum tree_code code)
598 switch (TREE_CODE_CLASS (code))
600 case tcc_declaration: /* A decl node */
605 return sizeof (struct tree_field_decl);
607 return sizeof (struct tree_parm_decl);
609 return sizeof (struct tree_var_decl);
611 return sizeof (struct tree_label_decl);
613 return sizeof (struct tree_result_decl);
615 return sizeof (struct tree_const_decl);
617 return sizeof (struct tree_type_decl);
619 return sizeof (struct tree_function_decl);
620 case DEBUG_EXPR_DECL:
621 return sizeof (struct tree_decl_with_rtl);
623 return sizeof (struct tree_decl_non_common);
627 case tcc_type: /* a type node */
628 return sizeof (struct tree_type_non_common);
630 case tcc_reference: /* a reference */
631 case tcc_expression: /* an expression */
632 case tcc_statement: /* an expression with side effects */
633 case tcc_comparison: /* a comparison expression */
634 case tcc_unary: /* a unary arithmetic expression */
635 case tcc_binary: /* a binary arithmetic expression */
636 return (sizeof (struct tree_exp)
637 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
639 case tcc_constant: /* a constant */
642 case INTEGER_CST: return sizeof (struct tree_int_cst);
643 case REAL_CST: return sizeof (struct tree_real_cst);
644 case FIXED_CST: return sizeof (struct tree_fixed_cst);
645 case COMPLEX_CST: return sizeof (struct tree_complex);
646 case VECTOR_CST: return sizeof (struct tree_vector);
647 case STRING_CST: gcc_unreachable ();
649 return lang_hooks.tree_size (code);
652 case tcc_exceptional: /* something random, like an identifier. */
655 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
656 case TREE_LIST: return sizeof (struct tree_list);
659 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
662 case OMP_CLAUSE: gcc_unreachable ();
664 case SSA_NAME: return sizeof (struct tree_ssa_name);
666 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
667 case BLOCK: return sizeof (struct tree_block);
668 case CONSTRUCTOR: return sizeof (struct tree_constructor);
669 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option);
670 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option);
673 return lang_hooks.tree_size (code);
681 /* Compute the number of bytes occupied by NODE. This routine only
682 looks at TREE_CODE, except for those nodes that have variable sizes. */
684 tree_size (const_tree node)
686 const enum tree_code code = TREE_CODE (node);
690 return (offsetof (struct tree_binfo, base_binfos)
692 ::embedded_size (BINFO_N_BASE_BINFOS (node)));
695 return (sizeof (struct tree_vec)
696 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
699 return (sizeof (struct tree_vector)
700 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node)) - 1) * sizeof (tree));
703 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
706 return (sizeof (struct tree_omp_clause)
707 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
711 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
712 return (sizeof (struct tree_exp)
713 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
715 return tree_code_size (code);
719 /* Record interesting allocation statistics for a tree node with CODE
723 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED,
724 size_t length ATTRIBUTE_UNUSED)
726 enum tree_code_class type = TREE_CODE_CLASS (code);
729 if (!GATHER_STATISTICS)
734 case tcc_declaration: /* A decl node */
738 case tcc_type: /* a type node */
742 case tcc_statement: /* an expression with side effects */
746 case tcc_reference: /* a reference */
750 case tcc_expression: /* an expression */
751 case tcc_comparison: /* a comparison expression */
752 case tcc_unary: /* a unary arithmetic expression */
753 case tcc_binary: /* a binary arithmetic expression */
757 case tcc_constant: /* a constant */
761 case tcc_exceptional: /* something random, like an identifier. */
764 case IDENTIFIER_NODE:
777 kind = ssa_name_kind;
789 kind = omp_clause_kind;
806 tree_code_counts[(int) code]++;
807 tree_node_counts[(int) kind]++;
808 tree_node_sizes[(int) kind] += length;
811 /* Allocate and return a new UID from the DECL_UID namespace. */
814 allocate_decl_uid (void)
816 return next_decl_uid++;
819 /* Return a newly allocated node of code CODE. For decl and type
820 nodes, some other fields are initialized. The rest of the node is
821 initialized to zero. This function cannot be used for TREE_VEC or
822 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
824 Achoo! I got a code in the node. */
827 make_node_stat (enum tree_code code MEM_STAT_DECL)
830 enum tree_code_class type = TREE_CODE_CLASS (code);
831 size_t length = tree_code_size (code);
833 record_node_allocation_statistics (code, length);
835 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
836 TREE_SET_CODE (t, code);
841 TREE_SIDE_EFFECTS (t) = 1;
844 case tcc_declaration:
845 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
847 if (code == FUNCTION_DECL)
849 DECL_ALIGN (t) = FUNCTION_BOUNDARY;
850 DECL_MODE (t) = FUNCTION_MODE;
855 DECL_SOURCE_LOCATION (t) = input_location;
856 if (TREE_CODE (t) == DEBUG_EXPR_DECL)
857 DECL_UID (t) = --next_debug_decl_uid;
860 DECL_UID (t) = allocate_decl_uid ();
861 SET_DECL_PT_UID (t, -1);
863 if (TREE_CODE (t) == LABEL_DECL)
864 LABEL_DECL_UID (t) = -1;
869 TYPE_UID (t) = next_type_uid++;
870 TYPE_ALIGN (t) = BITS_PER_UNIT;
871 TYPE_USER_ALIGN (t) = 0;
872 TYPE_MAIN_VARIANT (t) = t;
873 TYPE_CANONICAL (t) = t;
875 /* Default to no attributes for type, but let target change that. */
876 TYPE_ATTRIBUTES (t) = NULL_TREE;
877 targetm.set_default_type_attributes (t);
879 /* We have not yet computed the alias set for this type. */
880 TYPE_ALIAS_SET (t) = -1;
884 TREE_CONSTANT (t) = 1;
893 case PREDECREMENT_EXPR:
894 case PREINCREMENT_EXPR:
895 case POSTDECREMENT_EXPR:
896 case POSTINCREMENT_EXPR:
897 /* All of these have side-effects, no matter what their
899 TREE_SIDE_EFFECTS (t) = 1;
908 /* Other classes need no special treatment. */
915 /* Return a new node with the same contents as NODE except that its
916 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
919 copy_node_stat (tree node MEM_STAT_DECL)
922 enum tree_code code = TREE_CODE (node);
925 gcc_assert (code != STATEMENT_LIST);
927 length = tree_size (node);
928 record_node_allocation_statistics (code, length);
929 t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
930 memcpy (t, node, length);
932 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
934 TREE_ASM_WRITTEN (t) = 0;
935 TREE_VISITED (t) = 0;
937 if (TREE_CODE_CLASS (code) == tcc_declaration)
939 if (code == DEBUG_EXPR_DECL)
940 DECL_UID (t) = --next_debug_decl_uid;
943 DECL_UID (t) = allocate_decl_uid ();
944 if (DECL_PT_UID_SET_P (node))
945 SET_DECL_PT_UID (t, DECL_PT_UID (node));
947 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
948 && DECL_HAS_VALUE_EXPR_P (node))
950 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
951 DECL_HAS_VALUE_EXPR_P (t) = 1;
953 /* DECL_DEBUG_EXPR is copied explicitely by callers. */
954 if (TREE_CODE (node) == VAR_DECL)
955 DECL_HAS_DEBUG_EXPR_P (t) = 0;
956 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
958 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
959 DECL_HAS_INIT_PRIORITY_P (t) = 1;
961 if (TREE_CODE (node) == FUNCTION_DECL)
962 DECL_STRUCT_FUNCTION (t) = NULL;
964 else if (TREE_CODE_CLASS (code) == tcc_type)
966 TYPE_UID (t) = next_type_uid++;
967 /* The following is so that the debug code for
968 the copy is different from the original type.
969 The two statements usually duplicate each other
970 (because they clear fields of the same union),
971 but the optimizer should catch that. */
972 TYPE_SYMTAB_POINTER (t) = 0;
973 TYPE_SYMTAB_ADDRESS (t) = 0;
975 /* Do not copy the values cache. */
976 if (TYPE_CACHED_VALUES_P (t))
978 TYPE_CACHED_VALUES_P (t) = 0;
979 TYPE_CACHED_VALUES (t) = NULL_TREE;
986 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
987 For example, this can copy a list made of TREE_LIST nodes. */
990 copy_list (tree list)
998 head = prev = copy_node (list);
999 next = TREE_CHAIN (list);
1002 TREE_CHAIN (prev) = copy_node (next);
1003 prev = TREE_CHAIN (prev);
1004 next = TREE_CHAIN (next);
1010 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1013 build_int_cst (tree type, HOST_WIDE_INT low)
1015 /* Support legacy code. */
1017 type = integer_type_node;
1019 return double_int_to_tree (type, double_int::from_shwi (low));
1022 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1025 build_int_cst_type (tree type, HOST_WIDE_INT low)
1029 return double_int_to_tree (type, double_int::from_shwi (low));
1032 /* Constructs tree in type TYPE from with value given by CST. Signedness
1033 of CST is assumed to be the same as the signedness of TYPE. */
1036 double_int_to_tree (tree type, double_int cst)
1038 bool sign_extended_type = !TYPE_UNSIGNED (type);
1040 cst = cst.ext (TYPE_PRECISION (type), !sign_extended_type);
1042 return build_int_cst_wide (type, cst.low, cst.high);
1045 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed
1046 to be the same as the signedness of TYPE. */
1049 double_int_fits_to_tree_p (const_tree type, double_int cst)
1051 bool sign_extended_type = !TYPE_UNSIGNED (type);
1054 = cst.ext (TYPE_PRECISION (type), !sign_extended_type);
1059 /* We force the double_int CST to the range of the type TYPE by sign or
1060 zero extending it. OVERFLOWABLE indicates if we are interested in
1061 overflow of the value, when >0 we are only interested in signed
1062 overflow, for <0 we are interested in any overflow. OVERFLOWED
1063 indicates whether overflow has already occurred. CONST_OVERFLOWED
1064 indicates whether constant overflow has already occurred. We force
1065 T's value to be within range of T's type (by setting to 0 or 1 all
1066 the bits outside the type's range). We set TREE_OVERFLOWED if,
1067 OVERFLOWED is nonzero,
1068 or OVERFLOWABLE is >0 and signed overflow occurs
1069 or OVERFLOWABLE is <0 and any overflow occurs
1070 We return a new tree node for the extended double_int. The node
1071 is shared if no overflow flags are set. */
1075 force_fit_type_double (tree type, double_int cst, int overflowable,
1078 bool sign_extended_type = !TYPE_UNSIGNED (type);
1080 /* If we need to set overflow flags, return a new unshared node. */
1081 if (overflowed || !double_int_fits_to_tree_p (type, cst))
1085 || (overflowable > 0 && sign_extended_type))
1087 tree t = make_node (INTEGER_CST);
1089 = cst.ext (TYPE_PRECISION (type), !sign_extended_type);
1090 TREE_TYPE (t) = type;
1091 TREE_OVERFLOW (t) = 1;
1096 /* Else build a shared node. */
1097 return double_int_to_tree (type, cst);
1100 /* These are the hash table functions for the hash table of INTEGER_CST
1101 nodes of a sizetype. */
1103 /* Return the hash code code X, an INTEGER_CST. */
1106 int_cst_hash_hash (const void *x)
1108 const_tree const t = (const_tree) x;
1110 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
1111 ^ htab_hash_pointer (TREE_TYPE (t)));
1114 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1115 is the same as that given by *Y, which is the same. */
1118 int_cst_hash_eq (const void *x, const void *y)
1120 const_tree const xt = (const_tree) x;
1121 const_tree const yt = (const_tree) y;
1123 return (TREE_TYPE (xt) == TREE_TYPE (yt)
1124 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
1125 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
1128 /* Create an INT_CST node of TYPE and value HI:LOW.
1129 The returned node is always shared. For small integers we use a
1130 per-type vector cache, for larger ones we use a single hash table. */
1133 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
1141 switch (TREE_CODE (type))
1144 gcc_assert (hi == 0 && low == 0);
1148 case REFERENCE_TYPE:
1149 case POINTER_BOUNDS_TYPE:
1150 /* Cache NULL pointer and zero bounds. */
1159 /* Cache false or true. */
1167 if (TYPE_UNSIGNED (type))
1170 limit = INTEGER_SHARE_LIMIT;
1171 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1177 limit = INTEGER_SHARE_LIMIT + 1;
1178 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1180 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
1194 /* Look for it in the type's vector of small shared ints. */
1195 if (!TYPE_CACHED_VALUES_P (type))
1197 TYPE_CACHED_VALUES_P (type) = 1;
1198 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
1201 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
1204 /* Make sure no one is clobbering the shared constant. */
1205 gcc_assert (TREE_TYPE (t) == type);
1206 gcc_assert (TREE_INT_CST_LOW (t) == low);
1207 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
1211 /* Create a new shared int. */
1212 t = make_node (INTEGER_CST);
1214 TREE_INT_CST_LOW (t) = low;
1215 TREE_INT_CST_HIGH (t) = hi;
1216 TREE_TYPE (t) = type;
1218 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
1223 /* Use the cache of larger shared ints. */
1226 TREE_INT_CST_LOW (int_cst_node) = low;
1227 TREE_INT_CST_HIGH (int_cst_node) = hi;
1228 TREE_TYPE (int_cst_node) = type;
1230 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
1234 /* Insert this one into the hash table. */
1237 /* Make a new node for next time round. */
1238 int_cst_node = make_node (INTEGER_CST);
1246 cache_integer_cst (tree t)
1248 tree type = TREE_TYPE (t);
1249 HOST_WIDE_INT hi = TREE_INT_CST_HIGH (t);
1250 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (t);
1254 gcc_assert (!TREE_OVERFLOW (t));
1256 switch (TREE_CODE (type))
1259 gcc_assert (hi == 0 && low == 0);
1263 case REFERENCE_TYPE:
1264 /* Cache NULL pointer. */
1273 /* Cache false or true. */
1281 if (TYPE_UNSIGNED (type))
1284 limit = INTEGER_SHARE_LIMIT;
1285 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1291 limit = INTEGER_SHARE_LIMIT + 1;
1292 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1294 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
1308 /* Look for it in the type's vector of small shared ints. */
1309 if (!TYPE_CACHED_VALUES_P (type))
1311 TYPE_CACHED_VALUES_P (type) = 1;
1312 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
1315 gcc_assert (TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) == NULL_TREE);
1316 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
1320 /* Use the cache of larger shared ints. */
1323 slot = htab_find_slot (int_cst_hash_table, t, INSERT);
1324 /* If there is already an entry for the number verify it's the
1328 gcc_assert (TREE_INT_CST_LOW ((tree)*slot) == low
1329 && TREE_INT_CST_HIGH ((tree)*slot) == hi);
1332 /* Otherwise insert this one into the hash table. */
1338 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1339 and the rest are zeros. */
1342 build_low_bits_mask (tree type, unsigned bits)
1346 gcc_assert (bits <= TYPE_PRECISION (type));
1348 if (bits == TYPE_PRECISION (type)
1349 && !TYPE_UNSIGNED (type))
1350 /* Sign extended all-ones mask. */
1351 mask = double_int_minus_one;
1353 mask = double_int::mask (bits);
1355 return build_int_cst_wide (type, mask.low, mask.high);
1358 /* Checks that X is integer constant that can be expressed in (unsigned)
1359 HOST_WIDE_INT without loss of precision. */
1362 cst_and_fits_in_hwi (const_tree x)
1364 if (TREE_CODE (x) != INTEGER_CST)
1367 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
1370 return (TREE_INT_CST_HIGH (x) == 0
1371 || TREE_INT_CST_HIGH (x) == -1);
1374 /* Build a newly constructed TREE_VEC node of length LEN. */
1377 make_vector_stat (unsigned len MEM_STAT_DECL)
1380 unsigned length = (len - 1) * sizeof (tree) + sizeof (struct tree_vector);
1382 record_node_allocation_statistics (VECTOR_CST, length);
1384 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1386 TREE_SET_CODE (t, VECTOR_CST);
1387 TREE_CONSTANT (t) = 1;
1392 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1393 are in a list pointed to by VALS. */
1396 build_vector_stat (tree type, tree *vals MEM_STAT_DECL)
1400 tree v = make_vector (TYPE_VECTOR_SUBPARTS (type));
1401 TREE_TYPE (v) = type;
1403 /* Iterate through elements and check for overflow. */
1404 for (cnt = 0; cnt < TYPE_VECTOR_SUBPARTS (type); ++cnt)
1406 tree value = vals[cnt];
1408 VECTOR_CST_ELT (v, cnt) = value;
1410 /* Don't crash if we get an address constant. */
1411 if (!CONSTANT_CLASS_P (value))
1414 over |= TREE_OVERFLOW (value);
1417 TREE_OVERFLOW (v) = over;
1421 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1422 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1425 build_vector_from_ctor (tree type, vec<constructor_elt, va_gc> *v)
1427 tree *vec = XALLOCAVEC (tree, TYPE_VECTOR_SUBPARTS (type));
1428 unsigned HOST_WIDE_INT idx;
1431 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1433 for (; idx < TYPE_VECTOR_SUBPARTS (type); ++idx)
1434 vec[idx] = build_zero_cst (TREE_TYPE (type));
1436 return build_vector (type, vec);
1439 /* Build a vector of type VECTYPE where all the elements are SCs. */
1441 build_vector_from_val (tree vectype, tree sc)
1443 int i, nunits = TYPE_VECTOR_SUBPARTS (vectype);
1445 if (sc == error_mark_node)
1448 /* Verify that the vector type is suitable for SC. Note that there
1449 is some inconsistency in the type-system with respect to restrict
1450 qualifications of pointers. Vector types always have a main-variant
1451 element type and the qualification is applied to the vector-type.
1452 So TREE_TYPE (vector-type) does not return a properly qualified
1453 vector element-type. */
1454 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
1455 TREE_TYPE (vectype)));
1457 if (CONSTANT_CLASS_P (sc))
1459 tree *v = XALLOCAVEC (tree, nunits);
1460 for (i = 0; i < nunits; ++i)
1462 return build_vector (vectype, v);
1466 vec<constructor_elt, va_gc> *v;
1467 vec_alloc (v, nunits);
1468 for (i = 0; i < nunits; ++i)
1469 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
1470 return build_constructor (vectype, v);
1474 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1475 are in the vec pointed to by VALS. */
1477 build_constructor (tree type, vec<constructor_elt, va_gc> *vals)
1479 tree c = make_node (CONSTRUCTOR);
1481 constructor_elt *elt;
1482 bool constant_p = true;
1483 bool side_effects_p = false;
1485 TREE_TYPE (c) = type;
1486 CONSTRUCTOR_ELTS (c) = vals;
1488 FOR_EACH_VEC_SAFE_ELT (vals, i, elt)
1490 /* Mostly ctors will have elts that don't have side-effects, so
1491 the usual case is to scan all the elements. Hence a single
1492 loop for both const and side effects, rather than one loop
1493 each (with early outs). */
1494 if (!TREE_CONSTANT (elt->value))
1496 if (TREE_SIDE_EFFECTS (elt->value))
1497 side_effects_p = true;
1500 TREE_SIDE_EFFECTS (c) = side_effects_p;
1501 TREE_CONSTANT (c) = constant_p;
1506 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1509 build_constructor_single (tree type, tree index, tree value)
1511 vec<constructor_elt, va_gc> *v;
1512 constructor_elt elt = {index, value};
1515 v->quick_push (elt);
1517 return build_constructor (type, v);
1521 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1522 are in a list pointed to by VALS. */
1524 build_constructor_from_list (tree type, tree vals)
1527 vec<constructor_elt, va_gc> *v = NULL;
1531 vec_alloc (v, list_length (vals));
1532 for (t = vals; t; t = TREE_CHAIN (t))
1533 CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
1536 return build_constructor (type, v);
1539 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
1540 of elements, provided as index/value pairs. */
1543 build_constructor_va (tree type, int nelts, ...)
1545 vec<constructor_elt, va_gc> *v = NULL;
1548 va_start (p, nelts);
1549 vec_alloc (v, nelts);
1552 tree index = va_arg (p, tree);
1553 tree value = va_arg (p, tree);
1554 CONSTRUCTOR_APPEND_ELT (v, index, value);
1557 return build_constructor (type, v);
1560 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1563 build_fixed (tree type, FIXED_VALUE_TYPE f)
1566 FIXED_VALUE_TYPE *fp;
1568 v = make_node (FIXED_CST);
1569 fp = ggc_alloc_fixed_value ();
1570 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1572 TREE_TYPE (v) = type;
1573 TREE_FIXED_CST_PTR (v) = fp;
1577 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1580 build_real (tree type, REAL_VALUE_TYPE d)
1583 REAL_VALUE_TYPE *dp;
1586 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1587 Consider doing it via real_convert now. */
1589 v = make_node (REAL_CST);
1590 dp = ggc_alloc_real_value ();
1591 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1593 TREE_TYPE (v) = type;
1594 TREE_REAL_CST_PTR (v) = dp;
1595 TREE_OVERFLOW (v) = overflow;
1599 /* Return a new REAL_CST node whose type is TYPE
1600 and whose value is the integer value of the INTEGER_CST node I. */
1603 real_value_from_int_cst (const_tree type, const_tree i)
1607 /* Clear all bits of the real value type so that we can later do
1608 bitwise comparisons to see if two values are the same. */
1609 memset (&d, 0, sizeof d);
1611 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1612 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1613 TYPE_UNSIGNED (TREE_TYPE (i)));
1617 /* Given a tree representing an integer constant I, return a tree
1618 representing the same value as a floating-point constant of type TYPE. */
1621 build_real_from_int_cst (tree type, const_tree i)
1624 int overflow = TREE_OVERFLOW (i);
1626 v = build_real (type, real_value_from_int_cst (type, i));
1628 TREE_OVERFLOW (v) |= overflow;
1632 /* Return a newly constructed STRING_CST node whose value is
1633 the LEN characters at STR.
1634 Note that for a C string literal, LEN should include the trailing NUL.
1635 The TREE_TYPE is not initialized. */
1638 build_string (int len, const char *str)
1643 /* Do not waste bytes provided by padding of struct tree_string. */
1644 length = len + offsetof (struct tree_string, str) + 1;
1646 record_node_allocation_statistics (STRING_CST, length);
1648 s = ggc_alloc_tree_node (length);
1650 memset (s, 0, sizeof (struct tree_typed));
1651 TREE_SET_CODE (s, STRING_CST);
1652 TREE_CONSTANT (s) = 1;
1653 TREE_STRING_LENGTH (s) = len;
1654 memcpy (s->string.str, str, len);
1655 s->string.str[len] = '\0';
1660 /* Return a newly constructed COMPLEX_CST node whose value is
1661 specified by the real and imaginary parts REAL and IMAG.
1662 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1663 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1666 build_complex (tree type, tree real, tree imag)
1668 tree t = make_node (COMPLEX_CST);
1670 TREE_REALPART (t) = real;
1671 TREE_IMAGPART (t) = imag;
1672 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1673 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1677 /* Return a constant of arithmetic type TYPE which is the
1678 multiplicative identity of the set TYPE. */
1681 build_one_cst (tree type)
1683 switch (TREE_CODE (type))
1685 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1686 case POINTER_TYPE: case REFERENCE_TYPE:
1688 return build_int_cst (type, 1);
1691 return build_real (type, dconst1);
1693 case FIXED_POINT_TYPE:
1694 /* We can only generate 1 for accum types. */
1695 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1696 return build_fixed (type, FCONST1 (TYPE_MODE (type)));
1700 tree scalar = build_one_cst (TREE_TYPE (type));
1702 return build_vector_from_val (type, scalar);
1706 return build_complex (type,
1707 build_one_cst (TREE_TYPE (type)),
1708 build_zero_cst (TREE_TYPE (type)));
1715 /* Return an integer of type TYPE containing all 1's in as much precision as
1716 it contains, or a complex or vector whose subparts are such integers. */
1719 build_all_ones_cst (tree type)
1721 if (TREE_CODE (type) == COMPLEX_TYPE)
1723 tree scalar = build_all_ones_cst (TREE_TYPE (type));
1724 return build_complex (type, scalar, scalar);
1727 return build_minus_one_cst (type);
1730 /* Return a constant of arithmetic type TYPE which is the
1731 opposite of the multiplicative identity of the set TYPE. */
1734 build_minus_one_cst (tree type)
1736 switch (TREE_CODE (type))
1738 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1739 case POINTER_TYPE: case REFERENCE_TYPE:
1741 return build_int_cst (type, -1);
1744 return build_real (type, dconstm1);
1746 case FIXED_POINT_TYPE:
1747 /* We can only generate 1 for accum types. */
1748 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1749 return build_fixed (type, fixed_from_double_int (double_int_minus_one,
1754 tree scalar = build_minus_one_cst (TREE_TYPE (type));
1756 return build_vector_from_val (type, scalar);
1760 return build_complex (type,
1761 build_minus_one_cst (TREE_TYPE (type)),
1762 build_zero_cst (TREE_TYPE (type)));
1769 /* Build 0 constant of type TYPE. This is used by constructor folding
1770 and thus the constant should be represented in memory by
1774 build_zero_cst (tree type)
1776 switch (TREE_CODE (type))
1778 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1779 case POINTER_TYPE: case REFERENCE_TYPE:
1780 case OFFSET_TYPE: case NULLPTR_TYPE:
1781 return build_int_cst (type, 0);
1784 return build_real (type, dconst0);
1786 case FIXED_POINT_TYPE:
1787 return build_fixed (type, FCONST0 (TYPE_MODE (type)));
1791 tree scalar = build_zero_cst (TREE_TYPE (type));
1793 return build_vector_from_val (type, scalar);
1798 tree zero = build_zero_cst (TREE_TYPE (type));
1800 return build_complex (type, zero, zero);
1804 if (!AGGREGATE_TYPE_P (type))
1805 return fold_convert (type, integer_zero_node);
1806 return build_constructor (type, NULL);
1811 /* Build a BINFO with LEN language slots. */
1814 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1817 size_t length = (offsetof (struct tree_binfo, base_binfos)
1818 + vec<tree, va_gc>::embedded_size (base_binfos));
1820 record_node_allocation_statistics (TREE_BINFO, length);
1822 t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1824 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1826 TREE_SET_CODE (t, TREE_BINFO);
1828 BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
1833 /* Create a CASE_LABEL_EXPR tree node and return it. */
1836 build_case_label (tree low_value, tree high_value, tree label_decl)
1838 tree t = make_node (CASE_LABEL_EXPR);
1840 TREE_TYPE (t) = void_type_node;
1841 SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
1843 CASE_LOW (t) = low_value;
1844 CASE_HIGH (t) = high_value;
1845 CASE_LABEL (t) = label_decl;
1846 CASE_CHAIN (t) = NULL_TREE;
1851 /* Build a newly constructed TREE_VEC node of length LEN. */
1854 make_tree_vec_stat (int len MEM_STAT_DECL)
1857 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1859 record_node_allocation_statistics (TREE_VEC, length);
1861 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1863 TREE_SET_CODE (t, TREE_VEC);
1864 TREE_VEC_LENGTH (t) = len;
1869 /* Grow a TREE_VEC node to new length LEN. */
1872 grow_tree_vec_stat (tree v, int len MEM_STAT_DECL)
1874 gcc_assert (TREE_CODE (v) == TREE_VEC);
1876 int oldlen = TREE_VEC_LENGTH (v);
1877 gcc_assert (len > oldlen);
1879 int oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
1880 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1882 record_node_allocation_statistics (TREE_VEC, length - oldlength);
1884 v = (tree) ggc_realloc_stat (v, length PASS_MEM_STAT);
1886 TREE_VEC_LENGTH (v) = len;
1891 /* Return 1 if EXPR is the integer constant zero or a complex constant
1895 integer_zerop (const_tree expr)
1899 switch (TREE_CODE (expr))
1902 return (TREE_INT_CST_LOW (expr) == 0
1903 && TREE_INT_CST_HIGH (expr) == 0);
1905 return (integer_zerop (TREE_REALPART (expr))
1906 && integer_zerop (TREE_IMAGPART (expr)));
1910 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
1911 if (!integer_zerop (VECTOR_CST_ELT (expr, i)))
1920 /* Return 1 if EXPR is the integer constant one or the corresponding
1921 complex constant. */
1924 integer_onep (const_tree expr)
1928 switch (TREE_CODE (expr))
1931 return (TREE_INT_CST_LOW (expr) == 1
1932 && TREE_INT_CST_HIGH (expr) == 0);
1934 return (integer_onep (TREE_REALPART (expr))
1935 && integer_zerop (TREE_IMAGPART (expr)));
1939 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
1940 if (!integer_onep (VECTOR_CST_ELT (expr, i)))
1949 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1950 it contains, or a complex or vector whose subparts are such integers. */
1953 integer_all_onesp (const_tree expr)
1960 if (TREE_CODE (expr) == COMPLEX_CST
1961 && integer_all_onesp (TREE_REALPART (expr))
1962 && integer_all_onesp (TREE_IMAGPART (expr)))
1965 else if (TREE_CODE (expr) == VECTOR_CST)
1968 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
1969 if (!integer_all_onesp (VECTOR_CST_ELT (expr, i)))
1974 else if (TREE_CODE (expr) != INTEGER_CST)
1977 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1978 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1979 && TREE_INT_CST_HIGH (expr) == -1)
1984 prec = TYPE_PRECISION (TREE_TYPE (expr));
1985 if (prec >= HOST_BITS_PER_WIDE_INT)
1987 HOST_WIDE_INT high_value;
1990 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1992 /* Can not handle precisions greater than twice the host int size. */
1993 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1994 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1995 /* Shifting by the host word size is undefined according to the ANSI
1996 standard, so we must handle this as a special case. */
1999 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
2001 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
2002 && TREE_INT_CST_HIGH (expr) == high_value);
2005 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
2008 /* Return 1 if EXPR is the integer constant minus one. */
2011 integer_minus_onep (const_tree expr)
2015 if (TREE_CODE (expr) == COMPLEX_CST)
2016 return (integer_all_onesp (TREE_REALPART (expr))
2017 && integer_zerop (TREE_IMAGPART (expr)));
2019 return integer_all_onesp (expr);
2022 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2026 integer_pow2p (const_tree expr)
2029 unsigned HOST_WIDE_INT high, low;
2033 if (TREE_CODE (expr) == COMPLEX_CST
2034 && integer_pow2p (TREE_REALPART (expr))
2035 && integer_zerop (TREE_IMAGPART (expr)))
2038 if (TREE_CODE (expr) != INTEGER_CST)
2041 prec = TYPE_PRECISION (TREE_TYPE (expr));
2042 high = TREE_INT_CST_HIGH (expr);
2043 low = TREE_INT_CST_LOW (expr);
2045 /* First clear all bits that are beyond the type's precision in case
2046 we've been sign extended. */
2048 if (prec == HOST_BITS_PER_DOUBLE_INT)
2050 else if (prec > HOST_BITS_PER_WIDE_INT)
2051 high &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
2055 if (prec < HOST_BITS_PER_WIDE_INT)
2056 low &= ~(HOST_WIDE_INT_M1U << prec);
2059 if (high == 0 && low == 0)
2062 return ((high == 0 && (low & (low - 1)) == 0)
2063 || (low == 0 && (high & (high - 1)) == 0));
2066 /* Return 1 if EXPR is an integer constant other than zero or a
2067 complex constant other than zero. */
2070 integer_nonzerop (const_tree expr)
2074 return ((TREE_CODE (expr) == INTEGER_CST
2075 && (TREE_INT_CST_LOW (expr) != 0
2076 || TREE_INT_CST_HIGH (expr) != 0))
2077 || (TREE_CODE (expr) == COMPLEX_CST
2078 && (integer_nonzerop (TREE_REALPART (expr))
2079 || integer_nonzerop (TREE_IMAGPART (expr)))));
2082 /* Return 1 if EXPR is the fixed-point constant zero. */
2085 fixed_zerop (const_tree expr)
2087 return (TREE_CODE (expr) == FIXED_CST
2088 && TREE_FIXED_CST (expr).data.is_zero ());
2091 /* Return the power of two represented by a tree node known to be a
2095 tree_log2 (const_tree expr)
2098 HOST_WIDE_INT high, low;
2102 if (TREE_CODE (expr) == COMPLEX_CST)
2103 return tree_log2 (TREE_REALPART (expr));
2105 prec = TYPE_PRECISION (TREE_TYPE (expr));
2106 high = TREE_INT_CST_HIGH (expr);
2107 low = TREE_INT_CST_LOW (expr);
2109 /* First clear all bits that are beyond the type's precision in case
2110 we've been sign extended. */
2112 if (prec == HOST_BITS_PER_DOUBLE_INT)
2114 else if (prec > HOST_BITS_PER_WIDE_INT)
2115 high &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
2119 if (prec < HOST_BITS_PER_WIDE_INT)
2120 low &= ~(HOST_WIDE_INT_M1U << prec);
2123 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
2124 : exact_log2 (low));
2127 /* Similar, but return the largest integer Y such that 2 ** Y is less
2128 than or equal to EXPR. */
2131 tree_floor_log2 (const_tree expr)
2134 HOST_WIDE_INT high, low;
2138 if (TREE_CODE (expr) == COMPLEX_CST)
2139 return tree_log2 (TREE_REALPART (expr));
2141 prec = TYPE_PRECISION (TREE_TYPE (expr));
2142 high = TREE_INT_CST_HIGH (expr);
2143 low = TREE_INT_CST_LOW (expr);
2145 /* First clear all bits that are beyond the type's precision in case
2146 we've been sign extended. Ignore if type's precision hasn't been set
2147 since what we are doing is setting it. */
2149 if (prec == HOST_BITS_PER_DOUBLE_INT || prec == 0)
2151 else if (prec > HOST_BITS_PER_WIDE_INT)
2152 high &= ~(HOST_WIDE_INT_M1U << (prec - HOST_BITS_PER_WIDE_INT));
2156 if (prec < HOST_BITS_PER_WIDE_INT)
2157 low &= ~(HOST_WIDE_INT_M1U << prec);
2160 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
2161 : floor_log2 (low));
2164 /* Return number of known trailing zero bits in EXPR, or, if the value of
2165 EXPR is known to be zero, the precision of it's type. */
2168 tree_ctz (const_tree expr)
2170 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
2171 && !POINTER_TYPE_P (TREE_TYPE (expr)))
2174 unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
2175 switch (TREE_CODE (expr))
2178 ret1 = tree_to_double_int (expr).trailing_zeros ();
2179 return MIN (ret1, prec);
2181 ret1 = get_nonzero_bits (expr).trailing_zeros ();
2182 return MIN (ret1, prec);
2189 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2192 ret2 = tree_ctz (TREE_OPERAND (expr, 1));
2193 return MIN (ret1, ret2);
2194 case POINTER_PLUS_EXPR:
2195 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2196 ret2 = tree_ctz (TREE_OPERAND (expr, 1));
2197 /* Second operand is sizetype, which could be in theory
2198 wider than pointer's precision. Make sure we never
2199 return more than prec. */
2200 ret2 = MIN (ret2, prec);
2201 return MIN (ret1, ret2);
2203 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2204 ret2 = tree_ctz (TREE_OPERAND (expr, 1));
2205 return MAX (ret1, ret2);
2207 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2208 ret2 = tree_ctz (TREE_OPERAND (expr, 1));
2209 return MIN (ret1 + ret2, prec);
2211 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2212 if (host_integerp (TREE_OPERAND (expr, 1), 1)
2213 && ((unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (expr, 1), 1)
2214 < (unsigned HOST_WIDE_INT) prec))
2216 ret2 = tree_low_cst (TREE_OPERAND (expr, 1), 1);
2217 return MIN (ret1 + ret2, prec);
2221 if (host_integerp (TREE_OPERAND (expr, 1), 1)
2222 && ((unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (expr, 1), 1)
2223 < (unsigned HOST_WIDE_INT) prec))
2225 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2226 ret2 = tree_low_cst (TREE_OPERAND (expr, 1), 1);
2231 case TRUNC_DIV_EXPR:
2233 case FLOOR_DIV_EXPR:
2234 case ROUND_DIV_EXPR:
2235 case EXACT_DIV_EXPR:
2236 if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
2237 && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
2239 int l = tree_log2 (TREE_OPERAND (expr, 1));
2242 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2250 ret1 = tree_ctz (TREE_OPERAND (expr, 0));
2251 if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2253 return MIN (ret1, prec);
2255 return tree_ctz (TREE_OPERAND (expr, 0));
2257 ret1 = tree_ctz (TREE_OPERAND (expr, 1));
2260 ret2 = tree_ctz (TREE_OPERAND (expr, 2));
2261 return MIN (ret1, ret2);
2263 return tree_ctz (TREE_OPERAND (expr, 1));
2265 ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
2266 if (ret1 > BITS_PER_UNIT)
2268 ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
2269 return MIN (ret1, prec);
2277 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2278 decimal float constants, so don't return 1 for them. */
2281 real_zerop (const_tree expr)
2285 switch (TREE_CODE (expr))
2288 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)
2289 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
2291 return real_zerop (TREE_REALPART (expr))
2292 && real_zerop (TREE_IMAGPART (expr));
2296 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
2297 if (!real_zerop (VECTOR_CST_ELT (expr, i)))
2306 /* Return 1 if EXPR is the real constant one in real or complex form.
2307 Trailing zeroes matter for decimal float constants, so don't return
2311 real_onep (const_tree expr)
2315 switch (TREE_CODE (expr))
2318 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)
2319 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
2321 return real_onep (TREE_REALPART (expr))
2322 && real_zerop (TREE_IMAGPART (expr));
2326 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
2327 if (!real_onep (VECTOR_CST_ELT (expr, i)))
2336 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2337 matter for decimal float constants, so don't return 1 for them. */
2340 real_minus_onep (const_tree expr)
2344 switch (TREE_CODE (expr))
2347 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1)
2348 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
2350 return real_minus_onep (TREE_REALPART (expr))
2351 && real_zerop (TREE_IMAGPART (expr));
2355 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
2356 if (!real_minus_onep (VECTOR_CST_ELT (expr, i)))
2365 /* Nonzero if EXP is a constant or a cast of a constant. */
2368 really_constant_p (const_tree exp)
2370 /* This is not quite the same as STRIP_NOPS. It does more. */
2371 while (CONVERT_EXPR_P (exp)
2372 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2373 exp = TREE_OPERAND (exp, 0);
2374 return TREE_CONSTANT (exp);
2377 /* Return first list element whose TREE_VALUE is ELEM.
2378 Return 0 if ELEM is not in LIST. */
2381 value_member (tree elem, tree list)
2385 if (elem == TREE_VALUE (list))
2387 list = TREE_CHAIN (list);
2392 /* Return first list element whose TREE_PURPOSE is ELEM.
2393 Return 0 if ELEM is not in LIST. */
2396 purpose_member (const_tree elem, tree list)
2400 if (elem == TREE_PURPOSE (list))
2402 list = TREE_CHAIN (list);
2407 /* Return true if ELEM is in V. */
2410 vec_member (const_tree elem, vec<tree, va_gc> *v)
2414 FOR_EACH_VEC_SAFE_ELT (v, ix, t)
2420 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2424 chain_index (int idx, tree chain)
2426 for (; chain && idx > 0; --idx)
2427 chain = TREE_CHAIN (chain);
2431 /* Return nonzero if ELEM is part of the chain CHAIN. */
2434 chain_member (const_tree elem, const_tree chain)
2440 chain = DECL_CHAIN (chain);
2446 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2447 We expect a null pointer to mark the end of the chain.
2448 This is the Lisp primitive `length'. */
2451 list_length (const_tree t)
2454 #ifdef ENABLE_TREE_CHECKING
2462 #ifdef ENABLE_TREE_CHECKING
2465 gcc_assert (p != q);
2473 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2474 UNION_TYPE TYPE, or NULL_TREE if none. */
2477 first_field (const_tree type)
2479 tree t = TYPE_FIELDS (type);
2480 while (t && TREE_CODE (t) != FIELD_DECL)
2485 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2486 by modifying the last node in chain 1 to point to chain 2.
2487 This is the Lisp primitive `nconc'. */
2490 chainon (tree op1, tree op2)
2499 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
2501 TREE_CHAIN (t1) = op2;
2503 #ifdef ENABLE_TREE_CHECKING
2506 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
2507 gcc_assert (t2 != t1);
2514 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2517 tree_last (tree chain)
2521 while ((next = TREE_CHAIN (chain)))
2526 /* Reverse the order of elements in the chain T,
2527 and return the new head of the chain (old last element). */
2532 tree prev = 0, decl, next;
2533 for (decl = t; decl; decl = next)
2535 /* We shouldn't be using this function to reverse BLOCK chains; we
2536 have blocks_nreverse for that. */
2537 gcc_checking_assert (TREE_CODE (decl) != BLOCK);
2538 next = TREE_CHAIN (decl);
2539 TREE_CHAIN (decl) = prev;
2545 /* Return a newly created TREE_LIST node whose
2546 purpose and value fields are PARM and VALUE. */
2549 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
2551 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
2552 TREE_PURPOSE (t) = parm;
2553 TREE_VALUE (t) = value;
2557 /* Build a chain of TREE_LIST nodes from a vector. */
2560 build_tree_list_vec_stat (const vec<tree, va_gc> *vec MEM_STAT_DECL)
2562 tree ret = NULL_TREE;
2566 FOR_EACH_VEC_SAFE_ELT (vec, i, t)
2568 *pp = build_tree_list_stat (NULL, t PASS_MEM_STAT);
2569 pp = &TREE_CHAIN (*pp);
2574 /* Return a newly created TREE_LIST node whose
2575 purpose and value fields are PURPOSE and VALUE
2576 and whose TREE_CHAIN is CHAIN. */
2579 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
2583 node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
2584 memset (node, 0, sizeof (struct tree_common));
2586 record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
2588 TREE_SET_CODE (node, TREE_LIST);
2589 TREE_CHAIN (node) = chain;
2590 TREE_PURPOSE (node) = purpose;
2591 TREE_VALUE (node) = value;
2595 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2599 ctor_to_vec (tree ctor)
2601 vec<tree, va_gc> *vec;
2602 vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
2606 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
2607 vec->quick_push (val);
2612 /* Return the size nominally occupied by an object of type TYPE
2613 when it resides in memory. The value is measured in units of bytes,
2614 and its data type is that normally used for type sizes
2615 (which is the first type created by make_signed_type or
2616 make_unsigned_type). */
2619 size_in_bytes (const_tree type)
2623 if (type == error_mark_node)
2624 return integer_zero_node;
2626 type = TYPE_MAIN_VARIANT (type);
2627 t = TYPE_SIZE_UNIT (type);
2631 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
2632 return size_zero_node;
2638 /* Return the size of TYPE (in bytes) as a wide integer
2639 or return -1 if the size can vary or is larger than an integer. */
2642 int_size_in_bytes (const_tree type)
2646 if (type == error_mark_node)
2649 type = TYPE_MAIN_VARIANT (type);
2650 t = TYPE_SIZE_UNIT (type);
2652 || TREE_CODE (t) != INTEGER_CST
2653 || TREE_INT_CST_HIGH (t) != 0
2654 /* If the result would appear negative, it's too big to represent. */
2655 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
2658 return TREE_INT_CST_LOW (t);
2661 /* Return the maximum size of TYPE (in bytes) as a wide integer
2662 or return -1 if the size can vary or is larger than an integer. */
2665 max_int_size_in_bytes (const_tree type)
2667 HOST_WIDE_INT size = -1;
2670 /* If this is an array type, check for a possible MAX_SIZE attached. */
2672 if (TREE_CODE (type) == ARRAY_TYPE)
2674 size_tree = TYPE_ARRAY_MAX_SIZE (type);
2676 if (size_tree && host_integerp (size_tree, 1))
2677 size = tree_low_cst (size_tree, 1);
2680 /* If we still haven't been able to get a size, see if the language
2681 can compute a maximum size. */
2685 size_tree = lang_hooks.types.max_size (type);
2687 if (size_tree && host_integerp (size_tree, 1))
2688 size = tree_low_cst (size_tree, 1);
2694 /* Return the bit position of FIELD, in bits from the start of the record.
2695 This is a tree of type bitsizetype. */
2698 bit_position (const_tree field)
2700 return bit_from_pos (DECL_FIELD_OFFSET (field),
2701 DECL_FIELD_BIT_OFFSET (field));
2704 /* Likewise, but return as an integer. It must be representable in
2705 that way (since it could be a signed value, we don't have the
2706 option of returning -1 like int_size_in_byte can. */
2709 int_bit_position (const_tree field)
2711 return tree_low_cst (bit_position (field), 0);
2714 /* Return the byte position of FIELD, in bytes from the start of the record.
2715 This is a tree of type sizetype. */
2718 byte_position (const_tree field)
2720 return byte_from_pos (DECL_FIELD_OFFSET (field),
2721 DECL_FIELD_BIT_OFFSET (field));
2724 /* Likewise, but return as an integer. It must be representable in
2725 that way (since it could be a signed value, we don't have the
2726 option of returning -1 like int_size_in_byte can. */
2729 int_byte_position (const_tree field)
2731 return tree_low_cst (byte_position (field), 0);
2734 /* Return the strictest alignment, in bits, that T is known to have. */
2737 expr_align (const_tree t)
2739 unsigned int align0, align1;
2741 switch (TREE_CODE (t))
2743 CASE_CONVERT: case NON_LVALUE_EXPR:
2744 /* If we have conversions, we know that the alignment of the
2745 object must meet each of the alignments of the types. */
2746 align0 = expr_align (TREE_OPERAND (t, 0));
2747 align1 = TYPE_ALIGN (TREE_TYPE (t));
2748 return MAX (align0, align1);
2750 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2751 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2752 case CLEANUP_POINT_EXPR:
2753 /* These don't change the alignment of an object. */
2754 return expr_align (TREE_OPERAND (t, 0));
2757 /* The best we can do is say that the alignment is the least aligned
2759 align0 = expr_align (TREE_OPERAND (t, 1));
2760 align1 = expr_align (TREE_OPERAND (t, 2));
2761 return MIN (align0, align1);
2763 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2764 meaningfully, it's always 1. */
2765 case LABEL_DECL: case CONST_DECL:
2766 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2768 gcc_assert (DECL_ALIGN (t) != 0);
2769 return DECL_ALIGN (t);
2775 /* Otherwise take the alignment from that of the type. */
2776 return TYPE_ALIGN (TREE_TYPE (t));
2779 /* Return, as a tree node, the number of elements for TYPE (which is an
2780 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2783 array_type_nelts (const_tree type)
2785 tree index_type, min, max;
2787 /* If they did it with unspecified bounds, then we should have already
2788 given an error about it before we got here. */
2789 if (! TYPE_DOMAIN (type))
2790 return error_mark_node;
2792 index_type = TYPE_DOMAIN (type);
2793 min = TYPE_MIN_VALUE (index_type);
2794 max = TYPE_MAX_VALUE (index_type);
2796 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
2798 return error_mark_node;
2800 return (integer_zerop (min)
2802 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
2805 /* If arg is static -- a reference to an object in static storage -- then
2806 return the object. This is not the same as the C meaning of `static'.
2807 If arg isn't static, return NULL. */
2812 switch (TREE_CODE (arg))
2815 /* Nested functions are static, even though taking their address will
2816 involve a trampoline as we unnest the nested function and create
2817 the trampoline on the tree level. */
2821 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2822 && ! DECL_THREAD_LOCAL_P (arg)
2823 && ! DECL_DLLIMPORT_P (arg)
2827 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2831 return TREE_STATIC (arg) ? arg : NULL;
2838 /* If the thing being referenced is not a field, then it is
2839 something language specific. */
2840 gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
2842 /* If we are referencing a bitfield, we can't evaluate an
2843 ADDR_EXPR at compile time and so it isn't a constant. */
2844 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2847 return staticp (TREE_OPERAND (arg, 0));
2853 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2856 case ARRAY_RANGE_REF:
2857 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2858 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2859 return staticp (TREE_OPERAND (arg, 0));
2863 case COMPOUND_LITERAL_EXPR:
2864 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
2874 /* Return whether OP is a DECL whose address is function-invariant. */
2877 decl_address_invariant_p (const_tree op)
2879 /* The conditions below are slightly less strict than the one in
2882 switch (TREE_CODE (op))
2891 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2892 || DECL_THREAD_LOCAL_P (op)
2893 || DECL_CONTEXT (op) == current_function_decl
2894 || decl_function_context (op) == current_function_decl)
2899 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2900 || decl_function_context (op) == current_function_decl)
2911 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2914 decl_address_ip_invariant_p (const_tree op)
2916 /* The conditions below are slightly less strict than the one in
2919 switch (TREE_CODE (op))
2927 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2928 && !DECL_DLLIMPORT_P (op))
2929 || DECL_THREAD_LOCAL_P (op))
2934 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
2946 /* Return true if T is function-invariant (internal function, does
2947 not handle arithmetic; that's handled in skip_simple_arithmetic and
2948 tree_invariant_p). */
2950 static bool tree_invariant_p (tree t);
2953 tree_invariant_p_1 (tree t)
2957 if (TREE_CONSTANT (t)
2958 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2961 switch (TREE_CODE (t))
2967 op = TREE_OPERAND (t, 0);
2968 while (handled_component_p (op))
2970 switch (TREE_CODE (op))
2973 case ARRAY_RANGE_REF:
2974 if (!tree_invariant_p (TREE_OPERAND (op, 1))
2975 || TREE_OPERAND (op, 2) != NULL_TREE
2976 || TREE_OPERAND (op, 3) != NULL_TREE)
2981 if (TREE_OPERAND (op, 2) != NULL_TREE)
2987 op = TREE_OPERAND (op, 0);
2990 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2999 /* Return true if T is function-invariant. */
3002 tree_invariant_p (tree t)
3004 tree inner = skip_simple_arithmetic (t);
3005 return tree_invariant_p_1 (inner);
3008 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
3009 Do this to any expression which may be used in more than one place,
3010 but must be evaluated only once.
3012 Normally, expand_expr would reevaluate the expression each time.
3013 Calling save_expr produces something that is evaluated and recorded
3014 the first time expand_expr is called on it. Subsequent calls to
3015 expand_expr just reuse the recorded value.
3017 The call to expand_expr that generates code that actually computes
3018 the value is the first call *at compile time*. Subsequent calls
3019 *at compile time* generate code to use the saved value.
3020 This produces correct result provided that *at run time* control
3021 always flows through the insns made by the first expand_expr
3022 before reaching the other places where the save_expr was evaluated.
3023 You, the caller of save_expr, must make sure this is so.
3025 Constants, and certain read-only nodes, are returned with no
3026 SAVE_EXPR because that is safe. Expressions containing placeholders
3027 are not touched; see tree.def for an explanation of what these
3031 save_expr (tree expr)
3033 tree t = fold (expr);
3036 /* If the tree evaluates to a constant, then we don't want to hide that
3037 fact (i.e. this allows further folding, and direct checks for constants).
3038 However, a read-only object that has side effects cannot be bypassed.
3039 Since it is no problem to reevaluate literals, we just return the
3041 inner = skip_simple_arithmetic (t);
3042 if (TREE_CODE (inner) == ERROR_MARK)
3045 if (tree_invariant_p_1 (inner))
3048 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
3049 it means that the size or offset of some field of an object depends on
3050 the value within another field.
3052 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
3053 and some variable since it would then need to be both evaluated once and
3054 evaluated more than once. Front-ends must assure this case cannot
3055 happen by surrounding any such subexpressions in their own SAVE_EXPR
3056 and forcing evaluation at the proper time. */
3057 if (contains_placeholder_p (inner))
3060 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
3061 SET_EXPR_LOCATION (t, EXPR_LOCATION (expr));
3063 /* This expression might be placed ahead of a jump to ensure that the
3064 value was computed on both sides of the jump. So make sure it isn't
3065 eliminated as dead. */
3066 TREE_SIDE_EFFECTS (t) = 1;
3070 /* Look inside EXPR into any simple arithmetic operations. Return the
3071 outermost non-arithmetic or non-invariant node. */
3074 skip_simple_arithmetic (tree expr)
3076 /* We don't care about whether this can be used as an lvalue in this
3078 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
3079 expr = TREE_OPERAND (expr, 0);
3081 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
3082 a constant, it will be more efficient to not make another SAVE_EXPR since
3083 it will allow better simplification and GCSE will be able to merge the
3084 computations if they actually occur. */
3087 if (UNARY_CLASS_P (expr))
3088 expr = TREE_OPERAND (expr, 0);
3089 else if (BINARY_CLASS_P (expr))
3091 if (tree_invariant_p (TREE_OPERAND (expr, 1)))
3092 expr = TREE_OPERAND (expr, 0);
3093 else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
3094 expr = TREE_OPERAND (expr, 1);
3105 /* Look inside EXPR into simple arithmetic operations involving constants.
3106 Return the outermost non-arithmetic or non-constant node. */
3109 skip_simple_constant_arithmetic (tree expr)
3111 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
3112 expr = TREE_OPERAND (expr, 0);
3116 if (UNARY_CLASS_P (expr))
3117 expr = TREE_OPERAND (expr, 0);
3118 else if (BINARY_CLASS_P (expr))
3120 if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
3121 expr = TREE_OPERAND (expr, 0);
3122 else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
3123 expr = TREE_OPERAND (expr, 1);
3134 /* Return which tree structure is used by T. */
3136 enum tree_node_structure_enum
3137 tree_node_structure (const_tree t)
3139 const enum tree_code code = TREE_CODE (t);
3140 return tree_node_structure_for_code (code);
3143 /* Set various status flags when building a CALL_EXPR object T. */
3146 process_call_operands (tree t)
3148 bool side_effects = TREE_SIDE_EFFECTS (t);
3149 bool read_only = false;
3150 int i = call_expr_flags (t);
3152 /* Calls have side-effects, except those to const or pure functions. */
3153 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
3154 side_effects = true;
3155 /* Propagate TREE_READONLY of arguments for const functions. */
3159 if (!side_effects || read_only)
3160 for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
3162 tree op = TREE_OPERAND (t, i);
3163 if (op && TREE_SIDE_EFFECTS (op))
3164 side_effects = true;
3165 if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
3169 TREE_SIDE_EFFECTS (t) = side_effects;
3170 TREE_READONLY (t) = read_only;
3173 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3174 size or offset that depends on a field within a record. */
3177 contains_placeholder_p (const_tree exp)
3179 enum tree_code code;
3184 code = TREE_CODE (exp);
3185 if (code == PLACEHOLDER_EXPR)
3188 switch (TREE_CODE_CLASS (code))
3191 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3192 position computations since they will be converted into a
3193 WITH_RECORD_EXPR involving the reference, which will assume
3194 here will be valid. */
3195 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
3197 case tcc_exceptional:
3198 if (code == TREE_LIST)
3199 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
3200 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
3205 case tcc_comparison:
3206 case tcc_expression:
3210 /* Ignoring the first operand isn't quite right, but works best. */
3211 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
3214 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
3215 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
3216 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
3219 /* The save_expr function never wraps anything containing
3220 a PLACEHOLDER_EXPR. */
3227 switch (TREE_CODE_LENGTH (code))
3230 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
3232 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
3233 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
3244 const_call_expr_arg_iterator iter;
3245 FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
3246 if (CONTAINS_PLACEHOLDER_P (arg))
3260 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
3261 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
3265 type_contains_placeholder_1 (const_tree type)
3267 /* If the size contains a placeholder or the parent type (component type in
3268 the case of arrays) type involves a placeholder, this type does. */
3269 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
3270 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
3271 || (!POINTER_TYPE_P (type)
3273 && type_contains_placeholder_p (TREE_TYPE (type))))
3276 /* Now do type-specific checks. Note that the last part of the check above
3277 greatly limits what we have to do below. */
3278 switch (TREE_CODE (type))
3281 case POINTER_BOUNDS_TYPE:
3287 case REFERENCE_TYPE:
3296 case FIXED_POINT_TYPE:
3297 /* Here we just check the bounds. */
3298 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
3299 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
3302 /* We have already checked the component type above, so just check the
3304 return type_contains_placeholder_p (TYPE_DOMAIN (type));
3308 case QUAL_UNION_TYPE:
3312 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
3313 if (TREE_CODE (field) == FIELD_DECL
3314 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
3315 || (TREE_CODE (type) == QUAL_UNION_TYPE
3316 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
3317 || type_contains_placeholder_p (TREE_TYPE (field))))
3328 /* Wrapper around above function used to cache its result. */
3331 type_contains_placeholder_p (tree type)
3335 /* If the contains_placeholder_bits field has been initialized,
3336 then we know the answer. */
3337 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
3338 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
3340 /* Indicate that we've seen this type node, and the answer is false.
3341 This is what we want to return if we run into recursion via fields. */
3342 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
3344 /* Compute the real value. */
3345 result = type_contains_placeholder_1 (type);
3347 /* Store the real value. */
3348 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
3353 /* Push tree EXP onto vector QUEUE if it is not already present. */
3356 push_without_duplicates (tree exp, vec<tree> *queue)
3361 FOR_EACH_VEC_ELT (*queue, i, iter)
3362 if (simple_cst_equal (iter, exp) == 1)
3366 queue->safe_push (exp);
3369 /* Given a tree EXP, find all occurrences of references to fields
3370 in a PLACEHOLDER_EXPR and place them in vector REFS without
3371 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3372 we assume here that EXP contains only arithmetic expressions
3373 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3377 find_placeholder_in_expr (tree exp, vec<tree> *refs)
3379 enum tree_code code = TREE_CODE (exp);
3383 /* We handle TREE_LIST and COMPONENT_REF separately. */
3384 if (code == TREE_LIST)
3386 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
3387 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
3389 else if (code == COMPONENT_REF)
3391 for (inner = TREE_OPERAND (exp, 0);
3392 REFERENCE_CLASS_P (inner);
3393 inner = TREE_OPERAND (inner, 0))
3396 if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
3397 push_without_duplicates (exp, refs);
3399 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
3402 switch (TREE_CODE_CLASS (code))
3407 case tcc_declaration:
3408 /* Variables allocated to static storage can stay. */
3409 if (!TREE_STATIC (exp))
3410 push_without_duplicates (exp, refs);
3413 case tcc_expression:
3414 /* This is the pattern built in ada/make_aligning_type. */
3415 if (code == ADDR_EXPR
3416 && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
3418 push_without_duplicates (exp, refs);
3422 /* Fall through... */
3424 case tcc_exceptional:
3427 case tcc_comparison:
3429 for (i = 0; i < TREE_CODE_LENGTH (code); i++)
3430 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
3434 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
3435 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
3443 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3444 return a tree with all occurrences of references to F in a
3445 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3446 CONST_DECLs. Note that we assume here that EXP contains only
3447 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3448 occurring only in their argument list. */
3451 substitute_in_expr (tree exp, tree f, tree r)
3453 enum tree_code code = TREE_CODE (exp);
3454 tree op0, op1, op2, op3;
3457 /* We handle TREE_LIST and COMPONENT_REF separately. */
3458 if (code == TREE_LIST)
3460 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
3461 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
3462 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
3465 return tree_cons (TREE_PURPOSE (exp), op1, op0);
3467 else if (code == COMPONENT_REF)
3471 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3472 and it is the right field, replace it with R. */
3473 for (inner = TREE_OPERAND (exp, 0);
3474 REFERENCE_CLASS_P (inner);
3475 inner = TREE_OPERAND (inner, 0))
3479 op1 = TREE_OPERAND (exp, 1);
3481 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
3484 /* If this expression hasn't been completed let, leave it alone. */
3485 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
3488 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3489 if (op0 == TREE_OPERAND (exp, 0))
3493 = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
3496 switch (TREE_CODE_CLASS (code))
3501 case tcc_declaration:
3507 case tcc_expression:
3511 /* Fall through... */
3513 case tcc_exceptional:
3516 case tcc_comparison:
3518 switch (TREE_CODE_LENGTH (code))
3524 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3525 if (op0 == TREE_OPERAND (exp, 0))
3528 new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
3532 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3533 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
3535 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
3538 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
3542 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3543 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
3544 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
3546 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3547 && op2 == TREE_OPERAND (exp, 2))
3550 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
3554 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3555 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
3556 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
3557 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
3559 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3560 && op2 == TREE_OPERAND (exp, 2)
3561 && op3 == TREE_OPERAND (exp, 3))
3565 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
3577 new_tree = NULL_TREE;
3579 /* If we are trying to replace F with a constant, inline back
3580 functions which do nothing else than computing a value from
3581 the arguments they are passed. This makes it possible to
3582 fold partially or entirely the replacement expression. */
3583 if (CONSTANT_CLASS_P (r) && code == CALL_EXPR)
3585 tree t = maybe_inline_call_in_expr (exp);
3587 return SUBSTITUTE_IN_EXPR (t, f, r);
3590 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
3592 tree op = TREE_OPERAND (exp, i);
3593 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
3597 new_tree = copy_node (exp);
3598 TREE_OPERAND (new_tree, i) = new_op;
3604 new_tree = fold (new_tree);
3605 if (TREE_CODE (new_tree) == CALL_EXPR)
3606 process_call_operands (new_tree);
3617 TREE_READONLY (new_tree) |= TREE_READONLY (exp);
3619 if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
3620 TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
3625 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3626 for it within OBJ, a tree that is an object or a chain of references. */
3629 substitute_placeholder_in_expr (tree exp, tree obj)
3631 enum tree_code code = TREE_CODE (exp);
3632 tree op0, op1, op2, op3;
3635 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3636 in the chain of OBJ. */
3637 if (code == PLACEHOLDER_EXPR)
3639 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
3642 for (elt = obj; elt != 0;
3643 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
3644 || TREE_CODE (elt) == COND_EXPR)
3645 ? TREE_OPERAND (elt, 1)
3646 : (REFERENCE_CLASS_P (elt)
3647 || UNARY_CLASS_P (elt)
3648 || BINARY_CLASS_P (elt)
3649 || VL_EXP_CLASS_P (elt)
3650 || EXPRESSION_CLASS_P (elt))
3651 ? TREE_OPERAND (elt, 0) : 0))
3652 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
3655 for (elt = obj; elt != 0;
3656 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
3657 || TREE_CODE (elt) == COND_EXPR)
3658 ? TREE_OPERAND (elt, 1)
3659 : (REFERENCE_CLASS_P (elt)
3660 || UNARY_CLASS_P (elt)
3661 || BINARY_CLASS_P (elt)
3662 || VL_EXP_CLASS_P (elt)
3663 || EXPRESSION_CLASS_P (elt))
3664 ? TREE_OPERAND (elt, 0) : 0))
3665 if (POINTER_TYPE_P (TREE_TYPE (elt))
3666 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
3668 return fold_build1 (INDIRECT_REF, need_type, elt);
3670 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3671 survives until RTL generation, there will be an error. */
3675 /* TREE_LIST is special because we need to look at TREE_VALUE
3676 and TREE_CHAIN, not TREE_OPERANDS. */
3677 else if (code == TREE_LIST)
3679 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
3680 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
3681 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
3684 return tree_cons (TREE_PURPOSE (exp), op1, op0);
3687 switch (TREE_CODE_CLASS (code))
3690 case tcc_declaration:
3693 case tcc_exceptional:
3696 case tcc_comparison:
3697 case tcc_expression:
3700 switch (TREE_CODE_LENGTH (code))
3706 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3707 if (op0 == TREE_OPERAND (exp, 0))
3710 new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
3714 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3715 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
3717 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
3720 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
3724 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3725 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
3726 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
3728 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3729 && op2 == TREE_OPERAND (exp, 2))
3732 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
3736 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3737 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
3738 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
3739 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
3741 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3742 && op2 == TREE_OPERAND (exp, 2)
3743 && op3 == TREE_OPERAND (exp, 3))
3747 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
3759 new_tree = NULL_TREE;
3761 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
3763 tree op = TREE_OPERAND (exp, i);
3764 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
3768 new_tree = copy_node (exp);
3769 TREE_OPERAND (new_tree, i) = new_op;
3775 new_tree = fold (new_tree);
3776 if (TREE_CODE (new_tree) == CALL_EXPR)
3777 process_call_operands (new_tree);
3788 TREE_READONLY (new_tree) |= TREE_READONLY (exp);
3790 if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
3791 TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
3797 /* Subroutine of stabilize_reference; this is called for subtrees of
3798 references. Any expression with side-effects must be put in a SAVE_EXPR
3799 to ensure that it is only evaluated once.
3801 We don't put SAVE_EXPR nodes around everything, because assigning very
3802 simple expressions to temporaries causes us to miss good opportunities
3803 for optimizations. Among other things, the opportunity to fold in the
3804 addition of a constant into an addressing mode often gets lost, e.g.
3805 "y[i+1] += x;". In general, we take the approach that we should not make
3806 an assignment unless we are forced into it - i.e., that any non-side effect
3807 operator should be allowed, and that cse should take care of coalescing
3808 multiple utterances of the same expression should that prove fruitful. */
3811 stabilize_reference_1 (tree e)
3814 enum tree_code code = TREE_CODE (e);
3816 /* We cannot ignore const expressions because it might be a reference
3817 to a const array but whose index contains side-effects. But we can
3818 ignore things that are actual constant or that already have been
3819 handled by this function. */
3821 if (tree_invariant_p (e))
3824 switch (TREE_CODE_CLASS (code))
3826 case tcc_exceptional:
3828 case tcc_declaration:
3829 case tcc_comparison:
3831 case tcc_expression:
3834 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3835 so that it will only be evaluated once. */
3836 /* The reference (r) and comparison (<) classes could be handled as
3837 below, but it is generally faster to only evaluate them once. */
3838 if (TREE_SIDE_EFFECTS (e))
3839 return save_expr (e);
3843 /* Constants need no processing. In fact, we should never reach
3848 /* Division is slow and tends to be compiled with jumps,
3849 especially the division by powers of 2 that is often
3850 found inside of an array reference. So do it just once. */
3851 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
3852 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
3853 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
3854 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
3855 return save_expr (e);
3856 /* Recursively stabilize each operand. */
3857 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
3858 stabilize_reference_1 (TREE_OPERAND (e, 1)));
3862 /* Recursively stabilize each operand. */
3863 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
3870 TREE_TYPE (result) = TREE_TYPE (e);
3871 TREE_READONLY (result) = TREE_READONLY (e);
3872 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
3873 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
3878 /* Stabilize a reference so that we can use it any number of times
3879 without causing its operands to be evaluated more than once.
3880 Returns the stabilized reference. This works by means of save_expr,
3881 so see the caveats in the comments about save_expr.
3883 Also allows conversion expressions whose operands are references.
3884 Any other kind of expression is returned unchanged. */
3887 stabilize_reference (tree ref)
3890 enum tree_code code = TREE_CODE (ref);
3897 /* No action is needed in this case. */
3902 case FIX_TRUNC_EXPR:
3903 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
3907 result = build_nt (INDIRECT_REF,
3908 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
3912 result = build_nt (COMPONENT_REF,
3913 stabilize_reference (TREE_OPERAND (ref, 0)),
3914 TREE_OPERAND (ref, 1), NULL_TREE);
3918 result = build_nt (BIT_FIELD_REF,
3919 stabilize_reference (TREE_OPERAND (ref, 0)),
3920 TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
3924 result = build_nt (ARRAY_REF,
3925 stabilize_reference (TREE_OPERAND (ref, 0)),
3926 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
3927 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
3930 case ARRAY_RANGE_REF:
3931 result = build_nt (ARRAY_RANGE_REF,
3932 stabilize_reference (TREE_OPERAND (ref, 0)),
3933 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
3934 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
3938 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3939 it wouldn't be ignored. This matters when dealing with
3941 return stabilize_reference_1 (ref);
3943 /* If arg isn't a kind of lvalue we recognize, make no change.
3944 Caller should recognize the error for an invalid lvalue. */
3949 return error_mark_node;
3952 TREE_TYPE (result) = TREE_TYPE (ref);
3953 TREE_READONLY (result) = TREE_READONLY (ref);
3954 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
3955 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
3960 /* Low-level constructors for expressions. */
3962 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3963 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3966 recompute_tree_invariant_for_addr_expr (tree t)
3969 bool tc = true, se = false;
3971 /* We started out assuming this address is both invariant and constant, but
3972 does not have side effects. Now go down any handled components and see if
3973 any of them involve offsets that are either non-constant or non-invariant.
3974 Also check for side-effects.
3976 ??? Note that this code makes no attempt to deal with the case where
3977 taking the address of something causes a copy due to misalignment. */
3979 #define UPDATE_FLAGS(NODE) \
3980 do { tree _node = (NODE); \
3981 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3982 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3984 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
3985 node = TREE_OPERAND (node, 0))
3987 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3988 array reference (probably made temporarily by the G++ front end),
3989 so ignore all the operands. */
3990 if ((TREE_CODE (node) == ARRAY_REF
3991 || TREE_CODE (node) == ARRAY_RANGE_REF)
3992 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
3994 UPDATE_FLAGS (TREE_OPERAND (node, 1));
3995 if (TREE_OPERAND (node, 2))
3996 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3997 if (TREE_OPERAND (node, 3))
3998 UPDATE_FLAGS (TREE_OPERAND (node, 3));
4000 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
4001 FIELD_DECL, apparently. The G++ front end can put something else
4002 there, at least temporarily. */
4003 else if (TREE_CODE (node) == COMPONENT_REF
4004 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
4006 if (TREE_OPERAND (node, 2))
4007 UPDATE_FLAGS (TREE_OPERAND (node, 2));
4011 node = lang_hooks.expr_to_decl (node, &tc, &se);
4013 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
4014 the address, since &(*a)->b is a form of addition. If it's a constant, the
4015 address is constant too. If it's a decl, its address is constant if the
4016 decl is static. Everything else is not constant and, furthermore,
4017 taking the address of a volatile variable is not volatile. */
4018 if (TREE_CODE (node) == INDIRECT_REF
4019 || TREE_CODE (node) == MEM_REF)
4020 UPDATE_FLAGS (TREE_OPERAND (node, 0));
4021 else if (CONSTANT_CLASS_P (node))
4023 else if (DECL_P (node))
4024 tc &= (staticp (node) != NULL_TREE);
4028 se |= TREE_SIDE_EFFECTS (node);
4032 TREE_CONSTANT (t) = tc;
4033 TREE_SIDE_EFFECTS (t) = se;
4037 /* Build an expression of code CODE, data type TYPE, and operands as
4038 specified. Expressions and reference nodes can be created this way.
4039 Constants, decls, types and misc nodes cannot be.
4041 We define 5 non-variadic functions, from 0 to 4 arguments. This is
4042 enough for all extant tree codes. */
4045 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
4049 gcc_assert (TREE_CODE_LENGTH (code) == 0);
4051 t = make_node_stat (code PASS_MEM_STAT);
4058 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
4060 int length = sizeof (struct tree_exp);
4063 record_node_allocation_statistics (code, length);
4065 gcc_assert (TREE_CODE_LENGTH (code) == 1);
4067 t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
4069 memset (t, 0, sizeof (struct tree_common));
4071 TREE_SET_CODE (t, code);
4073 TREE_TYPE (t) = type;
4074 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
4075 TREE_OPERAND (t, 0) = node;
4076 if (node && !TYPE_P (node))
4078 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
4079 TREE_READONLY (t) = TREE_READONLY (node);
4082 if (TREE_CODE_CLASS (code) == tcc_statement)
4083 TREE_SIDE_EFFECTS (t) = 1;
4087 /* All of these have side-effects, no matter what their
4089 TREE_SIDE_EFFECTS (t) = 1;
4090 TREE_READONLY (t) = 0;
4094 /* Whether a dereference is readonly has nothing to do with whether
4095 its operand is readonly. */
4096 TREE_READONLY (t) = 0;
4101 recompute_tree_invariant_for_addr_expr (t);
4105 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
4106 && node && !TYPE_P (node)
4107 && TREE_CONSTANT (node))
4108 TREE_CONSTANT (t) = 1;
4109 if (TREE_CODE_CLASS (code) == tcc_reference
4110 && node && TREE_THIS_VOLATILE (node))
4111 TREE_THIS_VOLATILE (t) = 1;
4118 #define PROCESS_ARG(N) \
4120 TREE_OPERAND (t, N) = arg##N; \
4121 if (arg##N &&!TYPE_P (arg##N)) \
4123 if (TREE_SIDE_EFFECTS (arg##N)) \
4125 if (!TREE_READONLY (arg##N) \
4126 && !CONSTANT_CLASS_P (arg##N)) \
4127 (void) (read_only = 0); \
4128 if (!TREE_CONSTANT (arg##N)) \
4129 (void) (constant = 0); \
4134 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
4136 bool constant, read_only, side_effects;
4139 gcc_assert (TREE_CODE_LENGTH (code) == 2);
4141 if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
4142 && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
4143 /* When sizetype precision doesn't match that of pointers
4144 we need to be able to build explicit extensions or truncations
4145 of the offset argument. */
4146 && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
4147 gcc_assert (TREE_CODE (arg0) == INTEGER_CST
4148 && TREE_CODE (arg1) == INTEGER_CST);
4150 if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
4151 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
4152 && ptrofftype_p (TREE_TYPE (arg1)));
4154 t = make_node_stat (code PASS_MEM_STAT);
4157 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4158 result based on those same flags for the arguments. But if the
4159 arguments aren't really even `tree' expressions, we shouldn't be trying
4162 /* Expressions without side effects may be constant if their
4163 arguments are as well. */
4164 constant = (TREE_CODE_CLASS (code) == tcc_comparison
4165 || TREE_CODE_CLASS (code) == tcc_binary);
4167 side_effects = TREE_SIDE_EFFECTS (t);
4172 TREE_READONLY (t) = read_only;
4173 TREE_CONSTANT (t) = constant;
4174 TREE_SIDE_EFFECTS (t) = side_effects;
4175 TREE_THIS_VOLATILE (t)
4176 = (TREE_CODE_CLASS (code) == tcc_reference
4177 && arg0 && TREE_THIS_VOLATILE (arg0));
4184 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
4185 tree arg2 MEM_STAT_DECL)
4187 bool constant, read_only, side_effects;
4190 gcc_assert (TREE_CODE_LENGTH (code) == 3);
4191 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
4193 t = make_node_stat (code PASS_MEM_STAT);
4198 /* As a special exception, if COND_EXPR has NULL branches, we
4199 assume that it is a gimple statement and always consider
4200 it to have side effects. */
4201 if (code == COND_EXPR
4202 && tt == void_type_node
4203 && arg1 == NULL_TREE
4204 && arg2 == NULL_TREE)
4205 side_effects = true;
4207 side_effects = TREE_SIDE_EFFECTS (t);
4213 if (code == COND_EXPR)
4214 TREE_READONLY (t) = read_only;
4216 TREE_SIDE_EFFECTS (t) = side_effects;
4217 TREE_THIS_VOLATILE (t)
4218 = (TREE_CODE_CLASS (code) == tcc_reference
4219 && arg0 && TREE_THIS_VOLATILE (arg0));
4225 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
4226 tree arg2, tree arg3 MEM_STAT_DECL)
4228 bool constant, read_only, side_effects;
4231 gcc_assert (TREE_CODE_LENGTH (code) == 4);
4233 t = make_node_stat (code PASS_MEM_STAT);
4236 side_effects = TREE_SIDE_EFFECTS (t);
4243 TREE_SIDE_EFFECTS (t) = side_effects;
4244 TREE_THIS_VOLATILE (t)
4245 = (TREE_CODE_CLASS (code) == tcc_reference
4246 && arg0 && TREE_THIS_VOLATILE (arg0));
4252 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
4253 tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
4255 bool constant, read_only, side_effects;
4258 gcc_assert (TREE_CODE_LENGTH (code) == 5);
4260 t = make_node_stat (code PASS_MEM_STAT);
4263 side_effects = TREE_SIDE_EFFECTS (t);
4271 TREE_SIDE_EFFECTS (t) = side_effects;
4272 TREE_THIS_VOLATILE (t)
4273 = (TREE_CODE_CLASS (code) == tcc_reference
4274 && arg0 && TREE_THIS_VOLATILE (arg0));
4279 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
4280 on the pointer PTR. */
4283 build_simple_mem_ref_loc (location_t loc, tree ptr)
4285 HOST_WIDE_INT offset = 0;
4286 tree ptype = TREE_TYPE (ptr);
4288 /* For convenience allow addresses that collapse to a simple base
4290 if (TREE_CODE (ptr) == ADDR_EXPR
4291 && (handled_component_p (TREE_OPERAND (ptr, 0))
4292 || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
4294 ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
4296 ptr = build_fold_addr_expr (ptr);
4297 gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
4299 tem = build2 (MEM_REF, TREE_TYPE (ptype),
4300 ptr, build_int_cst (ptype, offset));
4301 SET_EXPR_LOCATION (tem, loc);
4305 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4308 mem_ref_offset (const_tree t)
4310 tree toff = TREE_OPERAND (t, 1);
4311 return tree_to_double_int (toff).sext (TYPE_PRECISION (TREE_TYPE (toff)));
4314 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4315 offsetted by OFFSET units. */
4318 build_invariant_address (tree type, tree base, HOST_WIDE_INT offset)
4320 tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
4321 build_fold_addr_expr (base),
4322 build_int_cst (ptr_type_node, offset));
4323 tree addr = build1 (ADDR_EXPR, type, ref);
4324 recompute_tree_invariant_for_addr_expr (addr);
4328 /* Similar except don't specify the TREE_TYPE
4329 and leave the TREE_SIDE_EFFECTS as 0.
4330 It is permissible for arguments to be null,
4331 or even garbage if their values do not matter. */
4334 build_nt (enum tree_code code, ...)
4341 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
4345 t = make_node (code);
4346 length = TREE_CODE_LENGTH (code);
4348 for (i = 0; i < length; i++)
4349 TREE_OPERAND (t, i) = va_arg (p, tree);
4355 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4359 build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
4364 ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
4365 CALL_EXPR_FN (ret) = fn;
4366 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
4367 FOR_EACH_VEC_SAFE_ELT (args, ix, t)
4368 CALL_EXPR_ARG (ret, ix) = t;
4372 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4373 We do NOT enter this node in any sort of symbol table.
4375 LOC is the location of the decl.
4377 layout_decl is used to set up the decl's storage layout.
4378 Other slots are initialized to 0 or null pointers. */
4381 build_decl_stat (location_t loc, enum tree_code code, tree name,
4382 tree type MEM_STAT_DECL)
4386 t = make_node_stat (code PASS_MEM_STAT);
4387 DECL_SOURCE_LOCATION (t) = loc;
4389 /* if (type == error_mark_node)
4390 type = integer_type_node; */
4391 /* That is not done, deliberately, so that having error_mark_node
4392 as the type can suppress useless errors in the use of this variable. */
4394 DECL_NAME (t) = name;
4395 TREE_TYPE (t) = type;
4397 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
4403 /* Builds and returns function declaration with NAME and TYPE. */
4406 build_fn_decl (const char *name, tree type)
4408 tree id = get_identifier (name);
4409 tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
4411 DECL_EXTERNAL (decl) = 1;
4412 TREE_PUBLIC (decl) = 1;
4413 DECL_ARTIFICIAL (decl) = 1;
4414 TREE_NOTHROW (decl) = 1;
4419 vec<tree, va_gc> *all_translation_units;
4421 /* Builds a new translation-unit decl with name NAME, queues it in the
4422 global list of translation-unit decls and returns it. */
4425 build_translation_unit_decl (tree name)
4427 tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
4429 TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
4430 vec_safe_push (all_translation_units, tu);
4435 /* BLOCK nodes are used to represent the structure of binding contours
4436 and declarations, once those contours have been exited and their contents
4437 compiled. This information is used for outputting debugging info. */
4440 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
4442 tree block = make_node (BLOCK);
4444 BLOCK_VARS (block) = vars;
4445 BLOCK_SUBBLOCKS (block) = subblocks;
4446 BLOCK_SUPERCONTEXT (block) = supercontext;
4447 BLOCK_CHAIN (block) = chain;
4452 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4454 LOC is the location to use in tree T. */
4457 protected_set_expr_location (tree t, location_t loc)
4459 if (t && CAN_HAVE_LOCATION_P (t))
4460 SET_EXPR_LOCATION (t, loc);
4463 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4467 build_decl_attribute_variant (tree ddecl, tree attribute)
4469 DECL_ATTRIBUTES (ddecl) = attribute;
4473 /* Borrowed from hashtab.c iterative_hash implementation. */
4474 #define mix(a,b,c) \
4476 a -= b; a -= c; a ^= (c>>13); \
4477 b -= c; b -= a; b ^= (a<< 8); \
4478 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
4479 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
4480 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
4481 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
4482 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
4483 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
4484 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
4488 /* Produce good hash value combining VAL and VAL2. */
4490 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
4492 /* the golden ratio; an arbitrary value. */
4493 hashval_t a = 0x9e3779b9;
4499 /* Produce good hash value combining VAL and VAL2. */
4501 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
4503 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
4504 return iterative_hash_hashval_t (val, val2);
4507 hashval_t a = (hashval_t) val;
4508 /* Avoid warnings about shifting of more than the width of the type on
4509 hosts that won't execute this path. */
4511 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
4513 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
4515 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
4516 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
4523 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4524 is ATTRIBUTE and its qualifiers are QUALS.
4526 Record such modified types already made so we don't make duplicates. */
4529 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
4531 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
4533 hashval_t hashcode = 0;
4535 enum tree_code code = TREE_CODE (ttype);
4537 /* Building a distinct copy of a tagged type is inappropriate; it
4538 causes breakage in code that expects there to be a one-to-one
4539 relationship between a struct and its fields.
4540 build_duplicate_type is another solution (as used in
4541 handle_transparent_union_attribute), but that doesn't play well
4542 with the stronger C++ type identity model. */
4543 if (TREE_CODE (ttype) == RECORD_TYPE
4544 || TREE_CODE (ttype) == UNION_TYPE
4545 || TREE_CODE (ttype) == QUAL_UNION_TYPE
4546 || TREE_CODE (ttype) == ENUMERAL_TYPE)
4548 warning (OPT_Wattributes,
4549 "ignoring attributes applied to %qT after definition",
4550 TYPE_MAIN_VARIANT (ttype));
4551 return build_qualified_type (ttype, quals);
4554 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
4555 ntype = build_distinct_type_copy (ttype);
4557 TYPE_ATTRIBUTES (ntype) = attribute;
4559 hashcode = iterative_hash_object (code, hashcode);
4560 if (TREE_TYPE (ntype))
4561 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
4563 hashcode = attribute_hash_list (attribute, hashcode);
4565 switch (TREE_CODE (ntype))
4568 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
4571 if (TYPE_DOMAIN (ntype))
4572 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
4576 hashcode = iterative_hash_object
4577 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
4578 hashcode = iterative_hash_object
4579 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
4582 case FIXED_POINT_TYPE:
4584 unsigned int precision = TYPE_PRECISION (ntype);
4585 hashcode = iterative_hash_object (precision, hashcode);
4592 ntype = type_hash_canon (hashcode, ntype);
4594 /* If the target-dependent attributes make NTYPE different from
4595 its canonical type, we will need to use structural equality
4596 checks for this type. */
4597 if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
4598 || !comp_type_attributes (ntype, ttype))
4599 SET_TYPE_STRUCTURAL_EQUALITY (ntype);
4600 else if (TYPE_CANONICAL (ntype) == ntype)
4601 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
4603 ttype = build_qualified_type (ntype, quals);
4605 else if (TYPE_QUALS (ttype) != quals)
4606 ttype = build_qualified_type (ttype, quals);
4611 /* Check if "omp declare simd" attribute arguments, CLAUSES1 and CLAUSES2, are
4615 omp_declare_simd_clauses_equal (tree clauses1, tree clauses2)
4618 for (cl1 = clauses1, cl2 = clauses2;
4620 cl1 = OMP_CLAUSE_CHAIN (cl1), cl2 = OMP_CLAUSE_CHAIN (cl2))
4622 if (OMP_CLAUSE_CODE (cl1) != OMP_CLAUSE_CODE (cl2))
4624 if (OMP_CLAUSE_CODE (cl1) != OMP_CLAUSE_SIMDLEN)
4626 if (simple_cst_equal (OMP_CLAUSE_DECL (cl1),
4627 OMP_CLAUSE_DECL (cl2)) != 1)
4630 switch (OMP_CLAUSE_CODE (cl1))
4632 case OMP_CLAUSE_ALIGNED:
4633 if (simple_cst_equal (OMP_CLAUSE_ALIGNED_ALIGNMENT (cl1),
4634 OMP_CLAUSE_ALIGNED_ALIGNMENT (cl2)) != 1)
4637 case OMP_CLAUSE_LINEAR:
4638 if (simple_cst_equal (OMP_CLAUSE_LINEAR_STEP (cl1),
4639 OMP_CLAUSE_LINEAR_STEP (cl2)) != 1)
4642 case OMP_CLAUSE_SIMDLEN:
4643 if (simple_cst_equal (OMP_CLAUSE_SIMDLEN_EXPR (cl1),
4644 OMP_CLAUSE_SIMDLEN_EXPR (cl2)) != 1)
4653 /* Compare two constructor-element-type constants. Return 1 if the lists
4654 are known to be equal; otherwise return 0. */
4657 simple_cst_list_equal (const_tree l1, const_tree l2)
4659 while (l1 != NULL_TREE && l2 != NULL_TREE)
4661 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
4664 l1 = TREE_CHAIN (l1);
4665 l2 = TREE_CHAIN (l2);
4671 /* Compare two attributes for their value identity. Return true if the
4672 attribute values are known to be equal; otherwise return false.
4676 attribute_value_equal (const_tree attr1, const_tree attr2)
4678 if (TREE_VALUE (attr1) == TREE_VALUE (attr2))
4681 if (TREE_VALUE (attr1) != NULL_TREE
4682 && TREE_CODE (TREE_VALUE (attr1)) == TREE_LIST
4683 && TREE_VALUE (attr2) != NULL
4684 && TREE_CODE (TREE_VALUE (attr2)) == TREE_LIST)
4685 return (simple_cst_list_equal (TREE_VALUE (attr1),
4686 TREE_VALUE (attr2)) == 1);
4688 if ((flag_openmp || flag_openmp_simd)
4689 && TREE_VALUE (attr1) && TREE_VALUE (attr2)
4690 && TREE_CODE (TREE_VALUE (attr1)) == OMP_CLAUSE
4691 && TREE_CODE (TREE_VALUE (attr2)) == OMP_CLAUSE)
4692 return omp_declare_simd_clauses_equal (TREE_VALUE (attr1),
4693 TREE_VALUE (attr2));
4695 return (simple_cst_equal (TREE_VALUE (attr1), TREE_VALUE (attr2)) == 1);
4698 /* Return 0 if the attributes for two types are incompatible, 1 if they
4699 are compatible, and 2 if they are nearly compatible (which causes a
4700 warning to be generated). */
4702 comp_type_attributes (const_tree type1, const_tree type2)
4704 const_tree a1 = TYPE_ATTRIBUTES (type1);
4705 const_tree a2 = TYPE_ATTRIBUTES (type2);
4710 for (a = a1; a != NULL_TREE; a = TREE_CHAIN (a))
4712 const struct attribute_spec *as;
4715 as = lookup_attribute_spec (get_attribute_name (a));
4716 if (!as || as->affects_type_identity == false)
4719 attr = lookup_attribute (as->name, CONST_CAST_TREE (a2));
4720 if (!attr || !attribute_value_equal (a, attr))
4725 for (a = a2; a != NULL_TREE; a = TREE_CHAIN (a))
4727 const struct attribute_spec *as;
4729 as = lookup_attribute_spec (get_attribute_name (a));
4730 if (!as || as->affects_type_identity == false)
4733 if (!lookup_attribute (as->name, CONST_CAST_TREE (a1)))
4735 /* We don't need to compare trees again, as we did this
4736 already in first loop. */
4738 /* All types - affecting identity - are equal, so
4739 there is no need to call target hook for comparison. */
4743 /* As some type combinations - like default calling-convention - might
4744 be compatible, we have to call the target hook to get the final result. */
4745 return targetm.comp_type_attributes (type1, type2);
4748 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4751 Record such modified types already made so we don't make duplicates. */
4754 build_type_attribute_variant (tree ttype, tree attribute)
4756 return build_type_attribute_qual_variant (ttype, attribute,
4757 TYPE_QUALS (ttype));
4761 /* Reset the expression *EXPR_P, a size or position.
4763 ??? We could reset all non-constant sizes or positions. But it's cheap
4764 enough to not do so and refrain from adding workarounds to dwarf2out.c.
4766 We need to reset self-referential sizes or positions because they cannot
4767 be gimplified and thus can contain a CALL_EXPR after the gimplification
4768 is finished, which will run afoul of LTO streaming. And they need to be
4769 reset to something essentially dummy but not constant, so as to preserve
4770 the properties of the object they are attached to. */
4773 free_lang_data_in_one_sizepos (tree *expr_p)
4775 tree expr = *expr_p;
4776 if (CONTAINS_PLACEHOLDER_P (expr))
4777 *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
4781 /* Reset all the fields in a binfo node BINFO. We only keep
4782 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
4785 free_lang_data_in_binfo (tree binfo)
4790 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
4792 BINFO_VIRTUALS (binfo) = NULL_TREE;
4793 BINFO_BASE_ACCESSES (binfo) = NULL;
4794 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
4795 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
4797 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
4798 free_lang_data_in_binfo (t);
4802 /* Reset all language specific information still present in TYPE. */
4805 free_lang_data_in_type (tree type)
4807 gcc_assert (TYPE_P (type));
4809 /* Give the FE a chance to remove its own data first. */
4810 lang_hooks.free_lang_data (type);
4812 TREE_LANG_FLAG_0 (type) = 0;
4813 TREE_LANG_FLAG_1 (type) = 0;
4814 TREE_LANG_FLAG_2 (type) = 0;
4815 TREE_LANG_FLAG_3 (type) = 0;
4816 TREE_LANG_FLAG_4 (type) = 0;
4817 TREE_LANG_FLAG_5 (type) = 0;
4818 TREE_LANG_FLAG_6 (type) = 0;
4820 if (TREE_CODE (type) == FUNCTION_TYPE)
4822 /* Remove the const and volatile qualifiers from arguments. The
4823 C++ front end removes them, but the C front end does not,
4824 leading to false ODR violation errors when merging two
4825 instances of the same function signature compiled by
4826 different front ends. */
4829 for (p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
4831 tree arg_type = TREE_VALUE (p);
4833 if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
4835 int quals = TYPE_QUALS (arg_type)
4837 & ~TYPE_QUAL_VOLATILE;
4838 TREE_VALUE (p) = build_qualified_type (arg_type, quals);
4839 free_lang_data_in_type (TREE_VALUE (p));
4844 /* Remove members that are not actually FIELD_DECLs from the field
4845 list of an aggregate. These occur in C++. */
4846 if (RECORD_OR_UNION_TYPE_P (type))
4850 /* Note that TYPE_FIELDS can be shared across distinct
4851 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4852 to be removed, we cannot set its TREE_CHAIN to NULL.
4853 Otherwise, we would not be able to find all the other fields
4854 in the other instances of this TREE_TYPE.
4856 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4858 member = TYPE_FIELDS (type);
4861 if (TREE_CODE (member) == FIELD_DECL
4862 || TREE_CODE (member) == TYPE_DECL)
4865 TREE_CHAIN (prev) = member;
4867 TYPE_FIELDS (type) = member;
4871 member = TREE_CHAIN (member);
4875 TREE_CHAIN (prev) = NULL_TREE;
4877 TYPE_FIELDS (type) = NULL_TREE;
4879 TYPE_METHODS (type) = NULL_TREE;
4880 if (TYPE_BINFO (type))
4881 free_lang_data_in_binfo (TYPE_BINFO (type));
4885 /* For non-aggregate types, clear out the language slot (which
4886 overloads TYPE_BINFO). */
4887 TYPE_LANG_SLOT_1 (type) = NULL_TREE;
4889 if (INTEGRAL_TYPE_P (type)
4890 || SCALAR_FLOAT_TYPE_P (type)
4891 || FIXED_POINT_TYPE_P (type))
4893 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
4894 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
4898 free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
4899 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
4901 if (TYPE_CONTEXT (type)
4902 && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
4904 tree ctx = TYPE_CONTEXT (type);
4907 ctx = BLOCK_SUPERCONTEXT (ctx);
4909 while (ctx && TREE_CODE (ctx) == BLOCK);
4910 TYPE_CONTEXT (type) = ctx;
4915 /* Return true if DECL may need an assembler name to be set. */
4918 need_assembler_name_p (tree decl)
4920 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4921 if (TREE_CODE (decl) != FUNCTION_DECL
4922 && TREE_CODE (decl) != VAR_DECL)
4925 /* If DECL already has its assembler name set, it does not need a
4927 if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
4928 || DECL_ASSEMBLER_NAME_SET_P (decl))
4931 /* Abstract decls do not need an assembler name. */
4932 if (DECL_ABSTRACT (decl))
4935 /* For VAR_DECLs, only static, public and external symbols need an
4937 if (TREE_CODE (decl) == VAR_DECL
4938 && !TREE_STATIC (decl)
4939 && !TREE_PUBLIC (decl)
4940 && !DECL_EXTERNAL (decl))
4943 if (TREE_CODE (decl) == FUNCTION_DECL)
4945 /* Do not set assembler name on builtins. Allow RTL expansion to
4946 decide whether to expand inline or via a regular call. */
4947 if (DECL_BUILT_IN (decl)
4948 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
4951 /* Functions represented in the callgraph need an assembler name. */
4952 if (cgraph_get_node (decl) != NULL)
4955 /* Unused and not public functions don't need an assembler name. */
4956 if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
4964 /* Reset all language specific information still present in symbol
4968 free_lang_data_in_decl (tree decl)
4970 gcc_assert (DECL_P (decl));
4972 /* Give the FE a chance to remove its own data first. */
4973 lang_hooks.free_lang_data (decl);
4975 TREE_LANG_FLAG_0 (decl) = 0;
4976 TREE_LANG_FLAG_1 (decl) = 0;
4977 TREE_LANG_FLAG_2 (decl) = 0;
4978 TREE_LANG_FLAG_3 (decl) = 0;
4979 TREE_LANG_FLAG_4 (decl) = 0;
4980 TREE_LANG_FLAG_5 (decl) = 0;
4981 TREE_LANG_FLAG_6 (decl) = 0;
4983 free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
4984 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
4985 if (TREE_CODE (decl) == FIELD_DECL)
4987 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
4988 if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
4989 DECL_QUALIFIER (decl) = NULL_TREE;
4992 if (TREE_CODE (decl) == FUNCTION_DECL)
4994 struct cgraph_node *node;
4995 if (!(node = cgraph_get_node (decl))
4996 || (!node->definition && !node->clones))
4999 cgraph_release_function_body (node);
5002 release_function_body (decl);
5003 DECL_ARGUMENTS (decl) = NULL;
5004 DECL_RESULT (decl) = NULL;
5005 DECL_INITIAL (decl) = error_mark_node;
5008 if (gimple_has_body_p (decl))
5012 /* If DECL has a gimple body, then the context for its
5013 arguments must be DECL. Otherwise, it doesn't really
5014 matter, as we will not be emitting any code for DECL. In
5015 general, there may be other instances of DECL created by
5016 the front end and since PARM_DECLs are generally shared,
5017 their DECL_CONTEXT changes as the replicas of DECL are
5018 created. The only time where DECL_CONTEXT is important
5019 is for the FUNCTION_DECLs that have a gimple body (since
5020 the PARM_DECL will be used in the function's body). */
5021 for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
5022 DECL_CONTEXT (t) = decl;
5025 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
5026 At this point, it is not needed anymore. */
5027 DECL_SAVED_TREE (decl) = NULL_TREE;
5029 /* Clear the abstract origin if it refers to a method. Otherwise
5030 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
5031 origin will not be output correctly. */
5032 if (DECL_ABSTRACT_ORIGIN (decl)
5033 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
5034 && RECORD_OR_UNION_TYPE_P
5035 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
5036 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
5038 /* Sometimes the C++ frontend doesn't manage to transform a temporary
5039 DECL_VINDEX referring to itself into a vtable slot number as it
5040 should. Happens with functions that are copied and then forgotten
5041 about. Just clear it, it won't matter anymore. */
5042 if (DECL_VINDEX (decl) && !host_integerp (DECL_VINDEX (decl), 0))
5043 DECL_VINDEX (decl) = NULL_TREE;
5045 else if (TREE_CODE (decl) == VAR_DECL)
5047 if ((DECL_EXTERNAL (decl)
5048 && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
5049 || (decl_function_context (decl) && !TREE_STATIC (decl)))
5050 DECL_INITIAL (decl) = NULL_TREE;
5052 else if (TREE_CODE (decl) == TYPE_DECL
5053 || TREE_CODE (decl) == FIELD_DECL)
5054 DECL_INITIAL (decl) = NULL_TREE;
5055 else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
5056 && DECL_INITIAL (decl)
5057 && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
5059 /* Strip builtins from the translation-unit BLOCK. We still have targets
5060 without builtin_decl_explicit support and also builtins are shared
5061 nodes and thus we can't use TREE_CHAIN in multiple lists. */
5062 tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
5066 if (TREE_CODE (var) == FUNCTION_DECL
5067 && DECL_BUILT_IN (var))
5068 *nextp = TREE_CHAIN (var);
5070 nextp = &TREE_CHAIN (var);
5076 /* Data used when collecting DECLs and TYPEs for language data removal. */
5078 struct free_lang_data_d
5080 /* Worklist to avoid excessive recursion. */
5083 /* Set of traversed objects. Used to avoid duplicate visits. */
5084 struct pointer_set_t *pset;
5086 /* Array of symbols to process with free_lang_data_in_decl. */
5089 /* Array of types to process with free_lang_data_in_type. */
5094 /* Save all language fields needed to generate proper debug information
5095 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
5098 save_debug_info_for_decl (tree t)
5100 /*struct saved_debug_info_d *sdi;*/
5102 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && DECL_P (t));
5104 /* FIXME. Partial implementation for saving debug info removed. */
5108 /* Save all language fields needed to generate proper debug information
5109 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
5112 save_debug_info_for_type (tree t)
5114 /*struct saved_debug_info_d *sdi;*/
5116 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && TYPE_P (t));
5118 /* FIXME. Partial implementation for saving debug info removed. */
5122 /* Add type or decl T to one of the list of tree nodes that need their
5123 language data removed. The lists are held inside FLD. */
5126 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld)
5130 fld->decls.safe_push (t);
5131 if (debug_info_level > DINFO_LEVEL_TERSE)
5132 save_debug_info_for_decl (t);
5134 else if (TYPE_P (t))
5136 fld->types.safe_push (t);
5137 if (debug_info_level > DINFO_LEVEL_TERSE)
5138 save_debug_info_for_type (t);
5144 /* Push tree node T into FLD->WORKLIST. */
5147 fld_worklist_push (tree t, struct free_lang_data_d *fld)
5149 if (t && !is_lang_specific (t) && !pointer_set_contains (fld->pset, t))
5150 fld->worklist.safe_push ((t));
5154 /* Operand callback helper for free_lang_data_in_node. *TP is the
5155 subtree operand being considered. */
5158 find_decls_types_r (tree *tp, int *ws, void *data)
5161 struct free_lang_data_d *fld = (struct free_lang_data_d *) data;
5163 if (TREE_CODE (t) == TREE_LIST)
5166 /* Language specific nodes will be removed, so there is no need
5167 to gather anything under them. */
5168 if (is_lang_specific (t))
5176 /* Note that walk_tree does not traverse every possible field in
5177 decls, so we have to do our own traversals here. */
5178 add_tree_to_fld_list (t, fld);
5180 fld_worklist_push (DECL_NAME (t), fld);
5181 fld_worklist_push (DECL_CONTEXT (t), fld);
5182 fld_worklist_push (DECL_SIZE (t), fld);
5183 fld_worklist_push (DECL_SIZE_UNIT (t), fld);
5185 /* We are going to remove everything under DECL_INITIAL for
5186 TYPE_DECLs. No point walking them. */
5187 if (TREE_CODE (t) != TYPE_DECL)
5188 fld_worklist_push (DECL_INITIAL (t), fld);
5190 fld_worklist_push (DECL_ATTRIBUTES (t), fld);
5191 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
5193 if (TREE_CODE (t) == FUNCTION_DECL)
5195 fld_worklist_push (DECL_ARGUMENTS (t), fld);
5196 fld_worklist_push (DECL_RESULT (t), fld);
5198 else if (TREE_CODE (t) == TYPE_DECL)
5200 fld_worklist_push (DECL_ARGUMENT_FLD (t), fld);
5201 fld_worklist_push (DECL_VINDEX (t), fld);
5202 fld_worklist_push (DECL_ORIGINAL_TYPE (t), fld);
5204 else if (TREE_CODE (t) == FIELD_DECL)
5206 fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
5207 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
5208 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
5209 fld_worklist_push (DECL_FCONTEXT (t), fld);
5211 else if (TREE_CODE (t) == VAR_DECL)
5213 fld_worklist_push (DECL_SECTION_NAME (t), fld);
5214 fld_worklist_push (DECL_COMDAT_GROUP (t), fld);
5217 if ((TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == PARM_DECL)
5218 && DECL_HAS_VALUE_EXPR_P (t))
5219 fld_worklist_push (DECL_VALUE_EXPR (t), fld);
5221 if (TREE_CODE (t) != FIELD_DECL
5222 && TREE_CODE (t) != TYPE_DECL)
5223 fld_worklist_push (TREE_CHAIN (t), fld);
5226 else if (TYPE_P (t))
5228 /* Note that walk_tree does not traverse every possible field in
5229 types, so we have to do our own traversals here. */
5230 add_tree_to_fld_list (t, fld);
5232 if (!RECORD_OR_UNION_TYPE_P (t))
5233 fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
5234 fld_worklist_push (TYPE_SIZE (t), fld);
5235 fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
5236 fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
5237 fld_worklist_push (TYPE_POINTER_TO (t), fld);
5238 fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
5239 fld_worklist_push (TYPE_NAME (t), fld);
5240 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
5241 them and thus do not and want not to reach unused pointer types
5243 if (!POINTER_TYPE_P (t))
5244 fld_worklist_push (TYPE_MINVAL (t), fld);
5245 if (!RECORD_OR_UNION_TYPE_P (t))
5246 fld_worklist_push (TYPE_MAXVAL (t), fld);
5247 fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
5248 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
5249 do not and want not to reach unused variants this way. */
5250 if (TYPE_CONTEXT (t))
5252 tree ctx = TYPE_CONTEXT (t);
5253 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
5254 So push that instead. */
5255 while (ctx && TREE_CODE (ctx) == BLOCK)
5256 ctx = BLOCK_SUPERCONTEXT (ctx);
5257 fld_worklist_push (ctx, fld);
5259 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
5260 and want not to reach unused types this way. */
5262 if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
5266 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
5267 fld_worklist_push (TREE_TYPE (tem), fld);
5268 tem = BINFO_VIRTUALS (TYPE_BINFO (t));
5270 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
5271 && TREE_CODE (tem) == TREE_LIST)
5274 fld_worklist_push (TREE_VALUE (tem), fld);
5275 tem = TREE_CHAIN (tem);
5279 if (RECORD_OR_UNION_TYPE_P (t))
5282 /* Push all TYPE_FIELDS - there can be interleaving interesting
5283 and non-interesting things. */
5284 tem = TYPE_FIELDS (t);
5287 if (TREE_CODE (tem) == FIELD_DECL
5288 || TREE_CODE (tem) == TYPE_DECL)
5289 fld_worklist_push (tem, fld);
5290 tem = TREE_CHAIN (tem);
5294 fld_worklist_push (TYPE_STUB_DECL (t), fld);
5297 else if (TREE_CODE (t) == BLOCK)
5300 for (tem = BLOCK_VARS (t); tem; tem = TREE_CHAIN (tem))
5301 fld_worklist_push (tem, fld);
5302 for (tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
5303 fld_worklist_push (tem, fld);
5304 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
5307 if (TREE_CODE (t) != IDENTIFIER_NODE
5308 && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
5309 fld_worklist_push (TREE_TYPE (t), fld);
5315 /* Find decls and types in T. */
5318 find_decls_types (tree t, struct free_lang_data_d *fld)
5322 if (!pointer_set_contains (fld->pset, t))
5323 walk_tree (&t, find_decls_types_r, fld, fld->pset);
5324 if (fld->worklist.is_empty ())
5326 t = fld->worklist.pop ();
5330 /* Translate all the types in LIST with the corresponding runtime
5334 get_eh_types_for_runtime (tree list)
5338 if (list == NULL_TREE)
5341 head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
5343 list = TREE_CHAIN (list);
5346 tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
5347 TREE_CHAIN (prev) = n;
5348 prev = TREE_CHAIN (prev);
5349 list = TREE_CHAIN (list);
5356 /* Find decls and types referenced in EH region R and store them in
5357 FLD->DECLS and FLD->TYPES. */
5360 find_decls_types_in_eh_region (eh_region r, struct free_lang_data_d *fld)
5371 /* The types referenced in each catch must first be changed to the
5372 EH types used at runtime. This removes references to FE types
5374 for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
5376 c->type_list = get_eh_types_for_runtime (c->type_list);
5377 walk_tree (&c->type_list, find_decls_types_r, fld, fld->pset);
5382 case ERT_ALLOWED_EXCEPTIONS:
5383 r->u.allowed.type_list
5384 = get_eh_types_for_runtime (r->u.allowed.type_list);
5385 walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, fld->pset);
5388 case ERT_MUST_NOT_THROW:
5389 walk_tree (&r->u.must_not_throw.failure_decl,
5390 find_decls_types_r, fld, fld->pset);
5396 /* Find decls and types referenced in cgraph node N and store them in
5397 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5398 look for *every* kind of DECL and TYPE node reachable from N,
5399 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5400 NAMESPACE_DECLs, etc). */
5403 find_decls_types_in_node (struct cgraph_node *n, struct free_lang_data_d *fld)
5406 struct function *fn;
5410 find_decls_types (n->decl, fld);
5412 if (!gimple_has_body_p (n->decl))
5415 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
5417 fn = DECL_STRUCT_FUNCTION (n->decl);
5419 /* Traverse locals. */
5420 FOR_EACH_LOCAL_DECL (fn, ix, t)
5421 find_decls_types (t, fld);
5423 /* Traverse EH regions in FN. */
5426 FOR_ALL_EH_REGION_FN (r, fn)
5427 find_decls_types_in_eh_region (r, fld);
5430 /* Traverse every statement in FN. */
5431 FOR_EACH_BB_FN (bb, fn)
5433 gimple_stmt_iterator si;
5436 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
5438 gimple phi = gsi_stmt (si);
5440 for (i = 0; i < gimple_phi_num_args (phi); i++)
5442 tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
5443 find_decls_types (*arg_p, fld);
5447 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
5449 gimple stmt = gsi_stmt (si);
5451 if (is_gimple_call (stmt))
5452 find_decls_types (gimple_call_fntype (stmt), fld);
5454 for (i = 0; i < gimple_num_ops (stmt); i++)
5456 tree arg = gimple_op (stmt, i);
5457 find_decls_types (arg, fld);
5464 /* Find decls and types referenced in varpool node N and store them in
5465 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5466 look for *every* kind of DECL and TYPE node reachable from N,
5467 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5468 NAMESPACE_DECLs, etc). */
5471 find_decls_types_in_var (struct varpool_node *v, struct free_lang_data_d *fld)
5473 find_decls_types (v->decl, fld);
5476 /* If T needs an assembler name, have one created for it. */
5479 assign_assembler_name_if_neeeded (tree t)
5481 if (need_assembler_name_p (t))
5483 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5484 diagnostics that use input_location to show locus
5485 information. The problem here is that, at this point,
5486 input_location is generally anchored to the end of the file
5487 (since the parser is long gone), so we don't have a good
5488 position to pin it to.
5490 To alleviate this problem, this uses the location of T's
5491 declaration. Examples of this are
5492 testsuite/g++.dg/template/cond2.C and
5493 testsuite/g++.dg/template/pr35240.C. */
5494 location_t saved_location = input_location;
5495 input_location = DECL_SOURCE_LOCATION (t);
5497 decl_assembler_name (t);
5499 input_location = saved_location;
5504 /* Free language specific information for every operand and expression
5505 in every node of the call graph. This process operates in three stages:
5507 1- Every callgraph node and varpool node is traversed looking for
5508 decls and types embedded in them. This is a more exhaustive
5509 search than that done by find_referenced_vars, because it will
5510 also collect individual fields, decls embedded in types, etc.
5512 2- All the decls found are sent to free_lang_data_in_decl.
5514 3- All the types found are sent to free_lang_data_in_type.
5516 The ordering between decls and types is important because
5517 free_lang_data_in_decl sets assembler names, which includes
5518 mangling. So types cannot be freed up until assembler names have
5522 free_lang_data_in_cgraph (void)
5524 struct cgraph_node *n;
5525 struct varpool_node *v;
5526 struct free_lang_data_d fld;
5531 /* Initialize sets and arrays to store referenced decls and types. */
5532 fld.pset = pointer_set_create ();
5533 fld.worklist.create (0);
5534 fld.decls.create (100);
5535 fld.types.create (100);
5537 /* Find decls and types in the body of every function in the callgraph. */
5538 FOR_EACH_FUNCTION (n)
5539 find_decls_types_in_node (n, &fld);
5541 FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
5542 find_decls_types (p->decl, &fld);
5544 /* Find decls and types in every varpool symbol. */
5545 FOR_EACH_VARIABLE (v)
5546 find_decls_types_in_var (v, &fld);
5548 /* Set the assembler name on every decl found. We need to do this
5549 now because free_lang_data_in_decl will invalidate data needed
5550 for mangling. This breaks mangling on interdependent decls. */
5551 FOR_EACH_VEC_ELT (fld.decls, i, t)
5552 assign_assembler_name_if_neeeded (t);
5554 /* Traverse every decl found freeing its language data. */
5555 FOR_EACH_VEC_ELT (fld.decls, i, t)
5556 free_lang_data_in_decl (t);
5558 /* Traverse every type found freeing its language data. */
5559 FOR_EACH_VEC_ELT (fld.types, i, t)
5560 free_lang_data_in_type (t);
5562 pointer_set_destroy (fld.pset);
5563 fld.worklist.release ();
5564 fld.decls.release ();
5565 fld.types.release ();
5569 /* Free resources that are used by FE but are not needed once they are done. */
5572 free_lang_data (void)
5576 /* If we are the LTO frontend we have freed lang-specific data already. */
5578 || !flag_generate_lto)
5581 /* Allocate and assign alias sets to the standard integer types
5582 while the slots are still in the way the frontends generated them. */
5583 for (i = 0; i < itk_none; ++i)
5584 if (integer_types[i])
5585 TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
5587 /* Traverse the IL resetting language specific information for
5588 operands, expressions, etc. */
5589 free_lang_data_in_cgraph ();
5591 /* Create gimple variants for common types. */
5592 ptrdiff_type_node = integer_type_node;
5593 fileptr_type_node = ptr_type_node;
5595 /* Reset some langhooks. Do not reset types_compatible_p, it may
5596 still be used indirectly via the get_alias_set langhook. */
5597 lang_hooks.dwarf_name = lhd_dwarf_name;
5598 lang_hooks.decl_printable_name = gimple_decl_printable_name;
5599 /* We do not want the default decl_assembler_name implementation,
5600 rather if we have fixed everything we want a wrapper around it
5601 asserting that all non-local symbols already got their assembler
5602 name and only produce assembler names for local symbols. Or rather
5603 make sure we never call decl_assembler_name on local symbols and
5604 devise a separate, middle-end private scheme for it. */
5606 /* Reset diagnostic machinery. */
5607 tree_diagnostics_defaults (global_dc);
5615 const pass_data pass_data_ipa_free_lang_data =
5617 SIMPLE_IPA_PASS, /* type */
5618 "*free_lang_data", /* name */
5619 OPTGROUP_NONE, /* optinfo_flags */
5620 false, /* has_gate */
5621 true, /* has_execute */
5622 TV_IPA_FREE_LANG_DATA, /* tv_id */
5623 0, /* properties_required */
5624 0, /* properties_provided */
5625 0, /* properties_destroyed */
5626 0, /* todo_flags_start */
5627 0, /* todo_flags_finish */
5630 class pass_ipa_free_lang_data : public simple_ipa_opt_pass
5633 pass_ipa_free_lang_data (gcc::context *ctxt)
5634 : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
5637 /* opt_pass methods: */
5638 unsigned int execute () { return free_lang_data (); }
5640 }; // class pass_ipa_free_lang_data
5644 simple_ipa_opt_pass *
5645 make_pass_ipa_free_lang_data (gcc::context *ctxt)
5647 return new pass_ipa_free_lang_data (ctxt);
5650 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of
5651 ATTR_NAME. Also used internally by remove_attribute(). */
5653 private_is_attribute_p (const char *attr_name, size_t attr_len, const_tree ident)
5655 size_t ident_len = IDENTIFIER_LENGTH (ident);
5657 if (ident_len == attr_len)
5659 if (strcmp (attr_name, IDENTIFIER_POINTER (ident)) == 0)
5662 else if (ident_len == attr_len + 4)
5664 /* There is the possibility that ATTR is 'text' and IDENT is
5666 const char *p = IDENTIFIER_POINTER (ident);
5667 if (p[0] == '_' && p[1] == '_'
5668 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
5669 && strncmp (attr_name, p + 2, attr_len) == 0)
5676 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
5677 of ATTR_NAME, and LIST is not NULL_TREE. */
5679 private_lookup_attribute (const char *attr_name, size_t attr_len, tree list)
5683 size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list));
5685 if (ident_len == attr_len)
5687 if (!strcmp (attr_name,
5688 IDENTIFIER_POINTER (get_attribute_name (list))))
5691 /* TODO: If we made sure that attributes were stored in the
5692 canonical form without '__...__' (ie, as in 'text' as opposed
5693 to '__text__') then we could avoid the following case. */
5694 else if (ident_len == attr_len + 4)
5696 const char *p = IDENTIFIER_POINTER (get_attribute_name (list));
5697 if (p[0] == '_' && p[1] == '_'
5698 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
5699 && strncmp (attr_name, p + 2, attr_len) == 0)
5702 list = TREE_CHAIN (list);
5708 /* A variant of lookup_attribute() that can be used with an identifier
5709 as the first argument, and where the identifier can be either
5710 'text' or '__text__'.
5712 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
5713 return a pointer to the attribute's list element if the attribute
5714 is part of the list, or NULL_TREE if not found. If the attribute
5715 appears more than once, this only returns the first occurrence; the
5716 TREE_CHAIN of the return value should be passed back in if further
5717 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
5718 can be in the form 'text' or '__text__'. */
5720 lookup_ident_attribute (tree attr_identifier, tree list)
5722 gcc_checking_assert (TREE_CODE (attr_identifier) == IDENTIFIER_NODE);
5726 gcc_checking_assert (TREE_CODE (get_attribute_name (list))
5727 == IDENTIFIER_NODE);
5729 /* Identifiers can be compared directly for equality. */
5730 if (attr_identifier == get_attribute_name (list))
5733 /* If they are not equal, they may still be one in the form
5734 'text' while the other one is in the form '__text__'. TODO:
5735 If we were storing attributes in normalized 'text' form, then
5736 this could all go away and we could take full advantage of
5737 the fact that we're comparing identifiers. :-) */
5739 size_t attr_len = IDENTIFIER_LENGTH (attr_identifier);
5740 size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list));
5742 if (ident_len == attr_len + 4)
5744 const char *p = IDENTIFIER_POINTER (get_attribute_name (list));
5745 const char *q = IDENTIFIER_POINTER (attr_identifier);
5746 if (p[0] == '_' && p[1] == '_'
5747 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
5748 && strncmp (q, p + 2, attr_len) == 0)
5751 else if (ident_len + 4 == attr_len)
5753 const char *p = IDENTIFIER_POINTER (get_attribute_name (list));
5754 const char *q = IDENTIFIER_POINTER (attr_identifier);
5755 if (q[0] == '_' && q[1] == '_'
5756 && q[attr_len - 2] == '_' && q[attr_len - 1] == '_'
5757 && strncmp (q + 2, p, ident_len) == 0)
5761 list = TREE_CHAIN (list);
5767 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5771 remove_attribute (const char *attr_name, tree list)
5774 size_t attr_len = strlen (attr_name);
5776 gcc_checking_assert (attr_name[0] != '_');
5778 for (p = &list; *p; )
5781 /* TODO: If we were storing attributes in normalized form, here
5782 we could use a simple strcmp(). */
5783 if (private_is_attribute_p (attr_name, attr_len, get_attribute_name (l)))
5784 *p = TREE_CHAIN (l);
5786 p = &TREE_CHAIN (l);
5792 /* Return an attribute list that is the union of a1 and a2. */
5795 merge_attributes (tree a1, tree a2)
5799 /* Either one unset? Take the set one. */
5801 if ((attributes = a1) == 0)
5804 /* One that completely contains the other? Take it. */
5806 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
5808 if (attribute_list_contained (a2, a1))
5812 /* Pick the longest list, and hang on the other list. */
5814 if (list_length (a1) < list_length (a2))
5815 attributes = a2, a2 = a1;
5817 for (; a2 != 0; a2 = TREE_CHAIN (a2))
5820 for (a = lookup_ident_attribute (get_attribute_name (a2),
5822 a != NULL_TREE && !attribute_value_equal (a, a2);
5823 a = lookup_ident_attribute (get_attribute_name (a2),
5828 a1 = copy_node (a2);
5829 TREE_CHAIN (a1) = attributes;
5838 /* Given types T1 and T2, merge their attributes and return
5842 merge_type_attributes (tree t1, tree t2)
5844 return merge_attributes (TYPE_ATTRIBUTES (t1),
5845 TYPE_ATTRIBUTES (t2));
5848 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5852 merge_decl_attributes (tree olddecl, tree newdecl)
5854 return merge_attributes (DECL_ATTRIBUTES (olddecl),
5855 DECL_ATTRIBUTES (newdecl));
5858 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5860 /* Specialization of merge_decl_attributes for various Windows targets.
5862 This handles the following situation:
5864 __declspec (dllimport) int foo;
5867 The second instance of `foo' nullifies the dllimport. */
5870 merge_dllimport_decl_attributes (tree old, tree new_tree)
5873 int delete_dllimport_p = 1;
5875 /* What we need to do here is remove from `old' dllimport if it doesn't
5876 appear in `new'. dllimport behaves like extern: if a declaration is
5877 marked dllimport and a definition appears later, then the object
5878 is not dllimport'd. We also remove a `new' dllimport if the old list
5879 contains dllexport: dllexport always overrides dllimport, regardless
5880 of the order of declaration. */
5881 if (!VAR_OR_FUNCTION_DECL_P (new_tree))
5882 delete_dllimport_p = 0;
5883 else if (DECL_DLLIMPORT_P (new_tree)
5884 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
5886 DECL_DLLIMPORT_P (new_tree) = 0;
5887 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
5888 "dllimport ignored", new_tree);
5890 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree))
5892 /* Warn about overriding a symbol that has already been used, e.g.:
5893 extern int __attribute__ ((dllimport)) foo;
5894 int* bar () {return &foo;}
5897 if (TREE_USED (old))
5899 warning (0, "%q+D redeclared without dllimport attribute "
5900 "after being referenced with dll linkage", new_tree);
5901 /* If we have used a variable's address with dllimport linkage,
5902 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5903 decl may already have had TREE_CONSTANT computed.
5904 We still remove the attribute so that assembler code refers
5905 to '&foo rather than '_imp__foo'. */
5906 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
5907 DECL_DLLIMPORT_P (new_tree) = 1;
5910 /* Let an inline definition silently override the external reference,
5911 but otherwise warn about attribute inconsistency. */
5912 else if (TREE_CODE (new_tree) == VAR_DECL
5913 || !DECL_DECLARED_INLINE_P (new_tree))
5914 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
5915 "previous dllimport ignored", new_tree);
5918 delete_dllimport_p = 0;
5920 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree));
5922 if (delete_dllimport_p)
5923 a = remove_attribute ("dllimport", a);
5928 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5929 struct attribute_spec.handler. */
5932 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
5938 /* These attributes may apply to structure and union types being created,
5939 but otherwise should pass to the declaration involved. */
5942 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
5943 | (int) ATTR_FLAG_ARRAY_NEXT))
5945 *no_add_attrs = true;
5946 return tree_cons (name, args, NULL_TREE);
5948 if (TREE_CODE (node) == RECORD_TYPE
5949 || TREE_CODE (node) == UNION_TYPE)
5951 node = TYPE_NAME (node);
5957 warning (OPT_Wattributes, "%qE attribute ignored",
5959 *no_add_attrs = true;
5964 if (TREE_CODE (node) != FUNCTION_DECL
5965 && TREE_CODE (node) != VAR_DECL
5966 && TREE_CODE (node) != TYPE_DECL)
5968 *no_add_attrs = true;
5969 warning (OPT_Wattributes, "%qE attribute ignored",
5974 if (TREE_CODE (node) == TYPE_DECL
5975 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE
5976 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE)
5978 *no_add_attrs = true;
5979 warning (OPT_Wattributes, "%qE attribute ignored",
5984 is_dllimport = is_attribute_p ("dllimport", name);
5986 /* Report error on dllimport ambiguities seen now before they cause
5990 /* Honor any target-specific overrides. */
5991 if (!targetm.valid_dllimport_attribute_p (node))
5992 *no_add_attrs = true;
5994 else if (TREE_CODE (node) == FUNCTION_DECL
5995 && DECL_DECLARED_INLINE_P (node))
5997 warning (OPT_Wattributes, "inline function %q+D declared as "
5998 " dllimport: attribute ignored", node);
5999 *no_add_attrs = true;
6001 /* Like MS, treat definition of dllimported variables and
6002 non-inlined functions on declaration as syntax errors. */
6003 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
6005 error ("function %q+D definition is marked dllimport", node);
6006 *no_add_attrs = true;
6009 else if (TREE_CODE (node) == VAR_DECL)
6011 if (DECL_INITIAL (node))
6013 error ("variable %q+D definition is marked dllimport",
6015 *no_add_attrs = true;
6018 /* `extern' needn't be specified with dllimport.
6019 Specify `extern' now and hope for the best. Sigh. */
6020 DECL_EXTERNAL (node) = 1;
6021 /* Also, implicitly give dllimport'd variables declared within
6022 a function global scope, unless declared static. */
6023 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
6024 TREE_PUBLIC (node) = 1;
6027 if (*no_add_attrs == false)
6028 DECL_DLLIMPORT_P (node) = 1;
6030 else if (TREE_CODE (node) == FUNCTION_DECL
6031 && DECL_DECLARED_INLINE_P (node)
6032 && flag_keep_inline_dllexport)
6033 /* An exported function, even if inline, must be emitted. */
6034 DECL_EXTERNAL (node) = 0;
6036 /* Report error if symbol is not accessible at global scope. */
6037 if (!TREE_PUBLIC (node)
6038 && (TREE_CODE (node) == VAR_DECL
6039 || TREE_CODE (node) == FUNCTION_DECL))
6041 error ("external linkage required for symbol %q+D because of "
6042 "%qE attribute", node, name);
6043 *no_add_attrs = true;
6046 /* A dllexport'd entity must have default visibility so that other
6047 program units (shared libraries or the main executable) can see
6048 it. A dllimport'd entity must have default visibility so that
6049 the linker knows that undefined references within this program
6050 unit can be resolved by the dynamic linker. */
6053 if (DECL_VISIBILITY_SPECIFIED (node)
6054 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT)
6055 error ("%qE implies default visibility, but %qD has already "
6056 "been declared with a different visibility",
6058 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT;
6059 DECL_VISIBILITY_SPECIFIED (node) = 1;
6065 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
6067 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
6068 of the various TYPE_QUAL values. */
6071 set_type_quals (tree type, int type_quals)
6073 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
6074 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
6075 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
6076 TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
6077 TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
6080 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
6083 check_qualified_type (const_tree cand, const_tree base, int type_quals)
6085 return (TYPE_QUALS (cand) == type_quals
6086 && TYPE_NAME (cand) == TYPE_NAME (base)
6087 /* Apparently this is needed for Objective-C. */
6088 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
6089 /* Check alignment. */
6090 && TYPE_ALIGN (cand) == TYPE_ALIGN (base)
6091 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
6092 TYPE_ATTRIBUTES (base)));
6095 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
6098 check_aligned_type (const_tree cand, const_tree base, unsigned int align)
6100 return (TYPE_QUALS (cand) == TYPE_QUALS (base)
6101 && TYPE_NAME (cand) == TYPE_NAME (base)
6102 /* Apparently this is needed for Objective-C. */
6103 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
6104 /* Check alignment. */
6105 && TYPE_ALIGN (cand) == align
6106 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
6107 TYPE_ATTRIBUTES (base)));
6110 /* This function checks to see if TYPE matches the size one of the built-in
6111 atomic types, and returns that core atomic type. */
6114 find_atomic_core_type (tree type)
6116 tree base_atomic_type;
6118 /* Only handle complete types. */
6119 if (TYPE_SIZE (type) == NULL_TREE)
6122 HOST_WIDE_INT type_size = tree_low_cst (TYPE_SIZE (type), 1);
6126 base_atomic_type = atomicQI_type_node;
6130 base_atomic_type = atomicHI_type_node;
6134 base_atomic_type = atomicSI_type_node;
6138 base_atomic_type = atomicDI_type_node;
6142 base_atomic_type = atomicTI_type_node;
6146 base_atomic_type = NULL_TREE;
6149 return base_atomic_type;
6152 /* Return a version of the TYPE, qualified as indicated by the
6153 TYPE_QUALS, if one exists. If no qualified version exists yet,
6154 return NULL_TREE. */
6157 get_qualified_type (tree type, int type_quals)
6161 if (TYPE_QUALS (type) == type_quals)
6164 /* Search the chain of variants to see if there is already one there just
6165 like the one we need to have. If so, use that existing one. We must
6166 preserve the TYPE_NAME, since there is code that depends on this. */
6167 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
6168 if (check_qualified_type (t, type, type_quals))
6174 /* Like get_qualified_type, but creates the type if it does not
6175 exist. This function never returns NULL_TREE. */
6178 build_qualified_type (tree type, int type_quals)
6182 /* See if we already have the appropriate qualified variant. */
6183 t = get_qualified_type (type, type_quals);
6185 /* If not, build it. */
6188 t = build_variant_type_copy (type);
6189 set_type_quals (t, type_quals);
6191 if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
6193 /* See if this object can map to a basic atomic type. */
6194 tree atomic_type = find_atomic_core_type (type);
6197 /* Ensure the alignment of this type is compatible with
6198 the required alignment of the atomic type. */
6199 if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
6200 TYPE_ALIGN (t) = TYPE_ALIGN (atomic_type);
6204 if (TYPE_STRUCTURAL_EQUALITY_P (type))
6205 /* Propagate structural equality. */
6206 SET_TYPE_STRUCTURAL_EQUALITY (t);
6207 else if (TYPE_CANONICAL (type) != type)
6208 /* Build the underlying canonical type, since it is different
6210 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type),
6213 /* T is its own canonical type. */
6214 TYPE_CANONICAL (t) = t;
6221 /* Create a variant of type T with alignment ALIGN. */
6224 build_aligned_type (tree type, unsigned int align)
6228 if (TYPE_PACKED (type)
6229 || TYPE_ALIGN (type) == align)
6232 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
6233 if (check_aligned_type (t, type, align))
6236 t = build_variant_type_copy (type);
6237 TYPE_ALIGN (t) = align;
6242 /* Create a new distinct copy of TYPE. The new type is made its own
6243 MAIN_VARIANT. If TYPE requires structural equality checks, the
6244 resulting type requires structural equality checks; otherwise, its
6245 TYPE_CANONICAL points to itself. */
6248 build_distinct_type_copy (tree type)
6250 tree t = copy_node (type);
6252 TYPE_POINTER_TO (t) = 0;
6253 TYPE_REFERENCE_TO (t) = 0;
6255 /* Set the canonical type either to a new equivalence class, or
6256 propagate the need for structural equality checks. */
6257 if (TYPE_STRUCTURAL_EQUALITY_P (type))
6258 SET_TYPE_STRUCTURAL_EQUALITY (t);
6260 TYPE_CANONICAL (t) = t;
6262 /* Make it its own variant. */
6263 TYPE_MAIN_VARIANT (t) = t;
6264 TYPE_NEXT_VARIANT (t) = 0;
6266 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
6267 whose TREE_TYPE is not t. This can also happen in the Ada
6268 frontend when using subtypes. */
6273 /* Create a new variant of TYPE, equivalent but distinct. This is so
6274 the caller can modify it. TYPE_CANONICAL for the return type will
6275 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
6276 are considered equal by the language itself (or that both types
6277 require structural equality checks). */
6280 build_variant_type_copy (tree type)
6282 tree t, m = TYPE_MAIN_VARIANT (type);
6284 t = build_distinct_type_copy (type);
6286 /* Since we're building a variant, assume that it is a non-semantic
6287 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
6288 TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
6290 /* Add the new type to the chain of variants of TYPE. */
6291 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
6292 TYPE_NEXT_VARIANT (m) = t;
6293 TYPE_MAIN_VARIANT (t) = m;
6298 /* Return true if the from tree in both tree maps are equal. */
6301 tree_map_base_eq (const void *va, const void *vb)
6303 const struct tree_map_base *const a = (const struct tree_map_base *) va,
6304 *const b = (const struct tree_map_base *) vb;
6305 return (a->from == b->from);
6308 /* Hash a from tree in a tree_base_map. */
6311 tree_map_base_hash (const void *item)
6313 return htab_hash_pointer (((const struct tree_map_base *)item)->from);
6316 /* Return true if this tree map structure is marked for garbage collection
6317 purposes. We simply return true if the from tree is marked, so that this
6318 structure goes away when the from tree goes away. */
6321 tree_map_base_marked_p (const void *p)
6323 return ggc_marked_p (((const struct tree_map_base *) p)->from);
6326 /* Hash a from tree in a tree_map. */
6329 tree_map_hash (const void *item)
6331 return (((const struct tree_map *) item)->hash);
6334 /* Hash a from tree in a tree_decl_map. */
6337 tree_decl_map_hash (const void *item)
6339 return DECL_UID (((const struct tree_decl_map *) item)->base.from);
6342 /* Return the initialization priority for DECL. */
6345 decl_init_priority_lookup (tree decl)
6347 struct tree_priority_map *h;
6348 struct tree_map_base in;
6350 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
6352 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
6353 return h ? h->init : DEFAULT_INIT_PRIORITY;
6356 /* Return the finalization priority for DECL. */
6359 decl_fini_priority_lookup (tree decl)
6361 struct tree_priority_map *h;
6362 struct tree_map_base in;
6364 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
6366 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
6367 return h ? h->fini : DEFAULT_INIT_PRIORITY;
6370 /* Return the initialization and finalization priority information for
6371 DECL. If there is no previous priority information, a freshly
6372 allocated structure is returned. */
6374 static struct tree_priority_map *
6375 decl_priority_info (tree decl)
6377 struct tree_priority_map in;
6378 struct tree_priority_map *h;
6381 in.base.from = decl;
6382 loc = htab_find_slot (init_priority_for_decl, &in, INSERT);
6383 h = (struct tree_priority_map *) *loc;
6386 h = ggc_alloc_cleared_tree_priority_map ();
6388 h->base.from = decl;
6389 h->init = DEFAULT_INIT_PRIORITY;
6390 h->fini = DEFAULT_INIT_PRIORITY;
6396 /* Set the initialization priority for DECL to PRIORITY. */
6399 decl_init_priority_insert (tree decl, priority_type priority)
6401 struct tree_priority_map *h;
6403 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
6404 if (priority == DEFAULT_INIT_PRIORITY)
6406 h = decl_priority_info (decl);
6410 /* Set the finalization priority for DECL to PRIORITY. */
6413 decl_fini_priority_insert (tree decl, priority_type priority)
6415 struct tree_priority_map *h;
6417 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
6418 if (priority == DEFAULT_INIT_PRIORITY)
6420 h = decl_priority_info (decl);
6424 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6427 print_debug_expr_statistics (void)
6429 fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
6430 (long) htab_size (debug_expr_for_decl),
6431 (long) htab_elements (debug_expr_for_decl),
6432 htab_collisions (debug_expr_for_decl));
6435 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6438 print_value_expr_statistics (void)
6440 fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
6441 (long) htab_size (value_expr_for_decl),
6442 (long) htab_elements (value_expr_for_decl),
6443 htab_collisions (value_expr_for_decl));
6446 /* Lookup a debug expression for FROM, and return it if we find one. */
6449 decl_debug_expr_lookup (tree from)
6451 struct tree_decl_map *h, in;
6452 in.base.from = from;
6454 h = (struct tree_decl_map *)
6455 htab_find_with_hash (debug_expr_for_decl, &in, DECL_UID (from));
6461 /* Insert a mapping FROM->TO in the debug expression hashtable. */
6464 decl_debug_expr_insert (tree from, tree to)
6466 struct tree_decl_map *h;
6469 h = ggc_alloc_tree_decl_map ();
6470 h->base.from = from;
6472 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, DECL_UID (from),
6474 *(struct tree_decl_map **) loc = h;
6477 /* Lookup a value expression for FROM, and return it if we find one. */
6480 decl_value_expr_lookup (tree from)
6482 struct tree_decl_map *h, in;
6483 in.base.from = from;
6485 h = (struct tree_decl_map *)
6486 htab_find_with_hash (value_expr_for_decl, &in, DECL_UID (from));
6492 /* Insert a mapping FROM->TO in the value expression hashtable. */
6495 decl_value_expr_insert (tree from, tree to)
6497 struct tree_decl_map *h;
6500 h = ggc_alloc_tree_decl_map ();
6501 h->base.from = from;
6503 loc = htab_find_slot_with_hash (value_expr_for_decl, h, DECL_UID (from),
6505 *(struct tree_decl_map **) loc = h;
6508 /* Lookup a vector of debug arguments for FROM, and return it if we
6512 decl_debug_args_lookup (tree from)
6514 struct tree_vec_map *h, in;
6516 if (!DECL_HAS_DEBUG_ARGS_P (from))
6518 gcc_checking_assert (debug_args_for_decl != NULL);
6519 in.base.from = from;
6520 h = (struct tree_vec_map *)
6521 htab_find_with_hash (debug_args_for_decl, &in, DECL_UID (from));
6527 /* Insert a mapping FROM->empty vector of debug arguments in the value
6528 expression hashtable. */
6531 decl_debug_args_insert (tree from)
6533 struct tree_vec_map *h;
6536 if (DECL_HAS_DEBUG_ARGS_P (from))
6537 return decl_debug_args_lookup (from);
6538 if (debug_args_for_decl == NULL)
6539 debug_args_for_decl = htab_create_ggc (64, tree_vec_map_hash,
6540 tree_vec_map_eq, 0);
6541 h = ggc_alloc_tree_vec_map ();
6542 h->base.from = from;
6544 loc = htab_find_slot_with_hash (debug_args_for_decl, h, DECL_UID (from),
6546 *(struct tree_vec_map **) loc = h;
6547 DECL_HAS_DEBUG_ARGS_P (from) = 1;
6551 /* Hashing of types so that we don't make duplicates.
6552 The entry point is `type_hash_canon'. */
6554 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6555 with types in the TREE_VALUE slots), by adding the hash codes
6556 of the individual types. */
6559 type_hash_list (const_tree list, hashval_t hashcode)
6563 for (tail = list; tail; tail = TREE_CHAIN (tail))
6564 if (TREE_VALUE (tail) != error_mark_node)
6565 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
6571 /* These are the Hashtable callback functions. */
6573 /* Returns true iff the types are equivalent. */
6576 type_hash_eq (const void *va, const void *vb)
6578 const struct type_hash *const a = (const struct type_hash *) va,
6579 *const b = (const struct type_hash *) vb;
6581 /* First test the things that are the same for all types. */
6582 if (a->hash != b->hash
6583 || TREE_CODE (a->type) != TREE_CODE (b->type)
6584 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6585 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6586 TYPE_ATTRIBUTES (b->type))
6587 || (TREE_CODE (a->type) != COMPLEX_TYPE
6588 && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6591 /* Be careful about comparing arrays before and after the element type
6592 has been completed; don't compare TYPE_ALIGN unless both types are
6594 if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6595 && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6596 || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6599 switch (TREE_CODE (a->type))
6604 case REFERENCE_TYPE:
6609 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
6612 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6613 && !(TYPE_VALUES (a->type)
6614 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6615 && TYPE_VALUES (b->type)
6616 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6617 && type_list_equal (TYPE_VALUES (a->type),
6618 TYPE_VALUES (b->type))))
6621 /* ... fall through ... */
6626 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6627 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6628 TYPE_MAX_VALUE (b->type)))
6629 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6630 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6631 TYPE_MIN_VALUE (b->type))));
6633 case FIXED_POINT_TYPE:
6634 return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6637 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6640 if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6641 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6642 || (TYPE_ARG_TYPES (a->type)
6643 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6644 && TYPE_ARG_TYPES (b->type)
6645 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6646 && type_list_equal (TYPE_ARG_TYPES (a->type),
6647 TYPE_ARG_TYPES (b->type)))))
6651 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
6655 case QUAL_UNION_TYPE:
6656 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6657 || (TYPE_FIELDS (a->type)
6658 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6659 && TYPE_FIELDS (b->type)
6660 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6661 && type_list_equal (TYPE_FIELDS (a->type),
6662 TYPE_FIELDS (b->type))));
6665 if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6666 || (TYPE_ARG_TYPES (a->type)
6667 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6668 && TYPE_ARG_TYPES (b->type)
6669 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6670 && type_list_equal (TYPE_ARG_TYPES (a->type),
6671 TYPE_ARG_TYPES (b->type))))
6679 if (lang_hooks.types.type_hash_eq != NULL)
6680 return lang_hooks.types.type_hash_eq (a->type, b->type);
6685 /* Return the cached hash value. */
6688 type_hash_hash (const void *item)
6690 return ((const struct type_hash *) item)->hash;
6693 /* Look in the type hash table for a type isomorphic to TYPE.
6694 If one is found, return it. Otherwise return 0. */
6697 type_hash_lookup (hashval_t hashcode, tree type)
6699 struct type_hash *h, in;
6701 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6702 must call that routine before comparing TYPE_ALIGNs. */
6708 h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in,
6715 /* Add an entry to the type-hash-table
6716 for a type TYPE whose hash code is HASHCODE. */
6719 type_hash_add (hashval_t hashcode, tree type)
6721 struct type_hash *h;
6724 h = ggc_alloc_type_hash ();
6727 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
6731 /* Given TYPE, and HASHCODE its hash code, return the canonical
6732 object for an identical type if one already exists.
6733 Otherwise, return TYPE, and record it as the canonical object.
6735 To use this function, first create a type of the sort you want.
6736 Then compute its hash code from the fields of the type that
6737 make it different from other similar types.
6738 Then call this function and use the value. */
6741 type_hash_canon (unsigned int hashcode, tree type)
6745 /* The hash table only contains main variants, so ensure that's what we're
6747 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6749 /* See if the type is in the hash table already. If so, return it.
6750 Otherwise, add the type. */
6751 t1 = type_hash_lookup (hashcode, type);
6754 if (GATHER_STATISTICS)
6756 tree_code_counts[(int) TREE_CODE (type)]--;
6757 tree_node_counts[(int) t_kind]--;
6758 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type_non_common);
6764 type_hash_add (hashcode, type);
6769 /* See if the data pointed to by the type hash table is marked. We consider
6770 it marked if the type is marked or if a debug type number or symbol
6771 table entry has been made for the type. */
6774 type_hash_marked_p (const void *p)
6776 const_tree const type = ((const struct type_hash *) p)->type;
6778 return ggc_marked_p (type);
6782 print_type_hash_statistics (void)
6784 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
6785 (long) htab_size (type_hash_table),
6786 (long) htab_elements (type_hash_table),
6787 htab_collisions (type_hash_table));
6790 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6791 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6792 by adding the hash codes of the individual attributes. */
6795 attribute_hash_list (const_tree list, hashval_t hashcode)
6799 for (tail = list; tail; tail = TREE_CHAIN (tail))
6800 /* ??? Do we want to add in TREE_VALUE too? */
6801 hashcode = iterative_hash_object
6802 (IDENTIFIER_HASH_VALUE (get_attribute_name (tail)), hashcode);
6806 /* Given two lists of attributes, return true if list l2 is
6807 equivalent to l1. */
6810 attribute_list_equal (const_tree l1, const_tree l2)
6815 return attribute_list_contained (l1, l2)
6816 && attribute_list_contained (l2, l1);
6819 /* Given two lists of attributes, return true if list L2 is
6820 completely contained within L1. */
6821 /* ??? This would be faster if attribute names were stored in a canonicalized
6822 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6823 must be used to show these elements are equivalent (which they are). */
6824 /* ??? It's not clear that attributes with arguments will always be handled
6828 attribute_list_contained (const_tree l1, const_tree l2)
6832 /* First check the obvious, maybe the lists are identical. */
6836 /* Maybe the lists are similar. */
6837 for (t1 = l1, t2 = l2;
6839 && get_attribute_name (t1) == get_attribute_name (t2)
6840 && TREE_VALUE (t1) == TREE_VALUE (t2);
6841 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6844 /* Maybe the lists are equal. */
6845 if (t1 == 0 && t2 == 0)
6848 for (; t2 != 0; t2 = TREE_CHAIN (t2))
6851 /* This CONST_CAST is okay because lookup_attribute does not
6852 modify its argument and the return value is assigned to a
6854 for (attr = lookup_ident_attribute (get_attribute_name (t2),
6855 CONST_CAST_TREE (l1));
6856 attr != NULL_TREE && !attribute_value_equal (t2, attr);
6857 attr = lookup_ident_attribute (get_attribute_name (t2),
6861 if (attr == NULL_TREE)
6868 /* Given two lists of types
6869 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6870 return 1 if the lists contain the same types in the same order.
6871 Also, the TREE_PURPOSEs must match. */
6874 type_list_equal (const_tree l1, const_tree l2)
6878 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6879 if (TREE_VALUE (t1) != TREE_VALUE (t2)
6880 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6881 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6882 && (TREE_TYPE (TREE_PURPOSE (t1))
6883 == TREE_TYPE (TREE_PURPOSE (t2))))))
6889 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6890 given by TYPE. If the argument list accepts variable arguments,
6891 then this function counts only the ordinary arguments. */
6894 type_num_arguments (const_tree type)
6899 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6900 /* If the function does not take a variable number of arguments,
6901 the last element in the list will have type `void'. */
6902 if (VOID_TYPE_P (TREE_VALUE (t)))
6910 /* Nonzero if integer constants T1 and T2
6911 represent the same constant value. */
6914 tree_int_cst_equal (const_tree t1, const_tree t2)
6919 if (t1 == 0 || t2 == 0)
6922 if (TREE_CODE (t1) == INTEGER_CST
6923 && TREE_CODE (t2) == INTEGER_CST
6924 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
6925 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
6931 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6932 The precise way of comparison depends on their data type. */
6935 tree_int_cst_lt (const_tree t1, const_tree t2)
6940 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
6942 int t1_sgn = tree_int_cst_sgn (t1);
6943 int t2_sgn = tree_int_cst_sgn (t2);
6945 if (t1_sgn < t2_sgn)
6947 else if (t1_sgn > t2_sgn)
6949 /* Otherwise, both are non-negative, so we compare them as
6950 unsigned just in case one of them would overflow a signed
6953 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
6954 return INT_CST_LT (t1, t2);
6956 return INT_CST_LT_UNSIGNED (t1, t2);
6959 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6962 tree_int_cst_compare (const_tree t1, const_tree t2)
6964 if (tree_int_cst_lt (t1, t2))
6966 else if (tree_int_cst_lt (t2, t1))
6972 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6973 the host. If POS is zero, the value can be represented in a single
6974 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6975 be represented in a single unsigned HOST_WIDE_INT. */
6978 host_integerp (const_tree t, int pos)
6983 return (TREE_CODE (t) == INTEGER_CST
6984 && ((TREE_INT_CST_HIGH (t) == 0
6985 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
6986 || (! pos && TREE_INT_CST_HIGH (t) == -1
6987 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
6988 && !TYPE_UNSIGNED (TREE_TYPE (t)))
6989 || (pos && TREE_INT_CST_HIGH (t) == 0)));
6992 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6993 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6994 be non-negative. We must be able to satisfy the above conditions. */
6997 tree_low_cst (const_tree t, int pos)
6999 gcc_assert (host_integerp (t, pos));
7000 return TREE_INT_CST_LOW (t);
7003 /* Return the most significant (sign) bit of T. */
7006 tree_int_cst_sign_bit (const_tree t)
7008 unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
7009 unsigned HOST_WIDE_INT w;
7011 if (bitno < HOST_BITS_PER_WIDE_INT)
7012 w = TREE_INT_CST_LOW (t);
7015 w = TREE_INT_CST_HIGH (t);
7016 bitno -= HOST_BITS_PER_WIDE_INT;
7019 return (w >> bitno) & 1;
7022 /* Return an indication of the sign of the integer constant T.
7023 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
7024 Note that -1 will never be returned if T's type is unsigned. */
7027 tree_int_cst_sgn (const_tree t)
7029 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
7031 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
7033 else if (TREE_INT_CST_HIGH (t) < 0)
7039 /* Return the minimum number of bits needed to represent VALUE in a
7040 signed or unsigned type, UNSIGNEDP says which. */
7043 tree_int_cst_min_precision (tree value, bool unsignedp)
7045 /* If the value is negative, compute its negative minus 1. The latter
7046 adjustment is because the absolute value of the largest negative value
7047 is one larger than the largest positive value. This is equivalent to
7048 a bit-wise negation, so use that operation instead. */
7050 if (tree_int_cst_sgn (value) < 0)
7051 value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
7053 /* Return the number of bits needed, taking into account the fact
7054 that we need one more bit for a signed than unsigned type.
7055 If value is 0 or -1, the minimum precision is 1 no matter
7056 whether unsignedp is true or false. */
7058 if (integer_zerop (value))
7061 return tree_floor_log2 (value) + 1 + !unsignedp;
7064 /* Return truthvalue of whether T1 is the same tree structure as T2.
7065 Return 1 if they are the same.
7066 Return 0 if they are understandably different.
7067 Return -1 if either contains tree structure not understood by
7071 simple_cst_equal (const_tree t1, const_tree t2)
7073 enum tree_code code1, code2;
7079 if (t1 == 0 || t2 == 0)
7082 code1 = TREE_CODE (t1);
7083 code2 = TREE_CODE (t2);
7085 if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
7087 if (CONVERT_EXPR_CODE_P (code2)
7088 || code2 == NON_LVALUE_EXPR)
7089 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
7091 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
7094 else if (CONVERT_EXPR_CODE_P (code2)
7095 || code2 == NON_LVALUE_EXPR)
7096 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
7104 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
7105 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
7108 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
7111 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
7114 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
7115 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
7116 TREE_STRING_LENGTH (t1)));
7120 unsigned HOST_WIDE_INT idx;
7121 vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
7122 vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
7124 if (vec_safe_length (v1) != vec_safe_length (v2))
7127 for (idx = 0; idx < vec_safe_length (v1); ++idx)
7128 /* ??? Should we handle also fields here? */
7129 if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
7135 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
7138 cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
7141 if (call_expr_nargs (t1) != call_expr_nargs (t2))
7144 const_tree arg1, arg2;
7145 const_call_expr_arg_iterator iter1, iter2;
7146 for (arg1 = first_const_call_expr_arg (t1, &iter1),
7147 arg2 = first_const_call_expr_arg (t2, &iter2);
7149 arg1 = next_const_call_expr_arg (&iter1),
7150 arg2 = next_const_call_expr_arg (&iter2))
7152 cmp = simple_cst_equal (arg1, arg2);
7156 return arg1 == arg2;
7160 /* Special case: if either target is an unallocated VAR_DECL,
7161 it means that it's going to be unified with whatever the
7162 TARGET_EXPR is really supposed to initialize, so treat it
7163 as being equivalent to anything. */
7164 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
7165 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
7166 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
7167 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
7168 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
7169 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
7172 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
7177 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
7179 case WITH_CLEANUP_EXPR:
7180 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
7184 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
7187 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
7188 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
7202 /* This general rule works for most tree codes. All exceptions should be
7203 handled above. If this is a language-specific tree code, we can't
7204 trust what might be in the operand, so say we don't know
7206 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
7209 switch (TREE_CODE_CLASS (code1))
7213 case tcc_comparison:
7214 case tcc_expression:
7218 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
7220 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
7232 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
7233 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
7234 than U, respectively. */
7237 compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
7239 if (tree_int_cst_sgn (t) < 0)
7241 else if (TREE_INT_CST_HIGH (t) != 0)
7243 else if (TREE_INT_CST_LOW (t) == u)
7245 else if (TREE_INT_CST_LOW (t) < u)
7251 /* Return true if SIZE represents a constant size that is in bounds of
7252 what the middle-end and the backend accepts (covering not more than
7253 half of the address-space). */
7256 valid_constant_size_p (const_tree size)
7258 if (! host_integerp (size, 1)
7259 || TREE_OVERFLOW (size)
7260 || tree_int_cst_sign_bit (size) != 0)
7265 /* Return the precision of the type, or for a complex or vector type the
7266 precision of the type of its elements. */
7269 element_precision (const_tree type)
7271 enum tree_code code = TREE_CODE (type);
7272 if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7273 type = TREE_TYPE (type);
7275 return TYPE_PRECISION (type);
7278 /* Return true if CODE represents an associative tree code. Otherwise
7281 associative_tree_code (enum tree_code code)
7300 /* Return true if CODE represents a commutative tree code. Otherwise
7303 commutative_tree_code (enum tree_code code)
7309 case MULT_HIGHPART_EXPR:
7317 case UNORDERED_EXPR:
7321 case TRUTH_AND_EXPR:
7322 case TRUTH_XOR_EXPR:
7324 case WIDEN_MULT_EXPR:
7325 case VEC_WIDEN_MULT_HI_EXPR:
7326 case VEC_WIDEN_MULT_LO_EXPR:
7327 case VEC_WIDEN_MULT_EVEN_EXPR:
7328 case VEC_WIDEN_MULT_ODD_EXPR:
7337 /* Return true if CODE represents a ternary tree code for which the
7338 first two operands are commutative. Otherwise return false. */
7340 commutative_ternary_tree_code (enum tree_code code)
7344 case WIDEN_MULT_PLUS_EXPR:
7345 case WIDEN_MULT_MINUS_EXPR:
7354 /* Generate a hash value for an expression. This can be used iteratively
7355 by passing a previous result as the VAL argument.
7357 This function is intended to produce the same hash for expressions which
7358 would compare equal using operand_equal_p. */
7361 iterative_hash_expr (const_tree t, hashval_t val)
7364 enum tree_code code;
7368 return iterative_hash_hashval_t (0, val);
7370 code = TREE_CODE (t);
7374 /* Alas, constants aren't shared, so we can't rely on pointer
7377 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
7378 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
7381 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
7383 return iterative_hash_hashval_t (val2, val);
7387 unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t));
7389 return iterative_hash_hashval_t (val2, val);
7392 return iterative_hash (TREE_STRING_POINTER (t),
7393 TREE_STRING_LENGTH (t), val);
7395 val = iterative_hash_expr (TREE_REALPART (t), val);
7396 return iterative_hash_expr (TREE_IMAGPART (t), val);
7400 for (i = 0; i < VECTOR_CST_NELTS (t); ++i)
7401 val = iterative_hash_expr (VECTOR_CST_ELT (t, i), val);
7405 /* We can just compare by pointer. */
7406 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t), val);
7407 case PLACEHOLDER_EXPR:
7408 /* The node itself doesn't matter. */
7411 /* A list of expressions, for a CALL_EXPR or as the elements of a
7413 for (; t; t = TREE_CHAIN (t))
7414 val = iterative_hash_expr (TREE_VALUE (t), val);
7418 unsigned HOST_WIDE_INT idx;
7420 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
7422 val = iterative_hash_expr (field, val);
7423 val = iterative_hash_expr (value, val);
7428 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7429 Otherwise nodes that compare equal according to operand_equal_p might
7430 get different hash codes. However, don't do this for machine specific
7431 or front end builtins, since the function code is overloaded in those
7433 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
7434 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t)))
7436 t = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
7437 code = TREE_CODE (t);
7441 tclass = TREE_CODE_CLASS (code);
7443 if (tclass == tcc_declaration)
7445 /* DECL's have a unique ID */
7446 val = iterative_hash_host_wide_int (DECL_UID (t), val);
7450 gcc_assert (IS_EXPR_CODE_CLASS (tclass));
7452 val = iterative_hash_object (code, val);
7454 /* Don't hash the type, that can lead to having nodes which
7455 compare equal according to operand_equal_p, but which
7456 have different hash codes. */
7457 if (CONVERT_EXPR_CODE_P (code)
7458 || code == NON_LVALUE_EXPR)
7460 /* Make sure to include signness in the hash computation. */
7461 val += TYPE_UNSIGNED (TREE_TYPE (t));
7462 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
7465 else if (commutative_tree_code (code))
7467 /* It's a commutative expression. We want to hash it the same
7468 however it appears. We do this by first hashing both operands
7469 and then rehashing based on the order of their independent
7471 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
7472 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
7476 t = one, one = two, two = t;
7478 val = iterative_hash_hashval_t (one, val);
7479 val = iterative_hash_hashval_t (two, val);
7482 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
7483 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
7489 /* Constructors for pointer, array and function types.
7490 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7491 constructed by language-dependent code, not here.) */
7493 /* Construct, lay out and return the type of pointers to TO_TYPE with
7494 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
7495 reference all of memory. If such a type has already been
7496 constructed, reuse it. */
7499 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
7504 if (to_type == error_mark_node)
7505 return error_mark_node;
7507 /* If the pointed-to type has the may_alias attribute set, force
7508 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7509 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7510 can_alias_all = true;
7512 /* In some cases, languages will have things that aren't a POINTER_TYPE
7513 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7514 In that case, return that type without regard to the rest of our
7517 ??? This is a kludge, but consistent with the way this function has
7518 always operated and there doesn't seem to be a good way to avoid this
7520 if (TYPE_POINTER_TO (to_type) != 0
7521 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7522 return TYPE_POINTER_TO (to_type);
7524 /* First, if we already have a type for pointers to TO_TYPE and it's
7525 the proper mode, use it. */
7526 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7527 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7530 t = make_node (POINTER_TYPE);
7532 TREE_TYPE (t) = to_type;
7533 SET_TYPE_MODE (t, mode);
7534 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7535 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7536 TYPE_POINTER_TO (to_type) = t;
7538 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
7539 SET_TYPE_STRUCTURAL_EQUALITY (t);
7540 else if (TYPE_CANONICAL (to_type) != to_type)
7542 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7543 mode, can_alias_all);
7545 /* Lay out the type. This function has many callers that are concerned
7546 with expression-construction, and this simplifies them all. */
7552 /* By default build pointers in ptr_mode. */
7555 build_pointer_type (tree to_type)
7557 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
7558 : TYPE_ADDR_SPACE (to_type);
7559 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
7560 return build_pointer_type_for_mode (to_type, pointer_mode, false);
7563 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7566 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
7571 if (to_type == error_mark_node)
7572 return error_mark_node;
7574 /* If the pointed-to type has the may_alias attribute set, force
7575 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7576 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7577 can_alias_all = true;
7579 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7580 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7581 In that case, return that type without regard to the rest of our
7584 ??? This is a kludge, but consistent with the way this function has
7585 always operated and there doesn't seem to be a good way to avoid this
7587 if (TYPE_REFERENCE_TO (to_type) != 0
7588 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7589 return TYPE_REFERENCE_TO (to_type);
7591 /* First, if we already have a type for pointers to TO_TYPE and it's
7592 the proper mode, use it. */
7593 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7594 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7597 t = make_node (REFERENCE_TYPE);
7599 TREE_TYPE (t) = to_type;
7600 SET_TYPE_MODE (t, mode);
7601 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7602 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7603 TYPE_REFERENCE_TO (to_type) = t;
7605 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
7606 SET_TYPE_STRUCTURAL_EQUALITY (t);
7607 else if (TYPE_CANONICAL (to_type) != to_type)
7609 = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7610 mode, can_alias_all);
7618 /* Build the node for the type of references-to-TO_TYPE by default
7622 build_reference_type (tree to_type)
7624 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
7625 : TYPE_ADDR_SPACE (to_type);
7626 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
7627 return build_reference_type_for_mode (to_type, pointer_mode, false);
7630 #define MAX_INT_CACHED_PREC \
7631 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7632 static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7634 /* Builds a signed or unsigned integer type of precision PRECISION.
7635 Used for C bitfields whose precision does not match that of
7636 built-in target types. */
7638 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7644 unsignedp = MAX_INT_CACHED_PREC + 1;
7646 if (precision <= MAX_INT_CACHED_PREC)
7648 itype = nonstandard_integer_type_cache[precision + unsignedp];
7653 itype = make_node (INTEGER_TYPE);
7654 TYPE_PRECISION (itype) = precision;
7657 fixup_unsigned_type (itype);
7659 fixup_signed_type (itype);
7662 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
7663 ret = type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
7664 if (precision <= MAX_INT_CACHED_PREC)
7665 nonstandard_integer_type_cache[precision + unsignedp] = ret;
7670 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7671 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7672 is true, reuse such a type that has already been constructed. */
7675 build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7677 tree itype = make_node (INTEGER_TYPE);
7678 hashval_t hashcode = 0;
7680 TREE_TYPE (itype) = type;
7682 TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7683 TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7685 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7686 SET_TYPE_MODE (itype, TYPE_MODE (type));
7687 TYPE_SIZE (itype) = TYPE_SIZE (type);
7688 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7689 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
7690 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7695 if ((TYPE_MIN_VALUE (itype)
7696 && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7697 || (TYPE_MAX_VALUE (itype)
7698 && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7700 /* Since we cannot reliably merge this type, we need to compare it using
7701 structural equality checks. */
7702 SET_TYPE_STRUCTURAL_EQUALITY (itype);
7706 hashcode = iterative_hash_expr (TYPE_MIN_VALUE (itype), hashcode);
7707 hashcode = iterative_hash_expr (TYPE_MAX_VALUE (itype), hashcode);
7708 hashcode = iterative_hash_hashval_t (TYPE_HASH (type), hashcode);
7709 itype = type_hash_canon (hashcode, itype);
7714 /* Wrapper around build_range_type_1 with SHARED set to true. */
7717 build_range_type (tree type, tree lowval, tree highval)
7719 return build_range_type_1 (type, lowval, highval, true);
7722 /* Wrapper around build_range_type_1 with SHARED set to false. */
7725 build_nonshared_range_type (tree type, tree lowval, tree highval)
7727 return build_range_type_1 (type, lowval, highval, false);
7730 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7731 MAXVAL should be the maximum value in the domain
7732 (one less than the length of the array).
7734 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7735 We don't enforce this limit, that is up to caller (e.g. language front end).
7736 The limit exists because the result is a signed type and we don't handle
7737 sizes that use more than one HOST_WIDE_INT. */
7740 build_index_type (tree maxval)
7742 return build_range_type (sizetype, size_zero_node, maxval);
7745 /* Return true if the debug information for TYPE, a subtype, should be emitted
7746 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7747 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7748 debug info and doesn't reflect the source code. */
7751 subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7753 tree base_type = TREE_TYPE (type), low, high;
7755 /* Subrange types have a base type which is an integral type. */
7756 if (!INTEGRAL_TYPE_P (base_type))
7759 /* Get the real bounds of the subtype. */
7760 if (lang_hooks.types.get_subrange_bounds)
7761 lang_hooks.types.get_subrange_bounds (type, &low, &high);
7764 low = TYPE_MIN_VALUE (type);
7765 high = TYPE_MAX_VALUE (type);
7768 /* If the type and its base type have the same representation and the same
7769 name, then the type is not a subrange but a copy of the base type. */
7770 if ((TREE_CODE (base_type) == INTEGER_TYPE
7771 || TREE_CODE (base_type) == BOOLEAN_TYPE)
7772 && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7773 && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7774 && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type)))
7776 tree type_name = TYPE_NAME (type);
7777 tree base_type_name = TYPE_NAME (base_type);
7779 if (type_name && TREE_CODE (type_name) == TYPE_DECL)
7780 type_name = DECL_NAME (type_name);
7782 if (base_type_name && TREE_CODE (base_type_name) == TYPE_DECL)
7783 base_type_name = DECL_NAME (base_type_name);
7785 if (type_name == base_type_name)
7796 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7797 and number of elements specified by the range of values of INDEX_TYPE.
7798 If SHARED is true, reuse such a type that has already been constructed. */
7801 build_array_type_1 (tree elt_type, tree index_type, bool shared)
7805 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7807 error ("arrays of functions are not meaningful");
7808 elt_type = integer_type_node;
7811 t = make_node (ARRAY_TYPE);
7812 TREE_TYPE (t) = elt_type;
7813 TYPE_DOMAIN (t) = index_type;
7814 TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7817 /* If the element type is incomplete at this point we get marked for
7818 structural equality. Do not record these types in the canonical
7820 if (TYPE_STRUCTURAL_EQUALITY_P (t))
7825 hashval_t hashcode = iterative_hash_object (TYPE_HASH (elt_type), 0);
7827 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
7828 t = type_hash_canon (hashcode, t);
7831 if (TYPE_CANONICAL (t) == t)
7833 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7834 || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
7835 SET_TYPE_STRUCTURAL_EQUALITY (t);
7836 else if (TYPE_CANONICAL (elt_type) != elt_type
7837 || (index_type && TYPE_CANONICAL (index_type) != index_type))
7839 = build_array_type_1 (TYPE_CANONICAL (elt_type),
7841 ? TYPE_CANONICAL (index_type) : NULL_TREE,
7848 /* Wrapper around build_array_type_1 with SHARED set to true. */
7851 build_array_type (tree elt_type, tree index_type)
7853 return build_array_type_1 (elt_type, index_type, true);
7856 /* Wrapper around build_array_type_1 with SHARED set to false. */
7859 build_nonshared_array_type (tree elt_type, tree index_type)
7861 return build_array_type_1 (elt_type, index_type, false);
7864 /* Return a representation of ELT_TYPE[NELTS], using indices of type
7868 build_array_type_nelts (tree elt_type, unsigned HOST_WIDE_INT nelts)
7870 return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7873 /* Recursively examines the array elements of TYPE, until a non-array
7874 element type is found. */
7877 strip_array_types (tree type)
7879 while (TREE_CODE (type) == ARRAY_TYPE)
7880 type = TREE_TYPE (type);
7885 /* Computes the canonical argument types from the argument type list
7888 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7889 on entry to this function, or if any of the ARGTYPES are
7892 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7893 true on entry to this function, or if any of the ARGTYPES are
7896 Returns a canonical argument list, which may be ARGTYPES when the
7897 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7898 true) or would not differ from ARGTYPES. */
7901 maybe_canonicalize_argtypes (tree argtypes,
7902 bool *any_structural_p,
7903 bool *any_noncanonical_p)
7906 bool any_noncanonical_argtypes_p = false;
7908 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7910 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7911 /* Fail gracefully by stating that the type is structural. */
7912 *any_structural_p = true;
7913 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7914 *any_structural_p = true;
7915 else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7916 || TREE_PURPOSE (arg))
7917 /* If the argument has a default argument, we consider it
7918 non-canonical even though the type itself is canonical.
7919 That way, different variants of function and method types
7920 with default arguments will all point to the variant with
7921 no defaults as their canonical type. */
7922 any_noncanonical_argtypes_p = true;
7925 if (*any_structural_p)
7928 if (any_noncanonical_argtypes_p)
7930 /* Build the canonical list of argument types. */
7931 tree canon_argtypes = NULL_TREE;
7932 bool is_void = false;
7934 for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7936 if (arg == void_list_node)
7939 canon_argtypes = tree_cons (NULL_TREE,
7940 TYPE_CANONICAL (TREE_VALUE (arg)),
7944 canon_argtypes = nreverse (canon_argtypes);
7946 canon_argtypes = chainon (canon_argtypes, void_list_node);
7948 /* There is a non-canonical type. */
7949 *any_noncanonical_p = true;
7950 return canon_argtypes;
7953 /* The canonical argument types are the same as ARGTYPES. */
7957 /* Construct, lay out and return
7958 the type of functions returning type VALUE_TYPE
7959 given arguments of types ARG_TYPES.
7960 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7961 are data type nodes for the arguments of the function.
7962 If such a type has already been constructed, reuse it. */
7965 build_function_type (tree value_type, tree arg_types)
7968 hashval_t hashcode = 0;
7969 bool any_structural_p, any_noncanonical_p;
7970 tree canon_argtypes;
7972 if (TREE_CODE (value_type) == FUNCTION_TYPE)
7974 error ("function return type cannot be function");
7975 value_type = integer_type_node;
7978 /* Make a node of the sort we want. */
7979 t = make_node (FUNCTION_TYPE);
7980 TREE_TYPE (t) = value_type;
7981 TYPE_ARG_TYPES (t) = arg_types;
7983 /* If we already have such a type, use the old one. */
7984 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
7985 hashcode = type_hash_list (arg_types, hashcode);
7986 t = type_hash_canon (hashcode, t);
7988 /* Set up the canonical type. */
7989 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7990 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7991 canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7993 &any_noncanonical_p);
7994 if (any_structural_p)
7995 SET_TYPE_STRUCTURAL_EQUALITY (t);
7996 else if (any_noncanonical_p)
7997 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
8000 if (!COMPLETE_TYPE_P (t))
8005 /* Build a function type. The RETURN_TYPE is the type returned by the
8006 function. If VAARGS is set, no void_type_node is appended to the
8007 the list. ARGP must be always be terminated be a NULL_TREE. */
8010 build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
8014 t = va_arg (argp, tree);
8015 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
8016 args = tree_cons (NULL_TREE, t, args);
8021 if (args != NULL_TREE)
8022 args = nreverse (args);
8023 gcc_assert (last != void_list_node);
8025 else if (args == NULL_TREE)
8026 args = void_list_node;
8030 args = nreverse (args);
8031 TREE_CHAIN (last) = void_list_node;
8033 args = build_function_type (return_type, args);
8038 /* Build a function type. The RETURN_TYPE is the type returned by the
8039 function. If additional arguments are provided, they are
8040 additional argument types. The list of argument types must always
8041 be terminated by NULL_TREE. */
8044 build_function_type_list (tree return_type, ...)
8049 va_start (p, return_type);
8050 args = build_function_type_list_1 (false, return_type, p);
8055 /* Build a variable argument function type. The RETURN_TYPE is the
8056 type returned by the function. If additional arguments are provided,
8057 they are additional argument types. The list of argument types must
8058 always be terminated by NULL_TREE. */
8061 build_varargs_function_type_list (tree return_type, ...)
8066 va_start (p, return_type);
8067 args = build_function_type_list_1 (true, return_type, p);
8073 /* Build a function type. RETURN_TYPE is the type returned by the
8074 function; VAARGS indicates whether the function takes varargs. The
8075 function takes N named arguments, the types of which are provided in
8079 build_function_type_array_1 (bool vaargs, tree return_type, int n,
8083 tree t = vaargs ? NULL_TREE : void_list_node;
8085 for (i = n - 1; i >= 0; i--)
8086 t = tree_cons (NULL_TREE, arg_types[i], t);
8088 return build_function_type (return_type, t);
8091 /* Build a function type. RETURN_TYPE is the type returned by the
8092 function. The function takes N named arguments, the types of which
8093 are provided in ARG_TYPES. */
8096 build_function_type_array (tree return_type, int n, tree *arg_types)
8098 return build_function_type_array_1 (false, return_type, n, arg_types);
8101 /* Build a variable argument function type. RETURN_TYPE is the type
8102 returned by the function. The function takes N named arguments, the
8103 types of which are provided in ARG_TYPES. */
8106 build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
8108 return build_function_type_array_1 (true, return_type, n, arg_types);
8111 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
8112 and ARGTYPES (a TREE_LIST) are the return type and arguments types
8113 for the method. An implicit additional parameter (of type
8114 pointer-to-BASETYPE) is added to the ARGTYPES. */
8117 build_method_type_directly (tree basetype,
8124 bool any_structural_p, any_noncanonical_p;
8125 tree canon_argtypes;
8127 /* Make a node of the sort we want. */
8128 t = make_node (METHOD_TYPE);
8130 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
8131 TREE_TYPE (t) = rettype;
8132 ptype = build_pointer_type (basetype);
8134 /* The actual arglist for this function includes a "hidden" argument
8135 which is "this". Put it into the list of argument types. */
8136 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
8137 TYPE_ARG_TYPES (t) = argtypes;
8139 /* If we already have such a type, use the old one. */
8140 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
8141 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
8142 hashcode = type_hash_list (argtypes, hashcode);
8143 t = type_hash_canon (hashcode, t);
8145 /* Set up the canonical type. */
8147 = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8148 || TYPE_STRUCTURAL_EQUALITY_P (rettype));
8150 = (TYPE_CANONICAL (basetype) != basetype
8151 || TYPE_CANONICAL (rettype) != rettype);
8152 canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
8154 &any_noncanonical_p);
8155 if (any_structural_p)
8156 SET_TYPE_STRUCTURAL_EQUALITY (t);
8157 else if (any_noncanonical_p)
8159 = build_method_type_directly (TYPE_CANONICAL (basetype),
8160 TYPE_CANONICAL (rettype),
8162 if (!COMPLETE_TYPE_P (t))
8168 /* Construct, lay out and return the type of methods belonging to class
8169 BASETYPE and whose arguments and values are described by TYPE.
8170 If that type exists already, reuse it.
8171 TYPE must be a FUNCTION_TYPE node. */
8174 build_method_type (tree basetype, tree type)
8176 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
8178 return build_method_type_directly (basetype,
8180 TYPE_ARG_TYPES (type));
8183 /* Construct, lay out and return the type of offsets to a value
8184 of type TYPE, within an object of type BASETYPE.
8185 If a suitable offset type exists already, reuse it. */
8188 build_offset_type (tree basetype, tree type)
8191 hashval_t hashcode = 0;
8193 /* Make a node of the sort we want. */
8194 t = make_node (OFFSET_TYPE);
8196 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
8197 TREE_TYPE (t) = type;
8199 /* If we already have such a type, use the old one. */
8200 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
8201 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
8202 t = type_hash_canon (hashcode, t);
8204 if (!COMPLETE_TYPE_P (t))
8207 if (TYPE_CANONICAL (t) == t)
8209 if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8210 || TYPE_STRUCTURAL_EQUALITY_P (type))
8211 SET_TYPE_STRUCTURAL_EQUALITY (t);
8212 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
8213 || TYPE_CANONICAL (type) != type)
8215 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
8216 TYPE_CANONICAL (type));
8222 /* Create a complex type whose components are COMPONENT_TYPE. */
8225 build_complex_type (tree component_type)
8230 gcc_assert (INTEGRAL_TYPE_P (component_type)
8231 || SCALAR_FLOAT_TYPE_P (component_type)
8232 || FIXED_POINT_TYPE_P (component_type));
8234 /* Make a node of the sort we want. */
8235 t = make_node (COMPLEX_TYPE);
8237 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
8239 /* If we already have such a type, use the old one. */
8240 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
8241 t = type_hash_canon (hashcode, t);
8243 if (!COMPLETE_TYPE_P (t))
8246 if (TYPE_CANONICAL (t) == t)
8248 if (TYPE_STRUCTURAL_EQUALITY_P (component_type))
8249 SET_TYPE_STRUCTURAL_EQUALITY (t);
8250 else if (TYPE_CANONICAL (component_type) != component_type)
8252 = build_complex_type (TYPE_CANONICAL (component_type));
8255 /* We need to create a name, since complex is a fundamental type. */
8256 if (! TYPE_NAME (t))
8259 if (component_type == char_type_node)
8260 name = "complex char";
8261 else if (component_type == signed_char_type_node)
8262 name = "complex signed char";
8263 else if (component_type == unsigned_char_type_node)
8264 name = "complex unsigned char";
8265 else if (component_type == short_integer_type_node)
8266 name = "complex short int";
8267 else if (component_type == short_unsigned_type_node)
8268 name = "complex short unsigned int";
8269 else if (component_type == integer_type_node)
8270 name = "complex int";
8271 else if (component_type == unsigned_type_node)
8272 name = "complex unsigned int";
8273 else if (component_type == long_integer_type_node)
8274 name = "complex long int";
8275 else if (component_type == long_unsigned_type_node)
8276 name = "complex long unsigned int";
8277 else if (component_type == long_long_integer_type_node)
8278 name = "complex long long int";
8279 else if (component_type == long_long_unsigned_type_node)
8280 name = "complex long long unsigned int";
8285 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8286 get_identifier (name), t);
8289 return build_qualified_type (t, TYPE_QUALS (component_type));
8292 /* If TYPE is a real or complex floating-point type and the target
8293 does not directly support arithmetic on TYPE then return the wider
8294 type to be used for arithmetic on TYPE. Otherwise, return
8298 excess_precision_type (tree type)
8300 if (flag_excess_precision != EXCESS_PRECISION_FAST)
8302 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
8303 switch (TREE_CODE (type))
8306 switch (flt_eval_method)
8309 if (TYPE_MODE (type) == TYPE_MODE (float_type_node))
8310 return double_type_node;
8313 if (TYPE_MODE (type) == TYPE_MODE (float_type_node)
8314 || TYPE_MODE (type) == TYPE_MODE (double_type_node))
8315 return long_double_type_node;
8322 if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8324 switch (flt_eval_method)
8327 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node))
8328 return complex_double_type_node;
8331 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)
8332 || (TYPE_MODE (TREE_TYPE (type))
8333 == TYPE_MODE (double_type_node)))
8334 return complex_long_double_type_node;
8347 /* Return OP, stripped of any conversions to wider types as much as is safe.
8348 Converting the value back to OP's type makes a value equivalent to OP.
8350 If FOR_TYPE is nonzero, we return a value which, if converted to
8351 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8353 OP must have integer, real or enumeral type. Pointers are not allowed!
8355 There are some cases where the obvious value we could return
8356 would regenerate to OP if converted to OP's type,
8357 but would not extend like OP to wider types.
8358 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8359 For example, if OP is (unsigned short)(signed char)-1,
8360 we avoid returning (signed char)-1 if FOR_TYPE is int,
8361 even though extending that to an unsigned short would regenerate OP,
8362 since the result of extending (signed char)-1 to (int)
8363 is different from (int) OP. */
8366 get_unwidened (tree op, tree for_type)
8368 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8369 tree type = TREE_TYPE (op);
8371 = TYPE_PRECISION (for_type != 0 ? for_type : type);
8373 = (for_type != 0 && for_type != type
8374 && final_prec > TYPE_PRECISION (type)
8375 && TYPE_UNSIGNED (type));
8378 while (CONVERT_EXPR_P (op))
8382 /* TYPE_PRECISION on vector types has different meaning
8383 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8384 so avoid them here. */
8385 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8388 bitschange = TYPE_PRECISION (TREE_TYPE (op))
8389 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8391 /* Truncations are many-one so cannot be removed.
8392 Unless we are later going to truncate down even farther. */
8394 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8397 /* See what's inside this conversion. If we decide to strip it,
8399 op = TREE_OPERAND (op, 0);
8401 /* If we have not stripped any zero-extensions (uns is 0),
8402 we can strip any kind of extension.
8403 If we have previously stripped a zero-extension,
8404 only zero-extensions can safely be stripped.
8405 Any extension can be stripped if the bits it would produce
8406 are all going to be discarded later by truncating to FOR_TYPE. */
8410 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8412 /* TYPE_UNSIGNED says whether this is a zero-extension.
8413 Let's avoid computing it if it does not affect WIN
8414 and if UNS will not be needed again. */
8416 || CONVERT_EXPR_P (op))
8417 && TYPE_UNSIGNED (TREE_TYPE (op)))
8425 /* If we finally reach a constant see if it fits in for_type and
8426 in that case convert it. */
8428 && TREE_CODE (win) == INTEGER_CST
8429 && TREE_TYPE (win) != for_type
8430 && int_fits_type_p (win, for_type))
8431 win = fold_convert (for_type, win);
8436 /* Return OP or a simpler expression for a narrower value
8437 which can be sign-extended or zero-extended to give back OP.
8438 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8439 or 0 if the value should be sign-extended. */
8442 get_narrower (tree op, int *unsignedp_ptr)
8447 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8449 while (TREE_CODE (op) == NOP_EXPR)
8452 = (TYPE_PRECISION (TREE_TYPE (op))
8453 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8455 /* Truncations are many-one so cannot be removed. */
8459 /* See what's inside this conversion. If we decide to strip it,
8464 op = TREE_OPERAND (op, 0);
8465 /* An extension: the outermost one can be stripped,
8466 but remember whether it is zero or sign extension. */
8468 uns = TYPE_UNSIGNED (TREE_TYPE (op));
8469 /* Otherwise, if a sign extension has been stripped,
8470 only sign extensions can now be stripped;
8471 if a zero extension has been stripped, only zero-extensions. */
8472 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8476 else /* bitschange == 0 */
8478 /* A change in nominal type can always be stripped, but we must
8479 preserve the unsignedness. */
8481 uns = TYPE_UNSIGNED (TREE_TYPE (op));
8483 op = TREE_OPERAND (op, 0);
8484 /* Keep trying to narrow, but don't assign op to win if it
8485 would turn an integral type into something else. */
8486 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8493 if (TREE_CODE (op) == COMPONENT_REF
8494 /* Since type_for_size always gives an integer type. */
8495 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8496 && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8497 /* Ensure field is laid out already. */
8498 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8499 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
8501 unsigned HOST_WIDE_INT innerprec
8502 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
8503 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8504 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8505 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8507 /* We can get this structure field in a narrower type that fits it,
8508 but the resulting extension to its nominal type (a fullword type)
8509 must satisfy the same conditions as for other extensions.
8511 Do this only for fields that are aligned (not bit-fields),
8512 because when bit-field insns will be used there is no
8513 advantage in doing this. */
8515 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8516 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8517 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8521 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8522 win = fold_convert (type, op);
8526 *unsignedp_ptr = uns;
8530 /* Returns true if integer constant C has a value that is permissible
8531 for type TYPE (an INTEGER_TYPE). */
8534 int_fits_type_p (const_tree c, const_tree type)
8536 tree type_low_bound, type_high_bound;
8537 bool ok_for_low_bound, ok_for_high_bound, unsc;
8540 dc = tree_to_double_int (c);
8541 unsc = TYPE_UNSIGNED (TREE_TYPE (c));
8544 type_low_bound = TYPE_MIN_VALUE (type);
8545 type_high_bound = TYPE_MAX_VALUE (type);
8547 /* If at least one bound of the type is a constant integer, we can check
8548 ourselves and maybe make a decision. If no such decision is possible, but
8549 this type is a subtype, try checking against that. Otherwise, use
8550 double_int_fits_to_tree_p, which checks against the precision.
8552 Compute the status for each possibly constant bound, and return if we see
8553 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8554 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8555 for "constant known to fit". */
8557 /* Check if c >= type_low_bound. */
8558 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8560 dd = tree_to_double_int (type_low_bound);
8561 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_low_bound)))
8563 int c_neg = (!unsc && dc.is_negative ());
8564 int t_neg = (unsc && dd.is_negative ());
8566 if (c_neg && !t_neg)
8568 if ((c_neg || !t_neg) && dc.ult (dd))
8571 else if (dc.cmp (dd, unsc) < 0)
8573 ok_for_low_bound = true;
8576 ok_for_low_bound = false;
8578 /* Check if c <= type_high_bound. */
8579 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8581 dd = tree_to_double_int (type_high_bound);
8582 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_high_bound)))
8584 int c_neg = (!unsc && dc.is_negative ());
8585 int t_neg = (unsc && dd.is_negative ());
8587 if (t_neg && !c_neg)
8589 if ((t_neg || !c_neg) && dc.ugt (dd))
8592 else if (dc.cmp (dd, unsc) > 0)
8594 ok_for_high_bound = true;
8597 ok_for_high_bound = false;
8599 /* If the constant fits both bounds, the result is known. */
8600 if (ok_for_low_bound && ok_for_high_bound)
8603 /* Perform some generic filtering which may allow making a decision
8604 even if the bounds are not constant. First, negative integers
8605 never fit in unsigned types, */
8606 if (TYPE_UNSIGNED (type) && !unsc && dc.is_negative ())
8609 /* Second, narrower types always fit in wider ones. */
8610 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8613 /* Third, unsigned integers with top bit set never fit signed types. */
8614 if (! TYPE_UNSIGNED (type) && unsc)
8616 int prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c))) - 1;
8617 if (prec < HOST_BITS_PER_WIDE_INT)
8619 if (((((unsigned HOST_WIDE_INT) 1) << prec) & dc.low) != 0)
8622 else if (((((unsigned HOST_WIDE_INT) 1)
8623 << (prec - HOST_BITS_PER_WIDE_INT)) & dc.high) != 0)
8627 /* If we haven't been able to decide at this point, there nothing more we
8628 can check ourselves here. Look at the base type if we have one and it
8629 has the same precision. */
8630 if (TREE_CODE (type) == INTEGER_TYPE
8631 && TREE_TYPE (type) != 0
8632 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8634 type = TREE_TYPE (type);
8638 /* Or to double_int_fits_to_tree_p, if nothing else. */
8639 return double_int_fits_to_tree_p (type, dc);
8642 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8643 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8644 represented (assuming two's-complement arithmetic) within the bit
8645 precision of the type are returned instead. */
8648 get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8650 if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8651 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8652 mpz_set_double_int (min, tree_to_double_int (TYPE_MIN_VALUE (type)),
8653 TYPE_UNSIGNED (type));
8656 if (TYPE_UNSIGNED (type))
8657 mpz_set_ui (min, 0);
8661 mn = double_int::mask (TYPE_PRECISION (type) - 1);
8662 mn = (mn + double_int_one).sext (TYPE_PRECISION (type));
8663 mpz_set_double_int (min, mn, false);
8667 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8668 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8669 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)),
8670 TYPE_UNSIGNED (type));
8673 if (TYPE_UNSIGNED (type))
8674 mpz_set_double_int (max, double_int::mask (TYPE_PRECISION (type)),
8677 mpz_set_double_int (max, double_int::mask (TYPE_PRECISION (type) - 1),
8682 /* Return true if VAR is an automatic variable defined in function FN. */
8685 auto_var_in_fn_p (const_tree var, const_tree fn)
8687 return (DECL_P (var) && DECL_CONTEXT (var) == fn
8688 && ((((TREE_CODE (var) == VAR_DECL && ! DECL_EXTERNAL (var))
8689 || TREE_CODE (var) == PARM_DECL)
8690 && ! TREE_STATIC (var))
8691 || TREE_CODE (var) == LABEL_DECL
8692 || TREE_CODE (var) == RESULT_DECL));
8695 /* Subprogram of following function. Called by walk_tree.
8697 Return *TP if it is an automatic variable or parameter of the
8698 function passed in as DATA. */
8701 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8703 tree fn = (tree) data;
8708 else if (DECL_P (*tp)
8709 && auto_var_in_fn_p (*tp, fn))
8715 /* Returns true if T is, contains, or refers to a type with variable
8716 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8717 arguments, but not the return type. If FN is nonzero, only return
8718 true if a modifier of the type or position of FN is a variable or
8719 parameter inside FN.
8721 This concept is more general than that of C99 'variably modified types':
8722 in C99, a struct type is never variably modified because a VLA may not
8723 appear as a structure member. However, in GNU C code like:
8725 struct S { int i[f()]; };
8727 is valid, and other languages may define similar constructs. */
8730 variably_modified_type_p (tree type, tree fn)
8734 /* Test if T is either variable (if FN is zero) or an expression containing
8735 a variable in FN. If TYPE isn't gimplified, return true also if
8736 gimplify_one_sizepos would gimplify the expression into a local
8738 #define RETURN_TRUE_IF_VAR(T) \
8739 do { tree _t = (T); \
8740 if (_t != NULL_TREE \
8741 && _t != error_mark_node \
8742 && TREE_CODE (_t) != INTEGER_CST \
8743 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8745 || (!TYPE_SIZES_GIMPLIFIED (type) \
8746 && !is_gimple_sizepos (_t)) \
8747 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8748 return true; } while (0)
8750 if (type == error_mark_node)
8753 /* If TYPE itself has variable size, it is variably modified. */
8754 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8755 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8757 switch (TREE_CODE (type))
8760 case REFERENCE_TYPE:
8762 if (variably_modified_type_p (TREE_TYPE (type), fn))
8768 /* If TYPE is a function type, it is variably modified if the
8769 return type is variably modified. */
8770 if (variably_modified_type_p (TREE_TYPE (type), fn))
8776 case FIXED_POINT_TYPE:
8779 /* Scalar types are variably modified if their end points
8781 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8782 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8787 case QUAL_UNION_TYPE:
8788 /* We can't see if any of the fields are variably-modified by the
8789 definition we normally use, since that would produce infinite
8790 recursion via pointers. */
8791 /* This is variably modified if some field's type is. */
8792 for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8793 if (TREE_CODE (t) == FIELD_DECL)
8795 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8796 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8797 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8799 if (TREE_CODE (type) == QUAL_UNION_TYPE)
8800 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8805 /* Do not call ourselves to avoid infinite recursion. This is
8806 variably modified if the element type is. */
8807 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8808 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8815 /* The current language may have other cases to check, but in general,
8816 all other types are not variably modified. */
8817 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8819 #undef RETURN_TRUE_IF_VAR
8822 /* Given a DECL or TYPE, return the scope in which it was declared, or
8823 NULL_TREE if there is no containing scope. */
8826 get_containing_scope (const_tree t)
8828 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8831 /* Return the innermost context enclosing DECL that is
8832 a FUNCTION_DECL, or zero if none. */
8835 decl_function_context (const_tree decl)
8839 if (TREE_CODE (decl) == ERROR_MARK)
8842 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8843 where we look up the function at runtime. Such functions always take
8844 a first argument of type 'pointer to real context'.
8846 C++ should really be fixed to use DECL_CONTEXT for the real context,
8847 and use something else for the "virtual context". */
8848 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
8851 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8853 context = DECL_CONTEXT (decl);
8855 while (context && TREE_CODE (context) != FUNCTION_DECL)
8857 if (TREE_CODE (context) == BLOCK)
8858 context = BLOCK_SUPERCONTEXT (context);
8860 context = get_containing_scope (context);
8866 /* Return the innermost context enclosing DECL that is
8867 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8868 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8871 decl_type_context (const_tree decl)
8873 tree context = DECL_CONTEXT (decl);
8876 switch (TREE_CODE (context))
8878 case NAMESPACE_DECL:
8879 case TRANSLATION_UNIT_DECL:
8884 case QUAL_UNION_TYPE:
8889 context = DECL_CONTEXT (context);
8893 context = BLOCK_SUPERCONTEXT (context);
8903 /* CALL is a CALL_EXPR. Return the declaration for the function
8904 called, or NULL_TREE if the called function cannot be
8908 get_callee_fndecl (const_tree call)
8912 if (call == error_mark_node)
8913 return error_mark_node;
8915 /* It's invalid to call this function with anything but a
8917 gcc_assert (TREE_CODE (call) == CALL_EXPR);
8919 /* The first operand to the CALL is the address of the function
8921 addr = CALL_EXPR_FN (call);
8925 /* If this is a readonly function pointer, extract its initial value. */
8926 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8927 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8928 && DECL_INITIAL (addr))
8929 addr = DECL_INITIAL (addr);
8931 /* If the address is just `&f' for some function `f', then we know
8932 that `f' is being called. */
8933 if (TREE_CODE (addr) == ADDR_EXPR
8934 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8935 return TREE_OPERAND (addr, 0);
8937 /* We couldn't figure out what was being called. */
8941 /* Print debugging information about tree nodes generated during the compile,
8942 and any language-specific information. */
8945 dump_tree_statistics (void)
8947 if (GATHER_STATISTICS)
8950 int total_nodes, total_bytes;
8951 fprintf (stderr, "Kind Nodes Bytes\n");
8952 fprintf (stderr, "---------------------------------------\n");
8953 total_nodes = total_bytes = 0;
8954 for (i = 0; i < (int) all_kinds; i++)
8956 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
8957 tree_node_counts[i], tree_node_sizes[i]);
8958 total_nodes += tree_node_counts[i];
8959 total_bytes += tree_node_sizes[i];
8961 fprintf (stderr, "---------------------------------------\n");
8962 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
8963 fprintf (stderr, "---------------------------------------\n");
8964 fprintf (stderr, "Code Nodes\n");
8965 fprintf (stderr, "----------------------------\n");
8966 for (i = 0; i < (int) MAX_TREE_CODES; i++)
8967 fprintf (stderr, "%-20s %7d\n", get_tree_code_name ((enum tree_code) i),
8968 tree_code_counts[i]);
8969 fprintf (stderr, "----------------------------\n");
8970 ssanames_print_statistics ();
8971 phinodes_print_statistics ();
8974 fprintf (stderr, "(No per-node statistics)\n");
8976 print_type_hash_statistics ();
8977 print_debug_expr_statistics ();
8978 print_value_expr_statistics ();
8979 lang_hooks.print_statistics ();
8982 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8984 /* Generate a crc32 of a byte. */
8987 crc32_unsigned_bits (unsigned chksum, unsigned value, unsigned bits)
8991 for (ix = bits; ix--; value <<= 1)
8995 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
9002 /* Generate a crc32 of a 32-bit unsigned. */
9005 crc32_unsigned (unsigned chksum, unsigned value)
9007 return crc32_unsigned_bits (chksum, value, 32);
9010 /* Generate a crc32 of a byte. */
9013 crc32_byte (unsigned chksum, char byte)
9015 return crc32_unsigned_bits (chksum, (unsigned) byte << 24, 8);
9018 /* Generate a crc32 of a string. */
9021 crc32_string (unsigned chksum, const char *string)
9025 chksum = crc32_byte (chksum, *string);
9031 /* P is a string that will be used in a symbol. Mask out any characters
9032 that are not valid in that context. */
9035 clean_symbol_name (char *p)
9039 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9042 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9049 /* Generate a name for a special-purpose function.
9050 The generated name may need to be unique across the whole link.
9051 Changes to this function may also require corresponding changes to
9052 xstrdup_mask_random.
9053 TYPE is some string to identify the purpose of this function to the
9054 linker or collect2; it must start with an uppercase letter,
9056 I - for constructors
9058 N - for C++ anonymous namespaces
9059 F - for DWARF unwind frame information. */
9062 get_file_function_name (const char *type)
9068 /* If we already have a name we know to be unique, just use that. */
9069 if (first_global_object_name)
9070 p = q = ASTRDUP (first_global_object_name);
9071 /* If the target is handling the constructors/destructors, they
9072 will be local to this file and the name is only necessary for
9074 We also assign sub_I and sub_D sufixes to constructors called from
9075 the global static constructors. These are always local. */
9076 else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9077 || (strncmp (type, "sub_", 4) == 0
9078 && (type[4] == 'I' || type[4] == 'D')))
9080 const char *file = main_input_filename;
9082 file = input_filename;
9083 /* Just use the file's basename, because the full pathname
9084 might be quite long. */
9085 p = q = ASTRDUP (lbasename (file));
9089 /* Otherwise, the name must be unique across the entire link.
9090 We don't have anything that we know to be unique to this translation
9091 unit, so use what we do have and throw in some randomness. */
9093 const char *name = weak_global_object_name;
9094 const char *file = main_input_filename;
9099 file = input_filename;
9101 len = strlen (file);
9102 q = (char *) alloca (9 + 17 + len + 1);
9103 memcpy (q, file, len + 1);
9105 snprintf (q + len, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9106 crc32_string (0, name), get_random_seed (false));
9111 clean_symbol_name (q);
9112 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9115 /* Set up the name of the file-level functions we may need.
9116 Use a global object (which is already required to be unique over
9117 the program) rather than the file name (which imposes extra
9119 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9121 return get_identifier (buf);
9124 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9126 /* Complain that the tree code of NODE does not match the expected 0
9127 terminated list of trailing codes. The trailing code list can be
9128 empty, for a more vague error message. FILE, LINE, and FUNCTION
9129 are of the caller. */
9132 tree_check_failed (const_tree node, const char *file,
9133 int line, const char *function, ...)
9137 unsigned length = 0;
9138 enum tree_code code;
9140 va_start (args, function);
9141 while ((code = (enum tree_code) va_arg (args, int)))
9142 length += 4 + strlen (get_tree_code_name (code));
9147 va_start (args, function);
9148 length += strlen ("expected ");
9149 buffer = tmp = (char *) alloca (length);
9151 while ((code = (enum tree_code) va_arg (args, int)))
9153 const char *prefix = length ? " or " : "expected ";
9155 strcpy (tmp + length, prefix);
9156 length += strlen (prefix);
9157 strcpy (tmp + length, get_tree_code_name (code));
9158 length += strlen (get_tree_code_name (code));
9163 buffer = "unexpected node";
9165 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9166 buffer, get_tree_code_name (TREE_CODE (node)),
9167 function, trim_filename (file), line);
9170 /* Complain that the tree code of NODE does match the expected 0
9171 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9175 tree_not_check_failed (const_tree node, const char *file,
9176 int line, const char *function, ...)
9180 unsigned length = 0;
9181 enum tree_code code;
9183 va_start (args, function);
9184 while ((code = (enum tree_code) va_arg (args, int)))
9185 length += 4 + strlen (get_tree_code_name (code));
9187 va_start (args, function);
9188 buffer = (char *) alloca (length);
9190 while ((code = (enum tree_code) va_arg (args, int)))
9194 strcpy (buffer + length, " or ");
9197 strcpy (buffer + length, get_tree_code_name (code));
9198 length += strlen (get_tree_code_name (code));
9202 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9203 buffer, get_tree_code_name (TREE_CODE (node)),
9204 function, trim_filename (file), line);
9207 /* Similar to tree_check_failed, except that we check for a class of tree
9208 code, given in CL. */
9211 tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9212 const char *file, int line, const char *function)
9215 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9216 TREE_CODE_CLASS_STRING (cl),
9217 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9218 get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9221 /* Similar to tree_check_failed, except that instead of specifying a
9222 dozen codes, use the knowledge that they're all sequential. */
9225 tree_range_check_failed (const_tree node, const char *file, int line,
9226 const char *function, enum tree_code c1,
9230 unsigned length = 0;
9233 for (c = c1; c <= c2; ++c)
9234 length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9236 length += strlen ("expected ");
9237 buffer = (char *) alloca (length);
9240 for (c = c1; c <= c2; ++c)
9242 const char *prefix = length ? " or " : "expected ";
9244 strcpy (buffer + length, prefix);
9245 length += strlen (prefix);
9246 strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9247 length += strlen (get_tree_code_name ((enum tree_code) c));
9250 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9251 buffer, get_tree_code_name (TREE_CODE (node)),
9252 function, trim_filename (file), line);
9256 /* Similar to tree_check_failed, except that we check that a tree does
9257 not have the specified code, given in CL. */
9260 tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9261 const char *file, int line, const char *function)
9264 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9265 TREE_CODE_CLASS_STRING (cl),
9266 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9267 get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9271 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9274 omp_clause_check_failed (const_tree node, const char *file, int line,
9275 const char *function, enum omp_clause_code code)
9277 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
9278 omp_clause_code_name[code], get_tree_code_name (TREE_CODE (node)),
9279 function, trim_filename (file), line);
9283 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9286 omp_clause_range_check_failed (const_tree node, const char *file, int line,
9287 const char *function, enum omp_clause_code c1,
9288 enum omp_clause_code c2)
9291 unsigned length = 0;
9294 for (c = c1; c <= c2; ++c)
9295 length += 4 + strlen (omp_clause_code_name[c]);
9297 length += strlen ("expected ");
9298 buffer = (char *) alloca (length);
9301 for (c = c1; c <= c2; ++c)
9303 const char *prefix = length ? " or " : "expected ";
9305 strcpy (buffer + length, prefix);
9306 length += strlen (prefix);
9307 strcpy (buffer + length, omp_clause_code_name[c]);
9308 length += strlen (omp_clause_code_name[c]);
9311 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9312 buffer, omp_clause_code_name[TREE_CODE (node)],
9313 function, trim_filename (file), line);
9317 #undef DEFTREESTRUCT
9318 #define DEFTREESTRUCT(VAL, NAME) NAME,
9320 static const char *ts_enum_names[] = {
9321 #include "treestruct.def"
9323 #undef DEFTREESTRUCT
9325 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9327 /* Similar to tree_class_check_failed, except that we check for
9328 whether CODE contains the tree structure identified by EN. */
9331 tree_contains_struct_check_failed (const_tree node,
9332 const enum tree_node_structure_enum en,
9333 const char *file, int line,
9334 const char *function)
9337 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9339 get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9343 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9344 (dynamically sized) vector. */
9347 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9348 const char *function)
9351 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
9352 idx + 1, len, function, trim_filename (file), line);
9355 /* Similar to above, except that the check is for the bounds of the operand
9356 vector of an expression node EXP. */
9359 tree_operand_check_failed (int idx, const_tree exp, const char *file,
9360 int line, const char *function)
9362 enum tree_code code = TREE_CODE (exp);
9364 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9365 idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9366 function, trim_filename (file), line);
9369 /* Similar to above, except that the check is for the number of
9370 operands of an OMP_CLAUSE node. */
9373 omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9374 int line, const char *function)
9377 ("tree check: accessed operand %d of omp_clause %s with %d operands "
9378 "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9379 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9380 trim_filename (file), line);
9382 #endif /* ENABLE_TREE_CHECKING */
9384 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
9385 and mapped to the machine mode MODE. Initialize its fields and build
9386 the information necessary for debugging output. */
9389 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
9392 hashval_t hashcode = 0;
9394 t = make_node (VECTOR_TYPE);
9395 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
9396 SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9397 SET_TYPE_MODE (t, mode);
9399 if (TYPE_STRUCTURAL_EQUALITY_P (innertype))
9400 SET_TYPE_STRUCTURAL_EQUALITY (t);
9401 else if (TYPE_CANONICAL (innertype) != innertype
9402 || mode != VOIDmode)
9404 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode);
9408 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
9409 hashcode = iterative_hash_host_wide_int (nunits, hashcode);
9410 hashcode = iterative_hash_host_wide_int (mode, hashcode);
9411 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (t)), hashcode);
9412 t = type_hash_canon (hashcode, t);
9414 /* We have built a main variant, based on the main variant of the
9415 inner type. Use it to build the variant we return. */
9416 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9417 && TREE_TYPE (t) != innertype)
9418 return build_type_attribute_qual_variant (t,
9419 TYPE_ATTRIBUTES (innertype),
9420 TYPE_QUALS (innertype));
9426 make_or_reuse_type (unsigned size, int unsignedp)
9428 if (size == INT_TYPE_SIZE)
9429 return unsignedp ? unsigned_type_node : integer_type_node;
9430 if (size == CHAR_TYPE_SIZE)
9431 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9432 if (size == SHORT_TYPE_SIZE)
9433 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9434 if (size == LONG_TYPE_SIZE)
9435 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9436 if (size == LONG_LONG_TYPE_SIZE)
9437 return (unsignedp ? long_long_unsigned_type_node
9438 : long_long_integer_type_node);
9439 if (size == 128 && int128_integer_type_node)
9440 return (unsignedp ? int128_unsigned_type_node
9441 : int128_integer_type_node);
9444 return make_unsigned_type (size);
9446 return make_signed_type (size);
9449 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9452 make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9456 if (size == SHORT_FRACT_TYPE_SIZE)
9457 return unsignedp ? sat_unsigned_short_fract_type_node
9458 : sat_short_fract_type_node;
9459 if (size == FRACT_TYPE_SIZE)
9460 return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9461 if (size == LONG_FRACT_TYPE_SIZE)
9462 return unsignedp ? sat_unsigned_long_fract_type_node
9463 : sat_long_fract_type_node;
9464 if (size == LONG_LONG_FRACT_TYPE_SIZE)
9465 return unsignedp ? sat_unsigned_long_long_fract_type_node
9466 : sat_long_long_fract_type_node;
9470 if (size == SHORT_FRACT_TYPE_SIZE)
9471 return unsignedp ? unsigned_short_fract_type_node
9472 : short_fract_type_node;
9473 if (size == FRACT_TYPE_SIZE)
9474 return unsignedp ? unsigned_fract_type_node : fract_type_node;
9475 if (size == LONG_FRACT_TYPE_SIZE)
9476 return unsignedp ? unsigned_long_fract_type_node
9477 : long_fract_type_node;
9478 if (size == LONG_LONG_FRACT_TYPE_SIZE)
9479 return unsignedp ? unsigned_long_long_fract_type_node
9480 : long_long_fract_type_node;
9483 return make_fract_type (size, unsignedp, satp);
9486 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9489 make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9493 if (size == SHORT_ACCUM_TYPE_SIZE)
9494 return unsignedp ? sat_unsigned_short_accum_type_node
9495 : sat_short_accum_type_node;
9496 if (size == ACCUM_TYPE_SIZE)
9497 return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9498 if (size == LONG_ACCUM_TYPE_SIZE)
9499 return unsignedp ? sat_unsigned_long_accum_type_node
9500 : sat_long_accum_type_node;
9501 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9502 return unsignedp ? sat_unsigned_long_long_accum_type_node
9503 : sat_long_long_accum_type_node;
9507 if (size == SHORT_ACCUM_TYPE_SIZE)
9508 return unsignedp ? unsigned_short_accum_type_node
9509 : short_accum_type_node;
9510 if (size == ACCUM_TYPE_SIZE)
9511 return unsignedp ? unsigned_accum_type_node : accum_type_node;
9512 if (size == LONG_ACCUM_TYPE_SIZE)
9513 return unsignedp ? unsigned_long_accum_type_node
9514 : long_accum_type_node;
9515 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9516 return unsignedp ? unsigned_long_long_accum_type_node
9517 : long_long_accum_type_node;
9520 return make_accum_type (size, unsignedp, satp);
9524 /* Create an atomic variant node for TYPE. This routine is called
9525 during initialization of data types to create the 5 basic atomic
9526 types. The generic build_variant_type function requires these to
9527 already be set up in order to function properly, so cannot be
9528 called from there. */
9531 build_atomic_base (tree type)
9535 /* Make sure its not already registered. */
9536 if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9539 t = build_variant_type_copy (type);
9540 set_type_quals (t, TYPE_QUAL_ATOMIC);
9545 /* Create nodes for all integer types (and error_mark_node) using the sizes
9546 of C datatypes. SIGNED_CHAR specifies whether char is signed,
9547 SHORT_DOUBLE specifies whether double should be of the same precision
9551 build_common_tree_nodes (bool signed_char, bool short_double)
9553 error_mark_node = make_node (ERROR_MARK);
9554 TREE_TYPE (error_mark_node) = error_mark_node;
9556 initialize_sizetypes ();
9558 /* Define both `signed char' and `unsigned char'. */
9559 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9560 TYPE_STRING_FLAG (signed_char_type_node) = 1;
9561 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9562 TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9564 /* Define `char', which is like either `signed char' or `unsigned char'
9565 but not the same as either. */
9568 ? make_signed_type (CHAR_TYPE_SIZE)
9569 : make_unsigned_type (CHAR_TYPE_SIZE));
9570 TYPE_STRING_FLAG (char_type_node) = 1;
9572 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9573 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9574 integer_type_node = make_signed_type (INT_TYPE_SIZE);
9575 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9576 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9577 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9578 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9579 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9580 #if HOST_BITS_PER_WIDE_INT >= 64
9581 /* TODO: This isn't correct, but as logic depends at the moment on
9582 host's instead of target's wide-integer.
9583 If there is a target not supporting TImode, but has an 128-bit
9584 integer-scalar register, this target check needs to be adjusted. */
9585 if (targetm.scalar_mode_supported_p (TImode))
9587 int128_integer_type_node = make_signed_type (128);
9588 int128_unsigned_type_node = make_unsigned_type (128);
9592 /* Define a boolean type. This type only represents boolean values but
9593 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9594 Front ends which want to override this size (i.e. Java) can redefine
9595 boolean_type_node before calling build_common_tree_nodes_2. */
9596 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9597 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9598 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9599 TYPE_PRECISION (boolean_type_node) = 1;
9601 /* Define what type to use for size_t. */
9602 if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9603 size_type_node = unsigned_type_node;
9604 else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9605 size_type_node = long_unsigned_type_node;
9606 else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9607 size_type_node = long_long_unsigned_type_node;
9608 else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9609 size_type_node = short_unsigned_type_node;
9613 /* Fill in the rest of the sized types. Reuse existing type nodes
9615 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9616 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9617 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9618 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9619 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9621 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9622 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9623 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9624 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9625 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9627 /* Don't call build_qualified type for atomics. That routine does
9628 special processing for atomics, and until they are initialized
9629 it's better not to make that call. */
9631 atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node);
9632 atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node);
9633 atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node);
9634 atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node);
9635 atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node);
9637 access_public_node = get_identifier ("public");
9638 access_protected_node = get_identifier ("protected");
9639 access_private_node = get_identifier ("private");
9641 /* Define these next since types below may used them. */
9642 integer_zero_node = build_int_cst (integer_type_node, 0);
9643 integer_one_node = build_int_cst (integer_type_node, 1);
9644 integer_three_node = build_int_cst (integer_type_node, 3);
9645 integer_minus_one_node = build_int_cst (integer_type_node, -1);
9647 size_zero_node = size_int (0);
9648 size_one_node = size_int (1);
9649 bitsize_zero_node = bitsize_int (0);
9650 bitsize_one_node = bitsize_int (1);
9651 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9653 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9654 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9656 void_type_node = make_node (VOID_TYPE);
9657 layout_type (void_type_node);
9659 pointer_bounds_type_node = targetm.chkp_bound_type ();
9661 /* We are not going to have real types in C with less than byte alignment,
9662 so we might as well not have any types that claim to have it. */
9663 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
9664 TYPE_USER_ALIGN (void_type_node) = 0;
9666 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9667 layout_type (TREE_TYPE (null_pointer_node));
9669 ptr_type_node = build_pointer_type (void_type_node);
9671 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9672 fileptr_type_node = ptr_type_node;
9674 pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9676 float_type_node = make_node (REAL_TYPE);
9677 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
9678 layout_type (float_type_node);
9680 double_type_node = make_node (REAL_TYPE);
9682 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
9684 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
9685 layout_type (double_type_node);
9687 long_double_type_node = make_node (REAL_TYPE);
9688 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
9689 layout_type (long_double_type_node);
9691 float_ptr_type_node = build_pointer_type (float_type_node);
9692 double_ptr_type_node = build_pointer_type (double_type_node);
9693 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9694 integer_ptr_type_node = build_pointer_type (integer_type_node);
9696 /* Fixed size integer types. */
9697 uint16_type_node = build_nonstandard_integer_type (16, true);
9698 uint32_type_node = build_nonstandard_integer_type (32, true);
9699 uint64_type_node = build_nonstandard_integer_type (64, true);
9701 /* Decimal float types. */
9702 dfloat32_type_node = make_node (REAL_TYPE);
9703 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9704 layout_type (dfloat32_type_node);
9705 SET_TYPE_MODE (dfloat32_type_node, SDmode);
9706 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node);
9708 dfloat64_type_node = make_node (REAL_TYPE);
9709 TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9710 layout_type (dfloat64_type_node);
9711 SET_TYPE_MODE (dfloat64_type_node, DDmode);
9712 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node);
9714 dfloat128_type_node = make_node (REAL_TYPE);
9715 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9716 layout_type (dfloat128_type_node);
9717 SET_TYPE_MODE (dfloat128_type_node, TDmode);
9718 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node);
9720 complex_integer_type_node = build_complex_type (integer_type_node);
9721 complex_float_type_node = build_complex_type (float_type_node);
9722 complex_double_type_node = build_complex_type (double_type_node);
9723 complex_long_double_type_node = build_complex_type (long_double_type_node);
9725 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9726 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9727 sat_ ## KIND ## _type_node = \
9728 make_sat_signed_ ## KIND ## _type (SIZE); \
9729 sat_unsigned_ ## KIND ## _type_node = \
9730 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9731 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9732 unsigned_ ## KIND ## _type_node = \
9733 make_unsigned_ ## KIND ## _type (SIZE);
9735 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9736 sat_ ## WIDTH ## KIND ## _type_node = \
9737 make_sat_signed_ ## KIND ## _type (SIZE); \
9738 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9739 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9740 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9741 unsigned_ ## WIDTH ## KIND ## _type_node = \
9742 make_unsigned_ ## KIND ## _type (SIZE);
9744 /* Make fixed-point type nodes based on four different widths. */
9745 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9746 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9747 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9748 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9749 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9751 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9752 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9753 NAME ## _type_node = \
9754 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9755 u ## NAME ## _type_node = \
9756 make_or_reuse_unsigned_ ## KIND ## _type \
9757 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9758 sat_ ## NAME ## _type_node = \
9759 make_or_reuse_sat_signed_ ## KIND ## _type \
9760 (GET_MODE_BITSIZE (MODE ## mode)); \
9761 sat_u ## NAME ## _type_node = \
9762 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9763 (GET_MODE_BITSIZE (U ## MODE ## mode));
9765 /* Fixed-point type and mode nodes. */
9766 MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9767 MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9768 MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9769 MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9770 MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9771 MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9772 MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9773 MAKE_FIXED_MODE_NODE (accum, ha, HA)
9774 MAKE_FIXED_MODE_NODE (accum, sa, SA)
9775 MAKE_FIXED_MODE_NODE (accum, da, DA)
9776 MAKE_FIXED_MODE_NODE (accum, ta, TA)
9779 tree t = targetm.build_builtin_va_list ();
9781 /* Many back-ends define record types without setting TYPE_NAME.
9782 If we copied the record type here, we'd keep the original
9783 record type without a name. This breaks name mangling. So,
9784 don't copy record types and let c_common_nodes_and_builtins()
9785 declare the type to be __builtin_va_list. */
9786 if (TREE_CODE (t) != RECORD_TYPE)
9787 t = build_variant_type_copy (t);
9789 va_list_type_node = t;
9793 /* Modify DECL for given flags.
9794 TM_PURE attribute is set only on types, so the function will modify
9795 DECL's type when ECF_TM_PURE is used. */
9798 set_call_expr_flags (tree decl, int flags)
9800 if (flags & ECF_NOTHROW)
9801 TREE_NOTHROW (decl) = 1;
9802 if (flags & ECF_CONST)
9803 TREE_READONLY (decl) = 1;
9804 if (flags & ECF_PURE)
9805 DECL_PURE_P (decl) = 1;
9806 if (flags & ECF_LOOPING_CONST_OR_PURE)
9807 DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9808 if (flags & ECF_NOVOPS)
9809 DECL_IS_NOVOPS (decl) = 1;
9810 if (flags & ECF_NORETURN)
9811 TREE_THIS_VOLATILE (decl) = 1;
9812 if (flags & ECF_MALLOC)
9813 DECL_IS_MALLOC (decl) = 1;
9814 if (flags & ECF_RETURNS_TWICE)
9815 DECL_IS_RETURNS_TWICE (decl) = 1;
9816 if (flags & ECF_LEAF)
9817 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9818 NULL, DECL_ATTRIBUTES (decl));
9819 if ((flags & ECF_TM_PURE) && flag_tm)
9820 apply_tm_attr (decl, get_identifier ("transaction_pure"));
9821 /* Looping const or pure is implied by noreturn.
9822 There is currently no way to declare looping const or looping pure alone. */
9823 gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
9824 || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
9828 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9831 local_define_builtin (const char *name, tree type, enum built_in_function code,
9832 const char *library_name, int ecf_flags)
9836 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
9837 library_name, NULL_TREE);
9838 set_call_expr_flags (decl, ecf_flags);
9840 set_builtin_decl (code, decl, true);
9843 /* Call this function after instantiating all builtins that the language
9844 front end cares about. This will build the rest of the builtins that
9845 are relied upon by the tree optimizers and the middle-end. */
9848 build_common_builtin_nodes (void)
9853 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
9855 ftype = build_function_type (void_type_node, void_list_node);
9856 local_define_builtin ("__builtin_unreachable", ftype, BUILT_IN_UNREACHABLE,
9857 "__builtin_unreachable",
9858 ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
9859 | ECF_CONST | ECF_LEAF);
9862 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
9863 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
9865 ftype = build_function_type_list (ptr_type_node,
9866 ptr_type_node, const_ptr_type_node,
9867 size_type_node, NULL_TREE);
9869 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
9870 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
9871 "memcpy", ECF_NOTHROW | ECF_LEAF);
9872 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
9873 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
9874 "memmove", ECF_NOTHROW | ECF_LEAF);
9877 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
9879 ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
9880 const_ptr_type_node, size_type_node,
9882 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
9883 "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
9886 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
9888 ftype = build_function_type_list (ptr_type_node,
9889 ptr_type_node, integer_type_node,
9890 size_type_node, NULL_TREE);
9891 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
9892 "memset", ECF_NOTHROW | ECF_LEAF);
9895 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
9897 ftype = build_function_type_list (ptr_type_node,
9898 size_type_node, NULL_TREE);
9899 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
9900 "alloca", ECF_MALLOC | ECF_NOTHROW | ECF_LEAF);
9903 ftype = build_function_type_list (ptr_type_node, size_type_node,
9904 size_type_node, NULL_TREE);
9905 local_define_builtin ("__builtin_alloca_with_align", ftype,
9906 BUILT_IN_ALLOCA_WITH_ALIGN, "alloca",
9907 ECF_MALLOC | ECF_NOTHROW | ECF_LEAF);
9909 /* If we're checking the stack, `alloca' can throw. */
9910 if (flag_stack_check)
9912 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA)) = 0;
9913 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN)) = 0;
9916 ftype = build_function_type_list (void_type_node,
9917 ptr_type_node, ptr_type_node,
9918 ptr_type_node, NULL_TREE);
9919 local_define_builtin ("__builtin_init_trampoline", ftype,
9920 BUILT_IN_INIT_TRAMPOLINE,
9921 "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
9922 local_define_builtin ("__builtin_init_heap_trampoline", ftype,
9923 BUILT_IN_INIT_HEAP_TRAMPOLINE,
9924 "__builtin_init_heap_trampoline",
9925 ECF_NOTHROW | ECF_LEAF);
9927 ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
9928 local_define_builtin ("__builtin_adjust_trampoline", ftype,
9929 BUILT_IN_ADJUST_TRAMPOLINE,
9930 "__builtin_adjust_trampoline",
9931 ECF_CONST | ECF_NOTHROW);
9933 ftype = build_function_type_list (void_type_node,
9934 ptr_type_node, ptr_type_node, NULL_TREE);
9935 local_define_builtin ("__builtin_nonlocal_goto", ftype,
9936 BUILT_IN_NONLOCAL_GOTO,
9937 "__builtin_nonlocal_goto",
9938 ECF_NORETURN | ECF_NOTHROW);
9940 ftype = build_function_type_list (void_type_node,
9941 ptr_type_node, ptr_type_node, NULL_TREE);
9942 local_define_builtin ("__builtin_setjmp_setup", ftype,
9943 BUILT_IN_SETJMP_SETUP,
9944 "__builtin_setjmp_setup", ECF_NOTHROW);
9946 ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
9947 local_define_builtin ("__builtin_setjmp_dispatcher", ftype,
9948 BUILT_IN_SETJMP_DISPATCHER,
9949 "__builtin_setjmp_dispatcher",
9950 ECF_PURE | ECF_NOTHROW);
9952 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
9953 local_define_builtin ("__builtin_setjmp_receiver", ftype,
9954 BUILT_IN_SETJMP_RECEIVER,
9955 "__builtin_setjmp_receiver", ECF_NOTHROW);
9957 ftype = build_function_type_list (ptr_type_node, NULL_TREE);
9958 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
9959 "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
9961 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
9962 local_define_builtin ("__builtin_stack_restore", ftype,
9963 BUILT_IN_STACK_RESTORE,
9964 "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
9966 /* If there's a possibility that we might use the ARM EABI, build the
9967 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9968 if (targetm.arm_eabi_unwinder)
9970 ftype = build_function_type_list (void_type_node, NULL_TREE);
9971 local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
9972 BUILT_IN_CXA_END_CLEANUP,
9973 "__cxa_end_cleanup", ECF_NORETURN | ECF_LEAF);
9976 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
9977 local_define_builtin ("__builtin_unwind_resume", ftype,
9978 BUILT_IN_UNWIND_RESUME,
9979 ((targetm_common.except_unwind_info (&global_options)
9981 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9984 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
9986 ftype = build_function_type_list (ptr_type_node, integer_type_node,
9988 local_define_builtin ("__builtin_return_address", ftype,
9989 BUILT_IN_RETURN_ADDRESS,
9990 "__builtin_return_address",
9994 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
9995 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
9997 ftype = build_function_type_list (void_type_node, ptr_type_node,
9998 ptr_type_node, NULL_TREE);
9999 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10000 local_define_builtin ("__cyg_profile_func_enter", ftype,
10001 BUILT_IN_PROFILE_FUNC_ENTER,
10002 "__cyg_profile_func_enter", 0);
10003 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10004 local_define_builtin ("__cyg_profile_func_exit", ftype,
10005 BUILT_IN_PROFILE_FUNC_EXIT,
10006 "__cyg_profile_func_exit", 0);
10009 /* The exception object and filter values from the runtime. The argument
10010 must be zero before exception lowering, i.e. from the front end. After
10011 exception lowering, it will be the region number for the exception
10012 landing pad. These functions are PURE instead of CONST to prevent
10013 them from being hoisted past the exception edge that will initialize
10014 its value in the landing pad. */
10015 ftype = build_function_type_list (ptr_type_node,
10016 integer_type_node, NULL_TREE);
10017 ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10018 /* Only use TM_PURE if we we have TM language support. */
10019 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10020 ecf_flags |= ECF_TM_PURE;
10021 local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10022 "__builtin_eh_pointer", ecf_flags);
10024 tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10025 ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10026 local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10027 "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10029 ftype = build_function_type_list (void_type_node,
10030 integer_type_node, integer_type_node,
10032 local_define_builtin ("__builtin_eh_copy_values", ftype,
10033 BUILT_IN_EH_COPY_VALUES,
10034 "__builtin_eh_copy_values", ECF_NOTHROW);
10036 /* Complex multiplication and division. These are handled as builtins
10037 rather than optabs because emit_library_call_value doesn't support
10038 complex. Further, we can do slightly better with folding these
10039 beasties if the real and complex parts of the arguments are separate. */
10043 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10045 char mode_name_buf[4], *q;
10047 enum built_in_function mcode, dcode;
10048 tree type, inner_type;
10049 const char *prefix = "__";
10051 if (targetm.libfunc_gnu_prefix)
10054 type = lang_hooks.types.type_for_mode ((enum machine_mode) mode, 0);
10057 inner_type = TREE_TYPE (type);
10059 ftype = build_function_type_list (type, inner_type, inner_type,
10060 inner_type, inner_type, NULL_TREE);
10062 mcode = ((enum built_in_function)
10063 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10064 dcode = ((enum built_in_function)
10065 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10067 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10071 built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10073 local_define_builtin (built_in_names[mcode], ftype, mcode,
10074 built_in_names[mcode],
10075 ECF_CONST | ECF_NOTHROW | ECF_LEAF);
10077 built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10079 local_define_builtin (built_in_names[dcode], ftype, dcode,
10080 built_in_names[dcode],
10081 ECF_CONST | ECF_NOTHROW | ECF_LEAF);
10086 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10089 If we requested a pointer to a vector, build up the pointers that
10090 we stripped off while looking for the inner type. Similarly for
10091 return values from functions.
10093 The argument TYPE is the top of the chain, and BOTTOM is the
10094 new type which we will point to. */
10097 reconstruct_complex_type (tree type, tree bottom)
10101 if (TREE_CODE (type) == POINTER_TYPE)
10103 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10104 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10105 TYPE_REF_CAN_ALIAS_ALL (type));
10107 else if (TREE_CODE (type) == REFERENCE_TYPE)
10109 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10110 outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10111 TYPE_REF_CAN_ALIAS_ALL (type));
10113 else if (TREE_CODE (type) == ARRAY_TYPE)
10115 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10116 outer = build_array_type (inner, TYPE_DOMAIN (type));
10118 else if (TREE_CODE (type) == FUNCTION_TYPE)
10120 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10121 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
10123 else if (TREE_CODE (type) == METHOD_TYPE)
10125 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10126 /* The build_method_type_directly() routine prepends 'this' to argument list,
10127 so we must compensate by getting rid of it. */
10129 = build_method_type_directly
10130 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10132 TREE_CHAIN (TYPE_ARG_TYPES (type)));
10134 else if (TREE_CODE (type) == OFFSET_TYPE)
10136 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10137 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10142 return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10143 TYPE_QUALS (type));
10146 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10149 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
10153 switch (GET_MODE_CLASS (mode))
10155 case MODE_VECTOR_INT:
10156 case MODE_VECTOR_FLOAT:
10157 case MODE_VECTOR_FRACT:
10158 case MODE_VECTOR_UFRACT:
10159 case MODE_VECTOR_ACCUM:
10160 case MODE_VECTOR_UACCUM:
10161 nunits = GET_MODE_NUNITS (mode);
10165 /* Check that there are no leftover bits. */
10166 gcc_assert (GET_MODE_BITSIZE (mode)
10167 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10169 nunits = GET_MODE_BITSIZE (mode)
10170 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10174 gcc_unreachable ();
10177 return make_vector_type (innertype, nunits, mode);
10180 /* Similarly, but takes the inner type and number of units, which must be
10184 build_vector_type (tree innertype, int nunits)
10186 return make_vector_type (innertype, nunits, VOIDmode);
10189 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10192 build_opaque_vector_type (tree innertype, int nunits)
10194 tree t = make_vector_type (innertype, nunits, VOIDmode);
10196 /* We always build the non-opaque variant before the opaque one,
10197 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10198 cand = TYPE_NEXT_VARIANT (t);
10200 && TYPE_VECTOR_OPAQUE (cand)
10201 && check_qualified_type (cand, t, TYPE_QUALS (t)))
10203 /* Othewise build a variant type and make sure to queue it after
10204 the non-opaque type. */
10205 cand = build_distinct_type_copy (t);
10206 TYPE_VECTOR_OPAQUE (cand) = true;
10207 TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10208 TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10209 TYPE_NEXT_VARIANT (t) = cand;
10210 TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10215 /* Given an initializer INIT, return TRUE if INIT is zero or some
10216 aggregate of zeros. Otherwise return FALSE. */
10218 initializer_zerop (const_tree init)
10224 switch (TREE_CODE (init))
10227 return integer_zerop (init);
10230 /* ??? Note that this is not correct for C4X float formats. There,
10231 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10232 negative exponent. */
10233 return real_zerop (init)
10234 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
10237 return fixed_zerop (init);
10240 return integer_zerop (init)
10241 || (real_zerop (init)
10242 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10243 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
10248 for (i = 0; i < VECTOR_CST_NELTS (init); ++i)
10249 if (!initializer_zerop (VECTOR_CST_ELT (init, i)))
10256 unsigned HOST_WIDE_INT idx;
10258 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10259 if (!initializer_zerop (elt))
10268 /* We need to loop through all elements to handle cases like
10269 "\0" and "\0foobar". */
10270 for (i = 0; i < TREE_STRING_LENGTH (init); ++i)
10271 if (TREE_STRING_POINTER (init)[i] != '\0')
10282 /* Check if vector VEC consists of all the equal elements and
10283 that the number of elements corresponds to the type of VEC.
10284 The function returns first element of the vector
10285 or NULL_TREE if the vector is not uniform. */
10287 uniform_vector_p (const_tree vec)
10292 if (vec == NULL_TREE)
10295 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10297 if (TREE_CODE (vec) == VECTOR_CST)
10299 first = VECTOR_CST_ELT (vec, 0);
10300 for (i = 1; i < VECTOR_CST_NELTS (vec); ++i)
10301 if (!operand_equal_p (first, VECTOR_CST_ELT (vec, i), 0))
10307 else if (TREE_CODE (vec) == CONSTRUCTOR)
10309 first = error_mark_node;
10311 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10318 if (!operand_equal_p (first, t, 0))
10321 if (i != TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)))
10330 /* Build an empty statement at location LOC. */
10333 build_empty_stmt (location_t loc)
10335 tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10336 SET_EXPR_LOCATION (t, loc);
10341 /* Build an OpenMP clause with code CODE. LOC is the location of the
10345 build_omp_clause (location_t loc, enum omp_clause_code code)
10350 length = omp_clause_num_ops[code];
10351 size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10353 record_node_allocation_statistics (OMP_CLAUSE, size);
10355 t = ggc_alloc_tree_node (size);
10356 memset (t, 0, size);
10357 TREE_SET_CODE (t, OMP_CLAUSE);
10358 OMP_CLAUSE_SET_CODE (t, code);
10359 OMP_CLAUSE_LOCATION (t) = loc;
10364 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10365 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10366 Except for the CODE and operand count field, other storage for the
10367 object is initialized to zeros. */
10370 build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
10373 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10375 gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
10376 gcc_assert (len >= 1);
10378 record_node_allocation_statistics (code, length);
10380 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
10382 TREE_SET_CODE (t, code);
10384 /* Can't use TREE_OPERAND to store the length because if checking is
10385 enabled, it will try to check the length before we store it. :-P */
10386 t->exp.operands[0] = build_int_cst (sizetype, len);
10391 /* Helper function for build_call_* functions; build a CALL_EXPR with
10392 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10393 the argument slots. */
10396 build_call_1 (tree return_type, tree fn, int nargs)
10400 t = build_vl_exp (CALL_EXPR, nargs + 3);
10401 TREE_TYPE (t) = return_type;
10402 CALL_EXPR_FN (t) = fn;
10403 CALL_EXPR_STATIC_CHAIN (t) = NULL;
10408 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10409 FN and a null static chain slot. NARGS is the number of call arguments
10410 which are specified as "..." arguments. */
10413 build_call_nary (tree return_type, tree fn, int nargs, ...)
10417 va_start (args, nargs);
10418 ret = build_call_valist (return_type, fn, nargs, args);
10423 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10424 FN and a null static chain slot. NARGS is the number of call arguments
10425 which are specified as a va_list ARGS. */
10428 build_call_valist (tree return_type, tree fn, int nargs, va_list args)
10433 t = build_call_1 (return_type, fn, nargs);
10434 for (i = 0; i < nargs; i++)
10435 CALL_EXPR_ARG (t, i) = va_arg (args, tree);
10436 process_call_operands (t);
10440 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10441 FN and a null static chain slot. NARGS is the number of call arguments
10442 which are specified as a tree array ARGS. */
10445 build_call_array_loc (location_t loc, tree return_type, tree fn,
10446 int nargs, const tree *args)
10451 t = build_call_1 (return_type, fn, nargs);
10452 for (i = 0; i < nargs; i++)
10453 CALL_EXPR_ARG (t, i) = args[i];
10454 process_call_operands (t);
10455 SET_EXPR_LOCATION (t, loc);
10459 /* Like build_call_array, but takes a vec. */
10462 build_call_vec (tree return_type, tree fn, vec<tree, va_gc> *args)
10467 ret = build_call_1 (return_type, fn, vec_safe_length (args));
10468 FOR_EACH_VEC_SAFE_ELT (args, ix, t)
10469 CALL_EXPR_ARG (ret, ix) = t;
10470 process_call_operands (ret);
10474 /* Return true if T (assumed to be a DECL) must be assigned a memory
10478 needs_to_live_in_memory (const_tree t)
10480 return (TREE_ADDRESSABLE (t)
10481 || is_global_var (t)
10482 || (TREE_CODE (t) == RESULT_DECL
10483 && !DECL_BY_REFERENCE (t)
10484 && aggregate_value_p (t, current_function_decl)));
10487 /* Return value of a constant X and sign-extend it. */
10490 int_cst_value (const_tree x)
10492 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
10493 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
10495 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10496 gcc_assert (TREE_INT_CST_HIGH (x) == 0
10497 || TREE_INT_CST_HIGH (x) == -1);
10499 if (bits < HOST_BITS_PER_WIDE_INT)
10501 bool negative = ((val >> (bits - 1)) & 1) != 0;
10503 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
10505 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
10511 /* Return value of a constant X and sign-extend it. */
10514 widest_int_cst_value (const_tree x)
10516 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
10517 unsigned HOST_WIDEST_INT val = TREE_INT_CST_LOW (x);
10519 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
10520 gcc_assert (HOST_BITS_PER_WIDEST_INT >= HOST_BITS_PER_DOUBLE_INT);
10521 val |= (((unsigned HOST_WIDEST_INT) TREE_INT_CST_HIGH (x))
10522 << HOST_BITS_PER_WIDE_INT);
10524 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10525 gcc_assert (TREE_INT_CST_HIGH (x) == 0
10526 || TREE_INT_CST_HIGH (x) == -1);
10529 if (bits < HOST_BITS_PER_WIDEST_INT)
10531 bool negative = ((val >> (bits - 1)) & 1) != 0;
10533 val |= (~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1;
10535 val &= ~((~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1);
10541 /* If TYPE is an integral or pointer type, return an integer type with
10542 the same precision which is unsigned iff UNSIGNEDP is true, or itself
10543 if TYPE is already an integer type of signedness UNSIGNEDP. */
10546 signed_or_unsigned_type_for (int unsignedp, tree type)
10548 if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type) == unsignedp)
10551 if (TREE_CODE (type) == VECTOR_TYPE)
10553 tree inner = TREE_TYPE (type);
10554 tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
10557 if (inner == inner2)
10559 return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
10562 if (!INTEGRAL_TYPE_P (type)
10563 && !POINTER_TYPE_P (type))
10566 return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
10569 /* If TYPE is an integral or pointer type, return an integer type with
10570 the same precision which is unsigned, or itself if TYPE is already an
10571 unsigned integer type. */
10574 unsigned_type_for (tree type)
10576 return signed_or_unsigned_type_for (1, type);
10579 /* If TYPE is an integral or pointer type, return an integer type with
10580 the same precision which is signed, or itself if TYPE is already a
10581 signed integer type. */
10584 signed_type_for (tree type)
10586 return signed_or_unsigned_type_for (0, type);
10589 /* If TYPE is a vector type, return a signed integer vector type with the
10590 same width and number of subparts. Otherwise return boolean_type_node. */
10593 truth_type_for (tree type)
10595 if (TREE_CODE (type) == VECTOR_TYPE)
10597 tree elem = lang_hooks.types.type_for_size
10598 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))), 0);
10599 return build_opaque_vector_type (elem, TYPE_VECTOR_SUBPARTS (type));
10602 return boolean_type_node;
10605 /* Returns the largest value obtainable by casting something in INNER type to
10609 upper_bound_in_type (tree outer, tree inner)
10612 unsigned int det = 0;
10613 unsigned oprec = TYPE_PRECISION (outer);
10614 unsigned iprec = TYPE_PRECISION (inner);
10617 /* Compute a unique number for every combination. */
10618 det |= (oprec > iprec) ? 4 : 0;
10619 det |= TYPE_UNSIGNED (outer) ? 2 : 0;
10620 det |= TYPE_UNSIGNED (inner) ? 1 : 0;
10622 /* Determine the exponent to use. */
10627 /* oprec <= iprec, outer: signed, inner: don't care. */
10632 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10636 /* oprec > iprec, outer: signed, inner: signed. */
10640 /* oprec > iprec, outer: signed, inner: unsigned. */
10644 /* oprec > iprec, outer: unsigned, inner: signed. */
10648 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10652 gcc_unreachable ();
10655 /* Compute 2^^prec - 1. */
10656 if (prec <= HOST_BITS_PER_WIDE_INT)
10659 high.low = ((~(unsigned HOST_WIDE_INT) 0)
10660 >> (HOST_BITS_PER_WIDE_INT - prec));
10664 high.high = ((~(unsigned HOST_WIDE_INT) 0)
10665 >> (HOST_BITS_PER_DOUBLE_INT - prec));
10666 high.low = ~(unsigned HOST_WIDE_INT) 0;
10669 return double_int_to_tree (outer, high);
10672 /* Returns the smallest value obtainable by casting something in INNER type to
10676 lower_bound_in_type (tree outer, tree inner)
10679 unsigned oprec = TYPE_PRECISION (outer);
10680 unsigned iprec = TYPE_PRECISION (inner);
10682 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10684 if (TYPE_UNSIGNED (outer)
10685 /* If we are widening something of an unsigned type, OUTER type
10686 contains all values of INNER type. In particular, both INNER
10687 and OUTER types have zero in common. */
10688 || (oprec > iprec && TYPE_UNSIGNED (inner)))
10689 low.low = low.high = 0;
10692 /* If we are widening a signed type to another signed type, we
10693 want to obtain -2^^(iprec-1). If we are keeping the
10694 precision or narrowing to a signed type, we want to obtain
10696 unsigned prec = oprec > iprec ? iprec : oprec;
10698 if (prec <= HOST_BITS_PER_WIDE_INT)
10700 low.high = ~(unsigned HOST_WIDE_INT) 0;
10701 low.low = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1);
10705 low.high = ((~(unsigned HOST_WIDE_INT) 0)
10706 << (prec - HOST_BITS_PER_WIDE_INT - 1));
10711 return double_int_to_tree (outer, low);
10714 /* Return nonzero if two operands that are suitable for PHI nodes are
10715 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10716 SSA_NAME or invariant. Note that this is strictly an optimization.
10717 That is, callers of this function can directly call operand_equal_p
10718 and get the same result, only slower. */
10721 operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
10725 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
10727 return operand_equal_p (arg0, arg1, 0);
10730 /* Returns number of zeros at the end of binary representation of X.
10732 ??? Use ffs if available? */
10735 num_ending_zeros (const_tree x)
10737 unsigned HOST_WIDE_INT fr, nfr;
10738 unsigned num, abits;
10739 tree type = TREE_TYPE (x);
10741 if (TREE_INT_CST_LOW (x) == 0)
10743 num = HOST_BITS_PER_WIDE_INT;
10744 fr = TREE_INT_CST_HIGH (x);
10749 fr = TREE_INT_CST_LOW (x);
10752 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
10755 if (nfr << abits == fr)
10762 if (num > TYPE_PRECISION (type))
10763 num = TYPE_PRECISION (type);
10765 return build_int_cst_type (type, num);
10769 #define WALK_SUBTREE(NODE) \
10772 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10778 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10779 be walked whenever a type is seen in the tree. Rest of operands and return
10780 value are as for walk_tree. */
10783 walk_type_fields (tree type, walk_tree_fn func, void *data,
10784 struct pointer_set_t *pset, walk_tree_lh lh)
10786 tree result = NULL_TREE;
10788 switch (TREE_CODE (type))
10791 case REFERENCE_TYPE:
10792 /* We have to worry about mutually recursive pointers. These can't
10793 be written in C. They can in Ada. It's pathological, but
10794 there's an ACATS test (c38102a) that checks it. Deal with this
10795 by checking if we're pointing to another pointer, that one
10796 points to another pointer, that one does too, and we have no htab.
10797 If so, get a hash table. We check three levels deep to avoid
10798 the cost of the hash table if we don't need one. */
10799 if (POINTER_TYPE_P (TREE_TYPE (type))
10800 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
10801 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
10804 result = walk_tree_without_duplicates (&TREE_TYPE (type),
10812 /* ... fall through ... */
10815 WALK_SUBTREE (TREE_TYPE (type));
10819 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
10821 /* Fall through. */
10823 case FUNCTION_TYPE:
10824 WALK_SUBTREE (TREE_TYPE (type));
10828 /* We never want to walk into default arguments. */
10829 for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
10830 WALK_SUBTREE (TREE_VALUE (arg));
10835 /* Don't follow this nodes's type if a pointer for fear that
10836 we'll have infinite recursion. If we have a PSET, then we
10839 || (!POINTER_TYPE_P (TREE_TYPE (type))
10840 && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
10841 WALK_SUBTREE (TREE_TYPE (type));
10842 WALK_SUBTREE (TYPE_DOMAIN (type));
10846 WALK_SUBTREE (TREE_TYPE (type));
10847 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
10857 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
10858 called with the DATA and the address of each sub-tree. If FUNC returns a
10859 non-NULL value, the traversal is stopped, and the value returned by FUNC
10860 is returned. If PSET is non-NULL it is used to record the nodes visited,
10861 and to avoid visiting a node more than once. */
10864 walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
10865 struct pointer_set_t *pset, walk_tree_lh lh)
10867 enum tree_code code;
10871 #define WALK_SUBTREE_TAIL(NODE) \
10875 goto tail_recurse; \
10880 /* Skip empty subtrees. */
10884 /* Don't walk the same tree twice, if the user has requested
10885 that we avoid doing so. */
10886 if (pset && pointer_set_insert (pset, *tp))
10889 /* Call the function. */
10891 result = (*func) (tp, &walk_subtrees, data);
10893 /* If we found something, return it. */
10897 code = TREE_CODE (*tp);
10899 /* Even if we didn't, FUNC may have decided that there was nothing
10900 interesting below this point in the tree. */
10901 if (!walk_subtrees)
10903 /* But we still need to check our siblings. */
10904 if (code == TREE_LIST)
10905 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
10906 else if (code == OMP_CLAUSE)
10907 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
10914 result = (*lh) (tp, &walk_subtrees, func, data, pset);
10915 if (result || !walk_subtrees)
10922 case IDENTIFIER_NODE:
10929 case PLACEHOLDER_EXPR:
10933 /* None of these have subtrees other than those already walked
10938 WALK_SUBTREE (TREE_VALUE (*tp));
10939 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
10944 int len = TREE_VEC_LENGTH (*tp);
10949 /* Walk all elements but the first. */
10951 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
10953 /* Now walk the first one as a tail call. */
10954 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
10958 WALK_SUBTREE (TREE_REALPART (*tp));
10959 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
10963 unsigned HOST_WIDE_INT idx;
10964 constructor_elt *ce;
10966 for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (*tp), idx, &ce);
10968 WALK_SUBTREE (ce->value);
10973 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
10978 for (decl = BIND_EXPR_VARS (*tp); decl; decl = DECL_CHAIN (decl))
10980 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
10981 into declarations that are just mentioned, rather than
10982 declared; they don't really belong to this part of the tree.
10983 And, we can see cycles: the initializer for a declaration
10984 can refer to the declaration itself. */
10985 WALK_SUBTREE (DECL_INITIAL (decl));
10986 WALK_SUBTREE (DECL_SIZE (decl));
10987 WALK_SUBTREE (DECL_SIZE_UNIT (decl));
10989 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp));
10992 case STATEMENT_LIST:
10994 tree_stmt_iterator i;
10995 for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
10996 WALK_SUBTREE (*tsi_stmt_ptr (i));
11001 switch (OMP_CLAUSE_CODE (*tp))
11003 case OMP_CLAUSE_PRIVATE:
11004 case OMP_CLAUSE_SHARED:
11005 case OMP_CLAUSE_FIRSTPRIVATE:
11006 case OMP_CLAUSE_COPYIN:
11007 case OMP_CLAUSE_COPYPRIVATE:
11008 case OMP_CLAUSE_FINAL:
11009 case OMP_CLAUSE_IF:
11010 case OMP_CLAUSE_NUM_THREADS:
11011 case OMP_CLAUSE_SCHEDULE:
11012 case OMP_CLAUSE_UNIFORM:
11013 case OMP_CLAUSE_DEPEND:
11014 case OMP_CLAUSE_NUM_TEAMS:
11015 case OMP_CLAUSE_THREAD_LIMIT:
11016 case OMP_CLAUSE_DEVICE:
11017 case OMP_CLAUSE_DIST_SCHEDULE:
11018 case OMP_CLAUSE_SAFELEN:
11019 case OMP_CLAUSE_SIMDLEN:
11020 case OMP_CLAUSE__LOOPTEMP_:
11021 case OMP_CLAUSE__SIMDUID_:
11022 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
11025 case OMP_CLAUSE_NOWAIT:
11026 case OMP_CLAUSE_ORDERED:
11027 case OMP_CLAUSE_DEFAULT:
11028 case OMP_CLAUSE_UNTIED:
11029 case OMP_CLAUSE_MERGEABLE:
11030 case OMP_CLAUSE_PROC_BIND:
11031 case OMP_CLAUSE_INBRANCH:
11032 case OMP_CLAUSE_NOTINBRANCH:
11033 case OMP_CLAUSE_FOR:
11034 case OMP_CLAUSE_PARALLEL:
11035 case OMP_CLAUSE_SECTIONS:
11036 case OMP_CLAUSE_TASKGROUP:
11037 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
11039 case OMP_CLAUSE_LASTPRIVATE:
11040 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp));
11041 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp));
11042 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
11044 case OMP_CLAUSE_COLLAPSE:
11047 for (i = 0; i < 3; i++)
11048 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
11049 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
11052 case OMP_CLAUSE_ALIGNED:
11053 case OMP_CLAUSE_LINEAR:
11054 case OMP_CLAUSE_FROM:
11055 case OMP_CLAUSE_TO:
11056 case OMP_CLAUSE_MAP:
11057 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp));
11058 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 1));
11059 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
11061 case OMP_CLAUSE_REDUCTION:
11064 for (i = 0; i < 4; i++)
11065 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
11066 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
11070 gcc_unreachable ();
11078 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11079 But, we only want to walk once. */
11080 len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3;
11081 for (i = 0; i < len; ++i)
11082 WALK_SUBTREE (TREE_OPERAND (*tp, i));
11083 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len));
11087 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11088 defining. We only want to walk into these fields of a type in this
11089 case and not in the general case of a mere reference to the type.
11091 The criterion is as follows: if the field can be an expression, it
11092 must be walked only here. This should be in keeping with the fields
11093 that are directly gimplified in gimplify_type_sizes in order for the
11094 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11095 variable-sized types.
11097 Note that DECLs get walked as part of processing the BIND_EXPR. */
11098 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
11100 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
11101 if (TREE_CODE (*type_p) == ERROR_MARK)
11104 /* Call the function for the type. See if it returns anything or
11105 doesn't want us to continue. If we are to continue, walk both
11106 the normal fields and those for the declaration case. */
11107 result = (*func) (type_p, &walk_subtrees, data);
11108 if (result || !walk_subtrees)
11111 /* But do not walk a pointed-to type since it may itself need to
11112 be walked in the declaration case if it isn't anonymous. */
11113 if (!POINTER_TYPE_P (*type_p))
11115 result = walk_type_fields (*type_p, func, data, pset, lh);
11120 /* If this is a record type, also walk the fields. */
11121 if (RECORD_OR_UNION_TYPE_P (*type_p))
11125 for (field = TYPE_FIELDS (*type_p); field;
11126 field = DECL_CHAIN (field))
11128 /* We'd like to look at the type of the field, but we can
11129 easily get infinite recursion. So assume it's pointed
11130 to elsewhere in the tree. Also, ignore things that
11132 if (TREE_CODE (field) != FIELD_DECL)
11135 WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11136 WALK_SUBTREE (DECL_SIZE (field));
11137 WALK_SUBTREE (DECL_SIZE_UNIT (field));
11138 if (TREE_CODE (*type_p) == QUAL_UNION_TYPE)
11139 WALK_SUBTREE (DECL_QUALIFIER (field));
11143 /* Same for scalar types. */
11144 else if (TREE_CODE (*type_p) == BOOLEAN_TYPE
11145 || TREE_CODE (*type_p) == ENUMERAL_TYPE
11146 || TREE_CODE (*type_p) == INTEGER_TYPE
11147 || TREE_CODE (*type_p) == FIXED_POINT_TYPE
11148 || TREE_CODE (*type_p) == REAL_TYPE)
11150 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p));
11151 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p));
11154 WALK_SUBTREE (TYPE_SIZE (*type_p));
11155 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p));
11160 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11164 /* Walk over all the sub-trees of this operand. */
11165 len = TREE_OPERAND_LENGTH (*tp);
11167 /* Go through the subtrees. We need to do this in forward order so
11168 that the scope of a FOR_EXPR is handled properly. */
11171 for (i = 0; i < len - 1; ++i)
11172 WALK_SUBTREE (TREE_OPERAND (*tp, i));
11173 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len - 1));
11176 /* If this is a type, walk the needed fields in the type. */
11177 else if (TYPE_P (*tp))
11178 return walk_type_fields (*tp, func, data, pset, lh);
11182 /* We didn't find what we were looking for. */
11185 #undef WALK_SUBTREE_TAIL
11187 #undef WALK_SUBTREE
11189 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11192 walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11196 struct pointer_set_t *pset;
11198 pset = pointer_set_create ();
11199 result = walk_tree_1 (tp, func, data, pset, lh);
11200 pointer_set_destroy (pset);
11206 tree_block (tree t)
11208 char const c = TREE_CODE_CLASS (TREE_CODE (t));
11210 if (IS_EXPR_CODE_CLASS (c))
11211 return LOCATION_BLOCK (t->exp.locus);
11212 gcc_unreachable ();
11217 tree_set_block (tree t, tree b)
11219 char const c = TREE_CODE_CLASS (TREE_CODE (t));
11221 if (IS_EXPR_CODE_CLASS (c))
11224 t->exp.locus = COMBINE_LOCATION_DATA (line_table, t->exp.locus, b);
11226 t->exp.locus = LOCATION_LOCUS (t->exp.locus);
11229 gcc_unreachable ();
11232 /* Create a nameless artificial label and put it in the current
11233 function context. The label has a location of LOC. Returns the
11234 newly created label. */
11237 create_artificial_label (location_t loc)
11239 tree lab = build_decl (loc,
11240 LABEL_DECL, NULL_TREE, void_type_node);
11242 DECL_ARTIFICIAL (lab) = 1;
11243 DECL_IGNORED_P (lab) = 1;
11244 DECL_CONTEXT (lab) = current_function_decl;
11248 /* Given a tree, try to return a useful variable name that we can use
11249 to prefix a temporary that is being assigned the value of the tree.
11250 I.E. given <temp> = &A, return A. */
11255 tree stripped_decl;
11258 STRIP_NOPS (stripped_decl);
11259 if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
11260 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
11261 else if (TREE_CODE (stripped_decl) == SSA_NAME)
11263 tree name = SSA_NAME_IDENTIFIER (stripped_decl);
11266 return IDENTIFIER_POINTER (name);
11270 switch (TREE_CODE (stripped_decl))
11273 return get_name (TREE_OPERAND (stripped_decl, 0));
11280 /* Return true if TYPE has a variable argument list. */
11283 stdarg_p (const_tree fntype)
11285 function_args_iterator args_iter;
11286 tree n = NULL_TREE, t;
11291 FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
11296 return n != NULL_TREE && n != void_type_node;
11299 /* Return true if TYPE has a prototype. */
11302 prototype_p (tree fntype)
11306 gcc_assert (fntype != NULL_TREE);
11308 t = TYPE_ARG_TYPES (fntype);
11309 return (t != NULL_TREE);
11312 /* If BLOCK is inlined from an __attribute__((__artificial__))
11313 routine, return pointer to location from where it has been
11316 block_nonartificial_location (tree block)
11318 location_t *ret = NULL;
11320 while (block && TREE_CODE (block) == BLOCK
11321 && BLOCK_ABSTRACT_ORIGIN (block))
11323 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
11325 while (TREE_CODE (ao) == BLOCK
11326 && BLOCK_ABSTRACT_ORIGIN (ao)
11327 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
11328 ao = BLOCK_ABSTRACT_ORIGIN (ao);
11330 if (TREE_CODE (ao) == FUNCTION_DECL)
11332 /* If AO is an artificial inline, point RET to the
11333 call site locus at which it has been inlined and continue
11334 the loop, in case AO's caller is also an artificial
11336 if (DECL_DECLARED_INLINE_P (ao)
11337 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
11338 ret = &BLOCK_SOURCE_LOCATION (block);
11342 else if (TREE_CODE (ao) != BLOCK)
11345 block = BLOCK_SUPERCONTEXT (block);
11351 /* If EXP is inlined from an __attribute__((__artificial__))
11352 function, return the location of the original call expression. */
11355 tree_nonartificial_location (tree exp)
11357 location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
11362 return EXPR_LOCATION (exp);
11366 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
11369 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11372 cl_option_hash_hash (const void *x)
11374 const_tree const t = (const_tree) x;
11378 hashval_t hash = 0;
11380 if (TREE_CODE (t) == OPTIMIZATION_NODE)
11382 p = (const char *)TREE_OPTIMIZATION (t);
11383 len = sizeof (struct cl_optimization);
11386 else if (TREE_CODE (t) == TARGET_OPTION_NODE)
11388 p = (const char *)TREE_TARGET_OPTION (t);
11389 len = sizeof (struct cl_target_option);
11393 gcc_unreachable ();
11395 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
11397 for (i = 0; i < len; i++)
11399 hash = (hash << 4) ^ ((i << 2) | p[i]);
11404 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11405 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11409 cl_option_hash_eq (const void *x, const void *y)
11411 const_tree const xt = (const_tree) x;
11412 const_tree const yt = (const_tree) y;
11417 if (TREE_CODE (xt) != TREE_CODE (yt))
11420 if (TREE_CODE (xt) == OPTIMIZATION_NODE)
11422 xp = (const char *)TREE_OPTIMIZATION (xt);
11423 yp = (const char *)TREE_OPTIMIZATION (yt);
11424 len = sizeof (struct cl_optimization);
11427 else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
11429 xp = (const char *)TREE_TARGET_OPTION (xt);
11430 yp = (const char *)TREE_TARGET_OPTION (yt);
11431 len = sizeof (struct cl_target_option);
11435 gcc_unreachable ();
11437 return (memcmp (xp, yp, len) == 0);
11440 /* Build an OPTIMIZATION_NODE based on the options in OPTS. */
11443 build_optimization_node (struct gcc_options *opts)
11448 /* Use the cache of optimization nodes. */
11450 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
11453 slot = htab_find_slot (cl_option_hash_table, cl_optimization_node, INSERT);
11457 /* Insert this one into the hash table. */
11458 t = cl_optimization_node;
11461 /* Make a new node for next time round. */
11462 cl_optimization_node = make_node (OPTIMIZATION_NODE);
11468 /* Build a TARGET_OPTION_NODE based on the options in OPTS. */
11471 build_target_option_node (struct gcc_options *opts)
11476 /* Use the cache of optimization nodes. */
11478 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
11481 slot = htab_find_slot (cl_option_hash_table, cl_target_option_node, INSERT);
11485 /* Insert this one into the hash table. */
11486 t = cl_target_option_node;
11489 /* Make a new node for next time round. */
11490 cl_target_option_node = make_node (TARGET_OPTION_NODE);
11496 /* Determine the "ultimate origin" of a block. The block may be an inlined
11497 instance of an inlined instance of a block which is local to an inline
11498 function, so we have to trace all of the way back through the origin chain
11499 to find out what sort of node actually served as the original seed for the
11503 block_ultimate_origin (const_tree block)
11505 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
11507 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
11508 nodes in the function to point to themselves; ignore that if
11509 we're trying to output the abstract instance of this function. */
11510 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
11513 if (immediate_origin == NULL_TREE)
11518 tree lookahead = immediate_origin;
11522 ret_val = lookahead;
11523 lookahead = (TREE_CODE (ret_val) == BLOCK
11524 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
11526 while (lookahead != NULL && lookahead != ret_val);
11528 /* The block's abstract origin chain may not be the *ultimate* origin of
11529 the block. It could lead to a DECL that has an abstract origin set.
11530 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
11531 will give us if it has one). Note that DECL's abstract origins are
11532 supposed to be the most distant ancestor (or so decl_ultimate_origin
11533 claims), so we don't need to loop following the DECL origins. */
11534 if (DECL_P (ret_val))
11535 return DECL_ORIGIN (ret_val);
11541 /* Return true iff conversion in EXP generates no instruction. Mark
11542 it inline so that we fully inline into the stripping functions even
11543 though we have two uses of this function. */
11546 tree_nop_conversion (const_tree exp)
11548 tree outer_type, inner_type;
11550 if (!CONVERT_EXPR_P (exp)
11551 && TREE_CODE (exp) != NON_LVALUE_EXPR)
11553 if (TREE_OPERAND (exp, 0) == error_mark_node)
11556 outer_type = TREE_TYPE (exp);
11557 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
11562 /* Use precision rather then machine mode when we can, which gives
11563 the correct answer even for submode (bit-field) types. */
11564 if ((INTEGRAL_TYPE_P (outer_type)
11565 || POINTER_TYPE_P (outer_type)
11566 || TREE_CODE (outer_type) == OFFSET_TYPE)
11567 && (INTEGRAL_TYPE_P (inner_type)
11568 || POINTER_TYPE_P (inner_type)
11569 || TREE_CODE (inner_type) == OFFSET_TYPE))
11570 return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
11572 /* Otherwise fall back on comparing machine modes (e.g. for
11573 aggregate types, floats). */
11574 return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
11577 /* Return true iff conversion in EXP generates no instruction. Don't
11578 consider conversions changing the signedness. */
11581 tree_sign_nop_conversion (const_tree exp)
11583 tree outer_type, inner_type;
11585 if (!tree_nop_conversion (exp))
11588 outer_type = TREE_TYPE (exp);
11589 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
11591 return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
11592 && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
11595 /* Strip conversions from EXP according to tree_nop_conversion and
11596 return the resulting expression. */
11599 tree_strip_nop_conversions (tree exp)
11601 while (tree_nop_conversion (exp))
11602 exp = TREE_OPERAND (exp, 0);
11606 /* Strip conversions from EXP according to tree_sign_nop_conversion
11607 and return the resulting expression. */
11610 tree_strip_sign_nop_conversions (tree exp)
11612 while (tree_sign_nop_conversion (exp))
11613 exp = TREE_OPERAND (exp, 0);
11617 /* Avoid any floating point extensions from EXP. */
11619 strip_float_extensions (tree exp)
11621 tree sub, expt, subt;
11623 /* For floating point constant look up the narrowest type that can hold
11624 it properly and handle it like (type)(narrowest_type)constant.
11625 This way we can optimize for instance a=a*2.0 where "a" is float
11626 but 2.0 is double constant. */
11627 if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
11629 REAL_VALUE_TYPE orig;
11632 orig = TREE_REAL_CST (exp);
11633 if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
11634 && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
11635 type = float_type_node;
11636 else if (TYPE_PRECISION (TREE_TYPE (exp))
11637 > TYPE_PRECISION (double_type_node)
11638 && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
11639 type = double_type_node;
11641 return build_real (type, real_value_truncate (TYPE_MODE (type), orig));
11644 if (!CONVERT_EXPR_P (exp))
11647 sub = TREE_OPERAND (exp, 0);
11648 subt = TREE_TYPE (sub);
11649 expt = TREE_TYPE (exp);
11651 if (!FLOAT_TYPE_P (subt))
11654 if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
11657 if (TYPE_PRECISION (subt) > TYPE_PRECISION (expt))
11660 return strip_float_extensions (sub);
11663 /* Strip out all handled components that produce invariant
11667 strip_invariant_refs (const_tree op)
11669 while (handled_component_p (op))
11671 switch (TREE_CODE (op))
11674 case ARRAY_RANGE_REF:
11675 if (!is_gimple_constant (TREE_OPERAND (op, 1))
11676 || TREE_OPERAND (op, 2) != NULL_TREE
11677 || TREE_OPERAND (op, 3) != NULL_TREE)
11681 case COMPONENT_REF:
11682 if (TREE_OPERAND (op, 2) != NULL_TREE)
11688 op = TREE_OPERAND (op, 0);
11694 static GTY(()) tree gcc_eh_personality_decl;
11696 /* Return the GCC personality function decl. */
11699 lhd_gcc_personality (void)
11701 if (!gcc_eh_personality_decl)
11702 gcc_eh_personality_decl = build_personality_function ("gcc");
11703 return gcc_eh_personality_decl;
11706 /* For languages with One Definition Rule, work out if
11707 trees are actually the same even if the tree representation
11708 differs. This handles only decls appearing in TYPE_NAME
11709 and TYPE_CONTEXT. That is NAMESPACE_DECL, TYPE_DECL,
11710 RECORD_TYPE and IDENTIFIER_NODE. */
11713 same_for_odr (tree t1, tree t2)
11719 /* C and C++ FEs differ by using IDENTIFIER_NODE and TYPE_DECL. */
11720 if (TREE_CODE (t1) == IDENTIFIER_NODE
11721 && TREE_CODE (t2) == TYPE_DECL
11722 && DECL_FILE_SCOPE_P (t1))
11724 t2 = DECL_NAME (t2);
11725 gcc_assert (TREE_CODE (t2) == IDENTIFIER_NODE);
11727 if (TREE_CODE (t2) == IDENTIFIER_NODE
11728 && TREE_CODE (t1) == TYPE_DECL
11729 && DECL_FILE_SCOPE_P (t2))
11731 t1 = DECL_NAME (t1);
11732 gcc_assert (TREE_CODE (t1) == IDENTIFIER_NODE);
11734 if (TREE_CODE (t1) != TREE_CODE (t2))
11737 return types_same_for_odr (t1, t2);
11739 return decls_same_for_odr (t1, t2);
11743 /* For languages with One Definition Rule, work out if
11744 decls are actually the same even if the tree representation
11745 differs. This handles only decls appearing in TYPE_NAME
11746 and TYPE_CONTEXT. That is NAMESPACE_DECL, TYPE_DECL,
11747 RECORD_TYPE and IDENTIFIER_NODE. */
11750 decls_same_for_odr (tree decl1, tree decl2)
11752 if (decl1 && TREE_CODE (decl1) == TYPE_DECL
11753 && DECL_ORIGINAL_TYPE (decl1))
11754 decl1 = DECL_ORIGINAL_TYPE (decl1);
11755 if (decl2 && TREE_CODE (decl2) == TYPE_DECL
11756 && DECL_ORIGINAL_TYPE (decl2))
11757 decl2 = DECL_ORIGINAL_TYPE (decl2);
11758 if (decl1 == decl2)
11760 if (!decl1 || !decl2)
11762 gcc_checking_assert (DECL_P (decl1) && DECL_P (decl2));
11763 if (TREE_CODE (decl1) != TREE_CODE (decl2))
11765 if (TREE_CODE (decl1) == TRANSLATION_UNIT_DECL)
11767 if (TREE_CODE (decl1) != NAMESPACE_DECL
11768 && TREE_CODE (decl1) != TYPE_DECL)
11770 if (!DECL_NAME (decl1))
11772 gcc_checking_assert (TREE_CODE (DECL_NAME (decl1)) == IDENTIFIER_NODE);
11773 gcc_checking_assert (!DECL_NAME (decl2)
11774 || TREE_CODE (DECL_NAME (decl2)) == IDENTIFIER_NODE);
11775 if (DECL_NAME (decl1) != DECL_NAME (decl2))
11777 return same_for_odr (DECL_CONTEXT (decl1),
11778 DECL_CONTEXT (decl2));
11781 /* For languages with One Definition Rule, work out if
11782 types are same even if the tree representation differs.
11783 This is non-trivial for LTO where minnor differences in
11784 the type representation may have prevented type merging
11785 to merge two copies of otherwise equivalent type. */
11788 types_same_for_odr (tree type1, tree type2)
11790 gcc_checking_assert (TYPE_P (type1) && TYPE_P (type2));
11791 type1 = TYPE_MAIN_VARIANT (type1);
11792 type2 = TYPE_MAIN_VARIANT (type2);
11793 if (type1 == type2)
11796 #ifndef ENABLE_CHECKING
11801 /* Check for anonymous namespaces. Those have !TREE_PUBLIC
11802 on the corresponding TYPE_STUB_DECL. */
11803 if (type_in_anonymous_namespace_p (type1)
11804 || type_in_anonymous_namespace_p (type2))
11806 /* When assembler name of virtual table is available, it is
11807 easy to compare types for equivalence. */
11808 if (TYPE_BINFO (type1) && TYPE_BINFO (type2)
11809 && BINFO_VTABLE (TYPE_BINFO (type1))
11810 && BINFO_VTABLE (TYPE_BINFO (type2)))
11812 tree v1 = BINFO_VTABLE (TYPE_BINFO (type1));
11813 tree v2 = BINFO_VTABLE (TYPE_BINFO (type2));
11815 if (TREE_CODE (v1) == POINTER_PLUS_EXPR)
11817 if (TREE_CODE (v2) != POINTER_PLUS_EXPR
11818 || !operand_equal_p (TREE_OPERAND (v1, 1),
11819 TREE_OPERAND (v2, 1), 0))
11821 v1 = TREE_OPERAND (TREE_OPERAND (v1, 0), 0);
11822 v2 = TREE_OPERAND (TREE_OPERAND (v2, 0), 0);
11824 v1 = DECL_ASSEMBLER_NAME (v1);
11825 v2 = DECL_ASSEMBLER_NAME (v2);
11829 /* FIXME: the code comparing type names consider all instantiations of the
11830 same template to have same name. This is because we have no access
11831 to template parameters. For types with no virtual method tables
11832 we thus can return false positives. At the moment we do not need
11833 to compare types in other scenarios than devirtualization. */
11835 /* If types are not structuraly same, do not bother to contnue.
11836 Match in the remainder of code would mean ODR violation. */
11837 if (!types_compatible_p (type1, type2))
11839 if (!TYPE_NAME (type1))
11841 if (!decls_same_for_odr (TYPE_NAME (type1), TYPE_NAME (type2)))
11843 if (!same_for_odr (TYPE_CONTEXT (type1), TYPE_CONTEXT (type2)))
11845 /* When not in LTO the MAIN_VARIANT check should be the same. */
11846 gcc_assert (in_lto_p);
11851 /* TARGET is a call target of GIMPLE call statement
11852 (obtained by gimple_call_fn). Return true if it is
11853 OBJ_TYPE_REF representing an virtual call of C++ method.
11854 (As opposed to OBJ_TYPE_REF representing objc calls
11855 through a cast where middle-end devirtualization machinery
11859 virtual_method_call_p (tree target)
11861 if (TREE_CODE (target) != OBJ_TYPE_REF)
11863 target = TREE_TYPE (target);
11864 gcc_checking_assert (TREE_CODE (target) == POINTER_TYPE);
11865 target = TREE_TYPE (target);
11866 if (TREE_CODE (target) == FUNCTION_TYPE)
11868 gcc_checking_assert (TREE_CODE (target) == METHOD_TYPE);
11872 /* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */
11875 obj_type_ref_class (tree ref)
11877 gcc_checking_assert (TREE_CODE (ref) == OBJ_TYPE_REF);
11878 ref = TREE_TYPE (ref);
11879 gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE);
11880 ref = TREE_TYPE (ref);
11881 /* We look for type THIS points to. ObjC also builds
11882 OBJ_TYPE_REF with non-method calls, Their first parameter
11883 ID however also corresponds to class type. */
11884 gcc_checking_assert (TREE_CODE (ref) == METHOD_TYPE
11885 || TREE_CODE (ref) == FUNCTION_TYPE);
11886 ref = TREE_VALUE (TYPE_ARG_TYPES (ref));
11887 gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE);
11888 return TREE_TYPE (ref);
11891 /* Return true if T is in anonymous namespace. */
11894 type_in_anonymous_namespace_p (tree t)
11896 return (TYPE_STUB_DECL (t) && !TREE_PUBLIC (TYPE_STUB_DECL (t)));
11899 /* Try to find a base info of BINFO that would have its field decl at offset
11900 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
11901 found, return, otherwise return NULL_TREE. */
11904 get_binfo_at_offset (tree binfo, HOST_WIDE_INT offset, tree expected_type)
11906 tree type = BINFO_TYPE (binfo);
11910 HOST_WIDE_INT pos, size;
11914 if (types_same_for_odr (type, expected_type))
11919 for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
11921 if (TREE_CODE (fld) != FIELD_DECL)
11924 pos = int_bit_position (fld);
11925 size = tree_low_cst (DECL_SIZE (fld), 1);
11926 if (pos <= offset && (pos + size) > offset)
11929 if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
11932 if (!DECL_ARTIFICIAL (fld))
11934 binfo = TYPE_BINFO (TREE_TYPE (fld));
11938 /* Offset 0 indicates the primary base, whose vtable contents are
11939 represented in the binfo for the derived class. */
11940 else if (offset != 0)
11942 tree base_binfo, found_binfo = NULL_TREE;
11943 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
11944 if (types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
11946 found_binfo = base_binfo;
11951 binfo = found_binfo;
11954 type = TREE_TYPE (fld);
11959 /* Returns true if X is a typedef decl. */
11962 is_typedef_decl (tree x)
11964 return (x && TREE_CODE (x) == TYPE_DECL
11965 && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
11968 /* Returns true iff TYPE is a type variant created for a typedef. */
11971 typedef_variant_p (tree type)
11973 return is_typedef_decl (TYPE_NAME (type));
11976 /* Warn about a use of an identifier which was marked deprecated. */
11978 warn_deprecated_use (tree node, tree attr)
11982 if (node == 0 || !warn_deprecated_decl)
11988 attr = DECL_ATTRIBUTES (node);
11989 else if (TYPE_P (node))
11991 tree decl = TYPE_STUB_DECL (node);
11993 attr = lookup_attribute ("deprecated",
11994 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
11999 attr = lookup_attribute ("deprecated", attr);
12002 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
12008 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
12010 warning (OPT_Wdeprecated_declarations,
12011 "%qD is deprecated (declared at %r%s:%d%R): %s",
12012 node, "locus", xloc.file, xloc.line, msg);
12014 warning (OPT_Wdeprecated_declarations,
12015 "%qD is deprecated (declared at %r%s:%d%R)",
12016 node, "locus", xloc.file, xloc.line);
12018 else if (TYPE_P (node))
12020 tree what = NULL_TREE;
12021 tree decl = TYPE_STUB_DECL (node);
12023 if (TYPE_NAME (node))
12025 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12026 what = TYPE_NAME (node);
12027 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12028 && DECL_NAME (TYPE_NAME (node)))
12029 what = DECL_NAME (TYPE_NAME (node));
12034 expanded_location xloc
12035 = expand_location (DECL_SOURCE_LOCATION (decl));
12039 warning (OPT_Wdeprecated_declarations,
12040 "%qE is deprecated (declared at %r%s:%d%R): %s",
12041 what, "locus", xloc.file, xloc.line, msg);
12043 warning (OPT_Wdeprecated_declarations,
12044 "%qE is deprecated (declared at %r%s:%d%R)",
12045 what, "locus", xloc.file, xloc.line);
12050 warning (OPT_Wdeprecated_declarations,
12051 "type is deprecated (declared at %r%s:%d%R): %s",
12052 "locus", xloc.file, xloc.line, msg);
12054 warning (OPT_Wdeprecated_declarations,
12055 "type is deprecated (declared at %r%s:%d%R)",
12056 "locus", xloc.file, xloc.line);
12064 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
12067 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
12072 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
12075 warning (OPT_Wdeprecated_declarations, "type is deprecated");
12081 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12082 somewhere in it. */
12085 contains_bitfld_component_ref_p (const_tree ref)
12087 while (handled_component_p (ref))
12089 if (TREE_CODE (ref) == COMPONENT_REF
12090 && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12092 ref = TREE_OPERAND (ref, 0);
12098 /* Try to determine whether a TRY_CATCH expression can fall through.
12099 This is a subroutine of block_may_fallthru. */
12102 try_catch_may_fallthru (const_tree stmt)
12104 tree_stmt_iterator i;
12106 /* If the TRY block can fall through, the whole TRY_CATCH can
12108 if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12111 i = tsi_start (TREE_OPERAND (stmt, 1));
12112 switch (TREE_CODE (tsi_stmt (i)))
12115 /* We expect to see a sequence of CATCH_EXPR trees, each with a
12116 catch expression and a body. The whole TRY_CATCH may fall
12117 through iff any of the catch bodies falls through. */
12118 for (; !tsi_end_p (i); tsi_next (&i))
12120 if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12125 case EH_FILTER_EXPR:
12126 /* The exception filter expression only matters if there is an
12127 exception. If the exception does not match EH_FILTER_TYPES,
12128 we will execute EH_FILTER_FAILURE, and we will fall through
12129 if that falls through. If the exception does match
12130 EH_FILTER_TYPES, the stack unwinder will continue up the
12131 stack, so we will not fall through. We don't know whether we
12132 will throw an exception which matches EH_FILTER_TYPES or not,
12133 so we just ignore EH_FILTER_TYPES and assume that we might
12134 throw an exception which doesn't match. */
12135 return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12138 /* This case represents statements to be executed when an
12139 exception occurs. Those statements are implicitly followed
12140 by a RESX statement to resume execution after the exception.
12141 So in this case the TRY_CATCH never falls through. */
12146 /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12147 need not be 100% accurate; simply be conservative and return true if we
12148 don't know. This is used only to avoid stupidly generating extra code.
12149 If we're wrong, we'll just delete the extra code later. */
12152 block_may_fallthru (const_tree block)
12154 /* This CONST_CAST is okay because expr_last returns its argument
12155 unmodified and we assign it to a const_tree. */
12156 const_tree stmt = expr_last (CONST_CAST_TREE (block));
12158 switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12162 /* Easy cases. If the last statement of the block implies
12163 control transfer, then we can't fall through. */
12167 /* If SWITCH_LABELS is set, this is lowered, and represents a
12168 branch to a selected label and hence can not fall through.
12169 Otherwise SWITCH_BODY is set, and the switch can fall
12171 return SWITCH_LABELS (stmt) == NULL_TREE;
12174 if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12176 return block_may_fallthru (COND_EXPR_ELSE (stmt));
12179 return block_may_fallthru (BIND_EXPR_BODY (stmt));
12181 case TRY_CATCH_EXPR:
12182 return try_catch_may_fallthru (stmt);
12184 case TRY_FINALLY_EXPR:
12185 /* The finally clause is always executed after the try clause,
12186 so if it does not fall through, then the try-finally will not
12187 fall through. Otherwise, if the try clause does not fall
12188 through, then when the finally clause falls through it will
12189 resume execution wherever the try clause was going. So the
12190 whole try-finally will only fall through if both the try
12191 clause and the finally clause fall through. */
12192 return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12193 && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12196 if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12197 stmt = TREE_OPERAND (stmt, 1);
12203 /* Functions that do not return do not fall through. */
12204 return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12206 case CLEANUP_POINT_EXPR:
12207 return block_may_fallthru (TREE_OPERAND (stmt, 0));
12210 return block_may_fallthru (TREE_OPERAND (stmt, 1));
12216 return lang_hooks.block_may_fallthru (stmt);
12220 /* True if we are using EH to handle cleanups. */
12221 static bool using_eh_for_cleanups_flag = false;
12223 /* This routine is called from front ends to indicate eh should be used for
12226 using_eh_for_cleanups (void)
12228 using_eh_for_cleanups_flag = true;
12231 /* Query whether EH is used for cleanups. */
12233 using_eh_for_cleanups_p (void)
12235 return using_eh_for_cleanups_flag;
12238 /* Wrapper for tree_code_name to ensure that tree code is valid */
12240 get_tree_code_name (enum tree_code code)
12242 const char *invalid = "<invalid tree code>";
12244 if (code >= MAX_TREE_CODES)
12247 return tree_code_name[code];
12250 /* Drops the TREE_OVERFLOW flag from T. */
12253 drop_tree_overflow (tree t)
12255 gcc_checking_assert (TREE_OVERFLOW (t));
12257 /* For tree codes with a sharing machinery re-build the result. */
12258 if (TREE_CODE (t) == INTEGER_CST)
12259 return build_int_cst_wide (TREE_TYPE (t),
12260 TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t));
12262 /* Otherwise, as all tcc_constants are possibly shared, copy the node
12263 and drop the flag. */
12265 TREE_OVERFLOW (t) = 0;
12269 #include "gt-tree.h"