1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
44 #include "filenames.h"
47 #include "langhooks.h"
48 #include "tree-inline.h"
49 #include "tree-iterator.h"
50 #include "basic-block.h"
51 #include "tree-flow.h"
53 #include "pointer-set.h"
54 #include "tree-pass.h"
55 #include "langhooks-def.h"
56 #include "diagnostic.h"
57 #include "tree-diagnostic.h"
58 #include "tree-pretty-print.h"
65 /* Tree code classes. */
67 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
68 #define END_OF_BASE_TREE_CODES tcc_exceptional,
70 const enum tree_code_class tree_code_type[] = {
71 #include "all-tree.def"
75 #undef END_OF_BASE_TREE_CODES
77 /* Table indexed by tree code giving number of expression
78 operands beyond the fixed part of the node structure.
79 Not used for types or decls. */
81 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
82 #define END_OF_BASE_TREE_CODES 0,
84 const unsigned char tree_code_length[] = {
85 #include "all-tree.def"
89 #undef END_OF_BASE_TREE_CODES
91 /* Names of tree components.
92 Used for printing out the tree and error messages. */
93 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
94 #define END_OF_BASE_TREE_CODES "@dummy",
96 const char *const tree_code_name[] = {
97 #include "all-tree.def"
101 #undef END_OF_BASE_TREE_CODES
103 /* Each tree code class has an associated string representation.
104 These must correspond to the tree_code_class entries. */
106 const char *const tree_code_class_strings[] =
121 /* obstack.[ch] explicitly declined to prototype this. */
122 extern int _obstack_allocated_p (struct obstack *h, void *obj);
124 #ifdef GATHER_STATISTICS
125 /* Statistics-gathering stuff. */
127 int tree_node_counts[(int) all_kinds];
128 int tree_node_sizes[(int) all_kinds];
130 /* Keep in sync with tree.h:enum tree_node_kind. */
131 static const char * const tree_node_kind_names[] = {
149 #endif /* GATHER_STATISTICS */
151 /* Unique id for next decl created. */
152 static GTY(()) int next_decl_uid;
153 /* Unique id for next type created. */
154 static GTY(()) int next_type_uid = 1;
155 /* Unique id for next debug decl created. Use negative numbers,
156 to catch erroneous uses. */
157 static GTY(()) int next_debug_decl_uid;
159 /* Since we cannot rehash a type after it is in the table, we have to
160 keep the hash code. */
162 struct GTY(()) type_hash {
167 /* Initial size of the hash table (rounded to next prime). */
168 #define TYPE_HASH_INITIAL_SIZE 1000
170 /* Now here is the hash table. When recording a type, it is added to
171 the slot whose index is the hash code. Note that the hash table is
172 used for several kinds of types (function types, array types and
173 array index range types, for now). While all these live in the
174 same table, they are completely independent, and the hash code is
175 computed differently for each of these. */
177 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
178 htab_t type_hash_table;
180 /* Hash table and temporary node for larger integer const values. */
181 static GTY (()) tree int_cst_node;
182 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
183 htab_t int_cst_hash_table;
185 /* Hash table for optimization flags and target option flags. Use the same
186 hash table for both sets of options. Nodes for building the current
187 optimization and target option nodes. The assumption is most of the time
188 the options created will already be in the hash table, so we avoid
189 allocating and freeing up a node repeatably. */
190 static GTY (()) tree cl_optimization_node;
191 static GTY (()) tree cl_target_option_node;
192 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
193 htab_t cl_option_hash_table;
195 /* General tree->tree mapping structure for use in hash tables. */
198 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map)))
199 htab_t debug_expr_for_decl;
201 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map)))
202 htab_t value_expr_for_decl;
204 static GTY ((if_marked ("tree_priority_map_marked_p"),
205 param_is (struct tree_priority_map)))
206 htab_t init_priority_for_decl;
208 static void set_type_quals (tree, int);
209 static int type_hash_eq (const void *, const void *);
210 static hashval_t type_hash_hash (const void *);
211 static hashval_t int_cst_hash_hash (const void *);
212 static int int_cst_hash_eq (const void *, const void *);
213 static hashval_t cl_option_hash_hash (const void *);
214 static int cl_option_hash_eq (const void *, const void *);
215 static void print_type_hash_statistics (void);
216 static void print_debug_expr_statistics (void);
217 static void print_value_expr_statistics (void);
218 static int type_hash_marked_p (const void *);
219 static unsigned int type_hash_list (const_tree, hashval_t);
220 static unsigned int attribute_hash_list (const_tree, hashval_t);
222 tree global_trees[TI_MAX];
223 tree integer_types[itk_none];
225 unsigned char tree_contains_struct[MAX_TREE_CODES][64];
227 /* Number of operands for each OpenMP clause. */
228 unsigned const char omp_clause_num_ops[] =
230 0, /* OMP_CLAUSE_ERROR */
231 1, /* OMP_CLAUSE_PRIVATE */
232 1, /* OMP_CLAUSE_SHARED */
233 1, /* OMP_CLAUSE_FIRSTPRIVATE */
234 2, /* OMP_CLAUSE_LASTPRIVATE */
235 4, /* OMP_CLAUSE_REDUCTION */
236 1, /* OMP_CLAUSE_COPYIN */
237 1, /* OMP_CLAUSE_COPYPRIVATE */
238 1, /* OMP_CLAUSE_IF */
239 1, /* OMP_CLAUSE_NUM_THREADS */
240 1, /* OMP_CLAUSE_SCHEDULE */
241 0, /* OMP_CLAUSE_NOWAIT */
242 0, /* OMP_CLAUSE_ORDERED */
243 0, /* OMP_CLAUSE_DEFAULT */
244 3, /* OMP_CLAUSE_COLLAPSE */
245 0 /* OMP_CLAUSE_UNTIED */
248 const char * const omp_clause_code_name[] =
269 /* Return the tree node structure used by tree code CODE. */
271 static inline enum tree_node_structure_enum
272 tree_node_structure_for_code (enum tree_code code)
274 switch (TREE_CODE_CLASS (code))
276 case tcc_declaration:
281 return TS_FIELD_DECL;
287 return TS_LABEL_DECL;
289 return TS_RESULT_DECL;
290 case DEBUG_EXPR_DECL:
293 return TS_CONST_DECL;
297 return TS_FUNCTION_DECL;
298 case TRANSLATION_UNIT_DECL:
299 return TS_TRANSLATION_UNIT_DECL;
301 return TS_DECL_NON_COMMON;
314 default: /* tcc_constant and tcc_exceptional */
319 /* tcc_constant cases. */
320 case INTEGER_CST: return TS_INT_CST;
321 case REAL_CST: return TS_REAL_CST;
322 case FIXED_CST: return TS_FIXED_CST;
323 case COMPLEX_CST: return TS_COMPLEX;
324 case VECTOR_CST: return TS_VECTOR;
325 case STRING_CST: return TS_STRING;
326 /* tcc_exceptional cases. */
327 case ERROR_MARK: return TS_COMMON;
328 case IDENTIFIER_NODE: return TS_IDENTIFIER;
329 case TREE_LIST: return TS_LIST;
330 case TREE_VEC: return TS_VEC;
331 case SSA_NAME: return TS_SSA_NAME;
332 case PLACEHOLDER_EXPR: return TS_COMMON;
333 case STATEMENT_LIST: return TS_STATEMENT_LIST;
334 case BLOCK: return TS_BLOCK;
335 case CONSTRUCTOR: return TS_CONSTRUCTOR;
336 case TREE_BINFO: return TS_BINFO;
337 case OMP_CLAUSE: return TS_OMP_CLAUSE;
338 case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
339 case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
347 /* Initialize tree_contains_struct to describe the hierarchy of tree
351 initialize_tree_contains_struct (void)
355 for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
358 enum tree_node_structure_enum ts_code;
360 code = (enum tree_code) i;
361 ts_code = tree_node_structure_for_code (code);
363 /* Mark the TS structure itself. */
364 tree_contains_struct[code][ts_code] = 1;
366 /* Mark all the structures that TS is derived from. */
382 MARK_TS_TYPED (code);
386 case TS_DECL_MINIMAL:
393 case TS_STATEMENT_LIST:
395 case TS_OPTIMIZATION:
396 case TS_TARGET_OPTION:
397 MARK_TS_COMMON (code);
401 MARK_TS_DECL_MINIMAL (code);
406 MARK_TS_DECL_COMMON (code);
409 case TS_DECL_NON_COMMON:
410 MARK_TS_DECL_WITH_VIS (code);
413 case TS_DECL_WITH_VIS:
417 MARK_TS_DECL_WRTL (code);
421 MARK_TS_DECL_COMMON (code);
425 MARK_TS_DECL_WITH_VIS (code);
429 case TS_FUNCTION_DECL:
430 MARK_TS_DECL_NON_COMMON (code);
433 case TS_TRANSLATION_UNIT_DECL:
434 MARK_TS_DECL_COMMON (code);
442 /* Basic consistency checks for attributes used in fold. */
443 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
444 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
445 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
446 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
447 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
448 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
449 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
450 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
451 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
452 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
453 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
454 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
455 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
456 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
457 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
458 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
459 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
460 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
461 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
462 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
463 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
464 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
465 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
466 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
467 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
468 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
469 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
470 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
471 gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
472 gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
473 gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
474 gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
475 gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
476 gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
477 gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
478 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
479 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
480 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
489 /* Initialize the hash table of types. */
490 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
493 debug_expr_for_decl = htab_create_ggc (512, tree_decl_map_hash,
494 tree_decl_map_eq, 0);
496 value_expr_for_decl = htab_create_ggc (512, tree_decl_map_hash,
497 tree_decl_map_eq, 0);
498 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
499 tree_priority_map_eq, 0);
501 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
502 int_cst_hash_eq, NULL);
504 int_cst_node = make_node (INTEGER_CST);
506 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash,
507 cl_option_hash_eq, NULL);
509 cl_optimization_node = make_node (OPTIMIZATION_NODE);
510 cl_target_option_node = make_node (TARGET_OPTION_NODE);
512 /* Initialize the tree_contains_struct array. */
513 initialize_tree_contains_struct ();
514 lang_hooks.init_ts ();
518 /* The name of the object as the assembler will see it (but before any
519 translations made by ASM_OUTPUT_LABELREF). Often this is the same
520 as DECL_NAME. It is an IDENTIFIER_NODE. */
522 decl_assembler_name (tree decl)
524 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
525 lang_hooks.set_decl_assembler_name (decl);
526 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
529 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
532 decl_assembler_name_equal (tree decl, const_tree asmname)
534 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
535 const char *decl_str;
536 const char *asmname_str;
539 if (decl_asmname == asmname)
542 decl_str = IDENTIFIER_POINTER (decl_asmname);
543 asmname_str = IDENTIFIER_POINTER (asmname);
546 /* If the target assembler name was set by the user, things are trickier.
547 We have a leading '*' to begin with. After that, it's arguable what
548 is the correct thing to do with -fleading-underscore. Arguably, we've
549 historically been doing the wrong thing in assemble_alias by always
550 printing the leading underscore. Since we're not changing that, make
551 sure user_label_prefix follows the '*' before matching. */
552 if (decl_str[0] == '*')
554 size_t ulp_len = strlen (user_label_prefix);
560 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
561 decl_str += ulp_len, test=true;
565 if (asmname_str[0] == '*')
567 size_t ulp_len = strlen (user_label_prefix);
573 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
574 asmname_str += ulp_len, test=true;
581 return strcmp (decl_str, asmname_str) == 0;
584 /* Hash asmnames ignoring the user specified marks. */
587 decl_assembler_name_hash (const_tree asmname)
589 if (IDENTIFIER_POINTER (asmname)[0] == '*')
591 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
592 size_t ulp_len = strlen (user_label_prefix);
596 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
599 return htab_hash_string (decl_str);
602 return htab_hash_string (IDENTIFIER_POINTER (asmname));
605 /* Compute the number of bytes occupied by a tree with code CODE.
606 This function cannot be used for nodes that have variable sizes,
607 including TREE_VEC, STRING_CST, and CALL_EXPR. */
609 tree_code_size (enum tree_code code)
611 switch (TREE_CODE_CLASS (code))
613 case tcc_declaration: /* A decl node */
618 return sizeof (struct tree_field_decl);
620 return sizeof (struct tree_parm_decl);
622 return sizeof (struct tree_var_decl);
624 return sizeof (struct tree_label_decl);
626 return sizeof (struct tree_result_decl);
628 return sizeof (struct tree_const_decl);
630 return sizeof (struct tree_type_decl);
632 return sizeof (struct tree_function_decl);
633 case DEBUG_EXPR_DECL:
634 return sizeof (struct tree_decl_with_rtl);
636 return sizeof (struct tree_decl_non_common);
640 case tcc_type: /* a type node */
641 return sizeof (struct tree_type);
643 case tcc_reference: /* a reference */
644 case tcc_expression: /* an expression */
645 case tcc_statement: /* an expression with side effects */
646 case tcc_comparison: /* a comparison expression */
647 case tcc_unary: /* a unary arithmetic expression */
648 case tcc_binary: /* a binary arithmetic expression */
649 return (sizeof (struct tree_exp)
650 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
652 case tcc_constant: /* a constant */
655 case INTEGER_CST: return sizeof (struct tree_int_cst);
656 case REAL_CST: return sizeof (struct tree_real_cst);
657 case FIXED_CST: return sizeof (struct tree_fixed_cst);
658 case COMPLEX_CST: return sizeof (struct tree_complex);
659 case VECTOR_CST: return sizeof (struct tree_vector);
660 case STRING_CST: gcc_unreachable ();
662 return lang_hooks.tree_size (code);
665 case tcc_exceptional: /* something random, like an identifier. */
668 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
669 case TREE_LIST: return sizeof (struct tree_list);
672 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
675 case OMP_CLAUSE: gcc_unreachable ();
677 case SSA_NAME: return sizeof (struct tree_ssa_name);
679 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
680 case BLOCK: return sizeof (struct tree_block);
681 case CONSTRUCTOR: return sizeof (struct tree_constructor);
682 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option);
683 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option);
686 return lang_hooks.tree_size (code);
694 /* Compute the number of bytes occupied by NODE. This routine only
695 looks at TREE_CODE, except for those nodes that have variable sizes. */
697 tree_size (const_tree node)
699 const enum tree_code code = TREE_CODE (node);
703 return (offsetof (struct tree_binfo, base_binfos)
704 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
707 return (sizeof (struct tree_vec)
708 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
711 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
714 return (sizeof (struct tree_omp_clause)
715 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
719 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
720 return (sizeof (struct tree_exp)
721 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
723 return tree_code_size (code);
727 /* Record interesting allocation statistics for a tree node with CODE
731 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED,
732 size_t length ATTRIBUTE_UNUSED)
734 #ifdef GATHER_STATISTICS
735 enum tree_code_class type = TREE_CODE_CLASS (code);
740 case tcc_declaration: /* A decl node */
744 case tcc_type: /* a type node */
748 case tcc_statement: /* an expression with side effects */
752 case tcc_reference: /* a reference */
756 case tcc_expression: /* an expression */
757 case tcc_comparison: /* a comparison expression */
758 case tcc_unary: /* a unary arithmetic expression */
759 case tcc_binary: /* a binary arithmetic expression */
763 case tcc_constant: /* a constant */
767 case tcc_exceptional: /* something random, like an identifier. */
770 case IDENTIFIER_NODE:
783 kind = ssa_name_kind;
795 kind = omp_clause_kind;
812 tree_node_counts[(int) kind]++;
813 tree_node_sizes[(int) kind] += length;
817 /* Return a newly allocated node of code CODE. For decl and type
818 nodes, some other fields are initialized. The rest of the node is
819 initialized to zero. This function cannot be used for TREE_VEC or
820 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
822 Achoo! I got a code in the node. */
825 make_node_stat (enum tree_code code MEM_STAT_DECL)
828 enum tree_code_class type = TREE_CODE_CLASS (code);
829 size_t length = tree_code_size (code);
831 record_node_allocation_statistics (code, length);
833 t = ggc_alloc_zone_cleared_tree_node_stat (
834 (code == IDENTIFIER_NODE) ? &tree_id_zone : &tree_zone,
835 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) = next_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_zone_tree_node_stat (&tree_zone, 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;
936 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
937 *DECL_VAR_ANN_PTR (t) = 0;
939 if (TREE_CODE_CLASS (code) == tcc_declaration)
941 if (code == DEBUG_EXPR_DECL)
942 DECL_UID (t) = --next_debug_decl_uid;
945 DECL_UID (t) = next_decl_uid++;
946 if (DECL_PT_UID_SET_P (node))
947 SET_DECL_PT_UID (t, DECL_PT_UID (node));
949 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
950 && DECL_HAS_VALUE_EXPR_P (node))
952 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
953 DECL_HAS_VALUE_EXPR_P (t) = 1;
955 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
957 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
958 DECL_HAS_INIT_PRIORITY_P (t) = 1;
961 else if (TREE_CODE_CLASS (code) == tcc_type)
963 TYPE_UID (t) = next_type_uid++;
964 /* The following is so that the debug code for
965 the copy is different from the original type.
966 The two statements usually duplicate each other
967 (because they clear fields of the same union),
968 but the optimizer should catch that. */
969 TYPE_SYMTAB_POINTER (t) = 0;
970 TYPE_SYMTAB_ADDRESS (t) = 0;
972 /* Do not copy the values cache. */
973 if (TYPE_CACHED_VALUES_P(t))
975 TYPE_CACHED_VALUES_P (t) = 0;
976 TYPE_CACHED_VALUES (t) = NULL_TREE;
983 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
984 For example, this can copy a list made of TREE_LIST nodes. */
987 copy_list (tree list)
995 head = prev = copy_node (list);
996 next = TREE_CHAIN (list);
999 TREE_CHAIN (prev) = copy_node (next);
1000 prev = TREE_CHAIN (prev);
1001 next = TREE_CHAIN (next);
1007 /* Create an INT_CST node with a LOW value sign extended. */
1010 build_int_cst (tree type, HOST_WIDE_INT low)
1012 /* Support legacy code. */
1014 type = integer_type_node;
1016 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
1019 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
1020 if it is negative. This function is similar to build_int_cst, but
1021 the extra bits outside of the type precision are cleared. Constants
1022 with these extra bits may confuse the fold so that it detects overflows
1023 even in cases when they do not occur, and in general should be avoided.
1024 We cannot however make this a default behavior of build_int_cst without
1025 more intrusive changes, since there are parts of gcc that rely on the extra
1026 precision of the integer constants. */
1029 build_int_cst_type (tree type, HOST_WIDE_INT low)
1033 return double_int_to_tree (type, shwi_to_double_int (low));
1036 /* Constructs tree in type TYPE from with value given by CST. Signedness
1037 of CST is assumed to be the same as the signedness of TYPE. */
1040 double_int_to_tree (tree type, double_int cst)
1042 /* Size types *are* sign extended. */
1043 bool sign_extended_type = (!TYPE_UNSIGNED (type)
1044 || (TREE_CODE (type) == INTEGER_TYPE
1045 && TYPE_IS_SIZETYPE (type)));
1047 cst = double_int_ext (cst, TYPE_PRECISION (type), !sign_extended_type);
1049 return build_int_cst_wide (type, cst.low, cst.high);
1052 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed
1053 to be the same as the signedness of TYPE. */
1056 double_int_fits_to_tree_p (const_tree type, double_int cst)
1058 /* Size types *are* sign extended. */
1059 bool sign_extended_type = (!TYPE_UNSIGNED (type)
1060 || (TREE_CODE (type) == INTEGER_TYPE
1061 && TYPE_IS_SIZETYPE (type)));
1064 = double_int_ext (cst, TYPE_PRECISION (type), !sign_extended_type);
1066 return double_int_equal_p (cst, ext);
1069 /* We force the double_int CST to the range of the type TYPE by sign or
1070 zero extending it. OVERFLOWABLE indicates if we are interested in
1071 overflow of the value, when >0 we are only interested in signed
1072 overflow, for <0 we are interested in any overflow. OVERFLOWED
1073 indicates whether overflow has already occurred. CONST_OVERFLOWED
1074 indicates whether constant overflow has already occurred. We force
1075 T's value to be within range of T's type (by setting to 0 or 1 all
1076 the bits outside the type's range). We set TREE_OVERFLOWED if,
1077 OVERFLOWED is nonzero,
1078 or OVERFLOWABLE is >0 and signed overflow occurs
1079 or OVERFLOWABLE is <0 and any overflow occurs
1080 We return a new tree node for the extended double_int. The node
1081 is shared if no overflow flags are set. */
1085 force_fit_type_double (tree type, double_int cst, int overflowable,
1088 bool sign_extended_type;
1090 /* Size types *are* sign extended. */
1091 sign_extended_type = (!TYPE_UNSIGNED (type)
1092 || (TREE_CODE (type) == INTEGER_TYPE
1093 && TYPE_IS_SIZETYPE (type)));
1095 /* If we need to set overflow flags, return a new unshared node. */
1096 if (overflowed || !double_int_fits_to_tree_p(type, cst))
1100 || (overflowable > 0 && sign_extended_type))
1102 tree t = make_node (INTEGER_CST);
1103 TREE_INT_CST (t) = double_int_ext (cst, TYPE_PRECISION (type),
1104 !sign_extended_type);
1105 TREE_TYPE (t) = type;
1106 TREE_OVERFLOW (t) = 1;
1111 /* Else build a shared node. */
1112 return double_int_to_tree (type, cst);
1115 /* These are the hash table functions for the hash table of INTEGER_CST
1116 nodes of a sizetype. */
1118 /* Return the hash code code X, an INTEGER_CST. */
1121 int_cst_hash_hash (const void *x)
1123 const_tree const t = (const_tree) x;
1125 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
1126 ^ htab_hash_pointer (TREE_TYPE (t)));
1129 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1130 is the same as that given by *Y, which is the same. */
1133 int_cst_hash_eq (const void *x, const void *y)
1135 const_tree const xt = (const_tree) x;
1136 const_tree const yt = (const_tree) y;
1138 return (TREE_TYPE (xt) == TREE_TYPE (yt)
1139 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
1140 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
1143 /* Create an INT_CST node of TYPE and value HI:LOW.
1144 The returned node is always shared. For small integers we use a
1145 per-type vector cache, for larger ones we use a single hash table. */
1148 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
1156 switch (TREE_CODE (type))
1159 gcc_assert (hi == 0 && low == 0);
1163 case REFERENCE_TYPE:
1164 /* Cache NULL pointer. */
1173 /* Cache false or true. */
1181 if (TYPE_UNSIGNED (type))
1184 limit = INTEGER_SHARE_LIMIT;
1185 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1191 limit = INTEGER_SHARE_LIMIT + 1;
1192 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1194 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
1208 /* Look for it in the type's vector of small shared ints. */
1209 if (!TYPE_CACHED_VALUES_P (type))
1211 TYPE_CACHED_VALUES_P (type) = 1;
1212 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
1215 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
1218 /* Make sure no one is clobbering the shared constant. */
1219 gcc_assert (TREE_TYPE (t) == type);
1220 gcc_assert (TREE_INT_CST_LOW (t) == low);
1221 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
1225 /* Create a new shared int. */
1226 t = make_node (INTEGER_CST);
1228 TREE_INT_CST_LOW (t) = low;
1229 TREE_INT_CST_HIGH (t) = hi;
1230 TREE_TYPE (t) = type;
1232 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
1237 /* Use the cache of larger shared ints. */
1240 TREE_INT_CST_LOW (int_cst_node) = low;
1241 TREE_INT_CST_HIGH (int_cst_node) = hi;
1242 TREE_TYPE (int_cst_node) = type;
1244 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
1248 /* Insert this one into the hash table. */
1251 /* Make a new node for next time round. */
1252 int_cst_node = make_node (INTEGER_CST);
1259 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1260 and the rest are zeros. */
1263 build_low_bits_mask (tree type, unsigned bits)
1267 gcc_assert (bits <= TYPE_PRECISION (type));
1269 if (bits == TYPE_PRECISION (type)
1270 && !TYPE_UNSIGNED (type))
1271 /* Sign extended all-ones mask. */
1272 mask = double_int_minus_one;
1274 mask = double_int_mask (bits);
1276 return build_int_cst_wide (type, mask.low, mask.high);
1279 /* Checks that X is integer constant that can be expressed in (unsigned)
1280 HOST_WIDE_INT without loss of precision. */
1283 cst_and_fits_in_hwi (const_tree x)
1285 if (TREE_CODE (x) != INTEGER_CST)
1288 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
1291 return (TREE_INT_CST_HIGH (x) == 0
1292 || TREE_INT_CST_HIGH (x) == -1);
1295 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1296 are in a list pointed to by VALS. */
1299 build_vector (tree type, tree vals)
1301 tree v = make_node (VECTOR_CST);
1306 TREE_VECTOR_CST_ELTS (v) = vals;
1307 TREE_TYPE (v) = type;
1309 /* Iterate through elements and check for overflow. */
1310 for (link = vals; link; link = TREE_CHAIN (link))
1312 tree value = TREE_VALUE (link);
1315 /* Don't crash if we get an address constant. */
1316 if (!CONSTANT_CLASS_P (value))
1319 over |= TREE_OVERFLOW (value);
1322 gcc_assert (cnt == TYPE_VECTOR_SUBPARTS (type));
1324 TREE_OVERFLOW (v) = over;
1328 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1329 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1332 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
1334 tree list = NULL_TREE;
1335 unsigned HOST_WIDE_INT idx;
1338 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1339 list = tree_cons (NULL_TREE, value, list);
1340 for (; idx < TYPE_VECTOR_SUBPARTS (type); ++idx)
1341 list = tree_cons (NULL_TREE,
1342 build_zero_cst (TREE_TYPE (type)), list);
1343 return build_vector (type, nreverse (list));
1346 /* Build a vector of type VECTYPE where all the elements are SCs. */
1348 build_vector_from_val (tree vectype, tree sc)
1350 int i, nunits = TYPE_VECTOR_SUBPARTS (vectype);
1351 VEC(constructor_elt, gc) *v = NULL;
1353 if (sc == error_mark_node)
1356 /* Verify that the vector type is suitable for SC. Note that there
1357 is some inconsistency in the type-system with respect to restrict
1358 qualifications of pointers. Vector types always have a main-variant
1359 element type and the qualification is applied to the vector-type.
1360 So TREE_TYPE (vector-type) does not return a properly qualified
1361 vector element-type. */
1362 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
1363 TREE_TYPE (vectype)));
1365 v = VEC_alloc (constructor_elt, gc, nunits);
1366 for (i = 0; i < nunits; ++i)
1367 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
1369 if (CONSTANT_CLASS_P (sc))
1370 return build_vector_from_ctor (vectype, v);
1372 return build_constructor (vectype, v);
1375 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1376 are in the VEC pointed to by VALS. */
1378 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
1380 tree c = make_node (CONSTRUCTOR);
1382 constructor_elt *elt;
1383 bool constant_p = true;
1385 TREE_TYPE (c) = type;
1386 CONSTRUCTOR_ELTS (c) = vals;
1388 FOR_EACH_VEC_ELT (constructor_elt, vals, i, elt)
1389 if (!TREE_CONSTANT (elt->value))
1395 TREE_CONSTANT (c) = constant_p;
1400 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1403 build_constructor_single (tree type, tree index, tree value)
1405 VEC(constructor_elt,gc) *v;
1406 constructor_elt *elt;
1408 v = VEC_alloc (constructor_elt, gc, 1);
1409 elt = VEC_quick_push (constructor_elt, v, NULL);
1413 return build_constructor (type, v);
1417 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1418 are in a list pointed to by VALS. */
1420 build_constructor_from_list (tree type, tree vals)
1423 VEC(constructor_elt,gc) *v = NULL;
1427 v = VEC_alloc (constructor_elt, gc, list_length (vals));
1428 for (t = vals; t; t = TREE_CHAIN (t))
1429 CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
1432 return build_constructor (type, v);
1435 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1438 build_fixed (tree type, FIXED_VALUE_TYPE f)
1441 FIXED_VALUE_TYPE *fp;
1443 v = make_node (FIXED_CST);
1444 fp = ggc_alloc_fixed_value ();
1445 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1447 TREE_TYPE (v) = type;
1448 TREE_FIXED_CST_PTR (v) = fp;
1452 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1455 build_real (tree type, REAL_VALUE_TYPE d)
1458 REAL_VALUE_TYPE *dp;
1461 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1462 Consider doing it via real_convert now. */
1464 v = make_node (REAL_CST);
1465 dp = ggc_alloc_real_value ();
1466 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1468 TREE_TYPE (v) = type;
1469 TREE_REAL_CST_PTR (v) = dp;
1470 TREE_OVERFLOW (v) = overflow;
1474 /* Return a new REAL_CST node whose type is TYPE
1475 and whose value is the integer value of the INTEGER_CST node I. */
1478 real_value_from_int_cst (const_tree type, const_tree i)
1482 /* Clear all bits of the real value type so that we can later do
1483 bitwise comparisons to see if two values are the same. */
1484 memset (&d, 0, sizeof d);
1486 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1487 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1488 TYPE_UNSIGNED (TREE_TYPE (i)));
1492 /* Given a tree representing an integer constant I, return a tree
1493 representing the same value as a floating-point constant of type TYPE. */
1496 build_real_from_int_cst (tree type, const_tree i)
1499 int overflow = TREE_OVERFLOW (i);
1501 v = build_real (type, real_value_from_int_cst (type, i));
1503 TREE_OVERFLOW (v) |= overflow;
1507 /* Return a newly constructed STRING_CST node whose value is
1508 the LEN characters at STR.
1509 The TREE_TYPE is not initialized. */
1512 build_string (int len, const char *str)
1517 /* Do not waste bytes provided by padding of struct tree_string. */
1518 length = len + offsetof (struct tree_string, str) + 1;
1520 record_node_allocation_statistics (STRING_CST, length);
1522 s = ggc_alloc_tree_node (length);
1524 memset (s, 0, sizeof (struct tree_common));
1525 TREE_SET_CODE (s, STRING_CST);
1526 TREE_CONSTANT (s) = 1;
1527 TREE_STRING_LENGTH (s) = len;
1528 memcpy (s->string.str, str, len);
1529 s->string.str[len] = '\0';
1534 /* Return a newly constructed COMPLEX_CST node whose value is
1535 specified by the real and imaginary parts REAL and IMAG.
1536 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1537 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1540 build_complex (tree type, tree real, tree imag)
1542 tree t = make_node (COMPLEX_CST);
1544 TREE_REALPART (t) = real;
1545 TREE_IMAGPART (t) = imag;
1546 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1547 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1551 /* Return a constant of arithmetic type TYPE which is the
1552 multiplicative identity of the set TYPE. */
1555 build_one_cst (tree type)
1557 switch (TREE_CODE (type))
1559 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1560 case POINTER_TYPE: case REFERENCE_TYPE:
1562 return build_int_cst (type, 1);
1565 return build_real (type, dconst1);
1567 case FIXED_POINT_TYPE:
1568 /* We can only generate 1 for accum types. */
1569 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1570 return build_fixed (type, FCONST1(TYPE_MODE (type)));
1574 tree scalar = build_one_cst (TREE_TYPE (type));
1576 return build_vector_from_val (type, scalar);
1580 return build_complex (type,
1581 build_one_cst (TREE_TYPE (type)),
1582 build_zero_cst (TREE_TYPE (type)));
1589 /* Build 0 constant of type TYPE. This is used by constructor folding
1590 and thus the constant should be represented in memory by
1594 build_zero_cst (tree type)
1596 switch (TREE_CODE (type))
1598 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1599 case POINTER_TYPE: case REFERENCE_TYPE:
1601 return build_int_cst (type, 0);
1604 return build_real (type, dconst0);
1606 case FIXED_POINT_TYPE:
1607 return build_fixed (type, FCONST0 (TYPE_MODE (type)));
1611 tree scalar = build_zero_cst (TREE_TYPE (type));
1613 return build_vector_from_val (type, scalar);
1618 tree zero = build_zero_cst (TREE_TYPE (type));
1620 return build_complex (type, zero, zero);
1624 if (!AGGREGATE_TYPE_P (type))
1625 return fold_convert (type, integer_zero_node);
1626 return build_constructor (type, NULL);
1631 /* Build a BINFO with LEN language slots. */
1634 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1637 size_t length = (offsetof (struct tree_binfo, base_binfos)
1638 + VEC_embedded_size (tree, base_binfos));
1640 record_node_allocation_statistics (TREE_BINFO, length);
1642 t = ggc_alloc_zone_tree_node_stat (&tree_zone, length PASS_MEM_STAT);
1644 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1646 TREE_SET_CODE (t, TREE_BINFO);
1648 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1654 /* Build a newly constructed TREE_VEC node of length LEN. */
1657 make_tree_vec_stat (int len MEM_STAT_DECL)
1660 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1662 record_node_allocation_statistics (TREE_VEC, length);
1664 t = ggc_alloc_zone_cleared_tree_node_stat (&tree_zone, length PASS_MEM_STAT);
1666 TREE_SET_CODE (t, TREE_VEC);
1667 TREE_VEC_LENGTH (t) = len;
1672 /* Return 1 if EXPR is the integer constant zero or a complex constant
1676 integer_zerop (const_tree expr)
1680 return ((TREE_CODE (expr) == INTEGER_CST
1681 && TREE_INT_CST_LOW (expr) == 0
1682 && TREE_INT_CST_HIGH (expr) == 0)
1683 || (TREE_CODE (expr) == COMPLEX_CST
1684 && integer_zerop (TREE_REALPART (expr))
1685 && integer_zerop (TREE_IMAGPART (expr))));
1688 /* Return 1 if EXPR is the integer constant one or the corresponding
1689 complex constant. */
1692 integer_onep (const_tree expr)
1696 return ((TREE_CODE (expr) == INTEGER_CST
1697 && TREE_INT_CST_LOW (expr) == 1
1698 && TREE_INT_CST_HIGH (expr) == 0)
1699 || (TREE_CODE (expr) == COMPLEX_CST
1700 && integer_onep (TREE_REALPART (expr))
1701 && integer_zerop (TREE_IMAGPART (expr))));
1704 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1705 it contains. Likewise for the corresponding complex constant. */
1708 integer_all_onesp (const_tree expr)
1715 if (TREE_CODE (expr) == COMPLEX_CST
1716 && integer_all_onesp (TREE_REALPART (expr))
1717 && integer_zerop (TREE_IMAGPART (expr)))
1720 else if (TREE_CODE (expr) != INTEGER_CST)
1723 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1724 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1725 && TREE_INT_CST_HIGH (expr) == -1)
1730 /* Note that using TYPE_PRECISION here is wrong. We care about the
1731 actual bits, not the (arbitrary) range of the type. */
1732 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1733 if (prec >= HOST_BITS_PER_WIDE_INT)
1735 HOST_WIDE_INT high_value;
1738 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1740 /* Can not handle precisions greater than twice the host int size. */
1741 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1742 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1743 /* Shifting by the host word size is undefined according to the ANSI
1744 standard, so we must handle this as a special case. */
1747 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1749 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1750 && TREE_INT_CST_HIGH (expr) == high_value);
1753 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1756 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1760 integer_pow2p (const_tree expr)
1763 HOST_WIDE_INT high, low;
1767 if (TREE_CODE (expr) == COMPLEX_CST
1768 && integer_pow2p (TREE_REALPART (expr))
1769 && integer_zerop (TREE_IMAGPART (expr)))
1772 if (TREE_CODE (expr) != INTEGER_CST)
1775 prec = TYPE_PRECISION (TREE_TYPE (expr));
1776 high = TREE_INT_CST_HIGH (expr);
1777 low = TREE_INT_CST_LOW (expr);
1779 /* First clear all bits that are beyond the type's precision in case
1780 we've been sign extended. */
1782 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1784 else if (prec > HOST_BITS_PER_WIDE_INT)
1785 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1789 if (prec < HOST_BITS_PER_WIDE_INT)
1790 low &= ~((HOST_WIDE_INT) (-1) << prec);
1793 if (high == 0 && low == 0)
1796 return ((high == 0 && (low & (low - 1)) == 0)
1797 || (low == 0 && (high & (high - 1)) == 0));
1800 /* Return 1 if EXPR is an integer constant other than zero or a
1801 complex constant other than zero. */
1804 integer_nonzerop (const_tree expr)
1808 return ((TREE_CODE (expr) == INTEGER_CST
1809 && (TREE_INT_CST_LOW (expr) != 0
1810 || TREE_INT_CST_HIGH (expr) != 0))
1811 || (TREE_CODE (expr) == COMPLEX_CST
1812 && (integer_nonzerop (TREE_REALPART (expr))
1813 || integer_nonzerop (TREE_IMAGPART (expr)))));
1816 /* Return 1 if EXPR is the fixed-point constant zero. */
1819 fixed_zerop (const_tree expr)
1821 return (TREE_CODE (expr) == FIXED_CST
1822 && double_int_zero_p (TREE_FIXED_CST (expr).data));
1825 /* Return the power of two represented by a tree node known to be a
1829 tree_log2 (const_tree expr)
1832 HOST_WIDE_INT high, low;
1836 if (TREE_CODE (expr) == COMPLEX_CST)
1837 return tree_log2 (TREE_REALPART (expr));
1839 prec = TYPE_PRECISION (TREE_TYPE (expr));
1840 high = TREE_INT_CST_HIGH (expr);
1841 low = TREE_INT_CST_LOW (expr);
1843 /* First clear all bits that are beyond the type's precision in case
1844 we've been sign extended. */
1846 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1848 else if (prec > HOST_BITS_PER_WIDE_INT)
1849 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1853 if (prec < HOST_BITS_PER_WIDE_INT)
1854 low &= ~((HOST_WIDE_INT) (-1) << prec);
1857 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1858 : exact_log2 (low));
1861 /* Similar, but return the largest integer Y such that 2 ** Y is less
1862 than or equal to EXPR. */
1865 tree_floor_log2 (const_tree expr)
1868 HOST_WIDE_INT high, low;
1872 if (TREE_CODE (expr) == COMPLEX_CST)
1873 return tree_log2 (TREE_REALPART (expr));
1875 prec = TYPE_PRECISION (TREE_TYPE (expr));
1876 high = TREE_INT_CST_HIGH (expr);
1877 low = TREE_INT_CST_LOW (expr);
1879 /* First clear all bits that are beyond the type's precision in case
1880 we've been sign extended. Ignore if type's precision hasn't been set
1881 since what we are doing is setting it. */
1883 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1885 else if (prec > HOST_BITS_PER_WIDE_INT)
1886 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1890 if (prec < HOST_BITS_PER_WIDE_INT)
1891 low &= ~((HOST_WIDE_INT) (-1) << prec);
1894 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1895 : floor_log2 (low));
1898 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
1899 decimal float constants, so don't return 1 for them. */
1902 real_zerop (const_tree expr)
1906 return ((TREE_CODE (expr) == REAL_CST
1907 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)
1908 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1909 || (TREE_CODE (expr) == COMPLEX_CST
1910 && real_zerop (TREE_REALPART (expr))
1911 && real_zerop (TREE_IMAGPART (expr))));
1914 /* Return 1 if EXPR is the real constant one in real or complex form.
1915 Trailing zeroes matter for decimal float constants, so don't return
1919 real_onep (const_tree expr)
1923 return ((TREE_CODE (expr) == REAL_CST
1924 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)
1925 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1926 || (TREE_CODE (expr) == COMPLEX_CST
1927 && real_onep (TREE_REALPART (expr))
1928 && real_zerop (TREE_IMAGPART (expr))));
1931 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
1932 for decimal float constants, so don't return 1 for them. */
1935 real_twop (const_tree expr)
1939 return ((TREE_CODE (expr) == REAL_CST
1940 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2)
1941 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1942 || (TREE_CODE (expr) == COMPLEX_CST
1943 && real_twop (TREE_REALPART (expr))
1944 && real_zerop (TREE_IMAGPART (expr))));
1947 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
1948 matter for decimal float constants, so don't return 1 for them. */
1951 real_minus_onep (const_tree expr)
1955 return ((TREE_CODE (expr) == REAL_CST
1956 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1)
1957 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1958 || (TREE_CODE (expr) == COMPLEX_CST
1959 && real_minus_onep (TREE_REALPART (expr))
1960 && real_zerop (TREE_IMAGPART (expr))));
1963 /* Nonzero if EXP is a constant or a cast of a constant. */
1966 really_constant_p (const_tree exp)
1968 /* This is not quite the same as STRIP_NOPS. It does more. */
1969 while (CONVERT_EXPR_P (exp)
1970 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1971 exp = TREE_OPERAND (exp, 0);
1972 return TREE_CONSTANT (exp);
1975 /* Return first list element whose TREE_VALUE is ELEM.
1976 Return 0 if ELEM is not in LIST. */
1979 value_member (tree elem, tree list)
1983 if (elem == TREE_VALUE (list))
1985 list = TREE_CHAIN (list);
1990 /* Return first list element whose TREE_PURPOSE is ELEM.
1991 Return 0 if ELEM is not in LIST. */
1994 purpose_member (const_tree elem, tree list)
1998 if (elem == TREE_PURPOSE (list))
2000 list = TREE_CHAIN (list);
2005 /* Return true if ELEM is in V. */
2008 vec_member (const_tree elem, VEC(tree,gc) *v)
2012 FOR_EACH_VEC_ELT (tree, v, ix, t)
2018 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2022 chain_index (int idx, tree chain)
2024 for (; chain && idx > 0; --idx)
2025 chain = TREE_CHAIN (chain);
2029 /* Return nonzero if ELEM is part of the chain CHAIN. */
2032 chain_member (const_tree elem, const_tree chain)
2038 chain = DECL_CHAIN (chain);
2044 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2045 We expect a null pointer to mark the end of the chain.
2046 This is the Lisp primitive `length'. */
2049 list_length (const_tree t)
2052 #ifdef ENABLE_TREE_CHECKING
2060 #ifdef ENABLE_TREE_CHECKING
2063 gcc_assert (p != q);
2071 /* Returns the number of FIELD_DECLs in TYPE. */
2074 fields_length (const_tree type)
2076 tree t = TYPE_FIELDS (type);
2079 for (; t; t = DECL_CHAIN (t))
2080 if (TREE_CODE (t) == FIELD_DECL)
2086 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2087 UNION_TYPE TYPE, or NULL_TREE if none. */
2090 first_field (const_tree type)
2092 tree t = TYPE_FIELDS (type);
2093 while (t && TREE_CODE (t) != FIELD_DECL)
2098 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2099 by modifying the last node in chain 1 to point to chain 2.
2100 This is the Lisp primitive `nconc'. */
2103 chainon (tree op1, tree op2)
2112 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
2114 TREE_CHAIN (t1) = op2;
2116 #ifdef ENABLE_TREE_CHECKING
2119 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
2120 gcc_assert (t2 != t1);
2127 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2130 tree_last (tree chain)
2134 while ((next = TREE_CHAIN (chain)))
2139 /* Reverse the order of elements in the chain T,
2140 and return the new head of the chain (old last element). */
2145 tree prev = 0, decl, next;
2146 for (decl = t; decl; decl = next)
2148 /* We shouldn't be using this function to reverse BLOCK chains; we
2149 have blocks_nreverse for that. */
2150 gcc_checking_assert (TREE_CODE (decl) != BLOCK);
2151 next = TREE_CHAIN (decl);
2152 TREE_CHAIN (decl) = prev;
2158 /* Return a newly created TREE_LIST node whose
2159 purpose and value fields are PARM and VALUE. */
2162 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
2164 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
2165 TREE_PURPOSE (t) = parm;
2166 TREE_VALUE (t) = value;
2170 /* Build a chain of TREE_LIST nodes from a vector. */
2173 build_tree_list_vec_stat (const VEC(tree,gc) *vec MEM_STAT_DECL)
2175 tree ret = NULL_TREE;
2179 FOR_EACH_VEC_ELT (tree, vec, i, t)
2181 *pp = build_tree_list_stat (NULL, t PASS_MEM_STAT);
2182 pp = &TREE_CHAIN (*pp);
2187 /* Return a newly created TREE_LIST node whose
2188 purpose and value fields are PURPOSE and VALUE
2189 and whose TREE_CHAIN is CHAIN. */
2192 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
2196 node = ggc_alloc_zone_tree_node_stat (&tree_zone, sizeof (struct tree_list)
2198 memset (node, 0, sizeof (struct tree_common));
2200 record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
2202 TREE_SET_CODE (node, TREE_LIST);
2203 TREE_CHAIN (node) = chain;
2204 TREE_PURPOSE (node) = purpose;
2205 TREE_VALUE (node) = value;
2209 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2213 ctor_to_vec (tree ctor)
2215 VEC(tree, gc) *vec = VEC_alloc (tree, gc, CONSTRUCTOR_NELTS (ctor));
2219 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
2220 VEC_quick_push (tree, vec, val);
2225 /* Return the size nominally occupied by an object of type TYPE
2226 when it resides in memory. The value is measured in units of bytes,
2227 and its data type is that normally used for type sizes
2228 (which is the first type created by make_signed_type or
2229 make_unsigned_type). */
2232 size_in_bytes (const_tree type)
2236 if (type == error_mark_node)
2237 return integer_zero_node;
2239 type = TYPE_MAIN_VARIANT (type);
2240 t = TYPE_SIZE_UNIT (type);
2244 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
2245 return size_zero_node;
2251 /* Return the size of TYPE (in bytes) as a wide integer
2252 or return -1 if the size can vary or is larger than an integer. */
2255 int_size_in_bytes (const_tree type)
2259 if (type == error_mark_node)
2262 type = TYPE_MAIN_VARIANT (type);
2263 t = TYPE_SIZE_UNIT (type);
2265 || TREE_CODE (t) != INTEGER_CST
2266 || TREE_INT_CST_HIGH (t) != 0
2267 /* If the result would appear negative, it's too big to represent. */
2268 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
2271 return TREE_INT_CST_LOW (t);
2274 /* Return the maximum size of TYPE (in bytes) as a wide integer
2275 or return -1 if the size can vary or is larger than an integer. */
2278 max_int_size_in_bytes (const_tree type)
2280 HOST_WIDE_INT size = -1;
2283 /* If this is an array type, check for a possible MAX_SIZE attached. */
2285 if (TREE_CODE (type) == ARRAY_TYPE)
2287 size_tree = TYPE_ARRAY_MAX_SIZE (type);
2289 if (size_tree && host_integerp (size_tree, 1))
2290 size = tree_low_cst (size_tree, 1);
2293 /* If we still haven't been able to get a size, see if the language
2294 can compute a maximum size. */
2298 size_tree = lang_hooks.types.max_size (type);
2300 if (size_tree && host_integerp (size_tree, 1))
2301 size = tree_low_cst (size_tree, 1);
2307 /* Returns a tree for the size of EXP in bytes. */
2310 tree_expr_size (const_tree exp)
2313 && DECL_SIZE_UNIT (exp) != 0)
2314 return DECL_SIZE_UNIT (exp);
2316 return size_in_bytes (TREE_TYPE (exp));
2319 /* Return the bit position of FIELD, in bits from the start of the record.
2320 This is a tree of type bitsizetype. */
2323 bit_position (const_tree field)
2325 return bit_from_pos (DECL_FIELD_OFFSET (field),
2326 DECL_FIELD_BIT_OFFSET (field));
2329 /* Likewise, but return as an integer. It must be representable in
2330 that way (since it could be a signed value, we don't have the
2331 option of returning -1 like int_size_in_byte can. */
2334 int_bit_position (const_tree field)
2336 return tree_low_cst (bit_position (field), 0);
2339 /* Return the byte position of FIELD, in bytes from the start of the record.
2340 This is a tree of type sizetype. */
2343 byte_position (const_tree field)
2345 return byte_from_pos (DECL_FIELD_OFFSET (field),
2346 DECL_FIELD_BIT_OFFSET (field));
2349 /* Likewise, but return as an integer. It must be representable in
2350 that way (since it could be a signed value, we don't have the
2351 option of returning -1 like int_size_in_byte can. */
2354 int_byte_position (const_tree field)
2356 return tree_low_cst (byte_position (field), 0);
2359 /* Return the strictest alignment, in bits, that T is known to have. */
2362 expr_align (const_tree t)
2364 unsigned int align0, align1;
2366 switch (TREE_CODE (t))
2368 CASE_CONVERT: case NON_LVALUE_EXPR:
2369 /* If we have conversions, we know that the alignment of the
2370 object must meet each of the alignments of the types. */
2371 align0 = expr_align (TREE_OPERAND (t, 0));
2372 align1 = TYPE_ALIGN (TREE_TYPE (t));
2373 return MAX (align0, align1);
2375 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2376 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2377 case CLEANUP_POINT_EXPR:
2378 /* These don't change the alignment of an object. */
2379 return expr_align (TREE_OPERAND (t, 0));
2382 /* The best we can do is say that the alignment is the least aligned
2384 align0 = expr_align (TREE_OPERAND (t, 1));
2385 align1 = expr_align (TREE_OPERAND (t, 2));
2386 return MIN (align0, align1);
2388 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2389 meaningfully, it's always 1. */
2390 case LABEL_DECL: case CONST_DECL:
2391 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2393 gcc_assert (DECL_ALIGN (t) != 0);
2394 return DECL_ALIGN (t);
2400 /* Otherwise take the alignment from that of the type. */
2401 return TYPE_ALIGN (TREE_TYPE (t));
2404 /* Return, as a tree node, the number of elements for TYPE (which is an
2405 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2408 array_type_nelts (const_tree type)
2410 tree index_type, min, max;
2412 /* If they did it with unspecified bounds, then we should have already
2413 given an error about it before we got here. */
2414 if (! TYPE_DOMAIN (type))
2415 return error_mark_node;
2417 index_type = TYPE_DOMAIN (type);
2418 min = TYPE_MIN_VALUE (index_type);
2419 max = TYPE_MAX_VALUE (index_type);
2421 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
2423 return error_mark_node;
2425 return (integer_zerop (min)
2427 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
2430 /* If arg is static -- a reference to an object in static storage -- then
2431 return the object. This is not the same as the C meaning of `static'.
2432 If arg isn't static, return NULL. */
2437 switch (TREE_CODE (arg))
2440 /* Nested functions are static, even though taking their address will
2441 involve a trampoline as we unnest the nested function and create
2442 the trampoline on the tree level. */
2446 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2447 && ! DECL_THREAD_LOCAL_P (arg)
2448 && ! DECL_DLLIMPORT_P (arg)
2452 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2456 return TREE_STATIC (arg) ? arg : NULL;
2463 /* If the thing being referenced is not a field, then it is
2464 something language specific. */
2465 gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
2467 /* If we are referencing a bitfield, we can't evaluate an
2468 ADDR_EXPR at compile time and so it isn't a constant. */
2469 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2472 return staticp (TREE_OPERAND (arg, 0));
2478 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2481 case ARRAY_RANGE_REF:
2482 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2483 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2484 return staticp (TREE_OPERAND (arg, 0));
2488 case COMPOUND_LITERAL_EXPR:
2489 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
2499 /* Return whether OP is a DECL whose address is function-invariant. */
2502 decl_address_invariant_p (const_tree op)
2504 /* The conditions below are slightly less strict than the one in
2507 switch (TREE_CODE (op))
2516 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2517 || DECL_THREAD_LOCAL_P (op)
2518 || DECL_CONTEXT (op) == current_function_decl
2519 || decl_function_context (op) == current_function_decl)
2524 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2525 || decl_function_context (op) == current_function_decl)
2536 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2539 decl_address_ip_invariant_p (const_tree op)
2541 /* The conditions below are slightly less strict than the one in
2544 switch (TREE_CODE (op))
2552 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2553 && !DECL_DLLIMPORT_P (op))
2554 || DECL_THREAD_LOCAL_P (op))
2559 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
2571 /* Return true if T is function-invariant (internal function, does
2572 not handle arithmetic; that's handled in skip_simple_arithmetic and
2573 tree_invariant_p). */
2575 static bool tree_invariant_p (tree t);
2578 tree_invariant_p_1 (tree t)
2582 if (TREE_CONSTANT (t)
2583 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2586 switch (TREE_CODE (t))
2592 op = TREE_OPERAND (t, 0);
2593 while (handled_component_p (op))
2595 switch (TREE_CODE (op))
2598 case ARRAY_RANGE_REF:
2599 if (!tree_invariant_p (TREE_OPERAND (op, 1))
2600 || TREE_OPERAND (op, 2) != NULL_TREE
2601 || TREE_OPERAND (op, 3) != NULL_TREE)
2606 if (TREE_OPERAND (op, 2) != NULL_TREE)
2612 op = TREE_OPERAND (op, 0);
2615 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2624 /* Return true if T is function-invariant. */
2627 tree_invariant_p (tree t)
2629 tree inner = skip_simple_arithmetic (t);
2630 return tree_invariant_p_1 (inner);
2633 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2634 Do this to any expression which may be used in more than one place,
2635 but must be evaluated only once.
2637 Normally, expand_expr would reevaluate the expression each time.
2638 Calling save_expr produces something that is evaluated and recorded
2639 the first time expand_expr is called on it. Subsequent calls to
2640 expand_expr just reuse the recorded value.
2642 The call to expand_expr that generates code that actually computes
2643 the value is the first call *at compile time*. Subsequent calls
2644 *at compile time* generate code to use the saved value.
2645 This produces correct result provided that *at run time* control
2646 always flows through the insns made by the first expand_expr
2647 before reaching the other places where the save_expr was evaluated.
2648 You, the caller of save_expr, must make sure this is so.
2650 Constants, and certain read-only nodes, are returned with no
2651 SAVE_EXPR because that is safe. Expressions containing placeholders
2652 are not touched; see tree.def for an explanation of what these
2656 save_expr (tree expr)
2658 tree t = fold (expr);
2661 /* If the tree evaluates to a constant, then we don't want to hide that
2662 fact (i.e. this allows further folding, and direct checks for constants).
2663 However, a read-only object that has side effects cannot be bypassed.
2664 Since it is no problem to reevaluate literals, we just return the
2666 inner = skip_simple_arithmetic (t);
2667 if (TREE_CODE (inner) == ERROR_MARK)
2670 if (tree_invariant_p_1 (inner))
2673 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2674 it means that the size or offset of some field of an object depends on
2675 the value within another field.
2677 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2678 and some variable since it would then need to be both evaluated once and
2679 evaluated more than once. Front-ends must assure this case cannot
2680 happen by surrounding any such subexpressions in their own SAVE_EXPR
2681 and forcing evaluation at the proper time. */
2682 if (contains_placeholder_p (inner))
2685 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
2686 SET_EXPR_LOCATION (t, EXPR_LOCATION (expr));
2688 /* This expression might be placed ahead of a jump to ensure that the
2689 value was computed on both sides of the jump. So make sure it isn't
2690 eliminated as dead. */
2691 TREE_SIDE_EFFECTS (t) = 1;
2695 /* Look inside EXPR and into any simple arithmetic operations. Return
2696 the innermost non-arithmetic node. */
2699 skip_simple_arithmetic (tree expr)
2703 /* We don't care about whether this can be used as an lvalue in this
2705 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
2706 expr = TREE_OPERAND (expr, 0);
2708 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2709 a constant, it will be more efficient to not make another SAVE_EXPR since
2710 it will allow better simplification and GCSE will be able to merge the
2711 computations if they actually occur. */
2715 if (UNARY_CLASS_P (inner))
2716 inner = TREE_OPERAND (inner, 0);
2717 else if (BINARY_CLASS_P (inner))
2719 if (tree_invariant_p (TREE_OPERAND (inner, 1)))
2720 inner = TREE_OPERAND (inner, 0);
2721 else if (tree_invariant_p (TREE_OPERAND (inner, 0)))
2722 inner = TREE_OPERAND (inner, 1);
2734 /* Return which tree structure is used by T. */
2736 enum tree_node_structure_enum
2737 tree_node_structure (const_tree t)
2739 const enum tree_code code = TREE_CODE (t);
2740 return tree_node_structure_for_code (code);
2743 /* Set various status flags when building a CALL_EXPR object T. */
2746 process_call_operands (tree t)
2748 bool side_effects = TREE_SIDE_EFFECTS (t);
2749 bool read_only = false;
2750 int i = call_expr_flags (t);
2752 /* Calls have side-effects, except those to const or pure functions. */
2753 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
2754 side_effects = true;
2755 /* Propagate TREE_READONLY of arguments for const functions. */
2759 if (!side_effects || read_only)
2760 for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
2762 tree op = TREE_OPERAND (t, i);
2763 if (op && TREE_SIDE_EFFECTS (op))
2764 side_effects = true;
2765 if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
2769 TREE_SIDE_EFFECTS (t) = side_effects;
2770 TREE_READONLY (t) = read_only;
2773 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
2774 size or offset that depends on a field within a record. */
2777 contains_placeholder_p (const_tree exp)
2779 enum tree_code code;
2784 code = TREE_CODE (exp);
2785 if (code == PLACEHOLDER_EXPR)
2788 switch (TREE_CODE_CLASS (code))
2791 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2792 position computations since they will be converted into a
2793 WITH_RECORD_EXPR involving the reference, which will assume
2794 here will be valid. */
2795 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2797 case tcc_exceptional:
2798 if (code == TREE_LIST)
2799 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
2800 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
2805 case tcc_comparison:
2806 case tcc_expression:
2810 /* Ignoring the first operand isn't quite right, but works best. */
2811 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
2814 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2815 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
2816 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
2819 /* The save_expr function never wraps anything containing
2820 a PLACEHOLDER_EXPR. */
2827 switch (TREE_CODE_LENGTH (code))
2830 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2832 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2833 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
2844 const_call_expr_arg_iterator iter;
2845 FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
2846 if (CONTAINS_PLACEHOLDER_P (arg))
2860 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
2861 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
2865 type_contains_placeholder_1 (const_tree type)
2867 /* If the size contains a placeholder or the parent type (component type in
2868 the case of arrays) type involves a placeholder, this type does. */
2869 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
2870 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
2871 || (!POINTER_TYPE_P (type)
2873 && type_contains_placeholder_p (TREE_TYPE (type))))
2876 /* Now do type-specific checks. Note that the last part of the check above
2877 greatly limits what we have to do below. */
2878 switch (TREE_CODE (type))
2886 case REFERENCE_TYPE:
2894 case FIXED_POINT_TYPE:
2895 /* Here we just check the bounds. */
2896 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
2897 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
2900 /* We have already checked the component type above, so just check the
2902 return type_contains_placeholder_p (TYPE_DOMAIN (type));
2906 case QUAL_UNION_TYPE:
2910 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2911 if (TREE_CODE (field) == FIELD_DECL
2912 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
2913 || (TREE_CODE (type) == QUAL_UNION_TYPE
2914 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
2915 || type_contains_placeholder_p (TREE_TYPE (field))))
2926 /* Wrapper around above function used to cache its result. */
2929 type_contains_placeholder_p (tree type)
2933 /* If the contains_placeholder_bits field has been initialized,
2934 then we know the answer. */
2935 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
2936 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
2938 /* Indicate that we've seen this type node, and the answer is false.
2939 This is what we want to return if we run into recursion via fields. */
2940 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
2942 /* Compute the real value. */
2943 result = type_contains_placeholder_1 (type);
2945 /* Store the real value. */
2946 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
2951 /* Push tree EXP onto vector QUEUE if it is not already present. */
2954 push_without_duplicates (tree exp, VEC (tree, heap) **queue)
2959 FOR_EACH_VEC_ELT (tree, *queue, i, iter)
2960 if (simple_cst_equal (iter, exp) == 1)
2964 VEC_safe_push (tree, heap, *queue, exp);
2967 /* Given a tree EXP, find all occurences of references to fields
2968 in a PLACEHOLDER_EXPR and place them in vector REFS without
2969 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
2970 we assume here that EXP contains only arithmetic expressions
2971 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
2975 find_placeholder_in_expr (tree exp, VEC (tree, heap) **refs)
2977 enum tree_code code = TREE_CODE (exp);
2981 /* We handle TREE_LIST and COMPONENT_REF separately. */
2982 if (code == TREE_LIST)
2984 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
2985 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
2987 else if (code == COMPONENT_REF)
2989 for (inner = TREE_OPERAND (exp, 0);
2990 REFERENCE_CLASS_P (inner);
2991 inner = TREE_OPERAND (inner, 0))
2994 if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
2995 push_without_duplicates (exp, refs);
2997 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
3000 switch (TREE_CODE_CLASS (code))
3005 case tcc_declaration:
3006 /* Variables allocated to static storage can stay. */
3007 if (!TREE_STATIC (exp))
3008 push_without_duplicates (exp, refs);
3011 case tcc_expression:
3012 /* This is the pattern built in ada/make_aligning_type. */
3013 if (code == ADDR_EXPR
3014 && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
3016 push_without_duplicates (exp, refs);
3020 /* Fall through... */
3022 case tcc_exceptional:
3025 case tcc_comparison:
3027 for (i = 0; i < TREE_CODE_LENGTH (code); i++)
3028 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
3032 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
3033 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
3041 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3042 return a tree with all occurrences of references to F in a
3043 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3044 CONST_DECLs. Note that we assume here that EXP contains only
3045 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3046 occurring only in their argument list. */
3049 substitute_in_expr (tree exp, tree f, tree r)
3051 enum tree_code code = TREE_CODE (exp);
3052 tree op0, op1, op2, op3;
3055 /* We handle TREE_LIST and COMPONENT_REF separately. */
3056 if (code == TREE_LIST)
3058 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
3059 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
3060 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
3063 return tree_cons (TREE_PURPOSE (exp), op1, op0);
3065 else if (code == COMPONENT_REF)
3069 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3070 and it is the right field, replace it with R. */
3071 for (inner = TREE_OPERAND (exp, 0);
3072 REFERENCE_CLASS_P (inner);
3073 inner = TREE_OPERAND (inner, 0))
3077 op1 = TREE_OPERAND (exp, 1);
3079 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
3082 /* If this expression hasn't been completed let, leave it alone. */
3083 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
3086 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3087 if (op0 == TREE_OPERAND (exp, 0))
3091 = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
3094 switch (TREE_CODE_CLASS (code))
3099 case tcc_declaration:
3105 case tcc_expression:
3109 /* Fall through... */
3111 case tcc_exceptional:
3114 case tcc_comparison:
3116 switch (TREE_CODE_LENGTH (code))
3122 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3123 if (op0 == TREE_OPERAND (exp, 0))
3126 new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
3130 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3131 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
3133 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
3136 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
3140 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3141 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
3142 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
3144 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3145 && op2 == TREE_OPERAND (exp, 2))
3148 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
3152 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
3153 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
3154 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
3155 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
3157 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3158 && op2 == TREE_OPERAND (exp, 2)
3159 && op3 == TREE_OPERAND (exp, 3))
3163 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
3175 new_tree = NULL_TREE;
3177 /* If we are trying to replace F with a constant, inline back
3178 functions which do nothing else than computing a value from
3179 the arguments they are passed. This makes it possible to
3180 fold partially or entirely the replacement expression. */
3181 if (CONSTANT_CLASS_P (r) && code == CALL_EXPR)
3183 tree t = maybe_inline_call_in_expr (exp);
3185 return SUBSTITUTE_IN_EXPR (t, f, r);
3188 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
3190 tree op = TREE_OPERAND (exp, i);
3191 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
3195 new_tree = copy_node (exp);
3196 TREE_OPERAND (new_tree, i) = new_op;
3202 new_tree = fold (new_tree);
3203 if (TREE_CODE (new_tree) == CALL_EXPR)
3204 process_call_operands (new_tree);
3215 TREE_READONLY (new_tree) |= TREE_READONLY (exp);
3217 if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
3218 TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
3223 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3224 for it within OBJ, a tree that is an object or a chain of references. */
3227 substitute_placeholder_in_expr (tree exp, tree obj)
3229 enum tree_code code = TREE_CODE (exp);
3230 tree op0, op1, op2, op3;
3233 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3234 in the chain of OBJ. */
3235 if (code == PLACEHOLDER_EXPR)
3237 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
3240 for (elt = obj; elt != 0;
3241 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
3242 || TREE_CODE (elt) == COND_EXPR)
3243 ? TREE_OPERAND (elt, 1)
3244 : (REFERENCE_CLASS_P (elt)
3245 || UNARY_CLASS_P (elt)
3246 || BINARY_CLASS_P (elt)
3247 || VL_EXP_CLASS_P (elt)
3248 || EXPRESSION_CLASS_P (elt))
3249 ? TREE_OPERAND (elt, 0) : 0))
3250 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
3253 for (elt = obj; elt != 0;
3254 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
3255 || TREE_CODE (elt) == COND_EXPR)
3256 ? TREE_OPERAND (elt, 1)
3257 : (REFERENCE_CLASS_P (elt)
3258 || UNARY_CLASS_P (elt)
3259 || BINARY_CLASS_P (elt)
3260 || VL_EXP_CLASS_P (elt)
3261 || EXPRESSION_CLASS_P (elt))
3262 ? TREE_OPERAND (elt, 0) : 0))
3263 if (POINTER_TYPE_P (TREE_TYPE (elt))
3264 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
3266 return fold_build1 (INDIRECT_REF, need_type, elt);
3268 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3269 survives until RTL generation, there will be an error. */
3273 /* TREE_LIST is special because we need to look at TREE_VALUE
3274 and TREE_CHAIN, not TREE_OPERANDS. */
3275 else if (code == TREE_LIST)
3277 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
3278 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
3279 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
3282 return tree_cons (TREE_PURPOSE (exp), op1, op0);
3285 switch (TREE_CODE_CLASS (code))
3288 case tcc_declaration:
3291 case tcc_exceptional:
3294 case tcc_comparison:
3295 case tcc_expression:
3298 switch (TREE_CODE_LENGTH (code))
3304 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3305 if (op0 == TREE_OPERAND (exp, 0))
3308 new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
3312 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3313 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
3315 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
3318 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
3322 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3323 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
3324 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
3326 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3327 && op2 == TREE_OPERAND (exp, 2))
3330 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
3334 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
3335 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
3336 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
3337 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
3339 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
3340 && op2 == TREE_OPERAND (exp, 2)
3341 && op3 == TREE_OPERAND (exp, 3))
3345 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
3357 new_tree = NULL_TREE;
3359 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
3361 tree op = TREE_OPERAND (exp, i);
3362 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
3366 new_tree = copy_node (exp);
3367 TREE_OPERAND (new_tree, i) = new_op;
3373 new_tree = fold (new_tree);
3374 if (TREE_CODE (new_tree) == CALL_EXPR)
3375 process_call_operands (new_tree);
3386 TREE_READONLY (new_tree) |= TREE_READONLY (exp);
3388 if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
3389 TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
3394 /* Stabilize a reference so that we can use it any number of times
3395 without causing its operands to be evaluated more than once.
3396 Returns the stabilized reference. This works by means of save_expr,
3397 so see the caveats in the comments about save_expr.
3399 Also allows conversion expressions whose operands are references.
3400 Any other kind of expression is returned unchanged. */
3403 stabilize_reference (tree ref)
3406 enum tree_code code = TREE_CODE (ref);
3413 /* No action is needed in this case. */
3418 case FIX_TRUNC_EXPR:
3419 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
3423 result = build_nt (INDIRECT_REF,
3424 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
3428 result = build_nt (COMPONENT_REF,
3429 stabilize_reference (TREE_OPERAND (ref, 0)),
3430 TREE_OPERAND (ref, 1), NULL_TREE);
3434 result = build_nt (BIT_FIELD_REF,
3435 stabilize_reference (TREE_OPERAND (ref, 0)),
3436 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
3437 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
3441 result = build_nt (ARRAY_REF,
3442 stabilize_reference (TREE_OPERAND (ref, 0)),
3443 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
3444 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
3447 case ARRAY_RANGE_REF:
3448 result = build_nt (ARRAY_RANGE_REF,
3449 stabilize_reference (TREE_OPERAND (ref, 0)),
3450 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
3451 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
3455 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3456 it wouldn't be ignored. This matters when dealing with
3458 return stabilize_reference_1 (ref);
3460 /* If arg isn't a kind of lvalue we recognize, make no change.
3461 Caller should recognize the error for an invalid lvalue. */
3466 return error_mark_node;
3469 TREE_TYPE (result) = TREE_TYPE (ref);
3470 TREE_READONLY (result) = TREE_READONLY (ref);
3471 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
3472 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
3477 /* Subroutine of stabilize_reference; this is called for subtrees of
3478 references. Any expression with side-effects must be put in a SAVE_EXPR
3479 to ensure that it is only evaluated once.
3481 We don't put SAVE_EXPR nodes around everything, because assigning very
3482 simple expressions to temporaries causes us to miss good opportunities
3483 for optimizations. Among other things, the opportunity to fold in the
3484 addition of a constant into an addressing mode often gets lost, e.g.
3485 "y[i+1] += x;". In general, we take the approach that we should not make
3486 an assignment unless we are forced into it - i.e., that any non-side effect
3487 operator should be allowed, and that cse should take care of coalescing
3488 multiple utterances of the same expression should that prove fruitful. */
3491 stabilize_reference_1 (tree e)
3494 enum tree_code code = TREE_CODE (e);
3496 /* We cannot ignore const expressions because it might be a reference
3497 to a const array but whose index contains side-effects. But we can
3498 ignore things that are actual constant or that already have been
3499 handled by this function. */
3501 if (tree_invariant_p (e))
3504 switch (TREE_CODE_CLASS (code))
3506 case tcc_exceptional:
3508 case tcc_declaration:
3509 case tcc_comparison:
3511 case tcc_expression:
3514 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3515 so that it will only be evaluated once. */
3516 /* The reference (r) and comparison (<) classes could be handled as
3517 below, but it is generally faster to only evaluate them once. */
3518 if (TREE_SIDE_EFFECTS (e))
3519 return save_expr (e);
3523 /* Constants need no processing. In fact, we should never reach
3528 /* Division is slow and tends to be compiled with jumps,
3529 especially the division by powers of 2 that is often
3530 found inside of an array reference. So do it just once. */
3531 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
3532 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
3533 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
3534 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
3535 return save_expr (e);
3536 /* Recursively stabilize each operand. */
3537 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
3538 stabilize_reference_1 (TREE_OPERAND (e, 1)));
3542 /* Recursively stabilize each operand. */
3543 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
3550 TREE_TYPE (result) = TREE_TYPE (e);
3551 TREE_READONLY (result) = TREE_READONLY (e);
3552 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
3553 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
3558 /* Low-level constructors for expressions. */
3560 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3561 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3564 recompute_tree_invariant_for_addr_expr (tree t)
3567 bool tc = true, se = false;
3569 /* We started out assuming this address is both invariant and constant, but
3570 does not have side effects. Now go down any handled components and see if
3571 any of them involve offsets that are either non-constant or non-invariant.
3572 Also check for side-effects.
3574 ??? Note that this code makes no attempt to deal with the case where
3575 taking the address of something causes a copy due to misalignment. */
3577 #define UPDATE_FLAGS(NODE) \
3578 do { tree _node = (NODE); \
3579 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3580 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3582 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
3583 node = TREE_OPERAND (node, 0))
3585 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3586 array reference (probably made temporarily by the G++ front end),
3587 so ignore all the operands. */
3588 if ((TREE_CODE (node) == ARRAY_REF
3589 || TREE_CODE (node) == ARRAY_RANGE_REF)
3590 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
3592 UPDATE_FLAGS (TREE_OPERAND (node, 1));
3593 if (TREE_OPERAND (node, 2))
3594 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3595 if (TREE_OPERAND (node, 3))
3596 UPDATE_FLAGS (TREE_OPERAND (node, 3));
3598 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3599 FIELD_DECL, apparently. The G++ front end can put something else
3600 there, at least temporarily. */
3601 else if (TREE_CODE (node) == COMPONENT_REF
3602 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
3604 if (TREE_OPERAND (node, 2))
3605 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3607 else if (TREE_CODE (node) == BIT_FIELD_REF)
3608 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3611 node = lang_hooks.expr_to_decl (node, &tc, &se);
3613 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3614 the address, since &(*a)->b is a form of addition. If it's a constant, the
3615 address is constant too. If it's a decl, its address is constant if the
3616 decl is static. Everything else is not constant and, furthermore,
3617 taking the address of a volatile variable is not volatile. */
3618 if (TREE_CODE (node) == INDIRECT_REF
3619 || TREE_CODE (node) == MEM_REF)
3620 UPDATE_FLAGS (TREE_OPERAND (node, 0));
3621 else if (CONSTANT_CLASS_P (node))
3623 else if (DECL_P (node))
3624 tc &= (staticp (node) != NULL_TREE);
3628 se |= TREE_SIDE_EFFECTS (node);
3632 TREE_CONSTANT (t) = tc;
3633 TREE_SIDE_EFFECTS (t) = se;
3637 /* Build an expression of code CODE, data type TYPE, and operands as
3638 specified. Expressions and reference nodes can be created this way.
3639 Constants, decls, types and misc nodes cannot be.
3641 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3642 enough for all extant tree codes. */
3645 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
3649 gcc_assert (TREE_CODE_LENGTH (code) == 0);
3651 t = make_node_stat (code PASS_MEM_STAT);
3658 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
3660 int length = sizeof (struct tree_exp);
3663 record_node_allocation_statistics (code, length);
3665 gcc_assert (TREE_CODE_LENGTH (code) == 1);
3667 t = ggc_alloc_zone_tree_node_stat (&tree_zone, length PASS_MEM_STAT);
3669 memset (t, 0, sizeof (struct tree_common));
3671 TREE_SET_CODE (t, code);
3673 TREE_TYPE (t) = type;
3674 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
3675 TREE_OPERAND (t, 0) = node;
3676 TREE_BLOCK (t) = NULL_TREE;
3677 if (node && !TYPE_P (node))
3679 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
3680 TREE_READONLY (t) = TREE_READONLY (node);
3683 if (TREE_CODE_CLASS (code) == tcc_statement)
3684 TREE_SIDE_EFFECTS (t) = 1;
3688 /* All of these have side-effects, no matter what their
3690 TREE_SIDE_EFFECTS (t) = 1;
3691 TREE_READONLY (t) = 0;
3695 /* Whether a dereference is readonly has nothing to do with whether
3696 its operand is readonly. */
3697 TREE_READONLY (t) = 0;
3702 recompute_tree_invariant_for_addr_expr (t);
3706 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
3707 && node && !TYPE_P (node)
3708 && TREE_CONSTANT (node))
3709 TREE_CONSTANT (t) = 1;
3710 if (TREE_CODE_CLASS (code) == tcc_reference
3711 && node && TREE_THIS_VOLATILE (node))
3712 TREE_THIS_VOLATILE (t) = 1;
3719 #define PROCESS_ARG(N) \
3721 TREE_OPERAND (t, N) = arg##N; \
3722 if (arg##N &&!TYPE_P (arg##N)) \
3724 if (TREE_SIDE_EFFECTS (arg##N)) \
3726 if (!TREE_READONLY (arg##N) \
3727 && !CONSTANT_CLASS_P (arg##N)) \
3728 (void) (read_only = 0); \
3729 if (!TREE_CONSTANT (arg##N)) \
3730 (void) (constant = 0); \
3735 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
3737 bool constant, read_only, side_effects;
3740 gcc_assert (TREE_CODE_LENGTH (code) == 2);
3742 if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
3743 && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
3744 /* When sizetype precision doesn't match that of pointers
3745 we need to be able to build explicit extensions or truncations
3746 of the offset argument. */
3747 && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
3748 gcc_assert (TREE_CODE (arg0) == INTEGER_CST
3749 && TREE_CODE (arg1) == INTEGER_CST);
3751 if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
3752 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
3753 && INTEGRAL_TYPE_P (TREE_TYPE (arg1))
3754 && useless_type_conversion_p (sizetype, TREE_TYPE (arg1)));
3756 t = make_node_stat (code PASS_MEM_STAT);
3759 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3760 result based on those same flags for the arguments. But if the
3761 arguments aren't really even `tree' expressions, we shouldn't be trying
3764 /* Expressions without side effects may be constant if their
3765 arguments are as well. */
3766 constant = (TREE_CODE_CLASS (code) == tcc_comparison
3767 || TREE_CODE_CLASS (code) == tcc_binary);
3769 side_effects = TREE_SIDE_EFFECTS (t);
3774 TREE_READONLY (t) = read_only;
3775 TREE_CONSTANT (t) = constant;
3776 TREE_SIDE_EFFECTS (t) = side_effects;
3777 TREE_THIS_VOLATILE (t)
3778 = (TREE_CODE_CLASS (code) == tcc_reference
3779 && arg0 && TREE_THIS_VOLATILE (arg0));
3786 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3787 tree arg2 MEM_STAT_DECL)
3789 bool constant, read_only, side_effects;
3792 gcc_assert (TREE_CODE_LENGTH (code) == 3);
3793 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3795 t = make_node_stat (code PASS_MEM_STAT);
3800 /* As a special exception, if COND_EXPR has NULL branches, we
3801 assume that it is a gimple statement and always consider
3802 it to have side effects. */
3803 if (code == COND_EXPR
3804 && tt == void_type_node
3805 && arg1 == NULL_TREE
3806 && arg2 == NULL_TREE)
3807 side_effects = true;
3809 side_effects = TREE_SIDE_EFFECTS (t);
3815 if (code == COND_EXPR)
3816 TREE_READONLY (t) = read_only;
3818 TREE_SIDE_EFFECTS (t) = side_effects;
3819 TREE_THIS_VOLATILE (t)
3820 = (TREE_CODE_CLASS (code) == tcc_reference
3821 && arg0 && TREE_THIS_VOLATILE (arg0));
3827 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3828 tree arg2, tree arg3 MEM_STAT_DECL)
3830 bool constant, read_only, side_effects;
3833 gcc_assert (TREE_CODE_LENGTH (code) == 4);
3835 t = make_node_stat (code PASS_MEM_STAT);
3838 side_effects = TREE_SIDE_EFFECTS (t);
3845 TREE_SIDE_EFFECTS (t) = side_effects;
3846 TREE_THIS_VOLATILE (t)
3847 = (TREE_CODE_CLASS (code) == tcc_reference
3848 && arg0 && TREE_THIS_VOLATILE (arg0));
3854 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3855 tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
3857 bool constant, read_only, side_effects;
3860 gcc_assert (TREE_CODE_LENGTH (code) == 5);
3862 t = make_node_stat (code PASS_MEM_STAT);
3865 side_effects = TREE_SIDE_EFFECTS (t);
3873 TREE_SIDE_EFFECTS (t) = side_effects;
3874 TREE_THIS_VOLATILE (t)
3875 = (TREE_CODE_CLASS (code) == tcc_reference
3876 && arg0 && TREE_THIS_VOLATILE (arg0));
3882 build6_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3883 tree arg2, tree arg3, tree arg4, tree arg5 MEM_STAT_DECL)
3885 bool constant, read_only, side_effects;
3888 gcc_assert (code == TARGET_MEM_REF);
3890 t = make_node_stat (code PASS_MEM_STAT);
3893 side_effects = TREE_SIDE_EFFECTS (t);
3900 if (code == TARGET_MEM_REF)
3904 TREE_SIDE_EFFECTS (t) = side_effects;
3905 TREE_THIS_VOLATILE (t)
3906 = (code == TARGET_MEM_REF
3907 && arg5 && TREE_THIS_VOLATILE (arg5));
3912 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
3913 on the pointer PTR. */
3916 build_simple_mem_ref_loc (location_t loc, tree ptr)
3918 HOST_WIDE_INT offset = 0;
3919 tree ptype = TREE_TYPE (ptr);
3921 /* For convenience allow addresses that collapse to a simple base
3923 if (TREE_CODE (ptr) == ADDR_EXPR
3924 && (handled_component_p (TREE_OPERAND (ptr, 0))
3925 || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
3927 ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
3929 ptr = build_fold_addr_expr (ptr);
3930 gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
3932 tem = build2 (MEM_REF, TREE_TYPE (ptype),
3933 ptr, build_int_cst (ptype, offset));
3934 SET_EXPR_LOCATION (tem, loc);
3938 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
3941 mem_ref_offset (const_tree t)
3943 tree toff = TREE_OPERAND (t, 1);
3944 return double_int_sext (tree_to_double_int (toff),
3945 TYPE_PRECISION (TREE_TYPE (toff)));
3948 /* Return the pointer-type relevant for TBAA purposes from the
3949 gimple memory reference tree T. This is the type to be used for
3950 the offset operand of MEM_REF or TARGET_MEM_REF replacements of T. */
3953 reference_alias_ptr_type (const_tree t)
3955 const_tree base = t;
3956 while (handled_component_p (base))
3957 base = TREE_OPERAND (base, 0);
3958 if (TREE_CODE (base) == MEM_REF)
3959 return TREE_TYPE (TREE_OPERAND (base, 1));
3960 else if (TREE_CODE (base) == TARGET_MEM_REF)
3961 return TREE_TYPE (TMR_OFFSET (base));
3963 return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (base)));
3966 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
3967 offsetted by OFFSET units. */
3970 build_invariant_address (tree type, tree base, HOST_WIDE_INT offset)
3972 tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
3973 build_fold_addr_expr (base),
3974 build_int_cst (ptr_type_node, offset));
3975 tree addr = build1 (ADDR_EXPR, type, ref);
3976 recompute_tree_invariant_for_addr_expr (addr);
3980 /* Similar except don't specify the TREE_TYPE
3981 and leave the TREE_SIDE_EFFECTS as 0.
3982 It is permissible for arguments to be null,
3983 or even garbage if their values do not matter. */
3986 build_nt (enum tree_code code, ...)
3993 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3997 t = make_node (code);
3998 length = TREE_CODE_LENGTH (code);
4000 for (i = 0; i < length; i++)
4001 TREE_OPERAND (t, i) = va_arg (p, tree);
4007 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4011 build_nt_call_vec (tree fn, VEC(tree,gc) *args)
4016 ret = build_vl_exp (CALL_EXPR, VEC_length (tree, args) + 3);
4017 CALL_EXPR_FN (ret) = fn;
4018 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
4019 FOR_EACH_VEC_ELT (tree, args, ix, t)
4020 CALL_EXPR_ARG (ret, ix) = t;
4024 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4025 We do NOT enter this node in any sort of symbol table.
4027 LOC is the location of the decl.
4029 layout_decl is used to set up the decl's storage layout.
4030 Other slots are initialized to 0 or null pointers. */
4033 build_decl_stat (location_t loc, enum tree_code code, tree name,
4034 tree type MEM_STAT_DECL)
4038 t = make_node_stat (code PASS_MEM_STAT);
4039 DECL_SOURCE_LOCATION (t) = loc;
4041 /* if (type == error_mark_node)
4042 type = integer_type_node; */
4043 /* That is not done, deliberately, so that having error_mark_node
4044 as the type can suppress useless errors in the use of this variable. */
4046 DECL_NAME (t) = name;
4047 TREE_TYPE (t) = type;
4049 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
4055 /* Builds and returns function declaration with NAME and TYPE. */
4058 build_fn_decl (const char *name, tree type)
4060 tree id = get_identifier (name);
4061 tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
4063 DECL_EXTERNAL (decl) = 1;
4064 TREE_PUBLIC (decl) = 1;
4065 DECL_ARTIFICIAL (decl) = 1;
4066 TREE_NOTHROW (decl) = 1;
4071 VEC(tree,gc) *all_translation_units;
4073 /* Builds a new translation-unit decl with name NAME, queues it in the
4074 global list of translation-unit decls and returns it. */
4077 build_translation_unit_decl (tree name)
4079 tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
4081 TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
4082 VEC_safe_push (tree, gc, all_translation_units, tu);
4087 /* BLOCK nodes are used to represent the structure of binding contours
4088 and declarations, once those contours have been exited and their contents
4089 compiled. This information is used for outputting debugging info. */
4092 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
4094 tree block = make_node (BLOCK);
4096 BLOCK_VARS (block) = vars;
4097 BLOCK_SUBBLOCKS (block) = subblocks;
4098 BLOCK_SUPERCONTEXT (block) = supercontext;
4099 BLOCK_CHAIN (block) = chain;
4104 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4106 LOC is the location to use in tree T. */
4109 protected_set_expr_location (tree t, location_t loc)
4111 if (t && CAN_HAVE_LOCATION_P (t))
4112 SET_EXPR_LOCATION (t, loc);
4115 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4119 build_decl_attribute_variant (tree ddecl, tree attribute)
4121 DECL_ATTRIBUTES (ddecl) = attribute;
4125 /* Borrowed from hashtab.c iterative_hash implementation. */
4126 #define mix(a,b,c) \
4128 a -= b; a -= c; a ^= (c>>13); \
4129 b -= c; b -= a; b ^= (a<< 8); \
4130 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
4131 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
4132 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
4133 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
4134 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
4135 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
4136 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
4140 /* Produce good hash value combining VAL and VAL2. */
4142 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
4144 /* the golden ratio; an arbitrary value. */
4145 hashval_t a = 0x9e3779b9;
4151 /* Produce good hash value combining VAL and VAL2. */
4153 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
4155 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
4156 return iterative_hash_hashval_t (val, val2);
4159 hashval_t a = (hashval_t) val;
4160 /* Avoid warnings about shifting of more than the width of the type on
4161 hosts that won't execute this path. */
4163 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
4165 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
4167 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
4168 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
4175 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4176 is ATTRIBUTE and its qualifiers are QUALS.
4178 Record such modified types already made so we don't make duplicates. */
4181 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
4183 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
4185 hashval_t hashcode = 0;
4187 enum tree_code code = TREE_CODE (ttype);
4189 /* Building a distinct copy of a tagged type is inappropriate; it
4190 causes breakage in code that expects there to be a one-to-one
4191 relationship between a struct and its fields.
4192 build_duplicate_type is another solution (as used in
4193 handle_transparent_union_attribute), but that doesn't play well
4194 with the stronger C++ type identity model. */
4195 if (TREE_CODE (ttype) == RECORD_TYPE
4196 || TREE_CODE (ttype) == UNION_TYPE
4197 || TREE_CODE (ttype) == QUAL_UNION_TYPE
4198 || TREE_CODE (ttype) == ENUMERAL_TYPE)
4200 warning (OPT_Wattributes,
4201 "ignoring attributes applied to %qT after definition",
4202 TYPE_MAIN_VARIANT (ttype));
4203 return build_qualified_type (ttype, quals);
4206 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
4207 ntype = build_distinct_type_copy (ttype);
4209 TYPE_ATTRIBUTES (ntype) = attribute;
4211 hashcode = iterative_hash_object (code, hashcode);
4212 if (TREE_TYPE (ntype))
4213 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
4215 hashcode = attribute_hash_list (attribute, hashcode);
4217 switch (TREE_CODE (ntype))
4220 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
4223 if (TYPE_DOMAIN (ntype))
4224 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
4228 hashcode = iterative_hash_object
4229 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
4230 hashcode = iterative_hash_object
4231 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
4234 case FIXED_POINT_TYPE:
4236 unsigned int precision = TYPE_PRECISION (ntype);
4237 hashcode = iterative_hash_object (precision, hashcode);
4244 ntype = type_hash_canon (hashcode, ntype);
4246 /* If the target-dependent attributes make NTYPE different from
4247 its canonical type, we will need to use structural equality
4248 checks for this type. */
4249 if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
4250 || !comp_type_attributes (ntype, ttype))
4251 SET_TYPE_STRUCTURAL_EQUALITY (ntype);
4252 else if (TYPE_CANONICAL (ntype) == ntype)
4253 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
4255 ttype = build_qualified_type (ntype, quals);
4257 else if (TYPE_QUALS (ttype) != quals)
4258 ttype = build_qualified_type (ttype, quals);
4263 /* Compare two attributes for their value identity. Return true if the
4264 attribute values are known to be equal; otherwise return false.
4268 attribute_value_equal (const_tree attr1, const_tree attr2)
4270 if (TREE_VALUE (attr1) == TREE_VALUE (attr2))
4273 if (TREE_VALUE (attr1) != NULL_TREE
4274 && TREE_CODE (TREE_VALUE (attr1)) == TREE_LIST
4275 && TREE_VALUE (attr2) != NULL
4276 && TREE_CODE (TREE_VALUE (attr2)) == TREE_LIST)
4277 return (simple_cst_list_equal (TREE_VALUE (attr1),
4278 TREE_VALUE (attr2)) == 1);
4280 return (simple_cst_equal (TREE_VALUE (attr1), TREE_VALUE (attr2)) == 1);
4283 /* Return 0 if the attributes for two types are incompatible, 1 if they
4284 are compatible, and 2 if they are nearly compatible (which causes a
4285 warning to be generated). */
4287 comp_type_attributes (const_tree type1, const_tree type2)
4289 const_tree a1 = TYPE_ATTRIBUTES (type1);
4290 const_tree a2 = TYPE_ATTRIBUTES (type2);
4295 for (a = a1; a != NULL_TREE; a = TREE_CHAIN (a))
4297 const struct attribute_spec *as;
4300 as = lookup_attribute_spec (TREE_PURPOSE (a));
4301 if (!as || as->affects_type_identity == false)
4304 attr = lookup_attribute (as->name, CONST_CAST_TREE (a2));
4305 if (!attr || !attribute_value_equal (a, attr))
4310 for (a = a2; a != NULL_TREE; a = TREE_CHAIN (a))
4312 const struct attribute_spec *as;
4314 as = lookup_attribute_spec (TREE_PURPOSE (a));
4315 if (!as || as->affects_type_identity == false)
4318 if (!lookup_attribute (as->name, CONST_CAST_TREE (a1)))
4320 /* We don't need to compare trees again, as we did this
4321 already in first loop. */
4323 /* All types - affecting identity - are equal, so
4324 there is no need to call target hook for comparison. */
4328 /* As some type combinations - like default calling-convention - might
4329 be compatible, we have to call the target hook to get the final result. */
4330 return targetm.comp_type_attributes (type1, type2);
4333 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4336 Record such modified types already made so we don't make duplicates. */
4339 build_type_attribute_variant (tree ttype, tree attribute)
4341 return build_type_attribute_qual_variant (ttype, attribute,
4342 TYPE_QUALS (ttype));
4346 /* Reset the expression *EXPR_P, a size or position.
4348 ??? We could reset all non-constant sizes or positions. But it's cheap
4349 enough to not do so and refrain from adding workarounds to dwarf2out.c.
4351 We need to reset self-referential sizes or positions because they cannot
4352 be gimplified and thus can contain a CALL_EXPR after the gimplification
4353 is finished, which will run afoul of LTO streaming. And they need to be
4354 reset to something essentially dummy but not constant, so as to preserve
4355 the properties of the object they are attached to. */
4358 free_lang_data_in_one_sizepos (tree *expr_p)
4360 tree expr = *expr_p;
4361 if (CONTAINS_PLACEHOLDER_P (expr))
4362 *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
4366 /* Reset all the fields in a binfo node BINFO. We only keep
4367 BINFO_VIRTUALS, which is used by gimple_fold_obj_type_ref. */
4370 free_lang_data_in_binfo (tree binfo)
4375 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
4377 BINFO_VTABLE (binfo) = NULL_TREE;
4378 BINFO_BASE_ACCESSES (binfo) = NULL;
4379 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
4380 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
4382 FOR_EACH_VEC_ELT (tree, BINFO_BASE_BINFOS (binfo), i, t)
4383 free_lang_data_in_binfo (t);
4387 /* Reset all language specific information still present in TYPE. */
4390 free_lang_data_in_type (tree type)
4392 gcc_assert (TYPE_P (type));
4394 /* Give the FE a chance to remove its own data first. */
4395 lang_hooks.free_lang_data (type);
4397 TREE_LANG_FLAG_0 (type) = 0;
4398 TREE_LANG_FLAG_1 (type) = 0;
4399 TREE_LANG_FLAG_2 (type) = 0;
4400 TREE_LANG_FLAG_3 (type) = 0;
4401 TREE_LANG_FLAG_4 (type) = 0;
4402 TREE_LANG_FLAG_5 (type) = 0;
4403 TREE_LANG_FLAG_6 (type) = 0;
4405 if (TREE_CODE (type) == FUNCTION_TYPE)
4407 /* Remove the const and volatile qualifiers from arguments. The
4408 C++ front end removes them, but the C front end does not,
4409 leading to false ODR violation errors when merging two
4410 instances of the same function signature compiled by
4411 different front ends. */
4414 for (p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
4416 tree arg_type = TREE_VALUE (p);
4418 if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
4420 int quals = TYPE_QUALS (arg_type)
4422 & ~TYPE_QUAL_VOLATILE;
4423 TREE_VALUE (p) = build_qualified_type (arg_type, quals);
4424 free_lang_data_in_type (TREE_VALUE (p));
4429 /* Remove members that are not actually FIELD_DECLs from the field
4430 list of an aggregate. These occur in C++. */
4431 if (RECORD_OR_UNION_TYPE_P (type))
4435 /* Note that TYPE_FIELDS can be shared across distinct
4436 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4437 to be removed, we cannot set its TREE_CHAIN to NULL.
4438 Otherwise, we would not be able to find all the other fields
4439 in the other instances of this TREE_TYPE.
4441 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4443 member = TYPE_FIELDS (type);
4446 if (TREE_CODE (member) == FIELD_DECL)
4449 TREE_CHAIN (prev) = member;
4451 TYPE_FIELDS (type) = member;
4455 member = TREE_CHAIN (member);
4459 TREE_CHAIN (prev) = NULL_TREE;
4461 TYPE_FIELDS (type) = NULL_TREE;
4463 TYPE_METHODS (type) = NULL_TREE;
4464 if (TYPE_BINFO (type))
4465 free_lang_data_in_binfo (TYPE_BINFO (type));
4469 /* For non-aggregate types, clear out the language slot (which
4470 overloads TYPE_BINFO). */
4471 TYPE_LANG_SLOT_1 (type) = NULL_TREE;
4473 if (INTEGRAL_TYPE_P (type)
4474 || SCALAR_FLOAT_TYPE_P (type)
4475 || FIXED_POINT_TYPE_P (type))
4477 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
4478 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
4482 free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
4483 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
4485 if (debug_info_level < DINFO_LEVEL_TERSE
4486 || (TYPE_CONTEXT (type)
4487 && TREE_CODE (TYPE_CONTEXT (type)) != FUNCTION_DECL
4488 && TREE_CODE (TYPE_CONTEXT (type)) != NAMESPACE_DECL))
4489 TYPE_CONTEXT (type) = NULL_TREE;
4491 if (debug_info_level < DINFO_LEVEL_TERSE)
4492 TYPE_STUB_DECL (type) = NULL_TREE;
4496 /* Return true if DECL may need an assembler name to be set. */
4499 need_assembler_name_p (tree decl)
4501 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4502 if (TREE_CODE (decl) != FUNCTION_DECL
4503 && TREE_CODE (decl) != VAR_DECL)
4506 /* If DECL already has its assembler name set, it does not need a
4508 if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
4509 || DECL_ASSEMBLER_NAME_SET_P (decl))
4512 /* Abstract decls do not need an assembler name. */
4513 if (DECL_ABSTRACT (decl))
4516 /* For VAR_DECLs, only static, public and external symbols need an
4518 if (TREE_CODE (decl) == VAR_DECL
4519 && !TREE_STATIC (decl)
4520 && !TREE_PUBLIC (decl)
4521 && !DECL_EXTERNAL (decl))
4524 if (TREE_CODE (decl) == FUNCTION_DECL)
4526 /* Do not set assembler name on builtins. Allow RTL expansion to
4527 decide whether to expand inline or via a regular call. */
4528 if (DECL_BUILT_IN (decl)
4529 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
4532 /* Functions represented in the callgraph need an assembler name. */
4533 if (cgraph_get_node (decl) != NULL)
4536 /* Unused and not public functions don't need an assembler name. */
4537 if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
4545 /* Reset all language specific information still present in symbol
4549 free_lang_data_in_decl (tree decl)
4551 gcc_assert (DECL_P (decl));
4553 /* Give the FE a chance to remove its own data first. */
4554 lang_hooks.free_lang_data (decl);
4556 TREE_LANG_FLAG_0 (decl) = 0;
4557 TREE_LANG_FLAG_1 (decl) = 0;
4558 TREE_LANG_FLAG_2 (decl) = 0;
4559 TREE_LANG_FLAG_3 (decl) = 0;
4560 TREE_LANG_FLAG_4 (decl) = 0;
4561 TREE_LANG_FLAG_5 (decl) = 0;
4562 TREE_LANG_FLAG_6 (decl) = 0;
4564 /* Identifiers need not have a type. */
4565 if (DECL_NAME (decl))
4566 TREE_TYPE (DECL_NAME (decl)) = NULL_TREE;
4568 free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
4569 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
4570 if (TREE_CODE (decl) == FIELD_DECL)
4571 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
4573 /* DECL_FCONTEXT is only used for debug info generation. */
4574 if (TREE_CODE (decl) == FIELD_DECL
4575 && debug_info_level < DINFO_LEVEL_TERSE)
4576 DECL_FCONTEXT (decl) = NULL_TREE;
4578 if (TREE_CODE (decl) == FUNCTION_DECL)
4580 if (gimple_has_body_p (decl))
4584 /* If DECL has a gimple body, then the context for its
4585 arguments must be DECL. Otherwise, it doesn't really
4586 matter, as we will not be emitting any code for DECL. In
4587 general, there may be other instances of DECL created by
4588 the front end and since PARM_DECLs are generally shared,
4589 their DECL_CONTEXT changes as the replicas of DECL are
4590 created. The only time where DECL_CONTEXT is important
4591 is for the FUNCTION_DECLs that have a gimple body (since
4592 the PARM_DECL will be used in the function's body). */
4593 for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
4594 DECL_CONTEXT (t) = decl;
4597 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
4598 At this point, it is not needed anymore. */
4599 DECL_SAVED_TREE (decl) = NULL_TREE;
4601 /* Clear the abstract origin if it refers to a method. Otherwise
4602 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
4603 origin will not be output correctly. */
4604 if (DECL_ABSTRACT_ORIGIN (decl)
4605 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
4606 && RECORD_OR_UNION_TYPE_P
4607 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
4608 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
4610 /* Sometimes the C++ frontend doesn't manage to transform a temporary
4611 DECL_VINDEX referring to itself into a vtable slot number as it
4612 should. Happens with functions that are copied and then forgotten
4613 about. Just clear it, it won't matter anymore. */
4614 if (DECL_VINDEX (decl) && !host_integerp (DECL_VINDEX (decl), 0))
4615 DECL_VINDEX (decl) = NULL_TREE;
4617 else if (TREE_CODE (decl) == VAR_DECL)
4619 if ((DECL_EXTERNAL (decl)
4620 && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
4621 || (decl_function_context (decl) && !TREE_STATIC (decl)))
4622 DECL_INITIAL (decl) = NULL_TREE;
4624 else if (TREE_CODE (decl) == TYPE_DECL)
4625 DECL_INITIAL (decl) = NULL_TREE;
4626 else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
4627 && DECL_INITIAL (decl)
4628 && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
4630 /* Strip builtins from the translation-unit BLOCK. We still have
4631 targets without builtin_decl support and also builtins are
4632 shared nodes and thus we can't use TREE_CHAIN in multiple
4634 tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
4638 if (TREE_CODE (var) == FUNCTION_DECL
4639 && DECL_BUILT_IN (var))
4640 *nextp = TREE_CHAIN (var);
4642 nextp = &TREE_CHAIN (var);
4648 /* Data used when collecting DECLs and TYPEs for language data removal. */
4650 struct free_lang_data_d
4652 /* Worklist to avoid excessive recursion. */
4653 VEC(tree,heap) *worklist;
4655 /* Set of traversed objects. Used to avoid duplicate visits. */
4656 struct pointer_set_t *pset;
4658 /* Array of symbols to process with free_lang_data_in_decl. */
4659 VEC(tree,heap) *decls;
4661 /* Array of types to process with free_lang_data_in_type. */
4662 VEC(tree,heap) *types;
4666 /* Save all language fields needed to generate proper debug information
4667 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
4670 save_debug_info_for_decl (tree t)
4672 /*struct saved_debug_info_d *sdi;*/
4674 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && DECL_P (t));
4676 /* FIXME. Partial implementation for saving debug info removed. */
4680 /* Save all language fields needed to generate proper debug information
4681 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
4684 save_debug_info_for_type (tree t)
4686 /*struct saved_debug_info_d *sdi;*/
4688 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && TYPE_P (t));
4690 /* FIXME. Partial implementation for saving debug info removed. */
4694 /* Add type or decl T to one of the list of tree nodes that need their
4695 language data removed. The lists are held inside FLD. */
4698 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld)
4702 VEC_safe_push (tree, heap, fld->decls, t);
4703 if (debug_info_level > DINFO_LEVEL_TERSE)
4704 save_debug_info_for_decl (t);
4706 else if (TYPE_P (t))
4708 VEC_safe_push (tree, heap, fld->types, t);
4709 if (debug_info_level > DINFO_LEVEL_TERSE)
4710 save_debug_info_for_type (t);
4716 /* Push tree node T into FLD->WORKLIST. */
4719 fld_worklist_push (tree t, struct free_lang_data_d *fld)
4721 if (t && !is_lang_specific (t) && !pointer_set_contains (fld->pset, t))
4722 VEC_safe_push (tree, heap, fld->worklist, (t));
4726 /* Operand callback helper for free_lang_data_in_node. *TP is the
4727 subtree operand being considered. */
4730 find_decls_types_r (tree *tp, int *ws, void *data)
4733 struct free_lang_data_d *fld = (struct free_lang_data_d *) data;
4735 if (TREE_CODE (t) == TREE_LIST)
4738 /* Language specific nodes will be removed, so there is no need
4739 to gather anything under them. */
4740 if (is_lang_specific (t))
4748 /* Note that walk_tree does not traverse every possible field in
4749 decls, so we have to do our own traversals here. */
4750 add_tree_to_fld_list (t, fld);
4752 fld_worklist_push (DECL_NAME (t), fld);
4753 fld_worklist_push (DECL_CONTEXT (t), fld);
4754 fld_worklist_push (DECL_SIZE (t), fld);
4755 fld_worklist_push (DECL_SIZE_UNIT (t), fld);
4757 /* We are going to remove everything under DECL_INITIAL for
4758 TYPE_DECLs. No point walking them. */
4759 if (TREE_CODE (t) != TYPE_DECL)
4760 fld_worklist_push (DECL_INITIAL (t), fld);
4762 fld_worklist_push (DECL_ATTRIBUTES (t), fld);
4763 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
4765 if (TREE_CODE (t) == FUNCTION_DECL)
4767 fld_worklist_push (DECL_ARGUMENTS (t), fld);
4768 fld_worklist_push (DECL_RESULT (t), fld);
4770 else if (TREE_CODE (t) == TYPE_DECL)
4772 fld_worklist_push (DECL_ARGUMENT_FLD (t), fld);
4773 fld_worklist_push (DECL_VINDEX (t), fld);
4775 else if (TREE_CODE (t) == FIELD_DECL)
4777 fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
4778 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
4779 fld_worklist_push (DECL_QUALIFIER (t), fld);
4780 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
4781 fld_worklist_push (DECL_FCONTEXT (t), fld);
4783 else if (TREE_CODE (t) == VAR_DECL)
4785 fld_worklist_push (DECL_SECTION_NAME (t), fld);
4786 fld_worklist_push (DECL_COMDAT_GROUP (t), fld);
4789 if ((TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == PARM_DECL)
4790 && DECL_HAS_VALUE_EXPR_P (t))
4791 fld_worklist_push (DECL_VALUE_EXPR (t), fld);
4793 if (TREE_CODE (t) != FIELD_DECL
4794 && TREE_CODE (t) != TYPE_DECL)
4795 fld_worklist_push (TREE_CHAIN (t), fld);
4798 else if (TYPE_P (t))
4800 /* Note that walk_tree does not traverse every possible field in
4801 types, so we have to do our own traversals here. */
4802 add_tree_to_fld_list (t, fld);
4804 if (!RECORD_OR_UNION_TYPE_P (t))
4805 fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
4806 fld_worklist_push (TYPE_SIZE (t), fld);
4807 fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
4808 fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
4809 fld_worklist_push (TYPE_POINTER_TO (t), fld);
4810 fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
4811 fld_worklist_push (TYPE_NAME (t), fld);
4812 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
4813 them and thus do not and want not to reach unused pointer types
4815 if (!POINTER_TYPE_P (t))
4816 fld_worklist_push (TYPE_MINVAL (t), fld);
4817 if (!RECORD_OR_UNION_TYPE_P (t))
4818 fld_worklist_push (TYPE_MAXVAL (t), fld);
4819 fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
4820 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
4821 do not and want not to reach unused variants this way. */
4822 fld_worklist_push (TYPE_CONTEXT (t), fld);
4823 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
4824 and want not to reach unused types this way. */
4826 if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
4830 for (i = 0; VEC_iterate (tree, BINFO_BASE_BINFOS (TYPE_BINFO (t)),
4832 fld_worklist_push (TREE_TYPE (tem), fld);
4833 tem = BINFO_VIRTUALS (TYPE_BINFO (t));
4835 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
4836 && TREE_CODE (tem) == TREE_LIST)
4839 fld_worklist_push (TREE_VALUE (tem), fld);
4840 tem = TREE_CHAIN (tem);
4844 if (RECORD_OR_UNION_TYPE_P (t))
4847 /* Push all TYPE_FIELDS - there can be interleaving interesting
4848 and non-interesting things. */
4849 tem = TYPE_FIELDS (t);
4852 if (TREE_CODE (tem) == FIELD_DECL)
4853 fld_worklist_push (tem, fld);
4854 tem = TREE_CHAIN (tem);
4858 fld_worklist_push (TREE_CHAIN (t), fld);
4861 else if (TREE_CODE (t) == BLOCK)
4864 for (tem = BLOCK_VARS (t); tem; tem = TREE_CHAIN (tem))
4865 fld_worklist_push (tem, fld);
4866 for (tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
4867 fld_worklist_push (tem, fld);
4868 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
4871 if (TREE_CODE (t) != IDENTIFIER_NODE)
4872 fld_worklist_push (TREE_TYPE (t), fld);
4878 /* Find decls and types in T. */
4881 find_decls_types (tree t, struct free_lang_data_d *fld)
4885 if (!pointer_set_contains (fld->pset, t))
4886 walk_tree (&t, find_decls_types_r, fld, fld->pset);
4887 if (VEC_empty (tree, fld->worklist))
4889 t = VEC_pop (tree, fld->worklist);
4893 /* Translate all the types in LIST with the corresponding runtime
4897 get_eh_types_for_runtime (tree list)
4901 if (list == NULL_TREE)
4904 head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
4906 list = TREE_CHAIN (list);
4909 tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
4910 TREE_CHAIN (prev) = n;
4911 prev = TREE_CHAIN (prev);
4912 list = TREE_CHAIN (list);
4919 /* Find decls and types referenced in EH region R and store them in
4920 FLD->DECLS and FLD->TYPES. */
4923 find_decls_types_in_eh_region (eh_region r, struct free_lang_data_d *fld)
4934 /* The types referenced in each catch must first be changed to the
4935 EH types used at runtime. This removes references to FE types
4937 for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
4939 c->type_list = get_eh_types_for_runtime (c->type_list);
4940 walk_tree (&c->type_list, find_decls_types_r, fld, fld->pset);
4945 case ERT_ALLOWED_EXCEPTIONS:
4946 r->u.allowed.type_list
4947 = get_eh_types_for_runtime (r->u.allowed.type_list);
4948 walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, fld->pset);
4951 case ERT_MUST_NOT_THROW:
4952 walk_tree (&r->u.must_not_throw.failure_decl,
4953 find_decls_types_r, fld, fld->pset);
4959 /* Find decls and types referenced in cgraph node N and store them in
4960 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
4961 look for *every* kind of DECL and TYPE node reachable from N,
4962 including those embedded inside types and decls (i.e,, TYPE_DECLs,
4963 NAMESPACE_DECLs, etc). */
4966 find_decls_types_in_node (struct cgraph_node *n, struct free_lang_data_d *fld)
4969 struct function *fn;
4973 find_decls_types (n->decl, fld);
4975 if (!gimple_has_body_p (n->decl))
4978 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
4980 fn = DECL_STRUCT_FUNCTION (n->decl);
4982 /* Traverse locals. */
4983 FOR_EACH_LOCAL_DECL (fn, ix, t)
4984 find_decls_types (t, fld);
4986 /* Traverse EH regions in FN. */
4989 FOR_ALL_EH_REGION_FN (r, fn)
4990 find_decls_types_in_eh_region (r, fld);
4993 /* Traverse every statement in FN. */
4994 FOR_EACH_BB_FN (bb, fn)
4996 gimple_stmt_iterator si;
4999 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
5001 gimple phi = gsi_stmt (si);
5003 for (i = 0; i < gimple_phi_num_args (phi); i++)
5005 tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
5006 find_decls_types (*arg_p, fld);
5010 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
5012 gimple stmt = gsi_stmt (si);
5014 for (i = 0; i < gimple_num_ops (stmt); i++)
5016 tree arg = gimple_op (stmt, i);
5017 find_decls_types (arg, fld);
5024 /* Find decls and types referenced in varpool node N and store them in
5025 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5026 look for *every* kind of DECL and TYPE node reachable from N,
5027 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5028 NAMESPACE_DECLs, etc). */
5031 find_decls_types_in_var (struct varpool_node *v, struct free_lang_data_d *fld)
5033 find_decls_types (v->decl, fld);
5036 /* If T needs an assembler name, have one created for it. */
5039 assign_assembler_name_if_neeeded (tree t)
5041 if (need_assembler_name_p (t))
5043 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5044 diagnostics that use input_location to show locus
5045 information. The problem here is that, at this point,
5046 input_location is generally anchored to the end of the file
5047 (since the parser is long gone), so we don't have a good
5048 position to pin it to.
5050 To alleviate this problem, this uses the location of T's
5051 declaration. Examples of this are
5052 testsuite/g++.dg/template/cond2.C and
5053 testsuite/g++.dg/template/pr35240.C. */
5054 location_t saved_location = input_location;
5055 input_location = DECL_SOURCE_LOCATION (t);
5057 decl_assembler_name (t);
5059 input_location = saved_location;
5064 /* Free language specific information for every operand and expression
5065 in every node of the call graph. This process operates in three stages:
5067 1- Every callgraph node and varpool node is traversed looking for
5068 decls and types embedded in them. This is a more exhaustive
5069 search than that done by find_referenced_vars, because it will
5070 also collect individual fields, decls embedded in types, etc.
5072 2- All the decls found are sent to free_lang_data_in_decl.
5074 3- All the types found are sent to free_lang_data_in_type.
5076 The ordering between decls and types is important because
5077 free_lang_data_in_decl sets assembler names, which includes
5078 mangling. So types cannot be freed up until assembler names have
5082 free_lang_data_in_cgraph (void)
5084 struct cgraph_node *n;
5085 struct varpool_node *v;
5086 struct free_lang_data_d fld;
5091 /* Initialize sets and arrays to store referenced decls and types. */
5092 fld.pset = pointer_set_create ();
5093 fld.worklist = NULL;
5094 fld.decls = VEC_alloc (tree, heap, 100);
5095 fld.types = VEC_alloc (tree, heap, 100);
5097 /* Find decls and types in the body of every function in the callgraph. */
5098 for (n = cgraph_nodes; n; n = n->next)
5099 find_decls_types_in_node (n, &fld);
5101 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
5102 find_decls_types (p->decl, &fld);
5104 /* Find decls and types in every varpool symbol. */
5105 for (v = varpool_nodes; v; v = v->next)
5106 find_decls_types_in_var (v, &fld);
5108 /* Set the assembler name on every decl found. We need to do this
5109 now because free_lang_data_in_decl will invalidate data needed
5110 for mangling. This breaks mangling on interdependent decls. */
5111 FOR_EACH_VEC_ELT (tree, fld.decls, i, t)
5112 assign_assembler_name_if_neeeded (t);
5114 /* Traverse every decl found freeing its language data. */
5115 FOR_EACH_VEC_ELT (tree, fld.decls, i, t)
5116 free_lang_data_in_decl (t);
5118 /* Traverse every type found freeing its language data. */
5119 FOR_EACH_VEC_ELT (tree, fld.types, i, t)
5120 free_lang_data_in_type (t);
5122 pointer_set_destroy (fld.pset);
5123 VEC_free (tree, heap, fld.worklist);
5124 VEC_free (tree, heap, fld.decls);
5125 VEC_free (tree, heap, fld.types);
5129 /* Free resources that are used by FE but are not needed once they are done. */
5132 free_lang_data (void)
5136 /* If we are the LTO frontend we have freed lang-specific data already. */
5138 || !flag_generate_lto)
5141 /* Allocate and assign alias sets to the standard integer types
5142 while the slots are still in the way the frontends generated them. */
5143 for (i = 0; i < itk_none; ++i)
5144 if (integer_types[i])
5145 TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
5147 /* Traverse the IL resetting language specific information for
5148 operands, expressions, etc. */
5149 free_lang_data_in_cgraph ();
5151 /* Create gimple variants for common types. */
5152 ptrdiff_type_node = integer_type_node;
5153 fileptr_type_node = ptr_type_node;
5154 if (TREE_CODE (boolean_type_node) != BOOLEAN_TYPE
5155 || (TYPE_MODE (boolean_type_node)
5156 != mode_for_size (BOOL_TYPE_SIZE, MODE_INT, 0))
5157 || TYPE_PRECISION (boolean_type_node) != 1
5158 || !TYPE_UNSIGNED (boolean_type_node))
5160 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
5161 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
5162 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
5163 TYPE_PRECISION (boolean_type_node) = 1;
5164 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
5165 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
5168 /* Unify char_type_node with its properly signed variant. */
5169 if (TYPE_UNSIGNED (char_type_node))
5170 unsigned_char_type_node = char_type_node;
5172 signed_char_type_node = char_type_node;
5174 /* Reset some langhooks. Do not reset types_compatible_p, it may
5175 still be used indirectly via the get_alias_set langhook. */
5176 lang_hooks.callgraph.analyze_expr = NULL;
5177 lang_hooks.dwarf_name = lhd_dwarf_name;
5178 lang_hooks.decl_printable_name = gimple_decl_printable_name;
5179 lang_hooks.set_decl_assembler_name = lhd_set_decl_assembler_name;
5181 /* Reset diagnostic machinery. */
5182 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
5183 diagnostic_finalizer (global_dc) = default_diagnostic_finalizer;
5184 diagnostic_format_decoder (global_dc) = default_tree_printer;
5190 struct simple_ipa_opt_pass pass_ipa_free_lang_data =
5194 "*free_lang_data", /* name */
5196 free_lang_data, /* execute */
5199 0, /* static_pass_number */
5200 TV_IPA_FREE_LANG_DATA, /* tv_id */
5201 0, /* properties_required */
5202 0, /* properties_provided */
5203 0, /* properties_destroyed */
5204 0, /* todo_flags_start */
5205 TODO_ggc_collect /* todo_flags_finish */
5209 /* Return nonzero if IDENT is a valid name for attribute ATTR,
5212 We try both `text' and `__text__', ATTR may be either one. */
5213 /* ??? It might be a reasonable simplification to require ATTR to be only
5214 `text'. One might then also require attribute lists to be stored in
5215 their canonicalized form. */
5218 is_attribute_with_length_p (const char *attr, int attr_len, const_tree ident)
5223 if (TREE_CODE (ident) != IDENTIFIER_NODE)
5226 p = IDENTIFIER_POINTER (ident);
5227 ident_len = IDENTIFIER_LENGTH (ident);
5229 if (ident_len == attr_len
5230 && strcmp (attr, p) == 0)
5233 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
5236 gcc_assert (attr[1] == '_');
5237 gcc_assert (attr[attr_len - 2] == '_');
5238 gcc_assert (attr[attr_len - 1] == '_');
5239 if (ident_len == attr_len - 4
5240 && strncmp (attr + 2, p, attr_len - 4) == 0)
5245 if (ident_len == attr_len + 4
5246 && p[0] == '_' && p[1] == '_'
5247 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
5248 && strncmp (attr, p + 2, attr_len) == 0)
5255 /* Return nonzero if IDENT is a valid name for attribute ATTR,
5258 We try both `text' and `__text__', ATTR may be either one. */
5261 is_attribute_p (const char *attr, const_tree ident)
5263 return is_attribute_with_length_p (attr, strlen (attr), ident);
5266 /* Given an attribute name and a list of attributes, return a pointer to the
5267 attribute's list element if the attribute is part of the list, or NULL_TREE
5268 if not found. If the attribute appears more than once, this only
5269 returns the first occurrence; the TREE_CHAIN of the return value should
5270 be passed back in if further occurrences are wanted. */
5273 lookup_attribute (const char *attr_name, tree list)
5276 size_t attr_len = strlen (attr_name);
5278 for (l = list; l; l = TREE_CHAIN (l))
5280 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
5281 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
5287 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5291 remove_attribute (const char *attr_name, tree list)
5294 size_t attr_len = strlen (attr_name);
5296 for (p = &list; *p; )
5299 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
5300 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
5301 *p = TREE_CHAIN (l);
5303 p = &TREE_CHAIN (l);
5309 /* Return an attribute list that is the union of a1 and a2. */
5312 merge_attributes (tree a1, tree a2)
5316 /* Either one unset? Take the set one. */
5318 if ((attributes = a1) == 0)
5321 /* One that completely contains the other? Take it. */
5323 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
5325 if (attribute_list_contained (a2, a1))
5329 /* Pick the longest list, and hang on the other list. */
5331 if (list_length (a1) < list_length (a2))
5332 attributes = a2, a2 = a1;
5334 for (; a2 != 0; a2 = TREE_CHAIN (a2))
5337 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
5339 a != NULL_TREE && !attribute_value_equal (a, a2);
5340 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
5345 a1 = copy_node (a2);
5346 TREE_CHAIN (a1) = attributes;
5355 /* Given types T1 and T2, merge their attributes and return
5359 merge_type_attributes (tree t1, tree t2)
5361 return merge_attributes (TYPE_ATTRIBUTES (t1),
5362 TYPE_ATTRIBUTES (t2));
5365 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5369 merge_decl_attributes (tree olddecl, tree newdecl)
5371 return merge_attributes (DECL_ATTRIBUTES (olddecl),
5372 DECL_ATTRIBUTES (newdecl));
5375 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5377 /* Specialization of merge_decl_attributes for various Windows targets.
5379 This handles the following situation:
5381 __declspec (dllimport) int foo;
5384 The second instance of `foo' nullifies the dllimport. */
5387 merge_dllimport_decl_attributes (tree old, tree new_tree)
5390 int delete_dllimport_p = 1;
5392 /* What we need to do here is remove from `old' dllimport if it doesn't
5393 appear in `new'. dllimport behaves like extern: if a declaration is
5394 marked dllimport and a definition appears later, then the object
5395 is not dllimport'd. We also remove a `new' dllimport if the old list
5396 contains dllexport: dllexport always overrides dllimport, regardless
5397 of the order of declaration. */
5398 if (!VAR_OR_FUNCTION_DECL_P (new_tree))
5399 delete_dllimport_p = 0;
5400 else if (DECL_DLLIMPORT_P (new_tree)
5401 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
5403 DECL_DLLIMPORT_P (new_tree) = 0;
5404 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
5405 "dllimport ignored", new_tree);
5407 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree))
5409 /* Warn about overriding a symbol that has already been used, e.g.:
5410 extern int __attribute__ ((dllimport)) foo;
5411 int* bar () {return &foo;}
5414 if (TREE_USED (old))
5416 warning (0, "%q+D redeclared without dllimport attribute "
5417 "after being referenced with dll linkage", new_tree);
5418 /* If we have used a variable's address with dllimport linkage,
5419 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5420 decl may already have had TREE_CONSTANT computed.
5421 We still remove the attribute so that assembler code refers
5422 to '&foo rather than '_imp__foo'. */
5423 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
5424 DECL_DLLIMPORT_P (new_tree) = 1;
5427 /* Let an inline definition silently override the external reference,
5428 but otherwise warn about attribute inconsistency. */
5429 else if (TREE_CODE (new_tree) == VAR_DECL
5430 || !DECL_DECLARED_INLINE_P (new_tree))
5431 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
5432 "previous dllimport ignored", new_tree);
5435 delete_dllimport_p = 0;
5437 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree));
5439 if (delete_dllimport_p)
5442 const size_t attr_len = strlen ("dllimport");
5444 /* Scan the list for dllimport and delete it. */
5445 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
5447 if (is_attribute_with_length_p ("dllimport", attr_len,
5450 if (prev == NULL_TREE)
5453 TREE_CHAIN (prev) = TREE_CHAIN (t);
5462 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5463 struct attribute_spec.handler. */
5466 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
5472 /* These attributes may apply to structure and union types being created,
5473 but otherwise should pass to the declaration involved. */
5476 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
5477 | (int) ATTR_FLAG_ARRAY_NEXT))
5479 *no_add_attrs = true;
5480 return tree_cons (name, args, NULL_TREE);
5482 if (TREE_CODE (node) == RECORD_TYPE
5483 || TREE_CODE (node) == UNION_TYPE)
5485 node = TYPE_NAME (node);
5491 warning (OPT_Wattributes, "%qE attribute ignored",
5493 *no_add_attrs = true;
5498 if (TREE_CODE (node) != FUNCTION_DECL
5499 && TREE_CODE (node) != VAR_DECL
5500 && TREE_CODE (node) != TYPE_DECL)
5502 *no_add_attrs = true;
5503 warning (OPT_Wattributes, "%qE attribute ignored",
5508 if (TREE_CODE (node) == TYPE_DECL
5509 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE
5510 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE)
5512 *no_add_attrs = true;
5513 warning (OPT_Wattributes, "%qE attribute ignored",
5518 is_dllimport = is_attribute_p ("dllimport", name);
5520 /* Report error on dllimport ambiguities seen now before they cause
5524 /* Honor any target-specific overrides. */
5525 if (!targetm.valid_dllimport_attribute_p (node))
5526 *no_add_attrs = true;
5528 else if (TREE_CODE (node) == FUNCTION_DECL
5529 && DECL_DECLARED_INLINE_P (node))
5531 warning (OPT_Wattributes, "inline function %q+D declared as "
5532 " dllimport: attribute ignored", node);
5533 *no_add_attrs = true;
5535 /* Like MS, treat definition of dllimported variables and
5536 non-inlined functions on declaration as syntax errors. */
5537 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
5539 error ("function %q+D definition is marked dllimport", node);
5540 *no_add_attrs = true;
5543 else if (TREE_CODE (node) == VAR_DECL)
5545 if (DECL_INITIAL (node))
5547 error ("variable %q+D definition is marked dllimport",
5549 *no_add_attrs = true;
5552 /* `extern' needn't be specified with dllimport.
5553 Specify `extern' now and hope for the best. Sigh. */
5554 DECL_EXTERNAL (node) = 1;
5555 /* Also, implicitly give dllimport'd variables declared within
5556 a function global scope, unless declared static. */
5557 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
5558 TREE_PUBLIC (node) = 1;
5561 if (*no_add_attrs == false)
5562 DECL_DLLIMPORT_P (node) = 1;
5564 else if (TREE_CODE (node) == FUNCTION_DECL
5565 && DECL_DECLARED_INLINE_P (node)
5566 && flag_keep_inline_dllexport)
5567 /* An exported function, even if inline, must be emitted. */
5568 DECL_EXTERNAL (node) = 0;
5570 /* Report error if symbol is not accessible at global scope. */
5571 if (!TREE_PUBLIC (node)
5572 && (TREE_CODE (node) == VAR_DECL
5573 || TREE_CODE (node) == FUNCTION_DECL))
5575 error ("external linkage required for symbol %q+D because of "
5576 "%qE attribute", node, name);
5577 *no_add_attrs = true;
5580 /* A dllexport'd entity must have default visibility so that other
5581 program units (shared libraries or the main executable) can see
5582 it. A dllimport'd entity must have default visibility so that
5583 the linker knows that undefined references within this program
5584 unit can be resolved by the dynamic linker. */
5587 if (DECL_VISIBILITY_SPECIFIED (node)
5588 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT)
5589 error ("%qE implies default visibility, but %qD has already "
5590 "been declared with a different visibility",
5592 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT;
5593 DECL_VISIBILITY_SPECIFIED (node) = 1;
5599 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
5601 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5602 of the various TYPE_QUAL values. */
5605 set_type_quals (tree type, int type_quals)
5607 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5608 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5609 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5610 TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5613 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5616 check_qualified_type (const_tree cand, const_tree base, int type_quals)
5618 return (TYPE_QUALS (cand) == type_quals
5619 && TYPE_NAME (cand) == TYPE_NAME (base)
5620 /* Apparently this is needed for Objective-C. */
5621 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5622 /* Check alignment. */
5623 && TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5624 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5625 TYPE_ATTRIBUTES (base)));
5628 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5631 check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5633 return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5634 && TYPE_NAME (cand) == TYPE_NAME (base)
5635 /* Apparently this is needed for Objective-C. */
5636 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5637 /* Check alignment. */
5638 && TYPE_ALIGN (cand) == align
5639 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5640 TYPE_ATTRIBUTES (base)));
5643 /* Return a version of the TYPE, qualified as indicated by the
5644 TYPE_QUALS, if one exists. If no qualified version exists yet,
5645 return NULL_TREE. */
5648 get_qualified_type (tree type, int type_quals)
5652 if (TYPE_QUALS (type) == type_quals)
5655 /* Search the chain of variants to see if there is already one there just
5656 like the one we need to have. If so, use that existing one. We must
5657 preserve the TYPE_NAME, since there is code that depends on this. */
5658 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5659 if (check_qualified_type (t, type, type_quals))
5665 /* Like get_qualified_type, but creates the type if it does not
5666 exist. This function never returns NULL_TREE. */
5669 build_qualified_type (tree type, int type_quals)
5673 /* See if we already have the appropriate qualified variant. */
5674 t = get_qualified_type (type, type_quals);
5676 /* If not, build it. */
5679 t = build_variant_type_copy (type);
5680 set_type_quals (t, type_quals);
5682 if (TYPE_STRUCTURAL_EQUALITY_P (type))
5683 /* Propagate structural equality. */
5684 SET_TYPE_STRUCTURAL_EQUALITY (t);
5685 else if (TYPE_CANONICAL (type) != type)
5686 /* Build the underlying canonical type, since it is different
5688 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type),
5691 /* T is its own canonical type. */
5692 TYPE_CANONICAL (t) = t;
5699 /* Create a variant of type T with alignment ALIGN. */
5702 build_aligned_type (tree type, unsigned int align)
5706 if (TYPE_PACKED (type)
5707 || TYPE_ALIGN (type) == align)
5710 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5711 if (check_aligned_type (t, type, align))
5714 t = build_variant_type_copy (type);
5715 TYPE_ALIGN (t) = align;
5720 /* Create a new distinct copy of TYPE. The new type is made its own
5721 MAIN_VARIANT. If TYPE requires structural equality checks, the
5722 resulting type requires structural equality checks; otherwise, its
5723 TYPE_CANONICAL points to itself. */
5726 build_distinct_type_copy (tree type)
5728 tree t = copy_node (type);
5730 TYPE_POINTER_TO (t) = 0;
5731 TYPE_REFERENCE_TO (t) = 0;
5733 /* Set the canonical type either to a new equivalence class, or
5734 propagate the need for structural equality checks. */
5735 if (TYPE_STRUCTURAL_EQUALITY_P (type))
5736 SET_TYPE_STRUCTURAL_EQUALITY (t);
5738 TYPE_CANONICAL (t) = t;
5740 /* Make it its own variant. */
5741 TYPE_MAIN_VARIANT (t) = t;
5742 TYPE_NEXT_VARIANT (t) = 0;
5744 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5745 whose TREE_TYPE is not t. This can also happen in the Ada
5746 frontend when using subtypes. */
5751 /* Create a new variant of TYPE, equivalent but distinct. This is so
5752 the caller can modify it. TYPE_CANONICAL for the return type will
5753 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5754 are considered equal by the language itself (or that both types
5755 require structural equality checks). */
5758 build_variant_type_copy (tree type)
5760 tree t, m = TYPE_MAIN_VARIANT (type);
5762 t = build_distinct_type_copy (type);
5764 /* Since we're building a variant, assume that it is a non-semantic
5765 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5766 TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5768 /* Add the new type to the chain of variants of TYPE. */
5769 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5770 TYPE_NEXT_VARIANT (m) = t;
5771 TYPE_MAIN_VARIANT (t) = m;
5776 /* Return true if the from tree in both tree maps are equal. */
5779 tree_map_base_eq (const void *va, const void *vb)
5781 const struct tree_map_base *const a = (const struct tree_map_base *) va,
5782 *const b = (const struct tree_map_base *) vb;
5783 return (a->from == b->from);
5786 /* Hash a from tree in a tree_base_map. */
5789 tree_map_base_hash (const void *item)
5791 return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5794 /* Return true if this tree map structure is marked for garbage collection
5795 purposes. We simply return true if the from tree is marked, so that this
5796 structure goes away when the from tree goes away. */
5799 tree_map_base_marked_p (const void *p)
5801 return ggc_marked_p (((const struct tree_map_base *) p)->from);
5804 /* Hash a from tree in a tree_map. */
5807 tree_map_hash (const void *item)
5809 return (((const struct tree_map *) item)->hash);
5812 /* Hash a from tree in a tree_decl_map. */
5815 tree_decl_map_hash (const void *item)
5817 return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5820 /* Return the initialization priority for DECL. */
5823 decl_init_priority_lookup (tree decl)
5825 struct tree_priority_map *h;
5826 struct tree_map_base in;
5828 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
5830 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
5831 return h ? h->init : DEFAULT_INIT_PRIORITY;
5834 /* Return the finalization priority for DECL. */
5837 decl_fini_priority_lookup (tree decl)
5839 struct tree_priority_map *h;
5840 struct tree_map_base in;
5842 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
5844 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
5845 return h ? h->fini : DEFAULT_INIT_PRIORITY;
5848 /* Return the initialization and finalization priority information for
5849 DECL. If there is no previous priority information, a freshly
5850 allocated structure is returned. */
5852 static struct tree_priority_map *
5853 decl_priority_info (tree decl)
5855 struct tree_priority_map in;
5856 struct tree_priority_map *h;
5859 in.base.from = decl;
5860 loc = htab_find_slot (init_priority_for_decl, &in, INSERT);
5861 h = (struct tree_priority_map *) *loc;
5864 h = ggc_alloc_cleared_tree_priority_map ();
5866 h->base.from = decl;
5867 h->init = DEFAULT_INIT_PRIORITY;
5868 h->fini = DEFAULT_INIT_PRIORITY;
5874 /* Set the initialization priority for DECL to PRIORITY. */
5877 decl_init_priority_insert (tree decl, priority_type priority)
5879 struct tree_priority_map *h;
5881 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
5882 if (priority == DEFAULT_INIT_PRIORITY)
5884 h = decl_priority_info (decl);
5888 /* Set the finalization priority for DECL to PRIORITY. */
5891 decl_fini_priority_insert (tree decl, priority_type priority)
5893 struct tree_priority_map *h;
5895 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
5896 if (priority == DEFAULT_INIT_PRIORITY)
5898 h = decl_priority_info (decl);
5902 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
5905 print_debug_expr_statistics (void)
5907 fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
5908 (long) htab_size (debug_expr_for_decl),
5909 (long) htab_elements (debug_expr_for_decl),
5910 htab_collisions (debug_expr_for_decl));
5913 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
5916 print_value_expr_statistics (void)
5918 fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
5919 (long) htab_size (value_expr_for_decl),
5920 (long) htab_elements (value_expr_for_decl),
5921 htab_collisions (value_expr_for_decl));
5924 /* Lookup a debug expression for FROM, and return it if we find one. */
5927 decl_debug_expr_lookup (tree from)
5929 struct tree_decl_map *h, in;
5930 in.base.from = from;
5932 h = (struct tree_decl_map *)
5933 htab_find_with_hash (debug_expr_for_decl, &in, DECL_UID (from));
5939 /* Insert a mapping FROM->TO in the debug expression hashtable. */
5942 decl_debug_expr_insert (tree from, tree to)
5944 struct tree_decl_map *h;
5947 h = ggc_alloc_tree_decl_map ();
5948 h->base.from = from;
5950 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, DECL_UID (from),
5952 *(struct tree_decl_map **) loc = h;
5955 /* Lookup a value expression for FROM, and return it if we find one. */
5958 decl_value_expr_lookup (tree from)
5960 struct tree_decl_map *h, in;
5961 in.base.from = from;
5963 h = (struct tree_decl_map *)
5964 htab_find_with_hash (value_expr_for_decl, &in, DECL_UID (from));
5970 /* Insert a mapping FROM->TO in the value expression hashtable. */
5973 decl_value_expr_insert (tree from, tree to)
5975 struct tree_decl_map *h;
5978 h = ggc_alloc_tree_decl_map ();
5979 h->base.from = from;
5981 loc = htab_find_slot_with_hash (value_expr_for_decl, h, DECL_UID (from),
5983 *(struct tree_decl_map **) loc = h;
5986 /* Hashing of types so that we don't make duplicates.
5987 The entry point is `type_hash_canon'. */
5989 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
5990 with types in the TREE_VALUE slots), by adding the hash codes
5991 of the individual types. */
5994 type_hash_list (const_tree list, hashval_t hashcode)
5998 for (tail = list; tail; tail = TREE_CHAIN (tail))
5999 if (TREE_VALUE (tail) != error_mark_node)
6000 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
6006 /* These are the Hashtable callback functions. */
6008 /* Returns true iff the types are equivalent. */
6011 type_hash_eq (const void *va, const void *vb)
6013 const struct type_hash *const a = (const struct type_hash *) va,
6014 *const b = (const struct type_hash *) vb;
6016 /* First test the things that are the same for all types. */
6017 if (a->hash != b->hash
6018 || TREE_CODE (a->type) != TREE_CODE (b->type)
6019 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6020 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6021 TYPE_ATTRIBUTES (b->type))
6022 || (TREE_CODE (a->type) != COMPLEX_TYPE
6023 && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6026 /* Be careful about comparing arrays before and after the element type
6027 has been completed; don't compare TYPE_ALIGN unless both types are
6029 if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6030 && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6031 || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6034 switch (TREE_CODE (a->type))
6039 case REFERENCE_TYPE:
6043 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
6046 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6047 && !(TYPE_VALUES (a->type)
6048 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6049 && TYPE_VALUES (b->type)
6050 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6051 && type_list_equal (TYPE_VALUES (a->type),
6052 TYPE_VALUES (b->type))))
6055 /* ... fall through ... */
6060 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6061 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6062 TYPE_MAX_VALUE (b->type)))
6063 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6064 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6065 TYPE_MIN_VALUE (b->type))));
6067 case FIXED_POINT_TYPE:
6068 return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6071 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6074 if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6075 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6076 || (TYPE_ARG_TYPES (a->type)
6077 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6078 && TYPE_ARG_TYPES (b->type)
6079 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6080 && type_list_equal (TYPE_ARG_TYPES (a->type),
6081 TYPE_ARG_TYPES (b->type)))))
6085 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
6089 case QUAL_UNION_TYPE:
6090 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6091 || (TYPE_FIELDS (a->type)
6092 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6093 && TYPE_FIELDS (b->type)
6094 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6095 && type_list_equal (TYPE_FIELDS (a->type),
6096 TYPE_FIELDS (b->type))));
6099 if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6100 || (TYPE_ARG_TYPES (a->type)
6101 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6102 && TYPE_ARG_TYPES (b->type)
6103 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6104 && type_list_equal (TYPE_ARG_TYPES (a->type),
6105 TYPE_ARG_TYPES (b->type))))
6113 if (lang_hooks.types.type_hash_eq != NULL)
6114 return lang_hooks.types.type_hash_eq (a->type, b->type);
6119 /* Return the cached hash value. */
6122 type_hash_hash (const void *item)
6124 return ((const struct type_hash *) item)->hash;
6127 /* Look in the type hash table for a type isomorphic to TYPE.
6128 If one is found, return it. Otherwise return 0. */
6131 type_hash_lookup (hashval_t hashcode, tree type)
6133 struct type_hash *h, in;
6135 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6136 must call that routine before comparing TYPE_ALIGNs. */
6142 h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in,
6149 /* Add an entry to the type-hash-table
6150 for a type TYPE whose hash code is HASHCODE. */
6153 type_hash_add (hashval_t hashcode, tree type)
6155 struct type_hash *h;
6158 h = ggc_alloc_type_hash ();
6161 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
6165 /* Given TYPE, and HASHCODE its hash code, return the canonical
6166 object for an identical type if one already exists.
6167 Otherwise, return TYPE, and record it as the canonical object.
6169 To use this function, first create a type of the sort you want.
6170 Then compute its hash code from the fields of the type that
6171 make it different from other similar types.
6172 Then call this function and use the value. */
6175 type_hash_canon (unsigned int hashcode, tree type)
6179 /* The hash table only contains main variants, so ensure that's what we're
6181 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6183 /* See if the type is in the hash table already. If so, return it.
6184 Otherwise, add the type. */
6185 t1 = type_hash_lookup (hashcode, type);
6188 #ifdef GATHER_STATISTICS
6189 tree_node_counts[(int) t_kind]--;
6190 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
6196 type_hash_add (hashcode, type);
6201 /* See if the data pointed to by the type hash table is marked. We consider
6202 it marked if the type is marked or if a debug type number or symbol
6203 table entry has been made for the type. */
6206 type_hash_marked_p (const void *p)
6208 const_tree const type = ((const struct type_hash *) p)->type;
6210 return ggc_marked_p (type);
6214 print_type_hash_statistics (void)
6216 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
6217 (long) htab_size (type_hash_table),
6218 (long) htab_elements (type_hash_table),
6219 htab_collisions (type_hash_table));
6222 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6223 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6224 by adding the hash codes of the individual attributes. */
6227 attribute_hash_list (const_tree list, hashval_t hashcode)
6231 for (tail = list; tail; tail = TREE_CHAIN (tail))
6232 /* ??? Do we want to add in TREE_VALUE too? */
6233 hashcode = iterative_hash_object
6234 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
6238 /* Given two lists of attributes, return true if list l2 is
6239 equivalent to l1. */
6242 attribute_list_equal (const_tree l1, const_tree l2)
6244 return attribute_list_contained (l1, l2)
6245 && attribute_list_contained (l2, l1);
6248 /* Given two lists of attributes, return true if list L2 is
6249 completely contained within L1. */
6250 /* ??? This would be faster if attribute names were stored in a canonicalized
6251 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6252 must be used to show these elements are equivalent (which they are). */
6253 /* ??? It's not clear that attributes with arguments will always be handled
6257 attribute_list_contained (const_tree l1, const_tree l2)
6261 /* First check the obvious, maybe the lists are identical. */
6265 /* Maybe the lists are similar. */
6266 for (t1 = l1, t2 = l2;
6268 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
6269 && TREE_VALUE (t1) == TREE_VALUE (t2);
6270 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
6272 /* Maybe the lists are equal. */
6273 if (t1 == 0 && t2 == 0)
6276 for (; t2 != 0; t2 = TREE_CHAIN (t2))
6279 /* This CONST_CAST is okay because lookup_attribute does not
6280 modify its argument and the return value is assigned to a
6282 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
6283 CONST_CAST_TREE(l1));
6284 attr != NULL_TREE && !attribute_value_equal (t2, attr);
6285 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
6289 if (attr == NULL_TREE)
6296 /* Given two lists of types
6297 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6298 return 1 if the lists contain the same types in the same order.
6299 Also, the TREE_PURPOSEs must match. */
6302 type_list_equal (const_tree l1, const_tree l2)
6306 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6307 if (TREE_VALUE (t1) != TREE_VALUE (t2)
6308 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6309 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6310 && (TREE_TYPE (TREE_PURPOSE (t1))
6311 == TREE_TYPE (TREE_PURPOSE (t2))))))
6317 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6318 given by TYPE. If the argument list accepts variable arguments,
6319 then this function counts only the ordinary arguments. */
6322 type_num_arguments (const_tree type)
6327 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6328 /* If the function does not take a variable number of arguments,
6329 the last element in the list will have type `void'. */
6330 if (VOID_TYPE_P (TREE_VALUE (t)))
6338 /* Nonzero if integer constants T1 and T2
6339 represent the same constant value. */
6342 tree_int_cst_equal (const_tree t1, const_tree t2)
6347 if (t1 == 0 || t2 == 0)
6350 if (TREE_CODE (t1) == INTEGER_CST
6351 && TREE_CODE (t2) == INTEGER_CST
6352 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
6353 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
6359 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6360 The precise way of comparison depends on their data type. */
6363 tree_int_cst_lt (const_tree t1, const_tree t2)
6368 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
6370 int t1_sgn = tree_int_cst_sgn (t1);
6371 int t2_sgn = tree_int_cst_sgn (t2);
6373 if (t1_sgn < t2_sgn)
6375 else if (t1_sgn > t2_sgn)
6377 /* Otherwise, both are non-negative, so we compare them as
6378 unsigned just in case one of them would overflow a signed
6381 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
6382 return INT_CST_LT (t1, t2);
6384 return INT_CST_LT_UNSIGNED (t1, t2);
6387 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6390 tree_int_cst_compare (const_tree t1, const_tree t2)
6392 if (tree_int_cst_lt (t1, t2))
6394 else if (tree_int_cst_lt (t2, t1))
6400 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6401 the host. If POS is zero, the value can be represented in a single
6402 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6403 be represented in a single unsigned HOST_WIDE_INT. */
6406 host_integerp (const_tree t, int pos)
6411 return (TREE_CODE (t) == INTEGER_CST
6412 && ((TREE_INT_CST_HIGH (t) == 0
6413 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
6414 || (! pos && TREE_INT_CST_HIGH (t) == -1
6415 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
6416 && (!TYPE_UNSIGNED (TREE_TYPE (t))
6417 || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
6418 && TYPE_IS_SIZETYPE (TREE_TYPE (t)))))
6419 || (pos && TREE_INT_CST_HIGH (t) == 0)));
6422 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6423 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6424 be non-negative. We must be able to satisfy the above conditions. */
6427 tree_low_cst (const_tree t, int pos)
6429 gcc_assert (host_integerp (t, pos));
6430 return TREE_INT_CST_LOW (t);
6433 /* Return the most significant bit of the integer constant T. */
6436 tree_int_cst_msb (const_tree t)
6440 unsigned HOST_WIDE_INT l;
6442 /* Note that using TYPE_PRECISION here is wrong. We care about the
6443 actual bits, not the (arbitrary) range of the type. */
6444 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
6445 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
6446 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
6447 return (l & 1) == 1;
6450 /* Return an indication of the sign of the integer constant T.
6451 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6452 Note that -1 will never be returned if T's type is unsigned. */
6455 tree_int_cst_sgn (const_tree t)
6457 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
6459 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6461 else if (TREE_INT_CST_HIGH (t) < 0)
6467 /* Return the minimum number of bits needed to represent VALUE in a
6468 signed or unsigned type, UNSIGNEDP says which. */
6471 tree_int_cst_min_precision (tree value, bool unsignedp)
6475 /* If the value is negative, compute its negative minus 1. The latter
6476 adjustment is because the absolute value of the largest negative value
6477 is one larger than the largest positive value. This is equivalent to
6478 a bit-wise negation, so use that operation instead. */
6480 if (tree_int_cst_sgn (value) < 0)
6481 value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6483 /* Return the number of bits needed, taking into account the fact
6484 that we need one more bit for a signed than unsigned type. */
6486 if (integer_zerop (value))
6489 log = tree_floor_log2 (value);
6491 return log + 1 + !unsignedp;
6494 /* Compare two constructor-element-type constants. Return 1 if the lists
6495 are known to be equal; otherwise return 0. */
6498 simple_cst_list_equal (const_tree l1, const_tree l2)
6500 while (l1 != NULL_TREE && l2 != NULL_TREE)
6502 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
6505 l1 = TREE_CHAIN (l1);
6506 l2 = TREE_CHAIN (l2);
6512 /* Return truthvalue of whether T1 is the same tree structure as T2.
6513 Return 1 if they are the same.
6514 Return 0 if they are understandably different.
6515 Return -1 if either contains tree structure not understood by
6519 simple_cst_equal (const_tree t1, const_tree t2)
6521 enum tree_code code1, code2;
6527 if (t1 == 0 || t2 == 0)
6530 code1 = TREE_CODE (t1);
6531 code2 = TREE_CODE (t2);
6533 if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6535 if (CONVERT_EXPR_CODE_P (code2)
6536 || code2 == NON_LVALUE_EXPR)
6537 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6539 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6542 else if (CONVERT_EXPR_CODE_P (code2)
6543 || code2 == NON_LVALUE_EXPR)
6544 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6552 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
6553 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
6556 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
6559 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6562 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6563 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6564 TREE_STRING_LENGTH (t1)));
6568 unsigned HOST_WIDE_INT idx;
6569 VEC(constructor_elt, gc) *v1 = CONSTRUCTOR_ELTS (t1);
6570 VEC(constructor_elt, gc) *v2 = CONSTRUCTOR_ELTS (t2);
6572 if (VEC_length (constructor_elt, v1) != VEC_length (constructor_elt, v2))
6575 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
6576 /* ??? Should we handle also fields here? */
6577 if (!simple_cst_equal (VEC_index (constructor_elt, v1, idx)->value,
6578 VEC_index (constructor_elt, v2, idx)->value))
6584 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6587 cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6590 if (call_expr_nargs (t1) != call_expr_nargs (t2))
6593 const_tree arg1, arg2;
6594 const_call_expr_arg_iterator iter1, iter2;
6595 for (arg1 = first_const_call_expr_arg (t1, &iter1),
6596 arg2 = first_const_call_expr_arg (t2, &iter2);
6598 arg1 = next_const_call_expr_arg (&iter1),
6599 arg2 = next_const_call_expr_arg (&iter2))
6601 cmp = simple_cst_equal (arg1, arg2);
6605 return arg1 == arg2;
6609 /* Special case: if either target is an unallocated VAR_DECL,
6610 it means that it's going to be unified with whatever the
6611 TARGET_EXPR is really supposed to initialize, so treat it
6612 as being equivalent to anything. */
6613 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6614 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6615 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6616 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6617 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6618 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6621 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6626 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6628 case WITH_CLEANUP_EXPR:
6629 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6633 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6636 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6637 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6651 /* This general rule works for most tree codes. All exceptions should be
6652 handled above. If this is a language-specific tree code, we can't
6653 trust what might be in the operand, so say we don't know
6655 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6658 switch (TREE_CODE_CLASS (code1))
6662 case tcc_comparison:
6663 case tcc_expression:
6667 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6669 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6681 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6682 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6683 than U, respectively. */
6686 compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6688 if (tree_int_cst_sgn (t) < 0)
6690 else if (TREE_INT_CST_HIGH (t) != 0)
6692 else if (TREE_INT_CST_LOW (t) == u)
6694 else if (TREE_INT_CST_LOW (t) < u)
6700 /* Return true if CODE represents an associative tree code. Otherwise
6703 associative_tree_code (enum tree_code code)
6722 /* Return true if CODE represents a commutative tree code. Otherwise
6725 commutative_tree_code (enum tree_code code)
6738 case UNORDERED_EXPR:
6742 case TRUTH_AND_EXPR:
6743 case TRUTH_XOR_EXPR:
6753 /* Return true if CODE represents a ternary tree code for which the
6754 first two operands are commutative. Otherwise return false. */
6756 commutative_ternary_tree_code (enum tree_code code)
6760 case WIDEN_MULT_PLUS_EXPR:
6761 case WIDEN_MULT_MINUS_EXPR:
6770 /* Generate a hash value for an expression. This can be used iteratively
6771 by passing a previous result as the VAL argument.
6773 This function is intended to produce the same hash for expressions which
6774 would compare equal using operand_equal_p. */
6777 iterative_hash_expr (const_tree t, hashval_t val)
6780 enum tree_code code;
6784 return iterative_hash_hashval_t (0, val);
6786 code = TREE_CODE (t);
6790 /* Alas, constants aren't shared, so we can't rely on pointer
6793 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
6794 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
6797 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
6799 return iterative_hash_hashval_t (val2, val);
6803 unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t));
6805 return iterative_hash_hashval_t (val2, val);
6808 return iterative_hash (TREE_STRING_POINTER (t),
6809 TREE_STRING_LENGTH (t), val);
6811 val = iterative_hash_expr (TREE_REALPART (t), val);
6812 return iterative_hash_expr (TREE_IMAGPART (t), val);
6814 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
6816 /* We can just compare by pointer. */
6817 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t), val);
6818 case PLACEHOLDER_EXPR:
6819 /* The node itself doesn't matter. */
6822 /* A list of expressions, for a CALL_EXPR or as the elements of a
6824 for (; t; t = TREE_CHAIN (t))
6825 val = iterative_hash_expr (TREE_VALUE (t), val);
6829 unsigned HOST_WIDE_INT idx;
6831 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
6833 val = iterative_hash_expr (field, val);
6834 val = iterative_hash_expr (value, val);
6840 /* The type of the second operand is relevant, except for
6841 its top-level qualifiers. */
6842 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t, 1)));
6844 val = iterative_hash_object (TYPE_HASH (type), val);
6846 /* We could use the standard hash computation from this point
6848 val = iterative_hash_object (code, val);
6849 val = iterative_hash_expr (TREE_OPERAND (t, 1), val);
6850 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
6854 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
6855 Otherwise nodes that compare equal according to operand_equal_p might
6856 get different hash codes. However, don't do this for machine specific
6857 or front end builtins, since the function code is overloaded in those
6859 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
6860 && built_in_decls[DECL_FUNCTION_CODE (t)])
6862 t = built_in_decls[DECL_FUNCTION_CODE (t)];
6863 code = TREE_CODE (t);
6867 tclass = TREE_CODE_CLASS (code);
6869 if (tclass == tcc_declaration)
6871 /* DECL's have a unique ID */
6872 val = iterative_hash_host_wide_int (DECL_UID (t), val);
6876 gcc_assert (IS_EXPR_CODE_CLASS (tclass));
6878 val = iterative_hash_object (code, val);
6880 /* Don't hash the type, that can lead to having nodes which
6881 compare equal according to operand_equal_p, but which
6882 have different hash codes. */
6883 if (CONVERT_EXPR_CODE_P (code)
6884 || code == NON_LVALUE_EXPR)
6886 /* Make sure to include signness in the hash computation. */
6887 val += TYPE_UNSIGNED (TREE_TYPE (t));
6888 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
6891 else if (commutative_tree_code (code))
6893 /* It's a commutative expression. We want to hash it the same
6894 however it appears. We do this by first hashing both operands
6895 and then rehashing based on the order of their independent
6897 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
6898 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
6902 t = one, one = two, two = t;
6904 val = iterative_hash_hashval_t (one, val);
6905 val = iterative_hash_hashval_t (two, val);
6908 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
6909 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
6916 /* Generate a hash value for a pair of expressions. This can be used
6917 iteratively by passing a previous result as the VAL argument.
6919 The same hash value is always returned for a given pair of expressions,
6920 regardless of the order in which they are presented. This is useful in
6921 hashing the operands of commutative functions. */
6924 iterative_hash_exprs_commutative (const_tree t1,
6925 const_tree t2, hashval_t val)
6927 hashval_t one = iterative_hash_expr (t1, 0);
6928 hashval_t two = iterative_hash_expr (t2, 0);
6932 t = one, one = two, two = t;
6933 val = iterative_hash_hashval_t (one, val);
6934 val = iterative_hash_hashval_t (two, val);
6939 /* Constructors for pointer, array and function types.
6940 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
6941 constructed by language-dependent code, not here.) */
6943 /* Construct, lay out and return the type of pointers to TO_TYPE with
6944 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
6945 reference all of memory. If such a type has already been
6946 constructed, reuse it. */
6949 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
6954 if (to_type == error_mark_node)
6955 return error_mark_node;
6957 /* If the pointed-to type has the may_alias attribute set, force
6958 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
6959 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
6960 can_alias_all = true;
6962 /* In some cases, languages will have things that aren't a POINTER_TYPE
6963 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
6964 In that case, return that type without regard to the rest of our
6967 ??? This is a kludge, but consistent with the way this function has
6968 always operated and there doesn't seem to be a good way to avoid this
6970 if (TYPE_POINTER_TO (to_type) != 0
6971 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
6972 return TYPE_POINTER_TO (to_type);
6974 /* First, if we already have a type for pointers to TO_TYPE and it's
6975 the proper mode, use it. */
6976 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
6977 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
6980 t = make_node (POINTER_TYPE);
6982 TREE_TYPE (t) = to_type;
6983 SET_TYPE_MODE (t, mode);
6984 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
6985 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
6986 TYPE_POINTER_TO (to_type) = t;
6988 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
6989 SET_TYPE_STRUCTURAL_EQUALITY (t);
6990 else if (TYPE_CANONICAL (to_type) != to_type)
6992 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
6993 mode, can_alias_all);
6995 /* Lay out the type. This function has many callers that are concerned
6996 with expression-construction, and this simplifies them all. */
7002 /* By default build pointers in ptr_mode. */
7005 build_pointer_type (tree to_type)
7007 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
7008 : TYPE_ADDR_SPACE (to_type);
7009 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
7010 return build_pointer_type_for_mode (to_type, pointer_mode, false);
7013 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7016 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
7021 if (to_type == error_mark_node)
7022 return error_mark_node;
7024 /* If the pointed-to type has the may_alias attribute set, force
7025 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7026 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7027 can_alias_all = true;
7029 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7030 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7031 In that case, return that type without regard to the rest of our
7034 ??? This is a kludge, but consistent with the way this function has
7035 always operated and there doesn't seem to be a good way to avoid this
7037 if (TYPE_REFERENCE_TO (to_type) != 0
7038 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7039 return TYPE_REFERENCE_TO (to_type);
7041 /* First, if we already have a type for pointers to TO_TYPE and it's
7042 the proper mode, use it. */
7043 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7044 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7047 t = make_node (REFERENCE_TYPE);
7049 TREE_TYPE (t) = to_type;
7050 SET_TYPE_MODE (t, mode);
7051 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7052 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7053 TYPE_REFERENCE_TO (to_type) = t;
7055 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
7056 SET_TYPE_STRUCTURAL_EQUALITY (t);
7057 else if (TYPE_CANONICAL (to_type) != to_type)
7059 = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7060 mode, can_alias_all);
7068 /* Build the node for the type of references-to-TO_TYPE by default
7072 build_reference_type (tree to_type)
7074 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
7075 : TYPE_ADDR_SPACE (to_type);
7076 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
7077 return build_reference_type_for_mode (to_type, pointer_mode, false);
7080 /* Build a type that is compatible with t but has no cv quals anywhere
7083 const char *const *const * -> char ***. */
7086 build_type_no_quals (tree t)
7088 switch (TREE_CODE (t))
7091 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
7093 TYPE_REF_CAN_ALIAS_ALL (t));
7094 case REFERENCE_TYPE:
7096 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
7098 TYPE_REF_CAN_ALIAS_ALL (t));
7100 return TYPE_MAIN_VARIANT (t);
7104 #define MAX_INT_CACHED_PREC \
7105 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7106 static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7108 /* Builds a signed or unsigned integer type of precision PRECISION.
7109 Used for C bitfields whose precision does not match that of
7110 built-in target types. */
7112 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7118 unsignedp = MAX_INT_CACHED_PREC + 1;
7120 if (precision <= MAX_INT_CACHED_PREC)
7122 itype = nonstandard_integer_type_cache[precision + unsignedp];
7127 itype = make_node (INTEGER_TYPE);
7128 TYPE_PRECISION (itype) = precision;
7131 fixup_unsigned_type (itype);
7133 fixup_signed_type (itype);
7136 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
7137 ret = type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
7138 if (precision <= MAX_INT_CACHED_PREC)
7139 nonstandard_integer_type_cache[precision + unsignedp] = ret;
7144 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7145 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7146 is true, reuse such a type that has already been constructed. */
7149 build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7151 tree itype = make_node (INTEGER_TYPE);
7152 hashval_t hashcode = 0;
7154 TREE_TYPE (itype) = type;
7156 TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7157 TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7159 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7160 SET_TYPE_MODE (itype, TYPE_MODE (type));
7161 TYPE_SIZE (itype) = TYPE_SIZE (type);
7162 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7163 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
7164 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7169 if ((TYPE_MIN_VALUE (itype)
7170 && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7171 || (TYPE_MAX_VALUE (itype)
7172 && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7174 /* Since we cannot reliably merge this type, we need to compare it using
7175 structural equality checks. */
7176 SET_TYPE_STRUCTURAL_EQUALITY (itype);
7180 hashcode = iterative_hash_expr (TYPE_MIN_VALUE (itype), hashcode);
7181 hashcode = iterative_hash_expr (TYPE_MAX_VALUE (itype), hashcode);
7182 hashcode = iterative_hash_hashval_t (TYPE_HASH (type), hashcode);
7183 itype = type_hash_canon (hashcode, itype);
7188 /* Wrapper around build_range_type_1 with SHARED set to true. */
7191 build_range_type (tree type, tree lowval, tree highval)
7193 return build_range_type_1 (type, lowval, highval, true);
7196 /* Wrapper around build_range_type_1 with SHARED set to false. */
7199 build_nonshared_range_type (tree type, tree lowval, tree highval)
7201 return build_range_type_1 (type, lowval, highval, false);
7204 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7205 MAXVAL should be the maximum value in the domain
7206 (one less than the length of the array).
7208 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7209 We don't enforce this limit, that is up to caller (e.g. language front end).
7210 The limit exists because the result is a signed type and we don't handle
7211 sizes that use more than one HOST_WIDE_INT. */
7214 build_index_type (tree maxval)
7216 return build_range_type (sizetype, size_zero_node, maxval);
7219 /* Return true if the debug information for TYPE, a subtype, should be emitted
7220 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7221 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7222 debug info and doesn't reflect the source code. */
7225 subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7227 tree base_type = TREE_TYPE (type), low, high;
7229 /* Subrange types have a base type which is an integral type. */
7230 if (!INTEGRAL_TYPE_P (base_type))
7233 /* Get the real bounds of the subtype. */
7234 if (lang_hooks.types.get_subrange_bounds)
7235 lang_hooks.types.get_subrange_bounds (type, &low, &high);
7238 low = TYPE_MIN_VALUE (type);
7239 high = TYPE_MAX_VALUE (type);
7242 /* If the type and its base type have the same representation and the same
7243 name, then the type is not a subrange but a copy of the base type. */
7244 if ((TREE_CODE (base_type) == INTEGER_TYPE
7245 || TREE_CODE (base_type) == BOOLEAN_TYPE)
7246 && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7247 && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7248 && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type)))
7250 tree type_name = TYPE_NAME (type);
7251 tree base_type_name = TYPE_NAME (base_type);
7253 if (type_name && TREE_CODE (type_name) == TYPE_DECL)
7254 type_name = DECL_NAME (type_name);
7256 if (base_type_name && TREE_CODE (base_type_name) == TYPE_DECL)
7257 base_type_name = DECL_NAME (base_type_name);
7259 if (type_name == base_type_name)
7270 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7271 and number of elements specified by the range of values of INDEX_TYPE.
7272 If SHARED is true, reuse such a type that has already been constructed. */
7275 build_array_type_1 (tree elt_type, tree index_type, bool shared)
7279 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7281 error ("arrays of functions are not meaningful");
7282 elt_type = integer_type_node;
7285 t = make_node (ARRAY_TYPE);
7286 TREE_TYPE (t) = elt_type;
7287 TYPE_DOMAIN (t) = index_type;
7288 TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7291 /* If the element type is incomplete at this point we get marked for
7292 structural equality. Do not record these types in the canonical
7294 if (TYPE_STRUCTURAL_EQUALITY_P (t))
7299 hashval_t hashcode = iterative_hash_object (TYPE_HASH (elt_type), 0);
7301 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
7302 t = type_hash_canon (hashcode, t);
7305 if (TYPE_CANONICAL (t) == t)
7307 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7308 || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
7309 SET_TYPE_STRUCTURAL_EQUALITY (t);
7310 else if (TYPE_CANONICAL (elt_type) != elt_type
7311 || (index_type && TYPE_CANONICAL (index_type) != index_type))
7313 = build_array_type_1 (TYPE_CANONICAL (elt_type),
7315 ? TYPE_CANONICAL (index_type) : NULL_TREE,
7322 /* Wrapper around build_array_type_1 with SHARED set to true. */
7325 build_array_type (tree elt_type, tree index_type)
7327 return build_array_type_1 (elt_type, index_type, true);
7330 /* Wrapper around build_array_type_1 with SHARED set to false. */
7333 build_nonshared_array_type (tree elt_type, tree index_type)
7335 return build_array_type_1 (elt_type, index_type, false);
7338 /* Recursively examines the array elements of TYPE, until a non-array
7339 element type is found. */
7342 strip_array_types (tree type)
7344 while (TREE_CODE (type) == ARRAY_TYPE)
7345 type = TREE_TYPE (type);
7350 /* Computes the canonical argument types from the argument type list
7353 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7354 on entry to this function, or if any of the ARGTYPES are
7357 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7358 true on entry to this function, or if any of the ARGTYPES are
7361 Returns a canonical argument list, which may be ARGTYPES when the
7362 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7363 true) or would not differ from ARGTYPES. */
7366 maybe_canonicalize_argtypes(tree argtypes,
7367 bool *any_structural_p,
7368 bool *any_noncanonical_p)
7371 bool any_noncanonical_argtypes_p = false;
7373 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7375 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7376 /* Fail gracefully by stating that the type is structural. */
7377 *any_structural_p = true;
7378 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7379 *any_structural_p = true;
7380 else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7381 || TREE_PURPOSE (arg))
7382 /* If the argument has a default argument, we consider it
7383 non-canonical even though the type itself is canonical.
7384 That way, different variants of function and method types
7385 with default arguments will all point to the variant with
7386 no defaults as their canonical type. */
7387 any_noncanonical_argtypes_p = true;
7390 if (*any_structural_p)
7393 if (any_noncanonical_argtypes_p)
7395 /* Build the canonical list of argument types. */
7396 tree canon_argtypes = NULL_TREE;
7397 bool is_void = false;
7399 for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7401 if (arg == void_list_node)
7404 canon_argtypes = tree_cons (NULL_TREE,
7405 TYPE_CANONICAL (TREE_VALUE (arg)),
7409 canon_argtypes = nreverse (canon_argtypes);
7411 canon_argtypes = chainon (canon_argtypes, void_list_node);
7413 /* There is a non-canonical type. */
7414 *any_noncanonical_p = true;
7415 return canon_argtypes;
7418 /* The canonical argument types are the same as ARGTYPES. */
7422 /* Construct, lay out and return
7423 the type of functions returning type VALUE_TYPE
7424 given arguments of types ARG_TYPES.
7425 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7426 are data type nodes for the arguments of the function.
7427 If such a type has already been constructed, reuse it. */
7430 build_function_type (tree value_type, tree arg_types)
7433 hashval_t hashcode = 0;
7434 bool any_structural_p, any_noncanonical_p;
7435 tree canon_argtypes;
7437 if (TREE_CODE (value_type) == FUNCTION_TYPE)
7439 error ("function return type cannot be function");
7440 value_type = integer_type_node;
7443 /* Make a node of the sort we want. */
7444 t = make_node (FUNCTION_TYPE);
7445 TREE_TYPE (t) = value_type;
7446 TYPE_ARG_TYPES (t) = arg_types;
7448 /* If we already have such a type, use the old one. */
7449 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
7450 hashcode = type_hash_list (arg_types, hashcode);
7451 t = type_hash_canon (hashcode, t);
7453 /* Set up the canonical type. */
7454 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7455 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7456 canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7458 &any_noncanonical_p);
7459 if (any_structural_p)
7460 SET_TYPE_STRUCTURAL_EQUALITY (t);
7461 else if (any_noncanonical_p)
7462 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7465 if (!COMPLETE_TYPE_P (t))
7470 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */
7473 build_function_type_skip_args (tree orig_type, bitmap args_to_skip)
7475 tree new_type = NULL;
7476 tree args, new_args = NULL, t;
7480 for (args = TYPE_ARG_TYPES (orig_type); args && args != void_list_node;
7481 args = TREE_CHAIN (args), i++)
7482 if (!bitmap_bit_p (args_to_skip, i))
7483 new_args = tree_cons (NULL_TREE, TREE_VALUE (args), new_args);
7485 new_reversed = nreverse (new_args);
7489 TREE_CHAIN (new_args) = void_list_node;
7491 new_reversed = void_list_node;
7494 /* Use copy_node to preserve as much as possible from original type
7495 (debug info, attribute lists etc.)
7496 Exception is METHOD_TYPEs must have THIS argument.
7497 When we are asked to remove it, we need to build new FUNCTION_TYPE
7499 if (TREE_CODE (orig_type) != METHOD_TYPE
7500 || !bitmap_bit_p (args_to_skip, 0))
7502 new_type = build_distinct_type_copy (orig_type);
7503 TYPE_ARG_TYPES (new_type) = new_reversed;
7508 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
7510 TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
7513 /* This is a new type, not a copy of an old type. Need to reassociate
7514 variants. We can handle everything except the main variant lazily. */
7515 t = TYPE_MAIN_VARIANT (orig_type);
7518 TYPE_MAIN_VARIANT (new_type) = t;
7519 TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t);
7520 TYPE_NEXT_VARIANT (t) = new_type;
7524 TYPE_MAIN_VARIANT (new_type) = new_type;
7525 TYPE_NEXT_VARIANT (new_type) = NULL;
7530 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
7532 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
7533 linked by TREE_CHAIN directly. The caller is responsible for eliminating
7534 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
7537 build_function_decl_skip_args (tree orig_decl, bitmap args_to_skip)
7539 tree new_decl = copy_node (orig_decl);
7542 new_type = TREE_TYPE (orig_decl);
7543 if (prototype_p (new_type))
7544 new_type = build_function_type_skip_args (new_type, args_to_skip);
7545 TREE_TYPE (new_decl) = new_type;
7547 /* For declarations setting DECL_VINDEX (i.e. methods)
7548 we expect first argument to be THIS pointer. */
7549 if (bitmap_bit_p (args_to_skip, 0))
7550 DECL_VINDEX (new_decl) = NULL_TREE;
7552 /* When signature changes, we need to clear builtin info. */
7553 if (DECL_BUILT_IN (new_decl) && !bitmap_empty_p (args_to_skip))
7555 DECL_BUILT_IN_CLASS (new_decl) = NOT_BUILT_IN;
7556 DECL_FUNCTION_CODE (new_decl) = (enum built_in_function) 0;
7561 /* Build a function type. The RETURN_TYPE is the type returned by the
7562 function. If VAARGS is set, no void_type_node is appended to the
7563 the list. ARGP must be always be terminated be a NULL_TREE. */
7566 build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7570 t = va_arg (argp, tree);
7571 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7572 args = tree_cons (NULL_TREE, t, args);
7577 if (args != NULL_TREE)
7578 args = nreverse (args);
7579 gcc_assert (last != void_list_node);
7581 else if (args == NULL_TREE)
7582 args = void_list_node;
7586 args = nreverse (args);
7587 TREE_CHAIN (last) = void_list_node;
7589 args = build_function_type (return_type, args);
7594 /* Build a function type. The RETURN_TYPE is the type returned by the
7595 function. If additional arguments are provided, they are
7596 additional argument types. The list of argument types must always
7597 be terminated by NULL_TREE. */
7600 build_function_type_list (tree return_type, ...)
7605 va_start (p, return_type);
7606 args = build_function_type_list_1 (false, return_type, p);
7611 /* Build a variable argument function type. The RETURN_TYPE is the
7612 type returned by the function. If additional arguments are provided,
7613 they are additional argument types. The list of argument types must
7614 always be terminated by NULL_TREE. */
7617 build_varargs_function_type_list (tree return_type, ...)
7622 va_start (p, return_type);
7623 args = build_function_type_list_1 (true, return_type, p);
7629 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7630 and ARGTYPES (a TREE_LIST) are the return type and arguments types
7631 for the method. An implicit additional parameter (of type
7632 pointer-to-BASETYPE) is added to the ARGTYPES. */
7635 build_method_type_directly (tree basetype,
7642 bool any_structural_p, any_noncanonical_p;
7643 tree canon_argtypes;
7645 /* Make a node of the sort we want. */
7646 t = make_node (METHOD_TYPE);
7648 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7649 TREE_TYPE (t) = rettype;
7650 ptype = build_pointer_type (basetype);
7652 /* The actual arglist for this function includes a "hidden" argument
7653 which is "this". Put it into the list of argument types. */
7654 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7655 TYPE_ARG_TYPES (t) = argtypes;
7657 /* If we already have such a type, use the old one. */
7658 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
7659 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
7660 hashcode = type_hash_list (argtypes, hashcode);
7661 t = type_hash_canon (hashcode, t);
7663 /* Set up the canonical type. */
7665 = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7666 || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7668 = (TYPE_CANONICAL (basetype) != basetype
7669 || TYPE_CANONICAL (rettype) != rettype);
7670 canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7672 &any_noncanonical_p);
7673 if (any_structural_p)
7674 SET_TYPE_STRUCTURAL_EQUALITY (t);
7675 else if (any_noncanonical_p)
7677 = build_method_type_directly (TYPE_CANONICAL (basetype),
7678 TYPE_CANONICAL (rettype),
7680 if (!COMPLETE_TYPE_P (t))
7686 /* Construct, lay out and return the type of methods belonging to class
7687 BASETYPE and whose arguments and values are described by TYPE.
7688 If that type exists already, reuse it.
7689 TYPE must be a FUNCTION_TYPE node. */
7692 build_method_type (tree basetype, tree type)
7694 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7696 return build_method_type_directly (basetype,
7698 TYPE_ARG_TYPES (type));
7701 /* Construct, lay out and return the type of offsets to a value
7702 of type TYPE, within an object of type BASETYPE.
7703 If a suitable offset type exists already, reuse it. */
7706 build_offset_type (tree basetype, tree type)
7709 hashval_t hashcode = 0;
7711 /* Make a node of the sort we want. */
7712 t = make_node (OFFSET_TYPE);
7714 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7715 TREE_TYPE (t) = type;
7717 /* If we already have such a type, use the old one. */
7718 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
7719 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
7720 t = type_hash_canon (hashcode, t);
7722 if (!COMPLETE_TYPE_P (t))
7725 if (TYPE_CANONICAL (t) == t)
7727 if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7728 || TYPE_STRUCTURAL_EQUALITY_P (type))
7729 SET_TYPE_STRUCTURAL_EQUALITY (t);
7730 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7731 || TYPE_CANONICAL (type) != type)
7733 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7734 TYPE_CANONICAL (type));
7740 /* Create a complex type whose components are COMPONENT_TYPE. */
7743 build_complex_type (tree component_type)
7748 gcc_assert (INTEGRAL_TYPE_P (component_type)
7749 || SCALAR_FLOAT_TYPE_P (component_type)
7750 || FIXED_POINT_TYPE_P (component_type));
7752 /* Make a node of the sort we want. */
7753 t = make_node (COMPLEX_TYPE);
7755 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
7757 /* If we already have such a type, use the old one. */
7758 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
7759 t = type_hash_canon (hashcode, t);
7761 if (!COMPLETE_TYPE_P (t))
7764 if (TYPE_CANONICAL (t) == t)
7766 if (TYPE_STRUCTURAL_EQUALITY_P (component_type))
7767 SET_TYPE_STRUCTURAL_EQUALITY (t);
7768 else if (TYPE_CANONICAL (component_type) != component_type)
7770 = build_complex_type (TYPE_CANONICAL (component_type));
7773 /* We need to create a name, since complex is a fundamental type. */
7774 if (! TYPE_NAME (t))
7777 if (component_type == char_type_node)
7778 name = "complex char";
7779 else if (component_type == signed_char_type_node)
7780 name = "complex signed char";
7781 else if (component_type == unsigned_char_type_node)
7782 name = "complex unsigned char";
7783 else if (component_type == short_integer_type_node)
7784 name = "complex short int";
7785 else if (component_type == short_unsigned_type_node)
7786 name = "complex short unsigned int";
7787 else if (component_type == integer_type_node)
7788 name = "complex int";
7789 else if (component_type == unsigned_type_node)
7790 name = "complex unsigned int";
7791 else if (component_type == long_integer_type_node)
7792 name = "complex long int";
7793 else if (component_type == long_unsigned_type_node)
7794 name = "complex long unsigned int";
7795 else if (component_type == long_long_integer_type_node)
7796 name = "complex long long int";
7797 else if (component_type == long_long_unsigned_type_node)
7798 name = "complex long long unsigned int";
7803 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
7804 get_identifier (name), t);
7807 return build_qualified_type (t, TYPE_QUALS (component_type));
7810 /* If TYPE is a real or complex floating-point type and the target
7811 does not directly support arithmetic on TYPE then return the wider
7812 type to be used for arithmetic on TYPE. Otherwise, return
7816 excess_precision_type (tree type)
7818 if (flag_excess_precision != EXCESS_PRECISION_FAST)
7820 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
7821 switch (TREE_CODE (type))
7824 switch (flt_eval_method)
7827 if (TYPE_MODE (type) == TYPE_MODE (float_type_node))
7828 return double_type_node;
7831 if (TYPE_MODE (type) == TYPE_MODE (float_type_node)
7832 || TYPE_MODE (type) == TYPE_MODE (double_type_node))
7833 return long_double_type_node;
7840 if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
7842 switch (flt_eval_method)
7845 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node))
7846 return complex_double_type_node;
7849 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)
7850 || (TYPE_MODE (TREE_TYPE (type))
7851 == TYPE_MODE (double_type_node)))
7852 return complex_long_double_type_node;
7865 /* Return OP, stripped of any conversions to wider types as much as is safe.
7866 Converting the value back to OP's type makes a value equivalent to OP.
7868 If FOR_TYPE is nonzero, we return a value which, if converted to
7869 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
7871 OP must have integer, real or enumeral type. Pointers are not allowed!
7873 There are some cases where the obvious value we could return
7874 would regenerate to OP if converted to OP's type,
7875 but would not extend like OP to wider types.
7876 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
7877 For example, if OP is (unsigned short)(signed char)-1,
7878 we avoid returning (signed char)-1 if FOR_TYPE is int,
7879 even though extending that to an unsigned short would regenerate OP,
7880 since the result of extending (signed char)-1 to (int)
7881 is different from (int) OP. */
7884 get_unwidened (tree op, tree for_type)
7886 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
7887 tree type = TREE_TYPE (op);
7889 = TYPE_PRECISION (for_type != 0 ? for_type : type);
7891 = (for_type != 0 && for_type != type
7892 && final_prec > TYPE_PRECISION (type)
7893 && TYPE_UNSIGNED (type));
7896 while (CONVERT_EXPR_P (op))
7900 /* TYPE_PRECISION on vector types has different meaning
7901 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
7902 so avoid them here. */
7903 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
7906 bitschange = TYPE_PRECISION (TREE_TYPE (op))
7907 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
7909 /* Truncations are many-one so cannot be removed.
7910 Unless we are later going to truncate down even farther. */
7912 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
7915 /* See what's inside this conversion. If we decide to strip it,
7917 op = TREE_OPERAND (op, 0);
7919 /* If we have not stripped any zero-extensions (uns is 0),
7920 we can strip any kind of extension.
7921 If we have previously stripped a zero-extension,
7922 only zero-extensions can safely be stripped.
7923 Any extension can be stripped if the bits it would produce
7924 are all going to be discarded later by truncating to FOR_TYPE. */
7928 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
7930 /* TYPE_UNSIGNED says whether this is a zero-extension.
7931 Let's avoid computing it if it does not affect WIN
7932 and if UNS will not be needed again. */
7934 || CONVERT_EXPR_P (op))
7935 && TYPE_UNSIGNED (TREE_TYPE (op)))
7943 /* If we finally reach a constant see if it fits in for_type and
7944 in that case convert it. */
7946 && TREE_CODE (win) == INTEGER_CST
7947 && TREE_TYPE (win) != for_type
7948 && int_fits_type_p (win, for_type))
7949 win = fold_convert (for_type, win);
7954 /* Return OP or a simpler expression for a narrower value
7955 which can be sign-extended or zero-extended to give back OP.
7956 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
7957 or 0 if the value should be sign-extended. */
7960 get_narrower (tree op, int *unsignedp_ptr)
7965 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
7967 while (TREE_CODE (op) == NOP_EXPR)
7970 = (TYPE_PRECISION (TREE_TYPE (op))
7971 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
7973 /* Truncations are many-one so cannot be removed. */
7977 /* See what's inside this conversion. If we decide to strip it,
7982 op = TREE_OPERAND (op, 0);
7983 /* An extension: the outermost one can be stripped,
7984 but remember whether it is zero or sign extension. */
7986 uns = TYPE_UNSIGNED (TREE_TYPE (op));
7987 /* Otherwise, if a sign extension has been stripped,
7988 only sign extensions can now be stripped;
7989 if a zero extension has been stripped, only zero-extensions. */
7990 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
7994 else /* bitschange == 0 */
7996 /* A change in nominal type can always be stripped, but we must
7997 preserve the unsignedness. */
7999 uns = TYPE_UNSIGNED (TREE_TYPE (op));
8001 op = TREE_OPERAND (op, 0);
8002 /* Keep trying to narrow, but don't assign op to win if it
8003 would turn an integral type into something else. */
8004 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8011 if (TREE_CODE (op) == COMPONENT_REF
8012 /* Since type_for_size always gives an integer type. */
8013 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8014 && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8015 /* Ensure field is laid out already. */
8016 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8017 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
8019 unsigned HOST_WIDE_INT innerprec
8020 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
8021 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8022 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8023 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8025 /* We can get this structure field in a narrower type that fits it,
8026 but the resulting extension to its nominal type (a fullword type)
8027 must satisfy the same conditions as for other extensions.
8029 Do this only for fields that are aligned (not bit-fields),
8030 because when bit-field insns will be used there is no
8031 advantage in doing this. */
8033 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8034 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8035 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8039 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8040 win = fold_convert (type, op);
8044 *unsignedp_ptr = uns;
8048 /* Returns true if integer constant C has a value that is permissible
8049 for type TYPE (an INTEGER_TYPE). */
8052 int_fits_type_p (const_tree c, const_tree type)
8054 tree type_low_bound, type_high_bound;
8055 bool ok_for_low_bound, ok_for_high_bound, unsc;
8058 dc = tree_to_double_int (c);
8059 unsc = TYPE_UNSIGNED (TREE_TYPE (c));
8061 if (TREE_CODE (TREE_TYPE (c)) == INTEGER_TYPE
8062 && TYPE_IS_SIZETYPE (TREE_TYPE (c))
8064 /* So c is an unsigned integer whose type is sizetype and type is not.
8065 sizetype'd integers are sign extended even though they are
8066 unsigned. If the integer value fits in the lower end word of c,
8067 and if the higher end word has all its bits set to 1, that
8068 means the higher end bits are set to 1 only for sign extension.
8069 So let's convert c into an equivalent zero extended unsigned
8071 dc = double_int_zext (dc, TYPE_PRECISION (TREE_TYPE (c)));
8074 type_low_bound = TYPE_MIN_VALUE (type);
8075 type_high_bound = TYPE_MAX_VALUE (type);
8077 /* If at least one bound of the type is a constant integer, we can check
8078 ourselves and maybe make a decision. If no such decision is possible, but
8079 this type is a subtype, try checking against that. Otherwise, use
8080 double_int_fits_to_tree_p, which checks against the precision.
8082 Compute the status for each possibly constant bound, and return if we see
8083 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8084 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8085 for "constant known to fit". */
8087 /* Check if c >= type_low_bound. */
8088 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8090 dd = tree_to_double_int (type_low_bound);
8091 if (TREE_CODE (type) == INTEGER_TYPE
8092 && TYPE_IS_SIZETYPE (type)
8093 && TYPE_UNSIGNED (type))
8094 dd = double_int_zext (dd, TYPE_PRECISION (type));
8095 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_low_bound)))
8097 int c_neg = (!unsc && double_int_negative_p (dc));
8098 int t_neg = (unsc && double_int_negative_p (dd));
8100 if (c_neg && !t_neg)
8102 if ((c_neg || !t_neg) && double_int_ucmp (dc, dd) < 0)
8105 else if (double_int_cmp (dc, dd, unsc) < 0)
8107 ok_for_low_bound = true;
8110 ok_for_low_bound = false;
8112 /* Check if c <= type_high_bound. */
8113 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8115 dd = tree_to_double_int (type_high_bound);
8116 if (TREE_CODE (type) == INTEGER_TYPE
8117 && TYPE_IS_SIZETYPE (type)
8118 && TYPE_UNSIGNED (type))
8119 dd = double_int_zext (dd, TYPE_PRECISION (type));
8120 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_high_bound)))
8122 int c_neg = (!unsc && double_int_negative_p (dc));
8123 int t_neg = (unsc && double_int_negative_p (dd));
8125 if (t_neg && !c_neg)
8127 if ((t_neg || !c_neg) && double_int_ucmp (dc, dd) > 0)
8130 else if (double_int_cmp (dc, dd, unsc) > 0)
8132 ok_for_high_bound = true;
8135 ok_for_high_bound = false;
8137 /* If the constant fits both bounds, the result is known. */
8138 if (ok_for_low_bound && ok_for_high_bound)
8141 /* Perform some generic filtering which may allow making a decision
8142 even if the bounds are not constant. First, negative integers
8143 never fit in unsigned types, */
8144 if (TYPE_UNSIGNED (type) && !unsc && double_int_negative_p (dc))
8147 /* Second, narrower types always fit in wider ones. */
8148 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8151 /* Third, unsigned integers with top bit set never fit signed types. */
8152 if (! TYPE_UNSIGNED (type) && unsc)
8154 int prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c))) - 1;
8155 if (prec < HOST_BITS_PER_WIDE_INT)
8157 if (((((unsigned HOST_WIDE_INT) 1) << prec) & dc.low) != 0)
8160 else if (((((unsigned HOST_WIDE_INT) 1)
8161 << (prec - HOST_BITS_PER_WIDE_INT)) & dc.high) != 0)
8165 /* If we haven't been able to decide at this point, there nothing more we
8166 can check ourselves here. Look at the base type if we have one and it
8167 has the same precision. */
8168 if (TREE_CODE (type) == INTEGER_TYPE
8169 && TREE_TYPE (type) != 0
8170 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8172 type = TREE_TYPE (type);
8176 /* Or to double_int_fits_to_tree_p, if nothing else. */
8177 return double_int_fits_to_tree_p (type, dc);
8180 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8181 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8182 represented (assuming two's-complement arithmetic) within the bit
8183 precision of the type are returned instead. */
8186 get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8188 if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8189 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8190 mpz_set_double_int (min, tree_to_double_int (TYPE_MIN_VALUE (type)),
8191 TYPE_UNSIGNED (type));
8194 if (TYPE_UNSIGNED (type))
8195 mpz_set_ui (min, 0);
8199 mn = double_int_mask (TYPE_PRECISION (type) - 1);
8200 mn = double_int_sext (double_int_add (mn, double_int_one),
8201 TYPE_PRECISION (type));
8202 mpz_set_double_int (min, mn, false);
8206 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8207 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8208 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)),
8209 TYPE_UNSIGNED (type));
8212 if (TYPE_UNSIGNED (type))
8213 mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type)),
8216 mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type) - 1),
8221 /* Return true if VAR is an automatic variable defined in function FN. */
8224 auto_var_in_fn_p (const_tree var, const_tree fn)
8226 return (DECL_P (var) && DECL_CONTEXT (var) == fn
8227 && ((((TREE_CODE (var) == VAR_DECL && ! DECL_EXTERNAL (var))
8228 || TREE_CODE (var) == PARM_DECL)
8229 && ! TREE_STATIC (var))
8230 || TREE_CODE (var) == LABEL_DECL
8231 || TREE_CODE (var) == RESULT_DECL));
8234 /* Subprogram of following function. Called by walk_tree.
8236 Return *TP if it is an automatic variable or parameter of the
8237 function passed in as DATA. */
8240 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8242 tree fn = (tree) data;
8247 else if (DECL_P (*tp)
8248 && auto_var_in_fn_p (*tp, fn))
8254 /* Returns true if T is, contains, or refers to a type with variable
8255 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8256 arguments, but not the return type. If FN is nonzero, only return
8257 true if a modifier of the type or position of FN is a variable or
8258 parameter inside FN.
8260 This concept is more general than that of C99 'variably modified types':
8261 in C99, a struct type is never variably modified because a VLA may not
8262 appear as a structure member. However, in GNU C code like:
8264 struct S { int i[f()]; };
8266 is valid, and other languages may define similar constructs. */
8269 variably_modified_type_p (tree type, tree fn)
8273 /* Test if T is either variable (if FN is zero) or an expression containing
8274 a variable in FN. */
8275 #define RETURN_TRUE_IF_VAR(T) \
8276 do { tree _t = (T); \
8277 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
8278 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8279 return true; } while (0)
8281 if (type == error_mark_node)
8284 /* If TYPE itself has variable size, it is variably modified. */
8285 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8286 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8288 switch (TREE_CODE (type))
8291 case REFERENCE_TYPE:
8293 if (variably_modified_type_p (TREE_TYPE (type), fn))
8299 /* If TYPE is a function type, it is variably modified if the
8300 return type is variably modified. */
8301 if (variably_modified_type_p (TREE_TYPE (type), fn))
8307 case FIXED_POINT_TYPE:
8310 /* Scalar types are variably modified if their end points
8312 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8313 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8318 case QUAL_UNION_TYPE:
8319 /* We can't see if any of the fields are variably-modified by the
8320 definition we normally use, since that would produce infinite
8321 recursion via pointers. */
8322 /* This is variably modified if some field's type is. */
8323 for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8324 if (TREE_CODE (t) == FIELD_DECL)
8326 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8327 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8328 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8330 if (TREE_CODE (type) == QUAL_UNION_TYPE)
8331 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8336 /* Do not call ourselves to avoid infinite recursion. This is
8337 variably modified if the element type is. */
8338 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8339 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8346 /* The current language may have other cases to check, but in general,
8347 all other types are not variably modified. */
8348 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8350 #undef RETURN_TRUE_IF_VAR
8353 /* Given a DECL or TYPE, return the scope in which it was declared, or
8354 NULL_TREE if there is no containing scope. */
8357 get_containing_scope (const_tree t)
8359 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8362 /* Return the innermost context enclosing DECL that is
8363 a FUNCTION_DECL, or zero if none. */
8366 decl_function_context (const_tree decl)
8370 if (TREE_CODE (decl) == ERROR_MARK)
8373 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8374 where we look up the function at runtime. Such functions always take
8375 a first argument of type 'pointer to real context'.
8377 C++ should really be fixed to use DECL_CONTEXT for the real context,
8378 and use something else for the "virtual context". */
8379 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
8382 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8384 context = DECL_CONTEXT (decl);
8386 while (context && TREE_CODE (context) != FUNCTION_DECL)
8388 if (TREE_CODE (context) == BLOCK)
8389 context = BLOCK_SUPERCONTEXT (context);
8391 context = get_containing_scope (context);
8397 /* Return the innermost context enclosing DECL that is
8398 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8399 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8402 decl_type_context (const_tree decl)
8404 tree context = DECL_CONTEXT (decl);
8407 switch (TREE_CODE (context))
8409 case NAMESPACE_DECL:
8410 case TRANSLATION_UNIT_DECL:
8415 case QUAL_UNION_TYPE:
8420 context = DECL_CONTEXT (context);
8424 context = BLOCK_SUPERCONTEXT (context);
8434 /* CALL is a CALL_EXPR. Return the declaration for the function
8435 called, or NULL_TREE if the called function cannot be
8439 get_callee_fndecl (const_tree call)
8443 if (call == error_mark_node)
8444 return error_mark_node;
8446 /* It's invalid to call this function with anything but a
8448 gcc_assert (TREE_CODE (call) == CALL_EXPR);
8450 /* The first operand to the CALL is the address of the function
8452 addr = CALL_EXPR_FN (call);
8456 /* If this is a readonly function pointer, extract its initial value. */
8457 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8458 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8459 && DECL_INITIAL (addr))
8460 addr = DECL_INITIAL (addr);
8462 /* If the address is just `&f' for some function `f', then we know
8463 that `f' is being called. */
8464 if (TREE_CODE (addr) == ADDR_EXPR
8465 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8466 return TREE_OPERAND (addr, 0);
8468 /* We couldn't figure out what was being called. */
8472 /* Print debugging information about tree nodes generated during the compile,
8473 and any language-specific information. */
8476 dump_tree_statistics (void)
8478 #ifdef GATHER_STATISTICS
8480 int total_nodes, total_bytes;
8483 fprintf (stderr, "\n??? tree nodes created\n\n");
8484 #ifdef GATHER_STATISTICS
8485 fprintf (stderr, "Kind Nodes Bytes\n");
8486 fprintf (stderr, "---------------------------------------\n");
8487 total_nodes = total_bytes = 0;
8488 for (i = 0; i < (int) all_kinds; i++)
8490 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
8491 tree_node_counts[i], tree_node_sizes[i]);
8492 total_nodes += tree_node_counts[i];
8493 total_bytes += tree_node_sizes[i];
8495 fprintf (stderr, "---------------------------------------\n");
8496 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
8497 fprintf (stderr, "---------------------------------------\n");
8498 ssanames_print_statistics ();
8499 phinodes_print_statistics ();
8501 fprintf (stderr, "(No per-node statistics)\n");
8503 print_type_hash_statistics ();
8504 print_debug_expr_statistics ();
8505 print_value_expr_statistics ();
8506 lang_hooks.print_statistics ();
8509 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8511 /* Generate a crc32 of a string. */
8514 crc32_string (unsigned chksum, const char *string)
8518 unsigned value = *string << 24;
8521 for (ix = 8; ix--; value <<= 1)
8525 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
8534 /* P is a string that will be used in a symbol. Mask out any characters
8535 that are not valid in that context. */
8538 clean_symbol_name (char *p)
8542 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
8545 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
8552 /* Generate a name for a special-purpose function function.
8553 The generated name may need to be unique across the whole link.
8554 TYPE is some string to identify the purpose of this function to the
8555 linker or collect2; it must start with an uppercase letter,
8557 I - for constructors
8559 N - for C++ anonymous namespaces
8560 F - for DWARF unwind frame information. */
8563 get_file_function_name (const char *type)
8569 /* If we already have a name we know to be unique, just use that. */
8570 if (first_global_object_name)
8571 p = q = ASTRDUP (first_global_object_name);
8572 /* If the target is handling the constructors/destructors, they
8573 will be local to this file and the name is only necessary for
8575 We also assign sub_I and sub_D sufixes to constructors called from
8576 the global static constructors. These are always local. */
8577 else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
8578 || (strncmp (type, "sub_", 4) == 0
8579 && (type[4] == 'I' || type[4] == 'D')))
8581 const char *file = main_input_filename;
8583 file = input_filename;
8584 /* Just use the file's basename, because the full pathname
8585 might be quite long. */
8586 p = q = ASTRDUP (lbasename (file));
8590 /* Otherwise, the name must be unique across the entire link.
8591 We don't have anything that we know to be unique to this translation
8592 unit, so use what we do have and throw in some randomness. */
8594 const char *name = weak_global_object_name;
8595 const char *file = main_input_filename;
8600 file = input_filename;
8602 len = strlen (file);
8603 q = (char *) alloca (9 * 2 + len + 1);
8604 memcpy (q, file, len + 1);
8606 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
8607 crc32_string (0, get_random_seed (false)));
8612 clean_symbol_name (q);
8613 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
8616 /* Set up the name of the file-level functions we may need.
8617 Use a global object (which is already required to be unique over
8618 the program) rather than the file name (which imposes extra
8620 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
8622 return get_identifier (buf);
8625 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
8627 /* Complain that the tree code of NODE does not match the expected 0
8628 terminated list of trailing codes. The trailing code list can be
8629 empty, for a more vague error message. FILE, LINE, and FUNCTION
8630 are of the caller. */
8633 tree_check_failed (const_tree node, const char *file,
8634 int line, const char *function, ...)
8638 unsigned length = 0;
8641 va_start (args, function);
8642 while ((code = va_arg (args, int)))
8643 length += 4 + strlen (tree_code_name[code]);
8648 va_start (args, function);
8649 length += strlen ("expected ");
8650 buffer = tmp = (char *) alloca (length);
8652 while ((code = va_arg (args, int)))
8654 const char *prefix = length ? " or " : "expected ";
8656 strcpy (tmp + length, prefix);
8657 length += strlen (prefix);
8658 strcpy (tmp + length, tree_code_name[code]);
8659 length += strlen (tree_code_name[code]);
8664 buffer = "unexpected node";
8666 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8667 buffer, tree_code_name[TREE_CODE (node)],
8668 function, trim_filename (file), line);
8671 /* Complain that the tree code of NODE does match the expected 0
8672 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
8676 tree_not_check_failed (const_tree node, const char *file,
8677 int line, const char *function, ...)
8681 unsigned length = 0;
8684 va_start (args, function);
8685 while ((code = va_arg (args, int)))
8686 length += 4 + strlen (tree_code_name[code]);
8688 va_start (args, function);
8689 buffer = (char *) alloca (length);
8691 while ((code = va_arg (args, int)))
8695 strcpy (buffer + length, " or ");
8698 strcpy (buffer + length, tree_code_name[code]);
8699 length += strlen (tree_code_name[code]);
8703 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
8704 buffer, tree_code_name[TREE_CODE (node)],
8705 function, trim_filename (file), line);
8708 /* Similar to tree_check_failed, except that we check for a class of tree
8709 code, given in CL. */
8712 tree_class_check_failed (const_tree node, const enum tree_code_class cl,
8713 const char *file, int line, const char *function)
8716 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
8717 TREE_CODE_CLASS_STRING (cl),
8718 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
8719 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
8722 /* Similar to tree_check_failed, except that instead of specifying a
8723 dozen codes, use the knowledge that they're all sequential. */
8726 tree_range_check_failed (const_tree node, const char *file, int line,
8727 const char *function, enum tree_code c1,
8731 unsigned length = 0;
8734 for (c = c1; c <= c2; ++c)
8735 length += 4 + strlen (tree_code_name[c]);
8737 length += strlen ("expected ");
8738 buffer = (char *) alloca (length);
8741 for (c = c1; c <= c2; ++c)
8743 const char *prefix = length ? " or " : "expected ";
8745 strcpy (buffer + length, prefix);
8746 length += strlen (prefix);
8747 strcpy (buffer + length, tree_code_name[c]);
8748 length += strlen (tree_code_name[c]);
8751 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8752 buffer, tree_code_name[TREE_CODE (node)],
8753 function, trim_filename (file), line);
8757 /* Similar to tree_check_failed, except that we check that a tree does
8758 not have the specified code, given in CL. */
8761 tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
8762 const char *file, int line, const char *function)
8765 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
8766 TREE_CODE_CLASS_STRING (cl),
8767 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
8768 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
8772 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
8775 omp_clause_check_failed (const_tree node, const char *file, int line,
8776 const char *function, enum omp_clause_code code)
8778 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
8779 omp_clause_code_name[code], tree_code_name[TREE_CODE (node)],
8780 function, trim_filename (file), line);
8784 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
8787 omp_clause_range_check_failed (const_tree node, const char *file, int line,
8788 const char *function, enum omp_clause_code c1,
8789 enum omp_clause_code c2)
8792 unsigned length = 0;
8795 for (c = c1; c <= c2; ++c)
8796 length += 4 + strlen (omp_clause_code_name[c]);
8798 length += strlen ("expected ");
8799 buffer = (char *) alloca (length);
8802 for (c = c1; c <= c2; ++c)
8804 const char *prefix = length ? " or " : "expected ";
8806 strcpy (buffer + length, prefix);
8807 length += strlen (prefix);
8808 strcpy (buffer + length, omp_clause_code_name[c]);
8809 length += strlen (omp_clause_code_name[c]);
8812 internal_error ("tree check: %s, have %s in %s, at %s:%d",
8813 buffer, omp_clause_code_name[TREE_CODE (node)],
8814 function, trim_filename (file), line);
8818 #undef DEFTREESTRUCT
8819 #define DEFTREESTRUCT(VAL, NAME) NAME,
8821 static const char *ts_enum_names[] = {
8822 #include "treestruct.def"
8824 #undef DEFTREESTRUCT
8826 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
8828 /* Similar to tree_class_check_failed, except that we check for
8829 whether CODE contains the tree structure identified by EN. */
8832 tree_contains_struct_check_failed (const_tree node,
8833 const enum tree_node_structure_enum en,
8834 const char *file, int line,
8835 const char *function)
8838 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
8840 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
8844 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
8845 (dynamically sized) vector. */
8848 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
8849 const char *function)
8852 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
8853 idx + 1, len, function, trim_filename (file), line);
8856 /* Similar to above, except that the check is for the bounds of the operand
8857 vector of an expression node EXP. */
8860 tree_operand_check_failed (int idx, const_tree exp, const char *file,
8861 int line, const char *function)
8863 int code = TREE_CODE (exp);
8865 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
8866 idx + 1, tree_code_name[code], TREE_OPERAND_LENGTH (exp),
8867 function, trim_filename (file), line);
8870 /* Similar to above, except that the check is for the number of
8871 operands of an OMP_CLAUSE node. */
8874 omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
8875 int line, const char *function)
8878 ("tree check: accessed operand %d of omp_clause %s with %d operands "
8879 "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
8880 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
8881 trim_filename (file), line);
8883 #endif /* ENABLE_TREE_CHECKING */
8885 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
8886 and mapped to the machine mode MODE. Initialize its fields and build
8887 the information necessary for debugging output. */
8890 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
8893 hashval_t hashcode = 0;
8895 t = make_node (VECTOR_TYPE);
8896 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
8897 SET_TYPE_VECTOR_SUBPARTS (t, nunits);
8898 SET_TYPE_MODE (t, mode);
8900 if (TYPE_STRUCTURAL_EQUALITY_P (innertype))
8901 SET_TYPE_STRUCTURAL_EQUALITY (t);
8902 else if (TYPE_CANONICAL (innertype) != innertype
8903 || mode != VOIDmode)
8905 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode);
8909 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
8910 hashcode = iterative_hash_host_wide_int (nunits, hashcode);
8911 hashcode = iterative_hash_host_wide_int (mode, hashcode);
8912 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (t)), hashcode);
8913 t = type_hash_canon (hashcode, t);
8915 /* We have built a main variant, based on the main variant of the
8916 inner type. Use it to build the variant we return. */
8917 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
8918 && TREE_TYPE (t) != innertype)
8919 return build_type_attribute_qual_variant (t,
8920 TYPE_ATTRIBUTES (innertype),
8921 TYPE_QUALS (innertype));
8927 make_or_reuse_type (unsigned size, int unsignedp)
8929 if (size == INT_TYPE_SIZE)
8930 return unsignedp ? unsigned_type_node : integer_type_node;
8931 if (size == CHAR_TYPE_SIZE)
8932 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
8933 if (size == SHORT_TYPE_SIZE)
8934 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
8935 if (size == LONG_TYPE_SIZE)
8936 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
8937 if (size == LONG_LONG_TYPE_SIZE)
8938 return (unsignedp ? long_long_unsigned_type_node
8939 : long_long_integer_type_node);
8940 if (size == 128 && int128_integer_type_node)
8941 return (unsignedp ? int128_unsigned_type_node
8942 : int128_integer_type_node);
8945 return make_unsigned_type (size);
8947 return make_signed_type (size);
8950 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
8953 make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
8957 if (size == SHORT_FRACT_TYPE_SIZE)
8958 return unsignedp ? sat_unsigned_short_fract_type_node
8959 : sat_short_fract_type_node;
8960 if (size == FRACT_TYPE_SIZE)
8961 return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
8962 if (size == LONG_FRACT_TYPE_SIZE)
8963 return unsignedp ? sat_unsigned_long_fract_type_node
8964 : sat_long_fract_type_node;
8965 if (size == LONG_LONG_FRACT_TYPE_SIZE)
8966 return unsignedp ? sat_unsigned_long_long_fract_type_node
8967 : sat_long_long_fract_type_node;
8971 if (size == SHORT_FRACT_TYPE_SIZE)
8972 return unsignedp ? unsigned_short_fract_type_node
8973 : short_fract_type_node;
8974 if (size == FRACT_TYPE_SIZE)
8975 return unsignedp ? unsigned_fract_type_node : fract_type_node;
8976 if (size == LONG_FRACT_TYPE_SIZE)
8977 return unsignedp ? unsigned_long_fract_type_node
8978 : long_fract_type_node;
8979 if (size == LONG_LONG_FRACT_TYPE_SIZE)
8980 return unsignedp ? unsigned_long_long_fract_type_node
8981 : long_long_fract_type_node;
8984 return make_fract_type (size, unsignedp, satp);
8987 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
8990 make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
8994 if (size == SHORT_ACCUM_TYPE_SIZE)
8995 return unsignedp ? sat_unsigned_short_accum_type_node
8996 : sat_short_accum_type_node;
8997 if (size == ACCUM_TYPE_SIZE)
8998 return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
8999 if (size == LONG_ACCUM_TYPE_SIZE)
9000 return unsignedp ? sat_unsigned_long_accum_type_node
9001 : sat_long_accum_type_node;
9002 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9003 return unsignedp ? sat_unsigned_long_long_accum_type_node
9004 : sat_long_long_accum_type_node;
9008 if (size == SHORT_ACCUM_TYPE_SIZE)
9009 return unsignedp ? unsigned_short_accum_type_node
9010 : short_accum_type_node;
9011 if (size == ACCUM_TYPE_SIZE)
9012 return unsignedp ? unsigned_accum_type_node : accum_type_node;
9013 if (size == LONG_ACCUM_TYPE_SIZE)
9014 return unsignedp ? unsigned_long_accum_type_node
9015 : long_accum_type_node;
9016 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9017 return unsignedp ? unsigned_long_long_accum_type_node
9018 : long_long_accum_type_node;
9021 return make_accum_type (size, unsignedp, satp);
9024 /* Create nodes for all integer types (and error_mark_node) using the sizes
9025 of C datatypes. The caller should call set_sizetype soon after calling
9026 this function to select one of the types as sizetype. */
9029 build_common_tree_nodes (bool signed_char)
9031 error_mark_node = make_node (ERROR_MARK);
9032 TREE_TYPE (error_mark_node) = error_mark_node;
9034 initialize_sizetypes ();
9036 /* Define both `signed char' and `unsigned char'. */
9037 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9038 TYPE_STRING_FLAG (signed_char_type_node) = 1;
9039 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9040 TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9042 /* Define `char', which is like either `signed char' or `unsigned char'
9043 but not the same as either. */
9046 ? make_signed_type (CHAR_TYPE_SIZE)
9047 : make_unsigned_type (CHAR_TYPE_SIZE));
9048 TYPE_STRING_FLAG (char_type_node) = 1;
9050 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9051 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9052 integer_type_node = make_signed_type (INT_TYPE_SIZE);
9053 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9054 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9055 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9056 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9057 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9058 #if HOST_BITS_PER_WIDE_INT >= 64
9059 /* TODO: This isn't correct, but as logic depends at the moment on
9060 host's instead of target's wide-integer.
9061 If there is a target not supporting TImode, but has an 128-bit
9062 integer-scalar register, this target check needs to be adjusted. */
9063 if (targetm.scalar_mode_supported_p (TImode))
9065 int128_integer_type_node = make_signed_type (128);
9066 int128_unsigned_type_node = make_unsigned_type (128);
9069 /* Define a boolean type. This type only represents boolean values but
9070 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9071 Front ends which want to override this size (i.e. Java) can redefine
9072 boolean_type_node before calling build_common_tree_nodes_2. */
9073 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9074 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9075 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9076 TYPE_PRECISION (boolean_type_node) = 1;
9078 /* Fill in the rest of the sized types. Reuse existing type nodes
9080 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9081 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9082 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9083 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9084 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9086 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9087 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9088 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9089 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9090 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9092 access_public_node = get_identifier ("public");
9093 access_protected_node = get_identifier ("protected");
9094 access_private_node = get_identifier ("private");
9097 /* Call this function after calling build_common_tree_nodes and set_sizetype.
9098 It will create several other common tree nodes. */
9101 build_common_tree_nodes_2 (int short_double)
9103 /* Define these next since types below may used them. */
9104 integer_zero_node = build_int_cst (integer_type_node, 0);
9105 integer_one_node = build_int_cst (integer_type_node, 1);
9106 integer_three_node = build_int_cst (integer_type_node, 3);
9107 integer_minus_one_node = build_int_cst (integer_type_node, -1);
9109 size_zero_node = size_int (0);
9110 size_one_node = size_int (1);
9111 bitsize_zero_node = bitsize_int (0);
9112 bitsize_one_node = bitsize_int (1);
9113 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9115 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9116 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9118 void_type_node = make_node (VOID_TYPE);
9119 layout_type (void_type_node);
9121 /* We are not going to have real types in C with less than byte alignment,
9122 so we might as well not have any types that claim to have it. */
9123 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
9124 TYPE_USER_ALIGN (void_type_node) = 0;
9126 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9127 layout_type (TREE_TYPE (null_pointer_node));
9129 ptr_type_node = build_pointer_type (void_type_node);
9131 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9132 fileptr_type_node = ptr_type_node;
9134 float_type_node = make_node (REAL_TYPE);
9135 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
9136 layout_type (float_type_node);
9138 double_type_node = make_node (REAL_TYPE);
9140 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
9142 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
9143 layout_type (double_type_node);
9145 long_double_type_node = make_node (REAL_TYPE);
9146 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
9147 layout_type (long_double_type_node);
9149 float_ptr_type_node = build_pointer_type (float_type_node);
9150 double_ptr_type_node = build_pointer_type (double_type_node);
9151 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9152 integer_ptr_type_node = build_pointer_type (integer_type_node);
9154 /* Fixed size integer types. */
9155 uint32_type_node = build_nonstandard_integer_type (32, true);
9156 uint64_type_node = build_nonstandard_integer_type (64, true);
9158 /* Decimal float types. */
9159 dfloat32_type_node = make_node (REAL_TYPE);
9160 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9161 layout_type (dfloat32_type_node);
9162 SET_TYPE_MODE (dfloat32_type_node, SDmode);
9163 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node);
9165 dfloat64_type_node = make_node (REAL_TYPE);
9166 TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9167 layout_type (dfloat64_type_node);
9168 SET_TYPE_MODE (dfloat64_type_node, DDmode);
9169 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node);
9171 dfloat128_type_node = make_node (REAL_TYPE);
9172 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9173 layout_type (dfloat128_type_node);
9174 SET_TYPE_MODE (dfloat128_type_node, TDmode);
9175 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node);
9177 complex_integer_type_node = build_complex_type (integer_type_node);
9178 complex_float_type_node = build_complex_type (float_type_node);
9179 complex_double_type_node = build_complex_type (double_type_node);
9180 complex_long_double_type_node = build_complex_type (long_double_type_node);
9182 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9183 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9184 sat_ ## KIND ## _type_node = \
9185 make_sat_signed_ ## KIND ## _type (SIZE); \
9186 sat_unsigned_ ## KIND ## _type_node = \
9187 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9188 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9189 unsigned_ ## KIND ## _type_node = \
9190 make_unsigned_ ## KIND ## _type (SIZE);
9192 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9193 sat_ ## WIDTH ## KIND ## _type_node = \
9194 make_sat_signed_ ## KIND ## _type (SIZE); \
9195 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9196 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9197 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9198 unsigned_ ## WIDTH ## KIND ## _type_node = \
9199 make_unsigned_ ## KIND ## _type (SIZE);
9201 /* Make fixed-point type nodes based on four different widths. */
9202 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9203 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9204 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9205 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9206 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9208 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9209 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9210 NAME ## _type_node = \
9211 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9212 u ## NAME ## _type_node = \
9213 make_or_reuse_unsigned_ ## KIND ## _type \
9214 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9215 sat_ ## NAME ## _type_node = \
9216 make_or_reuse_sat_signed_ ## KIND ## _type \
9217 (GET_MODE_BITSIZE (MODE ## mode)); \
9218 sat_u ## NAME ## _type_node = \
9219 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9220 (GET_MODE_BITSIZE (U ## MODE ## mode));
9222 /* Fixed-point type and mode nodes. */
9223 MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9224 MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9225 MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9226 MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9227 MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9228 MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9229 MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9230 MAKE_FIXED_MODE_NODE (accum, ha, HA)
9231 MAKE_FIXED_MODE_NODE (accum, sa, SA)
9232 MAKE_FIXED_MODE_NODE (accum, da, DA)
9233 MAKE_FIXED_MODE_NODE (accum, ta, TA)
9236 tree t = targetm.build_builtin_va_list ();
9238 /* Many back-ends define record types without setting TYPE_NAME.
9239 If we copied the record type here, we'd keep the original
9240 record type without a name. This breaks name mangling. So,
9241 don't copy record types and let c_common_nodes_and_builtins()
9242 declare the type to be __builtin_va_list. */
9243 if (TREE_CODE (t) != RECORD_TYPE)
9244 t = build_variant_type_copy (t);
9246 va_list_type_node = t;
9250 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9253 local_define_builtin (const char *name, tree type, enum built_in_function code,
9254 const char *library_name, int ecf_flags)
9258 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
9259 library_name, NULL_TREE);
9260 if (ecf_flags & ECF_CONST)
9261 TREE_READONLY (decl) = 1;
9262 if (ecf_flags & ECF_PURE)
9263 DECL_PURE_P (decl) = 1;
9264 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
9265 DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9266 if (ecf_flags & ECF_NORETURN)
9267 TREE_THIS_VOLATILE (decl) = 1;
9268 if (ecf_flags & ECF_NOTHROW)
9269 TREE_NOTHROW (decl) = 1;
9270 if (ecf_flags & ECF_MALLOC)
9271 DECL_IS_MALLOC (decl) = 1;
9272 if (ecf_flags & ECF_LEAF)
9273 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9274 NULL, DECL_ATTRIBUTES (decl));
9276 built_in_decls[code] = decl;
9277 implicit_built_in_decls[code] = decl;
9280 /* Call this function after instantiating all builtins that the language
9281 front end cares about. This will build the rest of the builtins that
9282 are relied upon by the tree optimizers and the middle-end. */
9285 build_common_builtin_nodes (void)
9289 if (built_in_decls[BUILT_IN_MEMCPY] == NULL
9290 || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
9292 ftype = build_function_type_list (ptr_type_node,
9293 ptr_type_node, const_ptr_type_node,
9294 size_type_node, NULL_TREE);
9296 if (built_in_decls[BUILT_IN_MEMCPY] == NULL)
9297 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
9298 "memcpy", ECF_NOTHROW | ECF_LEAF);
9299 if (built_in_decls[BUILT_IN_MEMMOVE] == NULL)
9300 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
9301 "memmove", ECF_NOTHROW | ECF_LEAF);
9304 if (built_in_decls[BUILT_IN_MEMCMP] == NULL)
9306 ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
9307 const_ptr_type_node, size_type_node,
9309 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
9310 "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
9313 if (built_in_decls[BUILT_IN_MEMSET] == NULL)
9315 ftype = build_function_type_list (ptr_type_node,
9316 ptr_type_node, integer_type_node,
9317 size_type_node, NULL_TREE);
9318 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
9319 "memset", ECF_NOTHROW | ECF_LEAF);
9322 if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
9324 ftype = build_function_type_list (ptr_type_node,
9325 size_type_node, NULL_TREE);
9326 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
9327 "alloca", ECF_MALLOC | ECF_NOTHROW | ECF_LEAF);
9330 /* If we're checking the stack, `alloca' can throw. */
9331 if (flag_stack_check)
9332 TREE_NOTHROW (built_in_decls[BUILT_IN_ALLOCA]) = 0;
9334 ftype = build_function_type_list (void_type_node,
9335 ptr_type_node, ptr_type_node,
9336 ptr_type_node, NULL_TREE);
9337 local_define_builtin ("__builtin_init_trampoline", ftype,
9338 BUILT_IN_INIT_TRAMPOLINE,
9339 "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
9341 ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
9342 local_define_builtin ("__builtin_adjust_trampoline", ftype,
9343 BUILT_IN_ADJUST_TRAMPOLINE,
9344 "__builtin_adjust_trampoline",
9345 ECF_CONST | ECF_NOTHROW);
9347 ftype = build_function_type_list (void_type_node,
9348 ptr_type_node, ptr_type_node, NULL_TREE);
9349 local_define_builtin ("__builtin_nonlocal_goto", ftype,
9350 BUILT_IN_NONLOCAL_GOTO,
9351 "__builtin_nonlocal_goto",
9352 ECF_NORETURN | ECF_NOTHROW);
9354 ftype = build_function_type_list (void_type_node,
9355 ptr_type_node, ptr_type_node, NULL_TREE);
9356 local_define_builtin ("__builtin_setjmp_setup", ftype,
9357 BUILT_IN_SETJMP_SETUP,
9358 "__builtin_setjmp_setup", ECF_NOTHROW);
9360 ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
9361 local_define_builtin ("__builtin_setjmp_dispatcher", ftype,
9362 BUILT_IN_SETJMP_DISPATCHER,
9363 "__builtin_setjmp_dispatcher",
9364 ECF_PURE | ECF_NOTHROW);
9366 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
9367 local_define_builtin ("__builtin_setjmp_receiver", ftype,
9368 BUILT_IN_SETJMP_RECEIVER,
9369 "__builtin_setjmp_receiver", ECF_NOTHROW);
9371 ftype = build_function_type_list (ptr_type_node, NULL_TREE);
9372 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
9373 "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
9375 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
9376 local_define_builtin ("__builtin_stack_restore", ftype,
9377 BUILT_IN_STACK_RESTORE,
9378 "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
9380 /* If there's a possibility that we might use the ARM EABI, build the
9381 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9382 if (targetm.arm_eabi_unwinder)
9384 ftype = build_function_type_list (void_type_node, NULL_TREE);
9385 local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
9386 BUILT_IN_CXA_END_CLEANUP,
9387 "__cxa_end_cleanup", ECF_NORETURN | ECF_LEAF);
9390 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
9391 local_define_builtin ("__builtin_unwind_resume", ftype,
9392 BUILT_IN_UNWIND_RESUME,
9393 ((targetm.except_unwind_info (&global_options)
9395 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9398 /* The exception object and filter values from the runtime. The argument
9399 must be zero before exception lowering, i.e. from the front end. After
9400 exception lowering, it will be the region number for the exception
9401 landing pad. These functions are PURE instead of CONST to prevent
9402 them from being hoisted past the exception edge that will initialize
9403 its value in the landing pad. */
9404 ftype = build_function_type_list (ptr_type_node,
9405 integer_type_node, NULL_TREE);
9406 local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
9407 "__builtin_eh_pointer", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
9409 tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
9410 ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
9411 local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
9412 "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
9414 ftype = build_function_type_list (void_type_node,
9415 integer_type_node, integer_type_node,
9417 local_define_builtin ("__builtin_eh_copy_values", ftype,
9418 BUILT_IN_EH_COPY_VALUES,
9419 "__builtin_eh_copy_values", ECF_NOTHROW);
9421 /* Complex multiplication and division. These are handled as builtins
9422 rather than optabs because emit_library_call_value doesn't support
9423 complex. Further, we can do slightly better with folding these
9424 beasties if the real and complex parts of the arguments are separate. */
9428 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
9430 char mode_name_buf[4], *q;
9432 enum built_in_function mcode, dcode;
9433 tree type, inner_type;
9435 type = lang_hooks.types.type_for_mode ((enum machine_mode) mode, 0);
9438 inner_type = TREE_TYPE (type);
9440 ftype = build_function_type_list (type, inner_type, inner_type,
9441 inner_type, inner_type, NULL_TREE);
9443 mcode = ((enum built_in_function)
9444 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
9445 dcode = ((enum built_in_function)
9446 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
9448 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
9452 built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL);
9453 local_define_builtin (built_in_names[mcode], ftype, mcode,
9454 built_in_names[mcode], ECF_CONST | ECF_NOTHROW | ECF_LEAF);
9456 built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL);
9457 local_define_builtin (built_in_names[dcode], ftype, dcode,
9458 built_in_names[dcode], ECF_CONST | ECF_NOTHROW | ECF_LEAF);
9463 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
9466 If we requested a pointer to a vector, build up the pointers that
9467 we stripped off while looking for the inner type. Similarly for
9468 return values from functions.
9470 The argument TYPE is the top of the chain, and BOTTOM is the
9471 new type which we will point to. */
9474 reconstruct_complex_type (tree type, tree bottom)
9478 if (TREE_CODE (type) == POINTER_TYPE)
9480 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
9481 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
9482 TYPE_REF_CAN_ALIAS_ALL (type));
9484 else if (TREE_CODE (type) == REFERENCE_TYPE)
9486 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
9487 outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
9488 TYPE_REF_CAN_ALIAS_ALL (type));
9490 else if (TREE_CODE (type) == ARRAY_TYPE)
9492 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
9493 outer = build_array_type (inner, TYPE_DOMAIN (type));
9495 else if (TREE_CODE (type) == FUNCTION_TYPE)
9497 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
9498 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
9500 else if (TREE_CODE (type) == METHOD_TYPE)
9502 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
9503 /* The build_method_type_directly() routine prepends 'this' to argument list,
9504 so we must compensate by getting rid of it. */
9506 = build_method_type_directly
9507 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
9509 TREE_CHAIN (TYPE_ARG_TYPES (type)));
9511 else if (TREE_CODE (type) == OFFSET_TYPE)
9513 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
9514 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
9519 return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
9523 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
9526 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
9530 switch (GET_MODE_CLASS (mode))
9532 case MODE_VECTOR_INT:
9533 case MODE_VECTOR_FLOAT:
9534 case MODE_VECTOR_FRACT:
9535 case MODE_VECTOR_UFRACT:
9536 case MODE_VECTOR_ACCUM:
9537 case MODE_VECTOR_UACCUM:
9538 nunits = GET_MODE_NUNITS (mode);
9542 /* Check that there are no leftover bits. */
9543 gcc_assert (GET_MODE_BITSIZE (mode)
9544 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
9546 nunits = GET_MODE_BITSIZE (mode)
9547 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
9554 return make_vector_type (innertype, nunits, mode);
9557 /* Similarly, but takes the inner type and number of units, which must be
9561 build_vector_type (tree innertype, int nunits)
9563 return make_vector_type (innertype, nunits, VOIDmode);
9566 /* Similarly, but takes the inner type and number of units, which must be
9570 build_opaque_vector_type (tree innertype, int nunits)
9573 innertype = build_distinct_type_copy (innertype);
9574 t = make_vector_type (innertype, nunits, VOIDmode);
9575 TYPE_VECTOR_OPAQUE (t) = true;
9580 /* Given an initializer INIT, return TRUE if INIT is zero or some
9581 aggregate of zeros. Otherwise return FALSE. */
9583 initializer_zerop (const_tree init)
9589 switch (TREE_CODE (init))
9592 return integer_zerop (init);
9595 /* ??? Note that this is not correct for C4X float formats. There,
9596 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
9597 negative exponent. */
9598 return real_zerop (init)
9599 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
9602 return fixed_zerop (init);
9605 return integer_zerop (init)
9606 || (real_zerop (init)
9607 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
9608 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
9611 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
9612 if (!initializer_zerop (TREE_VALUE (elt)))
9618 unsigned HOST_WIDE_INT idx;
9620 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
9621 if (!initializer_zerop (elt))
9630 /* We need to loop through all elements to handle cases like
9631 "\0" and "\0foobar". */
9632 for (i = 0; i < TREE_STRING_LENGTH (init); ++i)
9633 if (TREE_STRING_POINTER (init)[i] != '\0')
9644 /* Build an empty statement at location LOC. */
9647 build_empty_stmt (location_t loc)
9649 tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
9650 SET_EXPR_LOCATION (t, loc);
9655 /* Build an OpenMP clause with code CODE. LOC is the location of the
9659 build_omp_clause (location_t loc, enum omp_clause_code code)
9664 length = omp_clause_num_ops[code];
9665 size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
9667 record_node_allocation_statistics (OMP_CLAUSE, size);
9669 t = ggc_alloc_tree_node (size);
9670 memset (t, 0, size);
9671 TREE_SET_CODE (t, OMP_CLAUSE);
9672 OMP_CLAUSE_SET_CODE (t, code);
9673 OMP_CLAUSE_LOCATION (t) = loc;
9678 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
9679 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
9680 Except for the CODE and operand count field, other storage for the
9681 object is initialized to zeros. */
9684 build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
9687 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
9689 gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
9690 gcc_assert (len >= 1);
9692 record_node_allocation_statistics (code, length);
9694 t = ggc_alloc_zone_cleared_tree_node_stat (&tree_zone, length PASS_MEM_STAT);
9696 TREE_SET_CODE (t, code);
9698 /* Can't use TREE_OPERAND to store the length because if checking is
9699 enabled, it will try to check the length before we store it. :-P */
9700 t->exp.operands[0] = build_int_cst (sizetype, len);
9705 /* Helper function for build_call_* functions; build a CALL_EXPR with
9706 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
9707 the argument slots. */
9710 build_call_1 (tree return_type, tree fn, int nargs)
9714 t = build_vl_exp (CALL_EXPR, nargs + 3);
9715 TREE_TYPE (t) = return_type;
9716 CALL_EXPR_FN (t) = fn;
9717 CALL_EXPR_STATIC_CHAIN (t) = NULL;
9722 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9723 FN and a null static chain slot. NARGS is the number of call arguments
9724 which are specified as "..." arguments. */
9727 build_call_nary (tree return_type, tree fn, int nargs, ...)
9731 va_start (args, nargs);
9732 ret = build_call_valist (return_type, fn, nargs, args);
9737 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9738 FN and a null static chain slot. NARGS is the number of call arguments
9739 which are specified as a va_list ARGS. */
9742 build_call_valist (tree return_type, tree fn, int nargs, va_list args)
9747 t = build_call_1 (return_type, fn, nargs);
9748 for (i = 0; i < nargs; i++)
9749 CALL_EXPR_ARG (t, i) = va_arg (args, tree);
9750 process_call_operands (t);
9754 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
9755 FN and a null static chain slot. NARGS is the number of call arguments
9756 which are specified as a tree array ARGS. */
9759 build_call_array_loc (location_t loc, tree return_type, tree fn,
9760 int nargs, const tree *args)
9765 t = build_call_1 (return_type, fn, nargs);
9766 for (i = 0; i < nargs; i++)
9767 CALL_EXPR_ARG (t, i) = args[i];
9768 process_call_operands (t);
9769 SET_EXPR_LOCATION (t, loc);
9773 /* Like build_call_array, but takes a VEC. */
9776 build_call_vec (tree return_type, tree fn, VEC(tree,gc) *args)
9781 ret = build_call_1 (return_type, fn, VEC_length (tree, args));
9782 FOR_EACH_VEC_ELT (tree, args, ix, t)
9783 CALL_EXPR_ARG (ret, ix) = t;
9784 process_call_operands (ret);
9789 /* Returns true if it is possible to prove that the index of
9790 an array access REF (an ARRAY_REF expression) falls into the
9794 in_array_bounds_p (tree ref)
9796 tree idx = TREE_OPERAND (ref, 1);
9799 if (TREE_CODE (idx) != INTEGER_CST)
9802 min = array_ref_low_bound (ref);
9803 max = array_ref_up_bound (ref);
9806 || TREE_CODE (min) != INTEGER_CST
9807 || TREE_CODE (max) != INTEGER_CST)
9810 if (tree_int_cst_lt (idx, min)
9811 || tree_int_cst_lt (max, idx))
9817 /* Returns true if it is possible to prove that the range of
9818 an array access REF (an ARRAY_RANGE_REF expression) falls
9819 into the array bounds. */
9822 range_in_array_bounds_p (tree ref)
9824 tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref));
9825 tree range_min, range_max, min, max;
9827 range_min = TYPE_MIN_VALUE (domain_type);
9828 range_max = TYPE_MAX_VALUE (domain_type);
9831 || TREE_CODE (range_min) != INTEGER_CST
9832 || TREE_CODE (range_max) != INTEGER_CST)
9835 min = array_ref_low_bound (ref);
9836 max = array_ref_up_bound (ref);
9839 || TREE_CODE (min) != INTEGER_CST
9840 || TREE_CODE (max) != INTEGER_CST)
9843 if (tree_int_cst_lt (range_min, min)
9844 || tree_int_cst_lt (max, range_max))
9850 /* Return true if T (assumed to be a DECL) must be assigned a memory
9854 needs_to_live_in_memory (const_tree t)
9856 if (TREE_CODE (t) == SSA_NAME)
9857 t = SSA_NAME_VAR (t);
9859 return (TREE_ADDRESSABLE (t)
9860 || is_global_var (t)
9861 || (TREE_CODE (t) == RESULT_DECL
9862 && !DECL_BY_REFERENCE (t)
9863 && aggregate_value_p (t, current_function_decl)));
9866 /* Return value of a constant X and sign-extend it. */
9869 int_cst_value (const_tree x)
9871 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
9872 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
9874 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9875 gcc_assert (TREE_INT_CST_HIGH (x) == 0
9876 || TREE_INT_CST_HIGH (x) == -1);
9878 if (bits < HOST_BITS_PER_WIDE_INT)
9880 bool negative = ((val >> (bits - 1)) & 1) != 0;
9882 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
9884 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
9890 /* Return value of a constant X and sign-extend it. */
9893 widest_int_cst_value (const_tree x)
9895 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
9896 unsigned HOST_WIDEST_INT val = TREE_INT_CST_LOW (x);
9898 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
9899 gcc_assert (HOST_BITS_PER_WIDEST_INT >= 2 * HOST_BITS_PER_WIDE_INT);
9900 val |= (((unsigned HOST_WIDEST_INT) TREE_INT_CST_HIGH (x))
9901 << HOST_BITS_PER_WIDE_INT);
9903 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9904 gcc_assert (TREE_INT_CST_HIGH (x) == 0
9905 || TREE_INT_CST_HIGH (x) == -1);
9908 if (bits < HOST_BITS_PER_WIDEST_INT)
9910 bool negative = ((val >> (bits - 1)) & 1) != 0;
9912 val |= (~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1;
9914 val &= ~((~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1);
9920 /* If TYPE is an integral type, return an equivalent type which is
9921 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
9922 return TYPE itself. */
9925 signed_or_unsigned_type_for (int unsignedp, tree type)
9928 if (POINTER_TYPE_P (type))
9930 /* If the pointer points to the normal address space, use the
9931 size_type_node. Otherwise use an appropriate size for the pointer
9932 based on the named address space it points to. */
9933 if (!TYPE_ADDR_SPACE (TREE_TYPE (t)))
9936 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
9939 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
9942 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
9945 /* Returns unsigned variant of TYPE. */
9948 unsigned_type_for (tree type)
9950 return signed_or_unsigned_type_for (1, type);
9953 /* Returns signed variant of TYPE. */
9956 signed_type_for (tree type)
9958 return signed_or_unsigned_type_for (0, type);
9961 /* Returns the largest value obtainable by casting something in INNER type to
9965 upper_bound_in_type (tree outer, tree inner)
9967 unsigned HOST_WIDE_INT lo, hi;
9968 unsigned int det = 0;
9969 unsigned oprec = TYPE_PRECISION (outer);
9970 unsigned iprec = TYPE_PRECISION (inner);
9973 /* Compute a unique number for every combination. */
9974 det |= (oprec > iprec) ? 4 : 0;
9975 det |= TYPE_UNSIGNED (outer) ? 2 : 0;
9976 det |= TYPE_UNSIGNED (inner) ? 1 : 0;
9978 /* Determine the exponent to use. */
9983 /* oprec <= iprec, outer: signed, inner: don't care. */
9988 /* oprec <= iprec, outer: unsigned, inner: don't care. */
9992 /* oprec > iprec, outer: signed, inner: signed. */
9996 /* oprec > iprec, outer: signed, inner: unsigned. */
10000 /* oprec > iprec, outer: unsigned, inner: signed. */
10004 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10008 gcc_unreachable ();
10011 /* Compute 2^^prec - 1. */
10012 if (prec <= HOST_BITS_PER_WIDE_INT)
10015 lo = ((~(unsigned HOST_WIDE_INT) 0)
10016 >> (HOST_BITS_PER_WIDE_INT - prec));
10020 hi = ((~(unsigned HOST_WIDE_INT) 0)
10021 >> (2 * HOST_BITS_PER_WIDE_INT - prec));
10022 lo = ~(unsigned HOST_WIDE_INT) 0;
10025 return build_int_cst_wide (outer, lo, hi);
10028 /* Returns the smallest value obtainable by casting something in INNER type to
10032 lower_bound_in_type (tree outer, tree inner)
10034 unsigned HOST_WIDE_INT lo, hi;
10035 unsigned oprec = TYPE_PRECISION (outer);
10036 unsigned iprec = TYPE_PRECISION (inner);
10038 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10040 if (TYPE_UNSIGNED (outer)
10041 /* If we are widening something of an unsigned type, OUTER type
10042 contains all values of INNER type. In particular, both INNER
10043 and OUTER types have zero in common. */
10044 || (oprec > iprec && TYPE_UNSIGNED (inner)))
10048 /* If we are widening a signed type to another signed type, we
10049 want to obtain -2^^(iprec-1). If we are keeping the
10050 precision or narrowing to a signed type, we want to obtain
10052 unsigned prec = oprec > iprec ? iprec : oprec;
10054 if (prec <= HOST_BITS_PER_WIDE_INT)
10056 hi = ~(unsigned HOST_WIDE_INT) 0;
10057 lo = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1);
10061 hi = ((~(unsigned HOST_WIDE_INT) 0)
10062 << (prec - HOST_BITS_PER_WIDE_INT - 1));
10067 return build_int_cst_wide (outer, lo, hi);
10070 /* Return nonzero if two operands that are suitable for PHI nodes are
10071 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10072 SSA_NAME or invariant. Note that this is strictly an optimization.
10073 That is, callers of this function can directly call operand_equal_p
10074 and get the same result, only slower. */
10077 operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
10081 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
10083 return operand_equal_p (arg0, arg1, 0);
10086 /* Returns number of zeros at the end of binary representation of X.
10088 ??? Use ffs if available? */
10091 num_ending_zeros (const_tree x)
10093 unsigned HOST_WIDE_INT fr, nfr;
10094 unsigned num, abits;
10095 tree type = TREE_TYPE (x);
10097 if (TREE_INT_CST_LOW (x) == 0)
10099 num = HOST_BITS_PER_WIDE_INT;
10100 fr = TREE_INT_CST_HIGH (x);
10105 fr = TREE_INT_CST_LOW (x);
10108 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
10111 if (nfr << abits == fr)
10118 if (num > TYPE_PRECISION (type))
10119 num = TYPE_PRECISION (type);
10121 return build_int_cst_type (type, num);
10125 #define WALK_SUBTREE(NODE) \
10128 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10134 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10135 be walked whenever a type is seen in the tree. Rest of operands and return
10136 value are as for walk_tree. */
10139 walk_type_fields (tree type, walk_tree_fn func, void *data,
10140 struct pointer_set_t *pset, walk_tree_lh lh)
10142 tree result = NULL_TREE;
10144 switch (TREE_CODE (type))
10147 case REFERENCE_TYPE:
10148 /* We have to worry about mutually recursive pointers. These can't
10149 be written in C. They can in Ada. It's pathological, but
10150 there's an ACATS test (c38102a) that checks it. Deal with this
10151 by checking if we're pointing to another pointer, that one
10152 points to another pointer, that one does too, and we have no htab.
10153 If so, get a hash table. We check three levels deep to avoid
10154 the cost of the hash table if we don't need one. */
10155 if (POINTER_TYPE_P (TREE_TYPE (type))
10156 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
10157 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
10160 result = walk_tree_without_duplicates (&TREE_TYPE (type),
10168 /* ... fall through ... */
10171 WALK_SUBTREE (TREE_TYPE (type));
10175 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
10177 /* Fall through. */
10179 case FUNCTION_TYPE:
10180 WALK_SUBTREE (TREE_TYPE (type));
10184 /* We never want to walk into default arguments. */
10185 for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
10186 WALK_SUBTREE (TREE_VALUE (arg));
10191 /* Don't follow this nodes's type if a pointer for fear that
10192 we'll have infinite recursion. If we have a PSET, then we
10195 || (!POINTER_TYPE_P (TREE_TYPE (type))
10196 && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
10197 WALK_SUBTREE (TREE_TYPE (type));
10198 WALK_SUBTREE (TYPE_DOMAIN (type));
10202 WALK_SUBTREE (TREE_TYPE (type));
10203 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
10213 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
10214 called with the DATA and the address of each sub-tree. If FUNC returns a
10215 non-NULL value, the traversal is stopped, and the value returned by FUNC
10216 is returned. If PSET is non-NULL it is used to record the nodes visited,
10217 and to avoid visiting a node more than once. */
10220 walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
10221 struct pointer_set_t *pset, walk_tree_lh lh)
10223 enum tree_code code;
10227 #define WALK_SUBTREE_TAIL(NODE) \
10231 goto tail_recurse; \
10236 /* Skip empty subtrees. */
10240 /* Don't walk the same tree twice, if the user has requested
10241 that we avoid doing so. */
10242 if (pset && pointer_set_insert (pset, *tp))
10245 /* Call the function. */
10247 result = (*func) (tp, &walk_subtrees, data);
10249 /* If we found something, return it. */
10253 code = TREE_CODE (*tp);
10255 /* Even if we didn't, FUNC may have decided that there was nothing
10256 interesting below this point in the tree. */
10257 if (!walk_subtrees)
10259 /* But we still need to check our siblings. */
10260 if (code == TREE_LIST)
10261 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
10262 else if (code == OMP_CLAUSE)
10263 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
10270 result = (*lh) (tp, &walk_subtrees, func, data, pset);
10271 if (result || !walk_subtrees)
10278 case IDENTIFIER_NODE:
10285 case PLACEHOLDER_EXPR:
10289 /* None of these have subtrees other than those already walked
10294 WALK_SUBTREE (TREE_VALUE (*tp));
10295 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
10300 int len = TREE_VEC_LENGTH (*tp);
10305 /* Walk all elements but the first. */
10307 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
10309 /* Now walk the first one as a tail call. */
10310 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
10314 WALK_SUBTREE (TREE_REALPART (*tp));
10315 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
10319 unsigned HOST_WIDE_INT idx;
10320 constructor_elt *ce;
10323 VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce);
10325 WALK_SUBTREE (ce->value);
10330 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
10335 for (decl = BIND_EXPR_VARS (*tp); decl; decl = DECL_CHAIN (decl))
10337 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
10338 into declarations that are just mentioned, rather than
10339 declared; they don't really belong to this part of the tree.
10340 And, we can see cycles: the initializer for a declaration
10341 can refer to the declaration itself. */
10342 WALK_SUBTREE (DECL_INITIAL (decl));
10343 WALK_SUBTREE (DECL_SIZE (decl));
10344 WALK_SUBTREE (DECL_SIZE_UNIT (decl));
10346 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp));
10349 case STATEMENT_LIST:
10351 tree_stmt_iterator i;
10352 for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
10353 WALK_SUBTREE (*tsi_stmt_ptr (i));
10358 switch (OMP_CLAUSE_CODE (*tp))
10360 case OMP_CLAUSE_PRIVATE:
10361 case OMP_CLAUSE_SHARED:
10362 case OMP_CLAUSE_FIRSTPRIVATE:
10363 case OMP_CLAUSE_COPYIN:
10364 case OMP_CLAUSE_COPYPRIVATE:
10365 case OMP_CLAUSE_IF:
10366 case OMP_CLAUSE_NUM_THREADS:
10367 case OMP_CLAUSE_SCHEDULE:
10368 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
10371 case OMP_CLAUSE_NOWAIT:
10372 case OMP_CLAUSE_ORDERED:
10373 case OMP_CLAUSE_DEFAULT:
10374 case OMP_CLAUSE_UNTIED:
10375 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
10377 case OMP_CLAUSE_LASTPRIVATE:
10378 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp));
10379 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp));
10380 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
10382 case OMP_CLAUSE_COLLAPSE:
10385 for (i = 0; i < 3; i++)
10386 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
10387 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
10390 case OMP_CLAUSE_REDUCTION:
10393 for (i = 0; i < 4; i++)
10394 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
10395 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
10399 gcc_unreachable ();
10407 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
10408 But, we only want to walk once. */
10409 len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3;
10410 for (i = 0; i < len; ++i)
10411 WALK_SUBTREE (TREE_OPERAND (*tp, i));
10412 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len));
10416 /* If this is a TYPE_DECL, walk into the fields of the type that it's
10417 defining. We only want to walk into these fields of a type in this
10418 case and not in the general case of a mere reference to the type.
10420 The criterion is as follows: if the field can be an expression, it
10421 must be walked only here. This should be in keeping with the fields
10422 that are directly gimplified in gimplify_type_sizes in order for the
10423 mark/copy-if-shared/unmark machinery of the gimplifier to work with
10424 variable-sized types.
10426 Note that DECLs get walked as part of processing the BIND_EXPR. */
10427 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
10429 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
10430 if (TREE_CODE (*type_p) == ERROR_MARK)
10433 /* Call the function for the type. See if it returns anything or
10434 doesn't want us to continue. If we are to continue, walk both
10435 the normal fields and those for the declaration case. */
10436 result = (*func) (type_p, &walk_subtrees, data);
10437 if (result || !walk_subtrees)
10440 result = walk_type_fields (*type_p, func, data, pset, lh);
10444 /* If this is a record type, also walk the fields. */
10445 if (RECORD_OR_UNION_TYPE_P (*type_p))
10449 for (field = TYPE_FIELDS (*type_p); field;
10450 field = DECL_CHAIN (field))
10452 /* We'd like to look at the type of the field, but we can
10453 easily get infinite recursion. So assume it's pointed
10454 to elsewhere in the tree. Also, ignore things that
10456 if (TREE_CODE (field) != FIELD_DECL)
10459 WALK_SUBTREE (DECL_FIELD_OFFSET (field));
10460 WALK_SUBTREE (DECL_SIZE (field));
10461 WALK_SUBTREE (DECL_SIZE_UNIT (field));
10462 if (TREE_CODE (*type_p) == QUAL_UNION_TYPE)
10463 WALK_SUBTREE (DECL_QUALIFIER (field));
10467 /* Same for scalar types. */
10468 else if (TREE_CODE (*type_p) == BOOLEAN_TYPE
10469 || TREE_CODE (*type_p) == ENUMERAL_TYPE
10470 || TREE_CODE (*type_p) == INTEGER_TYPE
10471 || TREE_CODE (*type_p) == FIXED_POINT_TYPE
10472 || TREE_CODE (*type_p) == REAL_TYPE)
10474 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p));
10475 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p));
10478 WALK_SUBTREE (TYPE_SIZE (*type_p));
10479 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p));
10484 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
10488 /* Walk over all the sub-trees of this operand. */
10489 len = TREE_OPERAND_LENGTH (*tp);
10491 /* Go through the subtrees. We need to do this in forward order so
10492 that the scope of a FOR_EXPR is handled properly. */
10495 for (i = 0; i < len - 1; ++i)
10496 WALK_SUBTREE (TREE_OPERAND (*tp, i));
10497 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len - 1));
10500 /* If this is a type, walk the needed fields in the type. */
10501 else if (TYPE_P (*tp))
10502 return walk_type_fields (*tp, func, data, pset, lh);
10506 /* We didn't find what we were looking for. */
10509 #undef WALK_SUBTREE_TAIL
10511 #undef WALK_SUBTREE
10513 /* Like walk_tree, but does not walk duplicate nodes more than once. */
10516 walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
10520 struct pointer_set_t *pset;
10522 pset = pointer_set_create ();
10523 result = walk_tree_1 (tp, func, data, pset, lh);
10524 pointer_set_destroy (pset);
10530 tree_block (tree t)
10532 char const c = TREE_CODE_CLASS (TREE_CODE (t));
10534 if (IS_EXPR_CODE_CLASS (c))
10535 return &t->exp.block;
10536 gcc_unreachable ();
10540 /* Create a nameless artificial label and put it in the current
10541 function context. The label has a location of LOC. Returns the
10542 newly created label. */
10545 create_artificial_label (location_t loc)
10547 tree lab = build_decl (loc,
10548 LABEL_DECL, NULL_TREE, void_type_node);
10550 DECL_ARTIFICIAL (lab) = 1;
10551 DECL_IGNORED_P (lab) = 1;
10552 DECL_CONTEXT (lab) = current_function_decl;
10556 /* Given a tree, try to return a useful variable name that we can use
10557 to prefix a temporary that is being assigned the value of the tree.
10558 I.E. given <temp> = &A, return A. */
10563 tree stripped_decl;
10566 STRIP_NOPS (stripped_decl);
10567 if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
10568 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
10571 switch (TREE_CODE (stripped_decl))
10574 return get_name (TREE_OPERAND (stripped_decl, 0));
10581 /* Return true if TYPE has a variable argument list. */
10584 stdarg_p (const_tree fntype)
10586 function_args_iterator args_iter;
10587 tree n = NULL_TREE, t;
10592 FOREACH_FUNCTION_ARGS(fntype, t, args_iter)
10597 return n != NULL_TREE && n != void_type_node;
10600 /* Return true if TYPE has a prototype. */
10603 prototype_p (tree fntype)
10607 gcc_assert (fntype != NULL_TREE);
10609 t = TYPE_ARG_TYPES (fntype);
10610 return (t != NULL_TREE);
10613 /* If BLOCK is inlined from an __attribute__((__artificial__))
10614 routine, return pointer to location from where it has been
10617 block_nonartificial_location (tree block)
10619 location_t *ret = NULL;
10621 while (block && TREE_CODE (block) == BLOCK
10622 && BLOCK_ABSTRACT_ORIGIN (block))
10624 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
10626 while (TREE_CODE (ao) == BLOCK
10627 && BLOCK_ABSTRACT_ORIGIN (ao)
10628 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
10629 ao = BLOCK_ABSTRACT_ORIGIN (ao);
10631 if (TREE_CODE (ao) == FUNCTION_DECL)
10633 /* If AO is an artificial inline, point RET to the
10634 call site locus at which it has been inlined and continue
10635 the loop, in case AO's caller is also an artificial
10637 if (DECL_DECLARED_INLINE_P (ao)
10638 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
10639 ret = &BLOCK_SOURCE_LOCATION (block);
10643 else if (TREE_CODE (ao) != BLOCK)
10646 block = BLOCK_SUPERCONTEXT (block);
10652 /* If EXP is inlined from an __attribute__((__artificial__))
10653 function, return the location of the original call expression. */
10656 tree_nonartificial_location (tree exp)
10658 location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
10663 return EXPR_LOCATION (exp);
10667 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
10670 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
10673 cl_option_hash_hash (const void *x)
10675 const_tree const t = (const_tree) x;
10679 hashval_t hash = 0;
10681 if (TREE_CODE (t) == OPTIMIZATION_NODE)
10683 p = (const char *)TREE_OPTIMIZATION (t);
10684 len = sizeof (struct cl_optimization);
10687 else if (TREE_CODE (t) == TARGET_OPTION_NODE)
10689 p = (const char *)TREE_TARGET_OPTION (t);
10690 len = sizeof (struct cl_target_option);
10694 gcc_unreachable ();
10696 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
10698 for (i = 0; i < len; i++)
10700 hash = (hash << 4) ^ ((i << 2) | p[i]);
10705 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
10706 TARGET_OPTION tree node) is the same as that given by *Y, which is the
10710 cl_option_hash_eq (const void *x, const void *y)
10712 const_tree const xt = (const_tree) x;
10713 const_tree const yt = (const_tree) y;
10718 if (TREE_CODE (xt) != TREE_CODE (yt))
10721 if (TREE_CODE (xt) == OPTIMIZATION_NODE)
10723 xp = (const char *)TREE_OPTIMIZATION (xt);
10724 yp = (const char *)TREE_OPTIMIZATION (yt);
10725 len = sizeof (struct cl_optimization);
10728 else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
10730 xp = (const char *)TREE_TARGET_OPTION (xt);
10731 yp = (const char *)TREE_TARGET_OPTION (yt);
10732 len = sizeof (struct cl_target_option);
10736 gcc_unreachable ();
10738 return (memcmp (xp, yp, len) == 0);
10741 /* Build an OPTIMIZATION_NODE based on the current options. */
10744 build_optimization_node (void)
10749 /* Use the cache of optimization nodes. */
10751 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
10754 slot = htab_find_slot (cl_option_hash_table, cl_optimization_node, INSERT);
10758 /* Insert this one into the hash table. */
10759 t = cl_optimization_node;
10762 /* Make a new node for next time round. */
10763 cl_optimization_node = make_node (OPTIMIZATION_NODE);
10769 /* Build a TARGET_OPTION_NODE based on the current options. */
10772 build_target_option_node (void)
10777 /* Use the cache of optimization nodes. */
10779 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
10782 slot = htab_find_slot (cl_option_hash_table, cl_target_option_node, INSERT);
10786 /* Insert this one into the hash table. */
10787 t = cl_target_option_node;
10790 /* Make a new node for next time round. */
10791 cl_target_option_node = make_node (TARGET_OPTION_NODE);
10797 /* Determine the "ultimate origin" of a block. The block may be an inlined
10798 instance of an inlined instance of a block which is local to an inline
10799 function, so we have to trace all of the way back through the origin chain
10800 to find out what sort of node actually served as the original seed for the
10804 block_ultimate_origin (const_tree block)
10806 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
10808 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
10809 nodes in the function to point to themselves; ignore that if
10810 we're trying to output the abstract instance of this function. */
10811 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
10814 if (immediate_origin == NULL_TREE)
10819 tree lookahead = immediate_origin;
10823 ret_val = lookahead;
10824 lookahead = (TREE_CODE (ret_val) == BLOCK
10825 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
10827 while (lookahead != NULL && lookahead != ret_val);
10829 /* The block's abstract origin chain may not be the *ultimate* origin of
10830 the block. It could lead to a DECL that has an abstract origin set.
10831 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
10832 will give us if it has one). Note that DECL's abstract origins are
10833 supposed to be the most distant ancestor (or so decl_ultimate_origin
10834 claims), so we don't need to loop following the DECL origins. */
10835 if (DECL_P (ret_val))
10836 return DECL_ORIGIN (ret_val);
10842 /* Return true if T1 and T2 are equivalent lists. */
10845 list_equal_p (const_tree t1, const_tree t2)
10847 for (; t1 && t2; t1 = TREE_CHAIN (t1) , t2 = TREE_CHAIN (t2))
10848 if (TREE_VALUE (t1) != TREE_VALUE (t2))
10853 /* Return true iff conversion in EXP generates no instruction. Mark
10854 it inline so that we fully inline into the stripping functions even
10855 though we have two uses of this function. */
10858 tree_nop_conversion (const_tree exp)
10860 tree outer_type, inner_type;
10862 if (!CONVERT_EXPR_P (exp)
10863 && TREE_CODE (exp) != NON_LVALUE_EXPR)
10865 if (TREE_OPERAND (exp, 0) == error_mark_node)
10868 outer_type = TREE_TYPE (exp);
10869 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10874 /* Use precision rather then machine mode when we can, which gives
10875 the correct answer even for submode (bit-field) types. */
10876 if ((INTEGRAL_TYPE_P (outer_type)
10877 || POINTER_TYPE_P (outer_type)
10878 || TREE_CODE (outer_type) == OFFSET_TYPE)
10879 && (INTEGRAL_TYPE_P (inner_type)
10880 || POINTER_TYPE_P (inner_type)
10881 || TREE_CODE (inner_type) == OFFSET_TYPE))
10882 return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
10884 /* Otherwise fall back on comparing machine modes (e.g. for
10885 aggregate types, floats). */
10886 return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
10889 /* Return true iff conversion in EXP generates no instruction. Don't
10890 consider conversions changing the signedness. */
10893 tree_sign_nop_conversion (const_tree exp)
10895 tree outer_type, inner_type;
10897 if (!tree_nop_conversion (exp))
10900 outer_type = TREE_TYPE (exp);
10901 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10903 return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
10904 && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
10907 /* Strip conversions from EXP according to tree_nop_conversion and
10908 return the resulting expression. */
10911 tree_strip_nop_conversions (tree exp)
10913 while (tree_nop_conversion (exp))
10914 exp = TREE_OPERAND (exp, 0);
10918 /* Strip conversions from EXP according to tree_sign_nop_conversion
10919 and return the resulting expression. */
10922 tree_strip_sign_nop_conversions (tree exp)
10924 while (tree_sign_nop_conversion (exp))
10925 exp = TREE_OPERAND (exp, 0);
10929 static GTY(()) tree gcc_eh_personality_decl;
10931 /* Return the GCC personality function decl. */
10934 lhd_gcc_personality (void)
10936 if (!gcc_eh_personality_decl)
10937 gcc_eh_personality_decl = build_personality_function ("gcc");
10938 return gcc_eh_personality_decl;
10941 /* Try to find a base info of BINFO that would have its field decl at offset
10942 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
10943 found, return, otherwise return NULL_TREE. */
10946 get_binfo_at_offset (tree binfo, HOST_WIDE_INT offset, tree expected_type)
10948 tree type = BINFO_TYPE (binfo);
10952 HOST_WIDE_INT pos, size;
10956 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (expected_type))
10961 for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
10963 if (TREE_CODE (fld) != FIELD_DECL)
10966 pos = int_bit_position (fld);
10967 size = tree_low_cst (DECL_SIZE (fld), 1);
10968 if (pos <= offset && (pos + size) > offset)
10971 if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
10974 if (!DECL_ARTIFICIAL (fld))
10976 binfo = TYPE_BINFO (TREE_TYPE (fld));
10980 /* Offset 0 indicates the primary base, whose vtable contents are
10981 represented in the binfo for the derived class. */
10982 else if (offset != 0)
10984 tree base_binfo, found_binfo = NULL_TREE;
10985 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
10986 if (TREE_TYPE (base_binfo) == TREE_TYPE (fld))
10988 found_binfo = base_binfo;
10993 binfo = found_binfo;
10996 type = TREE_TYPE (fld);
11001 /* Returns true if X is a typedef decl. */
11004 is_typedef_decl (tree x)
11006 return (x && TREE_CODE (x) == TYPE_DECL
11007 && DECL_ORIGINAL_TYPE (x) != NULL_TREE);
11010 /* Returns true iff TYPE is a type variant created for a typedef. */
11013 typedef_variant_p (tree type)
11015 return is_typedef_decl (TYPE_NAME (type));
11018 /* Warn about a use of an identifier which was marked deprecated. */
11020 warn_deprecated_use (tree node, tree attr)
11024 if (node == 0 || !warn_deprecated_decl)
11030 attr = DECL_ATTRIBUTES (node);
11031 else if (TYPE_P (node))
11033 tree decl = TYPE_STUB_DECL (node);
11035 attr = lookup_attribute ("deprecated",
11036 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
11041 attr = lookup_attribute ("deprecated", attr);
11044 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
11050 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
11052 warning (OPT_Wdeprecated_declarations,
11053 "%qD is deprecated (declared at %s:%d): %s",
11054 node, xloc.file, xloc.line, msg);
11056 warning (OPT_Wdeprecated_declarations,
11057 "%qD is deprecated (declared at %s:%d)",
11058 node, xloc.file, xloc.line);
11060 else if (TYPE_P (node))
11062 tree what = NULL_TREE;
11063 tree decl = TYPE_STUB_DECL (node);
11065 if (TYPE_NAME (node))
11067 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
11068 what = TYPE_NAME (node);
11069 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
11070 && DECL_NAME (TYPE_NAME (node)))
11071 what = DECL_NAME (TYPE_NAME (node));
11076 expanded_location xloc
11077 = expand_location (DECL_SOURCE_LOCATION (decl));
11081 warning (OPT_Wdeprecated_declarations,
11082 "%qE is deprecated (declared at %s:%d): %s",
11083 what, xloc.file, xloc.line, msg);
11085 warning (OPT_Wdeprecated_declarations,
11086 "%qE is deprecated (declared at %s:%d)", what,
11087 xloc.file, xloc.line);
11092 warning (OPT_Wdeprecated_declarations,
11093 "type is deprecated (declared at %s:%d): %s",
11094 xloc.file, xloc.line, msg);
11096 warning (OPT_Wdeprecated_declarations,
11097 "type is deprecated (declared at %s:%d)",
11098 xloc.file, xloc.line);
11106 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
11109 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
11114 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
11117 warning (OPT_Wdeprecated_declarations, "type is deprecated");
11123 #include "gt-tree.h"